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 // cppcheck-suppress danglingLifetime; false positive
72 m_menuJSON_hlt = hlt.get(); // Keep a cached pointer from which we can add to the output metastore
73 // cppcheck-suppress danglingLifetime; false positive
74 m_menuJSON_hlt->setStore(aux_hlt.get());
75
76 ATH_CHECK(m_metaStore->record(std::move(aux_hlt), m_metaNameJSON_hlt + "Aux."));
77 ATH_CHECK(m_metaStore->record(std::move(hlt), m_metaNameJSON_hlt));
78
79 // HLT Monitoring JSON object - contains Monitoring groups for HLT menus
80 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_hltmonitoring = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
81 std::unique_ptr<xAOD::TriggerMenuJsonContainer> hltmonitoring = std::make_unique<xAOD::TriggerMenuJsonContainer>();
82 // cppcheck-suppress danglingLifetime; false positive
83 m_menuJSON_hltmonitoring = hltmonitoring.get(); // Keep a cached pointer from which we can add to the output metastore
84 // cppcheck-suppress danglingLifetime; false positive
85 m_menuJSON_hltmonitoring->setStore(aux_hltmonitoring.get());
86
87 ATH_CHECK(m_metaStore->record(std::move(aux_hltmonitoring), m_metaNameJSON_hltmonitoring + "Aux."));
88 ATH_CHECK(m_metaStore->record(std::move(hltmonitoring), m_metaNameJSON_hltmonitoring));
89
90 // L1 JSON object - contains L1 menus
91 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_l1 = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
92 std::unique_ptr<xAOD::TriggerMenuJsonContainer> l1 = std::make_unique<xAOD::TriggerMenuJsonContainer>();
93 // cppcheck-suppress danglingLifetime; false positive
94 m_menuJSON_l1 = l1.get(); // Keep a cached pointer from which we can add to the output metastore
95 // cppcheck-suppress danglingLifetime; false positive
96 m_menuJSON_l1->setStore(aux_l1.get());
97
98 ATH_CHECK(m_metaStore->record(std::move(aux_l1), m_metaNameJSON_l1 + "Aux."));
99 ATH_CHECK(m_metaStore->record(std::move(l1), m_metaNameJSON_l1));
100
101 // HLT PS JSON object - contains prescales sets for HLT menus
102 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_hltps = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
103 std::unique_ptr<xAOD::TriggerMenuJsonContainer> hltps = std::make_unique<xAOD::TriggerMenuJsonContainer>();
104 // cppcheck-suppress danglingLifetime; false positive
105 m_menuJSON_hltps = hltps.get(); // Keep a cached pointer from which we can add to the output metastore
106 // cppcheck-suppress danglingLifetime; false positive
107 m_menuJSON_hltps->setStore(aux_hltps.get());
108
109 ATH_CHECK(m_metaStore->record(std::move(aux_hltps), m_metaNameJSON_hltps + "Aux."));
110 ATH_CHECK(m_metaStore->record(std::move(hltps), m_metaNameJSON_hltps));
111
112 // L1 PS JSON object - contains prescales sets for L1 menus
113 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_l1ps = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
114 std::unique_ptr<xAOD::TriggerMenuJsonContainer> l1ps = std::make_unique<xAOD::TriggerMenuJsonContainer>();
115 // cppcheck-suppress danglingLifetime; false positive
116 m_menuJSON_l1ps = l1ps.get(); // Keep a cached pointer from which we can add to the output metastore
117 // cppcheck-suppress danglingLifetime; false positive
118 m_menuJSON_l1ps->setStore(aux_l1ps.get());
119
120 ATH_CHECK(m_metaStore->record(std::move(aux_l1ps), m_metaNameJSON_l1ps + "Aux."));
121 ATH_CHECK(m_metaStore->record(std::move(l1ps), m_metaNameJSON_l1ps));
122
123 // Bunchgroup JSON object - contains bungchgroup configuration
124 std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_bg = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
125 std::unique_ptr<xAOD::TriggerMenuJsonContainer> bg = std::make_unique<xAOD::TriggerMenuJsonContainer>();
126 // cppcheck-suppress danglingLifetime; false positive
127 m_menuJSON_bg = bg.get(); // Keep a cached pointer from which we can add to the output metastore
128 // cppcheck-suppress danglingLifetime; false positive
129 m_menuJSON_bg->setStore( aux_bg.get() );
130
131 ATH_CHECK( m_metaStore->record(std::move(aux_bg), m_metaNameJSON_bg + "Aux." ) );
132 ATH_CHECK( m_metaStore->record(std::move(bg), m_metaNameJSON_bg ) );
133
134 // Return gracefully:
135 return StatusCode::SUCCESS;
136 }
137
138 StatusCode xAODMenuWriter::execute(const EventContext &ctx) const
139 {
140
141 // Create the keys in the "internal format":
142 TrigKey_t ckeys;
143
144 // Write to SG via writer tool.
145 // Get keys back via pass-by-reference
146 ATH_CHECK(m_keyWriterTool->writeKeys(ctx, /*SMK*/ ckeys.first, /*L1PSK*/ ckeys.second.first, /*HLTPSK*/ ckeys.second.second));
147
148 uint32_t bunchgroupKey = 0;
149 ATH_CHECK(m_keyWriterTool->writeBunchgroupKey(ctx, bunchgroupKey));
150
151 // The following code must only run on one event at a time
152 std::lock_guard<std::mutex> lock(m_mutex);
153
154 if (!m_converted_smk.insert(ckeys.first).second) {
155 ATH_MSG_VERBOSE("Already converted SMK: " << ckeys.first);
156 } else {
157 ATH_MSG_DEBUG("Filling HLT Menu information for SMK:" << ckeys.first);
159 ATH_CHECK(hltMenuHandle.isValid());
160 std::stringstream hltTriggerMenuJson;
161 hltMenuHandle->printRaw(hltTriggerMenuJson);
163 m_menuJSON_hlt->push_back(hlt); // Now owned by MetaDataStore
164 hlt->setKey(ckeys.first);
165 hlt->setName(hltMenuHandle->name());
166 hlt->setPayload(hltTriggerMenuJson.str());
168 ATH_MSG_DEBUG("Filling HLT Monitoring information for SMK:" << ckeys.first);
170 if (hltMonitoringHandle.isValid()) {
171 std::stringstream hltMonitoringJson;
172 hltMonitoringHandle->printRaw(hltMonitoringJson);
173 xAOD::TriggerMenuJson *hltmonitoring = new xAOD::TriggerMenuJson();
174 m_menuJSON_hltmonitoring->push_back(hltmonitoring); // Now owned by MetaDataStore
175 hltmonitoring->setKey(ckeys.first);
176 hltmonitoring->setName(hltMonitoringHandle->name());
177 hltmonitoring->setPayload(hltMonitoringJson.str());
178 } else {
179 ATH_MSG_DEBUG("No HLT Monitoring JSON available - skipping.");
180 }
182 ATH_MSG_DEBUG("Filling L1 information for SMK:" << ckeys.first);
184 ATH_CHECK(l1MenuHandle.isValid());
185 std::stringstream l1TriggerMenuJson;
186 l1MenuHandle->printRaw(l1TriggerMenuJson);
188 m_menuJSON_l1->push_back(l1); // Now owned by MetaDataStore
189 l1->setKey(ckeys.first);
190 l1->setName(l1MenuHandle->name());
191 l1->setPayload(l1TriggerMenuJson.str());
192 }
193
194 if (!m_converted_hltpsk.insert(ckeys.second.second).second) {
195 ATH_MSG_VERBOSE("Already converted HLTPSK: " << ckeys.second.second);
196 } else {
197 ATH_MSG_DEBUG("Filling prescale information for HLTPSK:" << ckeys.second.second);
199 ATH_CHECK(hltPSHandle.isValid());
200 std::stringstream hltPSJSON;
201 hltPSHandle->printRaw(hltPSJSON);
203 m_menuJSON_hltps->push_back(hltps); // Now owned by MetaDataStore
204 hltps->setKey(ckeys.second.second);
205 hltps->setName(hltPSHandle->name());
206 hltps->setPayload(hltPSJSON.str());
207 }
208
209 if (!m_converted_l1psk.insert(ckeys.second.first).second) {
210 ATH_MSG_VERBOSE("Already converted LVL1PSK: " << ckeys.second.first);
211 } else {
212 ATH_MSG_DEBUG("Filling prescale information for LVL1PSK:" << ckeys.second.first);
214 ATH_CHECK(l1PSHandle.isValid());
215 std::stringstream l1PSJSON;
216 l1PSHandle->printRaw(l1PSJSON);
218 m_menuJSON_l1ps->push_back(l1ps); // Now owned by MetaDataStore
219 l1ps->setKey(ckeys.second.first);
220 l1ps->setName(l1PSHandle->name());
221 l1ps->setPayload(l1PSJSON.str());
222 }
223
224 if (!m_converted_bg.insert(bunchgroupKey).second) {
225 ATH_MSG_VERBOSE("Already converted Bunchgroup Key: " << bunchgroupKey);
226 } else {
227 ATH_MSG_DEBUG("Filling prescale information for Bunchgroup Key:" << bunchgroupKey);
229 ATH_CHECK(bunchgroupHandle.isValid());
230 std::stringstream l1BunchgroupJSON;
231 bunchgroupHandle->printRaw(l1BunchgroupJSON);
233 m_menuJSON_bg->push_back(l1bg); // Now owned by MetaDataStore
234 l1bg->setKey(bunchgroupKey);
235 l1bg->setName(bunchgroupHandle->name());
236 l1bg->setPayload(l1BunchgroupJSON.str());
237 }
238
239 // Return gracefully:
240 return StatusCode::SUCCESS;
241 }
242
243}
#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.