ATLAS Offline Software
Loading...
Searching...
No Matches
TopoSteering.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8
16
20
27
28// c++ libraries
29#include <iostream>
30#include <iomanip>
31#include <string>
32
33using namespace std;
34using namespace TCS;
35using namespace TrigConf;
36
37
41
43TopoSteering::setupFromConfiguration ATLAS_NOT_THREAD_SAFE (const TrigConf::L1Menu& l1menu){
44
45 TCS::StatusCode sc = m_structure.setupFromMenu( l1menu, m_isLegacyTopo );
46
47 // configure layout of the simulation result
48 //coverity[USELESS_CALL:FALSE]
49 sc &= m_simulationResult.setupFromMenu( m_structure.outputConnectors(), m_structure.countConnectors() );
50
51 return sc;
52
53}
54
55TCS::StatusCode
88
89
92 TRG_MSG_INFO("initializing algorithms");
93 if( ! structure().isConfigured() ) {
94 TCS_EXCEPTION("L1Topo Steering has not been configured, can't run");
95 }
96
97 for(auto conn: m_structure.connectors()) {
98 TCS::ConfigurableAlg * alg = conn->algorithm();
99 if(alg) {
100 TRG_MSG_INFO("initializing algorithm " << alg->name());
101 if(m_histSvc) {
102 alg->setL1TopoHistSvc(m_histSvc);
103 }
104 alg->setLegacyMode(m_isLegacyTopo);
105 alg->initialize();
106 }
107
108 }
109
111}
112
113
115TopoSteering::setHistSvc(std::shared_ptr<IL1TopoHistSvc> histSvc) {
116 TRG_MSG_INFO("setting L1TopoHistSvc ");
117 m_histSvc = std::move(histSvc);
119}
120
121
124 if(m_histSvc) {
125 m_histSvc->save();
126 } else {
127 TRG_MSG_WARNING("saveHist called without an L1TopoHistSvc being available");
128 }
130}
131
132
135
136
137 TRG_MSG_INFO("L1 TopoSteering: start executing event " << m_evtCounter << "-----------------------------------");
138
139
140 if( ! structure().isConfigured() ) {
141 TRG_MSG_INFO("L1Topo Steering has not been configured, can't run");
142 TCS_EXCEPTION("L1Topo Steering has not been configured, can't run");
143 }
144
145 inputEvent().print();
146
147 // execute all connectors
149 TRG_MSG_INFO("Going to execute " << m_structure.outputConnectors().size() << " decision connectors and " << m_structure.countConnectors().size() << " multiplicity connectors.");
150 for(const auto & [name, pConnector]: m_structure.outputConnectors()) {
151 TRG_MSG_INFO("executing trigger line " << name);
152 sc |= executeConnector(pConnector);
153 TRG_MSG_INFO("result of trigger line " << name << " : " << pConnector->decision().decision());
154 }
155
156 for(const auto & [name, pConnector]: m_structure.countConnectors()) {
157 TRG_MSG_INFO("executing trigger line " << name);
158 sc |= executeConnector(pConnector);
159 }
160 //coverity[USELESS_CALL:FALSE]
161 sc |= m_simulationResult.collectResult();
162
163 m_simulationResult.globalOutput().print();
164
165 TRG_MSG_INFO("finished executing event " << m_evtCounter++);
167}
168
169
170
172TopoSteering::executeTrigger(const std::string & TrigName) {
173 if( ! structure().isConfigured() )
174 TCS_EXCEPTION("TopoSteering has not been configured, can't run");
175
176 DecisionConnector * outConn = m_structure.outputConnector(TrigName);
177
179
180 m_simulationResult.collectResult(outConn);
181
182 return sc;
183}
184
185
186
187
188
189
192
193 if (conn == NULL) {
195 }
196
197 // caching
198 if(conn->isExecuted())
199 return conn->executionStatusCode();
200
202
203 if(conn->isInputConnector()) {
204 //TRG_MSG_DEBUG(" ... executing input connector '" << conn->name() << "'");
205 sc = executeInputConnector(dynamic_cast<InputConnector*>(conn));
206 } else if(conn->isSortingConnector()) {
207 //TRG_MSG_DEBUG(" ... executing sorting connector '" << conn->name() << "'");
208 sc = executeSortingConnector(dynamic_cast<SortingConnector*>(conn));
209 } else if(conn->isDecisionConnector()){
210 //TRG_MSG_DEBUG(" ... executing decision connector '" << conn->name() << "'");
211 sc = executeDecisionConnector(dynamic_cast<DecisionConnector*>(conn));
212 } else if(conn->isCountingConnector()){
213 sc = executeCountingConnector(dynamic_cast<CountingConnector*>(conn));
214 }
215
216 conn->setIsExecuted(true);
217 conn->setExecutionStatusCode(sc);
218
219 return sc;
220}
221
222
223
226
227 if (conn == NULL) {
229 }
230
232
233 // attaching data from inputEvent to input connector, depending on the configured input type
234
235 const InputTOBArray * inputData = inputEvent().inputTOBs( conn->inputTOBType() );
236 const bool hasInputOverflow = inputEvent().hasInputOverflow(conn->inputTOBType());
237 conn->attachOutputData( inputData );
238 conn->toggleInputOverflow(hasInputOverflow);
239
240 TRG_MSG_DEBUG(" ... executing input connector '" << conn->name() << "' -> attaching '" << inputData->name() << "' of size " << inputData->size());
241
242 return sc;
243}
244
245
246
249
250 if (conn == NULL) {
251 return StatusCode::FAILURE;
252 }
253
255
256 // execute all the prior connectors
257 for( TCS::Connector* inputConn: conn->inputConnectors() ){
258 sc &= executeConnector(inputConn);
259 conn->toggleInputOverflow(conn->hasInputOverflow() ||
260 inputConn->hasInputOverflow());
261 }
262 TCS::SortingAlg* alg = conn->sortingAlgorithm();
263
264 TOBArray * sortedOutput = new TOBArray(conn->outputName());
265 //coverity[USELESS_CALL:FALSE]
266 sc &= executeSortingAlgorithm(alg, conn->inputConnector(), sortedOutput);
267
268 conn->toggleAmbiguity(sortedOutput->ambiguityFlag());
269
270 TRG_MSG_DEBUG(" ... executing sorting connector '" << conn->name() << "' -> attaching '" << sortedOutput->name() << "' of size " << sortedOutput->size());
271
272 conn->attachOutputData(sortedOutput);
273
274 return sc;
275}
276
277
278
281
282 if (conn == NULL) {
284 }
285
287
288 // execute all the prior connectors
289 for( TCS::Connector* inputConn: conn->inputConnectors() ){
290 sc &= executeConnector(inputConn);
291 conn->toggleInputOverflow(conn->hasInputOverflow() ||
292 inputConn->hasInputOverflow());
293 conn->toggleAmbiguity(conn->hasAmbiguity() ||
294 inputConn->hasAmbiguity());
295 }
296 // execute
297 TCS::DecisionAlg* alg = conn->decisionAlgorithm();
298
299 // TRG_MSG_DEBUG(" ... executing decision connector '" << conn->name() << "' with " << conn->triggers().size() << " active trigger lines. The algorithm has " << alg->numberOutputBits() << " output bits.");
300
301 // the output is one TOBArray per output line
302 vector<TOBArray *> output( alg->numberOutputBits() );
303
304 for(unsigned int i=0; i<alg->numberOutputBits(); ++i) {
305 output[i] = new TOBArray(conn->triggers()[i].name());
306 output[i]->setAmbiguityFlag(conn->hasAmbiguity());
307 }
308 //coverity[USELESS_CALL:FALSE]
309 sc &= executeDecisionAlgorithm(alg, conn->inputConnectors(), output, conn->m_decision);
310
311 TRG_MSG_DEBUG(" ... executing decision connector '" << conn->name() << "' -> attaching output data:");
312 for(TOBArray const * outarr : output) {
313 TRG_MSG_DEBUG(" data '" << outarr->name() << "' of size " << outarr->size());
314 conn->toggleAmbiguity(conn->hasAmbiguity() || outarr->ambiguityFlag());
315 }
316
317 conn->attachOutputData(output);
318
319 conn->setIsExecuted(true);
320 conn->setExecutionStatusCode(sc);
321 bool sortOverflow = false;
322 for(TCS::Connector* inputConnector: conn->inputConnectors()) {
323 // TODO DG-2017-04-18 the sort overflow (>10 TOBs) in the SortAlg is not implemented yet
324 if(inputConnector->isSortingConnector()) {
325 if (auto sortConn = dynamic_cast<SortingConnector*>(inputConnector)) {
326 sortOverflow = sortConn->sortingAlgorithm()->overflow();
327 if (sortOverflow) break;
328 }
329 }
330 }
331 conn->m_decision.setOverflow(conn->hasInputOverflow() || sortOverflow);
332 conn->m_decision.setAmbiguity(conn->hasAmbiguity());
333 return sc;
334}
335
336
339
340 if (conn == NULL) {
342 }
343
345
346 // execute all the prior connectors
347 for( TCS::Connector* inputConn: conn->inputConnectors() ){
348 sc &= executeConnector(inputConn);
349 conn->toggleInputOverflow(conn->hasInputOverflow() ||
350 inputConn->hasInputOverflow());
351 }
352
353 // execute
354 TCS::CountingAlg* alg = conn->countingAlgorithm();
355
356 // Execute algorithm with no output data - not needed for now
357 //coverity[USELESS_CALL:FALSE]
358 sc &= executeCountingAlgorithm(alg, conn->inputConnector(), conn->m_count);
359
360 conn->setIsExecuted(true);
361 conn->setExecutionStatusCode(sc);
362
363 // TO-DO overflows in multiplicity algorithms
364
365 return sc;
366}
367
368
369
372 TCS::InputConnector* inputConnector,
373 TCS::TOBArray * & sortedOutput) {
374
375 TRG_MSG_DEBUG(" ... executing sorting alg '" << alg->fullname() << "'"
376 <<(m_useBitwise?" (bitwise)":""));
377
378 const InputTOBArray * input = inputConnector->outputData();
379
380 if(m_useBitwise) alg->sortBitCorrect(*input, *sortedOutput);
381 else alg->sort(*input, *sortedOutput);
382
384}
385
386
387
390 const std::vector<Connector*> & inputConnectors,
391 const std::vector<TCS::TOBArray *> & output,
392 TCS::Decision & decision) {
393
394 TRG_MSG_DEBUG(" ... executing decision alg '" << alg->fullname() << "'"
395 <<(m_useBitwise?" (bitwise)":""));
396
397 if(inputConnectors.size()<1) {
398 TCS_EXCEPTION("L1Topo Steering: Decision algorithm expects at least 1 input array but got 0");
399 }
400
401 std::vector<TCS::TOBArray const *> input; // needs to be optimized
402 for(const Connector* inConn: inputConnectors)
403 {
404 if (inConn == nullptr) continue;
405 const SortingConnector * sc = dynamic_cast<const SortingConnector *>(inConn);
406 if (sc==nullptr) {
407 TCS_EXCEPTION("L1Topo Steering: Decision algorithm " << alg->name() << " could not cast as SortingConnector* the input connector " << inConn->name());
408 }
409 else {
410 const TOBArray * tobA = dynamic_cast<const TOBArray *>( sc->outputData());
411 if(tobA==nullptr) {
412 TCS_EXCEPTION("L1Topo Steering: Decision algorithm " << alg->name() << " expects TOBArray(s) as input, but did not get it from connector " << (inConn ? inConn->name() : ""));
413 }
414 input.push_back( tobA );
415 }
416 }
417
418 alg->reset();
419
420
421 if(m_useBitwise) alg->processBitCorrect( input, output, decision);
422 else alg->process( input, output, decision );
423 //TRG_MSG_ALWAYS("[XS1234sz]L1Topo Steering alg " << alg->name() << " has decision " << decision.decision());
424
426}
427
428
431 TCS::InputConnector* inputConnector,
432 TCS::Count & count) {
433
434 TRG_MSG_DEBUG(" ... executing multiplicity alg '" <<alg->fullname() << "'");
435
436 const InputTOBArray * input = inputConnector->outputData();
437
438 alg->process( *input, count);
439
441}
442
443
444void
446 TRG_MSG_INFO("Number of ClusterTOB : " << ClusterTOB::heap().size());
447 TRG_MSG_INFO("Number of eEmTOB : " << eEmTOB::heap().size());
448 TRG_MSG_INFO("Number of JetTOB : " << JetTOB::heap().size());
449 TRG_MSG_INFO("Number of jJetTOB : " << jJetTOB::heap().size());
450 TRG_MSG_INFO("Number of GenericTOB : " << GenericTOB::heap().size());
451 TRG_MSG_INFO("Number of CompositeTOB: " << CompositeTOB::heap().size());
452 TRG_MSG_INFO("Number of MuonTOB : " << MuonTOB::heap().size());
453 TRG_MSG_INFO("Number of LateMuonTOB : " << LateMuonTOB::heap().size());
454}
455
456
457
458void
459TopoSteering::printConfiguration(std::ostream & o) const {
460 o << "==========================\n"
461 << "TopoSteering configuration\n"
462 << "--------------------------\n";
463 structure().print(o);
464 o << "==========================" << endl;
465}
466
467
468
469void
471
472 //const char* levelNames[TrigConf::MSGTC::NUM_LEVELS] = {"NIL","VERBOSE","DEBUG","INFO",
473 // "WARNING","ERROR","FATAL","ALWAYS"};
474 msg().setLevel( lvl );
475
476 inputEvent().msg().setLevel(lvl);
477
478 m_simulationResult.setMsgLevel( lvl );
479}
480
481void
483 m_AlgMsgLvl = lvl;
484 for( Connector * conn : m_structure.connectors() ) {
485 const ConfigurableAlg * alg = conn->algorithm();
486 if(alg==nullptr) continue;
487 alg->msg().setLevel(lvl);
488 }
489}
490
491//----------------------------------------------------------
492void
493TopoSteering::setHardwareBits(const std::bitset<numberOfL1TopoBits> &triggerBits,
494 const std::bitset<numberOfL1TopoBits> &ovrflowBits){
495 m_triggerHdwBits = triggerBits;
496 m_ovrflowHdwBits = ovrflowBits;
497}
498//----------------------------------------------------------
499void
501 for(const auto & [connectorName, outCon] : m_structure.outputConnectors()) {
502 outCon->decisionAlgorithm()->resetHardwareBits();
503 unsigned int pos = 0; // for multi-output algorithms pos is the output index
504 for(const TrigConf::TriggerLine &trigger : outCon->triggers()){
505 unsigned int bitNumber = trigger.flatindex();
506 outCon->decisionAlgorithm()->setHardwareBits(pos,
507 m_triggerHdwBits[bitNumber],
508 m_ovrflowHdwBits[bitNumber]);
509 pos++;
510 TRG_MSG_DEBUG("propagating hardware bit (dec/ovr) "<<bitNumber
511 <<" to algo "<<connectorName<<"["<<pos<<"]"
512 <<" "<<m_triggerHdwBits[bitNumber]<<" /"
513 <<" "<<m_ovrflowHdwBits[bitNumber]);
514
515 }
516 }
517}
518//----------------------------------------------------------
519void
521 for(const auto & [connectorName, outCon] : m_structure.outputConnectors()) {
522 if(outCon) {
523 outCon->decisionAlgorithm()->setFillHistosBasedOnHardware(value);
524 } else {
525 TRG_MSG_DEBUG("skipping invalid DecisionConnector '"<<connectorName<<"'");
526 }
527 }
528}
529//----------------------------------------------------------
530void
532 for(const auto & [connectorName,outCon] : m_structure.outputConnectors()) {
533 if(outCon) {
534 outCon->decisionAlgorithm()->setSkipHistos(value);
535 } else {
536 TRG_MSG_DEBUG("skipping invalid DecisionConnector '"<<connectorName<<"'");
537 }
538 }
539}
540//----------------------------------------------------------
static Double_t sc
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
static void clearHeap()
static const Heap< TCS::ClusterTOB > & heap()
Definition ClusterTOB.h:56
static const Heap< TCS::CompositeTOB > & heap()
static void clearHeap()
size_t size() const
const std::string & name() const
Definition DataArray.h:20
static const Heap< TCS::GenericTOB > & heap()
Definition GenericTOB.h:110
static void clearHeap()
const InputTOBArray * outputData() const
virtual unsigned int size() const =0
static void clearHeap()
Definition JetTOB.cxx:37
static const Heap< TCS::JetTOB > & heap()
Definition JetTOB.h:71
static const Heap< TCS::LateMuonTOB > & heap()
Definition LateMuonTOB.h:74
static void clearHeap()
static void clearHeap()
Definition MetTOB.cxx:38
static void clearHeap()
static const Heap< TCS::MuonTOB > & heap()
Definition MuonTOB.h:79
static void clearHeap()
Definition MuonTOB.cxx:33
bool ambiguityFlag() const
Definition TOBArray.h:37
const InputTOBArray * inputTOBs(TCS::inputTOBType_t) const
bool hasInputOverflow(TCS::inputTOBType_t) const
whether there are input overflows from Mioct for muon and from CMX for calo
void print(std::ostream &o) const
StatusCode executeSortingAlgorithm(SortingAlg *alg, TCS::InputConnector *inputConnector, TOBArray *&output)
StatusCode saveHist()
void setOutputAlgosFillBasedOnHardware(const bool &value)
tell output algos to fill accept/reject histos based on hdw decision.
void printConfiguration(std::ostream &o) const
std::bitset< numberOfL1TopoBits > m_ovrflowHdwBits
StatusCode executeEvent()
StatusCode reset()
std::bitset< numberOfL1TopoBits > m_triggerHdwBits
StatusCode executeSortingConnector(TCS::SortingConnector *conn)
void setMsgLevel(TrigConf::MSGTC::Level lvl)
void setHardwareBits(const std::bitset< numberOfL1TopoBits > &triggerBits, const std::bitset< numberOfL1TopoBits > &ovrflowBits)
cache the decision/overflow bits from hardware These bits are propagated to the algorithms with propa...
std::shared_ptr< IL1TopoHistSvc > m_histSvc
TopoSteeringStructure m_structure
void setOutputAlgosSkipHistograms(const bool &value)
skip filling the histos
StatusCode executeDecisionConnector(TCS::DecisionConnector *conn)
const TopoSteeringStructure & structure() const
TopoInputEvent & inputEvent()
unsigned int m_evtCounter
StatusCode executeInputConnector(TCS::InputConnector *conn)
void propagateHardwareBitsToAlgos()
propagate the bits from hardware to each simulated decision algo.
StatusCode executeTrigger(const std::string &triggerName)
StatusCode setHistSvc(std::shared_ptr< IL1TopoHistSvc > histSvc)
enables the histogramming service
StatusCode executeConnector(TCS::Connector *conn)
StatusCode executeCountingConnector(TCS::CountingConnector *conn)
TopoCoreSimResult m_simulationResult
StatusCode executeCountingAlgorithm(TCS::CountingAlg *alg, TCS::InputConnector *inputConnector, Count &count)
TrigConf::MSGTC::Level m_AlgMsgLvl
StatusCode executeDecisionAlgorithm(TCS::DecisionAlg *alg, const std::vector< Connector * > &inputConnectors, const std::vector< TCS::TOBArray * > &output, Decision &decsion)
StatusCode initializeAlgorithms()
void setAlgMsgLevel(TrigConf::MSGTC::Level lvl)
static void clearHeap()
Definition cTauTOB.cxx:38
static const Heap< TCS::eEmTOB > & heap()
static void clearHeap()
Definition eTauTOB.cxx:38
static void clearHeap()
Definition gJetTOB.cxx:35
static void clearHeap()
Definition gLJetTOB.cxx:35
static void clearHeap()
Definition gTETOB.cxx:31
static void clearHeap()
Definition gXETOB.cxx:33
static void clearHeap()
Definition jEmTOB.cxx:32
static const Heap< TCS::jJetTOB > & heap()
Definition jJetTOB.h:54
static void clearHeap()
Definition jJetTOB.cxx:32
static void clearHeap()
Definition jLJetTOB.cxx:32
static void clearHeap()
Definition jTETOB.cxx:31
static void clearHeap()
Definition jTauTOB.cxx:32
static void clearHeap()
Definition jXETOB.cxx:33
L1 menu configuration.
Definition L1Menu.h:28
void setLevel(MSGTC::Level lvl)
Set message level of stream.
MsgStreamTC & msg() const
The standard message stream.
TrigConfMessaging(const std::string &name)
Constructor with parameters.
a TriggerLine entry describes the location of a threshold multiplicity on a cable (connector)
Definition L1Connector.h:22
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
STL namespace.