ATLAS Offline Software
Loading...
Searching...
No Matches
TrigSignatureMoni Class Reference

#include <TrigSignatureMoni.h>

Inheritance diagram for TrigSignatureMoni:

Classes

class  RateHistogram

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode start () override
virtual StatusCode execute (const EventContext &context) const override
virtual StatusCode stop () override
virtual void handle (const Incident &incident) override

Private Member Functions

int nBinsX (SG::ReadHandle< TrigConf::HLTMenu > &) const
int nBinsX () const
int nChains (SG::ReadHandle< TrigConf::HLTMenu > &) const
int nSteps () const
StatusCode initHist (LockedHandle< TH2 > &, SG::ReadHandle< TrigConf::HLTMenu > &, bool=true)
StatusCode initSeqHist (LockedHandle< TH2 > &, std::set< std::string > &)
StatusCode fillDecisionCount (const std::vector< TrigCompositeUtils::DecisionID > &, int) const
StatusCode fillPassEvents (const TrigCompositeUtils::DecisionIDContainer &, int) const
StatusCode fillRate (const TrigCompositeUtils::DecisionIDContainer &, int) const
StatusCode fillHistogram (const TrigCompositeUtils::DecisionIDContainer &, int, LockedHandle< TH2 > &) const
StatusCode fillSequences (const std::set< std::string > &) const
StatusCode fillStreamsAndGroups (const std::map< std::string, TrigCompositeUtils::DecisionIDContainer > &, const TrigCompositeUtils::DecisionIDContainer &, int) const

Private Attributes

SG::ReadHandleKey< TrigCompositeUtils::DecisionContainerm_l1DecisionsKey { this, "L1Decisions", "HLTSeedingSummary", "Chains activated after the L1" }
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainerm_finalDecisionKey { this, "FinalDecisionKey", "HLTNav_Summary", "Final stage of all decisions" }
SG::ReadHandleKey< TrigConf::HLTMenum_HLTMenuKey { this, "HLTTriggerMenu", "DetectorStore+HLTTriggerMenu", "HLT Menu" }
SG::ReadHandleKey< TrigConf::L1Menum_L1MenuKey { this, "L1TriggerMenu", "DetectorStore+L1TriggerMenu", "L1 Menu" }
ServiceHandle< IIncidentSvc > m_incidentSvc { this, "IncidentSvc", "IncidentSvc", "Incident service"}
ServiceHandle< ITHistSvc > m_histSvc { this, "THistSvc", "THistSvc/THistSvc", "Histogramming svc" }
Gaudi::Property< std::string > m_bookingPath { this, "HistPath", "/EXPERT/HLTFramework", "Booking path for the histogram"}
Gaudi::Property< bool > m_countLegFeatures { this, "CountLegFeatures", false, "Save features per leg as well as per chain"}
Gaudi::Property< unsigned int > m_duration {this, "RateIntegrationDuration", 10, "Integration time for the rate histogram in seconds"}
Gaudi::Property< unsigned int > m_intervals {this, "RateIntegrationIntervals", 6, "Number of the rate histogram publications"}
ToolHandleArray< DecisionCollectorToolm_decisionCollectorTools { this, "DecisionCollectorTools", {}, "Tools that collect decisions (yes/no) for steps" }
ToolHandleArray< DecisionCollectorToolm_featureCollectorTools { this, "FeatureCollectorTools", {}, "Tools that collect decision counts for specific features for steps" }
LockedHandle< TH2 > m_passHistogram ATLAS_THREAD_SAFE
LockedHandle< TH2 > m_countHistogram ATLAS_THREAD_SAFE
RateHistogram m_rateHistogram
RateHistogram m_sequenceHistogram
std::unordered_map< unsigned int, int > m_chainIDToBinMap
 Chain id to histogram bin map.
std::unordered_map< std::string, int > m_nameToBinMap
 Sequence/group/bunchgroup name to bin map.
std::unordered_map< std::string, int > m_sequenceToBinMap
 Sequence to bin map for sequence histogram.
std::map< std::string, TrigCompositeUtils::DecisionIDContainerm_groupToChainMap
 Group name to chain objects map.
std::map< std::string, TrigCompositeUtils::DecisionIDContainerm_streamToChainMap
 Stream name to chain objects map, excluding express.
std::map< std::string, TrigCompositeUtils::DecisionIDContainerm_expressChainMap
 Stream name to chain objects map, including only express.

Detailed Description

Definition at line 37 of file TrigSignatureMoni.h.

Member Function Documentation

◆ execute()

StatusCode TrigSignatureMoni::execute ( const EventContext & context) const
overridevirtual

Definition at line 324 of file TrigSignatureMoni.cxx.

