ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::TPyEvent Class Reference

Python interface to xAOD::TEvent. More...

#include <TPyEvent.h>

Inheritance diagram for xAOD::TPyEvent:
Collaboration diagram for xAOD::TPyEvent:

Public Types

enum  EAuxMode { kBranchAccess = 0 , kClassAccess = 1 , kAthenaAccess = 2 }
 Auxiliary store "mode". More...
using sgkey_t = SG::sgkey_t

Public Member Functions

 TPyEvent (EAuxMode mode=kClassAccess)
 Constructor with an access mode.
PyObject * pyRetrieve (const std::string &key)
 Return the object with a given key as a PyObject.
bool pyContains (const std::string &key, const std::string &type)
 Function checking if an object is available from the store.
bool pyTransientContains (const std::string &key, const std::string &type) const
 Function checking if an object is already in memory.
StatusCode pyRecord (void *obj, const std::string &key, const std::string &type)
 Add an output object to the event.
void setOtherMetaDataTreeNamePattern (const std::string &pattern)
 Change the pattern used for collecting information from other MetaData trees NB: Additional MetaData trees are only expected for augmented files This function also allows user to redefine MetaData tree pattern to skip trees that would not be proper MetaData ones i.e.
EAuxMode auxMode () const
 Get what auxiliary access mode the object was constructed with.
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.
Setup functions
StatusCode readFrom (::TFile &inFile) override
 Set up the reading of an input file from TFile This method implements the interface from Event.
StatusCode readFrom (::TFile *file, bool useTreeCache=true, std::string_view treeName=EVENT_TREE_NAME)
 This is the 'native' interface for reading from a TFile, allowing the specification of TTree cache use and the event tree name.
StatusCode readFrom (::TTree *tree, bool useTreeCache=true)
 Connect the object to a new input tree/chain.
StatusCode writeTo (TFile &file) override
 Connect the object to an output file.
StatusCode writeTo (::TFile *file, int autoFlush=200, std::string_view treeName=EVENT_TREE_NAME)
 Connect the object to an output file.
StatusCode finishWritingTo (TFile &file) override
 Finish writing to an output file.
StatusCode finishWritingTo (::TFile *file)
 Finish writing to an output file.
Event data accessor/modifier functions
SG::IAuxStore * recordAux (const std::string &key, SG::IAuxStoreHolder::AuxStoreType type=SG::IAuxStoreHolder::AST_ContainerStore)
 Add an auxiliary store object to the output.
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.
Persistent data accessor/modifier functions
::Long64_t getEntries () const override
 Get how many entries are available from the current input file(s).
::Int_t getEntry (::Long64_t entry, ::Int_t getall=0) override
 Function loading a given entry of the input TTree.
::Long64_t getFiles () const
 Get how many files are available on the currently defined input.
::Int_t getFile (::Long64_t file, ::Int_t getall=0)
 Load the first event for a given file from the input TChain.
::Int_t fill () override
 Function filling one event into the output tree.
Persistent data accessor/modifier functions
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.
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 recordAux (TAuxStore *store, const std::string &key)
 Function setting up an existing auxiliary store for writing.
StatusCode record (std::unique_ptr< TAuxStore > store, const std::string &key)
 Internal function for adding an auxiliary store object to the output.
StatusCode initStats ()
 Function to initialise the statistics for all Tree content.
StatusCode setUpDynamicStore (TObjectManager &mgr, ::TTree *tree)
 Function adding dynamic variable reading capabilities to an auxiliary store object.
StatusCode putAux (::TTree &outTree, TVirtualManager &mgr, bool metadata)
 Function saving the dynamically created auxiliary properties.
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.
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.
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.
const EventContext & currentContext () const
 Return the event context corresponding to this event.
Functions implemented from @c xAOD::Event
StatusCode recordAux (TVirtualManager &mgr, const std::string &key, bool metadata) override
 Record an auxiliary store into a connected output file.
bool hasInput () const override
 Check if an input file is connected to the object.
bool hasOutput () const override
 Check if an output file is connected to the object.
StatusCode getNames (const std::string &targetClassName, std::vector< std::string > &vkeys, bool metadata) const override
 Function determining the list keys associated with a type name.
StatusCode connectObject (const std::string &key, bool silent) override
 Function setting up access to a particular object.
StatusCode connectMetaObject (const std::string &key, bool silent) override
 Function setting up access to a particular metadata object.
StatusCode connectAux (const std::string &prefix, bool standalone) override
 Function setting up access to a set of auxiliary branches.
StatusCode connectMetaAux (const std::string &prefix, bool standalone) override
 Function setting up access to a set of auxiliary branches for a metadata object.
StatusCode setAuxStore (const std::string &key, Details::IObjectManager &mgr, bool metadata) override
 Function connecting a DV object to its auxiliary store.
StatusCode record (void *obj, const std::string &typeName, const std::string &key, bool overwrite, bool metadata, bool isOwner) override
 Record an object into a connected output file.
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.

Protected Attributes

EAuxMode m_auxMode
 The auxiliary access mode.
::TTree * m_inTree = nullptr
 The main tree that we are reading from.
bool m_inTreeMissing = false
 Internal status flag showing that an input file is open, but it doesn't contain an event tree.
::TChain * m_inChain = nullptr
 The (optional) chain provided as input.
std::unique_ptr< TChainStateTracker > m_inChainTracker
 Optional object for tracking the state changes of an input TChain.
::Int_t m_inTreeNumber = -1
 The number of the currently open tree in the input chain.
::TTree * m_inMetaTree = nullptr
 Pointer to the metadata tree in the input file.
::Long64_t m_entry = -1
 The entry to look at from the input tree.
std::unique_ptr<::TTree > m_outTree
 The tree that we are writing to.
std::regex m_otherMetaDataTreeNamePattern
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

friend::TTree * MakeTransientTree (TEvent &, const char *)
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.

Setup functions

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 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.
static std::unique_ptr< Event > createAndReadFrom (TFile &file)
 static method to create an Event object and readFrom a file, given by a TFile.

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.

Variable(s) used in the @c IProxyDict implementation

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

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.

Detailed Description

Python interface to xAOD::TEvent.

In order to make it possible to record objects that are created in Python, into an xAOD::TEvent object (in order to record selected objects into an output file for instance), this class extends the xAOD::TEvent object with some non-template functions. Functions that are inconvenient to use from C++, but which allow for much more flexibility in PyROOT.

Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 29 of file TPyEvent.h.

Member Typedef Documentation

◆ Object_t

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

Definition of the internal data structure type.

Definition at line 338 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
protectedinherited

Mutex type for multithread synchronization.

Definition at line 383 of file Event.h.

◆ upgrading_lock_t

using xAOD::Event::upgrading_lock_t
protectedinherited
Initial value:

Lock type for multithread synchronization.

Definition at line 385 of file Event.h.

Member Enumeration Documentation

◆ EAuxMode

enum xAOD::TEvent::EAuxMode
inherited

Auxiliary store "mode".

Enumerator
kBranchAccess 

Access auxiliary data branch-by-branch.

kClassAccess 

Access auxiliary data using the aux containers.

kAthenaAccess 

Access containers/objects like Athena does.

Definition at line 71 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

71 {
72 kBranchAccess = 0,
73 kClassAccess = 1,
74 kAthenaAccess = 2
75 };
@ kAthenaAccess
Access containers/objects like Athena does.
@ kClassAccess
Access auxiliary data using the aux containers.
@ kBranchAccess
Access auxiliary data branch-by-branch.

Constructor & Destructor Documentation

◆ TPyEvent()

xAOD::TPyEvent::TPyEvent ( EAuxMode mode = kClassAccess)

Constructor with an access mode.

It has to be implemented explicitly, as PyROOT is having some issues with callin non-default constructors inherited from the base class.

Definition at line 18 of file TPyEvent.cxx.

18: TEvent(mode) {}
TEvent(EAuxMode mode=kClassAccess)
Default constructor.

Member Function Documentation

◆ addListener()

StatusCode Event::addListener ( TVirtualIncidentListener * listener)
inherited

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 101 of file EventCore.cxx.

101 {
102
103 // Check that we received a valid pointer:
104 if (listener == nullptr) {
105 ATH_MSG_ERROR("Received a null pointer for the listener");
106 return StatusCode::FAILURE;
107 }
108
109 // Check whether we already have this listener.
110 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
111 if (itr != m_listeners.end()) {
112 ATH_MSG_WARNING("Listener " << static_cast<void*>(listener)
113 << " is already registered");
114 return StatusCode::SUCCESS;
115 }
116
117 // Add the listener.
118 m_listeners.push_back(listener);
119
120 // Return gracefully:
121 return StatusCode::SUCCESS;
122}
#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:363

◆ addNameRemap()

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

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 166 of file EventCore.cxx.

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

◆ addToStore()

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

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:388
bool m_printEventProxyWarnings
Option to silence common warnings that seem to be harmless.
Definition Event.h:369
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition Event.h:392
AthContainers_detail::upgrading_lock< upgrade_mutex_t > upgrading_lock_t
Lock type for multithread synchronization.
Definition Event.h:385
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:375
std::unique_ptr< SG::DataProxy > m_proxy
Data proxy describing this branch/object.
Definition Event.h:377

◆ auxMode()

TEvent::EAuxMode xAOD::TEvent::auxMode ( ) const
inherited

Get what auxiliary access mode the object was constructed with.

Returns
The auxiliary data access mode currently in use

Definition at line 103 of file Control/xAODRootAccess/Root/TEvent.cxx.

103{ return m_auxMode; }
EAuxMode m_auxMode
The auxiliary access mode.

◆ clearListeners()

void Event::clearListeners ( )
inherited

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 147 of file EventCore.cxx.

147 {
148
149 m_listeners.clear();
150}

◆ clearNameRemap()

void Event::clearNameRemap ( )
inherited

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 197 of file EventCore.cxx.

197 {
198
199 m_nameRemapping.clear();
200}

◆ connectAux()

StatusCode xAOD::TEvent::connectAux ( const std::string & prefix,
bool standalone )
overrideprotectedvirtualinherited

Function setting up access to a set of auxiliary branches.

This function is used internally to connect an auxiliary object to the input.

Based on the configuration of the object it will either use TAuxStore, or the EDM object that was used to write the auxiliary information in Athena.

Parameters
prefixThe prefix (main branch name) of the auxiliary data
standaloneType of the auxiliary store that should be created
Returns
The usual StatusCode types

Implements xAOD::Event.

Definition at line 1362 of file Control/xAODRootAccess/Root/TEvent.cxx.

1362 {
1363
1364 // A simple test...
1365 if (hasInput() == false) {
1366 ATH_MSG_ERROR("No input tree is available");
1367 return StatusCode::FAILURE;
1368 }
1369
1370 // Check if we know anything about this auxiliary object:
1371 if ((!m_inTree->GetBranch(prefix.c_str())) &&
1373 // If not, then let's just return right away. Not having
1374 // an auxiliary object with this name is not an error per se.
1375 return StatusCode::SUCCESS;
1376 }
1377
1378 // Check if the branch is already connected.
1379 if (m_inputObjects.contains(prefix)) {
1380 return StatusCode::SUCCESS;
1381 }
1382
1383 // Do different things based on the "auxiliary mode" we are in.
1384 if ((m_auxMode == kClassAccess) || (m_auxMode == kAthenaAccess)) {
1385
1386 // In "class" and "athena" access modes just connect the concrete auxiliary
1387 // object to the input.
1388 static constexpr bool SILENT = false;
1389 ATH_CHECK(connectObject(prefix, SILENT));
1390
1391 // Return gracefully.
1392 return StatusCode::SUCCESS;
1393
1394 } else if (m_auxMode == kBranchAccess) {
1395
1396 // In "branch access mode" let's create a TAuxStore object, and let
1397 // that take care of the auxiliary store access.
1398 static constexpr bool TOP_STORE = true;
1399 auto store = std::make_unique<TAuxStore>(
1400 this->currentContext(),
1401 prefix, TOP_STORE,
1404
1405 // Connect it to the input tree.
1406 ATH_CHECK(store->readFrom(*m_inTree));
1407
1408 // We're using this object to read from the input, it needs to be
1409 // locked:
1410 store->lock();
1411
1412 // Finally, set up an appropriate manager for it.
1413 static constexpr bool IS_OWNER = true;
1415 std::make_unique<TAuxManager>(store.release(), IS_OWNER);
1416
1417 // Return gracefully:
1418 return StatusCode::SUCCESS;
1419 }
1420
1421 // There was some problem:
1422 ATH_MSG_ERROR("Unknown auxiliary access mode set (" << m_auxMode << ")");
1423 return StatusCode::FAILURE;
1424}
#define ATH_CHECK
Evaluate an expression and check for errors.
Object_t m_inputObjects
Collection of all the managed input objects.
Definition Event.h:342
const EventContext & currentContext() const
Return the event context corresponding to this event.
StatusCode connectObject(const std::string &key, bool silent) override
Function setting up access to a particular object.
bool hasInput() const override
Check if an input file is connected to the object.
::TTree * m_inTree
The main tree that we are reading from.
@ kObjectStore
The object describes a single object.
@ kContainerStore
The object describes an entire container.
@ SILENT
don't print anything and return success
TestStore store
Definition TestStore.cxx:23

◆ connectMetaAux()

StatusCode xAOD::TEvent::connectMetaAux ( const std::string & prefix,
bool standalone )
overrideprotectedvirtualinherited

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

This function is used internally to connect an auxiliary metadata object to the input.

Based on the configuration of the object it will either use TAuxStore, or the EDM object that was used to write the auxiliary information in Athena.

Parameters
prefixThe prefix (main branch name) of the auxiliary data
standaloneType of the auxiliary store that should be created
Returns
The usual StatusCode types

Implements xAOD::Event.

Definition at line 1435 of file Control/xAODRootAccess/Root/TEvent.cxx.

1435 {
1436
1437 // Check if the branch is already connected:
1438 if (m_inputMetaObjects.contains(prefix)) {
1439 return StatusCode::SUCCESS;
1440 }
1441
1442 // A sanity check:
1443 if (!m_inMetaTree) {
1444 ATH_MSG_FATAL("Internal logic error detected");
1445 return StatusCode::FAILURE;
1446 }
1447
1448 // Do different things based on the "auxiliary mode" we are in:
1450
1451 // In "class" and "athena" access modes just connect the concrete auxiliary
1452 // object to the input.
1453 static constexpr bool SILENT = false;
1454 ATH_CHECK(connectMetaObject(prefix, SILENT));
1455
1456 // Return gracefully:
1457 return StatusCode::SUCCESS;
1458
1459 } else if (m_auxMode == kBranchAccess) {
1460
1461 // In "branch access mode" let's create a TAuxStore object, and let
1462 // that take care of the auxiliary store access.
1463 static constexpr bool TOP_STORE = true;
1464 auto store = std::make_unique<TAuxStore>(
1465 this->currentContext(),
1466 prefix, TOP_STORE,
1469
1470 // Connect it to the input tree.
1471 ATH_CHECK(store->readFrom(*m_inMetaTree));
1472
1473 // We're using this object to read from the input, it needs to be
1474 // locked:
1475 store->lock();
1476
1477 // Finally, set up an appropriate manager for it.
1478 static constexpr bool IS_OWNER = true;
1480 std::make_unique<TAuxManager>(store.release(), IS_OWNER);
1481
1482 // Return gracefully.
1483 return StatusCode::SUCCESS;
1484 }
1485
1486 // There was some problem:
1487 ATH_MSG_ERROR("Unknown auxiliary access mode set (" << m_auxMode << ")");
1488 return StatusCode::FAILURE;
1489}
#define ATH_MSG_FATAL(x,...)
Object_t m_inputMetaObjects
Collection of all the managed input meta-objects.
Definition Event.h:350
::TTree * m_inMetaTree
Pointer to the metadata tree in the input file.
StatusCode connectMetaObject(const std::string &key, bool silent) override
Function setting up access to a particular metadata object.

◆ connectMetaObject()

StatusCode xAOD::TEvent::connectMetaObject ( const std::string & key,
bool silent )
overrideprotectedvirtualinherited

Function setting up access to a particular metadata object.

This is the function doing the heavy lifting with creating metadata objects in memory out of the payload of the input file.

Parameters
keyThe key (branch name) of the metadata object to retrieve
silentSet to kTRUE to make the code fail silently in case the branch can't be connected to
Returns
The usual StatusCode types

Implements xAOD::Event.

Definition at line 1261 of file Control/xAODRootAccess/Root/TEvent.cxx.

1261 {
1262
1263 // A little sanity check:
1264 if (!m_inMetaTree) {
1265 ATH_MSG_ERROR("Function called on un-initialised object");
1266 return StatusCode::FAILURE;
1267 }
1268
1269 // Check if the branch is already connected:
1270 if (m_inputMetaObjects.contains(key)) {
1271 return StatusCode::SUCCESS;
1272 }
1273
1274 // Check if the branch exists in our metadata tree:
1275 ::TBranch* br = m_inMetaTree->GetBranch(key.c_str());
1276 if (br == nullptr) {
1277 if (silent == false) {
1278 ATH_MSG_WARNING("Metadata branch \"" << key
1279 << "\" not available on input");
1280 }
1281 return StatusCode::RECOVERABLE;
1282 }
1283
1284 // Check that we have an entry in the branch:
1285 if (br->GetEntries() == 0) {
1286 if (silent == false) {
1287 ATH_MSG_WARNING("Metadata branch \"" << key
1288 << "\" doesn't hold any data");
1289 }
1290 return StatusCode::RECOVERABLE;
1291 }
1292
1293 // Make sure that it's not in "MakeClass mode":
1294 br->SetMakeClass(0);
1295
1296 // Extract the type of the branch:
1297 ::TClass* cl = 0;
1298 ::EDataType dt = kOther_t;
1299 if (br->GetExpectedType(cl, dt) || (!cl)) {
1300 ATH_MSG_ERROR("Couldn't get the type for metadata branch \"" << key
1301 << "\"");
1302 return StatusCode::FAILURE;
1303 }
1304
1305 // Create the object, and all of the managers around it:
1306 void* ptr = cl->New();
1307 const bool renewOnRead = (m_auxMode == kAthenaAccess);
1308 auto mgr = std::make_unique<TObjectManager>(
1309 nullptr, std::make_unique<THolder>(ptr, cl), renewOnRead);
1310
1311 // Now try to connect to the branch:
1312 const ::Int_t status = m_inMetaTree->SetBranchAddress(
1313 key.c_str(), mgr->holder()->getPtr(), mgr->branchPtr(), cl, dt, kTRUE);
1314 if (status < 0) {
1315 ATH_MSG_ERROR("Couldn't connect variable of type \""
1316 << cl->GetName() << "\" to input branch \"" << key
1317 << "\". Return code: " << status);
1318 // Clean up:
1319 *(mgr->holder()->getPtr()) = 0;
1320 m_inputMetaObjects.erase(key);
1321 return StatusCode::FAILURE;
1322 }
1323
1324 // Store the manager.
1325 TObjectManager *mgrPtr = mgr.get();
1326 m_inputMetaObjects[key] = std::move(mgr);
1327
1328 // Read in the object:
1329 if (mgrPtr->getEntry() < 0) {
1330 ATH_MSG_ERROR("Couldn't read in metadata object with key \"" << key
1331 << "\"");
1332 return StatusCode::FAILURE;
1333 }
1334
1335 // If it's an auxiliary store object, set it up correctly:
1336 if (Details::isAuxStore(*(mgrPtr->holder()->getClass()))) {
1338 }
1339
1340 // If there may be an auxiliary object connected to this one,
1341 // connect that as well.
1342 if (Details::hasAuxStore(*(mgrPtr->holder()->getClass()))) {
1344 key + "Aux.", Details::isStandalone(*(mgrPtr->holder()->getClass()))));
1345 static constexpr bool METADATA = true;
1346 ATH_CHECK(setAuxStore(key, *mgrPtr, METADATA));
1347 }
1348
1349 // We succeeded:
1350 return StatusCode::SUCCESS;
1351}
StatusCode connectMetaAux(const std::string &prefix, bool standalone) override
Function setting up access to a set of auxiliary branches for a metadata object.
StatusCode setAuxStore(const std::string &key, Details::IObjectManager &mgr, bool metadata) override
Function connecting a DV object to its auxiliary store.
StatusCode setUpDynamicStore(TObjectManager &mgr, ::TTree *tree)
Function adding dynamic variable reading capabilities to an auxiliary store object.
constexpr auto getPtr(typename std::remove_reference< T >::type &arg) noexcept
void * ptr(T *p)
Definition SGImplSvc.cxx:75
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
status
Definition merge.py:16
bool hasAuxStore(const TClass &cl)
Helper function deciding if a given type "has an auxiliary store".
Definition IOUtils.cxx:40
bool isAuxStore(const TClass &cl)
Helper function deciding if a given type "is an auxiliary store".
Definition IOUtils.cxx:53
bool isStandalone(const TClass &cl)
Helper function deciding if a given type "is a standalone object".
Definition IOUtils.cxx:65

