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

#include <xAODEvent.h>

Inheritance diagram for xAOD::xAODREvent:
Collaboration diagram for xAOD::xAODREvent:

Public Types

using sgkey_t = SG::sgkey_t

Public Member Functions

 xAODREvent ()
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 (std::string_view fileName)
 Set up the reading of an input file via a file name.
StatusCode writeTo (TFile &file) override
 Connect the object to an output file.
StatusCode finishWritingTo (TFile &file) override
 Finish writing to an output file.
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 RNTuple.
::Int_t fill () override
 Method filling one event into 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
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

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

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

StatusCode initStats ()
 Function to initialise the statistics for all RNTuple content.
StatusCode setUpDynamicStore (RObjectManager &mgr, ROOT::RNTupleReader &ntupleReader)
 event uses RNTupleReader:
void initMessaging () const
 Initialize our message level and MessageSvc.
Functions implemented from @c xAOD::Event
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.
StatusCode recordAux (TVirtualManager &mgr, const std::string &key, bool metadata) override
 Record an auxiliary store into a connected output file.
StatusCode putAux (TVirtualManager &mgr, ::Bool_t metadata=kFALSE)
 Method saving the dynamically created auxiliary properties.
StatusCode addField (const std::string &key, const TVirtualManager &mgr)
 Add field to RNTuple model given the StoreGate key and output object manager.

Private Attributes

std::unique_ptr< ROOT::RNTupleReader > m_eventReader
 The main event data reader.
bool m_inputNTupleIsMissing = false
 Whether the input has an event RNTuple or not.
std::unique_ptr< ROOT::RNTupleReader > m_metaReader
 The metadata reader.
::Long64_t m_entry {}
 The entry to look at from the input.
std::unique_ptr< ROOT::RNTupleModel > m_model
 The RNTuple model used for event fields.
std::unique_ptr< ROOT::RNTupleWriter > m_eventWriter
 The main event writer: RNTupleWeader.
::TFile * m_outputFile {nullptr}
 The output file for writing.
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

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

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

Definition at line 38 of file xAODEvent.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.

Constructor & Destructor Documentation

◆ xAODREvent()

xAOD::xAODREvent::xAODREvent ( )
inline

Definition at line 41 of file xAODEvent.h.

42 {
43 m_ctx = Gaudi::Hive::currentContext();
44 }
EventContext m_ctx
The event context associated with this event.
Definition Event.h:408

Member Function Documentation

◆ addField()

StatusCode xAOD::Experimental::REvent::addField ( const std::string & key,
const TVirtualManager & mgr )
privateinherited

Add field to RNTuple model given the StoreGate key and output object manager.

Definition at line 1694 of file REvent.cxx.

1694 {
1695
1696 // Add to the RNTuple model -
1697 // This is done by either adding the field to the initial model before the first event is written, or
1698 // after the first event has been written a new field is added via an extension of the output RNTuple model.
1699 // This can occurs when an AuxStore is empty for the initial events
1700
1701 // Get field name and class name to create a RFieldBase
1702 std::string fieldName;
1703 std::string className;
1704 if (getInfoForFieldCreation( key, mgr, fieldName, className ).isFailure()) return StatusCode::FAILURE;
1705 // should have found class name
1706 if ( className.empty() ) {
1707 ATH_MSG_ERROR( "could not find className!" );
1708 return StatusCode::FAILURE;
1709 }
1710
1711 if (m_model) {
1712 // Continue to add to the initial RNTuple model
1713 m_model->AddField( ROOT::RFieldBase::Create( fieldName, className ).Unwrap());
1714 }
1715 else {
1716 if (m_eventWriter.get() == nullptr) {
1717 ATH_MSG_ERROR("Internal logic error detected - no output found");
1718 return StatusCode::FAILURE;
1719 }
1720 // After the first event, one needs to extend the output RNTuple model
1721 auto field = ROOT::RFieldBase::Create(fieldName, className).Unwrap();
1722 auto updater = m_eventWriter->CreateModelUpdater();
1723 updater->BeginUpdate();
1724 updater->AddField(std::move(field));
1725 updater->CommitUpdate();
1726 }
1727
1728 // Return gracefully:
1729 return StatusCode::SUCCESS;
1730
1731}
#define ATH_MSG_ERROR(x,...)
std::unique_ptr< ROOT::RNTupleWriter > m_eventWriter
The main event writer: RNTupleWeader.
Definition REvent.h:144
std::unique_ptr< ROOT::RNTupleModel > m_model
The RNTuple model used for event fields.
Definition REvent.h:141
Updater_t & updater()
Access the Updater instance.

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

◆ 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::Experimental::REvent::connectAux ( const std::string & prefix,
bool standalone )
overrideprivatevirtualinherited

Function setting up access to a set of auxiliary branches.

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

This uses 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
kTRUE if the connection was successful, or kFALSE if it was not

Implements xAOD::Event.

Definition at line 1085 of file REvent.cxx.

