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 () const
 
bool current (EntryNumber entry) const
 
void dropBranch (std::string const &oldBranchName)
 
EntryNumber const & entries () const
 
EntryNumber const & entryNumber () const
 
EntryNumber const & entryNumberForIndex (unsigned int index) const
 
template<typename T >
void fillAux (T *&pAux)
 
template<typename T >
void fillBranchEntry (TBranch *branch, T *&pbuf)
 
template<typename T >
void fillBranchEntry (TBranch *branch, EntryNumber entryNumber, T *&pbuf)
 
template<typename T >
void fillBranchEntryMeta (TBranch *branch, T *&pbuf)
 
template<typename T >
void fillBranchEntryMeta (TBranch *branch, EntryNumber entryNumber, T *&pbuf)
 
void getEntry (TBranch *branch, EntryNumber entry) const
 
void insertEntryForIndex (unsigned int index)
 
bool isValid () const
 
TTree const * metaTree () const
 
bool next ()
 
RootTreeoperator= (RootTree const &)=delete
 
bool previous ()
 
void resetTraining ()
 
void rewind ()
 
DelayedReaderrootDelayedReader () const
 
 RootTree (std::shared_ptr< InputFile > filePtr, BranchType const &branchType, unsigned int nIndexes, unsigned int maxVirtualSize, unsigned int cacheSize, unsigned int learningEntries, bool enablePrefetching, InputType inputType)
 
 RootTree (RootTree const &)=delete
 
TTreeCache * selectCache (TBranch *branch, EntryNumber entryNumber) const
 
void setEntryNumber (EntryNumber theEntryNumber)
 