◆ connectObject()

StatusCode xAOD::TEvent::connectObject ( const std::string & key,
bool silent )
overrideprotectedvirtualinherited

Function setting up access to a particular object.

This is one of the more important functions of the class.

It connects the event object to a given branch of the input TTree.

The type that is read in to memory is not actually determined by the type written to the tree itself, but from the xAOD::EventFormat object. Which is there to make it possible to possibly use ROOT read rules in the future to read a different type than what's on disk.

Everything else is fairly basic ROOT stuff, the code just has to make sure that the memory management is set up correctly for the created object.

Parameters
keyThe name of the branch to connect to
silentSet to true to make the code fail silently in case the branch can't be connected to
Returns
The usual StatusCode types

Implements xAOD::Event.

Definition at line 1089 of file Control/xAODRootAccess/Root/TEvent.cxx.

1089 {
1090
1091 // A little sanity check:
1092 if (hasInput() == false) {
1093 ATH_MSG_ERROR("Function called on un-initialised object");
1094 return StatusCode::FAILURE;
1095 }
1096
1097 // Increment the access counter on this container:
1099
1100 // Check if the branch is already connected:
1101 if (m_inputObjects.contains(key)) {
1102 return StatusCode::SUCCESS;
1103 }
1104 // Check if it was already found to be missing.
1105 if (m_inputMissingObjects.contains(key)) {
1106 if (silent == false) {
1107 ATH_MSG_WARNING("Branch \"" << key << "\" not available on input");
1108 }
1109 return StatusCode::RECOVERABLE;
1110 }
1111
1112 // Check if we have metadata about this branch:
1113 const xAOD::EventFormatElement* ef = nullptr;
1114 if (m_inputEventFormat.exists(key) == false) {
1115 if (silent == false) {
1116 ATH_MSG_WARNING("No metadata available for branch: " << key);
1117 }
1118 } else {
1119 ef = m_inputEventFormat.get(key);
1120 }
1121
1122 // Check if the branch exists in our input tree:
1123 ::TBranch* br = m_inTree->GetBranch(key.c_str());
1124 if (br == nullptr) {
1125 if (!silent) {
1126 ATH_MSG_WARNING("Branch \"" << key << "\" not available on input");
1127 }
1128 m_inputMissingObjects.insert(key);
1129 return StatusCode::RECOVERABLE;
1130 }
1131
1132 // Make sure that it's not in "MakeClass mode":
1133 br->SetMakeClass(0);
1134
1135 // Decide about the type that we need to use for the reading of this
1136 // branch:
1137 std::string className = br->GetClassName();
1138 if (className == "") {
1139 if (ef) {
1140 // This is a fairly weird situation, but let's fall back to taking
1141 // the class name from the metadata object in this case.
1142 className = ef->className();
1143 } else {
1145 "Couldn't find an appropriate type with a dictionary for branch \""
1146 << key << "\"");
1147 return StatusCode::FAILURE;
1148 }
1149 }
1150 ::TClass* realClass = ::TClass::GetClass(className.c_str());
1151 if (((!realClass) || (!realClass->IsLoaded())) && ef) {
1152 // We may need to do an actual schema evolution here, in which
1153 // case let's fall back on the class name coming from the metadata
1154 // object.
1155 className = ef->className();
1156 realClass = ::TClass::GetClass(className.c_str());
1157 }
1158 if ((!realClass) || (!realClass->IsLoaded())) {
1159 // Now we're in trouble...
1161 "Couldn't find an appropriate type with a dictionary for branch \""
1162 << key << "\"");
1163 return StatusCode::FAILURE;
1164 }
1165
1166 // Make sure that the current object is the "active event":
1167#ifndef XAOD_STANDALONE
1168 SG::CurrentEventStore::Push save (SG::CurrentEventStore::store());
1169#endif
1170 setActive();
1171
1172 // The data type is always "other" for us:
1173 static const ::EDataType dataType = kOther_t;
1174
1175 // Check if the output already has this object. If it does, let's
1176 // assume that we have been copying the object to the output. Which
1177 // means that we need to resume filling the same memory address that
1178 // the output holder points to.
1179 void* ptr = nullptr;
1180 Object_t::const_iterator out_itr = m_outputObjects.find(key);
1181 if (out_itr != m_outputObjects.end()) {
1182 // It needs to be an object manager...
1183 TObjectManager* mgr = dynamic_cast<TObjectManager* >(out_itr->second.get());
1184 if (mgr == nullptr) {
1185 ATH_MSG_ERROR("Couldn't access output manager for: " << key);
1186 return StatusCode::FAILURE;
1187 }
1188 // Get the pointer out of it:
1189 ptr = mgr->holder()->get();
1190 }
1191
1192 // If there is no output object, then let's create one ourselves.
1193 // This is the only way in which we can have the memory management of
1194 // THolder do the right thing with this object.
1195 if (ptr == nullptr) {
1196 ptr = realClass->New();
1197 }
1198
1199 // Create the new manager object that will hold this EDM object:
1200 const bool renewOnRead = (m_auxMode == kAthenaAccess);
1201 auto mgr = std::make_unique<TObjectManager>(
1202 nullptr, std::make_unique<THolder>(ptr, realClass), renewOnRead);
1203
1204 // One final check. If it's not an auxiliary store, then it must have
1205 // a split level of 0. Otherwise read rules may not work on it. Causing
1206 // *very* serious silent corruption in the data read, if we don't use
1207 // the "Athena read mode".
1208 if ((m_auxMode != kAthenaAccess) && (br->GetSplitLevel() != 0) &&
1209 (Details::isAuxStore(*(mgr->holder()->getClass())) == false)) {
1210 ATH_MSG_ERROR("Split level for branch \""
1211 << key << "\" is " << br->GetSplitLevel()
1212 << ". This can only be read in kAthenaAccess mode.");
1213 // Clean up:
1214 *(mgr->holder()->getPtr()) = nullptr;
1215 m_inputObjects.erase(key);
1216 return StatusCode::FAILURE;
1217 }
1218
1219 // Now try to connect to the branch:
1220 const ::Int_t status =
1221 m_inTree->SetBranchAddress(key.c_str(), mgr->holder()->getPtr(),
1222 mgr->branchPtr(), realClass, dataType, kTRUE);
1223 if (status < 0) {
1224 ATH_MSG_ERROR("Couldn't connect variable of type \""
1225 << className << "\" to input branch \"" << key
1226 << "\". Return code: " << status);
1227 // Clean up:
1228 *(mgr->holder()->getPtr()) = 0;
1229 m_inputObjects.erase(key);
1230 return StatusCode::FAILURE;
1231 }
1232
1233 // At this point we have successfully connected the branch.
1234 TObjectManager* mgrPtr = mgr.get();
1235 m_inputObjects[key] = std::move(mgr);
1236
1237 // If it's an auxiliary store object, set it up correctly:
1238 if (Details::isAuxStore(*(mgrPtr->holder()->getClass()))) {
1240 }
1241
1242 // If there may be an auxiliary object connected to this one,
1243 // connect that as well:
1244 if (Details::hasAuxStore(*(mgrPtr->holder()->getClass()))) {
1246 key + "Aux.", Details::isStandalone(*(mgrPtr->holder()->getClass()))));
1247 }
1248
1249 // Return gracefully.
1250 return StatusCode::SUCCESS;
1251}
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:345
void setActive() const
Set this event object as the currently active one.
Definition EventCore.cxx:57
Object_t m_outputObjects
Collection of all the managed output object.
Definition Event.h:347
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 readContainer(const std::string &name)
Function incrementing the read counter on a specific container.
StatusCode connectAux(const std::string &prefix, bool standalone) override
Function setting up access to a set of auxiliary branches.
save(self, fileName="./columbo.out")
Definition checkTP.py:176

◆ contains() [1/2]

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

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 )
protectedinherited

Internal function checking if an object is in the input.

◆ containsMeta()

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

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

◆ copy()

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

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_MSG_DEBUG(x,...)
#define ATH_MSG_VERBOSE(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.
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.
@ OVERWRITE
create the directory as is, removing existing directories if needed

◆ createAndReadFrom()

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

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:77
static const char *const EVENT_RNTUPLE_NAME
Name of the event RNTuple.
Definition Event.h:78
str inFile
Definition makeTOC.py:5
#define unlikely(x)

◆ currentContext()

const EventContext & Event::currentContext ( ) const
protectedinherited

Return the event context corresponding to this event.

(Returns a dummy in standalone builds.)

Definition at line 308 of file EventCore.cxx.

308 {
309#ifdef XAOD_STANDALONE
310 return Gaudi::Hive::currentContext();
311#else
312 return m_ctx;
313#endif
314}
EventContext m_ctx
The event context associated with this event.
Definition Event.h:408

◆ dump()

std::string Event::dump ( )
inherited

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 254 of file EventCore.cxx.

254 {
255
256 // The internal stream object.
257 std::ostringstream ost;
258 ost << "<<<<<<<<<<<<<<<<<<<< xAOD::TEvent Dump >>>>>>>>>>>>>>>>>>>>\n";
259
260 // Loop over the input EventFormat object.
261 for (const auto& [key, element] : m_inputEventFormat) {
262
263 // Get the type.
264 ::TClass* cl = ::TClass::GetClass(element.className().c_str());
265 const std::type_info* ti = (cl ? cl->GetTypeInfo() : nullptr);
266 if ((cl == nullptr) || (cl->IsLoaded() == false) || (ti == nullptr)) {
267 ATH_MSG_WARNING("Unknown type (" << element.className()
268 << ") found in the event format");
269 continue;
270 }
271
272 // Skip containers that are not available anyway.
273 static const bool METADATA = false;
274 if (!contains(element.branchName(), *ti, METADATA)) {
275 continue;
276 }
277
278 // Do the printout.
279 ost << " Hash: 0x" << std::setw(8) << std::setfill('0') << std::hex
280 << element.hash() << " Key: \"" << element.branchName() << "\"\n";
281
282 ost << " type: " << element.className() << "\n";
283 const bool isNonConst =
284 transientContains(element.branchName(), *ti, METADATA);
285 ost << " isConst: " << (isNonConst ? "No" : "Yes") << "\n";
286 static const bool SILENT = false;
287 ost << " Data: "
288 << (isNonConst
289 ? getOutputObject(element.branchName(), *ti, METADATA)
290 : getInputObject(element.branchName(), *ti, SILENT, METADATA))
291 << "\n";
292 }
293
294 // Finish with the construction:
295 ost << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
296 return ost.str();
297}
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.

◆ fill()

Int_t xAOD::TEvent::fill ( )
overridevirtualinherited

Function filling one event into the output tree.

This function needs to be called by the user at the end of processing each event that is meant to be written out.

Returns
The number of bytes written if successful, a negative number if not

Implements xAOD::Event.

Definition at line 847 of file Control/xAODRootAccess/Root/TEvent.cxx.

