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 
29 class Database
30 {
31 public:
35  Database();
36 
40  virtual
41  ~Database();
42 
53  virtual
54  bool
55  create(
56  const std::string& file_name,
57  const MPI_Comm comm=MPI_COMM_NULL);
58 
70  virtual
71  bool
72  open(
73  const std::string& file_name,
74  const std::string& type,
75  const MPI_Comm comm=MPI_COMM_NULL);
76 
82  virtual
83  bool
84  close() = 0;
85 
93  void
95  const std::string& key,
96  int data)
97  {
98  putIntegerArray(key, &data, 1);
99  }
100 
112  virtual
113  void
115  const std::string& key,
116  const int* const data,
117  int nelements,
118  const bool distributed=false) = 0;
119 
127  void
129  const std::string& key,
130  double data)
131  {
132  putDoubleArray(key, &data, 1);
133  }
134 
146  virtual
147  void
149  const std::string& key,
150  const double* const data,
151  int nelements,
152  const bool distributed=false) = 0;
153 
165  virtual
166  void
168  const std::string& key,
169  const std::vector<double>& data,
170  int nelements,
171  const bool distributed=false) = 0;
172 
180  void
182  const std::string& key,
183  int& data)
184  {
185  getIntegerArray(key, &data, 1);
186  }
187 
199  virtual
200  void
202  const std::string& key,
203  int* data,
204  int nelements,
205  const bool distributed=false) = 0;
206 
214  void
216  const std::string& key,
217  double& data)
218  {
219  getDoubleArray(key, &data, 1);
220  }
221 
232  virtual
233  int
234  getDoubleArraySize(const std::string& key) = 0;
235 
247  virtual
248  void
250  const std::string& key,
251  double* data,
252  int nelements,
253  const bool distributed=false) = 0;
254 
270  virtual
271  void
273  const std::string& key,
274  double* data,
275  int nelements,
276  const std::vector<int>& idx,
277  const bool distributed=false) = 0;
278 
296  virtual
297  void
299  const std::string& key,
300  double* data,
301  int nelements,
302  int offset,
303  int block_size,
304  int stride,
305  const bool distributed=false) = 0;
306 
311  enum class formats {
312  HDF5,
313  CSV,
314  HDF5_MPIO
315  };
316 
317 private:
321  Database(
322  const Database& other);
323 
327  Database&
328  operator = (
329  const Database& rhs);
330 };
331 
332 }
333 
334 #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:29
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:20
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:181
virtual ~Database()
Destructor.
Definition: Database.cpp:24
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:311
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:128
void putInteger(const std::string &key, int data)
Writes an integer associated with the supplied key to currently open database file.
Definition: Database.h:94
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:215
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:38