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 
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);
30 
32 
33  RootOutputTree(RootOutputTree const&) = delete; // Disallow copying and moving
34  RootOutputTree& operator=(RootOutputTree const&) = delete; // Disallow copying and moving
35 
36  template <typename T>
37  void
38  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
48  addAuxiliary(std::string const& branchName, T*& pAux, int bufSize,bool allowCloning=true) {
49  if(allowCloning) {
50  auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
51  } else {
52  unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
53  }
54  }
55 
56  void fastCloneTTree(TTree* in, std::string const& option);
57 
58  static TTree* makeTTree(TFile* filePtr, std::string const& name, int splitLevel);
59 
60  static TTree* assignTTree(TFile* file, TTree* tree);
61 
62  static void writeTTree(TTree* tree);
63 
64  bool isValid() const;
65 
66  void addBranch(std::string const& branchName,
67  std::string const& className,
68  void const*& pProd,
69  int splitLevel,
70  int basketSize,
71  bool produced);
72 
73  bool checkSplitLevelsAndBasketSizes(TTree* inputTree) const;
74 
75  bool checkIfFastClonable(TTree* inputTree) const;
76 
77  bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const;
78 
79  void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree* tree, std::string const& option);
80 
81  void fillTree();
82 
83  void writeTree();
84 
85  TTree const* tree() const {
86  return tree_.get();
87  }
88 
89  TTree* tree() {
90  return tree_.get();
91  }
92 
93  void setEntries() {
94  if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
95  }
96 
97  bool
98  uncloned(std::string const& branchName) const {
99  return clonedReadBranchNames_.find(branchName) == clonedReadBranchNames_.end();
100  }
101 
102  void close();
103 
104  void optimizeBaskets(ULong64_t size) {
105  tree_->OptimizeBaskets(size);
106  }
107 
108  void setAutoFlush(Long64_t size) {
109  tree_->SetAutoFlush(size);
110  }
111  private:
112  static void fillTTree(std::vector<TBranch*> const& branches);
113 // We use bare pointers for pointers to some ROOT entities.
114 // Root owns them and uses bare pointers internally.
115 // Therefore, using smart pointers here will do no good.
118 
119  std::vector<TBranch*> producedBranches_; // does not include cloned branches
120  std::vector<TBranch*> readBranches_;
121  std::vector<TBranch*> auxBranches_;
122  std::vector<TBranch*> unclonedAuxBranches_;
123  std::vector<TBranch*> unclonedReadBranches_;
124 
125  std::set<std::string> clonedReadBranchNames_;
128  };
129 }
130 #endif
size
Write out results.
std::set< std::string > clonedReadBranchNames_
edm::propagate_const< TTree * > tree_
static void fillTTree(std::vector< TBranch * > const &branches)
bool checkSplitLevelsAndBasketSizes(TTree *inputTree) const
TTree const * tree() const
void addAuxiliary(std::string const &branchName, T *&pAux, int bufSize, bool allowCloning=true)
void setAutoFlush(Long64_t size)
std::vector< TBranch * > unclonedAuxBranches_
edm::propagate_const< std::shared_ptr< TFile > > filePtr_
static int const bufSize
Definition: Guid.cc:24
bool checkIfFastClonable(TTree *inputTree) const
BranchType
Definition: BranchType.h:11
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > auxBranches_
RootOutputTree(std::shared_ptr< TFile > filePtr, BranchType const &branchType, int splitLevel, int treeMaxVirtualSize)
static TTree * assignTTree(TFile *file, TTree *tree)
void addBranch(std::string const &branchName, std::string const &className, void const *&pProd, int splitLevel, int basketSize, bool produced)
RootOutputTree & operator=(RootOutputTree const &)=delete
std::vector< TBranch * > unclonedReadBranches_
bool uncloned(std::string const &branchName) const
bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
element_type const * get() const
bool isValid() const
void addAuxiliary(std::string const &branchName, T const *&pAux, int bufSize, bool allowCloning=true)
static void writeTTree(TTree *tree)
std::vector< TBranch * > readBranches_
HLT enums.
Definition: tree.py:1
void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree *tree, std::string const &option)
const eventsetup::produce::Produce produced
Definition: ESProducts.cc:20
long double T
void optimizeBaskets(ULong64_t size)
def branchType(schema, name)
Definition: revisionDML.py:112
std::string className(const T &t)
Definition: ClassName.h:30
void fastCloneTTree(TTree *in, std::string const &option)