ATLAS Offline Software
Loading...
Searching...
No Matches
PassThroughModelSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "nlohmann/json.hpp"
11#include <fstream>
12#include <stdexcept>
13
14namespace FlavorTagInference {
15
17 if (m_jsonFile.value().empty()) {
18 ATH_MSG_ERROR("JsonFile property is empty");
19 return StatusCode::FAILURE;
20 }
21
22 // Resolve the JSON file path
23 std::string resolved = PathResolverFindCalibFile(m_jsonFile);
24 if (resolved.empty()) {
25 ATH_MSG_ERROR("Could not resolve JSON file: " << m_jsonFile);
26 return StatusCode::FAILURE;
27 }
28
29 // Load and parse the JSON
30 std::ifstream file(resolved);
31 if (!file.is_open()) {
32 ATH_MSG_ERROR("Could not open JSON file: " << resolved);
33 return StatusCode::FAILURE;
34 }
35
36 nlohmann::json config;
37 try {
38 file >> config;
39 } catch (const nlohmann::json::parse_error& e) {
40 ATH_MSG_ERROR("JSON parse error in " << resolved << ": " << e.what());
41 return StatusCode::FAILURE;
42 }
43
44 // Create the PassThroughSaltModel
45 try {
46 auto model = std::make_shared<const PassThroughSaltModel>(config);
47 ISaltModelPtr salt_model = model;
48
49 // Create the GNN wrapper with variable remapping so that
50 // TracksLoader uses the correct aux variable names (e.g.
51 // GhostTrack instead of BTagTrackToJetAssociator)
52 GNNOptions opts;
53 opts.variable_remapping = m_variableRemapping;
54 m_gnn = std::make_shared<const GNN>(salt_model, opts);
55 } catch (const std::exception& e) {
56 ATH_MSG_ERROR("Failed to create PassThroughSaltModel: " << e.what());
57 return StatusCode::FAILURE;
58 }
59
60 ATH_MSG_INFO("PassThroughModelSvc initialized from " << resolved);
61 return StatusCode::SUCCESS;
62 }
63
64 std::shared_ptr<const GNN> PassThroughModelSvc::get(
65 const std::string& /*nn_name*/,
66 const GNNOptions& opts)
67 {
68 // If options differ from defaults, create a new GNN sharing
69 // the underlying model but with new options
70 GNNOptions default_opts;
71 if (!(opts == default_opts)) {
72 return std::make_shared<const GNN>(*m_gnn, opts);
73 }
74 return m_gnn;
75 }
76
77} // namespace FlavorTagInference
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Gaudi::Property< std::string > m_jsonFile
Gaudi::Property< std::map< std::string, std::string > > m_variableRemapping
virtual std::shared_ptr< const GNN > get(const std::string &nn_name, const GNNOptions &opts) override
This file contains "getter" functions used for accessing tagger inputs from the EDM.
std::shared_ptr< const ISaltModel > ISaltModelPtr
Definition ISaltModel.h:54
TFile * file