847 {
848
849 // A little sanity check:
850 if (!m_outTree) {
851 ATH_MSG_ERROR("Object not connected to an output file!");
852 return 0;
853 }
854
855 // Make sure that all objects have been read in. The 99 as the value
856 // has a special meaning for TAuxStore. With this value it doesn't
857 // delete its transient (decoration) variables. Otherwise it does.
858 // (As it's supposed to, when moving to a new event.)
859 Int_t readBytes = 0;
860 if (m_inChain != nullptr) {
861 readBytes = getEntry(m_inChain->GetReadEntry(), 99);
862 } else if (m_inTree != nullptr) {
863 readBytes = getEntry(m_entry, 99);
864 }
865 if (readBytes < 0) {
866 ATH_MSG_ERROR("getEntry failed!");
867 return readBytes;
868 }
869
870 // Prepare the objects for writing. Note that we need to iterate over a
871 // copy of the m_outputObjects container. Since the putAux(...) function
872 // called inside the loop may itself add elements to the m_outputObject
873 // container.
874 std::string unsetObjects;
875 std::vector<std::pair<std::string, TVirtualManager* >> outputObjectsCopy;
876 outputObjectsCopy.reserve(m_outputObjects.size());
877 for (const auto &[key, mgr] : m_outputObjects) {
878 outputObjectsCopy.emplace_back(key, mgr.get());
879 }
880 for (auto &[key, mgr] : outputObjectsCopy) {
881 // Check that a new object was provided in the event:
882 if (!mgr->create()) {
883 // We are now going to fail. But let's collect the names of
884 // all the unset objects:
885 if (unsetObjects.size()) {
886 unsetObjects += ", ";
887 }
888 unsetObjects.append("\"" + key + "\"");
889 continue;
890 }
891 // Make sure that any dynamic auxiliary variables that
892 // were added to the object after it was put into the event,
893 // get added to the output:
894 static constexpr bool METADATA = false;
895 if (putAux(*m_outTree, *mgr, METADATA).isFailure()) {
896 ATH_MSG_ERROR("Failed to put dynamic auxiliary variables "
897 "in the output for object \""
898 << key << "\"");
899 return 0;
900 }
901 }
902
903 // Check if there were any unset objects:
904 if (unsetObjects.size()) {
905 ATH_MSG_ERROR("The following objects were not set in the current event: "
906 << unsetObjects);
907 return 0;
908 }
909
910 // Write the entry, and check the return value:
911 const ::Int_t ret = m_outTree->Fill();
912 if (ret <= 0) {
913 ATH_MSG_ERROR("Output tree filling failed with return value: " << ret);
914 }
915
916 // Reset the object managers.
917 for (auto &[key, mgr] : m_outputObjects) {
918 mgr->reset();
919 }
920
921 // Return the value:
922 return ret;
923}
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0) override
Function loading a given entry of the input TTree.
::Long64_t m_entry
The entry to look at from the input tree.
::TChain * m_inChain
The (optional) chain provided as input.
StatusCode putAux(::TTree &outTree, TVirtualManager &mgr, bool metadata)
Function saving the dynamically created auxiliary properties.
std::unique_ptr<::TTree > m_outTree
The tree that we are writing to.

◆ finishWritingTo() [1/2]

StatusCode xAOD::TEvent::finishWritingTo ( ::TFile * file)
inherited

Finish writing to an output file.

This function needs to be called when the user is done writing events to a file, before (s)he would close the file itself.

Parameters
fileThe file that the event data is written to
Returns
The usual StatusCode tyoes

Definition at line 479 of file Control/xAODRootAccess/Root/TEvent.cxx.

479 {
480
481 // A small sanity check:
482 if (!m_outTree) {
483 ATH_MSG_ERROR("The object doesn't seem to be connected to an output file!");
484 return StatusCode::FAILURE;
485 }
486
487 // Make sure we return to the current directory:
488 TDirectoryReset dr;
489
490 // Notify the listeners that they should write out their metadata, if they
491 // have any.
492 const TIncident incident(IncidentType::MetaDataStop);
493 for (auto &listener : m_listeners) {
494 listener->handle(incident);
495 }
496
497 // Write out the event tree, and delete it:
498 m_outTree->AutoSave("FlushBaskets");
499 m_outTree->SetDirectory(0);
500 m_outTree.reset();
501
502 // Now go to the output file:
503 file->cd();
504
505 // Check if there's already a metadata tree in the output:
506 if (file->Get(METADATA_OBJECT_NAME)) {
507 // Let's assume that the metadata is complete in the file already.
508 return StatusCode::SUCCESS;
509 }
510
511 // Create the metadata tree.
512 auto metatree =
513 std::make_unique<TTree>(METADATA_OBJECT_NAME, "xAOD metadata tree");
514 metatree->SetAutoSave(10000);
515 metatree->SetAutoFlush(-30000000);
516 metatree->SetDirectory(file);
517
518 // Create the xAOD::EventFormat branch in it.
519 try {
520 metatree->Branch(
521 "EventFormat",
524 } catch (const CxxUtils::ClassName::ExcBadClassName &e) {
525 ::Error("xAOD::TEvent::finishWritingTo",
526 XAOD_MESSAGE("Class name parsing fails for %s ! "), e.what());
527 return StatusCode::FAILURE;
528 }
529
530 // Create a copy of the m_outputMetaObjects variable. This is necessary
531 // because the putAux(...) function will modify this variable while we
532 // loop over it.
533 std::vector<std::pair<std::string, TObjectManager* >> outputMetaObjects;
534 outputMetaObjects.reserve(m_outputMetaObjects.size());
535 for (const auto &[key, mgr] : m_outputMetaObjects) {
536 TObjectManager* objMgr = dynamic_cast<TObjectManager* >(mgr.get());
537 if (objMgr == nullptr) {
538 ATH_MSG_FATAL("Internal logic error detected");
539 return StatusCode::FAILURE;
540 }
541 outputMetaObjects.emplace_back(key, objMgr);
542 }
543
544 // Now loop over all the metadata objects that need to be put into the
545 // output file:
546 for (auto &[key, mgr] : outputMetaObjects) {
547
548 // Select a split level depending on whether this is an interface or an
549 // auxiliary object:
550 const ::Int_t splitLevel = (key.ends_with("Aux.") ? 1 : 0);
551 // Create the new branch:
552 *(mgr->branchPtr()) =
553 metatree->Branch(key.c_str(), mgr->holder()->getClass()->GetName(),
554 mgr->holder()->getPtr(), 32000, splitLevel);
555 if (!mgr->branch()) {
556 ATH_MSG_ERROR("Failed to create metadata branch \""
557 << mgr->holder()->getClass()->GetName() << "/" << key
558 << "\"");
559 return StatusCode::FAILURE;
560 }
561 // Set up the saving of all the dynamic auxiliary properties
562 // of the object if it has any:
563 static constexpr bool METADATA = true;
564 ATH_CHECK(putAux(*metatree, *mgr, METADATA));
565 }
566
567 // Write the metadata objects:
568 if (metatree->Fill() <= 0) {
569 ATH_MSG_ERROR("Failed to write event format metadata into the output");
570 metatree->SetDirectory(nullptr);
571 return StatusCode::FAILURE;
572 }
573
574 // Now clean up:
575 metatree->Write();
576 metatree->SetDirectory(nullptr);
577 m_outputEventFormat = nullptr;
578 m_outputObjects.clear();
579 m_outputMetaObjects.clear();
580
581 // Return gracefully:
582 return StatusCode::SUCCESS;
583}
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
static const char *const METADATA_OBJECT_NAME
Name of the metadata tree or RNTuple.
Definition Event.h:79
EventFormat * m_outputEventFormat
Format of the current output file.
Definition Event.h:357
Object_t m_outputMetaObjects
Collection of all the managed output meta-objects.
Definition Event.h:352
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...
static const ::Int_t MetaDataStop
The metadata for the output file should be written out.
Definition TIncident.h:31
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition EventFormat.h:16
TFile * file

◆ finishWritingTo() [2/2]

StatusCode xAOD::TEvent::finishWritingTo ( TFile & file)
overridevirtualinherited

Finish writing to an output file.

This function needs to be called when the user is done writing events to a file, before (s)he would close the file itself.

Parameters
fileThe file that the event data is written to
Returns
The usual StatusCode tyoes

Implements xAOD::Event.

Definition at line 469 of file Control/xAODRootAccess/Root/TEvent.cxx.

469 {
470 return finishWritingTo(&file);
471}
StatusCode finishWritingTo(TFile &file) override
Finish writing to an output file.

◆ getBranchInfo()

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

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 & name() const override
Get the name of the instance.
const std::string & getName(const void *obj) const override
Function returning the key describing a known object.
friend class xAODPrivate::Loader
Definition Event.h:65
Event(std::string_view name)
Constructor with a name.
Definition EventCore.cxx:29
const xAOD::EventFormatElement * getEventFormatElement(SG::sgkey_t sgkey) const
Get the metadata object for a given "SG key".

◆ getEntries()

Long64_t xAOD::TEvent::getEntries ( ) const
overridevirtualinherited

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

Returns
The number of events in the input file(s)

Implements xAOD::Event.

Definition at line 654 of file Control/xAODRootAccess/Root/TEvent.cxx.

654 {
655
656 if (m_inChain) {
657 return m_inChain->GetEntries();
658 } else if (m_inTree) {
659 return m_inTree->GetEntries();
660 } else if (m_inTreeMissing) {
661 // The input file is empty:
662 return 0;
663 } else {
664 ATH_MSG_ERROR("Function called on an uninitialised object");
665 return 0;
666 }
667}
bool m_inTreeMissing
Internal status flag showing that an input file is open, but it doesn't contain an event tree.

◆ getEntry()

Int_t xAOD::TEvent::getEntry ( ::Long64_t entry,
::Int_t getall = 0 )
overridevirtualinherited

Function loading a given entry of the input TTree.

This function is used to move to looking at a new entry from the input tree.

It doesn't do any I/O operation at this point, it just remembers which entry the objects should be loaded from later on.

Unless one calls the function with getall==1. In that case all input is force-read. This is necessary when writing out an event that was processed in a load-on-request manner.

Parameters
entryThe entry from the input tree to load
getallParameter deciding if partial reading should be used or not.
Returns
The number of bytes read, or a negative number in case of an error

Implements xAOD::Event.

Definition at line 683 of file Control/xAODRootAccess/Root/TEvent.cxx.

683 {
684
685 // A little sanity check:
686 if ((!m_inTree) && (!m_inChain)) {
687 ATH_MSG_ERROR("Function called on an uninitialised object");
688 return -1;
689 }
690
691 // If we have a chain as input:
692 if (m_inChain) {
693 // Make sure that the correct tree is loaded:
694 const ::Long64_t fileEntry = m_inChain->LoadTree(entry);
695 if (fileEntry < 0) {
696 ATH_MSG_ERROR("Failure in loading entry " << entry
697 << " from the input chain");
698 return -1;
699 }
700 // Check if a new file was loaded:
701 if ((m_inTreeNumber != m_inChain->GetTreeNumber()) ||
702 m_inChainTracker->internalStateChanged()) {
703 // Reset the tracker:
704 m_inChainTracker->reset();
705 // Connect to this new file:
706 m_inTreeNumber = m_inChain->GetTreeNumber();
707 ::TFile* file = m_inChain->GetFile();
708 // The useTreeCache parameter is set to false, since the cache
709 // is anyway set up through the TChain. It shouldn't be modified
710 // on the file level.
711 static constexpr bool USE_TREE_CACHE = false;
712 if (readFrom(file, USE_TREE_CACHE, m_inChain->GetName()).isFailure()) {
713 ATH_MSG_ERROR("Couldn't connect to input file #"
714 << m_inTreeNumber << " of the input chain");
715 return -1;
716 }
717 }
718 // Restore the previously received entry number.
719 m_entry = fileEntry;
720 }
721 // If we have a regular file/tree as input:
722 else {
723 m_entry = entry;
724 }
725
726 // In order to make the reading of branches+tree cache work
727 // NB: TTree::LoadTree() only set the entry that should be read for each
728 // branch but no reading of the branch content is performed when calling that
729 // function. The entry set that can be retrieved with
730 // branch->GetTree()->GetReadEntry()
731 // For friend trees, if an index was built, then the entry which is set for
732 // the related branches is found by the LoadTree function by matching the the
733 // major and minor values of the main tree and friend tree
734 if (m_inTree && m_inTree->LoadTree(m_entry) < 0) {
735 ATH_MSG_ERROR("Failure in loading entry " << m_entry
736 << " from the input file");
737 return -1;
738 }
739
740 // Stats counter needs to know it's the next event:
742
743 // The final number of bytes read.
744 ::Int_t result = 0;
745
746 // Check if objects need to be read in.
747 if (getall) {
748 if (m_auxMode == kAthenaAccess) {
749 // In kAthenaAccess mode we need to use getInputObject(...) to load
750 // all the input objects correctly.
751 for (auto &[key, mgr] : m_inputObjects) {
752 static const std::string dynStorePostfix = "Aux.Dynamic";
753 if (key.ends_with(dynStorePostfix)) {
754 // Ignore the dynamic store objects. They get loaded through
755 // their parents.
756 } else {
757 // Load the objects and their auxiliary stores through the
758 // getInputObject(...) function, which takes care of correctly
759 // setting them up. The type is irrelevant here. We don't
760 // really care about the exact type of the objects.
761 static constexpr bool SILENT = true;
762 static constexpr bool METADATA = false;
763 getInputObject(key, typeid(int), SILENT, METADATA);
764 }
765 }
766 } else {
767 // In a "reasonable" access mode, we do something very simple:
768 for (auto &[key, mgr] : m_inputObjects) {
769 result += mgr->getEntry(getall);
770 }
771 }
772 }
773
774 // Notify the listeners that a new event was loaded:
775 const TIncident incident(IncidentType::BeginEvent);
776 for (auto &listener : m_listeners) {
777 listener->handle(incident);
778 }
779
780 // Return the number of bytes read:
781 return result;
782}
void nextEvent()
Function incrementing the processed event counter.
std::unique_ptr< TChainStateTracker > m_inChainTracker
Optional object for tracking the state changes of an input TChain.
StatusCode readFrom(::TFile &inFile) override
Set up the reading of an input file from TFile This method implements the interface from Event.
::Int_t m_inTreeNumber
The number of the currently open tree in the input chain.
static const ::Int_t BeginEvent
A new event was just loaded.
Definition TIncident.h:29

◆ getEventFormatElement()

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

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.
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.

◆ getFile()

Int_t xAOD::TEvent::getFile ( ::Long64_t file,
::Int_t getall = 0 )
inherited

Load the first event for a given file from the input TChain.

This function can be used to iterate over the input files specified for the object.

It should be most useful for collecting metadata about a set of input files, if there's no regular event loop done to process them.

Parameters
fileThe file number to load
getallIf set to 1, all connected branches are loaded
Returns
The number of read bytes on success, or a negative number on failure

Definition at line 813 of file Control/xAODRootAccess/Root/TEvent.cxx.

813 {
814
815 // Check if the file number is valid:
816 if ((file < 0) || (file >= getFiles())) {
817 ATH_MSG_ERROR("Function called with invalid file number (" << file << ")");
818 return -1;
819 }
820
821 // If we are not reading a TChain, return at this point. As the one and
822 // only file is open already...
823 if (!m_inChain) {
824 return 0;
825 }
826
827 // Trigger the "scanning" of the input files, so the TChain would know
828 // how many entries are in the various files.
829 getEntries();
830
831 // Calculate which entry/event we need to load:
832 ::Long64_t entry = 0;
833 for (::Long64_t i = 0; i < file; ++i) {
834 entry += m_inChain->GetTreeOffset()[i];
835 }
836
837 // Load this entry using the regular event opening function:
838 return getEntry(entry, getall);
839}
::Long64_t getFiles() const
Get how many files are available on the currently defined input.
::Long64_t getEntries() const override
Get how many entries are available from the current input file(s).

◆ getFiles()

Long64_t xAOD::TEvent::getFiles ( ) const
inherited

Get how many files are available on the currently defined input.

This function can be used to get the number of input files that the object currently knows about.

This is meant to be used to collect the metadata from each of the input files, or to access the metadata using a transient tree. (xAOD::TMetaTree)

Returns
The number of input files when reading from a TChain, 1 when reading from a TFile, and 0 if the object is not connected to any input

Definition at line 793 of file Control/xAODRootAccess/Root/TEvent.cxx.

793 {
794
795 if (m_inChain) {
796 return m_inChain->GetListOfFiles()->GetEntries();
797 } else if (m_inTree || m_inTreeMissing) {
798 return 1;
799 } else {
800 return 0;
801 }
802}

◆ getHash()

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

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 )
protectedinherited

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:338
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.
static TStore * store()
Access the currently active TStore object.
::StatusCode StatusCode
StatusCode definition for legacy code.
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 )
overrideprotectedvirtualinherited

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
overridevirtualinherited

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
overridevirtualinherited

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
overridevirtualinherited

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()

