CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
edm::RootTree Class Reference

#include <RootTree.h>

Public Types

typedef roottree::BranchMap BranchMap
 
typedef roottree::EntryNumber EntryNumber
 

Public Member Functions

void addBranch (BranchKey const &key, BranchDescription const &prod, std::string const &oldBranchName)
 
TBranch * branchEntryInfoBranch () const
 
BranchMap const & branches () const
 
std::vector< std::string > const & branchNames () const
 
BranchType branchType () const
 
TTreeCache * checkTriggerCache (TBranch *branch, EntryNumber entryNumber) const
 
TTreeCache * checkTriggerCacheImpl (TBranch *branch, EntryNumber entryNumber) const
 
void close ()
 
bool current ()
 
void dropBranch (std::string const &oldBranchName)
 
EntryNumber const & entries () const
 
EntryNumber const & entryNumber () const
 
template<typename T >
void fillAux (T *&pAux)
 
template<typename T >
void fillBranchEntry (TBranch *branch, T *&pbuf)
 
template<typename T >
void fillBranchEntryMeta (TBranch *branch, T *&pbuf)
 
void getEntry (TBranch *branch, EntryNumber entry) const
 
bool isValid () const
 
TTree const * metaTree () const
 
bool next ()
 
RootTreeoperator= (RootTree const &)=delete
 
bool previous ()
 
void resetTraining ()
 
void rewind ()
 
DelayedReaderrootDelayedReader () const
 
 RootTree (boost::shared_ptr< InputFile > filePtr, BranchType const &branchType, unsigned int maxVirtualSize, unsigned int cacheSize, unsigned int learningEntries, bool enablePrefetching)
 
 RootTree (RootTree const &)=delete
 
TTreeCache * selectCache (TBranch *branch, EntryNumber entryNumber) const
 
void setEntryNumber (EntryNumber theEntryNumber)
 
void setPresence (BranchDescription const &prod, std::string const &oldBranchName)
 
void trainCache (char const *branchNames)
 
TTree const * tree () const
 
TTree * tree ()
 
 ~RootTree ()
 

Private Member Functions

void setCacheSize (unsigned int cacheSize)
 
void setTreeMaxVirtualSize (int treeMaxVirtualSize)
 
void startTraining ()
 
void stopTraining ()
 

Private Attributes

TBranch * auxBranch_
 
TBranch * branchEntryInfoBranch_
 
boost::shared_ptr< BranchMapbranches_
 
std::vector< std::string > branchNames_
 
BranchType branchType_
 
unsigned int cacheSize_
 
bool enablePrefetching_
 
bool enableTriggerCache_
 
EntryNumber entries_
 
EntryNumber entryNumber_
 
boost::shared_ptr< InputFilefilePtr_
 
TTree * infoTree_
 
unsigned int learningEntries_
 
TTree * metaTree_
 
bool performedSwitchOver_
 
boost::shared_ptr< TTreeCache > rawTreeCache_
 
EntryNumber rawTriggerSwitchOverEntry_
 
boost::shared_ptr< TTreeCache > rawTriggerTreeCache_
 
std::unique_ptr< DelayedReaderrootDelayedReader_
 
TBranch * statusBranch_
 
EntryNumber switchOverEntry_
 
std::unordered_set< TBranch * > trainedSet_
 
bool trainNow_
 
TTree * tree_
 
unsigned long treeAutoFlush_
 
boost::shared_ptr< TTreeCache > treeCache_
 
std::unordered_set< TBranch * > triggerSet_
 
boost::shared_ptr< TTreeCache > triggerTreeCache_
 

Detailed Description

Definition at line 57 of file RootTree.h.

Member Typedef Documentation

Definition at line 59 of file RootTree.h.

Definition at line 60 of file RootTree.h.

Constructor & Destructor Documentation

edm::RootTree::RootTree ( boost::shared_ptr< InputFile filePtr,
BranchType const &  branchType,
unsigned int  maxVirtualSize,
unsigned int  cacheSize,
unsigned int  learningEntries,
bool  enablePrefetching 
)

Definition at line 27 of file RootTree.cc.

References cacheSize_, learningEntries_, setCacheSize(), setTreeMaxVirtualSize(), trainedSet_, tree_, treeAutoFlush_, and triggerSet_.