324 {
325
326 SG::ReadHandle<TrigCompositeUtils::DecisionContainer> l1Decisions = SG::makeHandle(m_l1DecisionsKey, context);
327
328 [[maybe_unused]] static const bool sanityCheckDone = [&] {
329 if (l1Decisions->at(INPUT-1)->name() == "l1seeded" &&
330 l1Decisions->at(AFTER_PS-1)->name() == "unprescaled") {
331 return true;
332 }
333 throw GaudiException(m_l1DecisionsKey.key() + " does not contain the expected entries",
334 name(), StatusCode::FAILURE);
335 }();
336
337 auto fillL1 = [&](int index) -> StatusCode {
339 TrigCompositeUtils::decisionIDs(l1Decisions->at(index-1), ids);
340 ATH_MSG_DEBUG( "L1 " << index-1 << " N positive decisions " << ids.size() );
342 ATH_CHECK(fillPassEvents(ids, index));
343 ATH_CHECK(fillRate(ids, index));
344 if (!ids.empty()){
345 m_passHistogram->Fill(1, static_cast<double>(index));
346 m_rateHistogram.fill(1, static_cast<double>(index));
347 }
348 return StatusCode::SUCCESS;
349 };
350
351 // Fill histograms with L1 decisions in and after prescale
352 ATH_CHECK(fillL1(INPUT));
353 ATH_CHECK(fillL1(AFTER_PS));
354
355 // Fill HLT steps
356 int step = 0;
357 std::vector<TrigCompositeUtils::DecisionID> stepSum;
358 std::set<std::string> stepSequences;
359 for ( auto& ctool: m_decisionCollectorTools ) {
360 ctool->getDecisions( stepSum, stepSequences, context );
361 ATH_MSG_DEBUG( " Step " << step << " decisions (for decisions): " << stepSum.size() );
362 TrigCompositeUtils::DecisionIDContainer stepUniqueSum( stepSum.begin(), stepSum.end() );
363 ATH_CHECK( fillPassEvents( stepUniqueSum, 3+step ) );
364 ATH_CHECK( fillSequences( stepSequences ) );
365 ++step;
366 stepSum.clear();
367 stepSequences.clear();
368 }
369
370 step = 0;
371 for ( auto& ctool: m_featureCollectorTools ) {
372 stepSum.clear();
373 ctool->getDecisions( stepSum, context );
374 ATH_MSG_DEBUG( " Step " << step << " decisions (for features): " << stepSum.size() );
375 ATH_CHECK( fillDecisionCount( stepSum, 3+step ) );
376 ++step;
377 }
378
379 // Collect the final decisions
380 SG::ReadHandle<TrigCompositeUtils::DecisionContainer> finalDecisionsHandle = SG::makeHandle( m_finalDecisionKey, context );
381 ATH_CHECK( finalDecisionsHandle.isValid() );
383 const TrigCompositeUtils::Decision* decisionObject = TrigCompositeUtils::getTerminusNode(*finalDecisionsHandle);
384 if (!decisionObject) {
385 ATH_MSG_WARNING("Unable to locate trigger navigation terminus node. Cannot tell which chains passed the event.");
386 } else {
387 TrigCompositeUtils::decisionIDs(decisionObject, finalIDs);
388 }
389
390 // Collect the express stream decisions
392 const TrigCompositeUtils::Decision* expressDecisionObject = TrigCompositeUtils::getExpressTerminusNode(*finalDecisionsHandle);
393 if (!expressDecisionObject) {
394 ATH_MSG_WARNING("Unable to locate trigger navigation express terminus node. Cannot tell which chains passed the express stream in this event.");
395 } else {
396 TrigCompositeUtils::decisionIDs(expressDecisionObject, expressFinalIDs);
397 }
398
399 // Fill the histograms with output counts/rate
400 const int countOutputRow {nSteps() + OUTPUT};
403 ATH_CHECK( fillPassEvents(finalIDs, countOutputRow));
404 ATH_CHECK( fillRate(finalIDs, OUTPUT));
405
406 // Fill the histograms with express counts/rate
407 const int countExpressRow {nSteps() + EXPRESS};
408 // express stream rate is filled into OUTPUT bin on purpose
411 ATH_CHECK( fillPassEvents(expressFinalIDs, countExpressRow));
412 ATH_CHECK( fillRate(expressFinalIDs, EXPRESS));
413
414 // Fill the "All" column in counts/rate histograms
415 if (!finalIDs.empty()) {
416 m_passHistogram->Fill(1, static_cast<double>(countOutputRow));
417 m_rateHistogram.fill(1, static_cast<double>(OUTPUT));
418 }
419 if (!expressFinalIDs.empty()) {
420 m_passHistogram->Fill(1, static_cast<double>(countExpressRow));
421 m_rateHistogram.fill(1, static_cast<double>(EXPRESS));
422 }
423
424 return StatusCode::SUCCESS;
425}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode fillPassEvents(const TrigCompositeUtils::DecisionIDContainer &, int) const
StatusCode fillRate(const TrigCompositeUtils::DecisionIDContainer &, int) const
std::map< std::string, TrigCompositeUtils::DecisionIDContainer > m_streamToChainMap
Stream name to chain objects map, excluding express.
StatusCode fillDecisionCount(const std::vector< TrigCompositeUtils::DecisionID > &, int) const
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_l1DecisionsKey
std::map< std::string, TrigCompositeUtils::DecisionIDContainer > m_expressChainMap
Stream name to chain objects map, including only express.
std::map< std::string, TrigCompositeUtils::DecisionIDContainer > m_groupToChainMap
Group name to chain objects map.
StatusCode fillSequences(const std::set< std::string > &) const
RateHistogram m_rateHistogram
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_finalDecisionKey
StatusCode fillStreamsAndGroups(const std::map< std::string, TrigCompositeUtils::DecisionIDContainer > &, const TrigCompositeUtils::DecisionIDContainer &, int) const
ToolHandleArray< DecisionCollectorTool > m_decisionCollectorTools
ToolHandleArray< DecisionCollectorTool > m_featureCollectorTools
str index
Definition DeMoScan.py:362
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
xAOD::TrigComposite Decision
const Decision * getExpressTerminusNode(const DecisionContainer &container)
Returns the express-accept navigation node from a collection or nullptr if missing.
std::set< DecisionID > DecisionIDContainer
const Decision * getTerminusNode(SG::ReadHandle< DecisionContainer > &container)
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.