StatusCode xAOD::TEvent::getNames ( const std::string & targetClassName,
std::vector< std::string > & vkeys,
bool metadata ) const
overrideprotectedvirtualinherited

Function determining the list keys associated with a type name.

Implements xAOD::Event.

Definition at line 932 of file Control/xAODRootAccess/Root/TEvent.cxx.

934 {
935 // The results go in here
936 std::set<std::string> keys;
937
938 // Get list of branches from
939 // the input metadata tree or input tree
940 std::vector<TObjArray* > fullListOfBranches = {};
941 if (metadata) {
942 if (m_inMetaTree) {
943 // No friend tree expected for metadata tree
944 // Only add the list of branches of the metadata tree
945 ATH_MSG_DEBUG("Scanning for input metadata objects");
946 fullListOfBranches.push_back(m_inMetaTree->GetListOfBranches());
947 }
948 } else {
949 if (m_inTree) {
950 ATH_MSG_DEBUG("Scanning for input data objects");
951 // Add the list of branches of the main tree
952 fullListOfBranches.push_back(m_inTree->GetListOfBranches());
953 // If the input tree has friend trees
954 // add as well the list of friend tree branches
955 if (m_inTree->GetListOfFriends()) {
956 // Get the list of friends
957 TList* fList = m_inTree->GetListOfFriends();
958 // Loop over friend elements
959 for (TObject* feObj : *fList) {
960 if (feObj) {
961 // Get corresponding friend tree
962 auto* pElement = dynamic_cast<TFriendElement* >(feObj);
963 if (pElement == nullptr) {
964 continue;
965 }
966 TTree* friendTree = pElement->GetTree();
967 // Add list of branches of the friend tree
968 fullListOfBranches.push_back(friendTree->GetListOfBranches());
969 }
970 }
971 }
972 }
973 }
974
975 // Loop over all list of branches (if any)
976 for (const TObjArray* in : fullListOfBranches) {
977 // Loop over all branches inside the current list of branches
978 for (const TObject* obj : *in) {
979
980 if (obj == nullptr) {
981 continue;
982 }
983 const TBranch* element = dynamic_cast<const TBranch* >(obj);
984 if (!element) {
985 ATH_MSG_ERROR("Failure inspecting input data objects");
986 return StatusCode::FAILURE;
987 }
988 const std::string objClassName = element->GetClassName();
989 std::string key = obj->GetName();
990 ATH_MSG_VERBOSE("Inspecting \"" << objClassName << "\" / \"" << key
991 << "\"");
992 if (objClassName == targetClassName) {
993 ATH_MSG_DEBUG("Matched \"" << targetClassName << "\" to key \"" << key
994 << "\"");
995 keys.insert(std::move(key));
996 }
997 }
998 }
999
1001
1002 ATH_MSG_DEBUG("Scanning input objects for \"" << targetClassName << "\"");
1003 for (const auto &[key, vmgr] : inAux) {
1004 // All (metadata) objects should be held by TObjectManager objects.
1005 const TObjectManager* mgr =
1006 dynamic_cast<const TObjectManager* >(vmgr.get());
1007 if (mgr == nullptr) {
1008 continue;
1009 }
1010 const std::string &objClassName = mgr->holder()->getClass()->GetName();
1011 ATH_MSG_VERBOSE("Inspecting \"" << objClassName << "\" / \"" << key
1012 << "\"");
1013 if (objClassName == targetClassName) {
1014 ATH_MSG_DEBUG("Matched \"" << targetClassName << "\" to key \"" << key
1015 << "\"");
1016 keys.insert(key);
1017 }
1018 }
1019
1020 // Check for output objects.
1021 if ((metadata == false) && m_outTree) {
1022 const TObjArray* out = m_outTree->GetListOfBranches();
1023 ATH_MSG_DEBUG("Scanning for output data objects");
1024
1025 for (const TObject* obj : *out) {
1026 if (obj == nullptr) {
1027 continue;
1028 }
1029 const TBranch* element = dynamic_cast<const TBranch* >(obj);
1030 if (element == nullptr) {
1031 ATH_MSG_ERROR("Failure inspecting output objects");
1032 return StatusCode::FAILURE;
1033 }
1034 const std::string objClassName = element->GetClassName();
1035 std::string key = obj->GetName();
1036 ATH_MSG_VERBOSE("Inspecting \"" << objClassName << "\" / \"" << key
1037 << "\"");
1038 if (objClassName == targetClassName) {
1039 ATH_MSG_DEBUG("Matched \"" << targetClassName << "\" to key \"" << key
1040 << "\"");
1041 keys.insert(std::move(key));
1042 }
1043 }
1044 }
1045
1047
1048 // Search though the in-memory output objects.
1049 ATH_MSG_DEBUG("Scanning output objects for \"" << targetClassName << "\"");
1050 for (const auto &[key, vmgr] : outAux) {
1051 // All (metadata) objects should be held by TObjectManager objects.
1052 TObjectManager* mgr = dynamic_cast<TObjectManager* >(vmgr.get());
1053 if (mgr == nullptr) {
1054 continue;
1055 }
1056 const std::string &objClassName = mgr->holder()->getClass()->GetName();
1057 ATH_MSG_VERBOSE("Inspecting \"" << objClassName << "\" / \"" << key
1058 << "\"");
1059 if (objClassName == targetClassName) {
1060 ATH_MSG_DEBUG("Matched \"" << targetClassName << "\" to key \"" << key
1061 << "\"");
1062 keys.insert(key);
1063 }
1064 }
1065
1066 vkeys.insert(vkeys.end(), keys.begin(), keys.end());
1067
1068 // Return gracefully.
1069 return StatusCode::SUCCESS;
1070}

◆ getOutputObject() [1/2]

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

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}

◆ getOutputObject() [2/2]

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

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()

bool xAOD::TEvent::hasInput ( ) const
overrideprotectedvirtualinherited

Check if an input file is connected to the object.

Implements xAOD::Event.

Definition at line 925 of file Control/xAODRootAccess/Root/TEvent.cxx.

925 {
926
927 return ((m_inTree != nullptr) || (m_inChain != nullptr));
928}

◆ hasOutput()

bool xAOD::TEvent::hasOutput ( ) const
overrideprotectedvirtualinherited

Check if an output file is connected to the object.

Implements xAOD::Event.

Definition at line 930 of file Control/xAODRootAccess/Root/TEvent.cxx.

930{ return (m_outTree.get() != nullptr); }

◆ 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)

◆ initStats()

StatusCode xAOD::TEvent::initStats ( )
protectedinherited

Function to initialise the statistics for all Tree content.

This function is used internally to initialise the reading of an input file.

It prepares the "monitoring information" in memory that gets filled while the code is running, with information about xAOD I/O.

Returns
The usual StatusCode tyoes

Definition at line 1863 of file Control/xAODRootAccess/Root/TEvent.cxx.

1863 {
1864
1865 // If we're dealing with an empty input file, stop here:
1866 if (m_inTreeMissing) {
1867 return StatusCode::SUCCESS;
1868 }
1869
1870 // A little sanity check:
1871 if (!m_inTree) {
1872 ATH_MSG_ERROR("Function called on an uninitialised object");
1873 return StatusCode::FAILURE;
1874 }
1875
1876 // Reset the number of input branches information:
1878
1879 // Loop over the EventFormat information
1882 for (; itr != end; ++itr) {
1883
1884 // Get the name of the branch in question:
1885 const std::string &branchName = itr->second.branchName();
1886
1887 // If it's an auxiliary container, scan it using TAuxStore:
1888 if (branchName.find("Aux.") != std::string::npos) {
1889
1890 // But first decide whether it describes a container, or just
1891 // a single object. Since the file may have been written in
1892 // kBranchAccess mode, it's not necessarily a good idea to check
1893 // the type of the auxiliary class. So let's check the interface
1894 // class instead.
1895 //
1896 // Get the name of the interface object/container:
1897 const std::string intName = branchName.substr(0, branchName.size() - 4);
1898 if (!m_inputEventFormat.exists(intName)) {
1899 // When this happens, it may still be that both the interface and
1900 // the auxiliary container is missing from the file. As we didn't
1901 // check yet whether the auxiliary container is in place or not.
1902 // So, before printing a warning, let's check for this.
1903 // Unfortunately the check is pretty expensive, but this should
1904 // not be performance critical code after all...
1905 ::Bool_t auxFound = kFALSE;
1906 const std::string dynName = Utils::dynBranchPrefix(branchName);
1907
1908 std::vector<TObjArray* > fullListOfBranches = {};
1909 // Add the list of branches of the main tree
1910 fullListOfBranches.push_back(m_inTree->GetListOfBranches());
1911 // If input tree has friend trees
1912 // add as well the list of friend tree branches
1913 if (m_inTree->GetListOfFriends()) {
1914 // Get the list of friends
1915 TList* fList = m_inTree->GetListOfFriends();
1916 // Loop over friend elements
1917 for (TObject* feObj : *fList) {
1918 if (feObj) {
1919 // Get corresponding friend tree
1920 auto* pElement = dynamic_cast<TFriendElement* >(feObj);
1921 if (not pElement)
1922 continue;
1923 TTree* friendTree = pElement->GetTree();
1924 // Add list of branches of the friend tree
1925 fullListOfBranches.push_back(friendTree->GetListOfBranches());
1926 }
1927 }
1928 }
1929
1930 for (TObjArray* branches : fullListOfBranches) {
1931 for (Int_t i = 0; i < branches->GetEntriesFast(); ++i) {
1932 if (!branches->At(i))
1933 continue;
1934
1935 const TString name(branches->At(i)->GetName());
1936 if (name.BeginsWith(branchName) || name.BeginsWith(dynName)) {
1937 auxFound = kTRUE;
1938 break;
1939 }
1940 }
1941 }
1942 if (auxFound) {
1943 ATH_MSG_WARNING("Couldn't find interface object/container \""
1944 << intName << "\" belonging to branch \""
1945 << branchName << "\"");
1946 }
1947 continue;
1948 }
1949
1950 // Get the type of the interface:
1951 const EventFormatElement* el = m_inputEventFormat.get(intName);
1952 ::TClass* cl = ::TClass::GetClass(el->className().c_str());
1953 if ((!cl) || (!cl->IsLoaded())) {
1954 ATH_MSG_WARNING("Couldn't find dictionary for type \""
1955 << el->className() << "\"");
1956 continue;
1957 }
1958
1959 // Get the dictionary for the DataVector base class:
1960 static const std::type_info &baseTi = typeid(SG::AuxVectorBase);
1961 static const std::string baseName = SG::normalizedTypeinfoName(baseTi);
1962 static ::TClass* const baseCl = ::TClass::GetClass(baseName.c_str());
1963 if (!baseCl) {
1964 ATH_MSG_ERROR("Couldn't get dictionary for type \"" << baseName
1965 << "\"");
1966 return StatusCode::FAILURE;
1967 }
1968
1969 // The type of the auxiliary store is finally deduced from the
1970 // inheritance of the interface container.
1972 (cl->InheritsFrom(baseCl) ? TAuxStore::EStructMode::kContainerStore
1974
1975 // Scan the branches using a temporary TAuxStore instance:
1976 static constexpr bool TOP_STORE = true;
1977 TAuxStore temp(this->currentContext(), branchName, TOP_STORE, mode);
1978 static constexpr bool PRINT_WARNINGS = false;
1979 ATH_CHECK(temp.readFrom(*m_inTree, PRINT_WARNINGS));
1980
1981 // Conveninence variable:
1982 ReadStats &stats = IOStats::instance().stats();
1983
1984 // Teach the cache about all the branches:
1985 for (SG::auxid_t id : temp.getAuxIDs()) {
1986 stats.branch(branchName, id);
1987 }
1988
1989 // Increment the number of known branches:
1990 stats.setBranchNum(stats.branchNum() + temp.getAuxIDs().size());
1991 }
1992 // If it's an interface container:
1993 else {
1994 // Try to access the branch:
1995 const ::TBranch* container = m_inTree->GetBranch(branchName.c_str());
1996 // If it exists, let's remember it:
1997 if (container) {
1998 IOStats::instance().stats().container(branchName);
1999 }
2000 }
2001 }
2002
2003 // Return gracefully:
2004 return StatusCode::SUCCESS;
2005}
KeyedData_t::const_iterator const_iterator
Iterator for looping over the elements of the object.
BranchStats * container(const std::string &name)
Access the description of a container. Creating it if necessary.
void setBranchNum(::Int_t num)
Set the total number of branches on the input.
EStructMode
"Structural" modes of the object
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
std::string dynBranchPrefix(const std::string &key)
This function is used to figure out what to name dynamic auxiliary branches coming from a container c...

◆ inputEventFormat()

const EventFormat * Event::inputEventFormat ( ) const
inherited

Get information about the input objects.

Definition at line 232 of file EventCore.cxx.

232 {
233
234 if (hasInput()) {
235 return &m_inputEventFormat;
236 }
237 return nullptr;
238}

◆ keys()

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

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
overrideprotectedinherited

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
overrideprotectedinherited

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}

◆ MakeTransientTree()

friend::TTree * xAOD::TEvent::MakeTransientTree ( TEvent & ,
const char *  )
privateinherited

◆ metaKeys()

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

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
overrideprotectedinherited

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
inherited

Get information about the output objects.

Definition at line 240 of file EventCore.cxx.

240 {
241
242 return m_outputEventFormat;
243}

◆ printIOStats()

void Event::printIOStats ( ) const
inherited

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 302 of file EventCore.cxx.

302 {
303
304 // Simply do this via the xAODCore code:
305 IOStats::instance().stats().Print("Summary");
306}
void Print(::Option_t *option="") const
Print information about the collected statistics.

◆ printNameRemap()

void Event::printNameRemap ( ) const
inherited

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 205 of file EventCore.cxx.

205 {
206
207 // Print a header.
208 ATH_MSG_INFO("Name remapping rules:");
209
210 // In case no remapping rules have been set.
211 if (m_nameRemapping.empty()) {
212 ATH_MSG_INFO(" NONE");
213 return;
214 }
215
216 // Otherwise.
217 for (const auto& [newName, onfile] : m_nameRemapping) {
218 ATH_MSG_INFO(" \"" << newName << "\" -> \"" << onfile << "\"");
219 }
220}
#define ATH_MSG_INFO(x,...)

◆ printProxyWarnings()

void Event::printProxyWarnings ( bool value = true)
inherited

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 227 of file EventCore.cxx.

227 {
228
230}

◆ proxies()

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

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
overrideprotectedinherited

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
overrideprotectedinherited

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
overrideprotectedinherited

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}

◆ putAux()

StatusCode xAOD::TEvent::putAux ( ::TTree & outTree,
TVirtualManager & vmgr,
bool metadata )
protectedinherited

Function saving the dynamically created auxiliary properties.

This function is used internally to set up the writing of the auxiliary store variables that were dynamically created on an object.

(And not statically defined to be part of that object.)

Parameters
outTreeThe TTree to put the auxiliary branches into
mgrThe object manager of the output object
metadataFlag specifying whether the info written is metadata or not
Returns
The usual StatusCode types

