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>

Inheritance diagram for edm::RootOutputTree:

Public Member Functions

template<typename T >
void addAuxiliary (std::string const &branchName, T const *&pAux, int bufSize)
 
template<typename T >
void addAuxiliary (std::string const &branchName, T *&pAux, int bufSize)
 
void addBranch (std::string const &branchName, std::string const &className, void const *&pProd, int splitLevel, int basketSize, bool produced)
 
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)
 
void optimizeBaskets (ULong64_t size)
 
 RootOutputTree (boost::shared_ptr< TFile > filePtr, BranchType const &branchType, int bufSize, int splitLevel, int treeMaxVirtualSize)
 
void setAutoFlush (Long64_t size)
 
void setEntries ()
 
TTree *const 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 (TTree *tree, std::vector< TBranch * > const &branches)
 

Private Attributes

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

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  bufSize,
int  splitLevel,
int  treeMaxVirtualSize 
)

Definition at line 26 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 > unclonedReadBranchNames_
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:96
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
std::vector< TBranch * > readBranches_
edm::RootOutputTree::~RootOutputTree ( )
inline

Definition at line 33 of file RootOutputTree.h.

33 {}

Member Function Documentation

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

Definition at line 37 of file RootOutputTree.h.

References auxBranches_, and tree_.

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

37  {
38  auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
39  }
std::vector< TBranch * > auxBranches_
template<typename T >
void edm::RootOutputTree::addAuxiliary ( std::string const &  branchName,
T *&  pAux,
int  bufSize 
)
inline

Definition at line 43 of file RootOutputTree.h.

References auxBranches_, and tree_.

43  {
44  auxBranches_.push_back(tree_->Branch(branchName.c_str(), &pAux, bufSize, 0));
45  }
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 254 of file RootOutputTree.cc.

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

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

259  {
261  assert(basketSize != BranchDescription::invalidBasketSize);
262  TBranch* branch = tree_->Branch(branchName.c_str(),
263  className.c_str(),
264  &pProd,
265  basketSize,
266  splitLevel);
267  if(produced) {
268  producedBranches_.push_back(branch);
269  } else {
270  readBranches_.push_back(branch);
271  }
272  }
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  }
TTree *const tree() const
const T & max(const T &a, const T &b)
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  }
134  }
135  }
136  }
137  return true;
138  }
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 275 of file RootOutputTree.cc.

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

Referenced by python.Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), and python.Vispa.Gui.FindDialog.FindDialog::keyPressEvent().

275  {
276  // The TFile was just closed.
277  // Just to play it safe, zero all pointers to quantities in the file.
278  auxBranches_.clear();
279  producedBranches_.clear();
280  readBranches_.clear();
281  unclonedReadBranches_.clear();
282  tree_ = 0;
283  filePtr_.reset();
284  }
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 141 of file RootOutputTree.cc.

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

Referenced by maybeFastCloneTree().

141  {
142  if(in->GetEntries() != 0) {
143  TObjArray* branches = tree_->GetListOfBranches();
144  // If any products were produced (not just event products), the EventAuxiliary will be modified.
145  // In that case, don't fast copy auxiliary branches. Remove them, and add back after fast copying.
146  std::map<Int_t, TBranch *> auxIndexes;
147  if (!fastCloneAuxBranches_) {
148  for (std::vector<TBranch *>::const_iterator it = auxBranches_.begin(), itEnd = auxBranches_.end();
149  it != itEnd; ++it) {
150  int auxIndex = branches->IndexOf(*it);
151  assert (auxIndex >= 0);
152  auxIndexes.insert(std::make_pair(auxIndex, *it));
153  branches->RemoveAt(auxIndex);
154  }
155  branches->Compress();
156  }
157 
158 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,0)
159  TTreeCloner cloner(in, tree_, option.c_str(), TTreeCloner::kNoWarnings|TTreeCloner::kIgnoreMissingTopLevel);
160 #else
161  TTreeCloner cloner(in, tree_, option.c_str());
162 #endif
163 
164  if(!cloner.IsValid()) {
165 
166 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,0)
167  // Let's check why
168  static const char* okerror = "One of the export branch";
169  if ( strncmp(cloner.GetWarning(),okerror,strlen(okerror)) == 0 ) {
170  // That's fine we will handle it;
171  }
172  else {
174  << "invalid TTreeCloner\n";
175  }
176 #else
178  << "invalid TTreeCloner\n";
179 #endif
180  }
181  tree_->SetEntries(tree_->GetEntries() + in->GetEntries());
182  Service<RootHandlers> rootHandler;
183  rootHandler->enableErrorHandlerWithoutWarnings();
184  cloner.Exec();
185  rootHandler->enableErrorHandler();
186  if (!fastCloneAuxBranches_) {
187  for (std::map<Int_t, TBranch *>::const_iterator it = auxIndexes.begin(), itEnd = auxIndexes.end();
188  it != itEnd; ++it) {
189  // Add the auxiliary branches back after fast copying the rest of the tree.
190  Int_t last = branches->GetLast();
191  if (last >= 0) {
192  branches->AddAtAndExpand(branches->At(last), last+1);
193  for(Int_t ind = last-1; ind >= it->first; --ind) {
194  branches->AddAt(branches->At(ind), ind+1);
195  };
196  branches->AddAt(it->second, it->first);
197  } else {
198  branches->Add(it->second);
199  }
200  }
201  }
202  }
203  }
std::vector< TBranch * > auxBranches_
void edm::RootOutputTree::fillTree ( ) const

