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 "boost/shared_ptr.hpp"
14 
17 
18 #include "TTree.h"
19 
20 class TFile;
21 class TBranch;
22 
23 namespace edm {
24  class WrapperInterfaceBase;
26  public:
27  RootOutputTree(boost::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  WrapperInterfaceBase const* interface,
70  void const*& pProd,
71  int splitLevel,
72  int basketSize,
73  bool produced);
74 
75  bool checkSplitLevelsAndBasketSizes(TTree* inputTree) const;
76 
77  bool checkIfFastClonable(TTree* inputTree) const;
78 
79  bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const;
80 
81  void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree* tree, std::string const& option);
82 
83  void fillTree() const;
84 
85  void writeTree() const;
86 
87  TTree* tree() const {
88  return tree_;
89  }
90 
91  void setEntries() {
92  if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
93  }
94 
95  bool
96  uncloned(std::string const& branchName) const {
97  return clonedReadBranchNames_.find(branchName) == clonedReadBranchNames_.end();
98  }
99 
100  void close();
101 
102  void optimizeBaskets(ULong64_t size) {
103  tree_->OptimizeBaskets(size);
104  }
105 
106  void setAutoFlush(Long64_t size) {
107  tree_->SetAutoFlush(size);
108  }
109  private:
110  static void fillTTree(std::vector<TBranch*> const& branches);
111 // We use bare pointers for pointers to some ROOT entities.
112 // Root owns them and uses bare pointers internally.
113 // Therefore, using smart pointers here will do no good.
114  boost::shared_ptr<TFile> filePtr_;
115  TTree* tree_;
116  std::vector<TBranch*> producedBranches_; // does not include cloned branches
117  std::vector<TBranch*> readBranches_;
118  std::vector<TBranch*> auxBranches_;
119  std::vector<TBranch*> unclonedAuxBranches_;
120  std::vector<TBranch*> unclonedReadBranches_;
121  std::set<std::string> clonedReadBranchNames_;
124  };
125 }
126 #endif
std::set< std::string > clonedReadBranchNames_
void writeTree() const
void fillTree() const
static void fillTTree(std::vector< TBranch * > const &branches)
bool checkSplitLevelsAndBasketSizes(TTree *inputTree) const
void addAuxiliary(std::string const &branchName, T *&pAux, int bufSize, bool allowCloning=true)
void setAutoFlush(Long64_t size)
std::vector< TBranch * > unclonedAuxBranches_
static int const bufSize
Definition: Guid.cc:24
bool checkIfFastClonable(TTree *inputTree) const
void addBranch(std::string const &branchName, std::string const &className, WrapperInterfaceBase const *interface, void const *&pProd, int splitLevel, int basketSize, bool produced)
BranchType
Definition: BranchType.h:11
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > auxBranches_
boost::shared_ptr< TFile > filePtr_
static TTree * assignTTree(TFile *file, TTree *tree)
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)
eventsetup::produce::Produce produced
Definition: ESProducts.cc:21
RootOutputTree(boost::shared_ptr< TFile > filePtr, BranchType const &branchType, int splitLevel, int treeMaxVirtualSize)
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_
TTree * tree() const
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)