libSplash
SerialDataCollector.hpp
1 
23 #ifndef SERIALDATACOLLECTOR_H
24 #define SERIALDATACOLLECTOR_H
25 
26 #include <hdf5.h>
27 #include <sstream>
28 #include <iostream>
29 
30 #include "splash/DataCollector.hpp"
31 #include "splash/DCException.hpp"
32 #include "splash/core/HandleMgr.hpp"
33 #include "splash/sdc_defines.hpp"
34 
35 namespace splash
36 {
37 
38  class DCGroup;
39 
46  {
47  private:
53  void setFileAccessParams(hid_t& fileAccProperties);
54 
61  bool fileExists(std::string filename);
62 
74  std::string getFullFilename(const Dimensions mpiPos, std::string baseFilename,
75  bool isFullNameAllowed) const throw (DCException);
76 
85  std::string getExceptionString(std::string func, std::string msg, const char *info = NULL);
86 
87  static herr_t visitObjCallback(hid_t o_id, const char *name,
88  const H5O_info_t *object_info, void *op_data);
89 
90  void openCustomGroup(DCGroup& group, Dimensions *mpiPosition = NULL) throw (DCException);
92  hid_t openGroup(DCGroup& group, int32_t id, const char* name,
93  Dimensions *mpiPosition = NULL) throw (DCException);
94 
95  protected:
96 
100  enum FileStatusType
101  {
102  FST_CLOSED, FST_WRITING, FST_READING, FST_CREATING, FST_MERGING
103  };
104 
105  // internal HDF5 file handles
106  HandleMgr handles;
107 
108  // property list for HDF5 file access
109  hid_t fileAccProperties;
110 
111  // current file access type
112  FileStatusType fileStatus;
113 
114  // id for last written iteration
115  int32_t maxID;
116 
117  // the MPI topology for a distributed file
118  Dimensions mpiTopology;
119 
120  // enable data compression
121  bool enableCompression;
122 
123  void openCreate(const char *filename,
124  FileCreationAttr &attr) throw (DCException);
125 
126  void openRead(const char *filename,
127  FileCreationAttr &attr) throw (DCException);
128 
129  void openWrite(const char *filename,
130  FileCreationAttr &attr) throw (DCException);
131 
132  void openMerge(const char *filename) throw (DCException);
133 
145  void readMerged(int32_t id,
146  const CollectionType& type,
147  const char* name,
148  Dimensions dstBuffer,
149  Dimensions dstOffset,
150  Dimensions& srcBuffer,
151  void* data) throw (DCException);
152 
156  size_t getNDims(H5Handle h5File,
157  int32_t id,
158  const char* name);
159 
163  void readCompleteDataSet(H5Handle h5File,
164  int32_t id,
165  const char* name,
166  const Dimensions dstBuffer,
167  const Dimensions dstOffset,
168  const Dimensions srcOffset,
169  Dimensions &sizeRead,
170  uint32_t& srcDims,
171  void* dst)
172  throw (DCException);
173 
177  void readDataSet(H5Handle h5File,
178  int32_t id,
179  const char* name,
180  const Dimensions dstBuffer,
181  const Dimensions dstOffset,
182  const Dimensions srcSize,
183  const Dimensions srcOffset,
184  Dimensions& sizeRead,
185  uint32_t& srcDims,
186  void* dst) throw (DCException);
187 
191  CollectionType* readDataSetMeta(H5Handle h5File,
192  int32_t id,
193  const char* name,
194  const Dimensions dstBuffer,
195  const Dimensions dstOffset,
196  const Dimensions srcOffset,
197  Dimensions &sizeRead,
198  uint32_t& srcDims) throw (DCException);
199 
200  void readSizeInternal(H5Handle h5File,
201  int32_t id,
202  const char* name,
203  Dimensions &sizeRead) throw (DCException);
204 
208  void writeDataSet(
209  hid_t group,
210  const CollectionType& datatype,
211  uint32_t ndims,
212  const Selection select,
213  const char* name,
214  const void* data) throw (DCException);
215 
221  void appendDataSet(
222  hid_t group,
223  const CollectionType& datatype,
224  size_t count,
225  size_t offset,
226  size_t stride,
227  const char *name,
228  const void *data) throw (DCException);
229 
230  hid_t openDatasetHandle(int32_t id,
231  const char *dsetName,
232  Dimensions *mpiPosition = NULL) throw (DCException);
233 
234  void closeDatasetHandle(hid_t handle) throw (DCException);
235  public:
236 
241  SerialDataCollector(uint32_t maxFileHandles);
242 
246  virtual ~SerialDataCollector();
247 
248  void open(const char *filename,
249  FileCreationAttr& attr) throw (DCException);
250 
251  void close();
252 
253  int32_t getMaxID();
254 
255  void getMPISize(Dimensions& mpiSize);
256 
257  void getEntryIDs(int32_t *ids, size_t *count) throw (DCException);
258 
259  void getEntriesForID(int32_t id, DCEntry *entries, size_t *count) throw (DCException);
260 
261  void write(int32_t id,
262  const CollectionType& type,
263  uint32_t ndims,
264  const Selection select,
265  const char* name,
266  const void* data) throw (DCException);
267 
268  void append(int32_t id,
269  const CollectionType& type,
270  size_t count,
271  const char *name,
272  const void *data) throw (DCException);
273 
274  void append(int32_t id,
275  const CollectionType& type,
276  size_t count,
277  size_t offset,
278  size_t striding,
279  const char *name,
280  const void *data) throw (DCException);
281 
282  void remove(int32_t id) throw (DCException);
283 
284  void remove(int32_t id,
285  const char *name) throw (DCException);
286 
287  void createReference(int32_t srcID,
288  const char *srcName,
289  int32_t dstID,
290  const char *dstName) throw (DCException);
291 
292  void createReference(int32_t srcID,
293  const char *srcName,
294  int32_t dstID,
295  const char *dstName,
296  Dimensions count,
297  Dimensions offset,
298  Dimensions stride) throw (DCException);
299 
301  int32_t id,
302  const char *name,
303  Dimensions *mpiPosition = NULL) throw (DCException);
304 
305  SPLASH_DEPRECATED("Use safer readGlobalAttributeInfo")
306  void readGlobalAttribute(
307  const char *name,
308  void* data,
309  Dimensions *mpiPosition = NULL) throw (DCException);
310 
311  void writeGlobalAttribute(const CollectionType& type,
312  const char *name,
313  const void* data) throw (DCException);
314 
315  void writeGlobalAttribute(const CollectionType& type,
316  const char *name,
317  uint32_t ndims,
318  const Dimensions dims,
319  const void* data) throw (DCException);
320 
321  AttributeInfo readAttributeInfo(int32_t id,
322  const char *dataName,
323  const char *attrName,
324  Dimensions *mpiPosition = NULL) throw (DCException);
325 
326  SPLASH_DEPRECATED("Use safer readAttributeInfo")
327  void readAttribute(int32_t id,
328  const char *dataName,
329  const char *attrName,
330  void *data,
331  Dimensions *mpiPosition = NULL) throw (DCException);
332 
333  void writeAttribute(int32_t id,
334  const CollectionType& type,
335  const char *dataName,
336  const char *attrName,
337  const void *data) throw (DCException);
338 
339  void writeAttribute(int32_t id,
340  const CollectionType& type,
341  const char *dataName,
342  const char *attrName,
343  uint32_t ndims,
344  const Dimensions dims,
345  const void *data) throw (DCException);
346 
347  void read(int32_t id,
348  const char* name,
349  Dimensions &sizeRead,
350  void* data) throw (DCException);
351 
352  void read(int32_t id,
353  const char* name,
354  const Dimensions dstBuffer,
355  const Dimensions dstOffset,
356  Dimensions &sizeRead,
357  void* data) throw (DCException);
358 
359  CollectionType* readMeta(int32_t id,
360  const char* name,
361  const Dimensions dstBuffer,
362  const Dimensions dstOffset,
363  Dimensions &sizeRead) throw (DCException);
364  };
365 
366 } // namespace DataCollector
367 
368 #endif /* SERIALDATACOLLECTOR_H */
CollectionType * readMeta(int32_t id, const char *name, const Dimensions dstBuffer, const Dimensions dstOffset, Dimensions &sizeRead)
void getEntriesForID(int32_t id, DCEntry *entries, size_t *count)
void append(int32_t id, const CollectionType &type, size_t count, const char *name, const void *data)
void getEntryIDs(int32_t *ids, size_t *count)
void open(const char *filename, FileCreationAttr &attr)
void writeGlobalAttribute(const CollectionType &type, const char *name, const void *data)
void getMPISize(Dimensions &mpiSize)
void readAttribute(int32_t id, const char *dataName, const char *attrName, void *data, Dimensions *mpiPosition=NULL)
void write(int32_t id, const CollectionType &type, uint32_t ndims, const Selection select, const char *name, const void *data)
void readGlobalAttribute(const char *name, void *data, Dimensions *mpiPosition=NULL)
void writeAttribute(int32_t id, const CollectionType &type, const char *dataName, const char *attrName, const void *data)
SerialDataCollector(uint32_t maxFileHandles)
void read(int32_t id, const char *name, Dimensions &sizeRead, void *data)
void createReference(int32_t srcID, const char *srcName, int32_t dstID, const char *dstName)
AttributeInfo readGlobalAttributeInfo(int32_t id, const char *name, Dimensions *mpiPosition=NULL)
AttributeInfo readAttributeInfo(int32_t id, const char *dataName, const char *attrName, Dimensions *mpiPosition=NULL)