◆ fillDecisionCount()

StatusCode TrigSignatureMoni::fillDecisionCount ( const std::vector< TrigCompositeUtils::DecisionID > & dc,
int row ) const
private

Definition at line 260 of file TrigSignatureMoni.cxx.

260 {
261 for (TrigCompositeUtils::DecisionID id : dc) {
262 if (!m_countLegFeatures && TrigCompositeUtils::isLegId(HLT::Identifier(id))) {continue;}
263 auto id2bin = m_chainIDToBinMap.find( id );
264 if ( id2bin == m_chainIDToBinMap.end()) {
265 ATH_MSG_WARNING("HLT chain " << HLT::Identifier(id) << " not configured to be monitored");
266 } else {
267 ATH_MSG_VERBOSE( "Filling histogram for " << HLT::Identifier(id).name() << " ==> bin " << id2bin->second);
268 m_countHistogram->Fill(id2bin->second, static_cast<double>(row));
269 }
270 }
271
272 return StatusCode::SUCCESS;
273}
#define ATH_MSG_VERBOSE(x,...)
Gaudi::Property< bool > m_countLegFeatures
std::unordered_map< unsigned int, int > m_chainIDToBinMap
Chain id to histogram bin map.
unsigned int DecisionID
bool isLegId(const HLT::Identifier &legIdentifier)
Recognise whether the chain ID is a leg ID.

◆ fillHistogram()

StatusCode TrigSignatureMoni::fillHistogram ( const TrigCompositeUtils::DecisionIDContainer & dc,
int row,
LockedHandle< TH2 > & histogram ) const
private

Definition at line 231 of file TrigSignatureMoni.cxx.

231 {
232
233 // This locks the histogram handle for the entire duration of the function,
234 // which is faster than (un)locking the handle many times during the loop.
235 auto lockedHist = *histogram;
236
237 for (TrigCompositeUtils::DecisionID id : dc) {
238 auto id2bin = m_chainIDToBinMap.find( id );
239 // Can ignore leg IDs if we are not explicitly saving their counts
240 if ( id2bin == m_chainIDToBinMap.end() ) {
241 if (!(!m_countLegFeatures && TrigCompositeUtils::isLegId(HLT::Identifier(id)))) {
242 ATH_MSG_WARNING( "HLT chain " << HLT::Identifier(id) << " not configured to be monitored" );
243 }
244 } else {
245 ATH_MSG_VERBOSE( "Filling histogram for " << HLT::Identifier(id).name() << " ==> bin " << id2bin->second );
246 lockedHist->Fill( id2bin->second, static_cast<double>(row) );
247 }
248 }
249 return StatusCode::SUCCESS;
250}
std::string histogram
Definition chains.cxx:52

◆ fillPassEvents()

StatusCode TrigSignatureMoni::fillPassEvents ( const TrigCompositeUtils::DecisionIDContainer & dc,
int row ) const
private

Definition at line 256 of file TrigSignatureMoni.cxx.

256 {
257 return fillHistogram(dc, row, m_passHistogram);
258}
StatusCode fillHistogram(const TrigCompositeUtils::DecisionIDContainer &, int, LockedHandle< TH2 > &) const

◆ fillRate()

StatusCode TrigSignatureMoni::fillRate ( const TrigCompositeUtils::DecisionIDContainer & dc,
int row ) const
private

Definition at line 252 of file TrigSignatureMoni.cxx.

252 {
253 return fillHistogram(dc, row, m_rateHistogram.getBuffer());
254}

◆ fillSequences()

StatusCode TrigSignatureMoni::fillSequences ( const std::set< std::string > & sequences) const
private

Definition at line 275 of file TrigSignatureMoni.cxx.

275 {
276 for (const std::string& seq : sequences) {
278 }
279
280 return StatusCode::SUCCESS;
281}
std::unordered_map< std::string, int > m_sequenceToBinMap
Sequence to bin map for sequence histogram.
RateHistogram m_sequenceHistogram

◆ fillStreamsAndGroups()

StatusCode TrigSignatureMoni::fillStreamsAndGroups ( const std::map< std::string, TrigCompositeUtils::DecisionIDContainer > & nameToChainsMap,
const TrigCompositeUtils::DecisionIDContainer & dc,
int row ) const
private

Definition at line 283 of file TrigSignatureMoni.cxx.

