ATLAS Offline Software
Loading...
Searching...
No Matches
Event.h
Go to the documentation of this file.
1// Copyright (C) 2002-2026 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):
17
18// System include(s).
19#include <memory>
20#include <set>
21#include <string>
22#include <unordered_map>
23#include <vector>
24
25// Forward declaration(s).
26class TClass;
27class TFile;
28namespace xAODPrivate {
29class HolderBucket;
30class Loader;
31} // namespace xAODPrivate
32
33namespace xAOD {
34namespace Details {
35
38#ifdef XAOD_STANDALONE
40#else
41 implements<IProxyDict>;
42#endif
43
44// Forward declaration(s).
45class IObjectManager;
46
47} // namespace Details
48
49// Forward declaration(s).
51class TVirtualManager;
52
59class Event : public TVirtualEvent,
61 public asg::AsgMessaging {
62
63 // Declare the friend functions/classes.
65 friend class xAODPrivate::Loader;
66
67 public:
69 // If ctx is supplied, then remember that as the context corresponding
70 // to this event. Otherwise, make this the current event store.
71 Event(std::string_view name, const EventContext* ctx = nullptr);
73 virtual ~Event();
74
77
79 static const char* const EVENT_TREE_NAME;
80 static const char* const EVENT_RNTUPLE_NAME;
81 static const char* const METADATA_OBJECT_NAME;
82
86 static std::unique_ptr<Event> createAndReadFrom(TFile& file);
87
89 virtual StatusCode readFrom(TFile& inFile) = 0;
90
92 virtual StatusCode writeTo(TFile& file) = 0;
93
95 virtual StatusCode finishWritingTo(TFile& file) = 0;
96
98 void setActive() const;
99
101 void setAuxItemList(const std::string& containerKey,
102 const std::string& itemList);
103
105 StatusCode addListener(TVirtualIncidentListener* listener);
107 StatusCode removeListener(TVirtualIncidentListener* listener);
109 void clearListeners();
110
112 StatusCode addNameRemap(const std::string& onfile,
113 const std::string& newName);
115 void clearNameRemap();
117 void printNameRemap() const;
118
120 void printProxyWarnings(bool value = true);
121
123
126
128 virtual ::Long64_t getEntries() const = 0;
130 virtual ::Int_t getEntry(::Long64_t entry, ::Int_t getall = 0) = 0;
131
133 virtual ::Int_t fill() = 0;
134
136 const EventFormat* inputEventFormat() const;
138 const EventFormat* outputEventFormat() const;
139
141
144
146 std::string dump();
147
149 void printIOStats() const;
150
152 template <typename T>
153 bool contains(const std::string& key);
155 template <typename T>
156 bool transientContains(const std::string& key) const;
157
159 template <typename T>
160 StatusCode keys(std::vector<std::string>& vkeys, bool metadata) const;
161
163 template <typename T>
164 StatusCode retrieve(const T*& obj, const std::string& key);
166 template <typename T>
167 StatusCode retrieve(T*& obj, const std::string& key);
168
170 template <typename T>
171 StatusCode record(T* obj, const std::string& key);
173 template <typename T>
174 StatusCode record(std::unique_ptr<T> obj, const std::string& key);
175
177 StatusCode copy(const std::string& pattern = ".*");
178
180
183
185 template <typename T>
186 bool containsMeta(const std::string& key);
188 template <typename T>
189 bool transientContainsMeta(const std::string& key) const;
190
192 template <typename T>
193 StatusCode metaKeys(std::vector<std::string>& vkeys) const;
194
196 template <typename T>
197 StatusCode retrieveMetaInput(const T*& obj, const std::string& key);
198
200 template <typename T>
201 StatusCode retrieveMetaOutput(const T*& obj, const std::string& key);
203 template <typename T>
204 StatusCode retrieveMetaOutput(T*& obj, const std::string& key);
205
207 template <typename T>
208 StatusCode recordMeta(T* obj, const std::string& key);
211 template <typename T>
212 StatusCode recordMeta(std::unique_ptr<T> obj, const std::string& key);
213
215
218
220 SG::sgkey_t getHash(const std::string& key) const override;
222 SG::sgkey_t getKey(const void* obj) const override;
224 const std::string& getName(const void* obj) const override;
226 const std::string& getName(SG::sgkey_t hash) const override;
227
228 protected:
229
231 void* getOutputObject(SG::sgkey_t key, const std::type_info& ti) override;
233 const void* getInputObject(SG::sgkey_t key, const std::type_info& ti,
234 bool silent) override;
235
237
240
242 SG::DataProxy* proxy(const void* const pTransient) const override;
243
245 SG::DataProxy* proxy(const CLID& id, const std::string& key) const override;
246
248 SG::DataProxy* proxy_exact(SG::sgkey_t sgkey) const override;
249
251 StatusCode addToStore(CLID id, SG::DataProxy* proxy) override;
252
254 std::vector<const SG::DataProxy*> proxies() const override;
255
257 SG::sgkey_t stringToKey(const std::string& str, CLID clid) override;
258
260 const std::string* keyToString(SG::sgkey_t key) const override;
261
263 const std::string* keyToString(SG::sgkey_t key, CLID& clid) const override;
264
266 void registerKey(SG::sgkey_t key, const std::string& str, CLID clid) override;
267
270 const std::string& key, bool allowMods,
271 bool returnExisting) override;
272
274 const std::string& name() const override;
275
277
279 StatusCode recordTypeless(void* obj, const std::string& typeName,
280 const std::string& key, bool overwrite = false,
281 bool metadata = true, bool isOwner = true);
282
285
287 virtual bool hasInput() const = 0;
289 virtual bool hasOutput() const = 0;
290
292 virtual StatusCode getNames(const std::string& targetClassName,
293 std::vector<std::string>& vkeys,
294 bool metadata = false) const = 0;
295
297 virtual StatusCode connectObject(const std::string& key, bool silent) = 0;
299 virtual StatusCode connectMetaObject(const std::string& key, bool silent) = 0;
301 virtual StatusCode connectAux(const std::string& prefix, bool standalone) = 0;
304 virtual StatusCode connectMetaAux(const std::string& prefix,
305 bool standalone) = 0;
306
308 virtual StatusCode setAuxStore(const std::string& key,
310 bool metadata) = 0;
311
313 StatusCode record(void* obj, const std::string& typeName,
314 const std::string& key, bool overwrite,
315 bool metadata, bool isOwner)
316 { return recordImpl( obj, typeName, key, overwrite, metadata, isOwner ); }
317 virtual StatusCode recordImpl(void* obj, const std::string& typeName,
318 const std::string& key, bool overwrite,
319 bool metadata, bool isOwner) = 0;
321 virtual StatusCode recordAux(TVirtualManager& mgr, const std::string& key,
322 bool metadata) = 0;
323
325
327 void* getOutputObject(const std::string& key, const std::type_info& ti,
328 bool metadata) const;
330 const void* getInputObject(const std::string& key, const std::type_info& ti,
331 bool silent, bool metadata);
333 bool contains(const std::string& key, const std::type_info& ti,
334 bool metadata);
336 bool transientContains(const std::string& key, const std::type_info& ti,
337 bool metadata) const;
338
341 const EventContext& currentContext() const;
342
344 using Object_t =
345 std::unordered_map<std::string, std::unique_ptr<TVirtualManager>>;
346
351 std::set<std::string> m_inputMissingObjects;
354
359
364
366 std::unordered_map<std::string, std::set<std::string>> m_auxItemList;
367
369 std::vector<TVirtualIncidentListener*> m_listeners;
370
372 std::unordered_map<std::string, std::string> m_nameRemapping;
373
376
379
381 struct BranchInfo {
383 std::unique_ptr<SG::DataProxy> m_proxy;
385 const ::TClass* m_class = 0;
386 }; // struct BranchInfo
387
389 using upgrade_mutex_t = AthContainers_detail::upgrade_mutex;
395
397 mutable SG::SGKeyMap<BranchInfo> m_branches
398 ATLAS_THREAD_SAFE; // protected by mutex
399
401
404
407 SG::sgkey_t sgkey) const;
408
410 const BranchInfo* getBranchInfo(SG::sgkey_t sgkey) const;
411
412#ifndef XAOD_STANDALONE
414 EventContext m_ctx;
415#endif
417
418}; // class Event
419
420} // namespace xAOD
421
422// Include the implementation of the template functions.
424
425#endif // XAODROOTACCESS_EVENT_H
uint32_t CLID
The Class ID type.
Define macros for attributes used to control the static checker.
Lock object for taking out upgradable locks.
Definition threading.h:177
Class mimicking the AthMessaging class from the offline software.
Helper object for holding something through a THolder.
Manager for EDM objects created by ROOT.
Class describing one branch of the ROOT file.
StatusCode removeListener(TVirtualIncidentListener *listener)
Remove an incident listener object.
virtual bool hasInput() const =0
Check if an input file is connected to the object.
StatusCode record(std::unique_ptr< T > obj, const std::string &key)
Add an output object to the event, explicitly taking ownership of it.
virtual StatusCode writeTo(TFile &file)=0
Connect the object to an output file.
StatusCode addListener(TVirtualIncidentListener *listener)
Register an incident listener object.
virtual StatusCode connectAux(const std::string &prefix, bool standalone)=0
Function setting up access to a set of auxiliary branches.
StatusCode retrieve(T *&obj, const std::string &key)
Retrieve an output object from the event.
EventFormat m_inputEventFormat
Format of the current input file.
Definition Event.h:361
const std::string & name() const override
Get the name of the instance.
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:351
virtual StatusCode readFrom(TFile &inFile)=0
Read from a new file - only needed for the second+ files.
StatusCode retrieveMetaInput(const T *&obj, const std::string &key)
Retrieve an input metadata object.
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.
bool transientContains(const std::string &key) const
Function checking if an object is already in memory.
const EventFormat * outputEventFormat() const
Get information about the output objects.
const std::string * keyToString(SG::sgkey_t key) const override
Find the string corresponding to a given key.
virtual StatusCode recordAux(TVirtualManager &mgr, const std::string &key, bool metadata)=0
Record an auxiliary store into a connected output file.
virtual bool hasOutput() const =0
Check if an output file is connected to the object.
void registerKey(SG::sgkey_t key, const std::string &str, CLID clid) override
Remember an additional mapping from key to string/CLID.
EventContext m_ctx
The event context associated with this event.
Definition Event.h:414
bool contains(const std::string &key, const std::type_info &ti, bool metadata)
Internal function checking if an object is in the input.
void clearListeners()
Remove all listeners from the object.
static std::unique_ptr< Event > createAndReadFrom(TFile &file)
static method to create an Event object and readFrom a file, given by a TFile.
Definition EventIO.cxx:43
StatusCode recordMeta(T *obj, const std::string &key)
Add an object to the output file's metadata.
void clearNameRemap()
Clear the current name re-mapping.
const EventFormat * inputEventFormat() const
Get information about the input objects.
bool contains(const std::string &key)
Function checking if an object is available from the store.
virtual StatusCode recordImpl(void *obj, const std::string &typeName, const std::string &key, bool overwrite, bool metadata, bool isOwner)=0
virtual::Int_t fill()=0
Method filling one event into the output tree.
SG::sgkey_t stringToKey(const std::string &str, CLID clid) override
Find the string corresponding to a given key.
std::vector< const SG::DataProxy * > proxies() const override
return the list of all current proxies in store
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.
upgrade_mutex_t m_branchesMutex
Mutex for multithread synchronization.
Definition Event.h:394
virtual StatusCode connectObject(const std::string &key, bool silent)=0
Function setting up access to a particular object.
std::unordered_map< std::string, std::unique_ptr< TVirtualManager > > Object_t
Definition of the internal data structure type.
Definition Event.h:344
StatusCode addNameRemap(const std::string &onfile, const std::string &newName)
Add a name re-mapping rule.
StatusCode metaKeys(std::vector< std::string > &vkeys) const
Provide a list of all metadata object keys associated with a specific type.
const std::string & getName(const void *obj) const override
Function returning the key describing a known object.
SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override
Get proxy given a hashed key+clid.
Object_t m_inputObjects
Collection of all the managed input objects.
Definition Event.h:348
Event(std::string_view name, const EventContext *ctx=nullptr)
Constructor with a name.
Definition EventCore.cxx:28
void setAuxItemList(const std::string &containerKey, const std::string &itemList)
Configure which dynamic variables to write out for a given store.
Definition EventCore.cxx:80
static const char *const METADATA_OBJECT_NAME
Name of the metadata tree or RNTuple.
Definition Event.h:81
virtual ~Event()
Virtual destructor.
Definition EventCore.cxx:48
static const char *const EVENT_TREE_NAME
Default name of the event TTree.
Definition Event.h:79
StatusCode copy(const std::string &pattern=".*")
Copy an object directly from the input to the output.
Definition EventIO.cxx:95
SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Record an object in the store.
std::string dump()
Function creating a user-readable dump of the current input.
void printProxyWarnings(bool value=true)
Enable warnings associated with broken element links.
virtual::Long64_t getEntries() const =0
Get how many entries are available from the current input file(s).
bool m_printEventProxyWarnings
Option to silence common warnings that seem to be harmless.
Definition Event.h:375
SG::sgkey_t getKey(const void *obj) const override
Function returning the hash describing a known object.
void * getOutputObject(SG::sgkey_t key, const std::type_info &ti) override
Function for retrieving an output object in a non-template way.
StatusCode addToStore(CLID id, SG::DataProxy *proxy) override
Add a new proxy to the store.
StatusCode retrieveMetaOutput(T *&obj, const std::string &key)
Retrieve an output metadata object.
virtual StatusCode connectMetaObject(const std::string &key, bool silent)=0
Function setting up access to a particular metadata object.
virtual StatusCode finishWritingTo(TFile &file)=0
Finish writing to an output file.
virtual StatusCode setAuxStore(const std::string &key, Details::IObjectManager &mgr, bool metadata)=0
Function connecting a DV object to its auxiliary store.
const BranchInfo * getBranchInfo(SG::sgkey_t sgkey) const
Get the object describing one object/branch.
StatusCode record(T *obj, const std::string &key)
Add an output object to the event.
bool transientContainsMeta(const std::string &key) const
Function checking if a meta-object is already in memory.
StatusCode record(void *obj, const std::string &typeName, const std::string &key, bool overwrite, bool metadata, bool isOwner)
Record an object into a connected output file.
Definition Event.h:313
const xAOD::EventFormatElement * getEventFormatElement(SG::sgkey_t sgkey) const
Get the metadata object for a given "SG key".
void printNameRemap() const
Print the current name re-mapping rules.
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.
StatusCode keys(std::vector< std::string > &vkeys, bool metadata) const
Provide a list of all data object keys associated with a specific type.
virtual StatusCode connectMetaAux(const std::string &prefix, bool standalone)=0
Function setting up access to a set of auxiliary branches for a metadata object.
StatusCode retrieveMetaOutput(const T *&obj, const std::string &key)
Retrieve an output metadata object.
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
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.
void setActive() const
Set this event object as the currently active one.
Definition EventCore.cxx:63
SG::sgkey_t getHash(const std::string &key) const override
Function returning the hash describing an object name.
static const char *const EVENT_RNTUPLE_NAME
Name of the event RNTuple.
Definition Event.h:80
std::unordered_map< std::string, std::string > m_nameRemapping
Container name re-mapping rules.
Definition Event.h:372
Object_t m_inputMetaObjects
Collection of all the managed input meta-objects.
Definition Event.h:356
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition Event.h:366
EventFormat * m_outputEventFormat
Format of the current output file.
Definition Event.h:363
bool transientContains(const std::string &key, const std::type_info &ti, bool metadata) const
Internal function checking if an object is already in memory.
virtual::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)=0
Function loading a given entry of the input TTree.
Object_t m_outputObjects
Collection of all the managed output object.
Definition Event.h:353
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition Event.h:398
AthContainers_detail::upgrading_lock< upgrade_mutex_t > upgrading_lock_t
Lock type for multithread synchronization.
Definition Event.h:391
void printIOStats() const
Function printing the I/O statistics of the current process.
bool containsMeta(const std::string &key)
Function checking if a meta-object is available from the store.
AthContainers_detail::upgrade_mutex upgrade_mutex_t
Mutex type for multithread synchronization.
Definition Event.h:389
const EventContext & currentContext() const
Return the event context corresponding to this event.
std::vector< TVirtualIncidentListener * > m_listeners
Listeners who should be notified when certain incidents happen.
Definition Event.h:369
SG::DataProxy * proxy(const void *const pTransient) const override
get proxy for a given data object address in memory
Object_t m_outputMetaObjects
Collection of all the managed output meta-objects.
Definition Event.h:358
Base interface for getting objects out of the input file.
Class providing an interface for classes listening to xAOD incidents.
Interface class for the "manager classes".
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
std::unordered_map< sgkey_t, T > SGKeyMap
A map using sgkey_t as a key.
Definition sgkey_t.h:93
implements< IProxyDict > IProxyDictBase
IProxyDict base class to use in a specific build environment
Definition Event.h:37
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition EventFormat.h:16
Helper struct used by the IProxyDict code.
Definition Event.h:381
std::unique_ptr< SG::DataProxy > m_proxy
Data proxy describing this branch/object.
Definition Event.h:383
const ::TClass * m_class
Dictionary describing this branch/object.
Definition Event.h:385
Threading definitions.
TFile * file