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

#include <CSVDatabase.h>

Inheritance diagram for CAROM::CSVDatabase:
CAROM::Database

Public Member Functions

 CSVDatabase ()
 Default constructor.
 
virtual ~CSVDatabase ()
 Destructor.
 
bool create (const std::string &file_name, const MPI_Comm comm=MPI_COMM_NULL) override
 Creates a new CSV database file with the supplied name. NOTE: CSVDatabase does not actually create a file with this. This function will only print out the file_name. More...
 
bool open (const std::string &file_name, const std::string &type, const MPI_Comm comm=MPI_COMM_NULL) override
 Opens an existing CSV database file with the supplied name. NOTE: CSVDatabase does not actually open a file with this. This function will only print out the file_name. More...
 
bool close ()
 Closes the currently open CSV database file. More...
 
void putIntegerArray (const std::string &file_name, const int *const data, int nelements, const bool distributed=false) override
 Writes an array of integers associated with the supplied filename. More...
 
void putDoubleArray (const std::string &file_name, const double *const data, int nelements, const bool distributed=false) override
 Writes an array of doubles associated with the supplied filename. More...
 
void putDoubleVector (const std::string &file_name, const std::vector< double > &data, int nelements, const bool distributed=false) override
 Writes a vector of doubles associated with the supplied filename to the currently open CSV database file. More...
 
void putComplexVector (const std::string &file_name, const std::vector< std::complex< double >> &data, int nelements)
 Writes a vector of complex doubles associated with the supplied filename. More...
 
void putStringVector (const std::string &file_name, const std::vector< std::string > &data, int nelements)
 Writes a vector of strings associated with the supplied filename. More...
 
void getIntegerArray (const std::string &file_name, int *data, int nelements, const bool distributed=false) override
 Reads an array of integers associated with the supplied filename. More...
 
void getIntegerVector (const std::string &file_name, std::vector< int > &data, bool append=false)
 Reads a vector of integers associated with the supplied filename. More...
 
int getDoubleArraySize (const std::string &file_name) override
 Count the number of elements in an array of doubles associated with the supplied filename. More...
 
void getDoubleArray (const std::string &file_name, double *data, int nelements, const bool distributed=false) override
 Reads an array of doubles associated with the supplied filename. More...
 
void getDoubleArray (const std::string &file_name, double *data, int nelements, const std::vector< int > &idx, const bool distributed=false) override
 Reads a sub-array of doubles associated with the supplied filename. More...
 
void getDoubleArray (const std::string &file_name, double *data, int nelements, int offset, int block_size, int stride, const bool distributed=false) override
 Reads an array of doubles associated with the supplied filename. More...
 
void getDoubleVector (const std::string &file_name, std::vector< double > &data, bool append=false)
 Reads a vector of doubles associated with the supplied filename. More...
 
void getStringVector (const std::string &file_name, std::vector< std::string > &data, bool append=false)
 Reads a vector of strings associated with the supplied filename. More...
 
int getLineCount (const std::string &file_name)
 Count the number of lines of CSV 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...
 

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

CSVDatabase implements the interface of Database for CSV database files.

Definition at line 26 of file CSVDatabase.h.

Member Function Documentation

◆ close()

bool CAROM::CSVDatabase::close ( )
virtual

Closes the currently open CSV database file.

Returns
True if the file close was successful.

Implements CAROM::Database.

Definition at line 49 of file CSVDatabase.cpp.

◆ create()

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

Creates a new CSV database file with the supplied name. NOTE: CSVDatabase does not actually create a file with this. This function will only print out the file_name.

Parameters
[in]file_nameName of CSV database file to create.
[in]commMPI communicator for distributed data I/O. CSVDatabase I/O is always performed serially, regardless.
Returns
True if file create was successful.

Reimplemented from CAROM::Database.

Definition at line 30 of file CSVDatabase.cpp.

◆ getDoubleArray() [1/3]

void CAROM::CSVDatabase::getDoubleArray ( const std::string &  file_name,
double *  data,
int  nelements,
const bool  distributed = false 
)
overridevirtual

Reads an array of doubles associated with the supplied filename.

Precondition
!file_name.empty()
data != nullptr || nelements == 0
Parameters
[in]file_nameThe filename 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. CSVDatabase reads the array serially whether or not distributed.

Implements CAROM::Database.

Definition at line 194 of file CSVDatabase.cpp.

◆ getDoubleArray() [2/3]

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

Reads a sub-array of doubles associated with the supplied filename.

Precondition
!file_name.empty()
data != nullptr || nelements == 0
Parameters
[in]file_nameThe filename 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 integer array. CSVDatabase reads the array serially whether or not distributed.

Implements CAROM::Database.

Definition at line 217 of file CSVDatabase.cpp.

◆ getDoubleArray() [3/3]

void CAROM::CSVDatabase::getDoubleArray ( const std::string &  file_name,
double *  data,
int  nelements,
int  offset,
int  block_size,
int  stride,
const bool  distributed = false 
)
overridevirtual

Reads an array of doubles associated with the supplied filename.

Precondition
!file_name.empty()
data != nullptr || nelements == 0
Parameters
[in]file_nameThe filename 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.
[in]block_sizeThe block size to read from the CSV dataset.
[in]strideThe stride to read from the CSV dataset.
[in]distributedTrue if data is a distributed integer array. CSVDatabase reads the array serially whether or not distributed.

Implements CAROM::Database.

Definition at line 257 of file CSVDatabase.cpp.

◆ getDoubleArraySize()

int CAROM::CSVDatabase::getDoubleArraySize ( const std::string &  file_name)
inlineoverridevirtual

Count the number of elements in an array of doubles associated with the supplied filename.

