ATLAS Offline Software
Loading...
Searching...
No Matches
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
15namespace Trig {
19
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
75 StatusCode DecisionUnpackerAthena::unpackDecision(const EventContext& ctx,
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
132 StatusCode DecisionUnpackerAthena::unpackNavigation(const EventContext& ctx,
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
#define endmsg
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static unsigned int inquireChainCounter(uint32_t chainWord)
unpack chain counter from the serialized word
Definition Chain.cxx:123
const std::vector< uint32_t > & getNavigationResult() const
retrieve the sub-payloads (can be used to retrieve/write data)
Definition HLTResult.h:250
HLTLevel getHLTLevel() const
hlt level (L2 or EF)
Definition HLTResult.h:173
const std::vector< uint32_t > & getChainResult() const
Definition HLTResult.h:252
The NavigationCore class, adds on top of the TrigNavStructure the EDM read-only handling.
virtual void reset(bool inFinalize=false)
resets all the navigation, goes to the factory and asks to withdraw all produced objects
bool deserialize(const std::vector< uint32_t > &input)
virtual bool deserialize(const std::vector< uint32_t > &)=0
Property holding a SG store/key/clid from which a ReadHandle is made.
const_pointer_type cptr()
Dereference the pointer.
The TrigDecision is an object which merges trigger informations from various levels.
const HLT::HLTResult & getEFResult() const
const HLT::HLTResult & getL2Result() const
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
virtual StatusCode unpackNavigation(const EventContext &, HLT::TrigNavStructure *) const override
StatusCode unpackItems(const LVL1CTP::Lvl1Result &result, std::map< CTPID, LVL1CTP::Lvl1Item > &, std::unordered_map< std::string, const LVL1CTP::Lvl1Item * > &) const
const SG::ReadHandleKey< TrigDec::TrigDecision > * m_deckey
Key of the trigger decision object in the event.
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
DecisionUnpackerAthena(const SG::ReadHandleKey< TrigDec::TrigDecision > *olddeckey)
The common trigger namespace for trigger analysis tools.