void setPresence (BranchDescription &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_
 
std::shared_ptr< BranchMapbranches_
 
std::vector< std::string > branchNames_
 
BranchType branchType_
 
unsigned int cacheSize_
 
bool enablePrefetching_
 
bool enableTriggerCache_
 
EntryNumber entries_
 
EntryNumber entryNumber_
 
std::unique_ptr< std::vector
< EntryNumber > > 
entryNumberForIndex_
 
std::shared_ptr< InputFilefilePtr_
 
TTree * infoTree_
 
unsigned int learningEntries_
 
TTree * metaTree_
 
bool performedSwitchOver_
 
std::shared_ptr< TTreeCache > rawTreeCache_
 
EntryNumber rawTriggerSwitchOverEntry_
 
std::shared_ptr< TTreeCache > rawTriggerTreeCache_
 
std::unique_ptr< DelayedReaderrootDelayedReader_
 
TBranch * statusBranch_
 
EntryNumber switchOverEntry_
 
std::unordered_set< TBranch * > trainedSet_
 
bool trainNow_
 
TTree * tree_
 
unsigned long treeAutoFlush_
 
std::shared_ptr< TTreeCache > treeCache_
 
std::unordered_set< TBranch * > triggerSet_
 
std::shared_ptr< TTreeCache > triggerTreeCache_
 

Detailed Description

Definition at line 61 of file RootTree.h.

Member Typedef Documentation

Definition at line 63 of file RootTree.h.

Definition at line 64 of file RootTree.h.

Constructor & Destructor Documentation

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

Definition at line 28 of file RootTree.cc.

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

35  :
36  filePtr_(filePtr),
37  tree_(dynamic_cast<TTree*>(filePtr_.get() != nullptr ? filePtr_->Get(BranchTypeToProductTreeName(branchType).c_str()) : nullptr)),
38  metaTree_(dynamic_cast<TTree*>(filePtr_.get() != nullptr ? filePtr_->Get(BranchTypeToMetaDataTreeName(branchType).c_str()) : nullptr)),
40  auxBranch_(tree_ ? getAuxiliaryBranch(tree_, branchType_) : nullptr),
41  treeCache_(),
42  rawTreeCache_(),
45  trainedSet_(),
46  triggerSet_(),
47  entries_(tree_ ? tree_->GetEntries() : 0),
48  entryNumber_(-1),
49  entryNumberForIndex_(new std::vector<EntryNumber>(nIndexes, IndexIntoFile::invalidEntry)),
50  branchNames_(),
51  branches_(new BranchMap),
52  trainNow_(false),
53  switchOverEntry_(-1),
55  learningEntries_(learningEntries),
56  cacheSize_(cacheSize),
57  treeAutoFlush_(0),
58  enablePrefetching_(enablePrefetching),
59  //enableTriggerCache_(branchType_ == InEvent),
60  enableTriggerCache_(false), // Disable, for now. Using the trigger cache in the multithreaded environment causes the assert on line 331 to fire occasionally.
61  rootDelayedReader_(new RootDelayedReader(*this, filePtr, inputType)),
62  branchEntryInfoBranch_(metaTree_ ? getProductProvenanceBranch(metaTree_, branchType_) : (tree_ ? getProductProvenanceBranch(tree_, branchType_) : 0)),
63  infoTree_(dynamic_cast<TTree*>(filePtr_.get() != nullptr ? filePtr->Get(BranchTypeToInfoTreeName(branchType).c_str()) : nullptr)) // backward compatibility
64  {
65  assert(tree_);
66  // On merged files in older releases of ROOT, the autoFlush setting is always negative; we must guess.
67  // TODO: On newer merged files, we should be able to get this from the cluster iterator.
68  long treeAutoFlush = (tree_ ? tree_->GetAutoFlush() : 0);
69  if (treeAutoFlush < 0) {
70  // The "+1" is here to avoid divide-by-zero in degenerate cases.
71  Long64_t averageEventSizeBytes = tree_->GetZipBytes() / (tree_->GetEntries()+1) + 1;
72  treeAutoFlush_ = cacheSize_/averageEventSizeBytes+1;
73  } else {
74  treeAutoFlush_ = treeAutoFlush;
75  }
78  }
79  setTreeMaxVirtualSize(maxVirtualSize);
80  setCacheSize(cacheSize);
81  if (tree_) {
82  Int_t branchCount = tree_->GetListOfBranches()->GetEntriesFast();
83  trainedSet_.reserve(branchCount);
84  triggerSet_.reserve(branchCount);
85  }
86  }
EntryNumber entryNumber_
Definition: RootTree.h:178
std::string const & BranchTypeToMetaDataTreeName(BranchType const &branchType)
Definition: BranchType.cc:107
unsigned int learningEntries_
Definition: RootTree.h:186
std::shared_ptr< TTreeCache > rawTriggerTreeCache_
Definition: RootTree.h:174
std::vector< std::string > branchNames_
Definition: RootTree.h:180
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
TTree * tree_
Definition: RootTree.h:164
bool trainNow_
Definition: RootTree.h:182
std::shared_ptr< BranchMap > branches_
Definition: RootTree.h:181
EntryNumber rawTriggerSwitchOverEntry_
Definition: RootTree.h:184
roottree::BranchMap BranchMap
Definition: RootTree.h:63
TTree * metaTree_
Definition: RootTree.h:165
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:175
TBranch * branchEntryInfoBranch_
Definition: RootTree.h:195
EntryNumber entries_
Definition: RootTree.h:177
bool enablePrefetching_
Definition: RootTree.h:191
void setTreeMaxVirtualSize(int treeMaxVirtualSize)
Definition: RootTree.cc:185
BranchType branchType() const
Definition: RootTree.h:153
unsigned long treeAutoFlush_
Definition: RootTree.h:188
std::string const & BranchTypeToProductTreeName(BranchType const &branchType)
Definition: BranchType.cc:103
TBranch * auxBranch_
Definition: RootTree.h:167
std::string const & BranchTypeToInfoTreeName(BranchType const &branchType)
Definition: BranchType.cc:111
bool enableTriggerCache_
Definition: RootTree.h:192
static EntryNumber_t const invalidEntry
std::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:172
std::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:160
void setCacheSize(unsigned int cacheSize)
Definition: RootTree.cc:175
std::unique_ptr< std::vector< EntryNumber > > entryNumberForIndex_
Definition: RootTree.h:179
unsigned int cacheSize_
Definition: RootTree.h:187
std::unordered_set< TBranch * > triggerSet_
Definition: RootTree.h:176
std::unique_ptr< DelayedReader > rootDelayedReader_
Definition: RootTree.h:193
EntryNumber switchOverEntry_
Definition: RootTree.h:183
std::shared_ptr< TTreeCache > triggerTreeCache_
Definition: RootTree.h:173
BranchType branchType_
Definition: RootTree.h:166
TTree * infoTree_
Definition: RootTree.h:197
edm::RootTree::~RootTree ( )

