8#include "OMSimLogger.hh"
9#include "OMSimOpBoundaryProcess.hh"
10#include <G4SystemOfUnits.hh>
11#include <boost/property_tree/json_parser.hpp>
13namespace pt = boost::property_tree;
54 log_trace(
"Fetching parameter {} in key {}", pParameter, pKey);
57 const T lValue =
m_table.at(pKey).get<T>(pParameter);
61 catch (
const std::exception &e)
63 log_error(
"Fetching parameter {} in key {} from table failed!", pParameter, pKey);
64 throw std::runtime_error(
"Fetching parameter failed");
87 std::basic_string<char> pKey, G4double pScaling,
90 log_trace(
"Parsing content in key {} to a vector", pKey);
91 for (pt::ptree::value_type &ridx : pTree.get_child(
96 pVector.push_back(pScaling / ridx.second.get_value<T>());
100 pVector.push_back(ridx.second.get_value<T>() * pScaling);
118 template <
typename T>
120 std::basic_string<char> p_MapKey,
121 std::basic_string<char> pKey, G4double pScaling,
124 log_trace(
"Parsing content in key {} to a vector", pKey);
127 boost::property_tree::ptree lTree =
getJSONTree(p_MapKey);
132 log_warning(
"JSON tree is empty for key {}", p_MapKey);
137 auto lChildNode = lTree.get_child_optional(pKey);
142 log_warning(
"Child node with key {} not found in JSON tree", pKey);
147 for (
const auto &ridx : *lChildNode)
152 pVector.push_back(pScaling / ridx.second.get_value<T>());
157 pVector.push_back(ridx.second.get_value<T>() * pScaling);
163 std::map<G4String, boost::property_tree::ptree>
m_table;
200 enum class FileType {
209 static const std::unordered_map<std::string, FileType> fileTypePrefixes;
210 FileType getFileType(
const std::string& fileName)
const;
216 void scannDataDirectory();
217 void processFile(
const std::string &filePath,
const std::string &fileName);
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
G4bool checkIfTreeNameInTable(G4String pKey)
Checks if a key exists within the table.
Definition OMSimInputData.cc:102
G4bool checkIfKeyInTree(G4String p_treeName, G4String p_key)
Checks if a specific key exists in a given JSON tree.
Definition OMSimInputData.cc:119
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.
Definition OMSimInputData.hh:119
G4double getValueWithUnit(G4String pKey, G4String pParameter)
Fetches the value associated with a given key and parameter.
Definition OMSimInputData.cc:39
std::map< G4String, G4String > m_keyToFileName
A table mapping keys to original file name.
Definition OMSimInputData.hh:164
T getValue(G4String pKey, G4String pParameter)
Fetches a value from the table based on a key and parameter.
Definition OMSimInputData.hh:52
std::map< G4String, boost::property_tree::ptree > m_table
A table mapping keys to property trees.
Definition OMSimInputData.hh:163