283 {
284
285 // Adjust bin index for those histograms that monitor all steps
286 int rowWithSteps = row;
287 if (row==OUTPUT || row==EXPRESS) rowWithSteps += m_decisionCollectorTools.size();
288
289 for (const auto& [name, decisions] : nameToChainsMap) {
290 for (TrigCompositeUtils::DecisionID id : dc) {
291 if (decisions.contains(id)) {
292 const double bin = m_nameToBinMap.at(name);
293 m_rateHistogram.fill(bin, row);
294 m_countHistogram->Fill(bin, rowWithSteps);
295 m_passHistogram->Fill(bin, rowWithSteps);
296 break;
297 }
298 }
299 }
300 return StatusCode::SUCCESS;
301}
std::unordered_map< std::string, int > m_nameToBinMap
Sequence/group/bunchgroup name to bin map.
row
Appending html table to final .html summary file.

◆ handle()

void TrigSignatureMoni::handle ( const Incident & incident)
overridevirtual

Definition at line 303 of file TrigSignatureMoni.cxx.

303 {
304 // Create and start timer after fork
305 if (incident.type() == AthenaInterprocess::UpdateAfterFork::type()) {
306 if (m_rateHistogram.getTimer() || m_sequenceHistogram.getTimer()) {
307 ATH_MSG_WARNING("Timer is already running. UpdateAfterFork incident called more than once?");
308 return;
309 }
310
311 // Prevent from publishing empty histograms
312 if (nBinsX() > 0) {
314 }
315
316 if (!m_sequenceToBinMap.empty()) {
318 }
319
320 ATH_MSG_DEBUG("Started rate timer");
321 }
322}
static const std::string & type()
Incident type.
Definition Incidents.h:49
Gaudi::Property< unsigned int > m_intervals
Gaudi::Property< unsigned int > m_duration

◆ initHist()

StatusCode TrigSignatureMoni::initHist ( LockedHandle< TH2 > & hist,
SG::ReadHandle< TrigConf::HLTMenu > & hltMenuHandle,
bool steps = true )
private

Definition at line 451 of file TrigSignatureMoni.cxx.

451 {
452 TAxis* x = hist->GetXaxis();
453 x->SetBinLabel(1, "All");
454 int bin = 2; // 1 is for total count, (remember bin numbering in ROOT starts from 1)
455
456 std::set<std::string> sortedChainsList;
457 std::map<unsigned int,size_t> chainMultiplicities;
458 for ( const TrigConf::Chain& chain: *hltMenuHandle ) {
459 sortedChainsList.insert( chain.name() );
460 // if counting features, record the number of legs for later
462 std::vector<size_t> legs = chain.legMultiplicities();
463 chainMultiplicities.emplace( HLT::Identifier(chain.name()).numeric() ,legs.size());
464 if(legs.size()>1) {
465 ATH_MSG_DEBUG("For chain " << chain.name() << ", also recording feature counts for " << legs.size() << " legs.");
466 }
467 }
468 }
469
470 for ( const std::string& chainName: sortedChainsList ) {
471 x->SetBinLabel( bin, chainName.c_str() );
472 unsigned int chainID = HLT::Identifier( chainName ).numeric();
473 m_chainIDToBinMap[ chainID ] = bin;
474 ATH_MSG_VERBOSE(chainName << " --> bin " << bin );
475 ++bin;
476 if(m_countLegFeatures && chainMultiplicities[chainID]>1) {
477 size_t nlegs = chainMultiplicities[chainID];
478 // n.b. we don't care about the content of this vector (the required multiplicity per leg), just its size
479 for (size_t legID = 0; legID < nlegs; ++ legID) {
480 const std::string legName = ( TrigCompositeUtils::createLegName(HLT::Identifier(chainName), legID).name() );
481 ATH_MSG_VERBOSE(" " << legName << " --> bin " << bin );
482 x->SetBinLabel( bin, legName.c_str() );
483 m_chainIDToBinMap[ HLT::Identifier( legName ).numeric() ] = bin;
484 ++bin;
485 }
486 }
487 }
488
489
490 for ( const auto& stream : m_streamToChainMap){
491 x->SetBinLabel( bin, ("str_"+stream.first).c_str());
492 m_nameToBinMap[ stream.first ] = bin;
493 bin++;
494 }
495
496 for ( const auto& stream : m_expressChainMap){
497 x->SetBinLabel( bin, ("str_"+stream.first).c_str());
498 m_nameToBinMap[ stream.first ] = bin;
499 bin++;
500 }
501
502 for ( const auto& group : m_groupToChainMap){
503 x->SetBinLabel( bin, ("grp_"+group.first.substr(group.first.find(':')+1)).c_str() );
504 m_nameToBinMap[ group.first ] = bin;
505 bin++;
506 }
507
508
509 TAxis* y = hist->GetYaxis();
510 y->SetBinLabel(INPUT, steps ? "L1" : "Input");
511 y->SetBinLabel(AFTER_PS, "AfterPS");
512 for ( size_t i = 0; steps && i < m_decisionCollectorTools.size(); ++i) {
513 y->SetBinLabel(3 + i, std::format("Step {:d}", i).c_str());
514 }
515 y->SetBinLabel(y->GetNbins()-1, "Output"); // Second to last bin
516 y->SetBinLabel(y->GetNbins(), "Express"); // Last bin
517
518 return StatusCode::SUCCESS;
519}
#define y
#define x
std::string name() const
reports human redable name
HLT::Identifier createLegName(const HLT::Identifier &chainIdentifier, size_t counter)
Generate the HLT::Identifier which corresponds to a specific leg of a given chain.

◆ initialize()

StatusCode TrigSignatureMoni::initialize ( )
overridevirtual

Definition at line 25 of file TrigSignatureMoni.cxx.

25 {
26 ATH_CHECK(m_l1DecisionsKey.initialize());
27 ATH_CHECK(m_finalDecisionKey.initialize());
28 ATH_CHECK(m_HLTMenuKey.initialize());
29 ATH_CHECK(m_L1MenuKey.initialize());
32 ATH_CHECK(m_histSvc.retrieve());
33
34 ATH_CHECK(m_incidentSvc.retrieve());
36
37 return StatusCode::SUCCESS;
38}
ServiceHandle< ITHistSvc > m_histSvc
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
ServiceHandle< IIncidentSvc > m_incidentSvc
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey

◆ initSeqHist()

StatusCode TrigSignatureMoni::initSeqHist ( LockedHandle< TH2 > & hist,
std::set< std::string > & sequenceSet )
private

Definition at line 521 of file TrigSignatureMoni.cxx.

521 {
522 TAxis* x = hist->GetXaxis();
523 int bin = 1;
524
525 // Set bin labels
526 for (const std::string& seqName : sequenceSet) {
527 x->SetBinLabel(bin, seqName.c_str());
528 m_sequenceToBinMap[seqName] = bin;
529 ++bin;
530 }
531
532 TAxis* y = hist->GetYaxis();
533 y->SetBinLabel(1, "Rate");
534
535 return StatusCode::SUCCESS;
536}

◆ nBinsX() [1/2]

int TrigSignatureMoni::nBinsX ( ) const
private

Definition at line 431 of file TrigSignatureMoni.cxx.

431 {
432 return m_chainIDToBinMap.size() + m_groupToChainMap.size() + m_streamToChainMap.size() + m_expressChainMap.size() + 1;
433}

◆ nBinsX() [2/2]

int TrigSignatureMoni::nBinsX ( SG::ReadHandle< TrigConf::HLTMenu > & hltMenuHandle) const
private

Definition at line 427 of file TrigSignatureMoni.cxx.

427 {
428 return nChains(hltMenuHandle) + m_groupToChainMap.size() + m_streamToChainMap.size() + m_expressChainMap.size();
429}
int nChains(SG::ReadHandle< TrigConf::HLTMenu > &) const

◆ nChains()

int TrigSignatureMoni::nChains ( SG::ReadHandle< TrigConf::HLTMenu > & hltMenuHandle) const
private

Definition at line 435 of file TrigSignatureMoni.cxx.

435 {
436 int nchains = hltMenuHandle->size();
437 // If we want the leg counts, need to accumulate the multiplicities from each chain
439 for (const TrigConf::Chain& chain : *hltMenuHandle){
440 std::vector<size_t> legs = chain.legMultiplicities();
441 if(legs.size()>1) {nchains += legs.size();}
442 }
443 }
444 return nchains + 1; // Chains + "All"
445}

◆ nSteps()

int TrigSignatureMoni::nSteps ( ) const
private

Definition at line 447 of file TrigSignatureMoni.cxx.

447 {
448 return m_decisionCollectorTools.size();
449}

◆ start()

StatusCode TrigSignatureMoni::start ( )
overridevirtual

Definition at line 40 of file TrigSignatureMoni.cxx.

