ATLAS Offline Software
xAODMenuWriterMT.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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 "xAODMenuWriterMT.h"
32 #include "PrintVectorHelper.h"
33 #include "KeyWriterTool.h"
34 
35 namespace TrigConf
36 {
37 
39  ISvcLocator *svcLoc)
40  : AthReentrantAlgorithm(name, svcLoc),
41  m_metaStore("MetaDataStore", name)
42  {
43  }
44 
46  {
47 
48  // Greet the user:
49  ATH_MSG_INFO("Initialising");
50  ATH_MSG_VERBOSE("MetaDataStore = " << m_metaStore);
51 
52  // Retrieve the necessary service(s):
53  ATH_CHECK(m_metaStore.retrieve());
54 
55  ATH_CHECK(m_keyWriterTool.retrieve());
56 
57  ATH_CHECK(m_HLTMenuKey.initialize()); // ReadHandleKey, but DetStore (so renounce)
59  ATH_CHECK(m_HLTMonitoringKey.initialize()); // ReadHandleKey, but DetStore (so renounce)
61  ATH_CHECK(m_HLTPrescaleSetInputKey.initialize()); // ReadCondHandleKey
62 
63  ATH_CHECK(m_L1MenuKey.initialize()); // ReadHandleKey, but DetStore (so renounce)
65  ATH_CHECK(m_L1PrescaleSetInputKey.initialize()); // ReadCondHandleKey
66 
67  ATH_CHECK(m_bgInputKey.initialize()); // ReadCondHandleKey
68 
69  // HLT JSON object - contains HLT menus
70  std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_hlt = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
71  std::unique_ptr<xAOD::TriggerMenuJsonContainer> hlt = std::make_unique<xAOD::TriggerMenuJsonContainer>();
72  // cppcheck-suppress danglingLifetime; false positive
73  m_menuJSON_hlt = hlt.get(); // Keep a cached pointer from which we can add to the output metastore
74  // cppcheck-suppress danglingLifetime; false positive
75  m_menuJSON_hlt->setStore(aux_hlt.get());
76 
77  ATH_CHECK(m_metaStore->record(std::move(aux_hlt), m_metaNameJSON_hlt + "Aux."));
78  ATH_CHECK(m_metaStore->record(std::move(hlt), m_metaNameJSON_hlt));
79 
80  // HLT Monitoring JSON object - contains Monitoring groups for HLT menus
81  std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_hltmonitoring = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
82  std::unique_ptr<xAOD::TriggerMenuJsonContainer> hltmonitoring = std::make_unique<xAOD::TriggerMenuJsonContainer>();
83  // cppcheck-suppress danglingLifetime; false positive
84  m_menuJSON_hltmonitoring = hltmonitoring.get(); // Keep a cached pointer from which we can add to the output metastore
85  // cppcheck-suppress danglingLifetime; false positive
86  m_menuJSON_hltmonitoring->setStore(aux_hltmonitoring.get());
87 
88  ATH_CHECK(m_metaStore->record(std::move(aux_hltmonitoring), m_metaNameJSON_hltmonitoring + "Aux."));
89  ATH_CHECK(m_metaStore->record(std::move(hltmonitoring), m_metaNameJSON_hltmonitoring));
90 
91  // L1 JSON object - contains L1 menus
92  std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_l1 = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
93  std::unique_ptr<xAOD::TriggerMenuJsonContainer> l1 = std::make_unique<xAOD::TriggerMenuJsonContainer>();
94  // cppcheck-suppress danglingLifetime; false positive
95  m_menuJSON_l1 = l1.get(); // Keep a cached pointer from which we can add to the output metastore
96  // cppcheck-suppress danglingLifetime; false positive
97  m_menuJSON_l1->setStore(aux_l1.get());
98 
99  ATH_CHECK(m_metaStore->record(std::move(aux_l1), m_metaNameJSON_l1 + "Aux."));
100  ATH_CHECK(m_metaStore->record(std::move(l1), m_metaNameJSON_l1));
101 
102  // HLT PS JSON object - contains prescales sets for HLT menus
103  std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_hltps = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
104  std::unique_ptr<xAOD::TriggerMenuJsonContainer> hltps = std::make_unique<xAOD::TriggerMenuJsonContainer>();
105  // cppcheck-suppress danglingLifetime; false positive
106  m_menuJSON_hltps = hltps.get(); // Keep a cached pointer from which we can add to the output metastore
107  // cppcheck-suppress danglingLifetime; false positive
108  m_menuJSON_hltps->setStore(aux_hltps.get());
109 
110  ATH_CHECK(m_metaStore->record(std::move(aux_hltps), m_metaNameJSON_hltps + "Aux."));
111  ATH_CHECK(m_metaStore->record(std::move(hltps), m_metaNameJSON_hltps));
112 
113  // L1 PS JSON object - contains prescales sets for L1 menus
114  std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_l1ps = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
115  std::unique_ptr<xAOD::TriggerMenuJsonContainer> l1ps = std::make_unique<xAOD::TriggerMenuJsonContainer>();
116  // cppcheck-suppress danglingLifetime; false positive
117  m_menuJSON_l1ps = l1ps.get(); // Keep a cached pointer from which we can add to the output metastore
118  // cppcheck-suppress danglingLifetime; false positive
119  m_menuJSON_l1ps->setStore(aux_l1ps.get());
120 
121  ATH_CHECK(m_metaStore->record(std::move(aux_l1ps), m_metaNameJSON_l1ps + "Aux."));
122  ATH_CHECK(m_metaStore->record(std::move(l1ps), m_metaNameJSON_l1ps));
123 
124  // Bunchgroup JSON object - contains bungchgroup configuration
125  std::unique_ptr<xAOD::TriggerMenuJsonAuxContainer> aux_bg = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>();
126  std::unique_ptr<xAOD::TriggerMenuJsonContainer> bg = std::make_unique<xAOD::TriggerMenuJsonContainer>();
127  // cppcheck-suppress danglingLifetime; false positive
128  m_menuJSON_bg = bg.get(); // Keep a cached pointer from which we can add to the output metastore
129  // cppcheck-suppress danglingLifetime; false positive
130  m_menuJSON_bg->setStore( aux_bg.get() );
131 
132  ATH_CHECK( m_metaStore->record(std::move(aux_bg), m_metaNameJSON_bg + "Aux." ) );
133  ATH_CHECK( m_metaStore->record(std::move(bg), m_metaNameJSON_bg ) );
134 
135  // Return gracefully:
136  return StatusCode::SUCCESS;
137  }
138 
139  StatusCode xAODMenuWriterMT::execute(const EventContext &ctx) const
140  {
141 
142  // Create the keys in the "internal format":
143  TrigKey_t ckeys;
144 
145  // Write to SG via writer tool.
146  // Get keys back via pass-by-reference
147  ATH_CHECK(m_keyWriterTool->writeKeys(ctx, /*SMK*/ ckeys.first, /*L1PSK*/ ckeys.second.first, /*HLTPSK*/ ckeys.second.second));
148 
149  uint32_t bunchgroupKey = 0;
150  ATH_CHECK(m_keyWriterTool->writeBunchgroupKey(ctx, bunchgroupKey));
151 
152  // The following code must only run on one event at a time
153  std::lock_guard<std::mutex> lock(m_mutex);
154 
155  if (!m_converted_smk.insert(ckeys.first).second) {
156  ATH_MSG_VERBOSE("Already converted SMK: " << ckeys.first);
157  } else {
158  ATH_MSG_DEBUG("Filling HLT Menu information for SMK:" << ckeys.first);
160  ATH_CHECK(hltMenuHandle.isValid());
161  std::stringstream hltTriggerMenuJson;
162  hltMenuHandle->printRaw(hltTriggerMenuJson);
164  m_menuJSON_hlt->push_back(hlt); // Now owned by MetaDataStore
165  hlt->setKey(ckeys.first);
166  hlt->setName(hltMenuHandle->name());
167  hlt->setPayload(hltTriggerMenuJson.str());
169  ATH_MSG_DEBUG("Filling HLT Monitoring information for SMK:" << ckeys.first);
171  if (hltMonitoringHandle.isValid()) {
172  std::stringstream hltMonitoringJson;
173  hltMonitoringHandle->printRaw(hltMonitoringJson);
174  xAOD::TriggerMenuJson *hltmonitoring = new xAOD::TriggerMenuJson();
175  m_menuJSON_hltmonitoring->push_back(hltmonitoring); // Now owned by MetaDataStore
176  hltmonitoring->setKey(ckeys.first);
177  hltmonitoring->setName(hltMonitoringHandle->name());
178  hltmonitoring->setPayload(hltMonitoringJson.str());
179  } else {
180  ATH_MSG_DEBUG("No HLT Monitoring JSON available - skipping.");
181  }
183  ATH_MSG_DEBUG("Filling L1 information for SMK:" << ckeys.first);
185  ATH_CHECK(l1MenuHandle.isValid());
186  std::stringstream l1TriggerMenuJson;
187  l1MenuHandle->printRaw(l1TriggerMenuJson);
189  m_menuJSON_l1->push_back(l1); // Now owned by MetaDataStore
190  l1->setKey(ckeys.first);
191  l1->setName(l1MenuHandle->name());
192  l1->setPayload(l1TriggerMenuJson.str());
193  }
194 
195  if (!m_converted_hltpsk.insert(ckeys.second.second).second) {
196  ATH_MSG_VERBOSE("Already converted HLTPSK: " << ckeys.second.second);
197  } else {
198  ATH_MSG_DEBUG("Filling prescale information for HLTPSK:" << ckeys.second.second);
200  ATH_CHECK(hltPSHandle.isValid());
201  std::stringstream hltPSJSON;
202  hltPSHandle->printRaw(hltPSJSON);
204  m_menuJSON_hltps->push_back(hltps); // Now owned by MetaDataStore
205  hltps->setKey(ckeys.second.second);
206  hltps->setName(hltPSHandle->name());
207  hltps->setPayload(hltPSJSON.str());
208  }
209 
210  if (!m_converted_l1psk.insert(ckeys.second.first).second) {
211  ATH_MSG_VERBOSE("Already converted LVL1PSK: " << ckeys.second.first);
212  } else {
213  ATH_MSG_DEBUG("Filling prescale information for LVL1PSK:" << ckeys.second.first);
215  ATH_CHECK(l1PSHandle.isValid());
216  std::stringstream l1PSJSON;
217  l1PSHandle->printRaw(l1PSJSON);
219  m_menuJSON_l1ps->push_back(l1ps); // Now owned by MetaDataStore
220  l1ps->setKey(ckeys.second.first);
221  l1ps->setName(l1PSHandle->name());
222  l1ps->setPayload(l1PSJSON.str());
223  }
224 
225  if (!m_converted_bg.insert(bunchgroupKey).second) {
226  ATH_MSG_VERBOSE("Already converted Bunchgroup Key: " << bunchgroupKey);
227  } else {
228  ATH_MSG_DEBUG("Filling prescale information for Bunchgroup Key:" << bunchgroupKey);
230  ATH_CHECK(bunchgroupHandle.isValid());
231  std::stringstream l1BunchgroupJSON;
232  bunchgroupHandle->printRaw(l1BunchgroupJSON);
234  m_menuJSON_bg->push_back(l1bg); // Now owned by MetaDataStore
235  l1bg->setKey(bunchgroupKey);
236  l1bg->setName(bunchgroupHandle->name());
237  l1bg->setPayload(l1BunchgroupJSON.str());
238  }
239 
240  // Return gracefully:
241  return StatusCode::SUCCESS;
242  }
243 
244 }
TriggerItem.h
CTPConfig.h
PrescaleSet.h
HLTChainList.h
StandaloneBunchgroupHandler.bg
bg
Definition: StandaloneBunchgroupHandler.py:243
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TriggerMenuJson.h
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
KeyWriterTool.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::TriggerMenuJson_v1::setKey
void setKey(uint32_t value)
Set the key of this configuration.
TrigConf::xAODMenuWriterMT::execute
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
Definition: xAODMenuWriterMT.cxx:139
TrigConf::xAODMenuWriterMT::m_keyWriterTool
ToolHandle< IKeyWriterTool > m_keyWriterTool
Definition: xAODMenuWriterMT.h:109
TriggerMenuAuxContainer.h
HLTChain.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::renounce
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)
Definition: AthCommonDataStore.h:380
HLTPrescale.h
TrigConf::xAODMenuWriterMT::m_metaStore
ServiceHandle< StoreGateSvc > m_metaStore
Definition: xAODMenuWriterMT.h:106
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
TrigConf::xAODMenuWriterMT::m_L1PrescaleSetInputKey
SG::ReadCondHandleKey< TrigConf::L1PrescalesSet > m_L1PrescaleSetInputKey
Definition: xAODMenuWriterMT.h:82
TrigConf::xAODMenuWriterMT::m_metaNameJSON_hltps
Gaudi::Property< std::string > m_metaNameJSON_hltps
Definition: xAODMenuWriterMT.h:97
Menu.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TrigConf::DataStructure::name
virtual const std::string & name() const final
Definition: DataStructure.cxx:109
TrigConf::xAODMenuWriterMT::initialize
virtual StatusCode initialize() override
Function initialising the algorithm.
Definition: xAODMenuWriterMT.cxx:45
TrigConf::xAODMenuWriterMT::m_HLTMonitoringKey
SG::ReadHandleKey< TrigConf::HLTMonitoring > m_HLTMonitoringKey
Definition: xAODMenuWriterMT.h:73
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigConf::xAODMenuWriterMT::m_bgInputKey
SG::ReadCondHandleKey< TrigConf::L1BunchGroupSet > m_bgInputKey
Definition: xAODMenuWriterMT.h:85
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition: Config.h:22
TrigConf::xAODMenuWriterMT::m_metaNameJSON_l1
Gaudi::Property< std::string > m_metaNameJSON_l1
Definition: xAODMenuWriterMT.h:94
TrigConf::xAODMenuWriterMT::m_metaNameJSON_hltmonitoring
Gaudi::Property< std::string > m_metaNameJSON_hltmonitoring
Definition: xAODMenuWriterMT.h:91
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TriggerMenuJsonAuxContainer.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HLTSignature.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigConf::xAODMenuWriterMT::m_L1MenuKey
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
Definition: xAODMenuWriterMT.h:76
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigConf::name
Definition: HLTChainList.h:35
TriggerMenu.h
BunchGroup.h
xAOD::TriggerMenuJson_v1::setPayload
void setPayload(const std::string &payload)
Set the JSON payload.
BunchGroupSet.h
L1BunchGroupSet.h
TrigConf::xAODMenuWriterMT::m_HLTMenuKey
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
Definition: xAODMenuWriterMT.h:70
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TrigConf::xAODMenuWriterMT::m_metaNameJSON_hlt
Gaudi::Property< std::string > m_metaNameJSON_hlt
Definition: xAODMenuWriterMT.h:88
TrigConf::DataStructure::printRaw
void printRaw(std::ostream &os=std::cout) const
Definition: DataStructure.cxx:265
xAOD::TriggerMenuJson_v1::setName
void setName(const std::string &name)
Set the name key of this configuration.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
HLTTriggerElement.h
xAOD::TriggerMenuJson_v1
Raw JSON data for a given type of menu file.
Definition: TriggerMenuJson_v1.h:26
TrigConf::xAODMenuWriterMT::m_mutex
std::mutex m_mutex
The mutex to prevent us from writing more than one configuration at a time.
Definition: xAODMenuWriterMT.h:130
TrigConf::xAODMenuWriterMT::m_metaNameJSON_l1ps
Gaudi::Property< std::string > m_metaNameJSON_l1ps
Definition: xAODMenuWriterMT.h:100
HLTSequenceList.h
xAOD::TriggerMenuJson
TriggerMenuJson_v1 TriggerMenuJson
Define the latest version of the trigger menu JSON class.
Definition: TriggerMenuJson.h:15
PrintVectorHelper.h
skel.l1
l1
Definition: skel.GENtoEVGEN.py:425
TrigConf::xAODMenuWriterMT::m_HLTPrescaleSetInputKey
SG::ReadCondHandleKey< TrigConf::HLTPrescalesSet > m_HLTPrescaleSetInputKey
Definition: xAODMenuWriterMT.h:79
xAODMenuWriterMT.h
TrigConf::xAODMenuWriterMT::xAODMenuWriterMT
xAODMenuWriterMT(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: xAODMenuWriterMT.cxx:38
TrigConf::xAODMenuWriterMT::TrigKey_t
std::pair< uint32_t, std::pair< uint32_t, uint32_t > > TrigKey_t
Trigger configuration key type (used just internally)
Definition: xAODMenuWriterMT.h:113
TrigConf::xAODMenuWriterMT::m_metaNameJSON_bg
Gaudi::Property< std::string > m_metaNameJSON_bg
Definition: xAODMenuWriterMT.h:103