Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleTypes.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleTypes.hxx
2/// \ingroup NTuple
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-04
5
6/*************************************************************************
7 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#ifndef ROOT_RNTupleTypes
15#define ROOT_RNTupleTypes
16
17#include <ROOT/RConfig.hxx>
18
19#include <cstddef>
20#include <cstdint>
21#include <limits>
22#include <ostream>
23#include <type_traits>
24
25namespace ROOT {
26
27/// Helper types to present an offset column as array of collection sizes.
28/// See RField<RNTupleCardinality<SizeT>> for details.
29template <typename SizeT>
31 static_assert(std::is_same_v<SizeT, std::uint32_t> || std::is_same_v<SizeT, std::uint64_t>,
32 "RNTupleCardinality is only supported with std::uint32_t or std::uint64_t template parameters");
33
34 using ValueType = SizeT;
35
37 explicit constexpr RNTupleCardinality(ValueType value) : fValue(value) {}
39 {
40 fValue = value;
41 return *this;
42 }
43 operator ValueType() const { return fValue; }
44
46};
47
48// clang-format off
49/**
50\class ROOT::ENTupleColumnType
51\ingroup NTuple
52\brief The available trivial, native content types of a column
53
54More complex types, such as classes, get translated into columns of such simple types by the RField.
55When changed, remember to update
56 - RColumnElement::Generate()
57 - RColumnElement::GetTypeName()
58 - RColumnElement::GetValidBitRange()
59 - RColumnElement template specializations / packing & unpacking
60 - If necessary, endianess handling for the packing + unit test in ntuple_endian
61 - RNTupleSerializer::[Des|S]erializeColumnType
62*/
63// clang-format on
65 kUnknown = 0,
66 // type for root columns of (nested) collections; offsets are relative to the current cluster
69 // 96 bit column that is a pair of a kIndex64 and a 32bit dispatch tag to a column ID;
70 // used to serialize std::variant.
71 kSwitch,
72 kByte,
73 kChar,
74 kBit,
75 kReal64,
76 kReal32,
77 kReal16,
78 kInt64,
79 kUInt64,
80 kInt32,
81 kUInt32,
82 kInt16,
83 kUInt16,
84 kInt8,
85 kUInt8,
98 kMax,
99};
100
101/// The fields in the RNTuple data model tree can carry different structural information about the type system.
102/// Collection fields have an offset column and subfields with arbitrary cardinality, record fields have no
103/// materialization on the primitive column layer and an arbitrary number of subfields. Plain fields are either
104/// leafs (e.g., `float`) or "wrapper fields" with exactly one child that has the same cardinality
105/// (number of elements in the data set modulo field repetitions) as the parent (e.g., std::atomic<T>).
106// IMPORTANT: if you add members, remember to change the related `operator<<` below.
107enum class ENTupleStructure : std::uint16_t {
108 kInvalid,
109 kPlain,
111 kRecord,
112 kVariant,
113 kStreamer,
114 kUnknown,
115
116 // for backwards compatibility
117 kLeaf R__DEPRECATED(6, 42, "use instead ROOT::ENTupleStructure::kPlain") = kPlain
118};
119
120inline std::ostream &operator<<(std::ostream &os, ENTupleStructure structure)
121{
122 static const char *const names[] = {"Invalid", "Plain", "Collection", "Record", "Variant", "Streamer", "Unknown"};
123 static_assert((std::size_t)ENTupleStructure::kUnknown + 1 == std::size(names));
124
125 if (R__likely(static_cast<std::size_t>(structure) <= std::size(names)))
127 else
128 os << "(invalid)";
129 return os;
130}
131
132/// Integer type long enough to hold the maximum number of entries in a column
133using NTupleSize_t = std::uint64_t;
134constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
135
136/// Distriniguishes elements of the same type within a descriptor, e.g. different fields
137using DescriptorId_t = std::uint64_t;
138constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
139
140/// Addresses a column element or field item relative to a particular cluster, instead of a global NTupleSize_t index
142private:
145
146public:
147 RNTupleLocalIndex() = default;
154
159
164
169
170 RNTupleLocalIndex operator++(int) /* postfix */
171 {
172 auto r = *this;
174 return r;
175 }
176
178 {
180 return *this;
181 }
182
184 {
185 return fClusterId == other.fClusterId && fIndexInCluster == other.fIndexInCluster;
186 }
187
188 bool operator!=(RNTupleLocalIndex other) const { return !(*this == other); }
189
192};
193
194/// RNTupleLocator payload that is common for object stores using 64bit location information.
195/// This might not contain the full location of the content. In particular, for page locators this information may be
196/// used in conjunction with the cluster and column ID.
198private:
199 std::uint64_t fLocation = 0;
200
201public:
203 explicit RNTupleLocatorObject64(std::uint64_t location) : fLocation(location) {}
204 bool operator==(const RNTupleLocatorObject64 &other) const { return fLocation == other.fLocation; }
205 std::uint64_t GetLocation() const { return fLocation; }
206};
207
208// Workaround missing return type overloading
209class RNTupleLocator;
210namespace Internal {
211template <typename T>
213
214template <>
215struct RNTupleLocatorHelper<std::uint64_t> {
216 static std::uint64_t Get(const RNTupleLocator &loc);
217};
218
219template <>
223} // namespace Internal
224
225/// Generic information about the physical location of data. Values depend on the concrete storage type. E.g.,
226/// for a local file `fPosition` is a 64bit file offset. Referenced objects on storage can be compressed
227/// and therefore we need to store their actual size.
228/// Note that we use a representation optimized for memory consumption that slightly differs from the on-disk
229/// representation.
231 friend struct Internal::RNTupleLocatorHelper<std::uint64_t>;
232 friend struct Internal::RNTupleLocatorHelper<RNTupleLocatorObject64>;
233
234public:
235 /// Values for the _Type_ field in non-disk locators. Serializable types must have the MSb == 0; see
236 /// `doc/BinaryFormatSpecification.md` for details
237 enum ELocatorType : std::uint8_t {
238 // The kTypeFile locator may translate to an on-disk standard locator (type 0x00) or a large locator (type 0x01),
239 // if the size of the referenced data block is >2GB
240 kTypeFile = 0x00,
241 kTypeDAOS = 0x02,
242
243 kLastSerializableType = 0x7f,
244 kTypePageZero = kLastSerializableType + 1,
246 };
247
248private:
249 /// The 4 most significant bits of fFlagsAndNBytes carry the locator type (3 bits)
250 /// plus one bit for a reserved bit of an extended locator.
251 static constexpr std::uint64_t kMaskFlags = 0x0FULL << 60;
252 static constexpr std::uint64_t kMaskType = 0x07ULL << 61;
253 static constexpr std::uint64_t kMaskReservedBit = 1ull << 60;
254
255 /// To save memory, we use the most significant bits to store the locator type (file, DAOS, zero page,
256 /// unkown, kTestLocatorType) as well as the one "reserved bit" that we currently process, the DAOS cage bit.
257 /// Consequently, we can only store sizes up to 60 bits (1 EB), which in practice won't be an issue.
258 std::uint64_t fFlagsAndNBytes = 0;
259 /// Simple on-disk locators consisting of a 64-bit offset use variant type `uint64_t`;
260 /// Object store locators use RNTupleLocatorObject64 but can still use the same 64 bit int for information storage.
261 std::uint64_t fPosition = 0;
262
263public:
264 RNTupleLocator() = default;
265
266 bool operator==(const RNTupleLocator &other) const
267 {
268 return fPosition == other.fPosition && fFlagsAndNBytes == other.fFlagsAndNBytes;
269 }
270
271 std::uint64_t GetNBytesOnStorage() const { return fFlagsAndNBytes & ~kMaskFlags; }
272 /// For non-disk locators, the value for the _Type_ field. This makes it possible to have different type values even
273 /// if the payload structure is identical.
274 ELocatorType GetType() const;
275 /// The only currently supported reserved bit is the DAOS cage bit.
276 std::uint8_t GetReserved() const { return (fFlagsAndNBytes & kMaskReservedBit) > 0; }
277
278 void SetNBytesOnStorage(std::uint64_t nBytesOnStorage);
280 void SetReserved(std::uint8_t reserved);
281
282 /// Note that for GetPosition() / SetPosition(), the locator type must correspond (kTypeFile, kTypeDAOS).
283
284 template <typename T>
285 T GetPosition() const
286 {
288 }
289
290 void SetPosition(std::uint64_t position);
291 void SetPosition(RNTupleLocatorObject64 position);
292};
293
294namespace Internal {
295
296/// The in-memory representation of a 32bit or 64bit on-disk index column. Wraps the integer in a
297/// named type so that templates can distinguish between integer data columns and index columns.
299public:
300 using ValueType = std::uint64_t;
301
302private:
304
305public:
306 RColumnIndex() = default;
307 explicit constexpr RColumnIndex(ValueType value) : fValue(value) {}
309 {
310 fValue = value;
311 return *this;
312 }
314 {
315 fValue += value;
316 return *this;
317 }
319 {
320 auto result = *this;
321 fValue++;
322 return result;
323 }
324 operator ValueType() const { return fValue; }
325};
326
327/// Holds the index and the tag of a kSwitch column
329private:
331 std::uint32_t fTag = 0;
332
333public:
334 RColumnSwitch() = default;
335 RColumnSwitch(ROOT::NTupleSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) {}
337 std::uint32_t GetTag() const { return fTag; }
338};
339
340inline constexpr ENTupleColumnType kTestFutureColumnType =
341 static_cast<ENTupleColumnType>(std::numeric_limits<std::underlying_type_t<ENTupleColumnType>>::max() - 1);
342
344 static_cast<ROOT::ENTupleStructure>(std::numeric_limits<std::underlying_type_t<ROOT::ENTupleStructure>>::max() - 1);
345
348
349} // namespace Internal
350} // namespace ROOT
351
352#endif
#define R__likely(expr)
Definition RConfig.hxx:593
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 r
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 result
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 value
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
The in-memory representation of a 32bit or 64bit on-disk index column.
constexpr RColumnIndex(ValueType value)
RColumnIndex & operator=(const ValueType value)
RColumnIndex & operator+=(const ValueType value)
Holds the index and the tag of a kSwitch column.
std::uint32_t GetTag() const
ROOT::NTupleSize_t GetIndex() const
RColumnSwitch(ROOT::NTupleSize_t index, std::uint32_t tag)
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
RNTupleLocalIndex operator*(ROOT::NTupleSize_t repetitionFactor) const
RNTupleLocalIndex operator-(ROOT::NTupleSize_t off) const
ROOT::NTupleSize_t fIndexInCluster
RNTupleLocalIndex operator++(int)
bool operator==(RNTupleLocalIndex other) const
RNTupleLocalIndex operator+(ROOT::NTupleSize_t off) const
ROOT::NTupleSize_t GetIndexInCluster() const
constexpr RNTupleLocalIndex(ROOT::DescriptorId_t clusterId, ROOT::NTupleSize_t indexInCluster)
RNTupleLocalIndex & operator++()
RNTupleLocalIndex(const RNTupleLocalIndex &other)=default
RNTupleLocalIndex & operator=(const RNTupleLocalIndex &other)=default
bool operator!=(RNTupleLocalIndex other) const
ROOT::DescriptorId_t fClusterId
ROOT::DescriptorId_t GetClusterId() const
RNTupleLocator payload that is common for object stores using 64bit location information.
bool operator==(const RNTupleLocatorObject64 &other) const
RNTupleLocatorObject64(std::uint64_t location)
std::uint64_t GetLocation() const
Generic information about the physical location of data.
std::uint64_t GetNBytesOnStorage() const
bool operator==(const RNTupleLocator &other) const
std::uint64_t fPosition
Simple on-disk locators consisting of a 64-bit offset use variant type uint64_t; Object store locator...
RNTupleLocator()=default
ELocatorType
Values for the Type field in non-disk locators.
std::uint64_t fFlagsAndNBytes
To save memory, we use the most significant bits to store the locator type (file, DAOS,...
static constexpr std::uint64_t kMaskFlags
The 4 most significant bits of fFlagsAndNBytes carry the locator type (3 bits) plus one bit for a res...
ELocatorType GetType() const
For non-disk locators, the value for the Type field.
std::uint8_t GetReserved() const
The only currently supported reserved bit is the DAOS cage bit.
static constexpr std::uint64_t kMaskReservedBit
T GetPosition() const
Note that for GetPosition() / SetPosition(), the locator type must correspond (kTypeFile,...
void SetType(ELocatorType type)
void SetPosition(std::uint64_t position)
static constexpr std::uint64_t kMaskType
void SetReserved(std::uint8_t reserved)
See GetReserved(): we ignore the reserved flag since we don't use it anywhere currently.
void SetNBytesOnStorage(std::uint64_t nBytesOnStorage)
constexpr ROOT::ENTupleStructure kTestFutureFieldStructure
constexpr RNTupleLocator::ELocatorType kTestLocatorType
std::ostream & operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h)
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...
ENTupleColumnType
static RNTupleLocatorObject64 Get(const RNTupleLocator &loc)
Helper types to present an offset column as array of collection sizes.
RNTupleCardinality & operator=(const ValueType value)
constexpr RNTupleCardinality(ValueType value)