40 {
41 SG::ReadHandle<TrigConf::L1Menu> l1MenuHandle = SG::makeHandle(m_L1MenuKey);
42 SG::ReadHandle<TrigConf::HLTMenu> hltMenuHandle = SG::makeHandle(m_HLTMenuKey);
43 ATH_CHECK(hltMenuHandle.isValid());
44
45 // Retrieve chain information from menus
46 m_groupToChainMap.clear();
47 m_streamToChainMap.clear();
48 m_expressChainMap.clear();
49
50 std::unordered_map<std::string,std::string> mapStrNameToTypeName; // e.g. {Main -> physics_Main}
51 try {
52 const std::string nameStr{"name"};
53 const std::string typeStr{"type"};
54 for (const TrigConf::DataStructure& stream : hltMenuHandle->streams()) {
55 mapStrNameToTypeName.insert({stream.getAttribute(nameStr), stream.getAttribute(typeStr)+"_"+stream.getAttribute(nameStr)});
56 }
57 } catch (const std::exception& ex) {
58 ATH_MSG_ERROR("Exception reading stream tag configuration from the HLT menu: " << ex.what());
59 return StatusCode::FAILURE;
60 }
61
62 for (const TrigConf::Chain& chain : *hltMenuHandle) {
63 for (const std::string& group : chain.groups()) {
64 // Save chains per RATE group
65 if (group.starts_with( "RATE")){
66 m_groupToChainMap[group].insert(HLT::Identifier(chain.name()));
67 }
68 }
69
70 // Save chain to stream map
71 for (const std::string& streamName : chain.streams()){
72 const auto it = mapStrNameToTypeName.find(streamName);
73 if (it==mapStrNameToTypeName.cend()) {
74 ATH_MSG_ERROR("Stream name " << streamName << " assigned to chain " << chain.name()
75 << " is missing from menu streams definition");
76 return StatusCode::FAILURE;
77 }
78 if (it->second == "express_express") {
79 m_expressChainMap[it->second].insert(HLT::Identifier(chain.name()));
80 } else {
81 m_streamToChainMap[it->second].insert(HLT::Identifier(chain.name()));
82 }
83 }
84 }
85
86 // Prepare the histograms
87
88 // Initialize SignatureAcceptance and DecisionCount histograms that will monitor
89 // chains, groups and sequences per each step
90 const int x {nBinsX(hltMenuHandle)};
91 const int y {nSteps() + N_BINS};
92 ATH_MSG_DEBUG( "Histogram " << x << " x " << y << " bins");
93 std::unique_ptr<TH2> hSA = std::make_unique<TH2I>("SignatureAcceptance", "Raw acceptance of signatures in;chain;step", x, 1, x + 1, y, 1, y + 1);
94 std::unique_ptr<TH2> hDC = std::make_unique<TH2I>("DecisionCount", "Positive decisions count per step;chain;step", x, 1, x + 1, y, 1, y + 1);
95
96 ATH_CHECK(m_histSvc->regShared(m_bookingPath + "/" + name() + "/SignatureAcceptance", std::move(hSA), m_passHistogram));
97 ATH_CHECK(m_histSvc->regShared(m_bookingPath + "/" + name() + "/DecisionCount", std::move(hDC), m_countHistogram));
98
99 ATH_CHECK(initHist(m_passHistogram, hltMenuHandle));
100 ATH_CHECK(initHist(m_countHistogram, hltMenuHandle));
101
102 // Initialize Rate histogram to save the rates of positive decisions in given interval
103 // per chain/group/sequence per in, after ps, out steps
104 if ( x > 0 ){
105 const std::string outputRateName = std::format("Rate{:d}s", m_duration.value());
106 m_rateHistogram.init(outputRateName, "Rate of positive decisions;chain;step", x, N_BINS,
107 std::format("{}/{}/{}", m_bookingPath.value(), name(), outputRateName), m_histSvc).ignore();
108 ATH_CHECK(initHist(m_rateHistogram.getHistogram(), hltMenuHandle, false));
109 ATH_CHECK(initHist(m_rateHistogram.getBuffer(), hltMenuHandle, false));
110 }
111
112 // Initialize SequencesExecutionRate histogram to save the rates of sequences execution
113 // Save sequences names to be monitored
114 std::set<std::string> sequencesSet;
115 for (auto& ctool: m_decisionCollectorTools){
116 ctool->getSequencesNames(sequencesSet);
117 }
118 const int xc = sequencesSet.size();
119 const int yc {1}; // Only rate, this histogram is really 1 D
120 if (xc > 0){
121 const std::string outputSequenceName = std::format("SequencesExecutionRate{:d}s", m_duration.value());
122 m_sequenceHistogram.init(outputSequenceName, "Rate of sequences execution;sequence;rate", xc, yc,
123 std::format("{}/{}/{}", m_bookingPath.value(), name(), outputSequenceName), m_histSvc).ignore();
124
125 ATH_CHECK(initSeqHist(m_sequenceHistogram.getHistogram(), sequencesSet));
126 ATH_CHECK(initSeqHist(m_sequenceHistogram.getBuffer(), sequencesSet));
127 }
128
129 return StatusCode::SUCCESS;
130}
#define ATH_MSG_ERROR(x,...)
StatusCode initHist(LockedHandle< TH2 > &, SG::ReadHandle< TrigConf::HLTMenu > &, bool=true)
StatusCode initSeqHist(LockedHandle< TH2 > &, std::set< std::string > &)
Gaudi::Property< std::string > m_bookingPath

◆ stop()

StatusCode TrigSignatureMoni::stop ( )
overridevirtual

Definition at line 132 of file TrigSignatureMoni.cxx.

