A utility class for managing JSON-based data tables.
More...
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
G4double lValue = lTable.
getValue<G4double>(
"SomeKey",
"SomeParameter");
std::vector<G4double> lVector;
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
|
template<typename T > |
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.
|
|
|
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.
|
|
◆ appendAndReturnTree()
pt::ptree ParameterTable::appendAndReturnTree |
( |
G4String |
p_fileName | ) |
|
Appends information of json-file containing PMT/OM parameters to a dictionary of ptrees
- Parameters
-
p_fileName | Name of file containing json |
◆ checkIfKeyInTree()
G4bool ParameterTable::checkIfKeyInTree |
( |
G4String |
p_treeName, |
|
|
G4String |
p_key |
|
) |
| |
- Parameters
-
p_treeName | Name of the JSON tree to search in. |
p_key | Key to look for in the tree. |
- Returns
- true if the key exists in the tree, false otherwise.
◆ checkIfTreeNameInTable()
G4bool ParameterTable::checkIfTreeNameInTable |
( |
G4String |
pKey | ) |
|
- Parameters
-
- Returns
- true if the key exists, false otherwise.
◆ getJSONTree()
pt::ptree ParameterTable::getJSONTree |
( |
G4String |
pKey | ) |
|
Get tree object saved in table
- Parameters
-
pKey | Key of tree ("jName" in corresponding json file) |
- Returns
- pt::ptree
◆ getValue()
template<typename T >
T ParameterTable::getValue |
( |
G4String |
pKey, |
|
|
G4String |
pParameter |
|
) |
| |
|
inline |
- Template Parameters
-
T | The type of the value to fetch. |
- Parameters
-
pKey | The main key. |
pParameter | The 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
-
pKey | The main key. |
pParameter | The 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
-
pVector | Vector where the values will be stored. |
pTree | JSON subtree to extract values from. |
pKey | JSON key whose associated array values are to be extracted. |
pScaling | Scaling factor applied to each value. |
pInverse | If true, the value is divided by the scaling factor, if false it's multiplied. |
- Template Parameters
-
T | Type 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
-
pVector | Vector where the values will be stored. |
p_MapKey | Key of the JSON map to retrieve the desired subtree. |
pKey | JSON key within the subtree whose associated array values are to be extracted. |
pScaling | Scaling factor applied to each value. |
pInverse | If true, the value is divided by the scaling factor, if false it's multiplied. |
- Template Parameters
-
T | Type of the values to be extracted from the JSON tree. |
The documentation for this class was generated from the following files: