ergo
|
Write and read objects to/from file. More...
#include <FileWritable.h>
Classes | |
struct | Manager |
struct | Stats |
Public Member Functions | |
void | writeToFile () |
Write object to file if filewrite is active. | |
void | readFromFile () |
Read object from file if filewrite is active. | |
void | copyToFile (const char *destFileName) |
void | copyFromFile (const char *sourceFileName) |
bool | isOnFile () |
Check if object is on file. | |
long int | fileSize () |
Return file size. | |
Static Public Member Functions | |
static void | setPath (char const *const newPath) |
Set the path to which the objects will be written. | |
static void | activate () |
Activate the filewriting. | |
static std::string | getStatsFileSizes () |
static std::string | writeAndReadAll () |
static void | resetStats () |
static std::string | getStatsTimeWrite () |
static std::string | getStatsTimeRead () |
static std::string | getStatsTimeCopyAndAssign () |
static std::string | getStatsCountWrite () |
static std::string | getStatsCountRead () |
static std::string | getStatsCountCopyAndAssign () |
Protected Types | |
typedef std::map< std::string, double > | TypeTimeMap |
typedef std::map< std::string, int > | TypeCountMap |
typedef std::set< FileWritable * > | ObjPtrSet |
Protected Member Functions | |
virtual void | clear ()=0 |
Release memory for the information written to file. | |
virtual void | inMemorySet (bool)=0 |
Make object invalid (false) via this function when object is written to file and valid (true) when object is read from file. | |
virtual void | writeToFileProt (std::ofstream &) const =0 |
Write object to file. | |
virtual void | readFromFileProt (std::ifstream &)=0 |
Read object from file. | |
FileWritable () | |
Gives each object a unique ID-number and filename. | |
virtual | ~FileWritable () |
Removes file, if any. | |
FileWritable (FileWritable const &) | |
FileWritable & | operator= (FileWritable const &) |
virtual std::string | obj_type_id () const =0 |
Static Protected Member Functions | |
static std::string | getStatsTime (TypeTimeMap &theMap) |
static std::string | getStatsCount (TypeCountMap &theMap) |
static std::string | getStatsFileSizes (ObjPtrSet const &set) |
Private Attributes | |
unsigned int const | IDNumber |
Each object has its unique ID-number. | |
char * | fileName |
Each object has its unique filename. | |
bool | objectIsOnFile |
States whether the object is on file or not. | |
Static Private Attributes | |
static unsigned int | nObjects = 0 |
The number of instantiated objects. | |
static char * | path = NULL |
The path to which files will be written. | |
static bool | active = false |
States whether the filewriting is active. | |
Write and read objects to/from file.
This is an abstract class. Classes that are derived from this class must define the following pure virtual functions to be able to instantiate objects:
|
protected |
|
protected |
|
protected |
|
protected |
Gives each object a unique ID-number and filename.
References fileName, mat::getMachineEpsilon(), IDNumber, nObjects, path, and mat::FileWritable::Manager::registerObj().
|
protectedvirtual |
Removes file, if any.
References active, fileName, mat::getMachineEpsilon(), objectIsOnFile, and mat::FileWritable::Manager::unRegisterObj().
|
protected |
References active, mat::copy_file(), mat::FileWritable::Stats::countCopyAndAssign, fileName, mat::getMachineEpsilon(), IDNumber, mat::FileWritable::Stats::instance(), nObjects, objectIsOnFile, path, mat::FileWritable::Manager::registerObj(), mat::Time::tic(), and mat::FileWritable::Stats::wallTimeCopyAndAssign.
|
static |
Release memory for the information written to file.
Implemented in mat::MatrixBase< Treal, Tmatrix >, and mat::VectorGeneral< Treal, Tvector >.
Referenced by copyFromFile(), and writeToFile().
References active, clear(), fileName, mat::get_file_size(), mat::getMachineEpsilon(), inMemorySet(), objectIsOnFile, and readFromFileProt().
Referenced by GetDensFromFock::restore_from_checkpoint().
References active, fileName, mat::get_file_size(), mat::getMachineEpsilon(), objectIsOnFile, readFromFile(), writeToFile(), and writeToFileProt().
Referenced by GetDensFromFock::create_checkpoint().
Return file size.
Call only if obj is on file.
References active, fileName, mat::getMachineEpsilon(), and isOnFile().
|
staticprotected |
References mat::getMachineEpsilon().
Referenced by getStatsCountCopyAndAssign(), getStatsCountRead(), and getStatsCountWrite().
|
static |
References getStatsCount(), and mat::FileWritable::Stats::instance().
Referenced by GetDensFromFock::get_dens_from_fock_sparse(), and mainFun().
|
static |
References getStatsCount(), and mat::FileWritable::Stats::instance().
Referenced by GetDensFromFock::get_dens_from_fock_sparse(), and mainFun().
|
static |
References getStatsCount(), and mat::FileWritable::Stats::instance().
Referenced by GetDensFromFock::get_dens_from_fock_sparse(), and mainFun().
|
static |
References getStatsFileSizes(), and mat::FileWritable::Manager::instance().
Referenced by getStatsFileSizes(), and writeAndReadAll().
|
staticprotected |
References mat::getMachineEpsilon().
|
staticprotected |
References mat::getMachineEpsilon().
Referenced by getStatsTimeCopyAndAssign(), getStatsTimeRead(), and getStatsTimeWrite().
|
static |
References getStatsTime(), and mat::FileWritable::Stats::instance().
Referenced by GetDensFromFock::get_dens_from_fock_sparse(), and mainFun().
|
static |
References getStatsTime(), and mat::FileWritable::Stats::instance().
Referenced by GetDensFromFock::get_dens_from_fock_sparse(), and mainFun().
|
static |
References getStatsTime(), and mat::FileWritable::Stats::instance().
Referenced by GetDensFromFock::get_dens_from_fock_sparse(), and mainFun().
Make object invalid (false) via this function when object is written to file and valid (true) when object is read from file.
Implemented in mat::MatrixBase< Treal, Tmatrix >, and mat::VectorGeneral< Treal, Tvector >.
Referenced by copyFromFile(), readFromFile(), and writeToFile().
|
inline |
|
protectedpure virtual |
|
protected |
References active, mat::copy_file(), mat::FileWritable::Stats::countCopyAndAssign, fileName, mat::getMachineEpsilon(), mat::FileWritable::Stats::instance(), objectIsOnFile, mat::Time::tic(), and mat::FileWritable::Stats::wallTimeCopyAndAssign.
Referenced by mat::MatrixBase< Treal, Tmatrix >::operator=().
void mat::FileWritable::readFromFile | ( | ) |
Read object from file if filewrite is active.
References mat::FileWritable::Stats::countRead, fileName, mat::getMachineEpsilon(), inMemorySet(), mat::FileWritable::Stats::instance(), obj_type_id(), objectIsOnFile, readFromFileProt(), mat::Time::tic(), and mat::FileWritable::Stats::wallTimeRead.
Referenced by copyToFile(), GetDensFromFock::create_checkpoint(), SCF_restricted::get_FDSminusSDF(), SCF_unrestricted::get_FDSminusSDF(), mainFun(), and GetDensFromFock::restore_from_checkpoint().
Read object from file.
Defined in derived class.
Implemented in mat::MatrixGeneral< Treal, Tmatrix >, mat::MatrixSymmetric< Treal, Tmatrix >, mat::MatrixTriangular< Treal, Tmatrix >, and mat::VectorGeneral< Treal, Tvector >.
Referenced by copyFromFile(), and readFromFile().
|
static |
References mat::FileWritable::Stats::countCopyAndAssign, mat::FileWritable::Stats::countRead, mat::FileWritable::Stats::countWrite, mat::FileWritable::Stats::instance(), mat::FileWritable::Stats::wallTimeCopyAndAssign, mat::FileWritable::Stats::wallTimeRead, and mat::FileWritable::Stats::wallTimeWrite.
Referenced by GetDensFromFock::get_dens_from_fock_sparse(), and mainFun().
Set the path to which the objects will be written.
This function can only be called before instantiation of objects.
References mat::getMachineEpsilon(), nObjects, and path.
Referenced by es_run().
|
static |
References mat::getMachineEpsilon(), getStatsFileSizes(), mat::FileWritable::Manager::instance(), and mat::FileWritable::Manager::obj_ptr_set.
Referenced by compute_FDSminusSDF_sparse(), compute_J_by_boxes_sparse(), GetDensFromFock::get_dens_from_fock(), GetDensFromFock::get_dens_from_fock_sparse(), and PurificationGeneral< MatrixType >::output_time_WriteAndReadAll().
void mat::FileWritable::writeToFile | ( | ) |
Write object to file if filewrite is active.
Object is "cleared" in this call.
References active, clear(), mat::FileWritable::Stats::countWrite, fileName, mat::getMachineEpsilon(), inMemorySet(), mat::FileWritable::Stats::instance(), obj_type_id(), objectIsOnFile, mat::Time::tic(), mat::Time::toc(), mat::FileWritable::Stats::wallTimeWrite, and writeToFileProt().
Referenced by copyToFile(), GetDensFromFock::create_checkpoint(), SCF_restricted::get_FDSminusSDF(), SCF_unrestricted::get_FDSminusSDF(), mainFun(), and SCF_restricted::transform_with_S().
Write object to file.
Defined in derived class.
Implemented in mat::MatrixGeneral< Treal, Tmatrix >, mat::MatrixSymmetric< Treal, Tmatrix >, mat::MatrixTriangular< Treal, Tmatrix >, and mat::VectorGeneral< Treal, Tvector >.
Referenced by copyToFile(), and writeToFile().
States whether the filewriting is active.
Referenced by activate(), copyFromFile(), copyToFile(), fileSize(), FileWritable(), operator=(), writeToFile(), and ~FileWritable().
|
private |
Each object has its unique filename.
Referenced by copyFromFile(), copyToFile(), fileSize(), FileWritable(), FileWritable(), operator=(), readFromFile(), writeToFile(), and ~FileWritable().
Each object has its unique ID-number.
Referenced by FileWritable(), and FileWritable().
The number of instantiated objects.
Note that the objects may be of different types derived from this base class.
Referenced by activate(), FileWritable(), FileWritable(), and setPath().
|
private |
States whether the object is on file or not.
Referenced by copyFromFile(), copyToFile(), FileWritable(), isOnFile(), operator=(), readFromFile(), writeToFile(), and ~FileWritable().
The path to which files will be written.
Referenced by FileWritable(), FileWritable(), and setPath().