CMS 3D CMS Logo

RootOutputTree.h
Go to the documentation of this file.
1 #ifndef IOPool_Output_RootOutputTree_h
2 #define IOPool_Output_RootOutputTree_h
3 
4 /*----------------------------------------------------------------------
5 
6 RootOutputTree.h // used by ROOT output modules
7 
8 ----------------------------------------------------------------------*/
9 
10 #include <string>
11 #include <vector>
12 #include <set>
13 #include <memory>
14 
17 
18 #include "TTree.h"
19 
20 class TFile;
21 class TBranch;
22 
23 namespace edm {
25  public:
26  RootOutputTree(std::shared_ptr<TFile> filePtr,
27  BranchType const& branchType,
28  int splitLevel,
29  int treeMaxVirtualSize,
31 
33 
34  RootOutputTree(RootOutputTree const&) = delete; // Disallow copying and moving
35  RootOutputTree& operator=(RootOutputTree const&) = delete; // Disallow copying and moving
36 
37  template <typename T>
38  void addAuxiliary(std::string const& branchName, T const*& pAux, int bufSize, bool allowCloning = true) {
39  if (allowCloning) {
40  auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
41  } else {
42  unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
43  }
44  }
45 
46  template <typename T>
47  void addAuxiliary(std::string const& branchName, T*& pAux, int bufSize, bool allowCloning = true) {
48  if (allowCloning) {
49  auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
50  } else {
51  unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
52  }
53  }
54 
55  void fastCloneTTree(TTree* in, std::string const& option);
56 
57  static TTree* makeTTree(TFile* filePtr, std::string const& name, int splitLevel);
58 
59  static TTree* assignTTree(TFile* file, TTree* tree);
60 
61  static void writeTTree(TTree* tree);
62 
63  bool isValid() const;
64 
65  void addBranch(std::string const& branchName,
66  std::string const& className,
67  void const*& pProd,
68  int splitLevel,
69  int basketSize,
70  bool produced);
71 
72  bool checkSplitLevelsAndBasketSizes(TTree* inputTree) const;
73 
74  bool checkIfFastClonable(TTree* inputTree) const;
75 
76  bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const;
77 
78  void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree* tree, std::string const& option);
79 
80  void fillTree();
81 
82  void writeTree();
83 
84  TTree const* tree() const { return tree_.get(); }
85 
86  TTree* tree() { return tree_.get(); }
87 
88  void setEntries() {
89  if (tree_->GetNbranches() != 0)
90  tree_->SetEntries(-1);
91  }
92 
93  bool uncloned(std::string const& branchName) const {
95  }
96 
97  void close();
98 
99  void optimizeBaskets(ULong64_t size) { tree_->OptimizeBaskets(size); }
100 
101  void setAutoFlush(Long64_t size) { tree_->SetAutoFlush(size); }
102 
103  private:
104  static void fillTTree(std::vector<TBranch*> const& branches);
105  // We use bare pointers for pointers to some ROOT entities.
106  // Root owns them and uses bare pointers internally.
107  // Therefore, using smart pointers here will do no good.
110 
111  std::vector<TBranch*> producedBranches_; // does not include cloned branches
112  std::vector<TBranch*> readBranches_;
113  std::vector<TBranch*> auxBranches_;
114  std::vector<TBranch*> unclonedAuxBranches_;
115  std::vector<TBranch*> unclonedReadBranches_;
116 
117  std::set<std::string> clonedReadBranchNames_;
120  };
121 } // namespace edm
122 #endif
edm::RootOutputTree::fastCloneAuxBranches_
bool fastCloneAuxBranches_
Definition: RootOutputTree.h:119
edm::RootOutputTree::unclonedReadBranches_
std::vector< TBranch * > unclonedReadBranches_
Definition: RootOutputTree.h:115
edm::RootOutputTree::producedBranches_
std::vector< TBranch * > producedBranches_
Definition: RootOutputTree.h:111
edm::RootOutputTree::optimizeBaskets
void optimizeBaskets(ULong64_t size)
Definition: RootOutputTree.h:99
edm::RootOutputTree::fillTTree
static void fillTTree(std::vector< TBranch * > const &branches)
Definition: RootOutputTree.cc:289
BranchType.h
filterRecHits_cfg.splitLevel
splitLevel
Definition: filterRecHits_cfg.py:41
propagate_const.h
edm::RootOutputTree::tree
TTree * tree()
Definition: RootOutputTree.h:86
electrons_cff.branchName
branchName
Definition: electrons_cff.py:520
edm
HLT enums.
Definition: AlignableModifier.h:19
tree
Definition: tree.py:1
edm::propagate_const::get
constexpr element_type const * get() const
Definition: propagate_const.h:64
edm::RootOutputTree::addAuxiliary
void addAuxiliary(std::string const &branchName, T *&pAux, int bufSize, bool allowCloning=true)
Definition: RootOutputTree.h:47
edm::RootOutputTree::writeTTree
static void writeTTree(TTree *tree)
Definition: RootOutputTree.cc:279
fileinputsource_cfi.option
option
Definition: fileinputsource_cfi.py:94
edm::BranchType
BranchType
Definition: BranchType.h:11
edm::RootOutputTree::checkSplitLevelsAndBasketSizes
bool checkSplitLevelsAndBasketSizes(TTree *inputTree) const
Definition: RootOutputTree.cc:135
edm::RootOutputTree::assignTTree
static TTree * assignTTree(TFile *file, TTree *tree)
Definition: RootOutputTree.cc:116
edm::RootOutputTree::tree_
edm::propagate_const< TTree * > tree_
Definition: RootOutputTree.h:109
edm::propagate_const
Definition: propagate_const.h:32
edm::RootOutputTree::unclonedAuxBranches_
std::vector< TBranch * > unclonedAuxBranches_
Definition: RootOutputTree.h:114
edm::RootOutputTree::maybeFastCloneTree
void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree *tree, std::string const &option)
Definition: RootOutputTree.cc:295
edm::RootOutputTree::setAutoFlush
void setAutoFlush(Long64_t size)
Definition: RootOutputTree.h:101
edm::RootOutputTree::operator=
RootOutputTree & operator=(RootOutputTree const &)=delete
edm::RootOutputTree::readBranches_
std::vector< TBranch * > readBranches_
Definition: RootOutputTree.h:112
edm::RootOutputTree::RootOutputTree
RootOutputTree(std::shared_ptr< TFile > filePtr, BranchType const &branchType, int splitLevel, int treeMaxVirtualSize, std::string const &processName=std::string())
Definition: RootOutputTree.cc:96
edm::RootOutputTree::fastCloneTTree
void fastCloneTTree(TTree *in, std::string const &option)
Definition: RootOutputTree.cc:214
edm::RootOutputTree::checkIfFastClonable
bool checkIfFastClonable(TTree *inputTree) const
Definition: RootOutputTree.cc:183
edm::RootOutputTree::clonedReadBranchNames_
std::set< std::string > clonedReadBranchNames_
Definition: RootOutputTree.h:117
geometryDiff.file
file
Definition: geometryDiff.py:13
edm::RootOutputTree::isValid
bool isValid() const
edm::RootOutputTree::makeTTree
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
Definition: RootOutputTree.cc:124
edm::RootOutputTree::writeTree
void writeTree()
Definition: RootOutputTree.cc:293
edm::RootOutputTree::~RootOutputTree
~RootOutputTree()
Definition: RootOutputTree.h:32
recoMuon::in
Definition: RecoMuonEnumerators.h:6
edm::RootOutputTree
Definition: RootOutputTree.h:24
edm::RootOutputTree::checkEntriesInReadBranches
bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const
Definition: RootOutputTree.cc:205
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
edm::RootOutputTree::tree
TTree const * tree() const
Definition: RootOutputTree.h:84
edm::RootOutputTree::setEntries
void setEntries()
Definition: RootOutputTree.h:88
edm::RootOutputTree::uncloned
bool uncloned(std::string const &branchName) const
Definition: RootOutputTree.h:93
T
long double T
Definition: Basic3DVectorLD.h:48
edm::RootOutputTree::filePtr_
edm::propagate_const< std::shared_ptr< TFile > > filePtr_
Definition: RootOutputTree.h:108
edm::RootOutputTree::addAuxiliary
void addAuxiliary(std::string const &branchName, T const *&pAux, int bufSize, bool allowCloning=true)
Definition: RootOutputTree.h:38
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
className
std::string className(const T &t)
Definition: ClassName.h:31
edm::RootOutputTree::close
void close()
Definition: RootOutputTree.cc:356
edm::RootOutputTree::auxBranches_
std::vector< TBranch * > auxBranches_
Definition: RootOutputTree.h:113
edm::RootOutputTree::addBranch
void addBranch(std::string const &branchName, std::string const &className, void const *&pProd, int splitLevel, int basketSize, bool produced)
Definition: RootOutputTree.cc:331
edm::RootOutputTree::fillTree
void fillTree()
Definition: RootOutputTree.cc:317
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
edm::RootOutputTree::currentlyFastCloning_
bool currentlyFastCloning_
Definition: RootOutputTree.h:118