Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
serialbox::stella::Serializer Class Reference

Implementation of the STELLA Serializer. More...

#include <Serializer.h>

Public Member Functions

SerializerOpenMode mode () const
 Open mode. More...
 
std::string directory () const
 Directory where the data are stored. More...
 
std::string prefix () const
 Prefix of the files. More...
 
void Init (const std::string &directory, const std::string &prefix, SerializerOpenMode mode)
 Initializes the serializer. More...
 
const MetainfoSetglobalMetainfo () const
 Read-only access to the metainformation.
 
template<typename ValueType >
void AddMetainfo (const std::string &key, ValueType value)
 
bool RegisterField (const std::string &name, std::string type, int bytesPerElement, int iSize, int jSize, int kSize, int lSize, int iMinusHalo, int iPlusHalo, int jMinusHalo, int jPlusHalo, int kMinusHalo, int kPlusHalo, int lMinusHalo, int lPlusHalo)
 Register a field into the serializer. More...
 
const DataFieldInfoFindField (const std::string &fieldname) const
 Gives access to field info. More...
 
std::vector< std::string > fieldnames () const
 Gives access to the registered fields. More...
 
const std::vector< Savepoint > & savepoints () const
 Gives access to the list of savepoints. More...
 
std::vector< std::string > FieldsAtSavepoint (const Savepoint &savepoint) const
 Gives all fields which are available at the given savepoint and return their names. More...
 
void WriteField (const std::string &fieldName, const Savepoint &savepoint, const void *pData, int iStride, int jStride, int kStride, int lStride)
 Serializes data to file. More...
 
void ReadField (const std::string &fieldName, const Savepoint &savepoint, void *pData, int iStride, int jStride, int kStride, int lStride, bool alsoPrevious=false) const
 Deserializes data from file. More...
 
std::string ToString () const
 Convert to string.
 
boost::shared_ptr< SerializerImpl > & getImpl ()
 Get implementation pointer.
 
const boost::shared_ptr< SerializerImpl > & getImpl () const
 
void AddFieldMetainfo (const std::string &fieldname, const std::string &key, bool value)
 Adds a key-value metainformation pair to a field. More...
 
void AddFieldMetainfo (const std::string &fieldname, const std::string &key, int value)
 
void AddFieldMetainfo (const std::string &fieldname, const std::string &key, float value)
 
void AddFieldMetainfo (const std::string &fieldname, const std::string &key, double value)
 
void AddFieldMetainfo (const std::string &fieldname, const std::string &key, std::string value)
 
void AddFieldMetainfo (const std::string &fieldname, const std::string &key, const char *value)
 

Static Public Member Functions

static void EnableSerialization ()
 Enable serialization. More...
 
static void DisableSerialization ()
 Disable serialization. More...
 

Detailed Description

Implementation of the STELLA Serializer.

Definition at line 52 of file Serializer.h.

Member Function Documentation

◆ AddFieldMetainfo()

void serialbox::stella::Serializer::AddFieldMetainfo ( const std::string &  fieldname,
const std::string &  key,
bool  value 
)

Adds a key-value metainformation pair to a field.

Exceptions
SerializationExceptionThe field is not found in table or the type is not supported

Definition at line 158 of file Serializer.cpp.

◆ AddMetainfo()

template<typename ValueType >
void serialbox::stella::Serializer::AddMetainfo ( const std::string &  key,
ValueType  value 
)
inline

Adds a key-value metainformation pair to the serializer.

Exceptions
SerializationExceptionThe type of the value is not supported.

Definition at line 119 of file Serializer.h.

◆ directory()

std::string serialbox::stella::Serializer::directory ( ) const

Directory where the data are stored.

Returns
The directory is returned as copy

Definition at line 47 of file Serializer.cpp.

◆ DisableSerialization()

void serialbox::stella::Serializer::DisableSerialization ( )
static

Disable serialization.

Serialization is enabled by default, but it can be disabled either by setting the environment variable STELLA_SERIALIZATION_DISABLE to a positive value or by calling the funtcion DisableSerialization. With this function you disable the serialization independently of the current environment.

The serialization can be only globally enabled or disabled. There is no way to enable or disable only a specific serializer.

Definition at line 45 of file Serializer.cpp.

◆ EnableSerialization()

void serialbox::stella::Serializer::EnableSerialization ( )
static

Enable serialization.

Serialization is enabled by default, but it can be disabled either by setting the environment variable STELLA_SERIALIZATION_DISABLE to a positive value or by calling the function DisableSerialization. With this function you enable the serialization independently of the current environment.

The serialization can be only globally enabled or disabled. There is no way to enable or disable only a specific serializer.

Definition at line 43 of file Serializer.cpp.

◆ fieldnames()

std::vector< std::string > serialbox::stella::Serializer::fieldnames ( ) const

Gives access to the registered fields.

This function fills and returns a vector with the names of the registered fields

Returns
The vector with the names of the fields is returned

Definition at line 207 of file Serializer.cpp.

◆ FieldsAtSavepoint()

std::vector< std::string > serialbox::stella::Serializer::FieldsAtSavepoint ( const Savepoint savepoint) const

Gives all fields which are available at the given savepoint and return their names.

