Logo ROOT  
Reference Guide
ROOT::Experimental::RNTupleReader Class Reference

An RNTuple that is used to read data from storage.

An input ntuple provides data from storage as C++ objects. The ntuple model can be created from the data on storage or it can be imposed by the user. The latter case allows users to read into a specialized ntuple model that covers only a subset of the fields in the ntuple. The ntuple model is used when reading complete entries. Individual fields can be read as well by instantiating a tree view.

#include <ROOT/RNTuple.hxx>
#include <iostream>
auto ntuple = RNTupleReader::Open("myNTuple", "some/file.root");
std::cout << "myNTuple has " << ntuple->GetNEntries() << " entries\n";
An RNTuple that is used to read data from storage.
Definition: RNTuple.hxx:102
static std::unique_ptr< RNTupleReader > Open(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const RNTupleReadOptions &options=RNTupleReadOptions())
Throws an exception if the model is null.
Definition: RNTuple.cxx:125

Definition at line 102 of file RNTuple.hxx.

Classes

class  RIterator
 
struct  ROpenSpec
 Used to specify the underlying RNTuples in OpenFriends() More...
 

Public Member Functions

 RNTupleReader (std::unique_ptr< Detail::RPageSource > source)
 The model is generated from the ntuple metadata on storage. More...
 
 RNTupleReader (std::unique_ptr< RNTupleModel > model, std::unique_ptr< Detail::RPageSource > source)
 The user imposes an ntuple model, which must be compatible with the model found in the data on storage. More...
 
 ~RNTupleReader ()
 
RIterator begin ()
 
std::unique_ptr< RNTupleReaderClone ()
 
void EnableMetrics ()
 Enable performance measurements (decompression time, bytes read from storage, etc.) More...
 
RIterator end ()
 
const RNTupleDescriptorGetDescriptor () const
 
RNTupleGlobalRange GetEntryRange ()
 Returns an iterator over the entry indices of the RNTuple. More...
 
const Detail::RNTupleMetricsGetMetrics () const
 
RNTupleModelGetModel ()
 
NTupleSize_t GetNEntries () const
 
template<typename T >
RNTupleView< T > GetView (std::string_view fieldName)
 Provides access to an individual field that can contain either a scalar value or a collection, e.g. More...
 
RNTupleViewCollection GetViewCollection (std::string_view fieldName)
 Raises an exception if: More...
 
void LoadEntry (NTupleSize_t index)
 Analogous to Fill(), fills the default entry of the model. More...
 
void LoadEntry (NTupleSize_t index, REntry &entry)
 Fills a user provided entry after checking that the entry has been instantiated from the ntuple model. More...
 
void PrintInfo (const ENTupleInfo what=ENTupleInfo::kSummary, std::ostream &output=std::cout)
 Prints a detailed summary of the ntuple, including a list of fields. More...
 
void Show (NTupleSize_t index, const ENTupleShowFormat format=ENTupleShowFormat::kCurrentModelJSON, std::ostream &output=std::cout)
 Shows the values of the i-th entry/row, starting with 0 for the first entry. More...
 

Static Public Member Functions

static std::unique_ptr< RNTupleReaderOpen (std::string_view ntupleName, std::string_view storage, const RNTupleReadOptions &options=RNTupleReadOptions())
 Open an RNTuple for reading. More...
 
static std::unique_ptr< RNTupleReaderOpen (std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const RNTupleReadOptions &options=RNTupleReadOptions())
 Throws an exception if the model is null. More...
 
static std::unique_ptr< RNTupleReaderOpenFriends (std::span< ROpenSpec > ntuples)
 Open RNTuples as one virtual, horizontally combined ntuple. More...
 

Private Member Functions

void ConnectModel (const RNTupleModel &model)
 
RNTupleReaderGetDisplayReader ()
 
void InitPageSource ()
 

Private Attributes

std::unique_ptr< RNTupleReaderfDisplayReader
 We use a dedicated on-demand reader for Show() and Scan(). More...
 
Detail::RNTupleMetrics fMetrics
 
std::unique_ptr< RNTupleModelfModel
 Needs to be destructed before fSource. More...
 
std::unique_ptr< Detail::RPageSourcefSource
 
std::unique_ptr< Detail::RPageStorage::RTaskSchedulerfUnzipTasks
 Set as the page source's scheduler for parallel page decompression if IMT is on Needs to be destructed after the pages source is destructed (an thus be declared before) More...
 

#include <ROOT/RNTuple.hxx>

Constructor & Destructor Documentation

◆ RNTupleReader() [1/2]

ROOT::Experimental::RNTupleReader::RNTupleReader ( std::unique_ptr< RNTupleModel model,
std::unique_ptr< Detail::RPageSource source 
)

The user imposes an ntuple model, which must be compatible with the model found in the data on storage.

Throws an exception if the model or the source is null.

Definition at line 95 of file RNTuple.cxx.

◆ RNTupleReader() [2/2]

ROOT::Experimental::RNTupleReader::RNTupleReader ( std::unique_ptr< Detail::RPageSource source)
explicit

The model is generated from the ntuple metadata on storage.

Throws an exception if the source is null.

Definition at line 112 of file RNTuple.cxx.

◆ ~RNTupleReader()

ROOT::Experimental::RNTupleReader::~RNTupleReader ( )
default

Member Function Documentation

◆ begin()

RIterator ROOT::Experimental::RNTupleReader::begin ( )
inline

Definition at line 313 of file RNTuple.hxx.

◆ Clone()

std::unique_ptr< RNTupleReader > ROOT::Experimental::RNTupleReader::Clone ( )
inline

Definition at line 192 of file RNTuple.hxx.

◆ ConnectModel()

void ROOT::Experimental::RNTupleReader::ConnectModel ( const RNTupleModel model)
private

Definition at line 70 of file RNTuple.cxx.

◆ EnableMetrics()

void ROOT::Experimental::RNTupleReader::EnableMetrics ( )
inline

Enable performance measurements (decompression time, bytes read from storage, etc.)

Example: inspect the reader metrics after loading every entry

#include <ROOT/RNTuple.hxx>
#include <iostream>
auto ntuple = RNTupleReader::Open("myNTuple", "some/file.root");
// metrics must be turned on beforehand
ntuple->EnableMetrics();
for (auto i : ntuple->GetEntryRange()) {
ntuple->LoadEntry(i);
}
ntuple->PrintInfo(ENTupleInfo::kMetrics);
ENTupleInfo
Listing of the different options that can be printed by RNTupleReader::GetInfo()
Definition: RNTuple.hxx:51

Definition at line 335 of file RNTuple.hxx.

◆ end()

RIterator ROOT::Experimental::RNTupleReader::end ( )
inline

Definition at line 314 of file RNTuple.hxx.

◆ GetDescriptor()

const RNTupleDescriptor & ROOT::Experimental::RNTupleReader::GetDescriptor ( ) const
inline

Definition at line 197 of file RNTuple.hxx.

◆ GetDisplayReader()

ROOT::Experimental::RNTupleReader * ROOT::Experimental::RNTupleReader::GetDisplayReader ( )
private

Definition at line 221 of file RNTuple.cxx.

◆ GetEntryRange()

RNTupleGlobalRange ROOT::Experimental::RNTupleReader::GetEntryRange ( )
inline

Returns an iterator over the entry indices of the RNTuple.

Example: iterate over all entries and print each entry in JSON format

#include <ROOT/RNTuple.hxx>
#include <iostream>
auto ntuple = RNTupleReader::Open("myNTuple", "some/file.root");
for (auto i : ntuple->GetEntryRange()) {
}
ENTupleShowFormat
Listing of the different entry output formats of RNTupleReader::Show()
Definition: RNTuple.hxx:60

Definition at line 267 of file RNTuple.hxx.

◆ GetMetrics()

const Detail::RNTupleMetrics & ROOT::Experimental::RNTupleReader::GetMetrics ( ) const
inline

Definition at line 336 of file RNTuple.hxx.

◆ GetModel()

ROOT::Experimental::RNTupleModel * ROOT::Experimental::RNTupleReader::GetModel ( )

Definition at line 152 of file RNTuple.cxx.

◆ GetNEntries()

NTupleSize_t ROOT::Experimental::RNTupleReader::GetNEntries ( ) const
inline

Definition at line 196 of file RNTuple.hxx.

◆ GetView()

template<typename T >
RNTupleView< T > ROOT::Experimental::RNTupleReader::GetView ( std::string_view  fieldName)
inline

Provides access to an individual field that can contain either a scalar value or a collection, e.g.

GetView<double>("particles.pt") or GetView<std::vector<double>>("particle"). It can as well be the index field of a collection itself, like GetView<NTupleSize_t>("particle").

Raises an exception if there is no field with the given name.

Example: iterate over a field named "pt" of type float

#include <ROOT/RNTuple.hxx>
#include <iostream>
auto ntuple = RNTupleReader::Open("myNTuple", "some/file.root");
auto pt = ntuple->GetView<float>("pt");
for (auto i : ntuple->GetEntryRange()) {
std::cout << i << ": " << pt(i) << "\n";
}
TPaveText * pt

Definition at line 290 of file RNTuple.hxx.

◆ GetViewCollection()

RNTupleViewCollection ROOT::Experimental::RNTupleReader::GetViewCollection ( std::string_view  fieldName)
inline

Raises an exception if:

  • there is no field with the given name or,
  • the field is not a collection

Definition at line 303 of file RNTuple.hxx.

◆ InitPageSource()

void ROOT::Experimental::RNTupleReader::InitPageSource ( )
private

Definition at line 83 of file RNTuple.cxx.

◆ LoadEntry() [1/2]

void ROOT::Experimental::RNTupleReader::LoadEntry ( NTupleSize_t  index)
inline

Analogous to Fill(), fills the default entry of the model.

Returns false at the end of the ntuple. On I/O errors, raises an exception.

Definition at line 237 of file RNTuple.hxx.

◆ LoadEntry() [2/2]

void ROOT::Experimental::RNTupleReader::LoadEntry ( NTupleSize_t  index,
REntry entry 
)
inline

Fills a user provided entry after checking that the entry has been instantiated from the ntuple model.

Definition at line 246 of file RNTuple.hxx.

◆ Open() [1/2]

std::unique_ptr< ROOT::Experimental::RNTupleReader > ROOT::Experimental::RNTupleReader::Open ( std::string_view  ntupleName,
std::string_view  storage,
const RNTupleReadOptions options = RNTupleReadOptions() 
)
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

#include <ROOT/RNTuple.hxx>
#include <iostream>
auto ntuple = RNTupleReader::Open("myNTuple", "some/file.root");
std::cout << "myNTuple has " << ntuple->GetNEntries() << " entries\n";

Definition at line 134 of file RNTuple.cxx.

◆ Open() [2/2]

std::unique_ptr< ROOT::Experimental::RNTupleReader > ROOT::Experimental::RNTupleReader::Open ( std::unique_ptr< RNTupleModel model,
std::string_view  ntupleName,
std::string_view  storage,
const RNTupleReadOptions options = RNTupleReadOptions() 
)
static

Throws an exception if the model is null.

Definition at line 125 of file RNTuple.cxx.

◆ OpenFriends()

std::unique_ptr< ROOT::Experimental::RNTupleReader > ROOT::Experimental::RNTupleReader::OpenFriends ( std::span< ROpenSpec ntuples)
static

Open RNTuples as one virtual, horizontally combined ntuple.

The underlying RNTuples must have an identical number of entries. Fields in the combined RNTuple are named with the ntuple name as a prefix, e.g. myNTuple1.px and myNTuple2.pt (see tutorial ntpl006_friends)

Definition at line 142 of file RNTuple.cxx.

◆ PrintInfo()

void ROOT::Experimental::RNTupleReader::PrintInfo ( const ENTupleInfo  what = ENTupleInfo::kSummary,
std::ostream &  output = std::cout 
)

Prints a detailed summary of the ntuple, including a list of fields.

Example: print summary information to stdout

#include <ROOT/RNTuple.hxx>
#include <iostream>
auto ntuple = RNTupleReader::Open("myNTuple", "some/file.root");
ntuple->PrintInfo();
// or, equivalently:
ntuple->PrintInfo(ENTupleInfo::kSummary, std::cout);

Example: print detailed column storage data to stderr

#include <ROOT/RNTuple.hxx>
#include <iostream>
auto ntuple = RNTupleReader::Open("myNTuple", "some/file.root");
ntuple->PrintInfo(ENTupleInfo::kStorageDetails, std::cerr);

For use of ENTupleInfo::kMetrics, see EnableMetrics.

Definition at line 161 of file RNTuple.cxx.

◆ Show()

void ROOT::Experimental::RNTupleReader::Show ( NTupleSize_t  index,
const ENTupleShowFormat  format = ENTupleShowFormat::kCurrentModelJSON,
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 229 of file RNTuple.cxx.

Member Data Documentation

◆ fDisplayReader

std::unique_ptr<RNTupleReader> ROOT::Experimental::RNTupleReader::fDisplayReader
private

We use a dedicated on-demand reader for Show() and Scan().

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 114 of file RNTuple.hxx.

◆ fMetrics

Detail::RNTupleMetrics ROOT::Experimental::RNTupleReader::fMetrics
private

Definition at line 115 of file RNTuple.hxx.

◆ fModel

std::unique_ptr<RNTupleModel> ROOT::Experimental::RNTupleReader::fModel
private

Needs to be destructed before fSource.

Definition at line 110 of file RNTuple.hxx.

◆ fSource

std::unique_ptr<Detail::RPageSource> ROOT::Experimental::RNTupleReader::fSource
private

Definition at line 108 of file RNTuple.hxx.

◆ fUnzipTasks

std::unique_ptr<Detail::RPageStorage::RTaskScheduler> ROOT::Experimental::RNTupleReader::fUnzipTasks
private

Set as the page source's scheduler for parallel page decompression if IMT is on Needs to be destructed after the pages source is destructed (an thus be declared before)

Definition at line 106 of file RNTuple.hxx.


The documentation for this class was generated from the following files: