ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::Event Class Referenceabstract

Base class for the event (xAOD::TEvent and xAOD::REvent) classes. More...

#include <Event.h>

Inheritance diagram for xAOD::Event:
Collaboration diagram for xAOD::Event:

Classes

struct  BranchInfo
 Helper struct used by the IProxyDict code. More...

Public Types

using sgkey_t = SG::sgkey_t

Public Member Functions

 Event (std::string_view name, const EventContext *ctx=nullptr)
 Constructor with a name.
virtual ~Event ()
 Virtual destructor.
template<typename T>
bool retrieve (const T *&obj, sgkey_t key=DEFAULT_KEY, bool silent=false)
 Function retrieving an object from the event (constant version).
template<typename T>
bool retrieve (const T *&obj, const std::string &key, bool silent=false)
 Function retrieving an object from the event (constant version).
void setLevel (MSG::Level lvl)
 Change the current logging level.
Persistent data accessor/modifier functions
virtual::Long64_t getEntries () const =0
 Get how many entries are available from the current input file(s).
virtual::Int_t getEntry (::Long64_t entry, ::Int_t getall=0)=0
 Function loading a given entry of the input TTree.
virtual::Int_t fill ()=0
 Method filling one event into the output tree.
const EventFormat * inputEventFormat () const
 Get information about the input objects.
const EventFormat * outputEventFormat () const
 Get information about the output objects.
Event data accessor/modifier functions
std::string dump ()
 Function creating a user-readable dump of the current input.
void printIOStats () const
 Function printing the I/O statistics of the current process.
template<typename T>
bool contains (const std::string &key)
 Function checking if an object is available from the store.
template<typename T>
bool transientContains (const std::string &key) const
 Function checking if an object is already in memory.
template<typename T>
StatusCode keys (std::vector< std::string > &vkeys, bool metadata) const
 Provide a list of all data object keys associated with a specific type.
template<typename T>
StatusCode retrieve (const T *&obj, const std::string &key)
 Retrieve either an input or an output object from the event.
template<typename T>
StatusCode retrieve (T *&obj, const std::string &key)
 Retrieve an output object from the event.
template<typename T>
StatusCode record (T *obj, const std::string &key)
 Add an output object to the event.
template<typename T>
StatusCode record (std::unique_ptr< T > obj, const std::string &key)
 Add an output object to the event, explicitly taking ownership of it.
StatusCode copy (const std::string &pattern=".*")
 Copy an object directly from the input to the output.
Metadata accessor/modifier functions
template<typename T>
bool containsMeta (const std::string &key)
 Function checking if a meta-object is available from the store.
template<typename T>
bool transientContainsMeta (const std::string &key) const
 Function checking if a meta-object is already in memory.
template<typename T>
StatusCode metaKeys (std::vector< std::string > &vkeys) const
 Provide a list of all metadata object keys associated with a specific type.
template<typename T>
StatusCode retrieveMetaInput (const T *&obj, const std::string &key)
 Retrieve an input metadata object.
template<typename T>
StatusCode retrieveMetaOutput (const T *&obj, const std::string &key)
 Retrieve an output metadata object.
template<typename T>
StatusCode retrieveMetaOutput (T *&obj, const std::string &key)
 Retrieve an output metadata object.
template<typename T>
StatusCode recordMeta (T *obj, const std::string &key)
 Add an object to the output file's metadata.
template<typename T>
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.
Functions providing the same interface as AthMessaging
bool msgLvl (const MSG::Level lvl) const
 Test the output level of the object.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.

Static Public Attributes

static constexpr sgkey_t DEFAULT_KEY = ~static_cast<sgkey_t>(0)
 Key for retrieving the "default" object of a given type.
static constexpr sgkey_t KEY_MASK = DEFAULT_KEY >> 2
 Mask for the keys, used mostly internally.

Protected Types

using Object_t
 Definition of the internal data structure type.

Protected Member Functions

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.
void * getOutputObject (const std::string &key, const std::type_info &ti, bool metadata) const
 Function for retrieving an output object in a non-template way.
const void * getInputObject (const std::string &key, const std::type_info &ti, bool silent, bool metadata)
 Function for retrieving an input object in a non-template way.
bool contains (const std::string &key, const std::type_info &ti, bool metadata)
 Internal function checking if an object is in the input.
bool transientContains (const std::string &key, const std::type_info &ti, bool metadata) const
 Internal function checking if an object is already in memory.
const EventContext & currentContext () const
 Return the event context corresponding to this event.
Functions implementing the IProxyDict interface
SG::DataProxy * proxy (const void *const pTransient) const override
 get proxy for a given data object address in memory
SG::DataProxy * proxy (const CLID &id, const std::string &key) const override
 get proxy with given id and key. Returns 0 to flag failure
SG::DataProxy * proxy_exact (SG::sgkey_t sgkey) const override
 Get proxy given a hashed key+clid.
StatusCode addToStore (CLID id, SG::DataProxy *proxy) override
 Add a new proxy to the store.
std::vector< const SG::DataProxy * > proxies () const override
 return the list of all current proxies in store
SG::sgkey_t stringToKey (const std::string &str, CLID clid) override
 Find the string corresponding to a given key.
const std::string * keyToString (SG::sgkey_t key) const override
 Find the string corresponding to a given key.
const std::string * keyToString (SG::sgkey_t key, CLID &clid) const override
 Find the string and CLID corresponding to a given key.
void registerKey (SG::sgkey_t key, const std::string &str, CLID clid) override
 Remember an additional mapping from key to string/CLID.
