CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes
edm::RootOutputTree Class Reference

#include <RootOutputTree.h>

Public Member Functions

template<typename T >
void addAuxiliary (std::string const &branchName, T const *&pAux, int bufSize, bool allowCloning=true)
 
template<typename T >
void addAuxiliary (std::string const &branchName, T *&pAux, int bufSize, bool allowCloning=true)
 
void addBranch (std::string const &branchName, std::string const &className, void const *&pProd, int splitLevel, int basketSize, bool produced)
 
bool checkEntriesInReadBranches (Long64_t expectedNumberOfEntries) const
 
bool checkIfFastClonable (TTree *inputTree) const
 
bool checkSplitLevelsAndBasketSizes (TTree *inputTree) const
 
void close ()
 
void fastCloneTTree (TTree *in, std::string const &option)
 
void fillTree () const
 
bool isValid () const
 
void maybeFastCloneTree (bool canFastClone, bool canFastCloneAux, TTree *tree, std::string const &option)
 
RootOutputTreeoperator= (RootOutputTree const &)=delete
 
void optimizeBaskets (ULong64_t size)
 
 RootOutputTree (std::shared_ptr< TFile > filePtr, BranchType const &branchType, int splitLevel, int treeMaxVirtualSize)
 
 RootOutputTree (RootOutputTree const &)=delete
 
void setAutoFlush (Long64_t size)
 
void setEntries ()
 
TTree * tree () const
 
bool uncloned (std::string const &branchName) const
 
void writeTree () const
 
 ~RootOutputTree ()
 

Static Public Member Functions

static TTree * assignTTree (TFile *file, TTree *tree)
 
static TTree * makeTTree (TFile *filePtr, std::string const &name, int splitLevel)
 
static void writeTTree (TTree *tree)
 

Static Private Member Functions

static void fillTTree (std::vector< TBranch * > const &branches)
 

Private Attributes

std::vector< TBranch * > auxBranches_
 
std::set< std::string > clonedReadBranchNames_
 
bool currentlyFastCloning_
 
bool fastCloneAuxBranches_
 
std::shared_ptr< TFile > filePtr_
 
std::vector< TBranch * > producedBranches_
 
std::vector< TBranch * > readBranches_
 
TTree * tree_
 
std::vector< TBranch * > unclonedAuxBranches_
 
std::vector< TBranch * > unclonedReadBranches_
 

Detailed Description

Definition at line 24 of file RootOutputTree.h.

Constructor & Destructor Documentation

edm::RootOutputTree::RootOutputTree ( std::shared_ptr< TFile >  filePtr,
BranchType const &  branchType,
int  splitLevel,
int  treeMaxVirtualSize 
)

Definition at line 87 of file RootOutputTree.cc.

References tree_.

91  :
92  filePtr_(filePtr),
95  readBranches_(),
96  auxBranches_(),
100  fastCloneAuxBranches_(false) {
101 
102  if(treeMaxVirtualSize >= 0) tree_->SetMaxVirtualSize(treeMaxVirtualSize);
103  }
std::set< std::string > clonedReadBranchNames_
std::shared_ptr< TFile > filePtr_
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > auxBranches_
std::vector< TBranch * > unclonedReadBranches_
std::string const & BranchTypeToProductTreeName(BranchType const &branchType)
Definition: BranchType.cc:103
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
std::vector< TBranch * > readBranches_
edm::RootOutputTree::~RootOutputTree ( )
inline

Definition at line 31 of file RootOutputTree.h.

31 {}
edm::RootOutputTree::RootOutputTree ( RootOutputTree const &  )
delete

Member Function Documentation

template<typename T >
void edm::RootOutputTree::addAuxiliary ( std::string const &  branchName,
T const *&  pAux,
int  bufSize,
bool  allowCloning = true 
)
inline

Definition at line 38 of file RootOutputTree.h.

References auxBranches_, edm::bufSize, tree_, and unclonedAuxBranches_.

Referenced by edm::RootOutputFile::RootOutputFile().

38  {
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  }
std::vector< TBranch * > unclonedAuxBranches_
static int const bufSize
Definition: Guid.cc:24
std::vector< TBranch * > auxBranches_
template<typename T >
void edm::RootOutputTree::addAuxiliary ( std::string const &  branchName,
T *&  pAux,
int  bufSize,
bool  allowCloning = true 
)
inline

