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 
25 namespace ROOT {
26 namespace Experimental {
27 
28 class RLogChannel;
29 /// Log channel for RNTuple diagnostics.
30 RLogChannel &NTupleLog();
31 
32 struct RNTuple;
33 
34 namespace Internal {
35 
36 void PrintRNTuple(const RNTuple& ntuple, std::ostream& output);
37 
38 } // namespace Internal
39 
40 /**
41  * The fields in the ntuple model tree can carry different structural information about the type system.
42  * Leaf fields contain just data, collection fields resolve to offset columns, record fields have no
43  * materialization on the primitive column layer.
44  */
50  kReference, // unimplemented so far
52 };
53 
54 /// Integer type long enough to hold the maximum number of entries in a column
55 using NTupleSize_t = std::uint64_t;
56 constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
57 /// Wrap the 32bit integer in a struct in order to avoid template specialization clash with std::uint32_t
58 struct RClusterSize {
59  using ValueType = std::uint32_t;
60 
61  RClusterSize() : fValue(0) {}
62  explicit constexpr RClusterSize(ValueType value) : fValue(value) {}
63  RClusterSize& operator =(const ValueType value) { fValue = value; return *this; }
64  RClusterSize& operator +=(const ValueType value) { fValue += value; return *this; }
65  RClusterSize operator++(int) { auto result = *this; fValue++; return result; }
66  operator ValueType() const { return fValue; }
67 
69 };
71 constexpr ClusterSize_t kInvalidClusterIndex(std::uint32_t(-1));
72 
73 /// Holds the index and the tag of a kSwitch column
75 private:
77  std::uint32_t fTag = 0;
78 
79 public:
80  RColumnSwitch() = default;
81  RColumnSwitch(ClusterSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) { }
82  ClusterSize_t GetIndex() const { return fIndex; }
83  std::uint32_t GetTag() const { return fTag; }
84 };
85 
86 /// Uniquely identifies a physical column within the scope of the current process, used to tag pages
87 using ColumnId_t = std::int64_t;
89 
90 /// Distriniguishes elements of the same type within a descriptor, e.g. different fields
91 using DescriptorId_t = std::uint64_t;
92 constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
93 
94 /// Addresses a column element or field item relative to a particular cluster, instead of a global NTupleSize_t index
96 private:
99 public:
100  RClusterIndex() = default;
101  RClusterIndex(const RClusterIndex &other) = default;
102  RClusterIndex &operator =(const RClusterIndex &other) = default;
104  : fClusterId(clusterId), fIndex(index) {}
105 
108  RClusterIndex operator++(int) /* postfix */ { auto r = *this; fIndex++; return r; }
109  RClusterIndex& operator++() /* prefix */ { ++fIndex; return *this; }
110  bool operator==(const RClusterIndex &other) const {
111  return fClusterId == other.fClusterId && fIndex == other.fIndex;
112  }
113  bool operator!=(const RClusterIndex &other) const { return !(*this == other); }
114 
117 };
118 
119 /// Every NTuple is identified by a UUID. TODO(jblomer): should this be a TUUID?
120 using RNTupleUuid = std::string;
121 
122 
123 /// 64 possible flags to apply to all versioned entities (so far unused).
124 using NTupleFlags_t = std::uint64_t;
125 /// For forward and backward compatibility, attach version information to
126 /// the consitituents of the file format (column, field, cluster, ntuple).
128 private:
129  /// The version used to write an entity
130  std::uint32_t fVersionUse = 0;
131  /// The minimum required version necessary to read an entity
132  std::uint32_t fVersionMin = 0;
134 
135 public:
136  RNTupleVersion() = default;
137  RNTupleVersion(std::uint32_t versionUse, std::uint32_t versionMin)
138  : fVersionUse(versionUse), fVersionMin(versionMin)
139  {}
140  RNTupleVersion(std::uint32_t versionUse, std::uint32_t versionMin, NTupleFlags_t flags)
141  : fVersionUse(versionUse), fVersionMin(versionMin), fFlags(flags)
142  {}
143 
144  bool operator ==(const RNTupleVersion &other) const {
145  return fVersionUse == other.fVersionUse && fVersionMin == other.fVersionMin && fFlags == other.fFlags;
146  }
147 
148  std::uint32_t GetVersionUse() const { return fVersionUse; }
149  std::uint32_t GetVersionMin() const { return fVersionMin; }
150  NTupleFlags_t GetFlags() const { return fFlags; }
151 };
152 
153 } // namespace Experimental
154 } // namespace ROOT
155 
156 #endif
ROOT::Experimental::Internal::PrintRNTuple
void PrintRNTuple(const RNTuple &ntuple, std::ostream &output)
Definition: RNTupleUtil.cxx:33
ROOT::Experimental::kLeaf
@ kLeaf
Definition: RNTupleUtil.hxx:46
ROOT::Experimental::RClusterIndex::RClusterIndex
RClusterIndex(const RClusterIndex &other)=default
ROOT::Experimental::RNTupleVersion::fVersionUse
std::uint32_t fVersionUse
The version used to write an entity.
Definition: RNTupleUtil.hxx:130
ROOT::Experimental::RClusterSize::fValue
ValueType fValue
Definition: RNTupleUtil.hxx:68
ROOT::Experimental::NTupleLog
RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
Definition: RNTupleUtil.cxx:23
ROOT::Experimental::RColumnSwitch::RColumnSwitch
RColumnSwitch(ClusterSize_t index, std::uint32_t tag)
Definition: RNTupleUtil.hxx:81
ROOT::Experimental::RColumnSwitch::GetIndex
ClusterSize_t GetIndex() const
Definition: RNTupleUtil.hxx:82
ROOT::Experimental::DescriptorId_t
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
Definition: RNTupleUtil.hxx:91
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Experimental::kInvalid
@ kInvalid
Definition: RNTupleUtil.hxx:51
ROOT::Experimental::kReference
@ kReference
Definition: RNTupleUtil.hxx:50
output
static void output(int code)
Definition: gifencode.c:226
ROOT::Experimental::RClusterIndex::operator+
RClusterIndex operator+(ClusterSize_t::ValueType off) const
Definition: RNTupleUtil.hxx:106
ROOT::Experimental::RClusterSize::operator+=
RClusterSize & operator+=(const ValueType value)
Definition: RNTupleUtil.hxx:64
ROOT::Experimental::RNTupleVersion::operator==
bool operator==(const RNTupleVersion &other) const
Definition: RNTupleUtil.hxx:144
ROOT::Experimental::RClusterIndex::operator++
RClusterIndex operator++(int)
Definition: RNTupleUtil.hxx:108
ROOT::Experimental::RClusterSize::operator=
RClusterSize & operator=(const ValueType value)
Definition: RNTupleUtil.hxx:63
ROOT::Experimental::NTupleSize_t
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:55
ROOT::Experimental::RColumnSwitch::RColumnSwitch
RColumnSwitch()=default
ROOT::Experimental::RNTupleVersion::GetVersionMin
std::uint32_t GetVersionMin() const
Definition: RNTupleUtil.hxx:149
ROOT::Experimental::ENTupleStructure
ENTupleStructure
The fields in the ntuple model tree can carry different structural information about the type system.
Definition: RNTupleUtil.hxx:45
ROOT::Experimental::RClusterIndex::operator=
RClusterIndex & operator=(const RClusterIndex &other)=default
ROOT::Experimental::RClusterIndex::fClusterId
DescriptorId_t fClusterId
Definition: RNTupleUtil.hxx:97
ROOT::Experimental::kInvalidColumnId
constexpr ColumnId_t kInvalidColumnId
Definition: RNTupleUtil.hxx:88
ROOT::Experimental::RClusterIndex::GetIndex
ClusterSize_t::ValueType GetIndex() const
Definition: RNTupleUtil.hxx:116
ROOT::Experimental::RNTupleUuid
std::string RNTupleUuid
Every NTuple is identified by a UUID. TODO(jblomer): should this be a TUUID?
Definition: RNTupleUtil.hxx:120
ROOT::Experimental::RColumnSwitch::GetTag
std::uint32_t GetTag() const
Definition: RNTupleUtil.hxx:83
ROOT::Experimental::RNTupleVersion
For forward and backward compatibility, attach version information to the consitituents of the file f...
Definition: RNTupleUtil.hxx:127
ROOT::Experimental::RClusterSize::RClusterSize
RClusterSize()
Definition: RNTupleUtil.hxx:61
ROOT::Experimental::kCollection
@ kCollection
Definition: RNTupleUtil.hxx:47
RLogger.hxx
ROOT::Experimental::kInvalidClusterIndex
constexpr ClusterSize_t kInvalidClusterIndex(std::uint32_t(-1))
ROOT::Experimental::RClusterSize::ValueType
std::uint32_t ValueType
Definition: RNTupleUtil.hxx:59
ROOT::Experimental::RNTupleVersion::RNTupleVersion
RNTupleVersion(std::uint32_t versionUse, std::uint32_t versionMin, NTupleFlags_t flags)
Definition: RNTupleUtil.hxx:140
ROOT::Experimental::kInvalidNTupleIndex
constexpr NTupleSize_t kInvalidNTupleIndex
Definition: RNTupleUtil.hxx:56
ROOT::Experimental::RClusterIndex::GetClusterId
DescriptorId_t GetClusterId() const
Definition: RNTupleUtil.hxx:115
ROOT::Experimental::RClusterIndex::RClusterIndex
constexpr RClusterIndex(DescriptorId_t clusterId, ClusterSize_t::ValueType index)
Definition: RNTupleUtil.hxx:103
ROOT::Experimental::RNTupleVersion::GetFlags
NTupleFlags_t GetFlags() const
Definition: RNTupleUtil.hxx:150
ROOT::Experimental::kRecord
@ kRecord
Definition: RNTupleUtil.hxx:48
ROOT::Experimental::RNTupleVersion::RNTupleVersion
RNTupleVersion()=default
ROOT::Experimental::RClusterIndex::operator-
RClusterIndex operator-(ClusterSize_t::ValueType off) const
Definition: RNTupleUtil.hxx:107
ROOT::Experimental::RClusterIndex::RClusterIndex
RClusterIndex()=default
ROOT::Experimental::RClusterIndex::operator!=
bool operator!=(const RClusterIndex &other) const
Definition: RNTupleUtil.hxx:113
ROOT::Experimental::RClusterIndex
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Definition: RNTupleUtil.hxx:95
ROOT::Experimental::RNTupleVersion::fVersionMin
std::uint32_t fVersionMin
The minimum required version necessary to read an entity.
Definition: RNTupleUtil.hxx:132
ROOT::Experimental::RClusterSize
Wrap the 32bit integer in a struct in order to avoid template specialization clash with std::uint32_t...
Definition: RNTupleUtil.hxx:58
ROOT::Experimental::RClusterIndex::operator++
RClusterIndex & operator++()
Definition: RNTupleUtil.hxx:109
ROOT::Experimental::RColumnSwitch::fTag
std::uint32_t fTag
Definition: RNTupleUtil.hxx:77
ROOT::Experimental::RClusterIndex::operator==
bool operator==(const RClusterIndex &other) const
Definition: RNTupleUtil.hxx:110
ROOT::Experimental::kVariant
@ kVariant
Definition: RNTupleUtil.hxx:49
ROOT::Experimental::RColumnSwitch::fIndex
ClusterSize_t fIndex
Definition: RNTupleUtil.hxx:76
ROOT::Experimental::NTupleFlags_t
std::uint64_t NTupleFlags_t
64 possible flags to apply to all versioned entities (so far unused).
Definition: RNTupleUtil.hxx:124
ROOT::Experimental::RClusterSize::operator++
RClusterSize operator++(int)
Definition: RNTupleUtil.hxx:65
ROOT::Experimental::RClusterSize::RClusterSize
constexpr RClusterSize(ValueType value)
Definition: RNTupleUtil.hxx:62
ROOT::Experimental::RNTupleVersion::fFlags
NTupleFlags_t fFlags
Definition: RNTupleUtil.hxx:133
ROOT::Experimental::RColumnSwitch
Holds the index and the tag of a kSwitch column.
Definition: RNTupleUtil.hxx:74
ROOT::Experimental::kInvalidDescriptorId
constexpr DescriptorId_t kInvalidDescriptorId
Definition: RNTupleUtil.hxx:92
ROOT::Experimental::RNTupleVersion::GetVersionUse
std::uint32_t GetVersionUse() const
Definition: RNTupleUtil.hxx:148
ROOT::Experimental::RClusterIndex::fIndex
ClusterSize_t::ValueType fIndex
Definition: RNTupleUtil.hxx:98
ROOT::Experimental::ColumnId_t
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
Definition: RNTupleUtil.hxx:87
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Experimental::RNTupleVersion::RNTupleVersion
RNTupleVersion(std::uint32_t versionUse, std::uint32_t versionMin)
Definition: RNTupleUtil.hxx:137