Precondition
!file_name.empty()
Parameters
[in]file_nameThe filename associated with the array of values to be read.

Implements CAROM::Database.

Definition at line 228 of file CSVDatabase.h.

◆ getDoubleVector()

void CAROM::CSVDatabase::getDoubleVector ( const std::string &  file_name,
std::vector< double > &  data,
bool  append = false 
)

Reads a vector of doubles associated with the supplied filename.

Precondition
!file_name.empty()
Parameters
[in]file_nameThe filename associated with the vector of values to be read.
[out]dataThe allocated vector of double values to be read.
[in]appendIf true, append to the vector, otherwise overwrite.

Definition at line 301 of file CSVDatabase.cpp.

◆ getIntegerArray()

void CAROM::CSVDatabase::getIntegerArray ( const std::string &  file_name,
int *  data,
int  nelements,
const bool  distributed = false 
)
overridevirtual

Reads an array of integers associated with the supplied filename.

Precondition
!file_name.empty()
data != nullptr || nelements == 0
Parameters
[in]file_nameThe filename 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. CSVDatabase reads the array serially whether or not distributed.

Implements CAROM::Database.

Definition at line 151 of file CSVDatabase.cpp.

◆ getIntegerVector()

void CAROM::CSVDatabase::getIntegerVector ( const std::string &  file_name,
std::vector< int > &  data,
bool  append = false 
)

Reads a vector of integers associated with the supplied filename.

Precondition
!file_name.empty()
Parameters
[in]file_nameThe filename associated with the vector of values to be read.
[out]dataThe allocated vector of integer values to be read.
[in]appendIf true, append to the vector, otherwise overwrite.

Definition at line 176 of file CSVDatabase.cpp.

◆ getLineCount()

int CAROM::CSVDatabase::getLineCount ( const std::string &  file_name)

Count the number of lines of CSV database file.

Precondition
!file_name.empty()
Parameters
[in]file_nameThe filename associated with the vector of strings to be read.

Definition at line 337 of file CSVDatabase.cpp.

◆ getStringVector()

void CAROM::CSVDatabase::getStringVector ( const std::string &  file_name,
std::vector< std::string > &  data,
bool  append = false 
)

Reads a vector of strings associated with the supplied filename.

Precondition
!file_name.empty()
Parameters
[in]file_nameThe filename associated with the vector of strings to be read.
[out]dataThe allocated vector of strings to be read.
[in]appendIf true, append to the vector, otherwise overwrite.

Definition at line 319 of file CSVDatabase.cpp.

◆ open()

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

Opens an existing CSV database file with the supplied name. NOTE: CSVDatabase does not actually open a file with this. This function will only print out the file_name.

Parameters
[in]file_nameName of existing CSV database file to open.
[in]typeRead/write type ("r"/"wr")
[in]commMPI communicator for distributed data I/O. CSVDatabase I/O is always performed serially, regardless.
Returns
True if file open was successful.

Reimplemented from CAROM::Database.

Definition at line 39 of file CSVDatabase.cpp.

◆ putComplexVector()

void CAROM::CSVDatabase::putComplexVector ( const std::string &  file_name,
const std::vector< std::complex< double >> &  data,
int  nelements 
)

Writes a vector of complex doubles associated with the supplied filename.

Precondition
!file_name.empty()
data != nullptr
nelements > 0
Parameters
[in]file_nameThe filename associated with the vector of values to be written.
[in]dataThe vector of complex double values to be written.
[in]nelementsThe number of complex doubles in the vector.

Definition at line 114 of file CSVDatabase.cpp.

◆ putDoubleArray()

void CAROM::CSVDatabase::putDoubleArray ( const std::string &  file_name,
const double *const  data,
int  nelements,
const bool  distributed = false 
)
overridevirtual

Writes an array of doubles associated with the supplied filename.

Precondition
!file_name.empty()
data != nullptr
nelements > 0
Parameters
[in]file_nameThe filename 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. CSVDatabase writes the array serially whether or not distributed.

Implements CAROM::Database.

Definition at line 74 of file CSVDatabase.cpp.

◆ putDoubleVector()

void CAROM::CSVDatabase::putDoubleVector ( const std::string &  file_name,
const std::vector< double > &  data,
int  nelements,
const bool  distributed = false 
)
overridevirtual

Writes a vector of doubles associated with the supplied filename to the currently open CSV database file.

Precondition
!file_name.empty()
data != nullptr
nelements > 0
Parameters
[in]file_nameThe filename 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 vector. CSVDatabase writes the vector serially whether or not distributed.

Implements CAROM::Database.

Definition at line 94 of file CSVDatabase.cpp.

◆ putIntegerArray()

void CAROM::CSVDatabase::putIntegerArray ( const std::string &  file_name,
const int *const  data,
int  nelements,
const bool  distributed = false 
)
overridevirtual

Writes an array of integers associated with the supplied filename.

Precondition
!file_name.empty()
data != nullptr
nelements > 0
Parameters
[in]file_nameThe filename 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. CSVDatabase writes the array serially whether or not distributed.

Implements CAROM::Database.

Definition at line 55 of file CSVDatabase.cpp.

◆ putStringVector()

void CAROM::CSVDatabase::putStringVector ( const std::string &  file_name,
const std::vector< std::string > &  data,
int  nelements 
)

Writes a vector of strings associated with the supplied filename.

Precondition
!file_name.empty()
data != nullptr
nelements > 0
Parameters
[in]file_nameThe filename associated with the vector of values to be written.
[in]dataThe vector of strings to be written.
[in]nelementsThe number of strings in the vector.

Definition at line 133 of file CSVDatabase.cpp.


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