Definition at line 2180 of file Control/xAODRootAccess/Root/TEvent.cxx.

2181 {
2182
2183 // A little sanity check:
2184 assert(m_outputEventFormat != 0);
2185
2186 // Do the conversion:
2187 TObjectManager* mgr = dynamic_cast<TObjectManager* >(&vmgr);
2188 if (!mgr) {
2189 // It's not an error any more when we don't get a TObjectManager.
2190 return StatusCode::SUCCESS;
2191 }
2192
2193 // Check if we need to do anything here:
2194 if (!mgr->holder()->getClass()->InheritsFrom("SG::IAuxStoreIO")) {
2195 return StatusCode::SUCCESS;
2196 }
2197
2198 // Get a pointer to the auxiliary store I/O interface:
2199 SG::IAuxStoreIO* aux = reinterpret_cast<SG::IAuxStoreIO* >(
2200 mgr->holder()->getAs(typeid(SG::IAuxStoreIO)));
2201 if (!aux) {
2202 ATH_MSG_FATAL("There is a logic error in the code!");
2203 return StatusCode::FAILURE;
2204 }
2205
2206 // Check if we have rules defined for which auxiliary properties
2207 // to write out:
2208 xAOD::AuxSelection sel;
2209 if (!metadata) {
2210 auto item_itr = m_auxItemList.find(mgr->branch()->GetName());
2211 if (item_itr != m_auxItemList.end()) {
2212 sel.selectAux(item_itr->second);
2213 }
2214 }
2215
2216 // Get the dynamic auxiliary variables held by this object, which
2217 // were selected to be written:
2218 const SG::auxid_set_t auxids =
2219 sel.getSelectedAuxIDs(aux->getSelectedAuxIDs());
2220
2221 // If there are no dynamic auxiliary variables in the object, return
2222 // right away:
2223 if (auxids.empty()) {
2224 return StatusCode::SUCCESS;
2225 }
2226
2227 // Decide what should be the prefix of all the dynamic branches:
2228 const std::string dynNamePrefix =
2229 Utils::dynBranchPrefix(mgr->branch()->GetName());
2230
2231 // Select which container to add the variables to:
2233
2234 // This iteration will determine the ordering of branches within
2235 // the tree, so sort auxids by name.
2236 const SG::AuxTypeRegistry &r = SG::AuxTypeRegistry::instance();
2237 typedef std::pair<std::string, SG::auxid_t> AuxVarSort_t;
2238 std::vector<AuxVarSort_t> varsort;
2239 varsort.reserve(auxids.size());
2240 for (SG::auxid_t id : auxids) {
2241 varsort.emplace_back(r.getName(id), id);
2242 }
2243 std::sort(varsort.begin(), varsort.end());
2244
2245 // Extract all the dynamic variables from the object:
2246 for (const auto &p : varsort) {
2247
2248 // The auxiliary ID:
2249 const SG::auxid_t id = p.second;
2250
2251 // Construct a name for the branch that we will write:
2252 const std::string brName = dynNamePrefix + p.first;
2253
2254 // Try to find the branch:
2255 Object_t::iterator bmgr = objects.find(brName);
2256
2257 // Check if we already know about this variable:
2258 if (bmgr == objects.end()) {
2259
2260 // Construct the full type name of the variable:
2261 const std::type_info* brType = aux->getIOType(id);
2262 if (!brType) {
2263 ATH_MSG_ERROR("No I/O type found for variable " << brName);
2264 return StatusCode::FAILURE;
2265 }
2266 const std::string brTypeName = Utils::getTypeName(*brType);
2267 std::string brProperTypeName = "<unknown>";
2268
2269 // The branch that will hopefully be created:
2270 ::TBranch* br = 0;
2271
2272 // Check if it's a primitive type or not:
2273 if (strlen(brType->name()) == 1) {
2274
2275 // Making the "proper" type name is simple in this case:
2276 brProperTypeName = brTypeName;
2277
2278 // Get the character describing this type for ROOT:
2279 const char rootType = Utils::rootType(brType->name()[0]);
2280 if (rootType == '\0') {
2281 ATH_MSG_ERROR("Type not known for variable \""
2282 << brName << "\" of type \"" << brTypeName << "\"");
2283 return StatusCode::FAILURE;
2284 }
2285
2286 // Create the full description of the variable for ROOT:
2287 std::ostringstream leaflist;
2288 leaflist << brName << "/" << rootType;
2289
2290 // Let's create a holder for this property:
2291 static constexpr bool IS_OWNER = false;
2292 auto auxmgr = std::make_unique<TPrimitiveAuxBranchManager>(
2293 id, nullptr, new THolder(aux->getIOData(id), nullptr, IS_OWNER));
2294
2295 // ... and let's add it to the output TTree:
2296 static constexpr Int_t BASKET_SIZE = 32000;
2297 *(auxmgr->branchPtr()) =
2298 outTree.Branch(brName.c_str(), auxmgr->holder()->get(),
2299 leaflist.str().c_str(), BASKET_SIZE);
2300 if (!auxmgr->branch()) {
2301 ATH_MSG_ERROR("Failed to create branch \""
2302 << brName << "\" out of type \"" << brProperTypeName
2303 << "\"");
2304 // Clean up:
2305 *(auxmgr->holder()->getPtr()) = 0;
2306 return StatusCode::FAILURE;
2307 }
2308 br = auxmgr->branch();
2309
2310 // Store it in the output list.
2311 objects[brName] = std::move(auxmgr);
2312
2313 } else {
2314
2315 // Check if we have a dictionary for this type:
2316 static constexpr Bool_t LOAD_IF_NOT_FOUND = kTRUE;
2317 static constexpr Bool_t SILENT = kTRUE;
2318 TClass* cl = TClass::GetClass(*brType, LOAD_IF_NOT_FOUND, SILENT);
2319 if (cl == nullptr) {
2320 // The dictionary needs to be loaded now. This could be an
2321 // issue. But let's hope for the best...
2322 cl = TClass::GetClass(brTypeName.c_str());
2323 // If still not found...
2324 if (cl == nullptr) {
2325 ATH_MSG_ERROR("Dictionary not available for variable \""
2326 << brName << "\" of type \"" << brTypeName << "\"");
2327 return StatusCode::FAILURE;
2328 }
2329 }
2330
2331 // The proper type name comes from the dictionary in this case:
2332 brProperTypeName = cl->GetName();
2333
2334 // Let's create a holder for this property:
2335 static constexpr bool IS_OWNER = false;
2336 auto auxmgr = std::make_unique<TAuxBranchManager>(
2337 id, nullptr, new THolder(aux->getIOData(id), cl, IS_OWNER));
2338
2339 // ... and let's add it to the output TTree.
2340 static constexpr Int_t BASKET_SIZE = 32000;
2341 static constexpr Int_t SPLIT_LEVEL = 0;
2342 *(auxmgr->branchPtr()) = outTree.Branch(brName.c_str(), cl->GetName(),
2343 auxmgr->holder()->getPtr(),
2344 BASKET_SIZE, SPLIT_LEVEL);
2345 if (!auxmgr->branch()) {
2346 ATH_MSG_ERROR("Failed to create branch \""
2347 << brName << "\" out of type \"" << brProperTypeName
2348 << "\"");
2349 // Clean up:
2350 *(auxmgr->holder()->getPtr()) = 0;
2351 return StatusCode::FAILURE;
2352 }
2353 br = auxmgr->branch();
2354
2355 // Store it in the output list.
2356 objects[brName] = std::move(auxmgr);
2357 }
2358
2359 // If this is not the first event, fill up the already filled
2360 // events with (empty) content:
2361 if (outTree.GetEntries()) {
2362 void* ptr = br->GetAddress();
2363 br->SetAddress(0);
2364 for (::Long64_t i = 0; i < outTree.GetEntries(); ++i) {
2365 br->Fill();
2366 }
2367 br->SetAddress(ptr);
2368 }
2369
2370 // If all went fine, let's add this branch to the event format
2371 // metadata:
2372 if (!m_outputEventFormat->exists(brName)) {
2373 m_outputEventFormat->add(EventFormatElement(brName, brProperTypeName,
2374 mgr->branch()->GetName(),
2375 getHash(brName)));
2376 }
2377
2378 // We don't need to do the rest:
2379 continue;
2380 }
2381
2382 // Access the object manager:
2383 bmgr = objects.find(brName);
2384 if (bmgr == objects.end()) {
2385 ATH_MSG_FATAL("There is an internal logic error in the code...");
2386 return StatusCode::FAILURE;
2387 }
2388
2389 // Replace the managed object:
2390 void* nc_data ATLAS_THREAD_SAFE = // we hold non-const pointers but check
2391 // on retrieve
2392 const_cast<void* >(static_cast<const void* >(aux->getIOData(id)));
2393 bmgr->second->setObject(nc_data);
2394 }
2395
2396 // Return gracefully:
2397 return StatusCode::SUCCESS;
2398}
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging).
static AuxTypeRegistry & instance()
Return the singleton registry instance.
virtual SG::auxid_set_t getSelectedAuxIDs() const
Get a list of dynamic variables that need to be written out.
Definition IAuxStoreIO.h:86
virtual const std::type_info * getIOType(SG::auxid_t auxid) const =0
Return the type of the data to be stored for one aux data item.
virtual const void * getIOData(SG::auxid_t auxid) const =0
Return a pointer to the data to be stored for one aux data item.
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition Event.h:360
int r
Definition globals.cxx:22
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
char rootType(char typeidType)
This function is used internally in the code when creating primitive dynamic auxiliary branches.
std::string getTypeName(const std::type_info &ti)
This function is necessary in order to create type names that ROOT can understand.

◆ pyContains()

bool xAOD::TPyEvent::pyContains ( const std::string & key,
const std::string & type )

Function checking if an object is available from the store.

Definition at line 64 of file TPyEvent.cxx.

64 {
65
66 // Try to access the dictionary of this type.
67 ::TClass* cl = ::TClass::GetClass(type.c_str());
68 if (cl == nullptr) {
69 ::Warning("xAOD::TPyEvent::pyContains", "Type name \"%s\" not known",
70 type.c_str());
71 return false;
72 }
73
74 // Check if the dictionary can return a type_info.
75 const std::type_info* ti = cl->GetTypeInfo();
76 if (ti == nullptr) {
77 ::Warning("xAOD::TPyEvent::pyContains",
78 "Type \"%s\" doesn't have a proper dictionary", type.c_str());
79 return false;
80 }
81
82 // Let the base class do the work.
83 static constexpr bool METADATA = false;
84 return TEvent::contains(key, *ti, METADATA);
85}

◆ pyRecord()

StatusCode xAOD::TPyEvent::pyRecord ( void * obj,
const std::string & key,
const std::string & type )

Add an output object to the event.

This function is designed to be callable from PyROOT in order to record hand-made containers into an output file.

Notice that unline TEvent::record(...), this function doesn't take ownership of the object that's given to it. That's because all objects created by the Python interpreter are garbage collected by the Python interpreter. And we don't want to run into double-deletes.

Parameters
objTypeless pointer to the object that is to be recorded
keyThe key with which the object is to be recorded
typeThe type name of the object being recorded
Returns
The usual StatusCode types

Definition at line 123 of file TPyEvent.cxx.

124 {
125
126 // Simply forward the call to the base class:
127 static constexpr bool OVERWRITE = false;
128 static constexpr bool METADATA = false;
129 static constexpr bool IS_OWNER = false;
130 RETURN_CHECK("xAOD::TPyEvent::pyRecord",
131 record(obj, type, key, OVERWRITE, METADATA, IS_OWNER));
132 // Return gracefully:
133 return StatusCode::SUCCESS;
134}
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition ReturnCheck.h:26
StatusCode record(void *obj, const std::string &typeName, const std::string &key, bool overwrite, bool metadata, bool isOwner) override
Record an object into a connected output file.

◆ pyRetrieve()

PyObject * xAOD::TPyEvent::pyRetrieve ( const std::string & key)

Return the object with a given key as a PyObject.

Definition at line 20 of file TPyEvent.cxx.

20 {
21
22 // Try to find the event format corresponding to this key.
23 const EventFormat* ef = this->inputEventFormat();
24 const EventFormatElement* efe = ((ef != nullptr) ? ef->get(key) : nullptr);
25 if (efe == nullptr) {
26 ef = this->outputEventFormat();
27 efe = ((ef != nullptr) ? ef->get(key) : nullptr);
28 if (efe == nullptr) {
29 // Fail if we can't find the type.
30 Py_INCREF(Py_None);
31 return Py_None;
32 }
33 }
34
35 // Convert the type to a std::type_info.
36 ::TClass* cl = TClass::GetClass(efe->className().c_str());
37 if (cl == nullptr) {
38 Py_INCREF(Py_None);
39 return Py_None;
40 }
41 const std::type_info* ti = cl->GetTypeInfo();
42 if (ti == nullptr) {
43 Py_INCREF(Py_None);
44 return Py_None;
45 }
46
47 // Get the object from the store as a void*.
48 static constexpr bool SILENT = true;
49 static constexpr bool METADATA = false;
51 const_cast<void*>(this->getInputObject(key, *ti, SILENT, METADATA));
52 if (obj == nullptr) {
53 obj = this->getOutputObject(key, *ti, METADATA);
54 }
55 if (obj == nullptr) {
56 Py_INCREF(Py_None);
57 return Py_None;
58 }
59
60 // Convert to a PyObject.
61 return TPython::CPPInstance_FromVoidPtr(obj, efe->className().c_str());
62}
const EventFormat * outputEventFormat() const
Get information about the output objects.
const EventFormat * inputEventFormat() const
Get information about the input objects.

◆ pyTransientContains()

bool xAOD::TPyEvent::pyTransientContains ( const std::string & key,
const std::string & type ) const

Function checking if an object is already in memory.

Definition at line 87 of file TPyEvent.cxx.

88 {
89
90 // Try to access the dictionary of this type.
91 ::TClass* cl = ::TClass::GetClass(type.c_str());
92 if (cl == nullptr) {
93 ::Warning("xAOD::TPyEvent::pyTransientContains",
94 "Type name \"%s\" not known", type.c_str());
95 return false;
96 }
97
98 // Check if the dictionary can return a type_info:
99 const std::type_info* ti = cl->GetTypeInfo();
100 if (ti == nullptr) {
101 ::Warning("xAOD::TPyEvent::pyTransientContains",
102 "Type \"%s\" doesn't have a proper dictionary", type.c_str());
103 return false;
104 }
105
106 // Let the base class do the work:
107 return TEvent::transientContains(key, *ti, kFALSE);
108}

◆ readFrom() [1/3]

StatusCode xAOD::TEvent::readFrom ( ::TFile & inFile)
overridevirtualinherited

Set up the reading of an input file from TFile This method implements the interface from Event.

Interface implementation for reading - forward to readFrom below.

Implements xAOD::Event.

Definition at line 114 of file Control/xAODRootAccess/Root/TEvent.cxx.

114 {
115 ATH_CHECK(readFrom(&inFile));
116 return StatusCode::SUCCESS;
117}

◆ readFrom() [2/3]

StatusCode xAOD::TEvent::readFrom ( ::TFile * file,
bool useTreeCache = true,
std::string_view treeName = EVENT_TREE_NAME )
inherited

This is the 'native' interface for reading from a TFile, allowing the specification of TTree cache use and the event tree name.

This function takes care of connecting the event object to a new input file.

It reads in the metadata of the input file needed for reading the file.

Parameters
filePointer to the file being read
useTreeCacheFlag for turning on/off the usage of TTreeCache
treeNameName of the input tree
Returns
The usual StatusCode tyoes

Definition at line 129 of file Control/xAODRootAccess/Root/TEvent.cxx.