32  :
33  filePtr_(filePtr),
34  tree_(dynamic_cast<TTree*>(filePtr_.get() != 0 ? filePtr_->Get(BranchTypeToProductTreeName(branchType).c_str()) : 0)),
35  metaTree_(dynamic_cast<TTree*>(filePtr_.get() != 0 ? filePtr_->Get(BranchTypeToMetaDataTreeName(branchType).c_str()) : 0)),
37  auxBranch_(tree_ ? getAuxiliaryBranch(tree_, branchType_) : 0),
38  treeCache_(),
39  rawTreeCache_(),
42  trainedSet_(),
43  triggerSet_(),
44  entries_(tree_ ? tree_->GetEntries() : 0),
45  entryNumber_(-1),
46  branchNames_(),
47  branches_(new BranchMap),
48  trainNow_(false),
49  switchOverEntry_(-1),
51  learningEntries_(learningEntries),
52  cacheSize_(cacheSize),
53  treeAutoFlush_(0),
54  enablePrefetching_(enablePrefetching),
56  rootDelayedReader_(new RootDelayedReader(*this, filePtr)),
57  branchEntryInfoBranch_(metaTree_ ? getProductProvenanceBranch(metaTree_, branchType_) : (tree_ ? getProductProvenanceBranch(tree_, branchType_) : 0)),
58  infoTree_(dynamic_cast<TTree*>(filePtr_.get() != 0 ? filePtr->Get(BranchTypeToInfoTreeName(branchType).c_str()) : 0)) // backward compatibility
59  {
60  assert(tree_);
61  // On merged files in older releases of ROOT, the autoFlush setting is always negative; we must guess.
62  // TODO: On newer merged files, we should be able to get this from the cluster iterator.
63  long treeAutoFlush = (tree_ ? tree_->GetAutoFlush() : 0);
64  if (treeAutoFlush < 0) {
65  // The "+1" is here to avoid divide-by-zero in degenerate cases.
66  Long64_t averageEventSizeBytes = tree_->GetZipBytes() / (tree_->GetEntries()+1) + 1;
67  treeAutoFlush_ = cacheSize_/averageEventSizeBytes+1;
68  } else {
69  treeAutoFlush_ = treeAutoFlush;
70  }
73  }
74  setTreeMaxVirtualSize(maxVirtualSize);
75  setCacheSize(cacheSize);
76  if (tree_) {
77  Int_t branchCount = tree_->GetListOfBranches()->GetEntriesFast();
78  trainedSet_.reserve(branchCount);
79  triggerSet_.reserve(branchCount);
80  }
81  }
EntryNumber entryNumber_
Definition: RootTree.h:152
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
std::string const & BranchTypeToMetaDataTreeName(BranchType const &branchType)
Definition: BranchType.cc:106
unsigned int learningEntries_
Definition: RootTree.h:159
std::vector< std::string > branchNames_
Definition: RootTree.h:153
TTree * tree_
Definition: RootTree.h:138
bool trainNow_
Definition: RootTree.h:155
EntryNumber rawTriggerSwitchOverEntry_
Definition: RootTree.h:157
roottree::BranchMap BranchMap
Definition: RootTree.h:59
TTree * metaTree_
Definition: RootTree.h:139
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:149
TBranch * branchEntryInfoBranch_
Definition: RootTree.h:168
EntryNumber entries_
Definition: RootTree.h:151
boost::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:146
bool enablePrefetching_
Definition: RootTree.h:164
void setTreeMaxVirtualSize(int treeMaxVirtualSize)
Definition: RootTree.cc:170
boost::shared_ptr< TTreeCache > triggerTreeCache_
Definition: RootTree.h:147
boost::shared_ptr< TTreeCache > rawTriggerTreeCache_
Definition: RootTree.h:148
BranchType branchType() const
Definition: RootTree.h:127
unsigned long treeAutoFlush_
Definition: RootTree.h:161
std::string const & BranchTypeToProductTreeName(BranchType const &branchType)
Definition: BranchType.cc:102
TBranch * auxBranch_
Definition: RootTree.h:141
std::string const & BranchTypeToInfoTreeName(BranchType const &branchType)
Definition: BranchType.cc:110
bool enableTriggerCache_
Definition: RootTree.h:165
boost::shared_ptr< BranchMap > branches_
Definition: RootTree.h:154
void setCacheSize(unsigned int cacheSize)
Definition: RootTree.cc:160
unsigned int cacheSize_
Definition: RootTree.h:160
std::unordered_set< TBranch * > triggerSet_
Definition: RootTree.h:150
std::unique_ptr< DelayedReader > rootDelayedReader_
Definition: RootTree.h:166
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
EntryNumber switchOverEntry_
Definition: RootTree.h:156
BranchType branchType_
Definition: RootTree.h:140
TTree * infoTree_
Definition: RootTree.h:170
edm::RootTree::~RootTree ( )

Definition at line 83 of file RootTree.cc.

83  {
84  }
edm::RootTree::RootTree ( RootTree const &  )
delete

Member Function Documentation

void edm::RootTree::addBranch ( BranchKey const &  key,
BranchDescription const &  prod,
std::string const &  oldBranchName 
)

Definition at line 114 of file RootTree.cc.

References branches_, edm::BranchDescription::branchName(), branchNames_, info, edm::BranchDescription::init(), isValid(), metaTree_, edm::BranchDescription::present(), edm::roottree::BranchInfo::productBranch_, edm::roottree::BranchInfo::provenanceBranch_, and tree_.

116  {
117  assert(isValid());
118  prod.init();
119  //use the translated branch name
120  TBranch* branch = tree_->GetBranch(oldBranchName.c_str());
121  roottree::BranchInfo info = roottree::BranchInfo(ConstBranchDescription(prod));
122  info.productBranch_ = 0;
123  if (prod.present()) {
124  info.productBranch_ = branch;
125  //we want the new branch name for the JobReport
126  branchNames_.push_back(prod.branchName());
127  }
128  TTree* provTree = (metaTree_ != 0 ? metaTree_ : tree_);
129  info.provenanceBranch_ = provTree->GetBranch(oldBranchName.c_str());
130  branches_->insert(std::make_pair(key, info));
131  }
std::vector< std::string > branchNames_
Definition: RootTree.h:153
TTree * tree_
Definition: RootTree.h:138
TTree * metaTree_
Definition: RootTree.h:139
boost::shared_ptr< BranchMap > branches_
Definition: RootTree.h:154
bool isValid() const
Definition: RootTree.cc:87
list key
Definition: combine.py:13
TBranch* edm::RootTree::branchEntryInfoBranch ( ) const
inline
roottree::BranchMap const & edm::RootTree::branches ( ) const

Definition at line 157 of file RootTree.cc.

References branches_.

Referenced by edm::RootDelayedReader::branches(), checkTriggerCacheImpl(), and trainCache().

