Reads RNTuple data from storage.
The RNTupleReader provides access to data stored in the RNTuple binary format as C++ objects, using an RNTupleModel. It infers this model from the RNTuple's on-disk metadata, or uses a model imposed by the user. The latter case allows users to read into a specialized RNTuple model that covers only a subset of the fields in the RNTuple. The RNTuple model is used when reading complete entries through LoadEntry(). Individual fields can be read as well by instantiating a tree view.
Definition at line 69 of file RNTupleReader.hxx.
Classes | |
| struct | RActiveEntriesControlBlock |
| Shared data structure between the reader and all the issued active entry tokens. More... | |
| class | RActiveEntryToken |
| An active entry token is a pledge for the data of a certain entry number not to be evicted from the page cache or cluster cache. More... | |
| class | RIterator |
Public Member Functions | |
| RNTupleReader (const ROOT::RNTupleReader &)=delete | |
| RNTupleReader (ROOT::RNTupleReader &&)=delete | |
| ~RNTupleReader () | |
| RIterator | begin () |
| std::unique_ptr< RNTupleReader > | Clone () |
| RActiveEntryToken | CreateActiveEntryToken () |
| Create a new active entry token, which will not be bound to any entry number initially. | |
| std::unique_ptr< ROOT::REntry > | CreateEntry () |
| void | EnableMetrics () |
| Enable performance measurements (decompression time, bytes read from storage, etc.) | |
| RIterator | end () |
| ROOT::RNTupleCollectionView | GetCollectionView (ROOT::DescriptorId_t fieldId) |
| Provides access to a collection field from its on-disk ID, that can itself generate new RNTupleViews for its nested fields. | |
| ROOT::RNTupleCollectionView | GetCollectionView (std::string_view fieldName) |
| Provides access to a collection field, that can itself generate new RNTupleViews for its nested fields. | |
| const ROOT::RNTupleDescriptor & | GetDescriptor () |
| Returns a cached copy of the page source descriptor. | |
| template<typename T > | |
| ROOT::RNTupleDirectAccessView< T > | GetDirectAccessView (ROOT::DescriptorId_t fieldId) |
| Provides direct access to the I/O buffers of a mappable (sub)field from its on-disk ID. | |
| template<typename T > | |
| ROOT::RNTupleDirectAccessView< T > | GetDirectAccessView (std::string_view fieldName) |
| Provides direct access to the I/O buffers of a mappable (sub)field. | |
| ROOT::RNTupleGlobalRange | GetEntryRange () |
| Returns an iterator over the entry indices of the RNTuple. | |
| const Experimental::Detail::RNTupleMetrics & | GetMetrics () const |
| const ROOT::RNTupleModel & | GetModel () |
| ROOT::NTupleSize_t | GetNEntries () const |
| Returns the number of entries in this RNTuple. | |
| template<typename T > | |
| ROOT::RNTupleView< T > | GetView (ROOT::DescriptorId_t fieldId) |
| Provides access to an individual (sub)field from its on-disk ID. | |
| template<typename T > | |
| ROOT::RNTupleView< T > | GetView (ROOT::DescriptorId_t fieldId, std::shared_ptr< T > objPtr) |
Provides access to an individual (sub)field from its on-disk ID, reading its values into objPtr. | |
| template<typename T > | |
| ROOT::RNTupleView< T > | GetView (ROOT::DescriptorId_t fieldId, T *rawPtr) |
Provides access to an individual (sub)field from its on-disk ID, reading its values into rawPtr. | |
| ROOT::RNTupleView< void > | GetView (ROOT::DescriptorId_t fieldId, void *rawPtr, const std::type_info &ti) |
Provides access to an individual (sub)field from its on-disk ID, reading its values into objPtr as the type provided by ti. | |
| ROOT::RNTupleView< void > | GetView (ROOT::DescriptorId_t fieldId, void *rawPtr, std::string_view typeName) |
Provides access to an individual (sub)field from its on-disk ID, reading its values into rawPtr as the type provided by typeName. | |
| template<typename T > | |
| ROOT::RNTupleView< T > | GetView (std::string_view fieldName) |
| Provides access to an individual (sub)field, e.g. | |
| template<typename T > | |
| ROOT::RNTupleView< T > | GetView (std::string_view fieldName, std::shared_ptr< T > objPtr) |
Provides access to an individual (sub)field, reading its values into objPtr. | |
| template<typename T > | |
| ROOT::RNTupleView< T > | GetView (std::string_view fieldName, T *rawPtr) |
Provides access to an individual (sub)field, reading its values into rawPtr. | |
| ROOT::RNTupleView< void > | GetView (std::string_view fieldName, void *rawPtr, const std::type_info &ti) |
Provides access to an individual (sub)field, reading its values into rawPtr as the type provided by ti. | |
| ROOT::RNTupleView< void > | GetView (std::string_view fieldName, void *rawPtr, std::string_view typeName) |
Provides access to an individual (sub)field, reading its values into rawPtr as the type provided by typeName. | |
| void | LoadEntry (ROOT::NTupleSize_t index) |
| Fills the default entry of the model. | |
| void | LoadEntry (ROOT::NTupleSize_t index, ROOT::REntry &entry) |
| Fills a user provided entry after checking that the entry has been instantiated from the RNTuple model. | |
| std::unique_ptr< RNTupleAttrSetReader > | OpenAttributeSet (std::string_view attrSetName, const ROOT::RNTupleReadOptions &options={}) |
| Looks for an attribute set with the given name and creates an RNTupleAttrSetReader for it, with the provided read options. | |
| RNTupleReader & | operator= (const ROOT::RNTupleReader &)=delete |
| RNTupleReader & | operator= (ROOT::RNTupleReader &&)=delete |
| void | PrintInfo (const ENTupleInfo what=ENTupleInfo::kSummary, std::ostream &output=std::cout) const |
| Prints a detailed summary of the RNTuple, including a list of fields. | |
| void | Show (ROOT::NTupleSize_t index, std::ostream &output=std::cout) |
| Shows the values of the i-th entry/row, starting with 0 for the first entry. | |
Static Public Member Functions | |
| static std::unique_ptr< RNTupleReader > | Open (const RNTuple &ntuple, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions()) |
| static std::unique_ptr< RNTupleReader > | Open (const ROOT::RNTupleDescriptor::RCreateModelOptions &createModelOpts, const RNTuple &ntuple, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions()) |
| static std::unique_ptr< RNTupleReader > | Open (const ROOT::RNTupleDescriptor::RCreateModelOptions &createModelOpts, std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions()) |
| The caller imposes the way the model is reconstructed. | |
| static std::unique_ptr< RNTupleReader > | Open (std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions()) |
| Open an RNTuple for reading. | |
| static std::unique_ptr< RNTupleReader > | Open (std::unique_ptr< ROOT::RNTupleModel > model, const RNTuple &ntuple, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions()) |
| static std::unique_ptr< RNTupleReader > | Open (std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions()) |
| The caller imposes a model, which must be compatible with the model found in the data on storage. | |
Private Member Functions | |
| RNTupleReader (std::unique_ptr< Internal::RPageSource > source, const ROOT::RNTupleReadOptions &options) | |
| The model is generated from the RNTuple metadata on storage. | |
| RNTupleReader (std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< Internal::RPageSource > source, const ROOT::RNTupleReadOptions &options) | |
| void | ConnectModel (ROOT::RNTupleModel &model, bool allowFieldSubstitutions) |
| RNTupleReader * | GetDisplayReader () |
| void | InitPageSource (bool enableMetrics) |
| ROOT::DescriptorId_t | RetrieveFieldId (std::string_view fieldName) const |
Private Attributes | |
| std::shared_ptr< RActiveEntriesControlBlock > | fActiveEntriesControlBlock |
| Initialized when the page source is connected. | |
| std::optional< ROOT::RNTupleDescriptor > | fCachedDescriptor |
| The RNTuple descriptor in the page source is protected by a read-write lock. | |
| std::optional< ROOT::RNTupleDescriptor::RCreateModelOptions > | fCreateModelOptions |
| If not nullopt, these will be used when creating the model. | |
| std::unique_ptr< RNTupleReader > | fDisplayReader |
| We use a dedicated on-demand reader for Show(). | |
| Experimental::Detail::RNTupleMetrics | fMetrics |
| std::unique_ptr< ROOT::RNTupleModel > | fModel |
| Needs to be destructed before fSource. | |
| ROOT::NTupleSize_t | fNEntries = 0 |
| We know that the RNTupleReader is always reading a single RNTuple, so the number of entries is fixed. | |
| std::unique_ptr< Internal::RPageSource > | fSource |
| std::shared_ptr< Internal::RStringPool > | fStringPool |
| The shared string storage used for all views. | |
| std::unique_ptr< Internal::RNTupleTaskScheduler > | fUnzipTasks |
| Set as the page source's scheduler for parallel page decompression if implicit multi-threading (IMT) is on. | |
#include <ROOT/RNTupleReader.hxx>
|
private |
Definition at line 154 of file RNTupleReader.cxx.
|
explicitprivate |
The model is generated from the RNTuple metadata on storage.
Definition at line 169 of file RNTupleReader.cxx.
|
delete |
|
delete |
| ROOT::RNTupleReader::~RNTupleReader | ( | ) |
Definition at line 179 of file RNTupleReader.cxx.
|
inline |
Definition at line 518 of file RNTupleReader.hxx.
|
inline |
Definition at line 225 of file RNTupleReader.hxx.
|
private |
Definition at line 117 of file RNTupleReader.cxx.
|
inline |
Create a new active entry token, which will not be bound to any entry number initially.
In order to bind the new token, its SetEntryNumber() must be called subsequently.
Definition at line 310 of file RNTupleReader.hxx.
| std::unique_ptr< ROOT::REntry > ROOT::RNTupleReader::CreateEntry | ( | ) |
Definition at line 247 of file RNTupleReader.cxx.
|
inline |
Enable performance measurements (decompression time, bytes read from storage, etc.)
Example: inspect the reader metrics after loading every entry
Definition at line 537 of file RNTupleReader.hxx.
|
inline |
Definition at line 519 of file RNTupleReader.hxx.
|
inline |
Provides access to a collection field from its on-disk ID, that can itself generate new RNTupleViews for its nested fields.
Definition at line 512 of file RNTupleReader.hxx.
|
inline |
Provides access to a collection field, that can itself generate new RNTupleViews for its nested fields.
Raises an exception if:
Definition at line 498 of file RNTupleReader.hxx.
| const ROOT::RNTupleDescriptor & ROOT::RNTupleReader::GetDescriptor | ( | ) |
Returns a cached copy of the page source descriptor.
The returned pointer remains valid until the next call to LoadEntry() or to any of the views returned from the reader.
Definition at line 337 of file RNTupleReader.cxx.
|
inline |
Provides direct access to the I/O buffers of a mappable (sub)field from its on-disk ID.
Definition at line 483 of file RNTupleReader.hxx.
|
inline |
Provides direct access to the I/O buffers of a mappable (sub)field.
Raises an exception if there is no field with the given name. Attempting to access the values of a direct-access view for non-mappable fields will yield compilation errors.
Definition at line 474 of file RNTupleReader.hxx.
|
private |
Definition at line 301 of file RNTupleReader.cxx.
|
inline |
Returns an iterator over the entry indices of the RNTuple.
Example: iterate over all entries and print each entry in JSON format
Definition at line 324 of file RNTupleReader.hxx.
|
inline |
Definition at line 538 of file RNTupleReader.hxx.
| const ROOT::RNTupleModel & ROOT::RNTupleReader::GetModel | ( | ) |
Definition at line 236 of file RNTupleReader.cxx.
|
inline |
Returns the number of entries in this RNTuple.
Note that the recommended way to iterate the RNTuple is using
instead of
The reason is that determining the number of entries, while currently cheap, may in the future be an expensive operation.
Definition at line 251 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field from its on-disk ID.
Definition at line 414 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field from its on-disk ID, reading its values into objPtr.
Definition at line 426 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field from its on-disk ID, reading its values into rawPtr.
Definition at line 438 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field from its on-disk ID, reading its values into objPtr as the type provided by ti.
Definition at line 462 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field from its on-disk ID, reading its values into rawPtr as the type provided by typeName.
Definition at line 450 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field, e.g.
GetView<Particle>("particle"), GetView<double>("particle.pt") or GetView<std::vector<Particle>>("particles"). It is possible to directly get the size of a collection (without reading the collection itself) using RNTupleCardinality: GetView<ROOT::RNTupleCardinality<std::uint64_t>>("particles").
Raises an exception if there is no field with the given name.
Example: iterate over a field named "pt" of type float
Note: if T = void, type checks are disabled. This is not really useful for this overload because RNTupleView<void> does not give access to the pointer. If required, it is possible to provide an objPtr of a dynamic type, for example via GetView(std::string_view, void *, std::string_view).
Definition at line 351 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field, reading its values into objPtr.
Raises an exception if there is no field with the given name.
Example: iterate over a field named "pt" of type float
Note: if T = void, type checks are disabled. It is the caller's responsibility to match the field and object types. It is strongly recommended to use an overload that allows passing the typeName, such as GetView(std::string_view, void *, std::string_view). This allows type checks with the on-disk metadata and enables automatic schema evolution and conversion rules.
Definition at line 380 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field, reading its values into rawPtr.
Definition at line 389 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field, reading its values into rawPtr as the type provided by ti.
Definition at line 405 of file RNTupleReader.hxx.
|
inline |
Provides access to an individual (sub)field, reading its values into rawPtr as the type provided by typeName.
Definition at line 397 of file RNTupleReader.hxx.
|
private |
Definition at line 137 of file RNTupleReader.cxx.
|
inline |
Fills the default entry of the model.
Raises an exception when index is greater than the number of entries present in the RNTuple
Definition at line 290 of file RNTupleReader.hxx.
|
inline |
Fills a user provided entry after checking that the entry has been instantiated from the RNTuple model.
Definition at line 300 of file RNTupleReader.hxx.
|
static |
Definition at line 201 of file RNTupleReader.cxx.
|
static |
Definition at line 227 of file RNTupleReader.cxx.
|
static |
The caller imposes the way the model is reconstructed.
Definition at line 216 of file RNTupleReader.cxx.
|
static |
Open an RNTuple for reading.
Throws an RException if there is no RNTuple with the given name.
Example: open an RNTuple and print the number of entries
Definition at line 193 of file RNTupleReader.cxx.
|
static |
Definition at line 207 of file RNTupleReader.cxx.
|
static |
The caller imposes a model, which must be compatible with the model found in the data on storage.
Definition at line 185 of file RNTupleReader.cxx.
| std::unique_ptr< ROOT::RNTupleAttrSetReader > ROOT::RNTupleReader::OpenAttributeSet | ( | std::string_view | attrSetName, |
| const ROOT::RNTupleReadOptions & | options = {} ) |
Looks for an attribute set with the given name and creates an RNTupleAttrSetReader for it, with the provided read options.
The returned reader has an independent lifetime from this RNTupleReader.
Definition at line 356 of file RNTupleReader.cxx.
|
delete |
|
delete |
| void ROOT::RNTupleReader::PrintInfo | ( | const ENTupleInfo | what = ENTupleInfo::kSummary, |
| std::ostream & | output = std::cout ) const |
Prints a detailed summary of the RNTuple, including a list of fields.
Example: print summary information to stdout
Example: print detailed column storage data to stderr
For use of ENTupleInfo::kMetrics, see EnableMetrics.
Definition at line 252 of file RNTupleReader.cxx.
|
private |
Definition at line 345 of file RNTupleReader.cxx.
| void ROOT::RNTupleReader::Show | ( | ROOT::NTupleSize_t | index, |
| std::ostream & | output = std::cout ) |
Shows the values of the i-th entry/row, starting with 0 for the first entry.
By default, prints the output in JSON format. Uses the visitor pattern to traverse through each field of the given entry.
Definition at line 315 of file RNTupleReader.cxx.
|
private |
Initialized when the page source is connected.
It is then shared between the reader instance and all active entry tokens. When the reader destructs, it resets the page source pointer in the control block.
Definition at line 109 of file RNTupleReader.hxx.
|
private |
The RNTuple descriptor in the page source is protected by a read-write lock.
We don't expose that to the users of RNTupleReader::GetDescriptor(). Instead, if descriptor information is needed, we clone the descriptor. Using the descriptor's generation number, we know if the cached descriptor is stale. Retrieving descriptor data from an RNTupleReader is supposed to be for testing and information purposes, not on a hot code path.
Definition at line 101 of file RNTupleReader.hxx.
|
private |
If not nullopt, these will be used when creating the model.
Definition at line 106 of file RNTupleReader.hxx.
|
private |
We use a dedicated on-demand reader for Show().
Printing data uses all the fields from the full model even if the analysis code uses only a subset of fields. The display reader is a clone of the original reader.
Definition at line 95 of file RNTupleReader.hxx.
|
private |
Definition at line 104 of file RNTupleReader.hxx.
|
private |
Needs to be destructed before fSource.
Definition at line 89 of file RNTupleReader.hxx.
|
private |
We know that the RNTupleReader is always reading a single RNTuple, so the number of entries is fixed.
Definition at line 103 of file RNTupleReader.hxx.
|
private |
Definition at line 87 of file RNTupleReader.hxx.
|
private |
The shared string storage used for all views.
Definition at line 91 of file RNTupleReader.hxx.
|
private |
Set as the page source's scheduler for parallel page decompression if implicit multi-threading (IMT) is on.
Needs to be destructed after the page source is destructed (and thus be declared before)
Definition at line 85 of file RNTupleReader.hxx.