Definition at line 88 of file RootTree.cc.

88  {
89  }
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 130 of file RootTree.cc.

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

132  {
133  assert(isValid());
134  //use the translated branch name
135  TBranch* branch = tree_->GetBranch(oldBranchName.c_str());
136  roottree::BranchInfo info = roottree::BranchInfo(BranchDescription(prod));
137  info.productBranch_ = nullptr;
138  if (prod.present()) {
139  info.productBranch_ = branch;
140  //we want the new branch name for the JobReport
141  branchNames_.push_back(prod.branchName());
142  }
143  TTree* provTree = (metaTree_ != nullptr ? metaTree_ : tree_);
144  info.provenanceBranch_ = provTree->GetBranch(oldBranchName.c_str());
145  branches_->insert(std::make_pair(key, info));
146  }
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< std::string > branchNames_
Definition: RootTree.h:180
TTree * tree_
Definition: RootTree.h:164
std::shared_ptr< BranchMap > branches_
Definition: RootTree.h:181
TTree * metaTree_
Definition: RootTree.h:165
bool isValid() const
Definition: RootTree.cc:104
list key
Definition: combine.py:13
TBranch* edm::RootTree::branchEntryInfoBranch ( ) const
inline
roottree::BranchMap const & edm::RootTree::branches ( ) const

Definition at line 172 of file RootTree.cc.

References branches_.

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

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

Definition at line 98 of file RootTree.h.

References branchNames_.

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

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

Definition at line 153 of file RootTree.h.

References branchType_.

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

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

Definition at line 222 of file RootTree.cc.

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

Referenced by selectCache().

222  {
223  if (!treeCache_->IsAsyncReading() && enableTriggerCache_ && (trainedSet_.find(branch) == trainedSet_.end())) {
224  return checkTriggerCacheImpl(branch, entryNumber);
225  } else {
226  return NULL;
227  }
228  }
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:175
#define NULL
Definition: scimark2.h:8
TTreeCache * checkTriggerCacheImpl(TBranch *branch, EntryNumber entryNumber) const
Definition: RootTree.cc:233
EntryNumber const & entryNumber() const
Definition: RootTree.h:93
bool enableTriggerCache_
Definition: RootTree.h:192
TTreeCache * edm::RootTree::checkTriggerCacheImpl ( TBranch *  branch,
EntryNumber  entryNumber 
) const

Definition at line 233 of file RootTree.cc.

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

Referenced by checkTriggerCache().

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

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

408  {
409  // The TFile is about to be closed, and destructed.
410  // Just to play it safe, zero all pointers to quantities that are owned by the TFile.
412  tree_ = metaTree_ = infoTree_ = nullptr;
413  // We own the treeCache_.
414  // We make sure the treeCache_ is detached from the file,
415  // so that ROOT does not also delete it.
416  filePtr_->SetCacheRead(0);
417  // We *must* delete the TTreeCache here because the TFilePrefetch object
418  // references the TFile. If TFile is closed, before the TTreeCache is
419  // deleted, the TFilePrefetch may continue to do TFile operations, causing
420  // deadlocks or exceptions.
421  treeCache_.reset();
422  rawTreeCache_.reset();
423  triggerTreeCache_.reset();
424  rawTriggerTreeCache_.reset();
425  // We give up our shared ownership of the TFile itself.
426  filePtr_.reset();
427  }
std::shared_ptr< TTreeCache > rawTriggerTreeCache_
Definition: RootTree.h:174
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
TTree * tree_
Definition: RootTree.h:164
TTree * metaTree_
Definition: RootTree.h:165
TBranch * branchEntryInfoBranch_
Definition: RootTree.h:195
TBranch * auxBranch_
Definition: RootTree.h:167
std::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:172
std::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:160
std::shared_ptr< TTreeCache > triggerTreeCache_
Definition: RootTree.h:173
TTree * infoTree_
Definition: RootTree.h:197
bool edm::RootTree::current ( ) const
inline

Definition at line 89 of file RootTree.h.

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

