ATLAS Offline Software
TrigDecisionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /**********************************************************************************
6  * @Project: TrigDecisionTool
7  * @Package: TrigDecisionTool
8  * @Class : TrigDecisionTool
9  *
10  * @brief main tool
11  *
12  * @author Michael Begel <michael.begel@cern.ch> - Brookhaven National Laboratory
13  * @author Lukas Heinrich <lukas.heinrich@cern.ch> - NYU
14  *
15  ***********************************************************************************/
16 
20 
23 #include "TrigConfL1Data/Menu.h"
25 
27 
29 static std::atomic<int> s_instances = 0;
30 
31 
33  : Logger(this)
34  , asg::AsgMetadataTool(name)
35 {
36 #ifdef XAOD_ANALYSIS // AthAnalysis or AnalysisBase
38 #else //full Athena env
40 #endif
41 }
42 
43 
47 
48  if (m_navigationFormat != "TriggerElement" && m_navigationFormat != "TrigComposite") {
49  ATH_MSG_ERROR("NavigationFormat property must be one of 'TriggerElement' for Run 1, 2 triggered input or 'TrigComposite' for Run 3+ triggered input");
50  return StatusCode::FAILURE;
51  }
52 
53 
54 #ifndef XAOD_ANALYSIS // Full Athena only
55  ATH_CHECK(m_oldDecisionKey.initialize( m_useOldAODDecisionInput ) ); // Read TrigDec::TrigDecision
56  ATH_CHECK(m_oldEventInfoKey.initialize( m_useOldEventInfoDecisionFormat ) );
57 #endif
58 
59  ATH_CHECK(m_HLTSummaryKeyIn.initialize(m_navigationFormat == "TrigComposite"));
60  ATH_CHECK(m_navigationKey.initialize(m_navigationFormat == "TriggerElement"));
61  ATH_CHECK(m_decisionKey.initialize( !m_useOldAODDecisionInput )); // Read xAOD::TrigDecision. Mutually exclusive with reading TrigDec::TrigDecision
62 
63  ++s_instances;
64  if ( s_instances > 1) {
65  ATH_MSG_WARNING("Multiple TrigDecisionTool instances created. "
66  "This is not efficent from performance perspective. "
67  "Access of the same EDM objects will give warnings." );
68  if (!m_acceptMultipleInstance){
69  ATH_MSG_ERROR("Will not accept multiple instances. "
70  "Set 'AcceptMultipleInstance' to overwrite this behavior.");
71  return StatusCode::FAILURE;
72  }
73  }
74 
75  ATH_MSG_INFO("Initializing Trig::TrigDecisionTool (standalone version even for athena)");
76 
77 #ifndef XAOD_STANDALONE // AthAnalysis or full Athena
78  // We setup the TrigConfigSvc interface
79  // This is the standalone xAOD ConfigSvc
80  // In Run 3 the standalone xAOD ConfigSvc is useable in both RAWtoALL jobs and from ESD, AOD.
81 
82  if(m_configSvc.empty()) {
83  ATH_MSG_DEBUG("No TrigConfigSvc provided. Using ConfigTool instead...");
84  CHECK( m_configTool.retrieve()); //use configTool if no configSvc available
85  } else {
86 
87  m_configTool.disable();
88 
89  ATH_MSG_DEBUG("Fetching " << m_configSvc.typeAndName());
90  ATH_CHECK(m_configSvc.retrieve());
91 
92  // call update if there is anything in config svc
93  if ( m_configSvc->ctpConfig() ) {
94  configurationUpdate( &m_configSvc->chains(), m_configSvc->ctpConfig() );
95  }
96  }
97 #else // AnalysisBase
98  ATH_CHECK(m_configTool.retrieve());
99 #endif
100 
101 #ifndef XAOD_ANALYSIS // Full athena only
102  if (m_navigationFormat == "TriggerElement") {
103  ATH_CHECK(m_fullNavigation.retrieve());
104  }
105 #endif
106 
107  cgm()->navigation(&*m_navigation);
108 
109  cgm()->setStore(&*evtStore()); // Cache must be updated per-event too (when running with multiple slots)
110 
111 #ifndef XAOD_STANDALONE // AthAnalysis or full Athena
112  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc",name());
113  if (incSvc.retrieve().isFailure()) {
114  ATH_MSG_ERROR("Cannot retrieve IncidentSvc");
115  return StatusCode::FAILURE;
116  }
117 
118  long int pri=-1; //ensure happens *after* TrigConfxAOD tool ... use -1 priority
119  incSvc->removeListener( this, "BeginEvent"); //beginEvent is added by AsgMetadataTool already! ...DONT ADD IT AGAIN ... especially at priority 100!
120  incSvc->addListener( this, "BeginEvent", pri );
121  //do the same adjustment for the BeginInputFile incident, just to be safe
122  incSvc->removeListener( this, IncidentType::BeginInputFile );
123  incSvc->addListener( this, IncidentType::BeginInputFile, pri, true/*rethrow*/);
124 #endif
125 
126  ATH_MSG_INFO("Initialized TDT" );
127 
128  std::map<std::string, std::string>::const_iterator pIt;
129  for ( pIt = m_publicChainGroups.begin(); pIt != m_publicChainGroups.end(); ++pIt ) {
130  std::vector<std::string> patterns;
131  patterns.push_back(pIt->second);
132  cgm()->createChainGroup(patterns, pIt->first);
133  ATH_MSG_INFO("created Public Chain Group " << pIt->first << " with pattern: " << pIt->second );
134  }
135 
136  return StatusCode::SUCCESS;
137 }
138 
139 std::vector<uint32_t>* Trig::TrigDecisionTool::getKeys() {
140  return m_configKeysCache.get();
141 }
142 
143 void Trig::TrigDecisionTool::setForceConfigUpdate(bool b, bool forceForAllSlots) {
144 
145  if (forceForAllSlots) {
146  for (std::atomic<bool>& ab : m_forceConfigUpdate) {
147  ab = b;
148  }
149  }
150  else { // only current slot
151  std::atomic<bool>* ab = m_forceConfigUpdate.get();
152  (*ab) = b;
153  }
154 }
155 
156 
158  std::atomic<bool>* ab = m_forceConfigUpdate.get();
159  return *ab;
160 }
161 
162 
164 
165  CacheGlobalMemory* cgmPtr = cgm();
166  cgmPtr->setDecisionKeyPtr( &m_decisionKey );
167  cgmPtr->setRun2NavigationKeyPtr( &m_navigationKey );
168  cgmPtr->setRun3NavigationKeyPtr( &m_HLTSummaryKeyIn );
169 
170  size_t slot = 0;
171 #ifndef XAOD_STANDALONE // AthAnalysis or full Athena
172  cgmPtr->setStore(&*evtStore()); // Can change based on event slot
173  slot = Gaudi::Hive::currentContext().slot();
174 #ifndef XAOD_ANALYSIS // Full Athena only
175  cgmPtr->setOldDecisionKeyPtr( &m_oldDecisionKey );
176  cgmPtr->setOldEventInfoKeyPtr( &m_oldEventInfoKey );
177 #endif // End Full Athena only
178 #endif // End AthAnalysis or Full Athena
179 
180  // inform the CGM that we are on a new event
181  ATH_MSG_VERBOSE("beginEvent: invalidating CacheGlobalMemory");
182  cgmPtr->reset_decision();
183  TrigConf::IIHLTConfigSvc *iHLTConfig{nullptr};
184  TrigConf::IILVL1ConfigSvc *iL1Config{nullptr};
185 #ifndef XAOD_STANDALONE
186  if (!m_configSvc.empty())
187  {
188  iHLTConfig = m_configSvc.get();
189  iL1Config = m_configSvc.get();
190  }
191  else
192 #endif
193  {
194  iHLTConfig = m_configTool.operator->();
195  iL1Config = m_configTool.operator->();
196  }
197 
198  ATH_MSG_DEBUG("beginEvent: check if config update is necessary");
199  std::vector<uint32_t> newKeys = {
200  iHLTConfig->masterKey(),
201  iL1Config->lvl1PrescaleKey(),
202  iHLTConfig->hltPrescaleKey(),
203  iL1Config->bunchGroupSetKey()
204  };
205  if (*getKeys() != newKeys or getForceConfigUpdate())
206  {
207  ATH_MSG_INFO("Updating config in slot " << slot
208  << " with SMK: " << newKeys[0]
209  << " and L1PSK: " << newKeys[1]
210  << " and HLTPSK: " << newKeys[2]
211  << " and BGSK: " << newKeys[3]
212  << " getForceConfigUpdate()=" << getForceConfigUpdate()
213  << " HLT Chains: " << iHLTConfig->chains().size());
214  *getKeys() = newKeys;
215  configurationUpdate( &iHLTConfig->chains(), iL1Config->ctpConfig() );
216  setForceConfigUpdate(false);
217  }
218  else
219  ATH_MSG_DEBUG("Cached trigger configuration keys match for this event in slot " << slot);
220 
221  return StatusCode::SUCCESS;
222 }
223 
225  // We need to update the cached configuration when switching to a new input
226  // file:
227  //have to do this at the next beginEvent, because the event info isn't ready at this point (e.g. if the file has no events!)
228  ATH_MSG_VERBOSE("Trig::TrigDecisionTool::beginInputFile: setForceConfigUpdate(true, forceForAllSlots=true)");
229  setForceConfigUpdate(true, /*forceForAllSlots=*/ true);
230  return StatusCode::SUCCESS;
231 }
232 
235  // release all chaingroups
236  m_navigation->reset(true);
237 
238  --s_instances;
239 
240  ATH_MSG_INFO("Finalized");
241  return StatusCode::SUCCESS;
242 }
243 
244 #ifndef XAOD_ANALYSIS // Full Athena only
245 void
246 Trig::TrigDecisionTool::handle(const Incident& inc) {
247  // an update configuration incident triggers the update of the configuration
248  ATH_MSG_DEBUG("got incident type:" << inc.type() << " source: " << inc.source() );
249 
250  if (inc.type() == IncidentType::BeginEvent) {
251  ATH_MSG_VERBOSE("Obtained IncidentType::BeginEvent via Trig::TrigDecisionTool::handle");
252  if (beginEvent().isFailure()) {
253  throw std::runtime_error("In Trig::TrigDecisionTool::handle beginEvent() returned StatusCode::FAILURE");
254  }
255  }
256  else if (inc.type() == IncidentType::BeginInputFile) {
257  ATH_MSG_VERBOSE("Obtained IncidentType::BeginInputFile via Trig::TrigDecisionTool::handle");
258  if (beginInputFile().isFailure()) {
259  throw std::runtime_error("In Trig::TrigDecisionTool::handle beginInputFile() returned StatusCode::FAILURE");
260  }
261  }
262  else {
263  //call the parent handle
264  AsgMetadataTool::handle(inc);
265  }
266 }
267 #endif
268 
269 bool
270 Trig::TrigDecisionTool::isPassed(const std::string& chain, unsigned int condition) const {
272 }
273 
274 
275 bool
276 Trig::TrigDecisionTool::isPassed(const std::string& chain) const {
278 }
279 
280 unsigned int
281 Trig::TrigDecisionTool::isPassedBits( const std::string& chain ) const {
282 
284 }
285 
286 const std::string&
288  return m_navigationFormat;
289 }
290 
291 
Trig::TrigDecisionTool::beginInputFile
StatusCode beginInputFile()
Function called when a new input file is opened.
Definition: TrigDecisionTool.cxx:224
CTPConfig.h
Trig::TrigDecisionTool::getForceConfigUpdate
bool getForceConfigUpdate()
Definition: TrigDecisionTool.cxx:157
HLTChainList.h
DecisionUnpackerStandalone.h
Trig::TrigDecisionTool::handle
virtual void handle(const Incident &inc)
Function receiving incidents from IncidentSvc/TEvent.
Definition: TrigDecisionTool.cxx:246
Trig::CacheGlobalMemory::setRun3NavigationKeyPtr
void setRun3NavigationKeyPtr(SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > *k)
Definition: CacheGlobalMemory.h:143
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CurrentContext.h
patterns
std::vector< std::string > patterns
Definition: listroot.cxx:187
Trig::Logger
Logging adaptor to provide interfaces required for ATH_MSG macros.
Definition: Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/Logger.h:24
TrigConf::IILVL1ConfigSvc
Interface for all services/tools that provide LVL1 menu configuration information.
Definition: IILVL1ConfigSvc.h:36
python.TriggerAPI.TriggerDataAccess.getKeys
def getKeys(listOfRuns, doPrint=False)
Definition: TriggerDataAccess.py:61
asg
Definition: DataHandleTestTool.h:28
Trig::TrigDecisionTool::isPassedBits
virtual unsigned int isPassedBits(const std::string &chain) const
Implementation of the ITrigDecisionTool function.
Definition: TrigDecisionTool.cxx:281
TrigDecisionTool.h
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
Menu.h
Trig::CacheGlobalMemory
Definition: CacheGlobalMemory.h:67
Trig::CacheGlobalMemory::setRun2NavigationKeyPtr
void setRun2NavigationKeyPtr(SG::ReadHandleKey< xAOD::TrigNavigation > *k)
Definition: CacheGlobalMemory.h:142
Trig::TrigDecisionTool::getNavigationFormat
const std::string & getNavigationFormat() const
Note: Temporary.
Definition: TrigDecisionTool.cxx:287
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trig::CacheGlobalMemory::setStore
void setStore(asg::EventStoreType *store)
Set the event store to be used by the object.
Definition: CacheGlobalMemory.h:137
Trig::TrigDecisionToolCore::initialize
virtual StatusCode initialize()
Definition: TrigDecisionToolCore.cxx:50
Trig::TrigDecisionToolCore::m_navigation
HLT::TrigNavStructure * m_navigation
Definition: TrigDecisionToolCore.h:104
Trig::CacheGlobalMemory::setOldEventInfoKeyPtr
void setOldEventInfoKeyPtr(SG::ReadHandleKey< EventInfo > *k)
Definition: CacheGlobalMemory.h:149
Trig::DecisionAccess::isPassed
bool isPassed(const Trig::ChainGroup *chaingroup, unsigned int condition=TrigDefs::Physics) const
true if given group of chains passed
Definition: DecisionAccess.cxx:34
Trig::TrigDecisionTool::getKeys
std::vector< uint32_t > * getKeys()
Definition: TrigDecisionTool.cxx:139
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trig::CacheGlobalMemory::reset_decision
void reset_decision()
invalidate previously unpacked decision Needs to be called at the start of a new event.
Definition: CacheGlobalMemory.cxx:372
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::TrigDecisionTool::setForceConfigUpdate
void setForceConfigUpdate(bool b, bool forceForAllSlots=false)
Definition: TrigDecisionTool.cxx:143
Trig::CacheGlobalMemory::setOldDecisionKeyPtr
void setOldDecisionKeyPtr(SG::ReadHandleKey< TrigDec::TrigDecision > *k)
Definition: CacheGlobalMemory.h:148
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Trig::TrigDecisionTool::isPassed
virtual bool isPassed(const std::string &chain, unsigned int condition) const
true if given chain passed
Definition: TrigDecisionTool.cxx:270
L1BunchGroupSet.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Trig::TrigDecisionTool::m_fullNavigation
ToolHandle< HLT::Navigation > m_fullNavigation
Definition: TrigDecisionTool.h:143
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Trig::CacheGlobalMemory::setDecisionKeyPtr
void setDecisionKeyPtr(SG::ReadHandleKey< xAOD::TrigDecision > *k)
Definition: CacheGlobalMemory.h:141
Trig::DecisionAccess::isPassedBits
unsigned int isPassedBits(const Trig::ChainGroup *chaingroup) const
Return expert-level information about the various trigger flags as a bit mask.
Definition: DecisionAccess.cxx:67
DecisionUnpackerAthena.h
Trig::TrigDecisionTool::m_standaloneNavigation
HLT::StandaloneNavigation m_standaloneNavigation
Definition: TrigDecisionTool.h:151
Trig::TrigDecisionTool::finalize
StatusCode finalize()
Definition: TrigDecisionTool.cxx:234
Trig::TrigDecisionTool::TrigDecisionTool
TrigDecisionTool(const std::string &name)
Definition: TrigDecisionTool.cxx:32
TrigConf::IIHLTConfigSvc
Interface for all services/tools that provide HLT menu configuration information.
Definition: IIHLTConfigSvc.h:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trig::TrigDecisionTool::beginEvent
StatusCode beginEvent()
Function called when a new events is loaded.
Definition: TrigDecisionTool.cxx:163
Trig::TrigDecisionTool::initialize
StatusCode initialize()
Definition: TrigDecisionTool.cxx:45
ServiceHandle< IIncidentSvc >