fire v0.19.0
Framework for sImulation and Reconstruction of Events
|
Provides dynamic parameter storage by interfacing between a map to variants storing parameters and a h5::Data secialization. More...
#include <ParameterStorage.h>
Public Member Functions | |
template<typename ParameterType > | |
const ParameterType & | get (const std::string &name) const |
Get a parameter corresponding to the input name. More... | |
template<typename ParameterType > | |
void | set (const std::string &name, const ParameterType &val) |
Set a parameter to be a specific value. More... | |
void | clear () |
clear the parameters More... | |
Private Attributes | |
std::unordered_map< std::string, std::variant< int, float, std::string > > | parameters_ |
three types of parameters are allowed: int, float, string | |
Friends | |
class | Data< ParameterStorage > |
allow data set access for reading/writing | |
Provides dynamic parameter storage by interfacing between a map to variants storing parameters and a h5::Data secialization.
This class does some pretty absurd nonsense in order to be able to store a dynamic set of parameters of various types. The type casting necessary to load and save the data stored within this object does negatively impact performance, so this class should be used sparingly. Moreover, the h5::Data<ParameterStorage>::load mechanic only reads in new parameters into the map from disk on the first load call (it continues to load values). This prevents ParameterStorage from being usable by normal event objects whose data set names may change between input files due to changing pass names.
Currently, it is only used within the fire::EventHeader and the fire::RunHeader and users of fire are discouraged from using it within their own classes.
ParameterStorage only supports three atomic types (int, float, and std::string). This is just to keep the code relatively simple.
void fire::io::ParameterStorage::clear | ( | ) |
clear the parameters
We don't clear the container of parameters, we clear them individually by setting them to the numeric_limits minimum or clearing the std::string.
This is to help minimize the save/load type deduction processes that are necessary within h5::Data<ParameterStorage>.
|
inline |
Get a parameter corresponding to the input name.
Exception | if requested type differs from the type stored |
Exception | if parameter is not found |
It is recomended to use auto to avoid code repitition.
ParameterType | type of parameter that is being requested |
[in] | name | name of parameter to get |
|
inline |
Set a parameter to be a specific value.
With C++17's argument type deduction feature, the template parameter can be left out.
The | type of the parameter that is being set. |
[in] | name | Name of the parameter to set |
[in] | val | value of the parameter to keep in storage |