89 {return entryNumber_ < entries_ && entryNumber_ >= 0;}
bool edm::RootTree::current ( EntryNumber  entry) const
inline

Definition at line 90 of file RootTree.h.

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

Definition at line 149 of file RootTree.cc.

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

149  {
150  //use the translated branch name
151  TBranch* branch = tree_->GetBranch(oldBranchName.c_str());
152  if (branch != nullptr) {
153  TObjArray* leaves = tree_->GetListOfLeaves();
154  int entries = leaves->GetEntries();
155  for (int i = 0; i < entries; ++i) {
156  TLeaf* leaf = (TLeaf*)(*leaves)[i];
157  if (leaf == nullptr) continue;
158  TBranch* br = leaf->GetBranch();
159  if (br == nullptr) continue;
160  if (br->GetMother() == branch) {
161  leaves->Remove(leaf);
162  }
163  }
164  leaves->Compress();
165  tree_->GetListOfBranches()->Remove(branch);
166  tree_->GetListOfBranches()->Compress();
167  delete branch;
168  }
169  }
int i
Definition: DBlmapReader.cc:9
TTree * tree_
Definition: RootTree.h:164
EntryNumber const & entries() const
Definition: RootTree.h:95
tuple leaf
Definition: Node.py:62
EntryNumber const& edm::RootTree::entries ( ) const
inline

Definition at line 95 of file RootTree.h.

References entries_.

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

95 {return entries_;}
EntryNumber entries_
Definition: RootTree.h:177
EntryNumber const& edm::RootTree::entryNumber ( ) const
inline
RootTree::EntryNumber const & edm::RootTree::entryNumberForIndex ( unsigned int  index) const

Definition at line 92 of file RootTree.cc.

References entryNumberForIndex_, cmsHarvester::index, and findQualityFiles::size.

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

92  {
93  assert(index < entryNumberForIndex_->size());
94  return (*entryNumberForIndex_)[index];
95  }
std::unique_ptr< std::vector< EntryNumber > > entryNumberForIndex_
Definition: RootTree.h:179
tuple size
Write out results.
template<typename T >
void edm::RootTree::fillAux ( T *&  pAux)
inline

Definition at line 101 of file RootTree.h.

References auxBranch_, entryNumber_, and getEntry().

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

101  {
102  auxBranch_->SetAddress(&pAux);
104  }
EntryNumber entryNumber_
Definition: RootTree.h:178
TBranch * auxBranch_
Definition: RootTree.h:167
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:355
template<typename T >
void edm::RootTree::fillBranchEntry ( TBranch *  branch,
T *&  pbuf 
)
inline

Definition at line 117 of file RootTree.h.

References entryNumber_, and getEntry().

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

117  {
118  branch->SetAddress(&pbuf);
119  getEntry(branch, entryNumber_);
120  }
EntryNumber entryNumber_
Definition: RootTree.h:178
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:355
template<typename T >
void edm::RootTree::fillBranchEntry ( TBranch *  branch,
EntryNumber  entryNumber,
T *&  pbuf 
)
inline

Definition at line 134 of file RootTree.h.

References getEntry().

134  {
135  branch->SetAddress(&pbuf);
136  getEntry(branch, entryNumber);
137  }
EntryNumber const & entryNumber() const
Definition: RootTree.h:93
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:355
template<typename T >
void edm::RootTree::fillBranchEntryMeta ( TBranch *  branch,
T *&  pbuf 
)
inline

Definition at line 106 of file RootTree.h.

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

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

106  {
107  if (metaTree_ != nullptr) {
108  // Metadata was in separate tree. Not cached.
109  branch->SetAddress(&pbuf);
111  } else {
112  fillBranchEntry<T>(branch, pbuf);
113  }
114  }
EntryNumber entryNumber_
Definition: RootTree.h:178
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: RootTree.cc:461
TTree * metaTree_
Definition: RootTree.h:165
template<typename T >
void edm::RootTree::fillBranchEntryMeta ( TBranch *  branch,
EntryNumber  entryNumber,
T *&  pbuf 
)
inline

Definition at line 123 of file RootTree.h.

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