157 {return *branches_;}
boost::shared_ptr< BranchMap > branches_
Definition: RootTree.h:154
std::vector<std::string> const& edm::RootTree::branchNames ( ) const
inline

Definition at line 89 of file RootTree.h.

References branchNames_.

Referenced by edm::RootFile::reportOpened().

89 {return branchNames_;}
std::vector< std::string > branchNames_
Definition: RootTree.h:153
BranchType edm::RootTree::branchType ( ) const
inline

Definition at line 127 of file RootTree.h.

References branchType_.

Referenced by edm::RootDelayedReader::getProduct_(), and edm::ReducedProvenanceReader::ReducedProvenanceReader().

127 {return branchType_;}
BranchType branchType_
Definition: RootTree.h:140
TTreeCache * edm::RootTree::checkTriggerCache ( TBranch *  branch,
EntryNumber  entryNumber 
) const
inline

Definition at line 207 of file RootTree.cc.

References checkTriggerCacheImpl(), enableTriggerCache_, NULL, trainedSet_, and treeCache_.

Referenced by selectCache().

207  {
208  if (!treeCache_->IsAsyncReading() && enableTriggerCache_ && (trainedSet_.find(branch) == trainedSet_.end())) {
209  return checkTriggerCacheImpl(branch, entryNumber);
210  } else {
211  return NULL;
212  }
213  }
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:149
#define NULL
Definition: scimark2.h:8
TTreeCache * checkTriggerCacheImpl(TBranch *branch, EntryNumber entryNumber) const
Definition: RootTree.cc:218
EntryNumber const & entryNumber() const
Definition: RootTree.h:86
bool enableTriggerCache_
Definition: RootTree.h:165
TTreeCache * edm::RootTree::checkTriggerCacheImpl ( TBranch *  branch,
EntryNumber  entryNumber 
) const

Definition at line 218 of file RootTree.cc.

References branches(), entryNumber_, filePtr_, i, NULL, performedSwitchOver_, rawTriggerSwitchOverEntry_, rawTriggerTreeCache_, trainedSet_, tree_, triggerSet_, and triggerTreeCache_.

Referenced by checkTriggerCache().

218  {
219  // This branch is not going to be in the cache.
220  // Assume this is a "trigger pattern".
221  // Always make sure the branch is added to the trigger set.
222  if (triggerSet_.find(branch) == triggerSet_.end()) {
223  triggerSet_.insert(branch);
224  if (triggerTreeCache_.get()) { triggerTreeCache_->AddBranch(branch, kTRUE); }
225  }
226 
227  if (rawTriggerSwitchOverEntry_ < 0) {
228  // The trigger has never fired before. Take everything not in the
229  // trainedSet and load it from disk
230 
231  // Calculate the end of the next cluster; triggers in the next cluster
232  // will use the triggerCache, not the rawTriggerCache.
233  TTree::TClusterIterator clusterIter = tree_->GetClusterIterator(entryNumber);
235  rawTriggerSwitchOverEntry_ = clusterIter();
236  }
237 
238  // ROOT will automatically expand the cache to fit one cluster; hence, we use
239  // 5 MB as the cache size below
240  tree_->SetCacheSize(static_cast<Long64_t>(5*1024*1024));
241  rawTriggerTreeCache_.reset(dynamic_cast<TTreeCache*>(filePtr_->GetCacheRead()));
242  if(rawTriggerTreeCache_) rawTriggerTreeCache_->SetEnablePrefetching(false);
243  TObjArray *branches = tree_->GetListOfBranches();
244  int branchCount = branches->GetEntriesFast();
245 
246  // Train the rawTriggerCache to have everything not in the regular cache.
247  rawTriggerTreeCache_->SetLearnEntries(0);
249  for (int i=0;i<branchCount;i++) {
250  TBranch *tmp_branch = (TBranch*)branches->UncheckedAt(i);
251  if (trainedSet_.find(tmp_branch) != trainedSet_.end()) {
252  continue;
253  }
254  rawTriggerTreeCache_->AddBranch(tmp_branch, kTRUE);
255  }
256  performedSwitchOver_ = false;
257  rawTriggerTreeCache_->StopLearningPhase();
258  filePtr_->SetCacheRead(0);
259 
260  return rawTriggerTreeCache_.get();
262  // The raw trigger has fired and it contents are valid.
263  return rawTriggerTreeCache_.get();
264  } else if (rawTriggerSwitchOverEntry_ > 0) {
265  // The raw trigger has fired, but we are out of the cache. Use the
266  // triggerCache instead.
267  if (!performedSwitchOver_) {
268  rawTriggerTreeCache_.reset();
269  performedSwitchOver_ = true;
270 
271  // Train the triggerCache
272  tree_->SetCacheSize(static_cast<Long64_t>(5*1024*1024));
273  triggerTreeCache_.reset(dynamic_cast<TTreeCache*>(filePtr_->GetCacheRead()));
274  triggerTreeCache_->SetEnablePrefetching(false);
275  triggerTreeCache_->SetLearnEntries(0);
276  triggerTreeCache_->SetEntryRange(entryNumber, tree_->GetEntries());
277  for(std::unordered_set<TBranch*>::const_iterator it = triggerSet_.begin(), itEnd = triggerSet_.end();
278  it != itEnd;
279  it++)
280  {
281  triggerTreeCache_->AddBranch(*it, kTRUE);
282  }
283  triggerTreeCache_->StopLearningPhase();
284  filePtr_->SetCacheRead(0);
285  }
286  return triggerTreeCache_.get();
288  // The raw trigger has fired and it contents are valid.
289  return rawTriggerTreeCache_.get();
290  } else if (rawTriggerSwitchOverEntry_ > 0) {
291  // The raw trigger has fired, but we are out of the cache. Use the
292  // triggerCache instead.
293  if (!performedSwitchOver_) {
294  rawTriggerTreeCache_.reset();
295  performedSwitchOver_ = true;
296 
297  // Train the triggerCache
298  tree_->SetCacheSize(static_cast<Long64_t>(5*1024*1024));
299  triggerTreeCache_.reset(dynamic_cast<TTreeCache*>(filePtr_->GetCacheRead()));
300  triggerTreeCache_->SetEnablePrefetching(false);
301  triggerTreeCache_->SetLearnEntries(0);
302  triggerTreeCache_->SetEntryRange(entryNumber, tree_->GetEntries());
303  for(std::unordered_set<TBranch*>::const_iterator it = triggerSet_.begin(), itEnd = triggerSet_.end();
304  it != itEnd;
305  it++)
306  {
307  triggerTreeCache_->AddBranch(*it, kTRUE);
308  }
309  triggerTreeCache_->StopLearningPhase();
310  filePtr_->SetCacheRead(0);
311  }
312  return triggerTreeCache_.get();
313  }
314 
315  // By construction, this case should be impossible.
316  assert (false);
317  return NULL;
318  }
EntryNumber entryNumber_
Definition: RootTree.h:152
int i
Definition: DBlmapReader.cc:9
TTree * tree_
Definition: RootTree.h:138
EntryNumber rawTriggerSwitchOverEntry_
Definition: RootTree.h:157
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:149
#define NULL
Definition: scimark2.h:8
boost::shared_ptr< TTreeCache > triggerTreeCache_
Definition: RootTree.h:147
boost::shared_ptr< TTreeCache > rawTriggerTreeCache_
Definition: RootTree.h:148
EntryNumber const & entryNumber() const
Definition: RootTree.h:86
bool performedSwitchOver_
Definition: RootTree.h:158
std::unordered_set< TBranch * > triggerSet_
Definition: RootTree.h:150
BranchMap const & branches() const
Definition: RootTree.cc:157
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
void edm::RootTree::close ( void  )

