Serializer implemenation of the gridtools frontend. More...
#include <Serializer.h>
Public Types | |
using | savepoint_t = serialbox::gridtools::savepoint |
Type-defs. | |
using | meta_info_map_t = serialbox::gridtools::meta_info_map |
using | field_meta_info_t = serialbox::gridtools::field_meta_info |
Public Member Functions | |
serializer (open_mode mode, const std::string &directory, const std::string &prefix, std::string archive_name="Binary") | |
Construct the serializer. More... | |
serializer (const serializer &)=default | |
Copy constructor. More... | |
serializer (serializer &&)=default | |
Move constructor. | |
serializer & | operator= (const serializer &)=delete |
Copy assignment. More... | |
serializer & | operator= (serializer &&)=default |
Move assignment. | |
open_mode | mode () const noexcept |
Access the mode of the serializer. | |
std::string | directory () const noexcept |
Access the directory in which the Serializer and Archive are opened. | |
std::string | prefix () const noexcept |
Access prefix of all filenames. | |
std::string | meta_data_file () const noexcept |
Access the path to the meta-data file. | |
std::string | archive_name () const noexcept |
Name of the archive in use. | |
void | clear () noexcept |
Drop all field and savepoint meta-data. More... | |
void | update_meta_data () |
Convert meta-data to JSON and serialize to MetaData-prefix.json and ArchiveMetaData-prefix.json. More... | |
template<class StringType , class ValueType > | |
void | add_global_meta_info (StringType &&key, ValueType &&value) |
Add a new key-value pair to the global meta-information of the serializer. More... | |
template<class T , class StringType > | |
T | get_global_meta_info_as (StringType &&key) const |
Query global meta_info_map for key and retrieve value as type T More... | |
meta_info_map | global_meta_info () noexcept |
Get a refrence to the global meta information. | |
template<class StringType , typename... Args> | |
void | register_field (StringType &&name, Args &&... args) |
Register a new field within the serializer. More... | |
template<class StringType > | |
bool | has_field (StringType &&name) const noexcept |
Check if field name has been registred within the serializer. More... | |
template<class StringType , class KeyType , class ValueType > | |
bool | add_meta_info_to_field (StringType &&name, KeyType &&key, ValueType &&value) |
Add key = value or key = {value1, ..., valueN} meta-information to field name More... | |
template<class StringType > | |
field_meta_info | get_field_meta_info (StringType &&name) const |
Get field_meta_info of field name More... | |
std::vector< std::string > | fieldnames () const |
Get a vector of all registered fields. More... | |
template<typename... Args> | |
bool | register_savepoint (Args &&... args) noexcept |
Register a savepoint. More... | |
template<typename... Args> | |
bool | has_savepoint (const savepoint sp) const noexcept |
Check if savepoint exists. More... | |
const std::vector< savepoint > & | savepoints () |
Get a refrence to savepoint vector. | |
template<class StorageType > | |
void | write (const std::string &name, const savepoint &sp, const StorageType &storage, bool register_field=true) |
Serialize gridtools field name given as storage at savepoint to disk. More... | |
template<class T > | |
void | write (const std::string &name, const savepoint &sp, T *origin_ptr, const std::vector< int > &strides) |
Serialize field name given as origin_ptr and strides at savepoint to disk. More... | |
template<class StorageType > | |
void | read (const std::string &name, const savepoint &sp, StorageType &storage) |
Deserialize gridtools field name given as storage at savepoint to disk. More... | |
template<class StorageType > | |
void | read_slice (const std::string &name, const savepoint &sp, StorageType &storage, Slice slice) |
Deserialize sliced field name (given as storageView and slice ) at savepoint from disk. More... | |
template<class T > | |
void | read (const std::string &name, const savepoint &sp, T *origin_ptr, const std::vector< int > &strides) |
Deserialize field name given as origin_ptr and strides at savepoint to disk. More... | |
std::string | to_string () const |
Convert to string. | |
Static Public Member Functions | |
static int | serializationStatus () noexcept |
Get the status of serialization. More... | |
static void | enableSerialization () noexcept |
Enable serialization. More... | |
static void | disableSerialization () noexcept |
Disable serialization. More... | |
template<class StorageType > | |
static void | to_file (std::string file, const StorageType &storage, std::string archive_name="") |
Directly write gridools field, given by storage , to file More... | |
template<class StorageType > | |
static void | from_file (std::string file, StorageType &storage, std::string archive_name="") |
Directly read a gridools field, given by storage , from file More... | |
Friends | |
std::ostream & | operator<< (std::ostream &stream, const serializer &s) |
Convert to stream. | |
Serializer implemenation of the gridtools frontend.
Definition at line 38 of file Serializer.h.
|
inline |
Construct the serializer.
mode | Mode of the Serializer |
directory | Directory of the Archive and Serializer meta-data |
prefix | Prefix of all filenames |
archive_name | String passed to the ArchiveFactory to construct the Archive |
exception | Invalid directory or corrupted meta-data files |
Definition at line 91 of file Serializer.h.
|
default |
Copy constructor.
This performs a shallow copy of the Serializer.
|
inline |
Add a new key-value pair to the global meta-information of the serializer.
key | Key of the new element |
value | Object to be copied to (or moved as) the value of the new element |
exception | Value cannot be inserted as it already exists |
Definition at line 149 of file Serializer.h.
|
inline |
Add key = value
or key = {value1, ..., valueN}
meta-information to field name
name | Name of the field |
key | Key of the new element |
value | Object to be copied to (or moved as) the value of the new element |
exception | Field with name name does not exist in FieldMap |
Definition at line 204 of file Serializer.h.
|
inlinenoexcept |
Drop all field and savepoint meta-data.
This will also call Archive::clear() which may remove all related files on the disk.
Definition at line 129 of file Serializer.h.
|
inlinestaticnoexcept |
Disable serialization.
Serialization is enabled by default, but it can be disabled either by setting the environment variable SERIALBOX_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 only be globally enabled or disabled. There is no way to enable or disable only a specific serializer.
Definition at line 81 of file Serializer.h.
|
inlinestaticnoexcept |
Enable serialization.
Serialization is enabled by default, but it can be disabled either by setting the environment variable SERIALBOX_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 only globally enabled or disabled. There is no way to enable or disable only a specific serializer.
Definition at line 70 of file Serializer.h.
|
inline |
Get a vector of all registered fields.
Definition at line 222 of file Serializer.h.
|
inlinestatic |
Directly read a gridools field, given by storage
, from file
Certain archives require a fieldname, in this case the name of the storage will be used.
file | File to read from |
storage | gridtools storage i.e object of type gridtools::storage_type |
archive_name | Archive used to perform deserialization. If empty, the archive will be deduced from the file extension. |
exception | Deserialization failed |
Definition at line 399 of file Serializer.h.
|
inline |
Get field_meta_info of field name
name | Name of the field |
exception | Field name does not exist |
Definition at line 215 of file Serializer.h.
|
inline |
Query global meta_info_map for key
and retrieve value as type T
key | Key of the requested element |
exception | Key key does not exist in the globalMetainfo map or value cannot be converted to type T |
Definition at line 161 of file Serializer.h.
|
inlinenoexcept |
Check if field name
has been registred within the serializer.
name | Name of the the new field |
Definition at line 191 of file Serializer.h.
|
inlinenoexcept |
Check if savepoint exists.
sp | Savepoint to check for |
Definition at line 242 of file Serializer.h.
|
delete |
Copy assignment.
This performs a shallow copy of the Serializer.
|
inline |
Deserialize gridtools field name
given as storage
at savepoint
to disk.
name | Name of the field |
sp | Savepoint at which the field will be deserialized |
storage | gridtools storage i.e object of type gridtools::storage_type |
exception | Deserialization failed |
Definition at line 339 of file Serializer.h.
|
inline |
Deserialize field name
given as origin_ptr
and strides
at savepoint
to disk.
name | Name of the field |
sp | Savepoint at which the field will be deserialized |
origin_ptr | Pointer to the origin of the data i.e skipping all initial padding |
strides | Vector of strides |
exception | Deserialization failed |
Definition at line 381 of file Serializer.h.
|
inline |
Deserialize sliced field name
(given as storageView
and slice
) at savepoint
from disk.
name | Name of the field |
savepoint | Savepoint at which the field will be deserialized |
storage | gridtools storage i.e object of type gridtools::storage_type |
slice | Slice of the data to load |
exception | Deserialization failed |
Definition at line 361 of file Serializer.h.
|
inline |
Register a new field within the serializer.
name | Name of the the new field |
Args | Arguments forwarded to the constructor of FieldMetainfoImpl |
exception | Field with same name already exists |
Definition at line 181 of file Serializer.h.
|
inlinenoexcept |
Register a savepoint.
Args | Arguments forwarded to the constructor of Savepoint |
Definition at line 233 of file Serializer.h.
|
inlinestaticnoexcept |
Get the status of serialization.
The status is represented as an integer which can take the following values:
SERIALBOX_SERIALIZATION_DISABLE
is not set to a positive value. The first Serializer which is initialized has to set this value either to +1 or to -1 according to the environment.Definition at line 59 of file Serializer.h.
|
inlinestatic |
Directly write gridools field, given by storage
, to file
Certain archives require a fieldname, in this case the name of the storage will be used.
file | Newly created file (if file already exists, it's contents will be discarded) |
storage | gridtools storage i.e object of type gridtools::storage_type |
archive_name | Archive used to perform serialization. If empty, the archive will be deduced from the file extension. |
Definition at line 313 of file Serializer.h.
|
inline |
Convert meta-data to JSON and serialize to MetaData-prefix.json and ArchiveMetaData-prefix.json.
This will ensure MetaData-prefix.json is up-to-date with the in-memory version of the Serializer data-structures. This method is implicitly called by serializer::write().
Definition at line 136 of file Serializer.h.
|
inline |
Serialize gridtools field name
given as storage
at savepoint
to disk.
name | Name of the field |
sp | Savepoint at which the field will be serialized |
storage | gridtools storage i.e object of type gridtools::storage |
register_field | Register field if not yet present |
exception | Serialization failed |
Definition at line 273 of file Serializer.h.
|
inline |
Serialize field name
given as origin_ptr
and strides
at savepoint
to disk.
name | Name of the field |
sp | Savepoint at which the field will be serialized |
origin_ptr | Pointer to the origin of the data i.e skipping all initial padding |
strides | Vector of strides |
exception | Serialization failed |
Definition at line 296 of file Serializer.h.