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 if( menu->chainNames()[ i ].find( "L2_" ) == 0 ) {
97 level = "L2";
98 } else if( menu->chainNames()[ i ].find( "EF_" ) == 0 ) {
99 level = "EF";
100 } else if( menu->chainNames()[ i ].find( "HLT_" ) == 0 ) {
101 level = "HLT";
102 } else {
103 msg << MSG::WARNING << "prepareTriggerMenu(...): "
104 << "Couldn't figure out 'level' for chain: "
105 << menu->chainNames()[ i ] << endmsg;
106 }
107 // An empty signature list for the chain:
108 std::vector< HLTSignature* > signatures;
109
110 // If signature information is available, read it in:
111 if( menu->chainSignatureCountersAvailable() &&
112 menu->chainSignatureCounters().size() &&
113 menu->chainSignatureLogicsAvailable() &&
114 menu->chainSignatureLogics().size() &&
115 menu->chainSignatureOutputTEsAvailable() &&
116 menu->chainSignatureOutputTEs().size() /*&&
117 menu->chainSignatureLabelsAvailable() &&
118 menu->chainSignatureLabels().size() */) {
119
120 const std::vector< uint32_t >& counters =
121 menu->chainSignatureCounters()[ i ];
122 const std::vector< int >& logics =
123 menu->chainSignatureLogics()[ i ];
124 const std::vector< std::vector< std::string > >& outputTEs =
125 menu->chainSignatureOutputTEs()[ i ];
126 /*
127 const std::vector< std::string >& labels =
128 menu->chainSignatureLabels()[ i ];
129 */
130
131 if( msg.level() <= MSG::VERBOSE ) {
132 msg << MSG::VERBOSE << "chain " << menu->chainNames()[ i ]
133 << " has counter " << menu->chainIds()[ i ]
134 << " and " << counters.size() << " signatures" << endmsg;
135 }
136 for( size_t sig = 0; sig < counters.size(); ++sig ) {
137 std::vector< HLTTriggerElement* > outTEs;
138 outTEs.reserve(outputTEs[ sig ].size());
139 for( size_t outTEcounter = 0;
140 outTEcounter< outputTEs[ sig ].size(); ++outTEcounter ) {
141 HLTTriggerElement* element =
142 new HLTTriggerElement( outputTEs[ sig ][ outTEcounter ] );
143 outTEs.push_back( element );
144 }
145 HLTSignature* signature =
146 new HLTSignature( counters[ sig ], logics[ sig ], std::move(outTEs) );
147 signatures.push_back( signature );
148 if( msg.level() <= MSG::VERBOSE ) {
149 msg << MSG::VERBOSE << "prepared signature: "
150 << *( signatures.back() ) << endmsg;
151 }
152 }
153 } else if( ! signatureWarningPrinted ) {
154 msg << MSG::WARNING << "prepareTriggerMenu(...): "
155 << "HLT Signature information not available on the input"
156 << endmsg;
157 signatureWarningPrinted = true;
158 }
159
160 // Create the chain object:
161 HLTChain* chain = new HLTChain( menu->chainNames()[ i ],
162 menu->chainIds()[ i ],
163 1, // Chain version not important
164 level,
165 menu->chainParentNames()[ i ],
166 -1, // Lower chain ID not important
167 std::move(signatures) );
168 if( menu->chainRerunPrescalesAvailable() ) {
169 chain->set_rerun_prescale( menu->chainRerunPrescales()[ i ] );
170 }
171 if( menu->chainPassthroughPrescalesAvailable() ) {
172 chain->set_pass_through( menu->chainPassthroughPrescales()[ i ] );
173 }
174 if ( menu->chainPrescalesAvailable() ) {
175 chain->set_prescale( menu->chainPrescales()[ i ]);
176 }
177 {
178 auto parsed_multiplicities = ChainNameParser::multiplicities(menu->chainNames()[ i ]);
179 std::vector<long unsigned int> leg_multiplicities(parsed_multiplicities.begin(), parsed_multiplicities.end());
180 chain->set_leg_multiplicities( leg_multiplicities );
181 }
182 // Add it to the list of chains:
183 if( ! chainList.addHLTChain( chain ) ) {
184 msg << MSG::FATAL << "prepareTriggerMenu(...): "
185 << "Couldn't add chain \"" << chain->name()
186 << "\"" << endmsg;
187 delete chain;
188 return StatusCode::FAILURE;
189 }
190 }
191
192 // Add sequence information if it's available:
193 if( menu->sequenceInputTEsAvailable() &&
194 menu->sequenceOutputTEsAvailable() &&
195 menu->sequenceAlgorithmsAvailable() ) {
196
197 for( size_t i = 0; i< menu->sequenceOutputTEs().size(); ++i ) {
198 HLTTriggerElement* outputTE =
199 new HLTTriggerElement( menu->sequenceOutputTEs()[ i ] );
200 std::vector< HLTTriggerElement* > inputTEs;
201 for( size_t j = 0; j < menu->sequenceInputTEs()[ i ].size(); ++j ) {
203 new HLTTriggerElement( menu->sequenceInputTEs()[ i ][ j ] );
204 inputTEs.push_back( te );
205 }
206 HLTSequence* sequence =
207 new HLTSequence( inputTEs, outputTE,
208 menu->sequenceAlgorithms()[ i ] );
209 sequenceList.addHLTSequence( sequence );
210 // This throws a runtime_error if it fails, which we don't need to
211 // handle, since this is a FATAL error anyways.
212 }
213 } else {
214 msg << MSG::WARNING << "prepareTriggerMenu(...): "
215 << "HLT Sequence information not available on the input" << endmsg;
216 }
217
218 // Check if bunch-groups are available:
219 if( menu->bunchGroupBunchesAvailable() ) {
220
221 // Create a new BunchGroupSet object, since an existing one can't be
222 // modified... :-/
223 BunchGroupSet bgSetNew;
224
225 // Fill it with info:
226 for( size_t i = 0; i < menu->bunchGroupBunches().size(); ++i ) {
227
228 // Create a BunchGroup object:
229 BunchGroup bg;
230 bg.setInternalNumber( i );
231 std::vector< uint16_t >::const_iterator b_itr =
232 menu->bunchGroupBunches()[ i ].begin();
233 std::vector< uint16_t >::const_iterator b_end =
234 menu->bunchGroupBunches()[ i ].end();
235 for( ; b_itr != b_end; ++b_itr ) {
236 bg.addBunch( *b_itr );
237 }
238
239 // Add it to the set:
240 bgSetNew.addBunchGroup( bg );
241 }
242
243 // Replace the current bunch-group set with the new one:
244 bgSet = bgSetNew;
245
246 } else {
247 msg << MSG::WARNING << "prepareTriggerMenu(...): "
248 << "Bunch-group information not available on the "
249 << "input" << endmsg;
250 }
251
252 // Let the user know what happened:
253 msg << MSG::INFO << "Loaded xAOD::TriggerMenu configuration:" << endmsg;
254 msg << MSG::INFO << " SMK = " << menu->smk()
255 << ", L1PSK = " << menu->l1psk()
256 << ", HLTPSK = " << menu->hltpsk() << endmsg;
257
258 // Return gracefully:
259 return StatusCode::SUCCESS;
260 }
261
262
264 template<typename T>
265 std::vector<T> ToVector(const TrigConf::DataStructure& ds, const std::string& child){
266 using ptree = boost::property_tree::ptree;
267 std::vector<T> return_vector;
268 for( const ptree::value_type& entry : ds.data().get_child(child) ) {
269 return_vector.push_back( entry.second.get_value<T>() );
270 }
271 return return_vector;
272 }
273
275 template<typename T>
276 std::vector<std::vector<T>> ToVectorVector(const TrigConf::DataStructure& ds, const std::string& child){
277 using ptree = boost::property_tree::ptree;
278 std::vector<std::vector<T>> return_vector;
279 for( const ptree::value_type& outer : ds.data().get_child(child) ) {
280 return_vector.push_back(std::vector<T>());
281 for (const ptree::value_type& inner : outer.second) {
282 return_vector.back().push_back( inner.second.get_value<T>() );
283 }
284 }
285 return return_vector;
286 }
287
303 StatusCode prepareTriggerMenu(const HLTMenu& loadedHlt,
304 const L1Menu& loadedL1,
305 const HLTPrescalesSet& loadedHltps,
306 const L1PrescalesSet& loadedL1ps,
307 const L1BunchGroupSet& loadedBgSet,
308 CTPConfig& ctpConfig,
309 HLTChainList& chainList,
310 HLTSequenceList& sequenceList,
311 BunchGroupSet& bgSet,
312 MsgStream& msg ) {
313
314 // Clear the current LVL1 configuration:
315 ctpConfig.menu().clear();
316 ctpConfig.clearPrescaleSets();
317 ctpConfig.prescaleSet().resize( 512 );
318
319 if (loadedL1.isInitialized()) {
320 // Fill the LVL1 configuration:
321 for (const L1Item& loadedItem : loadedL1) {
322 TriggerItem* item = new TriggerItem();
323 item->setName( loadedItem.name() );
324 item->setCtpId( loadedItem.ctpId() );
325 ctpConfig.menu().addTriggerItem( item );
326
327 float ps = -1.0;
328 if (loadedL1ps.isInitialized()) {
329 const L1PrescalesSet::L1Prescale& loadedPrescale = loadedL1ps.prescale( loadedItem.name() );
330 ps = loadedPrescale.enabled ? static_cast< float >( loadedPrescale.prescale ) : -1.0;
331 }
332 ctpConfig.prescaleSet().setPrescale( loadedItem.ctpId(), ps );
333
334 if( msg.level() <= MSG::VERBOSE ) {
335 msg << MSG::VERBOSE << "L1 item " << loadedItem.name()
336 << " has ctpid " << loadedItem.ctpId()
337 << " and prescale " << ps
338 << endmsg;
339 }
340 }
341 }
342
343 // Clear the current HLT configuration:
344 chainList.clear();
345 sequenceList.clear();
346
347 // Fill the HLT configuration:
348 if (loadedHlt.isInitialized()) {
349 for (const Chain& loadedChain : loadedHlt) {
350 // Figure out which level this chain is from:
351 std::string level = "";
352 if( loadedChain.name().find( "L2_" ) == 0 ) {
353 level = "L2";
354 } else if( loadedChain.name().find( "EF_" ) == 0 ) {
355 level = "EF";
356 } else if( loadedChain.name().find( "HLT_" ) == 0 ) {
357 level = "HLT";
358 } else {
359 msg << MSG::WARNING << "prepareTriggerMenu(...): "
360 << "Couldn't figure out 'level' for chain: "
361 << loadedChain.name() << endmsg;
362 }
363
364 // An empty signature list for the chain:
365 std::vector< HLTSignature* > signatures;
366
367 // Optional Run2 payload
368 std::vector<uint32_t> counters;
369 std::vector<int> logics;
370 std::vector<std::vector<std::string>> outputTEs;
371 if (loadedChain.hasChild("signature")) {
372 counters = ToVector<uint32_t>(loadedChain, "signature.counters");
373 logics = ToVector<int>(loadedChain, "signature.logics");
374 outputTEs = ToVectorVector<std::string>(loadedChain, "signature.outputTEs");
375 }
376
377 for( size_t sig = 0; sig < counters.size(); ++sig ) {
378 std::vector< HLTTriggerElement* > outTEs;
379 outTEs.reserve(outputTEs[ sig ].size());
380 for( size_t outTEcounter = 0; outTEcounter< outputTEs[ sig ].size(); ++outTEcounter ) {
381 HLTTriggerElement* element = new HLTTriggerElement( outputTEs[ sig ][ outTEcounter ] );
382 outTEs.push_back( element );
383 }
384 HLTSignature* signature = new HLTSignature( counters[ sig ], logics[ sig ], std::move(outTEs) );
385 signatures.push_back( signature );
386 if( msg.level() <= MSG::VERBOSE ) {
387 msg << MSG::VERBOSE << "prepared signature: " << *( signatures.back() ) << endmsg;
388 }
389 }
390
391 // Create the chain object:
392 HLTChain* chain = new HLTChain( loadedChain.name(),
393 loadedChain.counter(),
394 1, // Chain version not important
395 level,
396 loadedChain.l1item(), // L1 seeds (string)
397 -1, // Lower chain ID not important
398 std::move(signatures) ); // Empty for R3 JSONs
399
400 chain->set_rerun_prescale( -1.0 ); // Not used in R3
401 chain->set_pass_through( -1.0 ); // Not used in R3
402 chain->set_leg_multiplicities( loadedChain.legMultiplicities() );
403
404 for (const std::string& group : loadedChain.groups()){
405 chain->addGroup(group);
406 }
407
408 float ps = -1.0;
409 if (loadedHltps.isInitialized()) {
410 const HLTPrescalesSet::HLTPrescale& loadedPrescale = loadedHltps.prescale( loadedChain.name() );
411 ps = loadedPrescale.enabled ? static_cast< float >( loadedPrescale.prescale ) : -1.0;
412 }
413 chain->set_prescale( ps );
414
415 if( msg.level() <= MSG::VERBOSE ) {
416 msg << MSG::VERBOSE << "chain " << loadedChain.name()
417 << " has counter " << loadedChain.counter()
418 << ", HLT prescale " << ps
419 << ", groups " << loadedChain.groups().size() << ", legs " << loadedChain.legMultiplicities().size()
420 << ", and " << counters.size() << " signatures (runs 1,2 only) " << endmsg;
421 }
422
423 // Add it to the list of chains:
424 if( ! chainList.addHLTChain( chain ) ) {
425 msg << MSG::FATAL << "prepareTriggerMenu(...): "
426 << "Couldn't add chain \"" << chain->name()
427 << "\"" << endmsg;
428 delete chain;
429 return StatusCode::FAILURE;
430 }
431 }
432 }
433
434 // Add sequence information if it's available (R1 or R2 menu):
435 if( loadedHlt.hasChild("sequence_run2") ) {
436 std::vector<std::string> menu_outputTEs = ToVector<std::string>(loadedHlt, "sequence_run2.outputTEs");
437 std::vector<std::vector<std::string>> menu_inputTEs = ToVectorVector<std::string>(loadedHlt, "sequence_run2.inputTEs");
438 std::vector<std::vector<std::string>> menu_algorithms = ToVectorVector<std::string>(loadedHlt, "sequence_run2.algorithms");
439
440 for( size_t i = 0; i< menu_outputTEs.size(); ++i ) {
441 HLTTriggerElement* outputTE = new HLTTriggerElement( menu_outputTEs[ i ] );
442 std::vector< HLTTriggerElement* > inputTEs;
443 for( size_t j = 0; j < menu_inputTEs[ i ].size(); ++j ) {
444 HLTTriggerElement* te = new HLTTriggerElement( menu_inputTEs[ i ][ j ] );
445 inputTEs.push_back( te );
446 }
447 HLTSequence* sequence = new HLTSequence( inputTEs, outputTE, menu_algorithms[ i ] );
448 sequenceList.addHLTSequence( sequence );
449 // This throws a runtime_error if it fails, which we don't need to
450 // handle, since this is a FATAL error anyways.
451 }
452 }
453
454 // Bunchgroup data is TODO
455 // Create a new BunchGroupSet object, since an existing one can't be
456 // modified... :-/
457 BunchGroupSet bgSetNew;
458
459 // Empty structure if data are missing
460 if (!loadedBgSet) {
461
462 for( size_t i = 0; i < 16; ++i ) {
463 BunchGroup bg;
464 bg.setInternalNumber(i);
465 bgSetNew.addBunchGroup(bg);
466 }
467
468 } else {
469
470 // Fill it with info:
471 for( size_t i = 0; i < loadedBgSet.size(); ++i ) {
472
473 const std::shared_ptr<L1BunchGroup> loadedBg = loadedBgSet.getBunchGroup(i);
474
475 // Create a BunchGroup object:
476 BunchGroup bg;
477 bg.setInternalNumber(i);
478
479 // Not the most efficient of copies, but one format has 16 bit ints whereas the other has 32 bit ints.
480 for (const uint16_t b : loadedBg->bunches()) {
481 bg.addBunch( static_cast<int>(b) );
482 }
483
484 // Add it to the set:
485 bgSetNew.addBunchGroup(bg);
486 }
487
488 }
489
490 static_assert(std::is_move_assignable<BunchGroupSet>::value);
491 // Replace the current bunch-group set with the new one:
492 bgSet = std::move(bgSetNew);
493
494 // Return gracefully:
495 return StatusCode::SUCCESS;
496 }
497
498
499} // namespace TrigConf
#define endmsg
boost::property_tree::ptree ptree
void addBunchGroup(const BunchGroup &)
const Menu & menu() const
Definition CTPConfig.h:38
const PrescaleSet & prescaleSet(unsigned int partition=0) const
Definition CTPConfig.h:39
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:28
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, int64_t prescaleValue) __attribute__((deprecated))
Set the prescale NUM from the int64 value prescaleValue.
void resize(size_t size)
make the sidebar many part of the config
Definition hcg.cxx:552
std::vector< int > multiplicities(const std::string &chain)
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
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