Definition at line 393 of file RootTree.cc.

References auxBranch_, branchEntryInfoBranch_, filePtr_, infoTree_, metaTree_, rawTreeCache_, rawTriggerTreeCache_, tree_, treeCache_, and triggerTreeCache_.

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

393  {
394  // The TFile is about to be closed, and destructed.
395  // Just to play it safe, zero all pointers to quantities that are owned by the TFile.
397  tree_ = metaTree_ = infoTree_ = 0;
398  // We own the treeCache_.
399  // We make sure the treeCache_ is detached from the file,
400  // so that ROOT does not also delete it.
401  filePtr_->SetCacheRead(0);
402  // We *must* delete the TTreeCache here because the TFilePrefetch object
403  // references the TFile. If TFile is closed, before the TTreeCache is
404  // deleted, the TFilePrefetch may continue to do TFile operations, causing
405  // deadlocks or exceptions.
406  treeCache_.reset();
407  rawTreeCache_.reset();
408  triggerTreeCache_.reset();
409  rawTriggerTreeCache_.reset();
410  // We give up our shared ownership of the TFile itself.
411  filePtr_.reset();
412  }
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
TTree * tree_
Definition: RootTree.h:138
TTree * metaTree_
Definition: RootTree.h:139
TBranch * branchEntryInfoBranch_
Definition: RootTree.h:168
boost::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:146
boost::shared_ptr< TTreeCache > triggerTreeCache_
Definition: RootTree.h:147
boost::shared_ptr< TTreeCache > rawTriggerTreeCache_
Definition: RootTree.h:148
TBranch * auxBranch_
Definition: RootTree.h:141
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
TTree * infoTree_
Definition: RootTree.h:170
bool edm::RootTree::current ( )
inline

Definition at line 83 of file RootTree.h.

Referenced by edm::RootFile::readCurrentEvent(), edm::RootFile::readLuminosityBlockAuxiliary_(), and edm::RootFile::readRunAuxiliary_().

83 {return entryNumber_ < entries_ && entryNumber_ >= 0;}
void edm::RootTree::dropBranch ( std::string const &  oldBranchName)

Definition at line 134 of file RootTree.cc.

References beamvalidation::br, entries(), i, python.Node::leaf, and tree_.

134  {
135  //use the translated branch name
136  TBranch* branch = tree_->GetBranch(oldBranchName.c_str());
137  if (branch != 0) {
138  TObjArray* leaves = tree_->GetListOfLeaves();
139  int entries = leaves->GetEntries();
140  for (int i = 0; i < entries; ++i) {
141  TLeaf* leaf = (TLeaf*)(*leaves)[i];
142  if (leaf == 0) continue;
143  TBranch* br = leaf->GetBranch();
144  if (br == 0) continue;
145  if (br->GetMother() == branch) {
146  leaves->Remove(leaf);
147  }
148  }
149  leaves->Compress();
150  tree_->GetListOfBranches()->Remove(branch);
151  tree_->GetListOfBranches()->Compress();
152  delete branch;
153  }
154  }
int i
Definition: DBlmapReader.cc:9
TTree * tree_
Definition: RootTree.h:138
EntryNumber const & entries() const
Definition: RootTree.h:87
tuple leaf
Definition: Node.py:62
EntryNumber const& edm::RootTree::entries ( ) const
inline