123  {
124  if (metaTree_ != nullptr) {
125  // Metadata was in separate tree. Not cached.
126  branch->SetAddress(&pbuf);
128  } else {
129  fillBranchEntry<T>(branch, entryNumber, pbuf);
130  }
131  }
Int_t getEntry(TBranch *branch, EntryNumber entryNumber)
Definition: RootTree.cc:461
TTree * metaTree_
Definition: RootTree.h:165
EntryNumber const & entryNumber() const
Definition: RootTree.h:93
void edm::RootTree::getEntry ( TBranch *  branch,
EntryNumber  entry 
) const

Definition at line 355 of file RootTree.cc.

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

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

355  {
356  try {
357  TTreeCache * cache = selectCache(branch, entryNumber);
358  filePtr_->SetCacheRead(cache);
359  branch->GetEntry(entryNumber);
360  filePtr_->SetCacheRead(0);
361  } catch(cms::Exception const& e) {
362  // We make sure the treeCache_ is detached from the file,
363  // so that ROOT does not also delete it.
364  filePtr_->SetCacheRead(0);
366  t.addContext(std::string("Reading branch ")+branch->GetName());
367  throw t;
368  }
369  }
TTreeCache * selectCache(TBranch *branch, EntryNumber entryNumber) const
Definition: RootTree.cc:336
EntryNumber const & entryNumber() const
Definition: RootTree.h:93
std::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:160
void edm::RootTree::insertEntryForIndex ( unsigned int  index)

Definition at line 98 of file RootTree.cc.

References entryNumber(), cmsHarvester::index, and findQualityFiles::size.

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

98  {
99  assert(index < entryNumberForIndex_->size());
100  (*entryNumberForIndex_)[index] = entryNumber();
101  }
EntryNumber const & entryNumber() const
Definition: RootTree.h:93
tuple size
Write out results.
bool edm::RootTree::isValid ( void  ) const

Definition at line 104 of file RootTree.cc.

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

Referenced by addBranch(), edm::RootFile::fillIndexIntoFile(), edm::RootFile::readLuminosityBlock_(), edm::RootFile::readLuminosityBlockAuxiliary_(), edm::RootFile::readRun_(), edm::RootFile::readRunAuxiliary_(), core.AutoHandle.AutoHandle::ReallyLoad(), setPresence(), and edm::RootFile::validateFile().

104  {
105  if (metaTree_ == nullptr || metaTree_->GetNbranches() == 0) {
106  return tree_ != nullptr && auxBranch_ != nullptr;
107  }
108  if (tree_ != nullptr && auxBranch_ != nullptr && metaTree_ != nullptr) { // backward compatibility
109  if (branchEntryInfoBranch_ != nullptr || infoTree_ != nullptr) return true; // backward compatibility
110  return (entries_ == metaTree_->GetEntries() && tree_->GetNbranches() <= metaTree_->GetNbranches() + 1); // backward compatibility
111  } // backward compatibility
112  return false;
113  }
TTree * tree_
Definition: RootTree.h:164
TTree * metaTree_
Definition: RootTree.h:165
TBranch * branchEntryInfoBranch_
Definition: RootTree.h:195
EntryNumber entries_
Definition: RootTree.h:177
TBranch * auxBranch_
Definition: RootTree.h:167
TTree * infoTree_
Definition: RootTree.h:197
TTree const* edm::RootTree::metaTree ( ) const
inline

Definition at line 141 of file RootTree.h.

References metaTree_.

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

141 {return metaTree_;}
TTree * metaTree_
Definition: RootTree.h:165
bool edm::RootTree::next ( void  )
inline
RootTree& edm::RootTree::operator= ( RootTree const &  )
delete
bool edm::RootTree::previous ( )
inline

Definition at line 88 of file RootTree.h.

References entryNumber_.

Referenced by BeautifulSoup.PageElement::_invert().

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

Definition at line 151 of file RootTree.h.

References trainNow_.

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

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

Definition at line 91 of file RootTree.h.

References entryNumber_.

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

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

Definition at line 116 of file RootTree.cc.

References rootDelayedReader_.

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

116  {
117  rootDelayedReader_->reset();
118  return rootDelayedReader_.get();
119  }
std::unique_ptr< DelayedReader > rootDelayedReader_
Definition: RootTree.h:193
TTreeCache * edm::RootTree::selectCache ( TBranch *  branch,
EntryNumber  entryNumber 
) const
inline

