ATLAS Offline Software
Loading...
Searching...
No Matches
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
29static 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
44StatusCode
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
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
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." );
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
139std::vector<uint32_t>* Trig::TrigDecisionTool::getKeys() {
140 return m_configKeysCache.get();
141}
142
143void 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();
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
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() );
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
233StatusCode
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
245void
246Trig::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
269bool
270Trig::TrigDecisionTool::isPassed(const std::string& chain, unsigned int condition) const {
271 return TrigDecisionToolCore::isPassed(chain, condition);
272}
273
274
275bool
276Trig::TrigDecisionTool::isPassed(const std::string& chain) const {
277 return TrigDecisionToolCore::isPassed(chain);
278}
279
280unsigned int
281Trig::TrigDecisionTool::isPassedBits( const std::string& chain ) const {
282
284}
285
286const std::string&
290
291
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static std::atomic< int > s_instances
Number of TDT instances.
ServiceHandle< StoreGateSvc > & evtStore()
Interface for all services/tools that provide HLT menu configuration information.
virtual const HLTChainList & chains() const =0
accessor to HLT chains
virtual uint32_t masterKey() const =0
accessor to the configuration super masterkey
virtual uint32_t hltPrescaleKey() const =0
accessor to the configuration hlt prescale key
Interface for all services/tools that provide LVL1 menu configuration information.
virtual uint32_t lvl1PrescaleKey() const =0
accessor to the configuration lvl1 prescale key
virtual uint32_t bunchGroupSetKey() const =0
accessor to the LVL1 bunch group set key
virtual const CTPConfig * ctpConfig() const =0
Provides the LVL1 trigger menu.
void setRun2NavigationKeyPtr(SG::ReadHandleKey< xAOD::TrigNavigation > *k)
void setDecisionKeyPtr(SG::ReadHandleKey< xAOD::TrigDecision > *k)
void setStore(asg::EventStoreType *store)
Set the event store to be used by the object.
void setRun3NavigationKeyPtr(SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > *k)
void setOldDecisionKeyPtr(SG::ReadHandleKey< TrigDec::TrigDecision > *k)
void setOldEventInfoKeyPtr(SG::ReadHandleKey< EventInfo > *k)
void reset_decision()
invalidate previously unpacked decision Needs to be called at the start of a new event.
void configurationUpdate(const TrigConf::HLTChainList *confChains, const TrigConf::CTPConfig *confItems)
Logging adaptor to provide interfaces required for ATH_MSG macros.
virtual Trig::CacheGlobalMemory * cgm()
unsigned int isPassedBits(const Trig::ChainGroup *chaingroup) const
Return expert-level information about the various trigger flags as a bit mask.
bool isPassed(const Trig::ChainGroup *chaingroup, unsigned int condition=TrigDefs::Physics) const
true if given group of chains passed
HLT::TrigNavStructure * m_navigation
SG::ReadHandleKey< xAOD::TrigDecision > m_decisionKey
Gaudi::Property< bool > m_useOldEventInfoDecisionFormat
StatusCode initialize()
Dummy implementation of the initialisation function.
StatusCode beginInputFile()
Function called when a new input file is opened.
TrigDecisionTool(const std::string &name)
SG::ReadHandleKey< EventInfo > m_oldEventInfoKey
ServiceHandle< TrigConf::ITrigConfigSvc > m_configSvc
trigger configuration service handle
StatusCode beginEvent()
Function called when a new events is loaded.
void setForceConfigUpdate(bool b, bool forceForAllSlots=false)
virtual bool isPassed(const std::string &chain, unsigned int condition) const
true if given chain passed
HLT::StandaloneNavigation m_standaloneNavigation
Gaudi::Property< std::map< std::string, std::string > > m_publicChainGroups
Gaudi::Property< std::string > m_navigationFormat
Note: Temporary property.
SG::SlotSpecificObj< std::atomic< bool > > m_forceConfigUpdate
Cache for registering new input files.
Gaudi::Property< bool > m_acceptMultipleInstance
const std::string & getNavigationFormat() const
Note: Temporary.
SG::SlotSpecificObj< std::vector< uint32_t > > m_configKeysCache
cache for config keys.
virtual void handle(const Incident &inc)
Function receiving incidents from IncidentSvc/TEvent.
Gaudi::Property< bool > m_useOldAODDecisionInput
SG::ReadHandleKey< xAOD::TrigNavigation > m_navigationKey
virtual unsigned int isPassedBits(const std::string &chain) const
Implementation of the ITrigDecisionTool function.
SG::ReadHandleKey< TrigDec::TrigDecision > m_oldDecisionKey
PublicToolHandle< TrigConf::ITrigConfigTool > m_configTool
std::vector< uint32_t > * getKeys()
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_HLTSummaryKeyIn
ToolHandle< HLT::Navigation > m_fullNavigation
AsgMetadataTool(const std::string &name)
Normal ASG tool constructor with a name.
std::vector< std::string > patterns
Definition listroot.cxx:187