130 {
131
132 // If no file was specified, return gracefully.
133 if (file == nullptr) {
134 ATH_MSG_DEBUG("No input file specified for readFrom(...)");
135 return StatusCode::SUCCESS;
136 }
137
138 // Clear the cached input objects.
139 m_inputObjects.clear();
140 m_inputMissingObjects.clear();
141 m_inputMetaObjects.clear();
142 {
144 lock.upgrade();
145 m_branches.clear();
146 }
147
148 // Reset the internal flags.
149 m_inTreeMissing = kFALSE;
150 m_entry = -1;
151
152 // Make sure we return to the current directory:
153 TDirectoryReset dr;
154
155 // Set up the file access tracer.
157
158 // Look for the metadata tree:
160 if (m_inMetaTree == nullptr) {
161 ATH_MSG_ERROR("Couldn't find metadata tree on input. Object is unusable!");
162 return StatusCode::FAILURE;
163 }
164
165 // Set metadata entry to be read
166 // NB: no reading is done calling LoadTree
167 if (m_inMetaTree->LoadTree(0) < 0) {
168 ATH_MSG_ERROR("Failed to load entry 0 for metadata tree");
169 return StatusCode::FAILURE;
170 }
171
172 // A sanity check.
173 if (m_inMetaTree->GetEntries() != 1) {
174 ATH_MSG_WARNING("Was expecting a metadata tree with size 1, instead of "
175 << m_inMetaTree->GetEntries() << ".");
176 ATH_MSG_WARNING("The input file was most probably produced by hadd...");
177 }
178
179 // Make sure that the xAOD::EventFormat dictonary is loaded.
180 // This may not be the case if streamer information reading is turned
181 // off.
182 static const std::string eventFormatTypeName =
184 ::TClass* cl = ::TClass::GetClass(eventFormatTypeName.c_str());
185 if (cl == nullptr) {
186 ATH_MSG_WARNING("Couldn't load the xAOD::EventFormat dictionary");
187 }
188
189 // Helper lambda for collecting the event format metadata from an RNTuple
190 // with a given name.
191 auto readEventFormatMetadata =
192 [&](std::string_view thisTreeName) -> StatusCode {
193 // Look for the metadata tree:
194 TTree* metaTree = file->Get<TTree>(thisTreeName.data());
195 if (metaTree == nullptr) {
196 ATH_MSG_ERROR("Couldn't find metadata tree \"" << thisTreeName
197 << "\"on input.");
198 return StatusCode::FAILURE;
199 }
200 // Set metadata entry to be read.
201 if (metaTree->LoadTree(0) < 0) {
202 ATH_MSG_ERROR("Failed to load entry 0 for metadata tree \""
203 << thisTreeName << "\"");
204 return StatusCode::FAILURE;
205 }
206
207 // Check if the EventFormat branch is available:
208 const std::string eventFormatBranchName =
210 if (!metaTree->GetBranch(eventFormatBranchName.c_str())) {
211 // This can happen when the file was produced by an Athena job that
212 // didn't have any input events itself. This means that the file
213 // doesn't actually have any useful metadata.
214 ATH_MSG_INFO("Input file provides no event or metadata");
215 return StatusCode::RECOVERABLE;
216 }
217
218 // Read in the event format object:
219 EventFormat* format = 0;
220 ::TBranch* br = 0;
221 const Int_t status =
222 metaTree->SetBranchAddress(eventFormatBranchName.c_str(), &format, &br);
223 if (status < 0) {
224 ATH_MSG_ERROR("Failed to connect to xAOD::EventFormat object");
225 return StatusCode::FAILURE;
226 }
227
228 // Merge the object into our private member.
229 br->GetEntry(0);
230 for (const auto &[key, element] : *format) {
231 m_inputEventFormat.add(element);
232 }
233
234 // This is a strange place. The object has to be deleted, as it is the
235 // responsibility of the user code to do so. But if I also explicitly
236 // tell the branch to forget about the address of the pointer, then
237 // all hell breaks loose...
238 delete format;
239
240 // Return gracefully.
241 return StatusCode::SUCCESS;
242 };
243
244 // Read in the metadata from the "main" metadata ntuple.
246 const StatusCode sc = readEventFormatMetadata(METADATA_OBJECT_NAME);
247 if (sc.isRecoverable()) {
248 m_inTree = nullptr;
249 m_inTreeMissing = true;
250 return StatusCode::SUCCESS;
251 }
252 ATH_CHECK(sc);
253
254 // List all the other Metadata trees in the input file
255 // Having several metatrees can happen for augmented files for instance
256 // as one metadata tree per stream is produced
257 std::set<std::string> lOtherMetaTreeNames = {};
258 TList* lKeys = file->GetListOfKeys();
259
260 if (lKeys) {
261 for (int iKey = 0; iKey < lKeys->GetEntries(); iKey++) {
262 // iterate over keys and add
263 std::string keyName = lKeys->At(iKey)->GetName();
264 // Make sure the key corresponds to a metadata tree but
265 // do not add the current metadata tree in the list of other trees
266 // and do not add the metadata tree handlers to the list
267 if ((keyName != METADATA_OBJECT_NAME) &&
268 std::regex_match(keyName, m_otherMetaDataTreeNamePattern)) {
269 // Make sure key corresponds to a tree
270 const char* className = ((::TKey* )lKeys->At(iKey))->GetClassName();
271 static constexpr Bool_t LOAD = kFALSE;
272 static constexpr Bool_t SILENT = kTRUE;
273 ::TClass* cl = ::TClass::GetClass(className, LOAD, SILENT);
274 if ((cl != nullptr) && cl->InheritsFrom(::TTree::Class())) {
275 // key is corresponding to a metadata tree
276 lOtherMetaTreeNames.insert(std::move(keyName));
277 }
278 }
279 }
280 }
281
282 // Loop over the other metadata trees found (if any).
283 for (const std::string &metaTreeName : lOtherMetaTreeNames) {
284 ATH_CHECK(readEventFormatMetadata(metaTreeName));
285 }
286
287 // Look for the event tree in the input file.
288 m_inTree = file->Get<TTree>(treeName.data());
289 if (m_inTree == nullptr) {
290 // This is no longer an error condition. As it can happen for DxAODs
291 // that don't have any events in them. But they still have metadata
292 // that needs to be collected.
293 m_inTreeMissing = kTRUE;
294 }
295
296 // Turn on the cache if requested.
297 if (m_inTree && useTreeCache && (!m_inTree->GetCacheSize())) {
298 m_inTree->SetCacheSize(CACHE_SIZE);
299 m_inTree->SetCacheLearnEntries(10);
300 }
301
302 // Init the statistics collection.
304 // Update the event counter in the statistics object.
305 xAOD::ReadStats &stats = IOStats::instance().stats();
306 if (m_inTree) {
307 stats.setNEvents(stats.nEvents() + m_inTree->GetEntries());
308 }
309
310 // Notify the listeners that a new file was opened.
311 const TIncident beginIncident(IncidentType::BeginInputFile);
312 for (TVirtualIncidentListener* listener : m_listeners) {
313 listener->handle(beginIncident);
314 }
315 // For now implement a very simple scheme in which we claim already
316 // at the start that the entire file was processed. Since we have no way
317 // of ensuring that the user indeed does this. And we can't delay calling
318 // this function, as the user may likely close his/her output file before
319 // closing the last opened input file.
320 const TIncident endIncident(IncidentType::EndInputFile);
321 for (TVirtualIncidentListener* listener : m_listeners) {
322 listener->handle(endIncident);
323 }
324
325 // The initialisation was successful.
326 return StatusCode::SUCCESS;
327}
StatusCode initStats()
Function to initialise the statistics for all Tree content.
void add(std::string_view fileName)
Add information about a new file that got accessed.
static TFileAccessTracer & instance()
Access the singleton instance of this class.
static const ::Int_t EndInputFile
The processing of an input file has finished.
Definition TIncident.h:40
static const ::Int_t BeginInputFile
A new input file was just opened.
Definition TIncident.h:27
std::string getFirstBranchMatch(TTree *tree, const std::string &pre)
This function is used to search for a branch in a TTree that contains a given substring.
static const ::Int_t CACHE_SIZE
Size of a possible TTreeCache.

◆ readFrom() [3/3]

StatusCode xAOD::TEvent::readFrom ( ::TTree * tree,
bool useTreeCache = true )
inherited

Connect the object to a new input tree/chain.

This version of the function sets up the object to read information from a tree/chain.

Using it with a TTree pointer makes not much sense, but using it with a TChain pointer could be a very valid usage mode.

Parameters
treeThe pointer to a TTree or a TChain
useTreeCacheFlag for switching TTreeCache usage on/off
Returns
The usual StatusCode tyoes

Definition at line 337 of file Control/xAODRootAccess/Root/TEvent.cxx.

337 {
338
339 // Remember the info:
340 m_inTree = nullptr;
341 m_inTreeMissing = false;
342 m_inChain = dynamic_cast<TChain* >(tree);
343 m_inMetaTree = nullptr;
344
345 if (m_inChain) {
346
347 // Set up the caching on the chain level. The individual trees of the
348 // input files will get a cache set up automatically after this.
349 if (useTreeCache && (!m_inChain->GetCacheSize())) {
350 m_inChain->SetCacheSize(CACHE_SIZE);
351 m_inChain->SetCacheLearnEntries(10);
352 }
353
354 // Explicitly open the first file of the chain. To correctly auto-load
355 // the dictionaries necessary. This doesn't happen automatically with
356 // some ROOT versions...
357 const TObjArray* files = m_inChain->GetListOfFiles();
358 if (!files) {
359 ATH_MSG_ERROR("Couldn't get the list of files from the input TChain");
360 return StatusCode::FAILURE;
361 }
362 if (!files->GetEntries()) {
363 ATH_MSG_ERROR("No files are present in the received TChain");
364 return StatusCode::FAILURE;
365 }
366 const ::TChainElement* chEl =
367 dynamic_cast<const ::TChainElement* >(files->At(0));
368 if (!chEl) {
369 ATH_MSG_ERROR("Couldn't cast object to TChainElement");
370 return StatusCode::FAILURE;
371 }
372 {
373 std::unique_ptr<TFile> dummyFile{TFile::Open(chEl->GetTitle())};
374 if (!dummyFile) {
375 ATH_MSG_ERROR("Couldn't open file " << chEl->GetTitle());
376 return StatusCode::FAILURE;
377 }
378 }
379
380 // Set up a tracker for the chain.
381 if (!m_inChainTracker) {
382 m_inChainTracker = std::make_unique<TChainStateTracker>();
383 }
384 m_inChainTracker->reset();
385 tree->SetNotify(m_inChainTracker.get());
386
387 // Stop at this point. The first file will be opened when the user
388 // asks for the first event. Otherwise we open the first file of the
389 // chain multiple times.
390 m_inTreeNumber = -1;
391 return StatusCode::SUCCESS;
392
393 } else {
394
395 // If it's a simple TTree, then let's fully initialise the object
396 // using its file:
397 m_inTreeNumber = -1;
398 if (m_inChainTracker) {
399 m_inChainTracker.reset();
400 }
401 ::TFile* file = tree->GetCurrentFile();
402 return readFrom(file, useTreeCache, tree->GetName());
403 }
404}
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:52
TChain * tree

◆ record() [1/4]

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

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

◆ record() [2/4]

StatusCode xAOD::TEvent::record ( std::unique_ptr< TAuxStore > store,
const std::string & key )
protectedinherited

Internal function for adding an auxiliary store object to the output.

This function is used internally when copying an object with its auxiliary store from the input file, and branch access mode is activated for the event object.

The assumption is that the store object already knows what prefix it should be using. The key parameter only specifies under what ID the object should be handled in the output object list.

Parameters
storeThe store object to connect to the output
keyThe "key" with which to record the object
Returns
The usual StatusCode tyoes

Definition at line 2019 of file Control/xAODRootAccess/Root/TEvent.cxx.

2020 {
2021
2022 // Check if we have an output tree:
2023 if (!m_outTree) {
2025 "No output tree defined. Did you forget to call writeTo(...)?");
2026 return StatusCode::FAILURE;
2027 }
2028
2029 // Check if we have a filtering rule for this key:
2030 const std::set<std::string>* filter = 0;
2031 auto filter_itr = m_auxItemList.find(key);
2032 if (filter_itr != m_auxItemList.end()) {
2033 filter = &(filter_itr->second);
2034 }
2035
2036 // Check if we need to add it to the event record:
2037 Object_t::iterator vitr = m_outputObjects.find(key);
2038 if (vitr == m_outputObjects.end()) {
2039
2040 // Configure the object for variable filtering:
2041 if (filter) {
2042 store->selectAux(*filter);
2043 }
2044 // Tell the object where to write its contents:
2045 ATH_CHECK(store->writeTo(*m_outTree));
2046 // Record it to the output list:
2047 static constexpr bool OWNS_STORE = true;
2049 std::make_unique<TAuxManager>(store.release(), OWNS_STORE);
2050
2051 // We're done:
2052 return StatusCode::SUCCESS;
2053 }
2054
2055 // Check if the output has the right store:
2056 if (vitr->second->object() == store.get()) {
2057 // We're done already:
2058 return StatusCode::SUCCESS;
2059 }
2060
2061 // If not, update the output manager. This can happen when we copy
2062 // objects from the input to the output files, and we process
2063 // multiple input files.
2064
2065 // Check if the output manager is of the right type:
2066 TAuxManager* mgr = dynamic_cast<TAuxManager* >(vitr->second.get());
2067 if (mgr == nullptr) {
2068 ATH_MSG_ERROR("Output object with key \""
2069 << key << "\" already exists, and is not of type TAuxStore");
2070 return StatusCode::FAILURE;
2071 }
2072
2073 // Configure the object for variable filtering:
2074 if (filter) {
2075 store->selectAux(*filter);
2076 }
2077
2078 // Connect the auxiliary store to the output tree:
2079 ATH_CHECK(store->writeTo(*m_outTree));
2080
2081 // Update the manager:
2082 mgr->setObject(store.release());
2083
2084 // Return gracefully:
2085 return StatusCode::SUCCESS;
2086}

◆ record() [3/4]

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

Add an output object to the event.

◆ record() [4/4]

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

Record an object into a connected output file.

This is the function doing the heavy lifting when recording a new object into the output tree/file.

It makes sure that the object is saved together with all of its dynamic auxiliary data if it has any.

Parameters
objA typeless pointer to the object that we want to record
typeNameThe type name of the output object
keyThe key (branch name) of the object to record
overwriteFlag selecting if it is allowed to overwrite an already existing object (used internally)
metadataFlag selecting if we are writing an event or a metadata object
isOwnerFlag selecting if we should take ownership of the object or not
Returns
The usual StatusCode tyoes

Implements xAOD::Event.

Definition at line 1693 of file Control/xAODRootAccess/Root/TEvent.cxx.

