Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleUtil.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleUtil.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-04
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#ifndef ROOT7_RNTupleUtil
17#define ROOT7_RNTupleUtil
18
19#include <cstdint>
20#include <string>
21#include <string_view>
22#include <type_traits>
23#include <variant>
24
25#include <ROOT/RError.hxx>
26#include <ROOT/RLogger.hxx>
27
28namespace ROOT {
29
30class RLogChannel;
31namespace Internal {
32/// Log channel for RNTuple diagnostics.
34} // namespace Internal
35
36/// Helper types to present an offset column as array of collection sizes.
37/// See RField<RNTupleCardinality<SizeT>> for details.
38template <typename SizeT>
40 static_assert(std::is_same_v<SizeT, std::uint32_t> || std::is_same_v<SizeT, std::uint64_t>,
41 "RNTupleCardinality is only supported with std::uint32_t or std::uint64_t template parameters");
42
43 using ValueType = SizeT;
44
46 explicit constexpr RNTupleCardinality(ValueType value) : fValue(value) {}
48 {
49 fValue = value;
50 return *this;
51 }
52 operator ValueType() const { return fValue; }
53
55};
56
57// clang-format off
58/**
59\class ROOT::ENTupleColumnType
60\ingroup NTuple
61\brief The available trivial, native content types of a column
62
63More complex types, such as classes, get translated into columns of such simple types by the RField.
64When changed, remember to update
65 - RColumnElement::Generate()
66 - RColumnElement::GetTypeName()
67 - RColumnElement::GetValidBitRange()
68 - RColumnElement template specializations / packing & unpacking
69 - If necessary, endianess handling for the packing + unit test in ntuple_endian
70 - RNTupleSerializer::[Des|S]erializeColumnType
71*/
72// clang-format on
74 kUnknown = 0,
75 // type for root columns of (nested) collections; offsets are relative to the current cluster
78 // 96 bit column that is a pair of a kIndex64 and a 32bit dispatch tag to a column ID;
79 // used to serialize std::variant.
80 kSwitch,
81 kByte,
82 kChar,
83 kBit,
84 kReal64,
85 kReal32,
86 kReal16,
87 kInt64,
88 kUInt64,
89 kInt32,
90 kUInt32,
91 kInt16,
92 kUInt16,
93 kInt8,
94 kUInt8,
107 kMax,
108};
109
110/// The fields in the ntuple model tree can carry different structural information about the type system.
111/// Leaf fields contain just data, collection fields resolve to offset columns, record fields have no
112/// materialization on the primitive column layer.
113enum class ENTupleStructure : std::uint16_t {
114 kInvalid,
115 kLeaf,
117 kRecord,
118 kVariant,
119 kStreamer,
121};
122
123/// Integer type long enough to hold the maximum number of entries in a column
124using NTupleSize_t = std::uint64_t;
125constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
126
127/// Distriniguishes elements of the same type within a descriptor, e.g. different fields
128using DescriptorId_t = std::uint64_t;
129constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
130
131/// Addresses a column element or field item relative to a particular cluster, instead of a global NTupleSize_t index
179
180/// RNTupleLocator payload that is common for object stores using 64bit location information.
181/// This might not contain the full location of the content. In particular, for page locators this information may be
182/// used in conjunction with the cluster and column ID.
184private:
185 std::uint64_t fLocation = 0;
186
187public:
189 explicit RNTupleLocatorObject64(std::uint64_t location) : fLocation(location) {}
190 bool operator==(const RNTupleLocatorObject64 &other) const { return fLocation == other.fLocation; }
191 std::uint64_t GetLocation() const { return fLocation; }
192};
193
194/// Generic information about the physical location of data. Values depend on the concrete storage type. E.g.,
195/// for a local file `fPosition` might be a 64bit file offset. Referenced objects on storage can be compressed
196/// and therefore we need to store their actual size.
198public:
199 /// Values for the _Type_ field in non-disk locators. Serializable types must have the MSb == 0; see
200 /// `doc/BinaryFormatSpecification.md` for details
201 enum ELocatorType : std::uint8_t {
202 // The kTypeFile locator may translate to an on-disk standard locator (type 0x00) or a large locator (type 0x01),
203 // if the size of the referenced data block is >2GB
204 kTypeFile = 0x00,
205 kTypeDAOS = 0x02,
206
210 };
211
212private:
213 std::uint64_t fNBytesOnStorage = 0;
214 /// Simple on-disk locators consisting of a 64-bit offset use variant type `uint64_t`; extended locators have
215 /// `fPosition.index()` > 0
216 std::variant<std::uint64_t, RNTupleLocatorObject64> fPosition{};
217 /// For non-disk locators, the value for the _Type_ field. This makes it possible to have different type values even
218 /// if the payload structure is identical.
220 /// Reserved for use by concrete storage backends
221 std::uint8_t fReserved = 0;
222
223public:
224 RNTupleLocator() = default;
225
226 bool operator==(const RNTupleLocator &other) const
227 {
228 return fPosition == other.fPosition && fNBytesOnStorage == other.fNBytesOnStorage && fType == other.fType;
229 }
230
231 std::uint64_t GetNBytesOnStorage() const { return fNBytesOnStorage; }
232 ELocatorType GetType() const { return fType; }
233 std::uint8_t GetReserved() const { return fReserved; }
234
237 void SetReserved(std::uint8_t reserved) { fReserved = reserved; }
238
239 template <typename T>
240 T GetPosition() const
241 {
242 return std::get<T>(fPosition);
243 }
244
245 template <typename T>
246 void SetPosition(T position)
247 {
248 fPosition = position;
249 }
250};
251
252namespace Experimental {
253
254namespace Internal {
255
256/// The in-memory representation of a 32bit or 64bit on-disk index column. Wraps the integer in a
257/// named type so that templates can distinguish between integer data columns and index columns.
259public:
260 using ValueType = std::uint64_t;
261
262private:
264
265public:
266 RColumnIndex() = default;
267 explicit constexpr RColumnIndex(ValueType value) : fValue(value) {}
269 {
270 fValue = value;
271 return *this;
272 }
274 {
275 fValue += value;
276 return *this;
277 }
279 {
280 auto result = *this;
281 fValue++;
282 return result;
283 }
284 operator ValueType() const { return fValue; }
285};
286
287/// Holds the index and the tag of a kSwitch column
289private:
291 std::uint32_t fTag = 0;
292
293public:
294 RColumnSwitch() = default;
295 RColumnSwitch(ROOT::NTupleSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) {}
297 std::uint32_t GetTag() const { return fTag; }
298};
299
300} // namespace Internal
301
302} // namespace Experimental
303
304namespace Internal {
305
306template <typename T>
308{
309 const static std::shared_ptr<T> fgRawPtrCtrlBlock;
310 return std::shared_ptr<T>(fgRawPtrCtrlBlock, rawPtr);
311}
312
313/// Make an array of default-initialized elements. This is useful for buffers that do not need to be initialized.
314///
315/// With C++20, this function can be replaced by std::make_unique_for_overwrite<T[]>.
316template <typename T>
317std::unique_ptr<T[]> MakeUninitArray(std::size_t size)
318{
319 // DO NOT use std::make_unique<T[]>, the array elements are value-initialized!
320 return std::unique_ptr<T[]>(new T[size]);
321}
322
323inline constexpr ENTupleColumnType kTestFutureColumnType =
324 static_cast<ENTupleColumnType>(std::numeric_limits<std::underlying_type_t<ENTupleColumnType>>::max() - 1);
325
327 static_cast<ROOT::ENTupleStructure>(std::numeric_limits<std::underlying_type_t<ROOT::ENTupleStructure>>::max() - 1);
328
331
332/// Check whether a given string is a valid name according to the RNTuple specification
333RResult<void> EnsureValidNameForRNTuple(std::string_view name, std::string_view where);
334
335} // namespace Internal
336
337namespace Experimental {
338
339// TODO(jblomer): remove before branching ROOT v6.36
340using EColumnType [[deprecated("ROOT::Experimental::EColumnType moved to ROOT::ENTupleColumnType")]] =
342using ENTupleStructure [[deprecated("ROOT::Experimental::ENTupleStructure moved to ROOT::ENTupleStructure")]] =
344using NTupleSize_t [[deprecated("ROOT::Experimental::NTupleSize_t moved to ROOT::NTupleSize_t")]] = ROOT::NTupleSize_t;
345using DescriptorId_t [[deprecated("ROOT::Experimental::DescriptorId_t moved to ROOT::DescriptorId_t")]] =
347
348} // namespace Experimental
349} // namespace ROOT
350
351#endif
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.
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
char name[80]
Definition TGX11.cxx:110
The in-memory representation of a 32bit or 64bit on-disk index column.
RColumnIndex & operator+=(const ValueType value)
RColumnIndex & operator=(const ValueType value)
constexpr RColumnIndex(ValueType value)
Holds the index and the tag of a kSwitch column.
RColumnSwitch(ROOT::NTupleSize_t index, std::uint32_t tag)
A log configuration for a channel, e.g.
Definition RLogger.hxx:98
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
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
RNTupleLocator()=default
ELocatorType
Values for the Type field in non-disk locators.
std::variant< std::uint64_t, RNTupleLocatorObject64 > fPosition
Simple on-disk locators consisting of a 64-bit offset use variant type uint64_t; extended locators ha...
std::uint8_t fReserved
Reserved for use by concrete storage backends.
std::uint8_t GetReserved() const
void SetPosition(T position)
void SetType(ELocatorType type)
ELocatorType GetType() const
void SetReserved(std::uint8_t reserved)
void SetNBytesOnStorage(std::uint64_t nBytesOnStorage)
ELocatorType fType
For non-disk locators, the value for the Type field.
std::uint64_t fNBytesOnStorage
constexpr ROOT::ENTupleStructure kTestFutureFieldStructure
RResult< void > EnsureValidNameForRNTuple(std::string_view name, std::string_view where)
Check whether a given string is a valid name according to the RNTuple specification.
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
std::unique_ptr< T[]> MakeUninitArray(std::size_t size)
Make an array of default-initialized elements.
auto MakeAliasedSharedPtr(T *rawPtr)
constexpr RNTupleLocator::ELocatorType kTestLocatorType
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
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 ntuple model tree can carry different structural information about the type system.
ENTupleColumnType
Helper types to present an offset column as array of collection sizes.
RNTupleCardinality & operator=(const ValueType value)
constexpr RNTupleCardinality(ValueType value)