fire v0.19.0
Framework for sImulation and Reconstruction of Events
fire::io::Data< ParameterStorage > Class Reference

io::Data specialization for ParameterStorage More...

#include <ParameterStorage.h>

Inheritance diagram for fire::io::Data< ParameterStorage >:
[legend]
Collaboration diagram for fire::io::Data< ParameterStorage >:
[legend]

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 ParameterStorageget () 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)
 
Readerinput_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
 
ParameterStoragehandle_
 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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Data()

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.

Parameters
[in]pathfull in-file path to the data set
[in]handleaddress of ParameterStorage object to save/load

Member Function Documentation

◆ attach()

template<typename ParameterType >
void fire::io::Data< ParameterStorage >::attach ( const std::string name)
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.

Note
Undefined behavior if the input ParameterType does not match the type of parameter stored in the variant in the handle's parameter map.
Template Parameters
ParameterTypetype of parameter to attach to us
Parameters
[in]nameof parameter to attach that already exists in the handle's parameter map

◆ load()

void fire::io::Data< ParameterStorage >::load ( h5::Reader r)
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.

Note
This load mechanic does not support changing pass names. This limits us to only using this type of dataset in the event and run headers.
Parameters
[in]rh5::Reader to load from

Implements fire::io::AbstractData< ParameterStorage >.

◆ save()

void fire::io::Data< ParameterStorage >::save ( Writer w)
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.

Parameters
[in]wWriter to save to

Implements fire::io::AbstractData< ParameterStorage >.

◆ structure()

void fire::io::Data< ParameterStorage >::structure ( Writer f)
finaloverridevirtual

pure virtual method for saving structure

Parameters
[in]fWriter to write to

Implements fire::io::AbstractData< ParameterStorage >.


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