SG::DataProxy * recordObject (SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
 Record an object in the store.
const std::string & name () const override
 Get the name of the instance.
Functions to be implemented by the derived types
virtual bool hasInput () const =0
 Check if an input file is connected to the object.
virtual bool hasOutput () const =0
 Check if an output file is connected to the 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.
virtual StatusCode connectObject (const std::string &key, bool silent)=0
 Function setting up access to a particular object.
virtual StatusCode connectMetaObject (const std::string &key, bool silent)=0
 Function setting up access to a particular metadata object.
virtual StatusCode connectAux (const std::string &prefix, bool standalone)=0
 Function setting up access to a set of auxiliary branches.
virtual StatusCode connectMetaAux (const std::string &prefix, bool standalone)=0
 Function setting up access to a set of auxiliary branches for a metadata object.
virtual StatusCode setAuxStore (const std::string &key, Details::IObjectManager &mgr, bool metadata)=0
 Function connecting a DV object to its auxiliary store.
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.
virtual StatusCode recordAux (TVirtualManager &mgr, const std::string &key, bool metadata)=0
 Record an auxiliary store into a connected output file.

Protected Attributes

Object_t m_inputObjects
 Collection of all the managed input objects.
std::set< std::string > m_inputMissingObjects
 Objects that have been asked for, but were found to be missing in the current input.
Object_t m_outputObjects
 Collection of all the managed output object.
Object_t m_inputMetaObjects
 Collection of all the managed input meta-objects.
Object_t m_outputMetaObjects
 Collection of all the managed output meta-objects.
EventFormat m_inputEventFormat
 Format of the current input file.
EventFormat * m_outputEventFormat = nullptr
 Format of the current output file.
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
 Rules for selecting which auxiliary branches to write.
std::vector< TVirtualIncidentListener * > m_listeners
 Listeners who should be notified when certain incidents happen.
std::unordered_map< std::string, std::string > m_nameRemapping
 Container name re-mapping rules.
bool m_printEventProxyWarnings = false
 Option to silence common warnings that seem to be harmless.

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.

Friends

class xAODPrivate::HolderBucket
class xAODPrivate::Loader

Variable(s) used in the @c IProxyDict implementation

using upgrade_mutex_t = AthContainers_detail::upgrade_mutex
 Mutex type for multithread synchronization.
using upgrading_lock_t
 Lock type for multithread synchronization.
upgrade_mutex_t m_branchesMutex
 Mutex for multithread synchronization.
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
 Map from hashed sgkey to BranchInfo.

Setup functions

static const char *const EVENT_TREE_NAME = "CollectionTree"
 Default name of the event TTree.
static const char *const EVENT_RNTUPLE_NAME = "EventData"
 Name of the event RNTuple.
static const char *const METADATA_OBJECT_NAME = "MetaData"
 Name of the metadata tree or RNTuple.
virtual StatusCode readFrom (TFile &inFile)=0
 Read from a new file - only needed for the second+ files.
virtual StatusCode writeTo (TFile &file)=0
 Connect the object to an output file.
virtual StatusCode finishWritingTo (TFile &file)=0
 Finish writing to an output file.
void setActive () const
 Set this event object as the currently active one.
void setAuxItemList (const std::string &containerKey, const std::string &itemList)
 Configure which dynamic variables to write out for a given store.
StatusCode addListener (TVirtualIncidentListener *listener)
 Register an incident listener object.
StatusCode removeListener (TVirtualIncidentListener *listener)
 Remove an incident listener object.
void clearListeners ()
 Remove all listeners from the object.
StatusCode addNameRemap (const std::string &onfile, const std::string &newName)
 Add a name re-mapping rule.
void clearNameRemap ()
 Clear the current name re-mapping.
void printNameRemap () const
 Print the current name re-mapping rules.
void printProxyWarnings (bool value=true)
 Enable warnings associated with broken element links.
static std::unique_ptr< Event > createAndReadFrom (TFile &file)
 static method to create an Event object and readFrom a file, given by a TFile.

Helper functions for the IProxyDict interface

EventContext m_ctx
 The event context associated with this event.
const xAOD::EventFormatElement * getEventFormatElement (SG::sgkey_t sgkey) const
 Get the metadata object for a given "SG key".
const BranchInfo * getBranchInfo (SG::sgkey_t sgkey) const
 Get the object describing one object/branch.

Functions implementing the @c xAOD::TVirtualEvent interface

SG::sgkey_t getHash (const std::string &key) const override
 Function returning the hash describing an object name.
SG::sgkey_t getKey (const void *obj) const override
 Function returning the hash describing a known object.
const std::string & getName (const void *obj) const override
 Function returning the key describing a known object.
const std::string & getName (SG::sgkey_t hash) const override
 Function returning the key 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.
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.

Detailed Description

Base class for the event (xAOD::TEvent and xAOD::REvent) classes.

It implements all the common functionality used by the different storage technologies. Leaving just the technology specific parts to the derived classes.

Definition at line 59 of file Event.h.

Member Typedef Documentation

◆ Object_t

using xAOD::Event::Object_t
protected
Initial value:
std::unordered_map<std::string, std::unique_ptr<TVirtualManager>>

Definition of the internal data structure type.

Definition at line 340 of file Event.h.

◆ sgkey_t

Definition at line 29 of file TVirtualEvent.h.

◆ upgrade_mutex_t

using xAOD::Event::upgrade_mutex_t = AthContainers_detail::upgrade_mutex
protected

Mutex type for multithread synchronization.

Definition at line 385 of file Event.h.

◆ upgrading_lock_t

Initial value:

Lock type for multithread synchronization.

Definition at line 387 of file Event.h.

Constructor & Destructor Documentation

◆ Event()

Event::Event ( std::string_view name,
const EventContext * ctx = nullptr )

Constructor with a name.

Parameters
nameName to use in printed messages

Definition at line 29 of file EventCore.cxx.

31 : TVirtualEvent(),
33 asg::AsgMessaging(std::string{name}) {
34
35 // Make sure that the I/O monitoring is active.
37
38 if (ctx) {
39#ifndef XAOD_STANDALONE
40 m_ctx = *ctx;
41#endif
42 }
43 else {
44 // Make this the active event.
45 this->setActive();
46 }
47}
const std::string & name() const override
Get the name of the instance.
EventContext m_ctx
The event context associated with this event.
Definition Event.h:410
void setActive() const
Set this event object as the currently active one.
Definition EventCore.cxx:65
static PerfStats & instance()
Function accessing the singleton instance.
implements< IProxyDict > IProxyDictBase
IProxyDict base class to use in a specific build environment
Definition Event.h:37

◆ ~Event()

Event::~Event ( )
virtual

Virtual destructor.

Definition at line 49 of file EventCore.cxx.

49 {
50
51 // If this is set up as the active event at the moment, notify
52 // the active event object that this object will no longer be
53 // available.
54 if (TActiveEvent::event() == this) {
56 }
57#ifndef XAOD_STANDALONE
59 SG::CurrentEventStore::setStore(nullptr);
61 }
62#endif // not XAOD_STANDALONE
63}
static void setEvent(TVirtualEvent *ptr)
Set the active event pointer.
static TVirtualEvent * event()
Access the currently active TVirtualEvent object.
void setProxyDictInEventContext(IProxyDict *sg)
Update the IProxyDict in the current EventContext.
IProxyDict * proxyDictFromEventContext()
Return the IProxyDict for this thread's current context.

Member Function Documentation

◆ addListener()

StatusCode Event::addListener ( TVirtualIncidentListener * listener)

Register an incident listener object.

This function works pretty much like IIncidentSvc::addListener does in Athena.

It tells the TEvent object that when certain "interesting incidents" happen, a given object should be notified about it.

Parameters
listenerPointer to the object that should be notified
Returns
The usual StatusCode types

Definition at line 109 of file EventCore.cxx.

109 {
110
111 // Check that we received a valid pointer:
112 if (listener == nullptr) {
113 ATH_MSG_ERROR("Received a null pointer for the listener");
114 return StatusCode::FAILURE;
115 }
116
117 // Check whether we already have this listener.
118 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
119 if (itr != m_listeners.end()) {
120 ATH_MSG_WARNING("Listener " << static_cast<void*>(listener)
121 << " is already registered");
122 return StatusCode::SUCCESS;
123 }
124
125 // Add the listener.
126 m_listeners.push_back(listener);
127
128 // Return gracefully:
129 return StatusCode::SUCCESS;
130}
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
std::vector< TVirtualIncidentListener * > m_listeners
Listeners who should be notified when certain incidents happen.
Definition Event.h:365

◆ addNameRemap()

StatusCode Event::addNameRemap ( const std::string & onfile,
const std::string & newName )

Add a name re-mapping rule.

The names of containers can change during the lifetime of the experiment.

One such change happened after the DC14 exercise, when many containers got a new name. (Like "ElectronCollection" became simply "Electrons".)

This function allows us to create aliases with which certain containers should be accessible. So that the analyser would be able to access older files, while using the latest container name(s).

Parameters
onfileThe name of the container as it was saved into the input file
newNameThe alias with which the object/container should be accessible
Returns
The usual StatusCode types

Save the new name association:

Definition at line 174 of file EventCore.cxx.

175 {
176
177 // Check if this name is known on the input or output already. As that's
178 // not good.
179 if (m_inputEventFormat.exists(newName)) {
180 ATH_MSG_ERROR("Can't use \"" << newName << "\" as the target name in the \""
181 << onfile << "\" -> \"" << newName
182 << "\" remapping");
183 return StatusCode::FAILURE;
184 }
185
186 // Check if this name was remapped to something already.
187 auto itr = m_nameRemapping.find(newName);
188 if (itr != m_nameRemapping.end()) {
189 ATH_MSG_WARNING("Overriding existing name remapping \""
190 << itr->second << "\" -> \"" << itr->first << "\" with: \""
191 << onfile << "\" -> \"" << newName << "\"");
192 }
193
195 m_nameRemapping[newName] = onfile;
196
197 // Return gracefully:
198 return StatusCode::SUCCESS;
199}
EventFormat m_inputEventFormat
Format of the current input file.
Definition Event.h:357
std::unordered_map< std::string, std::string > m_nameRemapping
Container name re-mapping rules.
Definition Event.h:368

◆ addToStore()

StatusCode Event::addToStore ( CLID clid,
SG::DataProxy * proxy )
overrideprotected

Add a new proxy to the store.

Smart pointers to objects that don't exist in the input event, can end up calling this function.

In this case warn the user that something fishy is happening, and take posession of the received proxy.

Parameters
clidThe CLID of the type. Not taken into account.
proxyThe proxy to take posession of. Not used for anything useful.

Definition at line 257 of file EventIProxyDict.cxx.

257 {
258
260
261 // Warn the user that the function got called:
262 static std::atomic_flag warningPrinted ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT;
263 if (!warningPrinted.test_and_set() && m_printEventProxyWarnings) {
265 "Function should only be called through an invalid ElementLink");
266 }
267
268 // Hold on to the proxy
269 BranchInfo bi;
270 bi.m_proxy.reset(proxy);
271 lock.upgrade();
272#ifdef XAOD_STANDALONE
273 std::string uniqueKey = std::format("NonExistentKey_{}", m_branches.size());
274 SG::sgkey_t sgkey = stringToKey(uniqueKey, clid);
275#else
276 SG::sgkey_t sgkey = proxy->sgkey();
277#endif
278 m_branches.emplace (sgkey, std::move(bi));
279
280 // Return gracefully:
281 return StatusCode::SUCCESS;
282}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
SG::sgkey_t stringToKey(const std::string &str, CLID clid) override
Find the string corresponding to a given key.
upgrade_mutex_t m_branchesMutex
Mutex for multithread synchronization.
Definition Event.h:390
bool m_printEventProxyWarnings
Option to silence common warnings that seem to be harmless.
Definition Event.h:371
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition Event.h:394
AthContainers_detail::upgrading_lock< upgrade_mutex_t > upgrading_lock_t
Lock type for multithread synchronization.
Definition Event.h:387
SG::DataProxy * proxy(const void *const pTransient) const override
get proxy for a given data object address in memory
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
sgkey(tool)
Definition common.py:1027
Helper struct used by the IProxyDict code.
Definition Event.h:377
std::unique_ptr< SG::DataProxy > m_proxy
Data proxy describing this branch/object.
Definition Event.h:379

