ATLAS Offline Software
Loading...
Searching...
No Matches
ROBPrefetchingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Local includes
6#include "ROBPrefetchingAlg.h"
7
8// Trigger includes
11
12// System includes
13#include <unordered_set>
14#include <vector>
15#include <sstream>
16
17namespace {
18 std::string robSetToString(const std::unordered_set<uint32_t>& robs) {
19 std::ostringstream ss;
20 bool first{true};
21 ss << "[";
22 for (const uint32_t rob : robs) {
23 if (first) {first=false;}
24 else {ss << ", ";}
25 ss << "0x" << std::hex << rob << std::dec;
26 }
27 ss << "]";
28 return ss.str();
29 }
30}
31
32ROBPrefetchingAlg::ROBPrefetchingAlg(const std::string& name, ISvcLocator* pSvcLocator)
33: AthReentrantAlgorithm(name, pSvcLocator) {}
34
36 ATH_CHECK(m_inputDecisions.initialize());
39 ATH_MSG_DEBUG("Will consume " << m_inputDecisions.size() << " input decision collection(s):");
40 if (msgLvl(MSG::DEBUG)) {
41 for (const auto& decisionContKey : m_inputDecisions) {
42 ATH_MSG_DEBUG("- " << decisionContKey.key());
43 }
44 }
45 // Convert ChainFilter vector to set
46 m_chainFilter.insert(m_chainFilterVec.value().begin(), m_chainFilterVec.value().end());
47 if (not m_chainFilter.empty()) {
48 ATH_MSG_DEBUG("Will consider only RoIs from " << m_chainFilter.size()
49 << " chains (or chain legs) in " << m_chainFilterVec.name());
50 }
51 return StatusCode::SUCCESS;
52}
53
54StatusCode ROBPrefetchingAlg::execute(const EventContext& eventContext) const {
55 using namespace TrigCompositeUtils;
56 std::unordered_set<uint32_t> robsToPrefetch;
57 std::vector<uint32_t> robsInRoI; // reused in the loop for each RoI
58
59 // Loop over all input Decision collections to extract RoIs
60 for (const auto& decisionContKey : m_inputDecisions) {
61 SG::ReadHandle<DecisionContainer> decisionCont{decisionContKey, eventContext};
62 ATH_CHECK(decisionCont.isValid());
63 ATH_MSG_DEBUG("Processing " << decisionCont->size() << " decisions in " << decisionContKey.key());
64 for (const Decision* decision : *decisionCont) {
65
66 if (not m_chainFilter.empty()) {
67 bool skipPrefetching{true};
68 // Loop over active chains for this Decision to see if at least one matches the ChainFilter
69 for (const DecisionID chainLegID : decisionIDs(decision)) {
70 if (m_chainFilter.find(chainLegID)!=m_chainFilter.cend()) {
71 skipPrefetching = false;
72 break;
73 }
74 }
75 if (skipPrefetching) {
76 ATH_MSG_DEBUG("Skipping decision " << decision->name() << " because no active chain matches the " << m_chainFilterVec.name());
77 continue;
78 }
79 }
80
82 if (!roiEL.isValid()) {
83 ATH_MSG_WARNING("No " << m_roiLinkName.value() << " link in " << decisionContKey.key() << " decision " << *decision);
84 continue;
85 }
86
87 const TrigRoiDescriptor& roi = **roiEL;
88 ATH_MSG_DEBUG("Processing decision " << *decision);
89 ATH_MSG_DEBUG("Processing RoI: " << roi);
90
91 for (const auto& tool : m_regionSelectorTools) {
92 robsInRoI.clear();
93 tool->lookup(eventContext)->ROBIDList( roi, robsInRoI );
94 robsToPrefetch.insert(robsInRoI.begin(),robsInRoI.end());
95 }
96 }
97 }
98
99 // Prefetch all ROBs collected above
100 ATH_MSG_DEBUG("Prefetching " << robsToPrefetch.size() << " ROBs: " << robSetToString(robsToPrefetch));
101 std::vector<uint32_t> robsToPrefetchVec{robsToPrefetch.begin(),robsToPrefetch.end()};
102 m_robDataProviderSvc->addROBData(eventContext, robsToPrefetchVec, name());
103
104 return StatusCode::SUCCESS;
105}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t ss
unsigned int DecisionID
void decisionIDs(const Decision *d, DecisionIDContainer &id)
Extracts DecisionIDs stored in the Decision object.
LinkInfo< T > findLink(const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
ROBPrefetchingAlg(const std::string &name, ISvcLocator *svcLoc)
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
The ROB data provider service used to prefetch the ROBs.
ToolHandleArray< IRegSelTool > m_regionSelectorTools
Array of RegionSelector tools for RoI->ROBs mapping, one for each detector to be prefetched.
std::unordered_set< TrigCompositeUtils::DecisionID > m_chainFilter
ChainFilter as unordered_set for faster lookup.
Gaudi::Property< std::string > m_roiLinkName
Choose the name of the RoI link to follow.
virtual StatusCode initialize() override
Gaudi::Property< std::vector< TrigCompositeUtils::DecisionID > > m_chainFilterVec
ChainFilter to select decisions for specific active chains.
virtual StatusCode execute(const EventContext &eventContext) const override
SG::ReadHandleKeyArray< TrigCompositeUtils::DecisionContainer > m_inputDecisions
Array of input decisions from which RoIs will be extracted.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
bool first
Definition DeMoScan.py:534