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