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, WrapperInterfaceBase const *interface, 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 (boost::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_
 
boost::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 25 of file RootOutputTree.h.

Constructor & Destructor Documentation

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

Definition at line 27 of file RootOutputTree.cc.

References tree_.

31  :
32  filePtr_(filePtr),
35  readBranches_(),
36  auxBranches_(),
40  fastCloneAuxBranches_(false) {
41 
42  if(treeMaxVirtualSize >= 0) tree_->SetMaxVirtualSize(treeMaxVirtualSize);
43  }
std::set< std::string > clonedReadBranchNames_
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > auxBranches_
boost::shared_ptr< TFile > filePtr_
std::vector< TBranch * > unclonedReadBranches_
std::string const & BranchTypeToProductTreeName(BranchType const &branchType)
Definition: BranchType.cc:102
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
std::vector< TBranch * > readBranches_
edm::RootOutputTree::~RootOutputTree ( )
inline

Definition at line 32 of file RootOutputTree.h.

32 {}
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 39 of file RootOutputTree.h.

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

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

39  {
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  }
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 49 of file RootOutputTree.h.

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

49  {
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  }
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,
WrapperInterfaceBase const *  interface,
void const *&  pProd,
int  splitLevel,
int  basketSize,
bool  produced 
)

Definition at line 273 of file RootOutputTree.cc.

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

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

279  {
281  assert(basketSize != BranchDescription::invalidBasketSize);
282  TBranch* branch = tree_->Branch(branchName.c_str(),
283  className.c_str(),
284  &pProd,
285  basketSize,
286  splitLevel);
287  assert(branch != 0);
288  if(pProd != 0) {
289  // Delete the product that ROOT has allocated.
290  interface->deleteProduct(pProd);
291  pProd = 0;
292  }
293  if(produced) {
294  producedBranches_.push_back(branch);
295  } else {
296  readBranches_.push_back(branch);
297  }
298  }
static int const invalidSplitLevel
static int const invalidBasketSize
std::vector< TBranch * > producedBranches_
eventsetup::produce::Produce produced
Definition: ESProducts.cc:21
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 46 of file RootOutputTree.cc.

References max(), and tree().

Referenced by makeTTree().

46  {
47  tree->SetDirectory(filePtr);
48  // Turn off autosaving because it is such a memory hog and we are not using
49  // this check-pointing feature anyway.
51  return tree;
52  }
const T & max(const T &a, const T &b)
TTree * tree() const
bool edm::RootOutputTree::checkEntriesInReadBranches ( Long64_t  expectedNumberOfEntries) const

Definition at line 141 of file RootOutputTree.cc.

References readBranches_.

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

141  {
142  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end(); it != itEnd; ++it) {
143  if((*it)->GetEntries() != expectedNumberOfEntries) {
144  return false;
145  }
146  }
147  return true;
148  }
std::vector< TBranch * > readBranches_
bool edm::RootOutputTree::checkIfFastClonable ( TTree *  inputTree) const

Definition at line 119 of file RootOutputTree.cc.

References readBranches_.

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

119  {
120 
121  if(inputTree == 0) return false;
122 
123  // 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.
124  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end(); it != itEnd; ++it) {
125  TBranchElement* outputBranch = dynamic_cast<TBranchElement*>(*it);
126  if(outputBranch != 0) {
127  TBranchElement* inputBranch = dynamic_cast<TBranchElement*>(inputTree->GetBranch(outputBranch->GetName()));
128  if(inputBranch != 0) {
129  // We have a matching top level branch. Do the recursive check on subbranches.
130  if(!checkMatchingBranches(inputBranch, outputBranch)) {
131  LogInfo("FastCloning")
132  << "Fast Cloning disabled because a data member has been added to split branch: " << inputBranch->GetName() << "\n.";
133  return false;
134  }
135  }
136  }
137  }
138  return true;
139  }
std::vector< TBranch * > readBranches_
bool edm::RootOutputTree::checkSplitLevelsAndBasketSizes ( TTree *  inputTree) const

Definition at line 67 of file RootOutputTree.cc.

References readBranches_.

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

