File indexing completed on 2025-12-14 10:31:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef ROOT_RNTupleTypes
0015 #define ROOT_RNTupleTypes
0016
0017 #include <ROOT/RConfig.hxx>
0018
0019 #include <cstddef>
0020 #include <cstdint>
0021 #include <limits>
0022 #include <ostream>
0023 #include <type_traits>
0024 #include <variant>
0025
0026 namespace ROOT {
0027
0028
0029
0030 template <typename SizeT>
0031 struct RNTupleCardinality {
0032 static_assert(std::is_same_v<SizeT, std::uint32_t> || std::is_same_v<SizeT, std::uint64_t>,
0033 "RNTupleCardinality is only supported with std::uint32_t or std::uint64_t template parameters");
0034
0035 using ValueType = SizeT;
0036
0037 RNTupleCardinality() : fValue(0) {}
0038 explicit constexpr RNTupleCardinality(ValueType value) : fValue(value) {}
0039 RNTupleCardinality &operator=(const ValueType value)
0040 {
0041 fValue = value;
0042 return *this;
0043 }
0044 operator ValueType() const { return fValue; }
0045
0046 ValueType fValue;
0047 };
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 enum class ENTupleColumnType {
0066 kUnknown = 0,
0067
0068 kIndex64,
0069 kIndex32,
0070
0071
0072 kSwitch,
0073 kByte,
0074 kChar,
0075 kBit,
0076 kReal64,
0077 kReal32,
0078 kReal16,
0079 kInt64,
0080 kUInt64,
0081 kInt32,
0082 kUInt32,
0083 kInt16,
0084 kUInt16,
0085 kInt8,
0086 kUInt8,
0087 kSplitIndex64,
0088 kSplitIndex32,
0089 kSplitReal64,
0090 kSplitReal32,
0091 kSplitInt64,
0092 kSplitUInt64,
0093 kSplitInt32,
0094 kSplitUInt32,
0095 kSplitInt16,
0096 kSplitUInt16,
0097 kReal32Trunc,
0098 kReal32Quant,
0099 kMax,
0100 };
0101
0102
0103
0104
0105
0106
0107
0108 enum class ENTupleStructure : std::uint16_t {
0109 kInvalid,
0110 kPlain,
0111 kCollection,
0112 kRecord,
0113 kVariant,
0114 kStreamer,
0115 kUnknown,
0116
0117
0118 kLeaf R__DEPRECATED(6, 42, "use instead ROOT::ENTupleStructure::kPlain") = kPlain
0119 };
0120
0121 inline std::ostream &operator<<(std::ostream &os, ENTupleStructure structure)
0122 {
0123 static const char *const names[] = {"Invalid", "Plain", "Collection", "Record", "Variant", "Streamer", "Unknown"};
0124 static_assert((std::size_t)ENTupleStructure::kUnknown + 1 == std::size(names));
0125
0126 if (R__likely(static_cast<std::size_t>(structure) <= std::size(names)))
0127 os << names[static_cast<std::uint16_t>(structure)];
0128 else
0129 os << "(invalid)";
0130 return os;
0131 }
0132
0133
0134 using NTupleSize_t = std::uint64_t;
0135 constexpr NTupleSize_t kInvalidNTupleIndex = std::uint64_t(-1);
0136
0137
0138 using DescriptorId_t = std::uint64_t;
0139 constexpr DescriptorId_t kInvalidDescriptorId = std::uint64_t(-1);
0140
0141
0142 class RNTupleLocalIndex {
0143 private:
0144 ROOT::DescriptorId_t fClusterId = ROOT::kInvalidDescriptorId;
0145 ROOT::NTupleSize_t fIndexInCluster = ROOT::kInvalidNTupleIndex;
0146
0147 public:
0148 RNTupleLocalIndex() = default;
0149 RNTupleLocalIndex(const RNTupleLocalIndex &other) = default;
0150 RNTupleLocalIndex &operator=(const RNTupleLocalIndex &other) = default;
0151 constexpr RNTupleLocalIndex(ROOT::DescriptorId_t clusterId, ROOT::NTupleSize_t indexInCluster)
0152 : fClusterId(clusterId), fIndexInCluster(indexInCluster)
0153 {
0154 }
0155
0156 RNTupleLocalIndex operator+(ROOT::NTupleSize_t off) const
0157 {
0158 return RNTupleLocalIndex(fClusterId, fIndexInCluster + off);
0159 }
0160
0161 RNTupleLocalIndex operator-(ROOT::NTupleSize_t off) const
0162 {
0163 return RNTupleLocalIndex(fClusterId, fIndexInCluster - off);
0164 }
0165
0166 RNTupleLocalIndex operator*(ROOT::NTupleSize_t repetitionFactor) const
0167 {
0168 return RNTupleLocalIndex(fClusterId, fIndexInCluster * repetitionFactor);
0169 }
0170
0171 RNTupleLocalIndex operator++(int)
0172 {
0173 auto r = *this;
0174 fIndexInCluster++;
0175 return r;
0176 }
0177
0178 RNTupleLocalIndex &operator++()
0179 {
0180 ++fIndexInCluster;
0181 return *this;
0182 }
0183
0184 bool operator==(RNTupleLocalIndex other) const
0185 {
0186 return fClusterId == other.fClusterId && fIndexInCluster == other.fIndexInCluster;
0187 }
0188
0189 bool operator!=(RNTupleLocalIndex other) const { return !(*this == other); }
0190
0191 ROOT::DescriptorId_t GetClusterId() const { return fClusterId; }
0192 ROOT::NTupleSize_t GetIndexInCluster() const { return fIndexInCluster; }
0193 };
0194
0195
0196
0197
0198 class RNTupleLocatorObject64 {
0199 private:
0200 std::uint64_t fLocation = 0;
0201
0202 public:
0203 RNTupleLocatorObject64() = default;
0204 explicit RNTupleLocatorObject64(std::uint64_t location) : fLocation(location) {}
0205 bool operator==(const RNTupleLocatorObject64 &other) const { return fLocation == other.fLocation; }
0206 std::uint64_t GetLocation() const { return fLocation; }
0207 };
0208
0209
0210
0211
0212 class RNTupleLocator {
0213 public:
0214
0215
0216 enum ELocatorType : std::uint8_t {
0217
0218
0219 kTypeFile = 0x00,
0220 kTypeDAOS = 0x02,
0221
0222 kLastSerializableType = 0x7f,
0223 kTypePageZero = kLastSerializableType + 1,
0224 kTypeUnknown,
0225 };
0226
0227 private:
0228 std::uint64_t fNBytesOnStorage = 0;
0229
0230
0231 std::variant<std::uint64_t, RNTupleLocatorObject64> fPosition{};
0232
0233
0234 ELocatorType fType = kTypeFile;
0235
0236 std::uint8_t fReserved = 0;
0237
0238 public:
0239 RNTupleLocator() = default;
0240
0241 bool operator==(const RNTupleLocator &other) const
0242 {
0243 return fPosition == other.fPosition && fNBytesOnStorage == other.fNBytesOnStorage && fType == other.fType;
0244 }
0245
0246 std::uint64_t GetNBytesOnStorage() const { return fNBytesOnStorage; }
0247 ELocatorType GetType() const { return fType; }
0248 std::uint8_t GetReserved() const { return fReserved; }
0249
0250 void SetNBytesOnStorage(std::uint64_t nBytesOnStorage) { fNBytesOnStorage = nBytesOnStorage; }
0251 void SetType(ELocatorType type) { fType = type; }
0252 void SetReserved(std::uint8_t reserved) { fReserved = reserved; }
0253
0254 template <typename T>
0255 T GetPosition() const
0256 {
0257 return std::get<T>(fPosition);
0258 }
0259
0260 template <typename T>
0261 void SetPosition(T position)
0262 {
0263 fPosition = position;
0264 }
0265 };
0266
0267 namespace Internal {
0268
0269
0270
0271 class RColumnIndex {
0272 public:
0273 using ValueType = std::uint64_t;
0274
0275 private:
0276 ValueType fValue = 0;
0277
0278 public:
0279 RColumnIndex() = default;
0280 explicit constexpr RColumnIndex(ValueType value) : fValue(value) {}
0281 RColumnIndex &operator=(const ValueType value)
0282 {
0283 fValue = value;
0284 return *this;
0285 }
0286 RColumnIndex &operator+=(const ValueType value)
0287 {
0288 fValue += value;
0289 return *this;
0290 }
0291 RColumnIndex operator++(int)
0292 {
0293 auto result = *this;
0294 fValue++;
0295 return result;
0296 }
0297 operator ValueType() const { return fValue; }
0298 };
0299
0300
0301 class RColumnSwitch {
0302 private:
0303 ROOT::NTupleSize_t fIndex;
0304 std::uint32_t fTag = 0;
0305
0306 public:
0307 RColumnSwitch() = default;
0308 RColumnSwitch(ROOT::NTupleSize_t index, std::uint32_t tag) : fIndex(index), fTag(tag) {}
0309 ROOT::NTupleSize_t GetIndex() const { return fIndex; }
0310 std::uint32_t GetTag() const { return fTag; }
0311 };
0312
0313 inline constexpr ENTupleColumnType kTestFutureColumnType =
0314 static_cast<ENTupleColumnType>(std::numeric_limits<std::underlying_type_t<ENTupleColumnType>>::max() - 1);
0315
0316 inline constexpr ROOT::ENTupleStructure kTestFutureFieldStructure =
0317 static_cast<ROOT::ENTupleStructure>(std::numeric_limits<std::underlying_type_t<ROOT::ENTupleStructure>>::max() - 1);
0318
0319 inline constexpr RNTupleLocator::ELocatorType kTestLocatorType = static_cast<RNTupleLocator::ELocatorType>(0x7e);
0320 static_assert(kTestLocatorType < RNTupleLocator::ELocatorType::kLastSerializableType);
0321
0322 }
0323 }
0324
0325 #endif