ATLAS Offline Software
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 
21 namespace {
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 
37 namespace Trig {
38 
41  : m_deckey(deckey), m_navikey(navikey)
42  {
43  }
44 
46  }
47 
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
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
xAOD::TrigDecision_v1::efPrescaled
const std::vector< uint32_t > & efPrescaled() const
Get the EF prescaled bits.
HLTChainList.h
DecisionUnpackerStandalone.h
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
xAOD::TrigDecision_v1::efResurrected
const std::vector< uint32_t > & efResurrected() const
Get the EF resurrected bits.
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
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
Trig::DecisionUnpackerStandalone::m_navikey
const SG::ReadHandleKey< xAOD::TrigNavigation > * m_navikey
Key of the trigger navigation object in the event.
Definition: DecisionUnpackerStandalone.h:87
xAOD::bgCode
bgCode
Definition: TrigDecision_v1.cxx:39
HLT::NavigationCore::deserialize
bool deserialize(const std::vector< uint32_t > &input)
Definition: NavigationCore.cxx:151
xAOD::TrigDecision_v1::tav
const std::vector< uint32_t > & tav() const
Get the Trigger After Veto bits.
HLT::TrigNavStructure::reset
virtual void reset(bool inFinalize=false)
resets all the navigation, goes to the factory and asks to withdraw all produced objects
Definition: TrigNavStructure.cxx:756
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
Trig::DecisionUnpackerStandalone::unpackDecision
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.
Definition: DecisionUnpackerStandalone.cxx:50
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
HLT::TrigNavStructure
Definition: TrigNavStructure.h:40
xAOD::TrigNavigation_v1::serialized
const std::vector< unsigned int > & serialized() const
expose the navigation information (in serialized form)
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
xAOD::TrigDecision_v1::lvl2PassedThrough
const std::vector< uint32_t > & lvl2PassedThrough() const
Get the LVL2 pass-through bits.
Lvl1Item.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
LVL1CTP::Lvl1Item
Definition: Lvl1Item.h:37
Trig::DecisionUnpackerStandalone::unpackItems
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.
Definition: DecisionUnpackerStandalone.cxx:163
Trig::DecisionUnpackerStandalone::m_deckey
const SG::ReadHandleKey< xAOD::TrigDecision > * m_deckey
Key of the trigger decision object in the event.
Definition: DecisionUnpackerStandalone.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trig::DecisionUnpackerStandalone::~DecisionUnpackerStandalone
virtual ~DecisionUnpackerStandalone()
Destructor.
Definition: DecisionUnpackerStandalone.cxx:45
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TrigDecision_v1::efPassedThrough
const std::vector< uint32_t > & efPassedThrough() const
Get the EF pass-through bits.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trig::DecisionUnpackerStandalone::DecisionUnpackerStandalone
DecisionUnpackerStandalone(const SG::ReadHandleKey< xAOD::TrigDecision > *, const SG::ReadHandleKey< xAOD::TrigNavigation > *navikey)
Constructor with arguments.
Definition: DecisionUnpackerStandalone.cxx:39
NavigationCore.h
xAOD::TrigDecision_v1::efPassedRaw
const std::vector< uint32_t > & efPassedRaw() const
Get the EF passed-raw bits.
Chain.h
Trig::DecisionUnpackerStandalone::unpackNavigation
virtual StatusCode unpackNavigation(const EventContext &ctx, HLT::TrigNavStructure *nav) const override
Function unpacking the payload of the trigger navigation.
Definition: DecisionUnpackerStandalone.cxx:111
merge.output
output
Definition: merge.py:17
get32BitDecision
bool get32BitDecision(unsigned int index, const std::vector< uint32_t > &vec)
Definition: DecisionUnpackerEventInfo.cxx:20
ReadHandle.h
Handle class for reading from StoreGate.
item
Definition: ItemListSvc.h:43
xAOD::TrigDecision_v1::tap
const std::vector< uint32_t > & tap() const
Get the Trigger After Prescale bits.
xAOD::TrigDecision_v1::bgCode
char bgCode() const
Get the bunch group code of the current event.
xAOD::TrigDecision_v1::lvl2Prescaled
const std::vector< uint32_t > & lvl2Prescaled() const
Get the LVL2 prescaled bits.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TrigNavigation_v1
Interface to the raw trigger navigation information of the event.
Definition: TrigNavigation_v1.h:34
xAOD::TrigDecision_v1::tbp
const std::vector< uint32_t > & tbp() const
Get the Trigger Before Prescale bits.
xAOD::TrigDecision_v1::lvl2Resurrected
const std::vector< uint32_t > & lvl2Resurrected() const
Get the LVL2 resurrected bits.
xAOD::TrigDecision_v1
Interface to the raw trigger decision information of the event.
Definition: TrigDecision_v1.h:44
xAOD::TrigDecision_v1::lvl2PassedRaw
const std::vector< uint32_t > & lvl2PassedRaw() const
Get the LVL2 passed-raw bits.
Trig::DecisionUnpackerStandalone::unpackChains
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.
Definition: DecisionUnpackerStandalone.cxx:190