Skip to content

Commit 7958762

Browse files
committed
Use just one TTreeCache when prompt reading
1 parent 6344955 commit 7958762

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

IOPool/Input/src/RootTree.cc

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ namespace edm {
2626
return branch;
2727
}
2828

29-
std::unique_ptr<RootDelayedReaderBase> makeRootDelayedReader(
30-
RootTree const& tree, std::shared_ptr<InputFile> filePtr, InputType inputType, unsigned int nIndexes, bool promptRead) {
31-
if(promptRead) {
32-
return std::make_unique<RootPromptReadDelayedReader>(tree, filePtr, inputType, nIndexes);
33-
}
29+
std::unique_ptr<RootDelayedReaderBase> makeRootDelayedReader(RootTree const& tree,
30+
std::shared_ptr<InputFile> filePtr,
31+
InputType inputType,
32+
unsigned int nIndexes,
33+
bool promptRead) {
34+
if (promptRead) {
35+
return std::make_unique<RootPromptReadDelayedReader>(tree, filePtr, inputType, nIndexes);
36+
}
3437
return std::make_unique<RootDelayedReader>(tree, filePtr, inputType);
3538
}
3639
} // namespace
@@ -50,6 +53,7 @@ namespace edm {
5053
learningEntries_(learningEntries),
5154
enablePrefetching_(enablePrefetching),
5255
enableTriggerCache_(branchType_ == InEvent),
56+
promptRead_(promptRead),
5357
rootDelayedReader_(makeRootDelayedReader(*this, filePtr, inputType, nIndexes, promptRead)) {}
5458

5559
// Used for Event/Lumi/Run RootTrees
@@ -59,7 +63,8 @@ namespace edm {
5963
Options const& options,
6064
unsigned int learningEntries,
6165
InputType inputType)
62-
: RootTree(filePtr, branchType, nIndexes, learningEntries, options.enablePrefetching, options.promptReading, inputType) {
66+
: RootTree(
67+
filePtr, branchType, nIndexes, learningEntries, options.enablePrefetching, options.promptReading, inputType) {
6368
init(BranchTypeToProductTreeName(branchType), options.treeMaxVirtualSize, options.treeCacheSize);
6469
metaTree_ = dynamic_cast<TTree*>(filePtr_->Get(BranchTypeToMetaDataTreeName(branchType).c_str()));
6570
auxBranch_ = getAuxiliaryBranch(tree_, branchType_);
@@ -77,7 +82,8 @@ namespace edm {
7782
Options const& options,
7883
unsigned int learningEntries,
7984
InputType inputType)
80-
: RootTree(filePtr, branchType, nIndexes, learningEntries, options.enablePrefetching, options.promptReading, inputType) {
85+
: RootTree(
86+
filePtr, branchType, nIndexes, learningEntries, options.enablePrefetching, options.promptReading, inputType) {
8187
processName_ = processName;
8288
init(BranchTypeToProductTreeName(branchType, processName), options.treeMaxVirtualSize, options.treeCacheSize);
8389
}
@@ -285,7 +291,8 @@ namespace edm {
285291
triggerSet_.clear();
286292
rawTriggerSwitchOverEntry_ = -1;
287293
}
288-
if (treeCache_ && treeCache_->IsLearning() && switchOverEntry_ >= 0 && entryNumber_ >= switchOverEntry_) {
294+
if (not promptRead_ && treeCache_ && treeCache_->IsLearning() && switchOverEntry_ >= 0 &&
295+
entryNumber_ >= switchOverEntry_) {
289296
stopTraining();
290297
}
291298
}
@@ -385,6 +392,9 @@ namespace edm {
385392

386393
inline TTreeCache* RootTree::selectCache(TBranch* branch, EntryNumber entryNumber) const {
387394
TTreeCache* triggerCache = nullptr;
395+
if (promptRead_) {
396+
return rawTreeCache_.get();
397+
}
388398
if (!treeCache_) {
389399
return nullptr;
390400
} else if (treeCache_->IsLearning() && rawTreeCache_) {
@@ -404,14 +414,11 @@ namespace edm {
404414
void RootTree::getEntryForAllBranches() const {
405415
filePtr_->SetCacheRead(rawTreeCache_.get());
406416
auto ptr = filePtr_.get();
407-
auto cleanup = [ptr](TTreeCache* cache) {
408-
ptr->SetCacheRead(nullptr);
409-
};
417+
auto cleanup = [ptr](TTreeCache* cache) { ptr->SetCacheRead(nullptr); };
410418
std::unique_ptr<TTreeCache, decltype(cleanup)> cacheGuard(rawTreeCache_.get(), cleanup);
411419
tree_->GetEntry(entryNumber_);
412420
}
413421

414-
415422
void RootTree::getEntry(TBranch* branch, EntryNumber entryNumber) const {
416423
try {
417424
TTreeCache* cache = selectCache(branch, entryNumber);
@@ -468,7 +475,11 @@ namespace edm {
468475
rawTreeCache_->SetEnablePrefetching(false);
469476
filePtr_->SetCacheRead(nullptr);
470477
rawTreeCache_->SetLearnEntries(0);
471-
switchOverEntry_ = entryNumber_ + learningEntries_;
478+
if (promptRead_) {
479+
switchOverEntry_ = entries_;
480+
} else {
481+
switchOverEntry_ = entryNumber_ + learningEntries_;
482+
}
472483
auto rawStart = entryNumber_;
473484
auto rawEnd = switchOverEntry_;
474485
auto treeStart = switchOverEntry_;

IOPool/Input/src/RootTree.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ namespace edm {
4747
void setBranch(TBranch* branch, TClass const* wrapperBaseTClass);
4848
std::unique_ptr<WrapperBase> newWrapper() const;
4949
TBranch* productBranch_;
50-
private:
50+
51+
private:
5152
//All access to a ROOT file is serialized
5253
TClass* classCache_;
5354
Int_t offsetToWrapperBase_;
@@ -59,9 +60,7 @@ namespace edm {
5960

6061
void reserve(Map::size_type iSize) { map_.reserve(iSize); }
6162
void insert(edm::BranchID const& iKey, BranchInfo const& iInfo) { map_.emplace(iKey.id(), iInfo); }
62-
BranchInfo const* find(BranchID const& iKey) const {
63-
return find(iKey.id());
64-
}
63+
BranchInfo const* find(BranchID const& iKey) const { return find(iKey.id()); }
6564
BranchInfo const* find(unsigned int iKey) const {
6665
auto itFound = map_.find(iKey);
6766
if (itFound == map_.end()) {
@@ -74,6 +73,7 @@ namespace edm {
7473
const_iterator begin() const { return map_.cbegin(); }
7574
const_iterator end() const { return map_.cend(); }
7675
Map::size_type size() const { return map_.size(); }
76+
7777
private:
7878
Map map_;
7979
};
@@ -201,13 +201,13 @@ namespace edm {
201201
signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadSource);
202202

203203
private:
204-
RootTree(std::shared_ptr<InputFile> filePtr,
205-
BranchType const& branchType,
206-
unsigned int nIndexes,
207-
unsigned int learningEntries,
208-
bool enablePrefetching,
209-
bool promptRead,
210-
InputType inputType);
204+
RootTree(std::shared_ptr<InputFile> filePtr,
205+
BranchType const& branchType,
206+
unsigned int nIndexes,
207+
unsigned int learningEntries,
208+
bool enablePrefetching,
209+
bool promptRead,
210+
InputType inputType);
211211

212212
void setCacheSize(unsigned int cacheSize);
213213
void setTreeMaxVirtualSize(int treeMaxVirtualSize);
@@ -249,6 +249,7 @@ namespace edm {
249249
// effect on the primary treeCache_; all other caches have this explicitly disabled.
250250
bool enablePrefetching_;
251251
bool enableTriggerCache_;
252+
bool promptRead_;
252253
std::unique_ptr<RootDelayedReaderBase> rootDelayedReader_;
253254

254255
TBranch* branchEntryInfoBranch_ = nullptr; //backwards compatibility

0 commit comments

Comments
 (0)