CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 #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 {
94  return clonedReadBranchNames_.find(branchName) == clonedReadBranchNames_.end();
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
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_
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, std::string const &processName=std::string())
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)
bool isValid() const
void addAuxiliary(std::string const &branchName, T const *&pAux, int bufSize, bool allowCloning=true)
constexpr element_type const * get() const
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:31
void fastCloneTTree(TTree *in, std::string const &option)