ATLAS Offline Software
Loading...
Searching...
No Matches
xAODMenuWriter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Gaudi/Athena include(s):
7
8// Trigger configuration include(s):
10#include "TrigConfL1Data/Menu.h"
21
23
24// EDM include(s):
29
30// Local include(s):
31#include "xAODMenuWriter.h"
32#include "PrintVectorHelper.h"
33#include "KeyWriterTool.h"
34
35namespace TrigConf
36{
37
39 ISvcLocator *svcLoc)
41 {
42 }
43
45 {
46
47 // Greet the user:
48 ATH_MSG_INFO("Initialising");
49 ATH_MSG_VERBOSE("MetaDataStore = " << m_metaStore);
50
51 // Retrieve the necessary service(s):
52 ATH_CHECK(m_metaStore.retrieve());
53
54 ATH_CHECK(m_keyWriterTool.retrieve());
55
56 ATH_CHECK(m_HLTMenuKey.initialize()); // ReadHandleKey, but DetStore (so renounce)
58 ATH_CHECK(m_HLTMonitoringKey.initialize()); // ReadHandleKey, but DetStore (so renounce)
60 ATH_CHECK(m_HLTPrescaleSetInputKey.initialize()); // ReadCondHandleKey
61
62 ATH_CHECK(m_L1MenuKey.initialize()); // ReadHandleKey, but DetStore (so renounce)
64 ATH_CHECK(m_L1PrescaleSetInputKey.initialize()); // ReadCondHandleKey
65
66 ATH_CHECK(m_bgInputKey.initialize()); // ReadCondHandleKey
67
68 // HLT JSON object - contains HLT menus
69 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_hlt = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
70 std::unique_ptr<xAOD::TriggerMenuJsonContainer> hlt = std::make_unique<xAOD::TriggerMenuJsonContainer>();
71 //all the static checkers are trying to tell us something...
72 //coverity[WRAPPER_ESCAPE]
73 // cppcheck-suppress danglingLifetime; false positive
74 m_menuJSON_hlt = hlt.get(); // Keep a cached pointer from which we can add to the output metastore
75 // cppcheck-suppress danglingLifetime; false positive
76 m_menuJSON_hlt->setStore(aux_hlt.get());
77
78 ATH_CHECK(m_metaStore->record(std::move(aux_hlt), m_metaNameJSON_hlt + "Aux."));
79 ATH_CHECK(m_metaStore->record(std::move(hlt), m_metaNameJSON_hlt));
80
81 // HLT Monitoring JSON object - contains Monitoring groups for HLT menus
82 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_hltmonitoring = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
83 std::unique_ptr<xAOD::TriggerMenuJsonContainer> hltmonitoring = std::make_unique<xAOD::TriggerMenuJsonContainer>();
84 // cppcheck-suppress danglingLifetime; false positive
85 m_menuJSON_hltmonitoring = hltmonitoring.get(); // Keep a cached pointer from which we can add to the output metastore
86 // cppcheck-suppress danglingLifetime; false positive
87 m_menuJSON_hltmonitoring->setStore(aux_hltmonitoring.get());
88
89 ATH_CHECK(m_metaStore->record(std::move(aux_hltmonitoring), m_metaNameJSON_hltmonitoring + "Aux."));
90 ATH_CHECK(m_metaStore->record(std::move(hltmonitoring), m_metaNameJSON_hltmonitoring));
91
92 // L1 JSON object - contains L1 menus
93 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_l1 = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
94 std::unique_ptr<xAOD::TriggerMenuJsonContainer> l1 = std::make_unique<xAOD::TriggerMenuJsonContainer>();
95 // cppcheck-suppress danglingLifetime; false positive
96 m_menuJSON_l1 = l1.get(); // Keep a cached pointer from which we can add to the output metastore
97 // cppcheck-suppress danglingLifetime; false positive
98 m_menuJSON_l1->setStore(aux_l1.get());
99
100 ATH_CHECK(m_metaStore->record(std::move(aux_l1), m_metaNameJSON_l1 + "Aux."));
101 ATH_CHECK(m_metaStore->record(std::move(l1), m_metaNameJSON_l1));
102
103 // HLT PS JSON object - contains prescales sets for HLT menus
104 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_hltps = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
105 std::unique_ptr<xAOD::TriggerMenuJsonContainer> hltps = std::make_unique<xAOD::TriggerMenuJsonContainer>();
106 // cppcheck-suppress danglingLifetime; false positive
107 m_menuJSON_hltps = hltps.get(); // Keep a cached pointer from which we can add to the output metastore
108 // cppcheck-suppress danglingLifetime; false positive
109 m_menuJSON_hltps->setStore(aux_hltps.get());
110
111 ATH_CHECK(m_metaStore->record(std::move(aux_hltps), m_metaNameJSON_hltps + "Aux."));
112 ATH_CHECK(m_metaStore->record(std::move(hltps), m_metaNameJSON_hltps));
113
114 // L1 PS JSON object - contains prescales sets for L1 menus
115 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_l1ps = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
116 std::unique_ptr<xAOD::TriggerMenuJsonContainer> l1ps = std::make_unique<xAOD::TriggerMenuJsonContainer>();
117 // cppcheck-suppress danglingLifetime; false positive
118 m_menuJSON_l1ps = l1ps.get(); // Keep a cached pointer from which we can add to the output metastore
119 // cppcheck-suppress danglingLifetime; false positive
120 m_menuJSON_l1ps->setStore(aux_l1ps.get());
121
122 ATH_CHECK(m_metaStore->record(std::move(aux_l1ps), m_metaNameJSON_l1ps + "Aux."));
123 ATH_CHECK(m_metaStore->record(std::move(l1ps), m_metaNameJSON_l1ps));
124
125 // Bunchgroup JSON object - contains bungchgroup configuration
126 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_bg = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
127 std::unique_ptr<xAOD::TriggerMenuJsonContainer> bg = std::make_unique<xAOD::TriggerMenuJsonContainer>();
128 // cppcheck-suppress danglingLifetime; false positive
129 m_menuJSON_bg = bg.get(); // Keep a cached pointer from which we can add to the output metastore
130 // cppcheck-suppress danglingLifetime; false positive
131 m_menuJSON_bg->setStore( aux_bg.get() );
132
133 ATH_CHECK( m_metaStore->record(std::move(aux_bg), m_metaNameJSON_bg + "Aux." ) );
134 ATH_CHECK( m_metaStore->record(std::move(bg), m_metaNameJSON_bg ) );
135
136 // Return gracefully:
137 return StatusCode::SUCCESS;
138 }
139
140 StatusCode xAODMenuWriter::execute(const EventContext &ctx) const
141 {
142
143 // Create the keys in the "internal format":
144 TrigKey_t ckeys;
145
146 // Write to SG via writer tool.
147 // Get keys back via pass-by-reference
148 ATH_CHECK(m_keyWriterTool->writeKeys(ctx, /*SMK*/ ckeys.first, /*L1PSK*/ ckeys.second.first, /*HLTPSK*/ ckeys.second.second));
149
150 uint32_t bunchgroupKey = 0;
151 ATH_CHECK(m_keyWriterTool->writeBunchgroupKey(ctx, bunchgroupKey));
152
153 // The following code must only run on one event at a time
154 std::lock_guard<std::mutex> lock(m_mutex);
155
156 if (!m_converted_smk.insert(ckeys.first).second) {
157 ATH_MSG_VERBOSE("Already converted SMK: " << ckeys.first);
158 } else {
159 ATH_MSG_DEBUG("Filling HLT Menu information for SMK:" << ckeys.first);
161 ATH_CHECK(hltMenuHandle.isValid());
162 std::stringstream hltTriggerMenuJson;
163 hltMenuHandle->printRaw(hltTriggerMenuJson);
165 m_menuJSON_hlt->push_back(hlt); // Now owned by MetaDataStore
166 hlt->setKey(ckeys.first);
167 hlt->setName(hltMenuHandle->name());
168 hlt->setPayload(hltTriggerMenuJson.str());
170 ATH_MSG_DEBUG("Filling HLT Monitoring information for SMK:" << ckeys.first);
172 if (hltMonitoringHandle.isValid()) {
173 std::stringstream hltMonitoringJson;
174 hltMonitoringHandle->printRaw(hltMonitoringJson);
175 xAOD::TriggerMenuJson *hltmonitoring = new xAOD::TriggerMenuJson();
176 m_menuJSON_hltmonitoring->push_back(hltmonitoring); // Now owned by MetaDataStore
177 hltmonitoring->setKey(ckeys.first);
178 hltmonitoring->setName(hltMonitoringHandle->name());
179 hltmonitoring->setPayload(hltMonitoringJson.str());
180 } else {
181 ATH_MSG_DEBUG("No HLT Monitoring JSON available - skipping.");
182 }
184 ATH_MSG_DEBUG("Filling L1 information for SMK:" << ckeys.first);
186 ATH_CHECK(l1MenuHandle.isValid());
187 std::stringstream l1TriggerMenuJson;
188 l1MenuHandle->printRaw(l1TriggerMenuJson);
190 m_menuJSON_l1->push_back(l1); // Now owned by MetaDataStore
191 l1->setKey(ckeys.first);
192 l1->setName(l1MenuHandle->name());
193 l1->setPayload(l1TriggerMenuJson.str());
194 }
195
196 if (!m_converted_hltpsk.insert(ckeys.second.second).second) {
197 ATH_MSG_VERBOSE("Already converted HLTPSK: " << ckeys.second.second);
198 } else {
199 ATH_MSG_DEBUG("Filling prescale information for HLTPSK:" << ckeys.second.second);
201 ATH_CHECK(hltPSHandle.isValid());
202 std::stringstream hltPSJSON;
203 hltPSHandle->printRaw(hltPSJSON);
205 m_menuJSON_hltps->push_back(hltps); // Now owned by MetaDataStore
206 hltps->setKey(ckeys.second.second);
207 hltps->setName(hltPSHandle->name());
208 hltps->setPayload(hltPSJSON.str());
209 }
210
211 if (!m_converted_l1psk.insert(ckeys.second.first).second) {
212 ATH_MSG_VERBOSE("Already converted LVL1PSK: " << ckeys.second.first);
213 } else {
214 ATH_MSG_DEBUG("Filling prescale information for LVL1PSK:" << ckeys.second.first);
216 ATH_CHECK(l1PSHandle.isValid());
217 std::stringstream l1PSJSON;
218 l1PSHandle->printRaw(l1PSJSON);
220 m_menuJSON_l1ps->push_back(l1ps); // Now owned by MetaDataStore
221 l1ps->setKey(ckeys.second.first);
222 l1ps->setName(l1PSHandle->name());
223 l1ps->setPayload(l1PSJSON.str());
224 }
225
226 if (!m_converted_bg.insert(bunchgroupKey).second) {
227 ATH_MSG_VERBOSE("Already converted Bunchgroup Key: " << bunchgroupKey);
228 } else {
229 ATH_MSG_DEBUG("Filling prescale information for Bunchgroup Key:" << bunchgroupKey);
231 ATH_CHECK(bunchgroupHandle.isValid());
232 std::stringstream l1BunchgroupJSON;
233 bunchgroupHandle->printRaw(l1BunchgroupJSON);
235 m_menuJSON_bg->push_back(l1bg); // Now owned by MetaDataStore
236 l1bg->setKey(bunchgroupKey);
237 l1bg->setName(bunchgroupHandle->name());
238 l1bg->setPayload(l1BunchgroupJSON.str());
239 }
240
241 // Return gracefully:
242 return StatusCode::SUCCESS;
243 }
244
245}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
An algorithm that can be simultaneously executed in multiple threads.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
SG::ReadHandleKey< TrigConf::HLTMonitoring > m_HLTMonitoringKey
ToolHandle< IKeyWriterTool > m_keyWriterTool
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
SG::ReadCondHandleKey< TrigConf::HLTPrescalesSet > m_HLTPrescaleSetInputKey
Gaudi::Property< std::string > m_metaNameJSON_bg
virtual StatusCode initialize() override
Function initialising the algorithm.
SG::ReadCondHandleKey< TrigConf::L1PrescalesSet > m_L1PrescaleSetInputKey
Gaudi::Property< std::string > m_metaNameJSON_hltps
Gaudi::Property< std::string > m_metaNameJSON_hlt
std::mutex m_mutex
The mutex to prevent us from writing more than one configuration at a time.
SG::ReadCondHandleKey< TrigConf::L1BunchGroupSet > m_bgInputKey
std::pair< uint32_t, std::pair< uint32_t, uint32_t > > TrigKey_t
Trigger configuration key type (used just internally)
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
Gaudi::Property< std::string > m_metaNameJSON_l1ps
Gaudi::Property< std::string > m_metaNameJSON_l1
ServiceHandle< StoreGateSvc > m_metaStore
xAODMenuWriter(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Gaudi::Property< std::string > m_metaNameJSON_hltmonitoring
void setPayload(const std::string &payload)
Set the JSON payload.
void setName(const std::string &name)
Set the name key of this configuration.
void setKey(uint32_t value)
Set the key of this configuration.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
TriggerMenuJson_v1 TriggerMenuJson
Define the latest version of the trigger menu JSON class.