Skip to content

Commit 78ec66c

Browse files
committed
[ntuple] allow creating an AttrSetReader from RNTupleReader
1 parent 5b67016 commit 78ec66c

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

tree/ntuple/inc/ROOT/RNTupleReader.hxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ public:
527527
/// ~~~
528528
void EnableMetrics() { fMetrics.Enable(); }
529529
const Experimental::Detail::RNTupleMetrics &GetMetrics() const { return fMetrics; }
530+
531+
/// Looks for an attribute set with the given name and creates an RNTupleAttrSetReader for it, with the provided
532+
/// read options.
533+
/// The returned reader has an independent lifetime from this RNTupleReader.
534+
std::unique_ptr<Experimental::RNTupleAttrSetReader>
535+
OpenAttributeSet(std::string_view attrSetName, const ROOT::RNTupleReadOptions &options = {});
530536
}; // class RNTupleReader
531537

532538
} // namespace ROOT

tree/ntuple/src/RNTupleReader.cxx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <ROOT/RField.hxx>
1717
#include <ROOT/RFieldVisitor.hxx>
18+
#include <ROOT/RNTupleAttrReading.hxx>
1819
#include <ROOT/RNTupleImtTaskScheduler.hxx>
1920
#include <ROOT/RNTuple.hxx>
2021
#include <ROOT/RNTupleModel.hxx>
@@ -366,3 +367,20 @@ ROOT::DescriptorId_t ROOT::RNTupleReader::RetrieveFieldId(std::string_view field
366367
}
367368
return fieldId;
368369
}
370+
371+
std::unique_ptr<ROOT::Experimental::RNTupleAttrSetReader>
372+
ROOT::RNTupleReader::OpenAttributeSet(std::string_view attrSetName, const ROOT::RNTupleReadOptions &readOpts)
373+
{
374+
auto attrSets = GetDescriptor().GetAttrSetIterable();
375+
const auto it =
376+
std::find_if(attrSets.begin(), attrSets.end(), [&](const auto &d) { return d.GetName() == attrSetName; });
377+
if (it == attrSets.end())
378+
throw ROOT::RException(R__FAIL(std::string("No such attribute set: ") + std::string(attrSetName)));
379+
380+
auto attrSource = fSource->OpenWithDifferentAnchor({it->GetAnchorLocator(), it->GetAnchorLength()}, readOpts);
381+
auto newReader = std::unique_ptr<RNTupleReader>(new RNTupleReader(std::move(attrSource), readOpts));
382+
R__ASSERT(newReader);
383+
auto attrSetReader = std::unique_ptr<ROOT::Experimental::RNTupleAttrSetReader>(
384+
new ROOT::Experimental::RNTupleAttrSetReader(std::move(newReader), it->GetSchemaVersionMajor()));
385+
return attrSetReader;
386+
}

0 commit comments

Comments
 (0)