67  {
68 
69  assert (inputTree != 0);
70 
71  // Do the split level and basket size match in the input and output?
72  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end();
73  it != itEnd; ++it) {
74 
75  TBranch* outputBranch = *it;
76  if(outputBranch != 0) {
77  TBranch* inputBranch = inputTree->GetBranch(outputBranch->GetName());
78 
79  if(inputBranch != 0) {
80  if(inputBranch->GetSplitLevel() != outputBranch->GetSplitLevel() ||
81  inputBranch->GetBasketSize() != outputBranch->GetBasketSize()) {
82  return false;
83  }
84  }
85  }
86  }
87  return true;
88  }
std::vector< TBranch * > readBranches_
void edm::RootOutputTree::close ( void  )

Definition at line 301 of file RootOutputTree.cc.

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

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

301  {
302  // The TFile was just closed.
303  // Just to play it safe, zero all pointers to quantities in the file.
304  auxBranches_.clear();
305  unclonedAuxBranches_.clear();
306  producedBranches_.clear();
307  readBranches_.clear();
308  unclonedReadBranches_.clear();
309  tree_ = 0;
310  filePtr_.reset();
311  }
std::vector< TBranch * > unclonedAuxBranches_
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > auxBranches_
boost::shared_ptr< TFile > filePtr_
std::vector< TBranch * > unclonedReadBranches_
std::vector< TBranch * > readBranches_
void edm::RootOutputTree::fastCloneTTree ( TTree *  in,
std::string const &  option 
)

Definition at line 151 of file RootOutputTree.cc.

References auxBranches_, edm::hlt::Exception, fastCloneAuxBranches_, edm::errors::FatalRootError, prof2calltree::last, tree_, and unclonedAuxBranches_.

Referenced by maybeFastCloneTree().

151  {
152  if(in->GetEntries() != 0) {
153  TObjArray* branches = tree_->GetListOfBranches();
154  // If any products were produced (not just event products), the EventAuxiliary will be modified.
155  // In that case, don't fast copy auxiliary branches. Remove them, and add back after fast copying.
156  std::map<Int_t, TBranch *> auxIndexes;
157  bool mustRemoveSomeAuxs = false;
158  if(!fastCloneAuxBranches_) {
159  for(std::vector<TBranch *>::const_iterator it = auxBranches_.begin(), itEnd = auxBranches_.end();
160  it != itEnd; ++it) {
161  int auxIndex = branches->IndexOf(*it);
162  assert (auxIndex >= 0);
163  auxIndexes.insert(std::make_pair(auxIndex, *it));
164  branches->RemoveAt(auxIndex);
165  }
166  mustRemoveSomeAuxs = true;
167  }
168 
169  //Deal with any aux branches which can never be cloned
170  for(std::vector<TBranch *>::const_iterator it = unclonedAuxBranches_.begin(),
171  itEnd = unclonedAuxBranches_.end();
172  it != itEnd; ++it) {
173  int auxIndex = branches->IndexOf(*it);
174  assert (auxIndex >= 0);
175  auxIndexes.insert(std::make_pair(auxIndex, *it));
176  branches->RemoveAt(auxIndex);
177  mustRemoveSomeAuxs = true;
178  }
179 
180  if(mustRemoveSomeAuxs) {
181  branches->Compress();
182  }
183 
184  TTreeCloner cloner(in, tree_, option.c_str(), TTreeCloner::kNoWarnings|TTreeCloner::kIgnoreMissingTopLevel);
185 
186  if(!cloner.IsValid()) {
187  // Let's check why
188  static const char* okerror = "One of the export branch";
189  if(strncmp(cloner.GetWarning(), okerror, strlen(okerror)) == 0) {
190  // That's fine we will handle it;
191  } else {
193  << "invalid TTreeCloner (" << cloner.GetWarning() << ")\n";
194  }
195  }
196  tree_->SetEntries(tree_->GetEntries() + in->GetEntries());
197  Service<RootHandlers> rootHandler;
198  rootHandler->enableErrorHandlerWithoutWarnings();
199  cloner.Exec();
200  rootHandler->enableErrorHandler();
201  if(mustRemoveSomeAuxs) {
202  for(std::map<Int_t, TBranch *>::const_iterator it = auxIndexes.begin(), itEnd = auxIndexes.end();
203  it != itEnd; ++it) {
204  // Add the auxiliary branches back after fast copying the rest of the tree.
205  Int_t last = branches->GetLast();
206  if(last >= 0) {
207  branches->AddAtAndExpand(branches->At(last), last+1);
208  for(Int_t ind = last-1; ind >= it->first; --ind) {
209  branches->AddAt(branches->At(ind), ind+1);
210  };
211  branches->AddAt(it->second, it->first);
212  } else {
213  branches->Add(it->second);
214  }
215  }
216  }
217  }
218  }
std::vector< TBranch * > unclonedAuxBranches_
std::vector< TBranch * > auxBranches_
void edm::RootOutputTree::fillTree ( ) const

