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 MetainfoSet & | globalMetainfo () 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 DataFieldInfo & | FindField (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... | |
Implementation of the STELLA Serializer.
Definition at line 52 of file Serializer.h.
void serialbox::stella::Serializer::AddFieldMetainfo | ( | const std::string & | fieldname, |
const std::string & | key, | ||
bool | value | ||
) |
Adds a key-value metainformation pair to a field.
SerializationException | The field is not found in table or the type is not supported |
Definition at line 158 of file Serializer.cpp.
|
inline |
Adds a key-value metainformation pair to the serializer.
SerializationException | The type of the value is not supported. |
Definition at line 119 of file Serializer.h.
std::string serialbox::stella::Serializer::directory | ( | ) | const |
Directory where the data are stored.
Definition at line 47 of file Serializer.cpp.
|
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.
|
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.
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
Definition at line 207 of file Serializer.cpp.
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.
Definition at line 209 of file Serializer.cpp.
const DataFieldInfo & serialbox::stella::Serializer::FindField | ( | const std::string & | fieldname | ) | const |
Gives access to field info.
SerializationException | The field is not registered |
Definition at line 146 of file Serializer.cpp.
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.
directory | The directory where the files will be stored (will be created if necessary) |
prefix | The prefix of the files |
mode | The read/write/append flag that sets the access mode |
Definition at line 51 of file Serializer.cpp.
SerializerOpenMode serialbox::stella::Serializer::mode | ( | ) | const |
std::string serialbox::stella::Serializer::prefix | ( | ) | const |
Prefix of the files.
Definition at line 49 of file Serializer.cpp.
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.
fieldName | The name of the field |
savepoint | The savepoint at which the field will be read |
pData | T The pointer to the beginning of the data |
iStride | The offset in bytes from one point to the next in i direction |
jStride | The offset in bytes from one point to the next in j direction |
kStride | The offset in bytes from one point to the next in k direction |
lStride | The offset in bytes from one point to the next in l direction |
alsoPrevious | Whether to search in previous savepoints with the same name until a valid entry is found [IGNORED] |
SerializationException | The field is not registered in the serializer or it is not saved at the savepoint |
Definition at line 267 of file Serializer.cpp.
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.
name | The name of the field |
type | The name of the data type (e.g. "double", "float") |
bytesPerElement | The size in bytes of a scalar value (e.g. 8 for doubles) |
iSize | The size of the first dimension |
jSize | The size of the second dimension |
kSize | The size of the third dimension |
lsize | The size of the fourth dimension |
iMinusHalo | The dimension of the halo in negative i-direction |
iPlusHalo | The dimension of the halo in positive i-direction |
jMinusHalo | The dimension of the halo in negative j-direction |
jPlusHalo | The dimension of the halo in positive j-direction |
kMinusHalo | The dimension of the halo in negative k-direction |
kPlusHalo | The dimension of the halo in positive k-direction |
lMinusHalo | The dimension of the halo in negative l-direction |
lPlusHalo | The dimension of the halo in positive l-direction |
SerializationException | A field with the same name but different properties is registered already |
Definition at line 93 of file Serializer.cpp.
|
inline |
Gives access to the list of savepoints.
Definition at line 186 of file Serializer.h.
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.
fieldName | The name of the field |
savepoint | The savepoint at which the field will be saved |
pData | The pointer to the beginning of the data |
iStride | The offset in bytes from one point to the next in i direction |
jStride | The offset in bytes from one point to the next in j direction |
kStride | The offset in bytes from one point to the next in k direction |
lStride | The offset in bytes from one point to the next in l direction |
SerializationException | The field is not registered or it is already present at the given savepoint |
Definition at line 243 of file Serializer.cpp.