ATLAS Offline Software
Loading...
Searching...
No Matches
SaltModelGraphConfig.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7namespace FlavorTagInference {
8 namespace SaltModelGraphConfig {
9 Input get_input(const nlohmann::json& v) {
10 std::string name = v.at("name").get<std::string>();
11 auto offset = v.at("offset").get<double>();
12 auto scale = v.at("scale").get<double>();
13 return {std::move(name), offset, scale};
14 }
15
16 InputNodeConfig get_input_node(const nlohmann::json& v) {
18 cfg.name = v.at("name").get<std::string>();
19 for (const auto& var: v.at("variables")) {
20 cfg.variables.push_back(get_input(var));
21 if (var.contains("default")) {
22 std::string name = var.at("name").get<std::string>();
23 cfg.defaults.emplace(name, var.at("default").get<double>());
24 }
25 }
26 return cfg;
27 }
28
29 OutputNodeConfig get_output_node(const nlohmann::json& v) {
31 for (const auto& lab: v.at("labels")) {
32 cfg.labels.push_back(lab.get<std::string>());
33 }
34 int idx = v.at("node_index").get<int>();
35 if (idx < 0) throw std::logic_error("output node index is negative");
36 cfg.node_index = idx;
37 return cfg;
38 }
39
40 GraphConfig parse_json_graph(const nlohmann::json& metadata) {
41 GraphConfig cfg;
42 for (const auto& v: metadata.at("inputs")) {
43 cfg.inputs.push_back(get_input_node(v));
44 }
45 for (const auto& v: metadata.at("input_sequences")) {
46 cfg.input_sequences.push_back(get_input_node(v));
47 }
48 if (metadata.contains("outputs")) {
49 for (const auto& v: metadata.at("outputs").items()) {
50 std::string name = v.key();
51 cfg.outputs.emplace(name, get_output_node(v.value()));
52 }
53 }
54 return cfg;
55 }
56 }
57}
GraphConfig parse_json_graph(const nlohmann::json &metadata)
OutputNodeConfig get_output_node(const nlohmann::json &v)
InputNodeConfig get_input_node(const nlohmann::json &v)
This file contains "getter" functions used for accessing tagger inputs from the EDM.