ATLAS Offline Software
Loading...
Searching...
No Matches
TriggerMenuMetaDataTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: TriggerMenuMetaDataTool.cxx 683395 2015-07-16 11:11:56Z krasznaa $
6
7// System include(s):
8#include <memory>
9
10#include <stdexcept>
11
12// Hack to initialise decoration accessors for Trigger EDM in offline jobs
13// starting from ESD or later, see ATR-22421
14#if !defined(XAOD_STANDALONE) && !defined(XAOD_ANALYSIS)
16#endif
17
18// Local include(s):
20
21namespace xAODMaker {
22
23 std::mutex TriggerMenuMetaDataTool::s_mutex;
24
26 : asg::AsgMetadataTool( name ),
28
29
30
31#ifndef XAOD_STANDALONE
32 declareInterface< ::IMetaDataTool >( this );
33#endif // XAOD_STANDALONE
34
35 declareProperty("InputKey", m_inputKey = "TriggerMenu");
36 declareProperty("OutputKey", m_outputKey = "TriggerMenu");
37 declareProperty("InputKeyJSON_HLT", m_inputKeyJSON_HLT = "TriggerMenuJson_HLT");
38 declareProperty("OutputKeyJSON_HLT", m_outputKeyJSON_HLT = "TriggerMenuJson_HLT");
39 declareProperty("InputKeyJSON_HLTMonitoring", m_inputKeyJSON_HLTMonitoring = "TriggerMenuJson_HLTMonitoring");
40 declareProperty("OutputKeyJSON_HLTMonitoring", m_outputKeyJSON_HLTMonitoring = "TriggerMenuJson_HLTMonitoring");
41 declareProperty("InputKeyJSON_L1", m_inputKeyJSON_L1 = "TriggerMenuJson_L1");
42 declareProperty("OutputKeyJSON_L1", m_outputKeyJSON_L1 = "TriggerMenuJson_L1");
43 declareProperty("InputKeyJSON_HLTPS", m_inputKeyJSON_HLTPS = "TriggerMenuJson_HLTPS");
44 declareProperty("OutputKeyJSON_HLTPS", m_outputKeyJSON_HLTPS = "TriggerMenuJson_HLTPS");
45 declareProperty("InputKeyJSON_L1PS", m_inputKeyJSON_L1PS = "TriggerMenuJson_L1PS");
46 declareProperty("OutputKeyJSON_L1PS", m_outputKeyJSON_L1PS = "TriggerMenuJson_L1PS");
47 declareProperty("InputKeyJSON_BG", m_inputKeyJSON_BG = "TriggerMenuJson_BG");
48 declareProperty("OutputKeyJSON_BG", m_outputKeyJSON_BG = "TriggerMenuJson_BG");
49 }
50
52
53 // Greet the user:
54 ATH_MSG_DEBUG( "Initialising TriggerMenuMetaDataTool" );
55
56
57 // Reset the internal variable(s):
58 m_menu.reset();
59 m_menuAux.reset();
60 m_menuJSON_hlt.reset();
61 m_menuJSON_hltAux.reset();
64 m_menuJSON_l1.reset();
65 m_menuJSON_l1Aux.reset();
66 m_menuJSON_hltps.reset();
67 m_menuJSON_hltpsAux.reset();
68 m_menuJSON_l1ps.reset();
69 m_menuJSON_l1psAux.reset();
70 m_menuJSON_bg.reset();
71 m_menuJSON_bgAux.reset();
72
74
75 // Return gracefully:
76 return StatusCode::SUCCESS;
77 }
78
80 // Return gracefully:
81 return StatusCode::SUCCESS;
82 }
84 // Whatever happens, we've seen the first BeginInputFile incident now.
88 return StatusCode::SUCCESS;
89 }
90
92 // If the input file doesn't have any trigger configuration metadata,
93 // then finish right away:
95 m_inputKey ) ) {
96 return StatusCode::SUCCESS;
97 }
98
99 // Retrieve the input container:
100 const xAOD::TriggerMenuContainer* input = nullptr;
101 ATH_CHECK( inputMetaStore()->retrieve( input, m_inputKey ) );
102
103 // Create an internal container if it doesn't exist yet:
104 if( ( ! m_menu.get() ) && ( ! m_menuAux.get() ) ) {
105 ATH_MSG_DEBUG( "Creating internal container" );
106 m_menu = std::make_unique<xAOD::TriggerMenuContainer>( );
107 m_menuAux = std::make_unique<xAOD::TriggerMenuAuxContainer>( );
108 m_menu->setStore( m_menuAux.get() );
109 }
110
111 // Copy (and de-duplicate) from the input collection to the internal collection
112 ATH_CHECK( doCopyxAODTriggerMenu(input, m_menu.get()) );
113
114 // Return gracefully:
115 return StatusCode::SUCCESS;
116 }
117
119 // Loop over the configurations of the copyFrom collection:
120 for( const xAOD::TriggerMenu* menu : *copyFrom ) {
121
122 // Check if this configuration is already in the copyTo container:
123 bool exists = false;
124 for( const xAOD::TriggerMenu* existing : *copyTo ) {
125 if( ( existing->smk() == menu->smk() ) &&
126 ( existing->l1psk() == menu->l1psk() ) &&
127 ( existing->hltpsk() == menu->hltpsk() ) ) {
128 exists = true;
129 break;
130 }
131 }
132 if( exists ) {
133 continue;
134 }
135
136 // If it's a new configuration, put it into the copyTo container:
137 ATH_MSG_VERBOSE( "Copying configuration with SMK: "
138 << menu->smk() << ", L1PSK: " << menu->l1psk()
139 << ", HLTPSK: " << menu->hltpsk() );
141 copyTo->push_back( out );
142 *out = *menu;
143 }
144 return StatusCode::SUCCESS;
145 }
146
156
157 StatusCode TriggerMenuMetaDataTool::checkCopyJson(const std::string& inputMetaSGKey,
158 std::unique_ptr< xAOD::TriggerMenuJsonContainer >& internalContainer,
159 std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer >& internalAuxContainer)
160 {
161
163 return StatusCode::SUCCESS;
164 }
165
166 const xAOD::TriggerMenuJsonContainer* input = nullptr;
167 if (inputMetaStore()->retrieve( input, inputMetaSGKey ).isSuccess() ) {
168
169 // Create an internal container if it doesn't exist yet:
170 if( ( ! internalContainer.get() ) && ( ! internalAuxContainer.get() ) ) {
171 ATH_MSG_DEBUG( "Creating internal container" );
172 internalContainer = std::make_unique<xAOD::TriggerMenuJsonContainer>( );
173 internalAuxContainer = std::make_unique<xAOD::TriggerMenuJsonAuxContainer>( );
174 internalContainer->setStore( internalAuxContainer.get() );
175 }
176
177 // Copy (and de-duplicate) from the input collection to the internal collection
178 ATH_CHECK( doCopyxAODTriggerMenuJson(inputMetaSGKey, input, internalContainer.get()) );
179 }
180 return StatusCode::SUCCESS;
181 }
182
183 StatusCode TriggerMenuMetaDataTool::doCopyxAODTriggerMenuJson(const std::string& inputMetaSGKey,
184 const xAOD::TriggerMenuJsonContainer* copyFrom,
186 {
187 // Loop over the configurations of the copyFrom input:
188 for( const xAOD::TriggerMenuJson* menuJson : *copyFrom ) {
189 // Check if this configuration is already in the copyTo container:
190 bool exists = false;
191 for( const xAOD::TriggerMenuJson* existing : *copyTo ) {
192 if (existing->key() == menuJson->key()) {
193 exists = true;
194 break;
195 }
196 }
197 if( exists ) {
198 continue;
199 }
200
201 // If it's a new configuration, put it into the copyTo container:
202 ATH_MSG_VERBOSE( "Copying " << inputMetaSGKey << " configuration with Key: " << menuJson->key() );
204 copyTo->push_back( out );
205 *out = *menuJson;
206 }
207 return StatusCode::SUCCESS;
208 }
209
211
212 // In case the BeginInputFile incident was missed in standalone mode, make
213 // sure that the metadata from the first input file is collected at this
214 // point at least.
217 }
218
219 // Return gracefully:
220 return StatusCode::SUCCESS;
221 }
222
224 // Note: Copying into a given collection in the output store should only be done
225 // by a single thread at a time.
226 std::scoped_lock lock(s_mutex);
227
230 return StatusCode::SUCCESS;
231 }
232
234 // The output may already have trigger configuration metadata in it.
235 // For instance from TrigConf::xAODMenuWriter or other instances of the
236 // TriggerMenuMetaDataTool in MP mode. Merge into the output
237
238 // If we don't have an internal store then nothing to do
239 if( ( ! m_menu.get() ) && ( ! m_menuAux.get() ) ) {
240 ATH_MSG_DEBUG( "No internal xAOD::TriggerMenu store to save/merge to output. (Expected in Run 3)." );
241 return StatusCode::SUCCESS;
242 }
243
245 // No output yet - hand over ownership of our internal store
246 ATH_MSG_DEBUG( "Recording xAOD::TriggerMenu trigger configuration metadata container with " << m_menu->size() << " entries." );
247 ATH_CHECK( outputMetaStore()->record( m_menu.release(),
248 m_outputKey ) );
249 ATH_CHECK( outputMetaStore()->record( m_menuAux.release(),
250 m_outputKey + "Aux." ) );
251 } else {
252 // Merge into the existing output store
253 ATH_MSG_DEBUG( "Merging into existing output xAOD::TriggerMenu configuration metadata container" );
254 xAOD::TriggerMenuContainer* output = nullptr;
255 ATH_CHECK( outputMetaStore()->retrieve( output, m_outputKey ) );
256 // Copy (and de-duplicate) from the internal collection to the output collection
257 ATH_CHECK( doCopyxAODTriggerMenu(m_menu.get(), output) );
258 }
259
260 // Return gracefully:
261 return StatusCode::SUCCESS;
262 }
263
273
274 StatusCode TriggerMenuMetaDataTool::checkExportJson(const std::string& outputMetaSGKey,
275 std::unique_ptr< xAOD::TriggerMenuJsonContainer >& internalContainer,
276 std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer >& internalAuxContainer)
277 {
278
279 // The output may already have trigger configuration metadata in it.
280 // For instance from TrigConf::xAODMenuWriter or other instances of the
281 // TriggerMenuMetaDataTool in MP mode. Merge into the output
282
283 // If we don't have an internal store then nothing to do
284 if( ( ! internalContainer.get() ) && ( ! internalAuxContainer.get() ) ) {
285 ATH_MSG_DEBUG( "No internal xAOD::TriggerJsonMenu " << outputMetaSGKey
286 << " store to save/merge to output. (Expected for Run 2 MC, release 21 data, or the BG data as this is not added as of Dec 21)." );
287 return StatusCode::SUCCESS;
288 }
289
290 if( not outputMetaStore()->contains< xAOD::TriggerMenuJsonContainer >( outputMetaSGKey ) ) {
291 // No output yet - hand over ownership of our internal store
292 ATH_MSG_DEBUG( "Recording " << outputMetaSGKey << " xAOD::TriggerMenuJson trigger configuration metadata container with "
293 << internalContainer->size() << " entries" );
294 ATH_CHECK( outputMetaStore()->record( internalContainer.release(),
295 outputMetaSGKey ) );
296 ATH_CHECK( outputMetaStore()->record( internalAuxContainer.release(),
297 outputMetaSGKey + "Aux." ) );
298 } else {
299 // Merge into the existing output store
300 ATH_MSG_DEBUG( "Merging into existing " << outputMetaSGKey << " output xAOD::TriggerMenuJson configuration metadata container" );
301 xAOD::TriggerMenuJsonContainer* output = nullptr;
302 ATH_CHECK( outputMetaStore()->retrieve( output, outputMetaSGKey ) );
303 // Copy (and de-duplicate) from the internal collection to the output collection
304 ATH_CHECK( doCopyxAODTriggerMenuJson(outputMetaSGKey, internalContainer.get(), output) );
305 }
306
307 // Return gracefully:
308 return StatusCode::SUCCESS;
309 }
310
311} // namespace xAODMaker
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
MetaStorePtr_t outputMetaStore() const
Accessor for the output metadata store.
AsgMetadataTool(const std::string &name)
Normal ASG tool constructor with a name.
MetaStorePtr_t inputMetaStore() const
Accessor for the input metadata store.
make the sidebar many part of the config
Definition hcg.cxx:552
virtual StatusCode beginEvent()
Function used to make sure that file openings are not missed.
std::unique_ptr< xAOD::TriggerMenuJsonContainer > m_menuJSON_l1
StatusCode checkxAODTriggerMenu()
Perform the R2 data copy from the input metastore to the internal metastore.
std::string m_outputKey
The key of the trigger menu for the output file.
std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer > m_menuJSON_bgAux
StatusCode checkCopyJson(const std::string &inputMetaSGKey, std::unique_ptr< xAOD::TriggerMenuJsonContainer > &internalContainer, std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer > &internalAuxContainer)
Helper function to do the R3 data copy to the internal store for a given JSON.
virtual StatusCode initialize()
Function initialising the tool.
std::unique_ptr< xAOD::TriggerMenuAuxContainer > m_menuAux
The merged trigger menu auxiliary container.
std::string m_inputKey
The key of the trigger menu in the input file.
bool m_beginFileIncidentSeen
Internal status flag showing whether a BeginInputFile incident was seen already.
StatusCode doCopyxAODTriggerMenu(const xAOD::TriggerMenuContainer *copyFrom, xAOD::TriggerMenuContainer *copyTo)
Common code to copy and de-duplicate menus from the copyFrom collection into the copyTo collection.
StatusCode checkxAODTriggerMenuJson()
Perform the R3 data copy from the input metastore to the internal metastore.
virtual StatusCode metaDataStop()
Function writing out the collected metadata.
virtual StatusCode beginInputFile()
Function collecting the trigger configuration metadata from the input file.
StatusCode doCopyxAODTriggerMenuJson(const std::string &inputMetaSGKey, const xAOD::TriggerMenuJsonContainer *copyFrom, xAOD::TriggerMenuJsonContainer *copyTo)
Common code to copy and de-duplicate menus from the copyFrom collection into the copyTo collection.
virtual StatusCode endInputFile()
Function called when the currently open input file got completely processed.
std::unique_ptr< xAOD::TriggerMenuJsonContainer > m_menuJSON_hlt
std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer > m_menuJSON_hltpsAux
std::unique_ptr< xAOD::TriggerMenuJsonContainer > m_menuJSON_bg
std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer > m_menuJSON_hltmonitoringAux
StatusCode checkExportJson(const std::string &outputMetaSGKey, std::unique_ptr< xAOD::TriggerMenuJsonContainer > &internalContainer, std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer > &internalAuxContainer)
std::unique_ptr< xAOD::TriggerMenuContainer > m_menu
The merged trigger menu container.
std::unique_ptr< xAOD::TriggerMenuJsonContainer > m_menuJSON_hltps
StatusCode endxAODTriggerMenuJson()
Perform the R3 data copy from the internal metastore to the output metastore.
std::unique_ptr< xAOD::TriggerMenuJsonContainer > m_menuJSON_l1ps
StatusCode endxAODTriggerMenu()
Perform the R2 data copy from the internal metastore to the output metastore.
std::unique_ptr< xAOD::TriggerMenuJsonContainer > m_menuJSON_hltmonitoring
std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer > m_menuJSON_l1psAux
std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer > m_menuJSON_hltAux
std::unique_ptr< xAOD::TriggerMenuJsonAuxContainer > m_menuJSON_l1Aux
TriggerMenuMetaDataTool(const std::string &name="TriggerMenuMetaDataTool")
Declare the correct constructor for Athena.
bool exists(const std::string &filename)
does a file exist
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
TriggerMenuJson_v1 TriggerMenuJson
Define the latest version of the trigger menu JSON class.
TriggerMenu_v1 TriggerMenu
Define the latest version of the trigger menu class.
Definition TriggerMenu.h:16
TriggerMenuContainer_v1 TriggerMenuContainer
Define the latest version of the trigger menu container class.
TriggerMenuJsonContainer_v1 TriggerMenuJsonContainer