Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleDSFields.hxx
Go to the documentation of this file.
1/// \file RNTupleDSFields.cxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \author Enrico Guiraud <enrico.guiraud@cern.ch>
4/// \date 2026-09-23
5
6#include <ROOT/RFieldBase.hxx>
7
8// clang-format off
9/**
10 * \class ROOT::Internal::RDF::RRDFCardinalityFieldBase
11 * \ingroup dataframe
12 * \brief Base for an artificial field that transforms an RNTuple column containing the offset of collections into collection sizes.
13 *
14 * It is used to provide the "number of" RDF columns for collections, e.g. `R_rdf_sizeof_jets` for a collection named `jets`.
15 */
16// clang-format on
17namespace ROOT::Internal::RDF {
19protected:
20 // We construct these fields and know that they match the page source
22
23 RRDFCardinalityFieldBase(std::string_view name, std::string_view type)
24 : ROOT::RFieldBase(name, type, ROOT::ENTupleStructure::kPlain, false /* isSimple */)
25 {
26 }
27
28 // Field is only used for reading
29 void GenerateColumns() final { throw RException(R__FAIL("Cardinality fields must only be used for reading")); }
31 {
32 GenerateColumnsImpl<ROOT::Internal::RColumnIndex>(desc);
33 }
34
35public:
40 ~RRDFCardinalityFieldBase() override = default;
41
43 {
44 static const RColumnRepresentations representations({{ENTupleColumnType::kSplitIndex64},
48 {});
49 return representations;
50 }
51};
52
53// clang-format off
54/**
55 * \class ROOT::Internal::RDF::RRDFCardinalityField
56 * \ingroup dataframe
57 * \brief An artificial field that transforms an RNTuple column containing the offset of collections into collection sizes.
58 *
59 * It is used to provide the "number of" RDF columns for collections, e.g. `R_rdf_sizeof_jets` for a collection named `jets`.
60 *
61 * This is similar to the RCardinalityField but it presents itself as an integer type.
62 * The template argument T must be an integral type.
63 */
64// clang-format on
65template <typename T>
67 static_assert(std::is_integral_v<T>, "T must be an integral type");
68
70 {
71 if constexpr (std::is_same_v<T, bool> || std::is_same_v<T, std::uint64_t>)
72 return;
73 if (size > static_cast<ROOT::NTupleSize_t>(std::numeric_limits<T>::max())) {
74 throw RException(R__FAIL(std::string("integer overflow in field ") + GetFieldName() +
75 ". Please read the column with a larger-sized integral type."));
76 }
77 }
78
79protected:
80 std::unique_ptr<ROOT::RFieldBase> CloneImpl(std::string_view newName) const final
81 {
82 return std::make_unique<RRDFCardinalityField>(newName);
83 }
84 void ConstructValue(void *where) const final { *static_cast<T *>(where) = 0; }
85
86public:
87 RRDFCardinalityField(std::string_view name)
88 : RRDFCardinalityFieldBase(name, ROOT::Internal::GetRenormalizedTypeName(typeid(T)))
89 {
90 }
95 ~RRDFCardinalityField() override = default;
96
97 std::size_t GetValueSize() const final { return sizeof(T); }
98 std::size_t GetAlignment() const final { return alignof(T); }
99
100 /// Get the number of elements of the collection identified by globalIndex
101 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
102 {
103 RNTupleLocalIndex collectionStart;
105 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &size);
107 *static_cast<T *>(to) = size;
108 }
109
110 /// Get the number of elements of the collection identified by clusterIndex
111 void ReadInClusterImpl(ROOT::RNTupleLocalIndex localIndex, void *to) final
112 {
113 RNTupleLocalIndex collectionStart;
115 fPrincipalColumn->GetCollectionInfo(localIndex, &collectionStart, &size);
117 *static_cast<T *>(to) = size;
118 }
119};
120
121// clang-format off
122/**
123 * \class ROOT::Internal::RDF::RArraySizeField
124 * \ingroup dataframe
125 * \brief An artificial field that provides the size of a fixed-size array
126 *
127 * This is the implementation of `R_rdf_sizeof_column` in case `column` contains
128 * fixed-size arrays on disk.
129 */
130// clang-format on
131class RArraySizeField final : public ROOT::RFieldBase {
132private:
133 std::size_t fArrayLength;
134
135 std::unique_ptr<ROOT::RFieldBase> CloneImpl(std::string_view newName) const final
136 {
137 return std::make_unique<RArraySizeField>(newName, fArrayLength);
138 }
139 void GenerateColumns() final { throw RException(R__FAIL("RArraySizeField fields must only be used for reading")); }
141 void ReadGlobalImpl(ROOT::NTupleSize_t /*globalIndex*/, void *to) final
142 {
143 *static_cast<std::size_t *>(to) = fArrayLength;
144 }
145 void ReadInClusterImpl(RNTupleLocalIndex /*localIndex*/, void *to) final
146 {
147 *static_cast<std::size_t *>(to) = fArrayLength;
148 }
149
150 // We construct these fields and know that they match the page source
152
153public:
154 RArraySizeField(std::string_view name, std::size_t arrayLength)
155 : ROOT::RFieldBase(name, ROOT::Internal::GetRenormalizedTypeName(typeid(std::size_t)),
156 ROOT::ENTupleStructure::kPlain, false /* isSimple */),
157 fArrayLength(arrayLength)
158 {
159 }
160 RArraySizeField(const RArraySizeField &other) = delete;
164 ~RArraySizeField() final = default;
165
166 void ConstructValue(void *where) const final { *static_cast<std::size_t *>(where) = 0; }
167 std::size_t GetValueSize() const final { return sizeof(std::size_t); }
168 std::size_t GetAlignment() const final { return alignof(std::size_t); }
169};
170} // namespace ROOT::Internal::RDF
#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:322
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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:142
void GetCollectionInfo(const ROOT::NTupleSize_t globalIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *collectionSize)
For offset columns only, look at the two adjacent values that define a collection's coordinates.
Definition RColumn.hxx:282
An artificial field that provides the size of a fixed-size array.
void GenerateColumns(const ROOT::RNTupleDescriptor &) final
Implementations in derived classes should create the backing columns corresponding to the field type ...
void ReadGlobalImpl(ROOT::NTupleSize_t, void *to) final
RArraySizeField(const RArraySizeField &other)=delete
RArraySizeField(RArraySizeField &&other)=default
RArraySizeField & operator=(RArraySizeField &&other)=default
RArraySizeField(std::string_view name, std::size_t arrayLength)
void ReadInClusterImpl(RNTupleLocalIndex, void *to) final
void ReconcileOnDiskField(const RNTupleDescriptor &) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
RArraySizeField & operator=(const RArraySizeField &other)=delete
std::size_t GetAlignment() const final
What alignof(T) for this type returns.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
std::unique_ptr< ROOT::RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
Base for an artificial field that transforms an RNTuple column containing the offset of collections i...
void ReconcileOnDiskField(const RNTupleDescriptor &) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
RRDFCardinalityFieldBase(std::string_view name, std::string_view type)
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
void GenerateColumns(const ROOT::RNTupleDescriptor &desc) final
Implementations in derived classes should create the backing columns corresponding to the field type ...
RRDFCardinalityFieldBase(const RRDFCardinalityFieldBase &other)=delete
RRDFCardinalityFieldBase(RRDFCardinalityFieldBase &&other)=default
RRDFCardinalityFieldBase & operator=(const RRDFCardinalityFieldBase &other)=delete
RRDFCardinalityFieldBase & operator=(RRDFCardinalityFieldBase &&other)=default
An artificial field that transforms an RNTuple column containing the offset of collections into colle...
RRDFCardinalityField(RRDFCardinalityField &&other)=default
void CheckSize(ROOT::NTupleSize_t size) const
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
RRDFCardinalityField & operator=(const RRDFCardinalityField &other)=delete
void ReadInClusterImpl(ROOT::RNTupleLocalIndex localIndex, void *to) final
Get the number of elements of the collection identified by clusterIndex.
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
RRDFCardinalityField(const RRDFCardinalityField &other)=delete
RRDFCardinalityField & operator=(RRDFCardinalityField &&other)=default
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
Get the number of elements of the collection identified by globalIndex.
std::unique_ptr< ROOT::RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
std::size_t GetAlignment() const final
What alignof(T) for this type returns.
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
The list of column representations a field can have.
A field translates read and write calls from/to underlying columns to/from tree values.
ROOT::Internal::RColumn * fPrincipalColumn
All fields that have columns have a distinct main column.
const std::string & GetFieldName() const
The on-storage metadata of an RNTuple.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
ENTupleStructure
The fields in the RNTuple data model tree can carry different structural information about the type s...