◆ clearListeners()

void Event::clearListeners ( )

Remove all listeners from the object.

This function can be used to remove all the listeners from the internal list.

Should not be necessary under regular circumstances.

Definition at line 155 of file EventCore.cxx.

155 {
156
157 m_listeners.clear();
158}

◆ clearNameRemap()

void Event::clearNameRemap ( )

Clear the current name re-mapping.

This function simply clears out any existing name remapping declarations.

In case the remapping rules need to be changed in the code in some complicated way.

Definition at line 205 of file EventCore.cxx.

205 {
206
207 m_nameRemapping.clear();
208}

◆ connectAux()

virtual StatusCode xAOD::Event::connectAux ( const std::string & prefix,
bool standalone )
protectedpure virtual

Function setting up access to a set of auxiliary branches.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ connectMetaAux()

virtual StatusCode xAOD::Event::connectMetaAux ( const std::string & prefix,
bool standalone )
protectedpure virtual

Function setting up access to a set of auxiliary branches for a metadata object.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ connectMetaObject()

virtual StatusCode xAOD::Event::connectMetaObject ( const std::string & key,
bool silent )
protectedpure virtual

Function setting up access to a particular metadata object.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ connectObject()

virtual StatusCode xAOD::Event::connectObject ( const std::string & key,
bool silent )
protectedpure virtual

Function setting up access to a particular object.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ contains() [1/2]

template<typename T>
bool xAOD::Event::contains ( const std::string & key)

Function checking if an object is available from the store.

◆ contains() [2/2]

bool xAOD::Event::contains ( const std::string & key,
const std::type_info & ti,
bool metadata )
protected

Internal function checking if an object is in the input.

◆ containsMeta()

template<typename T>
bool xAOD::Event::containsMeta ( const std::string & key)

Function checking if a meta-object is available from the store.

◆ copy()

StatusCode Event::copy ( const std::string & pattern = ".*")

Copy an object directly from the input to the output.

This function can be used to easily copy a given (set of) object/container(s) to the output, without modifying the contents of it/them.

It only needs to be called on the interface object/container(s), the copying of the auxiliary data is done automatically, and is steered by the xAOD::Event::setAuxItemList function.

Parameters
patternRegular expression for the key(s)/name(s) of the object(s)/container(s) to copy

Definition at line 95 of file EventIO.cxx.

95 {
96
97 // Tell the user what's happening.
98 ATH_MSG_DEBUG("Copying objects matching pattern \"" << pattern
99 << "\" to the output");
100
101 // Collect a list of keys to copy.
102 std::set<std::string> keys;
103
104 // The regular expression to use.
105 std::regex re{pattern};
106
107 // Loop over the known input containers.
108 for (const auto& [key, efe] : m_inputEventFormat) {
109
110 // Tell the user what's happening.
111 ATH_MSG_VERBOSE("Considering input object with key \"" << key << "\"");
112
113 // Check if the class in question matches the requested pattern.
114 if (std::regex_match(key, re) == false) {
115 continue;
116 }
117 // Skip all branches ending in "Aux.":
118 if (key.ends_with("Aux.")) {
119 continue;
120 }
121 // Also skip dynamic branches:
122 if (efe.parentName() != "") {
123 continue;
124 }
125 // Ignore objects that don't exist on the input.
126 static const bool SILENT = true;
127 if (connectObject(key, SILENT).isSuccess() == false) {
128 continue;
129 }
130 // Add the key to the list.
131 ATH_MSG_VERBOSE("Matched key \"" << key << "\"");
132 keys.insert(key);
133 }
134
135 // Check if the pattern matches any of the name remapping rules.
136 for (const auto& [newname, onfile] : m_nameRemapping) {
137
138 // Tell the user what's happening.
139 ATH_MSG_VERBOSE("Considering remapped key \"" << newname << "\"");
140
141 // Check if the remapped name matches the pattern.
142 if (std::regex_match(newname, re) == false) {
143 continue;
144 }
145 // Ignore objects that don't exist on the input.
146 static const bool SILENT = true;
147 if (connectObject(onfile, SILENT).isSuccess() == false) {
148 continue;
149 }
150 // Add the remapped name to the list.
151 ATH_MSG_VERBOSE("Matched remapped key \"" << newname << "\"");
152 keys.insert(newname);
153 }
154
155 // Now loop over all of the found keys.
156 for (const std::string& key : keys) {
157
158 // Check if a name re-mapping should be applied or not.
159 std::string keyToUse = key;
160 auto remap_itr = m_nameRemapping.find(key);
161 if ((remap_itr != m_nameRemapping.end()) &&
162 (!m_inputEventFormat.exists(key)) &&
163 m_inputEventFormat.exists(remap_itr->second)) {
164 keyToUse = remap_itr->second;
165 }
166
167 // Make sure that the input object got connected to.
168 static const bool SILENT = false;
169 ATH_CHECK(connectObject(keyToUse, SILENT));
170
171 // Make sure that the input object is properly updated.
172 Object_t::const_iterator vobjMgr = m_inputObjects.find(keyToUse);
173 if (vobjMgr == m_inputObjects.end()) {
174 ATH_MSG_FATAL("Internal logic error detected");
175 return StatusCode::FAILURE;
176 }
177 Details::IObjectManager* objMgr =
178 dynamic_cast<Details::IObjectManager*>(vobjMgr->second.get());
179 if (objMgr == nullptr) {
180 ATH_MSG_FATAL("Internal logic error detected");
181 return StatusCode::FAILURE;
182 }
183 static const bool METADATA = false;
184 if (getInputObject(keyToUse, *(objMgr->holder()->getClass()->GetTypeInfo()),
185 SILENT, METADATA) == nullptr) {
186 ATH_MSG_FATAL("Internal logic error detected");
187 return StatusCode::FAILURE;
188 }
189
190 // Put the interface object into the output.
191 static const bool OVERWRITE = true;
192 static const bool IS_OWNER = true;
193 ATH_CHECK(record(objMgr->object(), objMgr->holder()->getClass()->GetName(),
194 key, OVERWRITE, METADATA, IS_OWNER));
195
196 // If there is also an auxiliary store for this object/container, copy that
197 // as well.
198 const std::string auxKey = keyToUse + "Aux.";
199 if (m_inputObjects.contains(auxKey)) {
200 ATH_CHECK(
201 recordAux(*(m_inputObjects.at(auxKey)), key + "Aux.", METADATA));
202 }
203 }
204
205 // Return gracefully:
206 return StatusCode::SUCCESS;
207}
const std::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_FATAL(x,...)
virtual StatusCode recordAux(TVirtualManager &mgr, const std::string &key, bool metadata)=0
Record an auxiliary store into a connected output file.
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.
virtual StatusCode connectObject(const std::string &key, bool silent)=0
Function setting up access to a particular object.
Object_t m_inputObjects
Collection of all the managed input objects.
Definition Event.h:344
StatusCode record(T *obj, const std::string &key)
Add an output object to the event.
StatusCode keys(std::vector< std::string > &vkeys, bool metadata) const
Provide a list of all data object keys associated with a specific type.
@ SILENT
don't print anything and return success
@ OVERWRITE
create the directory as is, removing existing directories if needed

◆ createAndReadFrom()

std::unique_ptr< Event > Event::createAndReadFrom ( TFile & inFile)
static

static method to create an Event object and readFrom a file, given by a TFile.

static method to get Event object for reading either TTree (TEvent) or RNTuple (REvent).

The the reader technology, TTree read by TEvent or RNTuple read by REvent, is determined by the looking into the file, given as a TFile object.

Here we access by TFile object

Definition at line 43 of file EventIO.cxx.