1085 {
1086
1087 // A little sanity check.
1088 if (!m_eventReader) {
1089 ATH_MSG_ERROR("Function called on un-initialised object");
1090 return StatusCode::FAILURE;
1091 }
1092
1093 // Check if the field is already connected.
1094 if (m_inputObjects.contains(prefix)) {
1095 return StatusCode::SUCCESS;
1096 }
1097
1098 // Connect to the field as we would for any other.
1099 static constexpr bool SILENT = false;
1100 ATH_CHECK(connectObject(prefix, SILENT));
1101
1102 // Access the object's manager.
1103 Object_t::const_iterator mgr_itr = m_inputObjects.find(prefix);
1104 if (mgr_itr == m_inputObjects.end()) {
1105 ATH_MSG_FATAL("There's a logic error in the code");
1106 return StatusCode::FAILURE;
1107 }
1108 const Details::IObjectManager* omgr =
1109 dynamic_cast<const RObjectManager*>(mgr_itr->second.get());
1110 if (omgr == nullptr) {
1111 ATH_MSG_FATAL("There's a logic error in the code");
1112 return StatusCode::FAILURE;
1113 }
1114
1115 // Check if we can switch out the internal store of this object.
1116 static const TClass* const holderClass = TClass::GetClass(typeid(SG::IAuxStoreHolder));
1117 if (omgr->holder()->getClass()->InheritsFrom(holderClass) == false) {
1118 // Nope... So let's just end the journey here.
1119 return StatusCode::SUCCESS;
1120 }
1121
1122 // Try to get the object as an IAuxStoreHolder.
1123 SG::IAuxStoreHolder* storeHolder = reinterpret_cast<SG::IAuxStoreHolder*>(
1124 omgr->holder()->getAs(typeid(SG::IAuxStoreHolder)));
1125 if (!storeHolder) {
1126 ATH_MSG_FATAL("There's a logic error in the code");
1127 return StatusCode::FAILURE;
1128 }
1129
1130 // A sanity check to see whether the store's type is in sync with the
1131 // object's type that it will be connected to:
1132 if ((standalone &&
1134 ((!standalone) && (storeHolder->getStoreType() !=
1136 ATH_MSG_ERROR("Requested store types inconsistent for: " << prefix);
1137 ATH_MSG_ERROR("standalone = "
1138 << standalone << ", getStoreType() = "
1139 << static_cast<int>(storeHolder->getStoreType()));
1140 return StatusCode::FAILURE;
1141 }
1142
1143 // Return gracefully.
1144 return StatusCode::SUCCESS;
1145}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x,...)
@ AST_ContainerStore
The store describes a container.
@ AST_ObjectStore
The store describes a single object.
virtual AuxStoreType getStoreType() const =0
Return the type of the store object.
Object_t m_inputObjects
Collection of all the managed input objects.
Definition Event.h:342
std::unique_ptr< ROOT::RNTupleReader > m_eventReader
The main event data reader.
Definition REvent.h:131
StatusCode connectObject(const std::string &key, bool silent) override
Function setting up access to a particular object.
Definition REvent.cxx:848
@ SILENT
don't print anything and return success

◆ connectMetaAux()

StatusCode xAOD::Experimental::REvent::connectMetaAux ( const std::string & prefix,
bool standalone )
overrideprivatevirtualinherited

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.

This uses 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 1155 of file REvent.cxx.

1156 {
1157
1158 // A little sanity check.
1159 if (!m_metaReader) {
1160 ATH_MSG_ERROR("Function called on un-initialised object");
1161 return StatusCode::FAILURE;
1162 }
1163
1164 // Check if the field is already connected.
1165 if (m_inputMetaObjects.contains(prefix)) {
1166 return StatusCode::SUCCESS;
1167 }
1168
1169 // Connect to the field as we would for any other.
1170 static constexpr bool SILENT = false;
1171 ATH_CHECK(connectMetaObject(prefix, SILENT));
1172
1173 // Access the object's manager.
1174 Object_t::const_iterator mgr_itr = m_inputMetaObjects.find(prefix);
1175 if (mgr_itr == m_inputMetaObjects.end()) {
1176 ATH_MSG_FATAL("There's a logic error in the code");
1177 return StatusCode::FAILURE;
1178 }
1179 const Details::IObjectManager* omgr =
1180 dynamic_cast<const RObjectManager*>(mgr_itr->second.get());
1181 if (omgr == nullptr) {
1182 ATH_MSG_FATAL("There's a logic error in the code");
1183 return StatusCode::FAILURE;
1184 }
1185
1186 // Check if we can switch out the internal store of this object.
1187 static const TClass* const holderClass =
1188 TClass::GetClass(typeid(SG::IAuxStoreHolder));
1189 if (omgr->holder()->getClass()->InheritsFrom(holderClass) == false) {
1190 // Nope... So let's just end the journey here.
1191 return StatusCode::SUCCESS;
1192 }
1193
1194 // Try to get the object as an IAuxStoreHolder.
1195 SG::IAuxStoreHolder* storeHolder = reinterpret_cast<SG::IAuxStoreHolder*>(
1196 omgr->holder()->getAs(typeid(SG::IAuxStoreHolder)));
1197 if (!storeHolder) {
1198 ATH_MSG_FATAL("There's a logic error in the code");
1199 return StatusCode::FAILURE;
1200 }
1201
1202 // A sanity check to see whether the store's type is in sync with the
1203 // object's type that it will be connected to:
1204 if ((standalone &&
1206 ((!standalone) && (storeHolder->getStoreType() !=
1208 ATH_MSG_ERROR("Requested store types inconsistent for: " << prefix);
1209 ATH_MSG_ERROR("standalone = "
1210 << standalone << ", getStoreType() = "
1211 << static_cast<int>(storeHolder->getStoreType()));
1212 return StatusCode::FAILURE;
1213 }
1214
1215 // Return gracefully.
1216 return StatusCode::SUCCESS;
1217}
Object_t m_inputMetaObjects
Collection of all the managed input meta-objects.
Definition Event.h:350
std::unique_ptr< ROOT::RNTupleReader > m_metaReader
The metadata reader.
Definition REvent.h:135
StatusCode connectMetaObject(const std::string &key, bool silent) override
Function setting up access to a particular metadata object.
Definition REvent.cxx:998

◆ connectMetaObject()

StatusCode xAOD::Experimental::REvent::connectMetaObject ( const std::string & key,
bool silent )
overrideprivatevirtualinherited

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 998 of file REvent.cxx.

998 {
999
1000 // A little sanity check.
1001 if (!m_metaReader) {
1002 ATH_MSG_ERROR("Function called on un-initialised object");
1003 return StatusCode::FAILURE;
1004 }
1005
1006 // Check if the branch is already connected.
1007 if (m_inputMetaObjects.contains(key)) {
1008 return StatusCode::SUCCESS;
1009 }
1010
1011 // Find the name of the field that stores the object.
1012 const std::string fieldName =
1013 Utils::getFieldName(m_metaReader->GetDescriptor(), key);
1014
1015 // Check if the field exists in our input RNTuple.
1016 if (m_metaReader->GetDescriptor().FindFieldId(fieldName.c_str()) ==
1017 ROOT::kInvalidDescriptorId) {
1018 // Field doesn't exist
1019 if (!silent) {
1020 ATH_MSG_WARNING("Field \"" << fieldName << "\" not available on input");
1021 }
1022 return StatusCode::RECOVERABLE;
1023 }
1024
1025 // RDS: may need some logic here to get type from inputEventFormat rather than
1026 // the view to read in with automatic schema evolution
1027
1028 // Get class name from the field
1029 ROOT::RNTupleView<void> view =
1030 m_metaReader->GetView<void>(fieldName.c_str(), nullptr);
1031 std::string className = view.GetField().GetTypeName();
1032 if (className == "") {
1034 "Couldn't find an appropriate type with a dictionary for field \""
1035 << fieldName << "\"");
1036 return StatusCode::FAILURE;
1037 }
1038 ::TClass* realClass = ::TClass::GetClass(className.c_str());
1039 if ((!realClass) || (!realClass->IsLoaded())) {
1040 // Now we're in trouble...
1042 "Couldn't find an appropriate type with a dictionary for field \""
1043 << fieldName << "\"");
1044 return StatusCode::FAILURE;
1045 }
1046
1047 // Create the object and the manager(s) around it.
1048 void* ptr = realClass->New();
1049 static const ::Long64_t FIRST_ENTRY = 0;
1050 auto mgr = std::make_unique<RObjectManager>(
1051 m_metaReader->GetView(fieldName, ptr, className), FIRST_ENTRY,
1052 std::make_unique<THolder>(ptr, realClass));
1053 // For metadata, we must read in the first entry - entry number already set by FIRST_ENTRY in constructor
1054 mgr->getEntry();
1055 RObjectManager* mgrPtr = mgr.get();
1056 m_inputMetaObjects[key] = std::move(mgr);
1057
1058 // If it's an auxiliary store object, set it up correctly.
1059 if (Details::isAuxStore(*(mgrPtr->holder()->getClass()))) {
1060 // For reading in of the dynamic variables for metadata
1062 }
1063
1064 // If it (probably) has an associated auxiliary store, set it up as well.
1065 if (Details::hasAuxStore(*(mgrPtr->holder()->getClass()))) {
1067 key + "Aux.", Details::isStandalone(*(mgrPtr->holder()->getClass()))));
1068 static constexpr bool METADATA = true;
1069 ATH_CHECK(setAuxStore(key, *mgrPtr, METADATA));
1070 }
1071
1072 // Return gracefully.
1073 return StatusCode::SUCCESS;
1074} // connectMetaObject
StatusCode setUpDynamicStore(RObjectManager &mgr, ROOT::RNTupleReader &ntupleReader)
event uses RNTupleReader:
Definition REvent.cxx:1824
StatusCode connectMetaAux(const std::string &prefix, bool standalone) override
Function setting up access to a set of auxiliary branches for a metadata object.
Definition REvent.cxx:1155
StatusCode setAuxStore(const std::string &key, Details::IObjectManager &mgr, bool metadata) override
Function connecting a DV object to its auxiliary store.
Definition REvent.cxx:1230
void * ptr(T *p)
Definition SGImplSvc.cxx:75
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
std::string getFieldName(const ROOT::RNTupleDescriptor &descriptor, const std::string &key)
This function is used to find the name of the field in an RNTuple that stores the object with a given...

◆ connectObject()

StatusCode xAOD::Experimental::REvent::connectObject ( const std::string & key,
bool silent )
overrideprivatevirtualinherited

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 field of the input RNTuple.

The type that is read in to memory is not actually determined by the type written to the ntuple itself, but from the xAOD::EventFormat object. Which is there to make it possible to possibly use ROOT read rules 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 field can't be connected to
Returns
The usual StatusCode values

Implements xAOD::Event.

Definition at line 848 of file REvent.cxx.

848 {
849
850 // A little sanity check.
851 if (!m_eventReader) {
852 ATH_MSG_ERROR("Function called on un-initialised object");
853 return StatusCode::FAILURE;
854 }
855
856 // Increment the access counter on this container.
858
859 // Check if the branch is already connected.
860 if (m_inputObjects.contains(key)) {
861 return StatusCode::SUCCESS;
862 }
863 // Check if it was already found to be missing.
864 if (m_inputMissingObjects.contains(key)) {
865 if (!silent) {
866 ATH_MSG_WARNING("Field \"" << key << "\" not available on input");
867 }
868 return StatusCode::RECOVERABLE;
869 }
870
871 // Tell the user what's happening.
872 ATH_MSG_DEBUG("Connecting to field \"" << key << "\"");
873
874 // Check if we have metadata about this branch.
875 const xAOD::EventFormatElement* ef = nullptr;
876
877 // Find the name of the field that stores the object.
878 const std::string fieldName =
879 Utils::getFieldName(m_eventReader->GetDescriptor(), key);
880
881 if (m_inputEventFormat.exists(key) == false) {
882 if (!silent) {
883 ATH_MSG_WARNING("No metadata available for object: " << key);
884 }
885 } else {
886 ef = m_inputEventFormat.get(key);
887 }
888
889 // Check if the field exists in our input RNTuple.
890 if (m_eventReader->GetDescriptor().FindFieldId(fieldName.c_str()) ==
891 ROOT::kInvalidDescriptorId) {
892 // Field doesn't exist
893 if (!silent) {
894 ATH_MSG_WARNING("Field \"" << fieldName << "\" not available on input");
895 }
896 m_inputMissingObjects.insert(key);
897 return StatusCode::RECOVERABLE;
898 }
899
900 // RDS: may need some logic here to get type from inputEventFormat rather than
901 // the view to read in with automatic schema evolution
902
903 // Get class name from the field
904 ROOT::RNTupleView<void> view =
905 m_eventReader->GetView<void>(fieldName.c_str(), nullptr);
906 std::string className = view.GetField().GetTypeName();
907 if (className == "") {
908 if (ef) {
909 // This is a fairly weird situation, but let's fall back to taking
910 // the class name from the metadata object in this case.
911 className = ef->className();
912 } else {
914 "Couldn't find an appropriate type with a dictionary for field \""
915 << fieldName << "\"");
916 return StatusCode::FAILURE;
917 }
918 }
919 ::TClass* realClass = ::TClass::GetClass(className.c_str());
920 if (((!realClass) || (!realClass->IsLoaded())) && ef) {
921 // We may need to do an actual schema evolution here, in which
922 // case let's fall back on the class name coming from the metadata
923 // object.
924 className = ef->className();
925 realClass = ::TClass::GetClass(className.c_str());
926 }
927 if ((!realClass) || (!realClass->IsLoaded())) {
928 // Now we're in trouble...
930 "Couldn't find an appropriate type with a dictionary for field \""
931 << fieldName << "\"");
932 return StatusCode::FAILURE;
933 }
934
935 // Make sure that the current object is the "active event":
936#ifndef XAOD_STANDALONE
937 SG::CurrentEventStore::Push save (SG::CurrentEventStore::store());
938#endif
939 setActive();
940
941 // Check if the output already has this object. If it does, let's
942 // assume that we have been copying the object to the output. Which
943 // means that we need to resume filling the same memory address that
944 // the output holder points to.
945 void* ptr = nullptr;
946
947 // Handle the case where an output object with this key already exists.
948 Object_t::const_iterator out_itr = m_outputObjects.find( key );
949 if( out_itr != m_outputObjects.end() ) {
950 // It needs to be an object manager...
951 RObjectManager* mgr =
952 dynamic_cast< RObjectManager* >( out_itr->second.get() );
953 if( ! mgr ) {
954 ATH_MSG_ERROR("Couldn't access output manager for: " << key );
955 return StatusCode::FAILURE;
956 }
957 // Get the pointer out of it:
958 ptr = mgr->holder()->get();
959 }
960
961 // If there is no output object, then let's create one ourselves.
962 // This is the only way in which we can have the memory management of
963 // THolder do the right thing with this object.
964 if (ptr == nullptr) {
965 ptr = realClass->New();
966 }
967
968 // Create the new manager object that will hold this EDM object.
969 auto mgr = std::make_unique<RObjectManager>(
970 m_eventReader->GetView(fieldName, ptr, className), m_entry,
971 std::make_unique<THolder>(ptr, realClass));
972 RObjectManager* mgrPtr = mgr.get();
973 m_inputObjects[key] = std::move(mgr);
974
975 // If it's an auxiliary store object, set it up correctly.
976 if (Details::isAuxStore(*(mgrPtr->holder()->getClass()))) {
978 }
979
980 // If it (probably) has an associated auxiliary store, set it up as well.
981 if (Details::hasAuxStore(*(mgrPtr->holder()->getClass()))) {
983 key + "Aux.", Details::isStandalone(*(mgrPtr->holder()->getClass()))));
984 }
985
986 // Return gracefully.
987 return StatusCode::SUCCESS;
988} // connectObject
#define ATH_MSG_DEBUG(x,...)
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
::Long64_t m_entry
The entry to look at from the input.
Definition REvent.h:138
StatusCode connectAux(const std::string &prefix, bool standalone) override
Function setting up access to a set of auxiliary branches.
Definition REvent.cxx:1085
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.
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_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
@ kAthenaAccess
Access containers/objects like Athena does.
@ kClassAccess
Access auxiliary data using the aux containers.
str inFile
Definition makeTOC.py:5
#define unlikely(x)

◆ currentContext()

const EventContext & Event::currentContext ( ) const
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}

◆ 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.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ fill()

Int_t xAOD::Experimental::REvent::fill ( )
overridevirtualinherited

Method filling one event into the output.

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 621 of file REvent.cxx.

621 {
622
623 // Make sure that all objects have been read in. The 99 as the value
624 // has a special meaning for RAuxStore. With this value it doesn't
625 // delete its transient (decoration) variables. Otherwise it does.
626 // (As it's supposed to, when moving to a new event.)
627 if( m_eventReader ) {
628 if (getEntry( m_entry, 99 ) < 0) {
629 ATH_MSG_ERROR( "getEntry failed!" );
630 return 0;
631 }
632 }
633
634 // Prepare the objects for writing. Note that we need to iterate over a
635 // copy of the m_outputObjects container. Since the putAux(...) function
636 // called inside the loop may itself add elements to the m_outputObject
637 // container.
638 std::string unsetObjects;
639 std::vector<std::pair<std::string, TVirtualManager*>> outputObjectsCopy;
640 outputObjectsCopy.reserve(m_outputObjects.size());
641 for (const auto& [key, mgr] : m_outputObjects) {
642 TVirtualManager* objMgr = dynamic_cast<TVirtualManager*>(mgr.get());
643 if (objMgr == nullptr) {
644 ATH_MSG_ERROR("Internal logic error detected");
645 return 0;
646 }
647 outputObjectsCopy.emplace_back(key, objMgr);
648 }
649 for (auto &[key, mgr] : outputObjectsCopy) {
650
651 ATH_MSG_DEBUG("REvent::fill - checking and adding aux for " << key << ", " << mgr << " isSet " << mgr->isSet());
652
653 // Check that a new object was provided in the event - skip dynamic variables:
654 if ((key.find("AuxDyn") == std::string::npos) && !mgr->isSet()) {
655
656 ATH_MSG_DEBUG("REvent::fill - not set " << key);
657
658 // We are now going to fail. But let's collect the names of
659 // all the unset objects:
660 if (unsetObjects.size()) {
661 unsetObjects += ", ";
662 }
663 unsetObjects.append("\"" + key + "\"");
664 continue;
665 }
666
667 // Make sure that any dynamic auxiliary variables that
668 // were added to the object after it was put into the event
669 // are also added to the output.
670 if( putAux( *mgr ).isFailure() ) {
671 ATH_MSG_ERROR( "Failed to put dynamic auxiliary variables in the output for object \"" << key << "\"" );
672 return 0;
673 }
674 }
675
676 // Check if there were any unset objects:
677 if (unsetObjects.size()) {
678 ATH_MSG_ERROR("The following objects were not set in the current event: "
679 << unsetObjects);
680 return 0;
681 }
682
683 // For the first call to fill, we create an RNTupleWriter with the RNTuple model already accumulated
684 // - there may be extensions for Aux containers which are empty for the first few events
685 ATH_MSG_DEBUG( "REvent::fill - has event writer " << (m_eventWriter.get() != nullptr) );
686
687 if( m_eventWriter.get() == nullptr ) {
688
689 // Set output RNTuple name as model description
690 const char* rnTupleName = EVENT_RNTUPLE_NAME;
691
692 // Create RNTuple write with model
693 m_eventWriter = ROOT::RNTupleWriter::Append(std::move(m_model), rnTupleName, *m_outputFile);
694
695 // Reset the RNTupleModel so that subsequent additions of new fields will be done with model extensions
696 m_model.reset();
697
698 ATH_MSG_DEBUG( "REvent::fill - created writer and reset model " );
699
700 }
701
702 // Get entry for writing
703 auto rnEntry = m_eventWriter->GetModel().CreateBareEntry();
704
705 // Now loop over all object managers and bind the output object pointers
706 // to the those in the output RNTuple
707 ::Int_t nbytes = 0;
708 for (auto &[key, mgr] : m_outputObjects) {
709
710 // Get field name from the key
711 auto fieldName = getFieldNameFromKey(key);
712
713 // Check if this is a container, top-level or aux, rather than a aux variable (AuxDyn):
714 ROutObjManager* omgr = dynamic_cast< ROutObjManager* >( mgr.get() );
715 bool isContainer = (omgr != nullptr);
716
717 ATH_MSG_DEBUG("REvent::fill - bind ptr " << key << " mgr " << mgr << " is set " << mgr->isSet()
718 << ", is container " << isContainer);
719
720 // Save value, if an object has been set, otherwise save default value
721 // Dynamic attributes don't exist for empty containers, e.g. no electrons in an event
722 if (mgr->isSet()) {
723 rnEntry->BindRawPtr(fieldName, mgr->object());
724 } else {
725
726 ATH_MSG_DEBUG("REvent::fill - bind unSet ptr " << key << " mgr " << mgr << " is set " << mgr->isSet()
727 << ", is container " << isContainer);
728
729 rnEntry->EmplaceNewValue(fieldName);
730 }
731 }
732
733 ATH_MSG_DEBUG("REvent::fill - writer fill ");
734
735 // Write the entry, and check the return value:
736 const ::Int_t ret = m_eventWriter->Fill(*rnEntry);
737 if( ret <= 0 ) {
738 ATH_MSG_ERROR( "Output RNTuple filling failed with return value: " << ret );
739 }
740 nbytes += ret;
741
742 ATH_MSG_DEBUG("REvent::fill - writer filled ");
743
744 // Reset the object managers:
745 for (auto &[key, mgr] : m_outputObjects) {
746 mgr->reset();
747
748 ATH_MSG_DEBUG("REvent::fill - after reset " << key << " is set " << mgr->isSet());
749
750 }
751
752 // Return the number of bytes written:
753 return nbytes;
754}
StatusCode putAux(TVirtualManager &mgr, ::Bool_t metadata=kFALSE)
Method saving the dynamically created auxiliary properties.
Definition REvent.cxx:1514
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0) override
Function loading a given entry of the input RNTuple.
Definition REvent.cxx:567
::TFile * m_outputFile
The output file for writing.
Definition REvent.h:147

◆ finishWritingTo()

StatusCode xAOD::Experimental::REvent::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
kTRUE if successful, kFALSE otherwise

reset writer (metaDataWriter will be reset when going out of scope)

Implements xAOD::Event.

Definition at line 386 of file REvent.cxx.

386 {
387
388 // A small sanity check for meta data writing - need output file as long as MetaData is in a rntuple:
389 if( m_outputFile != &file ) {
390 ATH_MSG_FATAL("File given to finishWritingTo does not match the file given in writeTo file!");
391 return StatusCode::FAILURE;
392 }
393
394 // Notify the listeners that they should write out their metadata, if they
395 // have any.
396 const TIncident incident( IncidentType::MetaDataStop );
397 for (auto& listener : m_listeners) {
398 listener->handle(incident);
399 }
400
401 // Now go to the output file:
402 m_outputFile->cd();
403
404 const char* outRNTupleName = METADATA_OBJECT_NAME;
405
406 // Check if there's already a metadata tree in the output, if so we can return:
407 if( m_outputFile->Get( outRNTupleName ) ) {
408
409 // Let's assume that the metadata is complete in the file already.
410 ATH_MSG_INFO( "Metadata tree already exists, returning" );
411
412 return StatusCode::SUCCESS;
413 }
414
415 // Write out meta data
416
417 // Create new model for this file
418 auto model = ROOT::RNTupleModel::Create();
419
420 // Set output RNTuple name as model description
421 model->SetDescription(outRNTupleName);
422
423
424 // Create field explicitly for EventFormat
425
426 // Check if we have a dictionary: for this object:
427 std::string typeName = SG::normalizedTypeinfoName( typeid( xAOD::EventFormat ) );
428 TClass* cl = TClass::GetClass( typeName.c_str() );
429 if( ! cl ) {
430 ATH_MSG_ERROR( "Didn't find dictionary for type: " << typeName );
431 return StatusCode::FAILURE;
432 }
433 std::string efName = cl->GetName();
434
435 ATH_MSG_DEBUG("finishWriting");
436
437 model->AddField( ROOT::RFieldBase::Create( "EventFormat", efName ).Unwrap());
438
439 // Loop over output meta data object managers and create the corresponding fields for the output model
440
441 // Make sure that any dynamic auxiliary variables that
442 // were added to the object after it was put into the event,
443 // get added to the output
444
445 // Must copy m_outputMetaObjects because it may be augmented in putAux
446 std::vector<std::pair<std::string, TVirtualManager*>> outputMetaObjects;
447 outputMetaObjects.reserve(m_outputMetaObjects.size());
448 for (const auto& [key, mgr] : m_outputMetaObjects) {
449 TVirtualManager* objMgr = dynamic_cast<TVirtualManager*>(mgr.get());
450 if (objMgr == nullptr) {
451 ATH_MSG_FATAL("Internal logic error detected");
452 return StatusCode::FAILURE;
453 }
454
455 ATH_MSG_DEBUG("finishWriting: save metadata key " << key);
456
457 outputMetaObjects.emplace_back(key, objMgr);
458 }
459
460 // Set up the saving of all the dynamic auxiliary properties
461 // of the object if it has any:
462 for( auto& itr : outputMetaObjects ) {
463 static constexpr bool IS_METADATA = true;
464 ATH_CHECK( putAux( *(itr.second), IS_METADATA ) );
465 }
466
467 // Now create fields for each output metadata object
468 for (auto &[key, mgr] : m_outputMetaObjects) {
469
470 // Get field name and class name to create a RFieldBase
471 std::string fieldName;
472 std::string className;
473 if (getInfoForFieldCreation( key, *mgr, fieldName, className ).isFailure()) return StatusCode::FAILURE;
474
475 // should have found class name
476 if ( className.empty() ) {
477 ATH_MSG_ERROR( "could not find className!" );
478 return StatusCode::FAILURE;
479 }
480
481 // Add RFieldBase to model
482 model->AddField( ROOT::RFieldBase::Create( fieldName, className ).Unwrap());
483
484 }
485
486 // Create RNTuple write for meta data with model
487 auto metaDataWriter = ROOT::RNTupleWriter::Append(std::move(model), outRNTupleName, *m_outputFile);
488
489
490 // Get entry for writing
491 auto rnEntry = metaDataWriter->GetModel().CreateBareEntry();
492
493 // Now loop over all object managers and bind the output object pointers
494 // to the those in the output metadata RNTuple
495 for (auto &[key, mgr] : m_outputMetaObjects) {
496
497 // Get field name from the key
498 auto fieldName = getFieldNameFromKey(key);
499
500 // Save value, if exist, otherwise save default value
501 if (mgr.get()) {
502 rnEntry->BindRawPtr(fieldName, mgr->object());
503 } else {
504 rnEntry->EmplaceNewValue(fieldName);
505 }
506 }
507
508 // Add EventFormat to the RNEntry
509 rnEntry->BindRawPtr( "EventFormat", m_outputEventFormat );
510
511 // Write the entry, and check the return value:
512 const ::Int_t ret = metaDataWriter->Fill(*rnEntry);
513 if( ret <= 0 ) {
514 ATH_MSG_FATAL( "Output rntuple filling failed with return value: " << ret );
515 }
516 else {
517 ATH_MSG_INFO( "Output meta data rntuple filled. nbytes = " << ret );
518 }
519
520 // Now clean up:
521
522 // reset output EventFormat
524 m_outputObjects.clear();
525 m_outputMetaObjects.clear();
526
527 rnEntry.reset();
528
530 m_eventWriter.reset();
531
532 metaDataWriter.reset();
533
534 // Return gracefully:
535 return StatusCode::SUCCESS;
536} // finishWriting
#define ATH_MSG_INFO(x,...)
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

◆ 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::Experimental::REvent::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 541 of file REvent.cxx.

541 {
542
543 if (m_eventReader) {
544 return m_eventReader->GetNEntries();
545 } else if (m_inputNTupleIsMissing) {
546 return 0u;
547 } else {
548 ATH_MSG_ERROR("Function called on an uninitialised object");
549 return 0u;
550 }
551}
bool m_inputNTupleIsMissing
Whether the input has an event RNTuple or not.
Definition REvent.h:133
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77

◆ getEntry()

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

Function loading a given entry of the input RNTuple.

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

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 RNtuple 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 567 of file REvent.cxx.

567 {
568
569 // A little sanity check:
570 if (!m_eventReader) {
571 ATH_MSG_ERROR("Function called on an uninitialised object");
572 return -1;
573 }
574
575 // Check if anything needs to be done.
576 if (entry == m_entry) {
577 ATH_MSG_DEBUG("Entry " << entry << " is already the active one");
578 return 0;
579 }
580
581 // Set entry value
582 m_entry = entry;
583
584 // Stats counter needs to know it's the next event.
586
587 // Loop over all input object managers, and force them to load their
588 // content. But only if getall was used.
589 ::Int_t result = 0;
590 if (getall) {
591 for (auto& [key, inObj] : m_inputObjects) {
592 result += inObj->getEntry(getall);
593 }
594 }
595
596 // Notify the listeners that a new event was loaded.
597 const TIncident incident(IncidentType::BeginEvent);
598 for (TVirtualIncidentListener* listener : m_listeners) {
599 listener->handle(incident);
600 }
601
602 // Return the number of bytes read.
603 return result;
604}
void nextEvent()
Function incrementing the processed event counter.
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.

◆ 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.
TestStore store
Definition TestStore.cxx:23
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::Experimental::REvent::getNames ( const std::string & targetClassName,
std::vector< std::string > & vkeys,
bool metadata ) const
overrideprivatevirtualinherited

Function determining the list keys associated with a type name.

Implements xAOD::Event.

Definition at line 757 of file REvent.cxx.