Definition at line 87 of file RootTree.h.

References entries_.

Referenced by dropBranch(), edm::RootFile::fillIndexIntoFile(), edm::RootFile::setIfFastClonable(), and edm::RootFile::validateFile().

87 {return entries_;}
EntryNumber entries_
Definition: RootTree.h:151
EntryNumber const& edm::RootTree::entryNumber ( ) const
inline
template<typename T >
void edm::RootTree::fillAux ( T *&  pAux)
inline

Definition at line 92 of file RootTree.h.

References auxBranch_, entryNumber_, and getEntry().

Referenced by edm::RootFile::fillLumiAuxiliary(), edm::RootFile::fillRunAuxiliary(), edm::RootFile::fillThisEventAuxiliary(), and edm::RootFileEventFinder::getEventNumberOfEntry().

92  {
93  auxBranch_->SetAddress(&pAux);
95  }
EntryNumber entryNumber_
Definition: RootTree.h:152
TBranch * auxBranch_
Definition: RootTree.h:141
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:340
template<typename T >
void edm::RootTree::fillBranchEntry ( TBranch *  branch,
T *&  pbuf 
)
inline

Definition at line 108 of file RootTree.h.

References entryNumber_, and getEntry().

Referenced by edm::RootFile::fillHistory(), and edm::ReducedProvenanceReader::readProvenance().

108  {
109  branch->SetAddress(&pbuf);
110  getEntry(branch, entryNumber_);
111  }
EntryNumber entryNumber_
Definition: RootTree.h:152
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:340
template<typename T >
void edm::RootTree::fillBranchEntryMeta ( TBranch *  branch,
T *&  pbuf 
)
inline

Definition at line 97 of file RootTree.h.

References entryNumber_, edm::roottree::getEntry(), and metaTree_.

Referenced by edm::FullProvenanceReader::readProvenance().

97  {
98  if (metaTree_ != 0) {
99  // Metadata was in separate tree. Not cached.
100  branch->SetAddress(&pbuf);
102  } else {
103  fillBranchEntry<T>(branch, pbuf);
104  }
105  }
EntryNumber entryNumber_
Definition: RootTree.h:152
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: RootTree.cc:446
TTree * metaTree_
Definition: RootTree.h:139
void edm::RootTree::getEntry ( TBranch *  branch,
EntryNumber  entry 
) const

Definition at line 340 of file RootTree.cc.

References cms::Exception::addContext(), alignCSCRings::e, filePtr_, edm::errors::FileReadError, selectCache(), AlCaHLTBitMon_QueryRunRegistry::string, and lumiQTWidget::t.

Referenced by fillAux(), fillBranchEntry(), and edm::RootDelayedReader::getProduct_().

340  {
341  try {
342  TTreeCache * cache = selectCache(branch, entryNumber);
343  filePtr_->SetCacheRead(cache);
344  branch->GetEntry(entryNumber);
345  filePtr_->SetCacheRead(0);
346  } catch(cms::Exception const& e) {
347  // We make sure the treeCache_ is detached from the file,
348  // so that ROOT does not also delete it.
349  filePtr_->SetCacheRead(0);
351  t.addContext(std::string("Reading branch ")+branch->GetName());
352  throw t;
353  }
354  }
TTreeCache * selectCache(TBranch *branch, EntryNumber entryNumber) const
Definition: RootTree.cc:321
EntryNumber const & entryNumber() const
Definition: RootTree.h:86
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
bool edm::RootTree::isValid ( void  ) const

Definition at line 87 of file RootTree.cc.

References auxBranch_, branchEntryInfoBranch_, entries_, infoTree_, metaTree_, and tree_.

Referenced by addBranch(), edm::RootFile::fillIndexIntoFile(), edm::RootFile::readLumi(), edm::RootFile::readLuminosityBlockAuxiliary_(), edm::RootFile::readRun_(), edm::RootFile::readRunAuxiliary_(), setPresence(), and edm::RootFile::validateFile().

87  {
88  if (metaTree_ == 0 || metaTree_->GetNbranches() == 0) {
89  return tree_ != 0 && auxBranch_ != 0;
90  }
91  if (tree_ != 0 && auxBranch_ != 0 && metaTree_ != 0) { // backward compatibility
92  if (branchEntryInfoBranch_ != 0 || infoTree_ != 0) return true; // backward compatibility
93  return (entries_ == metaTree_->GetEntries() && tree_->GetNbranches() <= metaTree_->GetNbranches() + 1); // backward compatibility
94  } // backward compatibility
95  return false;
96  }
TTree * tree_
Definition: RootTree.h:138
TTree * metaTree_
Definition: RootTree.h:139
TBranch * branchEntryInfoBranch_
Definition: RootTree.h:168
EntryNumber entries_
Definition: RootTree.h:151
TBranch * auxBranch_
Definition: RootTree.h:141
TTree * infoTree_
Definition: RootTree.h:170
TTree const* edm::RootTree::metaTree ( ) const
inline

Definition at line 115 of file RootTree.h.

References metaTree_.

Referenced by edm::RootFile::createFileBlock().

115 {return metaTree_;}
TTree * metaTree_
Definition: RootTree.h:139
bool edm::RootTree::next ( void  )
inline

Definition at line 81 of file RootTree.h.

References entries_, and entryNumber_.

Referenced by edm::RootFile::fillIndexIntoFile(), edm::RootFile::initializeDuplicateChecker(), and edm::RootFile::nextEventEntry().

