ATLAS Offline Software
RootAuxDynIO.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
10 #include "RNTupleAuxDynReader.h"
11 #include "RNTupleAuxDynWriter.h"
12 #include "TBranchAuxDynReader.h"
13 #include "TBranchAuxDynWriter.h"
14 
15 #include "TFile.h"
16 #include "TBranch.h"
17 #include "TClass.h"
18 #include "TROOT.h"
19 #include "TDictAttributeMap.h"
20 
21 
22 #include <ROOT/RNTuple.hxx>
23 
24 namespace RootAuxDynIO
25 {
28 
29  bool
30  hasAuxStore(std::string_view fieldname, TClass *tc) {
31  // check the name first, and only if it does not match AUX_POSTFIX ask TClass
32  return endsWithAuxPostfix(fieldname)
33  or ( tc and ( tc->GetBaseClass("SG::IAuxStore")
34  // the IAuxStore property is used in DataModelTests
35  or RootType(tc).Properties().HasProperty("IAuxStore") ));
36  }
37 
38 
39  std::string
41  {
42  TClass *tc = 0;
43  EDataType type;
44  if( branch->GetExpectedType(tc, type) == 0 && tc != nullptr) {
45  const char* brname = branch->GetName();
46  const char* clname = tc->GetName();
47  size_t namelen = strlen (clname);
48  std::string key = brname;
49  if( strncmp(brname, clname, namelen) == 0 && brname[namelen] == '_' ) {
50  key.erase (0, namelen+1);
51  }
53  return key;
54  }
55  return "";
56  }
57 
58 
59  bool
61  {
62  const std::string bname = branch->GetName();
63  TClass *tc = 0;
64  EDataType type;
65  if( branch->GetExpectedType(tc, type) ) {
66  // error - not expecting this to happen ever, but better report
67  errorcheck::ReportMessage msg (MSG::WARNING, ERRORCHECK_ARGS, "RootAuxDynIO::isAuxDynBranch");
68  msg << "GetExpectedType() failed for branch: " << bname;
69  return false;
70  }
71  if( hasAuxStore(bname, tc) ) {
72  return tc->GetBaseClass("SG::IAuxStoreHolder") != nullptr;
73  }
74  return false;
75  }
76 
77  // --------------------- Dynamic Aux Attribute Readers
78 
79  std::unique_ptr<RootAuxDynIO::IRootAuxDynReader>
80  getBranchAuxDynReader(TTree* tree, TBranch* branch) {
81  return std::make_unique<TBranchAuxDynReader>(tree, branch);
82  }
83 
84  std::unique_ptr<RootAuxDynIO::IRootAuxDynReader>
85  getNTupleAuxDynReader(const std::string& field_name, const std::string& field_type, RNTupleReader* reader) {
86  return std::make_unique<RNTupleAuxDynReader>(field_name, field_type, reader);
87  }
88 
89  // --------------------- Dynamic Aux Attribute Writers
90 
94  std::unique_ptr<RootAuxDynIO::IRootAuxDynWriter>
95  getBranchAuxDynWriter(TTree* tree, int bufferSize, int splitLevel, int offsettab_len, bool do_branch_fill) {
96  return std::make_unique<TBranchAuxDynWriter>(tree, bufferSize, splitLevel, offsettab_len, do_branch_fill);
97  }
98 
99  std::unique_ptr<RootAuxDynIO::IRNTupleAuxDynWriter>
101  return std::make_unique<RNTupleAuxDynWriter>();
102  }
103 }
RootAuxDynIO::getNTupleAuxDynWriter
std::unique_ptr< IRNTupleAuxDynWriter > getNTupleAuxDynWriter()
Definition: RootAuxDynIO.cxx:100
RootStorageSvc::RNTupleModel
ROOT::Experimental::RNTupleModel RNTupleModel
Definition: RNTupleWriterHelper.h:24
tree
TChain * tree
Definition: tile_monitor.h:30
exceptions.h
Exceptions that can be thrown from AthContainers.
pool::RootCollection::RNTupleReader
ROOT::Experimental::RNTupleReader RNTupleReader
Definition: RNTCollection.h:38
RootAuxDynIO::removeAuxPostfix
bool removeAuxPostfix(std::string &str)
if a string ends with AUX_POSTFIX then remove it
Definition: RootAuxDynDefs.h:49
errorcheck::ReportMessage
Helper class to use to report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:173
RootAuxDynIO::getNTupleAuxDynReader
std::unique_ptr< IRootAuxDynReader > getNTupleAuxDynReader(const std::string &field_name, const std::string &field_type, RNTupleReader *reader)
Definition: RootAuxDynIO.cxx:85
RootAuxDynIO::getKeyFromBranch
std::string getKeyFromBranch(TBranch *branch)
Exctract the Aux object SG Key from the branch name.
Definition: RootAuxDynIO.cxx:40
error.h
Helper for emitting error messages.
RootAuxDynIO::getBranchAuxDynReader
std::unique_ptr< IRootAuxDynReader > getBranchAuxDynReader(TTree *, TBranch *)
Definition: RootAuxDynIO.cxx:80
RNTupleAuxDynWriter.h
RootAuxDynIO::endsWithAuxPostfix
bool endsWithAuxPostfix(std::string_view str)
Check if a string ends with AUX_POSTFIX.
Definition: RootAuxDynDefs.h:21
RootAuxDynIO::hasAuxStore
bool hasAuxStore(std::string_view fieldname, TClass *tc)
check if a field/branch with fieldname and type tc has IAuxStore interface
Definition: RootAuxDynIO.cxx:30
RNTupleAuxDynReader.h
RootAuxDynIO
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
Definition: RNTupleContainer.h:25
RootAuxDynIO::isAuxDynBranch
bool isAuxDynBranch(TBranch *branch)
Check is a branch holds AuxStore objects.
Definition: RootAuxDynIO.cxx:60
TBranchAuxDynReader.h
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
RootAuxDynIO::getBranchAuxDynWriter
std::unique_ptr< IRootAuxDynWriter > getBranchAuxDynWriter(TTree *, int bufferSize, int splitLevel, int offsettab_len, bool do_branch_fill)
generate TBranchAuxDynWriter tree -> destination tree do_branch_fill -> flag telling to Fill each TBr...
Definition: RootAuxDynIO.cxx:95
RootAuxDynIO.h
RootType.h
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
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
TScopeAdapter
Definition: RootType.h:119