MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HDF5WriterBase.h
Go to the documentation of this file.
1 // HDF5WriterBase.h ---
2 //
3 // Filename: HDF5WriterBase.h
4 // Description:
5 // Author: Subhasis Ray
6 // Maintainer:
7 // Created: Sat Feb 25 14:39:19 2012 (+0530)
8 // Version:
9 // Last-Updated: Tue Aug 25 23:11:28 2015 (-0400)
10 // By: subha
11 // Update #: 57
12 // URL:
13 // Keywords:
14 // Compatibility:
15 //
16 //
17 
18 // Commentary:
19 //
20 // HDF5WriterBase provides a common interface for writing data/model to file.
21 //
22 //
23 
24 // Change log:
25 //
26 // 2012-02-25 14:39:36 (+0530) subha - started initial implementation
27 //
28 
29 // Code:
30 
31 #ifdef USE_HDF5
32 #ifndef _HDF5IO_H
33 #define _HDF5IO_H
34 #include <typeinfo>
35 
36 hid_t require_attribute(hid_t file_id, string path,
37  hid_t data_type, hid_t data_id);
38 
39 hid_t require_group(hid_t file_id, string path);
40 
41 class HDF5WriterBase
42 {
43  public:
44  static const hssize_t CHUNK_SIZE;
45  HDF5WriterBase();
46  virtual ~HDF5WriterBase();
47  void setFilename(string filename);
48  string getFilename() const;
49  bool isOpen() const;
50  void setMode(unsigned int mode);
51  unsigned int getMode() const;
52  void setChunkSize(unsigned int);
53  unsigned int getChunkSize() const;
54  void setCompressor(string compressor);
55  string getCompressor() const;
56  void setCompression(unsigned int level);
57  unsigned int getCompression() const;
58  void setStringAttr(string name, string value);
59  void setDoubleAttr(string name, double value);
60  void setLongAttr(string name, long value);
61  string getStringAttr(string name) const;
62  double getDoubleAttr(string name) const;
63  long getLongAttr(string name) const;
64 
65  void setStringVecAttr(string name, vector < string > value);
66  void setDoubleVecAttr(string name, vector < double > value);
67  void setLongVecAttr(string name, vector < long > value);
68  vector < string > getStringVecAttr(string name) const;
69  vector < double > getDoubleVecAttr(string name) const;
70  vector < long > getLongVecAttr(string name) const;
71 
72  virtual void flushAttributes();
73  virtual void flush();
74  virtual void close();
75 
76  static const Cinfo* initCinfo();
77 
78  protected:
79  friend void testCreateStringDataset();
80 
81  herr_t openFile();
82  // C++ sucks - does not allow template specialization inside class
83  hid_t createDoubleDataset(hid_t parent, std::string name, hsize_t size=0, hsize_t maxsize=H5S_UNLIMITED);
84  hid_t createStringDataset(hid_t parent, std::string name, hsize_t size=0, hsize_t maxsize=H5S_UNLIMITED);
85 
86  herr_t appendToDataset(hid_t dataset, const vector<double>& data);
87  hid_t createDataset2D(hid_t parent, string name, unsigned int rows);
88 
93  map <string, hid_t> nodemap_;
95  hid_t filehandle_;
96  string filename_;
97  unsigned int openmode_;
98  // We also allow attributes of string, double or long int type on / node
99  map<string, string> sattr_;
100  map<string, double> dattr_;
101  map<string, long> lattr_;
102  map<string, vector < string > > svecattr_;
103  map<string, vector < double > > dvecattr_;
104  map<string, vector < long > > lvecattr_;
105  // These are for compressing data
106  unsigned int chunkSize_;
107  string compressor_; // can be zlib or szip
108  unsigned int compression_;
109 
110 };
111 
112 
113 template <typename A> herr_t writeScalarAttr(hid_t file_id, string path, A value)
114 {
115  cerr << "This should be never be called."
116  << " Specialized version exist for basic types." << endl;
117  return -1;
118 }
119 
120 
122 // Write vector attributes
124 
125 template <typename A> herr_t writeVectorAttr(hid_t file_id, string path,
126  vector < A > value)
127 {
128  cerr << "writeVectorAttr: This should be never be called."
129  << " Specialized version exist for basic types." << endl;
130  return -1;
131 }
132 
133 #endif // _HDF5IO_H
134 #endif // USE_HDF5
135 
136 
137 
138 //
139 // HDF5WriterBase.h ends here
uint32_t value
Definition: moosemodule.h:42
void testCreateStringDataset()
Definition: testNSDF.cpp:91
static char name[]
Definition: mfield.cpp:401
Definition: Cinfo.h:18
static char path[]
Definition: mfield.cpp:403