libROM  v1.0
Data-driven physical simulation library
HDFDatabase.h
1 
11 // Description: The concrete database implementation using HDF5.
12 
13 #ifndef included_HDFDatabase_h
14 #define included_HDFDatabase_h
15 
16 #include "Database.h"
17 #include "Utilities.h"
18 #include "hdf5.h"
19 #include <string>
20 
21 namespace CAROM {
22 
26 class HDFDatabase : public Database
27 {
28 public:
32  HDFDatabase();
33 
37  virtual
38  ~HDFDatabase();
39 
50  virtual
51  bool
52  create(
53  const std::string& file_name,
54  const MPI_Comm comm=MPI_COMM_NULL) override;
55 
66  virtual
67  bool
68  open(
69  const std::string& file_name,
70  const std::string& type,
71  const MPI_Comm comm=MPI_COMM_NULL) override;
72 
78  virtual
79  bool
80  close();
81 
98  virtual
99  void
101  const std::string& key,
102  const int* const data,
103  int nelements,
104  const bool distributed=false);
105 
122  virtual
123  void
125  const std::string& key,
126  const double* const data,
127  int nelements,
128  const bool distributed=false);
129 
146  virtual
147  void
149  const std::string& key,
150  const std::vector<double>& data,
151  int nelements,
152  const bool distributed=false);
153 
169  virtual
170  void
172  const std::string& key,
173  int* data,
174  int nelements,
175  const bool distributed=false);
176 
185  virtual
186  int
187  getDoubleArraySize(const std::string& key);
188 
204  virtual
205  void
207  const std::string& key,
208  double* data,
209  int nelements,
210  const bool distributed=false);
211 
228  virtual
229  void
231  const std::string& key,
232  double* data,
233  int nelements,
234  const std::vector<int>& idx,
235  const bool distributed=false);
236 
258  virtual
259  void
261  const std::string& key,
262  double* data,
263  int nelements,
264  int offset,
265  int block_size,
266  int stride,
267  const bool distributed=false);
268 
269 protected:
270 
280  bool
281  isInteger(
282  const std::string& key);
283 
293  bool
294  isDouble(
295  const std::string& key);
296 
303  virtual
304  void
306  int type_key,
307  hid_t dataset_id);
308 
316  int
318  hid_t dataset_id);
319 
323  bool d_is_file;
324 
328  hid_t d_file_id;
329 
333  hid_t d_group_id;
334 
338  static const int KEY_DOUBLE_ARRAY;
339 
343  static const int KEY_INT_ARRAY;
344 
348  int d_rank;
349 
350 private:
354  HDFDatabase(
355  const HDFDatabase& other);
356 
360  HDFDatabase&
361  operator = (
362  const HDFDatabase& rhs);
363 };
364 
365 }
366 
367 #endif
bool d_is_file
True if the HDF5 database is mounted to a file.
Definition: HDFDatabase.h:323
static const int KEY_DOUBLE_ARRAY
The key representing a double array.
Definition: HDFDatabase.h:338
virtual ~HDFDatabase()
Destructor.
Definition: HDFDatabase.cpp:29
bool isInteger(const std::string &key)
Returns true if the specified key represents an integer entry. If the key does not exist or if the st...
bool isDouble(const std::string &key)
Returns true if the specified key represents a double entry. If the key does not exist or if the stri...
int d_rank
MPI process rank.
Definition: HDFDatabase.h:348
virtual void getIntegerArray(const std::string &key, int *data, int nelements, const bool distributed=false)
Reads an array of integers associated with the supplied key from the currently open HDF5 database fil...
virtual bool create(const std::string &file_name, const MPI_Comm comm=MPI_COMM_NULL) override
Creates a new HDF5 database file with the supplied name.
Definition: HDFDatabase.cpp:45
int readAttribute(hid_t dataset_id)
Read an attribute from the specified dataset.
virtual bool open(const std::string &file_name, const std::string &type, const MPI_Comm comm=MPI_COMM_NULL) override
Opens an existing HDF5 database file with the supplied name.
Definition: HDFDatabase.cpp:76
virtual void getDoubleArray(const std::string &key, double *data, int nelements, const bool distributed=false)
Reads an array of doubles associated with the supplied key from the currently open HDF5 database file...
hid_t d_group_id
ID of the group attached to the database.
Definition: HDFDatabase.h:333
HDFDatabase()
Default constructor.
Definition: HDFDatabase.cpp:22
static const int KEY_INT_ARRAY
The key representing an integer array.
Definition: HDFDatabase.h:343
virtual int getDoubleArraySize(const std::string &key)
Count the number of elements in an array of doubles associated with the supplied key from the current...
virtual void putDoubleArray(const std::string &key, const double *const data, int nelements, const bool distributed=false)
Writes an array of doubles associated with the supplied key to the currently open HDF5 database file.
virtual void putIntegerArray(const std::string &key, const int *const data, int nelements, const bool distributed=false)
Writes an array of integers associated with the supplied key to the currently open HDF5 database file...
virtual void writeAttribute(int type_key, hid_t dataset_id)
Write an attribute to the specified dataset.
virtual bool close()
Closes the currently open HDF5 database file.
hid_t d_file_id
ID of file attached to database or -1 if not mounted to a file.
Definition: HDFDatabase.h:328
virtual void putDoubleVector(const std::string &key, const std::vector< double > &data, int nelements, const bool distributed=false)
Writes a vector of doubles associated with the supplied key to the currently open HDF5 database file.