ATLAS Offline Software
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 
17 namespace {
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 
32 ROBPrefetchingAlg::ROBPrefetchingAlg(const std::string& name, ISvcLocator* pSvcLocator)
33 : AthReentrantAlgorithm(name, pSvcLocator) {}
34 
36  ATH_CHECK(m_inputDecisions.initialize());
37  ATH_CHECK(m_regionSelectorTools.retrieve());
38  ATH_CHECK(m_robDataProviderSvc.retrieve());
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 
54 StatusCode 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 
81  ElementLink<TrigRoiDescriptorCollection> roiEL = findLink<TrigRoiDescriptorCollection>(decision, m_roiLinkName.value()).link;
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->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 }
ROBPrefetchingAlg::m_chainFilterVec
Gaudi::Property< std::vector< TrigCompositeUtils::DecisionID > > m_chainFilterVec
ChainFilter to select decisions for specific active chains.
Definition: ROBPrefetchingAlg.h:52
TrigCompositeUtils::DecisionID
unsigned int DecisionID
Definition: TrigComposite_v1.h:27
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ROBPrefetchingAlg::ROBPrefetchingAlg
ROBPrefetchingAlg(const std::string &name, ISvcLocator *svcLoc)
Definition: ROBPrefetchingAlg.cxx:32
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
ROBPrefetchingAlg::m_roiLinkName
Gaudi::Property< std::string > m_roiLinkName
Choose the name of the RoI link to follow.
Definition: ROBPrefetchingAlg.h:48
ROBPrefetchingAlg::initialize
virtual StatusCode initialize() override
Definition: ROBPrefetchingAlg.cxx:35
ROBPrefetchingAlg::m_inputDecisions
SG::ReadHandleKeyArray< TrigCompositeUtils::DecisionContainer > m_inputDecisions
Array of input decisions from which RoIs will be extracted.
Definition: ROBPrefetchingAlg.h:36
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ROBPrefetchingAlg::m_regionSelectorTools
ToolHandleArray< IRegSelTool > m_regionSelectorTools
Array of RegionSelector tools for RoI->ROBs mapping, one for each detector to be prefetched.
Definition: ROBPrefetchingAlg.h:40
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
python.HLT.CommonSequences.EventBuildingSequences.robs
robs
Definition: EventBuildingSequences.py:401
ROBPrefetchingAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:536
DEBUG
#define DEBUG
Definition: page_access.h:11
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
ROBPrefetchingAlg::m_chainFilter
std::unordered_set< TrigCompositeUtils::DecisionID > m_chainFilter
ChainFilter as unordered_set for faster lookup.
Definition: ROBPrefetchingAlg.h:56
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigRoiDescriptor.h
ROBPrefetchingAlg::m_robDataProviderSvc
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
The ROB data provider service used to prefetch the ROBs.
Definition: ROBPrefetchingAlg.h:44
TrigRoiDescriptorCollection.h
ROBPrefetchingAlg::execute
virtual StatusCode execute(const EventContext &eventContext) const override
Definition: ROBPrefetchingAlg.cxx:54