Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleDescriptor.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleDescriptor.hxx
2/// \ingroup NTuple
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \author Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
5/// \date 2018-07-19
6
7/*************************************************************************
8 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
15#ifndef ROOT_RNTupleDescriptor
16#define ROOT_RNTupleDescriptor
17
19#include <ROOT/RError.hxx>
21#include <ROOT/RNTupleTypes.hxx>
22#include <ROOT/RSpan.hxx>
23
24#include <TError.h>
25
26#include <algorithm>
27#include <chrono>
28#include <cmath>
29#include <functional>
30#include <iterator>
31#include <map>
32#include <memory>
33#include <optional>
34#include <ostream>
35#include <vector>
36#include <set>
37#include <string>
38#include <string_view>
39#include <unordered_map>
40#include <unordered_set>
41
42namespace ROOT {
43
44class RFieldBase;
45class RNTupleModel;
46
47namespace Internal {
48class RColumnElementBase;
49}
50
51class RNTupleDescriptor;
52
53namespace Internal {
54class RColumnDescriptorBuilder;
55class RClusterDescriptorBuilder;
56class RClusterGroupDescriptorBuilder;
57class RExtraTypeInfoDescriptorBuilder;
58class RFieldDescriptorBuilder;
59class RNTupleDescriptorBuilder;
60
61RNTupleDescriptor CloneDescriptorSchema(const RNTupleDescriptor &desc);
66
67std::vector<ROOT::Internal::RNTupleClusterBoundaries> GetClusterBoundaries(const RNTupleDescriptor &desc);
68} // namespace Internal
69
70namespace Experimental {
71
72// clang-format off
73/**
74\class ROOT::Experimental::RNTupleAttrSetDescriptor
75\ingroup NTuple
76\brief Metadata stored for every Attribute Set linked to an RNTuple.
77*/
78// clang-format on
81
82 std::uint16_t fSchemaVersionMajor = 0;
83 std::uint16_t fSchemaVersionMinor = 0;
84 std::uint32_t fAnchorLength = 0; ///< uncompressed size of the linked anchor
85 // The locator of the AttributeSet anchor.
86 // In case of kTypeFile, it points to the beginning of the Anchor's payload.
87 // NOTE: Only kTypeFile is supported at the moment.
89 std::string fName;
90
91public:
97
98 bool operator==(const RNTupleAttrSetDescriptor &other) const;
99 bool operator!=(const RNTupleAttrSetDescriptor &other) const { return !(*this == other); }
100
101 const std::string &GetName() const { return fName; }
102 std::uint16_t GetSchemaVersionMajor() const { return fSchemaVersionMajor; }
103 std::uint16_t GetSchemaVersionMinor() const { return fSchemaVersionMinor; }
104 std::uint32_t GetAnchorLength() const { return fAnchorLength; }
106
108};
109
110class RNTupleAttrSetDescriptorIterable;
111
112} // namespace Experimental
113
114// clang-format off
115/**
116\class ROOT::RFieldDescriptor
117\ingroup NTuple
118\brief Metadata stored for every field of an RNTuple
119*/
120// clang-format on
124
125private:
127 /// The version of the C++-type-to-column translation mechanics
128 std::uint32_t fFieldVersion = 0;
129 /// The version of the C++ type itself
130 std::uint32_t fTypeVersion = 0;
131 /// The leaf name, not including parent fields
132 std::string fFieldName;
133 /// Free text set by the user
134 std::string fFieldDescription;
135 /// The C++ type that was used when writing the field
136 std::string fTypeName;
137 /// A typedef or using directive that resolved to the type name during field creation
138 std::string fTypeAlias;
139 /// The number of elements per entry for fixed-size arrays
140 std::uint64_t fNRepetitions = 0;
141 /// The structural information carried by this field in the data model tree
143 /// Establishes sub field relationships, such as classes and collections
145 /// For projected fields, the source field ID
147 /// The pointers in the other direction from parent to children. They are serialized, too, to keep the
148 /// order of sub fields.
149 std::vector<ROOT::DescriptorId_t> fLinkIds;
150 /// The number of columns in the column representations of the field. The column cardinality helps to navigate the
151 /// list of logical column ids. For example, the second column of the third column representation is
152 /// fLogicalColumnIds[2 * fColumnCardinality + 1]
153 std::uint32_t fColumnCardinality = 0;
154 /// The ordered list of columns attached to this field: first by representation index then by column index.
155 std::vector<ROOT::DescriptorId_t> fLogicalColumnIds;
156 /// For custom classes, we store the ROOT TClass reported checksum to facilitate the use of I/O rules that
157 /// identify types by their checksum
158 std::optional<std::uint32_t> fTypeChecksum;
159 /// Indicates if this is a collection that should be represented in memory by a SoA layout.
160 bool fIsSoACollection = false;
161
162public:
163 RFieldDescriptor() = default;
168
169 bool operator==(const RFieldDescriptor &other) const;
170 /// Get a copy of the descriptor
171 RFieldDescriptor Clone() const;
172
173 /// In general, we create a field simply from the C++ type name. For untyped fields, however, we potentially need
174 /// access to sub fields, which is provided by the RNTupleDescriptor argument.
175 std::unique_ptr<ROOT::RFieldBase>
176 CreateField(const RNTupleDescriptor &ntplDesc, const ROOT::RCreateFieldOptions &options = {}) const;
177
179 std::uint32_t GetFieldVersion() const { return fFieldVersion; }
180 std::uint32_t GetTypeVersion() const { return fTypeVersion; }
181 const std::string &GetFieldName() const { return fFieldName; }
182 const std::string &GetFieldDescription() const { return fFieldDescription; }
183 const std::string &GetTypeName() const { return fTypeName; }
184 const std::string &GetTypeAlias() const { return fTypeAlias; }
185 std::uint64_t GetNRepetitions() const { return fNRepetitions; }
189 const std::vector<ROOT::DescriptorId_t> &GetLinkIds() const { return fLinkIds; }
190 const std::vector<ROOT::DescriptorId_t> &GetLogicalColumnIds() const { return fLogicalColumnIds; }
191 std::uint32_t GetColumnCardinality() const { return fColumnCardinality; }
192 std::optional<std::uint32_t> GetTypeChecksum() const { return fTypeChecksum; }
194 bool IsSoACollection() const { return fIsSoACollection; }
195
199};
200
201// clang-format off
202/**
203\class ROOT::RColumnDescriptor
204\ingroup NTuple
205\brief Metadata stored for every column of an RNTuple
206*/
207// clang-format on
211
212public:
213 struct RValueRange {
214 double fMin = 0, fMax = 0;
215
216 RValueRange() = default;
217 RValueRange(double min, double max) : fMin(min), fMax(max) {}
218 RValueRange(std::pair<double, double> range) : fMin(range.first), fMax(range.second) {}
219
220 bool operator==(RValueRange other) const { return fMin == other.fMin && fMax == other.fMax; }
221 bool operator!=(RValueRange other) const { return !(*this == other); }
222 };
223
224private:
225 /// The actual column identifier, which is the link to the corresponding field
227 /// Usually identical to the logical column ID, except for alias columns where it references the shadowed column
229 /// Every column belongs to one and only one field
231 /// The absolute value specifies the index for the first stored element for this column.
232 /// For deferred columns the absolute value is larger than zero.
233 /// Negative values specify a suppressed and deferred column.
234 std::int64_t fFirstElementIndex = 0U;
235 /// A field can be serialized into several columns, which are numbered from zero to $n$
236 std::uint32_t fIndex = 0;
237 /// A field may use multiple column representations, which are numbered from zero to $m$.
238 /// Every representation has the same number of columns.
239 std::uint16_t fRepresentationIndex = 0;
240 /// The size in bits of elements of this column. Most columns have the size fixed by their type
241 /// but low-precision float columns have variable bit widths.
242 std::uint16_t fBitsOnStorage = 0;
243 /// The on-disk column type
245 /// Optional value range (used e.g. by quantized real fields)
246 std::optional<RValueRange> fValueRange;
247
248public:
249 RColumnDescriptor() = default;
254
255 bool operator==(const RColumnDescriptor &other) const;
256 /// Get a copy of the descriptor
257 RColumnDescriptor Clone() const;
258
259 ROOT::DescriptorId_t GetLogicalId() const { return fLogicalColumnId; }
260 ROOT::DescriptorId_t GetPhysicalId() const { return fPhysicalColumnId; }
262 std::uint32_t GetIndex() const { return fIndex; }
263 std::uint16_t GetRepresentationIndex() const { return fRepresentationIndex; }
264 std::uint64_t GetFirstElementIndex() const { return std::abs(fFirstElementIndex); }
265 std::uint16_t GetBitsOnStorage() const { return fBitsOnStorage; }
266 ROOT::ENTupleColumnType GetType() const { return fType; }
267 std::optional<RValueRange> GetValueRange() const { return fValueRange; }
268 bool IsAliasColumn() const { return fPhysicalColumnId != fLogicalColumnId; }
269 bool IsDeferredColumn() const { return fFirstElementIndex != 0; }
270 bool IsSuppressedDeferredColumn() const { return fFirstElementIndex < 0; }
271};
272
273// clang-format off
274/**
275\class ROOT::RClusterDescriptor
276\ingroup NTuple
277\brief Metadata for RNTuple clusters
278
279The cluster descriptor is built in two phases. In a first phase, the descriptor has only an ID.
280In a second phase, the event range, column group, page locations and column ranges are added.
281Both phases are populated by the RClusterDescriptorBuilder.
282Clusters span across all available columns in the RNTuple.
283*/
284// clang-format on
287
288public:
289 // clang-format off
290 /**
291 \class ROOT::RClusterDescriptor::RColumnRange
292 \ingroup NTuple
293 \brief The window of element indexes of a particular column in a particular cluster
294 */
295 // clang-format on
298 /// The global index of the first column element in the cluster
300 /// The number of column elements in the cluster
302 /// The usual format for ROOT compression settings (see Compression.h).
303 /// The pages of a particular column in a particular cluster are all compressed with the same settings.
304 /// If unset, the compression settings are undefined (deferred columns, suppressed columns).
305 std::optional<std::uint32_t> fCompressionSettings;
306 /// Suppressed columns have an empty page range and unknown compression settings.
307 /// Their element index range, however, is aligned with the corresponding column of the
308 /// primary column representation (see Section "Suppressed Columns" in the specification)
309 bool fIsSuppressed = false;
310
311 // TODO(jblomer): we perhaps want to store summary information, such as average, min/max, etc.
312 // Should this be done on the field level?
313
314 public:
315 RColumnRange() = default;
316
318 ROOT::NTupleSize_t nElements, std::optional<std::uint32_t> compressionSettings,
319 bool suppressed = false)
320 : fPhysicalColumnId(physicalColumnId),
321 fFirstElementIndex(firstElementIndex),
322 fNElements(nElements),
323 fCompressionSettings(compressionSettings),
324 fIsSuppressed(suppressed)
325 {
326 }
327
328 ROOT::DescriptorId_t GetPhysicalColumnId() const { return fPhysicalColumnId; }
329 void SetPhysicalColumnId(ROOT::DescriptorId_t id) { fPhysicalColumnId = id; }
330
331 ROOT::NTupleSize_t GetFirstElementIndex() const { return fFirstElementIndex; }
332 void SetFirstElementIndex(ROOT::NTupleSize_t idx) { fFirstElementIndex = idx; }
333 void IncrementFirstElementIndex(ROOT::NTupleSize_t by) { fFirstElementIndex += by; }
334
335 ROOT::NTupleSize_t GetNElements() const { return fNElements; }
336 void SetNElements(ROOT::NTupleSize_t n) { fNElements = n; }
338
339 std::optional<std::uint32_t> GetCompressionSettings() const { return fCompressionSettings; }
340 void SetCompressionSettings(std::optional<std::uint32_t> comp) { fCompressionSettings = comp; }
341
342 bool IsSuppressed() const { return fIsSuppressed; }
343 void SetIsSuppressed(bool suppressed) { fIsSuppressed = suppressed; }
344
345 bool operator==(const RColumnRange &other) const
346 {
347 return fPhysicalColumnId == other.fPhysicalColumnId && fFirstElementIndex == other.fFirstElementIndex &&
348 fNElements == other.fNElements && fCompressionSettings == other.fCompressionSettings &&
349 fIsSuppressed == other.fIsSuppressed;
350 }
351
353 {
354 return (fFirstElementIndex <= index && (fFirstElementIndex + fNElements) > index);
355 }
356 };
357
358 // clang-format off
359 /**
360 \class ROOT::RClusterDescriptor::RPageInfo
361 \ingroup NTuple
362 \brief Information about a single page in the context of a cluster's page range.
363 */
364 // clang-format on
365 // NOTE: We do not need to store the element size / uncompressed page size because we know to which column
366 // the page belongs
367 struct RPageInfo {
368 private:
369 /// The meaning of `fLocator` depends on the storage backend.
371 /// The sum of the elements of all the pages must match the corresponding `fNElements` field in `fColumnRanges`
372 std::uint32_t fNElements = std::uint32_t(-1);
373 /// If true, the 8 bytes following the serialized page are an xxhash of the on-disk page data
374 bool fHasChecksum = false;
375
376 public:
377 RPageInfo() = default;
379 : fLocator(locator), fNElements(nElements), fHasChecksum(hasChecksum)
380 {
381 }
382
383 bool operator==(const RPageInfo &other) const
384 {
385 return fLocator == other.fLocator && fNElements == other.fNElements;
386 }
387
388 const RNTupleLocator &GetLocator() const { return fLocator; }
389 RNTupleLocator &GetLocator() { return fLocator; }
390 void SetLocator(const RNTupleLocator &locator) { fLocator = locator; }
391
392 std::uint32_t GetNElements() const { return fNElements; }
393 void SetNElements(std::uint32_t n) { fNElements = n; }
394
395 bool HasChecksum() const { return fHasChecksum; }
396 void SetHasChecksum(bool hasChecksum) { fHasChecksum = hasChecksum; }
397 };
398
399 // clang-format off
400 /**
401 \class ROOT::RClusterDescriptor::RPageInfoExtended
402 \ingroup NTuple
403 \brief Additional information about a page in an in-memory RPageRange.
404
405 Used by RPageRange::Find() to return information relative to the RPageRange. This information is not stored on disk
406 and we don't need to keep it in memory because it can be easily recomputed.
407 */
408 // clang-format on
410 private:
411 /// Index (in cluster) of the first element in page.
412 ROOT::NTupleSize_t fFirstElementIndex = 0;
413 /// Page number in the corresponding RPageRange.
414 ROOT::NTupleSize_t fPageNumber = 0;
415
416 public:
417 RPageInfoExtended() = default;
422
423 ROOT::NTupleSize_t GetFirstElementIndex() const { return fFirstElementIndex; }
425
426 ROOT::NTupleSize_t GetPageNumber() const { return fPageNumber; }
428 };
429
430 // clang-format off
431 /**
432 \class ROOT::RClusterDescriptor::RPageRange
433 \ingroup NTuple
434 \brief Records the partition of data into pages for a particular column in a particular cluster
435 */
436 // clang-format on
439
440 private:
441 /// \brief Extend this RPageRange to fit the given RColumnRange.
442 ///
443 /// To do so, prepend as many synthetic RPageInfos as needed to cover the range in `columnRange`.
444 /// RPageInfos are constructed to contain as many elements of type `element` given a page size
445 /// limit of `pageSize` (in bytes); the locator for the referenced pages is `kTypePageZero`.
446 /// This function is used to make up RPageRanges for clusters that contain deferred columns.
447 /// \return The number of column elements covered by the synthesized RPageInfos
448 std::size_t ExtendToFitColumnRange(const RColumnRange &columnRange,
450
451 std::vector<RPageInfo> fPageInfos;
452
453 /// Has the same length than fPageInfos and stores the sum of the number of elements of all the pages
454 /// up to and including a given index. Used for binary search in Find().
455 /// This vector is only created if fPageInfos has at least kLargeRangeThreshold elements.
456 std::unique_ptr<std::vector<ROOT::NTupleSize_t>> fCumulativeNElements;
457
459
460 public:
461 /// Create the fCumulativeNElements only when its needed, i.e. when there are many pages to search through.
462 static constexpr std::size_t kLargeRangeThreshold = 10;
463
464 RPageRange() = default;
465 RPageRange(const RPageRange &other) = delete;
469
471 {
472 RPageRange clone;
473 clone.fPhysicalColumnId = fPhysicalColumnId;
474 clone.fPageInfos = fPageInfos;
475 if (fCumulativeNElements) {
476 clone.fCumulativeNElements = std::make_unique<std::vector<ROOT::NTupleSize_t>>(*fCumulativeNElements);
477 }
478 return clone;
479 }
480
481 /// Find the page in the RPageRange that contains the given element. The element must exist.
483
484 ROOT::DescriptorId_t GetPhysicalColumnId() const { return fPhysicalColumnId; }
485 void SetPhysicalColumnId(ROOT::DescriptorId_t id) { fPhysicalColumnId = id; }
486
487 const std::vector<RPageInfo> &GetPageInfos() const { return fPageInfos; }
488 std::vector<RPageInfo> &GetPageInfos() { return fPageInfos; }
489
490 bool operator==(const RPageRange &other) const
491 {
492 return fPhysicalColumnId == other.fPhysicalColumnId && fPageInfos == other.fPageInfos;
493 }
494 };
495
496private:
498 /// Clusters can be swapped by adjusting the entry offsets of the cluster and all ranges
501
502 std::unordered_map<ROOT::DescriptorId_t, RColumnRange> fColumnRanges;
503 std::unordered_map<ROOT::DescriptorId_t, RPageRange> fPageRanges;
504
505public:
507
513
514 RClusterDescriptor Clone() const;
515
516 bool operator==(const RClusterDescriptor &other) const;
517
518 ROOT::DescriptorId_t GetId() const { return fClusterId; }
519 ROOT::NTupleSize_t GetFirstEntryIndex() const { return fFirstEntryIndex; }
520 ROOT::NTupleSize_t GetNEntries() const { return fNEntries; }
521 const RColumnRange &GetColumnRange(ROOT::DescriptorId_t physicalId) const { return fColumnRanges.at(physicalId); }
522 const RPageRange &GetPageRange(ROOT::DescriptorId_t physicalId) const { return fPageRanges.at(physicalId); }
523 /// Returns an iterator over pairs { columnId, columnRange }. The iteration order is unspecified.
524 RColumnRangeIterable GetColumnRangeIterable() const;
526 {
527 return fColumnRanges.find(physicalId) != fColumnRanges.end();
528 }
529 std::uint64_t GetNBytesOnStorage() const;
530};
531
533private:
535
536public:
538 private:
539 using Iter_t = std::unordered_map<ROOT::DescriptorId_t, RColumnRange>::const_iterator;
540 /// The wrapped map iterator
542
543 public:
544 using iterator_category = std::forward_iterator_tag;
547 using difference_type = std::ptrdiff_t;
548 using pointer = const RColumnRange *;
549 using reference = const RColumnRange &;
550
551 RIterator(Iter_t iter) : fIter(iter) {}
552 iterator &operator++() /* prefix */
553 {
554 ++fIter;
555 return *this;
556 }
557 iterator operator++(int) /* postfix */
558 {
559 auto old = *this;
560 operator++();
561 return old;
562 }
563 reference operator*() const { return fIter->second; }
564 pointer operator->() const { return &fIter->second; }
565 bool operator!=(const iterator &rh) const { return fIter != rh.fIter; }
566 bool operator==(const iterator &rh) const { return fIter == rh.fIter; }
567 };
568
569 explicit RColumnRangeIterable(const RClusterDescriptor &desc) : fDesc(desc) {}
570
571 RIterator begin() { return RIterator{fDesc.fColumnRanges.cbegin()}; }
572 RIterator end() { return RIterator{fDesc.fColumnRanges.cend()}; }
573 size_t size() { return fDesc.fColumnRanges.size(); }
574};
575
576// clang-format off
577/**
578\class ROOT::RClusterGroupDescriptor
579\ingroup NTuple
580\brief Clusters are bundled in cluster groups.
581
582Very large RNTuples can contain multiple cluster groups to organize cluster metadata.
583Every RNTuple has at least one cluster group. The clusters in a cluster group are ordered
584corresponding to their first entry number.
585*/
586// clang-format on
589
590private:
592 /// The cluster IDs can be empty if the corresponding page list is not loaded.
593 /// Otherwise, cluster ids are sorted by first entry number.
594 std::vector<ROOT::DescriptorId_t> fClusterIds;
595 /// The page list that corresponds to the cluster group
597 /// Uncompressed size of the page list
598 std::uint64_t fPageListLength = 0;
599 /// The minimum first entry number of the clusters in the cluster group
600 std::uint64_t fMinEntry = 0;
601 /// Number of entries that are (partially for sharded clusters) covered by this cluster group.
602 std::uint64_t fEntrySpan = 0;
603 /// Number of clusters is always known even if the cluster IDs are not (yet) populated
604 std::uint32_t fNClusters = 0;
605
606public:
612
613 RClusterGroupDescriptor Clone() const;
614 /// Creates a clone without the cluster IDs
615 RClusterGroupDescriptor CloneSummary() const;
616
617 bool operator==(const RClusterGroupDescriptor &other) const;
618
619 ROOT::DescriptorId_t GetId() const { return fClusterGroupId; }
620 std::uint32_t GetNClusters() const { return fNClusters; }
621 RNTupleLocator GetPageListLocator() const { return fPageListLocator; }
622 std::uint64_t GetPageListLength() const { return fPageListLength; }
623 const std::vector<ROOT::DescriptorId_t> &GetClusterIds() const { return fClusterIds; }
624 std::uint64_t GetMinEntry() const { return fMinEntry; }
625 std::uint64_t GetEntrySpan() const { return fEntrySpan; }
626 /// A cluster group is loaded in two stages. Stage one loads only the summary information.
627 /// Stage two loads the list of cluster IDs.
628 bool HasClusterDetails() const { return !fClusterIds.empty(); }
629};
630
631/// Used in RExtraTypeInfoDescriptor
633 kInvalid,
635};
636
637// clang-format off
638/**
639\class ROOT::RExtraTypeInfoDescriptor
640\ingroup NTuple
641\brief Field specific extra type information from the header / extenstion header
642
643Currently only used by streamer fields to store RNTuple-wide list of streamer info records.
644*/
645// clang-format on
648
649private:
650 /// Specifies the meaning of the extra information
651 EExtraTypeInfoIds fContentId = EExtraTypeInfoIds::kInvalid;
652 /// Type version the extra type information is bound to
653 std::uint32_t fTypeVersion = 0;
654 /// The type name the extra information refers to; empty for RNTuple-wide extra information
655 std::string fTypeName;
656 /// The content format depends on the content ID and may be binary
657 std::string fContent;
658
659public:
665
666 bool operator==(const RExtraTypeInfoDescriptor &other) const;
667
668 RExtraTypeInfoDescriptor Clone() const;
669
670 EExtraTypeInfoIds GetContentId() const { return fContentId; }
671 std::uint32_t GetTypeVersion() const { return fTypeVersion; }
672 const std::string &GetTypeName() const { return fTypeName; }
673 const std::string &GetContent() const { return fContent; }
674};
675
676namespace Internal {
677// Used by the RNTupleReader to activate/deactivate entries. Needs to adapt when we have sharded clusters.
679} // namespace Internal
680
681// clang-format off
682/**
683\class ROOT::RNTupleDescriptor
684\ingroup NTuple
685\brief The on-storage metadata of an RNTuple
686
687Represents the on-disk (on storage) information about an RNTuple. The metadata consists of a header, a footer, and
688potentially multiple page lists.
689The header carries the RNTuple schema, i.e. the fields and the associated columns and their relationships.
690The footer carries information about one or several cluster groups and links to their page lists.
691For every cluster group, a page list envelope stores cluster summaries and page locations.
692For every cluster, it stores for every column the range of element indexes as well as a list of pages and page
693locations.
694
695The descriptor provides machine-independent (de-)serialization of headers and footers, and it provides lookup routines
696for RNTuple objects (pages, clusters, ...). It is supposed to be usable by all RPageStorage implementations.
697
698The serialization does not use standard ROOT streamers in order to not let it depend on libCore. The serialization uses
699the concept of envelopes and frames: header, footer, and page list envelopes have a preamble with a type ID and length.
700Substructures are serialized in frames and have a size and number of items (for list frames). This allows for forward
701and backward compatibility when the metadata evolves.
702*/
703// clang-format on
706 friend RNTupleDescriptor Internal::CloneDescriptorSchema(const RNTupleDescriptor &desc);
707 friend DescriptorId_t Internal::CallFindClusterIdOn(const RNTupleDescriptor &desc, NTupleSize_t entryIdx);
708
709public:
710 class RHeaderExtension;
711
712private:
713 /// The RNTuple name needs to be unique in a given storage location (file)
714 std::string fName;
715 /// Free text from the user
716 std::string fDescription;
717
718 ROOT::DescriptorId_t fFieldZeroId = ROOT::kInvalidDescriptorId; ///< Set by the descriptor builder
719
720 std::uint64_t fNPhysicalColumns = 0; ///< Updated by the descriptor builder when columns are added
721
722 std::set<unsigned int> fFeatureFlags;
723 std::unordered_map<ROOT::DescriptorId_t, RFieldDescriptor> fFieldDescriptors;
724 std::unordered_map<ROOT::DescriptorId_t, RColumnDescriptor> fColumnDescriptors;
725
726 std::vector<RExtraTypeInfoDescriptor> fExtraTypeInfoDescriptors;
727 std::unique_ptr<RHeaderExtension> fHeaderExtension;
728
729 //// All fields above are part of the schema and are cloned when creating a new descriptor from a given one
730 //// (see CloneSchema())
731
732 std::uint16_t fVersionEpoch = 0; ///< Set by the descriptor builder when deserialized
733 std::uint16_t fVersionMajor = 0; ///< Set by the descriptor builder when deserialized
734 std::uint16_t fVersionMinor = 0; ///< Set by the descriptor builder when deserialized
735 std::uint16_t fVersionPatch = 0; ///< Set by the descriptor builder when deserialized
736
737 std::uint64_t fOnDiskHeaderSize = 0; ///< Set by the descriptor builder when deserialized
738 std::uint64_t fOnDiskHeaderXxHash3 = 0; ///< Set by the descriptor builder when deserialized
739 std::uint64_t fOnDiskFooterSize = 0; ///< Like fOnDiskHeaderSize, contains both cluster summaries and page locations
740
741 std::uint64_t fNEntries = 0; ///< Updated by the descriptor builder when the cluster groups are added
742 std::uint64_t fNClusters = 0; ///< Updated by the descriptor builder when the cluster groups are added
743
744 /// \brief The generation of the descriptor
745 ///
746 /// Once constructed by an RNTupleDescriptorBuilder, the descriptor is mostly immutable except for the set of
747 /// active page locations. During the lifetime of the descriptor, page location information for clusters
748 /// can be added or removed. When this happens, the generation should be increased, so that users of the
749 /// descriptor know that the information changed. The generation is increased, e.g., by the page source's
750 /// exclusive lock guard around the descriptor. It is used, e.g., by the descriptor cache in RNTupleReader.
751 std::uint64_t fGeneration = 0;
752
753 std::unordered_map<ROOT::DescriptorId_t, RClusterGroupDescriptor> fClusterGroupDescriptors;
754 /// References cluster groups sorted by entry range and thus allows for binary search.
755 /// Note that this list is empty during the descriptor building process and will only be
756 /// created when the final descriptor is extracted from the builder.
757 std::vector<ROOT::DescriptorId_t> fSortedClusterGroupIds;
758 /// Potentially a subset of all the available clusters
759 std::unordered_map<ROOT::DescriptorId_t, RClusterDescriptor> fClusterDescriptors;
760 /// List of AttributeSets linked to this RNTuple
761 std::vector<Experimental::RNTupleAttrSetDescriptor> fAttributeSets;
762
763 // We don't expose this publicly because when we add sharded clusters, this interface does not make sense anymore
765
766 /// Creates a descriptor containing only the schema information about this RNTuple, i.e. all the information needed
767 /// to create a new RNTuple with the same schema as this one but not necessarily the same clustering. This is used
768 /// when merging two RNTuples.
769 RNTupleDescriptor CloneSchema() const;
770
771public:
772 static constexpr unsigned int kFeatureFlagTest = 137; // Bit reserved for forward-compatibility testing
773
780
781 /// Modifiers passed to CreateModel()
783 private:
784 /// If set to true, projected fields will be reconstructed as such. This will prevent the model to be used
785 /// with an RNTupleReader, but it is useful, e.g., to accurately merge data.
786 bool fReconstructProjections = false;
787 /// By default, creating a model will fail if any of the reconstructed fields contains an unknown column type
788 /// or an unknown field structural role.
789 /// If this option is enabled, the model will be created and all fields containing unknown data (directly
790 /// or indirectly) will be skipped instead.
791 bool fForwardCompatible = false;
792 /// If true, the model will be created without a default entry (bare model).
793 bool fCreateBare = false;
794 /// If true, fields with a user defined type that have no available dictionaries will be reconstructed
795 /// as record fields from the on-disk information; otherwise, they will cause an error.
796 bool fEmulateUnknownTypes = false;
797
798 public:
799 RCreateModelOptions() {} // Work around compiler bug, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88165
800
801 void SetReconstructProjections(bool v) { fReconstructProjections = v; }
802 bool GetReconstructProjections() const { return fReconstructProjections; }
803
804 void SetForwardCompatible(bool v) { fForwardCompatible = v; }
805 bool GetForwardCompatible() const { return fForwardCompatible; }
806
807 void SetCreateBare(bool v) { fCreateBare = v; }
808 bool GetCreateBare() const { return fCreateBare; }
809
810 void SetEmulateUnknownTypes(bool v) { fEmulateUnknownTypes = v; }
811 bool GetEmulateUnknownTypes() const { return fEmulateUnknownTypes; }
812 };
813
814 RNTupleDescriptor() = default;
819
820 RNTupleDescriptor Clone() const;
821
822 bool operator==(const RNTupleDescriptor &other) const;
823
824 std::uint64_t GetOnDiskHeaderXxHash3() const { return fOnDiskHeaderXxHash3; }
825 std::uint64_t GetOnDiskHeaderSize() const { return fOnDiskHeaderSize; }
826 std::uint64_t GetOnDiskFooterSize() const { return fOnDiskFooterSize; }
827 /// \see ROOT::RNTuple::GetCurrentVersion()
828 std::uint64_t GetVersion() const
829 {
830 return (static_cast<std::uint64_t>(fVersionEpoch) << 48) | (static_cast<std::uint64_t>(fVersionMajor) << 32) |
831 (static_cast<std::uint64_t>(fVersionMinor) << 16) | (static_cast<std::uint64_t>(fVersionPatch));
832 }
833
835 {
836 return fFieldDescriptors.at(fieldId);
837 }
839 {
840 return fColumnDescriptors.at(columnId);
841 }
843 {
844 return fClusterGroupDescriptors.at(clusterGroupId);
845 }
847 {
848 return fClusterDescriptors.at(clusterId);
849 }
850
851 RFieldDescriptorIterable GetFieldIterable(const RFieldDescriptor &fieldDesc) const;
852 RFieldDescriptorIterable
853 GetFieldIterable(const RFieldDescriptor &fieldDesc,
854 const std::function<bool(ROOT::DescriptorId_t, ROOT::DescriptorId_t)> &comparator) const;
855 RFieldDescriptorIterable GetFieldIterable(ROOT::DescriptorId_t fieldId) const;
856 RFieldDescriptorIterable
857 GetFieldIterable(ROOT::DescriptorId_t fieldId,
858 const std::function<bool(ROOT::DescriptorId_t, ROOT::DescriptorId_t)> &comparator) const;
859
860 RFieldDescriptorIterable GetTopLevelFields() const;
861 RFieldDescriptorIterable
862 GetTopLevelFields(const std::function<bool(ROOT::DescriptorId_t, ROOT::DescriptorId_t)> &comparator) const;
863
864 RColumnDescriptorIterable GetColumnIterable() const;
865 RColumnDescriptorIterable GetColumnIterable(const RFieldDescriptor &fieldDesc) const;
866 RColumnDescriptorIterable GetColumnIterable(ROOT::DescriptorId_t fieldId) const;
867
868 RClusterGroupDescriptorIterable GetClusterGroupIterable() const;
869
870 RClusterDescriptorIterable GetClusterIterable() const;
871
872 RExtraTypeInfoDescriptorIterable GetExtraTypeInfoIterable() const;
873
875
876 const std::string &GetName() const { return fName; }
877 const std::string &GetDescription() const { return fDescription; }
878
879 std::size_t GetNFields() const { return fFieldDescriptors.size(); }
880 std::size_t GetNLogicalColumns() const { return fColumnDescriptors.size(); }
881 std::size_t GetNPhysicalColumns() const { return fNPhysicalColumns; }
882 std::size_t GetNClusterGroups() const { return fClusterGroupDescriptors.size(); }
883 std::size_t GetNClusters() const { return fNClusters; }
884 std::size_t GetNActiveClusters() const { return fClusterDescriptors.size(); }
885 std::size_t GetNExtraTypeInfos() const { return fExtraTypeInfoDescriptors.size(); }
886 std::size_t GetNAttributeSets() const { return fAttributeSets.size(); }
887
888 /// We know the number of entries from adding the cluster summaries
889 ROOT::NTupleSize_t GetNEntries() const { return fNEntries; }
891
892 /// Returns the logical parent of all top-level RNTuple data fields.
893 ROOT::DescriptorId_t GetFieldZeroId() const { return fFieldZeroId; }
894 const RFieldDescriptor &GetFieldZero() const { return GetFieldDescriptor(GetFieldZeroId()); }
895 ROOT::DescriptorId_t FindFieldId(std::string_view fieldName, ROOT::DescriptorId_t parentId) const;
896 /// Searches for a top-level field
897 ROOT::DescriptorId_t FindFieldId(std::string_view fieldName) const;
898 ROOT::DescriptorId_t FindLogicalColumnId(ROOT::DescriptorId_t fieldId, std::uint32_t columnIndex,
899 std::uint16_t representationIndex) const;
900 ROOT::DescriptorId_t FindPhysicalColumnId(ROOT::DescriptorId_t fieldId, std::uint32_t columnIndex,
901 std::uint16_t representationIndex) const;
903 ROOT::DescriptorId_t FindNextClusterId(ROOT::DescriptorId_t clusterId) const;
904 ROOT::DescriptorId_t FindPrevClusterId(ROOT::DescriptorId_t clusterId) const;
905
906 /// Walks up the parents of the field ID and returns a field name of the form a.b.c.d
907 /// In case of invalid field ID, an empty string is returned.
908 std::string GetQualifiedFieldName(ROOT::DescriptorId_t fieldId) const;
909
910 /// Adjust the type name of the passed RFieldDescriptor for comparison with another renormalized type name.
911 std::string GetTypeNameForComparison(const RFieldDescriptor &fieldDesc) const;
912
913 bool HasFeature(unsigned int flag) const { return fFeatureFlags.count(flag) > 0; }
914 std::vector<std::uint64_t> GetFeatureFlags() const;
915
916 /// Return header extension information; if the descriptor does not have a header extension, return `nullptr`
917 const RHeaderExtension *GetHeaderExtension() const { return fHeaderExtension.get(); }
918
919 /// Methods to load and drop cluster group details (cluster IDs and page locations)
921 AddClusterGroupDetails(ROOT::DescriptorId_t clusterGroupId, std::vector<RClusterDescriptor> &clusterDescs);
922 RResult<void> DropClusterGroupDetails(ROOT::DescriptorId_t clusterGroupId);
923
924 std::uint64_t GetGeneration() const { return fGeneration; }
925 void IncGeneration() { fGeneration++; }
926
927 /// Re-create the C++ model from the stored metadata
928 std::unique_ptr<ROOT::RNTupleModel> CreateModel(const RCreateModelOptions &options = RCreateModelOptions()) const;
929 void PrintInfo(std::ostream &output) const;
930};
931
932// clang-format off
933/**
934\class ROOT::RNTupleDescriptor::RColumnDescriptorIterable
935\ingroup NTuple
936\brief Used to loop over a field's associated columns
937*/
938// clang-format on
940private:
941 /// The associated RNTuple for this range.
943 /// The descriptor ids of the columns ordered by field, representation, and column index
944 std::vector<ROOT::DescriptorId_t> fColumns = {};
945
946public:
948 private:
949 /// The enclosing range's RNTuple.
951 /// The enclosing range's descriptor id list.
952 const std::vector<ROOT::DescriptorId_t> &fColumns;
953 std::size_t fIndex = 0;
954
955 public:
956 using iterator_category = std::forward_iterator_tag;
959 using difference_type = std::ptrdiff_t;
960 using pointer = const RColumnDescriptor *;
962
963 RIterator(const RNTupleDescriptor &ntuple, const std::vector<ROOT::DescriptorId_t> &columns, std::size_t index)
964 : fNTuple(ntuple), fColumns(columns), fIndex(index)
965 {
966 }
967 iterator &operator++() /* prefix */
968 {
969 ++fIndex;
970 return *this;
971 }
972 iterator operator++(int) /* postfix */
973 {
974 auto old = *this;
975 operator++();
976 return old;
977 }
978 reference operator*() const { return fNTuple.GetColumnDescriptor(fColumns.at(fIndex)); }
979 pointer operator->() const { return &fNTuple.GetColumnDescriptor(fColumns.at(fIndex)); }
980 bool operator!=(const iterator &rh) const { return fIndex != rh.fIndex; }
981 bool operator==(const iterator &rh) const { return fIndex == rh.fIndex; }
982 };
983
986
987 RIterator begin() { return RIterator(fNTuple, fColumns, 0); }
988 RIterator end() { return RIterator(fNTuple, fColumns, fColumns.size()); }
989 size_t size() { return fColumns.size(); }
990};
991
992// clang-format off
993/**
994\class ROOT::RNTupleDescriptor::RFieldDescriptorIterable
995\ingroup NTuple
996\brief Used to loop over a field's child fields
997*/
998// clang-format on
1000private:
1001 /// The associated RNTuple for this range.
1003 /// The descriptor IDs of the child fields. These may be sorted using
1004 /// a comparison function.
1005 std::vector<ROOT::DescriptorId_t> fFieldChildren = {};
1006
1007public:
1009 private:
1010 /// The enclosing range's RNTuple.
1012 /// The enclosing range's descriptor id list.
1013 const std::vector<ROOT::DescriptorId_t> &fFieldChildren;
1014 std::size_t fIndex = 0;
1015
1016 public:
1017 using iterator_category = std::forward_iterator_tag;
1020 using difference_type = std::ptrdiff_t;
1021 using pointer = const RFieldDescriptor *;
1023
1024 RIterator(const RNTupleDescriptor &ntuple, const std::vector<ROOT::DescriptorId_t> &fieldChildren,
1025 std::size_t index)
1026 : fNTuple(ntuple), fFieldChildren(fieldChildren), fIndex(index)
1027 {
1028 }
1029 iterator &operator++() /* prefix */
1030 {
1031 ++fIndex;
1032 return *this;
1033 }
1034 iterator operator++(int) /* postfix */
1035 {
1036 auto old = *this;
1037 operator++();
1038 return old;
1039 }
1040 reference operator*() const { return fNTuple.GetFieldDescriptor(fFieldChildren.at(fIndex)); }
1041 pointer operator->() const { return &fNTuple.GetFieldDescriptor(fFieldChildren.at(fIndex)); }
1042 bool operator!=(const iterator &rh) const { return fIndex != rh.fIndex; }
1043 bool operator==(const iterator &rh) const { return fIndex == rh.fIndex; }
1044 };
1046 : fNTuple(ntuple), fFieldChildren(field.GetLinkIds())
1047 {
1048 }
1049 /// Sort the range using an arbitrary comparison function.
1051 const std::function<bool(ROOT::DescriptorId_t, ROOT::DescriptorId_t)> &comparator)
1052 : fNTuple(ntuple), fFieldChildren(field.GetLinkIds())
1053 {
1054 std::sort(fFieldChildren.begin(), fFieldChildren.end(), comparator);
1055 }
1056 RIterator begin() { return RIterator(fNTuple, fFieldChildren, 0); }
1057 RIterator end() { return RIterator(fNTuple, fFieldChildren, fFieldChildren.size()); }
1058};
1059
1060// clang-format off
1061/**
1062\class ROOT::RNTupleDescriptor::RClusterGroupDescriptorIterable
1063\ingroup NTuple
1064\brief Used to loop over all the cluster groups of an RNTuple (in unspecified order)
1065
1066Enumerate all cluster group IDs from the descriptor. No specific order can be assumed.
1067*/
1068// clang-format on
1070private:
1071 /// The associated RNTuple for this range.
1073
1074public:
1076 private:
1077 using Iter_t = std::unordered_map<ROOT::DescriptorId_t, RClusterGroupDescriptor>::const_iterator;
1078 /// The wrapped map iterator
1080
1081 public:
1082 using iterator_category = std::forward_iterator_tag;
1085 using difference_type = std::ptrdiff_t;
1088
1089 RIterator(Iter_t iter) : fIter(iter) {}
1090 iterator &operator++() /* prefix */
1091 {
1092 ++fIter;
1093 return *this;
1094 }
1095 iterator operator++(int) /* postfix */
1096 {
1097 auto old = *this;
1098 operator++();
1099 return old;
1100 }
1101 reference operator*() const { return fIter->second; }
1102 pointer operator->() const { return &fIter->second; }
1103 bool operator!=(const iterator &rh) const { return fIter != rh.fIter; }
1104 bool operator==(const iterator &rh) const { return fIter == rh.fIter; }
1105 };
1106
1108 RIterator begin() { return RIterator(fNTuple.fClusterGroupDescriptors.cbegin()); }
1109 RIterator end() { return RIterator(fNTuple.fClusterGroupDescriptors.cend()); }
1110};
1111
1112// clang-format off
1113/**
1114\class ROOT::RNTupleDescriptor::RClusterDescriptorIterable
1115\ingroup NTuple
1116\brief Used to loop over all the clusters of an RNTuple (in unspecified order)
1117
1118Enumerate all cluster IDs from all cluster descriptors. No specific order can be assumed, use
1119RNTupleDescriptor::FindNextClusterId() and RNTupleDescriptor::FindPrevClusterId() to traverse
1120clusters by entry number.
1121*/
1122// clang-format on
1124private:
1125 /// The associated RNTuple for this range.
1127
1128public:
1130 private:
1131 using Iter_t = std::unordered_map<ROOT::DescriptorId_t, RClusterDescriptor>::const_iterator;
1132 /// The wrapped map iterator
1134
1135 public:
1136 using iterator_category = std::forward_iterator_tag;
1139 using difference_type = std::ptrdiff_t;
1142
1143 RIterator(Iter_t iter) : fIter(iter) {}
1144 iterator &operator++() /* prefix */
1145 {
1146 ++fIter;
1147 return *this;
1148 }
1149 iterator operator++(int) /* postfix */
1150 {
1151 auto old = *this;
1152 operator++();
1153 return old;
1154 }
1155 reference operator*() const { return fIter->second; }
1156 pointer operator->() const { return &fIter->second; }
1157 bool operator!=(const iterator &rh) const { return fIter != rh.fIter; }
1158 bool operator==(const iterator &rh) const { return fIter == rh.fIter; }
1159 };
1160
1162 RIterator begin() { return RIterator(fNTuple.fClusterDescriptors.cbegin()); }
1163 RIterator end() { return RIterator(fNTuple.fClusterDescriptors.cend()); }
1164};
1165
1166// clang-format off
1167/**
1168\class ROOT::RNTupleDescriptor::RExtraTypeInfoDescriptorIterable
1169\ingroup NTuple
1170\brief Used to loop over all the extra type info record of an RNTuple (in unspecified order)
1171*/
1172// clang-format on
1174private:
1175 /// The associated RNTuple for this range.
1177
1178public:
1180 private:
1181 using Iter_t = std::vector<RExtraTypeInfoDescriptor>::const_iterator;
1182 /// The wrapped vector iterator
1184
1185 public:
1186 using iterator_category = std::forward_iterator_tag;
1189 using difference_type = std::ptrdiff_t;
1192
1193 RIterator(Iter_t iter) : fIter(iter) {}
1194 iterator &operator++() /* prefix */
1195 {
1196 ++fIter;
1197 return *this;
1198 }
1199 iterator operator++(int) /* postfix */
1200 {
1201 auto old = *this;
1202 operator++();
1203 return old;
1204 }
1205 reference operator*() const { return *fIter; }
1206 pointer operator->() const { return &*fIter; }
1207 bool operator!=(const iterator &rh) const { return fIter != rh.fIter; }
1208 bool operator==(const iterator &rh) const { return fIter == rh.fIter; }
1209 };
1210
1212 RIterator begin() { return RIterator(fNTuple.fExtraTypeInfoDescriptors.cbegin()); }
1213 RIterator end() { return RIterator(fNTuple.fExtraTypeInfoDescriptors.cend()); }
1214};
1215
1216namespace Experimental {
1217// clang-format off
1218/**
1219\class ROOT::Experimental::RNTupleAttrSetDescriptorIterable
1220\ingroup NTuple
1221\brief Used to loop over all the Attribute Sets linked to an RNTuple
1222*/
1223// clang-format on
1224// TODO: move this to RNTupleDescriptor::RNTupleAttrSetDescriptorIterable when it moves out of Experimental.
1226private:
1227 /// The associated RNTuple for this range.
1229
1230public:
1232 private:
1233 using Iter_t = std::vector<RNTupleAttrSetDescriptor>::const_iterator;
1234 /// The wrapped vector iterator
1236
1237 public:
1238 using iterator_category = std::forward_iterator_tag;
1241 using difference_type = std::ptrdiff_t;
1242 using pointer = const value_type *;
1243 using reference = const value_type &;
1244
1245 RIterator(Iter_t iter) : fIter(iter) {}
1246 iterator &operator++() /* prefix */
1247 {
1248 ++fIter;
1249 return *this;
1250 }
1251 iterator operator++(int) /* postfix */
1252 {
1253 auto old = *this;
1254 operator++();
1255 return old;
1256 }
1257 reference operator*() const { return *fIter; }
1258 pointer operator->() const { return &*fIter; }
1259 bool operator!=(const iterator &rh) const { return fIter != rh.fIter; }
1260 bool operator==(const iterator &rh) const { return fIter == rh.fIter; }
1261 };
1262
1264 RIterator begin() { return RIterator(fNTuple.fAttributeSets.cbegin()); }
1265 RIterator end() { return RIterator(fNTuple.fAttributeSets.cend()); }
1266};
1267} // namespace Experimental
1268
1269// clang-format off
1270/**
1271\class ROOT::RNTupleDescriptor::RHeaderExtension
1272\ingroup NTuple
1273\brief Summarizes information about fields and the corresponding columns that were added after the header has been serialized
1274*/
1275// clang-format on
1278
1279private:
1280 /// All field IDs of late model extensions, in the order of field addition. This is necessary to serialize the
1281 /// the fields in that order.
1282 std::vector<ROOT::DescriptorId_t> fFieldIdsOrder;
1283 /// All field IDs of late model extensions for efficient lookup. When a column gets added to the extension
1284 /// header, this enables us to determine if the column belongs to a field of the header extension of if it
1285 /// belongs to a field of the regular header that gets extended by additional column representations.
1286 std::unordered_set<ROOT::DescriptorId_t> fFieldIdsLookup;
1287 /// All logical column IDs of columns that extend, with additional column representations, fields of the regular
1288 /// header. During serialization, these columns are not picked up as columns of `fFieldIdsOrder`. But instead
1289 /// these columns need to be serialized in the extension header without re-serializing the field.
1290 std::vector<ROOT::DescriptorId_t> fExtendedColumnRepresentations;
1291 /// Number of logical and physical columns; updated by the descriptor builder when columns are added
1292 std::uint32_t fNLogicalColumns = 0;
1293 std::uint32_t fNPhysicalColumns = 0;
1294
1295 /// Marks `fieldDesc` as an extended field, i.e. a field that appears in the Header Extension (e.g. having been added
1296 /// through late model extension). Note that the field descriptor should also have been added to the RNTuple
1297 /// Descriptor alongside non-extended fields.
1299 {
1300 fFieldIdsOrder.emplace_back(fieldDesc.GetId());
1301 fFieldIdsLookup.insert(fieldDesc.GetId());
1302 }
1303
1304 /// Marks `columnDesc` as an extended column, i.e. a column that appears in the Header Extension (e.g. having been
1305 /// added through late model extension as an additional representation of an existing column). Note that the column
1306 /// descriptor should also have been added to the RNTuple Descriptor alongside non-extended columns.
1308 {
1309 fNLogicalColumns++;
1310 if (!columnDesc.IsAliasColumn())
1311 fNPhysicalColumns++;
1312 if (fFieldIdsLookup.count(columnDesc.GetFieldId()) == 0) {
1313 fExtendedColumnRepresentations.emplace_back(columnDesc.GetLogicalId());
1314 }
1315 }
1316
1317public:
1318 std::size_t GetNFields() const { return fFieldIdsOrder.size(); }
1319 std::size_t GetNLogicalColumns() const { return fNLogicalColumns; }
1320 std::size_t GetNPhysicalColumns() const { return fNPhysicalColumns; }
1321 const std::vector<ROOT::DescriptorId_t> &GetExtendedColumnRepresentations() const
1322 {
1323 return fExtendedColumnRepresentations;
1324 }
1325 /// Return a vector containing the IDs of the top-level fields defined in the extension header, in the order
1326 /// of their addition. Note that these fields are not necessarily top-level fields in the overall schema.
1327 /// If a nested field is extended, it will return the top-most field of the extended subtree.
1328 /// We cannot create this vector when building the fFields because at the time when AddExtendedField is called,
1329 /// the field is not yet linked into the schema tree.
1330 std::vector<ROOT::DescriptorId_t> GetTopMostFields(const RNTupleDescriptor &desc) const;
1331
1333 {
1334 return fFieldIdsLookup.find(fieldId) != fFieldIdsLookup.end();
1335 }
1337 {
1338 return std::find(fExtendedColumnRepresentations.begin(), fExtendedColumnRepresentations.end(), columnId) !=
1339 fExtendedColumnRepresentations.end();
1340 }
1341};
1342
1343namespace Experimental::Internal {
1346
1347public:
1349 {
1350 fDesc.fName = name;
1351 return *this;
1352 }
1354 {
1355 fDesc.fSchemaVersionMajor = major;
1356 fDesc.fSchemaVersionMinor = minor;
1357 return *this;
1358 }
1360 {
1361 fDesc.fAnchorLocator = loc;
1362 return *this;
1363 }
1365 {
1366 fDesc.fAnchorLength = length;
1367 return *this;
1368 }
1369
1370 /// Attempt to make an AttributeSet descriptor. This may fail if the builder
1371 /// was not given enough information to make a proper descriptor.
1373};
1374} // namespace Experimental::Internal
1375
1376namespace Internal {
1377
1378// clang-format off
1379/**
1380\class ROOT::Internal::RColumnDescriptorBuilder
1381\ingroup NTuple
1382\brief A helper class for piece-wise construction of an RColumnDescriptor
1383
1384Dangling column descriptors can become actual descriptors when added to an
1385RNTupleDescriptorBuilder instance and then linked to their fields.
1386*/
1387// clang-format on
1389private:
1391
1392public:
1393 /// Make an empty column descriptor builder.
1395
1407 {
1408 fColumn.fBitsOnStorage = bitsOnStorage;
1409 return *this;
1410 }
1412 {
1413 fColumn.fType = type;
1414 return *this;
1415 }
1417 {
1418 fColumn.fFieldId = fieldId;
1419 return *this;
1420 }
1422 {
1423 fColumn.fIndex = index;
1424 return *this;
1425 }
1427 {
1429 return *this;
1430 }
1432 {
1433 R__ASSERT(fColumn.fFirstElementIndex != 0);
1434 if (fColumn.fFirstElementIndex > 0)
1435 fColumn.fFirstElementIndex = -fColumn.fFirstElementIndex;
1436 return *this;
1437 }
1439 {
1441 return *this;
1442 }
1443 RColumnDescriptorBuilder &ValueRange(double min, double max)
1444 {
1445 fColumn.fValueRange = {min, max};
1446 return *this;
1447 }
1448 RColumnDescriptorBuilder &ValueRange(std::optional<RColumnDescriptor::RValueRange> valueRange)
1449 {
1450 fColumn.fValueRange = valueRange;
1451 return *this;
1452 }
1453 ROOT::DescriptorId_t GetFieldId() const { return fColumn.fFieldId; }
1455 /// Attempt to make a column descriptor. This may fail if the column
1456 /// was not given enough information to make a proper descriptor.
1457 RResult<RColumnDescriptor> MakeDescriptor() const;
1458};
1459
1460// clang-format off
1461/**
1462\class ROOT::Internal::RFieldDescriptorBuilder
1463\ingroup NTuple
1464\brief A helper class for piece-wise construction of an RFieldDescriptor
1465
1466Dangling field descriptors describe a single field in isolation. They are
1467missing the necessary relationship information (parent field, any child fields)
1468required to describe a real RNTuple field.
1469
1470Dangling field descriptors can only become actual descriptors when added to an
1471RNTupleDescriptorBuilder instance and then linked to other fields.
1472*/
1473// clang-format on
1475private:
1477
1478public:
1479 /// Make an empty dangling field descriptor.
1481
1482 /// Make a new RFieldDescriptorBuilder based off a live RNTuple field.
1483 static RFieldDescriptorBuilder FromField(const ROOT::RFieldBase &field);
1484
1486 {
1487 fField.fFieldId = fieldId;
1488 return *this;
1489 }
1491 {
1492 fField.fFieldVersion = fieldVersion;
1493 return *this;
1494 }
1496 {
1497 fField.fTypeVersion = typeVersion;
1498 return *this;
1499 }
1501 {
1502 fField.fParentId = id;
1503 return *this;
1504 }
1506 {
1507 fField.fProjectionSourceId = id;
1508 return *this;
1509 }
1511 {
1512 fField.fFieldName = fieldName;
1513 return *this;
1514 }
1516 {
1518 return *this;
1519 }
1520 RFieldDescriptorBuilder &TypeName(const std::string &typeName)
1521 {
1522 fField.fTypeName = typeName;
1523 return *this;
1524 }
1526 {
1527 fField.fTypeAlias = typeAlias;
1528 return *this;
1529 }
1531 {
1532 fField.fNRepetitions = nRepetitions;
1533 return *this;
1534 }
1536 {
1537 fField.fStructure = structure;
1538 return *this;
1539 }
1540 RFieldDescriptorBuilder &TypeChecksum(const std::optional<std::uint32_t> typeChecksum)
1541 {
1542 fField.fTypeChecksum = typeChecksum;
1543 return *this;
1544 }
1546 {
1547 fField.fIsSoACollection = val;
1548 return *this;
1549 }
1550 ROOT::DescriptorId_t GetParentId() const { return fField.fParentId; }
1551 /// Attempt to make a field descriptor. This may fail if the dangling field
1552 /// was not given enough information to make a proper descriptor.
1553 RResult<RFieldDescriptor> MakeDescriptor() const;
1554};
1555
1556// clang-format off
1557/**
1558\class ROOT::Internal::RClusterDescriptorBuilder
1559\ingroup NTuple
1560\brief A helper class for piece-wise construction of an RClusterDescriptor
1561
1562The cluster descriptor builder starts from a summary-only cluster descriptor and allows for the
1563piecewise addition of page locations.
1564*/
1565// clang-format on
1567private:
1569
1570public:
1572 {
1573 fCluster.fClusterId = clusterId;
1574 return *this;
1575 }
1576
1578 {
1580 return *this;
1581 }
1582
1584 {
1585 fCluster.fNEntries = nEntries;
1586 return *this;
1587 }
1588
1589 RResult<void> CommitColumnRange(ROOT::DescriptorId_t physicalId, std::uint64_t firstElementIndex,
1591
1592 /// Books the given column ID as being suppressed in this cluster. The correct first element index and number of
1593 /// elements need to be set by CommitSuppressedColumnRanges() once all the calls to CommitColumnRange() and
1594 /// MarkSuppressedColumnRange() took place.
1595 RResult<void> MarkSuppressedColumnRange(ROOT::DescriptorId_t physicalId);
1596
1597 /// Sets the first element index and number of elements for all the suppressed column ranges.
1598 /// The information is taken from the corresponding columns from the primary representation.
1599 /// Needs to be called when all the columns (suppressed and regular) where added.
1600 RResult<void> CommitSuppressedColumnRanges(const RNTupleDescriptor &desc);
1601
1602 /// Add column and page ranges for columns created during late model extension missing in this cluster. The locator
1603 /// type for the synthesized page ranges is `kTypePageZero`. All the page sources must be able to populate the
1604 /// 'zero' page from such locator. Any call to CommitColumnRange() and CommitSuppressedColumnRanges()
1605 /// should happen before calling this function.
1606 RClusterDescriptorBuilder &AddExtendedColumnRanges(const RNTupleDescriptor &desc);
1607
1612
1613 /// Move out the full cluster descriptor including page locations
1614 RResult<RClusterDescriptor> MoveDescriptor();
1615};
1616
1617// clang-format off
1618/**
1619\class ROOT::Internal::RClusterGroupDescriptorBuilder
1620\ingroup NTuple
1621\brief A helper class for piece-wise construction of an RClusterGroupDescriptor
1622*/
1623// clang-format on
1625private:
1627
1628public:
1631
1643 {
1644 fClusterGroup.fPageListLength = pageListLength;
1645 return *this;
1646 }
1648 {
1649 fClusterGroup.fMinEntry = minEntry;
1650 return *this;
1651 }
1653 {
1654 fClusterGroup.fEntrySpan = entrySpan;
1655 return *this;
1656 }
1658 {
1659 fClusterGroup.fNClusters = nClusters;
1660 return *this;
1661 }
1662 void AddSortedClusters(const std::vector<ROOT::DescriptorId_t> &clusterIds)
1663 {
1664 if (clusterIds.size() != fClusterGroup.GetNClusters())
1665 throw RException(R__FAIL("mismatch of number of clusters"));
1666 fClusterGroup.fClusterIds = clusterIds;
1667 }
1668
1669 RResult<RClusterGroupDescriptor> MoveDescriptor();
1670};
1671
1672// clang-format off
1673/**
1674\class ROOT::Internal::RExtraTypeInfoDescriptorBuilder
1675\ingroup NTuple
1676\brief A helper class for piece-wise construction of an RExtraTypeInfoDescriptor
1677*/
1678// clang-format on
1680private:
1682
1683public:
1685
1687 {
1688 fExtraTypeInfo.fContentId = contentId;
1689 return *this;
1690 }
1692 {
1693 fExtraTypeInfo.fTypeVersion = typeVersion;
1694 return *this;
1695 }
1696 RExtraTypeInfoDescriptorBuilder &TypeName(const std::string &typeName)
1697 {
1698 fExtraTypeInfo.fTypeName = typeName;
1699 return *this;
1700 }
1702 {
1703 fExtraTypeInfo.fContent = content;
1704 return *this;
1705 }
1706
1707 RResult<RExtraTypeInfoDescriptor> MoveDescriptor();
1708};
1709
1710// clang-format off
1711/**
1712\class ROOT::Internal::RNTupleDescriptorBuilder
1713\ingroup NTuple
1714\brief A helper class for piece-wise construction of an RNTupleDescriptor
1715
1716Used by RPageStorage implementations in order to construct the RNTupleDescriptor from the various header parts.
1717*/
1718// clang-format on
1720private:
1722 RResult<void> EnsureFieldExists(ROOT::DescriptorId_t fieldId) const;
1723
1724public:
1725 /// Checks whether invariants hold:
1726 /// * RNTuple epoch is valid
1727 /// * RNTuple name is valid
1728 /// * Fields have valid parents
1729 /// * Number of columns is constant across column representations
1730 RResult<void> EnsureValidDescriptor() const;
1731 const RNTupleDescriptor &GetDescriptor() const { return fDescriptor; }
1732 RNTupleDescriptor MoveDescriptor();
1733
1734 /// Copies the "schema" part of `descriptor` into the builder's descriptor.
1735 /// This resets the builder's descriptor.
1736 void SetSchemaFromExisting(const RNTupleDescriptor &descriptor);
1737
1738 void SetVersion(std::uint16_t versionEpoch, std::uint16_t versionMajor, std::uint16_t versionMinor,
1739 std::uint16_t versionPatch);
1740 void SetVersionForWriting();
1741
1742 void SetNTuple(const std::string_view name, const std::string_view description);
1743 void SetFeature(unsigned int flag);
1744
1745 void SetOnDiskHeaderXxHash3(std::uint64_t xxhash3) { fDescriptor.fOnDiskHeaderXxHash3 = xxhash3; }
1746 void SetOnDiskHeaderSize(std::uint64_t size) { fDescriptor.fOnDiskHeaderSize = size; }
1747 /// The real footer size also include the page list envelopes
1748 void AddToOnDiskFooterSize(std::uint64_t size) { fDescriptor.fOnDiskFooterSize += size; }
1749
1750 void AddField(const RFieldDescriptor &fieldDesc);
1753
1754 // The field that the column belongs to has to be already available. For fields with multiple columns,
1755 // the columns need to be added in order of the column index
1757
1760
1762 void ReplaceExtraTypeInfo(RExtraTypeInfoDescriptor &&extraTypeInfoDesc);
1763
1765
1766 /// Mark the beginning of the header extension; any fields and columns added after a call to this function are
1767 /// annotated as begin part of the header extension.
1768 void BeginHeaderExtension();
1769
1770 /// \brief Shift column IDs of alias columns by `offset`
1771 ///
1772 /// If the descriptor is constructed in pieces consisting of physical and alias columns
1773 /// (regular and projected fields), the natural column order would be
1774 /// - Physical and alias columns of piece one
1775 /// - Physical and alias columns of piece two
1776 /// - etc.
1777 /// What we want, however, are first all physical column IDs and then all alias column IDs.
1778 /// This method adds `offset` to the logical column IDs of all alias columns and fixes up the corresponding
1779 /// column IDs in the projected field descriptors. In this way, a new piece of physical and alias columns can
1780 /// first shift the existing alias columns by the number of new physical columns, resulting in the following order
1781 /// - Physical columns of piece one
1782 /// - Physical columns of piece two
1783 /// - ...
1784 // - Logical columns of piece one
1785 /// - Logical columns of piece two
1786 /// - ...
1787 void ShiftAliasColumns(std::uint32_t offset);
1788};
1789
1791{
1792 return desc.CloneSchema();
1793}
1794
1795/// Tells if the field describes a user-defined enum type.
1796/// The dictionary does not need to be available for this method.
1797/// Needs the full descriptor to look up sub fields.
1799
1800/// Tells if the field describes a std::atomic<T> type
1802
1803} // namespace Internal
1804
1805} // namespace ROOT
1806
1807#endif // ROOT_RNTupleDescriptor
#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:300
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:102
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:157
The available trivial, native content types of a column.
RNTupleAttrSetDescriptorBuilder & AnchorLocator(const RNTupleLocator &loc)
RNTupleAttrSetDescriptorBuilder & SchemaVersion(std::uint16_t major, std::uint16_t minor)
RNTupleAttrSetDescriptorBuilder & Name(std::string_view name)
RNTupleAttrSetDescriptorBuilder & AnchorLength(std::uint32_t length)
std::vector< RNTupleAttrSetDescriptor >::const_iterator Iter_t
Used to loop over all the Attribute Sets linked to an RNTuple.
const RNTupleDescriptor & fNTuple
The associated RNTuple for this range.
RNTupleAttrSetDescriptorIterable(const RNTupleDescriptor &ntuple)
Metadata stored for every Attribute Set linked to an RNTuple.
RNTupleAttrSetDescriptor & operator=(const RNTupleAttrSetDescriptor &other)=delete
bool operator==(const RNTupleAttrSetDescriptor &other) const
std::uint32_t fAnchorLength
uncompressed size of the linked anchor
RNTupleAttrSetDescriptor(const RNTupleAttrSetDescriptor &other)=delete
RNTupleAttrSetDescriptor & operator=(RNTupleAttrSetDescriptor &&other)=default
const RNTupleLocator & GetAnchorLocator() const
bool operator!=(const RNTupleAttrSetDescriptor &other) const
RNTupleAttrSetDescriptor(RNTupleAttrSetDescriptor &&other)=default
A helper class for piece-wise construction of an RClusterDescriptor.
RClusterDescriptorBuilder & NEntries(std::uint64_t nEntries)
const RClusterDescriptor::RColumnRange & GetColumnRange(ROOT::DescriptorId_t physicalId)
RClusterDescriptorBuilder & ClusterId(ROOT::DescriptorId_t clusterId)
RClusterDescriptorBuilder & FirstEntryIndex(std::uint64_t firstEntryIndex)
A helper class for piece-wise construction of an RClusterGroupDescriptor.
RClusterGroupDescriptorBuilder & EntrySpan(std::uint64_t entrySpan)
RClusterGroupDescriptorBuilder & PageListLocator(const RNTupleLocator &pageListLocator)
RClusterGroupDescriptorBuilder & PageListLength(std::uint64_t pageListLength)
RClusterGroupDescriptorBuilder & MinEntry(std::uint64_t minEntry)
void AddSortedClusters(const std::vector< ROOT::DescriptorId_t > &clusterIds)
RClusterGroupDescriptorBuilder & ClusterGroupId(ROOT::DescriptorId_t clusterGroupId)
RClusterGroupDescriptorBuilder & NClusters(std::uint32_t nClusters)
A helper class for piece-wise construction of an RColumnDescriptor.
ROOT::DescriptorId_t GetRepresentationIndex() const
RColumnDescriptorBuilder & SetSuppressedDeferred()
RColumnDescriptorBuilder & LogicalColumnId(ROOT::DescriptorId_t logicalColumnId)
RColumnDescriptorBuilder & FieldId(ROOT::DescriptorId_t fieldId)
RColumnDescriptorBuilder & BitsOnStorage(std::uint16_t bitsOnStorage)
RColumnDescriptorBuilder & ValueRange(double min, double max)
RColumnDescriptorBuilder()=default
Make an empty column descriptor builder.
RColumnDescriptorBuilder & ValueRange(std::optional< RColumnDescriptor::RValueRange > valueRange)
RColumnDescriptorBuilder & Type(ROOT::ENTupleColumnType type)
RColumnDescriptorBuilder & PhysicalColumnId(ROOT::DescriptorId_t physicalColumnId)
RColumnDescriptorBuilder & FirstElementIndex(std::uint64_t firstElementIdx)
RColumnDescriptorBuilder & Index(std::uint32_t index)
RColumnDescriptorBuilder & RepresentationIndex(std::uint16_t representationIndex)
A column element encapsulates the translation between basic C++ types and their column representation...
A helper class for piece-wise construction of an RExtraTypeInfoDescriptor.
RExtraTypeInfoDescriptorBuilder & ContentId(EExtraTypeInfoIds contentId)
RExtraTypeInfoDescriptorBuilder & TypeName(const std::string &typeName)
RExtraTypeInfoDescriptorBuilder & Content(const std::string &content)
RExtraTypeInfoDescriptorBuilder & TypeVersion(std::uint32_t typeVersion)
A helper class for piece-wise construction of an RFieldDescriptor.
RFieldDescriptorBuilder & NRepetitions(std::uint64_t nRepetitions)
RFieldDescriptorBuilder & Structure(const ROOT::ENTupleStructure &structure)
RFieldDescriptorBuilder()=default
Make an empty dangling field descriptor.
RFieldDescriptorBuilder & TypeAlias(const std::string &typeAlias)
RFieldDescriptorBuilder & ProjectionSourceId(ROOT::DescriptorId_t id)
RFieldDescriptorBuilder & TypeVersion(std::uint32_t typeVersion)
RFieldDescriptorBuilder & IsSoACollection(bool val)
RFieldDescriptorBuilder & TypeChecksum(const std::optional< std::uint32_t > typeChecksum)
RFieldDescriptorBuilder & ParentId(ROOT::DescriptorId_t id)
RFieldDescriptorBuilder & FieldDescription(const std::string &fieldDescription)
RFieldDescriptorBuilder & FieldVersion(std::uint32_t fieldVersion)
RFieldDescriptorBuilder & FieldName(const std::string &fieldName)
RFieldDescriptorBuilder & FieldId(ROOT::DescriptorId_t fieldId)
RFieldDescriptorBuilder & TypeName(const std::string &typeName)
A helper class for piece-wise construction of an RNTupleDescriptor.
const RNTupleDescriptor & GetDescriptor() const
void SetOnDiskHeaderXxHash3(std::uint64_t xxhash3)
void AddToOnDiskFooterSize(std::uint64_t size)
The real footer size also include the page list envelopes.
std::unordered_map< ROOT::DescriptorId_t, RColumnRange >::const_iterator Iter_t
RColumnRangeIterable(const RClusterDescriptor &desc)
The window of element indexes of a particular column in a particular cluster.
void SetCompressionSettings(std::optional< std::uint32_t > comp)
void SetPhysicalColumnId(ROOT::DescriptorId_t id)
ROOT::DescriptorId_t GetPhysicalColumnId() const
bool operator==(const RColumnRange &other) const
void SetFirstElementIndex(ROOT::NTupleSize_t idx)
std::optional< std::uint32_t > GetCompressionSettings() const
std::optional< std::uint32_t > fCompressionSettings
The usual format for ROOT compression settings (see Compression.h).
ROOT::NTupleSize_t GetFirstElementIndex() const
RColumnRange(ROOT::DescriptorId_t physicalColumnId, ROOT::NTupleSize_t firstElementIndex, ROOT::NTupleSize_t nElements, std::optional< std::uint32_t > compressionSettings, bool suppressed=false)
void IncrementFirstElementIndex(ROOT::NTupleSize_t by)
bool Contains(ROOT::NTupleSize_t index) const
void IncrementNElements(ROOT::NTupleSize_t by)
Records the partition of data into pages for a particular column in a particular cluster.
RPageRange & operator=(const RPageRange &other)=delete
std::unique_ptr< std::vector< ROOT::NTupleSize_t > > fCumulativeNElements
Has the same length than fPageInfos and stores the sum of the number of elements of all the pages up ...
RPageRange(RPageRange &&other)=default
RPageRange(const RPageRange &other)=delete
const std::vector< RPageInfo > & GetPageInfos() const
bool operator==(const RPageRange &other) const
ROOT::DescriptorId_t GetPhysicalColumnId() const
void SetPhysicalColumnId(ROOT::DescriptorId_t id)
RPageRange & operator=(RPageRange &&other)=default
std::vector< RPageInfo > & GetPageInfos()
Metadata for RNTuple clusters.
ROOT::NTupleSize_t GetNEntries() const
ROOT::NTupleSize_t fFirstEntryIndex
Clusters can be swapped by adjusting the entry offsets of the cluster and all ranges.
RClusterDescriptor & operator=(const RClusterDescriptor &other)=delete
ROOT::DescriptorId_t GetId() const
const RPageRange & GetPageRange(ROOT::DescriptorId_t physicalId) const
RClusterDescriptor(RClusterDescriptor &&other)=default
std::unordered_map< ROOT::DescriptorId_t, RColumnRange > fColumnRanges
ROOT::DescriptorId_t fClusterId
bool ContainsColumn(ROOT::DescriptorId_t physicalId) const
RClusterDescriptor & operator=(RClusterDescriptor &&other)=default
const RColumnRange & GetColumnRange(ROOT::DescriptorId_t physicalId) const
ROOT::NTupleSize_t GetFirstEntryIndex() const
std::unordered_map< ROOT::DescriptorId_t, RPageRange > fPageRanges
RClusterDescriptor(const RClusterDescriptor &other)=delete
Clusters are bundled in cluster groups.
RNTupleLocator fPageListLocator
The page list that corresponds to the cluster group.
RClusterGroupDescriptor & operator=(const RClusterGroupDescriptor &other)=delete
std::vector< ROOT::DescriptorId_t > fClusterIds
The cluster IDs can be empty if the corresponding page list is not loaded.
ROOT::DescriptorId_t GetId() const
RClusterGroupDescriptor(RClusterGroupDescriptor &&other)=default
std::uint64_t fMinEntry
The minimum first entry number of the clusters in the cluster group.
bool HasClusterDetails() const
A cluster group is loaded in two stages.
std::uint32_t fNClusters
Number of clusters is always known even if the cluster IDs are not (yet) populated.
RClusterGroupDescriptor & operator=(RClusterGroupDescriptor &&other)=default
const std::vector< ROOT::DescriptorId_t > & GetClusterIds() const
std::uint64_t fPageListLength
Uncompressed size of the page list.
std::uint64_t GetPageListLength() const
RNTupleLocator GetPageListLocator() const
RClusterGroupDescriptor(const RClusterGroupDescriptor &other)=delete
std::uint64_t fEntrySpan
Number of entries that are (partially for sharded clusters) covered by this cluster group.
Metadata stored for every column of an RNTuple.
std::optional< RValueRange > GetValueRange() const
ROOT::DescriptorId_t fPhysicalColumnId
Usually identical to the logical column ID, except for alias columns where it references the shadowed...
ROOT::DescriptorId_t fLogicalColumnId
The actual column identifier, which is the link to the corresponding field.
RColumnDescriptor(const RColumnDescriptor &other)=delete
std::uint64_t GetFirstElementIndex() const
ROOT::DescriptorId_t fFieldId
Every column belongs to one and only one field.
std::int64_t fFirstElementIndex
The absolute value specifies the index for the first stored element for this column.
ROOT::DescriptorId_t GetFieldId() const
RColumnDescriptor(RColumnDescriptor &&other)=default
std::uint32_t fIndex
A field can be serialized into several columns, which are numbered from zero to $n$.
RColumnDescriptor & operator=(RColumnDescriptor &&other)=default
std::uint32_t GetIndex() const
std::uint16_t fBitsOnStorage
The size in bits of elements of this column.
std::uint16_t fRepresentationIndex
A field may use multiple column representations, which are numbered from zero to $m$.
ROOT::ENTupleColumnType fType
The on-disk column type.
ROOT::ENTupleColumnType GetType() const
ROOT::DescriptorId_t GetPhysicalId() const
std::uint16_t GetRepresentationIndex() const
std::optional< RValueRange > fValueRange
Optional value range (used e.g. by quantized real fields)
std::uint16_t GetBitsOnStorage() const
RColumnDescriptor & operator=(const RColumnDescriptor &other)=delete
ROOT::DescriptorId_t GetLogicalId() const
Base class for all ROOT issued exceptions.
Definition RError.hxx:79
Field specific extra type information from the header / extenstion header.
RExtraTypeInfoDescriptor & operator=(RExtraTypeInfoDescriptor &&other)=default
RExtraTypeInfoDescriptor & operator=(const RExtraTypeInfoDescriptor &other)=delete
RExtraTypeInfoDescriptor(const RExtraTypeInfoDescriptor &other)=delete
EExtraTypeInfoIds fContentId
Specifies the meaning of the extra information.
std::string fTypeName
The type name the extra information refers to; empty for RNTuple-wide extra information.
std::string fContent
The content format depends on the content ID and may be binary.
const std::string & GetContent() const
const std::string & GetTypeName() const
RExtraTypeInfoDescriptor(RExtraTypeInfoDescriptor &&other)=default
EExtraTypeInfoIds GetContentId() const
std::uint32_t fTypeVersion
Type version the extra type information is bound to.
A field translates read and write calls from/to underlying columns to/from tree values.
Metadata stored for every field of an RNTuple.
const std::string & GetTypeAlias() const
std::unique_ptr< ROOT::RFieldBase > CreateField(const RNTupleDescriptor &ntplDesc, const ROOT::RCreateFieldOptions &options={}) const
In general, we create a field simply from the C++ type name.
std::uint32_t fFieldVersion
The version of the C++-type-to-column translation mechanics.
ROOT::DescriptorId_t fFieldId
RFieldDescriptor Clone() const
Get a copy of the descriptor.
ROOT::DescriptorId_t GetId() const
std::uint64_t fNRepetitions
The number of elements per entry for fixed-size arrays.
std::uint32_t GetFieldVersion() const
const std::vector< ROOT::DescriptorId_t > & GetLogicalColumnIds() const
std::uint32_t fColumnCardinality
The number of columns in the column representations of the field.
ROOT::DescriptorId_t fProjectionSourceId
For projected fields, the source field ID.
bool IsCustomEnum(const RNTupleDescriptor &desc) const R__DEPRECATED(6
ROOT::ENTupleStructure GetStructure() const
bool operator==(const RFieldDescriptor &other) const
RFieldDescriptor(const RFieldDescriptor &other)=delete
bool IsCustomClass() const R__DEPRECATED(6
std::uint32_t GetColumnCardinality() const
bool IsStdAtomic() const R__DEPRECATED(6
std::string fFieldDescription
Free text set by the user.
RFieldDescriptor & operator=(const RFieldDescriptor &other)=delete
RFieldDescriptor & operator=(RFieldDescriptor &&other)=default
const std::vector< ROOT::DescriptorId_t > & GetLinkIds() const
ROOT::DescriptorId_t fParentId
Establishes sub field relationships, such as classes and collections.
ROOT::DescriptorId_t GetParentId() const
std::string fTypeAlias
A typedef or using directive that resolved to the type name during field creation.
ROOT::ENTupleStructure fStructure
The structural information carried by this field in the data model tree.
std::uint64_t GetNRepetitions() const
RFieldDescriptor(RFieldDescriptor &&other)=default
std::vector< ROOT::DescriptorId_t > fLinkIds
The pointers in the other direction from parent to children.
std::string fFieldName
The leaf name, not including parent fields.
const std::string & GetFieldDescription() const
std::optional< std::uint32_t > GetTypeChecksum() const
ROOT::DescriptorId_t GetProjectionSourceId() const
bool fIsSoACollection
Indicates if this is a collection that should be represented in memory by a SoA layout.
std::uint32_t fTypeVersion
The version of the C++ type itself.
std::string fTypeName
The C++ type that was used when writing the field.
std::uint32_t GetTypeVersion() const
const std::string & GetFieldName() const
std::vector< ROOT::DescriptorId_t > fLogicalColumnIds
The ordered list of columns attached to this field: first by representation index then by column inde...
const std::string & GetTypeName() const
std::optional< std::uint32_t > fTypeChecksum
For custom classes, we store the ROOT TClass reported checksum to facilitate the use of I/O rules tha...
std::unordered_map< ROOT::DescriptorId_t, RClusterDescriptor >::const_iterator Iter_t
Used to loop over all the clusters of an RNTuple (in unspecified order)
const RNTupleDescriptor & fNTuple
The associated RNTuple for this range.
RClusterDescriptorIterable(const RNTupleDescriptor &ntuple)
std::unordered_map< ROOT::DescriptorId_t, RClusterGroupDescriptor >::const_iterator Iter_t
Used to loop over all the cluster groups of an RNTuple (in unspecified order)
const RNTupleDescriptor & fNTuple
The associated RNTuple for this range.
const RNTupleDescriptor & fNTuple
The enclosing range's RNTuple.
const std::vector< ROOT::DescriptorId_t > & fColumns
The enclosing range's descriptor id list.
RIterator(const RNTupleDescriptor &ntuple, const std::vector< ROOT::DescriptorId_t > &columns, std::size_t index)
Used to loop over a field's associated columns.
const RNTupleDescriptor & fNTuple
The associated RNTuple for this range.
std::vector< RExtraTypeInfoDescriptor >::const_iterator Iter_t
Used to loop over all the extra type info record of an RNTuple (in unspecified order)
const RNTupleDescriptor & fNTuple
The associated RNTuple for this range.
RIterator(const RNTupleDescriptor &ntuple, const std::vector< ROOT::DescriptorId_t > &fieldChildren, std::size_t index)
const std::vector< ROOT::DescriptorId_t > & fFieldChildren
The enclosing range's descriptor id list.
const RNTupleDescriptor & fNTuple
The enclosing range's RNTuple.
Used to loop over a field's child fields.
const RNTupleDescriptor & fNTuple
The associated RNTuple for this range.
RFieldDescriptorIterable(const RNTupleDescriptor &ntuple, const RFieldDescriptor &field, const std::function< bool(ROOT::DescriptorId_t, ROOT::DescriptorId_t)> &comparator)
Sort the range using an arbitrary comparison function.
RFieldDescriptorIterable(const RNTupleDescriptor &ntuple, const RFieldDescriptor &field)
Summarizes information about fields and the corresponding columns that were added after the header ha...
const std::vector< ROOT::DescriptorId_t > & GetExtendedColumnRepresentations() const
std::unordered_set< ROOT::DescriptorId_t > fFieldIdsLookup
All field IDs of late model extensions for efficient lookup.
std::vector< ROOT::DescriptorId_t > fExtendedColumnRepresentations
All logical column IDs of columns that extend, with additional column representations,...
bool ContainsExtendedColumnRepresentation(ROOT::DescriptorId_t columnId) const
void MarkExtendedField(const RFieldDescriptor &fieldDesc)
Marks fieldDesc as an extended field, i.e.
std::vector< ROOT::DescriptorId_t > fFieldIdsOrder
All field IDs of late model extensions, in the order of field addition.
bool ContainsField(ROOT::DescriptorId_t fieldId) const
void MarkExtendedColumn(const RColumnDescriptor &columnDesc)
Marks columnDesc as an extended column, i.e.
The on-storage metadata of an RNTuple.
std::uint64_t GetGeneration() const
RNTupleDescriptor(RNTupleDescriptor &&other)=default
const RClusterGroupDescriptor & GetClusterGroupDescriptor(ROOT::DescriptorId_t clusterGroupId) const
const RColumnDescriptor & GetColumnDescriptor(ROOT::DescriptorId_t columnId) const
std::set< unsigned int > fFeatureFlags
std::unordered_map< ROOT::DescriptorId_t, RClusterGroupDescriptor > fClusterGroupDescriptors
const RFieldDescriptor & GetFieldDescriptor(ROOT::DescriptorId_t fieldId) const
RNTupleDescriptor & operator=(RNTupleDescriptor &&other)=default
std::vector< Experimental::RNTupleAttrSetDescriptor > fAttributeSets
List of AttributeSets linked to this RNTuple.
std::size_t GetNExtraTypeInfos() const
std::uint64_t GetOnDiskFooterSize() const
std::size_t GetNActiveClusters() const
const std::string & GetName() const
std::uint64_t fOnDiskFooterSize
Like fOnDiskHeaderSize, contains both cluster summaries and page locations.
ROOT::NTupleSize_t GetNEntries() const
We know the number of entries from adding the cluster summaries.
ROOT::DescriptorId_t GetFieldZeroId() const
Returns the logical parent of all top-level RNTuple data fields.
std::unordered_map< ROOT::DescriptorId_t, RClusterDescriptor > fClusterDescriptors
Potentially a subset of all the available clusters.
std::size_t GetNAttributeSets() const
std::size_t GetNClusters() const
std::size_t GetNPhysicalColumns() const
const RHeaderExtension * GetHeaderExtension() const
Return header extension information; if the descriptor does not have a header extension,...
std::uint64_t GetVersion() const
std::uint64_t fOnDiskHeaderXxHash3
Set by the descriptor builder when deserialized.
const RClusterDescriptor & GetClusterDescriptor(ROOT::DescriptorId_t clusterId) const
std::string fName
The RNTuple name needs to be unique in a given storage location (file)
RNTupleDescriptor(const RNTupleDescriptor &other)=delete
std::uint64_t fOnDiskHeaderSize
Set by the descriptor builder when deserialized.
std::uint64_t GetOnDiskHeaderXxHash3() const
std::vector< ROOT::DescriptorId_t > fSortedClusterGroupIds
References cluster groups sorted by entry range and thus allows for binary search.
std::unordered_map< ROOT::DescriptorId_t, RColumnDescriptor > fColumnDescriptors
std::unordered_map< ROOT::DescriptorId_t, RFieldDescriptor > fFieldDescriptors
std::size_t GetNFields() const
bool HasFeature(unsigned int flag) const
std::uint64_t GetOnDiskHeaderSize() const
std::string fDescription
Free text from the user.
std::vector< RExtraTypeInfoDescriptor > fExtraTypeInfoDescriptors
std::size_t GetNLogicalColumns() const
RNTupleDescriptor & operator=(const RNTupleDescriptor &other)=delete
std::size_t GetNClusterGroups() const
RNTupleDescriptor CloneSchema() const
Creates a descriptor containing only the schema information about this RNTuple, i....
const std::string & GetDescription() const
std::unique_ptr< RHeaderExtension > fHeaderExtension
const RFieldDescriptor & GetFieldZero() const
Generic information about the physical location of data.
const Int_t n
Definition legend1.C:16
RNTupleDescriptor CloneDescriptorSchema(const RNTupleDescriptor &desc)
bool IsCustomEnumFieldDesc(const RNTupleDescriptor &desc, const RFieldDescriptor &fieldDesc)
Tells if the field describes a user-defined enum type.
std::vector< ROOT::Internal::RNTupleClusterBoundaries > GetClusterBoundaries(const RNTupleDescriptor &desc)
Return the cluster boundaries for each cluster in this RNTuple.
bool IsStdAtomicFieldDesc(const RFieldDescriptor &fieldDesc)
Tells if the field describes a std::atomic<T> type.
EExtraTypeInfoIds
Used in RExtraTypeInfoDescriptor.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr NTupleSize_t kInvalidNTupleIndex
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
ENTupleStructure
The fields in the RNTuple data model tree can carry different structural information about the type s...
Additional information about a page in an in-memory RPageRange.
RPageInfoExtended(const RPageInfo &pageInfo, ROOT::NTupleSize_t firstElementIndex, ROOT::NTupleSize_t pageNumber)
void SetFirstElementIndex(ROOT::NTupleSize_t firstInPage)
void SetPageNumber(ROOT::NTupleSize_t pageNumber)
Information about a single page in the context of a cluster's page range.
void SetLocator(const RNTupleLocator &locator)
bool operator==(const RPageInfo &other) const
const RNTupleLocator & GetLocator() const
RNTupleLocator fLocator
The meaning of fLocator depends on the storage backend.
RPageInfo(std::uint32_t nElements, const RNTupleLocator &locator, bool hasChecksum)
bool operator==(RValueRange other) const
RValueRange(std::pair< double, double > range)
bool operator!=(RValueRange other) const
static void output()