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
21#include <string>
22#include <variant>
23
24#include <ROOT/RLogger.hxx>
25
26namespace ROOT {
27namespace Experimental {
28
29class RLogChannel;
30/// Log channel for RNTuple diagnostics.
31RLogChannel &NTupleLog();
32
33// clang-format off
34/**
35\class ROOT::Experimental::EColumnType
36\ingroup NTuple
37\brief The available trivial, native content types of a column
38
39More complex types, such as classes, get translated into columns of such simple types by the RField.
40When changed, remember to update
41 - RColumnElement::Generate()
42 - RColumnElement::GetTypeName()
43 - RColumnElement::GetValidBitRange()
44 - RColumnElement template specializations / packing & unpacking
45 - If necessary, endianess handling for the packing + unit test in ntuple_endian
46 - RNTupleSerializer::[Des|S]erializeColumnType
47*/
48// clang-format on
49enum class EColumnType {
50 kUnknown = 0,
51 // type for root columns of (nested) collections; offsets are relative to the current cluster
54 // 96 bit column that is a pair of a kIndex64 and a 32bit dispatch tag to a column ID;
55 // used to serialize std::variant.
56 kSwitch,
57 kByte,
58 kChar,
59 kBit,
60 kReal64,
61 kReal32,
62 kReal16,
63 kInt64,
64 kUInt64,
65 kInt32,
66 kUInt32,
67 kInt16,
68 kUInt16,
69 kInt8,
70 kUInt8,
81 kMax,
82};
83
84/**
85 * The fields in the ntuple model tree can carry different structural information about the type system.
86 * Leaf fields contain just data, collection fields resolve to offset columns, record fields have no
87 * materialization on the primitive column layer.
88 */
96};
97
98/// Integer type long enough to hold the maximum number of entries in a column
99using NTupleSize_t = std::uint64_t;
100constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
101/// Wrap the integer in a struct in order to avoid template specialization clash with std::uint64_t
103 using ValueType = std::uint64_t;
104
106 explicit constexpr RClusterSize(ValueType value) : fValue(value) {}
107 RClusterSize& operator =(const ValueType value) { fValue = value; return *this; }
108 RClusterSize& operator +=(const ValueType value) { fValue += value; return *this; }
109 RClusterSize operator++(int) { auto result = *this; fValue++; return result; }
110 operator ValueType() const { return fValue; }
111
113};
115constexpr ClusterSize_t kInvalidClusterIndex(std::uint64_t(-1));
116
118
119/// Helper types to present an offset column as array of collection sizes.
120/// See RField<RNTupleCardinality<SizeT>> for details.
121template <typename SizeT>
123 static_assert(std::is_same_v<SizeT, std::uint32_t> || std::is_same_v<SizeT, std::uint64_t>,
124 "RNTupleCardinality is only supported with std::uint32_t or std::uint64_t template parameters");
125
126 using ValueType = SizeT;
127
131 {
132 fValue = value;
133 return *this;
134 }
135 operator ValueType() const { return fValue; }
136
138};
139
140/// Holds the index and the tag of a kSwitch column
142private:
144 std::uint32_t fTag = 0;
145
146public:
147 RColumnSwitch() = default;
148 RColumnSwitch(ClusterSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) { }
149 ClusterSize_t GetIndex() const { return fIndex; }
150 std::uint32_t GetTag() const { return fTag; }
151};
152
153/// Uniquely identifies a physical column within the scope of the current process, used to tag pages
154using ColumnId_t = std::int64_t;
156
157/// Distriniguishes elements of the same type within a descriptor, e.g. different fields
158using DescriptorId_t = std::uint64_t;
159constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
160
161/// Addresses a column element or field item relative to a particular cluster, instead of a global NTupleSize_t index
163private:
166public:
167 RClusterIndex() = default;
168 RClusterIndex(const RClusterIndex &other) = default;
169 RClusterIndex &operator =(const RClusterIndex &other) = default;
171 : fClusterId(clusterId), fIndex(index) {}
172
175 RClusterIndex operator++(int) /* postfix */ { auto r = *this; fIndex++; return r; }
176 RClusterIndex& operator++() /* prefix */ { ++fIndex; return *this; }
177 bool operator==(RClusterIndex other) const { return fClusterId == other.fClusterId && fIndex == other.fIndex; }
178 bool operator!=(RClusterIndex other) const { return !(*this == other); }
179
182};
183
184/// RNTupleLocator payload that is common for object stores using 64bit location information.
185/// This might not contain the full location of the content. In particular, for page locators this information may be
186/// used in conjunction with the cluster and column ID.
188 std::uint64_t fLocation = 0;
189 bool operator==(const RNTupleLocatorObject64 &other) const { return fLocation == other.fLocation; }
190};
191
192/// Generic information about the physical location of data. Values depend on the concrete storage type. E.g.,
193/// for a local file `fPosition` might be a 64bit file offset. Referenced objects on storage can be compressed
194/// and therefore we need to store their actual size.
195/// TODO(jblomer): consider moving this to `RNTupleDescriptor`
197 /// Values for the _Type_ field in non-disk locators. Serializable types must have the MSb == 0; see
198 /// `doc/specifications.md` for details
199 enum ELocatorType : std::uint8_t {
200 kTypeFile = 0x00,
201 kTypeURI = 0x01,
202 kTypeDAOS = 0x02,
203
206 };
207
208 /// Simple on-disk locators consisting of a 64-bit offset use variant type `uint64_t`; extended locators have
209 /// `fPosition.index()` > 0
210 std::variant<std::uint64_t, std::string, RNTupleLocatorObject64> fPosition{};
211 std::uint32_t fBytesOnStorage = 0;
212 /// For non-disk locators, the value for the _Type_ field. This makes it possible to have different type values even
213 /// if the payload structure is identical.
215 /// Reserved for use by concrete storage backends
216 std::uint8_t fReserved = 0;
217
218 bool operator==(const RNTupleLocator &other) const {
219 return fPosition == other.fPosition && fBytesOnStorage == other.fBytesOnStorage && fType == other.fType;
220 }
221 template <typename T>
222 const T &GetPosition() const
223 {
224 return std::get<T>(fPosition);
225 }
226};
227
228namespace Internal {
229template <typename T>
230auto MakeAliasedSharedPtr(T *rawPtr)
231{
232 const static std::shared_ptr<T> fgRawPtrCtrlBlock;
233 return std::shared_ptr<T>(fgRawPtrCtrlBlock, rawPtr);
234}
235} // namespace Internal
236
237} // namespace Experimental
238} // namespace ROOT
239
240#endif
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
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
RClusterIndex operator+(ClusterSize_t::ValueType off) const
ClusterSize_t::ValueType fIndex
RClusterIndex operator-(ClusterSize_t::ValueType off) const
bool operator==(RClusterIndex other) const
RClusterIndex & operator=(const RClusterIndex &other)=default
bool operator!=(RClusterIndex other) const
DescriptorId_t GetClusterId() const
constexpr RClusterIndex(DescriptorId_t clusterId, ClusterSize_t::ValueType index)
ClusterSize_t::ValueType GetIndex() const
RClusterIndex(const RClusterIndex &other)=default
Holds the index and the tag of a kSwitch column.
RColumnSwitch(ClusterSize_t index, std::uint32_t tag)
auto MakeAliasedSharedPtr(T *rawPtr)
RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
ENTupleStructure
The fields in the ntuple model tree can carry different structural information about the type system.
constexpr ColumnId_t kInvalidColumnId
constexpr int kUnknownCompressionSettings
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr NTupleSize_t kInvalidNTupleIndex
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
constexpr ClusterSize_t kInvalidClusterIndex(std::uint64_t(-1))
constexpr DescriptorId_t kInvalidDescriptorId
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Wrap the integer in a struct in order to avoid template specialization clash with std::uint64_t.
RClusterSize & operator=(const ValueType value)
constexpr RClusterSize(ValueType value)
RClusterSize & operator+=(const ValueType value)
Helper types to present an offset column as array of collection sizes.
RNTupleCardinality & operator=(const ValueType value)
constexpr RNTupleCardinality(ValueType value)
RNTupleLocator payload that is common for object stores using 64bit location information.
bool operator==(const RNTupleLocatorObject64 &other) const
Generic information about the physical location of data.
ELocatorType
Values for the Type field in non-disk locators.
std::uint8_t fReserved
Reserved for use by concrete storage backends.
ELocatorType fType
For non-disk locators, the value for the Type field.
bool operator==(const RNTupleLocator &other) const
std::variant< std::uint64_t, std::string, RNTupleLocatorObject64 > fPosition
Simple on-disk locators consisting of a 64-bit offset use variant type uint64_t; extended locators ha...