If the savepoint does not exist in the serializer returns an empty vector and does not throw any exceptions.

Returns
A vector with the names of the available fields is returned

Definition at line 209 of file Serializer.cpp.

◆ FindField()

const DataFieldInfo & serialbox::stella::Serializer::FindField ( const std::string &  fieldname) const

Gives access to field info.

Exceptions
SerializationExceptionThe field is not registered

Definition at line 146 of file Serializer.cpp.

◆ Init()

void serialbox::stella::Serializer::Init ( const std::string &  directory,
const std::string &  prefix,
SerializerOpenMode  mode 
)

Initializes the serializer.

This method initializes the serializer and prepares it to perform input/output operations.

The serializer is attached to a specific directory and to a specific prefix, with which all files read and written will start. There are three modes to open a serializer: read, write and append. Read will give a read-only access to the serialized data; Write will erase all files of a previous run of a serializer with same directory and prefix; Append wil import all existing information and allow the user to add more data.

Parameters
directoryThe directory where the files will be stored (will be created if necessary)
prefixThe prefix of the files
modeThe read/write/append flag that sets the access mode

Definition at line 51 of file Serializer.cpp.

◆ mode()

SerializerOpenMode serialbox::stella::Serializer::mode ( ) const

Open mode.

Returns
The mode is returned as value

Definition at line 30 of file Serializer.cpp.

◆ prefix()

std::string serialbox::stella::Serializer::prefix ( ) const

Prefix of the files.

Returns
The prefix is returned as copy

Definition at line 49 of file Serializer.cpp.

◆ ReadField()

void serialbox::stella::Serializer::ReadField ( const std::string &  fieldName,
const Savepoint savepoint,
void *  pData,
int  iStride,
int  jStride,
int  kStride,
int  lStride,
bool  alsoPrevious = false 
) const

Deserializes data from file.

This method reads the contents of the file corresponging to the given field name to the given savepoint and places the data into the provided array, which must already be allocated.

Parameters
fieldNameThe name of the field
savepointThe savepoint at which the field will be read
pDataT The pointer to the beginning of the data
iStrideThe offset in bytes from one point to the next in i direction
jStrideThe offset in bytes from one point to the next in j direction
kStrideThe offset in bytes from one point to the next in k direction
lStrideThe offset in bytes from one point to the next in l direction
alsoPreviousWhether to search in previous savepoints with the same name until a valid entry is found [IGNORED]
Exceptions
SerializationExceptionThe field is not registered in the serializer or it is not saved at the savepoint

Definition at line 267 of file Serializer.cpp.

◆ RegisterField()

bool serialbox::stella::Serializer::RegisterField ( const std::string &  name,
std::string  type,
int  bytesPerElement,
int  iSize,
int  jSize,
int  kSize,
int  lSize,
int  iMinusHalo,
int  iPlusHalo,
int  jMinusHalo,
int  jPlusHalo,
int  kMinusHalo,
int  kPlusHalo,
int  lMinusHalo,
int  lPlusHalo 
)

Register a field into the serializer.

It is possible to register a field multiple times, as long as all properties of the field always match.

Parameters
nameThe name of the field
typeThe name of the data type (e.g. "double", "float")
bytesPerElementThe size in bytes of a scalar value (e.g. 8 for doubles)
iSizeThe size of the first dimension
jSizeThe size of the second dimension
kSizeThe size of the third dimension
lsizeThe size of the fourth dimension
iMinusHaloThe dimension of the halo in negative i-direction
iPlusHaloThe dimension of the halo in positive i-direction
jMinusHaloThe dimension of the halo in negative j-direction
jPlusHaloThe dimension of the halo in positive j-direction
kMinusHaloThe dimension of the halo in negative k-direction
kPlusHaloThe dimension of the halo in positive k-direction
lMinusHaloThe dimension of the halo in negative l-direction
lPlusHaloThe dimension of the halo in positive l-direction
Returns
The method returns true if the field is new, false if the field was already registered with matching information.
Exceptions
SerializationExceptionA field with the same name but different properties is registered already

Definition at line 93 of file Serializer.cpp.

◆ savepoints()

const std::vector<Savepoint>& serialbox::stella::Serializer::savepoints ( ) const
inline

Gives access to the list of savepoints.

Returns
A constant reference to the underlying savepoints vector is returned

Definition at line 186 of file Serializer.h.

◆ WriteField()

void serialbox::stella::Serializer::WriteField ( const std::string &  fieldName,
const Savepoint savepoint,
const void *  pData,
int  iStride,
int  jStride,
int  kStride,
int  lStride 
)

Serializes data to file.

This method serializes the content of the given array as the field with the given name at the provided savepoint.

Parameters
fieldNameThe name of the field
savepointThe savepoint at which the field will be saved
pDataThe pointer to the beginning of the data
iStrideThe offset in bytes from one point to the next in i direction
jStrideThe offset in bytes from one point to the next in j direction
kStrideThe offset in bytes from one point to the next in k direction
lStrideThe offset in bytes from one point to the next in l direction
Exceptions
SerializationExceptionThe field is not registered or it is already present at the given savepoint

Definition at line 243 of file Serializer.cpp.


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