132 {
133 m_rateHistogram.stopTimer();
134 m_sequenceHistogram.stopTimer();
135
136 if (m_chainIDToBinMap.empty()) {
137 ATH_MSG_INFO( "No chains configured, no counts to print" );
138 return StatusCode::SUCCESS;
139 }
140
141 SG::ReadHandle<TrigConf::HLTMenu> hltMenuHandle = SG::makeHandle(m_HLTMenuKey);
142 ATH_CHECK(hltMenuHandle.isValid());
143
144 // Retrieve information whether chain was active in Step
145 std::unordered_map<std::string, std::set<int>> chainToStepsId;
146 for (const TrigConf::Chain& chain : *hltMenuHandle){
147 int nstep {1}; // Start from step=1
148 for (const std::string& seqName : chain.sequencers()){
149 // Example sequencer name is "Step1_FastCalo_electron", we need only information about Step + number
150 std::smatch stepNameMatch;
151 std::regex_search(seqName.begin(), seqName.end(), stepNameMatch, std::regex("[Ss]tep[0-9]+"));
152
153 std::string stepName = stepNameMatch[0];
154 stepName[0] = std::toupper(stepName[0]); // Fix "stepX" -> "StepX"
155 // Check that the step name is set with the same position in the execution (empty steps support)
156 if (std::format("Step{:d}", nstep) == stepName) {
157 chainToStepsId[chain.name()].insert(nstep);
158 if(m_countLegFeatures && chain.legMultiplicities().size()>1) {
159 for (size_t legID = 0; legID < chain.legMultiplicities().size(); ++ legID) {
160 const std::string legName = ( TrigCompositeUtils::createLegName(HLT::Identifier(chain.name()), legID).name() );
161 chainToStepsId[legName].insert(nstep);
162 }
163 }
164 } else {
165 ATH_MSG_DEBUG("Missing counts for step" << nstep << " in chain " << chain.name());
166 }
167 nstep++;
168 }
169 }
170
171 auto collToString = [&](int xbin, const LockedHandle<TH2>& hist, int startOfset=0, int endOffset=0){
172 std::string v;
173 const int stepsSize = hist->GetYaxis()->GetNbins() - N_BINS;
174 for (int ybin = 1; ybin <= hist->GetYaxis()->GetNbins()-endOffset; ++ybin) {
175 if (ybin > startOfset) {
176 // Skip steps where chain wasn't active
177 // ybins are for all axis labes, steps are in bins from 3 to stepsSize + 2
178 const std::string chainName = m_passHistogram->GetXaxis()->GetBinLabel(xbin);
179
180 if (ybin < 3 || ybin > stepsSize + 2 || chainToStepsId[chainName].contains(ybin - 2)) {
181 v += std::format("{:<11d}", static_cast<int>(hist->GetBinContent(xbin, ybin)));
182 } else {
183 v += std::format("{:<11s}", "-");
184 }
185 } else {
186 v += std::format("{:<11s}", " ");
187 }
188 }
189 return v;
190 };
191
192 std::string v;
193 v += std::format("{:<11s}", "L1");
194 v += std::format("{:<11s}", "AfterPS");
195 for (int bin = 1; bin <= m_passHistogram->GetYaxis()->GetNbins()-N_BINS; ++bin) {
196 v += std::format("Step{:<7d}", bin);
197 }
198 v += std::format("{:<11s}", "Output");
199 v += std::format("{:<11s}", "Express");
200
201 ATH_MSG_INFO("Chains passing step (1st row events & 2nd row decision counts):");
202 ATH_MSG_INFO(" Feature counts reflect the number of unique objects contributing to a positive chain decision (0 if step fails), including L1RoI for empty steps.");
204 ATH_MSG_INFO(" Leg feature counts indicate the number of unique objects that pass the leg's step selection (regardless of multiplicity), which may overlap with other legs.");
205 ATH_MSG_INFO(" 'PROBE' L1 RoIs are counted separately.");
206 }
207
208 ATH_MSG_INFO(std::format("{:<30s}", "ChainName") << v);
209
210
211 for (int bin = 1; bin <= (*m_passHistogram)->GetXaxis()->GetNbins(); ++bin) {
212 const std::string chainName = m_passHistogram->GetXaxis()->GetBinLabel(bin);
213 const std::string chainID = std::to_string(HLT::Identifier(chainName));
214 if (chainName.starts_with( "HLT")) { // print only for chains
215 ATH_MSG_INFO( std::format("{:s} #{:s}", chainName, chainID) );
216 ATH_MSG_INFO( std::format("{:<30s}", std::format("-- #{} Events", chainID)) << collToString( bin, m_passHistogram) );
217 ATH_MSG_INFO( std::format("{:<30s}", std::format("-- #{} Features", chainID)) << collToString( bin, m_countHistogram , 2, 1 ) );
218 }
219 if (chainName.starts_with( "All")){
220 ATH_MSG_INFO( std::format("{:<30s}", chainName) << collToString( bin, m_passHistogram) );
221 }
222 if (chainName.starts_with("leg")) { // print features only for legs
223 const std::string legID = chainName.substr(0,6);
224 ATH_MSG_INFO( std::format("{:<30s}", std::format("-- #{} Features", legID)) << collToString( bin, m_countHistogram , 2, 1 ) );
225 }
226 }
227
228 return StatusCode::SUCCESS;
229}
#define ATH_MSG_INFO(x,...)
size_t size() const
Number of registered mappings.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/2]

LockedHandle<TH2> m_countHistogram TrigSignatureMoni::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 112 of file TrigSignatureMoni.h.

◆ ATLAS_THREAD_SAFE [2/2]

LockedHandle<TH2> m_passHistogram TrigSignatureMoni::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 111 of file TrigSignatureMoni.h.

◆ m_bookingPath

Gaudi::Property<std::string> TrigSignatureMoni::m_bookingPath { this, "HistPath", "/EXPERT/HLTFramework", "Booking path for the histogram"}
private

Definition at line 99 of file TrigSignatureMoni.h.

99{ this, "HistPath", "/EXPERT/HLTFramework", "Booking path for the histogram"};

◆ m_chainIDToBinMap

std::unordered_map<unsigned int, int> TrigSignatureMoni::m_chainIDToBinMap
private

Chain id to histogram bin map.

Definition at line 117 of file TrigSignatureMoni.h.

◆ m_countLegFeatures

Gaudi::Property<bool> TrigSignatureMoni::m_countLegFeatures { this, "CountLegFeatures", false, "Save features per leg as well as per chain"}
private

Definition at line 101 of file TrigSignatureMoni.h.

101{ this, "CountLegFeatures", false, "Save features per leg as well as per chain"};

◆ m_decisionCollectorTools

