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

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
 

Detailed Description

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.

Member Function Documentation

◆ clear()

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>.

◆ get()

template<typename ParameterType >
const ParameterType & fire::io::ParameterStorage::get ( const std::string name) const
inline

Get a parameter corresponding to the input name.

Exceptions
Exceptionif requested type differs from the type stored
Exceptionif parameter is not found

usage

It is recomended to use auto to avoid code repitition.

// ps is a ParameterStorage instance that already has "one" in it.
auto one = ps.get<float>("one");
Template Parameters
ParameterTypetype of parameter that is being requested
Parameters
[in]namename of parameter to get
Returns
const reference to parameter named name

◆ set()

template<typename ParameterType >
void fire::io::ParameterStorage::set ( const std::string name,
const ParameterType &  val 
)
inline

Set a parameter to be a specific value.

Note
We do not check if another parameter is being overwritten.

usage

With C++17's argument type deduction feature, the template parameter can be left out.

ParameterStorage ps;
// these two are the same
ps.set("one",1.0);
ps.set<float>("one",1.0);
// this will not compile because double's aren't supported
ps.set<double>("one",1.0);
Template Parameters
Thetype of the parameter that is being set.
Parameters
[in]nameName of the parameter to set
[in]valvalue of the parameter to keep in storage

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