OMSim
Geant4 for IceCube optical module studies
OMSimCommandArgsTable Class Reference

A class used to hold OMSim command arguments with global instance access. More...

Detailed Description

This class uses a map to hold key-value pairs of simulation command arguments. It provides a method to write the parameters to a JSON file. Its lifecycle is managed by the OMSim class.

Public Types

using Key = std::string
 
using Value = boost::any
 

Public Member Functions

void setParameter (const Key &p_key, const Value &p_value)
 Sets a parameter in the arg table. More...
 
bool keyExists (const Key &p_key)
 
void writeToJson (std::string p_fileName)
 Writes the parameters to a JSON-formatted file. More...
 
void finalize ()
 Finalizes the table, setting a random seed if none was provided. m_finalized is set to true preventing any further modifications.
 
template<typename T >
get (const std::string &p_key)
 Retrieves a parameter from the table. More...
 

Static Public Member Functions

static void init ()
 Initializes the global instance of OMSimCommandArgsTable. More...
 
static void shutdown ()
 Deletes the global instance of OMSimCommandArgsTable. More...
 
static OMSimCommandArgsTablegetInstance ()
 

Private Member Functions

 OMSimCommandArgsTable (const OMSimCommandArgsTable &)=delete
 
OMSimCommandArgsTableoperator= (const OMSimCommandArgsTable &)=delete
 

Private Attributes

bool m_finalized = false
 
std::map< Key, Value > m_parameters
 

Member Function Documentation

◆ get()

template<typename T >
T OMSimCommandArgsTable::get ( const std::string &  p_key)
inline
Parameters
p_keyThe key for the parameter.
Returns
The parameter value.
Exceptions
std::invalid_argumentIf the parameter is not of type T, or if the key does not exist.

◆ getInstance()

OMSimCommandArgsTable & OMSimCommandArgsTable::getInstance ( )
static
Returns
A reference to the OMSimCommandArgsTable instance.
Exceptions
std::runtime_errorif accessed before initialization or after shutdown.

◆ init()

void OMSimCommandArgsTable::init ( )
static

This method is normally called in the constructor of OMSim.

◆ setParameter()

void OMSimCommandArgsTable::setParameter ( const Key &  p_key,
const Value &  p_value 
)
Parameters
p_keyThe key for the parameter.
p_valueThe value for the parameter.
Exceptions
std::runtime_errorIf the table is already finalized (i.e. somebody is trying to set a new arg parameter after args were parsed (?!)).

◆ shutdown()

void OMSimCommandArgsTable::shutdown ( )
static

This method is normally called in the destructor ~OMSim.

◆ writeToJson()

void OMSimCommandArgsTable::writeToJson ( std::string  p_fileName)
Parameters
p_fileNameThe name of the JSON file.
Exceptions
std::runtime_errorIf the file fails to open.

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