Skip to content

Commit 9632144

Browse files
committed
Use separate TTreeCache for auxiliary branch
1 parent 9330780 commit 9632144

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

IOPool/Input/src/RootTree.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,23 @@ namespace edm {
410410
return treeCache_.get();
411411
}
412412
}
413+
TTreeCache* RootTree::getAuxCache(TBranch* auxBranch) const {
414+
if (not auxCache_ and cacheSize_ > 0) {
415+
tree_->SetCacheSize(1 * 1024 * 1024);
416+
auxCache_.reset(dynamic_cast<TTreeCache*>(filePtr_->GetCacheRead(tree_)));
417+
if (auxCache_) {
418+
auxCache_->SetEnablePrefetching(enablePrefetching_);
419+
auxCache_->SetEnablePrefetching(false);
420+
filePtr_->SetCacheRead(nullptr, tree_);
421+
auxCache_->SetLearnEntries(0);
422+
auxCache_->StartLearningPhase();
423+
auxCache_->SetEntryRange(0, tree_->GetEntries());
424+
auxCache_->AddBranch(auxBranch->GetName(), kTRUE);
425+
auxCache_->StopLearningPhase();
426+
}
427+
}
428+
return auxCache_.get();
429+
}
413430

414431
void RootTree::getEntryForAllBranches() const {
415432
filePtr_->SetCacheRead(rawTreeCache_.get(), tree_);
@@ -420,8 +437,11 @@ namespace edm {
420437
}
421438

422439
void RootTree::getEntry(TBranch* branch, EntryNumber entryNumber) const {
440+
getEntryUsingCache(branch, entryNumber, selectCache(branch, entryNumber));
441+
}
442+
443+
inline void RootTree::getEntryUsingCache(TBranch* branch, EntryNumber entryNumber, TTreeCache* cache) const {
423444
try {
424-
TTreeCache* cache = selectCache(branch, entryNumber);
425445
filePtr_->SetCacheRead(cache, tree_);
426446
branch->GetEntry(entryNumber);
427447
filePtr_->SetCacheRead(nullptr, tree_);
@@ -529,6 +549,7 @@ namespace edm {
529549
rawTreeCache_.reset();
530550
triggerTreeCache_.reset();
531551
rawTriggerTreeCache_.reset();
552+
auxCache_.reset();
532553
// We give up our shared ownership of the TFile itself.
533554
filePtr_.reset();
534555
}

IOPool/Input/src/RootTree.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ namespace edm {
150150
template <typename T>
151151
void fillAux(T*& pAux) {
152152
auxBranch_->SetAddress(&pAux);
153-
getEntry(auxBranch_, entryNumber_);
153+
auto cache = getAuxCache(auxBranch_);
154+
getEntryUsingCache(auxBranch_, entryNumber_, cache);
154155
auxBranch_->SetAddress(nullptr);
155156
}
156157

@@ -213,6 +214,8 @@ namespace edm {
213214
void setTreeMaxVirtualSize(int treeMaxVirtualSize);
214215
void startTraining();
215216
void stopTraining();
217+
void getEntryUsingCache(TBranch* branch, EntryNumber entry, TTreeCache*) const;
218+
TTreeCache* getAuxCache(TBranch* auxBranch) const;
216219

217220
std::shared_ptr<InputFile> filePtr_;
218221
// We use bare pointers for pointers to some ROOT entities.
@@ -228,6 +231,7 @@ namespace edm {
228231
// So, we make sure to it is detached before closing the TFile so there is no double delete.
229232
std::shared_ptr<TTreeCache> treeCache_;
230233
std::shared_ptr<TTreeCache> rawTreeCache_;
234+
CMS_SA_ALLOW mutable std::shared_ptr<TTreeCache> auxCache_;
231235
//All access to a ROOT file is serialized
232236
CMS_SA_ALLOW mutable std::shared_ptr<TTreeCache> triggerTreeCache_;
233237
CMS_SA_ALLOW mutable std::shared_ptr<TTreeCache> rawTriggerTreeCache_;

0 commit comments

Comments
 (0)