ToolHandleArray<DecisionCollectorTool> TrigSignatureMoni::m_decisionCollectorTools { this, "DecisionCollectorTools", {}, "Tools that collect decisions (yes/no) for steps" }
private

Definition at line 107 of file TrigSignatureMoni.h.

107{ this, "DecisionCollectorTools", {}, "Tools that collect decisions (yes/no) for steps" };

◆ m_duration

Gaudi::Property<unsigned int> TrigSignatureMoni::m_duration {this, "RateIntegrationDuration", 10, "Integration time for the rate histogram in seconds"}
private

Definition at line 104 of file TrigSignatureMoni.h.

104{this, "RateIntegrationDuration", 10, "Integration time for the rate histogram in seconds"};

◆ m_expressChainMap

std::map<std::string, TrigCompositeUtils::DecisionIDContainer> TrigSignatureMoni::m_expressChainMap
private

Stream name to chain objects map, including only express.

Definition at line 124 of file TrigSignatureMoni.h.

◆ m_featureCollectorTools

ToolHandleArray<DecisionCollectorTool> TrigSignatureMoni::m_featureCollectorTools { this, "FeatureCollectorTools", {}, "Tools that collect decision counts for specific features for steps" }
private

Definition at line 108 of file TrigSignatureMoni.h.

108{ this, "FeatureCollectorTools", {}, "Tools that collect decision counts for specific features for steps" };

◆ m_finalDecisionKey

SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer> TrigSignatureMoni::m_finalDecisionKey { this, "FinalDecisionKey", "HLTNav_Summary", "Final stage of all decisions" }
private

Definition at line 93 of file TrigSignatureMoni.h.

93{ this, "FinalDecisionKey", "HLTNav_Summary", "Final stage of all decisions" };

◆ m_groupToChainMap

std::map<std::string, TrigCompositeUtils::DecisionIDContainer> TrigSignatureMoni::m_groupToChainMap
private

Group name to chain objects map.

Definition at line 122 of file TrigSignatureMoni.h.

◆ m_histSvc

ServiceHandle<ITHistSvc> TrigSignatureMoni::m_histSvc { this, "THistSvc", "THistSvc/THistSvc", "Histogramming svc" }
private

Definition at line 98 of file TrigSignatureMoni.h.

98{ this, "THistSvc", "THistSvc/THistSvc", "Histogramming svc" };

◆ m_HLTMenuKey

SG::ReadHandleKey<TrigConf::HLTMenu> TrigSignatureMoni::m_HLTMenuKey { this, "HLTTriggerMenu", "DetectorStore+HLTTriggerMenu", "HLT Menu" }
private

Definition at line 94 of file TrigSignatureMoni.h.

94{ this, "HLTTriggerMenu", "DetectorStore+HLTTriggerMenu", "HLT Menu" };

◆ m_incidentSvc

ServiceHandle<IIncidentSvc> TrigSignatureMoni::m_incidentSvc { this, "IncidentSvc", "IncidentSvc", "Incident service"}
private

Definition at line 97 of file TrigSignatureMoni.h.

97{ this, "IncidentSvc", "IncidentSvc", "Incident service"};

◆ m_intervals

Gaudi::Property<unsigned int> TrigSignatureMoni::m_intervals {this, "RateIntegrationIntervals", 6, "Number of the rate histogram publications"}
private

Definition at line 105 of file TrigSignatureMoni.h.

105{this, "RateIntegrationIntervals", 6, "Number of the rate histogram publications"};

◆ m_l1DecisionsKey

SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer> TrigSignatureMoni::m_l1DecisionsKey { this, "L1Decisions", "HLTSeedingSummary", "Chains activated after the L1" }
private

Definition at line 92 of file TrigSignatureMoni.h.

92{ this, "L1Decisions", "HLTSeedingSummary", "Chains activated after the L1" };

◆ m_L1MenuKey

SG::ReadHandleKey<TrigConf::L1Menu> TrigSignatureMoni::m_L1MenuKey { this, "L1TriggerMenu", "DetectorStore+L1TriggerMenu", "L1 Menu" }
private

Definition at line 95 of file TrigSignatureMoni.h.

95{ this, "L1TriggerMenu", "DetectorStore+L1TriggerMenu", "L1 Menu" };

◆ m_nameToBinMap

std::unordered_map<std::string, int> TrigSignatureMoni::m_nameToBinMap
private

Sequence/group/bunchgroup name to bin map.

Definition at line 118 of file TrigSignatureMoni.h.

◆ m_rateHistogram

RateHistogram TrigSignatureMoni::m_rateHistogram
private

Definition at line 113 of file TrigSignatureMoni.h.

◆ m_sequenceHistogram

RateHistogram TrigSignatureMoni::m_sequenceHistogram
private

Definition at line 114 of file TrigSignatureMoni.h.

◆ m_sequenceToBinMap

std::unordered_map<std::string, int> TrigSignatureMoni::m_sequenceToBinMap
private

Sequence to bin map for sequence histogram.

Definition at line 119 of file TrigSignatureMoni.h.

◆ m_streamToChainMap

std::map<std::string, TrigCompositeUtils::DecisionIDContainer> TrigSignatureMoni::m_streamToChainMap
private

Stream name to chain objects map, excluding express.

Definition at line 123 of file TrigSignatureMoni.h.


The documentation for this class was generated from the following files: