 |
ATLAS Offline Software
|
Go to the documentation of this file.
39 bool isContainerField(
const ROOT::RFieldDescriptor& fieldDesc,
54 TClass*
cl = TClass::GetClass(fieldDesc.GetTypeName().c_str());
60 ::Warning(
"::isPContainerField",
61 XAOD_MESSAGE(
"Couldn't get a dictionary for type \"%s\""),
62 fieldDesc.GetTypeName().c_str());
67 const std::type_info* root_ti =
cl->GetTypeInfo();
75 typeName.ReplaceAll(
"basic_string<char>",
"string");
76 ::TClass* newCl = ::TClass::GetClass(
typeName);
78 root_ti = newCl->GetTypeInfo();
83 XAOD_MESSAGE(
"Couldn't get an std::type_info object out of "
90 const std::type_info* aux_obj_ti =
96 static_cast<int>(auxid));
99 const std::type_info* aux_vec_ti =
105 static_cast<int>(auxid));
110 if (*root_ti == *aux_obj_ti) {
113 }
else if (*root_ti == *aux_vec_ti) {
121 if (
cl->GetCollectionProxy() && (*aux_vec_ti ==
typeid(std::vector<int>))) {
127 if (*cl2->GetTypeInfo() == *aux_vec_ti) {
143 aux_vec_cl->GetConversionStreamerInfo(
cl,
cl->GetClassVersion())) {
149 aux_obj_cl->GetConversionStreamerInfo(
cl,
cl->GetClassVersion())) {
155 XAOD_MESSAGE(
"Couldn't determine if field describes a single "
156 "object or a container"));
172 std::string_view
prefix,
void*
object,
const std::type_info* ti)
173 : m_field(std::move(
field)),
183 if ((m_entry ==
entry) && (!m_needsRead)) {
184 return StatusCode::SUCCESS;
190 }
catch (
const ROOT::RException&
e) {
191 ::Error(
"::RFieldInfo::getEntry",
192 "Failed to load entry %lld for field %s.%s: %s",
entry,
196 return StatusCode::FAILURE;
202 return StatusCode::SUCCESS;
211 void* objectPtr() {
return m_object; }
214 const std::type_info* typeInfo()
const {
return m_typeInfo; }
217 void reset() { m_needsRead =
true; }
221 ROOT::RNTupleView<void> m_field;
225 std::string_view m_prefix;
227 void* m_object =
nullptr;
229 const std::type_info* m_typeInfo =
nullptr;
231 ::Long64_t m_entry = -1;
233 bool m_needsRead =
true;
237 bool fieldExists(std::string_view
fieldName,
238 ROOT::RNTupleReader& ntupleReader) {
241 return (ntupleReader.GetDescriptor().FindFieldId(
fieldName) !=
263 return StatusCode::SUCCESS;
268 return StatusCode::SUCCESS;
272 for (
const ROOT::RFieldBase*
field :
273 #
if ROOT_VERSION_CODE >= ROOT_VERSION(6, 35, 0)
274 m_inTuple->GetModel().GetConstFieldZero().GetConstSubfields()
276 m_inTuple->GetModel().GetConstFieldZero().GetSubFields()
287 for (
const ROOT::RFieldBase* subField :
288 #
if ROOT_VERSION_CODE >= ROOT_VERSION(6, 35, 0)
289 field->GetConstSubfields()
291 field->GetSubFields()
296 const std::string&
typeName = subField->GetTypeName();
299 if (
typeName.starts_with(
"xAOD::") ||
302 typeName.starts_with(
"ILockable")) {
319 ::Error(
"xAOD::RAuxStore::impl::scanInputNtuple",
320 "Dynamic field with empty name found on container: %s",
326 auxName = auxName.substr(auxName.find(
':') + 1);
335 return StatusCode::SUCCESS;
348 std::string* expectedClassName =
nullptr) {
353 ::TClass* expectedClass = ::TClass::GetClass(
typeName.c_str());
354 if (expectedClassName) {
356 *expectedClassName = expectedClass->GetName();
370 const std::type_info* ti =
nullptr;
373 ti = expectedClass->GetTypeInfo();
378 if (!expectedClass) {
379 ::Warning(
"xAOD::RAuxStore::impl::auxFieldType",
380 "Couldn't get the type of field \"%s\"",
381 field.GetFieldName().c_str());
383 ::TVirtualCollectionProxy* prox = expectedClass->GetCollectionProxy();
388 prox = cl2->GetCollectionProxy();
393 ::Warning(
"xAOD::RAuxStore::impl::auxFieldType",
394 "Couldn't get the type of field \"%s\"",
395 field.GetFieldName().c_str());
397 if (prox->GetValueClass()) {
398 ti = prox->GetValueClass()->GetTypeInfo();
422 std::string_view auxName) {
425 std::string expectedClassName;
429 return StatusCode::SUCCESS;
438 const std::string auxNameStr{auxName};
440 regAuxid != SG::null_auxid) {
442 return StatusCode::SUCCESS;
451 const std::string linkedAttr =
453 const std::string linkedFieldName =
455 const std::type_info* linkedTi =
nullptr;
456 if (::fieldExists(linkedFieldName, *
m_inTuple)) {
462 *linkedTi, linkedAttr,
"",
465 if (linkedAuxId == SG::null_auxid) {
466 ::Error(
"xAOD::RAuxStore::setupAuxField",
467 "Could not find linked variable for %s type %s", auxName.data(),
468 expectedClassName.c_str());
477 if (auxid == SG::null_auxid) {
485 if (
typeName.starts_with(
"std::vector<"))
487 std::string factoryClassName =
489 if (factoryClassName[factoryClassName.size() - 1] ==
'>') {
490 factoryClassName +=
' ';
492 factoryClassName +=
"> >";
495 ::TClass* factoryClass = TClass::GetClass(factoryClassName.c_str());
496 if (factoryClass && factoryClass->IsLoaded()) {
497 ::TClass* baseClass = ::TClass::GetClass(
"SG::IAuxTypeVectorFactory");
498 if (baseClass && baseClass->IsLoaded()) {
499 const Int_t
offset = factoryClass->GetBaseClassOffset(baseClass);
501 void* factoryVoidPointer = factoryClass->New();
502 if (factoryVoidPointer) {
504 reinterpret_cast<unsigned long>(factoryVoidPointer) +
offset;
509 std::unique_ptr<SG::IAuxTypeVectorFactory>(factory));
519 if (auxid == SG::null_auxid && linkedAuxId == SG::null_auxid) {
522 if (vectorClassName[vectorClassName.size() - 1] ==
'>') {
523 vectorClassName +=
' ';
525 vectorClassName +=
'>';
528 ::TClass* vectorClass = ::TClass::GetClass(vectorClassName.c_str());
529 if (vectorClass && vectorClass->IsLoaded()) {
530 auto factory = std::make_unique<TAuxVectorFactory>(vectorClass);
531 if (factory->tiAlloc()) {
532 const std::type_info* tiAlloc = factory->tiAlloc();
533 registry.
addFactory(*ti, *tiAlloc, std::move(factory));
536 registry.
addFactory(*ti, tiAllocName, std::move(factory));
538 auxid = registry.
getAuxID(*ti, auxNameStr,
"",
541 ::Warning(
"xAOD::RAuxStore::setupAuxField",
542 "Couldn't find dictionary for type: %s",
543 vectorClassName.c_str());
548 if (auxid == SG::null_auxid) {
549 if (linkedAuxId != SG::null_auxid) {
550 ::Error(
"xAOD::RAuxStore::setupAuxField",
551 XAOD_MESSAGE(
"Dynamic ROOT vector factory not implemented for "
552 "linked types; field \"%s\""),
553 field.GetFieldName().c_str());
555 ::Error(
"xAOD::RAuxStore::setupAuxField",
556 XAOD_MESSAGE(
"Couldn't assign auxiliary ID to field \"%s\""),
557 field.GetFieldName().c_str());
559 return StatusCode::FAILURE;
564 return StatusCode::SUCCESS;
582 std::vector<std::unique_ptr<RFieldHandle> >
m_fields;
595 m_impl{std::make_unique<impl>(
m_data)} {
624 m_impl->m_missingFields.clear();
633 return StatusCode::SUCCESS;
661 return StatusCode::SUCCESS;
699 return StatusCode::SUCCESS;
710 return StatusCode::SUCCESS;
723 void* fieldPtr =
const_cast<void*
>(
getIOData(
id));
732 return StatusCode::SUCCESS;
744 m_impl->m_inputScanned =
false;
750 return ((
m_impl->m_fields.size() > auxid) &&
m_impl->m_fields[auxid]);
759 assert(
m_impl->m_fields.size() > auxid);
760 assert(
m_impl->m_fields[auxid]);
763 return StatusCode::SUCCESS;
769 return (
m_impl->m_outTuple !=
nullptr);
782 if ((auxid < m_impl->m_missingFields.size()) &&
783 m_impl->m_missingFields[auxid]) {
784 return StatusCode::RECOVERABLE;
789 if (
m_impl->m_inTuple ==
nullptr) {
790 return StatusCode::RECOVERABLE;
797 if (
m_impl->m_fields.size() <= auxid) {
798 m_impl->m_fields.resize(auxid + 1);
806 return (
m_impl->m_fields[auxid] ? StatusCode::SUCCESS
807 : StatusCode::RECOVERABLE);
814 const std::string statFieldName =
816 const std::string dynFieldName =
821 ROOT::DescriptorId_t fieldId;
822 if ((fieldId =
m_impl->m_inTuple->GetDescriptor().FindFieldId(
824 if ((fieldId =
m_impl->m_inTuple->GetDescriptor().FindFieldId(
827 if (
m_impl->m_missingFields.size() <= auxid) {
828 m_impl->m_missingFields.resize(auxid + 1);
830 m_impl->m_missingFields[auxid] =
true;
833 return StatusCode::RECOVERABLE;
840 const ROOT::RFieldDescriptor& fieldDesc =
841 m_impl->m_inTuple->GetDescriptor().GetFieldDescriptor(fieldId);
846 const bool containerField =
847 (primitiveField ? false : isContainerField(fieldDesc, auxid));
856 if ((containerField &&
858 !
r.isLinked(auxid)) ||
859 ((!containerField) &&
861 ::Error(
"xAOD::RAuxStore::setupInputData",
863 "differ for field: %s"),
865 return StatusCode::FAILURE;
869 const std::type_info* fieldType =
nullptr;
872 fieldType = (containerField ?
r.getVecType(auxid) :
r.getType(auxid));
875 TClass* clDummy = ::TClass::GetClass(fieldDesc.GetTypeName().c_str());
876 fieldType = (clDummy ? clDummy->GetTypeInfo()
880 ::Error(
"xAOD::RAuxStore::setupInputData",
882 fieldDesc.GetTypeName().c_str());
883 return StatusCode::RECOVERABLE;
888 ::TClass* fieldClass =
nullptr;
889 if (!primitiveField) {
891 fieldClass = ::TClass::GetClass(*fieldType,
true,
true);
893 fieldClass = ::TClass::GetClass(fieldTypeName);
896 ::Error(
"xAOD::RAuxStore::setupInputData",
897 XAOD_MESSAGE(
"No dictionary available for class \"%s\""),
898 fieldTypeName.Data());
899 return StatusCode::FAILURE;
905 m_data.
m_vecs[auxid] =
r.makeVector(auxid, (
size_t)0, (
size_t)0);
906 if (!containerField) {
910 strncmp(fieldClass->GetName(),
"SG::PackedContainer<", 20) == 0) {
911 std::unique_ptr<SG::IAuxTypeVector>
packed =
916 ::Error(
"xAOD::RAuxStore::setupInputData",
919 fieldName.c_str(),
static_cast<int>(auxid));
920 return StatusCode::FAILURE;
924 void* objectPtr = (containerField ?
m_data.
m_vecs[auxid]->toVector()
926 m_impl->m_fields[auxid] = std::make_unique<RFieldHandle>(
940 const std::string auxname =
r.getName(auxid);
952 const std::string testname =
r.getName(
i);
954 if (testname != auxname) {
959 ::Error(
"xAOD::RAuxStore::setupInputData",
971 if (linked_auxid != SG::null_auxid) {
976 return StatusCode::SUCCESS;
991 if (!
m_impl->m_outTuple) {
992 return StatusCode::SUCCESS;
997 return StatusCode::SUCCESS;
1004 if (
m_impl->m_fieldsWritten.size() <= auxid) {
1005 m_impl->m_fieldsWritten.resize(auxid + 1);
1009 if (
m_impl->m_fieldsWritten[auxid]) {
1010 return StatusCode::SUCCESS;
1016 m_impl->m_fieldsWritten[auxid] =
true;
1029 ::Fatal(
"xAOD::RAuxStore::setupOutputData",
1031 return StatusCode::FAILURE;
1038 ::Error(
"xAOD::RAuxStore::setupOutputData",
1041 return StatusCode::FAILURE;
1047 ::Error(
"xAOD::RAuxStore::setupOutputData",
1050 static_cast<int>(auxid));
1051 return StatusCode::FAILURE;
1056 ::Error(
"xAOD::RAuxStore::setupOutputData",
1057 XAOD_MESSAGE(
"No factory found for transient variable "
1059 static_cast<int>(auxid));
1060 return StatusCode::FAILURE;
1078 (!
m_impl->m_fields[auxid])) {
1085 ::Error(
"xAOD::RAuxStore::setupOutputData",
1086 XAOD_MESSAGE(
"Structure mode unknown for variable %s"),
1088 return StatusCode::FAILURE;
1110 auto updater =
m_impl->m_outTuple->CreateModelUpdater();
1111 updater->BeginUpdate();
1112 updater->AddField(std::move(
field));
1113 updater->CommitUpdate();
1120 return StatusCode::SUCCESS;
1126 assert(
m_impl->m_fields.size() > auxid);
1127 assert(
m_impl->m_fields[auxid]);
1128 return m_impl->m_fields[auxid]->objectPtr();
1134 assert(
m_impl->m_fields.size() > auxid);
1135 assert(
m_impl->m_fields[auxid]);
1136 return m_impl->m_fields[auxid]->typeInfo();
const IAuxTypeVectorFactory * getFactory(const std::type_info &ti, const std::type_info &ti_alloc)
Return the vector factory for a given vector element type.
virtual bool hasOutput() const override
Check if an output is being written by the object.
const std::string & prefix() const
Get the currently configured object name prefix.
std::vector< bool > m_fieldsWritten
"Write status" of the different variables
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
const IAuxTypeVectorFactory * addFactory(const std::type_info &ti, const std::type_info &ti_alloc, std::unique_ptr< const IAuxTypeVectorFactory > factory)
Add a new type -> factory mapping.
::Long64_t m_entry
The entry to load from the ntuple.
StatusCode setupAuxField(const ROOT::RFieldBase &field, std::string_view auxName)
This function sets up an auxiliary field by determining its type and attempting to register it with t...
TClass * lookupVectorType(TClass &cl)
Internal function used by xAOD::TAuxStore and xAOD::RAuxStore.
std::vector< std::unique_ptr< SG::IAuxTypeVector > > m_vecs
Variables handled currently by the object (indexed by auxiliary ID)
virtual void setPrefix(std::string_view prefix) override
Set the object name prefix.
std::vector< bool > m_missingFields
Mark fields we've found to be missing.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Make an AuxVectorData object from either a raw vector or an aux store.
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
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...
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
SG::auxid_set_t m_auxIDs
Internal list of auxiliary variable IDs handled currently by the object.
EStructMode
"Structural" modes of the object
virtual ~RAuxStore()
Destructor.
virtual const void * getInputObject(SG::auxid_t auxid) const override
Get a pointer to an input object, as it is in memory, for getIOData()
AthContainers_detail::lock_guard< mutex_t > guard_t
Guard type for multithreaded synchronisation.
std::unique_ptr< SG::AuxStoreInternal > m_transientStore
Store for the in-memory-only variables.
ROOT::RNTupleWriter * m_outTuple
The ntuple being written to.
std::string dynFieldPrefix(const std::string &key)
This function is used to figure out what to name dynamic auxiliary field coming from a container call...
mutex_t m_mutex
Mutex object used for multithreaded synchronisation.
std::size_t m_size
The current size of the container being described.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
std::vector< std::unique_ptr< RFieldHandle > > m_fields
Fields containing the various auxiliary variables.
bool isRegisteredType(SG::auxid_t auxid)
Check if the auxiliary variable has a registered type.
static std::string linkedName(const std::string &name)
Given a variable name, return the name of the corresponding linked variable.
bool isPrimitiveType(std::string_view typeName)
Check if the type name describes a primitive type.
virtual StatusCode getEntryFor(SG::auxid_t auxid) override
Load a single variable from the input.
StatusCode getEntry(std::int64_t entry, int getall=0)
Get entry from the input RNTuple.
static bool classNameHasLink(const std::string &className)
Test to see if a class name corresponds to a class with a linked variable.
Members & m_data
Variables coming from AuxStoreBase.
@ kObjectStore
The object describes a single object.
virtual StatusCode setupOutputData(SG::auxid_t auxid) override
Connect a variable to the output.
@ kContainerStore
The object describes an entire container.
StatusCode scanInputTuple()
Scans the input ntuple for auxiliary data fields and sets up the necessary structures to access them.
SG::auxid_set_t m_decorIDs
Internal list of auxiliary decoration IDs handled currently by the object.
virtual std::string tiAllocName() const =0
Return the (demangled) name of the vector allocator.
Handle mappings between names and auxid_t.
@ Linked
Mark that this variable is linked to another one.
ROOT::RNTupleReader * m_inTuple
The ntuple being read from.
size_t auxid_t
Identifier for a particular aux data item.
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
H5::CompType packed(H5::CompType in)
Members m_data
Member variables of the base class.
virtual bool hasEntryFor(SG::auxid_t auxid) const override
Check if a given variable is available from the input.
AthContainers_detail::mutex mutex_t
Mutex type for multithread synchronization.
std::string getTypeName(const std::type_info &ti)
This function is necessary in order to create type names that ROOT can understand.
ConcurrentBitset & insert(bit_t bit, bit_t new_nbits=0)
Set a bit to 1.
::StatusCode StatusCode
StatusCode definition for legacy code.
Interface for factory objects that create vectors.
virtual const std::type_info * tiAlloc() const =0
Return the type_info of the vector allocator.
std::string m_prefix
Static prefix for the branch names.
static bool isLinkedName(const std::string &name)
Test if a variable name corresponds to a linked variable.
virtual void copy(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const =0
Copy elements between vectors.
const std::type_info * getVecType(SG::auxid_t auxid) const
Return the type of the STL vector used to hold an aux data item.
virtual const std::type_info * getInputType(SG::auxid_t auxid) const override
Get the type of an input object, for getIOType()
AuxVarFlags
Additional flags to qualify an auxiliary variable.
virtual SG::auxid_set_t getSelectedAuxIDs() const override
Get the IDs of the selected aux variables.
bool isAuxIDSelected(SG::auxid_t auxid) const
Check if an auxiliary variable is selected for ouput writing.
StatusCode readFrom(ROOT::RNTupleReader &reader)
Connect the object to an input RNTuple.
std::unique_ptr< IAuxTypeVector > makeVector(SG::auxid_t auxid, size_t size, size_t capacity) const
Construct a new vector to hold an aux item.
EStructMode m_structMode
The "structural" mode of the object.
virtual StatusCode setupInputData(SG::auxid_t auxid) override
Connect a variable to the input.
const std::type_info * auxFieldType(const ROOT::RFieldBase &field, std::string *expectedClassName=nullptr)
This function retrieves the type information for a given auxiliary field.
const std::type_info & getTypeInfo(EDataType type)
This function is used when reading a primitive branch from an input file without the user explicitly ...
Make an AuxVectorData object from either a raw array or an aux store.
constexpr std::enable_if_t< is_bitmask_v< E >, E & > reset(E &lhs, E rhs)
Convenience function to clear bits in a class enum bitmask.
Handle mappings between names and auxid_t.
virtual const void * getIOData(SG::auxid_t auxid) const override
Get a pointer to the data being stored for one aux data item.
virtual void reset() override
Tell the object that all branches will need to be re-read.
RAuxStore(std::string_view prefix="", bool topStore=true, EStructMode mode=EStructMode::kUndefinedStore)
Constructor.
@ kUndefinedStore
The structure mode is not defined.
StatusCode writeTo(ROOT::RNTupleWriter &writer)
Add the variables of the store to an output RNTuple.
A set of aux data identifiers.
Error
The different types of error that can be flagged in the L1TopoRDO.
std::unique_ptr< impl > m_impl
Pointer to the internal object.
reader
read the goodrunslist xml file(s)
ConcurrentBitset & erase(bit_t bit)
Turn off one bit.
std::vector< bool > m_isDecoration
Per variable lock status (indexed by auxiliary ID)
writer
show summary of content
An auxiliary data store that holds data internally.
std::string m_dynPrefix
Dynamic prefix for the branch names.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
bool m_topStore
Flag stating whether this is a "top store".
StatusCode commitTo(ROOT::REntry &entry)
Commit a new entry to the output RNTuple.
bool m_inputScanned
"Scan status" of the input RNTuple
SG::auxid_t getAuxID(const std::string &name, const std::string &clsname="", const Flags flags=Flags::None, const SG::auxid_t linkedVariable=SG::null_auxid)
Look up a name -> auxid_t mapping.
Struct collecting all member variables of this base class.
bool test(bit_t bit) const
Test to see if a bit is set.