ATLAS Offline Software
DecisionUnpackerAthena.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef XAOD_ANALYSIS // Full Athena only
6 
13 
14 
15 namespace Trig {
17  m_deckey(olddeckey) {
18  }
19 
21  }
22 
23 
25  std::map<unsigned, LVL1CTP::Lvl1Item>& itemsCache,
26  std::unordered_map<std::string, const LVL1CTP::Lvl1Item*>& itemsByName) const {
27  itemsByName.reserve( itemsByName.size() + itemsCache.size() );
28  for ( auto& [ctpid, item] : itemsCache ) {
29  ATH_MSG_VERBOSE("Unpacking bits for item: " << ctpid << " " << item.name());
30  const bool passBP = result.isPassedBeforePrescale(ctpid);
31  const bool passAP = result.isPassedAfterPrescale(ctpid);
32  const bool passAV = result.isPassedAfterVeto(ctpid);
33  LVL1CTP::Lvl1Item itemNew (item.name(), item.hashId(),
34  passBP, passAP, passAV,
35  item.prescaleFactor());
36  item = std::move (itemNew);
37  itemsByName[item.name()] = &item;
38  }
39  return StatusCode::SUCCESS;
40  }
41 
42 
43  StatusCode DecisionUnpackerAthena::unpackChains(const std::vector<uint32_t>& serialized_chains,
44  std::map<unsigned, HLT::Chain>& cache,
45  std::unordered_map<std::string, const HLT::Chain*>& output) const {
46 
47  if( serialized_chains.empty() ) {
48  ATH_MSG_WARNING("ChainResult is empty");
49  return StatusCode::FAILURE;
50  }
51 
52  output.reserve( output.size() + cache.size() );
53 
54  std::vector<uint32_t>::const_iterator rawIt = serialized_chains.begin();
55  ++rawIt; // skip first number as it is count
56  for ( ; rawIt != serialized_chains.end(); ++rawIt ) {
57 
58  unsigned cntr = HLT::Chain::inquireChainCounter(*rawIt);
59 
60  // localte now the chain
61  auto cacheIt = cache.find(cntr);
62  if ( cacheIt == cache.end() ) {
63  ATH_MSG_WARNING("Missing chain of counter in the configuration: " << cntr);
64  return StatusCode::FAILURE;
65  } else {
66  cacheIt->second.reset();
67  cacheIt->second.deserialize(*rawIt);
68  output[cacheIt->second.getChainName()] = &cacheIt->second;
69  ATH_MSG_VERBOSE("Updated chain in this event : " << cacheIt->second);
70  }
71  }
72  return StatusCode::SUCCESS;
73  }
74 
76  std::unordered_map<std::string, const LVL1CTP::Lvl1Item*>& itemsByName,
77  std::map<CTPID, LVL1CTP::Lvl1Item>& itemsCache,
78  std::unordered_map<std::string, const HLT::Chain*>& l2chainsByName,
79  std::map<CHAIN_COUNTER, HLT::Chain>& l2chainsCache,
80  std::unordered_map<std::string, const HLT::Chain*>& efchainsByName,
81  std::map<CHAIN_COUNTER, HLT::Chain>& efchainsCache,
82  char& bgCode,
83  bool unpackHLT
84  ) const {
85 
87  const TrigDec::TrigDecision* dec = trigDec.cptr();
88 
89  bgCode = dec->BGCode();
90 
91  // L1 items
92  itemsByName.clear();
93  ATH_MSG_DEBUG("Unpacking of L1 items");
94  if( unpackItems(dec->getL1Result(),itemsCache,itemsByName).isFailure() ) {
95  ATH_MSG_WARNING("Unpacking of L1 items failed");
96  }
97 
98 
99  // protect from unpacking in case HLT was not run (i.e. configuration chains are 0)
100  if (!unpackHLT) return StatusCode::SUCCESS;
101 
102 
103  // L2 chains
104  l2chainsByName.clear();
105  ATH_MSG_DEBUG("Unpacking of L2 chains");
106  if ( dec->getL2Result().getHLTLevel() != HLT::UNKNOWN ) {
107  const std::vector<uint32_t>& l2_serialized_chains = dec->getL2Result().getChainResult();
108  ATH_MSG_DEBUG(l2_serialized_chains.size() << " L2 chains");
109 
110  if ( unpackChains(l2_serialized_chains, l2chainsCache, l2chainsByName).isFailure() ) {
111  ATH_MSG_WARNING("Unpacking of L2 chains failed");
112  }
113  }
114 
115  // EF chains
116  ATH_MSG_DEBUG("Unpacking of EF/HLT chains");
117  efchainsByName.clear();
118  const std::vector<uint32_t>& ef_serialized_chains = dec->getEFResult().getChainResult();
119  ATH_MSG_DEBUG(ef_serialized_chains.size() << " EF/HLT chains");
120 
121  if ( ! ef_serialized_chains.empty()) {
122  if ( unpackChains(ef_serialized_chains, efchainsCache, efchainsByName).isFailure() ) {
123  ATH_MSG_WARNING("Unpacking of EF/HLT chains failed");
124  }
125  } else {
126  ATH_MSG_DEBUG("Empty EF/HLT chains");
127  }
128 
129  return StatusCode::SUCCESS;
130  }
131 
133  HLT::TrigNavStructure* nav) const {
134  ATH_MSG_DEBUG("Unpacking Navigation");
136  const TrigDec::TrigDecision* dec = trigDec.cptr();
137  if (nav) {
138  HLT::NavigationCore* fullNav = dynamic_cast<HLT::NavigationCore*>(nav);
139 
140  if(!fullNav){
141  ATH_MSG_WARNING("downcast failed");
142  return StatusCode::FAILURE;
143  }
144 
145  fullNav->reset();
146 
147 
148  // try to get navigation from EF/HLT
149  ATH_MSG_DEBUG("Trying to unpack EF/HLT Navigation of size: " << dec->getEFResult().getNavigationResult().size());
150 
151  bool unpacking_status = !dec->getEFResult().getNavigationResult().empty() && fullNav->deserialize(dec->getEFResult().getNavigationResult());
152 
153  if ( ! unpacking_status ) {
154  if (msgLvl(MSG::DEBUG)) {
155  msg() << MSG::DEBUG << "EF/HLT Navigation unpacking failed";
156  }
157  if (!dec->getL2Result().getNavigationResult().empty()) {
158  msg() << ", falling back to L2 Navigation of size: "
159  << dec->getL2Result().getNavigationResult().size() << endmsg;
160  unpacking_status = nav->deserialize(dec->getL2Result().getNavigationResult());
161  } else {
162  msg() << endmsg;
163  }
164  }
165  if ( ! unpacking_status ) {
166  ATH_MSG_DEBUG("Full (L2 & EF) Navigation unpacking failed");
167  } else {
168  ATH_MSG_DEBUG("Unpacked Navigation ");
169  }
170  }
171 
172  return StatusCode::SUCCESS;
173  }
174 
175 }
176 
177 #endif // full Athena env
Trig::DecisionUnpackerAthena::~DecisionUnpackerAthena
virtual ~DecisionUnpackerAthena()
Definition: DecisionUnpackerAthena.cxx:20
get_generator_info.result
result
Definition: get_generator_info.py:21
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
HLT::TrigNavStructure::deserialize
virtual bool deserialize(const std::vector< uint32_t > &)=0
Trig
The common trigger namespace for trigger analysis tools.
Definition: CaloTowerVecMon.h:44
TrigNavStructure.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::bgCode
bgCode
Definition: TrigDecision_v1.cxx:39
HLT::NavigationCore::deserialize
bool deserialize(const std::vector< uint32_t > &input)
Definition: NavigationCore.cxx:151
HLT::Chain::inquireChainCounter
static unsigned int inquireChainCounter(uint32_t chainWord)
unpack chain counter from the serialized word
Definition: Chain.cxx:123
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< TrigDec::TrigDecision >
TrigDec::TrigDecision
The TrigDecision is an object which merges trigger informations from various levels.
Definition: Trigger/TrigEvent/TrigDecisionEvent/TrigDecisionEvent/TrigDecision.h:61
HLT::TrigNavStructure
Definition: TrigNavStructure.h:40
HLT::NavigationCore::reset
virtual void reset(bool inFinalize=false)
resets all the navigation, goes to the factory and asks to withdraw all produced objects
Definition: NavigationCore.cxx:281
Trig::Logger::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/Logger.h:34
HLT::UNKNOWN
@ UNKNOWN
Definition: Trigger/TrigEvent/TrigSteeringEvent/TrigSteeringEvent/Enums.h:173
Trig::DecisionUnpackerAthena::DecisionUnpackerAthena
DecisionUnpackerAthena(const SG::ReadHandleKey< TrigDec::TrigDecision > *olddeckey)
Definition: DecisionUnpackerAthena.cxx:16
Lvl1Result.h
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
HLT::NavigationCore
The NavigationCore class, adds on top of the TrigNavStructure the EDM read-only handling.
Definition: NavigationCore.h:96
HLT::HLTResult::getChainResult
const std::vector< uint32_t > & getChainResult() const
Definition: HLTResult.h:258
HLT::HLTResult::getNavigationResult
const std::vector< uint32_t > & getNavigationResult() const
retrieve the sub-payloads (can be used to retrieve/write data)
Definition: HLTResult.h:256
LVL1CTP::Lvl1Item
Definition: Lvl1Item.h:37
TrigDec::TrigDecision::BGCode
char BGCode() const
Definition: Trigger/TrigEvent/TrigDecisionEvent/TrigDecisionEvent/TrigDecision.h:86
Trig::DecisionUnpackerAthena::unpackNavigation
virtual StatusCode unpackNavigation(const EventContext &, HLT::TrigNavStructure *) const override
Definition: DecisionUnpackerAthena.cxx:132
TrigDecision.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
Trig::DecisionUnpackerAthena::unpackItems
StatusCode unpackItems(const LVL1CTP::Lvl1Result &result, std::map< CTPID, LVL1CTP::Lvl1Item > &, std::unordered_map< std::string, const LVL1CTP::Lvl1Item * > &) const
Definition: DecisionUnpackerAthena.cxx:24
NavigationCore.h
Trig::Logger::msg
MsgStream & msg() const
Definition: Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/Logger.h:29
TrigDec::TrigDecision::getL1Result
const LVL1CTP::Lvl1Result & getL1Result() const
Definition: Trigger/TrigEvent/TrigDecisionEvent/TrigDecisionEvent/TrigDecision.h:88
Trig::DecisionUnpackerAthena::m_deckey
const SG::ReadHandleKey< TrigDec::TrigDecision > * m_deckey
Key of the trigger decision object in the event.
Definition: DecisionUnpackerAthena.h:54
merge.output
output
Definition: merge.py:17
Trig::DecisionUnpackerAthena::unpackChains
StatusCode unpackChains(const std::vector< uint32_t > &serialized_chains, std::map< unsigned, HLT::Chain > &cache, std::unordered_map< std::string, const HLT::Chain * > &output) const
Definition: DecisionUnpackerAthena.cxx:43
LVL1CTP::Lvl1Result
Definition: Lvl1Result.h:32
item
Definition: ItemListSvc.h:43
TrigDec::TrigDecision::getEFResult
const HLT::HLTResult & getEFResult() const
Definition: TrigDecision.cxx:118
DecisionUnpackerAthena.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
HLT::HLTResult::getHLTLevel
HLTLevel getHLTLevel() const
hlt level (L2 or EF)
Definition: HLTResult.h:179
StoreGateSvc.h
TrigDec::TrigDecision::getL2Result
const HLT::HLTResult & getL2Result() const
Definition: TrigDecision.cxx:107
Trig::DecisionUnpackerAthena::unpackDecision
virtual StatusCode unpackDecision(const EventContext &, std::unordered_map< std::string, const LVL1CTP::Lvl1Item * > &, std::map< CTPID, LVL1CTP::Lvl1Item > &, std::unordered_map< std::string, const HLT::Chain * > &, std::map< CHAIN_COUNTER, HLT::Chain > &, std::unordered_map< std::string, const HLT::Chain * > &, std::map< CHAIN_COUNTER, HLT::Chain > &, char &, bool) const override
Definition: DecisionUnpackerAthena.cxx:75