CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
18 
19 #include "TTree.h"
20 
21 class TFile;
22 class TBranch;
23 
24 namespace edm {
26  public:
27  RootOutputTree(std::shared_ptr<TFile> filePtr,
28  BranchType const& branchType,
29  int splitLevel,
30  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
39  addAuxiliary(std::string const& branchName, T const*& pAux, int bufSize, bool allowCloning=true) {
40  if(allowCloning) {
41  auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
42  } else {
43  unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
44  }
45  }
46 
47  template <typename T>
48  void
49  addAuxiliary(std::string const& branchName, T*& pAux, int bufSize,bool allowCloning=true) {
50  if(allowCloning) {
51  auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
52  } else {
53  unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
54  }
55  }
56 
57  void fastCloneTTree(TTree* in, std::string const& option);
58 
59  static TTree* makeTTree(TFile* filePtr, std::string const& name, int splitLevel);
60 
61  static TTree* assignTTree(TFile* file, TTree* tree);
62 
63  static void writeTTree(TTree* tree);
64 
65  bool isValid() const;
66 
67  void addBranch(std::string const& branchName,
68  std::string const& className,
69  void const*& pProd,
70  int splitLevel,
71  int basketSize,
72  bool produced);
73 
74  bool checkSplitLevelsAndBasketSizes(TTree* inputTree) const;
75 
76  bool checkIfFastClonable(TTree* inputTree) const;
77 
78  bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const;
79 
80  void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree* tree, std::string const& option);
81 
82  void fillTree();
83 
84  void writeTree();
85 
86  TTree const* tree() const {
87  return tree_.get();
88  }
89 
90  TTree* tree() {
91  return tree_.get();
92  }
93 
94  void setEntries() {
95  if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
96  }
97 
98  bool
99  uncloned(std::string const& branchName) const {
100  return clonedReadBranchNames_.find(branchName) == clonedReadBranchNames_.end();
101  }
102 
103  void close();
104 
105  void optimizeBaskets(ULong64_t size) {
106  tree_->OptimizeBaskets(size);
107  }
108 
109  void setAutoFlush(Long64_t size) {
110  tree_->SetAutoFlush(size);
111  }
112  private:
113  static void fillTTree(std::vector<TBranch*> const& branches);
114 // We use bare pointers for pointers to some ROOT entities.
115 // Root owns them and uses bare pointers internally.
116 // Therefore, using smart pointers here will do no good.
119 
120  std::vector<TBranch*> producedBranches_; // does not include cloned branches
121  std::vector<TBranch*> readBranches_;
122  std::vector<TBranch*> auxBranches_;
123  std::vector<TBranch*> unclonedAuxBranches_;
124  std::vector<TBranch*> unclonedReadBranches_;
125 
126  std::set<std::string> clonedReadBranchNames_;
129  };
130 }
131 #endif
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
eventsetup::produce::Produce produced
Definition: ESProducts.cc:20
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_
void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree *tree, std::string const &option)
long double T
void optimizeBaskets(ULong64_t size)
tuple size
Write out results.
std::string className(const T &t)
Definition: ClassName.h:30
void fastCloneTTree(TTree *in, std::string const &option)