OMSim
Geant4 for IceCube optical module studies
Loading...
Searching...
No Matches
ParameterTable Class Reference

A utility class for managing JSON-based data tables. More...

Inheritance diagram for ParameterTable:
[legend]

Detailed Description

Interface for handling and querying data in the form of a property tree of the boost library. It facilitates the extraction of specific parameters from loaded JSON files while also supporting units and scales.

Its main use is as base class of OMSimInputData, but you may use it as needed (see Minimal example).

Minimal example

ParameterTable lTable; // Create an instance of the table
lTable.appendAndReturnTree("path/to/file.json"); // Load a JSON file into the table. The key of this file (in the following "SomeKey") is contained within the file under the variable "jName"
G4double lValue = lTable.getValue<G4double>("SomeKey", "SomeParameter"); // Fetch a specific value using its key and parameter name
// Parsing array content from a JSON subtree into a vector using parseKeyContentToVector
std::vector<G4double> lVector;
pt::ptree lSubtree = lTable.getJSONTree("SomeKey"); // Retrieving the subtree of the file
lTable.parseKeyContentToVector(lVector, lSubtree, "keyOfArray", 1.0, false); // parsing array into vector
A utility class for managing JSON-based data tables.
Definition OMSimInputData.hh:39
pt::ptree getJSONTree(G4String pKey)
Definition OMSimInputData.cc:87
pt::ptree appendAndReturnTree(G4String pFileName)
Definition OMSimInputData.cc:21
void parseKeyContentToVector(std::vector< T > &pVector, pt::ptree pTree, std::basic_string< char > pKey, G4double pScaling, bool pInverse)
Parses the content of a JSON subtree into a vector, scaling values if necessary.
Definition OMSimInputData.hh:86
T getValue(G4String pKey, G4String pParameter)
Fetches a value from the table based on a key and parameter.
Definition OMSimInputData.hh:52

Public Member Functions

template<typename T >
getValue (G4String pKey, G4String pParameter)
 Fetches a value from the table based on a key and parameter.
 
G4bool checkIfTreeNameInTable (G4String pKey)
 Checks if a key exists within the table.
 
G4bool checkIfKeyInTree (G4String p_treeName, G4String p_key)
 Checks if a specific key exists in a given JSON tree.
 
G4double getValueWithUnit (G4String pKey, G4String pParameter)
 Fetches the value associated with a given key and parameter.
 
pt::ptree appendAndReturnTree (G4String pFileName)
 
pt::ptree getJSONTree (G4String pKey)
 
template<typename T >
void parseKeyContentToVector (std::vector< T > &pVector, pt::ptree pTree, std::basic_string< char > pKey, G4double pScaling, bool pInverse)
 Parses the content of a JSON subtree into a vector, scaling values if necessary.
 
template<typename T >
void parseKeyContentToVector (std::vector< T > &pVector, std::basic_string< char > p_MapKey, std::basic_string< char > pKey, G4double pScaling, bool pInverse)
 Parses the content of a JSON subtree into a vector, scaling values if necessary.
 

Private Attributes

std::map< G4String, boost::property_tree::ptree > m_table
 A table mapping keys to property trees.
 
std::map< G4String, G4String > m_keyToFileName
 A table mapping keys to original file name.
 

Member Function Documentation

◆ appendAndReturnTree()

pt::ptree ParameterTable::appendAndReturnTree ( G4String  p_fileName)

Appends information of json-file containing PMT/OM parameters to a dictionary of ptrees

Parameters
p_fileNameName of file containing json

◆ checkIfKeyInTree()

G4bool ParameterTable::checkIfKeyInTree ( G4String  p_treeName,
G4String  p_key 
)
Parameters
p_treeNameName of the JSON tree to search in.
p_keyKey to look for in the tree.
Returns
true if the key exists in the tree, false otherwise.

◆ checkIfTreeNameInTable()

G4bool ParameterTable::checkIfTreeNameInTable ( G4String  pKey)
Parameters
pKeyThe key to check.
Returns
true if the key exists, false otherwise.

◆ getJSONTree()

pt::ptree ParameterTable::getJSONTree ( G4String  pKey)

Get tree object saved in table

Parameters
pKeyKey of tree ("jName" in corresponding json file)
Returns
pt::ptree

◆ getValue()

template<typename T >
T ParameterTable::getValue ( G4String  pKey,
G4String  pParameter 
)
inline
Template Parameters
TThe type of the value to fetch.
Parameters
pKeyThe main key.
pParameterThe parameter within the main key's tree.
Returns
The value associated with the key and parameter.

◆ getValueWithUnit()

G4double ParameterTable::getValueWithUnit ( G4String  pKey,
G4String  pParameter 
)
Parameters
pKeyThe main key.
pParameterThe parameter within the main key's tree.
Returns
The value associated with the key and parameter, with units converted to Geant4-compatible units.

◆ parseKeyContentToVector() [1/2]

template<typename T >
void ParameterTable::parseKeyContentToVector ( std::vector< T > &  pVector,
pt::ptree  pTree,
std::basic_string< char >  pKey,
G4double  pScaling,
bool  pInverse 
)
inline
Parameters
pVectorVector where the values will be stored.
pTreeJSON subtree to extract values from.
pKeyJSON key whose associated array values are to be extracted.
pScalingScaling factor applied to each value.
pInverseIf true, the value is divided by the scaling factor, if false it's multiplied.
Template Parameters
TType of the values to be extracted from the JSON tree.

◆ parseKeyContentToVector() [2/2]

template<typename T >
void ParameterTable::parseKeyContentToVector ( std::vector< T > &  pVector,
std::basic_string< char >  p_MapKey,
std::basic_string< char >  pKey,
G4double  pScaling,
bool  pInverse 
)
inline

This overloaded method additionally requires a map key to first retrieve the JSON subtree.

Parameters
pVectorVector where the values will be stored.
p_MapKeyKey of the JSON map to retrieve the desired subtree.
pKeyJSON key within the subtree whose associated array values are to be extracted.
pScalingScaling factor applied to each value.
pInverseIf true, the value is divided by the scaling factor, if false it's multiplied.
Template Parameters
TType of the values to be extracted from the JSON tree.

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