LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
RootOutputTree.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Root_RootOutputTree_h
2 #define art_Framework_IO_Root_RootOutputTree_h
3 // vim: set sw=2:
4 
5 // Used by ROOT output modules.
6 
10 #include "cetlib/exempt_ptr.h"
11 
12 #include "TTree.h"
13 
14 #include <memory>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
19 class TFile;
20 class TBranch;
21 
22 namespace art {
23 
25 
26  public: // STATIC MEMBER FUNCTIONS
27  static TTree* makeTTree(TFile*, std::string const& name, int splitLevel);
28  static void writeTTree(TTree*) noexcept(false); // This routine MAY THROW if
29  // art converts a ROOT error
30  // message to an exception.
31 
32  public: // MEMBER FUNCTIONS
33  // Constructor for trees with no fast cloning
34  template <typename Aux>
35  RootOutputTree(cet::exempt_ptr<TFile> filePtr,
36  BranchType const branchType,
37  Aux const*& pAux,
38  ProductProvenances*& pProductProvenanceVector,
39  int const bufSize,
40  int const splitLevel,
41  int64_t const treeMaxVirtualSize,
42  int64_t const saveMemoryObjectThreshold)
43  : filePtr_{filePtr}
44  , tree_{makeTTree(filePtr.get(),
45  BranchTypeToProductTreeName(branchType),
46  splitLevel)}
47  , metaTree_{makeTTree(filePtr.get(),
48  BranchTypeToMetaDataTreeName(branchType),
49  0)}
50  , basketSize_{bufSize}
51  , splitLevel_{splitLevel}
52  , saveMemoryObjectThreshold_{saveMemoryObjectThreshold}
53  {
54  if (treeMaxVirtualSize >= 0) {
55  tree_->SetMaxVirtualSize(treeMaxVirtualSize);
56  }
57  auxBranch_ = tree_->Branch(
58  BranchTypeToAuxiliaryBranchName(branchType).c_str(), &pAux, bufSize, 0);
59  delete pAux;
60  pAux = nullptr;
61  readBranches_.push_back(auxBranch_);
63  metaTree_->Branch(productProvenanceBranchName(branchType).c_str(),
64  &pProductProvenanceVector,
65  bufSize,
66  0);
68  }
69 
70  RootOutputTree(RootOutputTree const&) = delete;
71  RootOutputTree& operator=(RootOutputTree const&) = delete;
72 
73  bool isValid() const;
74 
76  void const*& pProd);
77 
79 
80  void addOutputBranch(BranchDescription const&, void const*& pProd);
81 
82  bool checkSplitLevelAndBasketSize(cet::exempt_ptr<TTree const>) const;
83 
84  bool fastCloneTree(cet::exempt_ptr<TTree const>);
85  void fillTree();
86  void writeTree() const;
87 
88  TTree*
89  tree() const
90  {
91  return tree_;
92  }
93 
94  TTree*
95  metaTree() const
96  {
97  return metaTree_;
98  }
99 
100  void
102  {
103  // The member trees are filled by filling their
104  // branches individually, which ends up not setting
105  // the tree entry count. Tell the trees to set their
106  // entry count based on their branches (all branches
107  // must have the same number of entries).
108  if (tree_->GetNbranches() != 0) {
109  tree_->SetEntries(-1);
110  }
111  if (metaTree_->GetNbranches() != 0) {
112  metaTree_->SetEntries(-1);
113  }
114  }
115 
116  void
117  beginInputFile(bool fastCloning)
118  {
119  fastCloningEnabled_ = fastCloning;
120  }
121 
122  bool
123  uncloned(std::string const& branchName) const
124  {
125  return unclonedReadBranchNames_.find(branchName) !=
127  }
128 
129  private: // MEMBER DATA
130  cet::exempt_ptr<TFile> filePtr_;
131  TTree* const tree_;
132  TTree* const metaTree_;
133  TBranch* auxBranch_{nullptr};
134  TBranch* productProvenanceBranch_{nullptr};
135  // does not include cloned branches
136  std::vector<TBranch*> producedBranches_{};
137  std::vector<TBranch*> metaBranches_{};
138  std::vector<TBranch*> readBranches_{};
139  std::vector<TBranch*> unclonedReadBranches_{};
140  std::set<std::string> unclonedReadBranchNames_{};
141 
142  // The default for 'fastCloningEnabled_' is false so that SubRuns
143  // and Runs are not fast-cloned. We explicitly set this variable
144  // to true for the event tree.
145  bool fastCloningEnabled_{false};
146 
150  int nEntries_{0};
151  };
152 
153 } // namespace art
154 
155 // Local Variables:
156 // mode: c++
157 // End:
158 #endif /* art_Framework_IO_Root_RootOutputTree_h */
bool uncloned(std::string const &branchName) const
bool checkSplitLevelAndBasketSize(cet::exempt_ptr< TTree const >) const
std::string const & BranchTypeToProductTreeName(BranchType const bt)
Definition: BranchType.cc:71
std::string const & productProvenanceBranchName(BranchType const bt)
Definition: BranchType.cc:91
std::set< std::string > unclonedReadBranchNames_
void writeTree() const
std::vector< TBranch * > readBranches_
std::string const & BranchTypeToMetaDataTreeName(BranchType const bt)
Definition: BranchType.cc:77
bool isValid() const
cet::exempt_ptr< TFile > filePtr_
TTree *const metaTree_
RootOutputTree(cet::exempt_ptr< TFile > filePtr, BranchType const branchType, Aux const *&pAux, ProductProvenances *&pProductProvenanceVector, int const bufSize, int const splitLevel, int64_t const treeMaxVirtualSize, int64_t const saveMemoryObjectThreshold)
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const bt)
Definition: BranchType.cc:83
static void writeTTree(TTree *) noexcept(false)
std::vector< TBranch * > producedBranches_
void setOutputBranchAddress(BranchDescription const &pd, void const *&pProd)
TBranch * productProvenanceBranch_
TTree * tree() const
void addOutputBranch(BranchDescription const &, void const *&pProd)
std::vector< TBranch * > unclonedReadBranches_
RootOutputTree & operator=(RootOutputTree const &)=delete
TTree * metaTree() const
void resetOutputBranchAddress(BranchDescription const &)
static TTree * makeTTree(TFile *, std::string const &name, int splitLevel)
BranchType
Definition: BranchType.h:18
bool fastCloneTree(cet::exempt_ptr< TTree const >)
std::vector< ProductProvenance > ProductProvenances
HLT enums.
int64_t saveMemoryObjectThreshold_
void beginInputFile(bool fastCloning)
std::vector< TBranch * > metaBranches_