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/**
34 * The fields in the ntuple model tree can carry different structural information about the type system.
35 * Leaf fields contain just data, collection fields resolve to offset columns, record fields have no
36 * materialization on the primitive column layer.
37 */
43 kReference, // unimplemented so far
45};
46
47/// Integer type long enough to hold the maximum number of entries in a column
48using NTupleSize_t = std::uint64_t;
49constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
50/// Wrap the integer in a struct in order to avoid template specialization clash with std::uint64_t
52 using ValueType = std::uint64_t;
53
55 explicit constexpr RClusterSize(ValueType value) : fValue(value) {}
56 RClusterSize& operator =(const ValueType value) { fValue = value; return *this; }
57 RClusterSize& operator +=(const ValueType value) { fValue += value; return *this; }
58 RClusterSize operator++(int) { auto result = *this; fValue++; return result; }
59 operator ValueType() const { return fValue; }
60
62};
64constexpr ClusterSize_t kInvalidClusterIndex(std::uint64_t(-1));
65
66/// Helper types to present an offset column as array of collection sizes.
67/// See RField<RNTupleCardinality<SizeT>> for details.
68template <typename SizeT>
70 static_assert(std::is_same_v<SizeT, std::uint32_t> || std::is_same_v<SizeT, std::uint64_t>,
71 "RNTupleCardinality is only supported with std::uint32_t or std::uint64_t template parameters");
72
73 using ValueType = SizeT;
74
76 explicit constexpr RNTupleCardinality(ValueType value) : fValue(value) {}
78 {
79 fValue = value;
80 return *this;
81 }
82 operator ValueType() const { return fValue; }
83
85};
86
87/// Holds the index and the tag of a kSwitch column
89private:
91 std::uint32_t fTag = 0;
92
93public:
94 RColumnSwitch() = default;
95 RColumnSwitch(ClusterSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) { }
96 ClusterSize_t GetIndex() const { return fIndex; }
97 std::uint32_t GetTag() const { return fTag; }
98};
99
100/// Uniquely identifies a physical column within the scope of the current process, used to tag pages
101using ColumnId_t = std::int64_t;
103
104/// Distriniguishes elements of the same type within a descriptor, e.g. different fields
105using DescriptorId_t = std::uint64_t;
106constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
107
108/// Addresses a column element or field item relative to a particular cluster, instead of a global NTupleSize_t index
110private:
113public:
114 RClusterIndex() = default;
115 RClusterIndex(const RClusterIndex &other) = default;
116 RClusterIndex &operator =(const RClusterIndex &other) = default;
118 : fClusterId(clusterId), fIndex(index) {}
119
122 RClusterIndex operator++(int) /* postfix */ { auto r = *this; fIndex++; return r; }
123 RClusterIndex& operator++() /* prefix */ { ++fIndex; return *this; }
124 bool operator==(RClusterIndex other) const { return fClusterId == other.fClusterId && fIndex == other.fIndex; }
125 bool operator!=(RClusterIndex other) const { return !(*this == other); }
126
129};
130
131/// RNTupleLocator payload that is common for object stores using 64bit location information.
132/// This might not contain the full location of the content. In particular, for page locators this information may be
133/// used in conjunction with the cluster and column ID.
135 std::uint64_t fLocation = 0;
136 bool operator==(const RNTupleLocatorObject64 &other) const { return fLocation == other.fLocation; }
137};
138
139/// Generic information about the physical location of data. Values depend on the concrete storage type. E.g.,
140/// for a local file `fPosition` might be a 64bit file offset. Referenced objects on storage can be compressed
141/// and therefore we need to store their actual size.
142/// TODO(jblomer): consider moving this to `RNTupleDescriptor`
144 /// Values for the _Type_ field in non-disk locators. Serializable types must have the MSb == 0; see
145 /// `doc/specifications.md` for details
146 enum ELocatorType : std::uint8_t {
147 kTypeFile = 0x00,
148 kTypeURI = 0x01,
149 kTypeDAOS = 0x02,
150
153 };
154
155 /// Simple on-disk locators consisting of a 64-bit offset use variant type `uint64_t`; extended locators have
156 /// `fPosition.index()` > 0
157 std::variant<std::uint64_t, std::string, RNTupleLocatorObject64> fPosition;
158 std::uint32_t fBytesOnStorage = 0;
159 /// For non-disk locators, the value for the _Type_ field. This makes it possible to have different type values even
160 /// if the payload structure is identical.
162 /// Reserved for use by concrete storage backends
163 std::uint8_t fReserved = 0;
164
165 bool operator==(const RNTupleLocator &other) const {
166 return fPosition == other.fPosition && fBytesOnStorage == other.fBytesOnStorage && fType == other.fType;
167 }
168 template <typename T>
169 const T &GetPosition() const
170 {
171 return std::get<T>(fPosition);
172 }
173};
174
175namespace Internal {
176template <typename T>
177auto MakeAliasedSharedPtr(T *rawPtr)
178{
179 const static std::shared_ptr<T> fgRawPtrCtrlBlock;
180 return std::shared_ptr<T>(fgRawPtrCtrlBlock, rawPtr);
181}
182} // namespace Internal
183
184} // namespace Experimental
185} // namespace ROOT
186
187#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.
ClusterSize_t GetIndex() const
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
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
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
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...