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 271 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().

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

References bookConverter::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  }
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 299 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().

299  {
300  // The TFile was just closed.
301  // Just to play it safe, zero all pointers to quantities in the file.
302  auxBranches_.clear();
303  unclonedAuxBranches_.clear();
304  producedBranches_.clear();
305  readBranches_.clear();
306  unclonedReadBranches_.clear();
307  tree_ = 0;
308  filePtr_.reset();
309  }
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->ignoreWarningsWhileDoing([&cloner] { cloner.Exec(); });
199  if(mustRemoveSomeAuxs) {
200  for(std::map<Int_t, TBranch *>::const_iterator it = auxIndexes.begin(), itEnd = auxIndexes.end();
201  it != itEnd; ++it) {
202  // Add the auxiliary branches back after fast copying the rest of the tree.
203  Int_t last = branches->GetLast();
204  if(last >= 0) {
205  branches->AddAtAndExpand(branches->At(last), last+1);
206  for(Int_t ind = last-1; ind >= it->first; --ind) {
207  branches->AddAt(branches->At(ind), ind+1);
208  };
209  branches->AddAt(it->second, it->first);
210  } else {
211  branches->Add(it->second);
212  }
213  }
214  }
215  }
216  }
std::vector< TBranch * > unclonedAuxBranches_
std::vector< TBranch * > auxBranches_
void edm::RootOutputTree::fillTree ( ) const

Definition at line 259 of file RootOutputTree.cc.

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

259  {
265  } else {
266  tree_->Fill();
267  }
268  }
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 228 of file RootOutputTree.cc.

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

Referenced by fillTree().

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

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

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

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

References tree_, and writeTTree().

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

Definition at line 219 of file RootOutputTree.cc.

References edm::setRefCoreStreamer().

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

219  {
220  if(tree->GetNbranches() != 0) {
221  tree->SetEntries(-1);
222  }
223  setRefCoreStreamer(true);
224  tree->AutoSave("FlushBaskets");
225  }
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().