ATLAS Offline Software
Loading...
Searching...
No Matches
prepareTriggerMenu.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: prepareTriggerMenu.cxx 792850 2017-01-18 18:58:03Z ssnyder $
6
7// Infrastructure include(s):
9
10// Trigger configuration include(s):
18
20#include "TrigConfData/L1Menu.h"
24
26#include "TrigConfData/L1Item.h"
28#include <type_traits>
29// Local include(s):
31
32namespace TrigConf {
33
48 CTPConfig& ctpConfig,
49 HLTChainList& chainList,
50 HLTSequenceList& sequenceList,
51 BunchGroupSet& bgSet,
52 MsgStream& msg ) {
53
54 // A little sanity check:
55 if( ( ! menu->hasStore() ) && ( ( ! menu->container() ) ||
56 ( ! menu->container()->hasStore() ) ) ) {
57 msg << MSG::FATAL << "prepareTriggerMenu(...) Received "
58 << "xAOD::TriggerMenu object is not connected to an auxiliary "
59 << "store" << endmsg;
60 return StatusCode::FAILURE;
61 }
62
63 // Clear the current LVL1 configuration:
64 ctpConfig.menu().clear();
65 ctpConfig.clearPrescaleSets();
66 ctpConfig.prescaleSet().resize( 512 );
67
68 // Fill the LVL1 configuration:
69 for( size_t i = 0; i < menu->itemCtpIds().size(); ++i ) {
70 TriggerItem* item = new TriggerItem();
71 item->setName( menu->itemNames()[ i ] );
72 item->setCtpId( menu->itemCtpIds()[ i ] );
73 ctpConfig.menu().addTriggerItem( item );
74 if( menu->itemPrescalesAvailable() ) {
75 ctpConfig.prescaleSet().setPrescale( menu->itemCtpIds()[ i ],
76 static_cast< float >( menu->itemPrescales()[ i ] ) );
77 }
78 if( msg.level() <= MSG::VERBOSE ) {
79 msg << MSG::VERBOSE << "L1 item " << menu->itemNames()[ i ]
80 << " has ctpid " << menu->itemCtpIds()[ i ] << endmsg;
81 }
82 }
83
84 // Clear the current HLT configuration:
85 chainList.clear();
86 sequenceList.clear();
87
88 // A helper variable:
89 bool signatureWarningPrinted = false;
90
91 // Fill the HLT configuration:
92 for( size_t i = 0; i < menu->chainIds().size(); ++i ) {
93
94 // Figure out which level this chain is from:
95 std::string level = "";
96 bool has_l2 = false;
97 if( menu->chainNames()[ i ].find( "L2_" ) == 0 ) {
98 level = "L2";
99 } else if( menu->chainNames()[ i ].find( "EF_" ) == 0 ) {
100 level = "EF";
101 // xAOD::TriggerMenu was introduced during Run 2.
102 // Hence if we encounter an old POOL file whose metadata is in this format, and which contains EF chains.
103 // Then we can safely deduce that this chain is from Run 1, and hence will connect to a L2 chain.
104 has_l2 = true;
105 } else if( menu->chainNames()[ i ].find( "HLT_" ) == 0 ) {
106 level = "HLT";
107 } else {
108 msg << MSG::WARNING << "prepareTriggerMenu(...): "
109 << "Couldn't figure out 'level' for chain: "
110 << menu->chainNames()[ i ] << endmsg;
111 }
112 // An empty signature list for the chain:
113 std::vector< HLTSignature* > signatures;
114
115 // If signature information is available, read it in:
116 if( menu->chainSignatureCountersAvailable() &&
117 menu->chainSignatureCounters().size() &&
118 menu->chainSignatureLogicsAvailable() &&
119 menu->chainSignatureLogics().size() &&
120 menu->chainSignatureOutputTEsAvailable() &&
121 menu->chainSignatureOutputTEs().size() /*&&
122 menu->chainSignatureLabelsAvailable() &&
123 menu->chainSignatureLabels().size() */) {
124
125 const std::vector< uint32_t >& counters =
126 menu->chainSignatureCounters()[ i ];
127 const std::vector< int >& logics =
128 menu->chainSignatureLogics()[ i ];
129 const std::vector< std::vector< std::string > >& outputTEs =
130 menu->chainSignatureOutputTEs()[ i ];
131 /*
132 const std::vector< std::string >& labels =
133 menu->chainSignatureLabels()[ i ];
134 */
135
136 if( msg.level() <= MSG::VERBOSE ) {
137 msg << MSG::VERBOSE << "chain " << menu->chainNames()[ i ]
138 << " has counter " << menu->chainIds()[ i ]
139 << " and " << counters.size() << " signatures" << endmsg;
140 }
141 for( size_t sig = 0; sig < counters.size(); ++sig ) {
142 std::vector< HLTTriggerElement* > outTEs;
143 outTEs.reserve(outputTEs[ sig ].size());
144 for( size_t outTEcounter = 0;
145 outTEcounter< outputTEs[ sig ].size(); ++outTEcounter ) {
146 HLTTriggerElement* element =
147 new HLTTriggerElement( outputTEs[ sig ][ outTEcounter ] );
148 outTEs.push_back( element );
149 }
150 HLTSignature* signature =
151 new HLTSignature( counters[ sig ], logics[ sig ], std::move(outTEs) );
152 signatures.push_back( signature );
153 if( msg.level() <= MSG::VERBOSE ) {
154 msg << MSG::VERBOSE << "prepared signature: "
155 << *( signatures.back() ) << endmsg;
156 }
157 }
158 } else if( ! signatureWarningPrinted ) {
159 msg << MSG::WARNING << "prepareTriggerMenu(...): "
160 << "HLT Signature information not available on the input"
161 << endmsg;
162 signatureWarningPrinted = true;
163 }
164
165 // Create the chain object:
166 HLTChain* chain = new HLTChain( menu->chainNames()[ i ],
167 menu->chainIds()[ i ],
168 1, // Chain version not important
169 level,
170 menu->chainParentNames()[ i ],
171 -1, // Lower chain ID not important
172 std::move(signatures) );
173 chain->set_has_l2(has_l2);
174 if( menu->chainRerunPrescalesAvailable() ) {
175 chain->set_rerun_prescale( menu->chainRerunPrescales()[ i ] );
176 }
177 if( menu->chainPassthroughPrescalesAvailable() ) {
178 chain->set_pass_through( menu->chainPassthroughPrescales()[ i ] );
179 }
180 if ( menu->chainPrescalesAvailable() ) {
181 chain->set_prescale( menu->chainPrescales()[ i ]);
182 }
183 {
184 auto parsed_multiplicities = ChainNameParser::multiplicities(menu->chainNames()[ i ]);
185 std::vector<long unsigned int> leg_multiplicities(parsed_multiplicities.begin(), parsed_multiplicities.end());
186 chain->set_leg_multiplicities( leg_multiplicities );
187 }
188 // Add it to the list of chains:
189 if( ! chainList.addHLTChain( chain ) ) {
190 msg << MSG::FATAL << "prepareTriggerMenu(...): "
191 << "Couldn't add chain \"" << chain->name()
192 << "\"" << endmsg;
193 delete chain;
194 return StatusCode::FAILURE;
195 }
196 }
197
198 // Add sequence information if it's available:
199 if( menu->sequenceInputTEsAvailable() &&
200 menu->sequenceOutputTEsAvailable() &&
201 menu->sequenceAlgorithmsAvailable() ) {
202
203 for( size_t i = 0; i< menu->sequenceOutputTEs().size(); ++i ) {
204 HLTTriggerElement* outputTE =
205 new HLTTriggerElement( menu->sequenceOutputTEs()[ i ] );
206 std::vector< HLTTriggerElement* > inputTEs;
207 for( size_t j = 0; j < menu->sequenceInputTEs()[ i ].size(); ++j ) {
209 new HLTTriggerElement( menu->sequenceInputTEs()[ i ][ j ] );
210 inputTEs.push_back( te );
211 }
212 HLTSequence* sequence =
213 new HLTSequence( inputTEs, outputTE,
214 menu->sequenceAlgorithms()[ i ] );
215 sequenceList.addHLTSequence( sequence );
216 // This throws a runtime_error if it fails, which we don't need to
217 // handle, since this is a FATAL error anyways.
218 }
219 } else {
220 msg << MSG::WARNING << "prepareTriggerMenu(...): "
221 << "HLT Sequence information not available on the input" << endmsg;
222 }
223
224 // Check if bunch-groups are available:
225 if( menu->bunchGroupBunchesAvailable() ) {
226
227 // Create a new BunchGroupSet object, since an existing one can't be
228 // modified... :-/
229 BunchGroupSet bgSetNew;
230
231 // Fill it with info:
232 for( size_t i = 0; i < menu->bunchGroupBunches().size(); ++i ) {
233
234 // Create a BunchGroup object:
235 BunchGroup bg;
236 bg.setInternalNumber( i );
237 std::vector< uint16_t >::const_iterator b_itr =
238 menu->bunchGroupBunches()[ i ].begin();
239 std::vector< uint16_t >::const_iterator b_end =
240 menu->bunchGroupBunches()[ i ].end();
241 for( ; b_itr != b_end; ++b_itr ) {
242 bg.addBunch( *b_itr );
243 }
244
245 // Add it to the set:
246 bgSetNew.addBunchGroup( bg );
247 }
248
249 // Replace the current bunch-group set with the new one:
250 bgSet = bgSetNew;
251
252 } else {
253 msg << MSG::WARNING << "prepareTriggerMenu(...): "
254 << "Bunch-group information not available on the "
255 << "input" << endmsg;
256 }
257
258 // Let the user know what happened:
259 msg << MSG::INFO << "Loaded xAOD::TriggerMenu configuration:" << endmsg;
260 msg << MSG::INFO << " SMK = " << menu->smk()
261 << ", L1PSK = " << menu->l1psk()
262 << ", HLTPSK = " << menu->hltpsk() << endmsg;
263
264 // Return gracefully:
265 return StatusCode::SUCCESS;
266 }
267
268
270 template<typename T>
271 std::vector<T> ToVector(const TrigConf::DataStructure& ds, const std::string& child){
272 using ptree = boost::property_tree::ptree;
273 std::vector<T> return_vector;
274 for( const ptree::value_type& entry : ds.data().get_child(child) ) {
275 return_vector.push_back( entry.second.get_value<T>() );
276 }
277 return return_vector;
278 }
279
281 template<typename T>
282 std::vector<std::vector<T>> ToVectorVector(const TrigConf::DataStructure& ds, const std::string& child){
283 using ptree = boost::property_tree::ptree;
284 std::vector<std::vector<T>> return_vector;
285 for( const ptree::value_type& outer : ds.data().get_child(child) ) {
286 return_vector.push_back(std::vector<T>());
287 for (const ptree::value_type& inner : outer.second) {
288 return_vector.back().push_back( inner.second.get_value<T>() );
289 }
290 }
291 return return_vector;
292 }
293
309 StatusCode prepareTriggerMenu(const HLTMenu& loadedHlt,
310 const L1Menu& loadedL1,
311 const HLTPrescalesSet& loadedHltps,
312 const L1PrescalesSet& loadedL1ps,
313 const L1BunchGroupSet& loadedBgSet,
314 CTPConfig& ctpConfig,
315 HLTChainList& chainList,
316 HLTSequenceList& sequenceList,
317 BunchGroupSet& bgSet,
318 MsgStream& msg ) {
319
320 // Clear the current LVL1 configuration:
321 ctpConfig.menu().clear();
322 ctpConfig.clearPrescaleSets();
323 ctpConfig.prescaleSet().resize( 512 );
324
325 if (loadedL1.isInitialized()) {
326 // Fill the LVL1 configuration:
327 for (const L1Item& loadedItem : loadedL1) {
328 TriggerItem* item = new TriggerItem();
329 item->setName( loadedItem.name() );
330 item->setCtpId( loadedItem.ctpId() );
331 ctpConfig.menu().addTriggerItem( item );
332
333 float ps = -1.0;
334 if (loadedL1ps.isInitialized()) {
335 const L1PrescalesSet::L1Prescale& loadedPrescale = loadedL1ps.prescale( loadedItem.name() );
336 ps = loadedPrescale.enabled ? static_cast< float >( loadedPrescale.prescale ) : -1.0;
337 }
338 ctpConfig.prescaleSet().setPrescale( loadedItem.ctpId(), ps );
339
340 if( msg.level() <= MSG::VERBOSE ) {
341 msg << MSG::VERBOSE << "L1 item " << loadedItem.name()
342 << " has ctpid " << loadedItem.ctpId()
343 << " and prescale " << ps
344 << endmsg;
345 }
346 }
347 }
348
349 // Clear the current HLT configuration:
350 chainList.clear();
351 sequenceList.clear();
352
353 // Fill the HLT configuration:
354 if (loadedHlt.isInitialized()) {
355 for (const Chain& loadedChain : loadedHlt) {
356 // Figure out which level this chain is from:
357 std::string level = "";
358 if( loadedChain.name().find( "L2_" ) == 0 ) {
359 level = "L2";
360 } else if( loadedChain.name().find( "EF_" ) == 0 ) {
361 level = "EF";
362 } else if( loadedChain.name().find( "HLT_" ) == 0 ) {
363 level = "HLT";
364 } else {
365 msg << MSG::WARNING << "prepareTriggerMenu(...): "
366 << "Couldn't figure out 'level' for chain: "
367 << loadedChain.name() << endmsg;
368 }
369
370 // An empty signature list for the chain:
371 std::vector< HLTSignature* > signatures;
372
373 // Optional Run2 payload
374 std::vector<uint32_t> counters;
375 std::vector<int> logics;
376 std::vector<std::vector<std::string>> outputTEs;
377 if (loadedChain.hasChild("signature")) {
378 counters = ToVector<uint32_t>(loadedChain, "signature.counters");
379 logics = ToVector<int>(loadedChain, "signature.logics");
380 outputTEs = ToVectorVector<std::string>(loadedChain, "signature.outputTEs");
381 }
382
383 for( size_t sig = 0; sig < counters.size(); ++sig ) {
384 std::vector< HLTTriggerElement* > outTEs;
385 outTEs.reserve(outputTEs[ sig ].size());
386 for( size_t outTEcounter = 0; outTEcounter< outputTEs[ sig ].size(); ++outTEcounter ) {
387 HLTTriggerElement* element = new HLTTriggerElement( outputTEs[ sig ][ outTEcounter ] );
388 outTEs.push_back( element );
389 }
390 HLTSignature* signature = new HLTSignature( counters[ sig ], logics[ sig ], std::move(outTEs) );
391 signatures.push_back( signature );
392 if( msg.level() <= MSG::VERBOSE ) {
393 msg << MSG::VERBOSE << "prepared signature: " << *( signatures.back() ) << endmsg;
394 }
395 }
396
397 // Create the chain object:
398 HLTChain* chain = new HLTChain( loadedChain.name(),
399 loadedChain.counter(),
400 1, // Chain version not important
401 level,
402 loadedChain.l1item(), // L1 seeds (string)
403 -1, // Lower chain ID not important
404 std::move(signatures) ); // Empty for Run 3+ JSONs
405 // Run 1 POOL files are not expected to have a JSON metadata payload (see above)
406 // Hence any EF chains encountered are Run 4 and not Run 1. They therefore do not connect to a L2 chain.
407 chain->set_has_l2(false);
408 chain->set_rerun_prescale( -1.0 ); // Not used in Run 3+
409 chain->set_pass_through( -1.0 ); // Not used in Run 3+
410 chain->set_leg_multiplicities( loadedChain.legMultiplicities() );
411
412 for (const std::string& group : loadedChain.groups()){
413 chain->addGroup(group);
414 }
415
416 float ps = -1.0;
417 if (loadedHltps.isInitialized()) {
418 const HLTPrescalesSet::HLTPrescale& loadedPrescale = loadedHltps.prescale( loadedChain.name() );
419 ps = loadedPrescale.enabled ? static_cast< float >( loadedPrescale.prescale ) : -1.0;
420 }
421 chain->set_prescale( ps );
422
423 if( msg.level() <= MSG::VERBOSE ) {
424 msg << MSG::VERBOSE << "chain " << loadedChain.name()
425 << " has counter " << loadedChain.counter()
426 << ", HLT prescale " << ps
427 << ", groups " << loadedChain.groups().size() << ", legs " << loadedChain.legMultiplicities().size()
428 << ", and " << counters.size() << " signatures (runs 1,2 only) " << endmsg;
429 }
430
431 // Add it to the list of chains:
432 if( ! chainList.addHLTChain( chain ) ) {
433 msg << MSG::FATAL << "prepareTriggerMenu(...): "
434 << "Couldn't add chain \"" << chain->name()
435 << "\"" << endmsg;
436 delete chain;
437 return StatusCode::FAILURE;
438 }
439 }
440 }
441
442 // Add sequence information if it's available (R1 or R2 menu):
443 if( loadedHlt.hasChild("sequence_run2") ) {
444 std::vector<std::string> menu_outputTEs = ToVector<std::string>(loadedHlt, "sequence_run2.outputTEs");
445 std::vector<std::vector<std::string>> menu_inputTEs = ToVectorVector<std::string>(loadedHlt, "sequence_run2.inputTEs");
446 std::vector<std::vector<std::string>> menu_algorithms = ToVectorVector<std::string>(loadedHlt, "sequence_run2.algorithms");
447
448 for( size_t i = 0; i< menu_outputTEs.size(); ++i ) {
449 HLTTriggerElement* outputTE = new HLTTriggerElement( menu_outputTEs[ i ] );
450 std::vector< HLTTriggerElement* > inputTEs;
451 for( size_t j = 0; j < menu_inputTEs[ i ].size(); ++j ) {
452 HLTTriggerElement* te = new HLTTriggerElement( menu_inputTEs[ i ][ j ] );
453 inputTEs.push_back( te );
454 }
455 HLTSequence* sequence = new HLTSequence( inputTEs, outputTE, menu_algorithms[ i ] );
456 sequenceList.addHLTSequence( sequence );
457 // This throws a runtime_error if it fails, which we don't need to
458 // handle, since this is a FATAL error anyways.
459 }
460 }
461
462 // Bunchgroup data is TODO
463 // Create a new BunchGroupSet object, since an existing one can't be
464 // modified... :-/
465 BunchGroupSet bgSetNew;
466
467 // Empty structure if data are missing
468 if (!loadedBgSet) {
469
470 for( size_t i = 0; i < 16; ++i ) {
471 BunchGroup bg;
472 bg.setInternalNumber(i);
473 bgSetNew.addBunchGroup(bg);
474 }
475
476 } else {
477
478 // Fill it with info:
479 for( size_t i = 0; i < loadedBgSet.size(); ++i ) {
480
481 const std::shared_ptr<L1BunchGroup> loadedBg = loadedBgSet.getBunchGroup(i);
482
483 // Create a BunchGroup object:
484 BunchGroup bg;
485 bg.setInternalNumber(i);
486
487 // Not the most efficient of copies, but one format has 16 bit ints whereas the other has 32 bit ints.
488 for (const uint16_t b : loadedBg->bunches()) {
489 bg.addBunch( static_cast<int>(b) );
490 }
491
492 // Add it to the set:
493 bgSetNew.addBunchGroup(bg);
494 }
495
496 }
497
498 static_assert(std::is_move_assignable<BunchGroupSet>::value);
499 // Replace the current bunch-group set with the new one:
500 bgSet = std::move(bgSetNew);
501
502 // Return gracefully:
503 return StatusCode::SUCCESS;
504 }
505
506
507} // namespace TrigConf
#define endmsg
boost::property_tree::ptree ptree
size_t size() const
Number of registered mappings.
void addBunchGroup(const BunchGroup &)
const Menu & menu() const
Definition CTPConfig.h:39
const PrescaleSet & prescaleSet(unsigned int partition=0) const
Definition CTPConfig.h:40
Base class for Trigger configuration data and wrapper around underlying representation.
bool hasChild(const std::string &path) const
Check if child exists.
list of all HLT chains in a trigger menu
bool addHLTChain(HLTChain *ch)
adds an HLTChain to the menu
HLT chain configuration information.
HLT menu configuration.
Definition HLTMenu.h:21
HLT menu configuration.
const HLTPrescale & prescale(const std::string &chainName) const
HLT prescales by chain names.
list of HLT sequences
void addHLTSequence(HLTSequence *sequence)
adds an HLTSequence to the menu
HLT sequence configuration information.
Definition HLTSequence.h:28
HLT signature configuration information.
HLT trigger element configuration information.
L1 board configuration.
std::size_t size() const
Accessor to the number of defined bunchgroups.
const std::shared_ptr< L1BunchGroup > & getBunchGroup(const std::string &name) const
Accessor to the bunchgroup by name.
L1 threshold configuration.
Definition L1Item.h:18
L1 menu configuration.
Definition L1Menu.h:29
L1 menu configuration.
const L1Prescale & prescale(const std::string &itemName) const
void addTriggerItem(TriggerItem *ti)
Definition Menu.cxx:48
void clear()
Definition Menu.cxx:160
void setPrescale(unsigned int num, float prescaleValue)
void resize(size_t size)
void setName(const std::string &name)
void setCtpId(int id)
Definition TriggerItem.h:46
make the sidebar many part of the config
Definition hcg.cxx:554
std::vector< int > multiplicities(const std::string &chain)
Forward iterator to traverse the main components of the trigger configuration.
StatusCode prepareTriggerMenu(const xAOD::TriggerMenu *menu, CTPConfig &ctpConfig, HLTChainList &chainList, HLTSequenceList &sequenceList, BunchGroupSet &bgSet, MsgStream &msg)
In order to avoid duplicating code between how the dual-use and the Athena-only code translates the x...
std::vector< std::vector< T > > ToVectorVector(const TrigConf::DataStructure &ds, const std::string &child)
Helper function ptree key->[[]] to std::vector<std::vector<T>>.
std::vector< T > ToVector(const TrigConf::DataStructure &ds, const std::string &child)
Helper function ptree key->[] to std::vector<T>.
TriggerMenu_v1 TriggerMenu
Define the latest version of the trigger menu class.
Definition TriggerMenu.h:16
MsgStream & msg
Definition testRead.cxx:32