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
117inline std::ostream &operator<<(std::ostream &os, ENTupleStructure structure)
118{
119 static const char *const names[] = {"Invalid", "Plain", "Collection", "Record", "Variant", "Streamer", "Unknown"};
120 static_assert((std::size_t)ENTupleStructure::kUnknown + 1 == std::size(names));
121
122 if (R__likely(static_cast<std::size_t>(structure) <= std::size(names)))
124 else
125 os << "(invalid)";
126 return os;
127}
128
129/// Integer type long enough to hold the maximum number of entries in a column
130using NTupleSize_t = std::uint64_t;
131constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
132
133/// Distriniguishes elements of the same type within a descriptor, e.g. different fields
134using DescriptorId_t = std::uint64_t;
135constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
136
137/// Addresses a column element or field item relative to a particular cluster, instead of a global NTupleSize_t index
139private:
142
143public:
144 RNTupleLocalIndex() = default;
151
156
161
166
167 RNTupleLocalIndex operator++(int) /* postfix */
168 {
169 auto r = *this;
171 return r;
172 }
173
175 {
177 return *this;
178 }
179
181 {
182 return fClusterId == other.fClusterId && fIndexInCluster == other.fIndexInCluster;
183 }
184
185 bool operator!=(RNTupleLocalIndex other) const { return !(*this == other); }
186
189};
190
191/// RNTupleLocator payload that is common for object stores using 64bit location information.
192/// This might not contain the full location of the content. In particular, for page locators this information may be
193/// used in conjunction with the cluster and column ID.
195private:
196 std::uint64_t fLocation = 0;
197
198public:
200 explicit RNTupleLocatorObject64(std::uint64_t location) : fLocation(location) {}
201 bool operator==(const RNTupleLocatorObject64 &other) const { return fLocation == other.fLocation; }
202 std::uint64_t GetLocation() const { return fLocation; }
203};
204
205// Workaround missing return type overloading
206class RNTupleLocator;
207namespace Internal {
208template <typename T>
210
211template <>
212struct RNTupleLocatorHelper<std::uint64_t> {
213 static std::uint64_t Get(const RNTupleLocator &loc);
214};
215
216template <>
220} // namespace Internal
221
222/// Generic information about the physical location of data. Values depend on the concrete storage type. E.g.,
223/// for a local file `fPosition` is a 64bit file offset. Referenced objects on storage can be compressed
224/// and therefore we need to store their actual size.
225/// Note that we use a representation optimized for memory consumption that slightly differs from the on-disk
226/// representation.
228 friend struct Internal::RNTupleLocatorHelper<std::uint64_t>;
229 friend struct Internal::RNTupleLocatorHelper<RNTupleLocatorObject64>;
230
231public:
232 /// Values for the _Type_ field in non-disk locators. Serializable types must have the MSb == 0; see
233 /// `doc/BinaryFormatSpecification.md` for details
234 enum ELocatorType : std::uint8_t {
235 // The kTypeFile locator may translate to an on-disk standard locator (type 0x00) or a large locator (type 0x01),
236 // if the size of the referenced data block is >2GB
237 kTypeFile = 0x00,
238 kTypeDAOS = 0x02,
239
240 kLastSerializableType = 0x7f,
241 kTypePageZero = kLastSerializableType + 1,
243 };
244
245private:
246 /// The 4 most significant bits of fFlagsAndNBytes carry the locator type (3 bits)
247 /// plus one bit for a reserved bit of an extended locator.
248 static constexpr std::uint64_t kMaskFlags = 0x0FULL << 60;
249 static constexpr std::uint64_t kMaskType = 0x07ULL << 61;
250 static constexpr std::uint64_t kMaskReservedBit = 1ull << 60;
251
252 /// To save memory, we use the most significant bits to store the locator type (file, DAOS, zero page,
253 /// unkown, kTestLocatorType) as well as one "reserved bit" that can be used in future locators.
254 /// Consequently, we can only store sizes up to 60 bits (1 EB), which in practice won't be an issue.
255 std::uint64_t fFlagsAndNBytes = 0;
256 /// Simple on-disk locators consisting of a 64-bit offset use variant type `uint64_t`;
257 /// Object store locators use RNTupleLocatorObject64 but can still use the same 64 bit int for information storage.
258 std::uint64_t fPosition = 0;
259
260public:
261 RNTupleLocator() = default;
262
263 bool operator==(const RNTupleLocator &other) const
264 {
265 return fPosition == other.fPosition && fFlagsAndNBytes == other.fFlagsAndNBytes;
266 }
267
268 std::uint64_t GetNBytesOnStorage() const { return fFlagsAndNBytes & ~kMaskFlags; }
269 /// For non-disk locators, the value for the _Type_ field. This makes it possible to have different type values even
270 /// if the payload structure is identical.
271 ELocatorType GetType() const;
272 /// We currently only support one of the 8 available reserved bits (none are used so far).
273 std::uint8_t GetReserved() const { return (fFlagsAndNBytes & kMaskReservedBit) > 0; }
274
275 void SetNBytesOnStorage(std::uint64_t nBytesOnStorage);
277 void SetReserved(std::uint8_t reserved);
278
279 /// Note that for GetPosition() / SetPosition(), the locator type must correspond (kTypeFile, kTypeDAOS).
280
281 template <typename T>
282 T GetPosition() const
283 {
285 }
286
287 void SetPosition(std::uint64_t position);
288 void SetPosition(RNTupleLocatorObject64 position);
289};
290
291namespace Internal {
292
295 /// Uncompressed length of the anchor, including the checksum.
296 std::uint32_t fLength = 0;
297};
298
299/// The in-memory representation of a 32bit or 64bit on-disk index column. Wraps the integer in a
300/// named type so that templates can distinguish between integer data columns and index columns.
302public:
303 using ValueType = std::uint64_t;
304
305private:
307
308public:
309 RColumnIndex() = default;
310 explicit constexpr RColumnIndex(ValueType value) : fValue(value) {}
312 {
313 fValue = value;
314 return *this;
315 }
317 {
318 fValue += value;
319 return *this;
320 }
322 {
323 auto result = *this;
324 fValue++;
325 return result;
326 }
327 operator ValueType() const { return fValue; }
328};
329
330/// Holds the index and the tag of a kSwitch column
332private:
334 std::uint32_t fTag = 0;
335
336public:
337 RColumnSwitch() = default;
338 RColumnSwitch(ROOT::NTupleSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) {}
340 std::uint32_t GetTag() const { return fTag; }
341};
342
343inline constexpr ENTupleColumnType kTestFutureColumnType =
344 static_cast<ENTupleColumnType>(std::numeric_limits<std::underlying_type_t<ENTupleColumnType>>::max() - 1);
345
347 static_cast<ROOT::ENTupleStructure>(std::numeric_limits<std::underlying_type_t<ROOT::ENTupleStructure>>::max() - 1);
348
351
352} // namespace Internal
353} // namespace ROOT
354
355#endif
#define R__likely(expr)
Definition RConfig.hxx:587
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
We currently only support one of the 8 available reserved bits (none are used so far).
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)