Loading...
Searching...
No Matches
PLMD::CheckpointWriter Class Reference

Writer for the PLUMED checkpoint file. More...

#include <Checkpoint.h>

Public Member Functions

 CheckpointWriter (const std::string &plumedVersion="")
 plumedVersion is stored in the header, for inspection only.
 
void beginSection (const std::string &name)
 Open a section. Sections can be nested.
 
void endSection ()
 Close the current section.
 
std::string finalize () const
 Return the complete file content (header, entries, trailer with checksum).
 
unsigned getNumberOfEntriesInSection () const
 Number of entries written so far in the current section (sub-sections count as one).
 
void write (const std::string &name, const char *value)
 
void write (const std::string &name, const std::string &value)
 
template<typename T>
void write (const std::string &name, const std::vector< T > &value, std::vector< unsigned long long > dims={})
 Write an array with an explicit shape (dims empty means one-dimensional).
 
void write (const std::string &name, double value)
 
void write (const std::string &name, long long value)
 
template<typename T>
std::enable_if< std::is_integral< T >::value &&!std::is_same< T, longlong >::value >::type write (const std::string &name, T value)
 
template<typename T>
std::enable_if< std::is_floating_point< T >::value &&!std::is_same< T, double >::value >::type write (const std::string &name, T value)
 
void writeFile (const std::string &path, const std::string &prevPath) const
 Write the content to path atomically: the data go to a temporary file, which is then renamed to path; the previous file, if any, is kept as prevPath (no backup if prevPath is empty).
 

Private Member Functions

std::string currentPath () const
 
void putName (const std::string &name)
 
void putShape (const std::vector< unsigned long long > &dims)
 
void writeDoubleArray (const std::string &name, const double *data, const std::vector< unsigned long long > &dims)
 
void writeIntArray (const std::string &name, const long long *data, const std::vector< unsigned long long > &dims)
 

Private Attributes

std::string buffer
 
std::vector< unsigned > entriesInSection
 
std::vector< std::string > sections
 

Detailed Description

Writer for the PLUMED checkpoint file.

The checkpoint is a sequence of named, typed entries (64-bit integers, doubles, strings, and arrays of integers or doubles with a shape) grouped in nested sections. Actions write their own state in a section named after their label and never see the storage format, which is a minimal little-endian binary layout described in Checkpoint.cpp. The content is accumulated in memory and written to disk atomically by writeFile().

Constructor & Destructor Documentation

◆ CheckpointWriter()

PLMD::CheckpointWriter::CheckpointWriter ( const std::string & plumedVersion = "")
explicit

plumedVersion is stored in the header, for inspection only.

Member Function Documentation

◆ beginSection()

void PLMD::CheckpointWriter::beginSection ( const std::string & name)

Open a section. Sections can be nested.

◆ currentPath()

std::string PLMD::CheckpointWriter::currentPath ( ) const
private

◆ endSection()

void PLMD::CheckpointWriter::endSection ( )

Close the current section.

◆ finalize()

std::string PLMD::CheckpointWriter::finalize ( ) const

Return the complete file content (header, entries, trailer with checksum).

All sections must be closed.

◆ getNumberOfEntriesInSection()

unsigned PLMD::CheckpointWriter::getNumberOfEntriesInSection ( ) const

Number of entries written so far in the current section (sub-sections count as one).

◆ putName()

void PLMD::CheckpointWriter::putName ( const std::string & name)
private

◆ putShape()

void PLMD::CheckpointWriter::putShape ( const std::vector< unsigned long long > & dims)
private

◆ write() [1/7]

void PLMD::CheckpointWriter::write ( const std::string & name,
const char * value )
inline

◆ write() [2/7]

void PLMD::CheckpointWriter::write ( const std::string & name,
const std::string & value )

◆ write() [3/7]

template<typename T>
void PLMD::CheckpointWriter::write ( const std::string & name,
const std::vector< T > & value,
std::vector< unsigned long long > dims = {} )
inline

Write an array with an explicit shape (dims empty means one-dimensional).

◆ write() [4/7]

void PLMD::CheckpointWriter::write ( const std::string & name,
double value )

◆ write() [5/7]

void PLMD::CheckpointWriter::write ( const std::string & name,
long long value )

◆ write() [6/7]

template<typename T>
std::enable_if< std::is_integral< T >::value &&!std::is_same< T, longlong >::value >::type PLMD::CheckpointWriter::write ( const std::string & name,
T value )
inline

◆ write() [7/7]

template<typename T>
std::enable_if< std::is_floating_point< T >::value &&!std::is_same< T, double >::value >::type PLMD::CheckpointWriter::write ( const std::string & name,
T value )
inline

◆ writeDoubleArray()

void PLMD::CheckpointWriter::writeDoubleArray ( const std::string & name,
const double * data,
const std::vector< unsigned long long > & dims )
private

◆ writeFile()

void PLMD::CheckpointWriter::writeFile ( const std::string & path,
const std::string & prevPath ) const

Write the content to path atomically: the data go to a temporary file, which is then renamed to path; the previous file, if any, is kept as prevPath (no backup if prevPath is empty).

◆ writeIntArray()

void PLMD::CheckpointWriter::writeIntArray ( const std::string & name,
const long long * data,
const std::vector< unsigned long long > & dims )
private

Member Data Documentation

◆ buffer

std::string PLMD::CheckpointWriter::buffer
private

◆ entriesInSection

std::vector<unsigned> PLMD::CheckpointWriter::entriesInSection
private

◆ sections

std::vector<std::string> PLMD::CheckpointWriter::sections
private

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