Logo ROOT  
Reference Guide
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} // namespace Experimental
176} // namespace ROOT
177
178#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.
Definition: RNTupleUtil.hxx:96
ClusterSize_t GetIndex() const
std::uint32_t GetTag() const
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
NTupleFlags_t GetFlags() 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)
Definition: RNTupleUtil.cxx:58
std::uint32_t DeserializeUInt16(const void *buffer, std::uint16_t *val)
std::uint32_t SerializeInt64(std::int64_t val, void *buffer)
Definition: RNTupleUtil.cxx:37
std::uint32_t SerializeUInt32(std::uint32_t val, void *buffer)
Definition: RNTupleUtil.cxx:85
std::uint32_t SerializeInt32(std::int32_t val, void *buffer)
Definition: RNTupleUtil.cxx:73
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)
Definition: RNTupleUtil.cxx:68
std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer)
Definition: RNTupleUtil.cxx:53
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)
Definition: RNTupleUtil.cxx:90
std::uint32_t DeserializeUInt32(const void *buffer, std::uint32_t *val)
Definition: RNTupleUtil.cxx:98
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.
Definition: RNTupleUtil.cxx:24
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:77
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.
Definition: RNTupleUtil.hxx:67
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
Definition: RNTupleUtil.hxx:78
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...
Definition: RNTupleUtil.hxx:80
RClusterSize & operator=(const ValueType value)
Definition: RNTupleUtil.hxx:85
constexpr RClusterSize(ValueType value)
Definition: RNTupleUtil.hxx:84
RClusterSize & operator+=(const ValueType value)
Definition: RNTupleUtil.hxx:86
Entry point for an RNTuple in a ROOT file.
Definition: RMiniFile.hxx:55
static void output(int code)
Definition: gifencode.c:226