ATLAS Offline Software
DecisionUnpackerEventInfo.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 
6 #ifndef XAOD_ANALYSIS // Full Athena only
7 
9 
10 #include "StoreGate/StoreGateSvc.h"
13 
14 #include "EventInfo/TriggerInfo.h"
15 
16 
18 
19 
20 bool get32BitDecision( unsigned int index,
21  const std::vector< uint32_t >& vec ) {
22 
23  if( index >= vec.size() * 32 ) {
24  return 0;
25  }
26  uint32_t word = vec[ index / 32 ];
27  return ( ( ( word >> ( index % 32 ) ) & 0x1 ) != 0 );
28 }
29 
30 
31 namespace Trig {
33  m_eventInfoKey(oldEventInfoKey){
34  }
35 
37  }
38 
39 
40  StatusCode DecisionUnpackerEventInfo::unpackItems(const std::vector<uint32_t>& level1TriggerInfo,
41  std::map<unsigned, LVL1CTP::Lvl1Item>& itemsCache,
42  std::unordered_map<std::string, const LVL1CTP::Lvl1Item*>& itemsByName) const {
43 
44  uint32_t L1SIZE = level1TriggerInfo.size()/3;
45  std::vector<uint32_t>::const_iterator begin, end;
46 
47  begin = level1TriggerInfo.begin();
48  end = begin;
49  std::advance(end,L1SIZE);
50  std::vector<uint32_t> tbp(begin,end);
51 
52  begin = end;
53  std::advance(end,L1SIZE);
54  std::vector<uint32_t> tap(begin,end);
55 
56  begin = end;
57  std::advance(end,L1SIZE);
58  std::vector<uint32_t> tav(begin,end);
59 
60  itemsByName.reserve( itemsByName.size() + itemsCache.size() );
61  for ( auto [ctpid, item] : itemsCache ) {
62  ATH_MSG_VERBOSE("Unpacking bits for item: " << ctpid << " " << item.name());
63  const bool passBP = get32BitDecision(ctpid,tbp);
64  const bool passAP = get32BitDecision(ctpid,tap);
65  const bool passAV = get32BitDecision(ctpid,tav);
66  LVL1CTP::Lvl1Item itemNew (item.name(), item.hashId(),
67  passBP, passAP, passAV,
68  item.prescaleFactor());
69  item = std::move (itemNew);
70  itemsByName[item.name()] = &item;
71  }
72  return StatusCode::SUCCESS;
73  }
74 
75 
76  StatusCode DecisionUnpackerEventInfo::unpackChains(const std::vector<uint32_t>& chainTriggerInfo,
77  std::map<unsigned, HLT::Chain>& cache,
78  std::unordered_map<std::string, const HLT::Chain*>& output) const {
79  output.reserve( output.size() + cache.size() );
80  for( auto& [cntr, chain] : cache){
81  chain.reset();
82 
83  //we have to make a guess here
84  //the bit form the event header is set according to
85  //HLT::Chain::chainPassed() i.e. either non-prescaled, non-ressurected && passed
86  //or it was passed through.
87  //if the bit is set, we will chose the first version for all chains
88  //even though some may be passed through
89  //if the bit is not set we will set all flags to false
90 
91  bool decision = get32BitDecision( cntr, chainTriggerInfo );
92  if(decision){
93  chain.setDecisions( true, //raw
94  false,//passedthrough
95  false,//prescaled
96  false //resurrected
97  );
98  }
99  else {
100  chain.setDecisions( false,//raw
101  false,//passedthrough
102  false,//prescaled
103  false //resurrected
104  );
105  }
106  output[chain.getChainName()] = &chain;
107  }
108  return StatusCode::SUCCESS;
109  }
110 
112  const EventContext& ctx,
113  std::unordered_map<std::string, const LVL1CTP::Lvl1Item*>& itemsByName,
114  std::map<CTPID, LVL1CTP::Lvl1Item>& itemsCache,
115  std::unordered_map<std::string, const HLT::Chain*>& l2chainsByName,
116  std::map<CHAIN_COUNTER, HLT::Chain>& l2chainsCache,
117  std::unordered_map<std::string, const HLT::Chain*>& efchainsByName,
118  std::map<CHAIN_COUNTER, HLT::Chain>& efchainsCache,
119  char& /*bgCode*/,
120  bool unpackHLT
121  ) const {
122 
123  ATH_MSG_DEBUG("unpacking decision from EventInfo");
124 
125  SG::ReadHandle<EventInfo> eventInfo(*m_eventInfoKey, ctx);
126  const TriggerInfo* dec = eventInfo->trigger_info();
127 
128  // bgCode = dec->BGCode();
129 
130  // L1 items
131  itemsByName.clear();
132  ATH_MSG_DEBUG("Unpacking of L1 items");
133  if( unpackItems(dec->level1TriggerInfo(),itemsCache,itemsByName).isFailure() ) {
134  ATH_MSG_WARNING("Unpacking of L1 items failed");
135  }
136 
137 
138  // protect from unpacking in case HLT was not run (i.e. configuration chains are 0)
139  if (!unpackHLT) return StatusCode::SUCCESS;
140 
141 
142  // L2 chains
143  l2chainsByName.clear();
144  const auto& level2TriggerInfo = dec->level2TriggerInfo();
145 
146  if ( unpackChains(level2TriggerInfo, l2chainsCache, l2chainsByName).isFailure() ) {
147  ATH_MSG_WARNING("Unpacking of L2 chains failed");
148  }
149 
150  // EF chains
151  efchainsByName.clear();
152  const auto& eventFilterInfo = dec->eventFilterInfo();
153 
154  if ( unpackChains(eventFilterInfo, efchainsCache, efchainsByName).isFailure() ) {
155  ATH_MSG_WARNING("Unpacking of EF/HLT chains failed");
156  }
157 
158  return StatusCode::SUCCESS;
159  }
160 
162  HLT::TrigNavStructure*) const {
163  ATH_MSG_WARNING("This is the EventInfo Unpacker, there is no Navigation available -- but someone seems to try to access features triggering a navi unpacking");
164  return StatusCode::SUCCESS;
165  }
166 
167 }
168 
169 #endif // full Athena env
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
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::DecisionUnpackerEventInfo::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: DecisionUnpackerEventInfo.cxx:111
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TriggerInfo.h
This class contains trigger related information.
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< EventInfo >
HLT::TrigNavStructure
Definition: TrigNavStructure.h:40
xAOD::tap
setBGCode tap
Definition: TrigDecision_v1.cxx:43
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TriggerInfo::level1TriggerInfo
const std::vector< number_type > & level1TriggerInfo() const
get level1 trigger info
Definition: TriggerInfo.cxx:143
Lvl1Result.h
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
Trig::DecisionUnpackerEventInfo::~DecisionUnpackerEventInfo
virtual ~DecisionUnpackerEventInfo()
Definition: DecisionUnpackerEventInfo.cxx:36
LVL1CTP::Lvl1Item
Definition: Lvl1Item.h:37
TriggerInfo::level2TriggerInfo
const std::vector< number_type > & level2TriggerInfo() const
get level2 trigger info
Definition: TriggerInfo.cxx:148
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
NavigationCore.h
Trig::DecisionUnpackerEventInfo::DecisionUnpackerEventInfo
DecisionUnpackerEventInfo(const SG::ReadHandleKey< EventInfo > *oldEventInfoKey)
Definition: DecisionUnpackerEventInfo.cxx:32
merge.output
output
Definition: merge.py:17
get32BitDecision
bool get32BitDecision(unsigned int index, const std::vector< uint32_t > &vec)
Definition: DecisionUnpackerEventInfo.cxx:20
TriggerInfo
This class contains trigger related information.
Definition: TriggerInfo.h:77
item
Definition: ItemListSvc.h:43
Trig::DecisionUnpackerEventInfo::m_eventInfoKey
const SG::ReadHandleKey< EventInfo > * m_eventInfoKey
Definition: DecisionUnpackerEventInfo.h:51
TriggerInfo::eventFilterInfo
const std::vector< number_type > & eventFilterInfo() const
get event filter trigger info
Definition: TriggerInfo.cxx:153
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
EventInfo::trigger_info
TriggerInfo * trigger_info()
trigger information (ptr may be NULL)
Definition: EventInfo/EventInfo/EventInfo.h:230
Trig::DecisionUnpackerEventInfo::unpackChains
StatusCode unpackChains(const std::vector< uint32_t > &chainTriggerInfo, std::map< unsigned, HLT::Chain > &cache, std::unordered_map< std::string, const HLT::Chain * > &output) const
Definition: DecisionUnpackerEventInfo.cxx:76
Trig::DecisionUnpackerEventInfo::unpackItems
StatusCode unpackItems(const std::vector< uint32_t > &level1TriggerInfo, std::map< CTPID, LVL1CTP::Lvl1Item > &itemsCache, std::unordered_map< std::string, const LVL1CTP::Lvl1Item * > &itemsByName) const
Definition: DecisionUnpackerEventInfo.cxx:40
StoreGateSvc.h
Trig::DecisionUnpackerEventInfo::unpackNavigation
virtual StatusCode unpackNavigation(const EventContext &, HLT::TrigNavStructure *) const override
Definition: DecisionUnpackerEventInfo.cxx:161
DecisionUnpackerEventInfo.h