ATLAS Offline Software
Loading...
Searching...
No Matches
DecoratorAlg.icc
Go to the documentation of this file.
1// In case the extension is confusing, this is a -*- C++ -*- file
2/*
3 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4*/
5
6#include "StoreGate/ReadDecorHandle.h"
7
8#include <exception>
9
10namespace FlavorTagInference {
11 template <typename C, typename D, typename N>
12 StatusCode DecoratorAlg<C,D,N>::initialize()
13 {
14 return initializeInternal();
15 }
16
17 template <typename C, typename D, typename N>
18 StatusCode DecoratorAlg<C,D,N>::initializeInternal(
19 DecoratorAlg::ExtraDependencies extraDeps)
20 {
21 ATH_CHECK(m_containerKey.initialize());
22 ATH_CHECK(m_constituentKey.initialize());
23 ATH_CHECK(m_electronKey.initialize(!m_electronKey.empty()));
24 ATH_CHECK(m_muonKey.initialize(!m_muonKey.empty()));
25
26 ATH_CHECK(m_decorator.retrieve());
27
28 std::set<std::string> veto(
29 m_undeclaredReadDecorKeys.begin(),
30 m_undeclaredReadDecorKeys.end());
31
32 // now we build data dependencies from the internal tools. We have
33 // to reserve the vectors here to prevent a segfault since read /
34 // write handles aren't movable once declaired as a property.
35 auto deps = m_decorator->getDependencies();
36 // jet inputs
37 auto auxKeys = deps.bTagInputs;
38 auxKeys.merge(extraDeps);
39 m_aux.reserve(auxKeys.size());
40 for (const std::string& key: auxKeys) {
41 const std::string full = m_containerKey.key() + "." + key;
42 if (veto.count(full)) {
43 ATH_MSG_DEBUG("Not declaring accessor: " + full);
44 continue;
45 }
46 ATH_MSG_DEBUG("Adding accessor: " + full);
47 m_aux.emplace_back(this, key, full, "");
48 ATH_CHECK(m_aux.back().initialize());
49 }
50 // track inputs
51 auto trackInputs = deps.trackInputs;
52 m_constituentAux.reserve(trackInputs.size());
53 for (const std::string& key: trackInputs) {
54 const std::string full = m_constituentKey.key() + "." + key;
55 if (veto.count(full)) {
56 ATH_MSG_DEBUG("Not declaring accessor: " + full);
57 continue;
58 }
59 ATH_MSG_DEBUG("Adding constituent accessor: " + full);
60 m_constituentAux.emplace_back(this, key, full, "");
61 ATH_CHECK(m_constituentAux.back().initialize());
62 }
63 // electron inputs
64 size_t n_electron_inputs = deps.electronInputs.size();
65 if (n_electron_inputs > 0 && m_electronKey.empty()) {
66 ATH_MSG_ERROR("using electrons without defining the input container");
67 return StatusCode::FAILURE;
68 }
69 m_electronAux.reserve(n_electron_inputs);
70 for (const std::string& key: deps.electronInputs) {
71 const std::string full = m_electronKey.key() + "." + key;
72 ATH_MSG_DEBUG("Adding electron accessor: " + full);
73 m_electronAux.emplace_back(this, key, full, "");
74 ATH_CHECK(m_electronAux.back().initialize());
75 }
76 // muon inputs
77 size_t n_muon_inputs = deps.muonInputs.size();
78 if (n_muon_inputs > 0 && m_muonKey.empty()) {
79 ATH_MSG_ERROR("using muons without defining the input container");
80 return StatusCode::FAILURE;
81 }
82 m_muonAux.reserve(n_muon_inputs);
83 for (const std::string& key: deps.muonInputs) {
84 const std::string full = m_muonKey.key() + "." + key;
85 ATH_MSG_DEBUG("Adding muon accessor: " + full);
86 m_muonAux.emplace_back(this, key, full, "");
87 ATH_CHECK(m_muonAux.back().initialize());
88 }
89 // jet outputs
90 std::set<std::string> keys = deps.bTagOutputs;
91 m_decor.reserve(keys.size());
92 for (const std::string& key: keys) {
93 const std::string full = m_containerKey.key() + "." + key;
94 m_decor.emplace_back(this, key, full, "");
95 ATH_CHECK(m_decor.back().initialize());
96 // look up auxids
97 SG::auxid_t auxid = SG::AuxTypeRegistry::instance().findAuxID(key);
98 ATH_MSG_DEBUG("Added decorator: " + full + ","
99 " key " + key + " has auxid " + std::to_string(auxid) );
100 m_auxids.push_back(auxid);
101 }
102 ATH_MSG_DEBUG("Finished setting up");
103 return StatusCode::SUCCESS;
104 }
105
106
107 template <typename C, typename D, typename N>
108 StatusCode DecoratorAlg<C,D,N>::execute(const EventContext& cxt ) const {
109 SG::ReadHandle<C> container(
110 m_containerKey, cxt);
111 if (!container.isValid()) {
112 ATH_MSG_ERROR("no container " << container.key());
113 return StatusCode::FAILURE;
114 }
115 ATH_MSG_DEBUG(
116 "Decorating " + std::to_string(container->size()) + " elements");
117 for (const auto* element: *container) {
118 m_decorator->decorate(*element);
119 }
120
121 // Lock the decorations
122 //
123 for (SG::auxid_t id: m_auxids) {
124 ATH_MSG_DEBUG("locking auxid " << id << " in " << m_containerKey.key());
125 const_cast<C*>(container.cptr())->lockDecoration(id);
126 }
127
128 ATH_MSG_DEBUG("Finished decorating");
129
130 return StatusCode::SUCCESS;
131 }
132
133 template <typename C, typename D, typename N>
134 StatusCode DecoratorAlg<C,D,N>::finalize() {
135 return StatusCode::SUCCESS;
136 }
137
138}