1695 {
1696
1697 // Check if we have an output tree when writing an event:
1698 if (!m_outTree && !metadata) {
1700 "No output tree defined. Did you forget to call writeTo(...)?");
1701 return StatusCode::FAILURE;
1702 }
1703 assert(m_outputEventFormat != 0);
1704
1705 // If this is metadata, just take ownership of it. The object will only
1706 // be recorded into the output file when calling finishWritingTo(...).
1707 if (metadata) {
1708 // Check whether we already have such an object:
1709 if ((!overwrite) &&
1710 (m_outputMetaObjects.find(key) != m_outputMetaObjects.end())) {
1711 ATH_MSG_ERROR("Meta-object \"" << typeName << "\"/\"" << key
1712 << "\" already recorded");
1713 return StatusCode::FAILURE;
1714 }
1715 // Check if we have a dictionary for this object:
1716 TClass* cl = TClass::GetClass(typeName.c_str());
1717 if (!cl) {
1718 ATH_MSG_ERROR("Didn't find dictionary for type: " << typeName);
1719 return StatusCode::FAILURE;
1720 }
1721 // Let's create a holder for the object:
1722 const bool renewOnRead = (m_auxMode == kAthenaAccess);
1723 m_outputMetaObjects[key] = std::make_unique<TObjectManager>(
1724 nullptr, std::make_unique<THolder>(obj, cl, isOwner), renewOnRead);
1725 // We're done. The rest will be done later on.
1726 return StatusCode::SUCCESS;
1727 }
1728
1729 // Check if we accessed this object on the input. If yes, then this
1730 // key may not be used for recording.
1731 if ((!overwrite) && (m_inputObjects.find(key) != m_inputObjects.end())) {
1732 ATH_MSG_ERROR("Object \"" << typeName << "\"/\"" << key
1733 << "\" already accessed from the input, can't be "
1734 "overwritten in memory");
1735 return StatusCode::FAILURE;
1736 }
1737
1738 // Choose a split level.
1739 const Int_t splitLevel = (key.ends_with("Aux.") ? 1 : 0);
1740
1741 // Check if we need to add it to the event record:
1742 Object_t::iterator vitr = m_outputObjects.find(key);
1743 if (vitr == m_outputObjects.end()) {
1744
1745 // Check if we have a dictionary for this object:
1746 TClass* cl = TClass::GetClass(typeName.c_str());
1747 if (cl == nullptr) {
1748 ATH_MSG_ERROR("Didn't find dictionary for type: " << typeName);
1749 return StatusCode::FAILURE;
1750 }
1751
1752 // Check if this is a new object "type" or not.
1753 if (!m_outputEventFormat->exists(key)) {
1755 EventFormatElement(key, cl->GetName(), "", getHash(key)));
1756 }
1757
1758 // Let's create a holder for the object.
1759 const bool renewOnRead = (m_auxMode == kAthenaAccess);
1760 auto mgr = std::make_unique<TObjectManager>(
1761 nullptr, std::make_unique<THolder>(obj, cl, isOwner), renewOnRead);
1762 TObjectManager* mgrPtr = mgr.get();
1763 m_outputObjects[key] = std::move(mgr);
1764
1765 // ... and let's add it to the output TTree.
1766 static constexpr Int_t basketSize = 32000;
1767 *(mgrPtr->branchPtr()) =
1768 m_outTree->Branch(key.c_str(), cl->GetName(),
1769 mgrPtr->holder()->getPtr(), basketSize, splitLevel);
1770 if (!mgrPtr->branch()) {
1771 ATH_MSG_ERROR("Failed to create branch \"" << key << "\" out of type \""
1772 << cl->GetName() << "\"");
1773 // Clean up:
1774 mgrPtr->holder()->setOwner(kFALSE);
1775 return StatusCode::FAILURE;
1776 }
1777
1778 // Set up the saving of all the dynamic auxiliary properties
1779 // of the object if it has any:
1780 static constexpr bool METADATA = false;
1781 ATH_CHECK(putAux(*m_outTree, *mgrPtr, METADATA));
1782
1783 // Return at this point, as we don't want to run the rest of
1784 // the function's code:
1785 return StatusCode::SUCCESS;
1786 }
1787
1788 // Access the object manager:
1789 TObjectManager* omgr = dynamic_cast<TObjectManager* >(vitr->second.get());
1790 if (!omgr) {
1791 ATH_MSG_ERROR("Manager object of the wrong type encountered");
1792 return StatusCode::FAILURE;
1793 }
1794
1795 // Check that the type of the object matches that of the previous
1796 // object:
1797 if (typeName != omgr->holder()->getClass()->GetName()) {
1798 // This may still be, when the ROOT dictionary name differs from the
1799 // "simple type name" known to C++. So let's get the ROOT name of the
1800 // new type:
1801 TClass* cl = TClass::GetClass(typeName.c_str());
1802 if ((!cl) ||
1803 ::strcmp(cl->GetName(), omgr->holder()->getClass()->GetName())) {
1804 ATH_MSG_ERROR("For output key \""
1805 << key << "\" the previous type was \""
1806 << omgr->holder()->getClass()->GetName()
1807 << "\", but the newly requested type is \"" << typeName
1808 << "\"");
1809 return StatusCode::FAILURE;
1810 }
1811 }
1812
1813 // Replace the managed object.
1814 omgr->setObject(obj);
1815
1816 // Replace the auxiliary objects.
1817 static constexpr bool METADATA = false;
1818 ATH_CHECK(putAux(*m_outTree, *omgr, METADATA));
1819
1820 // Return gracefully.
1821 return StatusCode::SUCCESS;
1822}

◆ recordAux() [1/3]

SG::IAuxStore * xAOD::TEvent::recordAux ( const std::string & key,
SG::IAuxStoreHolder::AuxStoreType type = SG::IAuxStoreHolder::AST_ContainerStore )
inherited

Add an auxiliary store object to the output.

This function can be used to create/retrieve a ROOT-specific auxiliary object container that can be used to write information in the output file.

Any auxiliary information written this way will however only be readable in ROOT, using the kBranchAccess option.

Parameters
keyThe name/prefix of the auxiliary store object/branches
typeThe type of the auxiliary store (object/container)
Returns
An auxiliary store object that will write to the output

Definition at line 594 of file Control/xAODRootAccess/Root/TEvent.cxx.

595 {
596
597 // A sanity check:
598 if (!m_outTree) {
599 ATH_MSG_ERROR("No output tree given to the object");
600 return nullptr;
601 }
602
603 // Check for an object with this name in the output list:
604 Object_t::iterator itr = m_outputObjects.find(key);
605 if (itr == m_outputObjects.end()) {
606 // Create one if if it doesn't exist yet...
607 // Translate the store type:
609 switch (type) {
612 break;
615 break;
616 default:
617 ATH_MSG_ERROR("Unknown store type (" << type << ") requested");
618 return nullptr;
619 }
620 // Create and record the object:
621 static constexpr bool TOP_STORE = true;
622 if (record(std::make_unique<TAuxStore>(this->currentContext(),
623 key, TOP_STORE, mode), key)
624 .isFailure()) {
625 ATH_MSG_ERROR("Couldn't connect TAuxStore object to the output");
626 return nullptr;
627 }
628 // Update the iterator:
629 itr = m_outputObjects.find(key);
630 }
631
632 // A security check:
633 if (itr == m_outputObjects.end()) {
634 ATH_MSG_ERROR("Internal logic error detected");
635 return nullptr;
636 }
637
638 // Check that it is of the right type:
639 TAuxManager* mgr = dynamic_cast<TAuxManager* >(itr->second.get());
640 if (!mgr) {
641 ATH_MSG_ERROR("Internal logic error detected");
642 return nullptr;
643 }
644
645 // Extract the pointer out of it:
646 TAuxStore* store = mgr->getStore();
647
648 // Give it to the user:
649 return store;
650}
@ AST_ContainerStore
The store describes a container.
@ AST_ObjectStore
The store describes a single object.
@ kUndefinedStore
The structure mode is not defined.

◆ recordAux() [2/3]

StatusCode xAOD::TEvent::recordAux ( TAuxStore * store,
const std::string & key )
protectedinherited

Function setting up an existing auxiliary store for writing.

Definition at line 2400 of file Control/xAODRootAccess/Root/TEvent.cxx.

2400 {
2401
2402 // Check if we have an output tree:
2403 if (hasOutput() == false) {
2404 ATH_MSG_ERROR("No output tree set up.");
2405 return StatusCode::FAILURE;
2406 }
2407
2408 // Check if we have a filtering rule for this key:
2409 const std::set<std::string>* filter = 0;
2410 auto filter_itr = m_auxItemList.find(key);
2411 if (filter_itr != m_auxItemList.end()) {
2412 filter = &(filter_itr->second);
2413 }
2414
2415 // Check if we need to add it to the event record:
2416 Object_t::iterator vitr = m_outputObjects.find(key);
2417 if (vitr == m_outputObjects.end()) {
2418
2419 // Configure the object for variable filtering:
2420 if (filter) {
2421 store->selectAux(*filter);
2422 }
2423 // Tell the object where to write its contents:
2424 ATH_CHECK(store->writeTo(*m_outTree));
2425 // Record it to the output list.
2426 static constexpr bool OWNS_STORE = false;
2427 m_outputObjects[key] = std::make_unique<TAuxManager>(store, OWNS_STORE);
2428
2429 // We're done:
2430 return StatusCode::SUCCESS;
2431 }
2432
2433 // Check if the output has the right store:
2434 if (vitr->second->object() == store) {
2435 // We're done already:
2436 return StatusCode::SUCCESS;
2437 }
2438
2439 // If not, update the output manager. This can happen when we copy
2440 // objects from the input to the output files, and we process
2441 // multiple input files.
2442
2443 // Check if the output manager is of the right type:
2444 TAuxManager* mgr = dynamic_cast<TAuxManager* >(vitr->second.get());
2445 if (mgr == nullptr) {
2446 ATH_MSG_ERROR("Output object with key \""
2447 << key << "\" already exists, and is not of type TAuxStore");
2448 return StatusCode::FAILURE;
2449 }
2450
2451 // Configure the object for variable filtering:
2452 if (filter) {
2453 store->selectAux(*filter);
2454 }
2455
2456 // Connect the auxiliary store to the output tree:
2457 ATH_CHECK(store->writeTo(*m_outTree));
2458
2459 // Update the manager:
2460 mgr->setObject(store);
2461
2462 // Return gracefully:
2463 return StatusCode::SUCCESS;
2464}
bool hasOutput() const override
Check if an output file is connected to the object.

◆ recordAux() [3/3]

StatusCode xAOD::TEvent::recordAux ( TVirtualManager & mgr,
const std::string & key,
bool metadata )
overrideprotectedvirtualinherited

Record an auxiliary store into a connected output file.

Implements xAOD::Event.

Definition at line 1824 of file Control/xAODRootAccess/Root/TEvent.cxx.

1825 {
1826
1827 // Check if the auxiliary store is a generic object.
1828 Details::IObjectManager* iomgr = dynamic_cast<Details::IObjectManager*>(&mgr);
1829 if (iomgr != nullptr) {
1830 // Record the auxiliary object using the main record function.
1831 static const bool OVERWRITE = true;
1832 static const bool IS_OWNER = true;
1833 ATH_CHECK(record(iomgr->object(), iomgr->holder()->getClass()->GetName(),
1834 key, OVERWRITE, metadata, IS_OWNER));
1835 return StatusCode::SUCCESS;
1836 }
1837
1838 // Check if it's a TAuxStore object.
1839 TAuxManager* auxmgr = dynamic_cast<TAuxManager* >(&mgr);
1840 if (auxmgr != nullptr) {
1841 // This type has to be an event object.
1842 if (metadata) {
1844 "TAuxStore auxiliary objects can only be recorded for event data");
1845 return StatusCode::FAILURE;
1846 }
1847 // Record the auxiliary object with the dedicated record function.
1848 ATH_CHECK(recordAux(auxmgr->getStore(), key));
1849 return StatusCode::SUCCESS;
1850 }
1851
1852 // Apparently we didn't recorgnize the auxiliary store type.
1853 ATH_MSG_ERROR("Unknown auxiliary store manager type encountered");
1854 return StatusCode::FAILURE;
1855}
SG::IAuxStore * recordAux(const std::string &key, SG::IAuxStoreHolder::AuxStoreType type=SG::IAuxStoreHolder::AST_ContainerStore)
Add an auxiliary store object to the output.

◆ recordMeta() [1/2]

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

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 )
inherited

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 )
overrideprotectedinherited

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 )
protectedinherited

Internal function for recording an object into the output.

◆ registerKey()

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

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)
inherited

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 130 of file EventCore.cxx.

130 {
131
132 // Remove the listener. Or at least try to...
133 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
134 if (itr == m_listeners.end()) {
135 ATH_MSG_ERROR("Listener " << static_cast<void*>(listener) << " not known");
136 return StatusCode::FAILURE;
137 }
138 m_listeners.erase(itr);
139
140 // Return gracefully:
141 return StatusCode::SUCCESS;
142}

◆ retrieve() [1/4]

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

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 )
inherited

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 )
inherited

Retrieve an input metadata object.

◆ retrieveMetaOutput() [1/2]

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

Retrieve an output metadata object.

◆ retrieveMetaOutput() [2/2]

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

Retrieve an output metadata object.

◆ setActive()

void Event::setActive ( ) const
inherited

Set this event object as the currently active one.

Definition at line 57 of file EventCore.cxx.

57 {
58
59 // The active event and current store are thread-local globals.
60 Event* nc_this ATLAS_THREAD_SAFE = const_cast<Event*>(this);
61 TActiveEvent::setEvent(static_cast<TVirtualEvent*>(nc_this));
62#ifndef XAOD_STANDALONE
63 SG::CurrentEventStore::setStore(nc_this);
65#endif // not XAOD_STANDALONE
66}
static void setEvent(TVirtualEvent *ptr)
Set the active event pointer.
void setProxyDictInEventContext(IProxyDict *sg)
Update the IProxyDict in the current EventContext.

◆ setAuxItemList()

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

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 75 of file EventCore.cxx.

76 {
77
78 // Decoded attributes.
79 std::set<std::string> attributes;
80
81 // Split up the received string using "." as the separator.
82 if (itemList.size()) {
83 std::istringstream ss(itemList);
84 std::string attr;
85 while (std::getline(ss, attr, '.')) {
86 attributes.insert(attr);
87 }
88 }
89
90 // Remember the setting.
91 m_auxItemList[containerKey] = std::move(attributes);
92}
static Double_t ss

◆ setAuxStore()

StatusCode xAOD::TEvent::setAuxStore ( const std::string & key,
Details::IObjectManager & mgr,
bool metadata )
overrideprotectedvirtualinherited

Function connecting a DV object to its auxiliary store.

Every time a DataVector is read in from the input for a new TTree entry, one needs to re-connect it with its auxiliary store.

This function takes care of this.

Parameters
mgrThe manager object of the DV container
metadataFlag specifying whether we're dealing with a metadata or event data object
Returns
The usual StatusCode types

Implements xAOD::Event.

Definition at line 1500 of file Control/xAODRootAccess/Root/TEvent.cxx.

