fire v0.19.0
Framework for sImulation and Reconstruction of Events
|
io::Data specialization for ParameterStorage More...
#include <ParameterStorage.h>
Public Member Functions | |
Data (const std::string &path, Reader *input_file, ParameterStorage *handle) | |
Define the full in-file path to the data set and provide the address of a ParameterStorage object already controled. More... | |
void | load (h5::Reader &r) final override |
load the next entry of ParameterStorage from disk into memory More... | |
void | save (Writer &w) final override |
save the current entry of ParameterStorage into the file More... | |
void | structure (Writer &w) final override |
pure virtual method for saving structure More... | |
Public Member Functions inherited from fire::io::AbstractData< ParameterStorage > | |
AbstractData (const std::string &path, Reader *input_file=nullptr, ParameterStorage *handle=nullptr) | |
Define the dataset path and provide an optional handle. More... | |
virtual | ~AbstractData () |
Delete our object if we own it, otherwise do nothing. More... | |
virtual void | clear () |
Define the clear function here to handle the most common cases. More... | |
virtual const ParameterStorage & | get () const |
Get the current in-memory data. More... | |
int | version () const |
Get the version number for the type we are loading from. More... | |
virtual void | update (const ParameterStorage &val) |
Update the in-memory data object with the passed value. More... | |
Public Member Functions inherited from fire::io::BaseData | |
BaseData (const std::string &path) | |
Define the full in-file path to the data set of this data. More... | |
virtual | ~BaseData ()=default |
virtual destructor so inherited classes can be properly destructed. | |
Private Member Functions | |
template<typename ParameterType > | |
void | attach (const std::string &name) |
Attach the input parameter name as a new dataset in our own parameter map using the entry in the handle's parameter variable map as the reference. More... | |
Private Attributes | |
std::unordered_map< std::string, std::unique_ptr< BaseData > > | parameters_ |
the dynamic parameter listing (parallel to parameters_ member variable) | |
Reader * | input_file_ |
the input file we are reading from | |
Additional Inherited Members | |
Protected Attributes inherited from fire::io::AbstractData< ParameterStorage > | |
std::optional< std::pair< std::string, int > > | load_type_ |
type this data is loading from | |
std::pair< std::string, int > | save_type_ |
type this data that is being used to write | |
ParameterStorage * | handle_ |
handle on current object in memory | |
bool | owner_ |
we own the object in memory | |
Protected Attributes inherited from fire::io::BaseData | |
std::string | path_ |
path of data set | |
io::Data specialization for ParameterStorage
We use HDF5's introspection capability to determine the types of parameters when loading and we use the std::visit method in combination with decltype to determine parameter types when saving. This is a delicate procedure and so should be used with care. Since ParameterStorage makes no attempt to keep parameters of a specific name a specific type, the user is excepted to put in checks that subsequent ParameterStorage::set calls with the same parameter name input the same type.
fire::io::Data< ParameterStorage >::Data | ( | const std::string & | path, |
Reader * | input_file, | ||
ParameterStorage * | handle | ||
) |
Define the full in-file path to the data set and provide the address of a ParameterStorage object already controled.
We do not provide the usual nullptr
default for the handle because we want to remove the possiblity of users of fire being able to add and get ParameterStorage objects directly.
[in] | path | full in-file path to the data set |
[in] | handle | address of ParameterStorage object to save/load |
|
inlineprivate |
Attach the input parameter name as a new dataset in our own parameter map using the entry in the handle's parameter variable map as the reference.
This is very similar to the standard attachment mechanism used by the general h5::Data class. We do need to specialize it in order to handle the oddness of std::variant.
ParameterType | type of parameter to attach to us |
[in] | name | of parameter to attach that already exists in the handle's parameter map |
|
finaloverridevirtual |
load the next entry of ParameterStorage from disk into memory
On the first call to load, we determine the parameters in this object by using our path member to list the objects in the group (h5::Reader::list). Then for each member of this list, we get its type (h5::Reader::getDataSetType) from its path and create a new object in the variant map of the ParameterStorage pointed to by our handle. Then we use the attach method to create a new dataset to track the parameter.
After the first load, we just call load on all of our attached datasets like any other user class.
[in] | r | h5::Reader to load from |
Implements fire::io::AbstractData< ParameterStorage >.
|
finaloverridevirtual |
save the current entry of ParameterStorage into the file
We go through all entries in the variant map held by the object pointed to by our handle. If the entry is not in our own map of data sets, we use std::vist to deduce the parameter type and use attach to create a new dataset for it. Then (even if the entry already has its own dataset), we pass the writer onto the individula entry dataset to save.
[in] | w | Writer to save to |
Implements fire::io::AbstractData< ParameterStorage >.
|
finaloverridevirtual |
pure virtual method for saving structure
[in] | f | Writer to write to |
Implements fire::io::AbstractData< ParameterStorage >.