CMS 3D CMS Logo

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 ()
 
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 const * tree () const
 
TTree * tree ()
 
bool uncloned (std::string const &branchName) const
 
void writeTree ()
 
 ~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_
 
edm::propagate_const< std::shared_ptr< TFile > > filePtr_
 
std::vector< TBranch * > producedBranches_
 
std::vector< TBranch * > readBranches_
 
edm::propagate_const< 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 89 of file RootOutputTree.cc.

References tree_.

Referenced by ~RootOutputTree().

93  :
94  filePtr_(filePtr),
97  readBranches_(),
98  auxBranches_(),
102  fastCloneAuxBranches_(false) {
103 
104  if(treeMaxVirtualSize >= 0) tree_->SetMaxVirtualSize(treeMaxVirtualSize);
105  }
std::set< std::string > clonedReadBranchNames_
edm::propagate_const< TTree * > tree_
edm::propagate_const< 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:104
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
std::vector< TBranch * > readBranches_
def branchType(schema, name)
Definition: revisionDML.py:113
edm::RootOutputTree::~RootOutputTree ( )
inline

Definition at line 31 of file RootOutputTree.h.

References operator=(), and RootOutputTree().

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  }
edm::propagate_const< TTree * > tree_
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
void edm::RootOutputTree::addBranch ( std::string const &  branchName,
std::string const &  className,
void const *&  pProd,
int  splitLevel,
int  basketSize,
bool  produced 
)

Definition at line 331 of file RootOutputTree.cc.

References MicroEventContent_cff::branch, edm::BranchDescription::invalidBasketSize, edm::BranchDescription::invalidSplitLevel, producedBranches_, readBranches_, MicroEventContent_cff::splitLevel, and tree_.

Referenced by addAuxiliary(), and edm::RootOutputFile::RootOutputFile().

336  {
338  assert(basketSize != BranchDescription::invalidBasketSize);
339  TBranch* branch = tree_->Branch(branchName.c_str(),
340  className.c_str(),
341  &pProd,
342  basketSize,
343  splitLevel);
344  assert(branch != nullptr);
345 /*
346  if(pProd != nullptr) {
347  // Delete the product that ROOT has allocated.
348  WrapperBase const* edp = static_cast<WrapperBase const *>(pProd);
349  delete edp;
350  pProd = nullptr;
351  }
352 */
353  if(produced) {
354  producedBranches_.push_back(branch);
355  } else {
356  readBranches_.push_back(branch);
357  }
358  }
edm::propagate_const< TTree * > tree_
static int const invalidSplitLevel
static int const invalidBasketSize
std::vector< TBranch * > producedBranches_
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 108 of file RootOutputTree.cc.

References SiStripPI::max, and tree().

Referenced by addAuxiliary(), and makeTTree().

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

Definition at line 200 of file RootOutputTree.cc.

References readBranches_.

Referenced by addAuxiliary(), and edm::RootOutputFile::writeIndexIntoFile().

200  {
201  for(auto const& readBranch : readBranches_) {
202  if(readBranch->GetEntries() != expectedNumberOfEntries) {
203  return false;
204  }
205  }
206  return true;
207  }
std::vector< TBranch * > readBranches_
bool edm::RootOutputTree::checkIfFastClonable ( TTree *  inputTree) const

Definition at line 178 of file RootOutputTree.cc.

References readBranches_.

Referenced by addAuxiliary(), and edm::RootOutputFile::beginInputFile().

178  {
179 
180  if(inputTree == nullptr) return false;
181 
182  // 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.
183  for(auto const& outputBr : readBranches_) {
184  TBranchElement* outputBranch = dynamic_cast<TBranchElement*>(outputBr);
185  if(outputBranch != nullptr) {
186  TBranchElement* inputBranch = dynamic_cast<TBranchElement*>(inputTree->GetBranch(outputBranch->GetName()));
187  if(inputBranch != nullptr) {
188  // We have a matching top level branch. Do the recursive check on subbranches.
189  if(!checkMatchingBranches(inputBranch, outputBranch)) {
190  LogInfo("FastCloning")
191  << "Fast Cloning disabled because a data member has been added to split branch: " << inputBranch->GetName() << "\n.";
192  return false;
193  }
194  }
195  }
196  }
197  return true;
198  }
std::vector< TBranch * > readBranches_
bool edm::RootOutputTree::checkSplitLevelsAndBasketSizes ( TTree *  inputTree) const

Definition at line 129 of file RootOutputTree.cc.

References GetRecoTauVFromDQM_MC_cff::obj, and readBranches_.

Referenced by addAuxiliary(), and edm::RootOutputFile::beginInputFile().

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

Definition at line 361 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(), Vispa.Gui.FindDialog.FindDialog::keyPressEvent(), and uncloned().

361  {
362  // The TFile was just closed.
363  // Just to play it safe, zero all pointers to quantities in the file.
364  auxBranches_.clear();
365  unclonedAuxBranches_.clear();
366  producedBranches_.clear();
367  readBranches_.clear();
368  unclonedReadBranches_.clear();
369  tree_ = nullptr; // propagate_const<T> has no reset() function
370  filePtr_ = nullptr; // propagate_const<T> has no reset() function
371  }
edm::propagate_const< TTree * > tree_
std::vector< TBranch * > unclonedAuxBranches_
edm::propagate_const< std::shared_ptr< TFile > > filePtr_
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 210 of file RootOutputTree.cc.

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

