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#include "AuxDiscoverySvc.h"
15
16#include "TBranch.h"
17#include "TClass.h"
18#include "TROOT.h"
19
20#include <ROOT/RNTuple.hxx>
21
22namespace RootAuxDynIO
23{
24
29
31 {
32 TClass *storeTClass = tc.GetBaseClass("SG::IAuxStoreIO");
33 if( storeTClass ) {
34 // This is a class implementing SG::IAuxStoreIO
35 // Find IAuxStoreIO interface offset
36 return tc.GetBaseClassOffset( storeTClass );
37 }
38 return -1;
39 }
40
42 {
43 return m_ioStoreOffset >= 0;
44 }
45
47 return ( hasAuxDynStore()?
48 reinterpret_cast<SG::IAuxStoreIO*>( (char*)object + m_ioStoreOffset )
49 : nullptr);
50 }
51
52
53 // --------------------- Dynamic Aux Attribute Writers
54
55 bool
56 FactoryTool::hasAuxStore(std::string_view fieldname, TClass *tc) const
57 {
58 // check the name first, and only if it does not match AUX_POSTFIX ask TClass
59 return endsWithAuxPostfix(fieldname)
60 or ( tc and ( tc->GetBaseClass("SG::IAuxStore")
61 // the IAuxStore property is used in DataModelTests
62 or RootType(tc).Properties().HasProperty("IAuxStore") ));
63 }
64
65
66 bool
68 {
69 return tc and tc->GetBaseClass("SG::IAuxStoreIO");
70 }
71
72
73 bool
74 FactoryTool::isAuxDynBranch(TBranch *branch) const
75 {
76 const std::string bname = branch->GetName();
77 TClass *tc = 0;
78 EDataType type;
79 if( branch->GetExpectedType(tc, type) ) {
80 // error - not expecting this to happen ever, but better report
81 errorcheck::ReportMessage msg (MSG::WARNING, ERRORCHECK_ARGS, "RootAuxDynIO::isAuxDynBranch");
82 msg << "GetExpectedType() failed for branch: " << bname;
83 return false;
84 }
85 if( hasAuxStore(bname, tc) ) {
86 return tc->GetBaseClass("SG::IAuxStoreHolder") != nullptr;
87 }
88 return false;
89 }
90
91 // --------------------- Dynamic Aux Attribute Writers
92
96 std::unique_ptr<RootAuxDynIO::IRootAuxDynWriter>
97 FactoryTool::getBranchAuxDynWriter(TTree& tree, TClass& cl, int bufferSize, int splitLevel,
98 int offsettab_len, bool do_branch_fill) const {
99 return std::make_unique<TBranchAuxDynWriter>(tree, cl, bufferSize, splitLevel,
100 offsettab_len, do_branch_fill);
101 }
102
103 std::unique_ptr<RootAuxDynIO::IRNTupleAuxDynWriter>
105 return std::make_unique<RNTupleAuxDynWriter>(tc);
106 }
107
108
109 // --------------------- Dynamic Aux Attribute Readers
110
111 std::unique_ptr<IRootAuxDynReader>
112 FactoryTool::getBranchAuxDynReader(TTree* tree, TBranch* branch) const {
113 return std::make_unique<TBranchAuxDynReader>(tree, branch);
114 }
115
116 std::unique_ptr<IRootAuxDynReader>
117 FactoryTool::getNTupleAuxDynReader(const std::string& field_name, const std::string& field_type,
118 ROOT::RNTupleReader* reader) const {
119 return std::make_unique<RNTupleAuxDynReader>(field_name, field_type, reader);
120 }
121
122
123 // --------------------- Dynamic Aux Attribute Share
124
125 std::unique_ptr<IAuxDynShare> FactoryTool::getAuxDynShare(const IAthenaSerializeSvc* serSvc, IAthenaIPCTool* ipcTool) const {
126 return std::make_unique<AuxDiscoverySvc>(serSvc, ipcTool);
127 }
128
129}
130
131// declare the component provided by this library (by type)
This file contains the class definition for the AuxDiscoverySvc class.
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< IAuxDynShare > getAuxDynShare(const IAthenaSerializeSvc *serSvc, IAthenaIPCTool *ipcTool) const override final
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