81 {return ++entryNumber_ < entries_;}
EntryNumber entryNumber_
Definition: RootTree.h:152
EntryNumber entries_
Definition: RootTree.h:151
RootTree& edm::RootTree::operator= ( RootTree const &  )
delete
bool edm::RootTree::previous ( )
inline

Definition at line 82 of file RootTree.h.

References entryNumber_.

82 {return --entryNumber_ >= 0;}
EntryNumber entryNumber_
Definition: RootTree.h:152
void edm::RootTree::resetTraining ( )
inline

Definition at line 125 of file RootTree.h.

References trainNow_.

Referenced by edm::RootFile::RootFile().

125 {trainNow_ = true;}
bool trainNow_
Definition: RootTree.h:155
void edm::RootTree::rewind ( )
inline

Definition at line 84 of file RootTree.h.

References entryNumber_.

Referenced by edm::RootFile::rewind().

84 {entryNumber_ = 0;}
EntryNumber entryNumber_
Definition: RootTree.h:152
DelayedReader * edm::RootTree::rootDelayedReader ( ) const

Definition at line 99 of file RootTree.cc.

References rootDelayedReader_.

Referenced by edm::RootFile::readCurrentEvent(), edm::RootFile::readLumi(), and edm::RootFile::readRun_().

99  {
100  rootDelayedReader_->reset();
101  return rootDelayedReader_.get();
102  }
std::unique_ptr< DelayedReader > rootDelayedReader_
Definition: RootTree.h:166
TTreeCache * edm::RootTree::selectCache ( TBranch *  branch,
EntryNumber  entryNumber 
) const
inline

Definition at line 321 of file RootTree.cc.

References checkTriggerCache(), NULL, rawTreeCache_, trainedSet_, and treeCache_.

Referenced by getEntry().

321  {
322  TTreeCache *triggerCache = NULL;
323  if (!treeCache_) {
324  return NULL;
325  } else if (treeCache_->IsLearning() && rawTreeCache_) {
326  treeCache_->AddBranch(branch, kTRUE);
327  trainedSet_.insert(branch);
328  return rawTreeCache_.get();
329  } else if ((triggerCache = checkTriggerCache(branch, entryNumber))) {
330  // A NULL return value from checkTriggerCache indicates the trigger cache case
331  // does not apply, and we should continue below.
332  return triggerCache;
333  } else {
334  // The "normal" TTreeCache case.
335  return treeCache_.get();
336  }
337  }
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
TTreeCache * checkTriggerCache(TBranch *branch, EntryNumber entryNumber) const
Definition: RootTree.cc:207
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:149
#define NULL
Definition: scimark2.h:8
boost::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:146
EntryNumber const & entryNumber() const
Definition: RootTree.h:86
void edm::RootTree::setCacheSize ( unsigned int  cacheSize)
private

Definition at line 160 of file RootTree.cc.

References cacheSize_, enablePrefetching_, filePtr_, rawTreeCache_, tree_, and treeCache_.

Referenced by RootTree().

160  {
161  cacheSize_ = cacheSize;
162  tree_->SetCacheSize(static_cast<Long64_t>(cacheSize));
163  treeCache_.reset(dynamic_cast<TTreeCache*>(filePtr_->GetCacheRead()));
164  if(treeCache_) treeCache_->SetEnablePrefetching(enablePrefetching_);
165  filePtr_->SetCacheRead(0);
166  rawTreeCache_.reset();
167  }
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
TTree * tree_
Definition: RootTree.h:138
boost::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:146
bool enablePrefetching_
Definition: RootTree.h:164
unsigned int cacheSize_
Definition: RootTree.h:160
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
void edm::RootTree::setEntryNumber ( EntryNumber  theEntryNumber)

Definition at line 175 of file RootTree.cc.

References entries_, entryNumber_, filePtr_, rawTriggerSwitchOverEntry_, startTraining(), stopTraining(), switchOverEntry_, trainedSet_, trainNow_, tree_, treeAutoFlush_, treeCache_, and triggerSet_.

Referenced by edm::RootFile::fillEventAuxiliary(), edm::RootFile::fillIndexIntoFile(), edm::RootFileEventFinder::getEventNumberOfEntry(), edm::RootFile::initializeDuplicateChecker(), edm::RootFile::readEvent(), edm::RootFile::readLumi(), edm::RootFile::readLuminosityBlockAuxiliary_(), edm::RootFile::readRunAuxiliary_(), edm::RootFile::setAtEventEntry(), edm::RootFile::setEntryAtEvent(), edm::RootFile::setEntryAtLumi(), edm::RootFile::setEntryAtNextEventInLumi(), edm::RootFile::setEntryAtRun(), and edm::RootFile::skipEvents().