1501 {
1502
1503 // Pre-compute some values.
1504 const bool isAuxStore = Details::isAuxStore(*(mgr.holder()->getClass()));
1505
1506 // Check if we need to do anything.
1507 if ((Details::hasAuxStore(*(mgr.holder()->getClass())) == false) &&
1508 (isAuxStore == false)) {
1509 return StatusCode::SUCCESS;
1510 }
1511
1512 // Select which object container to use:
1514
1515 // Look up the auxiliary object's manager:
1516 TVirtualManager* auxMgr = nullptr;
1517 std::string auxKey;
1518 if (isAuxStore) {
1519 auxMgr = &mgr;
1520 auxKey = key;
1521 } else {
1522 auto itr = objects.find(key + "Aux.");
1523 if (itr == objects.end()) {
1524 // Apparently there's no auxiliary object for this DV, so let's
1525 // give up:
1526 return StatusCode::SUCCESS;
1527 }
1528 auxMgr = itr->second.get();
1529 auxKey = key + "Aux.";
1530 }
1531
1532 if (metadata == false) {
1533 // Make sure the auxiliary object is up to date:
1534 const ::Int_t readBytes = auxMgr->getEntry();
1535 if (readBytes < 0) {
1537 "Couldn't load current entry for auxiliary object with key \""
1538 << auxKey << "\"");
1539 return StatusCode::FAILURE;
1540 }
1541
1542 // Check if there is a separate auxiliary object for the dynamic
1543 // variables:
1544 const std::string dynAuxKey = auxKey + "Dynamic";
1545 auto dynAuxMgr = objects.find(dynAuxKey);
1546
1547 if ((dynAuxMgr != objects.end()) &&
1548 (readBytes || (m_auxMode == kAthenaAccess) || (auxMgr == &mgr))) {
1549 // Do different things based on the access mode:
1550 if (m_auxMode != kAthenaAccess) {
1551 // In "normal" access modes just tell the dynamic store object
1552 // to switch to a new event.
1553 dynAuxMgr->second->getEntry();
1554 } else {
1555 // In "Athena mode" this object has already been deleted when
1556 // the main auxiliary store object was switched to the new
1557 // event. So let's re-create it:
1558 xAOD::TObjectManager &auxMgrRef =
1559 dynamic_cast<xAOD::TObjectManager &>(*auxMgr);
1560 ATH_CHECK(
1561 setUpDynamicStore(auxMgrRef, (metadata ? m_inMetaTree : m_inTree)));
1562 // Now tell the newly created dynamic store object which event
1563 // it should be looking at:
1564 auto dynAuxMgr = objects.find(dynAuxKey);
1565 if (dynAuxMgr == objects.end()) {
1566 ATH_MSG_ERROR("Internal logic error detected");
1567 return StatusCode::FAILURE;
1568 }
1569 dynAuxMgr->second->getEntry();
1570 }
1571 }
1572 }
1573
1574 // Stop here if we've set up an auxiliary store.
1575 if (isAuxStore) {
1576 return StatusCode::SUCCESS;
1577 }
1578
1579 // Access the auxiliary base class of the object/vector:
1580 SG::AuxVectorBase* vec = 0;
1581 SG::AuxElement* aux = 0;
1582 switch (mgr.holder()->typeKind()) {
1583 case THolder::DATAVECTOR: {
1584 void* vvec = mgr.holder()->getAs(typeid(SG::AuxVectorBase));
1585 vec = reinterpret_cast<SG::AuxVectorBase*>(vvec);
1586 } break;
1587 case THolder::AUXELEMENT: {
1588 void* vaux = mgr.holder()->getAs(typeid(SG::AuxElement));
1589 aux = reinterpret_cast<SG::AuxElement*>(vaux);
1590 } break;
1591 default:
1592 break;
1593 }
1594
1595 // Check whether index tracking is enabled for the type. If not, then
1596 // we need to fix it...
1597 if (vec && (!vec->trackIndices())) {
1598 Details::forceTrackIndices(*vec);
1599 }
1600
1601 // Check if we were successful:
1602 if ((!vec) && (!aux)) {
1603 ATH_MSG_FATAL("Couldn't access class \""
1604 << mgr.holder()->getClass()->GetName()
1605 << "\" as SG::AuxVectorBase or SG::AuxElement");
1606 return StatusCode::FAILURE;
1607 }
1608
1609 // Get the auxiliary store object:
1610 const SG::IConstAuxStore* store = 0;
1611#ifndef XAOD_STANDALONE
1612 SG::IAuxStore* store_nc = 0;
1613#endif
1614 if (m_auxMode == kBranchAccess) {
1615 // Get the concrete auxiliary manager:
1616 TAuxManager* amgr = dynamic_cast<TAuxManager* >(auxMgr);
1617 if (!amgr) {
1618 ATH_MSG_FATAL("Auxiliary manager for \""
1619 << auxKey << "\" is not of the right type");
1620 return StatusCode::FAILURE;
1621 }
1622 store = amgr->getConstStore();
1623 // If the store still doesn't know its type, help it now:
1624 if (amgr->getStore()->structMode() ==
1629 amgr->getStore()->setStructMode(mode);
1630 }
1631#ifndef XAOD_STANDALONE
1632 store_nc = amgr->getStore();
1633#endif
1634 } else if (m_auxMode == kClassAccess || m_auxMode == kAthenaAccess) {
1635 // Get the concrete auxiliary manager:
1636 TObjectManager* omgr = dynamic_cast<TObjectManager* >(auxMgr);
1637 if (!omgr) {
1638 ATH_MSG_FATAL("Auxiliary manager for \""
1639 << auxKey << "\" is not of the right type");
1640 return StatusCode::FAILURE;
1641 }
1642 void* p = omgr->holder()->getAs(typeid(SG::IConstAuxStore));
1643 SG::IConstAuxStore* store1 = reinterpret_cast<SG::IConstAuxStore* >(p);
1644 store = store1;
1645#ifndef XAOD_STANDALONE
1646 store_nc = dynamic_cast<SG::IAuxStore*>(store1);
1647#endif
1648 }
1649 if (!store) {
1650 ATH_MSG_FATAL("Logic error detected in the code");
1651 return StatusCode::FAILURE;
1652 }
1653
1654#ifndef XAOD_STANDALONE
1655 // Call toTransient on the aux store.
1656 if (store_nc)[[likely]] {
1657 store_nc->toTransient( this->currentContext() );
1658 } else {
1659 ATH_MSG_FATAL("Logic error detected in the code");
1660 return StatusCode::FAILURE;
1661 }
1662#endif
1663
1664 // Connect the two:
1665 if (vec) {
1666 vec->setStore(store);
1667 } else if (aux) {
1668 aux->setStore(store);
1669 } else {
1670 ATH_MSG_FATAL("Logic error detected in the code");
1671 return StatusCode::FAILURE;
1672 }
1673
1674 // We succeeded:
1675 return StatusCode::SUCCESS;
1676}
std::vector< size_t > vec
virtual void toTransient(const EventContext &ctx)=0
Perform post-read processing on this store.
@ DATAVECTOR
A DataVector container.
Definition THolder.h:105
@ AUXELEMENT
A type inheriting from SG::AuxElement.
Definition THolder.h:106
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
#define likely(x)

◆ 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}

◆ setOtherMetaDataTreeNamePattern()

void xAOD::TEvent::setOtherMetaDataTreeNamePattern ( const std::string & pattern)
inherited

Change the pattern used for collecting information from other MetaData trees NB: Additional MetaData trees are only expected for augmented files This function also allows user to redefine MetaData tree pattern to skip trees that would not be proper MetaData ones i.e.

trees not containing an EventFormat* branch

Definition at line 105 of file Control/xAODRootAccess/Root/TEvent.cxx.

105 {
106 // Only change if pattern provided is not empty
107 if (pattern.size()) {
108 // User provided a regular expression for other MetaData trees
109 m_otherMetaDataTreeNamePattern = std::regex(pattern);
110 }
111}

◆ setUpDynamicStore()

StatusCode xAOD::TEvent::setUpDynamicStore ( TObjectManager & mgr,
::TTree * tree )
protectedinherited

Function adding dynamic variable reading capabilities to an auxiliary store object.

This function is used by connectBranch(...) and connectMetaBranch(...) to set up auxiliary store type objects correctly for accessing dynamic variables from the input file.

Parameters
mgrThe object manager of the auxiliary store object
treeThe tree to read dynamic variables from
Returns
The usual StatusCode types

Definition at line 2096 of file Control/xAODRootAccess/Root/TEvent.cxx.

2096 {
2097
2098 // Check if we can call setName(...) on the object:
2099 ::TMethodCall setNameCall;
2100 // Don't use this code in Athena access mode. And just accept that access
2101 // monitoring is disabled in this case...
2102 if (m_auxMode != kAthenaAccess) {
2103 setNameCall.InitWithPrototype(mgr.holder()->getClass(), "setName",
2104 "const char*");
2105 if (setNameCall.IsValid()) {
2106 // Yes, there is such a function. Let's call it with the branch
2107 // name:
2108 const ::TString params =
2109 ::TString::Format("\"%s\"", mgr.branch()->GetName());
2110 const char* charParams = params.Data();
2111 setNameCall.Execute(mgr.holder()->get(), charParams);
2112 } else {
2113 // This is weird. What sort of auxiliary container is this? :-/
2114 ATH_MSG_WARNING("Couldn't find setName(...) function for container \""
2115 << mgr.branch()->GetName() << "\" (type: "
2116 << mgr.holder()->getClass()->GetName() << ")");
2117 }
2118 }
2119
2120 // Check if we can switch out the internal store of this object:
2121 static const TClass* const holderClass =
2122 TClass::GetClass(typeid(SG::IAuxStoreHolder));
2123 if (!mgr.holder()->getClass()->InheritsFrom(holderClass)) {
2124 // Nope... So let's just end the journey here.
2125 return StatusCode::SUCCESS;
2126 }
2127
2128 // Try to get the object as an IAuxStoreHolder:
2129 SG::IAuxStoreHolder* storeHolder = reinterpret_cast<SG::IAuxStoreHolder* >(
2130 mgr.holder()->getAs(typeid(SG::IAuxStoreHolder)));
2131 if (!storeHolder) {
2132 ATH_MSG_FATAL("There's a logic error in the code");
2133 return StatusCode::FAILURE;
2134 }
2135
2136 // Create a TAuxStore instance that will read the dynamic variables
2137 // of this container. Notice that the TAuxManager doesn't own the
2138 // TAuxStore object. It will be owned by the SG::IAuxStoreHolder
2139 // object.
2140 static constexpr bool TOP_STORE = false;
2141 const EventContext& ctx = this->currentContext();
2142 auto store = std::make_unique<TAuxStore>(
2143 ctx, mgr.branch()->GetName(), TOP_STORE,
2147 // This object is used to read data from the input, it needs to be
2148 // locked:
2149 store->lock();
2150
2151 // Set it up to read from the input TTree.
2152 ATH_CHECK(store->readFrom(*tree));
2153 // Tell the auxiliary store which entry to use. This is essential for
2154 // metadata objects, and non-important for event data objects, which will
2155 // get a possibly different entry loaded in setAuxStore(...).
2156 store->getEntry(0);
2157
2158 // Set up a manager for it.
2159 static constexpr bool SHARED_OWNER = false;
2160 m_inputObjects[std::string(mgr.branch()->GetName()) + "Dynamic"] =
2161 std::make_unique<TAuxManager>(store.get(), SHARED_OWNER);
2162
2163 // Give this object to the store holder:
2164 storeHolder->setStore(store.release());
2165
2166 // Return gracefully:
2167 return StatusCode::SUCCESS;
2168}
virtual AuxStoreType getStoreType() const =0
Return the type of the store object.
virtual void setStore(IAuxStore *store)=0
Give an auxiliary store object to the holder object.

◆ stringToKey()

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

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
inherited

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
protectedinherited

Internal function checking if an object is already in memory.

◆ transientContainsMeta()

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

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

◆ writeTo() [1/2]

StatusCode xAOD::TEvent::writeTo ( ::TFile * file,
int autoFlush = 200,
std::string_view treeName = EVENT_TREE_NAME )
inherited

Connect the object to an output file.

This function should be called on a file opened be the user, before any event processing would occur.

It sets up the output event tree.

Parameters
fileThe file that the event data should be written to
autoFlushThe auto-flush setting to use on the output TTree
treeNameName of the output event tree
Returns
The usual StatusCode tyoes

Definition at line 430 of file Control/xAODRootAccess/Root/TEvent.cxx.

431 {
432
433 // Just a simple security check.
434 if (!file) {
435 ATH_MSG_ERROR("Null pointer received!");
436 return StatusCode::FAILURE;
437 }
438
439 // Check that the object is in the "right state":
440 if (m_outTree) {
441 ATH_MSG_ERROR("Object already writing to a file. Close that file first!");
442 return StatusCode::FAILURE;
443 }
444
445 // Make sure we return to the current directory:
446 TDirectoryReset dr;
447
448 // Create the output TTree:
449 file->cd();
450 m_outTree = std::make_unique<TTree>(treeName.data(), "xAOD event tree");
451 m_outTree->SetDirectory(file);
452 m_outTree->SetAutoSave(1000000);
453 m_outTree->SetAutoFlush(autoFlush);
454
455 // Access the EventFormat object associated with this file:
458
459 // Return gracefully:
460 return StatusCode::SUCCESS;
461}
static const TEventFormatRegistry & instance()
Access the only instance of the object in memory.
EventFormat & getEventFormat(const TFile *file) const
Access the managed EventFormat object.

◆ writeTo() [2/2]

StatusCode xAOD::TEvent::writeTo ( TFile & file)
overridevirtualinherited

Connect the object to an output file.

This interface function should be called on a file opened be the user, before any event processing would occur.

It sets up the output event tree.

Parameters
fileThe file that the event data should be written to
Returns
The usual StatusCode tyoes

Implements xAOD::Event.

Definition at line 413 of file Control/xAODRootAccess/Root/TEvent.cxx.

413 {
414
415 // Forward call
417
418 // Return gracefully:
419 return StatusCode::SUCCESS;
420}
StatusCode writeTo(TFile &file) override
Connect the object to an output file.

Member Data Documentation

◆ ATLAS_THREAD_SAFE

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

Map from hashed sgkey to BranchInfo.

Definition at line 392 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"
staticinherited

Name of the event RNTuple.

Definition at line 78 of file Event.h.

◆ EVENT_TREE_NAME

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

Default name of the event TTree.

Name of the event TTree.

Definition at line 77 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
protectedinherited

Rules for selecting which auxiliary branches to write.

Definition at line 360 of file Event.h.

◆ m_auxMode

EAuxMode xAOD::TEvent::m_auxMode
protectedinherited

The auxiliary access mode.

Definition at line 206 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_branchesMutex

upgrade_mutex_t xAOD::Event::m_branchesMutex
mutableprotectedinherited

Mutex for multithread synchronization.

Definition at line 388 of file Event.h.

◆ m_ctx

EventContext xAOD::Event::m_ctx
protectedinherited

The event context associated with this event.

Definition at line 408 of file Event.h.

◆ m_entry

::Long64_t xAOD::TEvent::m_entry = -1
protectedinherited

The entry to look at from the input tree.

Definition at line 222 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_inChain

::TChain* xAOD::TEvent::m_inChain = nullptr
protectedinherited

The (optional) chain provided as input.

Definition at line 214 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_inChainTracker

std::unique_ptr<TChainStateTracker> xAOD::TEvent::m_inChainTracker
protectedinherited

Optional object for tracking the state changes of an input TChain.

Definition at line 216 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_inMetaTree

::TTree* xAOD::TEvent::m_inMetaTree = nullptr
protectedinherited

Pointer to the metadata tree in the input file.

Definition at line 220 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_inputEventFormat

EventFormat xAOD::Event::m_inputEventFormat
protectedinherited

Format of the current input file.

Definition at line 355 of file Event.h.

◆ m_inputMetaObjects

Object_t xAOD::Event::m_inputMetaObjects
protectedinherited

Collection of all the managed input meta-objects.

Definition at line 350 of file Event.h.

◆ m_inputMissingObjects

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

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

Definition at line 345 of file Event.h.

◆ m_inputObjects

Object_t xAOD::Event::m_inputObjects
protectedinherited

Collection of all the managed input objects.

Definition at line 342 of file Event.h.

◆ m_inTree

::TTree* xAOD::TEvent::m_inTree = nullptr
protectedinherited

The main tree that we are reading from.

Definition at line 209 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_inTreeMissing

bool xAOD::TEvent::m_inTreeMissing = false
protectedinherited

Internal status flag showing that an input file is open, but it doesn't contain an event tree.

Definition at line 212 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_inTreeNumber

::Int_t xAOD::TEvent::m_inTreeNumber = -1
protectedinherited

The number of the currently open tree in the input chain.

Definition at line 218 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_listeners

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

Listeners who should be notified when certain incidents happen.

Definition at line 363 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
protectedinherited

Container name re-mapping rules.

Definition at line 366 of file Event.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_otherMetaDataTreeNamePattern

std::regex xAOD::TEvent::m_otherMetaDataTreeNamePattern
protectedinherited
Initial value:
=
std::regex("^MetaData(?!Hdr)_.*$")

Definition at line 230 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_outputEventFormat

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

Format of the current output file.

Definition at line 357 of file Event.h.

◆ m_outputMetaObjects

Object_t xAOD::Event::m_outputMetaObjects
protectedinherited

Collection of all the managed output meta-objects.

Definition at line 352 of file Event.h.

◆ m_outputObjects

Object_t xAOD::Event::m_outputObjects
protectedinherited

Collection of all the managed output object.

Definition at line 347 of file Event.h.

◆ m_outTree

std::unique_ptr<::TTree> xAOD::TEvent::m_outTree
protectedinherited

The tree that we are writing to.

Definition at line 225 of file Control/xAODRootAccess/xAODRootAccess/TEvent.h.

◆ m_printEventProxyWarnings

bool xAOD::Event::m_printEventProxyWarnings = false
protectedinherited

Option to silence common warnings that seem to be harmless.

Definition at line 369 of file Event.h.

◆ METADATA_OBJECT_NAME

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

Name of the metadata tree or RNTuple.

Definition at line 79 of file Event.h.


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