759 {
760
761 // The results go in here
762 std::set<std::string> keys;
763
764 // Get list of fields from
765 // the input metadata tree or input tree
766
767 ROOT::RNTupleReader* reader = (metadata) ? m_metaReader.get() : m_eventReader.get();
768 if (reader == nullptr) {
769 ATH_MSG_ERROR("No input file is connected");
770 return StatusCode::FAILURE;
771 }
772 if (metadata) ATH_MSG_DEBUG("scanning input objects for metadata for type name " << targetClassName);
773 else ATH_MSG_DEBUG("scanning input objects for event data for type name " << targetClassName);
774
775 // add in names for all top level fields
776 for (const auto &topLevelField : reader->GetDescriptor().GetTopLevelFields()) {
777 std::string objClassName = topLevelField.GetTypeName();
778 std::string key = topLevelField.GetFieldName();
779 if (objClassName == targetClassName) {
780 ATH_MSG_VERBOSE("Matched " << targetClassName << " to key " << key);
781 keys.insert(std::move(key));
782 }
783 }
784
785 // check output objects
786 if (m_eventWriter && !metadata){
787 ATH_MSG_DEBUG("scanning output objects for type name " << targetClassName);
788 // add in names for all top level fields
789 for (const auto& topLevelFieldName : m_eventWriter->GetModel().GetRegisteredSubfieldNames()) {
790 auto& topLevelField = m_eventWriter->GetModel().GetConstField(topLevelFieldName);
791 std::string objClassName = topLevelField.GetTypeName();
792 std::string key = topLevelField.GetFieldName();
793 ATH_MSG_VERBOSE("Inspecting " << objClassName << "/" << key);
794 if (objClassName == targetClassName) {
795 ATH_MSG_VERBOSE("Matched " << targetClassName << " to key " << key);
796 keys.insert(std::move(key));
797 }
798 }
799 }
800
801 const Object_t& outAux = ( metadata ?
803
804 // Search though EventFormat for entries where class matches the provided
805 // typeName
806
807 ATH_MSG_DEBUG("scanning output Aux objects for type name " << targetClassName);
808
809 for( const auto& object : outAux ) {
810 // All metadata objects should be held by ROutObjManager objects.
811 // Anything else is an error.
812 std::string objClassName;
813 if ( metadata ) {
814 ROutObjManager* mgr = dynamic_cast< ROutObjManager* >( object.second.get() );
815 if ( ! mgr ) continue;
816 objClassName = mgr->holder()->getClass()->GetName();
817 }
818 const std::string& key = object.first;
819 ATH_MSG_VERBOSE("Inspecting " << objClassName << "/" << key);
820 if (objClassName == targetClassName) {
821 ATH_MSG_VERBOSE("Matched " << targetClassName << " to key " << key);
822 keys.insert(std::move(key));
823 }
824 }
825
826 vkeys.insert(vkeys.end(), keys.begin(), keys.end());
827
828 return StatusCode::SUCCESS;
829}
reader
read the goodrunslist xml file(s)
Definition collisions.py:22

◆ 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::Experimental::REvent::hasInput ( ) const
overrideprivatevirtualinherited

Check if an input file is connected to the object.

Implements xAOD::Event.

Definition at line 606 of file REvent.cxx.

606 {
607
609}

◆ hasOutput()

bool xAOD::Experimental::REvent::hasOutput ( ) const
overrideprivatevirtualinherited

Check if an output file is connected to the object.

Implements xAOD::Event.

Definition at line 611 of file REvent.cxx.

611 {
612 return (m_outputFile != nullptr);
613}

◆ 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::Experimental::REvent::initStats ( )
privateinherited

Function to initialise the statistics for all RNTuple 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 values

Definition at line 1740 of file REvent.cxx.

1740 {
1741
1742 // A little sanity check.
1743 if (!m_eventReader) {
1744 ATH_MSG_ERROR("Function called on an uninitialised object");
1745 return StatusCode::FAILURE;
1746 }
1747
1748 // Reset the number of input branches information.
1750
1751 // Loop over the EventFormat information.
1752 for (const auto& [key, format] : m_inputEventFormat) {
1753
1754 ATH_MSG_DEBUG("Investigating object \"" << key << "\" of class \""
1755 << format.className() << "\"");
1756
1757 // If it's an auxiliary container, scan it using RAuxStore.
1758 if (key.ends_with("Aux.")) {
1759
1760 // But first decide whether it describes a container, or just
1761 // a single object. For that, first get the class that it was
1762 // written with.
1763 TClass* cl = TClass::GetClass(format.className().c_str());
1764 if ((cl == nullptr) || (cl->IsLoaded() == false)) {
1766 "Couldn't find the dictionary for type: " << format.className());
1767 continue;
1768 }
1769
1770 // And then check if it inherits from xAOD::AuxInfoBase.
1771 // If so, consider this standalone, otherwise a container.
1772 static TClass* const auxInfoCl = TClass::GetClass(
1773 SG::normalizedTypeinfoName(typeid(xAOD::AuxInfoBase)).c_str());
1774 if (auxInfoCl == nullptr) {
1775 ATH_MSG_ERROR("Couldn't get dictionary for xAOD::AuxInfoBase");
1776 return StatusCode::FAILURE;
1777 }
1778 const bool isInfo = cl->InheritsFrom(auxInfoCl);
1779 ATH_MSG_VERBOSE("isInfo = {}", isInfo);
1780
1781 // Scan the branches using a temporary RAuxStore instance.
1782 const std::string fieldName =
1783 Utils::getFieldName(m_eventReader->GetDescriptor(), key);
1787 static constexpr bool TOP_STORE = true;
1788 RAuxStore temp(this->currentContext(), fieldName, TOP_STORE, mode);
1789 ATH_CHECK(temp.readFrom(*m_eventReader));
1790
1791 // Add all the auxids to the statistics object:
1792 ReadStats& stats = IOStats::instance().stats();
1793 for (SG::auxid_t id : temp.getAuxIDs()) {
1794 stats.branch(fieldName, id);
1795 }
1796
1797 // Increment the number of known branches.
1798 stats.setBranchNum(stats.branchNum() + temp.getAuxIDs().size());
1799 }
1800 // If it's an interface container.
1801 else {
1802 // Check if it's part of the input ntuple.
1803 const ROOT::RNTupleDescriptor& descriptor =
1804 m_eventReader->GetDescriptor();
1805 if (descriptor.FindFieldId(Utils::getFieldName(descriptor, key)) !=
1806 ROOT::kInvalidDescriptorId) {
1808 }
1809 }
1810 }
1811
1812 // Return gracefully:
1813 return StatusCode::SUCCESS;
1814}
const EventContext & currentContext() const
Return the event context corresponding to this event.
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
@ kObjectStore
The object describes a single object.
@ kContainerStore
The object describes an entire container.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

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

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

◆ 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::Experimental::REvent::putAux ( TVirtualManager & vmgr,
::Bool_t metadata = kFALSE )
privateinherited

Method 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.) The first time an aux store variable is encountered, an RAuxFieldManager is created to manage it. And for each call, the manager holder is set to point to the aux variable. Note: this may be called when recording an aux container, but new aux variables may be created up to a call to fill One also needs to keep track of empty aux containers on the first event to allow to add in the aux fields to the RNTuple model for the next event which has a non-empty container

Parameters
mgrThe object manager of the output object
metadataFlag specifying whether the info written is metadata or not
Returns
kTRUE if the setup was successful, or kFALSE if it was not

Add field to RNTuple model

Definition at line 1514 of file REvent.cxx.

1514 {
1515
1516 // A little sanity check:
1517 assert( m_outputEventFormat != 0 );
1518
1519 // Do the conversion:
1520 ROutObjManager* mgr = dynamic_cast< ROutObjManager* >( &vmgr );
1521
1522 ATH_MSG_DEBUG("REvent::putAux - vmgr " << mgr);
1523
1524 if( ! mgr ) {
1525 // It's not an error any more when we don't get a ROutObjManager.
1526 return StatusCode::SUCCESS;
1527 }
1528
1529 // Check if this class has an auxiliary store, if not nothing needs to be done:
1530 if( ! mgr->holder()->getClass()->InheritsFrom( "SG::IAuxStoreIO" ) ) {
1531
1532 ATH_MSG_DEBUG("REvent::putAux - no Aux store ");
1533
1534 return StatusCode::SUCCESS;
1535 }
1536
1537 // Get a pointer to the auxiliary store I/O interface:
1538 SG::IAuxStoreIO* aux = reinterpret_cast< SG::IAuxStoreIO* >(mgr->holder()->getAs( typeid( SG::IAuxStoreIO ) ) );
1539 if( ! aux ) {
1540 ATH_MSG_FATAL( "There is a logic error in the code!" );
1541 }
1542
1543 // Check if we have rules defined for which auxiliary properties
1544 // to write out:
1545 xAOD::AuxSelection sel;
1546 if( ! metadata ) {
1547 auto item_itr = m_auxItemList.find( mgr->key() );
1548 if( item_itr != m_auxItemList.end() ) {
1549 sel.selectAux( item_itr->second );
1550 }
1551 }
1552
1553 // Get the dynamic auxiliary variables held by this object, which
1554 // were selected to be written:
1555 const SG::auxid_set_t auxids = sel.getSelectedAuxIDs (aux->getSelectedAuxIDs());
1556
1557 // Decide what should be the prefix of all the dynamic branches:
1558 const std::string dynNamePrefix = Utils::dynBranchPrefix( mgr->key() );
1559
1560 ATH_MSG_DEBUG("REvent::putAux - dynNamePrefix " << dynNamePrefix);
1561
1562
1563 // Select which container to add the variables to:
1565
1566 // RDS: is the following needed in an RNTuple?
1567 // This iteration will determine the ordering of branches within
1568 // the tree, so sort auxids by name.
1569 const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
1570 typedef std::pair< std::string, SG::auxid_t > AuxVarSort_t;
1571 std::vector< AuxVarSort_t > varsort;
1572 varsort.reserve( auxids.size() );
1573 for( SG::auxid_t id : auxids ) {
1574 varsort.emplace_back( r.getName( id ), id );
1575 }
1576 std::sort( varsort.begin(), varsort.end() );
1577
1578 // Extract all the dynamic variables from the object:
1579 for( const auto& p : varsort ) {
1580
1581 // The auxiliary ID:
1582 const SG::auxid_t id = p.second;
1583
1584 // Construct a dynamic key name for the field that we will write:
1585 const std::string dynKey = dynNamePrefix + p.first;
1586
1587 ATH_MSG_DEBUG("REvent::putAux - id, dynKey " << id << ", " << dynKey);
1588
1589
1590 // Try to find the object manager:
1591 Object_t::iterator bmgr = objects.find( dynKey );
1592
1593 // Check if we already know about this variable:
1594 if( bmgr == objects.end() ) {
1595 // Construct the full type name of the variable:
1596 const std::type_info* brType = aux->getIOType( id );
1597 if( ! brType ) {
1598 ATH_MSG_FATAL( "No I/O type found for variable " << dynKey );
1599 return StatusCode::FAILURE;
1600 }
1601 const std::string brTypeName = Utils::getTypeName( *brType );
1602 std::string brProperTypeName = "<unknown>";
1603
1604 // Check if it's a primitive type or not:
1605 bool isPrimitive = false;
1606 TVirtualManager* outmgrPtr = nullptr;
1607
1608 if( strlen( brType->name() ) == 1 ) {
1609 isPrimitive = true;
1610
1611 ATH_MSG_DEBUG("REvent::putAux - primitive " << id << ", " << brTypeName << " brType name " << brType->name());
1612
1613
1614 // Making the "proper" type name is simple in this case:
1615 brProperTypeName = std::move(brTypeName);
1616
1617 // Let's create an RAuxFieldManager for this property:
1618 static constexpr bool IS_OWNER = false;
1619 auto auxmgr = std::make_unique<RAuxFieldManager>(
1620 std::make_unique<THolder>(aux->getIOData( id ), *brType, IS_OWNER), isPrimitive );
1621 outmgrPtr = auxmgr.get();
1622
1623 objects[ dynKey ] = std::move(auxmgr);
1624
1625 } else {
1626
1627 ATH_MSG_DEBUG("REvent::putAux - not primitive " << id << ", " << brTypeName);
1628
1629 // Check if we have a dictionary for this type:
1630 TClass* cl = TClass::GetClass( *brType, kTRUE, kTRUE );
1631 if( ! cl ) {
1632 // The dictionary needs to be loaded now. This could be an
1633 // issue. But let's hope for the best...
1634 cl = TClass::GetClass( brTypeName.c_str() );
1635 // If still not found...
1636 if( ! cl ) {
1637 ATH_MSG_FATAL( "Dictionary not available for variable \"" << dynKey
1638 << "\" of type \"" << brTypeName << "\"" );
1639 return StatusCode::FAILURE;
1640 }
1641 }
1642
1643 // The proper type name comes from the dictionary in this case:
1644 brProperTypeName = cl->GetName();
1645
1646 // Let's create an RAuxFieldManager for this property - not a primitive:
1647 static constexpr bool IS_OWNER = false;
1648 auto auxmgr = std::make_unique<RAuxFieldManager>(
1649 std::make_unique<THolder>(aux->getIOData( id ), cl, IS_OWNER), isPrimitive );
1650 outmgrPtr = auxmgr.get();
1651 objects[ dynKey ] = std::move(auxmgr);
1652 }
1653
1654 // For event data, add in the the new fields to the RNTuple model and event format metadata
1655 if (!metadata) {
1656
1658 ATH_CHECK( addField(dynKey, *outmgrPtr) );
1659
1660 // If all went fine, let's add this branch to the event format
1661 // metadata (but not for regular metadata):
1662 if( ! m_outputEventFormat->exists( dynKey ) ) {
1664 EventFormatElement( dynKey,
1665 brProperTypeName,
1666 mgr->key(),
1667 getHash( dynKey ) ) );
1668 }
1669 }
1670
1671 // We don't need to do the rest:
1672 continue;
1673 }
1674
1675 ATH_MSG_DEBUG("REvent::putAux - setObj " << dynKey);
1676
1677 // Access the object manager:
1678 bmgr = objects.find( dynKey );
1679 if( bmgr == objects.end() ) {
1680 ATH_MSG_FATAL( "There is an internal logic error in the code..." );
1681 }
1682 // Replace the managed object:
1683 void* nc_data ATLAS_THREAD_SAFE = // we hold non-const pointers but check on retrieve
1684 const_cast< void* >( static_cast< const void* >( aux->getIOData( id ) ) );
1685 bmgr->second->setObject( nc_data );
1686 }
1687
1688 // Return gracefully:
1689 return StatusCode::SUCCESS;
1690}
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
StatusCode addField(const std::string &key, const TVirtualManager &mgr)
Add field to RNTuple model given the StoreGate key and output object manager.
Definition REvent.cxx:1694
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.
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...
std::string getTypeName(const std::type_info &ti)
This function is necessary in order to create type names that ROOT can understand.

◆ readFrom() [1/2]

StatusCode xAOD::Experimental::REvent::readFrom ( std::string_view fileName)
inherited

Set up the reading of an input file via a file name.

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

This can be considered the 'native' interface as an RNTupleReader opens a file with a name

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

Parameters
fileNamename of file needed for metadata access

Definition at line 174 of file REvent.cxx.

174 {
175
176 ATH_MSG_INFO("REvent::readFrom: fileName " << fileName);
177
178 // Set up the file access tracer.
180
181 // Clear the cached input objects.
182 m_inputObjects.clear();
183 m_inputMissingObjects.clear();
184 m_inputMetaObjects.clear();
185 {
187 lock.upgrade();
188 m_branches.clear();
189 }
190 m_eventReader.reset();
191
192 // Reset the internal flags.
193 m_entry = -1;
195
196 // Clear out the current object.
198
199
200 ATH_MSG_DEBUG("Create RNTupleReader for \"" << METADATA_OBJECT_NAME
201 << "\" in file: " << fileName);
202
203 // Set up a reader for the metadata ntuple.
204 // Since some types are non-xAOD types and so not 'visible' when running in AnalysisBase
205 // we need to protect for unknown types with SetEmulateUnknownTypes(true)
206 ROOT::RNTupleDescriptor::RCreateModelOptions opts;
207 opts.SetEmulateUnknownTypes(true);
208 m_metaReader = ROOT::RNTupleReader::Open(opts, METADATA_OBJECT_NAME, fileName);
209 if (!m_metaReader) {
210 ATH_MSG_ERROR("Couldn't find \"" << METADATA_OBJECT_NAME
211 << "\" tree in input file: " << fileName);
212 return StatusCode::FAILURE;
213 }
214 ATH_MSG_DEBUG("Created RNTupleReader for \"" << METADATA_OBJECT_NAME
215 << "\" in file: " << fileName);
216
217 // Make sure that the xAOD::EventFormat dictonary is loaded.
218 // This may not be the case if streamer information reading is turned
219 // off.
220 static const std::string eventFormatTypeName =
222 if (::TClass::GetClass(eventFormatTypeName.c_str()) == nullptr) {
223 ATH_MSG_WARNING("Couldn't load the EventFormat dictionary");
224 }
225 ATH_MSG_VERBOSE("Loaded the xAOD::EventFormat dictionary");
226
227 // Helper lambda for collecting the event format metadata from an RNTuple
228 // with a given name.
229 auto readEventFormatMetadata = [&](std::string_view tupleName) -> StatusCode {
230 // Set up a reader. This may technically be the same as m_metaReader, but
231 // it's easier to write the code this way.
232 auto metaReader = ROOT::RNTupleReader::Open(tupleName, fileName);
233 if (!metaReader) {
234 ATH_MSG_ERROR("Couldn't find \""
235 << tupleName << "\" ntuple in input file: " << fileName);
236 return StatusCode::FAILURE;
237 }
238 ATH_MSG_VERBOSE("Created temporary RNTupleReader for \""
239 << tupleName << "\" in file: " << fileName);
240
241 // Try to read in the event format metadata.
242 const std::string eventFormatFieldName =
243 getFirstFieldMatch(*m_metaReader, "EventFormat");
244 try {
245 // Add its elements to m_inputEventFormat.
246 auto ef = m_metaReader->GetView<xAOD::EventFormat>(eventFormatFieldName);
247 for (const auto& [key, element] : ef(0u)) {
248 m_inputEventFormat.add(element);
249 }
250 } catch (const ROOT::RException&) {
251 ATH_MSG_WARNING("Input file provides no event or metadata");
252 return StatusCode::RECOVERABLE;
253 }
254 ATH_MSG_VERBOSE("Merged event format metadata from \"" << tupleName
255 << "\" ntuple");
256
257 // Return gracefully.
258 return StatusCode::SUCCESS;
259 };
260
261 // Read in the metadata from the "main" metadata ntuple.
262 const StatusCode sc = readEventFormatMetadata(METADATA_OBJECT_NAME);
263 if (sc.isRecoverable()) {
265 return StatusCode::SUCCESS;
266 }
267 ATH_CHECK(sc);
268
269 // List all the other Metadata RNTuples in the input file.
270 // Having several metadata tuples can happen for augmented files
271 // as one metadata tree per stream is produced.
272 std::set<std::string> lOtherMetaTupleNames;
273 {
274 std::unique_ptr<TFile> inFile(TFile::Open(fileName.data(), "READ"));
275 TList* lKeys = inFile->GetListOfKeys();
276 if (lKeys == nullptr) {
277 ATH_MSG_ERROR("Could not get list of keys for input file: " << fileName);
278 return StatusCode::FAILURE;
279 }
280 for (const TObject* obj : *lKeys) {
281 const std::string keyName = obj->GetName();
282 // Make sure the key corresponds to a metadata ntuple but
283 // do not add the current metadata tree in the list of other trees
284 // and do not add the metadata tree handlers to the list
285 if ((keyName != METADATA_OBJECT_NAME) &&
286 (keyName.find("MetaData") != std::string::npos) &&
287 (keyName.find("MetaDataHdr") == std::string::npos)) {
288 // Make sure key corresponds to an RNTuple
289 const TKey* key = dynamic_cast<const TKey*>(obj);
290 if (key == nullptr) {
291 ATH_MSG_ERROR("Object describing \"" << keyName << "\" in file \""
292 << fileName
293 << "\" is not a TKey?");
294 return StatusCode::FAILURE;
295 }
296 const char* className = key->GetClassName();
297 static constexpr bool LOAD = kFALSE;
298 static constexpr bool SILENT = kTRUE;
299 ::TClass* cl = ::TClass::GetClass(className, LOAD, SILENT);
300 if ((cl != nullptr) && cl->InheritsFrom(ROOT::RNTuple::Class())) {
301 lOtherMetaTupleNames.insert(std::move(keyName));
302 }
303 }
304 }
305 }
306
307 // Read in the metadata from any additonal NTuples found (if any).
308 for (const std::string& tupleName : lOtherMetaTupleNames) {
309 ATH_CHECK(readEventFormatMetadata(tupleName));
310 }
311
312 // Set up the main ntuple reader.
313 // Files written by Athena also store non-xAOD types (e.g. DataHeader_p6) in the
314 // event ntuple, so protect for unknown types the same way as for the metadata
315 m_eventReader = ROOT::RNTupleReader::Open(opts, EVENT_RNTUPLE_NAME, fileName);
316 if (!m_eventReader) {
317 ATH_MSG_ERROR("Couldn't access RNTuple \"" << EVENT_RNTUPLE_NAME
318 << "\" in file: " << fileName);
319 return StatusCode::FAILURE;
320 }
321 ATH_MSG_DEBUG("Created RNTupleReader for \"" << EVENT_RNTUPLE_NAME
322 << "\" in file: " << fileName);
323
324 // Init the statistics collection.
326 // Update the event counter in the statistics object:
327 xAOD::ReadStats& stats = IOStats::instance().stats();
328 stats.setNEvents(stats.nEvents() + m_eventReader->GetNEntries());
329
330 // Notify the listeners that a new file was opened:
331 const TIncident beginIncident(IncidentType::BeginInputFile);
332 for (TVirtualIncidentListener* listener : m_listeners) {
333 listener->handle(beginIncident);
334 }
335 // For now implement a very simple scheme in which we claim already
336 // at the start that the entire file was processed. Since we have no way
337 // of ensuring that the user indeed does this. And we can't delay calling
338 // this function, as the user may likely close his/her output file before
339 // closing the last opened input file.
340 const TIncident endIncident(IncidentType::EndInputFile);
341 for (TVirtualIncidentListener* listener : m_listeners) {
342 listener->handle(endIncident);
343 }
344
345 // The initialisation was successful:
346 return StatusCode::SUCCESS;
347}
StatusCode initStats()
Function to initialise the statistics for all RNTuple content.
Definition REvent.cxx:1740
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

◆ readFrom() [2/2]

StatusCode xAOD::Experimental::REvent::readFrom ( TFile & inFile)
overridevirtualinherited

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

Implementation of interface method taking a TFile object. Forwards to the method with a string view below.

Implements xAOD::Event.

Definition at line 163 of file REvent.cxx.

163 {
164 ATH_CHECK(readFrom(inFile.GetName()));
165 return StatusCode::SUCCESS;
166}
StatusCode readFrom(TFile &inFile) override
Set up the reading of an input file from TFile This method implements the interface from Event.
Definition REvent.cxx:163

◆ record() [1/3]

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/3]

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

Add an output object to the event.

◆ record() [3/3]

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

Record an object into a connected output file.

This is the function doing the heavy lifting when recording a new object into the output RNTuple.

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
kTRUE if the operation was successful, or kFALSE if it was not

Add field to RNTuple model

Implements xAOD::Event.

Definition at line 1359 of file REvent.cxx.

1364 {
1365
1366
1367 // Check if we have an output file when writing an event:
1368 if ( !hasOutput() ) {
1369 ATH_MSG_FATAL("No output output file defined. Did you forget to call writeTo(...)?" );
1370 return StatusCode::FAILURE;
1371 }
1372 assert( m_outputEventFormat != 0 );
1373
1374 ATH_MSG_DEBUG("REvent::record - key, type " << key << ", " << typeName);
1375
1376
1377 // If this is metadata, just take ownership of it. The object will only
1378 // be recorded into the output file when calling finishWriting(...).
1379 if( metadata ) {
1380 // Check whether we already have such an object:
1381 if( ( ! overwrite ) &&
1382 ( m_outputMetaObjects.find( key ) !=
1383 m_outputMetaObjects.end() ) ) {
1384 ATH_MSG_FATAL("Meta-object " << typeName << "/" << key << " already recorded" );
1385 return StatusCode::FAILURE;
1386 }
1387 // Check if we have a dictionary for this object:
1388 TClass* cl = TClass::GetClass( typeName.c_str() );
1389 if( ! cl ) {
1390 ATH_MSG_ERROR( "Didn't find dictionary for type: " << typeName );
1391 return StatusCode::FAILURE;
1392 }
1393 // Create output object manager with a holder for the object:
1394 auto outmgr = std::make_unique<ROutObjManager>( key, std::make_unique<THolder>(obj, cl, isOwner));
1395 m_outputMetaObjects[key] = std::move(outmgr);
1396 // We're done. The rest will be done later on.
1397 return StatusCode::SUCCESS;
1398 }
1399
1400 // Check if we accessed this object on the input. If yes, then this
1401 // key may not be used for recording.
1402 if( ( ! overwrite ) &&
1403 ( m_inputObjects.find( key ) != m_inputObjects.end() ) ) {
1404 ATH_MSG_FATAL( "Object " << typeName << "/" << key <<
1405 " already accessed from the input, can't be overwritten in memory" );
1406 return StatusCode::FAILURE;
1407 }
1408
1409 // Check if we need to add it to the event record:
1410 Object_t::iterator vitr = m_outputObjects.find( key );
1411 if( vitr == m_outputObjects.end() ) {
1412
1413 // Check if we have a dictionary for this object:
1414 TClass* cl = TClass::GetClass( typeName.c_str() );
1415 if( ! cl ) {
1416 ATH_MSG_ERROR( "Didn't find dictionary for type: " << typeName );
1417 return StatusCode::FAILURE;
1418 }
1419 // Check if this is a new object "type" or not:
1420 if( ! m_outputEventFormat->exists( key ) ) {
1421 m_outputEventFormat->add( EventFormatElement( key, cl->GetName(),
1422 "", getHash( key ) ) );
1423 }
1424 // Create output object manager with a holder for the object:
1425 auto outmgr = std::make_unique<ROutObjManager>( key, std::make_unique<THolder>(obj, cl, isOwner));
1426 ROutObjManager* outmgrPtr = outmgr.get();
1427 m_outputObjects[ key ] = std::move(outmgr);
1428
1429 ATH_MSG_DEBUG("REvent::record - save outObjMgr for key, type " << key << ", " << typeName);
1430
1431 // Set up the saving of all the dynamic auxiliary properties
1432 // of the object if it has any:
1433 ATH_CHECK( putAux( *outmgrPtr ) );
1434
1436 ATH_CHECK( addField(key, *outmgrPtr) );
1437
1438 // Return at this point, as we don't want to run the rest of
1439 // the function's code:
1440 return StatusCode::SUCCESS;
1441 }
1442
1443 // Access the object manager:
1444 ROutObjManager* omgr = dynamic_cast< ROutObjManager* >( vitr->second.get() );
1445 if( ! omgr ) {
1446 ATH_MSG_FATAL( "Manager object of the wrong type encountered" );
1447 return StatusCode::FAILURE;
1448 }
1449
1450 // RDS: Is the following still needed?
1451 // // Check that the type of the object matches that of the previous
1452 // // object:
1453 // if( typeName != omgr->holder()->getClass()->GetName() ) {
1454 // // This may still be, when the ROOT dictionary name differs from the
1455 // // "simple type name" known to C++. So let's get the ROOT name of the
1456 // // new type:
1457 // TClass* cl = TClass::GetClass( typeName.c_str() );
1458 // if( ( ! cl ) || ::strcmp( cl->GetName(),
1459 // omgr->holder()->getClass()->GetName() ) ) {
1460 // ATH_MSG_FATAL(
1461 // XAOD_MESSAGE( "For output key \"%s\" the previous type "
1462 // "was \"%s\", the newly requested type is "
1463 // "\"%s\"" ),
1464 // key.c_str(), omgr->holder()->getClass()->GetName(),
1465 // typeName.c_str() );
1466 // return StatusCode::FAILURE;
1467 // }
1468 // }
1469
1470 // Replace the managed object:
1471 omgr->setObject( obj );
1472
1473 // Replace the auxiliary objects:
1474 return putAux( *omgr );
1475} // record
bool hasOutput() const override
Check if an output file is connected to the object.
Definition REvent.cxx:611

◆ recordAux()

StatusCode xAOD::Experimental::REvent::recordAux ( TVirtualManager & mgr,
const std::string & key,
bool metadata )
overrideprivatevirtualinherited

Record an auxiliary store into a connected output file.

Implements xAOD::Event.

Definition at line 1477 of file REvent.cxx.

1478 {
1479
1480 // Check if the auxiliary store is a generic object.
1481 Details::IObjectManager* iomgr = dynamic_cast<Details::IObjectManager*>(&mgr);
1482 if (iomgr != nullptr) {
1483 // Record the auxiliary object using the main record function.
1484 static const bool OVERWRITE = true;
1485 static const bool IS_OWNER = true;
1486 ATH_CHECK(record(iomgr->object(), iomgr->holder()->getClass()->GetName(),
1487 key, OVERWRITE, metadata, IS_OWNER));
1488 return StatusCode::SUCCESS;
1489 }
1490
1491 // Apparently we didn't recorgnize the auxiliary store type.
1492 ATH_MSG_ERROR("Unknown auxiliary store manager type encountered");
1493 return StatusCode::FAILURE;
1494}
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.
Definition REvent.cxx:1359

◆ 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::Experimental::REvent::setAuxStore ( const std::string & key,
Details::IObjectManager & mgr,
bool metadata )
overrideprivatevirtualinherited

Function connecting a DV object to its auxiliary store.

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

This function takes care of this.

Parameters
keyThe key (field name) of the object whose auxiliary store should be set up
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 1230 of file REvent.cxx.

1231 {
1232
1233 // Check if we need to do anything:
1234 if ((Details::hasAuxStore(*(mgr.holder()->getClass())) == false) &&
1235 (Details::isAuxStore(*(mgr.holder()->getClass())) == false)) {
1236 return StatusCode::SUCCESS;
1237 }
1238
1239 // Select which object container to use:
1241
1242 // Look up the auxiliary object's manager:
1243 TVirtualManager* auxMgr = nullptr;
1244 std::string auxKey;
1245 if (Details::isAuxStore(*(mgr.holder()->getClass()))) {
1246 auxMgr = &mgr;
1247 auxKey = key;
1248 } else {
1249 auto itr = objects.find(key + "Aux.");
1250 if (itr == objects.end()) {
1251 // Apparently there's no auxiliary object for this DV, so let's
1252 // give up.
1253 return StatusCode::SUCCESS;
1254 }
1255 auxMgr = itr->second.get();
1256 auxKey = key + "Aux:";
1257 }
1258
1259 // Get the aux store object.
1260 RObjectManager* omgr = dynamic_cast<RObjectManager*>(auxMgr);
1261 if (!omgr) {
1262 ATH_MSG_FATAL("Auxiliary manager for \"" << auxKey
1263 << "\" is not of the right type");
1264 return StatusCode::FAILURE;
1265 }
1266 void* p = omgr->holder()->getAs(typeid(SG::IAuxStore));
1267 SG::IAuxStore* store = reinterpret_cast<SG::IAuxStore*>(p);
1268 if (store == nullptr) {
1269 ATH_MSG_FATAL("There's a logic error in the code");
1270 return StatusCode::FAILURE;
1271 }
1272
1273 if (!metadata) {
1274 // Make sure the auxiliary object is up to date.
1275 ::Int_t readBytes = auxMgr->getEntry();
1276
1277 // Check if there is a separate auxiliary object for the dynamic
1278 // variables, which would need to be updated.
1279 const std::string dynAuxKey = auxKey + "Dynamic";
1280 auto dynAuxMgr = objects.find(dynAuxKey);
1281 if ((dynAuxMgr != objects.end()) && (readBytes || (auxMgr == &mgr))) {
1282
1283 // Tell the dynamic store object to switch to a new entry.
1284 dynAuxMgr->second->getEntry();
1285 }
1286
1287#ifndef XAOD_STANDALONE
1288 // Call toTransient on the aux store.
1289 store->toTransient (this->currentContext());
1290#endif
1291 }
1292
1293 // Stop here if we've set up an auxiliary store.
1294 if (auxMgr == &mgr) {
1295 return StatusCode::SUCCESS;
1296 }
1297
1298 // Access the auxiliary base class of the object/vector:
1299 SG::AuxVectorBase* vec = 0;
1300 SG::AuxElement* aux = 0;
1301 switch (mgr.holder()->typeKind()) {
1302 case THolder::DATAVECTOR: {
1303 void* vvec = mgr.holder()->getAs(typeid(SG::AuxVectorBase));
1304 vec = reinterpret_cast<SG::AuxVectorBase*>(vvec);
1305 } break;
1306 case THolder::AUXELEMENT: {
1307 void* vaux = mgr.holder()->getAs(typeid(SG::AuxElement));
1308 aux = reinterpret_cast<SG::AuxElement*>(vaux);
1309 } break;
1310 default:
1311 break;
1312 }
1313
1314 // Check whether index tracking is enabled for the type. If not, then
1315 // we need to fix it...
1316 if (vec && (!vec->trackIndices())) {
1317 Details::forceTrackIndices(*vec);
1318 }
1319
1320 // Check if we were successful:
1321 if ((!vec) && (!aux)) {
1322 ATH_MSG_FATAL("Couldn't access class \""
1323 << mgr.holder()->getClass()->GetName()
1324 << "\" as SG::AuxVectorBase or SG::AuxElement");
1325 return StatusCode::FAILURE;
1326 }
1327
1328 // Connect with the aux store.
1329 if (vec) {
1330 vec->setStore(store);
1331 } else if (aux) {
1332 aux->setStore(store);
1333 } else {
1334 ATH_MSG_FATAL("There's a logic error in the code");
1335 return StatusCode::FAILURE;
1336 }
1337
1338 // We succeeded:
1339 return StatusCode::SUCCESS;
1340}
std::vector< size_t > vec
@ 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.

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

◆ setUpDynamicStore()

StatusCode xAOD::Experimental::REvent::setUpDynamicStore ( RObjectManager & mgr,
ROOT::RNTupleReader & reader )
privateinherited

event uses RNTupleReader:

This function is used by connectObject(...) and connectMetaObject(...) 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
readerThe RNTuple reader to read dynamic variables from
Returns
The usual StatusCode types

Definition at line 1824 of file REvent.cxx.

1825 {
1826
1827 // The name of the field that the object is connected to.
1828 const std::string fieldName = mgr.field().GetField().GetFieldName();
1829
1830 // Check if we can call setName(...) on the object.
1831 ::TMethodCall setNameCall;
1832 setNameCall.InitWithPrototype(mgr.holder()->getClass(), "setName",
1833 "const char*");
1834 if (setNameCall.IsValid()) {
1835 // Yes, there is such a function. Let's call it with the field
1836 // name.
1837 const ::TString params = ::TString::Format("\"%s\"", fieldName.c_str());
1838 const char* charParams = params.Data();
1839 setNameCall.Execute(mgr.holder()->get(), charParams);
1840 } else {
1841 // This is weird. What sort of auxiliary container is this? :-/
1842 ATH_MSG_WARNING("Couldn't find setName(...) function for container \""
1843 << fieldName << "\" (type: "
1844 << mgr.holder()->getClass()->GetName() << ")");
1845 }
1846
1847 // Check if we can switch out the internal store of this object:
1848 static const TClass* const holderClass =
1849 TClass::GetClass(typeid(SG::IAuxStoreHolder));
1850 if (!mgr.holder()->getClass()->InheritsFrom(holderClass)) {
1851 // Nope... So let's just end the journey here.
1852 return StatusCode::SUCCESS;
1853 }
1854
1855 // Try to get the object as an IAuxStoreHolder:
1856 SG::IAuxStoreHolder* storeHolder = reinterpret_cast<SG::IAuxStoreHolder*>(
1857 mgr.holder()->getAs(typeid(SG::IAuxStoreHolder)));
1858 if (!storeHolder) {
1859 ATH_MSG_FATAL("There's a logic error in the code");
1860 return StatusCode::FAILURE;
1861 }
1862
1863 // Create an RAuxStore instance that will read the dynamic variables
1864 // of this container. Notice that the RAuxManager doesn't own the
1865 // RAuxStore object. It will be owned by the SG::IAuxStoreHolder
1866 // object.
1867 static constexpr bool TOP_STORE = false;
1868 const EventContext& ctx = this->currentContext();
1869 auto store = std::make_unique<RAuxStore>(
1870 ctx,
1871 fieldName, TOP_STORE,
1875 // This object is used to read data from the input, it needs to be
1876 // locked:
1877 store->lock();
1878
1879 // Set it up to read from the input RNTuple.
1880 ATH_CHECK(store->readFrom(reader));
1881 // Tell the auxiliary store which entry to use. This is essential for
1882 // metadata objects, and non-important for event data objects, which will
1883 // get a possibly different entry loaded in setAuxStore(...).
1884 ATH_CHECK(store->getEntry(0));
1885
1886 // Set up a manager for it.
1887 static constexpr bool SHARED_OWNER = false;
1888 m_inputObjects[fieldName + "Dynamic"] =
1889 std::make_unique<RAuxManager>(store.get(), m_entry, SHARED_OWNER);
1890
1891 // Give this object to the store holder.
1892 storeHolder->setStore(store.release());
1893
1894 // Return gracefully:
1895 return StatusCode::SUCCESS;
1896}
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()

StatusCode xAOD::Experimental::REvent::writeTo ( TFile & file)
overridevirtualinherited

Connect the object to an output file.

This function should be called to create a file for writing and setup the output RNTuple and metadata trees.

Parameters
filethe TFile to which the output is writter

Implements xAOD::Event.

Definition at line 356 of file REvent.cxx.

356 {
357
358 // Save filefor writing
360
361 ATH_MSG_DEBUG("REvent::writeTo - opened output file " << m_outputFile->GetName());
362
363 // Access the EventFormat object associated with this file:
366
367 ATH_MSG_DEBUG("REvent::writeTo - creating RNTupleModel ");
368
369 // Create new model for this file
370 m_model = ROOT::RNTupleModel::Create();
371
372 // Set output RNTuple name as model description
373 const char* rnTupleName = EVENT_RNTUPLE_NAME;
374 m_model->SetDescription(rnTupleName);
375
376 // Return gracefully:
377 return StatusCode::SUCCESS;
378}
static const TEventFormatRegistry & instance()
Access the only instance of the object in memory.
EventFormat & getEventFormat(const TFile *file) const
Access the managed EventFormat object.

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_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::Experimental::REvent::m_entry {}
privateinherited

The entry to look at from the input.

Definition at line 138 of file REvent.h.

138{};

◆ m_eventReader

std::unique_ptr<ROOT::RNTupleReader> xAOD::Experimental::REvent::m_eventReader
privateinherited

The main event data reader.

Definition at line 131 of file REvent.h.

◆ m_eventWriter

std::unique_ptr<ROOT::RNTupleWriter> xAOD::Experimental::REvent::m_eventWriter
privateinherited

The main event writer: RNTupleWeader.

Definition at line 144 of file REvent.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_inputEventFormat

EventFormat xAOD::Event::m_inputEventFormat
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_inputNTupleIsMissing

bool xAOD::Experimental::REvent::m_inputNTupleIsMissing = false
privateinherited

Whether the input has an event RNTuple or not.

Definition at line 133 of file REvent.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_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_metaReader

std::unique_ptr<ROOT::RNTupleReader> xAOD::Experimental::REvent::m_metaReader
privateinherited

The metadata reader.

Definition at line 135 of file REvent.h.

◆ m_model

std::unique_ptr<ROOT::RNTupleModel> xAOD::Experimental::REvent::m_model
privateinherited

The RNTuple model used for event fields.

Definition at line 141 of file REvent.h.

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

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

Format of the current output file.

Definition at line 357 of file Event.h.

◆ m_outputFile

::TFile* xAOD::Experimental::REvent::m_outputFile {nullptr}
privateinherited

The output file for writing.

Definition at line 147 of file REvent.h.

147{nullptr};

◆ 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_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 file: