ATLAS Offline Software
CacheGlobalMemory.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRIGGER_DECISION_TOOL_CACHE_GLOBAL_MEMORY_H
6 #define TRIGGER_DECISION_TOOL_CACHE_GLOBAL_MEMORY_H
7 
8 /**********************************************************************************
9  * @Project: TrigDecisionTool
10  * @Package: TrigDecisionTool
11  * @class : CacheGlobalMemory
12  *
13  * @brief registry for ChainGroups
14  *
15  * @author Michael Begel <michael.begel@cern.ch> - Brookhaven National Laboratory
16  *
17  ***********************************************************************************/
18 
19 #include<vector>
20 #include<set>
21 #include<map>
22 #include<unordered_map>
23 #include<string>
24 #include<mutex>
25 #include<memory>
26 
30 
32 
35 
39 
43 
47 
48 #ifndef XAOD_ANALYSIS // Full Athena only
49 #include "EventInfo/EventInfo.h"
51 #endif
52 
53 namespace HLT {
54  class Chain;
55  class TriggerElement;
56 }
57 
58 namespace LVL1CTP {
59  class Lvl1Result;
60 }
61 
62 
63 namespace Trig {
64 
65  class ChainGroup;
66 
67  class CacheGlobalMemory : public virtual Logger {
68 
69  public:
70  // constructors, destructor
71  CacheGlobalMemory() = default;
72  ~CacheGlobalMemory() = default;
73 
84  const Trig::ChainGroup* createChainGroup(const std::vector< std::string >& patterns,
85  const std::string& alias="",
87 
92  void update(const TrigConf::HLTChainList* confChains,
93  const TrigConf::CTPConfig* ctp);
94 
95  const LVL1CTP::Lvl1Item* item(const std::string& name) const;
96  const LVL1CTP::Lvl1Item* item(const TrigConf::TriggerItem& i) const;
97  const TrigConf::TriggerItem* config_item(const std::string& name) const;
98  float item_prescale(int ctpid) const;
99 
100  const HLT::Chain* chain(const std::string& name) const;
101  const HLT::Chain* chain(const TrigConf::HLTChain& chIt) const;
102  const TrigConf::HLTChain* config_chain(const std::string& name) const;
103 
106  // CGM is slot-specific and unpackNavigation is locked
107  auto cgm ATLAS_THREAD_SAFE = const_cast<CacheGlobalMemory*>(this);
108  if(cgm->unpackNavigation().isFailure()){
109  ATH_MSG_WARNING("unpack Navigation failed");
110  }
111  }
112  return m_navigation;
113  }
115 
116  const Trig::ChainGroup* getChainGroup (const std::vector<std::string>& triggerNames,
117  TrigDefs::Group props) const;
118  size_t nChainGroups() const;
119  const std::map<std::string, std::vector<std::string> >& getStreams() const {return m_streams;};
120 
128  bool assert_decision() const;
129 
134  void reset_decision();
135 
139  const asg::EventStoreType* store() const { return m_store; }
140 
146 
147 #ifndef XAOD_ANALYSIS // Full Athena only
150 #endif
151 
153 
154  //
155  template<class T>
156  void deleteAtTheEndOfEvent(T t) const { m_deleteAtEndOfEvent.insert(t); }
157 
158 
159 
160 
161  private:
162  friend class DecisionAccess;
163 
167  StatusCode unpackDecision(const EventContext& ctx);
172 
176  void updateChainGroup(Trig::ChainGroup& chainGroup,
178 
179  //
180  // Data members
181  //
182 
184  const asg::EventStoreType* m_store{nullptr};
185 
187  mutable std::unique_ptr<IDecisionUnpacker> m_unpacker ATLAS_THREAD_SAFE; // for assert_decision
188 
189  bool m_decisionUnpacked{false};
190  bool m_navigationUnpacked{false};
191 
194 
195  // chain groups (protected by mutex)
196  mutable std::map< std::vector< std::string >, Trig::ChainGroup > m_chainGroups ATLAS_THREAD_SAFE;
197  mutable std::map< std::vector< std::string >, Trig::ChainGroup* > m_chainGroupsRef ATLAS_THREAD_SAFE;
198 
199  std::unordered_map<std::string, const LVL1CTP::Lvl1Item*> m_itemsByName;
200  std::unordered_map<std::string, const HLT::Chain*> m_l2chainsByName;
201  std::unordered_map<std::string, const HLT::Chain*> m_efchainsByName;
202 
203  typedef unsigned CTPID;
204  typedef unsigned CHAIN_COUNTER;
205  std::map<CTPID, LVL1CTP::Lvl1Item> m_itemsCache;
206  std::map<CHAIN_COUNTER, HLT::Chain> m_l2chainsCache;
207  std::map<CHAIN_COUNTER, HLT::Chain> m_efchainsCache;
208 
209  std::map<std::string, std::vector<std::string> > m_groups;
210  std::map<std::string, std::vector<std::string> > m_streams;
211 
214 
216 
217 #ifndef XAOD_ANALYSIS // Full Athena
220 #endif
221 
224 
225  typedef std::unordered_map<std::string, const TrigConf::HLTChain*> ChainHashMap_t;
227 
228  char m_bgCode{0};
229 
230 
232 
233 
234  struct iholder {
235  virtual ~iholder() {}
236  virtual const void* ptr() const { return nullptr;}
237  };
238 
239  struct holder_comp {
240  bool operator()(iholder* lhs, iholder* rhs) const {
241  return lhs->ptr() < rhs->ptr(); }
242  };
243  template<class T>
244  class holder : public iholder {
245  public:
246  holder(T& t): m_held(t) {}
247  virtual ~holder() {
248  delete m_held;
249  m_held = 0; }
250  virtual const void* ptr() const { return m_held;}
251  private:
253  };
254 
255  public:
256  template<class T>
257  void insert(T t) {
258  m_todel.insert(new holder<T>(t));
259  }
260  void clear() {
261  for(iholder* i : m_todel) {
262  delete i;
263  }
264  m_todel.clear();
265  }
266  ~AnyTypeDeleter();
267  private:
268  std::set< iholder*, holder_comp > m_todel;
269  }; // end of deleter
270 
271  // Thread-safe because CacheGlobalMemory is slot-specific
272  mutable AnyTypeDeleter m_deleteAtEndOfEvent ATLAS_THREAD_SAFE;
273 
274  mutable std::recursive_mutex m_cgmMutex;
275 
276 
277 
278  };
279 } // End of namespace
280 
281 #endif
CTPConfig.h
Trig::CacheGlobalMemory::m_decisionKeyPtr
SG::ReadHandleKey< xAOD::TrigDecision > * m_decisionKeyPtr
Parent TDT's read handle key.
Definition: CacheGlobalMemory.h:215
Trig::CacheGlobalMemory::unpackDecision
StatusCode unpackDecision(const EventContext &ctx)
unpacks whole trigger decision for the event
Definition: CacheGlobalMemory.cxx:377
Trig::CacheGlobalMemory::AnyTypeDeleter::clear
void clear()
Definition: CacheGlobalMemory.h:260
GroupProperties.h
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
HLTChainList.h
Trig::CacheGlobalMemory::m_store
const asg::EventStoreType * m_store
Pointer to the event store in use.
Definition: CacheGlobalMemory.h:184
Trig::CacheGlobalMemory::createChainGroup
const Trig::ChainGroup * createChainGroup(const std::vector< std::string > &patterns, const std::string &alias="", TrigDefs::Group props=TrigDefs::Group::Default) const
creates new chain group
Definition: CacheGlobalMemory.cxx:54
Trig::CacheGlobalMemory::setRun3NavigationKeyPtr
void setRun3NavigationKeyPtr(SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > *k)
Definition: CacheGlobalMemory.h:143
Trig::CacheGlobalMemory::getStreams
const std::map< std::string, std::vector< std::string > > & getStreams() const
Definition: CacheGlobalMemory.h:119
TrigDecision.h
Trig::CacheGlobalMemory::ATLAS_THREAD_SAFE
std::unique_ptr< IDecisionUnpacker > m_unpacker ATLAS_THREAD_SAFE
Trigger decision unpacker helper.
Definition: CacheGlobalMemory.h:187
Trig
The common trigger namespace for trigger analysis tools.
Definition: LArCellMonAlg.h:33
Trig::CacheGlobalMemory::config_item
const TrigConf::TriggerItem * config_item(const std::string &name) const
CTP config item from given name.
Definition: CacheGlobalMemory.cxx:234
Trig::DecisionAccess
Definition: DecisionAccess.h:53
EventStoreType.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
HLTChain.h
Trig::CacheGlobalMemory::deleteAtTheEndOfEvent
void deleteAtTheEndOfEvent(T t) const
Definition: CacheGlobalMemory.h:156
Trig::CacheGlobalMemory::item
const LVL1CTP::Lvl1Item * item(const std::string &name) const
CTP item from given name.
Definition: CacheGlobalMemory.cxx:260
Trig::CacheGlobalMemory::~CacheGlobalMemory
~CacheGlobalMemory()=default
Trig::CacheGlobalMemory::CTPID
unsigned CTPID
Definition: CacheGlobalMemory.h:203
Trig::CacheGlobalMemory::AnyTypeDeleter::holder::~holder
virtual ~holder()
Definition: CacheGlobalMemory.h:247
Trig::CacheGlobalMemory::m_streams
std::map< std::string, std::vector< std::string > > m_streams
mapping from stream to list of chains
Definition: CacheGlobalMemory.h:210
Trig::CacheGlobalMemory
Definition: CacheGlobalMemory.h:67
Trig::CacheGlobalMemory::setRun2NavigationKeyPtr
void setRun2NavigationKeyPtr(SG::ReadHandleKey< xAOD::TrigNavigation > *k)
Definition: CacheGlobalMemory.h:142
Trig::CacheGlobalMemory::m_cgmMutex
std::recursive_mutex m_cgmMutex
R3 MT protection only against –threads > 1.
Definition: CacheGlobalMemory.h:274
Trig::CacheGlobalMemory::AnyTypeDeleter::holder::ptr
virtual const void * ptr() const
Definition: CacheGlobalMemory.h:250
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
TrigConf::HLTChain
HLT chain configuration information.
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:35
Trig::CacheGlobalMemory::setStore
void setStore(asg::EventStoreType *store)
Set the event store to be used by the object.
Definition: CacheGlobalMemory.h:137
HLT::TrigNavStructure
Definition: TrigNavStructure.h:40
Trig::CacheGlobalMemory::ATLAS_THREAD_SAFE
AnyTypeDeleter m_deleteAtEndOfEvent ATLAS_THREAD_SAFE
Definition: CacheGlobalMemory.h:272
Trig::CacheGlobalMemory::setOldEventInfoKeyPtr
void setOldEventInfoKeyPtr(SG::ReadHandleKey< EventInfo > *k)
Definition: CacheGlobalMemory.h:149
TrigDefs::Group::Default
@ Default
Trig::CacheGlobalMemory::m_confChains
const TrigConf::HLTChainList * m_confChains
all chains configuration
Definition: CacheGlobalMemory.h:213
Trig::CacheGlobalMemory::CHAIN_COUNTER
unsigned CHAIN_COUNTER
Definition: CacheGlobalMemory.h:204
Trig::CacheGlobalMemory::AnyTypeDeleter
Definition: CacheGlobalMemory.h:231
TrigNavigation.h
Trig::CacheGlobalMemory::m_mConfChains
ChainHashMap_t m_mConfChains
map of conf chains
Definition: CacheGlobalMemory.h:226
Trig::CacheGlobalMemory::item_prescale
float item_prescale(int ctpid) const
Prescale for CPT item.
Definition: CacheGlobalMemory.cxx:241
Lvl1Item.h
Trig::CacheGlobalMemory::nChainGroups
size_t nChainGroups() const
Definition: CacheGlobalMemory.cxx:97
Trig::CacheGlobalMemory::navigation
const HLT::TrigNavStructure * navigation() const
Definition: CacheGlobalMemory.h:104
Trig::CacheGlobalMemory::m_groups
std::map< std::string, std::vector< std::string > > m_groups
mapping from group to list of chains
Definition: CacheGlobalMemory.h:209
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
LVL1CTP::Lvl1Item
Definition: Lvl1Item.h:37
Trig::CacheGlobalMemory::store
const asg::EventStoreType * store() const
Get the event store that the object is using.
Definition: CacheGlobalMemory.h:139
Trig::CacheGlobalMemory::getRun3NavigationKeyPtr
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > * getRun3NavigationKeyPtr() const
Definition: CacheGlobalMemory.h:145
Trig::CacheGlobalMemory::navigation
void navigation(HLT::TrigNavStructure *nav)
sets navigation object pointer
Definition: CacheGlobalMemory.h:114
Trig::CacheGlobalMemory::AnyTypeDeleter::iholder::~iholder
virtual ~iholder()
Definition: CacheGlobalMemory.h:235
Trig::CacheGlobalMemory::m_run3NavigationKeyPtr
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > * m_run3NavigationKeyPtr
Parent TDT's read handle key.
Definition: CacheGlobalMemory.h:223
Trig::CacheGlobalMemory::m_navigation
HLT::TrigNavStructure * m_navigation
Navigation owned by CGM.
Definition: CacheGlobalMemory.h:193
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
Trig::CacheGlobalMemory::assert_decision
bool assert_decision() const
checks if new event arrived with the decision Need to use before any call to CacheGlobalMemory.
Definition: CacheGlobalMemory.cxx:266
TrigConf::HLTChainList
list of all HLT chains in a trigger menu
Definition: HLTChainList.h:56
HLTStreamTag.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigDecision.h
Trig::CacheGlobalMemory::config_chain
const TrigConf::HLTChain * config_chain(const std::string &name) const
HLT config chain from given name.
Definition: CacheGlobalMemory.cxx:218
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
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
COOLRates.alias
alias
Definition: COOLRates.py:1172
Trig::CacheGlobalMemory::setOldDecisionKeyPtr
void setOldDecisionKeyPtr(SG::ReadHandleKey< TrigDec::TrigDecision > *k)
Definition: CacheGlobalMemory.h:148
Trig::CacheGlobalMemory::chain
const HLT::Chain * chain(const std::string &name) const
HLT chain object from given name (0 pointer returned if no match)
Definition: CacheGlobalMemory.cxx:201
Logger.h
Trig::CacheGlobalMemory::AnyTypeDeleter::~AnyTypeDeleter
~AnyTypeDeleter()
Definition: CacheGlobalMemory.cxx:417
Trig::CacheGlobalMemory::m_l2chainsByName
std::unordered_map< std::string, const HLT::Chain * > m_l2chainsByName
L2 chains keyed by chain name (chainging every event)
Definition: CacheGlobalMemory.h:200
Chain.h
HLT::Chain
Definition: Chain.h:64
Trig::CacheGlobalMemory::ChainHashMap_t
std::unordered_map< std::string, const TrigConf::HLTChain * > ChainHashMap_t
Definition: CacheGlobalMemory.h:225
Trig::CacheGlobalMemory::ATLAS_THREAD_SAFE
std::map< std::vector< std::string >, Trig::ChainGroup > m_chainGroups ATLAS_THREAD_SAFE
primary storage for chain groups
Definition: CacheGlobalMemory.h:196
Trig::CacheGlobalMemory::unpackNavigation
StatusCode unpackNavigation()
unpacks HLT navigation structure (object access)
Definition: CacheGlobalMemory.cxx:393
TrigCompositeContainer.h
Trig::CacheGlobalMemory::CacheGlobalMemory
CacheGlobalMemory()=default
Trig::ChainGroup
Definition: ChainGroup.h:51
Trig::CacheGlobalMemory::m_oldEventInfoKeyPtr
SG::ReadHandleKey< EventInfo > * m_oldEventInfoKeyPtr
Parent TDT's read handle key.
Definition: CacheGlobalMemory.h:219
Trig::CacheGlobalMemory::AnyTypeDeleter::m_todel
std::set< iholder *, holder_comp > m_todel
Definition: CacheGlobalMemory.h:268
Trig::CacheGlobalMemory::m_confItems
const TrigConf::ItemContainer * m_confItems
items configuration
Definition: CacheGlobalMemory.h:212
Trig::CacheGlobalMemory::AnyTypeDeleter::holder_comp
Definition: CacheGlobalMemory.h:239
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trig::CacheGlobalMemory::m_l2chainsCache
std::map< CHAIN_COUNTER, HLT::Chain > m_l2chainsCache
cache of all L2 chains possible (given configuration)
Definition: CacheGlobalMemory.h:206
Trig::CacheGlobalMemory::AnyTypeDeleter::holder::holder
holder(T &t)
Definition: CacheGlobalMemory.h:246
Trig::CacheGlobalMemory::m_efchainsByName
std::unordered_map< std::string, const HLT::Chain * > m_efchainsByName
L2 chains keyed by chain name (chainging every event)
Definition: CacheGlobalMemory.h:201
Trig::CacheGlobalMemory::setDecisionKeyPtr
void setDecisionKeyPtr(SG::ReadHandleKey< xAOD::TrigDecision > *k)
Definition: CacheGlobalMemory.h:141
TriggerTest.ctp
ctp
Retrieve trigger EDM objects.
Definition: TriggerTest.py:14
Trig::CacheGlobalMemory::m_itemsByName
std::unordered_map< std::string, const LVL1CTP::Lvl1Item * > m_itemsByName
items keyed by configuration name (chainging every event)
Definition: CacheGlobalMemory.h:199
TrigConf::ItemContainer
boost::multi_index::multi_index_container< TriggerItem *, boost::multi_index::indexed_by< boost::multi_index::random_access<>, boost::multi_index::ordered_unique< boost::multi_index::identity< TriggerItem > >, boost::multi_index::ordered_unique< boost::multi_index::tag< tag_ctpid >, boost::multi_index::const_mem_fun< TriggerItem, int, &TriggerItem::ctpId > >, boost::multi_index::hashed_unique< boost::multi_index::tag< tag_name_hash >, boost::multi_index::const_mem_fun< TrigConfData, const std::string &, &TrigConfData::name > > > > ItemContainer
Definition: Menu.h:39
Trig::CacheGlobalMemory::AnyTypeDeleter::insert
void insert(T t)
Definition: CacheGlobalMemory.h:257
Trig::CacheGlobalMemory::m_navigationUnpacked
bool m_navigationUnpacked
Was navigation unpacked for this event?
Definition: CacheGlobalMemory.h:190
Trig::CacheGlobalMemory::getChainGroup
const Trig::ChainGroup * getChainGroup(const std::vector< std::string > &triggerNames, TrigDefs::Group props) const
Definition: CacheGlobalMemory.cxx:83
Trig::CacheGlobalMemory::ATLAS_THREAD_SAFE
std::map< std::vector< std::string >, Trig::ChainGroup * > m_chainGroupsRef ATLAS_THREAD_SAFE
this map keeps the chain group more than once i.e.
Definition: CacheGlobalMemory.h:197
Trig::CacheGlobalMemory::xAODTrigDecisionKey
const SG::ReadHandleKey< xAOD::TrigDecision > * xAODTrigDecisionKey() const
Definition: CacheGlobalMemory.h:152
Trig::CacheGlobalMemory::updateChainGroup
void updateChainGroup(Trig::ChainGroup &chainGroup, TrigDefs::Group props=TrigDefs::Group::Default)
unpacks everything that belongs to a ChainGroup
Definition: CacheGlobalMemory.cxx:104
Trig::CacheGlobalMemory::m_decisionUnpacked
bool m_decisionUnpacked
Was decision unpacked for this event?
Definition: CacheGlobalMemory.h:189
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trig::CacheGlobalMemory::getRun3NavigationKey
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > & getRun3NavigationKey() const
Definition: CacheGlobalMemory.h:144
Trig::CacheGlobalMemory::m_bgCode
char m_bgCode
the encoded bunchgroup information
Definition: CacheGlobalMemory.h:228
IDecisionUnpacker.h
Trig::CacheGlobalMemory::AnyTypeDeleter::holder::m_held
T m_held
Definition: CacheGlobalMemory.h:252
Trig::CacheGlobalMemory::m_efchainsCache
std::map< CHAIN_COUNTER, HLT::Chain > m_efchainsCache
cache of all EF chains possible (given configuration)
Definition: CacheGlobalMemory.h:207
TrigConf::CTPConfig
Definition: CTPConfig.h:27
Trig::CacheGlobalMemory::update
void update(const TrigConf::HLTChainList *confChains, const TrigConf::CTPConfig *ctp)
Updates configuration of the chain groups (i.e.
Definition: CacheGlobalMemory.cxx:109
Trig::CacheGlobalMemory::AnyTypeDeleter::holder
Definition: CacheGlobalMemory.h:244
LVL1CTP
Definition: Lvl1ResultAccessTool.h:20
Trig::CacheGlobalMemory::m_run2NavigationKeyPtr
SG::ReadHandleKey< xAOD::TrigNavigation > * m_run2NavigationKeyPtr
Parent TDT's read handle key.
Definition: CacheGlobalMemory.h:222
Trig::CacheGlobalMemory::m_oldDecisionKeyPtr
SG::ReadHandleKey< TrigDec::TrigDecision > * m_oldDecisionKeyPtr
Parent TDT's read handle key.
Definition: CacheGlobalMemory.h:218
Trig::CacheGlobalMemory::AnyTypeDeleter::iholder::ptr
virtual const void * ptr() const
Definition: CacheGlobalMemory.h:236
checker_macros.h
Define macros for attributes used to control the static checker.
Trig::CacheGlobalMemory::AnyTypeDeleter::holder_comp::operator()
bool operator()(iholder *lhs, iholder *rhs) const
Definition: CacheGlobalMemory.h:240
Trig::CacheGlobalMemory::AnyTypeDeleter::iholder
Definition: CacheGlobalMemory.h:234
TrigConf::TriggerItem
Definition: TriggerItem.h:25
fitman.k
k
Definition: fitman.py:528
Trig::CacheGlobalMemory::m_itemsCache
std::map< CTPID, LVL1CTP::Lvl1Item > m_itemsCache
cache of all CTP items possible (given configuration)
Definition: CacheGlobalMemory.h:205