Definition at line 336 of file RootTree.cc.

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

Referenced by getEntry().

336  {
337  TTreeCache *triggerCache = NULL;
338  if (!treeCache_) {
339  return NULL;
340  } else if (treeCache_->IsLearning() && rawTreeCache_) {
341  treeCache_->AddBranch(branch, kTRUE);
342  trainedSet_.insert(branch);
343  return rawTreeCache_.get();
344  } else if ((triggerCache = checkTriggerCache(branch, entryNumber))) {
345  // A NULL return value from checkTriggerCache indicates the trigger cache case
346  // does not apply, and we should continue below.
347  return triggerCache;
348  } else {
349  // The "normal" TTreeCache case.
350  return treeCache_.get();
351  }
352  }
TTreeCache * checkTriggerCache(TBranch *branch, EntryNumber entryNumber) const
Definition: RootTree.cc:222
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:175
#define NULL
Definition: scimark2.h:8
EntryNumber const & entryNumber() const
Definition: RootTree.h:93
std::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:172
void edm::RootTree::setCacheSize ( unsigned int  cacheSize)
private

Definition at line 175 of file RootTree.cc.

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

Referenced by RootTree().

175  {
176  cacheSize_ = cacheSize;
177  tree_->SetCacheSize(static_cast<Long64_t>(cacheSize));
178  treeCache_.reset(dynamic_cast<TTreeCache*>(filePtr_->GetCacheRead()));
179  if(treeCache_) treeCache_->SetEnablePrefetching(enablePrefetching_);
180  filePtr_->SetCacheRead(0);
181  rawTreeCache_.reset();
182  }
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
TTree * tree_
Definition: RootTree.h:164
bool enablePrefetching_
Definition: RootTree.h:191
std::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:172
std::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:160
unsigned int cacheSize_
Definition: RootTree.h:187
void edm::RootTree::setEntryNumber ( EntryNumber  theEntryNumber)

Definition at line 190 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::readLuminosityBlock_(), edm::RootFile::readLuminosityBlockAuxiliary_(), edm::RootFile::readRunAuxiliary_(), edm::RootFile::setAtEventEntry(), edm::RootFile::setEntryAtEvent(), edm::RootFile::setEntryAtLumi(), and edm::RootFile::setEntryAtRun().

190  {
191  filePtr_->SetCacheRead(treeCache_.get());
192 
193  // Detect a backward skip. If the skip is sufficiently large, we roll the dice and reset the treeCache.
194  // This will cause some amount of over-reading: we pre-fetch all the events in some prior cluster.
195  // However, because reading one event in the cluster is supposed to be equivalent to reading all events in the cluster,
196  // we're not incurring additional over-reading - we're just doing it more efficiently.
197  // NOTE: Constructor guarantees treeAutoFlush_ is positive, even if TTree->GetAutoFlush() is negative.
198  if ((theEntryNumber < static_cast<EntryNumber>(entryNumber_-treeAutoFlush_)) &&
199  (treeCache_) && (!treeCache_->IsLearning()) && (entries_ > 0) && (switchOverEntry_ >= 0)) {
200  treeCache_->SetEntryRange(theEntryNumber, entries_);
201  treeCache_->FillBuffer();
202  }
203 
204  entryNumber_ = theEntryNumber;
205  tree_->LoadTree(entryNumber_);
206  filePtr_->SetCacheRead(0);
207  if(treeCache_ && trainNow_ && entryNumber_ >= 0) {
208  startTraining();
209  trainNow_ = false;
210  trainedSet_.clear();
211  triggerSet_.clear();
213  }
214  if (treeCache_ && treeCache_->IsLearning() && switchOverEntry_ >= 0 && entryNumber_ >= switchOverEntry_) {
215  stopTraining();
216  }
217  }
EntryNumber entryNumber_
Definition: RootTree.h:178
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
TTree * tree_
Definition: RootTree.h:164
bool trainNow_
Definition: RootTree.h:182
EntryNumber rawTriggerSwitchOverEntry_
Definition: RootTree.h:184
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:175
void stopTraining()
Definition: RootTree.cc:400
EntryNumber entries_
Definition: RootTree.h:177
unsigned long treeAutoFlush_
Definition: RootTree.h:188
void startTraining()
Definition: RootTree.cc:372
std::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:160
std::unordered_set< TBranch * > triggerSet_
Definition: RootTree.h:176
EntryNumber switchOverEntry_
Definition: RootTree.h:183
void edm::RootTree::setPresence ( BranchDescription prod,
std::string const &  oldBranchName 
)