Definition at line 48 of file RootOutputTree.h.

References auxBranches_, edm::bufSize, tree_, and unclonedAuxBranches_.

48  {
49  if(allowCloning) {
50  auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
51  } else {
52  unclonedAuxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
53  }
54  }
std::vector< TBranch * > unclonedAuxBranches_
static int const bufSize
Definition: Guid.cc:24
std::vector< TBranch * > auxBranches_
void edm::RootOutputTree::addBranch ( std::string const &  branchName,
std::string const &  className,
void const *&  pProd,
int  splitLevel,
int  basketSize,
bool  produced 
)

Definition at line 333 of file RootOutputTree.cc.

References assert(), edm::BranchDescription::invalidBasketSize, edm::BranchDescription::invalidSplitLevel, producedBranches_, readBranches_, dtDQMMerge_cfg::splitLevel, and tree_.

Referenced by edm::RootOutputFile::RootOutputFile().

338  {
341  TBranch* branch = tree_->Branch(branchName.c_str(),
342  className.c_str(),
343  &pProd,
344  basketSize,
345  splitLevel);
346  assert(branch != nullptr);
347 /*
348  if(pProd != nullptr) {
349  // Delete the product that ROOT has allocated.
350  WrapperBase const* edp = static_cast<WrapperBase const *>(pProd);
351  delete edp;
352  pProd = nullptr;
353  }
354 */
355  if(produced) {
356  producedBranches_.push_back(branch);
357  } else {
358  readBranches_.push_back(branch);
359  }
360  }
static int const invalidSplitLevel
static int const invalidBasketSize
assert(m_qm.get())
std::vector< TBranch * > producedBranches_
eventsetup::produce::Produce produced
Definition: ESProducts.cc:20
std::vector< TBranch * > readBranches_
std::string className(const T &t)
Definition: ClassName.h:30
TTree * edm::RootOutputTree::assignTTree ( TFile *  file,
TTree *  tree 
)
static

Definition at line 106 of file RootOutputTree.cc.

References bookConverter::max, and tree().

Referenced by makeTTree().

106  {
107  tree->SetDirectory(filePtr);
108  // Turn off autosaving because it is such a memory hog and we are not using
109  // this check-pointing feature anyway.
111  return tree;
112  }
TTree * tree() const
bool edm::RootOutputTree::checkEntriesInReadBranches ( Long64_t  expectedNumberOfEntries) const

Definition at line 201 of file RootOutputTree.cc.

References readBranches_.

Referenced by edm::RootOutputFile::writeIndexIntoFile().

201  {
202  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end(); it != itEnd; ++it) {
203  if((*it)->GetEntries() != expectedNumberOfEntries) {
204  return false;
205  }
206  }
207  return true;
208  }
std::vector< TBranch * > readBranches_
bool edm::RootOutputTree::checkIfFastClonable ( TTree *  inputTree) const

Definition at line 179 of file RootOutputTree.cc.

References readBranches_.

Referenced by edm::RootOutputFile::beginInputFile().

179  {
180 
181  if(inputTree == nullptr) return false;
182 
183  // Do the sub-branches match in the input and output. Extra sub-branches in the input are OK for fast cloning, but not in the output.
184  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end(); it != itEnd; ++it) {
185  TBranchElement* outputBranch = dynamic_cast<TBranchElement*>(*it);
186  if(outputBranch != nullptr) {
187  TBranchElement* inputBranch = dynamic_cast<TBranchElement*>(inputTree->GetBranch(outputBranch->GetName()));
188  if(inputBranch != nullptr) {
189  // We have a matching top level branch. Do the recursive check on subbranches.
190  if(!checkMatchingBranches(inputBranch, outputBranch)) {
191  LogInfo("FastCloning")
192  << "Fast Cloning disabled because a data member has been added to split branch: " << inputBranch->GetName() << "\n.";
193  return false;
194  }
195  }
196  }
197  }
198  return true;
199  }
std::vector< TBranch * > readBranches_
bool edm::RootOutputTree::checkSplitLevelsAndBasketSizes ( TTree *  inputTree) const

Definition at line 127 of file RootOutputTree.cc.

References assert(), and readBranches_.

