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 25 of file RootOutputTree.cc.

References tree_.

30  :
31  filePtr_(filePtr),
34  readBranches_(),
35  auxBranches_(),
39  fastCloneAuxBranches_(false) {
40 
41  if(treeMaxVirtualSize >= 0) tree_->SetMaxVirtualSize(treeMaxVirtualSize);
42  }
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 250 of file RootOutputTree.cc.

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

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

255  {
257  assert(basketSize != BranchDescription::invalidBasketSize);
258  TBranch* branch = tree_->Branch(branchName.c_str(),
259  className.c_str(),
260  &pProd,
261  basketSize,
262  splitLevel);
263  if(produced) {
264  producedBranches_.push_back(branch);
265  } else {
266  readBranches_.push_back(branch);
267  }
268  }
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 45 of file RootOutputTree.cc.

References max(), and tree().

Referenced by makeTTree().

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

Definition at line 118 of file RootOutputTree.cc.

References readBranches_.

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

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

Definition at line 66 of file RootOutputTree.cc.

References readBranches_.

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

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

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

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

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

Referenced by maybeFastCloneTree().

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

Definition at line 239 of file RootOutputTree.cc.

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

239  {
240  if (currentlyFastCloning_) {
244  } else {
245  tree_->Fill();
246  }
247  }
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 211 of file RootOutputTree.cc.

References edm::for_all().

Referenced by fillTree().

211  {
212  for_all(branches, boost::bind(&TBranch::Fill, _1));
213  }
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
bool edm::RootOutputTree::isValid ( ) const
TTree * edm::RootOutputTree::makeTTree ( TFile *  filePtr,
std::string const &  name,
int  splitLevel 
)
static

Definition at line 54 of file RootOutputTree.cc.

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

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

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

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

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

221  {
222  unclonedReadBranches_.clear();
223  unclonedReadBranchNames_.clear();
224  currentlyFastCloning_ = canFastClone && !readBranches_.empty();
226  fastCloneAuxBranches_ = canFastCloneAux;
227  fastCloneTTree(tree, option);
228  for(std::vector<TBranch*>::const_iterator it = readBranches_.begin(), itEnd = readBranches_.end();
229  it != itEnd; ++it) {
230  if((*it)->GetEntries() != tree_->GetEntries()) {
231  unclonedReadBranches_.push_back(*it);
232  unclonedReadBranchNames_.insert(std::string((*it)->GetName()));
233  }
234  }
235  }
236  }
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 216 of file RootOutputTree.cc.

References tree_, and writeTTree().

216  {
217  writeTTree(tree_);
218  }
static void writeTTree(TTree *tree)
void edm::RootOutputTree::writeTTree ( TTree *  tree)
static

Definition at line 202 of file RootOutputTree.cc.

References edm::setRefCoreStreamer().

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

202  {
203  if(tree->GetNbranches() != 0) {
204  tree->SetEntries(-1);
205  }
206  setRefCoreStreamer(true);
207  tree->AutoSave("FlushBaskets");
208  }
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().