43 {
44
45 // Make use of the messaging function(s) from the xAODEvent namespace.
46 using xAODEvent::msg;
47
48 if (inFile.FindKey(EVENT_RNTUPLE_NAME) != nullptr) {
49 // Create and set up an REvent object
50 auto event = std::make_unique<Experimental::REvent>();
51 if (event->readFrom(inFile).isFailure()) {
52 ANA_MSG_ERROR("Could not read RNTuple from: " << inFile.GetName());
53 return {};
54 }
55 return event;
56 } else if (inFile.FindKey(EVENT_TREE_NAME) != nullptr) {
57 // Create and set up a TEvent object
58 // Check if file is AOD, in which case kAthenaAccess must be used
59 auto eauxMode = TEvent::kClassAccess;
60 std::string sauxMode = "kClassAccess";
61 auto metaData = dynamic_cast<TTree*>(inFile.Get("MetaData"));
62 if (metaData) {
63 auto rc = metaData->LoadTree(0);
64 if (rc < 0)[[unlikely]]{
65 ANA_MSG_ERROR("Error from LoadTree: "<< rc);
66 return {};
67 }
68 if (metaData->GetBranch("StreamAOD")) {
69 eauxMode = TEvent::kAthenaAccess;
70 sauxMode = "kAthenaAccess";
71 }
72 }
73 ANA_MSG_INFO("Using aux mode " << sauxMode << " for file " << inFile.GetName());
74 auto event = std::make_unique<TEvent>(eauxMode);
75 if (event->readFrom(inFile).isFailure()) {
76 ANA_MSG_ERROR("Could not read TTree from: " << inFile.GetName());
77 return {};
78 }
79 return event;
80 } else {
81 ANA_MSG_ERROR("Could not recognize file: " << inFile.GetName());
82 return {};
83 }
84}
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
static Double_t rc
static const char *const EVENT_TREE_NAME
Default name of the event TTree.
Definition Event.h:79
static const char *const EVENT_RNTUPLE_NAME
Name of the event RNTuple.
Definition Event.h:80
@ kAthenaAccess
Access containers/objects like Athena does.
@ kClassAccess
Access auxiliary data using the aux containers.
str inFile
Definition makeTOC.py:5
#define unlikely(x)

◆ currentContext()

const EventContext & Event::currentContext ( ) const
protected

Return the event context corresponding to this event.

(Returns a dummy in standalone builds.)

Definition at line 316 of file EventCore.cxx.

316 {
317#ifdef XAOD_STANDALONE
318 return Gaudi::Hive::currentContext();
319#else
320 return m_ctx;
321#endif
322}

◆ dump()

std::string Event::dump ( )

Function creating a user-readable dump of the current input.

This function behaves exactly like StoreGateSvc::dump().

It doesn't actually print anything to the screen, it just returns a user readable dump of the contents of the current input file/chain.

It is a pretty dumb implementation for the moment. Should be made nicer later on.

Returns
The user-readable contents of the current input file/chain

Definition at line 262 of file EventCore.cxx.

262 {
263
264 // The internal stream object.
265 std::ostringstream ost;
266 ost << "<<<<<<<<<<<<<<<<<<<< xAOD::TEvent Dump >>>>>>>>>>>>>>>>>>>>\n";
267
268 // Loop over the input EventFormat object.
269 for (const auto& [key, element] : m_inputEventFormat) {
270
271 // Get the type.
272 ::TClass* cl = ::TClass::GetClass(element.className().c_str());
273 const std::type_info* ti = (cl ? cl->GetTypeInfo() : nullptr);
274 if ((cl == nullptr) || (cl->IsLoaded() == false) || (ti == nullptr)) {
275 ATH_MSG_WARNING("Unknown type (" << element.className()
276 << ") found in the event format");
277 continue;
278 }
279
280 // Skip containers that are not available anyway.
281 static const bool METADATA = false;
282 if (!contains(element.branchName(), *ti, METADATA)) {
283 continue;
284 }
285
286 // Do the printout.
287 ost << " Hash: 0x" << std::setw(8) << std::setfill('0') << std::hex
288 << element.hash() << " Key: \"" << element.branchName() << "\"\n";
289
290 ost << " type: " << element.className() << "\n";
291 const bool isNonConst =
292 transientContains(element.branchName(), *ti, METADATA);
293 ost << " isConst: " << (isNonConst ? "No" : "Yes") << "\n";
294 static const bool SILENT = false;
295 ost << " Data: "
296 << (isNonConst
297 ? getOutputObject(element.branchName(), *ti, METADATA)
298 : getInputObject(element.branchName(), *ti, SILENT, METADATA))
299 << "\n";
300 }
301
302 // Finish with the construction:
303 ost << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
304 return ost.str();
305}
bool transientContains(const std::string &key) const
Function checking if an object is already in memory.
bool contains(const std::string &key)
Function checking if an object is available from the store.
void * getOutputObject(SG::sgkey_t key, const std::type_info &ti) override
Function for retrieving an output object in a non-template way.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ fill()

virtual::Int_t xAOD::Event::fill ( )
pure virtual

Method filling one event into the output tree.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ finishWritingTo()

virtual StatusCode xAOD::Event::finishWritingTo ( TFile & file)
pure virtual

Finish writing to an output file.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ getBranchInfo()

const Event::BranchInfo * Event::getBranchInfo ( SG::sgkey_t sgkey) const
protected

Get the object describing one object/branch.

Definition at line 356 of file EventIProxyDict.cxx.

356 {
357
358 {
359 // We can only hold the lock (even though it's a shared lock) for
360 // this limited scope because the call to getInputObject below
361 // leads to a recursion and dead-lock if not released immediately.
363
364 // If the object already exists, return it:
365 auto it = m_branches.find(sgkey);
366 if (it != m_branches.end()) {
367 return &(it->second);
368 }
369 }
370
371 // If not, construct it now:
372 BranchInfo bi;
373 const xAOD::EventFormatElement* efe = getEventFormatElement(sgkey);
374 if (!efe) {
375 // Apparently this key is not known:
376 return nullptr;
377 }
378
379 // Helper variable(s).
380 static const bool SILENT = true;
381 static const bool METADATA = false;
382
383 // The name of the requested object.
384 const std::string& name = getName(sgkey);
385 // This is a bit perverse... In order to let the "base class" figure
386 // out the exact type of this object, we ask for it with an "Event
387 // pointer". I use that type because I need something that has a
388 // dictionary, and which should always be available when this code
389 // runs. In the end it doesn't matter that the object can't be
390 // retrieved as that type (of course...), it only matters that it gets
391 // "set up" following these calls.
392 Event* nc_this = const_cast<Event*>(this);
393 static const std::type_info& dummy = typeid(Event);
394 nc_this->getInputObject(name, dummy, SILENT, METADATA);
395 auto itr = m_outputObjects.find(name);
396 if (itr == m_outputObjects.end()) {
397 itr = m_inputObjects.find(name);
398 if (itr == m_inputObjects.end()) {
399 // We didn't find this object in the store...
400 return nullptr;
401 }
402 }
403 const Details::IObjectManager* mgr =
404 dynamic_cast<const Details::IObjectManager*>(itr->second.get());
405 if (!mgr) {
406 ATH_MSG_ERROR("Internal logic error found");
407 return nullptr;
408 }
409 bi.m_class = mgr->holder()->getClass();
410 // There's no need to check whether this is a "proper" dictionary
411 // at this point, since if TEvent is holding on to it, the type
412 // must have a proper compiled dictionary.
413
414#ifndef XAOD_STANDALONE
415 // Create a proper proxy for the input branch:
416 auto taddr = std::make_unique<SG::TransientAddress>(
417 CLID_NULL, efe->branchName(), new GenericAddress());
418 taddr->setSGKey(sgkey);
420 *nc_this, getName(sgkey), *bi.m_class->GetTypeInfo());
421 bi.m_proxy = std::make_unique<SG::DataProxy>(std::move(taddr), loader);
422 loader->setProxy(*bi.m_proxy.get());
423#endif // not XAOD_STANDALONE
424
425 // Add the branch info to our list:
427 lock.upgrade();
428 auto ret = m_branches.insert(std::make_pair(sgkey, std::move(bi)));
429
430 // Return a pointer to the branch info:
431 return &(ret.first->second);
432}
void setProxy(SG::DataProxy &proxy)
const std::string & branchName() const
Get the branch/key name.
const std::string & getName(const void *obj) const override
Function returning the key describing a known object.
Event(std::string_view name, const EventContext *ctx=nullptr)
Constructor with a name.
Definition EventCore.cxx:29
friend class xAODPrivate::Loader
Definition Event.h:65
const xAOD::EventFormatElement * getEventFormatElement(SG::sgkey_t sgkey) const
Get the metadata object for a given "SG key".
Object_t m_outputObjects
Collection of all the managed output object.
Definition Event.h:349

◆ getEntries()

virtual::Long64_t xAOD::Event::getEntries ( ) const
pure virtual

Get how many entries are available from the current input file(s).

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ getEntry()

virtual::Int_t xAOD::Event::getEntry ( ::Long64_t entry,
::Int_t getall = 0 )
pure virtual

Function loading a given entry of the input TTree.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ getEventFormatElement()

const xAOD::EventFormatElement * Event::getEventFormatElement ( SG::sgkey_t sgkey) const
protected

Get the metadata object for a given "SG key".

Definition at line 330 of file EventIProxyDict.cxx.

331 {
332
333 const xAOD::EventFormatElement* efe = nullptr;
334 static const bool QUIET = true;
336 efe = m_outputEventFormat->get(sgkey, QUIET);
337 }
338 if (!efe) {
339 efe = m_inputEventFormat.get(sgkey, QUIET);
340 }
341 if (!efe) {
342 static SG::SGKeySet missingSGKeys ATLAS_THREAD_SAFE;
343 static mutex_t mutex;
344 guard_t lock(mutex);
345 if (missingSGKeys.emplace(sgkey).second) {
348 "Can't find EventFormatElement for hashed SG key: " << sgkey);
349 }
350 return 0;
351 }
352 }
353 return efe;
354}
AthContainers_detail::lock_guard< mutex_t > guard_t
Guard type for multithreaded synchronisation.
EventFormat * m_outputEventFormat
Format of the current output file.
Definition Event.h:359
std::unordered_set< sgkey_t > SGKeySet
A set of sgkey_t values.
Definition sgkey_t.h:97
AthContainers_detail::mutex mutex_t
Mutex used to synchronize modifications to the cache vector.

◆ getHash()

SG::sgkey_t Event::getHash ( const std::string & key) const
overridevirtual

Function returning the hash describing an object name.

This helper function is mostly needed by the smart pointers of the xAOD EDM.

Right now it very simply just calculates the hash just based on the key given to the function. But later on it might be good to do some tests here, checking if the event format knows about the specified key or not. This is why it's not made to be a static function

Parameters
keyString key to turn into a hash
Returns
A hash corresponding to the specified string key

Implements xAOD::TVirtualEvent.

Definition at line 27 of file EventTVirtualEvent.cxx.

27 {
28
29 // For empty keys let's finish quickly.
30 if (key == "") {
31 return 0;
32 }
33
34 // If the key is used in the input file, let's use the same hash for
35 // the output file as well.
36 static constexpr bool QUIET = true;
37 if (const EventFormatElement* efe = m_inputEventFormat.get(key, QUIET)) {
38 return efe->hash();
39 }
40
41 // If it's a new key, make a new hash for it from scratch:
42 return Utils::hash(key);
43}
SG::sgkey_t hash(const std::string &name)
This function provides a hashed version of the key (branch) names used in the xAOD file,...

◆ getInputObject() [1/2]

const void * Event::getInputObject ( const std::string & key,
const std::type_info & ti,
bool silent,
bool metadata )
protected

Function for retrieving an input object in a non-template way.

This is the function doing the heavy lifting to retrieve objects from the input file.

Parameters
keyThe key (branch name) of the object to retrieve
tiThe type as which the object is to be retrieved
silentSet to kTRUE to make the code fail silently in case the object can't be retrieved
metadataFlag deciding whether we're looking for a metadata or event data object
Returns
A pointer to the input object if successful, or a null pointer if not

Definition at line 281 of file EventIO.cxx.

283 {
284
285 // Check if a name remapping should be applied or not:
286 std::string keyToUse = key;
287 auto remap_itr = m_nameRemapping.find(key);
288 if ((remap_itr != m_nameRemapping.end()) &&
289 (!m_inputEventFormat.exists(key)) &&
290 m_inputEventFormat.exists(remap_itr->second)) {
291 keyToUse = remap_itr->second;
292 }
293
294 // The following catches the cases when we ask for a transient
295 // ConstDataVector object to be returned as "const DataVector".
296 const TStore* store = TActiveStore::store();
297 if (const THolder* holder = (store ? store->holder(keyToUse) : nullptr)) {
298 static constexpr bool SILENT = true;
299 const void* result = holder->getAsConst(ti, SILENT);
300 if (result && !holder->getAs(ti, SILENT)) {
301 return result;
302 }
303 }
304
305 // A sanity check before checking for an object from the input file.
306 if (hasInput() == false) {
307 if (silent == false) {
308 ATH_MSG_WARNING("No input file connected to the Event object");
309 }
310 return nullptr;
311 }
312
313 // Make sure that the requested input is connected to.
314 const StatusCode sc = (metadata ? connectMetaObject(keyToUse, silent)
315 : connectObject(keyToUse, silent));
316 if (sc.isSuccess() == false) {
317 return nullptr;
318 }
319
320 // Select which object container to use:
321 Object_t& objects = (metadata ? m_inputMetaObjects : m_inputObjects);
322
323 // Access the object's manager:
324 auto itr = objects.find(keyToUse);
325 if (itr == objects.end()) {
326 ATH_MSG_FATAL("There is an internal logic error in the code...");
327 return nullptr;
328 }
329
330 // This has to be an ObjectManager object:
331 Details::IObjectManager* mgr =
332 dynamic_cast<Details::IObjectManager*>(itr->second.get());
333 if (mgr == nullptr) {
334 if (key == keyToUse) {
335 ATH_MSG_ERROR("Object of wrong type found for key \"" << key << "\"");
336 } else {
337 ATH_MSG_ERROR("Object of wrong type found for key \""
338 << key << "\"/\"" << keyToUse << "\"");
339 }
340 return nullptr;
341 }
342
343 // Make sure that the current entry is loaded for event data objects.
344 if (metadata == false) {
345 const Int_t readBytes = mgr->getEntry();
346 if (readBytes > 0) {
347 // Connect the auxiliary store to objects needing it. This call also
348 // takes care of updating the dynamic store of auxiliary containers,
349 // when they are getting accessed directly.
350 static const bool IS_METADATA = false;
351 if (setAuxStore(key, *mgr, IS_METADATA).isSuccess() == false) {
352 ATH_MSG_ERROR("Failed to set the auxiliary store for "
353 << mgr->holder()->getClass()->GetName() << "/"
354 << keyToUse);
355 return nullptr;
356 }
357 } else if (readBytes < 0) {
358 ATH_MSG_ERROR("Failed to load current entry for object "
359 << mgr->holder()->getClass()->GetName() << "/" << keyToUse);
360 return nullptr;
361 }
362 }
363
364 // Ask the holder object for the object of this type:
365 const void* result = mgr->holder()->getAsConst(ti, silent);
366 if (result == nullptr) {
367 if (!silent) {
368 ATH_MSG_WARNING("Could not retrieve object with key \""
369 << keyToUse << "\" as \""
370 << SG::normalizedTypeinfoName(ti) << "\"");
371 }
372 return nullptr;
373 }
374
375 // We succeeded:
376 return result;
377}
static Double_t sc
if(pathvar)
virtual bool hasInput() const =0
Check if an input file is connected to the object.
std::unordered_map< std::string, std::unique_ptr< TVirtualManager > > Object_t
Definition of the internal data structure type.
Definition Event.h:340
virtual StatusCode connectMetaObject(const std::string &key, bool silent)=0
Function setting up access to a particular metadata object.
virtual StatusCode setAuxStore(const std::string &key, Details::IObjectManager &mgr, bool metadata)=0
Function connecting a DV object to its auxiliary store.
Object_t m_inputMetaObjects
Collection of all the managed input meta-objects.
Definition Event.h:352
static TStore * store()
Access the currently active TStore object.
::StatusCode StatusCode
StatusCode definition for legacy code.
TestStore store
Definition TestStore.cxx:23
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
silent(func)
Redirect stdout/err to /dev/null Useful wrapper to get rid of ROOT verbosity... N....

◆ getInputObject() [2/2]

const void * Event::getInputObject ( SG::sgkey_t key,
const std::type_info & ti,
bool silent )
overrideprotectedvirtual

Function for retrieving an input object in a non-template way.

This function is used by the TVirtualEvent interface to access an input object with a given hashed key.

The function looks up the string key belonging to the hash, and then calls the other GetInputObject(...) function in the class with that parameter.

Parameters
keyThe hashed key of the input object
tiThe type description of the object requested
silentSwitch for being silent about failures or not
Returns
A pointer to the requested object, or a null pointer in case of failure

