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 <string_view>
23#include <variant>
24
25#include <ROOT/RError.hxx>
26#include <ROOT/RLogger.hxx>
28
29namespace ROOT {
30
31/// Helper types to present an offset column as array of collection sizes.
32/// See RField<RNTupleCardinality<SizeT>> for details.
33template <typename SizeT>
35 static_assert(std::is_same_v<SizeT, std::uint32_t> || std::is_same_v<SizeT, std::uint64_t>,
36 "RNTupleCardinality is only supported with std::uint32_t or std::uint64_t template parameters");
37
38 using ValueType = SizeT;
39
41 explicit constexpr RNTupleCardinality(ValueType value) : fValue(value) {}
43 {
44 fValue = value;
45 return *this;
46 }
47 operator ValueType() const { return fValue; }
48
50};
51
52namespace Experimental {
53
54class RLogChannel;
55/// Log channel for RNTuple diagnostics.
56RLogChannel &NTupleLog();
57
58// clang-format off
59/**
60\class ROOT::Experimental::EColumnType
61\ingroup NTuple
62\brief The available trivial, native content types of a column
63
64More complex types, such as classes, get translated into columns of such simple types by the RField.
65When changed, remember to update
66 - RColumnElement::Generate()
67 - RColumnElement::GetTypeName()
68 - RColumnElement::GetValidBitRange()
69 - RColumnElement template specializations / packing & unpacking
70 - If necessary, endianess handling for the packing + unit test in ntuple_endian
71 - RNTupleSerializer::[Des|S]erializeColumnType
72*/
73// clang-format on
74enum class EColumnType {
75 kUnknown = 0,
76 // type for root columns of (nested) collections; offsets are relative to the current cluster
79 // 96 bit column that is a pair of a kIndex64 and a 32bit dispatch tag to a column ID;
80 // used to serialize std::variant.
81 kSwitch,
82 kByte,
83 kChar,
84 kBit,
85 kReal64,
86 kReal32,
87 kReal16,
88 kInt64,
89 kUInt64,
90 kInt32,
91 kUInt32,
92 kInt16,
93 kUInt16,
94 kInt8,
95 kUInt8,
108 kMax,
109};
110
111/// The fields in the ntuple model tree can carry different structural information about the type system.
112/// Leaf fields contain just data, collection fields resolve to offset columns, record fields have no
113/// materialization on the primitive column layer.
115
116/// Integer type long enough to hold the maximum number of entries in a column
117using NTupleSize_t = std::uint64_t;
118constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
119/// Wrap the integer in a struct in order to avoid template specialization clash with std::uint64_t
121 using ValueType = std::uint64_t;
122
124 explicit constexpr RClusterSize(ValueType value) : fValue(value) {}
126 {
127 fValue = value;
128 return *this;
129 }
131 {
132 fValue += value;
133 return *this;
134 }
136 {
137 auto result = *this;
138 fValue++;
139 return result;
140 }
141 operator ValueType() const { return fValue; }
142
144};
146constexpr ClusterSize_t kInvalidClusterIndex(std::uint64_t(-1));
147
149
150/// Holds the index and the tag of a kSwitch column
152private:
154 std::uint32_t fTag = 0;
155
156public:
157 RColumnSwitch() = default;
158 RColumnSwitch(ClusterSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) {}
159 ClusterSize_t GetIndex() const { return fIndex; }
160 std::uint32_t GetTag() const { return fTag; }
161};
162
163/// Uniquely identifies a physical column within the scope of the current process, used to tag pages
164using ColumnId_t = std::int64_t;
166
167/// Distriniguishes elements of the same type within a descriptor, e.g. different fields
168using DescriptorId_t = std::uint64_t;
169constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
170
171/// Addresses a column element or field item relative to a particular cluster, instead of a global NTupleSize_t index
173private:
176
177public:
178 RClusterIndex() = default;
179 RClusterIndex(const RClusterIndex &other) = default;
180 RClusterIndex &operator=(const RClusterIndex &other) = default;
182 : fClusterId(clusterId), fIndex(index)
183 {
184 }
185
188 RClusterIndex operator++(int) /* postfix */
189 {
190 auto r = *this;
191 fIndex++;
192 return r;
193 }
194 RClusterIndex &operator++() /* prefix */
195 {
196 ++fIndex;
197 return *this;
198 }
199 bool operator==(RClusterIndex other) const { return fClusterId == other.fClusterId && fIndex == other.fIndex; }
200 bool operator!=(RClusterIndex other) const { return !(*this == other); }
201
204};
205
206/// RNTupleLocator payload that is common for object stores using 64bit location information.
207/// This might not contain the full location of the content. In particular, for page locators this information may be
208/// used in conjunction with the cluster and column ID.
210 std::uint64_t fLocation = 0;
211 bool operator==(const RNTupleLocatorObject64 &other) const { return fLocation == other.fLocation; }
212};
213
214/// Generic information about the physical location of data. Values depend on the concrete storage type. E.g.,
215/// for a local file `fPosition` might be a 64bit file offset. Referenced objects on storage can be compressed
216/// and therefore we need to store their actual size.
217/// TODO(jblomer): consider moving this to `RNTupleDescriptor`
219 /// Values for the _Type_ field in non-disk locators. Serializable types must have the MSb == 0; see
220 /// `doc/BinaryFormatSpecification.md` for details
221 enum ELocatorType : std::uint8_t {
222 // The kTypeFile locator may translate to an on-disk standard locator (type 0x00) or a large locator (type 0x01),
223 // if the size of the referenced data block is >2GB
224 kTypeFile = 0x00,
225 kTypeDAOS = 0x02,
226
230 };
231
232 std::uint64_t fBytesOnStorage = 0;
233 /// Simple on-disk locators consisting of a 64-bit offset use variant type `uint64_t`; extended locators have
234 /// `fPosition.index()` > 0
235 std::variant<std::uint64_t, RNTupleLocatorObject64> fPosition{};
236 /// For non-disk locators, the value for the _Type_ field. This makes it possible to have different type values even
237 /// if the payload structure is identical.
239 /// Reserved for use by concrete storage backends
240 std::uint8_t fReserved = 0;
241
242 bool operator==(const RNTupleLocator &other) const
243 {
244 return fPosition == other.fPosition && fBytesOnStorage == other.fBytesOnStorage && fType == other.fType;
245 }
246 template <typename T>
247 const T &GetPosition() const
248 {
249 return std::get<T>(fPosition);
250 }
251};
252
253/// Used to specify the underlying RNTuples in RNTupleProcessor and RNTupleReader::OpenFriends()
255 std::string fNTupleName;
256 std::string fStorage;
258
259 RNTupleOpenSpec(std::string_view n, std::string_view s) : fNTupleName(n), fStorage(s) {}
260};
261
262namespace Internal {
263template <typename T>
264auto MakeAliasedSharedPtr(T *rawPtr)
265{
266 const static std::shared_ptr<T> fgRawPtrCtrlBlock;
267 return std::shared_ptr<T>(fgRawPtrCtrlBlock, rawPtr);
268}
269
271 static_cast<ENTupleStructure>(std::numeric_limits<std::underlying_type_t<ENTupleStructure>>::max() - 1);
272
275
276/// Check whether a given string is a valid name according to the RNTuple specification
277RResult<void> EnsureValidNameForRNTuple(std::string_view name, std::string_view where);
278
279} // namespace Internal
280
281} // namespace Experimental
282} // namespace ROOT
283
284#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
char name[80]
Definition TGX11.cxx:110
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)
Common user-tunable settings for reading ntuples.
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
Definition RError.hxx:194
const Int_t n
Definition legend1.C:16
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.
constexpr RNTupleLocator::ELocatorType kTestLocatorType
auto MakeAliasedSharedPtr(T *rawPtr)
constexpr ENTupleStructure kTestFutureFieldStructure
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.
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))
ENTupleStructure
The fields in the ntuple model tree can carry different structural information about the type system.
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)
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, RNTupleLocatorObject64 > fPosition
Simple on-disk locators consisting of a 64-bit offset use variant type uint64_t; extended locators ha...
Used to specify the underlying RNTuples in RNTupleProcessor and RNTupleReader::OpenFriends()
RNTupleOpenSpec(std::string_view n, std::string_view s)
Helper types to present an offset column as array of collection sizes.
RNTupleCardinality & operator=(const ValueType value)
constexpr RNTupleCardinality(ValueType value)