175  {
176  filePtr_->SetCacheRead(treeCache_.get());
177 
178  // Detect a backward skip. If the skip is sufficiently large, we roll the dice and reset the treeCache.
179  // This will cause some amount of over-reading: we pre-fetch all the events in some prior cluster.
180  // However, because reading one event in the cluster is supposed to be equivalent to reading all events in the cluster,
181  // we're not incurring additional over-reading - we're just doing it more efficiently.
182  // NOTE: Constructor guarantees treeAutoFlush_ is positive, even if TTree->GetAutoFlush() is negative.
183  if ((theEntryNumber < static_cast<EntryNumber>(entryNumber_-treeAutoFlush_)) &&
184  (treeCache_) && (!treeCache_->IsLearning()) && (entries_ > 0) && (switchOverEntry_ >= 0)) {
185  treeCache_->SetEntryRange(theEntryNumber, entries_);
186  treeCache_->FillBuffer();
187  }
188 
189  entryNumber_ = theEntryNumber;
190  tree_->LoadTree(entryNumber_);
191  filePtr_->SetCacheRead(0);
192  if(treeCache_ && trainNow_ && entryNumber_ >= 0) {
193  startTraining();
194  trainNow_ = false;
195  trainedSet_.clear();
196  triggerSet_.clear();
198  }
199  if (treeCache_ && treeCache_->IsLearning() && switchOverEntry_ >= 0 && entryNumber_ >= switchOverEntry_) {
200  stopTraining();
201  }
202  }
EntryNumber entryNumber_
Definition: RootTree.h:152
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
TTree * tree_
Definition: RootTree.h:138
bool trainNow_
Definition: RootTree.h:155
EntryNumber rawTriggerSwitchOverEntry_
Definition: RootTree.h:157
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:149
void stopTraining()
Definition: RootTree.cc:385
EntryNumber entries_
Definition: RootTree.h:151
unsigned long treeAutoFlush_
Definition: RootTree.h:161
void startTraining()
Definition: RootTree.cc:357
std::unordered_set< TBranch * > triggerSet_
Definition: RootTree.h:150
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
EntryNumber switchOverEntry_
Definition: RootTree.h:156
void edm::RootTree::setPresence ( BranchDescription const &  prod,
std::string const &  oldBranchName 
)

Definition at line 105 of file RootTree.cc.

References edm::BranchDescription::init(), isValid(), edm::BranchDescription::setDropped(), and tree_.

105  {
106  assert(isValid());
107  prod.init();
108  if(tree_->GetBranch(oldBranchName.c_str()) == 0){
109  prod.setDropped();
110  }
111  }
TTree * tree_
Definition: RootTree.h:138
bool isValid() const
Definition: RootTree.cc:87
void edm::RootTree::setTreeMaxVirtualSize ( int  treeMaxVirtualSize)
private

Definition at line 170 of file RootTree.cc.

References tree_.

Referenced by RootTree().

170  {
171  if (treeMaxVirtualSize >= 0) tree_->SetMaxVirtualSize(static_cast<Long64_t>(treeMaxVirtualSize));
172  }
TTree * tree_
Definition: RootTree.h:138
void edm::RootTree::startTraining ( )
private

Definition at line 357 of file RootTree.cc.

References edm::poolNames::branchListIndexesBranchName(), branchType_, edm::BranchTypeToAuxiliaryBranchName(), cacheSize_, entryNumber_, filePtr_, edm::InEvent, learningEntries_, rawTreeCache_, switchOverEntry_, trainedSet_, tree_, treeCache_, and triggerSet_.

Referenced by setEntryNumber().

357  {
358  if (cacheSize_ == 0) {
359  return;
360  }
361  assert(treeCache_);
362  assert(branchType_ == InEvent);
363  assert(!rawTreeCache_);
364  treeCache_->SetLearnEntries(learningEntries_);
365  tree_->SetCacheSize(static_cast<Long64_t>(cacheSize_));
366  rawTreeCache_.reset(dynamic_cast<TTreeCache *>(filePtr_->GetCacheRead()));
367  rawTreeCache_->SetEnablePrefetching(false);
368  filePtr_->SetCacheRead(0);
369  rawTreeCache_->SetLearnEntries(0);
371  rawTreeCache_->StartLearningPhase();
373  rawTreeCache_->AddBranch("*", kTRUE);
374  rawTreeCache_->StopLearningPhase();
375  treeCache_->StartLearningPhase();
376  treeCache_->SetEntryRange(switchOverEntry_, tree_->GetEntries());
377  treeCache_->AddBranch(poolNames::branchListIndexesBranchName().c_str(), kTRUE);
378  treeCache_->AddBranch(BranchTypeToAuxiliaryBranchName(branchType_).c_str(), kTRUE);
379  trainedSet_.clear();
380  triggerSet_.clear();
381  assert(treeCache_->GetTree() == tree_);
382  }
EntryNumber entryNumber_
Definition: RootTree.h:152
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:114
unsigned int learningEntries_
Definition: RootTree.h:159
TTree * tree_
Definition: RootTree.h:138
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:149
boost::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:146
unsigned int cacheSize_
Definition: RootTree.h:160
std::unordered_set< TBranch * > triggerSet_
Definition: RootTree.h:150
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:241
EntryNumber switchOverEntry_
Definition: RootTree.h:156
BranchType branchType_
Definition: RootTree.h:140
void edm::RootTree::stopTraining ( )
private

Definition at line 385 of file RootTree.cc.

References filePtr_, rawTreeCache_, and treeCache_.

Referenced by setEntryNumber().

385  {
386  filePtr_->SetCacheRead(treeCache_.get());
387  treeCache_->StopLearningPhase();
388  filePtr_->SetCacheRead(0);
389  rawTreeCache_.reset();
390  }
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
boost::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:146
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
void edm::RootTree::trainCache ( char const *  branchNames)

Definition at line 415 of file RootTree.cc.

References branches(), cacheSize_, filePtr_, i, trainedSet_, tree_, and treeCache_.

Referenced by edm::RootFile::RootFile().