Implements xAOD::TVirtualEvent.

Definition at line 165 of file EventTVirtualEvent.cxx.

166 {
167
168 // Get a string name for this key:
169 const std::string& name = getName(key);
170 if (name.empty() && (silent == false)) {
171 ATH_MSG_WARNING("Key 0x" << std::hex << key << " unknown");
172 return nullptr;
173 }
174
175 // Forward the call to the function using an std::string key:
176 static const bool METADATA = false;
177 return getInputObject(name, ti, silent, METADATA);
178}

◆ getKey()

SG::sgkey_t Event::getKey ( const void * obj) const
overridevirtual

Function returning the hash describing a known object.

This function is used by the smart pointer code to find the identifier of an object that's already in the event in some way.

Parameters
objPointer to the object that we want to look up
Returns
The hashed identifier of the object, or 0 if the object was not found in the event

Implements xAOD::TVirtualEvent.

Definition at line 52 of file EventTVirtualEvent.cxx.

52 {
53
54 // Make use of the getName function.
55 return getHash(getName(obj));
56}
SG::sgkey_t getHash(const std::string &key) const override
Function returning the hash describing an object name.

◆ getName() [1/2]

const std::string & Event::getName ( const void * obj) const
overridevirtual

Function returning the key describing a known object.

This function is used by the smart pointer code to find the identifier of an object that's already in the event in some way.

Parameters
objPointer to the object that we want to look up
Returns
The name of the object, or an empty string if the object was not found in the event

Implements xAOD::TVirtualEvent.

Definition at line 65 of file EventTVirtualEvent.cxx.

65 {
66
67 // Check the active TStore first, its pointer lookup is cheap.
68 const TStore* store = TActiveStore::store();
69 if (store && store->contains(obj)) {
70 return store->getName(obj);
71 }
72
73 // Then look among the output objects.
74 for (const auto& [key, manager] : m_outputObjects) {
75 // Check if this is our object.
76 if (manager->object() == obj) {
77 // If it is, let's return right away.
78 return key;
79 }
80 }
81
82 // Now look among the input objects.
83 for (const auto& [key, manager] : m_inputObjects) {
84 // Check if this is our object.
85 if (manager->object() == obj) {
86 // If it is, let's return.
87 return key;
88 }
89 }
90
91 // We didn't find the object in the event...
92 ATH_MSG_WARNING("Didn't find object with pointer \"" << obj
93 << "\" in the event");
94 static const std::string dummy;
95 return dummy;
96}

◆ getName() [2/2]

const std::string & Event::getName ( SG::sgkey_t hash) const
overridevirtual

Function returning the key describing a known object.

This function is used primarily when getting the string key of a smart pointer that we read in from a file, or access it in memory.

Parameters
hashThe hashed key for the container/object
Returns
The name of the object, or an empty string if the object was not found in the event

Implements xAOD::TVirtualEvent.

Definition at line 105 of file EventTVirtualEvent.cxx.

105 {
106
107 // If the branch is known from the input:
108 static constexpr bool QUIET = true;
109 if (const EventFormatElement* efe = m_inputEventFormat.get(hash, QUIET)) {
110 return efe->branchName();
111 }
112
113 // If the branch is known on the output:
114 if (const EventFormatElement* efe =
115 (m_outputEventFormat ? m_outputEventFormat->get(hash, QUIET)
116 : nullptr)) {
117 return efe->branchName();
118 }
119
120 // If this is an object in the active store:
121 const TStore* store = TActiveStore::store();
122 if (store && store->contains(hash)) {
123 return store->getName(hash);
124 }
125
126 // If it is unknown:
127 static const std::string dummy;
128 return dummy;
129}

◆ getNames()

virtual StatusCode xAOD::Event::getNames ( const std::string & targetClassName,
std::vector< std::string > & vkeys,
bool metadata = false ) const
protectedpure virtual

Function determining the list keys associated with a type name.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ getOutputObject() [1/2]

void * Event::getOutputObject ( const std::string & key,
const std::type_info & ti,
bool metadata ) const
protected

Function for retrieving an output object in a non-template way.

This function does the heavy lifting of retrieving object from the list of output objects.

While it returns a typeless pointer, that pointer can be cast directly to the type described by the second parameter in the caller code.

Parameters
keyThe key (branch name) of the object to retrieve
tiThe type as which the object is to be retrieved
metadataFlag deciding whether we're looking for a metadata or event data object
Returns
A pointer to the output object if successful, or a null pointer if not

Definition at line 221 of file EventIO.cxx.

222 {
223
224 // Select which object container to use:
226
227 // Check if the object can be found:
228 auto itr = objects.find(key);
229 if (itr == objects.end()) {
230 // Do the following only for event data:
231 if (!metadata) {
232 // It's not in the event. Let's check if we find it in an active
233 // TStore object. (getAs fails for const objects, and wrong types.)
234 const TStore* store = TActiveStore::store();
235 const THolder* holder = (store ? store->holder(key) : nullptr);
236 static constexpr bool SILENT = true;
237 return (holder ? holder->getAs(ti, SILENT) : nullptr);
238 } else {
239 // For metadata we don't use external resources.
240 return nullptr;
241 }
242 }
243
244 // If the object is not set in this event yet, we can't continue:
245 if (itr->second->isSet() == false) {
246 return nullptr;
247 }
248
249 // If it does exist, check if it's the right kind of object:
250 Details::IObjectManager* mgr =
251 dynamic_cast<Details::IObjectManager*>(itr->second.get());
252 if (mgr == nullptr) {
253 ATH_MSG_ERROR("Object of wrong type found for key \"" << key << "\"");
254 return nullptr;
255 }
256
257 // Ask the holder object for the object of this type:
258 void* result = mgr->holder()->getAs(ti);
259 if (result == nullptr) {
260 ATH_MSG_WARNING("Couldn't retrieve object as \""
261 << SG::normalizedTypeinfoName(ti) << "\"");
262 return nullptr;
263 }
264
265 // Return the object:
266 return result;
267}
Object_t m_outputMetaObjects
Collection of all the managed output meta-objects.
Definition Event.h:354

◆ getOutputObject() [2/2]

void * Event::getOutputObject ( SG::sgkey_t key,
const std::type_info & ti )
overrideprotectedvirtual

Function for retrieving an output object in a non-template way.

This function is used by the TVirtualEvent interface to access an output object with a given hashed key.

The function looks up the string key belonging to the hash, and then calls the other GetOutputObject(...) function in the class with that parameter.

Parameters
keyThe hashed key of the output object
tiThe type description of the object requested
Returns
A pointer to the requested object, or a null pointer in case of failure

Implements xAOD::TVirtualEvent.

Definition at line 141 of file EventTVirtualEvent.cxx.

141 {
142
143 // Get a string name for this key.
144 const std::string& name = getName(key);
145 if (name.empty()) {
146 return nullptr;
147 }
148
149 // Forward the call to the function using an std::string key.
150 static const bool METADATA = false;
151 return getOutputObject(name, ti, METADATA);
152}

◆ hasInput()

virtual bool xAOD::Event::hasInput ( ) const
protectedpure virtual

Check if an input file is connected to the object.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ hasOutput()

virtual bool xAOD::Event::hasOutput ( ) const
protectedpure virtual

Check if an output file is connected to the object.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)
int outputLevel(const IMessageSvc *ims, const std::string &source)

◆ inputEventFormat()

const EventFormat * Event::inputEventFormat ( ) const

Get information about the input objects.

Definition at line 240 of file EventCore.cxx.

240 {
241
242 if (hasInput()) {
243 return &m_inputEventFormat;
244 }
245 return nullptr;
246}

◆ keys()

template<typename T>
StatusCode xAOD::Event::keys ( std::vector< std::string > & vkeys,
bool metadata ) const

Provide a list of all data object keys associated with a specific type.

◆ keyToString() [1/2]

const std::string * Event::keyToString ( SG::sgkey_t key) const
overrideprotected

Find the string corresponding to a given key.

Definition at line 303 of file EventIProxyDict.cxx.

303 {
304
305 return &(getName(key));
306}

◆ keyToString() [2/2]

const std::string * Event::keyToString ( SG::sgkey_t key,
CLID & clid ) const
overrideprotected

Find the string and CLID corresponding to a given key.

Definition at line 308 of file EventIProxyDict.cxx.

308 {
309
310 return &(getName(key));
311}

◆ metaKeys()

template<typename T>
StatusCode xAOD::Event::metaKeys ( std::vector< std::string > & vkeys) const

