ATLAS Offline Software
Loading...
Searching...
No Matches
DecisionUnpackerStandalone.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// Trigger include(s):
9
13
14// Local include(s):
16
17#if !defined(XAOD_STANDALONE) && !defined(XAOD_ANALYSIS) // Full athena
19#endif
20
21namespace {
22
25 bool get32BitDecision( unsigned int index,
26 const std::vector< uint32_t >& vec ) {
27
28 if( index >= vec.size() * 32 ) {
29 return 0;
30 }
31 uint32_t word = vec[ index / 32 ];
32 return ( ( ( word >> ( index % 32 ) ) & 0x1 ) != 0 );
33 }
34
35} // private namespace
36
37namespace Trig {
38
44
47
48 StatusCode
50 unpackDecision( const EventContext& ctx,
51 std::unordered_map< std::string,const LVL1CTP::Lvl1Item* >& itemsByName,
52 std::map< CTPID, LVL1CTP::Lvl1Item >& itemsCache,
53 std::unordered_map< std::string, const HLT::Chain* >& l2chainsByName,
54 std::map< CHAIN_COUNTER, HLT::Chain >& l2chainsCache,
55 std::unordered_map< std::string, const HLT::Chain* >& efchainsByName,
56 std::map< CHAIN_COUNTER, HLT::Chain >& efchainsCache,
57 char& bgCode,
58 bool unpackHLT ) const {
59
60 // Grab the trigger decision:
62 const xAOD::TrigDecision* xaoddec = trigDec.cptr();
63 if( ! xaoddec ){
64 ATH_MSG_ERROR( "xAOD decision is null" );
65 return StatusCode::FAILURE;
66 }
67
68 // Read the bunch group code:
69 bgCode = xaoddec->bgCode();
70
71 // L1 items
72 itemsByName.clear();
73 ATH_MSG_DEBUG( "Unpacking of L1 items" );
74
75 if( unpackItems( *xaoddec, itemsCache,itemsByName ).isFailure() ) {
76 ATH_MSG_WARNING( "Unpacking of L1 items failed" );
77 }
78
79 // Protect from unpacking in case HLT was not run
80 // (i.e. configuration chains are 0)
81 if( ! unpackHLT ) {
82 return StatusCode::SUCCESS;
83 }
84
85 // L2 chains
86 l2chainsByName.clear();
87 ATH_MSG_DEBUG( "Unpacking of L2 chains" );
88
89 if( unpackChains( l2chainsCache, xaoddec->lvl2PassedRaw(),
90 xaoddec->lvl2PassedThrough(), xaoddec->lvl2Prescaled(),
91 xaoddec->lvl2Resurrected(),
92 l2chainsByName ).isFailure() ) {
93 ATH_MSG_WARNING( "Unpacking of L2 chains failed" );
94 }
95
96 // EF chains
97 efchainsByName.clear();
98 ATH_MSG_DEBUG( "Unpacking of EF/HLT chains" );
99
100 if ( unpackChains( efchainsCache, xaoddec->efPassedRaw(),
101 xaoddec->efPassedThrough(), xaoddec->efPrescaled(),
102 xaoddec->efResurrected(),
103 efchainsByName ).isFailure() ) {
104 ATH_MSG_WARNING( "Unpacking of EF/HLT chains failed" );
105 }
106
107 return StatusCode::SUCCESS;
108 }
109
110 StatusCode
112 HLT::TrigNavStructure* nav ) const {
113 // A security check:
114 if( ! nav ) {
115 ATH_MSG_VERBOSE( "Null HLT::TrigNavStructure pointer received" );
116 return StatusCode::SUCCESS;
117 }
118
119 ATH_MSG_DEBUG( "Unpacking Navigation" );
121 const xAOD::TrigNavigation* serializedNav = trigNav.cptr();
122 if( ! serializedNav ) {
123 [[maybe_unused]] static std::atomic<bool> warningPrinted =
124 [&]() { ATH_MSG_WARNING( "Serialized navigation not available" );
125 return true; }();
126 return StatusCode::FAILURE;
127 }
128
129 // try to get navigation from EF/HLT
130 ATH_MSG_DEBUG( "Trying to unpack Navigation of size: "
131 << serializedNav->serialized().size() );
132
133
134 bool navi_nonempty = !(serializedNav->serialized().empty());
135
136#if !defined(XAOD_STANDALONE) && !defined(XAOD_ANALYSIS)
137 HLT::NavigationCore* fullNav = dynamic_cast<HLT::NavigationCore*>(nav);
138
139 if(!fullNav){
140 ATH_MSG_ERROR("downcast failed");
141 return StatusCode::FAILURE;
142 }
143
144 fullNav->reset();
145 bool unpacking_status = navi_nonempty && fullNav->deserialize( serializedNav->serialized() ) ;
146#else
147 nav->reset();
148 bool unpacking_status = navi_nonempty && nav->deserialize( serializedNav->serialized() ) ;
149#endif
150
151 if ( ! unpacking_status ) {
152 ATH_MSG_WARNING( "Navigation unpacking failed" );
153 } else {
154 ATH_MSG_DEBUG( "Unpacked Navigation" );
155 }
156
157 // Return gracefully:
158 return StatusCode::SUCCESS;
159 }
160
161 StatusCode
163 unpackItems( const xAOD::TrigDecision& trigDec,
164 std::map< unsigned, LVL1CTP::Lvl1Item >& itemsCache,
165 std::unordered_map< std::string, const LVL1CTP::Lvl1Item* >& itemsByName ) const {
166 itemsByName.reserve( itemsByName.size() + itemsCache.size() );
167 for( auto& [ctpid, item] : itemsCache ) {
168 ATH_MSG_VERBOSE( "Unpacking bits for item: " << ctpid << " "
169 << item.name() );
170 bool passBP = get32BitDecision( ctpid, trigDec.tbp() );
171 bool passAP = get32BitDecision( ctpid, trigDec.tap() );
172 bool passAV = get32BitDecision( ctpid, trigDec.tav() );
173 ATH_MSG_VERBOSE( " --- bits are: bp: " << passBP
174 << " ap: " << passAP << " av: "
175 << passAV );
176
177 LVL1CTP::Lvl1Item itemNew (item.name(), item.hashId(),
178 passBP, passAP, passAV,
179 item.prescaleFactor());
180 item = std::move (itemNew);
181 itemsByName[ item.name() ] = &item;
182 }
183
184 return StatusCode::SUCCESS;
185 }
186
187
188 StatusCode
190 unpackChains( std::map< unsigned, HLT::Chain >& cache,
191 const std::vector< uint32_t >& raw,
192 const std::vector< uint32_t >& passedthrough,
193 const std::vector< uint32_t >& prescaled,
194 const std::vector< uint32_t >& resurrected,
195 std::unordered_map< std::string, const HLT::Chain* >& output ) const {
196 output.reserve( output.size() + cache.size() );
197
198 for( auto& [cntr, chain] : cache ) {
199
200 chain.reset();
201 ATH_MSG_VERBOSE( "raw dec for " << cntr << " is "
202 << get32BitDecision( cntr, raw ) );
203 chain.setDecisions( get32BitDecision( cntr, raw ),
204 get32BitDecision( cntr,
205 passedthrough ),
206 get32BitDecision( cntr, prescaled),
207 get32BitDecision( cntr, resurrected ) );
208 output[ chain.getChainName() ] = &chain;
209 ATH_MSG_VERBOSE( "Updated chain in this event : " << chain );
210 }
211
212 return StatusCode::SUCCESS;
213 }
214
215} // namespace Trig
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
std::vector< size_t > vec
bool get32BitDecision(unsigned int index, const std::vector< uint32_t > &vec)
static const Attributes_t empty
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 void reset(bool inFinalize=false)
resets all the navigation, goes to the factory and asks to withdraw all produced objects
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.
virtual StatusCode unpackDecision(const EventContext &ctx, std::unordered_map< std::string, const LVL1CTP::Lvl1Item * > &itemsByName, std::map< CTPID, LVL1CTP::Lvl1Item > &itemsCache, std::unordered_map< std::string, const HLT::Chain * > &l2chainsByName, std::map< CHAIN_COUNTER, HLT::Chain > &l2chainsCache, std::unordered_map< std::string, const HLT::Chain * > &efchainsByName, std::map< CHAIN_COUNTER, HLT::Chain > &efchainsCache, char &bgCode, bool unpackHLT) const override
Function unpacking the payload of the trigger decision.
StatusCode unpackChains(std::map< unsigned, HLT::Chain > &cache, const std::vector< uint32_t > &raw, const std::vector< uint32_t > &passedThrough, const std::vector< uint32_t > &prescaled, const std::vector< uint32_t > &resurrected, std::unordered_map< std::string, const HLT::Chain * > &output) const
Function unpacking the decision of the HLT chains.
virtual StatusCode unpackNavigation(const EventContext &ctx, HLT::TrigNavStructure *nav) const override
Function unpacking the payload of the trigger navigation.
StatusCode unpackItems(const xAOD::TrigDecision &trigDec, std::map< CTPID, LVL1CTP::Lvl1Item > &itemsCache, std::unordered_map< std::string, const LVL1CTP::Lvl1Item * > &itemsByName) const
Function unpacking the decision of the LVL1 items.
const SG::ReadHandleKey< xAOD::TrigNavigation > * m_navikey
Key of the trigger navigation object in the event.
DecisionUnpackerStandalone(const SG::ReadHandleKey< xAOD::TrigDecision > *, const SG::ReadHandleKey< xAOD::TrigNavigation > *navikey)
Constructor with arguments.
const SG::ReadHandleKey< xAOD::TrigDecision > * m_deckey
Key of the trigger decision object in the event.
const std::vector< uint32_t > & efPrescaled() const
Get the EF prescaled bits.
const std::vector< uint32_t > & tav() const
Get the Trigger After Veto bits.
const std::vector< uint32_t > & lvl2PassedRaw() const
Get the LVL2 passed-raw bits.
const std::vector< uint32_t > & efPassedThrough() const
Get the EF pass-through bits.
const std::vector< uint32_t > & lvl2PassedThrough() const
Get the LVL2 pass-through bits.
const std::vector< uint32_t > & lvl2Resurrected() const
Get the LVL2 resurrected bits.
const std::vector< uint32_t > & lvl2Prescaled() const
Get the LVL2 prescaled bits.
const std::vector< uint32_t > & tap() const
Get the Trigger After Prescale bits.
const std::vector< uint32_t > & efPassedRaw() const
Get the EF passed-raw bits.
char bgCode() const
Get the bunch group code of the current event.
const std::vector< uint32_t > & tbp() const
Get the Trigger Before Prescale bits.
const std::vector< uint32_t > & efResurrected() const
Get the EF resurrected bits.
const std::vector< unsigned int > & serialized() const
expose the navigation information (in serialized form)
The common trigger namespace for trigger analysis tools.
Definition index.py:1
TrigDecision_v1 TrigDecision
Define the latest version of the trigger decision class.
TrigNavigation_v1 TrigNavigation
Define the latest version of the trigger navigation class.
setEventNumber uint32_t