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
23#include <ROOT/RLogger.hxx>
24
25namespace ROOT {
26namespace Experimental {
27
28class RLogChannel;
29/// Log channel for RNTuple diagnostics.
30RLogChannel &NTupleLog();
31
32struct RNTuple;
33
34namespace Internal {
35
36namespace RNTupleSerialization {
37
38std::uint32_t SerializeInt64(std::int64_t val, void *buffer);
39std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer);
40std::uint32_t DeserializeInt64(const void *buffer, std::int64_t *val);
41std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t *val);
42
43std::uint32_t SerializeInt32(std::int32_t val, void *buffer);
44std::uint32_t SerializeUInt32(std::uint32_t val, void *buffer);
45std::uint32_t DeserializeInt32(const void *buffer, std::int32_t *val);
46std::uint32_t DeserializeUInt32(const void *buffer, std::uint32_t *val);
47
48std::uint32_t SerializeInt16(std::int16_t val, void *buffer);
49std::uint32_t SerializeUInt16(std::uint16_t val, void *buffer);
50std::uint32_t DeserializeInt16(const void *buffer, std::int16_t *val);
51std::uint32_t DeserializeUInt16(const void *buffer, std::uint16_t *val);
52
53std::uint32_t SerializeString(const std::string &val, void *buffer);
54std::uint32_t DeserializeString(const void *buffer, std::string *val);
55
56} // namespace RNTupleSerialization
57
58void PrintRNTuple(const RNTuple& ntuple, std::ostream& output);
59
60} // namespace Internal
61
62/**
63 * The fields in the ntuple model tree can carry different structural information about the type system.
64 * Leaf fields contain just data, collection fields resolve to offset columns, record fields have no
65 * materialization on the primitive column layer.
66 */
72 kReference, // unimplemented so far
74};
75
76/// Integer type long enough to hold the maximum number of entries in a column
77using NTupleSize_t = std::uint64_t;
78constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
79/// Wrap the 32bit integer in a struct in order to avoid template specialization clash with std::uint32_t
81 using ValueType = std::uint32_t;
82
84 explicit constexpr RClusterSize(ValueType value) : fValue(value) {}
85 RClusterSize& operator =(const ValueType value) { fValue = value; return *this; }
86 RClusterSize& operator +=(const ValueType value) { fValue += value; return *this; }
87 RClusterSize operator++(int) { auto result = *this; fValue++; return result; }
88 operator ValueType() const { return fValue; }
89
91};
93constexpr ClusterSize_t kInvalidClusterIndex(std::uint32_t(-1));
94
95/// Holds the index and the tag of a kSwitch column
97private:
99 std::uint32_t fTag = 0;
100
101public:
102 RColumnSwitch() = default;
103 RColumnSwitch(ClusterSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) { }
104 ClusterSize_t GetIndex() const { return fIndex; }
105 std::uint32_t GetTag() const { return fTag; }
106};
107
108/// Uniquely identifies a physical column within the scope of the current process, used to tag pages
109using ColumnId_t = std::int64_t;
111
112/// Distriniguishes elements of the same type within a descriptor, e.g. different fields
113using DescriptorId_t = std::uint64_t;
114constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
115
116/// Addresses a column element or field item relative to a particular cluster, instead of a global NTupleSize_t index
118private:
121public:
122 RClusterIndex() = default;
123 RClusterIndex(const RClusterIndex &other) = default;
124 RClusterIndex &operator =(const RClusterIndex &other) = default;
126 : fClusterId(clusterId), fIndex(index) {}
127
130 RClusterIndex operator++(int) /* postfix */ { auto r = *this; fIndex++; return r; }
131 RClusterIndex& operator++() /* prefix */ { ++fIndex; return *this; }
132 bool operator==(const RClusterIndex &other) const {
133 return fClusterId == other.fClusterId && fIndex == other.fIndex;
134 }
135 bool operator!=(const RClusterIndex &other) const { return !(*this == other); }
136
139};
140
141/// Every NTuple is identified by a UUID. TODO(jblomer): should this be a TUUID?
142using RNTupleUuid = std::string;
143
144
145/// 64 possible flags to apply to all versioned entities (so far unused).
146using NTupleFlags_t = std::uint64_t;
147/// For forward and backward compatibility, attach version information to
148/// the consitituents of the file format (column, field, cluster, ntuple).
150private:
151 /// The version used to write an entity
152 std::uint32_t fVersionUse = 0;
153 /// The minimum required version necessary to read an entity
154 std::uint32_t fVersionMin = 0;
156
157public:
158 RNTupleVersion() = default;
159 RNTupleVersion(std::uint32_t versionUse, std::uint32_t versionMin)
160 : fVersionUse(versionUse), fVersionMin(versionMin)
161 {}
162 RNTupleVersion(std::uint32_t versionUse, std::uint32_t versionMin, NTupleFlags_t flags)
163 : fVersionUse(versionUse), fVersionMin(versionMin), fFlags(flags)
164 {}
165
166 bool operator ==(const RNTupleVersion &other) const {
167 return fVersionUse == other.fVersionUse && fVersionMin == other.fVersionMin && fFlags == other.fFlags;
168 }
169
170 std::uint32_t GetVersionUse() const { return fVersionUse; }
171 std::uint32_t GetVersionMin() const { return fVersionMin; }
172 NTupleFlags_t GetFlags() const { return fFlags; }
173};
174
175
176/// Generic information about the physical location of data. Values depend on the concrete storage type. E.g.,
177/// for a local file fUrl might be unsused and fPosition might be a file offset. Objects on storage can be compressed
178/// and therefore we need to store their actual size.
179/// TODO(jblomer): should move the RNTUpleDescriptor and should be an std::variant
181 std::int64_t fPosition = 0;
182 std::uint32_t fBytesOnStorage = 0;
183 std::string fUrl;
184
185 bool operator==(const RNTupleLocator &other) const {
186 return fPosition == other.fPosition && fBytesOnStorage == other.fBytesOnStorage && fUrl == other.fUrl;
187 }
188};
189
190} // namespace Experimental
191} // namespace ROOT
192
193#endif
ROOT::R::TRInterface & r
Definition Object.C:4
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
RClusterIndex operator+(ClusterSize_t::ValueType off) const
bool operator==(const RClusterIndex &other) const
bool operator!=(const RClusterIndex &other) const
ClusterSize_t::ValueType fIndex
RClusterIndex operator-(ClusterSize_t::ValueType off) const
RClusterIndex & operator=(const RClusterIndex &other)=default
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)
For forward and backward compatibility, attach version information to the consitituents of the file f...
bool operator==(const RNTupleVersion &other) const
std::uint32_t fVersionMin
The minimum required version necessary to read an entity.
RNTupleVersion(std::uint32_t versionUse, std::uint32_t versionMin)
std::uint32_t GetVersionUse() const
RNTupleVersion(std::uint32_t versionUse, std::uint32_t versionMin, NTupleFlags_t flags)
std::uint32_t fVersionUse
The version used to write an entity.
std::uint32_t GetVersionMin() const
std::uint32_t DeserializeInt64(const void *buffer, std::int64_t *val)
std::uint32_t DeserializeUInt16(const void *buffer, std::uint16_t *val)
std::uint32_t SerializeInt64(std::int64_t val, void *buffer)
std::uint32_t SerializeUInt32(std::uint32_t val, void *buffer)
std::uint32_t SerializeInt32(std::int32_t val, void *buffer)
std::uint32_t SerializeUInt16(std::uint16_t val, void *buffer)
std::uint32_t SerializeInt16(std::int16_t val, void *buffer)
std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t *val)
std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer)
std::uint32_t DeserializeString(const void *buffer, std::string *val)
std::uint32_t DeserializeInt16(const void *buffer, std::int16_t *val)
std::uint32_t DeserializeInt32(const void *buffer, std::int32_t *val)
std::uint32_t DeserializeUInt32(const void *buffer, std::uint32_t *val)
std::uint32_t SerializeString(const std::string &val, void *buffer)
void PrintRNTuple(const RNTuple &ntuple, std::ostream &output)
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.
std::uint64_t NTupleFlags_t
64 possible flags to apply to all versioned entities (so far unused).
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.
std::string RNTupleUuid
Every NTuple is identified by a UUID. TODO(jblomer): should this be a TUUID?
constexpr ClusterSize_t kInvalidClusterIndex(std::uint32_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 32bit integer in a struct in order to avoid template specialization clash with std::uint32_t...
RClusterSize & operator=(const ValueType value)
constexpr RClusterSize(ValueType value)
RClusterSize & operator+=(const ValueType value)
Generic information about the physical location of data.
bool operator==(const RNTupleLocator &other) const
Entry point for an RNTuple in a ROOT file.
Definition RMiniFile.hxx:55
static void output(int code)
Definition gifencode.c:226