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