ATLAS Offline Software
Event.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 #ifndef XAODROOTACCESS_EVENT_H
3 #define XAODROOTACCESS_EVENT_H
4 
5 // Local include(s):
7 
8 // Project include(s):
16 
17 // System include(s).
18 #include <memory>
19 #include <set>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 // Forward declaration(s).
25 class TClass;
26 namespace xAODPrivate {
27 class HolderBucket;
28 class Loader;
29 } // namespace xAODPrivate
30 
31 namespace xAOD {
32 namespace Details {
33 
36 #ifdef XAOD_STANDALONE
37  IProxyDict;
38 #else
39  implements<IProxyDict>;
40 #endif
41 
42 // Forward declaration(s).
43 class IObjectManager;
44 
45 } // namespace Details
46 
47 // Forward declaration(s).
49 class TVirtualManager;
50 
57 class Event : public TVirtualEvent,
59  public asg::AsgMessaging {
60 
61  // Declare the friend functions/classes.
63  friend class xAODPrivate::Loader;
64 
65  public:
67  Event(std::string_view name);
69  virtual ~Event();
70 
73 
75  void setActive() const;
76 
78  void setAuxItemList(const std::string& containerKey,
79  const std::string& itemList);
80 
86  void clearListeners();
87 
89  StatusCode addNameRemap(const std::string& onfile,
90  const std::string& newName);
92  void clearNameRemap();
94  void printNameRemap() const;
95 
97  void printProxyWarnings(bool value = true);
98 
100 
103 
105  const EventFormat* inputEventFormat() const;
107  const EventFormat* outputEventFormat() const;
108 
110 
113 
115  std::string dump();
116 
118  void printIOStats() const;
119 
121  template <typename T>
122  bool contains(const std::string& key);
124  template <typename T>
125  bool transientContains(const std::string& key) const;
126 
128  template <typename T>
129  StatusCode keys(std::vector<std::string>& vkeys, bool metadata) const;
130 
132  template <typename T>
133  StatusCode retrieve(const T*& obj, const std::string& key);
135  template <typename T>
136  StatusCode retrieve(T*& obj, const std::string& key);
137 
139  template <typename T>
140  StatusCode record(T* obj, const std::string& key);
142  template <typename T>
143  StatusCode record(std::unique_ptr<T> obj, const std::string& key);
144 
146  StatusCode copy(const std::string& pattern = ".*");
147 
149 
152 
154  template <typename T>
155  bool containsMeta(const std::string& key);
157  template <typename T>
158  bool transientContainsMeta(const std::string& key) const;
159 
161  template <typename T>
162  StatusCode metaKeys(std::vector<std::string>& vkeys) const;
163 
165  template <typename T>
166  StatusCode retrieveMetaInput(const T*& obj, const std::string& key);
167 
169  template <typename T>
170  StatusCode retrieveMetaOutput(const T*& obj, const std::string& key);
172  template <typename T>
173  StatusCode retrieveMetaOutput(T*& obj, const std::string& key);
174 
176  template <typename T>
177  StatusCode recordMeta(T* obj, const std::string& key);
180  template <typename T>
181  StatusCode recordMeta(std::unique_ptr<T> obj, const std::string& key);
182 
184 
187 
189  SG::sgkey_t getHash(const std::string& key) const override;
191  SG::sgkey_t getKey(const void* obj) const override;
193  const std::string& getName(const void* obj) const override;
195  const std::string& getName(SG::sgkey_t hash) const override;
196 
197  protected:
199  void* getOutputObject(SG::sgkey_t key, const std::type_info& ti) override;
201  const void* getInputObject(SG::sgkey_t key, const std::type_info& ti,
202  bool silent) override;
203 
205 
208 
210  SG::DataProxy* proxy(const void* const pTransient) const override;
211 
213  SG::DataProxy* proxy(const CLID& id, const std::string& key) const override;
214 
216  SG::DataProxy* proxy_exact(SG::sgkey_t sgkey) const override;
217 
220 
222  std::vector<const SG::DataProxy*> proxies() const override;
223 
225  SG::sgkey_t stringToKey(const std::string& str, CLID clid) override;
226 
228  const std::string* keyToString(SG::sgkey_t key) const override;
229 
231  const std::string* keyToString(SG::sgkey_t key, CLID& clid) const override;
232 
234  void registerKey(SG::sgkey_t key, const std::string& str, CLID clid) override;
235 
238  const std::string& key, bool allowMods,
239  bool returnExisting) override;
240 
242  const std::string& name() const override;
243 
245 
247  StatusCode recordTypeless(void* obj, const std::string& typeName,
248  const std::string& key, bool overwrite = false,
249  bool metadata = true, bool isOwner = true);
250 
253 
255  virtual bool hasInput() const = 0;
257  virtual bool hasOutput() const = 0;
258 
260  virtual StatusCode getNames(const std::string& targetClassName,
261  std::vector<std::string>& vkeys,
262  bool metadata = false) const = 0;
263 
265  virtual StatusCode connectObject(const std::string& key, bool silent) = 0;
267  virtual StatusCode connectMetaObject(const std::string& key, bool silent) = 0;
269  virtual StatusCode connectAux(const std::string& prefix, bool standalone) = 0;
272  virtual StatusCode connectMetaAux(const std::string& prefix,
273  bool standalone) = 0;
274 
276  virtual StatusCode setAuxStore(const std::string& key,
278  bool metadata) = 0;
279 
281  virtual StatusCode record(void* obj, const std::string& typeName,
282  const std::string& key, bool overwrite,
283  bool metadata, bool isOwner) = 0;
285  virtual StatusCode recordAux(TVirtualManager& mgr, const std::string& key,
286  bool metadata) = 0;
287 
289 
291  void* getOutputObject(const std::string& key, const std::type_info& ti,
292  bool metadata) const;
294  const void* getInputObject(const std::string& key, const std::type_info& ti,
295  bool silent, bool metadata);
297  bool contains(const std::string& key, const std::type_info& ti,
298  bool metadata);
300  bool transientContains(const std::string& key, const std::type_info& ti,
301  bool metadata) const;
302 
304  using Object_t =
305  std::unordered_map<std::string, std::unique_ptr<TVirtualManager>>;
306 
311  std::set<std::string> m_inputMissingObjects;
314 
319 
324 
326  std::unordered_map<std::string, std::set<std::string>> m_auxItemList;
327 
329  std::set<TVirtualIncidentListener*> m_listeners;
330 
332  std::unordered_map<std::string, std::string> m_nameRemapping;
333 
336 
339 
341  struct BranchInfo {
343  std::unique_ptr<SG::DataProxy> m_proxy;
345  const ::TClass* m_class = 0;
346  }; // struct BranchInfo
347 
349  using upgrade_mutex_t = AthContainers_detail::upgrade_mutex;
355 
357  mutable SG::SGKeyMap<BranchInfo> m_branches
358  ATLAS_THREAD_SAFE; // protected by mutex
359 
361 
364 
367  SG::sgkey_t sgkey) const;
368 
371 
373 
374 }; // class Event
375 
376 } // namespace xAOD
377 
378 // Include the implementation of the template functions.
379 #include "xAODRootAccess/Event.icc"
380 
381 #endif // XAODROOTACCESS_EVENT_H
xAOD::Event::keys
StatusCode keys(std::vector< std::string > &vkeys, bool metadata) const
Provide a list of all data object keys associated with a specific type.
xAOD::TVirtualEvent
Base interface for getting objects out of the input file.
Definition: TVirtualEvent.h:26
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:25
common.sgkey
def sgkey(tool)
Definition: common.py:1027
xAOD::Event::getEventFormatElement
const xAOD::EventFormatElement * getEventFormatElement(SG::sgkey_t sgkey) const
Get the metadata object for a given "SG key".
Definition: EventIProxyDict.cxx:319
xAOD::Event::retrieveMetaOutput
StatusCode retrieveMetaOutput(T *&obj, const std::string &key)
Retrieve an output metadata object.
xAOD::Event::clearListeners
void clearListeners()
Remove all listeners from the object.
Definition: EventCore.cxx:136
xAODPrivate::Loader
Definition: EventIProxyDict.cxx:142
xAOD::Event::ATLAS_THREAD_SAFE
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition: Event.h:358
xAOD::Event::setAuxStore
virtual StatusCode setAuxStore(const std::string &key, Details::IObjectManager &mgr, bool metadata)=0
Function connecting a DV object to its auxiliary store.
L1CaloPhase1Monitoring.standalone
standalone
Definition: L1CaloPhase1Monitoring.py:139
xAOD::Event::recordTypeless
StatusCode recordTypeless(void *obj, const std::string &typeName, const std::string &key, bool overwrite=false, bool metadata=true, bool isOwner=true)
Internal function for recording an object into the output.
xAOD::Event::name
const std::string & name() const override
Get the name of the instance.
Definition: EventIProxyDict.cxx:313
xAOD::Event::transientContains
bool transientContains(const std::string &key, const std::type_info &ti, bool metadata) const
Internal function checking if an object is already in memory.
xAOD::Event::BranchInfo::m_class
const ::TClass * m_class
Dictionary describing this branch/object.
Definition: Event.h:345
xAOD::Event::m_inputObjects
Object_t m_inputObjects
Collection of all the managed input objects.
Definition: Event.h:308
xAOD::Event::m_outputMetaObjects
Object_t m_outputMetaObjects
Collection of all the managed output meta-objects.
Definition: Event.h:318
xAOD::Event::m_inputEventFormat
EventFormat m_inputEventFormat
Format of the current input file.
Definition: Event.h:321
xAOD::Event::recordObject
SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Record an object in the store.
Definition: EventIProxyDict.cxx:307
xAOD::Event::setActive
void setActive() const
Set this event object as the currently active one.
Definition: EventCore.cxx:54
xAOD::Event::Event
Event(std::string_view name)
Constructor with a name.
Definition: EventCore.cxx:27
athena.value
value
Definition: athena.py:124
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::Event::keyToString
const std::string * keyToString(SG::sgkey_t key) const override
Find the string corresponding to a given key.
Definition: EventIProxyDict.cxx:292
xAOD::TVirtualIncidentListener
Class providing an interface for classes listening to xAOD incidents.
Definition: TVirtualIncidentListener.h:25
xAOD::EventFormatElement
Class describing one branch of the ROOT file.
Definition: EventFormatElement.h:39
xAOD::Event::stringToKey
SG::sgkey_t stringToKey(const std::string &str, CLID clid) override
Find the string corresponding to a given key.
Definition: EventIProxyDict.cxx:287
xAOD::Event::m_nameRemapping
std::unordered_map< std::string, std::string > m_nameRemapping
Container name re-mapping rules.
Definition: Event.h:332
xAOD::TVirtualManager
Interface class for the "manager classes".
Definition: TVirtualManager.h:24
IProxyDict.h
xAOD::Event::contains
bool contains(const std::string &key, const std::type_info &ti, bool metadata)
Internal function checking if an object is in the input.
xAOD::Event::removeListener
StatusCode removeListener(TVirtualIncidentListener *listener)
Remove an incident listener object.
Definition: EventCore.cxx:121
xAOD::Event::copy
StatusCode copy(const std::string &pattern=".*")
Copy an object directly from the input to the output.
Definition: EventIO.cxx:28
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
xAOD::Event::Object_t
std::unordered_map< std::string, std::unique_ptr< TVirtualManager > > Object_t
Definition of the internal data structure type.
Definition: Event.h:305
xAOD::Event::m_inputMetaObjects
Object_t m_inputMetaObjects
Collection of all the managed input meta-objects.
Definition: Event.h:316
xAOD::Event::getNames
virtual StatusCode getNames(const std::string &targetClassName, std::vector< std::string > &vkeys, bool metadata=false) const =0
Function determining the list keys associated with a type name.
xAOD::Event::getName
const std::string & getName(const void *obj) const override
Function returning the key describing a known object.
Definition: EventTVirtualEvent.cxx:64
python.checkMetadata.metadata
metadata
Definition: checkMetadata.py:175
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
AsgMessaging.h
xAOD::Event::hasOutput
virtual bool hasOutput() const =0
Check if an output file is connected to the object.
xAOD::Event::m_printEventProxyWarnings
bool m_printEventProxyWarnings
Option to silence common warnings that seem to be harmless.
Definition: Event.h:335
xAOD::Event::metaKeys
StatusCode metaKeys(std::vector< std::string > &vkeys) const
Provide a list of all metadata object keys associated with a specific type.
xAOD::Event::addToStore
StatusCode addToStore(CLID id, SG::DataProxy *proxy) override
Add a new proxy to the store.
Definition: EventIProxyDict.cxx:249
xAOD::Event::m_auxItemList
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition: Event.h:326
xAOD::Event::inputEventFormat
const EventFormat * inputEventFormat() const
Get information about the input objects.
Definition: EventCore.cxx:221
xAOD::Event::proxies
std::vector< const SG::DataProxy * > proxies() const override
return the list of all current proxies in store
Definition: EventIProxyDict.cxx:273
xAOD::Event::connectMetaObject
virtual StatusCode connectMetaObject(const std::string &key, bool silent)=0
Function setting up access to a particular metadata object.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::Event::BranchInfo::m_proxy
std::unique_ptr< SG::DataProxy > m_proxy
Data proxy describing this branch/object.
Definition: Event.h:343
xAOD::Event::retrieveMetaOutput
StatusCode retrieveMetaOutput(const T *&obj, const std::string &key)
Retrieve an output metadata object.
TVirtualEvent.h
vertexingJO_ITK_init.itemList
list itemList
Definition: vertexingJO_ITK_init.py:95
xAOD::Event::m_branchesMutex
upgrade_mutex_t m_branchesMutex
Mutex for multithread synchronization.
Definition: Event.h:354
xAOD::Event::getOutputObject
void * getOutputObject(SG::sgkey_t key, const std::type_info &ti) override
Function for retrieving an output object in a non-template way.
Definition: EventTVirtualEvent.cxx:138
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
xAOD::Event::recordAux
virtual StatusCode recordAux(TVirtualManager &mgr, const std::string &key, bool metadata)=0
Record an auxiliary store into a connected output file.
xAOD::Event::printIOStats
void printIOStats() const
Function printing the I/O statistics of the current process.
Definition: EventCore.cxx:291
xAOD::Event::transientContainsMeta
bool transientContainsMeta(const std::string &key) const
Function checking if a meta-object is already in memory.
xAOD::Event::proxy_exact
SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override
Get proxy given a hashed key+clid.
Definition: EventIProxyDict.cxx:220
xAOD::Event::printProxyWarnings
void printProxyWarnings(bool value=true)
Enable warnings associated with broken element links.
Definition: EventCore.cxx:216
xAOD::Event::addNameRemap
StatusCode addNameRemap(const std::string &onfile, const std::string &newName)
Add a name re-mapping rule.
Definition: EventCore.cxx:155
xAOD::Event::BranchInfo
Helper struct used by the IProxyDict code.
Definition: Event.h:341
xAOD::Details::IProxyDictBase
implements< IProxyDict > IProxyDictBase
IProxyDict base class to use in a specific build environment
Definition: Event.h:39
xAOD::Event::getInputObject
const void * getInputObject(SG::sgkey_t key, const std::type_info &ti, bool silent) override
Function for retrieving an input object in a non-template way.
Definition: EventTVirtualEvent.cxx:162
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
xAOD::Event::hasInput
virtual bool hasInput() const =0
Check if an input file is connected to the object.
xAOD::Event::record
StatusCode record(T *obj, const std::string &key)
Add an output object to the event.
xAODPrivate::HolderBucket
Helper object for holding something through a THolder.
Definition: EventIProxyDict.cxx:42
StatusCode.h
xAOD::Event::clearNameRemap
void clearNameRemap()
Clear the current name re-mapping.
Definition: EventCore.cxx:186
xAOD::Event::m_inputMissingObjects
std::set< std::string > m_inputMissingObjects
Objects that have been asked for, but were found to be missing in the current input.
Definition: Event.h:311
xAOD::Event::m_outputObjects
Object_t m_outputObjects
Collection of all the managed output object.
Definition: Event.h:313
xAOD::Event::connectAux
virtual StatusCode connectAux(const std::string &prefix, bool standalone)=0
Function setting up access to a set of auxiliary branches.
EventFormat.h
xAOD::EventFormat_v1
Event format metadata for xAOD files.
Definition: EventFormat_v1.h:38
xAOD::Event::printNameRemap
void printNameRemap() const
Print the current name re-mapping rules.
Definition: EventCore.cxx:194
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
xAOD::Event::connectObject
virtual StatusCode connectObject(const std::string &key, bool silent)=0
Function setting up access to a particular object.
MakeNewFileFromOldAndSubstitution.newName
dictionary newName
Definition: ICHEP2016/MakeNewFileFromOldAndSubstitution.py:95
xAOD::Event::record
StatusCode record(std::unique_ptr< T > obj, const std::string &key)
Add an output object to the event, explicitly taking ownership of it.
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
threading.h
Threading definitions.
xAOD::Event::m_listeners
std::set< TVirtualIncidentListener * > m_listeners
Listeners who should be notified when certain incidents happen.
Definition: Event.h:329
xAOD::Event::contains
bool contains(const std::string &key)
Function checking if an object is available from the store.
xAOD::Event::recordMeta
StatusCode recordMeta(T *obj, const std::string &key)
Add an object to the output file's metadata.
Event.icc
xAOD::Event::~Event
virtual ~Event()
Virtual destructor.
Definition: EventCore.cxx:39
xAOD::Event::addListener
StatusCode addListener(TVirtualIncidentListener *listener)
Register an incident listener object.
Definition: EventCore.cxx:97
xAOD::Event::getKey
SG::sgkey_t getKey(const void *obj) const override
Function returning the hash describing a known object.
Definition: EventTVirtualEvent.cxx:51
xAOD::Event::m_outputEventFormat
EventFormat * m_outputEventFormat
Format of the current output file.
Definition: Event.h:323
xAOD::Event::record
virtual StatusCode record(void *obj, const std::string &typeName, const std::string &key, bool overwrite, bool metadata, bool isOwner)=0
Record an object into a connected output file.
xAOD::Event::containsMeta
bool containsMeta(const std::string &key)
Function checking if a meta-object is available from the store.
python.trfDecorators.silent
def silent(func)
Redirect stdout/err to /dev/null Useful wrapper to get rid of ROOT verbosity...
Definition: trfDecorators.py:24
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
xAOD::Event::upgrade_mutex_t
AthContainers_detail::upgrade_mutex upgrade_mutex_t
Mutex type for multithread synchronization.
Definition: Event.h:349
SG::SGKeyMap
std::unordered_map< sgkey_t, T > SGKeyMap
A map using sgkey_t as a key.
Definition: CxxUtils/CxxUtils/sgkey_t.h:93
xAODPrivate
Definition: EventIProxyDict.cxx:39
xAOD::Event::dump
std::string dump()
Function creating a user-readable dump of the current input.
Definition: EventCore.cxx:243
xAOD::Event::retrieveMetaInput
StatusCode retrieveMetaInput(const T *&obj, const std::string &key)
Retrieve an input metadata object.
upgrade_mutex.h
xAOD::Event::setAuxItemList
void setAuxItemList(const std::string &containerKey, const std::string &itemList)
Configure which dynamic variables to write out for a given store.
Definition: EventCore.cxx:71
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
xAOD::Event::proxy
SG::DataProxy * proxy(const void *const pTransient) const override
get proxy for a given data object address in memory
Definition: EventIProxyDict.cxx:183
xAOD::Event::getHash
SG::sgkey_t getHash(const std::string &key) const override
Function returning the hash describing an object name.
Definition: EventTVirtualEvent.cxx:27
AthContainers_detail::upgrading_lock
Lock object for taking out upgradable locks.
Definition: threading.h:177
str
Definition: BTagTrackIpAccessor.cxx:11
xAOD::Event::getBranchInfo
const BranchInfo * getBranchInfo(SG::sgkey_t sgkey) const
Get the object describing one object/branch.
Definition: EventIProxyDict.cxx:345
SG::DataObjectSharedPtr
Smart pointer to manage DataObject reference counts.
Definition: DataObjectSharedPtr.h:45
xAOD::Event::retrieve
StatusCode retrieve(T *&obj, const std::string &key)
Retrieve an output object from the event.
xAOD::Details::IObjectManager
Manager for EDM objects created by ROOT.
Definition: IObjectManager.h:20
xAOD::Event
Base class for the event (xAOD::TEvent and xAOD::REvent) classes.
Definition: Event.h:59
xAOD::Event::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::DataProxy
Definition: DataProxy.h:45
xAOD::Event::recordMeta
StatusCode recordMeta(std::unique_ptr< T > obj, const std::string &key)
Add an object to the output file's metadata, explicitly taking ownership of it.
xAOD::Event::outputEventFormat
const EventFormat * outputEventFormat() const
Get information about the output objects.
Definition: EventCore.cxx:229
xAOD::Event::transientContains
bool transientContains(const std::string &key) const
Function checking if an object is already in memory.
xAOD::Event::registerKey
void registerKey(SG::sgkey_t key, const std::string &str, CLID clid) override
Remember an additional mapping from key to string/CLID.
Definition: EventIProxyDict.cxx:302
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
xAOD::Event::connectMetaAux
virtual StatusCode connectMetaAux(const std::string &prefix, bool standalone)=0
Function setting up access to a set of auxiliary branches for a metadata object.