Definition at line 243 of file RootOutputTree.cc.

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

243  {
244  if (currentlyFastCloning_) {
248  } else {
249  tree_->Fill();
250  }
251  }
std::vector< TBranch * > producedBranches_
std::vector< TBranch * > auxBranches_
static void fillTTree(TTree *tree, std::vector< TBranch * > const &branches)
std::vector< TBranch * > unclonedReadBranches_
void edm::RootOutputTree::fillTTree ( TTree *  tree,
std::vector< TBranch * > const &  branches 
)
staticprivate

Definition at line 215 of file RootOutputTree.cc.

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

Referenced by fillTree().

215  {
216  for_all(branches, boost::bind(&TBranch::Fill, _1));
217  }
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, filterRecHits_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  }
TTree *const tree() const
static TTree * assignTTree(TFile *file, TTree *tree)
void edm::RootOutputTree::maybeFastCloneTree ( bool  canFastClone,
bool  canFastCloneAux,
TTree *  tree,
std::string const &  option 
)

Definition at line 225 of file RootOutputTree.cc.

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

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

225  {
226  unclonedReadBranches_.clear();
227  unclonedReadBranchNames_.clear();
228  currentlyFastCloning_ = canFastClone && !readBranches_.empty();
230  fastCloneAuxBranches_ = canFastCloneAux;
231  fastCloneTTree(tree, option);
232  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end();
233  it != itEnd; ++it) {
234  if((*it)->GetEntries() != tree_->GetEntries()) {
235  unclonedReadBranches_.push_back(*it);
236  unclonedReadBranchNames_.insert(std::string((*it)->GetName()));
237  }
238  }
239  }
240  }
TTree *const tree() const
std::set< std::string > unclonedReadBranchNames_
std::vector< TBranch * > unclonedReadBranches_
std::vector< TBranch * > readBranches_
void fastCloneTTree(TTree *in, std::string const &option)
void edm::RootOutputTree::optimizeBaskets ( ULong64_t  size)
inline

Definition at line 89 of file RootOutputTree.h.

References tree_.

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

89  {
90  tree_->OptimizeBaskets(size);
91  }
tuple size
Write out results.
void edm::RootOutputTree::setAutoFlush ( Long64_t  size)
inline

Definition at line 93 of file RootOutputTree.h.

References tree_.

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

93  {
94  tree_->SetAutoFlush(size);
95  }
tuple size
Write out results.
void edm::RootOutputTree::setEntries ( )
inline

Definition at line 78 of file RootOutputTree.h.

References tree_.

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

78  {
79  if(tree_->GetNbranches() != 0) tree_->SetEntries(-1);
80  }
TTree* const edm::RootOutputTree::tree ( ) const
inline

Definition at line 74 of file RootOutputTree.h.

References tree_.

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

74  {
75  return tree_;
76  }
bool edm::RootOutputTree::uncloned ( std::string const &  branchName) const
inline

Definition at line 83 of file RootOutputTree.h.

References unclonedReadBranchNames_.

83  {
84  return unclonedReadBranchNames_.find(branchName) != unclonedReadBranchNames_.end();
85  }
std::set< std::string > unclonedReadBranchNames_
void edm::RootOutputTree::writeTree ( ) const

Definition at line 220 of file RootOutputTree.cc.

References tree_, and writeTTree().

220  {
221  writeTTree(tree_);
222  }
static void writeTTree(TTree *tree)
void edm::RootOutputTree::writeTTree ( TTree *  tree)
static

Definition at line 206 of file RootOutputTree.cc.

References edm::setRefCoreStreamer().

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

206  {
207  if(tree->GetNbranches() != 0) {
208  tree->SetEntries(-1);
209  }
210  setRefCoreStreamer(true);
211  tree->AutoSave("FlushBaskets");
212  }
TTree *const tree() const
void setRefCoreStreamer(bool resetAll=false)

Member Data Documentation

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

Definition at line 105 of file RootOutputTree.h.

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

bool edm::RootOutputTree::currentlyFastCloning_
private

Definition at line 108 of file RootOutputTree.h.

Referenced by fillTree(), and maybeFastCloneTree().

bool edm::RootOutputTree::fastCloneAuxBranches_
private

Definition at line 109 of file RootOutputTree.h.

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

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

Definition at line 101 of file RootOutputTree.h.

Referenced by close().

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

Definition at line 103 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::unclonedReadBranches_
private

Definition at line 106 of file RootOutputTree.h.

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

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

Definition at line 107 of file RootOutputTree.h.

Referenced by maybeFastCloneTree(), and uncloned().