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

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.
 
serializeroperator= (const serializer &)=delete
 Copy assignment. More...
 
serializeroperator= (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 >
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.
 

Detailed Description

Serializer implemenation of the gridtools frontend.

Definition at line 38 of file Serializer.h.

Constructor & Destructor Documentation

◆ serializer() [1/2]

serialbox::gridtools::serializer::serializer ( open_mode  mode,
const std::string &  directory,
const std::string &  prefix,
std::string  archive_name = "Binary" 
)
inline

Construct the serializer.

Parameters
modeMode of the Serializer
directoryDirectory of the Archive and Serializer meta-data
prefixPrefix of all filenames
archive_nameString passed to the ArchiveFactory to construct the Archive
Exceptions
exceptionInvalid directory or corrupted meta-data files

Definition at line 91 of file Serializer.h.

◆ serializer() [2/2]

serialbox::gridtools::serializer::serializer ( const serializer )
default

Copy constructor.

This performs a shallow copy of the Serializer.

Member Function Documentation

◆ add_global_meta_info()

template<class StringType , class ValueType >
void serialbox::gridtools::serializer::add_global_meta_info ( StringType &&  key,
ValueType &&  value 
)
inline

Add a new key-value pair to the global meta-information of the serializer.

Parameters
keyKey of the new element
valueObject to be copied to (or moved as) the value of the new element
Exceptions
exceptionValue cannot be inserted as it already exists

Definition at line 149 of file Serializer.h.

◆ add_meta_info_to_field()

template<class StringType , class KeyType , class ValueType >
bool serialbox::gridtools::serializer::add_meta_info_to_field ( StringType &&  name,
KeyType &&  key,
ValueType &&  value 
)
inline

Add key = value or key = {value1, ..., valueN} meta-information to field name

Parameters
nameName of the field
keyKey of the new element
valueObject to be copied to (or moved as) the value of the new element
Returns
Value indicating whether the element was successfully inserted or not
Exceptions
exceptionField with name name does not exist in FieldMap

Definition at line 204 of file Serializer.h.

◆ clear()

void serialbox::gridtools::serializer::clear ( )
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.

◆ disableSerialization()

static void serialbox::gridtools::serializer::disableSerialization ( )
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.

◆ enableSerialization()

static void serialbox::gridtools::serializer::enableSerialization ( )
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.

◆ fieldnames()

std::vector<std::string> serialbox::gridtools::serializer::fieldnames ( ) const
inline

Get a vector of all registered fields.

Returns
Vector with the names of the registered fields

Definition at line 222 of file Serializer.h.

◆ from_file()

template<class StorageType >
static void serialbox::gridtools::serializer::from_file ( std::string  file,
StorageType &  storage,
std::string  archive_name = "" 
)
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.

Parameters
fileFile to read from
storagegridtools storage i.e object of type gridtools::storage_type
archive_nameArchive used to perform deserialization. If empty, the archive will be deduced from the file extension.
Exceptions
exceptionDeserialization failed

Definition at line 399 of file Serializer.h.

◆ get_field_meta_info()

template<class StringType >
field_meta_info serialbox::gridtools::serializer::get_field_meta_info ( StringType &&  name) const
inline

Get field_meta_info of field name

Parameters
nameName of the field
Exceptions
exceptionField name does not exist

Definition at line 215 of file Serializer.h.

◆ get_global_meta_info_as()

template<class T , class StringType >
T serialbox::gridtools::serializer::get_global_meta_info_as ( StringType &&  key) const
inline

Query global meta_info_map for key and retrieve value as type T

Parameters
keyKey of the requested element
Exceptions
exceptionKey key does not exist in the globalMetainfo map or value cannot be converted to type T

Definition at line 161 of file Serializer.h.

◆ has_field()

template<class StringType >
bool serialbox::gridtools::serializer::has_field ( StringType &&  name) const
inlinenoexcept

Check if field name has been registred within the serializer.

Parameters
nameName of the the new field
Returns
True iff the field is present

Definition at line 191 of file Serializer.h.

◆ has_savepoint()

template<typename... Args>
bool serialbox::gridtools::serializer::has_savepoint ( const savepoint  sp) const
inlinenoexcept

Check if savepoint exists.

Parameters
spSavepoint to check for
Returns
True iff the savepoint was successfully inserted

Definition at line 242 of file Serializer.h.

◆ operator=()

serializer& serialbox::gridtools::serializer::operator= ( const serializer )
delete

Copy assignment.

This performs a shallow copy of the Serializer.

◆ read() [1/2]

template<class StorageType >
void serialbox::gridtools::serializer::read ( const std::string &  name,
const savepoint sp,
StorageType &  storage 
)
inline

Deserialize gridtools field name given as storage at savepoint to disk.

Parameters
nameName of the field
spSavepoint at which the field will be deserialized
storagegridtools storage i.e object of type gridtools::storage_type
Exceptions
exceptionDeserialization failed
See also
SerializerImpl::read

Definition at line 339 of file Serializer.h.

◆ read() [2/2]

template<class T >
void serialbox::gridtools::serializer::read ( const std::string &  name,
const savepoint sp,
T *  origin_ptr,
const std::vector< int > &  strides 
)
inline

Deserialize field name given as origin_ptr and strides at savepoint to disk.

Parameters
nameName of the field
spSavepoint at which the field will be deserialized
origin_ptrPointer to the origin of the data i.e skipping all initial padding
stridesVector of strides
Exceptions
exceptionDeserialization failed
See also
SerializerImpl::write

Definition at line 381 of file Serializer.h.

◆ read_slice()

template<class StorageType >
void serialbox::gridtools::serializer::read_slice ( const std::string &  name,
const savepoint sp,
StorageType &  storage,
Slice  slice 
)
inline

Deserialize sliced field name (given as storageView and slice) at savepoint from disk.

Parameters
nameName of the field
savepointSavepoint at which the field will be deserialized
storagegridtools storage i.e object of type gridtools::storage_type
sliceSlice of the data to load
Exceptions
exceptionDeserialization failed
See also
serializer::read

Definition at line 361 of file Serializer.h.

◆ register_field()

template<class StringType , typename... Args>
void serialbox::gridtools::serializer::register_field ( StringType &&  name,
Args &&...  args 
)
inline

Register a new field within the serializer.

Parameters
nameName of the the new field
ArgsArguments forwarded to the constructor of FieldMetainfoImpl
Exceptions
exceptionField with same name already exists

Definition at line 181 of file Serializer.h.

◆ register_savepoint()

template<typename... Args>
bool serialbox::gridtools::serializer::register_savepoint ( Args &&...  args)
inlinenoexcept

Register a savepoint.

Parameters
ArgsArguments forwarded to the constructor of Savepoint
Returns
True iff the savepoint was successfully inserted

Definition at line 233 of file Serializer.h.

◆ serializationStatus()

static int serialbox::gridtools::serializer::serializationStatus ( )
inlinestaticnoexcept

Get the status of serialization.

The status is represented as an integer which can take the following values:

  • 0: the variable is not yet initialized -> the serialization is enabled if the environment variable 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.
  • +1: the serialization is enabled, independently of the environment
  • -1: the serialization is disabled, independently of the environment
Returns
serialization status

Definition at line 59 of file Serializer.h.

◆ to_file()

template<class StorageType >
static void serialbox::gridtools::serializer::to_file ( std::string  file,
const StorageType &  storage,
std::string  archive_name = "" 
)
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.

Parameters
fileNewly created file (if file already exists, it's contents will be discarded)
storagegridtools storage i.e object of type gridtools::storage_type
archive_nameArchive used to perform serialization. If empty, the archive will be deduced from the file extension.

Definition at line 313 of file Serializer.h.

◆ update_meta_data()

void serialbox::gridtools::serializer::update_meta_data ( )
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.

◆ write() [1/2]

template<class StorageType >
void serialbox::gridtools::serializer::write ( const std::string &  name,
const savepoint sp,
const StorageType &  storage,
bool  register_field = true 
)
inline

Serialize gridtools field name given as storage at savepoint to disk.

Parameters
nameName of the field
spSavepoint at which the field will be serialized
storagegridtools storage i.e object of type gridtools::storage
register_fieldRegister field if not yet present
Exceptions
exceptionSerialization failed
See also
SerializerImpl::write

Definition at line 273 of file Serializer.h.

◆ write() [2/2]

template<class T >
void serialbox::gridtools::serializer::write ( const std::string &  name,
const savepoint sp,
T *  origin_ptr,
const std::vector< int > &  strides 
)
inline

Serialize field name given as origin_ptr and strides at savepoint to disk.

Parameters
nameName of the field
spSavepoint at which the field will be serialized
origin_ptrPointer to the origin of the data i.e skipping all initial padding
stridesVector of strides
Exceptions
exceptionSerialization failed
See also
SerializerImpl::write

Definition at line 296 of file Serializer.h.


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