 |
ATLAS Offline Software
|
Go to the documentation of this file.
30 #include <TMethodCall.h>
32 #include <ROOT/RNTuple.hxx>
51 std::string getFirstFieldMatch(ROOT::RNTupleReader&
reader,
52 const std::string& pre) {
55 for (
const auto&
field :
reader.GetDescriptor().GetTopLevelFields()) {
58 return field.GetFieldName();
70 static const char*
const EVENT_NTUPLE_NAME =
"EventData";
71 static const char*
const METADATA_NTUPLE_NAME =
"MetaData";
114 <<
"\" tree in input file: " <<
fileName);
115 return StatusCode::FAILURE;
117 ATH_MSG_DEBUG(
"Created RNTupleReader for \"" << METADATA_NTUPLE_NAME
123 static const std::string eventFormatTypeName =
125 if (::TClass::GetClass(eventFormatTypeName.c_str()) ==
nullptr) {
132 auto readEventFormatMetadata = [&](std::string_view tupleName) ->
StatusCode {
135 auto metaReader = ROOT::RNTupleReader::Open(tupleName,
fileName);
138 << tupleName <<
"\" ntuple in input file: " <<
fileName);
139 return StatusCode::FAILURE;
142 << tupleName <<
"\" in file: " <<
fileName);
145 const std::string eventFormatFieldName =
150 for (
const auto& [
key, element] :
ef(0
u)) {
153 }
catch (
const ROOT::RException&) {
155 return StatusCode::RECOVERABLE;
161 return StatusCode::SUCCESS;
165 const StatusCode sc = readEventFormatMetadata(METADATA_NTUPLE_NAME);
166 if (
sc.isRecoverable()) {
168 return StatusCode::SUCCESS;
175 std::set<std::string> lOtherMetaTupleNames;
177 std::unique_ptr<TFile>
inFile(TFile::Open(
fileName.data(),
"READ"));
178 TList* lKeys =
inFile->GetListOfKeys();
179 if (lKeys ==
nullptr) {
181 return StatusCode::FAILURE;
183 for (
const TObject*
obj : *lKeys) {
188 if ((
keyName != METADATA_NTUPLE_NAME) &&
189 (
keyName.find(
"MetaData") != std::string::npos) &&
190 (
keyName.find(
"MetaDataHdr") == std::string::npos)) {
192 const TKey*
key =
dynamic_cast<const TKey*
>(
obj);
193 if (
key ==
nullptr) {
196 <<
"\" is not a TKey?");
197 return StatusCode::FAILURE;
200 static constexpr
bool LOAD = kFALSE;
201 static constexpr
bool SILENT = kTRUE;
202 ::TClass*
cl = ::TClass::GetClass(
className, LOAD, SILENT);
203 if ((
cl !=
nullptr) &&
cl->InheritsFrom(ROOT::RNTuple::Class())) {
204 lOtherMetaTupleNames.insert(
keyName);
211 for (
const std::string& tupleName : lOtherMetaTupleNames) {
212 ATH_CHECK(readEventFormatMetadata(tupleName));
218 ATH_MSG_ERROR(
"Couldn't access RNTuple \"" << EVENT_NTUPLE_NAME
220 return StatusCode::FAILURE;
222 ATH_MSG_DEBUG(
"Created RNTupleReader for \"" << EVENT_NTUPLE_NAME
232 const TIncident beginIncident(IncidentType::BeginInputFile);
234 listener->handle(beginIncident);
241 const TIncident endIncident(IncidentType::EndInputFile);
243 listener->handle(endIncident);
247 return StatusCode::SUCCESS;
303 result += inObj->getEntry(getall);
308 const TIncident incident(IncidentType::BeginEvent);
310 listener->handle(incident);
328 std::vector<std::string>& ,
332 return StatusCode::FAILURE;
357 return StatusCode::FAILURE;
365 return StatusCode::SUCCESS;
372 return StatusCode::RECOVERABLE;
382 std::string key_to_read =
key;
383 if (
key.ends_with(
"Aux.")) {
384 key_to_read.replace(key_to_read.size() - 1, 1,
":");
396 if (
m_eventReader->GetDescriptor().FindFieldId(key_to_read.c_str()) ==
397 ROOT::kInvalidDescriptorId) {
400 ATH_MSG_WARNING(
"Field \"" << key_to_read <<
"\" not available on input");
403 return StatusCode::RECOVERABLE;
411 ROOT::RNTupleView<void>
view =
421 "Couldn't find an appropriate type with a dictionary for field \""
422 << key_to_read <<
"\"");
423 return StatusCode::FAILURE;
426 ::TClass* realClass = ::TClass::GetClass(
className.c_str());
427 if (((!realClass) || (!realClass->IsLoaded())) &&
ef) {
432 realClass = ::TClass::GetClass(
className.c_str());
434 if ((!realClass) || (!realClass->IsLoaded())) {
437 "Couldn't find an appropriate type with a dictionary for field \""
438 << key_to_read <<
"\"");
439 return StatusCode::FAILURE;
456 if (
ptr ==
nullptr) {
457 ptr = realClass->New();
461 auto mgr = std::make_unique<RObjectManager>(
463 std::make_unique<THolder>(
ptr, realClass));
479 return StatusCode::SUCCESS;
495 return StatusCode::FAILURE;
500 return StatusCode::SUCCESS;
504 std::string key_to_read =
key;
505 if (
key.ends_with(
"Aux.")) {
506 key_to_read.replace(key_to_read.size() - 1, 1,
":");
510 if (
m_metaReader->GetDescriptor().FindFieldId(key_to_read.c_str()) ==
511 ROOT::kInvalidDescriptorId) {
514 ATH_MSG_WARNING(
"Field \"" << key_to_read <<
"\" not available on input");
516 return StatusCode::RECOVERABLE;
524 ROOT::RNTupleView<void>
view =
525 m_metaReader->GetView<
void>(key_to_read.c_str(),
nullptr);
529 "Couldn't find an appropriate type with a dictionary for field \""
530 << key_to_read <<
"\"");
531 return StatusCode::FAILURE;
533 ::TClass* realClass = ::TClass::GetClass(
className.c_str());
534 if ((!realClass) || (!realClass->IsLoaded())) {
537 "Couldn't find an appropriate type with a dictionary for field \""
538 << key_to_read <<
"\"");
539 return StatusCode::FAILURE;
543 void*
ptr = realClass->New();
544 static const ::Long64_t FIRST_ENTRY = 0;
545 auto mgr = std::make_unique<RObjectManager>(
547 std::make_unique<THolder>(
ptr, realClass));
563 return StatusCode::SUCCESS;
581 return StatusCode::FAILURE;
586 return StatusCode::SUCCESS;
590 static constexpr
bool SILENT =
false;
597 return StatusCode::FAILURE;
601 if (omgr ==
nullptr) {
603 return StatusCode::FAILURE;
607 static const TClass*
const holderClass =
609 if (omgr->
holder()->
getClass()->InheritsFrom(holderClass) ==
false) {
611 return StatusCode::SUCCESS;
619 return StatusCode::FAILURE;
632 return StatusCode::FAILURE;
636 return StatusCode::SUCCESS;
654 return StatusCode::FAILURE;
659 return StatusCode::SUCCESS;
663 static constexpr
bool SILENT =
false;
670 return StatusCode::FAILURE;
674 if (omgr ==
nullptr) {
676 return StatusCode::FAILURE;
680 static const TClass*
const holderClass =
682 if (omgr->
holder()->
getClass()->InheritsFrom(holderClass) ==
false) {
684 return StatusCode::SUCCESS;
692 return StatusCode::FAILURE;
705 return StatusCode::FAILURE;
709 return StatusCode::SUCCESS;
729 return StatusCode::SUCCESS;
746 return StatusCode::SUCCESS;
748 auxMgr = itr->second.get();
749 auxKey =
key +
"Aux:";
754 ::Int_t readBytes = auxMgr->
getEntry();
758 const std::string dynAuxKey = auxKey +
"Dynamic";
759 auto dynAuxMgr =
objects.find(dynAuxKey);
760 if ((dynAuxMgr !=
objects.end()) && (readBytes || (auxMgr == &
mgr))) {
763 dynAuxMgr->second->getEntry();
768 if (auxMgr == &
mgr) {
769 return StatusCode::SUCCESS;
775 switch (
mgr.holder()->typeKind()) {
790 if (
vec && (!
vec->trackIndices())) {
791 Details::forceTrackIndices(*
vec);
795 if ((!
vec) && (!aux)) {
797 <<
mgr.holder()->getClass()->GetName()
798 <<
"\" as SG::AuxVectorBase or SG::AuxElement");
799 return StatusCode::FAILURE;
806 <<
"\" is not of the right type");
807 return StatusCode::FAILURE;
812 if (
store ==
nullptr) {
814 return StatusCode::FAILURE;
824 return StatusCode::FAILURE;
828 return StatusCode::SUCCESS;
835 return StatusCode::FAILURE;
840 ATH_MSG_ERROR(
"xAOD::REvent::recordAux not yet implemented");
841 return StatusCode::FAILURE;
855 return StatusCode::FAILURE;
865 <<
format.className() <<
"\"");
868 if (
key.ends_with(
"Aux.")) {
873 TClass*
cl = TClass::GetClass(
format.className().c_str());
874 if ((
cl ==
nullptr) || (
cl->IsLoaded() ==
false)) {
876 "Couldn't find the dictionary for type: " <<
format.className());
882 static TClass*
const auxContCl = TClass::GetClass(
884 static TClass*
const auxInfoCl = TClass::GetClass(
886 if ((auxContCl ==
nullptr) || (auxInfoCl ==
nullptr)) {
888 "Couldn't get dictionary for xAOD::AuxContainerBase or "
889 "xAOD::AuxInfoBase");
890 return StatusCode::FAILURE;
892 const bool isContainer =
cl->InheritsFrom(auxContCl);
893 const bool isInfo =
cl->InheritsFrom(auxInfoCl);
894 if ((isContainer ==
false) && (isInfo ==
false)) {
897 <<
"\" is of an unknown type: " <<
format.className());
901 <<
", isInfo = " << isInfo);
908 static constexpr
bool TOP_STORE =
true;
925 ROOT::kInvalidDescriptorId) {
932 return StatusCode::SUCCESS;
944 ROOT::RNTupleReader&
reader) {
947 const std::string
fieldName =
mgr.field().GetField().GetFieldName();
950 ::TMethodCall setNameCall;
951 setNameCall.InitWithPrototype(
mgr.holder()->getClass(),
"setName",
953 if (setNameCall.IsValid()) {
957 const char* charParams =
params.Data();
958 setNameCall.Execute(
mgr.holder()->get(), charParams);
963 <<
mgr.holder()->getClass()->GetName() <<
")");
967 static const TClass*
const holderClass =
969 if (!
mgr.holder()->getClass()->InheritsFrom(holderClass)) {
971 return StatusCode::SUCCESS;
979 return StatusCode::FAILURE;
986 static constexpr
bool TOP_STORE =
false;
987 auto store = std::make_unique<RAuxStore>(
1004 static constexpr
bool SHARED_OWNER =
false;
1006 std::make_unique<RAuxManager>(
store.get(),
m_entry, SHARED_OWNER);
1012 return StatusCode::SUCCESS;
Common base class for auxiliary info objects.
@ AUXELEMENT
A type inheriting from SG::AuxElement.
StatusCode connectObject(const std::string &key, bool silent) override
Function setting up access to a particular object.
StatusCode setAuxStore(const std::string &key, Details::IObjectManager &mgr, bool metadata) override
Function connecting a DV object to its auxiliary store.
virtual AuxStoreType getStoreType() const =0
Return the type of the store object.
StatusCode connectMetaAux(const std::string &prefix, bool standalone) override
Function setting up access to a set of auxiliary branches for a metadata object.
ReadStats & stats()
Access the object belonging to the current thread.
virtual const SG::auxid_set_t & getAuxIDs() const override
Get the types(names) of variables handled by this container.
StatusCode connectMetaObject(const std::string &key, bool silent) override
Function setting up access to a particular metadata object.
::Long64_t getEntries() const
Get how many entries are available from the current input file(s)
Object_t m_inputObjects
Collection of all the managed input objects.
Manager for EDM objects created by ROOT.
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...
EventFormat m_inputEventFormat
Format of the current input file.
Base class for elements of a container that can have aux data.
@ DATAVECTOR
A DataVector container.
virtual void * getAs(const std::type_info &tid, ::Bool_t silent=kFALSE) const
Return the object as a specific pointer.
const THolder * holder() const
Accessor to the Holder object.
void setActive() const
Set this event object as the currently active one.
virtual ::Int_t getEntry(::Int_t getall=0)=0
Function for updating the object in memory if needed.
EStructMode
"Structural" modes of the object
Common base class for the auxiliary containers.
"ROOT @c RNTuple implementation" of IAuxStore
bool hasOutput() const override
Check if an output file is connected to the object.
BranchStats * container(const std::string &name)
Access the description of a container. Creating it if necessary.
Class providing an interface for classes listening to xAOD incidents.
std::vector< size_t > vec
bool m_inputNTupleIsMissing
Whether the input has an event RNTuple or not.
Interface class for the "manager classes".
#define ATH_MSG_VERBOSE(x)
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)
Function loading a given entry of the input TTree.
StatusCode connectAux(const std::string &prefix, bool standalone) override
Function setting up access to a set of auxiliary branches.
StatusCode recordAux(TVirtualManager &mgr, const std::string &key, bool metadata) override
Record an auxiliary store into a connected output file.
@ kObjectStore
The object describes a single object.
std::vector< TVirtualIncidentListener * > m_listeners
Listeners who should be notified when certain incidents happen.
Manage index tracking and synchronization of auxiliary data.
@ kContainerStore
The object describes an entire container.
@ u
Enums for curvilinear frames.
Manage index tracking and synchronization of auxiliary data.
std::unordered_map< std::string, std::unique_ptr< TVirtualManager > > Object_t
Definition of the internal data structure type.
Object_t m_inputMetaObjects
Collection of all the managed input meta-objects.
StatusCode readFrom(std::string_view fileName)
Set up the reading of an input file.
void nextEvent()
Function incrementing the processed event counter.
const ::TClass * getClass() const
size_t auxid_t
Identifier for a particular aux data item.
bit_t size() const
Count the number of 1 bits in the set.
std::string getTypeName(const std::type_info &ti)
This function is necessary in order to create type names that ROOT can understand.
void setStore(const SG::IConstAuxStore *store)
Set the store associated with this object.
REvent()
Default constructor.
::StatusCode StatusCode
StatusCode definition for legacy code.
Class describing a certain "incident" that is communicated to user code.
upgrade_mutex_t m_branchesMutex
Mutex for multithread synchronization.
bool isStandalone(const TClass &cl)
Helper function deciding if a given type "is a standalone object".
void setBranchNum(::Int_t num)
Set the total number of branches on the input.
StatusCode setUpDynamicStore(RObjectManager &mgr, ROOT::RNTupleReader &ntupleReader)
event uses RNTupleReader:
static IOStats & instance()
Singleton object accessor.
bool hasInput() const override
Check if an input file is connected to the object.
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
virtual ~REvent()
Destructor.
virtual void setStore(IAuxStore *store)=0
Give an auxiliary store object to the holder object.
std::set< std::string > m_inputMissingObjects
Objects that have been asked for, but were found to be missing in the current input.
StatusCode readFrom(ROOT::RNTupleReader &reader)
Connect the object to an input RNTuple.
Object_t m_outputObjects
Collection of all the managed output object.
void readContainer(const std::string &name)
Function incrementing the read counter on a specific container.
::Long64_t m_entry
The entry to look at from the input tree.
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.
def silent(func)
Redirect stdout/err to /dev/null Useful wrapper to get rid of ROOT verbosity...
#define ATH_MSG_WARNING(x)
std::unique_ptr< ROOT::RNTupleReader > m_metaReader
The metadata reader.
Lock object for taking out upgradable locks.
bool hasAuxStore(const TClass &cl)
Helper function deciding if a given type "has an auxiliary store".
StatusCode initStats()
Function to initialise the statistics for all Tree content.
reader
read the goodrunslist xml file(s)
Manager for EDM objects created by ROOT.
Class describing the access statistics of a collection of branches.
Base class for the event (xAOD::TEvent and xAOD::REvent) classes.
Interface for const operations on an auxiliary store.
@ AST_ObjectStore
The store describes a single object.
Interface for objects taking part in direct ROOT I/O.
std::unique_ptr< ROOT::RNTupleReader > m_eventReader
The main event data reader.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
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.
Base class for elements of a container that can have aux data.
@ AST_ContainerStore
The store describes a container.
bool isAuxStore(const TClass &cl)
Helper function deciding if a given type "is an auxiliary store".