Definition at line 122 of file RootTree.cc.

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

122  {
123  assert(isValid());
124  if(tree_->GetBranch(oldBranchName.c_str()) == nullptr){
125  prod.setDropped(true);
126  }
127  }
TTree * tree_
Definition: RootTree.h:164
bool isValid() const
Definition: RootTree.cc:104
void edm::RootTree::setTreeMaxVirtualSize ( int  treeMaxVirtualSize)
private

Definition at line 185 of file RootTree.cc.

References tree_.

Referenced by RootTree().

185  {
186  if (treeMaxVirtualSize >= 0) tree_->SetMaxVirtualSize(static_cast<Long64_t>(treeMaxVirtualSize));
187  }
TTree * tree_
Definition: RootTree.h:164
void edm::RootTree::startTraining ( )
private

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

372  {
373  if (cacheSize_ == 0) {
374  return;
375  }
376  assert(treeCache_);
377  assert(branchType_ == InEvent);
378  assert(!rawTreeCache_);
379  treeCache_->SetLearnEntries(learningEntries_);
380  tree_->SetCacheSize(static_cast<Long64_t>(cacheSize_));
381  rawTreeCache_.reset(dynamic_cast<TTreeCache *>(filePtr_->GetCacheRead()));
382  rawTreeCache_->SetEnablePrefetching(false);
383  filePtr_->SetCacheRead(0);
384  rawTreeCache_->SetLearnEntries(0);
386  rawTreeCache_->StartLearningPhase();
388  rawTreeCache_->AddBranch("*", kTRUE);
389  rawTreeCache_->StopLearningPhase();
390  treeCache_->StartLearningPhase();
391  treeCache_->SetEntryRange(switchOverEntry_, tree_->GetEntries());
392  treeCache_->AddBranch(poolNames::branchListIndexesBranchName().c_str(), kTRUE);
393  treeCache_->AddBranch(BranchTypeToAuxiliaryBranchName(branchType_).c_str(), kTRUE);
394  trainedSet_.clear();
395  triggerSet_.clear();
396  assert(treeCache_->GetTree() == tree_);
397  }
EntryNumber entryNumber_
Definition: RootTree.h:178
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:115
unsigned int learningEntries_
Definition: RootTree.h:186
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
TTree * tree_
Definition: RootTree.h:164
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:175
std::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:172
std::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:160
unsigned int cacheSize_
Definition: RootTree.h:187
std::unordered_set< TBranch * > triggerSet_
Definition: RootTree.h:176
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:247
EntryNumber switchOverEntry_
Definition: RootTree.h:183
BranchType branchType_
Definition: RootTree.h:166
void edm::RootTree::stopTraining ( )
private

Definition at line 400 of file RootTree.cc.

References filePtr_, rawTreeCache_, and treeCache_.

Referenced by setEntryNumber().

400  {
401  filePtr_->SetCacheRead(treeCache_.get());
402  treeCache_->StopLearningPhase();
403  filePtr_->SetCacheRead(0);
404  rawTreeCache_.reset();
405  }
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
std::shared_ptr< TTreeCache > rawTreeCache_
Definition: RootTree.h:172
std::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:160
void edm::RootTree::trainCache ( char const *  branchNames)

Definition at line 430 of file RootTree.cc.

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

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

