Skip to content

Commit 2553a20

Browse files
committed
Better configuration of RNTupleTemp*
- made TTree only parameters optional - added RNTuple specific options
1 parent 4ca6c13 commit 2553a20

15 files changed

+204
-157
lines changed

FWIO/RNTupleTempInput/src/EmbeddedRNTupleTempSource.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ namespace edm {
1414
class EventPrincipal;
1515
} // namespace edm
1616
namespace edm::rntuple_temp {
17+
namespace {
18+
EmbeddedRNTupleTempSource::Optimizations fromConfig(edm::ParameterSet const& iConfig) {
19+
EmbeddedRNTupleTempSource::Optimizations opts;
20+
opts.useClusterCache = iConfig.getUntrackedParameter<bool>("useClusterCache");
21+
return opts;
22+
}
23+
24+
} // namespace
1725

1826
EmbeddedRNTupleTempSource::EmbeddedRNTupleTempSource(ParameterSet const& pset,
1927
VectorInputSourceDescription const& desc)
@@ -30,7 +38,8 @@ namespace edm::rntuple_temp {
3038
//
3139
skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles", false)),
3240
bypassVersionCheck_(pset.getUntrackedParameter<bool>("bypassVersionCheck", false)),
33-
treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize", -1)),
41+
treeMaxVirtualSize_(0),
42+
optimizations_(fromConfig(pset.getUntrackedParameterSet("rntupleReadOptions"))),
3443
productSelectorRules_(pset, "inputCommands", "InputSource"),
3544
runHelper_(new DefaultInputSourceRunHelper()),
3645
catalog_(pset.getUntrackedParameter<std::vector<std::string> >("fileNames"),
@@ -91,8 +100,13 @@ namespace edm::rntuple_temp {
91100
->setComment(
92101
"True: Bypass release version check.\n"
93102
"False: Throw exception if reading file in a release prior to the release in which the file was written.");
94-
desc.addUntracked<int>("treeMaxVirtualSize", -1)
95-
->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
103+
desc.addUntracked<int>("treeMaxVirtualSize", -1)->setComment("Not used by RNTuple.");
104+
{
105+
ParameterSetDescription rntupleReadOptions;
106+
rntupleReadOptions.addUntracked<bool>("useClusterCache", true)
107+
->setComment("True: use ROOT cluster cache. False: do not use cluster cache.");
108+
desc.addUntracked("rntupleReadOptions", rntupleReadOptions);
109+
}
96110

97111
ProductSelectorRules::fillDescription(desc, "inputCommands");
98112
RootEmbeddedFileSequence::fillDescription(desc);

FWIO/RNTupleTempInput/src/EmbeddedRNTupleTempSource.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ namespace edm::rntuple_temp {
3535

3636
class EmbeddedRNTupleTempSource : public VectorInputSource {
3737
public:
38+
struct Optimizations {
39+
bool useClusterCache = true;
40+
};
41+
3842
explicit EmbeddedRNTupleTempSource(ParameterSet const& pset, VectorInputSourceDescription const& desc);
3943
~EmbeddedRNTupleTempSource() override;
4044
using VectorInputSource::processHistoryRegistryForUpdate;
@@ -45,6 +49,7 @@ namespace edm::rntuple_temp {
4549
bool bypassVersionCheck() const { return bypassVersionCheck_; }
4650
unsigned int nStreams() const { return nStreams_; }
4751
int treeMaxVirtualSize() const { return treeMaxVirtualSize_; }
52+
Optimizations const& optimizations() const { return optimizations_; }
4853
ProductSelectorRules const& productSelectorRules() const { return productSelectorRules_; }
4954
InputSourceRunHelperBase* runHelper() { return runHelper_.get(); }
5055

@@ -68,6 +73,7 @@ namespace edm::rntuple_temp {
6873
bool skipBadFiles_;
6974
bool bypassVersionCheck_;
7075
int const treeMaxVirtualSize_;
76+
Optimizations optimizations_;
7177
ProductSelectorRules productSelectorRules_;
7278
std::unique_ptr<InputSourceRunHelperBase> runHelper_;
7379

FWIO/RNTupleTempInput/src/RNTupleTempSource.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ namespace edm::rntuple_temp {
6262
<< primary.id() << " has inconsistent RunAuxiliary data in the primary and secondary file\n";
6363
}
6464
}
65+
RNTupleTempSource::Optimizations fromConfig(edm::ParameterSet const& iConfig) {
66+
RNTupleTempSource::Optimizations opts;
67+
opts.useClusterCache = iConfig.getUntrackedParameter<bool>("useClusterCache");
68+
return opts;
69+
}
6570
} // namespace
6671

6772
RNTupleTempSource::RNTupleTempSource(ParameterSet const& pset, InputSourceDescription const& desc)
@@ -79,7 +84,8 @@ namespace edm::rntuple_temp {
7984
nStreams_(desc.allocations_->numberOfStreams()),
8085
skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles")),
8186
bypassVersionCheck_(pset.getUntrackedParameter<bool>("bypassVersionCheck")),
82-
treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize")),
87+
treeMaxVirtualSize_(0),
88+
optimizations_(fromConfig(pset.getUntrackedParameterSet("rntupleReadOptions"))),
8389
productSelectorRules_(pset, "inputCommands", "InputSource"),
8490
dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches")),
8591
labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC")),
@@ -301,7 +307,7 @@ namespace edm::rntuple_temp {
301307
ParameterSetDescription desc;
302308

303309
std::vector<std::string> defaultStrings;
304-
desc.setComment("Reads EDM/Root files.");
310+
desc.setComment("Reads EDM/RNTuple Root files.");
305311
desc.addUntracked<std::vector<std::string> >("fileNames")->setComment("Names of files to be processed.");
306312
desc.addUntracked<std::vector<std::string> >("secondaryFileNames", defaultStrings)
307313
->setComment("Names of secondary files to be processed.");
@@ -316,8 +322,13 @@ namespace edm::rntuple_temp {
316322
->setComment(
317323
"True: Bypass release version check.\n"
318324
"False: Throw exception if reading file in a release prior to the release in which the file was written.");
319-
desc.addUntracked<int>("treeMaxVirtualSize", -1)
320-
->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
325+
desc.addOptionalUntracked<int>("treeMaxVirtualSize", -1)->setComment("Not used by RNTuple.");
326+
{
327+
ParameterSetDescription rntupleReadOptions;
328+
rntupleReadOptions.addUntracked<bool>("useClusterCache", true)
329+
->setComment("True: use ROOT cluster cache. False: do not use cluster cache.");
330+
desc.addUntracked("rntupleReadOptions", rntupleReadOptions);
331+
}
321332
desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
322333
->setComment("If True, also drop on input any descendent of any branch dropped on input.");
323334
desc.addUntracked<bool>("labelRawDataLikeMC", true)

FWIO/RNTupleTempInput/src/RNTupleTempSource.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ namespace edm::rntuple_temp {
3232

3333
class RNTupleTempSource : public InputSource {
3434
public:
35+
struct Optimizations {
36+
bool useClusterCache = true;
37+
};
3538
explicit RNTupleTempSource(ParameterSet const& pset, InputSourceDescription const& desc);
3639
~RNTupleTempSource() override;
3740
using InputSource::processHistoryRegistryForUpdate;
@@ -45,6 +48,7 @@ namespace edm::rntuple_temp {
4548
bool delayReadingEventProducts() const { return delayReadingEventProducts_; }
4649
unsigned int nStreams() const { return nStreams_; }
4750
int treeMaxVirtualSize() const { return treeMaxVirtualSize_; }
51+
Optimizations const& optimizations() const { return optimizations_; }
4852
ProductSelectorRules const& productSelectorRules() const { return productSelectorRules_; }
4953
InputSourceRunHelperBase* runHelper() { return runHelper_.get(); }
5054

@@ -87,6 +91,7 @@ namespace edm::rntuple_temp {
8791
bool skipBadFiles_;
8892
bool bypassVersionCheck_;
8993
int const treeMaxVirtualSize_;
94+
Optimizations optimizations_;
9095
ProductSelectorRules productSelectorRules_;
9196
bool dropDescendants_;
9297
bool labelRawDataLikeMC_;

FWIO/RNTupleTempInput/src/RootEmbeddedFileSequence.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ namespace edm::rntuple_temp {
144144
.enforceGUIDInFileName = enforceGUIDInFileName_},
145145
InputType::SecondarySource,
146146
RootFile::ProcessingOptions{},
147-
RootFile::TTreeOptions{.treeCacheSize = treeCacheSize_,
148-
.treeMaxVirtualSize = input_.treeMaxVirtualSize(),
149-
.enablePrefetching = enablePrefetching_},
147+
RootFile::TTreeOptions{.useClusterCache = input_.optimizations().useClusterCache},
150148
RootFile::ProductChoices{.productSelectorRules = input_.productSelectorRules()},
151149
RootFile::CrossFileInfo{.runHelper = input_.runHelper(),
152150
.indexesIntoFiles = indexesIntoFiles(),
@@ -379,8 +377,7 @@ namespace edm::rntuple_temp {
379377
->setComment(
380378
"How many files to try if 'sequential' is False and 'skipBadFiles' is True.\n"
381379
"Defaults to 3 (or # of files if smaller).");
382-
desc.addUntracked<unsigned int>("cacheSize", rootrntuple::defaultCacheSize)
383-
->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
380+
desc.addOptionalUntracked<unsigned int>("cacheSize", 0)->setComment("Not used by RNTuple.");
384381
desc.addUntracked<bool>("enforceGUIDInFileName", false)
385382
->setComment(
386383
"True: file name part is required to be equal to the GUID of the file\n"

FWIO/RNTupleTempInput/src/RootFile.cc

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,9 @@ namespace edm::rntuple_temp {
169169
hasNewlyDroppedBranch_(),
170170
branchListIndexesUnchanged_(false),
171171
eventAuxCache_(),
172-
eventTree_(
173-
fileOptions.filePtr, InEvent, nStreams, ttreeOptions, rootrntuple::defaultLearningEntries, inputType),
174-
lumiTree_(fileOptions.filePtr,
175-
InLumi,
176-
1,
177-
ttreeOptions.usingDefaultNonEventOptions(),
178-
rootrntuple::defaultNonEventLearningEntries,
179-
inputType),
180-
runTree_(fileOptions.filePtr,
181-
InRun,
182-
1,
183-
ttreeOptions.usingDefaultNonEventOptions(),
184-
rootrntuple::defaultNonEventLearningEntries,
185-
inputType),
172+
eventTree_(fileOptions.filePtr, InEvent, nStreams, ttreeOptions, inputType),
173+
lumiTree_(fileOptions.filePtr, InLumi, 1, ttreeOptions.usingDefaultNonEventOptions(), inputType),
174+
runTree_(fileOptions.filePtr, InRun, 1, ttreeOptions.usingDefaultNonEventOptions(), inputType),
186175
treePointers_(),
187176
lastEventEntryNumberRead_(IndexIntoFile::invalidEntry),
188177
productRegistry_(),
@@ -1895,13 +1884,8 @@ namespace edm::rntuple_temp {
18951884
// the ProcessBlock TTree's in the file. (later in the RootFile constructor, dropOnInput might
18961885
// remove some and also reordering may occur).
18971886
for (auto const& process : storedProcessBlockHelper.processesWithProcessBlockProducts()) {
1898-
processBlockTrees_.emplace_back(std::make_unique<RootRNTuple>(filePtr,
1899-
InProcess,
1900-
process,
1901-
1,
1902-
options.usingDefaultNonEventOptions(),
1903-
rootrntuple::defaultNonEventLearningEntries,
1904-
inputType));
1887+
processBlockTrees_.emplace_back(std::make_unique<RootRNTuple>(
1888+
filePtr, InProcess, process, 1, options.usingDefaultNonEventOptions(), inputType));
19051889
}
19061890
}
19071891

FWIO/RNTupleTempInput/src/RootPrimaryFileSequence.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace edm::rntuple_temp {
3232
initialNumberOfEventsToSkip_(pset.getUntrackedParameter<unsigned int>("skipEvents")),
3333
noRunLumiSort_(pset.getUntrackedParameter<bool>("noRunLumiSort")),
3434
noEventSort_(noRunLumiSort_ ? true : pset.getUntrackedParameter<bool>("noEventSort")),
35-
treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize") : 0U),
35+
treeCacheSize_(0U),
3636
duplicateChecker_(new DuplicateChecker(pset)),
3737
usingGoToEvent_(false),
3838
enablePrefetching_(false),
@@ -161,9 +161,7 @@ namespace edm::rntuple_temp {
161161
.noRunLumiSort = noRunLumiSort_,
162162
.noEventSort = noEventSort_,
163163
.usingGoToEvent = usingGoToEvent_},
164-
RootFile::TTreeOptions{.treeCacheSize = treeCacheSize_,
165-
.treeMaxVirtualSize = input_.treeMaxVirtualSize(),
166-
.enablePrefetching = enablePrefetching_,
164+
RootFile::TTreeOptions{.useClusterCache = input_.optimizations().useClusterCache,
167165
.promptReading = not input_.delayReadingEventProducts()},
168166
RootFile::ProductChoices{.productSelectorRules = input_.productSelectorRules(),
169167
.associationsFromSecondary = nullptr, // associationsFromSecondary
@@ -427,8 +425,7 @@ namespace edm::rntuple_temp {
427425
->setComment(
428426
"True: Process runs, lumis and events in the order they appear in the file.\n"
429427
"False: Follow settings based on 'noEventSort' setting.");
430-
desc.addUntracked<unsigned int>("cacheSize", rootrntuple::defaultCacheSize)
431-
->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
428+
desc.addOptionalUntracked<unsigned int>("cacheSize", 0)->setComment("Not used by RNTuple");
432429
std::string defaultString("permissive");
433430
desc.addUntracked<std::string>("branchesMustMatch", defaultString)
434431
->setComment(

FWIO/RNTupleTempInput/src/RootRNTuple.cc

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ namespace edm::rntuple_temp {
3535
RootRNTuple::RootRNTuple(std::shared_ptr<InputFile> filePtr,
3636
BranchType const& branchType,
3737
unsigned int nIndexes,
38-
unsigned int learningEntries,
39-
bool enablePrefetching,
4038
bool promptRead,
4139
InputType inputType)
4240
: filePtr_(filePtr),
4341
branchType_(branchType),
4442
entryNumberForIndex_(std::make_unique<std::vector<EntryNumber>>(nIndexes, IndexIntoFile::invalidEntry)),
45-
enablePrefetching_(enablePrefetching),
4643
promptRead_(promptRead),
4744
rootDelayedReader_(makeRootDelayedReader(*this, filePtr, inputType, nIndexes, promptRead)) {}
4845

@@ -51,11 +48,9 @@ namespace edm::rntuple_temp {
5148
BranchType const& branchType,
5249
unsigned int nIndexes,
5350
Options const& options,
54-
unsigned int learningEntries,
5551
InputType inputType)
56-
: RootRNTuple(
57-
filePtr, branchType, nIndexes, learningEntries, options.enablePrefetching, options.promptReading, inputType) {
58-
init(BranchTypeToProductTreeName(branchType), options.treeMaxVirtualSize, options.treeCacheSize);
52+
: RootRNTuple(filePtr, branchType, nIndexes, options.promptReading, inputType) {
53+
init(BranchTypeToProductTreeName(branchType), options);
5954
auxDesc_ = getAuxiliaryFieldId(*reader_, branchType_);
6055
}
6156

@@ -65,19 +60,20 @@ namespace edm::rntuple_temp {
6560
std::string const& processName,
6661
unsigned int nIndexes,
6762
Options const& options,
68-
unsigned int learningEntries,
6963
InputType inputType)
70-
: RootRNTuple(
71-
filePtr, branchType, nIndexes, learningEntries, options.enablePrefetching, options.promptReading, inputType) {
64+
: RootRNTuple(filePtr, branchType, nIndexes, options.promptReading, inputType) {
7265
processName_ = processName;
73-
init(BranchTypeToProductTreeName(branchType, processName), options.treeMaxVirtualSize, options.treeCacheSize);
66+
init(BranchTypeToProductTreeName(branchType, processName), options);
7467
}
7568

76-
void RootRNTuple::init(std::string const& productTreeName, unsigned int maxVirtualSize, unsigned int cacheSize) {
69+
void RootRNTuple::init(std::string const& productTreeName, Options const& options) {
7770
if (filePtr_.get() != nullptr) {
7871
auto tuple = filePtr_->Get<ROOT::RNTuple>(productTreeName.c_str());
7972
if (tuple != nullptr) {
80-
reader_ = ROOT::RNTupleReader::Open(*tuple);
73+
ROOT::RNTupleReadOptions rntupleOptions;
74+
rntupleOptions.SetClusterCache(options.useClusterCache ? ROOT::RNTupleReadOptions::EClusterCache::kOn
75+
: ROOT::RNTupleReadOptions::EClusterCache::kOff);
76+
reader_ = ROOT::RNTupleReader::Open(*tuple, rntupleOptions);
8177
}
8278
}
8379
if (not reader_) {
@@ -86,9 +82,6 @@ namespace edm::rntuple_temp {
8682
<< "\n This is either not an edm ROOT file or is one that has been corrupted.";
8783
}
8884
entries_ = reader_->GetNEntries();
89-
90-
setTreeMaxVirtualSize(maxVirtualSize);
91-
setCacheSize(cacheSize);
9285
}
9386

9487
RootRNTuple::~RootRNTuple() {}

FWIO/RNTupleTempInput/src/RootRNTuple.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ namespace edm::rntuple_temp {
3636
class RootDelayedReaderBase;
3737

3838
namespace rootrntuple {
39-
unsigned int const defaultCacheSize = 20U * 1024 * 1024;
40-
unsigned int const defaultNonEventCacheSize = 1U * 1024 * 1024;
41-
unsigned int const defaultLearningEntries = 20U;
42-
unsigned int const defaultNonEventLearningEntries = 1U;
4339
using EntryNumber = IndexIntoFile::EntryNumber_t;
4440
struct ProductInfo {
4541
ProductInfo(ProductDescription const& prod) : productDescription_(prod) {}
@@ -94,33 +90,25 @@ namespace edm::rntuple_temp {
9490
using ProductMap = rootrntuple::ProductMap;
9591
using EntryNumber = rootrntuple::EntryNumber;
9692
struct Options {
97-
unsigned int treeCacheSize = 0U;
98-
int treeMaxVirtualSize;
99-
bool enablePrefetching;
93+
bool useClusterCache = true;
10094
bool promptReading = false;
10195

102-
Options usingDefaultNonEventOptions() const {
103-
return {rootrntuple::defaultNonEventCacheSize, treeMaxVirtualSize, enablePrefetching, false};
104-
}
96+
Options usingDefaultNonEventOptions() const { return {}; }
10597
};
10698

10799
RootRNTuple(std::shared_ptr<InputFile> filePtr,
108100
BranchType const& branchType,
109101
unsigned int nIndexes,
110102
Options const& options,
111-
unsigned int learningEntries,
112103
InputType inputType);
113104

114105
RootRNTuple(std::shared_ptr<InputFile> filePtr,
115106
BranchType const& branchType,
116107
std::string const& processName,
117108
unsigned int nIndexes,
118109
Options const& options,
119-
unsigned int learningEntries,
120110
InputType inputType);
121111

122-
void init(std::string const& productTreeName, unsigned int maxVirtualSize, unsigned int cacheSize);
123-
124112
~RootRNTuple();
125113

126114
RootRNTuple(RootRNTuple const&) = delete; // Disallow copying and moving
@@ -185,11 +173,11 @@ namespace edm::rntuple_temp {
185173
signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadSource);
186174

187175
private:
176+
void init(std::string const& productTreeName, Options const& options);
177+
188178
RootRNTuple(std::shared_ptr<InputFile> filePtr,
189179
BranchType const& branchType,
190180
unsigned int nIndexes,
191-
unsigned int learningEntries,
192-
bool enablePrefetching,
193181
bool promptRead,
194182
InputType inputType);
195183

@@ -211,7 +199,6 @@ namespace edm::rntuple_temp {
211199
ProductMap branches_;
212200
unsigned int cacheSize_ = 0;
213201
unsigned long treeAutoFlush_ = 0;
214-
bool enablePrefetching_;
215202
bool promptRead_;
216203
std::unique_ptr<RootDelayedReaderBase> rootDelayedReader_;
217204
};

FWIO/RNTupleTempInput/src/RootSecondaryFileSequence.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ namespace edm::rntuple_temp {
8282
RootFile::ProcessingOptions{
8383
.processingMode = input_.processingMode(),
8484
},
85-
RootFile::TTreeOptions{.treeMaxVirtualSize = input_.treeMaxVirtualSize(),
86-
.enablePrefetching = enablePrefetching_,
85+
RootFile::TTreeOptions{.useClusterCache = input_.optimizations().useClusterCache,
8786
.promptReading = not input_.delayReadingEventProducts()},
8887
RootFile::ProductChoices{.productSelectorRules = input_.productSelectorRules(),
8988
.associationsFromSecondary = &associationsFromSecondary_,

0 commit comments

Comments
 (0)