415  {
416  if (cacheSize_ == 0) {
417  return;
418  }
419  tree_->LoadTree(0);
420  assert(treeCache_);
421  filePtr_->SetCacheRead(treeCache_.get());
422  treeCache_->StartLearningPhase();
423  treeCache_->SetEntryRange(0, tree_->GetEntries());
424  treeCache_->AddBranch(branchNames, kTRUE);
425  treeCache_->StopLearningPhase();
426  assert(treeCache_->GetTree() == tree_);
427  // We own the treeCache_.
428  // We make sure the treeCache_ is detached from the file,
429  // so that ROOT does not also delete it.
430  filePtr_->SetCacheRead(0);
431 
432  // Must also manually add things to the trained set.
433  TObjArray *branches = tree_->GetListOfBranches();
434  int branchCount = branches->GetEntriesFast();
435  for (int i=0;i<branchCount;i++) {
436  TBranch *branch = (TBranch*)branches->UncheckedAt(i);
437  if ((branchNames[0] == '*') || (strcmp(branchNames, branch->GetName()) == 0)) {
438  trainedSet_.insert(branch);
439  }
440  }
441 
442  }
boost::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:145
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > const & branchNames() const
Definition: RootTree.h:89
TTree * tree_
Definition: RootTree.h:138
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:149
unsigned int cacheSize_
Definition: RootTree.h:160
BranchMap const & branches() const
Definition: RootTree.cc:157
boost::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:134
TTree const* edm::RootTree::tree ( ) const
inline
TTree* edm::RootTree::tree ( )
inline

Definition at line 114 of file RootTree.h.

References tree_.

Referenced by python.cmstools.EventTree::SetAlias().

114 {return tree_;}
TTree * tree_
Definition: RootTree.h:138

Member Data Documentation

TBranch* edm::RootTree::auxBranch_
private

Definition at line 141 of file RootTree.h.

Referenced by close(), fillAux(), and isValid().

TBranch* edm::RootTree::branchEntryInfoBranch_
private

Definition at line 168 of file RootTree.h.

Referenced by branchEntryInfoBranch(), close(), and isValid().

boost::shared_ptr<BranchMap> edm::RootTree::branches_
private

Definition at line 154 of file RootTree.h.

Referenced by addBranch(), and branches().

std::vector<std::string> edm::RootTree::branchNames_
private

Definition at line 153 of file RootTree.h.

Referenced by addBranch(), and branchNames().

BranchType edm::RootTree::branchType_
private

Definition at line 140 of file RootTree.h.

Referenced by branchType(), and startTraining().

unsigned int edm::RootTree::cacheSize_
private

Definition at line 160 of file RootTree.h.

Referenced by RootTree(), setCacheSize(), startTraining(), and trainCache().

bool edm::RootTree::enablePrefetching_
private

Definition at line 164 of file RootTree.h.

Referenced by setCacheSize().

bool edm::RootTree::enableTriggerCache_
private

Definition at line 165 of file RootTree.h.

Referenced by checkTriggerCache().

EntryNumber edm::RootTree::entries_
private

Definition at line 151 of file RootTree.h.

Referenced by entries(), isValid(), next(), and setEntryNumber().

EntryNumber edm::RootTree::entryNumber_
private
boost::shared_ptr<InputFile> edm::RootTree::filePtr_
private
TTree* edm::RootTree::infoTree_
private

Definition at line 170 of file RootTree.h.

Referenced by close(), and isValid().

unsigned int edm::RootTree::learningEntries_
private

Definition at line 159 of file RootTree.h.

Referenced by RootTree(), and startTraining().

TTree* edm::RootTree::metaTree_
private

Definition at line 139 of file RootTree.h.

Referenced by addBranch(), close(), fillBranchEntryMeta(), isValid(), and metaTree().

bool edm::RootTree::performedSwitchOver_
mutableprivate

Definition at line 158 of file RootTree.h.

Referenced by checkTriggerCacheImpl().

boost::shared_ptr<TTreeCache> edm::RootTree::rawTreeCache_
private

Definition at line 146 of file RootTree.h.

Referenced by close(), selectCache(), setCacheSize(), startTraining(), and stopTraining().

EntryNumber edm::RootTree::rawTriggerSwitchOverEntry_
mutableprivate

Definition at line 157 of file RootTree.h.

Referenced by checkTriggerCacheImpl(), and setEntryNumber().

boost::shared_ptr<TTreeCache> edm::RootTree::rawTriggerTreeCache_
mutableprivate

Definition at line 148 of file RootTree.h.

Referenced by checkTriggerCacheImpl(), and close().

std::unique_ptr<DelayedReader> edm::RootTree::rootDelayedReader_
private

Definition at line 166 of file RootTree.h.

Referenced by rootDelayedReader().

TBranch* edm::RootTree::statusBranch_
private

Definition at line 171 of file RootTree.h.

EntryNumber edm::RootTree::switchOverEntry_
private

Definition at line 156 of file RootTree.h.

Referenced by setEntryNumber(), and startTraining().

std::unordered_set<TBranch*> edm::RootTree::trainedSet_
mutableprivate
bool edm::RootTree::trainNow_
private

Definition at line 155 of file RootTree.h.

Referenced by resetTraining(), and setEntryNumber().

TTree* edm::RootTree::tree_
private
unsigned long edm::RootTree::treeAutoFlush_
private

Definition at line 161 of file RootTree.h.

Referenced by RootTree(), and setEntryNumber().

boost::shared_ptr<TTreeCache> edm::RootTree::treeCache_
private
std::unordered_set<TBranch*> edm::RootTree::triggerSet_
mutableprivate

Definition at line 150 of file RootTree.h.

Referenced by checkTriggerCacheImpl(), RootTree(), setEntryNumber(), and startTraining().

boost::shared_ptr<TTreeCache> edm::RootTree::triggerTreeCache_
mutableprivate

Definition at line 147 of file RootTree.h.

Referenced by checkTriggerCacheImpl(), and close().