430  {
431  if (cacheSize_ == 0) {
432  return;
433  }
434  tree_->LoadTree(0);
435  assert(treeCache_);
436  filePtr_->SetCacheRead(treeCache_.get());
437  treeCache_->StartLearningPhase();
438  treeCache_->SetEntryRange(0, tree_->GetEntries());
439  treeCache_->AddBranch(branchNames, kTRUE);
440  treeCache_->StopLearningPhase();
441  assert(treeCache_->GetTree() == tree_);
442  // We own the treeCache_.
443  // We make sure the treeCache_ is detached from the file,
444  // so that ROOT does not also delete it.
445  filePtr_->SetCacheRead(0);
446 
447  // Must also manually add things to the trained set.
448  TObjArray *branches = tree_->GetListOfBranches();
449  int branchCount = branches->GetEntriesFast();
450  for (int i=0;i<branchCount;i++) {
451  TBranch *branch = (TBranch*)branches->UncheckedAt(i);
452  if ((branchNames[0] == '*') || (strcmp(branchNames, branch->GetName()) == 0)) {
453  trainedSet_.insert(branch);
454  }
455  }
456 
457  }
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > const & branchNames() const
Definition: RootTree.h:98
std::shared_ptr< TTreeCache > treeCache_
Definition: RootTree.h:171
TTree * tree_
Definition: RootTree.h:164
std::unordered_set< TBranch * > trainedSet_
Definition: RootTree.h:175
std::shared_ptr< InputFile > filePtr_
Definition: RootTree.h:160
unsigned int cacheSize_
Definition: RootTree.h:187
BranchMap const & branches() const
Definition: RootTree.cc:172
TTree const* edm::RootTree::tree ( ) const
inline
TTree* edm::RootTree::tree ( )
inline

Member Data Documentation

TBranch* edm::RootTree::auxBranch_
private

Definition at line 167 of file RootTree.h.

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

TBranch* edm::RootTree::branchEntryInfoBranch_
private

Definition at line 195 of file RootTree.h.

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

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

Definition at line 181 of file RootTree.h.

Referenced by addBranch(), and branches().

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

Definition at line 180 of file RootTree.h.

Referenced by addBranch(), and branchNames().

BranchType edm::RootTree::branchType_
private

Definition at line 166 of file RootTree.h.

Referenced by branchType(), and startTraining().

unsigned int edm::RootTree::cacheSize_
private

Definition at line 187 of file RootTree.h.

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

bool edm::RootTree::enablePrefetching_
private

Definition at line 191 of file RootTree.h.

Referenced by setCacheSize().

bool edm::RootTree::enableTriggerCache_
private

Definition at line 192 of file RootTree.h.

Referenced by checkTriggerCache().

EntryNumber edm::RootTree::entries_
private

Definition at line 177 of file RootTree.h.

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

EntryNumber edm::RootTree::entryNumber_
private
std::unique_ptr<std::vector<EntryNumber> > edm::RootTree::entryNumberForIndex_
private

Definition at line 179 of file RootTree.h.

Referenced by entryNumberForIndex().

std::shared_ptr<InputFile> edm::RootTree::filePtr_
private
TTree* edm::RootTree::infoTree_
private

Definition at line 197 of file RootTree.h.

Referenced by close(), and isValid().

unsigned int edm::RootTree::learningEntries_
private

Definition at line 186 of file RootTree.h.

Referenced by RootTree(), and startTraining().

TTree* edm::RootTree::metaTree_
private

Definition at line 165 of file RootTree.h.

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

bool edm::RootTree::performedSwitchOver_
mutableprivate

Definition at line 185 of file RootTree.h.

Referenced by checkTriggerCacheImpl().

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

Definition at line 172 of file RootTree.h.

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

EntryNumber edm::RootTree::rawTriggerSwitchOverEntry_
mutableprivate

Definition at line 184 of file RootTree.h.

Referenced by checkTriggerCacheImpl(), and setEntryNumber().

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

Definition at line 174 of file RootTree.h.

Referenced by checkTriggerCacheImpl(), and close().

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

Definition at line 193 of file RootTree.h.

Referenced by rootDelayedReader().

TBranch* edm::RootTree::statusBranch_
private

Definition at line 198 of file RootTree.h.

EntryNumber edm::RootTree::switchOverEntry_
private

Definition at line 183 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 182 of file RootTree.h.

Referenced by resetTraining(), and setEntryNumber().

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

Definition at line 188 of file RootTree.h.

Referenced by RootTree(), and setEntryNumber().

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

Definition at line 176 of file RootTree.h.

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

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

Definition at line 173 of file RootTree.h.

Referenced by checkTriggerCacheImpl(), and close().