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 #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, 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 {
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
edm::RootOutputTree::fastCloneAuxBranches_
bool fastCloneAuxBranches_
Definition: RootOutputTree.h:115
edm::RootOutputTree::unclonedReadBranches_
std::vector< TBranch * > unclonedReadBranches_
Definition: RootOutputTree.h:111
edm::RootOutputTree::producedBranches_
std::vector< TBranch * > producedBranches_
Definition: RootOutputTree.h:107
edm::RootOutputTree::optimizeBaskets
void optimizeBaskets(ULong64_t size)
Definition: RootOutputTree.h:95
edm::RootOutputTree::fillTTree
static void fillTTree(std::vector< TBranch * > const &branches)
Definition: RootOutputTree.cc:286
BranchType.h
filterRecHits_cfg.splitLevel
splitLevel
Definition: filterRecHits_cfg.py:41
propagate_const.h
edm::RootOutputTree::tree
TTree * tree()
Definition: RootOutputTree.h:82
electrons_cff.branchName
branchName
Definition: electrons_cff.py:515
edm
HLT enums.
Definition: AlignableModifier.h:19
tree
Definition: tree.py:1
edm::propagate_const::get
constexpr element_type const * get() const
Definition: propagate_const.h:64
edm::RootOutputTree::addAuxiliary
void addAuxiliary(std::string const &branchName, T *&pAux, int bufSize, bool allowCloning=true)
Definition: RootOutputTree.h:43
edm::RootOutputTree::writeTTree
static void writeTTree(TTree *tree)
Definition: RootOutputTree.cc:276
fileinputsource_cfi.option
option
Definition: fileinputsource_cfi.py:87
edm::RootOutputTree::RootOutputTree
RootOutputTree(std::shared_ptr< TFile > filePtr, BranchType const &branchType, int splitLevel, int treeMaxVirtualSize)
Definition: RootOutputTree.cc:96
edm::BranchType
BranchType
Definition: BranchType.h:11
edm::RootOutputTree::checkSplitLevelsAndBasketSizes
bool checkSplitLevelsAndBasketSizes(TTree *inputTree) const
Definition: RootOutputTree.cc:132
edm::RootOutputTree::assignTTree
static TTree * assignTTree(TFile *file, TTree *tree)
Definition: RootOutputTree.cc:113
edm::RootOutputTree::tree_
edm::propagate_const< TTree * > tree_
Definition: RootOutputTree.h:105
edm::propagate_const
Definition: propagate_const.h:32
edm::RootOutputTree::unclonedAuxBranches_
std::vector< TBranch * > unclonedAuxBranches_
Definition: RootOutputTree.h:110
edm::RootOutputTree::maybeFastCloneTree
void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree *tree, std::string const &option)
Definition: RootOutputTree.cc:292
edm::RootOutputTree::setAutoFlush
void setAutoFlush(Long64_t size)
Definition: RootOutputTree.h:97
edm::RootOutputTree::operator=
RootOutputTree & operator=(RootOutputTree const &)=delete
edm::RootOutputTree::readBranches_
std::vector< TBranch * > readBranches_
Definition: RootOutputTree.h:108
edm::RootOutputTree::fastCloneTTree
void fastCloneTTree(TTree *in, std::string const &option)
Definition: RootOutputTree.cc:211
edm::RootOutputTree::checkIfFastClonable
bool checkIfFastClonable(TTree *inputTree) const
Definition: RootOutputTree.cc:180
edm::RootOutputTree::clonedReadBranchNames_
std::set< std::string > clonedReadBranchNames_
Definition: RootOutputTree.h:113
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::RootOutputTree::isValid
bool isValid() const
edm::RootOutputTree::makeTTree
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
Definition: RootOutputTree.cc:121
edm::RootOutputTree::writeTree
void writeTree()
Definition: RootOutputTree.cc:290
edm::RootOutputTree::~RootOutputTree
~RootOutputTree()
Definition: RootOutputTree.h:28
recoMuon::in
Definition: RecoMuonEnumerators.h:6
edm::RootOutputTree
Definition: RootOutputTree.h:24
edm::RootOutputTree::checkEntriesInReadBranches
bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const
Definition: RootOutputTree.cc:202
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
edm::RootOutputTree::tree
TTree const * tree() const
Definition: RootOutputTree.h:80
edm::RootOutputTree::setEntries
void setEntries()
Definition: RootOutputTree.h:84
edm::RootOutputTree::uncloned
bool uncloned(std::string const &branchName) const
Definition: RootOutputTree.h:89
T
long double T
Definition: Basic3DVectorLD.h:48
edm::RootOutputTree::filePtr_
edm::propagate_const< std::shared_ptr< TFile > > filePtr_
Definition: RootOutputTree.h:104
edm::RootOutputTree::addAuxiliary
void addAuxiliary(std::string const &branchName, T const *&pAux, int bufSize, bool allowCloning=true)
Definition: RootOutputTree.h:34
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
className
std::string className(const T &t)
Definition: ClassName.h:31
edm::RootOutputTree::close
void close()
Definition: RootOutputTree.cc:353
edm::RootOutputTree::auxBranches_
std::vector< TBranch * > auxBranches_
Definition: RootOutputTree.h:109
edm::RootOutputTree::addBranch
void addBranch(std::string const &branchName, std::string const &className, void const *&pProd, int splitLevel, int basketSize, bool produced)
Definition: RootOutputTree.cc:328
edm::RootOutputTree::fillTree
void fillTree()
Definition: RootOutputTree.cc:314
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
edm::RootOutputTree::currentlyFastCloning_
bool currentlyFastCloning_
Definition: RootOutputTree.h:114