Utopia  2
Framework for studying models of complex & adaptive systems.
Modules | Functions
DataIO

Writing data, reading configuration files, and reporting data to the Python frontend. More...

Collaboration diagram for DataIO:

Modules

 DataManager
 High-level interface for data writing.
 
 Graph Utilities
 Provides functions which wrap common tasks for writing out data from graphs.
 
 Chunking Utilities
 Provides algorithms for automatically optimize the chunksize in which data is written to the hard disk when writing compressed or extendable hdf5 files.
 
 HDF5
 Low-level interface for using HDF5 with modern C++ and STL.
 
 Monitor
 Interface for monitoring custom quantities for a simulation via standard out.
 
 Config Utilities
 Allows reading configuration entries from YAML files.
 
 Filesystem
 

Functions

template<class Exc >
YAML::Exception Utopia::DataIO::improve_yaml_exception (const Exc &e, const Config &node, std::string prefix={})
 Improves yaml-cpp exceptions occurring for a given node. More...
 
std::string Utopia::DataIO::to_string (const Config &node)
 Given a config node, returns a string representation of it. More...
 
template<typename CVecT , DimType dim = 0>
CVecT Utopia::DataIO::get_as_arma_vec (const std::string &key, const DataIO::Config &node)
 Retrieve a config entry as Armadillo column vector using get_. More...
 
template<class T , class Keys = std::list<std::string>>
Config Utopia::_internal::__recursive_setitem (Config d, Keys &&key_sequence, const T &val)
 Helper function for recursive_setitem. More...
 
Config Utopia::_internal::recursive_getitem (const Config &d, const std::vector< std::string > &key_sequence)
 Recursively retrieve an element from the configuration tree. More...
 
Config Utopia::_internal::recursive_getitem (const Config &d, const std::string &key_sequence, const std::string &delims=".")
 Overload for recursive_getitem, accepting a string-like key sequence. More...
 
template<class T >
void Utopia::_internal::recursive_setitem (Config &d, std::list< std::string > key_sequence, const T val)
 Recursively sets an element in a configuration tree. More...
 
template<class T >
void Utopia::_internal::recursive_setitem (Config &d, const std::string &key_sequence, const T val, const std::string &delims=".")
 Overload for recursive_setitem that splits a string into a key sequence. More...
 

Detailed Description

Writing data, reading configuration files, and reporting data to the Python frontend.

Function Documentation

◆ __recursive_setitem()

template<class T , class Keys = std::list<std::string>>
Config Utopia::_internal::__recursive_setitem ( Config  d,
Keys &&  key_sequence,
const T &  val 
)

Helper function for recursive_setitem.

Expects an (already deep-copied) node that is then recursively iterated through along the key sequence. For the last key in the sequence, the value is being set. Empty path segments in the key sequence are skipped.

Exceptions
std::invalid_argumentupon trailing empty path segments in the key sequence.

◆ get_as_arma_vec()

template<typename CVecT , DimType dim = 0>
CVecT Utopia::DataIO::get_as_arma_vec ( const std::string &  key,
const DataIO::Config node 
)

Retrieve a config entry as Armadillo column vector using get_.

Note
This method is necessary because arma::Col::fixed cannot be constructed from std::vector. In such cases, the target vector is constructed element-wise.
Template Parameters
CVecTThe Armadillo vector type to return
dimThe dimensionality of the vector (only needed for)

◆ improve_yaml_exception()

template<class Exc >
YAML::Exception Utopia::DataIO::improve_yaml_exception ( const Exc &  e,
const Config node,
std::string  prefix = {} 
)

Improves yaml-cpp exceptions occurring for a given node.

◆ recursive_getitem() [1/2]

Config Utopia::_internal::recursive_getitem ( const Config d,
const std::string &  key_sequence,
const std::string &  delims = "." 
)

Overload for recursive_getitem, accepting a string-like key sequence.

Returns the configuration node at the path specified by the key sequence.

Parameters
dThe configuration tree to retrieve the element from
key_sequenceA string denoting the path within the tree to get the item from. The path is split into segments using Utopia::split
delimsDelimiters (plural!) that split the string into a key sequence.
Returns
Config The configuration tree element at the given path.
Warning
Any character in the delims sequence acts as separator. See Utopia::split for more information on behaviour of the delims argument.

◆ recursive_getitem() [2/2]

Config Utopia::_internal::recursive_getitem ( const Config d,
const std::vector< std::string > &  key_sequence 
)

Recursively retrieve an element from the configuration tree.

Actually uses a loop internally to avoid recursion... ¯_(ツ)_/¯

Note
Only works with string-like keys, i.e. can't access sequences.
Warning
Due to yaml-cpp quirks, creates a deep copy of the given config to keep clear of any mutability side effects. Subsequently, this function should not be used in performance-critical code. Furthermore, to set an element in the configuration tree, the recursive_setitem functionality should be used – assigning a value to the returned Config object will not lead to a change in the tree provided via the d argument.
Parameters
dThe configuration tree to retrieve the element from
key_sequenceA key sequence denoting the path within the tree to get the item from.
Returns
Config The configuration tree element at the given path.

◆ recursive_setitem() [1/2]

template<class T >
void Utopia::_internal::recursive_setitem ( Config d,
const std::string &  key_sequence,
const T  val,
const std::string &  delims = "." 
)

Overload for recursive_setitem that splits a string into a key sequence.

Parameters
dThe configuration tree to set the entry in.
key_sequenceA string to split into a sequence of keys to walk along inside the tree.
valThe value to assign to the element of the tree specified by the key sequence.
delimsDelimiters to generate a key sequence from the given string key_sequence.
Warning
Any character in the delims sequence acts as separator. See Utopia::split for more information on behaviour of the delims argument.

◆ recursive_setitem() [2/2]

template<class T >
void Utopia::_internal::recursive_setitem ( Config d,
std::list< std::string >  key_sequence,
const T  val 
)

Recursively sets an element in a configuration tree.

This also creates all intermediate segments that may be missing.

As the YAML::Node::operator[] does not return references, this internally has to create a (deep) copy of the given node d. After recursing through it and setting the value, it will finally assign to the d reference.

Note
Only works with string-like keys, i.e. can't access sequences.
Parameters
dThe configuration tree to set the entry in.
key_sequenceA container with a sequence of keys to walk along inside the tree.
valThe value to assign to the element of the tree specified by the key sequence.

◆ to_string()

std::string Utopia::DataIO::to_string ( const Config node)

Given a config node, returns a string representation of it.

This is done by dumping the config node into an std::stringstream.