Referenced by addAuxiliary(), and maybeFastCloneTree().

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

Definition at line 317 of file RootOutputTree.cc.

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

Referenced by addAuxiliary(), and core.AutoFillTreeProducer.AutoFillTreeProducer::process().

317  {
323  } else {
324  // Isolate the fill operation so that IMT doesn't grab other large tasks
325  // that could lead to PoolOutputModule stalling
326  tbb::this_task_arena::isolate( [&]{ tree_->Fill(); } );
327  }
328  }
edm::propagate_const< TTree * > tree_
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 287 of file RootOutputTree.cc.

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

Referenced by fillTree(), and setAutoFlush().

287  {
288  for_all(branches, std::bind(&TBranch::Fill, std::placeholders::_1));
289  }
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 117 of file RootOutputTree.cc.

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

Referenced by addAuxiliary(), and edm::RootOutputFile::RootOutputFile().

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

Definition at line 297 of file RootOutputTree.cc.

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

Referenced by addAuxiliary(), and edm::RootOutputFile::beginInputFile().

297  {
298  unclonedReadBranches_.clear();
299  clonedReadBranchNames_.clear();
300  currentlyFastCloning_ = canFastClone && !readBranches_.empty();
302  fastCloneAuxBranches_ = canFastCloneAux;
304  for(auto const& branch : readBranches_) {
305  if(branch->GetEntries() == tree_->GetEntries()) {
306  clonedReadBranchNames_.insert(std::string(branch->GetName()));
307  } else {
308  unclonedReadBranches_.push_back(branch);
309  }
310  }
311  Service<JobReport> reportSvc;
312  reportSvc->reportFastClonedBranches(clonedReadBranchNames_, tree_->GetEntries());
313  }
314  }
std::set< std::string > clonedReadBranchNames_
edm::propagate_const< TTree * > tree_
std::vector< TBranch * > unclonedReadBranches_
std::vector< TBranch * > readBranches_
Definition: tree.py:1
void fastCloneTTree(TTree *in, std::string const &option)
RootOutputTree& edm::RootOutputTree::operator= ( RootOutputTree const &  )
delete

Referenced by ~RootOutputTree().

void edm::RootOutputTree::optimizeBaskets ( ULong64_t  size)
inline

Definition at line 104 of file RootOutputTree.h.

References tree_.

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

104  {
105  tree_->OptimizeBaskets(size);
106  }
size
Write out results.
edm::propagate_const< TTree * > tree_
void edm::RootOutputTree::setAutoFlush ( Long64_t  size)
inline

Definition at line 108 of file RootOutputTree.h.

References fillTTree(), and tree_.

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

108  {
109  tree_->SetAutoFlush(size);
110  }
size
Write out results.
edm::propagate_const< TTree * > tree_
void edm::RootOutputTree::setEntries ( )
inline

Definition at line 93 of file RootOutputTree.h.

References tree_.

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

93  {
94  if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
95  }
edm::propagate_const< TTree * > tree_
TTree const* edm::RootOutputTree::tree ( ) const
inline
TTree* edm::RootOutputTree::tree ( )
inline
bool edm::RootOutputTree::uncloned ( std::string const &  branchName) const
inline

Definition at line 98 of file RootOutputTree.h.

References clonedReadBranchNames_, and close().

98  {
100  }
std::set< std::string > clonedReadBranchNames_
void edm::RootOutputTree::writeTree ( )

Definition at line 292 of file RootOutputTree.cc.

References tree(), and writeTTree().

Referenced by addAuxiliary().

292  {
293  writeTTree(tree());
294  }
TTree const * tree() const
static void writeTTree(TTree *tree)
void edm::RootOutputTree::writeTTree ( TTree *  tree)
static

Definition at line 276 of file RootOutputTree.cc.

References edm::setRefCoreStreamer().

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

276  {
277  if(tree->GetNbranches() != 0) {
278  // This is required when Fill is called on individual branches
279  // in the TTree instead of calling Fill once for the entire TTree.
280  tree->SetEntries(-1);
281  }
282  setRefCoreStreamer(true);
283  tree->AutoSave("FlushBaskets");
284  }
void setRefCoreStreamer(bool resetAll=false)
Definition: tree.py:1

Member Data Documentation

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

Definition at line 121 of file RootOutputTree.h.

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

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

Definition at line 125 of file RootOutputTree.h.

Referenced by maybeFastCloneTree(), and uncloned().

bool edm::RootOutputTree::currentlyFastCloning_
private

Definition at line 126 of file RootOutputTree.h.

Referenced by fillTree(), and maybeFastCloneTree().

bool edm::RootOutputTree::fastCloneAuxBranches_
private

Definition at line 127 of file RootOutputTree.h.

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

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

Definition at line 116 of file RootOutputTree.h.

Referenced by close().

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

Definition at line 119 of file RootOutputTree.h.

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

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

Definition at line 122 of file RootOutputTree.h.

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

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

Definition at line 123 of file RootOutputTree.h.

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