Referenced by edm::RootOutputFile::beginInputFile().

127  {
128 
129  assert(inputTree != nullptr);
130 
131  // Do the split level and basket size match in the input and output?
132  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end();
133  it != itEnd; ++it) {
134 
135  TBranch* outputBranch = *it;
136  if(outputBranch != nullptr) {
137  TBranch* inputBranch = inputTree->GetBranch(outputBranch->GetName());
138 
139  if(inputBranch != nullptr) {
140  if(inputBranch->GetSplitLevel() != outputBranch->GetSplitLevel() ||
141  inputBranch->GetBasketSize() != outputBranch->GetBasketSize()) {
142  return false;
143  }
144  }
145  }
146  }
147  return true;
148  }
assert(m_qm.get())
std::vector< TBranch * > readBranches_
void edm::RootOutputTree::close ( void  )

Definition at line 363 of file RootOutputTree.cc.

References auxBranches_, filePtr_, producedBranches_, readBranches_, tree_, unclonedAuxBranches_, and unclonedReadBranches_.

Referenced by lumiQTWidget.ApplicationWindow::fileQuit(), esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), and Vispa.Gui.FindDialog.FindDialog::keyPressEvent().

363  {
364  // The TFile was just closed.
365  // Just to play it safe, zero all pointers to quantities in the file.
366  auxBranches_.clear();
367  unclonedAuxBranches_.clear();
368  producedBranches_.clear();
369  readBranches_.clear();
370  unclonedReadBranches_.clear();
371  tree_ = nullptr;
372  filePtr_.reset();
373  }
std::shared_ptr< TFile > filePtr_
std::vector< TBranch * > unclonedAuxBranches_
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > auxBranches_
std::vector< TBranch * > unclonedReadBranches_
std::vector< TBranch * > readBranches_
void edm::RootOutputTree::fastCloneTTree ( TTree *  in,
std::string const &  option 
)

Definition at line 211 of file RootOutputTree.cc.

References assert(), auxBranches_, Exception, fastCloneAuxBranches_, edm::errors::FatalRootError, prof2calltree::last, edm::DuplicateTreeSentry::tree(), tree_, and unclonedAuxBranches_.

Referenced by maybeFastCloneTree().

211  {
212  if(in->GetEntries() != 0) {
213  TObjArray* branches = tree_->GetListOfBranches();
214  // If any products were produced (not just event products), the EventAuxiliary will be modified.
215  // In that case, don't fast copy auxiliary branches. Remove them, and add back after fast copying.
216  std::map<Int_t, TBranch *> auxIndexes;
217  bool mustRemoveSomeAuxs = false;
218  if(!fastCloneAuxBranches_) {
219  for(std::vector<TBranch *>::const_iterator it = auxBranches_.begin(), itEnd = auxBranches_.end();
220  it != itEnd; ++it) {
221  int auxIndex = branches->IndexOf(*it);
222  assert (auxIndex >= 0);
223  auxIndexes.insert(std::make_pair(auxIndex, *it));
224  branches->RemoveAt(auxIndex);
225  }
226  mustRemoveSomeAuxs = true;
227  }
228 
229  //Deal with any aux branches which can never be cloned
230  for(std::vector<TBranch *>::const_iterator it = unclonedAuxBranches_.begin(),
231  itEnd = unclonedAuxBranches_.end();
232  it != itEnd; ++it) {
233  int auxIndex = branches->IndexOf(*it);
234  assert (auxIndex >= 0);
235  auxIndexes.insert(std::make_pair(auxIndex, *it));
236  branches->RemoveAt(auxIndex);
237  mustRemoveSomeAuxs = true;
238  }
239 
240  if(mustRemoveSomeAuxs) {
241  branches->Compress();
242  }
243 
244  DuplicateTreeSentry dupTree(in);
245  TTreeCloner cloner(dupTree.tree(), tree_, option.c_str(), TTreeCloner::kNoWarnings|TTreeCloner::kIgnoreMissingTopLevel);
246 
247  if(!cloner.IsValid()) {
248  // Let's check why
249  static const char* okerror = "One of the export branch";
250  if(strncmp(cloner.GetWarning(), okerror, strlen(okerror)) == 0) {
251  // That's fine we will handle it;
252  } else {
254  << "invalid TTreeCloner (" << cloner.GetWarning() << ")\n";
255  }
256  }
257  tree_->SetEntries(tree_->GetEntries() + in->GetEntries());
258  Service<RootHandlers> rootHandler;
259  rootHandler->ignoreWarningsWhileDoing([&cloner] { cloner.Exec(); });
260 
261  if(mustRemoveSomeAuxs) {
262  for(std::map<Int_t, TBranch *>::const_iterator it = auxIndexes.begin(), itEnd = auxIndexes.end();
263  it != itEnd; ++it) {
264  // Add the auxiliary branches back after fast copying the rest of the tree.
265  Int_t last = branches->GetLast();
266  if(last >= 0) {
267  branches->AddAtAndExpand(branches->At(last), last+1);
268  for(Int_t ind = last-1; ind >= it->first; --ind) {
269  branches->AddAt(branches->At(ind), ind+1);
270  };
271  branches->AddAt(it->second, it->first);
272  } else {
273  branches->Add(it->second);
274  }
275  }
276  }
277  }
278  }
assert(m_qm.get())
std::vector< TBranch * > unclonedAuxBranches_
std::vector< TBranch * > auxBranches_
void edm::RootOutputTree::fillTree ( ) const

