Skip to content

Commit

Permalink
[ntuple] allow passing RCreateModelOptions to RNTupleReader::Open
Browse files Browse the repository at this point in the history
  • Loading branch information
silverweed committed Dec 18, 2024
1 parent 1e57428 commit 9cf46f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
14 changes: 13 additions & 1 deletion tree/ntuple/v7/inc/ROOT/RNTupleReader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ private:
/// not on a hot code path.
std::unique_ptr<RNTupleDescriptor> fCachedDescriptor;
Detail::RNTupleMetrics fMetrics;
/// If not nullopt, these will used when creating the model
std::optional<RNTupleDescriptor::RCreateModelOptions> fCreateModelOptions;

RNTupleReader(std::unique_ptr<RNTupleModel> model, std::unique_ptr<Internal::RPageSource> source,
const RNTupleReadOptions &options);
Expand Down Expand Up @@ -153,12 +155,21 @@ public:
const RNTupleReadOptions &options = RNTupleReadOptions());
static std::unique_ptr<RNTupleReader>
Open(const RNTuple &ntuple, const RNTupleReadOptions &options = RNTupleReadOptions());

/// The caller imposes a model, which must be compatible with the model found in the data on storage.
static std::unique_ptr<RNTupleReader> Open(std::unique_ptr<RNTupleModel> model, std::string_view ntupleName,
std::string_view storage,
const RNTupleReadOptions &options = RNTupleReadOptions());
static std::unique_ptr<RNTupleReader> Open(std::unique_ptr<RNTupleModel> model, const RNTuple &ntuple,
const RNTupleReadOptions &options = RNTupleReadOptions());

/// The caller imposes the way the model is reconstructed
static std::unique_ptr<RNTupleReader> Open(const RNTupleDescriptor::RCreateModelOptions &createModelOpts,
std::string_view ntupleName, std::string_view storage,
const RNTupleReadOptions &options = RNTupleReadOptions());
static std::unique_ptr<RNTupleReader> Open(const RNTupleDescriptor::RCreateModelOptions &createModelOpts,
const RNTuple &ntuple,
const RNTupleReadOptions &options = RNTupleReadOptions());
std::unique_ptr<RNTupleReader> Clone()
{
auto options = RNTupleReadOptions{};
Expand Down Expand Up @@ -215,7 +226,8 @@ public:
{
// TODO(jblomer): can be templated depending on the factory method / constructor
if (R__unlikely(!fModel)) {
fModel = fSource->GetSharedDescriptorGuard()->CreateModel();
fModel = fSource->GetSharedDescriptorGuard()->CreateModel(
fCreateModelOptions.value_or(RNTupleDescriptor::RCreateModelOptions{}));
ConnectModel(*fModel);
}
LoadEntry(index, fModel->GetDefaultEntry());
Expand Down
27 changes: 25 additions & 2 deletions tree/ntuple/v7/src/RNTupleReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,32 @@ ROOT::Experimental::RNTupleReader::Open(std::unique_ptr<RNTupleModel> model, con
new RNTupleReader(std::move(model), Internal::RPageSourceFile::CreateFromAnchor(ntuple, options), options));
}

std::unique_ptr<ROOT::Experimental::RNTupleReader>
ROOT::Experimental::RNTupleReader::Open(const RNTupleDescriptor::RCreateModelOptions &createModelOpts,
std::string_view ntupleName, std::string_view storage,
const RNTupleReadOptions &options)
{
auto reader = std::unique_ptr<RNTupleReader>(
new RNTupleReader(Internal::RPageSource::Create(ntupleName, storage, options), options));
reader->fCreateModelOptions = createModelOpts;
return reader;
}

std::unique_ptr<ROOT::Experimental::RNTupleReader>
ROOT::Experimental::RNTupleReader::Open(const RNTupleDescriptor::RCreateModelOptions &createModelOpts,
const ROOT::RNTuple &ntuple, const RNTupleReadOptions &options)
{
auto reader = std::unique_ptr<RNTupleReader>(
new RNTupleReader(Internal::RPageSourceFile::CreateFromAnchor(ntuple, options), options));
reader->fCreateModelOptions = createModelOpts;
return reader;
}

const ROOT::Experimental::RNTupleModel &ROOT::Experimental::RNTupleReader::GetModel()
{
if (!fModel) {
fModel = fSource->GetSharedDescriptorGuard()->CreateModel();
fModel = fSource->GetSharedDescriptorGuard()->CreateModel(
fCreateModelOptions.value_or(RNTupleDescriptor::RCreateModelOptions{}));
ConnectModel(*fModel);
}
return *fModel;
Expand All @@ -140,7 +162,8 @@ void ROOT::Experimental::RNTupleReader::PrintInfo(const ENTupleInfo what, std::o
{
auto descriptorGuard = fSource->GetSharedDescriptorGuard();
name = descriptorGuard->GetName();
fullModel = descriptorGuard->CreateModel();
fullModel =
descriptorGuard->CreateModel(fCreateModelOptions.value_or(RNTupleDescriptor::RCreateModelOptions{}));
}

for (int i = 0; i < (width / 2 + width % 2 - 4); ++i)
Expand Down

0 comments on commit 9cf46f7

Please sign in to comment.