libROM  v1.0
Data-driven physical simulation library
Database.h
1 
11 // Description: The abstract database class defines interface for databases.
12 
13 #ifndef included_Database_h
14 #define included_Database_h
15 
16 #include "Utilities.h"
17 #include <string>
18 #include <vector>
19 #include "mpi.h"
20 
21 namespace CAROM {
22 
23 bool fileExists(const std::string& name);
24 
30 class Database
31 {
32 public:
36  Database();
37 
41  virtual
42  ~Database();
43 
54  virtual
55  bool
56  create(
57  const std::string& file_name,
58  const MPI_Comm comm=MPI_COMM_NULL);
59 
71  virtual
72  bool
73  open(
74  const std::string& file_name,
75  const std::string& type,
76  const MPI_Comm comm=MPI_COMM_NULL);
77 
83  virtual
84  bool
85  close() = 0;
86 
94  void
96  const std::string& key,
97  int data)
98  {
99  putIntegerArray(key, &data, 1);
100  }
101 
113  virtual
114  void
116  const std::string& key,
117  const int* const data,
118  int nelements,
119  const bool distributed=false) = 0;
120 
128  void
130  const std::string& key,
131  double data)
132  {
133  putDoubleArray(key, &data, 1);
134  }
135 
147  virtual
148  void
150  const std::string& key,
151  const double* const data,
152  int nelements,
153  const bool distributed=false) = 0;
154 
166  virtual
167  void
169  const std::string& key,
170  const std::vector<double>& data,
171  int nelements,
172  const bool distributed=false) = 0;
173 
181  void
183  const std::string& key,
184  int& data)
185  {
186  getIntegerArray(key, &data, 1);
187  }
188 
200  virtual
201  void
203  const std::string& key,
204  int* data,
205  int nelements,
206  const bool distributed=false) = 0;
207 
215  void
217  const std::string& key,
218  double& data)
219  {
220  getDoubleArray(key, &data, 1);
221  }
222 
233  virtual
234  int
235  getDoubleArraySize(const std::string& key) = 0;
236 
248  virtual
249  void
251  const std::string& key,
252  double* data,
253  int nelements,
254  const bool distributed=false) = 0;
255 
271  virtual
272  void
274  const std::string& key,
275  double* data,
276  int nelements,
277  const std::vector<int>& idx,
278  const bool distributed=false) = 0;
279 
297  virtual
298  void
300  const std::string& key,
301  double* data,
302  int nelements,
303  int offset,
304  int block_size,
305  int stride,
306  const bool distributed=false) = 0;
307 
312  enum class formats {
313  HDF5,
314  CSV,
315  HDF5_MPIO
316  };
317 
318 private:
322  Database(
323  const Database& other);
324 
328  Database&
329  operator = (
330  const Database& rhs);
331 };
332 
333 }
334 
335 #endif
virtual int getDoubleArraySize(const std::string &key)=0
Count the number of elements in an array of doubles associated with the supplied key from the current...
virtual bool create(const std::string &file_name, const MPI_Comm comm=MPI_COMM_NULL)
Creates a new database file with the supplied name.
Definition: Database.cpp:35
virtual void getIntegerArray(const std::string &key, int *data, int nelements, const bool distributed=false)=0
Reads an array of integers associated with the supplied key from the currently open database file.
Database()
Default constructor.
Definition: Database.cpp:26
void getInteger(const std::string &key, int &data)
Reads an integer associated with the supplied key from the currently open database file.
Definition: Database.h:182
virtual ~Database()
Destructor.
Definition: Database.cpp:30
virtual bool close()=0
Closes the currently open database file.
virtual void putDoubleVector(const std::string &key, const std::vector< double > &data, int nelements, const bool distributed=false)=0
Writes a vector of doubles associated with the supplied key to the currently open database file.
formats
Implemented database file formats. Add to this enum each time a new database format is implemented.
Definition: Database.h:312
virtual void getDoubleArray(const std::string &key, double *data, int nelements, const std::vector< int > &idx, const bool distributed=false)=0
Reads a sub-array of doubles associated with the supplied key from the currently open database file.
virtual void getDoubleArray(const std::string &key, double *data, int nelements, const bool distributed=false)=0
Reads an array of doubles associated with the supplied key from the currently open database file.
void putDouble(const std::string &key, double data)
Writes a double associated with the supplied key to currently open database file.
Definition: Database.h:129
void putInteger(const std::string &key, int data)
Writes an integer associated with the supplied key to currently open database file.
Definition: Database.h:95
virtual void getDoubleArray(const std::string &key, double *data, int nelements, int offset, int block_size, int stride, const bool distributed=false)=0
Reads an array of doubles associated with the supplied key from the currently open database file.
virtual void putIntegerArray(const std::string &key, const int *const data, int nelements, const bool distributed=false)=0
Writes an array of integers associated with the supplied key to the currently open database file.
void getDouble(const std::string &key, double &data)
Reads a double associated with the supplied key from the currently open database file.
Definition: Database.h:216
virtual void putDoubleArray(const std::string &key, const double *const data, int nelements, const bool distributed=false)=0
Writes an array of doubles associated with the supplied key to the currently open database file.
virtual bool open(const std::string &file_name, const std::string &type, const MPI_Comm comm=MPI_COMM_NULL)
Opens an existing database file with the supplied name.
Definition: Database.cpp:44