6 throw std::runtime_error(
"YamlInputReader: root DBNode is null after parsing file: " + filename);
10std::string YamlInputReader::unquote(std::string s) {
14 if ((a ==
'"' && b ==
'"') || (a ==
'\'' && b ==
'\'')) {
15 return s.substr(1, s.size() - 2);
21std::string YamlInputReader::as_string(
const DBNode::Value& v,
const std::string& ctx) {
22 if (std::holds_alternative<BlockName>(v)) {
23 return std::get<BlockName>(v).to_string();
26 throw std::runtime_error(
"YamlInputReader: expected string(BlockName) for " + ctx);
29double YamlInputReader::as_double(
const DBNode::Value& v,
const std::string& ctx) {
30 if (std::holds_alternative<double>(v))
return std::get<double>(v);
31 if (std::holds_alternative<int>(v))
return static_cast<double>(std::get<int>(v));
32 throw std::runtime_error(
"YamlInputReader: expected number(int/double) for " + ctx);
35std::shared_ptr<DBNode> YamlInputReader::as_node(
const DBNode::Value& v,
const std::string& ctx) {
36 if (std::holds_alternative<std::shared_ptr<DBNode>>(v)) {
37 return std::get<std::shared_ptr<DBNode>>(
v);
39 throw std::runtime_error(
"YamlInputReader: expected DBNode for " + ctx);
43 std::vector<YamlInputParam> out;
45 auto pSpecsNode = as_node(root_->get(
"p_specs"),
"p_specs");
46 auto items = pSpecsNode->getGroup({});
48 out.reserve(items.size());
50 for (
const auto& [idxKey, itemVal] : items) {
53 auto itemNode = as_node(itemVal,
"p_specs item");
55 auto block_raw = as_string(itemNode->get(
"block"),
"p_specs.block");
56 auto code_raw = as_string(itemNode->get(
"code"),
"p_specs.code");
58 std::string block = unquote(block_raw);
59 std::string code = unquote(code_raw);
63 .pdg_code =
LhaID(code)
71 std::vector<YamlScanParam> out;
73 auto scanNode = as_node(root_->get(
"scan_params"),
"scan_params");
74 auto items = scanNode->getGroup({});
76 out.reserve(items.size());
78 for (
const auto& [idxKey, itemVal] : items) {
81 auto itemNode = as_node(itemVal,
"scan_params item");
83 auto block_raw = as_string(itemNode->get(
"block"),
"scan_params.block");
84 auto code_raw = as_string(itemNode->get(
"code"),
"scan_params.code");
86 double minv = as_double(itemNode->get(
"min_val"),
"scan_params.min_val");
87 double maxv = as_double(itemNode->get(
"max_val"),
"scan_params.max_val");
88 double step = as_double(itemNode->get(
"step"),
"scan_params.step");
90 std::string block = unquote(block_raw);
91 std::string code = unquote(code_raw);
95 .pdg_code =
LhaID(code),
std::variant< BlockName, int, double, bool, std::shared_ptr< DBNode >, std::vector< std::shared_ptr< DBNode > > > Value
Variant type used to store values in the tree.
std::shared_ptr< DBNode > readFromFile(const std::string &filename) const override
Reads and parses YAML data from a file.
Represents an identifier of a LHA element, possibly containing several sub-ids.