Definition at line 261 of file RootOutputTree.cc.

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

261  {
267  } else {
268  tree_->Fill();
269  }
270  }
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 230 of file RootOutputTree.cc.

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

Referenced by fillTree().

230  {
231  for_all(branches, boost::bind(&TBranch::Fill, _1));
232  }
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 55 of file RootOutputTree.cc.

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

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

55  {
56  TTree* tree = new TTree(name.c_str(), "", splitLevel);
57  if(!tree) throw edm::Exception(errors::FatalRootError)
58  << "Failed to create the tree: " << name << "\n";
59  if(tree->IsZombie())
61  << "Tree: " << name << " is a zombie." << "\n";
62 
63  return assignTTree(filePtr, tree);
64  }
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 240 of file RootOutputTree.cc.

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

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

240  {
241  unclonedReadBranches_.clear();
242  clonedReadBranchNames_.clear();
243  currentlyFastCloning_ = canFastClone && !readBranches_.empty();
245  fastCloneAuxBranches_ = canFastCloneAux;
246  fastCloneTTree(tree, option);
247  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end();
248  it != itEnd; ++it) {
249  if((*it)->GetEntries() == tree_->GetEntries()) {
250  clonedReadBranchNames_.insert(std::string((*it)->GetName()));
251  } else {
252  unclonedReadBranches_.push_back(*it);
253  }
254  }
255  Service<JobReport> reportSvc;
256  reportSvc->reportFastClonedBranches(clonedReadBranchNames_, tree_->GetEntries());
257  }
258  }
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 102 of file RootOutputTree.h.

References tree_.

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

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

Definition at line 106 of file RootOutputTree.h.

References tree_.

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

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

Definition at line 91 of file RootOutputTree.h.

References tree_.

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

91  {
92  if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
93  }
TTree* edm::RootOutputTree::tree ( ) const
inline

Definition at line 87 of file RootOutputTree.h.

References tree_.

Referenced by assignTTree(), makeTTree(), and python.cmstools.EventTree::SetAlias().

87  {
88  return tree_;
89  }
bool edm::RootOutputTree::uncloned ( std::string const &  branchName) const
inline

Definition at line 96 of file RootOutputTree.h.

References clonedReadBranchNames_.

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

Definition at line 235 of file RootOutputTree.cc.

References tree_, and writeTTree().

235  {
236  writeTTree(tree_);
237  }
static void writeTTree(TTree *tree)
void edm::RootOutputTree::writeTTree ( TTree *  tree)
static

Definition at line 221 of file RootOutputTree.cc.

References edm::setRefCoreStreamer().

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

221  {
222  if(tree->GetNbranches() != 0) {
223  tree->SetEntries(-1);
224  }
225  setRefCoreStreamer(true);
226  tree->AutoSave("FlushBaskets");
227  }
void setRefCoreStreamer(bool resetAll=false)
TTree * tree() const

Member Data Documentation

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

Definition at line 118 of file RootOutputTree.h.

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

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

Definition at line 121 of file RootOutputTree.h.

Referenced by maybeFastCloneTree(), and uncloned().

bool edm::RootOutputTree::currentlyFastCloning_
private

Definition at line 122 of file RootOutputTree.h.

Referenced by fillTree(), and maybeFastCloneTree().

bool edm::RootOutputTree::fastCloneAuxBranches_
private

Definition at line 123 of file RootOutputTree.h.

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

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

Definition at line 114 of file RootOutputTree.h.

Referenced by close().

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

Definition at line 116 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 119 of file RootOutputTree.h.

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

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

Definition at line 120 of file RootOutputTree.h.

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