Provide a list of all metadata object keys associated with a specific type.

◆ msg() [1/2]

MsgStream & asg::AsgMessaging::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 49 of file AsgMessaging.cxx.

49 {
50#ifndef XAOD_STANDALONE
51 return ::AthMessaging::msg();
52#else // not XAOD_STANDALONE
53 return m_msg;
54#endif // not XAOD_STANDALONE
55 }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 57 of file AsgMessaging.cxx.

57 {
58#ifndef XAOD_STANDALONE
59 return ::AthMessaging::msg( lvl );
60#else // not XAOD_STANDALONE
61 m_msg << lvl;
62 return m_msg;
63#endif // not XAOD_STANDALONE
64 }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 41 of file AsgMessaging.cxx.

41 {
42#ifndef XAOD_STANDALONE
43 return ::AthMessaging::msgLvl( lvl );
44#else // not XAOD_STANDALONE
45 return m_msg.msgLevel( lvl );
46#endif // not XAOD_STANDALONE
47 }

◆ name()

const std::string & Event::name ( ) const
overrideprotected

Get the name of the instance.

Definition at line 324 of file EventIProxyDict.cxx.

324 {
325
326 static const std::string result{"xAOD::Event"};
327 return result;
328}

◆ outputEventFormat()

const EventFormat * Event::outputEventFormat ( ) const

Get information about the output objects.

Definition at line 248 of file EventCore.cxx.

248 {
249
250 return m_outputEventFormat;
251}

◆ printIOStats()

void Event::printIOStats ( ) const

Function printing the I/O statistics of the current process.

This is a convenience function for printing basic I/O information about the current job.

It can be called at the end of a job to get an overview of what the job did exactly I/O-wise.

Definition at line 310 of file EventCore.cxx.

310 {
311
312 // Simply do this via the xAODCore code:
313 IOStats::instance().stats().Print("Summary");
314}
ReadStats & stats()
Access the object belonging to the current thread.
Definition IOStats.cxx:17
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
void Print(::Option_t *option="") const
Print information about the collected statistics.

◆ printNameRemap()

void Event::printNameRemap ( ) const

Print the current name re-mapping rules.

This function can be used for debugging, to check what container/object name remapping rules are in place for the current TEvent object.

Definition at line 213 of file EventCore.cxx.

213 {
214
215 // Print a header.
216 ATH_MSG_INFO("Name remapping rules:");
217
218 // In case no remapping rules have been set.
219 if (m_nameRemapping.empty()) {
220 ATH_MSG_INFO(" NONE");
221 return;
222 }
223
224 // Otherwise.
225 for (const auto& [newName, onfile] : m_nameRemapping) {
226 ATH_MSG_INFO(" \"" << newName << "\" -> \"" << onfile << "\"");
227 }
228}
#define ATH_MSG_INFO(x,...)

◆ printProxyWarnings()

void Event::printProxyWarnings ( bool value = true)

Enable warnings associated with broken element links.

These appear harmless so long as you don't actually try to access the links.

Which will cause other errors anyway.

Parameters
valueThe new value for the option

Definition at line 235 of file EventCore.cxx.

235 {
236
238}

◆ proxies()

std::vector< const SG::DataProxy * > Event::proxies ( ) const
overrideprotected

return the list of all current proxies in store

Definition at line 284 of file EventIProxyDict.cxx.

284 {
285
287
288 std::vector<const SG::DataProxy*> ret;
289 for (const auto& p : m_branches) {
290 const SG::DataProxy* proxy = p.second.m_proxy.get();
291 if (proxy) {
292 ret.push_back(proxy);
293 }
294 }
295 return ret;
296}

◆ proxy() [1/2]

SG::DataProxy * Event::proxy ( const CLID & id,
const std::string & key ) const
overrideprotected

get proxy with given id and key. Returns 0 to flag failure

Definition at line 219 of file EventIProxyDict.cxx.

219 {
220
221 const SG::sgkey_t sgkey = getHash(key);
222 if (!sgkey) {
223 return 0;
224 }
225 return proxy_exact(sgkey);
226}
SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override
Get proxy given a hashed key+clid.

◆ proxy() [2/2]

SG::DataProxy * Event::proxy ( const void *const pTransient) const
overrideprotected

get proxy for a given data object address in memory

Definition at line 191 of file EventIProxyDict.cxx.

191 {
192
193 // Look up the name of this object
194 std::string name = getName(pTransient);
195 if (name.empty()) {
196 // Apparently the object is not known...
197 return nullptr;
198 }
199
200 // Get the metadata object for it:
201 const xAOD::EventFormatElement* efe = 0;
202 static const bool QUIET = true;
204 efe = m_outputEventFormat->get(name, QUIET);
205 }
206 if (!efe) {
207 efe = m_inputEventFormat.get(name, QUIET);
208 }
209 if (!efe) {
210 // No metadata found...
211 return nullptr;
212 }
213
214 // Return the proxy:
215 const BranchInfo* bi = getBranchInfo(efe->hash());
216 return bi->m_proxy.get();
217}
sgkey_t hash() const
Get the hash belonging to this branch/key.
const BranchInfo * getBranchInfo(SG::sgkey_t sgkey) const
Get the object describing one object/branch.

◆ proxy_exact()

SG::DataProxy * Event::proxy_exact ( SG::sgkey_t sgkey) const
overrideprotected

Get proxy given a hashed key+clid.

Definition at line 228 of file EventIProxyDict.cxx.

228 {
229
230 // Get the object describing this branch/object:
231 const BranchInfo* bi = getBranchInfo(sgkey);
232 if (!bi) {
233 static SG::SGKeySet missingSGKeys ATLAS_THREAD_SAFE;
234 static mutex_t mutex;
235 guard_t lock(mutex);
236 if (missingSGKeys.emplace(sgkey).second && m_printEventProxyWarnings) {
237 ATH_MSG_WARNING("Can't find BranchInfo for: " << sgkey);
238 }
239 return 0;
240 }
241
242 // Access its data proxy:
243 SG::DataProxy* proxy = bi->m_proxy.get();
244
245 // Return the proxy:
246 return proxy;
247}

◆ readFrom()

virtual StatusCode xAOD::Event::readFrom ( TFile & inFile)
pure virtual

Read from a new file - only needed for the second+ files.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ record() [1/3]

template<typename T>
StatusCode xAOD::Event::record ( std::unique_ptr< T > obj,
const std::string & key )

Add an output object to the event, explicitly taking ownership of it.

◆ record() [2/3]

template<typename T>
StatusCode xAOD::Event::record ( T * obj,
const std::string & key )

Add an output object to the event.

◆ record() [3/3]

virtual StatusCode xAOD::Event::record ( void * obj,
const std::string & typeName,
const std::string & key,
bool overwrite,
bool metadata,
bool isOwner )
protectedpure virtual

Record an object into a connected output file.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ recordAux()

virtual StatusCode xAOD::Event::recordAux ( TVirtualManager & mgr,
const std::string & key,
bool metadata )
protectedpure virtual

Record an auxiliary store into a connected output file.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ recordMeta() [1/2]

template<typename T>
StatusCode xAOD::Event::recordMeta ( std::unique_ptr< T > obj,
const std::string & key )

Add an object to the output file's metadata, explicitly taking ownership of it.

◆ recordMeta() [2/2]

template<typename T>
StatusCode xAOD::Event::recordMeta ( T * obj,
const std::string & key )

Add an object to the output file's metadata.

◆ recordObject()

SG::DataProxy * Event::recordObject ( SG::DataObjectSharedPtr< DataObject > obj,
const std::string & key,
bool allowMods,
bool returnExisting )
overrideprotected

Record an object in the store.

Definition at line 318 of file EventIProxyDict.cxx.

319 {
320
321 throw std::runtime_error("xAOD::Event::recordObject is not implemented");
322}

◆ recordTypeless()

StatusCode xAOD::Event::recordTypeless ( void * obj,
const std::string & typeName,
const std::string & key,
bool overwrite = false,
bool metadata = true,
bool isOwner = true )
protected

Internal function for recording an object into the output.

◆ registerKey()

void Event::registerKey ( SG::sgkey_t key,
const std::string & str,
CLID clid )
overrideprotected

Remember an additional mapping from key to string/CLID.

Definition at line 313 of file EventIProxyDict.cxx.

313 {
314
315 return;
316}

◆ removeListener()

StatusCode Event::removeListener ( TVirtualIncidentListener * listener)

Remove an incident listener object.

This function allows us to remove a listener when for instance a metadata tool is deleted during a job.

