libROM  v1.0
Data-driven physical simulation library
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CAROM::HDFDatabase Class Reference

#include <HDFDatabase.h>

Inheritance diagram for CAROM::HDFDatabase:
CAROM::Database CAROM::HDFDatabaseMPIO

Public Member Functions

 HDFDatabase ()
 Default constructor.
 
virtual ~HDFDatabase ()
 Destructor.
 
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. More...
 
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. More...
 
virtual bool close ()
 Closes the currently open HDF5 database file. More...
 
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. More...
 
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. More...
 
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. More...
 
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 file. More...
 
virtual int getDoubleArraySize (const std::string &key)
 Count the number of elements in an array of doubles associated with the supplied key from the currently open HDF5 database file. More...
 
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. More...
 
virtual void getDoubleArray (const std::string &key, double *data, int nelements, const std::vector< int > &idx, const bool distributed=false)
 Reads a sub-array of doubles associated with the supplied key from the currently open HDF5 database file. More...
 
virtual void getDoubleArray (const std::string &key, double *data, int nelements, int offset, int block_size, int stride, const bool distributed=false)
 Reads an array of doubles associated with the supplied key from the currently open HDF5 database file. More...
 
- Public Member Functions inherited from CAROM::Database
 Database ()
 Default constructor.
 
virtual ~Database ()
 Destructor.
 
void putInteger (const std::string &key, int data)
 Writes an integer associated with the supplied key to currently open database file. More...
 
void putDouble (const std::string &key, double data)
 Writes a double associated with the supplied key to currently open database file. More...
 
void getInteger (const std::string &key, int &data)
 Reads an integer associated with the supplied key from the currently open database file. More...
 
void getDouble (const std::string &key, double &data)
 Reads a double associated with the supplied key from the currently open database file. More...
 

Protected Member Functions

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 string is empty then false is returned. More...
 
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 string is empty then false is returned. More...
 
virtual void writeAttribute (int type_key, hid_t dataset_id)
 Write an attribute to the specified dataset. More...
 
int readAttribute (hid_t dataset_id)
 Read an attribute from the specified dataset. More...
 

Protected Attributes

bool d_is_file
 True if the HDF5 database is mounted to a file.
 
hid_t d_file_id
 ID of file attached to database or -1 if not mounted to a file.
 
hid_t d_group_id
 ID of the group attached to the database.
 
int d_rank
 MPI process rank.
 

Static Protected Attributes

static const int KEY_DOUBLE_ARRAY = 0
 The key representing a double array.
 
static const int KEY_INT_ARRAY = 1
 The key representing an integer array.
 

Additional Inherited Members

- Public Types inherited from CAROM::Database
enum class  formats { HDF5 , CSV , HDF5_MPIO }
 Implemented database file formats. Add to this enum each time a new database format is implemented.
 

Detailed Description

HDFDatabase implements the interface of Database for HDF5 database files.

Definition at line 26 of file HDFDatabase.h.

Member Function Documentation

◆ close()

bool CAROM::HDFDatabase::close ( )
virtual

Closes the currently open HDF5 database file.

Returns
True if the file close was successful.

Implements CAROM::Database.

Definition at line 118 of file HDFDatabase.cpp.

◆ create()

bool CAROM::HDFDatabase::create ( const std::string &  file_name,
const MPI_Comm  comm = MPI_COMM_NULL 
)
overridevirtual

Creates a new HDF5 database file with the supplied name.

Parameters
[in]file_nameName of HDF5 database file to create.
[in]commMPI communicator for distributed data I/O. If not MPI_COMM_NULL, each process creates a file whose name is file_name extended with process rank in 6 digits.
Returns
True if file create was successful.

Reimplemented from CAROM::Database.

Definition at line 45 of file HDFDatabase.cpp.

◆ getDoubleArray() [1/3]

void CAROM::HDFDatabase::getDoubleArray ( const std::string &  key,
double *  data,
int  nelements,
const bool  distributed = false 
)
virtual

Reads an array of doubles associated with the supplied key from the currently open HDF5 database file.

Precondition
!key.empty()
data != nullptr || nelements == 0
Parameters
[in]keyThe key associated with the array of values to be read.
[out]dataThe allocated array of double values to be read.
[in]nelementsThe number of doubles in the array.
[in]distributedTrue if data is a distributed double array. HDFDatabase reads the array in file-per-process, where each file is read serially by one process.

Implements CAROM::Database.

Definition at line 323 of file HDFDatabase.cpp.

◆ getDoubleArray() [2/3]

void CAROM::HDFDatabase::getDoubleArray ( const std::string &  key,
double *  data,
int  nelements,
const std::vector< int > &  idx,
const bool  distributed = false 
)
virtual

Reads a sub-array of doubles associated with the supplied key from the currently open HDF5 database file.

Precondition
!key.empty()
data != nullptr || nelements == 0
Parameters
[in]keyThe key associated with the array of values to be read.
[out]dataThe allocated sub-array of double values to be read.
[in]nelementsThe number of doubles in the full array.
[in]idxThe set of indices in the sub-array.
[in]distributedTrue if data is a distributed double array. HDFDatabase reads the array in file-per-process, where each file is read serially by one process.

Implements CAROM::Database.

Definition at line 366 of file HDFDatabase.cpp.

◆ getDoubleArray() [3/3]

void CAROM::HDFDatabase::getDoubleArray ( const std::string &  key,
double *  data,
int  nelements,
int  offset,
int  block_size,
int  stride,
const bool  distributed = false 
)
virtual

Reads an array of doubles associated with the supplied key from the currently open HDF5 database file.

Precondition
!key.empty()
data != nullptr || nelements == 0
Parameters
[in]keyThe key associated with the array of values to be read.
[out]dataThe allocated array of double values to be read.
[in]nelementsThe number of doubles in the array.
[in]offsetThe initial offset in the array. Typically, this is a column index of the matrix data.
[in]block_sizeThe block size to read from the HDF5 dataset. Typically, this is a number of columns of the matrix data.
[in]strideThe stride to read from the HDF5 dataset. Typically, this is the total number of columns of the matrix data.
[in]distributedTrue if data is a distributed double array. HDFDatabase reads the array in file-per-process, where each file is read serially by one process.

Implements CAROM::Database.

Definition at line 398 of file HDFDatabase.cpp.

◆ getDoubleArraySize()

int CAROM::HDFDatabase::getDoubleArraySize ( const std::string &  key)
virtual

Count the number of elements in an array of doubles associated with the supplied key from the currently open HDF5 database file.

Precondition
!key.empty()
Parameters
[in]keyThe key associated with the array of values to be read.

Implements CAROM::Database.

Definition at line 294 of file HDFDatabase.cpp.

◆ getIntegerArray()

void CAROM::HDFDatabase::getIntegerArray ( const std::string &  key,
int *  data,
int  nelements,
const bool  distributed = false 
)
virtual

Reads an array of integers associated with the supplied key from the currently open HDF5 database file.

Precondition
!key.empty()
data != nullptr || nelements == 0
Parameters
[in]keyThe key associated with the array of values to be read.
[out]dataThe allocated array of integer values to be read.
[in]nelementsThe number of integers in the array.
[in]distributedTrue if data is a distributed integer array. HDFDatabase reads the array in file-per-process, where each file is read serially by one process.

Implements CAROM::Database.

Definition at line 252 of file HDFDatabase.cpp.

◆ isDouble()

bool CAROM::HDFDatabase::isDouble ( const std::string &  key)
protected

Returns true if the specified key represents a double entry. If the key does not exist or if the string is empty then false is returned.

Parameters
[in]keyThe key associated with the data we are interested in.
Returns
True if the data associated with key is a double array.

Definition at line 481 of file HDFDatabase.cpp.

◆ isInteger()

bool CAROM::HDFDatabase::isInteger ( const std::string &  key)
protected

Returns true if the specified key represents an integer entry. If the key does not exist or if the string is empty then false is returned.

Parameters
[in]keyThe key associated with the data we are interested in.
Returns
True if the data associated with key is an integer array.

Definition at line 453 of file HDFDatabase.cpp.

◆ open()

bool CAROM::HDFDatabase::open ( const std::string &  file_name,
const std::string &  type,
const MPI_Comm  comm = MPI_COMM_NULL 
)
overridevirtual

Opens an existing HDF5 database file with the supplied name.

Parameters
[in]file_nameName of existing HDF5 database file to open.
[in]typeRead/write type ("r"/"wr") If not MPI_COMM_NULL, each process opens a file whose name is file_name extended with process rank in 6 digits.
Returns
True if file open was successful.

Reimplemented from CAROM::Database.

Definition at line 76 of file HDFDatabase.cpp.

◆ putDoubleArray()

void CAROM::HDFDatabase::putDoubleArray ( const std::string &  key,
const double *const  data,
int  nelements,
const bool  distributed = false 
)
virtual

Writes an array of doubles associated with the supplied key to the currently open HDF5 database file.

Precondition
!key.empty()
data != nullptr
nelements > 0
Parameters
[in]keyThe key associated with the array of values to be written.
[in]dataThe array of double values to be written.
[in]nelementsThe number of doubles in the array.
[in]distributedTrue if data is a distributed double array. HDFDatabase writes the array in file-per-process, where each file is written serially by one process.

Implements CAROM::Database.

Definition at line 189 of file HDFDatabase.cpp.

◆ putDoubleVector()

void CAROM::HDFDatabase::putDoubleVector ( const std::string &  key,
const std::vector< double > &  data,
int  nelements,
const bool  distributed = false 
)
virtual

Writes a vector of doubles associated with the supplied key to the currently open HDF5 database file.

Precondition
!key.empty()
data != nullptr
nelements > 0
Parameters
[in]keyThe key associated with the vector of values to be written.
[in]dataThe vector of double values to be written.
[in]nelementsThe number of doubles in the vector.
[in]distributedTrue if data is a distributed double array. HDFDatabase writes the array in file-per-process, where each file is written serially by one process.

Implements CAROM::Database.

Definition at line 242 of file HDFDatabase.cpp.

◆ putIntegerArray()

void CAROM::HDFDatabase::putIntegerArray ( const std::string &  key,
const int *const  data,
int  nelements,
const bool  distributed = false 
)
virtual

Writes an array of integers associated with the supplied key to the currently open HDF5 database file.

Precondition
!key.empty()
data != nullptr
nelements > 0
Parameters
[in]keyThe key associated with the array of values to be written.
[in]dataThe array of integer values to be written.
[in]nelementsThe number of integers in the array.
[in]distributedTrue if data is a distributed integer array. HDFDatabase writes the array in file-per-process, where each file is written serially by one process.

Implements CAROM::Database.

Definition at line 136 of file HDFDatabase.cpp.

◆ readAttribute()

int CAROM::HDFDatabase::readAttribute ( hid_t  dataset_id)
protected

Read an attribute from the specified dataset.

Parameters
[in]dataset_idID of the dataset key will be written to.
Returns
The attribute.

Definition at line 546 of file HDFDatabase.cpp.

◆ writeAttribute()

void CAROM::HDFDatabase::writeAttribute ( int  type_key,
hid_t  dataset_id 
)
protectedvirtual

Write an attribute to the specified dataset.

Parameters
[in]type_keyThe attribute to be written.
[in]dataset_idID of the dataset key will be written to.

Definition at line 509 of file HDFDatabase.cpp.


The documentation for this class was generated from the following files: