ATLAS Offline Software
Loading...
Searching...
No Matches
RootAuxDynIO.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9#include "RootAuxDynIO.h"
10#include "RNTupleAuxDynReader.h"
11#include "RNTupleAuxDynWriter.h"
12#include "TBranchAuxDynReader.h"
13#include "TBranchAuxDynWriter.h"
14
15#include "TBranch.h"
16#include "TClass.h"
17#include "TROOT.h"
18
19#include <ROOT/RNTuple.hxx>
20
21namespace RootAuxDynIO
22{
23
28
30 {
31 TClass *storeTClass = tc.GetBaseClass("SG::IAuxStoreIO");
32 if( storeTClass ) {
33 // This is a class implementing SG::IAuxStoreIO
34 // Find IAuxStoreIO interface offset
35 return tc.GetBaseClassOffset( storeTClass );
36 }
37 return -1;
38 }
39
41 {
42 return m_ioStoreOffset >= 0;
43 }
44
46 return ( hasAuxDynStore()?
47 reinterpret_cast<SG::IAuxStoreIO*>( (char*)object + m_ioStoreOffset )
48 : nullptr);
49 }
50
51
52 // --------------------- Dynamic Aux Attribute Writers
53
54 bool
55 FactoryTool::hasAuxStore(std::string_view fieldname, TClass *tc) const
56 {
57 // check the name first, and only if it does not match AUX_POSTFIX ask TClass
58 return endsWithAuxPostfix(fieldname)
59 or ( tc and ( tc->GetBaseClass("SG::IAuxStore")
60 // the IAuxStore property is used in DataModelTests
61 or RootType(tc).Properties().HasProperty("IAuxStore") ));
62 }
63
64
65 bool
67 {
68 return tc and tc->GetBaseClass("SG::IAuxStoreIO");
69 }
70
71
72 bool
73 FactoryTool::isAuxDynBranch(TBranch *branch) const
74 {
75 const std::string bname = branch->GetName();
76 TClass *tc = 0;
77 EDataType type;
78 if( branch->GetExpectedType(tc, type) ) {
79 // error - not expecting this to happen ever, but better report
80 errorcheck::ReportMessage msg (MSG::WARNING, ERRORCHECK_ARGS, "RootAuxDynIO::isAuxDynBranch");
81 msg << "GetExpectedType() failed for branch: " << bname;
82 return false;
83 }
84 if( hasAuxStore(bname, tc) ) {
85 return tc->GetBaseClass("SG::IAuxStoreHolder") != nullptr;
86 }
87 return false;
88 }
89
90 // --------------------- Dynamic Aux Attribute Writers
91
95 std::unique_ptr<RootAuxDynIO::IRootAuxDynWriter>
96 FactoryTool::getBranchAuxDynWriter(TTree& tree, TClass& cl, int bufferSize, int splitLevel,
97 int offsettab_len, bool do_branch_fill) const {
98 return std::make_unique<TBranchAuxDynWriter>(tree, cl, bufferSize, splitLevel,
99 offsettab_len, do_branch_fill);
100 }
101
102 std::unique_ptr<RootAuxDynIO::IRNTupleAuxDynWriter>
104 return std::make_unique<RNTupleAuxDynWriter>(tc);
105 }
106
107
108 // --------------------- Dynamic Aux Attribute Readers
109
110 std::unique_ptr<IRootAuxDynReader>
111 FactoryTool::getBranchAuxDynReader(TTree* tree, TBranch* branch) const {
112 return std::make_unique<TBranchAuxDynReader>(tree, branch);
113 }
114
115 std::unique_ptr<IRootAuxDynReader>
116 FactoryTool::getNTupleAuxDynReader(const std::string& field_name, const std::string& field_type,
117 ROOT::RNTupleReader* reader) const {
118 return std::make_unique<RNTupleAuxDynReader>(field_name, field_type, reader);
119 }
120
121}
122
123// declare the component provided by this library (by type)
Exceptions that can be thrown from AthContainers.
static Double_t tc
DECLARE_COMPONENT(MuonGMR4::ReadoutGeomCnvAlg)
TTypeAdapter RootType
Definition RootType.h:211
SG::IAuxStoreIO * castIOStore(void *object)
int m_ioStoreOffset
AuxStoreIO interface offset in the subclass type (for casting). negative means no inheritance.
TClass & m_holderType
TClass of the type containing the AuxStore with attributes.
virtual bool hasAuxStoreIO(TClass *tc) const override final
check if the type tc has IAuxStoreIO interface
virtual std::unique_ptr< IRNTupleAuxDynWriter > getNTupleAuxDynWriter(TClass &tc) const override final
virtual std::unique_ptr< IRootAuxDynWriter > getBranchAuxDynWriter(TTree &, TClass &, int bufferSize, int splitLevel, int offsettab_len, bool do_branch_fill) const override final
generate TBranchAuxDynWriter tree -> destination tree do_branch_fill -> flag telling to Fill each TBr...
virtual bool isAuxDynBranch(TBranch *branch) const override final
Check is a branch holds AuxStore objects.
virtual bool hasAuxStore(std::string_view fieldname, TClass *tc) const override final
check if a field/branch with fieldname and type tc has IAuxStore interface
virtual std::unique_ptr< IRootAuxDynReader > getBranchAuxDynReader(TTree *, TBranch *) const override final
virtual std::unique_ptr< IRootAuxDynReader > getNTupleAuxDynReader(const std::string &field_name, const std::string &field_type, ROOT::RNTupleReader *reader) const override final
Interface providing I/O for a generic auxiliary store.
Definition IAuxStoreIO.h:44
Helper class to use to report a message.
Helper for emitting error messages.
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
bool endsWithAuxPostfix(std::string_view str)
Check if a string ends with AUX_POSTFIX.
MsgStream & msg
Definition testRead.cxx:32
TChain * tree