Parameters
listenerPointer to the listener that should be removed
Returns
The usual StatusCode types

Definition at line 138 of file EventCore.cxx.

138 {
139
140 // Remove the listener. Or at least try to...
141 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
142 if (itr == m_listeners.end()) {
143 ATH_MSG_ERROR("Listener " << static_cast<void*>(listener) << " not known");
144 return StatusCode::FAILURE;
145 }
146 m_listeners.erase(itr);
147
148 // Return gracefully:
149 return StatusCode::SUCCESS;
150}

◆ retrieve() [1/4]

template<typename T>
StatusCode xAOD::Event::retrieve ( const T *& obj,
const std::string & key )

Retrieve either an input or an output object from the event.

◆ retrieve() [2/4]

template<typename T>
StatusCode xAOD::Event::retrieve ( T *& obj,
const std::string & key )

Retrieve an output object from the event.

◆ retrieve() [3/4]

template<typename T>
bool xAOD::TVirtualEvent::retrieve ( const T *& obj,
const std::string & key,
bool silent = false )
inherited

Function retrieving an object from the event (constant version).

◆ retrieve() [4/4]

template<typename T>
bool xAOD::TVirtualEvent::retrieve ( const T *& obj,
sgkey_t key = DEFAULT_KEY,
bool silent = false )
inherited

Function retrieving an object from the event (constant version).

◆ retrieveMetaInput()

template<typename T>
StatusCode xAOD::Event::retrieveMetaInput ( const T *& obj,
const std::string & key )

Retrieve an input metadata object.

◆ retrieveMetaOutput() [1/2]

template<typename T>
StatusCode xAOD::Event::retrieveMetaOutput ( const T *& obj,
const std::string & key )

Retrieve an output metadata object.

◆ retrieveMetaOutput() [2/2]

template<typename T>
StatusCode xAOD::Event::retrieveMetaOutput ( T *& obj,
const std::string & key )

Retrieve an output metadata object.

◆ setActive()

void Event::setActive ( ) const

Set this event object as the currently active one.

Definition at line 65 of file EventCore.cxx.

65 {
66
67 // The active event and current store are thread-local globals.
68 Event* nc_this ATLAS_THREAD_SAFE = const_cast<Event*>(this);
69 TActiveEvent::setEvent(static_cast<TVirtualEvent*>(nc_this));
70#ifndef XAOD_STANDALONE
71 SG::CurrentEventStore::setStore(nc_this);
73#endif // not XAOD_STANDALONE
74}

◆ setAuxItemList()

void Event::setAuxItemList ( const std::string & containerKey,
const std::string & itemList )

Configure which dynamic variables to write out for a given store.

This function receives the rules for selecting which dynamic auxiliary branches should be written for a given container, in the exact same format in which we need to set it in the Athena output ItemList.

Parameters
containerKeyThe name of the auxiliary container in question
itemListThe variable list according to the formatting rules

Definition at line 83 of file EventCore.cxx.

84 {
85
86 // Decoded attributes.
87 std::set<std::string> attributes;
88
89 // Split up the received string using "." as the separator.
90 if (itemList.size()) {
91 std::istringstream ss(itemList);
92 std::string attr;
93 while (std::getline(ss, attr, '.')) {
94 attributes.insert(attr);
95 }
96 }
97
98 // Remember the setting.
99 m_auxItemList[containerKey] = std::move(attributes);
100}
static Double_t ss
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition Event.h:362

◆ setAuxStore()

virtual StatusCode xAOD::Event::setAuxStore ( const std::string & key,
Details::IObjectManager & mgr,
bool metadata )
protectedpure virtual

Function connecting a DV object to its auxiliary store.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

◆ stringToKey()

SG::sgkey_t Event::stringToKey ( const std::string & str,
CLID clid )
overrideprotected

Find the string corresponding to a given key.

Definition at line 298 of file EventIProxyDict.cxx.

298 {
299
300 return getHash(str);
301}

◆ transientContains() [1/2]

template<typename T>
bool xAOD::Event::transientContains ( const std::string & key) const

Function checking if an object is already in memory.

◆ transientContains() [2/2]

bool xAOD::Event::transientContains ( const std::string & key,
const std::type_info & ti,
bool metadata ) const
protected

Internal function checking if an object is already in memory.

◆ transientContainsMeta()

template<typename T>
bool xAOD::Event::transientContainsMeta ( const std::string & key) const

Function checking if a meta-object is already in memory.

◆ writeTo()

virtual StatusCode xAOD::Event::writeTo ( TFile & file)
pure virtual

Connect the object to an output file.

Implemented in xAOD::Experimental::REvent, and xAOD::TEvent.

◆ xAODPrivate::HolderBucket

friend class xAODPrivate::HolderBucket
friend

Definition at line 64 of file Event.h.

◆ xAODPrivate::Loader

friend class xAODPrivate::Loader
friend

Definition at line 65 of file Event.h.

Member Data Documentation

◆ ATLAS_THREAD_SAFE

SG::SGKeyMap<BranchInfo> m_branches xAOD::Event::ATLAS_THREAD_SAFE
mutableprotected

Map from hashed sgkey to BranchInfo.

Definition at line 394 of file Event.h.

◆ DEFAULT_KEY

sgkey_t xAOD::TVirtualEvent::DEFAULT_KEY = ~static_cast<sgkey_t>(0)
staticconstexprinherited

Key for retrieving the "default" object of a given type.

Definition at line 35 of file TVirtualEvent.h.

◆ EVENT_RNTUPLE_NAME

const char *const Event::EVENT_RNTUPLE_NAME = "EventData"
static

Name of the event RNTuple.

Definition at line 80 of file Event.h.

◆ EVENT_TREE_NAME

const char *const Event::EVENT_TREE_NAME = "CollectionTree"
static

Default name of the event TTree.

Name of the event TTree.

Definition at line 79 of file Event.h.

◆ KEY_MASK

sgkey_t xAOD::TVirtualEvent::KEY_MASK = DEFAULT_KEY >> 2
staticconstexprinherited

Mask for the keys, used mostly internally.

Definition at line 37 of file TVirtualEvent.h.

◆ m_auxItemList

std::unordered_map<std::string, std::set<std::string> > xAOD::Event::m_auxItemList
protected

Rules for selecting which auxiliary branches to write.

Definition at line 362 of file Event.h.

◆ m_branchesMutex

upgrade_mutex_t xAOD::Event::m_branchesMutex
mutableprotected

Mutex for multithread synchronization.

Definition at line 390 of file Event.h.

◆ m_ctx

EventContext xAOD::Event::m_ctx
protected

The event context associated with this event.

Definition at line 410 of file Event.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_inputEventFormat

EventFormat xAOD::Event::m_inputEventFormat
protected

Format of the current input file.

Definition at line 357 of file Event.h.

◆ m_inputMetaObjects

Object_t xAOD::Event::m_inputMetaObjects
protected

Collection of all the managed input meta-objects.

Definition at line 352 of file Event.h.

◆ m_inputMissingObjects

std::set<std::string> xAOD::Event::m_inputMissingObjects
protected

Objects that have been asked for, but were found to be missing in the current input.

Definition at line 347 of file Event.h.

◆ m_inputObjects

Object_t xAOD::Event::m_inputObjects
protected

Collection of all the managed input objects.

Definition at line 344 of file Event.h.

◆ m_listeners

std::vector<TVirtualIncidentListener*> xAOD::Event::m_listeners
protected

Listeners who should be notified when certain incidents happen.

Definition at line 365 of file Event.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nameRemapping

std::unordered_map<std::string, std::string> xAOD::Event::m_nameRemapping
protected

Container name re-mapping rules.

Definition at line 368 of file Event.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_outputEventFormat

EventFormat* xAOD::Event::m_outputEventFormat = nullptr
protected

Format of the current output file.

Definition at line 359 of file Event.h.

◆ m_outputMetaObjects

Object_t xAOD::Event::m_outputMetaObjects
protected

Collection of all the managed output meta-objects.

Definition at line 354 of file Event.h.

◆ m_outputObjects

Object_t xAOD::Event::m_outputObjects
protected

Collection of all the managed output object.

Definition at line 349 of file Event.h.

◆ m_printEventProxyWarnings

bool xAOD::Event::m_printEventProxyWarnings = false
protected

Option to silence common warnings that seem to be harmless.

Definition at line 371 of file Event.h.

◆ METADATA_OBJECT_NAME

const char *const Event::METADATA_OBJECT_NAME = "MetaData"
static

Name of the metadata tree or RNTuple.

Definition at line 81 of file Event.h.


The documentation for this class was generated from the following files: