Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RNTupleReader.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleReader.hxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \date 2024-02-20
4
5/*************************************************************************
6 * Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_RNTupleReader
14#define ROOT_RNTupleReader
15
16#include <ROOT/RConfig.hxx> // for R__unlikely
17#include <ROOT/REntry.hxx>
18#include <ROOT/RError.hxx>
21#include <ROOT/RNTupleModel.hxx>
23#include <ROOT/RNTupleTypes.hxx>
24#include <ROOT/RNTupleView.hxx>
25#include <ROOT/RPageStorage.hxx>
26#include <ROOT/RSpan.hxx>
27
28#include <iostream>
29#include <iterator>
30#include <memory>
31#include <mutex>
32#include <string>
33#include <string_view>
34#include <unordered_map>
35
36namespace ROOT {
37class RNTuple;
38
39/// Listing of the different options that can be printed by RNTupleReader::GetInfo()
40enum class ENTupleInfo {
41 kSummary, // The RNTuple name, description, number of entries
42 kStorageDetails, // size on storage, page sizes, compression factor, etc.
43 kMetrics, // internals performance counters, requires that EnableMetrics() was called
44};
45
46// clang-format off
47/**
48\class ROOT::RNTupleReader
49\ingroup NTuple
50\brief Reads RNTuple data from storage
51
52The RNTupleReader provides access to data stored in the RNTuple binary format as C++ objects, using an RNTupleModel.
53It infers this model from the RNTuple's on-disk metadata, or uses a model imposed by the user.
54The latter case allows users to read into a specialized RNTuple model that covers
55only a subset of the fields in the RNTuple. The RNTuple model is used when reading complete entries through LoadEntry().
56Individual fields can be read as well by instantiating a tree view.
57
58~~~ {.cpp}
59#include <ROOT/RNTupleReader.hxx>
60#include <iostream>
61
62auto reader = ROOT::RNTupleReader::Open("myNTuple", "some/file.root");
63std::cout << "myNTuple has " << reader->GetNEntries() << " entries\n";
64~~~
65*/
66// clang-format on
68private:
69 /// Shared data structure between the reader and all the issued active entry tokens.
71 /// Points to the page source backing the associated RNTupleReader. When the reader is destructed, the
72 /// page source is reset to nullptr. At that point, operations on remaining active entry tokens become noops.
74 /// Reference counter of clusters pinned in the page source due to entries being marked as active.
75 std::unordered_map<ROOT::DescriptorId_t, std::uint64_t> fActiveClusters;
76 std::mutex fLock;
77
78 explicit RActiveEntriesControlBlock(Internal::RPageSource *pageSource) : fPageSource(pageSource) {}
79 };
80
81 /// Set as the page source's scheduler for parallel page decompression if implicit multi-threading (IMT) is on.
82 /// Needs to be destructed after the page source is destructed (and thus be declared before)
83 std::unique_ptr<Internal::RPageStorage::RTaskScheduler> fUnzipTasks;
84
85 std::unique_ptr<Internal::RPageSource> fSource;
86 /// Needs to be destructed before fSource
87 std::unique_ptr<ROOT::RNTupleModel> fModel;
88 /// We use a dedicated on-demand reader for Show(). Printing data uses all the fields
89 /// from the full model even if the analysis code uses only a subset of fields. The display reader
90 /// is a clone of the original reader.
91 std::unique_ptr<RNTupleReader> fDisplayReader;
92 /// The RNTuple descriptor in the page source is protected by a read-write lock. We don't expose that to the
93 /// users of RNTupleReader::GetDescriptor(). Instead, if descriptor information is needed, we clone the
94 /// descriptor. Using the descriptor's generation number, we know if the cached descriptor is stale.
95 /// Retrieving descriptor data from an RNTupleReader is supposed to be for testing and information purposes,
96 /// not on a hot code path.
97 std::optional<ROOT::RNTupleDescriptor> fCachedDescriptor;
98 /// We know that the RNTupleReader is always reading a single RNTuple, so the number of entries is fixed.
101 /// If not nullopt, these will be used when creating the model
102 std::optional<ROOT::RNTupleDescriptor::RCreateModelOptions> fCreateModelOptions;
103 /// Initialized when the page source is connected. It is then shared between the reader instance and all
104 /// active entry tokens. When the reader destructs, it resets the page source pointer in the control block.
105 std::shared_ptr<RActiveEntriesControlBlock> fActiveEntriesControlBlock;
106
107 RNTupleReader(std::unique_ptr<ROOT::RNTupleModel> model, std::unique_ptr<Internal::RPageSource> source,
108 const ROOT::RNTupleReadOptions &options);
109 /// The model is generated from the RNTuple metadata on storage.
110 explicit RNTupleReader(std::unique_ptr<Internal::RPageSource> source, const ROOT::RNTupleReadOptions &options);
111
112 void ConnectModel(ROOT::RNTupleModel &model, bool allowFieldSubstitutions);
114 void InitPageSource(bool enableMetrics);
115
116 ROOT::DescriptorId_t RetrieveFieldId(std::string_view fieldName) const;
117
118public:
119 // Browse through the entries
120 class RIterator {
121 private:
123
124 public:
126 using iterator_category = std::input_iterator_tag;
128 using difference_type = std::ptrdiff_t;
131
132 RIterator() = default;
133 explicit RIterator(ROOT::NTupleSize_t index) : fIndex(index) {}
134 ~RIterator() = default;
135
136 iterator operator++(int) /* postfix */
137 {
138 auto r = *this;
139 fIndex++;
140 return r;
141 }
142 iterator &operator++() /* prefix */
143 {
144 ++fIndex;
145 return *this;
146 }
147 reference operator*() const { return fIndex; }
148 pointer operator->() const { return &fIndex; }
149 bool operator==(const iterator &rh) const { return fIndex == rh.fIndex; }
150 bool operator!=(const iterator &rh) const { return fIndex != rh.fIndex; }
151 };
152
153 /// An active entry token is a pledge for the data of a certain entry number not to be evicted from the
154 /// page cache or cluster cache. An active entry token is linked to a specific reader through a control block
155 /// shared by the reader and all tokens of that reader. Active entry tokens can be destructed before or after
156 /// their reader is destructed. Once the corresponding reader is destructed, changing the entry number has no
157 /// effect.
158 /// Only the RNTuple reader can create an active entry token.
160 friend class RNTupleReader;
161
162 std::shared_ptr<RActiveEntriesControlBlock> fPtrControlBlock;
164
165 void ActivateEntry(NTupleSize_t entryNumber);
166 void DeactivateEntry(NTupleSize_t entryNumber);
167
168 explicit RActiveEntryToken(std::shared_ptr<RActiveEntriesControlBlock> ptrControlBlock)
169 : fPtrControlBlock(ptrControlBlock)
170 {
171 }
172
173 public:
179
181 /// Set or replace the entry number. If the entry number is replaced, the cluster corresponding to the new
182 /// entry is pinned _before_ the cluster of the old entry number is unpinned.
183 /// SetEntryNumber() should be called before the corresponding entry is used (through LoadEntry() or views).
184 void SetEntryNumber(NTupleSize_t entryNumber);
185 /// Release the entry number, i.e. allow the corresponding data to be evicted from caches.
186 /// Called implicitly on destruction.
187 void Reset();
188 };
189
190 /// Open an RNTuple for reading.
191 ///
192 /// Throws an RException if there is no RNTuple with the given name.
193 ///
194 /// **Example: open an RNTuple and print the number of entries**
195 /// ~~~ {.cpp}
196 /// #include <ROOT/RNTupleReader.hxx>
197 /// #include <iostream>
198 ///
199 /// auto reader = ROOT::RNTupleReader::Open("myNTuple", "some/file.root");
200 /// std::cout << "myNTuple has " << reader->GetNEntries() << " entries\n";
201 /// ~~~
202 static std::unique_ptr<RNTupleReader> Open(std::string_view ntupleName, std::string_view storage,
204 static std::unique_ptr<RNTupleReader>
205 Open(const RNTuple &ntuple, const ROOT::RNTupleReadOptions &options = ROOT::RNTupleReadOptions());
206
207 /// The caller imposes a model, which must be compatible with the model found in the data on storage.
208 static std::unique_ptr<RNTupleReader> Open(std::unique_ptr<ROOT::RNTupleModel> model, std::string_view ntupleName,
209 std::string_view storage,
211 static std::unique_ptr<RNTupleReader> Open(std::unique_ptr<ROOT::RNTupleModel> model, const RNTuple &ntuple,
213
214 /// The caller imposes the way the model is reconstructed
215 static std::unique_ptr<RNTupleReader> Open(const ROOT::RNTupleDescriptor::RCreateModelOptions &createModelOpts,
216 std::string_view ntupleName, std::string_view storage,
218 static std::unique_ptr<RNTupleReader> Open(const ROOT::RNTupleDescriptor::RCreateModelOptions &createModelOpts,
219 const RNTuple &ntuple,
221 std::unique_ptr<RNTupleReader> Clone()
222 {
223 auto options = ROOT::RNTupleReadOptions{};
224 options.SetEnableMetrics(fMetrics.IsEnabled());
225 return std::unique_ptr<RNTupleReader>(new RNTupleReader(fSource->Clone(), options));
226 }
227
233
234 /// Returns the number of entries in this RNTuple.
235 /// Note that the recommended way to iterate the RNTuple is using
236 /// ~~~ {.cpp}
237 /// // RECOMMENDED way to iterate an ntuple
238 /// for (auto i : reader->GetEntryRange()) { ... }
239 /// ~~~
240 /// instead of
241 /// ~~~ {.cpp}
242 /// // DISCOURAGED way to iterate an ntuple
243 /// for (auto i = 0u; i < reader->GetNEntries(); ++i) { ... }
244 /// ~~~
245 /// The reason is that determining the number of entries, while currently cheap, may in the future be
246 /// an expensive operation.
249 std::unique_ptr<ROOT::REntry> CreateEntry();
250
251 /// Returns a cached copy of the page source descriptor. The returned pointer remains valid until the next call
252 /// to LoadEntry() or to any of the views returned from the reader.
254
255 /// Prints a detailed summary of the RNTuple, including a list of fields.
256 ///
257 /// **Example: print summary information to stdout**
258 /// ~~~ {.cpp}
259 /// #include <ROOT/RNTupleReader.hxx>
260 /// #include <iostream>
261 ///
262 /// auto reader = ROOT::RNTupleReader::Open("myNTuple", "some/file.root");
263 /// reader->PrintInfo();
264 /// // or, equivalently:
265 /// reader->PrintInfo(ROOT::ENTupleInfo::kSummary, std::cout);
266 /// ~~~
267 /// **Example: print detailed column storage data to stderr**
268 /// ~~~ {.cpp}
269 /// #include <ROOT/RNTupleReader.hxx>
270 /// #include <iostream>
271 ///
272 /// auto reader = ROOT::RNTupleReader::Open("myNTuple", "some/file.root");
273 /// reader->PrintInfo(ROOT::ENTupleInfo::kStorageDetails, std::cerr);
274 /// ~~~
275 ///
276 /// For use of ENTupleInfo::kMetrics, see #EnableMetrics.
277 void PrintInfo(const ENTupleInfo what = ENTupleInfo::kSummary, std::ostream &output = std::cout) const;
278
279 /// Shows the values of the i-th entry/row, starting with 0 for the first entry. By default,
280 /// prints the output in JSON format.
281 /// Uses the visitor pattern to traverse through each field of the given entry.
282 void Show(ROOT::NTupleSize_t index, std::ostream &output = std::cout);
283
284 /// Fills the default entry of the model.
285 /// Raises an exception when `index` is greater than the number of entries present in the RNTuple
287 {
288 // TODO(jblomer): can be templated depending on the factory method / constructor
289 if (R__unlikely(!fModel)) {
290 // Will create the fModel.
291 GetModel();
292 }
293 LoadEntry(index, fModel->GetDefaultEntry());
294 }
295 /// Fills a user provided entry after checking that the entry has been instantiated from the RNTuple model
297 {
298 if (R__unlikely(entry.GetModelId() != fModel->GetModelId()))
299 throw RException(R__FAIL("mismatch between entry and model"));
300
301 entry.Read(index);
302 }
303
304 /// Create a new active entry token, which will not be bound to any entry number initially.
305 /// In order to bind the new token, its `SetEntryNumber()` must be called subsequently.
307
308 /// Returns an iterator over the entry indices of the RNTuple.
309 ///
310 /// **Example: iterate over all entries and print each entry in JSON format**
311 /// ~~~ {.cpp}
312 /// #include <ROOT/RNTupleReader.hxx>
313 /// #include <iostream>
314 ///
315 /// auto reader = ROOT::RNTupleReader::Open("myNTuple", "some/file.root");
316 /// for (auto i : ntuple->GetEntryRange()) {
317 /// reader->Show(i);
318 /// }
319 /// ~~~
321
322 /// Provides access to an individual (sub)field,
323 /// e.g. `GetView<Particle>("particle")`, `GetView<double>("particle.pt")` or
324 /// `GetView<std::vector<Particle>>("particles")`. It is possible to directly get the size of a collection (without
325 /// reading the collection itself) using RNTupleCardinality:
326 /// `GetView<ROOT::RNTupleCardinality<std::uint64_t>>("particles")`.
327 ///
328 /// Raises an exception if there is no field with the given name.
329 ///
330 /// **Example: iterate over a field named "pt" of type `float`**
331 /// ~~~ {.cpp}
332 /// #include <ROOT/RNTupleReader.hxx>
333 /// #include <iostream>
334 ///
335 /// auto reader = ROOT::RNTupleReader::Open("myNTuple", "some/file.root");
336 /// auto pt = reader->GetView<float>("pt");
337 ///
338 /// for (auto i : reader->GetEntryRange()) {
339 /// std::cout << i << ": " << pt(i) << "\n";
340 /// }
341 /// ~~~
342 ///
343 /// **Note**: if `T = void`, type checks are disabled. This is not really useful for this overload because
344 /// RNTupleView<void> does not give access to the pointer. If required, it is possible to provide an `objPtr` of a
345 /// dynamic type, for example via GetView(std::string_view, void *, std::string_view).
346 template <typename T>
347 ROOT::RNTupleView<T> GetView(std::string_view fieldName)
348 {
349 return GetView<T>(RetrieveFieldId(fieldName));
350 }
351
352 /// Provides access to an individual (sub)field, reading its values into `objPtr`.
353 ///
354 /// Raises an exception if there is no field with the given name.
355 ///
356 /// **Example: iterate over a field named "pt" of type `float`**
357 /// ~~~ {.cpp}
358 /// #include <ROOT/RNTupleReader.hxx>
359 /// #include <iostream>
360 ///
361 /// auto reader = ROOT::RNTupleReader::Open("myNTuple", "some/file.root");
362 /// auto pt = std::make_shared<float>();
363 /// auto ptView = reader->GetView("pt", pt);
364 ///
365 /// for (auto i : reader->GetEntryRange()) {
366 /// ptView(i);
367 /// std::cout << i << ": " << *pt << "\n";
368 /// }
369 /// ~~~
370 ///
371 /// **Note**: if `T = void`, type checks are disabled. It is the caller's responsibility to match the field and
372 /// object types. It is strongly recommended to use an overload that allows passing the `typeName`, such as
373 /// GetView(std::string_view, void *, std::string_view). This allows type checks with the on-disk metadata and
374 /// enables automatic schema evolution and conversion rules.
375 template <typename T>
376 ROOT::RNTupleView<T> GetView(std::string_view fieldName, std::shared_ptr<T> objPtr)
377 {
378 return GetView<T>(RetrieveFieldId(fieldName), objPtr);
379 }
380
381 /// Provides access to an individual (sub)field, reading its values into `rawPtr`.
382 ///
383 /// \sa GetView(std::string_view, std::shared_ptr<T>)
384 template <typename T>
385 ROOT::RNTupleView<T> GetView(std::string_view fieldName, T *rawPtr)
386 {
387 return GetView<T>(RetrieveFieldId(fieldName), rawPtr);
388 }
389
390 /// Provides access to an individual (sub)field, reading its values into `rawPtr` as the type provided by `typeName`.
391 ///
392 /// \sa GetView(std::string_view, std::shared_ptr<T>)
393 ROOT::RNTupleView<void> GetView(std::string_view fieldName, void *rawPtr, std::string_view typeName)
394 {
395 return GetView(RetrieveFieldId(fieldName), rawPtr, typeName);
396 }
397
398 /// Provides access to an individual (sub)field, reading its values into `rawPtr` as the type provided by `ti`.
399 ///
400 /// \sa GetView(std::string_view, std::shared_ptr<T>)
401 ROOT::RNTupleView<void> GetView(std::string_view fieldName, void *rawPtr, const std::type_info &ti)
402 {
404 }
405
406 /// Provides access to an individual (sub)field from its on-disk ID.
407 ///
408 /// \sa GetView(std::string_view)
409 template <typename T>
411 {
412 auto field = ROOT::RNTupleView<T>::CreateField(fieldId, *fSource);
413 auto range = ROOT::Internal::GetFieldRange(*field, *fSource);
414 return ROOT::RNTupleView<T>(std::move(field), range);
415 }
416
417 /// Provides access to an individual (sub)field from its on-disk ID, reading its values into `objPtr`.
418 ///
419 /// \sa GetView(std::string_view, std::shared_ptr<T>)
420 template <typename T>
421 ROOT::RNTupleView<T> GetView(ROOT::DescriptorId_t fieldId, std::shared_ptr<T> objPtr)
422 {
423 auto field = ROOT::RNTupleView<T>::CreateField(fieldId, *fSource);
424 auto range = ROOT::Internal::GetFieldRange(*field, *fSource);
425 return ROOT::RNTupleView<T>(std::move(field), range, objPtr);
426 }
427
428 /// Provides access to an individual (sub)field from its on-disk ID, reading its values into `rawPtr`.
429 ///
430 /// \sa GetView(std::string_view, std::shared_ptr<T>)
431 template <typename T>
433 {
434 auto field = ROOT::RNTupleView<T>::CreateField(fieldId, *fSource);
435 auto range = ROOT::Internal::GetFieldRange(*field, *fSource);
436 return ROOT::RNTupleView<T>(std::move(field), range, rawPtr);
437 }
438
439 /// Provides access to an individual (sub)field from its on-disk ID, reading its values into `rawPtr` as the type
440 /// provided by `typeName`.
441 ///
442 /// \sa GetView(std::string_view, std::shared_ptr<T>)
443 ROOT::RNTupleView<void> GetView(ROOT::DescriptorId_t fieldId, void *rawPtr, std::string_view typeName)
444 {
445 auto field = RNTupleView<void>::CreateField(fieldId, *fSource, typeName);
446 auto range = ROOT::Internal::GetFieldRange(*field, *fSource);
447 return RNTupleView<void>(std::move(field), range, rawPtr);
448 }
449
450 /// Provides access to an individual (sub)field from its on-disk ID, reading its values into `objPtr` as the type
451 /// provided by `ti`.
452 ///
453 /// \sa GetView(std::string_view, std::shared_ptr<T>)
454 ROOT::RNTupleView<void> GetView(ROOT::DescriptorId_t fieldId, void *rawPtr, const std::type_info &ti)
455 {
456 return GetView(fieldId, rawPtr, ROOT::Internal::GetRenormalizedTypeName(ti));
457 }
458
459 /// Provides direct access to the I/O buffers of a **mappable** (sub)field.
460 ///
461 /// Raises an exception if there is no field with the given name.
462 /// Attempting to access the values of a direct-access view for non-mappable fields will yield compilation errors.
463 ///
464 /// \sa GetView(std::string_view)
465 template <typename T>
467 {
468 return GetDirectAccessView<T>(RetrieveFieldId(fieldName));
469 }
470
471 /// Provides direct access to the I/O buffers of a **mappable** (sub)field from its on-disk ID.
472 ///
473 /// \sa GetDirectAccessView(std::string_view)
474 template <typename T>
481
482 /// Provides access to a collection field, that can itself generate new RNTupleViews for its nested fields.
483 ///
484 /// Raises an exception if:
485 /// * there is no field with the given name or,
486 /// * the field is not a collection
487 ///
488 /// \sa GetView(std::string_view)
490 {
491 auto fieldId = fSource->GetSharedDescriptorGuard()->FindFieldId(fieldName);
492 if (fieldId == ROOT::kInvalidDescriptorId) {
493 throw RException(R__FAIL("no field named '" + std::string(fieldName) + "' in RNTuple '" +
494 fSource->GetSharedDescriptorGuard()->GetName() + "'"));
495 }
496 return GetCollectionView(fieldId);
497 }
498
499 /// Provides access to a collection field from its on-disk ID, that can itself generate new RNTupleViews for its
500 /// nested fields.
501 ///
502 /// \sa GetCollectionView(std::string_view)
507
508 RIterator begin() { return RIterator(0); }
510
511 /// Enable performance measurements (decompression time, bytes read from storage, etc.)
512 ///
513 /// **Example: inspect the reader metrics after loading every entry**
514 /// ~~~ {.cpp}
515 /// #include <ROOT/RNTupleReader.hxx>
516 /// #include <iostream>
517 ///
518 /// auto ntuple = ROOT::RNTupleReader::Open("myNTuple", "some/file.root");
519 /// // metrics must be turned on beforehand
520 /// reader->EnableMetrics();
521 ///
522 /// for (auto i : ntuple->GetEntryRange()) {
523 /// reader->LoadEntry(i);
524 /// }
525 /// reader->PrintInfo(ROOT::ENTupleInfo::kMetrics);
526 /// ~~~
527 void EnableMetrics() { fMetrics.Enable(); }
529
530 /// Looks for an attribute set with the given name and creates an RNTupleAttrSetReader for it, with the provided
531 /// read options.
532 /// The returned reader has an independent lifetime from this RNTupleReader.
533 std::unique_ptr<Experimental::RNTupleAttrSetReader>
534 OpenAttributeSet(std::string_view attrSetName, const ROOT::RNTupleReadOptions &options = {});
535}; // class RNTupleReader
536
537} // namespace ROOT
538
539#endif // ROOT_RNTupleReader
ROOT::R::TRInterface & r
Definition Object.C:4
#define R__unlikely(expr)
Definition RConfig.hxx:586
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:299
A collection of Counter objects with a name, a unit, and a description.
Abstract interface to read data from an ntuple.
The REntry is a collection of values in an RNTuple corresponding to a complete row in the data set.
Definition REntry.hxx:54
std::uint64_t GetModelId() const
Definition REntry.hxx:254
void Read(ROOT::NTupleSize_t index)
Definition REntry.hxx:96
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
A view for a collection, that can itself generate new ntuple views for its nested fields.
static RNTupleCollectionView Create(ROOT::DescriptorId_t fieldId, ROOT::Internal::RPageSource *source)
The on-storage metadata of an RNTuple.
A view variant that provides direct access to the I/O buffers.
static ROOT::RField< T > CreateField(ROOT::DescriptorId_t fieldId, ROOT::Internal::RPageSource &pageSource)
Used to loop over indexes (entries or collections) between start and end.
The RNTupleModel encapulates the schema of an RNTuple.
Common user-tunable settings for reading RNTuples.
An active entry token is a pledge for the data of a certain entry number not to be evicted from the p...
std::shared_ptr< RActiveEntriesControlBlock > fPtrControlBlock
RActiveEntryToken & operator=(const RActiveEntryToken &other)
void ActivateEntry(NTupleSize_t entryNumber)
void Reset()
Release the entry number, i.e.
RActiveEntryToken(std::shared_ptr< RActiveEntriesControlBlock > ptrControlBlock)
void DeactivateEntry(NTupleSize_t entryNumber)
void SetEntryNumber(NTupleSize_t entryNumber)
Set or replace the entry number.
bool operator!=(const iterator &rh) const
RIterator(ROOT::NTupleSize_t index)
const ROOT::NTupleSize_t * pointer
std::input_iterator_tag iterator_category
const ROOT::NTupleSize_t & reference
bool operator==(const iterator &rh) const
Reads RNTuple data from storage.
ROOT::RNTupleGlobalRange GetEntryRange()
Returns an iterator over the entry indices of the RNTuple.
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< T > GetView(std::string_view fieldName, std::shared_ptr< T > objPtr)
Provides access to an individual (sub)field, reading its values into objPtr.
std::unique_ptr< RNTupleReader > fDisplayReader
We use a dedicated on-demand reader for Show().
ROOT::RNTupleView< T > GetView(ROOT::DescriptorId_t fieldId)
Provides access to an individual (sub)field from its on-disk ID.
std::unique_ptr< ROOT::REntry > CreateEntry()
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.
RNTupleReader & operator=(const ROOT::RNTupleReader &)=delete
void InitPageSource(bool enableMetrics)
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.
std::unique_ptr< Internal::RPageStorage::RTaskScheduler > fUnzipTasks
Set as the page source's scheduler for parallel page decompression if implicit multi-threading (IMT) ...
RNTupleReader(const ROOT::RNTupleReader &)=delete
ROOT::RNTupleView< T > GetView(std::string_view fieldName)
Provides access to an individual (sub)field, e.g.
ROOT::NTupleSize_t fNEntries
We know that the RNTupleReader is always reading a single RNTuple, so the number of entries is fixed.
std::unique_ptr< ROOT::RNTupleModel > fModel
Needs to be destructed before fSource.
const Experimental::Detail::RNTupleMetrics & GetMetrics() const
ROOT::RNTupleCollectionView GetCollectionView(std::string_view fieldName)
Provides access to a collection field, that can itself generate new RNTupleViews for its nested field...
ROOT::RNTupleDirectAccessView< T > GetDirectAccessView(std::string_view fieldName)
Provides direct access to the I/O buffers of a mappable (sub)field.
const ROOT::RNTupleDescriptor & GetDescriptor()
Returns a cached copy of the page source descriptor.
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 t...
std::optional< ROOT::RNTupleDescriptor::RCreateModelOptions > fCreateModelOptions
If not nullopt, these will be used when creating the model.
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.
std::unique_ptr< Internal::RPageSource > fSource
RNTupleReader(std::unique_ptr< ROOT::RNTupleModel > model, std::unique_ptr< Internal::RPageSource > source, const ROOT::RNTupleReadOptions &options)
const ROOT::RNTupleModel & GetModel()
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 th...
std::unique_ptr< Experimental::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,...
std::optional< ROOT::RNTupleDescriptor > fCachedDescriptor
The RNTuple descriptor in the page source is protected by a read-write lock.
RNTupleReader(ROOT::RNTupleReader &&)=delete
ROOT::RNTupleCollectionView GetCollectionView(ROOT::DescriptorId_t fieldId)
Provides access to a collection field from its on-disk ID, that can itself generate new RNTupleViews ...
std::unique_ptr< RNTupleReader > Clone()
RNTupleReader & operator=(ROOT::RNTupleReader &&)=delete
std::shared_ptr< RActiveEntriesControlBlock > fActiveEntriesControlBlock
Initialized when the page source is connected.
void ConnectModel(ROOT::RNTupleModel &model, bool allowFieldSubstitutions)
ROOT::NTupleSize_t GetNEntries() const
Returns the number of entries in this RNTuple.
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 t...
ROOT::DescriptorId_t RetrieveFieldId(std::string_view fieldName) const
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.
ROOT::RNTupleView< T > GetView(std::string_view fieldName, T *rawPtr)
Provides access to an individual (sub)field, reading its values into rawPtr.
RActiveEntryToken CreateActiveEntryToken()
Create a new active entry token, which will not be bound to any entry number initially.
RNTupleReader * GetDisplayReader()
Experimental::Detail::RNTupleMetrics fMetrics
void EnableMetrics()
Enable performance measurements (decompression time, bytes read from storage, etc....
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 mode...
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 th...
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.
void LoadEntry(ROOT::NTupleSize_t index)
Fills the default entry of the model.
static std::unique_ptr< ROOT::RFieldBase > CreateField(ROOT::DescriptorId_t fieldId, Internal::RPageSource &pageSource, std::string_view typeName="")
An RNTupleView for a known type.
Representation of an RNTuple data set in a ROOT file.
Definition RNTuple.hxx:67
ROOT::RNTupleGlobalRange GetFieldRange(const ROOT::RFieldBase &field, const ROOT::Internal::RPageSource &pageSource)
Helper to get the iteration space of the given field that needs to be connected to the given page sou...
std::string GetRenormalizedTypeName(const std::string &metaNormalizedName)
Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr NTupleSize_t kInvalidNTupleIndex
ENTupleInfo
Listing of the different options that can be printed by RNTupleReader::GetInfo().
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
static const char * what
Definition stlLoader.cc:5
RActiveEntriesControlBlock(Internal::RPageSource *pageSource)
Internal::RPageSource * fPageSource
Points to the page source backing the associated RNTupleReader.
std::unordered_map< ROOT::DescriptorId_t, std::uint64_t > fActiveClusters
Reference counter of clusters pinned in the page source due to entries being marked as active.