Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleSerialize.cxx
Go to the documentation of this file.
1/// \file RNTupleSerialize.cxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \author Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
5/// \date 2021-08-02
6/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
7/// is welcome!
8
9/*************************************************************************
10 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
11 * All rights reserved. *
12 * *
13 * For the licensing terms see $ROOTSYS/LICENSE. *
14 * For the list of contributors see $ROOTSYS/README/CREDITS. *
15 *************************************************************************/
16
18#include <ROOT/RColumnModel.hxx>
19#include <ROOT/RError.hxx>
22
23#include <RVersion.h>
24#include <xxhash.h>
25
26#include <cstring> // for memcpy
27#include <deque>
28#include <set>
29#include <unordered_map>
30
31template <typename T>
33
34
35namespace {
37
38std::uint32_t SerializeField(const ROOT::Experimental::RFieldDescriptor &fieldDesc,
39 ROOT::Experimental::DescriptorId_t onDiskParentId, void *buffer)
40{
41
42 auto base = reinterpret_cast<unsigned char *>(buffer);
43 auto pos = base;
44 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
45
46 pos += RNTupleSerializer::SerializeRecordFramePreamble(*where);
47
48 pos += RNTupleSerializer::SerializeUInt32(fieldDesc.GetFieldVersion(), *where);
49 pos += RNTupleSerializer::SerializeUInt32(fieldDesc.GetTypeVersion(), *where);
50 pos += RNTupleSerializer::SerializeUInt32(onDiskParentId, *where);
51 pos += RNTupleSerializer::SerializeFieldStructure(fieldDesc.GetStructure(), *where);
52 if (fieldDesc.GetNRepetitions() > 0) {
53 pos += RNTupleSerializer::SerializeUInt16(RNTupleSerializer::kFlagRepetitiveField, *where);
54 pos += RNTupleSerializer::SerializeUInt64(fieldDesc.GetNRepetitions(), *where);
55 } else {
56 pos += RNTupleSerializer::SerializeUInt16(0, *where);
57 }
58 pos += RNTupleSerializer::SerializeString(fieldDesc.GetFieldName(), *where);
59 pos += RNTupleSerializer::SerializeString(fieldDesc.GetTypeName(), *where);
60 pos += RNTupleSerializer::SerializeString(fieldDesc.GetTypeAlias(), *where);
61 pos += RNTupleSerializer::SerializeString(fieldDesc.GetFieldDescription(), *where);
62
63 auto size = pos - base;
64 RNTupleSerializer::SerializeFramePostscript(base, size);
65
66 return size;
67}
68
69// clang-format off
70/// Serialize, in order, fields enumerated in `fieldList` to `buffer`. `firstOnDiskId` specifies the on-disk ID for the
71/// first element in the `fieldList` sequence. Before calling this function `RContext::MapSchema()` should have been
72/// called on `context` in order to map in-memory field IDs to their on-disk counterpart.
73/// \return The number of bytes written to the output buffer; if `buffer` is `nullptr` no data is serialized and the
74/// required buffer size is returned
75// clang-format on
76std::uint32_t SerializeFieldList(const ROOT::Experimental::RNTupleDescriptor &desc,
77 std::span<const ROOT::Experimental::DescriptorId_t> fieldList,
78 std::size_t firstOnDiskId,
80{
81 auto base = reinterpret_cast<unsigned char *>(buffer);
82 auto pos = base;
83 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
84
85 auto fieldZeroId = desc.GetFieldZeroId();
86 ROOT::Experimental::DescriptorId_t onDiskFieldId = firstOnDiskId;
87 for (auto fieldId : fieldList) {
88 const auto &f = desc.GetFieldDescriptor(fieldId);
89 auto onDiskParentId =
90 (f.GetParentId() == fieldZeroId) ? onDiskFieldId : context.GetOnDiskFieldId(f.GetParentId());
91 pos += SerializeField(f, onDiskParentId, *where);
92 ++onDiskFieldId;
93 }
94
95 return pos - base;
96}
97
98RResult<std::uint32_t> DeserializeField(const void *buffer, std::uint64_t bufSize,
100{
101 using ENTupleStructure = ROOT::Experimental::ENTupleStructure;
102
103 auto base = reinterpret_cast<const unsigned char *>(buffer);
104 auto bytes = base;
105 std::uint64_t frameSize;
106 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
107 auto result = RNTupleSerializer::DeserializeFrameHeader(bytes, bufSize, frameSize);
108 if (!result)
109 return R__FORWARD_ERROR(result);
110 bytes += result.Unwrap();
111
112 std::uint32_t fieldVersion;
113 std::uint32_t typeVersion;
114 std::uint32_t parentId;
115 // initialize properly for call to SerializeFieldStructure()
116 ENTupleStructure structure{ENTupleStructure::kLeaf};
117 std::uint16_t flags;
118 if (fnFrameSizeLeft() < 3 * sizeof(std::uint32_t) +
119 RNTupleSerializer::SerializeFieldStructure(structure, nullptr) +
120 sizeof(std::uint16_t))
121 {
122 return R__FAIL("field record frame too short");
123 }
124 bytes += RNTupleSerializer::DeserializeUInt32(bytes, fieldVersion);
125 bytes += RNTupleSerializer::DeserializeUInt32(bytes, typeVersion);
126 bytes += RNTupleSerializer::DeserializeUInt32(bytes, parentId);
127 auto res16 = RNTupleSerializer::DeserializeFieldStructure(bytes, structure);
128 if (!res16)
129 return R__FORWARD_ERROR(res16);
130 bytes += res16.Unwrap();
131 bytes += RNTupleSerializer::DeserializeUInt16(bytes, flags);
132 fieldDesc.FieldVersion(fieldVersion).TypeVersion(typeVersion).ParentId(parentId).Structure(structure);
133
134 if (flags & RNTupleSerializer::kFlagRepetitiveField) {
135 if (fnFrameSizeLeft() < sizeof(std::uint64_t))
136 return R__FAIL("field record frame too short");
137 std::uint64_t nRepetitions;
138 bytes += RNTupleSerializer::DeserializeUInt64(bytes, nRepetitions);
139 fieldDesc.NRepetitions(nRepetitions);
140 }
141
142 std::string fieldName;
143 std::string typeName;
144 std::string aliasName;
145 std::string description;
146 result = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), fieldName).Unwrap();
147 if (!result)
148 return R__FORWARD_ERROR(result);
149 bytes += result.Unwrap();
150 result = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), typeName).Unwrap();
151 if (!result)
152 return R__FORWARD_ERROR(result);
153 bytes += result.Unwrap();
154 result = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), aliasName).Unwrap();
155 if (!result)
156 return R__FORWARD_ERROR(result);
157 bytes += result.Unwrap();
158 result = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), description).Unwrap();
159 if (!result)
160 return R__FORWARD_ERROR(result);
161 bytes += result.Unwrap();
162 fieldDesc.FieldName(fieldName).TypeName(typeName).TypeAlias(aliasName).FieldDescription(description);
163
164 return frameSize;
165}
166
167std::uint32_t SerializeColumnList(const ROOT::Experimental::RNTupleDescriptor &desc,
168 std::span<const ROOT::Experimental::DescriptorId_t> fieldList,
170 void *buffer)
171{
172 using RColumnElementBase = ROOT::Experimental::Internal::RColumnElementBase;
173
174 auto base = reinterpret_cast<unsigned char *>(buffer);
175 auto pos = base;
176 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
177
178 for (auto parentId : fieldList) {
179 for (const auto &c : desc.GetColumnIterable(parentId)) {
180 if (c.IsAliasColumn())
181 continue;
182
183 auto frame = pos;
184 pos += RNTupleSerializer::SerializeRecordFramePreamble(*where);
185
186 auto type = c.GetModel().GetType();
187 pos += RNTupleSerializer::SerializeColumnType(type, *where);
188 pos += RNTupleSerializer::SerializeUInt16(RColumnElementBase::GetBitsOnStorage(type), *where);
189 pos += RNTupleSerializer::SerializeUInt32(context.GetOnDiskFieldId(c.GetFieldId()), *where);
190 std::uint32_t flags = 0;
191 // TODO(jblomer): add support for descending columns in the column model
192 if (c.GetModel().GetIsSorted())
193 flags |= RNTupleSerializer::kFlagSortAscColumn;
194 // TODO(jblomer): fix for unsigned integer types
196 flags |= RNTupleSerializer::kFlagNonNegativeColumn;
197 const std::uint64_t firstElementIdx = c.GetFirstElementIndex();
198 if (firstElementIdx > 0)
199 flags |= RNTupleSerializer::kFlagDeferredColumn;
200 pos += RNTupleSerializer::SerializeUInt32(flags, *where);
201 if (flags & RNTupleSerializer::kFlagDeferredColumn)
202 pos += RNTupleSerializer::SerializeUInt64(firstElementIdx, *where);
203
204 pos += RNTupleSerializer::SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
205 }
206 }
207
208 return pos - base;
209}
210
211RResult<std::uint32_t> DeserializeColumn(const void *buffer, std::uint64_t bufSize,
213{
215
216 auto base = reinterpret_cast<const unsigned char *>(buffer);
217 auto bytes = base;
218 std::uint64_t frameSize;
219 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
220 auto result = RNTupleSerializer::DeserializeFrameHeader(bytes, bufSize, frameSize);
221 if (!result)
222 return R__FORWARD_ERROR(result);
223 bytes += result.Unwrap();
224
225 // Initialize properly for SerializeColumnType
226 EColumnType type{EColumnType::kIndex32};
227 std::uint16_t bitsOnStorage;
228 std::uint32_t fieldId;
229 std::uint32_t flags;
230 std::uint64_t firstElementIdx = 0;
231 if (fnFrameSizeLeft() < RNTupleSerializer::SerializeColumnType(type, nullptr) +
232 sizeof(std::uint16_t) + 2 * sizeof(std::uint32_t))
233 {
234 return R__FAIL("column record frame too short");
235 }
236 auto res16 = RNTupleSerializer::DeserializeColumnType(bytes, type);
237 if (!res16)
238 return R__FORWARD_ERROR(res16);
239 bytes += res16.Unwrap();
240 bytes += RNTupleSerializer::DeserializeUInt16(bytes, bitsOnStorage);
241 bytes += RNTupleSerializer::DeserializeUInt32(bytes, fieldId);
242 bytes += RNTupleSerializer::DeserializeUInt32(bytes, flags);
243 if (flags & RNTupleSerializer::kFlagDeferredColumn) {
244 if (fnFrameSizeLeft() < sizeof(std::uint64_t))
245 return R__FAIL("column record frame too short");
246 bytes += RNTupleSerializer::DeserializeUInt64(bytes, firstElementIdx);
247 }
248
250 return R__FAIL("column element size mismatch");
251
252 const bool isSorted = (flags & (RNTupleSerializer::kFlagSortAscColumn | RNTupleSerializer::kFlagSortDesColumn));
253 columnDesc.FieldId(fieldId).Model({type, isSorted}).FirstElementIndex(firstElementIdx);
254
255 return frameSize;
256}
257
258std::uint32_t SerializeLocatorPayloadURI(const ROOT::Experimental::RNTupleLocator &locator, unsigned char *buffer)
259{
260 const auto &uri = locator.GetPosition<std::string>();
261 if (uri.length() >= (1 << 16))
262 throw ROOT::Experimental::RException(R__FAIL("locator too large"));
263 if (buffer)
264 memcpy(buffer, uri.data(), uri.length());
265 return uri.length();
266}
267
268void DeserializeLocatorPayloadURI(const unsigned char *buffer, std::uint32_t payloadSize,
270{
271 locator.fBytesOnStorage = 0;
272 auto &uri = locator.fPosition.emplace<std::string>();
273 uri.resize(payloadSize);
274 memcpy(uri.data(), buffer, payloadSize);
275}
276
277std::uint32_t SerializeLocatorPayloadObject64(const ROOT::Experimental::RNTupleLocator &locator, unsigned char *buffer)
278{
280 if (buffer) {
281 RNTupleSerializer::SerializeUInt32(locator.fBytesOnStorage, buffer);
282 RNTupleSerializer::SerializeUInt64(data.fLocation, buffer + sizeof(std::uint32_t));
283 }
284 return sizeof(std::uint32_t) + sizeof(std::uint64_t);
285}
286
287void DeserializeLocatorPayloadObject64(const unsigned char *buffer, ROOT::Experimental::RNTupleLocator &locator)
288{
290 RNTupleSerializer::DeserializeUInt32(buffer, locator.fBytesOnStorage);
291 RNTupleSerializer::DeserializeUInt64(buffer + sizeof(std::uint32_t), data.fLocation);
292}
293
294std::uint32_t SerializeAliasColumnList(const ROOT::Experimental::RNTupleDescriptor &desc,
295 std::span<const ROOT::Experimental::DescriptorId_t> fieldList,
297 void *buffer)
298{
299 auto base = reinterpret_cast<unsigned char *>(buffer);
300 auto pos = base;
301 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
302
303 for (auto parentId : fieldList) {
304 for (const auto &c : desc.GetColumnIterable(parentId)) {
305 if (!c.IsAliasColumn())
306 continue;
307
308 auto frame = pos;
309 pos += RNTupleSerializer::SerializeRecordFramePreamble(*where);
310
311 pos += RNTupleSerializer::SerializeUInt32(context.GetOnDiskColumnId(c.GetPhysicalId()), *where);
312 pos += RNTupleSerializer::SerializeUInt32(context.GetOnDiskFieldId(c.GetFieldId()), *where);
313
314 pos += RNTupleSerializer::SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
315 }
316 }
317
318 return pos - base;
319}
320
321RResult<std::uint32_t> DeserializeAliasColumn(const void *buffer, std::uint64_t bufSize,
322 std::uint32_t &physicalColumnId, std::uint32_t &fieldId)
323{
324 auto base = reinterpret_cast<const unsigned char *>(buffer);
325 auto bytes = base;
326 std::uint64_t frameSize;
327 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
328 auto result = RNTupleSerializer::DeserializeFrameHeader(bytes, bufSize, frameSize);
329 if (!result)
330 return R__FORWARD_ERROR(result);
331 bytes += result.Unwrap();
332
333 if (fnFrameSizeLeft() < 2 * sizeof(std::uint32_t)) {
334 return R__FAIL("alias column record frame too short");
335 }
336
337 bytes += RNTupleSerializer::DeserializeUInt32(bytes, physicalColumnId);
338 bytes += RNTupleSerializer::DeserializeUInt32(bytes, fieldId);
339
340 return frameSize;
341}
342
343} // anonymous namespace
344
346 std::uint64_t length,
347 std::uint64_t &xxhash3, void *buffer)
348{
349 if (buffer != nullptr) {
350 xxhash3 = XXH3_64bits(data, length);
351 SerializeUInt64(xxhash3, buffer);
352 }
353 return 8;
354}
355
357 std::uint64_t length,
358 std::uint64_t &xxhash3)
359{
360 auto checksumReal = XXH3_64bits(data, length);
361 DeserializeUInt64(data + length, xxhash3);
362 if (xxhash3 != checksumReal)
363 return R__FAIL("XxHash-3 checksum mismatch");
364 return RResult<void>::Success();
365}
366
369{
370 std::uint64_t xxhash3;
371 return R__FORWARD_RESULT(VerifyXxHash3(data, length, xxhash3));
372}
373
374
375std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::SerializeInt16(std::int16_t val, void *buffer)
376{
377 if (buffer != nullptr) {
378 auto bytes = reinterpret_cast<unsigned char *>(buffer);
379 bytes[0] = (val & 0x00FF);
380 bytes[1] = (val & 0xFF00) >> 8;
381 }
382 return 2;
383}
384
385std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::DeserializeInt16(const void *buffer, std::int16_t &val)
386{
387 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
388 val = std::int16_t(bytes[0]) + (std::int16_t(bytes[1]) << 8);
389 return 2;
390}
391
392std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::SerializeUInt16(std::uint16_t val, void *buffer)
393{
394 return SerializeInt16(val, buffer);
395}
396
397std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::DeserializeUInt16(const void *buffer, std::uint16_t &val)
398{
399 return DeserializeInt16(buffer, *reinterpret_cast<std::int16_t *>(&val));
400}
401
402std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::SerializeInt32(std::int32_t val, void *buffer)
403{
404 if (buffer != nullptr) {
405 auto bytes = reinterpret_cast<unsigned char *>(buffer);
406 bytes[0] = (val & 0x000000FF);
407 bytes[1] = (val & 0x0000FF00) >> 8;
408 bytes[2] = (val & 0x00FF0000) >> 16;
409 bytes[3] = (val & 0xFF000000) >> 24;
410 }
411 return 4;
412}
413
414std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::DeserializeInt32(const void *buffer, std::int32_t &val)
415{
416 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
417 val = std::int32_t(bytes[0]) + (std::int32_t(bytes[1]) << 8) +
418 (std::int32_t(bytes[2]) << 16) + (std::int32_t(bytes[3]) << 24);
419 return 4;
420}
421
422std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::SerializeUInt32(std::uint32_t val, void *buffer)
423{
424 return SerializeInt32(val, buffer);
425}
426
427std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::DeserializeUInt32(const void *buffer, std::uint32_t &val)
428{
429 return DeserializeInt32(buffer, *reinterpret_cast<std::int32_t *>(&val));
430}
431
432std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::SerializeInt64(std::int64_t val, void *buffer)
433{
434 if (buffer != nullptr) {
435 auto bytes = reinterpret_cast<unsigned char *>(buffer);
436 bytes[0] = (val & 0x00000000000000FF);
437 bytes[1] = (val & 0x000000000000FF00) >> 8;
438 bytes[2] = (val & 0x0000000000FF0000) >> 16;
439 bytes[3] = (val & 0x00000000FF000000) >> 24;
440 bytes[4] = (val & 0x000000FF00000000) >> 32;
441 bytes[5] = (val & 0x0000FF0000000000) >> 40;
442 bytes[6] = (val & 0x00FF000000000000) >> 48;
443 bytes[7] = (val & 0xFF00000000000000) >> 56;
444 }
445 return 8;
446}
447
448std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::DeserializeInt64(const void *buffer, std::int64_t &val)
449{
450 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
451 val = std::int64_t(bytes[0]) + (std::int64_t(bytes[1]) << 8) +
452 (std::int64_t(bytes[2]) << 16) + (std::int64_t(bytes[3]) << 24) +
453 (std::int64_t(bytes[4]) << 32) + (std::int64_t(bytes[5]) << 40) +
454 (std::int64_t(bytes[6]) << 48) + (std::int64_t(bytes[7]) << 56);
455 return 8;
456}
457
458std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::SerializeUInt64(std::uint64_t val, void *buffer)
459{
460 return SerializeInt64(val, buffer);
461}
462
463std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::DeserializeUInt64(const void *buffer, std::uint64_t &val)
464{
465 return DeserializeInt64(buffer, *reinterpret_cast<std::int64_t *>(&val));
466}
467
468std::uint32_t ROOT::Experimental::Internal::RNTupleSerializer::SerializeString(const std::string &val, void *buffer)
469{
470 if (buffer) {
471 auto pos = reinterpret_cast<unsigned char *>(buffer);
472 pos += SerializeUInt32(val.length(), pos);
473 memcpy(pos, val.data(), val.length());
474 }
475 return sizeof(std::uint32_t) + val.length();
476}
477
479 std::uint64_t bufSize,
480 std::string &val)
481{
482 if (bufSize < sizeof(std::uint32_t))
483 return R__FAIL("string buffer too short");
484 bufSize -= sizeof(std::uint32_t);
485
486 auto base = reinterpret_cast<const unsigned char *>(buffer);
487 auto bytes = base;
488 std::uint32_t length;
489 bytes += DeserializeUInt32(buffer, length);
490 if (bufSize < length)
491 return R__FAIL("string buffer too short");
492
493 val.resize(length);
494 memcpy(&val[0], bytes, length);
495 return sizeof(std::uint32_t) + length;
496}
497
498
501{
503 switch (type) {
504 case EColumnType::kIndex64: return SerializeUInt16(0x01, buffer);
505 case EColumnType::kIndex32: return SerializeUInt16(0x02, buffer);
506 case EColumnType::kSwitch: return SerializeUInt16(0x03, buffer);
507 case EColumnType::kByte: return SerializeUInt16(0x04, buffer);
508 case EColumnType::kChar: return SerializeUInt16(0x05, buffer);
509 case EColumnType::kBit: return SerializeUInt16(0x06, buffer);
510 case EColumnType::kReal64: return SerializeUInt16(0x07, buffer);
511 case EColumnType::kReal32: return SerializeUInt16(0x08, buffer);
512 case EColumnType::kReal16: return SerializeUInt16(0x09, buffer);
513 case EColumnType::kInt64: return SerializeUInt16(0x16, buffer);
514 case EColumnType::kUInt64: return SerializeUInt16(0x0A, buffer);
515 case EColumnType::kInt32: return SerializeUInt16(0x17, buffer);
516 case EColumnType::kUInt32: return SerializeUInt16(0x0B, buffer);
517 case EColumnType::kInt16: return SerializeUInt16(0x18, buffer);
518 case EColumnType::kUInt16: return SerializeUInt16(0x0C, buffer);
519 case EColumnType::kInt8: return SerializeUInt16(0x19, buffer);
520 case EColumnType::kUInt8: return SerializeUInt16(0x0D, buffer);
521 case EColumnType::kSplitIndex64: return SerializeUInt16(0x0E, buffer);
522 case EColumnType::kSplitIndex32: return SerializeUInt16(0x0F, buffer);
523 case EColumnType::kSplitReal64: return SerializeUInt16(0x10, buffer);
524 case EColumnType::kSplitReal32: return SerializeUInt16(0x11, buffer);
525 case EColumnType::kSplitInt64: return SerializeUInt16(0x1A, buffer);
526 case EColumnType::kSplitUInt64: return SerializeUInt16(0x13, buffer);
527 case EColumnType::kSplitInt32: return SerializeUInt16(0x1B, buffer);
528 case EColumnType::kSplitUInt32: return SerializeUInt16(0x14, buffer);
529 case EColumnType::kSplitInt16: return SerializeUInt16(0x1C, buffer);
530 case EColumnType::kSplitUInt16: return SerializeUInt16(0x15, buffer);
531 default: throw RException(R__FAIL("ROOT bug: unexpected column type"));
532 }
533}
534
535
537 const void *buffer, ROOT::Experimental::EColumnType &type)
538{
540 std::uint16_t onDiskType;
541 auto result = DeserializeUInt16(buffer, onDiskType);
542 switch (onDiskType) {
543 case 0x01: type = EColumnType::kIndex64; break;
544 case 0x02: type = EColumnType::kIndex32; break;
545 case 0x03: type = EColumnType::kSwitch; break;
546 case 0x04: type = EColumnType::kByte; break;
547 case 0x05: type = EColumnType::kChar; break;
548 case 0x06: type = EColumnType::kBit; break;
549 case 0x07: type = EColumnType::kReal64; break;
550 case 0x08: type = EColumnType::kReal32; break;
551 case 0x09: type = EColumnType::kReal16; break;
552 case 0x16: type = EColumnType::kInt64; break;
553 case 0x0A: type = EColumnType::kUInt64; break;
554 case 0x17: type = EColumnType::kInt32; break;
555 case 0x0B: type = EColumnType::kUInt32; break;
556 case 0x18: type = EColumnType::kInt16; break;
557 case 0x0C: type = EColumnType::kUInt16; break;
558 case 0x19: type = EColumnType::kInt8; break;
559 case 0x0D: type = EColumnType::kUInt8; break;
560 case 0x0E: type = EColumnType::kSplitIndex64; break;
561 case 0x0F: type = EColumnType::kSplitIndex32; break;
562 case 0x10: type = EColumnType::kSplitReal64; break;
563 case 0x11: type = EColumnType::kSplitReal32; break;
564 case 0x1A: type = EColumnType::kSplitInt64; break;
565 case 0x13: type = EColumnType::kSplitUInt64; break;
566 case 0x1B: type = EColumnType::kSplitInt32; break;
567 case 0x14: type = EColumnType::kSplitUInt32; break;
568 case 0x1C: type = EColumnType::kSplitInt16; break;
569 case 0x15: type = EColumnType::kSplitUInt16; break;
570 default: return R__FAIL("unexpected on-disk column type");
571 }
572 return result;
573}
574
575
577 ROOT::Experimental::ENTupleStructure structure, void *buffer)
578{
580 switch (structure) {
582 return SerializeUInt16(0x00, buffer);
584 return SerializeUInt16(0x01, buffer);
586 return SerializeUInt16(0x02, buffer);
588 return SerializeUInt16(0x03, buffer);
590 return SerializeUInt16(0x04, buffer);
591 default:
592 throw RException(R__FAIL("ROOT bug: unexpected field structure type"));
593 }
594}
595
596
598 const void *buffer, ROOT::Experimental::ENTupleStructure &structure)
599{
601 std::uint16_t onDiskValue;
602 auto result = DeserializeUInt16(buffer, onDiskValue);
603 switch (onDiskValue) {
604 case 0x00:
605 structure = ENTupleStructure::kLeaf;
606 break;
607 case 0x01:
609 break;
610 case 0x02:
611 structure = ENTupleStructure::kRecord;
612 break;
613 case 0x03:
614 structure = ENTupleStructure::kVariant;
615 break;
616 case 0x04:
618 break;
619 default:
620 return R__FAIL("unexpected on-disk field structure value");
621 }
622 return result;
623}
624
625std::uint32_t
627{
628 auto base = reinterpret_cast<unsigned char *>(buffer);
629 auto pos = base;
630 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
631
632 pos += SerializeUInt64(envelopeType, *where);
633 // The 48bits size information is filled in the postscript
634 return pos - base;
635}
636
638 std::uint64_t size,
639 std::uint64_t &xxhash3)
640{
641 if (size < sizeof(std::uint64_t))
642 throw RException(R__FAIL("envelope size too small"));
643 if (size >= static_cast<uint64_t>(1) << 48)
644 throw RException(R__FAIL("envelope size too big"));
645 if (envelope) {
646 std::uint64_t typeAndSize;
647 DeserializeUInt64(envelope, typeAndSize);
648 typeAndSize |= (size + 8) << 16;
649 SerializeUInt64(typeAndSize, envelope);
650 }
651 return SerializeXxHash3(envelope, size, xxhash3, envelope ? (envelope + size) : nullptr);
652}
653
655 std::uint64_t size)
656{
657 std::uint64_t xxhash3;
658 return SerializeEnvelopePostscript(envelope, size, xxhash3);
659}
660
663 std::uint16_t expectedType, std::uint64_t &xxhash3)
664{
665 const std::uint64_t minEnvelopeSize = sizeof(std::uint64_t) + sizeof(std::uint64_t);
666 if (bufSize < minEnvelopeSize)
667 return R__FAIL("invalid envelope buffer, too short");
668
669 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
670 auto base = bytes;
671
672 std::uint64_t typeAndSize;
673 bytes += DeserializeUInt64(bytes, typeAndSize);
674
675 std::uint16_t envelopeType = typeAndSize & 0xFFFF;
676 if (envelopeType != expectedType) {
677 return R__FAIL("envelope type mismatch: expected " + std::to_string(expectedType) + ", found " +
678 std::to_string(envelopeType));
679 }
680
681 std::uint64_t envelopeSize = typeAndSize >> 16;
682 if (bufSize < envelopeSize)
683 return R__FAIL("envelope buffer size too small");
684 if (envelopeSize < minEnvelopeSize)
685 return R__FAIL("invalid envelope, too short");
686
687 auto result = VerifyXxHash3(base, envelopeSize - 8, xxhash3);
688 if (!result)
689 return R__FORWARD_ERROR(result);
690
691 return sizeof(typeAndSize);
692}
693
695 std::uint64_t bufSize,
696 std::uint16_t expectedType)
697{
698 std::uint64_t xxhash3;
699 return R__FORWARD_RESULT(DeserializeEnvelope(buffer, bufSize, expectedType, xxhash3));
700}
701
702
704{
705 // Marker: multiply the final size with 1
706 return SerializeInt64(1, buffer);
707}
708
709
711 std::uint32_t nitems, void *buffer)
712{
713 auto base = reinterpret_cast<unsigned char *>(buffer);
714 auto pos = base;
715 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
716
717 // Marker: multiply the final size with -1
718 pos += SerializeInt64(-1, *where);
719 pos += SerializeUInt32(nitems, *where);
720 return pos - base;
721}
722
724{
725 auto preambleSize = sizeof(std::int64_t);
726 if (size < preambleSize)
727 throw RException(R__FAIL("frame too short: " + std::to_string(size)));
728 if (frame) {
729 std::int64_t marker;
730 DeserializeInt64(frame, marker);
731 if ((marker < 0) && (size < (sizeof(std::uint32_t) + preambleSize)))
732 throw RException(R__FAIL("frame too short: " + std::to_string(size)));
733 SerializeInt64(marker * static_cast<int64_t>(size), frame);
734 }
735 return 0;
736}
737
740 std::uint64_t &frameSize, std::uint32_t &nitems)
741{
742 std::uint64_t minSize = sizeof(std::int64_t);
743 if (bufSize < minSize)
744 return R__FAIL("frame too short");
745
746 std::int64_t *ssize = reinterpret_cast<std::int64_t *>(&frameSize);
747 DeserializeInt64(buffer, *ssize);
748
749 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
750 bytes += minSize;
751
752 if (*ssize >= 0) {
753 // Record frame
754 nitems = 1;
755 } else {
756 // List frame
757 minSize += sizeof(std::uint32_t);
758 if (bufSize < minSize)
759 return R__FAIL("frame too short");
760 bytes += DeserializeUInt32(bytes, nitems);
761 *ssize = -(*ssize);
762 }
763
764 if (frameSize < minSize)
765 return R__FAIL("corrupt frame size");
766 if (bufSize < frameSize)
767 return R__FAIL("frame too short");
768
769 return bytes - reinterpret_cast<const unsigned char *>(buffer);
770}
771
774 std::uint64_t &frameSize)
775{
776 std::uint32_t nitems;
777 return R__FORWARD_RESULT(DeserializeFrameHeader(buffer, bufSize, frameSize, nitems));
778}
779
780std::uint32_t
782 void *buffer)
783{
784 if (flags.empty())
785 return SerializeUInt64(0, buffer);
786
787 if (buffer) {
788 auto bytes = reinterpret_cast<unsigned char *>(buffer);
789
790 for (unsigned i = 0; i < flags.size(); ++i) {
791 if (flags[i] & 0x8000000000000000)
792 throw RException(R__FAIL("feature flag out of bounds"));
793
794 // The MSb indicates that another Int64 follows; set this bit to 1 for all except the last element
795 if (i == (flags.size() - 1))
796 SerializeUInt64(flags[i], bytes);
797 else
798 bytes += SerializeUInt64(flags[i] | 0x8000000000000000, bytes);
799 }
800 }
801 return (flags.size() * sizeof(std::int64_t));
802}
803
806 std::vector<std::uint64_t> &flags)
807{
808 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
809
810 flags.clear();
811 std::uint64_t f;
812 do {
813 if (bufSize < sizeof(std::uint64_t))
814 return R__FAIL("feature flag buffer too short");
815 bytes += DeserializeUInt64(bytes, f);
816 bufSize -= sizeof(std::uint64_t);
817 flags.emplace_back(f & ~0x8000000000000000);
818 } while (f & 0x8000000000000000);
819
820 return (flags.size() * sizeof(std::uint64_t));
821}
822
824 const RNTupleLocator &locator, void *buffer)
825{
827 throw RException(R__FAIL("locator is not serializable"));
828
829 std::uint32_t size = 0;
830 if (locator.fType == RNTupleLocator::kTypeFile) {
831 if (static_cast<std::int32_t>(locator.fBytesOnStorage) < 0)
832 throw RException(R__FAIL("locator too large"));
833 size += SerializeUInt32(locator.fBytesOnStorage, buffer);
834 size += SerializeUInt64(locator.GetPosition<std::uint64_t>(),
835 buffer ? reinterpret_cast<unsigned char *>(buffer) + size : nullptr);
836 return size;
837 }
838
839 auto payloadp = buffer ? reinterpret_cast<unsigned char *>(buffer) + sizeof(std::int32_t) : nullptr;
840 switch (locator.fType) {
841 case RNTupleLocator::kTypeURI: size += SerializeLocatorPayloadURI(locator, payloadp); break;
842 case RNTupleLocator::kTypeDAOS: size += SerializeLocatorPayloadObject64(locator, payloadp); break;
843 default: throw RException(R__FAIL("locator has unknown type"));
844 }
845 std::int32_t head = sizeof(std::int32_t) + size;
846 head |= locator.fReserved << 16;
847 head |= static_cast<int>(locator.fType & 0x7F) << 24;
848 head = -head;
850 return size;
851}
852
854 std::uint64_t bufSize,
855 RNTupleLocator &locator)
856{
857 if (bufSize < sizeof(std::int32_t))
858 return R__FAIL("too short locator");
859
860 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
861 std::int32_t head;
862
863 bytes += DeserializeInt32(bytes, head);
864 bufSize -= sizeof(std::int32_t);
865 if (head < 0) {
866 head = -head;
867 const int type = head >> 24;
868 const std::uint32_t payloadSize = (static_cast<std::uint32_t>(head) & 0x0000FFFF) - sizeof(std::int32_t);
869 if (bufSize < payloadSize)
870 return R__FAIL("too short locator");
871 locator.fType = static_cast<RNTupleLocator::ELocatorType>(type);
872 locator.fReserved = static_cast<std::uint32_t>(head >> 16) & 0xFF;
873 switch (type) {
874 case RNTupleLocator::kTypeURI: DeserializeLocatorPayloadURI(bytes, payloadSize, locator); break;
875 case RNTupleLocator::kTypeDAOS: DeserializeLocatorPayloadObject64(bytes, locator); break;
876 default: return R__FAIL("unsupported locator type: " + std::to_string(type));
877 }
878 bytes += payloadSize;
879 } else {
880 if (bufSize < sizeof(std::uint64_t))
881 return R__FAIL("too short locator");
882 auto &offset = locator.fPosition.emplace<std::uint64_t>();
884 bytes += DeserializeUInt64(bytes, offset);
885 locator.fBytesOnStorage = head;
886 }
887
888 return bytes - reinterpret_cast<const unsigned char *>(buffer);
889}
890
892 const REnvelopeLink &envelopeLink, void *buffer)
893{
894 auto size = SerializeUInt64(envelopeLink.fLength, buffer);
895 size += SerializeLocator(envelopeLink.fLocator,
896 buffer ? reinterpret_cast<unsigned char *>(buffer) + size : nullptr);
897 return size;
898}
899
902 REnvelopeLink &envelopeLink)
903{
904 if (bufSize < sizeof(std::int64_t))
905 return R__FAIL("too short envelope link");
906
907 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
908 bytes += DeserializeUInt64(bytes, envelopeLink.fLength);
909 bufSize -= sizeof(std::uint64_t);
910 auto result = DeserializeLocator(bytes, bufSize, envelopeLink.fLocator);
911 if (!result)
912 return R__FORWARD_ERROR(result);
913 bytes += result.Unwrap();
914 return bytes - reinterpret_cast<const unsigned char *>(buffer);
915}
916
917
919 const RClusterSummary &clusterSummary, void *buffer)
920{
921 auto base = reinterpret_cast<unsigned char *>(buffer);
922 auto pos = base;
923 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
924
925 auto frame = pos;
926 pos += SerializeRecordFramePreamble(*where);
927 pos += SerializeUInt64(clusterSummary.fFirstEntry, *where);
928 if (clusterSummary.fColumnGroupID >= 0) {
929 pos += SerializeInt64(-static_cast<int64_t>(clusterSummary.fNEntries), *where);
930 pos += SerializeUInt32(clusterSummary.fColumnGroupID, *where);
931 } else {
932 pos += SerializeInt64(static_cast<int64_t>(clusterSummary.fNEntries), *where);
933 }
934 auto size = pos - frame;
935 pos += SerializeFramePostscript(frame, size);
936 return size;
937}
938
941 RClusterSummary &clusterSummary)
942{
943 auto base = reinterpret_cast<const unsigned char *>(buffer);
944 auto bytes = base;
945 std::uint64_t frameSize;
946 auto result = DeserializeFrameHeader(bytes, bufSize, frameSize);
947 if (!result)
948 return R__FORWARD_ERROR(result);
949 bytes += result.Unwrap();
950
951 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
952 if (fnFrameSizeLeft() < 2 * sizeof(std::uint64_t))
953 return R__FAIL("too short cluster summary");
954
955 bytes += DeserializeUInt64(bytes, clusterSummary.fFirstEntry);
956 std::int64_t nEntries;
957 bytes += DeserializeInt64(bytes, nEntries);
958
959 if (nEntries < 0) {
960 if (fnFrameSizeLeft() < sizeof(std::uint32_t))
961 return R__FAIL("too short cluster summary");
962 clusterSummary.fNEntries = -nEntries;
963 std::uint32_t columnGroupID;
964 bytes += DeserializeUInt32(bytes, columnGroupID);
965 clusterSummary.fColumnGroupID = columnGroupID;
966 } else {
967 clusterSummary.fNEntries = nEntries;
968 clusterSummary.fColumnGroupID = -1;
969 }
970
971 return frameSize;
972}
973
974
976 const RClusterGroup &clusterGroup, void *buffer)
977{
978 auto base = reinterpret_cast<unsigned char *>(buffer);
979 auto pos = base;
980 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
981
982 auto frame = pos;
983 pos += SerializeRecordFramePreamble(*where);
984 pos += SerializeUInt64(clusterGroup.fMinEntry, *where);
985 pos += SerializeUInt64(clusterGroup.fEntrySpan, *where);
986 pos += SerializeUInt32(clusterGroup.fNClusters, *where);
987 pos += SerializeEnvelopeLink(clusterGroup.fPageListEnvelopeLink, *where);
988 auto size = pos - frame;
989 pos += SerializeFramePostscript(frame, size);
990 return size;
991}
992
995 RClusterGroup &clusterGroup)
996{
997 auto base = reinterpret_cast<const unsigned char *>(buffer);
998 auto bytes = base;
999
1000 std::uint64_t frameSize;
1001 auto result = DeserializeFrameHeader(bytes, bufSize, frameSize);
1002 if (!result)
1003 return R__FORWARD_ERROR(result);
1004 bytes += result.Unwrap();
1005
1006 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
1007 if (fnFrameSizeLeft() < sizeof(std::uint32_t) + 2 * sizeof(std::uint64_t))
1008 return R__FAIL("too short cluster group");
1009
1010 bytes += DeserializeUInt64(bytes, clusterGroup.fMinEntry);
1011 bytes += DeserializeUInt64(bytes, clusterGroup.fEntrySpan);
1012 bytes += DeserializeUInt32(bytes, clusterGroup.fNClusters);
1013 result = DeserializeEnvelopeLink(bytes, fnFrameSizeLeft(), clusterGroup.fPageListEnvelopeLink);
1014 if (!result)
1015 return R__FORWARD_ERROR(result);
1016
1017 return frameSize;
1018}
1019
1021 bool forHeaderExtension)
1022{
1023 auto fieldZeroId = desc.GetFieldZeroId();
1024 auto depthFirstTraversal = [&](std::span<DescriptorId_t> fieldTrees, auto doForEachField) {
1025 std::deque<DescriptorId_t> idQueue{fieldTrees.begin(), fieldTrees.end()};
1026 while (!idQueue.empty()) {
1027 auto fieldId = idQueue.front();
1028 idQueue.pop_front();
1029 // Field zero has no physical representation nor columns of its own; recurse over its subfields only
1030 if (fieldId != fieldZeroId)
1031 doForEachField(fieldId);
1032 unsigned i = 0;
1033 for (const auto &f : desc.GetFieldIterable(fieldId))
1034 idQueue.insert(idQueue.begin() + i++, f.GetId());
1035 }
1036 };
1037
1038 R__ASSERT(desc.GetNFields() > 0); // we must have at least a zero field
1039 if (!forHeaderExtension)
1040 R__ASSERT(GetHeaderExtensionOffset() == -1U);
1041
1042 std::vector<DescriptorId_t> fieldTrees;
1043 if (!forHeaderExtension) {
1044 fieldTrees.emplace_back(fieldZeroId);
1045 } else if (auto xHeader = desc.GetHeaderExtension()) {
1046 fieldTrees = xHeader->GetTopLevelFields(desc);
1047 }
1048 depthFirstTraversal(fieldTrees, [&](DescriptorId_t fieldId) { MapFieldId(fieldId); });
1049 depthFirstTraversal(fieldTrees, [&](DescriptorId_t fieldId) {
1050 for (const auto &c : desc.GetColumnIterable(fieldId))
1051 if (!c.IsAliasColumn())
1052 MapColumnId(c.GetLogicalId());
1053 });
1054 depthFirstTraversal(fieldTrees, [&](DescriptorId_t fieldId) {
1055 for (const auto &c : desc.GetColumnIterable(fieldId))
1056 if (c.IsAliasColumn())
1057 MapColumnId(c.GetLogicalId());
1058 });
1059
1060 // Anything added after this point is accounted for the header extension
1061 if (!forHeaderExtension)
1062 BeginHeaderExtension();
1063}
1064
1066 const RNTupleDescriptor &desc,
1067 const RContext &context,
1068 bool forHeaderExtension)
1069{
1070 auto base = reinterpret_cast<unsigned char *>(buffer);
1071 auto pos = base;
1072 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
1073
1074 std::size_t nFields = 0, nColumns = 0, nAliasColumns = 0, fieldListOffset = 0;
1075 if (forHeaderExtension) {
1076 // A call to `RNTupleDescriptorBuilder::BeginHeaderExtension()` is not strictly required after serializing the
1077 // header, which may happen, e.g., in unit tests. Ensure an empty schema extension is serialized in this case
1078 if (auto xHeader = desc.GetHeaderExtension()) {
1079 nFields = xHeader->GetNFields();
1080 nColumns = xHeader->GetNPhysicalColumns();
1081 nAliasColumns = xHeader->GetNLogicalColumns() - xHeader->GetNPhysicalColumns();
1082 fieldListOffset = context.GetHeaderExtensionOffset();
1083 }
1084 } else {
1085 nFields = desc.GetNFields() - 1;
1086 nColumns = desc.GetNPhysicalColumns();
1087 nAliasColumns = desc.GetNLogicalColumns() - desc.GetNPhysicalColumns();
1088 }
1089 const auto &onDiskFields = context.GetOnDiskFieldList();
1090 R__ASSERT(onDiskFields.size() >= fieldListOffset);
1091 std::span<const DescriptorId_t> fieldList{onDiskFields.data() + fieldListOffset,
1092 onDiskFields.size() - fieldListOffset};
1093
1094 auto frame = pos;
1095 pos += SerializeListFramePreamble(nFields, *where);
1096 pos += SerializeFieldList(desc, fieldList, /*firstOnDiskId=*/fieldListOffset, context, *where);
1097 pos += SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
1098
1099 frame = pos;
1100 pos += SerializeListFramePreamble(nColumns, *where);
1101 pos += SerializeColumnList(desc, fieldList, context, *where);
1102 pos += SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
1103
1104 frame = pos;
1105 pos += SerializeListFramePreamble(nAliasColumns, *where);
1106 pos += SerializeAliasColumnList(desc, fieldList, context, *where);
1107 pos += SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
1108
1109 // We don't use extra type information yet
1110 frame = pos;
1111 pos += SerializeListFramePreamble(0, *where);
1112 pos += SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
1113 return static_cast<std::uint32_t>(pos - base);
1114}
1115
1118 RNTupleDescriptorBuilder &descBuilder)
1119{
1120 auto base = reinterpret_cast<const unsigned char *>(buffer);
1121 auto bytes = base;
1122 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
1124
1125 std::uint64_t frameSize;
1126 auto frame = bytes;
1127 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - frame); };
1128
1129 std::uint32_t nFields;
1130 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nFields);
1131 if (!result)
1132 return R__FORWARD_ERROR(result);
1133 bytes += result.Unwrap();
1134 // The zero field is always added before `DeserializeSchemaDescription()` is called
1135 const std::uint32_t fieldIdRangeBegin = descBuilder.GetDescriptor().GetNFields() - 1;
1136 for (unsigned i = 0; i < nFields; ++i) {
1137 std::uint32_t fieldId = fieldIdRangeBegin + i;
1138 RFieldDescriptorBuilder fieldBuilder;
1139 result = DeserializeField(bytes, fnFrameSizeLeft(), fieldBuilder);
1140 if (!result)
1141 return R__FORWARD_ERROR(result);
1142 bytes += result.Unwrap();
1143 if (fieldId == fieldBuilder.GetParentId())
1144 fieldBuilder.ParentId(kZeroFieldId);
1145 auto fieldDesc = fieldBuilder.FieldId(fieldId).MakeDescriptor();
1146 if (!fieldDesc)
1147 return R__FORWARD_ERROR(fieldDesc);
1148 auto parentId = fieldDesc.Inspect().GetParentId();
1149 descBuilder.AddField(fieldDesc.Unwrap());
1150 auto resVoid = descBuilder.AddFieldLink(parentId, fieldId);
1151 if (!resVoid)
1152 return R__FORWARD_ERROR(resVoid);
1153 }
1154 bytes = frame + frameSize;
1155
1156 std::uint32_t nColumns;
1157 frame = bytes;
1158 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nColumns);
1159 if (!result)
1160 return R__FORWARD_ERROR(result);
1161 bytes += result.Unwrap();
1162 const std::uint32_t columnIdRangeBegin = descBuilder.GetDescriptor().GetNLogicalColumns();
1163 std::unordered_map<DescriptorId_t, std::uint32_t> maxIndexes;
1164 for (unsigned i = 0; i < nColumns; ++i) {
1165 std::uint32_t columnId = columnIdRangeBegin + i;
1166 RColumnDescriptorBuilder columnBuilder;
1167 result = DeserializeColumn(bytes, fnFrameSizeLeft(), columnBuilder);
1168 if (!result)
1169 return R__FORWARD_ERROR(result);
1170 bytes += result.Unwrap();
1171
1172 std::uint32_t idx = 0;
1173 const auto fieldId = columnBuilder.GetFieldId();
1174 auto maxIdx = maxIndexes.find(fieldId);
1175 if (maxIdx != maxIndexes.end())
1176 idx = maxIdx->second + 1;
1177 maxIndexes[fieldId] = idx;
1178
1179 auto columnDesc = columnBuilder.Index(idx).LogicalColumnId(columnId).PhysicalColumnId(columnId).MakeDescriptor();
1180 if (!columnDesc)
1181 return R__FORWARD_ERROR(columnDesc);
1182 auto resVoid = descBuilder.AddColumn(columnDesc.Unwrap());
1183 if (!resVoid)
1184 return R__FORWARD_ERROR(resVoid);
1185 }
1186 bytes = frame + frameSize;
1187
1188 std::uint32_t nAliasColumns;
1189 frame = bytes;
1190 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nAliasColumns);
1191 if (!result)
1192 return R__FORWARD_ERROR(result);
1193 bytes += result.Unwrap();
1194 const std::uint32_t aliasColumnIdRangeBegin = columnIdRangeBegin + nColumns;
1195 for (unsigned i = 0; i < nAliasColumns; ++i) {
1196 std::uint32_t physicalId;
1197 std::uint32_t fieldId;
1198 result = DeserializeAliasColumn(bytes, fnFrameSizeLeft(), physicalId, fieldId);
1199 if (!result)
1200 return R__FORWARD_ERROR(result);
1201 bytes += result.Unwrap();
1202
1203 RColumnDescriptorBuilder columnBuilder;
1204 columnBuilder.LogicalColumnId(aliasColumnIdRangeBegin + i).PhysicalColumnId(physicalId).FieldId(fieldId);
1205 columnBuilder.Model(descBuilder.GetDescriptor().GetColumnDescriptor(physicalId).GetModel());
1206
1207 std::uint32_t idx = 0;
1208 auto maxIdx = maxIndexes.find(fieldId);
1209 if (maxIdx != maxIndexes.end())
1210 idx = maxIdx->second + 1;
1211 maxIndexes[fieldId] = idx;
1212
1213 auto aliasColumnDesc = columnBuilder.Index(idx).MakeDescriptor();
1214 if (!aliasColumnDesc)
1215 return R__FORWARD_ERROR(aliasColumnDesc);
1216 auto resVoid = descBuilder.AddColumn(aliasColumnDesc.Unwrap());
1217 if (!resVoid)
1218 return R__FORWARD_ERROR(resVoid);
1219 }
1220 bytes = frame + frameSize;
1221
1222 std::uint32_t nTypeInfo;
1223 frame = bytes;
1224 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nTypeInfo);
1225 if (!result)
1226 return R__FORWARD_ERROR(result);
1227 if (nTypeInfo > 0)
1228 R__LOG_WARNING(NTupleLog()) << "Extra type information is still unsupported! ";
1229 bytes = frame + frameSize;
1230
1231 return bytes - base;
1232}
1233
1237{
1238 RContext context;
1239
1240 auto base = reinterpret_cast<unsigned char *>(buffer);
1241 auto pos = base;
1242 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
1243
1244 pos += SerializeEnvelopePreamble(kEnvelopeTypeHeader, *where);
1245 // So far we don't make use of feature flags
1246 pos += SerializeFeatureFlags(desc.GetFeatureFlags(), *where);
1247 pos += SerializeString(desc.GetName(), *where);
1248 pos += SerializeString(desc.GetDescription(), *where);
1249 pos += SerializeString(std::string("ROOT v") + ROOT_RELEASE, *where);
1250
1251 context.MapSchema(desc, /*forHeaderExtension=*/false);
1252 pos += SerializeSchemaDescription(*where, desc, context);
1253
1254 std::uint64_t size = pos - base;
1255 std::uint64_t xxhash3 = 0;
1256 size += SerializeEnvelopePostscript(base, size, xxhash3);
1257
1258 context.SetHeaderSize(size);
1259 context.SetHeaderXxHash3(xxhash3);
1260 return context;
1261}
1262
1263std::uint32_t
1265 std::span<DescriptorId_t> physClusterIDs,
1266 const RContext &context)
1267{
1268 auto base = reinterpret_cast<unsigned char *>(buffer);
1269 auto pos = base;
1270 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
1271
1272 pos += SerializeEnvelopePreamble(kEnvelopeTypePageList, *where);
1273
1274 pos += SerializeUInt64(context.GetHeaderXxHash3(), *where);
1275
1276 // Cluster summaries
1277 const auto nClusters = physClusterIDs.size();
1278 auto clusterSummaryFrame = pos;
1279 pos += SerializeListFramePreamble(nClusters, *where);
1280 for (auto clusterId : physClusterIDs) {
1281 const auto &clusterDesc = desc.GetClusterDescriptor(context.GetMemClusterId(clusterId));
1282 RClusterSummary summary{clusterDesc.GetFirstEntryIndex(), clusterDesc.GetNEntries(), -1};
1283 pos += SerializeClusterSummary(summary, *where);
1284 }
1285 pos += SerializeFramePostscript(buffer ? clusterSummaryFrame : nullptr, pos - clusterSummaryFrame);
1286
1287 // Page locations
1288 auto topMostFrame = pos;
1289 pos += SerializeListFramePreamble(nClusters, *where);
1290
1291 for (auto clusterId : physClusterIDs) {
1292 const auto &clusterDesc = desc.GetClusterDescriptor(context.GetMemClusterId(clusterId));
1293 // Get an ordered set of physical column ids
1294 std::set<DescriptorId_t> onDiskColumnIds;
1295 for (auto column : clusterDesc.GetColumnIds())
1296 onDiskColumnIds.insert(context.GetOnDiskColumnId(column));
1297
1298 auto outerFrame = pos;
1299 pos += SerializeListFramePreamble(onDiskColumnIds.size(), *where);
1300 for (auto onDiskId : onDiskColumnIds) {
1301 auto memId = context.GetMemColumnId(onDiskId);
1302 const auto &columnRange = clusterDesc.GetColumnRange(memId);
1303 const auto &pageRange = clusterDesc.GetPageRange(memId);
1304
1305 auto innerFrame = pos;
1306 pos += SerializeListFramePreamble(pageRange.fPageInfos.size(), *where);
1307
1308 for (const auto &pi : pageRange.fPageInfos) {
1309 pos += SerializeUInt32(pi.fNElements, *where);
1310 pos += SerializeLocator(pi.fLocator, *where);
1311 }
1312 pos += SerializeUInt64(columnRange.fFirstElementIndex, *where);
1313 pos += SerializeUInt32(columnRange.fCompressionSettings, *where);
1314
1315 pos += SerializeFramePostscript(buffer ? innerFrame : nullptr, pos - innerFrame);
1316 }
1317 pos += SerializeFramePostscript(buffer ? outerFrame : nullptr, pos - outerFrame);
1318 }
1319
1320 pos += SerializeFramePostscript(buffer ? topMostFrame : nullptr, pos - topMostFrame);
1321 std::uint64_t size = pos - base;
1322 size += SerializeEnvelopePostscript(base, size);
1323 return size;
1324}
1325
1326std::uint32_t
1329 const RContext &context)
1330{
1331 auto base = reinterpret_cast<unsigned char *>(buffer);
1332 auto pos = base;
1333 void** where = (buffer == nullptr) ? &buffer : reinterpret_cast<void**>(&pos);
1334
1335 pos += SerializeEnvelopePreamble(kEnvelopeTypeFooter, *where);
1336
1337 // So far we don't make use of footer feature flags
1338 pos += SerializeFeatureFlags(std::vector<std::uint64_t>(), *where);
1339 pos += SerializeUInt64(context.GetHeaderXxHash3(), *where);
1340
1341 // Schema extension, i.e. incremental changes with respect to the header
1342 auto frame = pos;
1343 pos += SerializeRecordFramePreamble(*where);
1344 pos += SerializeSchemaDescription(*where, desc, context, /*forHeaderExtension=*/true);
1345 pos += SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
1346
1347 // So far no support for shared clusters (no column groups)
1348 frame = pos;
1349 pos += SerializeListFramePreamble(0, *where);
1350 pos += SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
1351
1352 // Cluster groups
1353 frame = pos;
1354 const auto nClusterGroups = desc.GetNClusterGroups();
1355 pos += SerializeListFramePreamble(nClusterGroups, *where);
1356 for (unsigned int i = 0; i < nClusterGroups; ++i) {
1357 const auto &cgDesc = desc.GetClusterGroupDescriptor(context.GetMemClusterGroupId(i));
1358 RClusterGroup clusterGroup;
1359 clusterGroup.fMinEntry = cgDesc.GetMinEntry();
1360 clusterGroup.fEntrySpan = cgDesc.GetEntrySpan();
1361 clusterGroup.fNClusters = cgDesc.GetNClusters();
1362 clusterGroup.fPageListEnvelopeLink.fLength = cgDesc.GetPageListLength();
1363 clusterGroup.fPageListEnvelopeLink.fLocator = cgDesc.GetPageListLocator();
1364 pos += SerializeClusterGroup(clusterGroup, *where);
1365 }
1366 pos += SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
1367
1368 // So far no support for meta-data
1369 frame = pos;
1370 pos += SerializeListFramePreamble(0, *where);
1371 pos += SerializeFramePostscript(buffer ? frame : nullptr, pos - frame);
1372
1373 std::uint32_t size = pos - base;
1374 size += SerializeEnvelopePostscript(base, size);
1375 return size;
1376}
1377
1380 RNTupleDescriptorBuilder &descBuilder)
1381{
1382 auto base = reinterpret_cast<const unsigned char *>(buffer);
1383 auto bytes = base;
1384 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
1386
1387 std::uint64_t xxhash3{0};
1388 result = DeserializeEnvelope(bytes, fnBufSizeLeft(), kEnvelopeTypeHeader, xxhash3);
1389 if (!result)
1390 return R__FORWARD_ERROR(result);
1391 bytes += result.Unwrap();
1392 descBuilder.SetOnDiskHeaderXxHash3(xxhash3);
1393
1394 std::vector<std::uint64_t> featureFlags;
1395 result = DeserializeFeatureFlags(bytes, fnBufSizeLeft(), featureFlags);
1396 if (!result)
1397 return R__FORWARD_ERROR(result);
1398 bytes += result.Unwrap();
1399 for (std::size_t i = 0; i < featureFlags.size(); ++i) {
1400 if (!featureFlags[i])
1401 continue;
1402 unsigned int bit = 0;
1403 while (!(featureFlags[i] & (static_cast<uint64_t>(1) << bit)))
1404 bit++;
1405 return R__FAIL("unsupported format feature: " + std::to_string(i * 64 + bit));
1406 }
1407
1408 std::string name;
1409 std::string description;
1410 std::string writer;
1411 result = DeserializeString(bytes, fnBufSizeLeft(), name);
1412 if (!result)
1413 return R__FORWARD_ERROR(result);
1414 bytes += result.Unwrap();
1415 result = DeserializeString(bytes, fnBufSizeLeft(), description);
1416 if (!result)
1417 return R__FORWARD_ERROR(result);
1418 bytes += result.Unwrap();
1419 result = DeserializeString(bytes, fnBufSizeLeft(), writer);
1420 if (!result)
1421 return R__FORWARD_ERROR(result);
1422 bytes += result.Unwrap();
1423 descBuilder.SetNTuple(name, description);
1424
1425 // Zero field
1426 descBuilder.AddField(
1427 RFieldDescriptorBuilder().FieldId(kZeroFieldId).Structure(ENTupleStructure::kRecord).MakeDescriptor().Unwrap());
1428 result = DeserializeSchemaDescription(bytes, fnBufSizeLeft(), descBuilder);
1429 if (!result)
1430 return R__FORWARD_ERROR(result);
1431
1432 return RResult<void>::Success();
1433}
1434
1437 RNTupleDescriptorBuilder &descBuilder)
1438{
1439 auto base = reinterpret_cast<const unsigned char *>(buffer);
1440 auto bytes = base;
1441 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
1443
1444 result = DeserializeEnvelope(bytes, fnBufSizeLeft(), kEnvelopeTypeFooter);
1445 if (!result)
1446 return R__FORWARD_ERROR(result);
1447 bytes += result.Unwrap();
1448
1449 std::vector<std::uint64_t> featureFlags;
1450 result = DeserializeFeatureFlags(bytes, fnBufSizeLeft(), featureFlags);
1451 if (!result)
1452 return R__FORWARD_ERROR(result);
1453 bytes += result.Unwrap();
1454 for (auto f: featureFlags) {
1455 if (f)
1456 R__LOG_WARNING(NTupleLog()) << "Unsupported feature flag! " << f;
1457 }
1458
1459 std::uint64_t xxhash3{0};
1460 if (fnBufSizeLeft() < static_cast<int>(sizeof(std::uint64_t)))
1461 return R__FAIL("footer too short");
1462 bytes += DeserializeUInt64(bytes, xxhash3);
1463 if (xxhash3 != descBuilder.GetDescriptor().GetOnDiskHeaderXxHash3())
1464 return R__FAIL("XxHash-3 mismatch between header and footer");
1465
1466 std::uint64_t frameSize;
1467 auto frame = bytes;
1468 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - frame); };
1469
1470 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize);
1471 if (!result)
1472 return R__FORWARD_ERROR(result);
1473 bytes += result.Unwrap();
1474 if (fnFrameSizeLeft() > 0) {
1475 descBuilder.BeginHeaderExtension();
1476 result = DeserializeSchemaDescription(bytes, fnFrameSizeLeft(), descBuilder);
1477 if (!result)
1478 return R__FORWARD_ERROR(result);
1479 }
1480 bytes = frame + frameSize;
1481
1482 std::uint32_t nColumnGroups;
1483 frame = bytes;
1484 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nColumnGroups);
1485 if (!result)
1486 return R__FORWARD_ERROR(result);
1487 if (nColumnGroups > 0)
1488 return R__FAIL("sharded clusters are still unsupported");
1489 bytes = frame + frameSize;
1490
1491 std::uint32_t nClusterGroups;
1492 frame = bytes;
1493 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nClusterGroups);
1494 if (!result)
1495 return R__FORWARD_ERROR(result);
1496 bytes += result.Unwrap();
1497 for (std::uint32_t groupId = 0; groupId < nClusterGroups; ++groupId) {
1498 RClusterGroup clusterGroup;
1499 result = DeserializeClusterGroup(bytes, fnFrameSizeLeft(), clusterGroup);
1500 if (!result)
1501 return R__FORWARD_ERROR(result);
1502 bytes += result.Unwrap();
1503
1505 RClusterGroupDescriptorBuilder clusterGroupBuilder;
1506 clusterGroupBuilder.ClusterGroupId(groupId)
1509 .MinEntry(clusterGroup.fMinEntry)
1510 .EntrySpan(clusterGroup.fEntrySpan)
1511 .NClusters(clusterGroup.fNClusters);
1512 descBuilder.AddClusterGroup(clusterGroupBuilder.MoveDescriptor().Unwrap());
1513 }
1514 bytes = frame + frameSize;
1515
1516 std::uint32_t nMDBlocks;
1517 frame = bytes;
1518 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nMDBlocks);
1519 if (!result)
1520 return R__FORWARD_ERROR(result);
1521 if (nMDBlocks > 0)
1522 R__LOG_WARNING(NTupleLog()) << "meta-data blocks are still unsupported";
1523 bytes = frame + frameSize;
1524
1525 return RResult<void>::Success();
1526}
1527
1530 DescriptorId_t clusterGroupId,
1531 RNTupleDescriptor &desc)
1532{
1533 auto base = reinterpret_cast<const unsigned char *>(buffer);
1534 auto bytes = base;
1535 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
1537
1538 result = DeserializeEnvelope(bytes, fnBufSizeLeft(), kEnvelopeTypePageList);
1539 if (!result)
1540 return R__FORWARD_ERROR(result);
1541 bytes += result.Unwrap();
1542
1543 std::uint64_t xxhash3{0};
1544 if (fnBufSizeLeft() < static_cast<int>(sizeof(std::uint64_t)))
1545 return R__FAIL("page list too short");
1546 bytes += DeserializeUInt64(bytes, xxhash3);
1547 if (xxhash3 != desc.GetOnDiskHeaderXxHash3())
1548 return R__FAIL("XxHash-3 mismatch between header and page list");
1549
1550 std::vector<RClusterDescriptorBuilder> clusterBuilders;
1551 DescriptorId_t firstClusterId{0};
1552 for (DescriptorId_t i = 0; i < clusterGroupId; ++i) {
1553 firstClusterId = firstClusterId + desc.GetClusterGroupDescriptor(i).GetNClusters();
1554 }
1555
1556 std::uint64_t clusterSummaryFrameSize;
1557 auto clusterSummaryFrame = bytes;
1558 auto fnClusterSummaryFrameSizeLeft = [&]() { return clusterSummaryFrameSize - (bytes - clusterSummaryFrame); };
1559
1560 std::uint32_t nClusterSummaries;
1561 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), clusterSummaryFrameSize, nClusterSummaries);
1562 if (!result)
1563 return R__FORWARD_ERROR(result);
1564 bytes += result.Unwrap();
1565 for (auto clusterId = firstClusterId; clusterId < firstClusterId + nClusterSummaries; ++clusterId) {
1566 RClusterSummary clusterSummary;
1567 result = DeserializeClusterSummary(bytes, fnClusterSummaryFrameSizeLeft(), clusterSummary);
1568 if (!result)
1569 return R__FORWARD_ERROR(result);
1570 bytes += result.Unwrap();
1571 if (clusterSummary.fColumnGroupID >= 0)
1572 return R__FAIL("sharded clusters are still unsupported");
1573
1575 builder.ClusterId(clusterId).FirstEntryIndex(clusterSummary.fFirstEntry).NEntries(clusterSummary.fNEntries);
1576 clusterBuilders.emplace_back(std::move(builder));
1577 }
1578 bytes = clusterSummaryFrame + clusterSummaryFrameSize;
1579
1580 std::uint64_t topMostFrameSize;
1581 auto topMostFrame = bytes;
1582 auto fnTopMostFrameSizeLeft = [&]() { return topMostFrameSize - (bytes - topMostFrame); };
1583
1584 std::uint32_t nClusters;
1585 result = DeserializeFrameHeader(bytes, fnBufSizeLeft(), topMostFrameSize, nClusters);
1586 if (!result)
1587 return R__FORWARD_ERROR(result);
1588 bytes += result.Unwrap();
1589
1590 if (nClusters != nClusterSummaries)
1591 return R__FAIL("mismatch between number of clusters and number of cluster summaries");
1592
1593 std::vector<RClusterDescriptor> clusters;
1594 for (std::uint32_t i = 0; i < nClusters; ++i) {
1595 std::uint64_t outerFrameSize;
1596 auto outerFrame = bytes;
1597 auto fnOuterFrameSizeLeft = [&]() { return outerFrameSize - (bytes - outerFrame); };
1598
1599 std::uint32_t nColumns;
1600 result = DeserializeFrameHeader(bytes, fnTopMostFrameSizeLeft(), outerFrameSize, nColumns);
1601 if (!result)
1602 return R__FORWARD_ERROR(result);
1603 bytes += result.Unwrap();
1604
1605 for (std::uint32_t j = 0; j < nColumns; ++j) {
1606 std::uint64_t innerFrameSize;
1607 auto innerFrame = bytes;
1608 auto fnInnerFrameSizeLeft = [&]() { return innerFrameSize - (bytes - innerFrame); };
1609
1610 std::uint32_t nPages;
1611 result = DeserializeFrameHeader(bytes, fnOuterFrameSizeLeft(), innerFrameSize, nPages);
1612 if (!result)
1613 return R__FORWARD_ERROR(result);
1614 bytes += result.Unwrap();
1615
1617 pageRange.fPhysicalColumnId = j;
1618 for (std::uint32_t k = 0; k < nPages; ++k) {
1619 if (fnInnerFrameSizeLeft() < static_cast<int>(sizeof(std::uint32_t)))
1620 return R__FAIL("inner frame too short");
1621 std::int32_t nElements;
1622 RNTupleLocator locator;
1623 bytes += DeserializeInt32(bytes, nElements);
1624 if (nElements < 0) {
1625 // TODO(jblomer): page with checksum
1626 nElements = -nElements;
1627 }
1628 result = DeserializeLocator(bytes, fnInnerFrameSizeLeft(), locator);
1629 if (!result)
1630 return R__FORWARD_ERROR(result);
1631 pageRange.fPageInfos.push_back({static_cast<std::uint32_t>(nElements), locator});
1632 bytes += result.Unwrap();
1633 }
1634
1635 if (fnInnerFrameSizeLeft() < static_cast<int>(sizeof(std::uint32_t) + sizeof(std::uint64_t)))
1636 return R__FAIL("page list frame too short");
1637 std::uint64_t columnOffset;
1638 bytes += DeserializeUInt64(bytes, columnOffset);
1639 std::uint32_t compressionSettings;
1640 bytes += DeserializeUInt32(bytes, compressionSettings);
1641
1642 clusterBuilders[i].CommitColumnRange(j, columnOffset, compressionSettings, pageRange);
1643 bytes = innerFrame + innerFrameSize;
1644 } // loop over columns
1645
1646 bytes = outerFrame + outerFrameSize;
1647
1648 clusterBuilders[i].AddDeferredColumnRanges(desc);
1649 clusters.emplace_back(clusterBuilders[i].MoveDescriptor().Unwrap());
1650 } // loop over clusters
1651 desc.AddClusterGroupDetails(clusterGroupId, clusters);
1652
1653 return RResult<void>::Success();
1654}
#define R__FORWARD_ERROR(res)
Short-hand to return an RResult<T> in an error state (i.e. after checking)
Definition RError.hxx:294
#define R__FORWARD_RESULT(res)
Short-hand to return an RResult<T> value from a subroutine to the calling stack frame.
Definition RError.hxx:292
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:290
#define R__LOG_WARNING(...)
Definition RLogger.hxx:363
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define ROOT_RELEASE
Definition RVersion.hxx:29
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define R__ASSERT(e)
Definition TError.h:118
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t nitems
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t bytes
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
The available trivial, native content types of a column.
A helper class for piece-wise construction of an RClusterDescriptor.
RClusterDescriptorBuilder & ClusterId(DescriptorId_t clusterId)
RClusterDescriptorBuilder & NEntries(std::uint64_t nEntries)
RClusterDescriptorBuilder & FirstEntryIndex(std::uint64_t firstEntryIndex)
A helper class for piece-wise construction of an RClusterGroupDescriptor.
RClusterGroupDescriptorBuilder & PageListLocator(const RNTupleLocator &pageListLocator)
RClusterGroupDescriptorBuilder & MinEntry(std::uint64_t minEntry)
RClusterGroupDescriptorBuilder & ClusterGroupId(DescriptorId_t clusterGroupId)
RClusterGroupDescriptorBuilder & EntrySpan(std::uint64_t entrySpan)
RClusterGroupDescriptorBuilder & NClusters(std::uint32_t nClusters)
RClusterGroupDescriptorBuilder & PageListLength(std::uint64_t pageListLength)
A helper class for piece-wise construction of an RColumnDescriptor.
RColumnDescriptorBuilder & PhysicalColumnId(DescriptorId_t physicalColumnId)
RColumnDescriptorBuilder & Model(const RColumnModel &model)
RColumnDescriptorBuilder & FieldId(DescriptorId_t fieldId)
RColumnDescriptorBuilder & Index(std::uint32_t index)
RResult< RColumnDescriptor > MakeDescriptor() const
Attempt to make a column descriptor.
RColumnDescriptorBuilder & LogicalColumnId(DescriptorId_t logicalColumnId)
A column element encapsulates the translation between basic C++ types and their column representation...
A helper class for piece-wise construction of an RFieldDescriptor.
RFieldDescriptorBuilder & TypeVersion(std::uint32_t typeVersion)
RFieldDescriptorBuilder & NRepetitions(std::uint64_t nRepetitions)
RFieldDescriptorBuilder & FieldVersion(std::uint32_t fieldVersion)
RFieldDescriptorBuilder & Structure(const ENTupleStructure &structure)
RFieldDescriptorBuilder & TypeName(const std::string &typeName)
RResult< RFieldDescriptor > MakeDescriptor() const
Attempt to make a field descriptor.
RFieldDescriptorBuilder & FieldName(const std::string &fieldName)
RFieldDescriptorBuilder & ParentId(DescriptorId_t id)
RFieldDescriptorBuilder & TypeAlias(const std::string &typeAlias)
RFieldDescriptorBuilder & FieldId(DescriptorId_t fieldId)
RFieldDescriptorBuilder & FieldDescription(const std::string &fieldDescription)
A helper class for piece-wise construction of an RNTupleDescriptor.
void BeginHeaderExtension()
Mark the beginning of the header extension; any fields and columns added after a call to this functio...
RResult< void > AddFieldLink(DescriptorId_t fieldId, DescriptorId_t linkId)
void AddToOnDiskFooterSize(std::uint64_t size)
The real footer size also include the page list envelopes.
void SetNTuple(const std::string_view name, const std::string_view description)
RResult< void > AddClusterGroup(RClusterGroupDescriptor &&clusterGroup)
void AddColumn(DescriptorId_t logicalId, DescriptorId_t physicalId, DescriptorId_t fieldId, const RColumnModel &model, std::uint32_t index, std::uint64_t firstElementIdx=0U)
The serialization context is used for the piecewise serialization of a descriptor.
DescriptorId_t GetOnDiskColumnId(DescriptorId_t memId) const
const std::vector< DescriptorId_t > & GetOnDiskFieldList() const
Return a vector containing the in-memory field ID for each on-disk counterpart, in order,...
DescriptorId_t GetOnDiskFieldId(DescriptorId_t memId) const
DescriptorId_t GetMemColumnId(DescriptorId_t onDiskId) const
std::size_t GetHeaderExtensionOffset() const
Return the offset of the first element in fOnDisk2MemFieldIDs that is part of the schema extension.
DescriptorId_t GetMemClusterGroupId(DescriptorId_t onDiskId) const
DescriptorId_t GetMemClusterId(DescriptorId_t onDiskId) const
void MapSchema(const RNTupleDescriptor &desc, bool forHeaderExtension)
Map in-memory field and column IDs to their on-disk counterparts.
A helper class for serializing and deserialization of the RNTuple binary format.
static std::uint32_t SerializeXxHash3(const unsigned char *data, std::uint64_t length, std::uint64_t &xxhash3, void *buffer)
Writes a XxHash-3 64bit checksum of the byte range given by data and length.
static RResult< std::uint32_t > DeserializeClusterSummary(const void *buffer, std::uint64_t bufSize, RClusterSummary &clusterSummary)
static std::uint32_t SerializeListFramePreamble(std::uint32_t nitems, void *buffer)
static RResult< std::uint32_t > DeserializeClusterGroup(const void *buffer, std::uint64_t bufSize, RClusterGroup &clusterGroup)
static std::uint32_t SerializeEnvelopePostscript(unsigned char *envelope, std::uint64_t size)
static RContext SerializeHeader(void *buffer, const RNTupleDescriptor &desc)
static std::uint32_t SerializeFeatureFlags(const std::vector< std::uint64_t > &flags, void *buffer)
static std::uint16_t SerializeColumnType(ROOT::Experimental::EColumnType type, void *buffer)
static std::uint32_t DeserializeUInt16(const void *buffer, std::uint16_t &val)
static RResult< void > DeserializeHeader(const void *buffer, std::uint64_t bufSize, RNTupleDescriptorBuilder &descBuilder)
static RResult< void > DeserializeFooter(const void *buffer, std::uint64_t bufSize, RNTupleDescriptorBuilder &descBuilder)
static std::uint32_t SerializeString(const std::string &val, void *buffer)
static RResult< std::uint32_t > DeserializeFrameHeader(const void *buffer, std::uint64_t bufSize, std::uint64_t &frameSize, std::uint32_t &nitems)
static std::uint32_t SerializePageList(void *buffer, const RNTupleDescriptor &desc, std::span< DescriptorId_t > physClusterIDs, const RContext &context)
static std::uint32_t DeserializeUInt32(const void *buffer, std::uint32_t &val)
static std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer)
static std::uint32_t SerializeEnvelopePreamble(std::uint16_t envelopeType, void *buffer)
static std::uint32_t DeserializeInt16(const void *buffer, std::int16_t &val)
static std::uint32_t SerializeClusterSummary(const RClusterSummary &clusterSummary, void *buffer)
static std::uint32_t SerializeFramePostscript(void *frame, std::uint64_t size)
static std::uint32_t SerializeInt16(std::int16_t val, void *buffer)
static RResult< void > DeserializePageList(const void *buffer, std::uint64_t bufSize, DescriptorId_t clusterGroupId, RNTupleDescriptor &desc)
static std::uint32_t SerializeSchemaDescription(void *buffer, const RNTupleDescriptor &desc, const RContext &context, bool forHeaderExtension=false)
Serialize the schema description in desc into buffer.
static RResult< std::uint32_t > DeserializeSchemaDescription(const void *buffer, std::uint64_t bufSize, RNTupleDescriptorBuilder &descBuilder)
static std::uint32_t SerializeLocator(const RNTupleLocator &locator, void *buffer)
static std::uint32_t SerializeInt32(std::int32_t val, void *buffer)
static RResult< void > VerifyXxHash3(const unsigned char *data, std::uint64_t length, std::uint64_t &xxhash3)
Expects an xxhash3 checksum in the 8 bytes following data + length and verifies it.
static RResult< std::uint16_t > DeserializeColumnType(const void *buffer, ROOT::Experimental::EColumnType &type)
static std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t &val)
static RResult< std::uint32_t > DeserializeFeatureFlags(const void *buffer, std::uint64_t bufSize, std::vector< std::uint64_t > &flags)
static std::uint32_t DeserializeInt32(const void *buffer, std::int32_t &val)
static std::uint32_t DeserializeInt64(const void *buffer, std::int64_t &val)
static RResult< std::uint16_t > DeserializeFieldStructure(const void *buffer, ROOT::Experimental::ENTupleStructure &structure)
static std::uint32_t SerializeEnvelopeLink(const REnvelopeLink &envelopeLink, void *buffer)
static RResult< std::uint32_t > DeserializeString(const void *buffer, std::uint64_t bufSize, std::string &val)
static std::uint32_t SerializeRecordFramePreamble(void *buffer)
static std::uint32_t SerializeUInt16(std::uint16_t val, void *buffer)
static std::uint32_t SerializeClusterGroup(const RClusterGroup &clusterGroup, void *buffer)
static RResult< std::uint32_t > DeserializeEnvelopeLink(const void *buffer, std::uint64_t bufSize, REnvelopeLink &envelopeLink)
static std::uint32_t SerializeFooter(void *buffer, const RNTupleDescriptor &desc, const RContext &context)
static std::uint32_t SerializeInt64(std::int64_t val, void *buffer)
static std::uint16_t SerializeFieldStructure(ROOT::Experimental::ENTupleStructure structure, void *buffer)
While we could just interpret the enums as ints, we make the translation explicit in order to avoid a...
static RResult< std::uint32_t > DeserializeEnvelope(const void *buffer, std::uint64_t bufSize, std::uint16_t expectedType)
static std::uint32_t SerializeUInt32(std::uint32_t val, void *buffer)
static RResult< std::uint32_t > DeserializeLocator(const void *buffer, std::uint64_t bufSize, RNTupleLocator &locator)
Records the parition of data into pages for a particular column in a particular cluster.
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Meta-data stored for every field of an ntuple.
The on-storage meta-data of an ntuple.
DescriptorId_t GetFieldZeroId() const
Returns the logical parent of all top-level NTuple data fields.
const RClusterDescriptor & GetClusterDescriptor(DescriptorId_t clusterId) const
RFieldDescriptorIterable GetFieldIterable(const RFieldDescriptor &fieldDesc) const
RResult< void > AddClusterGroupDetails(DescriptorId_t clusterGroupId, std::vector< RClusterDescriptor > &clusterDescs)
Methods to load and drop cluster group details (cluster IDs and page locations)
const RColumnDescriptor & GetColumnDescriptor(DescriptorId_t columnId) const
const RFieldDescriptor & GetFieldDescriptor(DescriptorId_t fieldId) const
const RClusterGroupDescriptor & GetClusterGroupDescriptor(DescriptorId_t clusterGroupId) const
RColumnDescriptorIterable GetColumnIterable() const
const RHeaderExtension * GetHeaderExtension() const
Return header extension information; if the descriptor does not have a header extension,...
std::vector< std::uint64_t > GetFeatureFlags() const
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
Definition RError.hxx:194
RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
ENTupleStructure
The fields in the ntuple model tree can carry different structural information about the type system.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
RNTupleLocator payload that is common for object stores using 64bit location information.
Generic information about the physical location of data.
ELocatorType
Values for the Type field in non-disk locators.
std::uint8_t fReserved
Reserved for use by concrete storage backends.
ELocatorType fType
For non-disk locators, the value for the Type field.
std::variant< std::uint64_t, std::string, RNTupleLocatorObject64 > fPosition
Simple on-disk locators consisting of a 64-bit offset use variant type uint64_t; extended locators ha...