Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
21 namespace RootAuxDynIO
22 {
23 
25  : m_holderType( tc ),
26  m_ioStoreOffset( auxStoreOffset(tc) )
27  { }
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
66  FactoryTool::hasAuxStoreIO(TClass *tc) const
67  {
68  return tc and tc->GetBaseClass("SG::IAuxStoreIO");
69  }
70 
71 
72  bool
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>
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)
RootAuxDynIO::FactoryTool::hasAuxStoreIO
virtual bool hasAuxStoreIO(TClass *tc) const override final
check if the type tc has IAuxStoreIO interface
Definition: RootAuxDynIO.cxx:66
RootAuxDynIO::FactoryTool::getNTupleAuxDynWriter
virtual std::unique_ptr< IRNTupleAuxDynWriter > getNTupleAuxDynWriter(TClass &tc) const override final
Definition: RootAuxDynIO.cxx:103
tree
TChain * tree
Definition: tile_monitor.h:30
exceptions.h
Exceptions that can be thrown from AthContainers.
errorcheck::ReportMessage
Helper class to use to report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:173
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
SG::IAuxStoreIO
Interface providing I/O for a generic auxiliary store.
Definition: IAuxStoreIO.h:44
EFTrackingXrtAlgorithmConfig.bufferSize
bufferSize
Definition: EFTrackingXrtAlgorithmConfig.py:77
error.h
Helper for emitting error messages.
RootAuxDynIO::FactoryTool
Definition: RootAuxDynIO.h:44
RootAuxDynIO::AuxDynAttrAccess::auxStoreOffset
int auxStoreOffset(TClass &tc)
Definition: RootAuxDynIO.cxx:29
RNTupleAuxDynWriter.h
RootAuxDynIO::FactoryTool::isAuxDynBranch
virtual bool isAuxDynBranch(TBranch *branch) const override final
Check is a branch holds AuxStore objects.
Definition: RootAuxDynIO.cxx:73
RootAuxDynIO::endsWithAuxPostfix
bool endsWithAuxPostfix(std::string_view str)
Check if a string ends with AUX_POSTFIX.
Definition: RootAuxDynDefs.h:21
RootAuxDynIO::AuxDynAttrAccess::m_ioStoreOffset
int m_ioStoreOffset
AuxStoreIO interface offset in the subclass type (for casting). negative means no inheritance.
Definition: RootAuxDynIO.h:32
RootAuxDynIO::AuxDynAttrAccess::castIOStore
SG::IAuxStoreIO * castIOStore(void *object)
Definition: RootAuxDynIO.cxx:45
RNTupleAuxDynReader.h
RootAuxDynIO::FactoryTool::hasAuxStore
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
Definition: RootAuxDynIO.cxx:55
RootAuxDynIO::AuxDynAttrAccess::hasAuxDynStore
bool hasAuxDynStore() const
Definition: RootAuxDynIO.cxx:40
RootAuxDynIO::FactoryTool::getBranchAuxDynWriter
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...
Definition: RootAuxDynIO.cxx:96
RootAuxDynIO
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
Definition: RNTupleContainer.h:26
RootAuxDynIO::FactoryTool::getNTupleAuxDynReader
virtual std::unique_ptr< IRootAuxDynReader > getNTupleAuxDynReader(const std::string &field_name, const std::string &field_type, ROOT::RNTupleReader *reader) const override final
Definition: RootAuxDynIO.cxx:116
TBranchAuxDynReader.h
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
RootAuxDynIO.h
RootType.h
RootAuxDynIO::AuxDynAttrAccess::AuxDynAttrAccess
AuxDynAttrAccess(TClass &tc)
Definition: RootAuxDynIO.cxx:24
collisions.reader
reader
read the goodrunslist xml file(s)
Definition: collisions.py:22
TBranchAuxDynWriter.h
ERRORCHECK_ARGS
#define ERRORCHECK_ARGS
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:323
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
RootAuxDynIO::FactoryTool::getBranchAuxDynReader
virtual std::unique_ptr< IRootAuxDynReader > getBranchAuxDynReader(TTree *, TBranch *) const override final
Definition: RootAuxDynIO.cxx:111
DECLARE_COMPONENT
DECLARE_COMPONENT(MuonGMR4::ReadoutGeomCnvAlg)
TScopeAdapter
Definition: RootType.h:119