Definition at line 321 of file RootOutputTree.cc.

References auxBranches_, currentlyFastCloning_, fastCloneAuxBranches_, fillTTree(), producedBranches_, tree_, unclonedAuxBranches_, and unclonedReadBranches_.

Referenced by core.AutoFillTreeProducer.AutoFillTreeProducer::process().

321  {
327  } else {
328  tree_->Fill();
329  }
330  }
static void fillTTree(std::vector< TBranch * > const &branches)
std::vector< TBranch * > unclonedAuxBranches_
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > auxBranches_
std::vector< TBranch * > unclonedReadBranches_
void edm::RootOutputTree::fillTTree ( std::vector< TBranch * > const &  branches)
staticprivate

Definition at line 290 of file RootOutputTree.cc.

References HcalObjRepresent::Fill(), and edm::for_all().

Referenced by fillTree().

290  {
291  for_all(branches, std::bind(&TBranch::Fill, std::placeholders::_1));
292  }
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
bool edm::RootOutputTree::isValid ( ) const
TTree * edm::RootOutputTree::makeTTree ( TFile *  filePtr,
std::string const &  name,
int  splitLevel 
)
static

Definition at line 115 of file RootOutputTree.cc.

References assignTTree(), Exception, edm::errors::FatalRootError, dtDQMMerge_cfg::splitLevel, and tree().

Referenced by edm::RootOutputFile::RootOutputFile().

115  {
116  TTree* tree = new TTree(name.c_str(), "", splitLevel);
117  if(!tree) throw edm::Exception(errors::FatalRootError)
118  << "Failed to create the tree: " << name << "\n";
119  if(tree->IsZombie())
121  << "Tree: " << name << " is a zombie." << "\n";
122 
123  return assignTTree(filePtr, tree);
124  }
static TTree * assignTTree(TFile *file, TTree *tree)
TTree * tree() const
void edm::RootOutputTree::maybeFastCloneTree ( bool  canFastClone,
bool  canFastCloneAux,
TTree *  tree,
std::string const &  option 
)

Definition at line 300 of file RootOutputTree.cc.

References clonedReadBranchNames_, currentlyFastCloning_, fastCloneAuxBranches_, fastCloneTTree(), readBranches_, AlCaHLTBitMon_QueryRunRegistry::string, tree_, and unclonedReadBranches_.

Referenced by edm::RootOutputFile::beginInputFile().

300  {
301  unclonedReadBranches_.clear();
302  clonedReadBranchNames_.clear();
303  currentlyFastCloning_ = canFastClone && !readBranches_.empty();
305  fastCloneAuxBranches_ = canFastCloneAux;
306  fastCloneTTree(tree, option);
307  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end();
308  it != itEnd; ++it) {
309  if((*it)->GetEntries() == tree_->GetEntries()) {
310  clonedReadBranchNames_.insert(std::string((*it)->GetName()));
311  } else {
312  unclonedReadBranches_.push_back(*it);
313  }
314  }
315  Service<JobReport> reportSvc;
316  reportSvc->reportFastClonedBranches(clonedReadBranchNames_, tree_->GetEntries());
317  }
318  }
std::set< std::string > clonedReadBranchNames_
std::vector< TBranch * > unclonedReadBranches_
std::vector< TBranch * > readBranches_
TTree * tree() const
void fastCloneTTree(TTree *in, std::string const &option)
RootOutputTree& edm::RootOutputTree::operator= ( RootOutputTree const &  )
delete
void edm::RootOutputTree::optimizeBaskets ( ULong64_t  size)
inline

Definition at line 100 of file RootOutputTree.h.

References tree_.

Referenced by edm::RootOutputFile::writeLuminosityBlock(), and edm::RootOutputFile::writeRun().

100  {
101  tree_->OptimizeBaskets(size);
102  }
tuple size
Write out results.
void edm::RootOutputTree::setAutoFlush ( Long64_t  size)
inline

Definition at line 104 of file RootOutputTree.h.

References tree_.

Referenced by edm::RootOutputFile::RootOutputFile().

104  {
105  tree_->SetAutoFlush(size);
106  }
tuple size
Write out results.
void edm::RootOutputTree::setEntries ( )
inline

Definition at line 89 of file RootOutputTree.h.

References tree_.

Referenced by edm::RootOutputFile::respondToCloseInputFile().

89  {
90  if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
91  }
TTree* edm::RootOutputTree::tree ( ) const
inline
bool edm::RootOutputTree::uncloned ( std::string const &  branchName) const
inline

Definition at line 94 of file RootOutputTree.h.

References clonedReadBranchNames_.

94  {
95  return clonedReadBranchNames_.find(branchName) == clonedReadBranchNames_.end();
96  }
std::set< std::string > clonedReadBranchNames_
void edm::RootOutputTree::writeTree ( ) const

Definition at line 295 of file RootOutputTree.cc.

References tree_, and writeTTree().

295  {
296  writeTTree(tree_);
297  }
static void writeTTree(TTree *tree)
void edm::RootOutputTree::writeTTree ( TTree *  tree)
static

Definition at line 281 of file RootOutputTree.cc.

References edm::setRefCoreStreamer().

Referenced by edm::RootOutputFile::finishEndFile(), and writeTree().

281  {
282  if(tree->GetNbranches() != 0) {
283  tree->SetEntries(-1);
284  }
285  setRefCoreStreamer(true);
286  tree->AutoSave("FlushBaskets");
287  }
void setRefCoreStreamer(bool resetAll=false)
TTree * tree() const

Member Data Documentation

std::vector<TBranch*> edm::RootOutputTree::auxBranches_
private

Definition at line 116 of file RootOutputTree.h.

Referenced by addAuxiliary(), close(), fastCloneTTree(), and fillTree().

std::set<std::string> edm::RootOutputTree::clonedReadBranchNames_
private

Definition at line 119 of file RootOutputTree.h.

Referenced by maybeFastCloneTree(), and uncloned().

bool edm::RootOutputTree::currentlyFastCloning_
private

Definition at line 120 of file RootOutputTree.h.

Referenced by fillTree(), and maybeFastCloneTree().

bool edm::RootOutputTree::fastCloneAuxBranches_
private

Definition at line 121 of file RootOutputTree.h.

Referenced by fastCloneTTree(), fillTree(), and maybeFastCloneTree().

std::shared_ptr<TFile> edm::RootOutputTree::filePtr_
private

Definition at line 112 of file RootOutputTree.h.

Referenced by close().

std::vector<TBranch*> edm::RootOutputTree::producedBranches_
private

Definition at line 114 of file RootOutputTree.h.

Referenced by addBranch(), close(), and fillTree().

std::vector<TBranch*> edm::RootOutputTree::readBranches_
private
TTree* edm::RootOutputTree::tree_
private
std::vector<TBranch*> edm::RootOutputTree::unclonedAuxBranches_
private

Definition at line 117 of file RootOutputTree.h.

Referenced by addAuxiliary(), close(), fastCloneTTree(), and fillTree().

std::vector<TBranch*> edm::RootOutputTree::unclonedReadBranches_
private

Definition at line 118 of file RootOutputTree.h.

Referenced by close(), fillTree(), and maybeFastCloneTree().