Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleSerialize.cxx
Go to the documentation of this file.
1/// \file RNTupleSerialize.cxx
2/// \ingroup NTuple
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \author Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
5/// \date 2021-08-02
6
7/*************************************************************************
8 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
16#include <ROOT/RError.hxx>
19#include <ROOT/RNTupleTypes.hxx>
20#include <ROOT/RNTupleUtils.hxx>
21
22#include <RVersion.h>
23#include <TBufferFile.h>
24#include <TClass.h>
25#include <TList.h>
26#include <TStreamerInfo.h>
28#include <xxhash.h>
29
30#include <cassert>
31#include <cmath>
32#include <cstring> // for memcpy
33#include <deque>
34#include <functional>
35#include <limits>
36#include <set>
37#include <unordered_map>
38
45
46namespace {
47using RNTupleSerializer = ROOT::Internal::RNTupleSerializer;
48
52{
53
54 auto base = reinterpret_cast<unsigned char *>(buffer);
55 auto pos = base;
56 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
57
58 pos += RNTupleSerializer::SerializeRecordFramePreamble(*where);
59
60 pos += RNTupleSerializer::SerializeUInt32(fieldDesc.GetFieldVersion(), *where);
61 pos += RNTupleSerializer::SerializeUInt32(fieldDesc.GetTypeVersion(), *where);
62 pos += RNTupleSerializer::SerializeUInt32(onDiskParentId, *where);
63 if (auto res = RNTupleSerializer::SerializeFieldStructure(fieldDesc.GetStructure(), *where)) {
64 pos += res.Unwrap();
65 } else {
66 return R__FORWARD_ERROR(res);
67 }
68
69 std::uint16_t flags = 0;
70 if (fieldDesc.GetNRepetitions() > 0)
71 flags |= RNTupleSerializer::kFlagRepetitiveField;
72 if (fieldDesc.IsProjectedField())
73 flags |= RNTupleSerializer::kFlagProjectedField;
74 if (fieldDesc.GetTypeChecksum().has_value())
75 flags |= RNTupleSerializer::kFlagHasTypeChecksum;
76 if (fieldDesc.IsSoACollection())
77 flags |= RNTupleSerializer::kFlagIsSoACollection;
78 pos += RNTupleSerializer::SerializeUInt16(flags, *where);
79
80 pos += RNTupleSerializer::SerializeString(fieldDesc.GetFieldName(), *where);
81 pos += RNTupleSerializer::SerializeString(fieldDesc.GetTypeName(), *where);
82 pos += RNTupleSerializer::SerializeString(fieldDesc.GetTypeAlias(), *where);
83 pos += RNTupleSerializer::SerializeString(fieldDesc.GetFieldDescription(), *where);
84
85 if (flags & RNTupleSerializer::kFlagRepetitiveField) {
86 pos += RNTupleSerializer::SerializeUInt64(fieldDesc.GetNRepetitions(), *where);
87 }
88 if (flags & RNTupleSerializer::kFlagProjectedField) {
89 pos += RNTupleSerializer::SerializeUInt32(onDiskProjectionSourceId, *where);
90 }
91 if (flags & RNTupleSerializer::kFlagHasTypeChecksum) {
92 pos += RNTupleSerializer::SerializeUInt32(fieldDesc.GetTypeChecksum().value(), *where);
93 }
94
95 auto size = pos - base;
96 RNTupleSerializer::SerializeFramePostscript(base, size);
97
98 return size;
99}
100
101// clang-format off
102/// Serialize, in order, fields enumerated in `fieldList` to `buffer`. `firstOnDiskId` specifies the on-disk ID for the
103/// first element in the `fieldList` sequence. Before calling this function `RContext::MapSchema()` should have been
104/// called on `context` in order to map in-memory field IDs to their on-disk counterpart.
105/// \return The number of bytes written to the output buffer; if `buffer` is `nullptr` no data is serialized and the
106/// required buffer size is returned
107// clang-format on
109SerializeFieldList(const ROOT::RNTupleDescriptor &desc, std::span<const ROOT::DescriptorId_t> fieldList,
110 std::size_t firstOnDiskId, const ROOT::Internal::RNTupleSerializer::RContext &context, void *buffer)
111{
112 auto base = reinterpret_cast<unsigned char *>(buffer);
113 auto pos = base;
114 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
115
116 auto fieldZeroId = desc.GetFieldZeroId();
118 for (auto fieldId : fieldList) {
119 const auto &f = desc.GetFieldDescriptor(fieldId);
120 auto onDiskParentId =
121 (f.GetParentId() == fieldZeroId) ? onDiskFieldId : context.GetOnDiskFieldId(f.GetParentId());
123 f.IsProjectedField() ? context.GetOnDiskFieldId(f.GetProjectionSourceId()) : ROOT::kInvalidDescriptorId;
125 pos += res.Unwrap();
126 } else {
127 return R__FORWARD_ERROR(res);
128 }
130 }
131
132 return pos - base;
133}
134
137{
138 using ENTupleStructure = ROOT::ENTupleStructure;
139
140 auto base = reinterpret_cast<const unsigned char *>(buffer);
141 auto bytes = base;
142 std::uint64_t frameSize;
143 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
144 if (auto res = RNTupleSerializer::DeserializeFrameHeader(bytes, bufSize, frameSize)) {
145 bytes += res.Unwrap();
146 } else {
147 return R__FORWARD_ERROR(res);
148 }
149
150 std::uint32_t fieldVersion;
151 std::uint32_t typeVersion;
152 std::uint32_t parentId;
153 // initialize properly for call to SerializeFieldStructure()
154 ENTupleStructure structure{ENTupleStructure::kPlain};
155 std::uint16_t flags;
156 std::uint32_t result;
157 if (auto res = RNTupleSerializer::SerializeFieldStructure(structure, nullptr)) {
158 result = res.Unwrap();
159 } else {
160 return R__FORWARD_ERROR(res);
161 }
162 if (fnFrameSizeLeft() < 3 * sizeof(std::uint32_t) + result + sizeof(std::uint16_t)) {
163 return R__FAIL("field record frame too short");
164 }
165 bytes += RNTupleSerializer::DeserializeUInt32(bytes, fieldVersion);
166 bytes += RNTupleSerializer::DeserializeUInt32(bytes, typeVersion);
167 bytes += RNTupleSerializer::DeserializeUInt32(bytes, parentId);
168 if (auto res = RNTupleSerializer::DeserializeFieldStructure(bytes, structure)) {
169 bytes += res.Unwrap();
170 } else {
171 return R__FORWARD_ERROR(res);
172 }
173 bytes += RNTupleSerializer::DeserializeUInt16(bytes, flags);
174 fieldDesc.FieldVersion(fieldVersion).TypeVersion(typeVersion).ParentId(parentId).Structure(structure);
175
176 std::string fieldName;
177 std::string typeName;
178 std::string aliasName;
179 std::string description;
180 if (auto res = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), fieldName)) {
181 bytes += res.Unwrap();
182 } else {
183 return R__FORWARD_ERROR(res);
184 }
185 if (auto res = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), typeName)) {
186 bytes += res.Unwrap();
187 } else {
188 return R__FORWARD_ERROR(res);
189 }
190 if (auto res = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), aliasName)) {
191 bytes += res.Unwrap();
192 } else {
193 return R__FORWARD_ERROR(res);
194 }
195 if (auto res = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), description)) {
196 bytes += res.Unwrap();
197 } else {
198 return R__FORWARD_ERROR(res);
199 }
200 fieldDesc.FieldName(fieldName).TypeName(typeName).TypeAlias(aliasName).FieldDescription(description);
201
202 if (flags & RNTupleSerializer::kFlagRepetitiveField) {
203 if (fnFrameSizeLeft() < sizeof(std::uint64_t))
204 return R__FAIL("field record frame too short");
205 std::uint64_t nRepetitions;
206 bytes += RNTupleSerializer::DeserializeUInt64(bytes, nRepetitions);
207 fieldDesc.NRepetitions(nRepetitions);
208 }
209
210 if (flags & RNTupleSerializer::kFlagProjectedField) {
211 if (fnFrameSizeLeft() < sizeof(std::uint32_t))
212 return R__FAIL("field record frame too short");
213 std::uint32_t projectionSourceId;
214 bytes += RNTupleSerializer::DeserializeUInt32(bytes, projectionSourceId);
215 fieldDesc.ProjectionSourceId(projectionSourceId);
216 }
217
218 if (flags & RNTupleSerializer::kFlagHasTypeChecksum) {
219 if (fnFrameSizeLeft() < sizeof(std::uint32_t))
220 return R__FAIL("field record frame too short");
221 std::uint32_t typeChecksum;
222 bytes += RNTupleSerializer::DeserializeUInt32(bytes, typeChecksum);
223 fieldDesc.TypeChecksum(typeChecksum);
224 }
225
226 if (flags & RNTupleSerializer::kFlagIsSoACollection) {
227 fieldDesc.IsSoACollection(true);
228 }
229
230 return frameSize;
231}
232
235 void *buffer)
236{
237 R__ASSERT(!columnDesc.IsAliasColumn());
238
239 auto base = reinterpret_cast<unsigned char *>(buffer);
240 auto pos = base;
241 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
242
243 pos += RNTupleSerializer::SerializeRecordFramePreamble(*where);
244
245 if (auto res = RNTupleSerializer::SerializeColumnType(columnDesc.GetType(), *where)) {
246 pos += res.Unwrap();
247 } else {
248 return R__FORWARD_ERROR(res);
249 }
250 pos += RNTupleSerializer::SerializeUInt16(columnDesc.GetBitsOnStorage(), *where);
251 pos += RNTupleSerializer::SerializeUInt32(context.GetOnDiskFieldId(columnDesc.GetFieldId()), *where);
252 std::uint16_t flags = 0;
253 if (columnDesc.IsDeferredColumn())
254 flags |= RNTupleSerializer::kFlagDeferredColumn;
255 if (columnDesc.GetValueRange().has_value())
256 flags |= RNTupleSerializer::kFlagHasValueRange;
257 std::int64_t firstElementIdx = columnDesc.GetFirstElementIndex();
258 if (columnDesc.IsSuppressedDeferredColumn())
260 pos += RNTupleSerializer::SerializeUInt16(flags, *where);
261 pos += RNTupleSerializer::SerializeUInt16(columnDesc.GetRepresentationIndex(), *where);
262 if (flags & RNTupleSerializer::kFlagDeferredColumn)
263 pos += RNTupleSerializer::SerializeInt64(firstElementIdx, *where);
264 if (flags & RNTupleSerializer::kFlagHasValueRange) {
265 auto [min, max] = *columnDesc.GetValueRange();
266 std::uint64_t intMin, intMax;
267 static_assert(sizeof(min) == sizeof(intMin) && sizeof(max) == sizeof(intMax));
268 memcpy(&intMin, &min, sizeof(min));
269 memcpy(&intMax, &max, sizeof(max));
270 pos += RNTupleSerializer::SerializeUInt64(intMin, *where);
271 pos += RNTupleSerializer::SerializeUInt64(intMax, *where);
272 }
273
274 if (auto res = RNTupleSerializer::SerializeFramePostscript(buffer ? base : nullptr, pos - base)) {
275 pos += res.Unwrap();
276 } else {
277 return R__FORWARD_ERROR(res);
278 }
279
280 return pos - base;
281}
282
284 std::span<const ROOT::DescriptorId_t> fieldList,
286 void *buffer, bool forHeaderExtension)
287{
288 auto base = reinterpret_cast<unsigned char *>(buffer);
289 auto pos = base;
290 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
291
292 const auto *xHeader = !forHeaderExtension ? desc.GetHeaderExtension() : nullptr;
293
294 for (auto parentId : fieldList) {
295 // If we're serializing the non-extended header and we already have a header extension (which may happen if
296 // we load an RNTuple for incremental merging), we need to skip all the extended fields, as they need to be
297 // written in the header extension, not in the regular header.
298 if (xHeader && xHeader->ContainsField(parentId))
299 continue;
300
301 for (const auto &c : desc.GetColumnIterable(parentId)) {
302 if (c.IsAliasColumn() || (xHeader && xHeader->ContainsExtendedColumnRepresentation(c.GetLogicalId())))
303 continue;
304
305 if (auto res = SerializePhysicalColumn(c, context, *where)) {
306 pos += res.Unwrap();
307 } else {
308 return R__FORWARD_ERROR(res);
309 }
310 }
311 }
312
313 return pos - base;
314}
315
318{
320
321 auto base = reinterpret_cast<const unsigned char *>(buffer);
322 auto bytes = base;
323 std::uint64_t frameSize;
324 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
325 if (auto res = RNTupleSerializer::DeserializeFrameHeader(bytes, bufSize, frameSize)) {
326 bytes += res.Unwrap();
327 } else {
328 return R__FORWARD_ERROR(res);
329 }
330
331 // Initialize properly for SerializeColumnType
332 ENTupleColumnType type{ENTupleColumnType::kIndex32};
333 std::uint16_t bitsOnStorage;
334 std::uint32_t fieldId;
335 std::uint16_t flags;
336 std::uint16_t representationIndex;
337 std::int64_t firstElementIdx = 0;
338 if (fnFrameSizeLeft() < RNTupleSerializer::SerializeColumnType(type, nullptr).Unwrap() + sizeof(std::uint16_t) +
339 2 * sizeof(std::uint32_t)) {
340 return R__FAIL("column record frame too short");
341 }
342 if (auto res = RNTupleSerializer::DeserializeColumnType(bytes, type)) {
343 bytes += res.Unwrap();
344 } else {
345 return R__FORWARD_ERROR(res);
346 }
347 bytes += RNTupleSerializer::DeserializeUInt16(bytes, bitsOnStorage);
348 bytes += RNTupleSerializer::DeserializeUInt32(bytes, fieldId);
349 bytes += RNTupleSerializer::DeserializeUInt16(bytes, flags);
350 bytes += RNTupleSerializer::DeserializeUInt16(bytes, representationIndex);
351 if (flags & RNTupleSerializer::kFlagDeferredColumn) {
352 if (fnFrameSizeLeft() < sizeof(std::uint64_t))
353 return R__FAIL("column record frame too short");
354 bytes += RNTupleSerializer::DeserializeInt64(bytes, firstElementIdx);
355 }
356 if (flags & RNTupleSerializer::kFlagHasValueRange) {
357 if (fnFrameSizeLeft() < 2 * sizeof(std::uint64_t))
358 return R__FAIL("field record frame too short");
359 std::uint64_t minInt, maxInt;
360 bytes += RNTupleSerializer::DeserializeUInt64(bytes, minInt);
361 bytes += RNTupleSerializer::DeserializeUInt64(bytes, maxInt);
362 double min, max;
363 memcpy(&min, &minInt, sizeof(min));
364 memcpy(&max, &maxInt, sizeof(max));
365 columnDesc.ValueRange(min, max);
366 }
367
368 columnDesc.FieldId(fieldId).BitsOnStorage(bitsOnStorage).Type(type).RepresentationIndex(representationIndex);
369 columnDesc.FirstElementIndex(std::abs(firstElementIdx));
370 if (firstElementIdx < 0)
371 columnDesc.SetSuppressedDeferred();
372
373 return frameSize;
374}
375
377{
378 auto base = reinterpret_cast<unsigned char *>(buffer);
379 auto pos = base;
380 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
381
382 pos += RNTupleSerializer::SerializeRecordFramePreamble(*where);
383
384 if (auto res = RNTupleSerializer::SerializeExtraTypeInfoId(desc.GetContentId(), *where)) {
385 pos += res.Unwrap();
386 } else {
387 return R__FORWARD_ERROR(res);
388 }
389 pos += RNTupleSerializer::SerializeUInt32(desc.GetTypeVersion(), *where);
390 pos += RNTupleSerializer::SerializeString(desc.GetTypeName(), *where);
391 pos += RNTupleSerializer::SerializeString(desc.GetContent(), *where);
392
393 auto size = pos - base;
394 RNTupleSerializer::SerializeFramePostscript(base, size);
395
396 return size;
397}
398
400{
401 auto base = reinterpret_cast<unsigned char *>(buffer);
402 auto pos = base;
403 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
404
405 for (const auto &extraTypeInfoDesc : ntplDesc.GetExtraTypeInfoIterable()) {
407 pos += res.Unwrap();
408 } else {
409 return R__FORWARD_ERROR(res);
410 }
411 }
412
413 return pos - base;
414}
415
416ROOT::RResult<std::uint32_t> DeserializeExtraTypeInfo(const void *buffer, std::uint64_t bufSize,
418{
420
421 auto base = reinterpret_cast<const unsigned char *>(buffer);
422 auto bytes = base;
423 std::uint64_t frameSize;
424 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
425 auto result = RNTupleSerializer::DeserializeFrameHeader(bytes, bufSize, frameSize);
426 if (!result)
427 return R__FORWARD_ERROR(result);
428 bytes += result.Unwrap();
429
430 EExtraTypeInfoIds contentId{EExtraTypeInfoIds::kInvalid};
431 std::uint32_t typeVersion;
432 if (fnFrameSizeLeft() < 2 * sizeof(std::uint32_t)) {
433 return R__FAIL("extra type info record frame too short");
434 }
435 result = RNTupleSerializer::DeserializeExtraTypeInfoId(bytes, contentId);
436 if (!result)
437 return R__FORWARD_ERROR(result);
438 bytes += result.Unwrap();
439 bytes += RNTupleSerializer::DeserializeUInt32(bytes, typeVersion);
440
441 std::string typeName;
442 std::string content;
443 result = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), typeName).Unwrap();
444 if (!result)
445 return R__FORWARD_ERROR(result);
446 bytes += result.Unwrap();
447 result = RNTupleSerializer::DeserializeString(bytes, fnFrameSizeLeft(), content).Unwrap();
448 if (!result)
449 return R__FORWARD_ERROR(result);
450 bytes += result.Unwrap();
451
453
454 return frameSize;
455}
456
457std::uint32_t SerializeLocatorPayloadLarge(const ROOT::RNTupleLocator &locator, unsigned char *buffer)
458{
459 if (buffer) {
460 RNTupleSerializer::SerializeUInt64(locator.GetNBytesOnStorage(), buffer);
461 RNTupleSerializer::SerializeUInt64(locator.GetPosition<std::uint64_t>(), buffer + sizeof(std::uint64_t));
462 }
463 return sizeof(std::uint64_t) + sizeof(std::uint64_t);
464}
465
466void DeserializeLocatorPayloadLarge(const unsigned char *buffer, ROOT::RNTupleLocator &locator)
467{
468 std::uint64_t nBytesOnStorage;
469 std::uint64_t position;
470 RNTupleSerializer::DeserializeUInt64(buffer, nBytesOnStorage);
471 RNTupleSerializer::DeserializeUInt64(buffer + sizeof(std::uint64_t), position);
472 locator.SetNBytesOnStorage(nBytesOnStorage);
473 locator.SetPosition(position);
474}
475
476std::uint32_t SerializeLocatorPayloadObject64(const ROOT::RNTupleLocator &locator, unsigned char *buffer)
477{
478 const auto &data = locator.GetPosition<ROOT::RNTupleLocatorObject64>();
479 const uint32_t sizeofNBytesOnStorage = (locator.GetNBytesOnStorage() > std::numeric_limits<std::uint32_t>::max())
480 ? sizeof(std::uint64_t)
481 : sizeof(std::uint32_t);
482 if (buffer) {
483 if (sizeofNBytesOnStorage == sizeof(std::uint32_t)) {
484 RNTupleSerializer::SerializeUInt32(locator.GetNBytesOnStorage(), buffer);
485 } else {
486 RNTupleSerializer::SerializeUInt64(locator.GetNBytesOnStorage(), buffer);
487 }
488 RNTupleSerializer::SerializeUInt64(data.GetLocation(), buffer + sizeofNBytesOnStorage);
489 }
490 return sizeofNBytesOnStorage + sizeof(std::uint64_t);
491}
492
493ROOT::RResult<void> DeserializeLocatorPayloadObject64(const unsigned char *buffer, std::uint32_t sizeofLocatorPayload,
495{
496 std::uint64_t location;
497 if (sizeofLocatorPayload == 12) {
498 std::uint32_t nBytesOnStorage;
499 RNTupleSerializer::DeserializeUInt32(buffer, nBytesOnStorage);
500 locator.SetNBytesOnStorage(nBytesOnStorage);
501 RNTupleSerializer::DeserializeUInt64(buffer + sizeof(std::uint32_t), location);
502 } else if (sizeofLocatorPayload == 16) {
503 std::uint64_t nBytesOnStorage;
504 RNTupleSerializer::DeserializeUInt64(buffer, nBytesOnStorage);
505 locator.SetNBytesOnStorage(nBytesOnStorage);
506 RNTupleSerializer::DeserializeUInt64(buffer + sizeof(std::uint64_t), location);
507 } else {
508 return R__FAIL("invalid DAOS locator payload size: " + std::to_string(sizeofLocatorPayload));
509 }
510 locator.SetPosition(ROOT::RNTupleLocatorObject64{location});
512}
513
515 const ROOT::Internal::RNTupleSerializer::RContext &context, void *buffer)
516{
517 R__ASSERT(columnDesc.IsAliasColumn());
518
519 auto base = reinterpret_cast<unsigned char *>(buffer);
520 auto pos = base;
521 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
522
523 pos += RNTupleSerializer::SerializeRecordFramePreamble(*where);
524
525 pos += RNTupleSerializer::SerializeUInt32(context.GetOnDiskColumnId(columnDesc.GetPhysicalId()), *where);
526 pos += RNTupleSerializer::SerializeUInt32(context.GetOnDiskFieldId(columnDesc.GetFieldId()), *where);
527
528 pos += RNTupleSerializer::SerializeFramePostscript(buffer ? base : nullptr, pos - base).Unwrap();
529
530 return pos - base;
531}
532
534 std::span<const ROOT::DescriptorId_t> fieldList,
535 const ROOT::Internal::RNTupleSerializer::RContext &context, void *buffer,
537{
538 auto base = reinterpret_cast<unsigned char *>(buffer);
539 auto pos = base;
540 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
541
542 const auto *xHeader = !forHeaderExtension ? desc.GetHeaderExtension() : nullptr;
543
544 for (auto parentId : fieldList) {
545 if (xHeader && xHeader->ContainsField(parentId))
546 continue;
547
548 for (const auto &c : desc.GetColumnIterable(parentId)) {
549 if (!c.IsAliasColumn() || (xHeader && xHeader->ContainsExtendedColumnRepresentation(c.GetLogicalId())))
550 continue;
551
552 pos += SerializeAliasColumn(c, context, *where);
553 }
554 }
555
556 return pos - base;
557}
558
559ROOT::RResult<std::uint32_t> DeserializeAliasColumn(const void *buffer, std::uint64_t bufSize,
560 std::uint32_t &physicalColumnId, std::uint32_t &fieldId)
561{
562 auto base = reinterpret_cast<const unsigned char *>(buffer);
563 auto bytes = base;
564 std::uint64_t frameSize;
565 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
566 auto result = RNTupleSerializer::DeserializeFrameHeader(bytes, bufSize, frameSize);
567 if (!result)
568 return R__FORWARD_ERROR(result);
569 bytes += result.Unwrap();
570
571 if (fnFrameSizeLeft() < 2 * sizeof(std::uint32_t)) {
572 return R__FAIL("alias column record frame too short");
573 }
574
575 bytes += RNTupleSerializer::DeserializeUInt32(bytes, physicalColumnId);
576 bytes += RNTupleSerializer::DeserializeUInt32(bytes, fieldId);
577
578 return frameSize;
579}
580
581} // anonymous namespace
582
583std::uint32_t ROOT::Internal::RNTupleSerializer::SerializeXxHash3(const unsigned char *data, std::uint64_t length,
584 std::uint64_t &xxhash3, void *buffer)
585{
586 if (buffer != nullptr) {
588 SerializeUInt64(xxhash3, buffer);
589 }
590 return 8;
591}
592
594 std::uint64_t &xxhash3)
595{
597 DeserializeUInt64(data + length, xxhash3);
598 if (xxhash3 != checksumReal)
599 return R__FAIL("XxHash-3 checksum mismatch");
600 return RResult<void>::Success();
601}
602
604{
605 std::uint64_t xxhash3;
606 return R__FORWARD_RESULT(VerifyXxHash3(data, length, xxhash3));
607}
608
609std::uint32_t ROOT::Internal::RNTupleSerializer::SerializeInt16(std::int16_t val, void *buffer)
610{
611 if (buffer != nullptr) {
612 auto bytes = reinterpret_cast<unsigned char *>(buffer);
613 bytes[0] = (val & 0x00FF);
614 bytes[1] = (val & 0xFF00) >> 8;
615 }
616 return 2;
617}
618
619std::uint32_t ROOT::Internal::RNTupleSerializer::DeserializeInt16(const void *buffer, std::int16_t &val)
620{
621 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
622 val = std::int16_t(bytes[0]) + (std::int16_t(bytes[1]) << 8);
623 return 2;
624}
625
626std::uint32_t ROOT::Internal::RNTupleSerializer::SerializeUInt16(std::uint16_t val, void *buffer)
627{
628 return SerializeInt16(val, buffer);
629}
630
631std::uint32_t ROOT::Internal::RNTupleSerializer::DeserializeUInt16(const void *buffer, std::uint16_t &val)
632{
633 return DeserializeInt16(buffer, *reinterpret_cast<std::int16_t *>(&val));
634}
635
636std::uint32_t ROOT::Internal::RNTupleSerializer::SerializeInt32(std::int32_t val, void *buffer)
637{
638 if (buffer != nullptr) {
639 auto bytes = reinterpret_cast<unsigned char *>(buffer);
640 bytes[0] = (val & 0x000000FF);
641 bytes[1] = (val & 0x0000FF00) >> 8;
642 bytes[2] = (val & 0x00FF0000) >> 16;
643 bytes[3] = (val & 0xFF000000) >> 24;
644 }
645 return 4;
646}
647
648std::uint32_t ROOT::Internal::RNTupleSerializer::DeserializeInt32(const void *buffer, std::int32_t &val)
649{
650 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
651 val = std::int32_t(bytes[0]) + (std::int32_t(bytes[1]) << 8) + (std::int32_t(bytes[2]) << 16) +
652 (std::int32_t(bytes[3]) << 24);
653 return 4;
654}
655
656std::uint32_t ROOT::Internal::RNTupleSerializer::SerializeUInt32(std::uint32_t val, void *buffer)
657{
658 return SerializeInt32(val, buffer);
659}
660
661std::uint32_t ROOT::Internal::RNTupleSerializer::DeserializeUInt32(const void *buffer, std::uint32_t &val)
662{
663 return DeserializeInt32(buffer, *reinterpret_cast<std::int32_t *>(&val));
664}
665
666std::uint32_t ROOT::Internal::RNTupleSerializer::SerializeInt64(std::int64_t val, void *buffer)
667{
668 if (buffer != nullptr) {
669 auto bytes = reinterpret_cast<unsigned char *>(buffer);
670 bytes[0] = (val & 0x00000000000000FF);
671 bytes[1] = (val & 0x000000000000FF00) >> 8;
672 bytes[2] = (val & 0x0000000000FF0000) >> 16;
673 bytes[3] = (val & 0x00000000FF000000) >> 24;
674 bytes[4] = (val & 0x000000FF00000000) >> 32;
675 bytes[5] = (val & 0x0000FF0000000000) >> 40;
676 bytes[6] = (val & 0x00FF000000000000) >> 48;
677 bytes[7] = (val & 0xFF00000000000000) >> 56;
678 }
679 return 8;
680}
681
682std::uint32_t ROOT::Internal::RNTupleSerializer::DeserializeInt64(const void *buffer, std::int64_t &val)
683{
684 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
685 val = std::int64_t(bytes[0]) + (std::int64_t(bytes[1]) << 8) + (std::int64_t(bytes[2]) << 16) +
686 (std::int64_t(bytes[3]) << 24) + (std::int64_t(bytes[4]) << 32) + (std::int64_t(bytes[5]) << 40) +
687 (std::int64_t(bytes[6]) << 48) + (std::int64_t(bytes[7]) << 56);
688 return 8;
689}
690
691std::uint32_t ROOT::Internal::RNTupleSerializer::SerializeUInt64(std::uint64_t val, void *buffer)
692{
693 return SerializeInt64(val, buffer);
694}
695
696std::uint32_t ROOT::Internal::RNTupleSerializer::DeserializeUInt64(const void *buffer, std::uint64_t &val)
697{
698 return DeserializeInt64(buffer, *reinterpret_cast<std::int64_t *>(&val));
699}
700
701std::uint32_t ROOT::Internal::RNTupleSerializer::SerializeString(const std::string &val, void *buffer)
702{
703 if (buffer) {
704 auto pos = reinterpret_cast<unsigned char *>(buffer);
705 pos += SerializeUInt32(val.length(), pos);
706 memcpy(pos, val.data(), val.length());
707 }
708 return sizeof(std::uint32_t) + val.length();
709}
710
712ROOT::Internal::RNTupleSerializer::DeserializeString(const void *buffer, std::uint64_t bufSize, std::string &val)
713{
714 if (bufSize < sizeof(std::uint32_t))
715 return R__FAIL("string buffer too short");
716 bufSize -= sizeof(std::uint32_t);
717
718 auto base = reinterpret_cast<const unsigned char *>(buffer);
719 auto bytes = base;
720 std::uint32_t length;
721 bytes += DeserializeUInt32(buffer, length);
722 if (bufSize < length)
723 return R__FAIL("string buffer too short");
724
725 val.resize(length);
726 memcpy(&val[0], bytes, length);
727 return sizeof(std::uint32_t) + length;
728}
729
732{
733 switch (type) {
734 case ENTupleColumnType::kBit: return SerializeUInt16(0x00, buffer);
735 case ENTupleColumnType::kByte: return SerializeUInt16(0x01, buffer);
736 case ENTupleColumnType::kChar: return SerializeUInt16(0x02, buffer);
737 case ENTupleColumnType::kInt8: return SerializeUInt16(0x03, buffer);
738 case ENTupleColumnType::kUInt8: return SerializeUInt16(0x04, buffer);
739 case ENTupleColumnType::kInt16: return SerializeUInt16(0x05, buffer);
740 case ENTupleColumnType::kUInt16: return SerializeUInt16(0x06, buffer);
741 case ENTupleColumnType::kInt32: return SerializeUInt16(0x07, buffer);
742 case ENTupleColumnType::kUInt32: return SerializeUInt16(0x08, buffer);
743 case ENTupleColumnType::kInt64: return SerializeUInt16(0x09, buffer);
744 case ENTupleColumnType::kUInt64: return SerializeUInt16(0x0A, buffer);
745 case ENTupleColumnType::kReal16: return SerializeUInt16(0x0B, buffer);
746 case ENTupleColumnType::kReal32: return SerializeUInt16(0x0C, buffer);
747 case ENTupleColumnType::kReal64: return SerializeUInt16(0x0D, buffer);
748 case ENTupleColumnType::kIndex32: return SerializeUInt16(0x0E, buffer);
749 case ENTupleColumnType::kIndex64: return SerializeUInt16(0x0F, buffer);
750 case ENTupleColumnType::kSwitch: return SerializeUInt16(0x10, buffer);
751 case ENTupleColumnType::kSplitInt16: return SerializeUInt16(0x11, buffer);
752 case ENTupleColumnType::kSplitUInt16: return SerializeUInt16(0x12, buffer);
753 case ENTupleColumnType::kSplitInt32: return SerializeUInt16(0x13, buffer);
754 case ENTupleColumnType::kSplitUInt32: return SerializeUInt16(0x14, buffer);
755 case ENTupleColumnType::kSplitInt64: return SerializeUInt16(0x15, buffer);
756 case ENTupleColumnType::kSplitUInt64: return SerializeUInt16(0x16, buffer);
757 case ENTupleColumnType::kSplitReal32: return SerializeUInt16(0x18, buffer);
758 case ENTupleColumnType::kSplitReal64: return SerializeUInt16(0x19, buffer);
759 case ENTupleColumnType::kSplitIndex32: return SerializeUInt16(0x1A, buffer);
760 case ENTupleColumnType::kSplitIndex64: return SerializeUInt16(0x1B, buffer);
761 case ENTupleColumnType::kReal32Trunc: return SerializeUInt16(0x1C, buffer);
762 case ENTupleColumnType::kReal32Quant: return SerializeUInt16(0x1D, buffer);
763 default:
765 return SerializeUInt16(0x99, buffer);
766 return R__FAIL("unexpected column type");
767 }
768}
769
772{
773 std::uint16_t onDiskType;
774 auto result = DeserializeUInt16(buffer, onDiskType);
775
776 switch (onDiskType) {
777 case 0x00: type = ENTupleColumnType::kBit; break;
778 case 0x01: type = ENTupleColumnType::kByte; break;
779 case 0x02: type = ENTupleColumnType::kChar; break;
780 case 0x03: type = ENTupleColumnType::kInt8; break;
781 case 0x04: type = ENTupleColumnType::kUInt8; break;
782 case 0x05: type = ENTupleColumnType::kInt16; break;
783 case 0x06: type = ENTupleColumnType::kUInt16; break;
784 case 0x07: type = ENTupleColumnType::kInt32; break;
785 case 0x08: type = ENTupleColumnType::kUInt32; break;
786 case 0x09: type = ENTupleColumnType::kInt64; break;
787 case 0x0A: type = ENTupleColumnType::kUInt64; break;
788 case 0x0B: type = ENTupleColumnType::kReal16; break;
789 case 0x0C: type = ENTupleColumnType::kReal32; break;
790 case 0x0D: type = ENTupleColumnType::kReal64; break;
791 case 0x0E: type = ENTupleColumnType::kIndex32; break;
792 case 0x0F: type = ENTupleColumnType::kIndex64; break;
793 case 0x10: type = ENTupleColumnType::kSwitch; break;
794 case 0x11: type = ENTupleColumnType::kSplitInt16; break;
795 case 0x12: type = ENTupleColumnType::kSplitUInt16; break;
796 case 0x13: type = ENTupleColumnType::kSplitInt32; break;
797 case 0x14: type = ENTupleColumnType::kSplitUInt32; break;
798 case 0x15: type = ENTupleColumnType::kSplitInt64; break;
799 case 0x16: type = ENTupleColumnType::kSplitUInt64; break;
800 case 0x18: type = ENTupleColumnType::kSplitReal32; break;
801 case 0x19: type = ENTupleColumnType::kSplitReal64; break;
802 case 0x1A: type = ENTupleColumnType::kSplitIndex32; break;
803 case 0x1B: type = ENTupleColumnType::kSplitIndex64; break;
804 case 0x1C: type = ENTupleColumnType::kReal32Trunc; break;
805 case 0x1D: type = ENTupleColumnType::kReal32Quant; break;
806 // case 0x99 => kTestFutureColumnType missing on purpose
807 default:
808 // may be a column type introduced by a future version
810 break;
811 }
812 return result;
813}
814
817{
819 switch (structure) {
820 case ENTupleStructure::kPlain: return SerializeUInt16(0x00, buffer);
821 case ENTupleStructure::kCollection: return SerializeUInt16(0x01, buffer);
822 case ENTupleStructure::kRecord: return SerializeUInt16(0x02, buffer);
823 case ENTupleStructure::kVariant: return SerializeUInt16(0x03, buffer);
824 case ENTupleStructure::kStreamer: return SerializeUInt16(0x04, buffer);
825 default:
827 return SerializeUInt16(0x99, buffer);
828 return R__FAIL("unexpected field structure type");
829 }
830}
831
834{
836 std::uint16_t onDiskValue;
837 auto result = DeserializeUInt16(buffer, onDiskValue);
838 switch (onDiskValue) {
839 case 0x00: structure = ENTupleStructure::kPlain; break;
840 case 0x01: structure = ENTupleStructure::kCollection; break;
841 case 0x02: structure = ENTupleStructure::kRecord; break;
842 case 0x03: structure = ENTupleStructure::kVariant; break;
843 case 0x04: structure = ENTupleStructure::kStreamer; break;
844 // case 0x99 => kTestFutureFieldStructure intentionally missing
845 default: structure = ENTupleStructure::kUnknown;
846 }
847 return result;
848}
849
852{
853 switch (id) {
854 case ROOT::EExtraTypeInfoIds::kStreamerInfo: return SerializeUInt32(0x00, buffer);
855 default: return R__FAIL("unexpected extra type info id");
856 }
857}
858
861{
862 std::uint32_t onDiskValue;
863 auto result = DeserializeUInt32(buffer, onDiskValue);
864 switch (onDiskValue) {
865 case 0x00: id = ROOT::EExtraTypeInfoIds::kStreamerInfo; break;
866 default:
868 R__LOG_DEBUG(0, ROOT::Internal::NTupleLog()) << "Unknown extra type info id: " << onDiskValue;
869 }
870 return result;
871}
872
874{
875 auto base = reinterpret_cast<unsigned char *>(buffer);
876 auto pos = base;
877 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
878
879 pos += SerializeUInt64(envelopeType, *where);
880 // The 48bits size information is filled in the postscript
881 return pos - base;
882}
883
885 std::uint64_t size,
886 std::uint64_t &xxhash3)
887{
888 if (size < sizeof(std::uint64_t))
889 return R__FAIL("envelope size too small");
890 if (size >= static_cast<uint64_t>(1) << 48)
891 return R__FAIL("envelope size too big");
892 if (envelope) {
893 std::uint64_t typeAndSize;
894 DeserializeUInt64(envelope, typeAndSize);
895 typeAndSize |= (size + 8) << 16;
896 SerializeUInt64(typeAndSize, envelope);
897 }
898 return SerializeXxHash3(envelope, size, xxhash3, envelope ? (envelope + size) : nullptr);
899}
900
903{
904 std::uint64_t xxhash3;
905 return R__FORWARD_RESULT(SerializeEnvelopePostscript(envelope, size, xxhash3));
906}
907
910 std::uint16_t expectedType, std::uint64_t &xxhash3)
911{
912 const std::uint64_t minEnvelopeSize = sizeof(std::uint64_t) + sizeof(std::uint64_t);
914 return R__FAIL("invalid envelope buffer, too short");
915
916 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
917 auto base = bytes;
918
919 std::uint64_t typeAndSize;
920 bytes += DeserializeUInt64(bytes, typeAndSize);
921
922 std::uint16_t envelopeType = typeAndSize & 0xFFFF;
923 if (envelopeType != expectedType) {
924 return R__FAIL("envelope type mismatch: expected " + std::to_string(expectedType) + ", found " +
925 std::to_string(envelopeType));
926 }
927
928 std::uint64_t envelopeSize = typeAndSize >> 16;
929 if (bufSize < envelopeSize)
930 return R__FAIL("envelope buffer size too small");
932 return R__FAIL("invalid envelope, too short");
933
934 auto result = VerifyXxHash3(base, envelopeSize - 8, xxhash3);
935 if (!result)
936 return R__FORWARD_ERROR(result);
937
938 return sizeof(typeAndSize);
939}
940
942 std::uint64_t bufSize,
943 std::uint16_t expectedType)
944{
945 std::uint64_t xxhash3;
946 return R__FORWARD_RESULT(DeserializeEnvelope(buffer, bufSize, expectedType, xxhash3));
947}
948
950{
951 // Marker: multiply the final size with 1
952 return SerializeInt64(1, buffer);
953}
954
956{
957 auto base = reinterpret_cast<unsigned char *>(buffer);
958 auto pos = base;
959 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
960
961 // Marker: multiply the final size with -1
962 pos += SerializeInt64(-1, *where);
963 pos += SerializeUInt32(nitems, *where);
964 return pos - base;
965}
966
969{
970 auto preambleSize = sizeof(std::int64_t);
971 if (size < preambleSize)
972 return R__FAIL("frame too short: " + std::to_string(size));
973 if (frame) {
974 std::int64_t marker;
975 DeserializeInt64(frame, marker);
976 if ((marker < 0) && (size < (sizeof(std::uint32_t) + preambleSize)))
977 return R__FAIL("frame too short: " + std::to_string(size));
978 SerializeInt64(marker * static_cast<int64_t>(size), frame);
979 }
980 return 0;
981}
982
985 std::uint64_t &frameSize, std::uint32_t &nitems)
986{
987 std::uint64_t minSize = sizeof(std::int64_t);
988 if (bufSize < minSize)
989 return R__FAIL("frame too short");
990
991 std::int64_t *ssize = reinterpret_cast<std::int64_t *>(&frameSize);
992 DeserializeInt64(buffer, *ssize);
993
994 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
995 bytes += minSize;
996
997 if (*ssize >= 0) {
998 // Record frame
999 nitems = 1;
1000 } else {
1001 // List frame
1002 minSize += sizeof(std::uint32_t);
1003 if (bufSize < minSize)
1004 return R__FAIL("frame too short");
1005 bytes += DeserializeUInt32(bytes, nitems);
1006 *ssize = -(*ssize);
1007 }
1008
1009 if (frameSize < minSize)
1010 return R__FAIL("corrupt frame size");
1011 if (bufSize < frameSize)
1012 return R__FAIL("frame too short");
1013
1014 return bytes - reinterpret_cast<const unsigned char *>(buffer);
1015}
1016
1018 std::uint64_t bufSize,
1019 std::uint64_t &frameSize)
1020{
1021 std::uint32_t nitems;
1022 return R__FORWARD_RESULT(DeserializeFrameHeader(buffer, bufSize, frameSize, nitems));
1023}
1024
1026ROOT::Internal::RNTupleSerializer::SerializeFeatureFlags(const std::vector<std::uint64_t> &flags, void *buffer)
1027{
1028 if (flags.empty())
1029 return SerializeUInt64(0, buffer);
1030
1031 if (buffer) {
1032 auto bytes = reinterpret_cast<unsigned char *>(buffer);
1033
1034 for (unsigned i = 0; i < flags.size(); ++i) {
1035 if (flags[i] & 0x8000000000000000)
1036 return R__FAIL("feature flag out of bounds");
1037
1038 // The MSb indicates that another Int64 follows; set this bit to 1 for all except the last element
1039 if (i == (flags.size() - 1))
1040 SerializeUInt64(flags[i], bytes);
1041 else
1042 bytes += SerializeUInt64(flags[i] | 0x8000000000000000, bytes);
1043 }
1044 }
1045 return (flags.size() * sizeof(std::int64_t));
1046}
1047
1050 std::vector<std::uint64_t> &flags)
1051{
1052 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
1053
1054 flags.clear();
1055 std::uint64_t f;
1056 do {
1057 if (bufSize < sizeof(std::uint64_t))
1058 return R__FAIL("feature flag buffer too short");
1059 bytes += DeserializeUInt64(bytes, f);
1060 bufSize -= sizeof(std::uint64_t);
1061 flags.emplace_back(f & ~0x8000000000000000);
1062 } while (f & 0x8000000000000000);
1063
1064 return (flags.size() * sizeof(std::uint64_t));
1065}
1066
1069{
1071 return R__FAIL("locator is not serializable");
1072
1073 std::uint32_t size = 0;
1074 if ((locator.GetType() == RNTupleLocator::kTypeFile) &&
1075 (locator.GetNBytesOnStorage() <= std::numeric_limits<std::int32_t>::max())) {
1076 size += SerializeUInt32(locator.GetNBytesOnStorage(), buffer);
1077 size += SerializeUInt64(locator.GetPosition<std::uint64_t>(),
1078 buffer ? reinterpret_cast<unsigned char *>(buffer) + size : nullptr);
1079 return size;
1080 }
1081
1082 std::uint8_t locatorType = 0;
1083 auto payloadp = buffer ? reinterpret_cast<unsigned char *>(buffer) + sizeof(std::int32_t) : nullptr;
1084 switch (locator.GetType()) {
1087 locatorType = 0x01;
1088 break;
1091 locatorType = 0x02;
1092 break;
1093 default:
1094 if (locator.GetType() == ROOT::Internal::kTestLocatorType) {
1095 // For the testing locator, use the same payload format as Object64. We won't read it back anyway.
1096 RNTupleLocator dummy;
1099 locatorType = 0x7e;
1100 } else {
1101 return R__FAIL("locator has unknown type");
1102 }
1103 }
1104 std::int32_t head = sizeof(std::int32_t) + size;
1105 head |= locator.GetReserved() << 16;
1106 head |= static_cast<int>(locatorType & 0x7F) << 24;
1107 head = -head;
1108 size += RNTupleSerializer::SerializeInt32(head, buffer);
1109 return size;
1110}
1111
1113 std::uint64_t bufSize,
1115{
1116 if (bufSize < sizeof(std::int32_t))
1117 return R__FAIL("too short locator");
1118
1119 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
1120 std::int32_t head;
1121
1122 bytes += DeserializeInt32(bytes, head);
1123 bufSize -= sizeof(std::int32_t);
1124 if (head < 0) {
1125 head = -head;
1126 const int type = head >> 24;
1127 const std::uint32_t payloadSize = (static_cast<std::uint32_t>(head) & 0x0000FFFF) - sizeof(std::int32_t);
1128 if (bufSize < payloadSize)
1129 return R__FAIL("too short locator");
1130
1131 locator.SetReserved(static_cast<std::uint32_t>(head >> 16) & 0xFF);
1132 switch (type) {
1133 case 0x01:
1136 break;
1137 case 0x02:
1140 break;
1141 default: locator.SetType(RNTupleLocator::kTypeUnknown);
1142 }
1143 bytes += payloadSize;
1144 } else {
1145 if (bufSize < sizeof(std::uint64_t))
1146 return R__FAIL("too short locator");
1147 std::uint64_t offset;
1148 bytes += DeserializeUInt64(bytes, offset);
1150 locator.SetNBytesOnStorage(head);
1151 locator.SetPosition(offset);
1152 }
1153
1154 return bytes - reinterpret_cast<const unsigned char *>(buffer);
1155}
1156
1159{
1160 auto size = SerializeUInt64(envelopeLink.fLength, buffer);
1161 auto res =
1162 SerializeLocator(envelopeLink.fLocator, buffer ? reinterpret_cast<unsigned char *>(buffer) + size : nullptr);
1163 if (res)
1164 size += res.Unwrap();
1165 else
1166 return R__FORWARD_ERROR(res);
1167 return size;
1168}
1169
1171 std::uint64_t bufSize,
1173{
1174 if (bufSize < sizeof(std::int64_t))
1175 return R__FAIL("too short envelope link");
1176
1177 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
1178 bytes += DeserializeUInt64(bytes, envelopeLink.fLength);
1179 bufSize -= sizeof(std::uint64_t);
1180 if (auto res = DeserializeLocator(bytes, bufSize, envelopeLink.fLocator)) {
1181 bytes += res.Unwrap();
1182 } else {
1183 return R__FORWARD_ERROR(res);
1184 }
1185 return bytes - reinterpret_cast<const unsigned char *>(buffer);
1186}
1187
1190{
1191 if (clusterSummary.fNEntries >= (static_cast<std::uint64_t>(1) << 56)) {
1192 return R__FAIL("number of entries in cluster exceeds maximum of 2^56");
1193 }
1194
1195 auto base = reinterpret_cast<unsigned char *>(buffer);
1196 auto pos = base;
1197 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
1198
1199 auto frame = pos;
1200 pos += SerializeRecordFramePreamble(*where);
1201 pos += SerializeUInt64(clusterSummary.fFirstEntry, *where);
1202 const std::uint64_t nEntriesAndFlags =
1203 (static_cast<std::uint64_t>(clusterSummary.fFlags) << 56) | clusterSummary.fNEntries;
1204 pos += SerializeUInt64(nEntriesAndFlags, *where);
1205
1206 auto size = pos - frame;
1207 if (auto res = SerializeFramePostscript(frame, size)) {
1208 pos += res.Unwrap();
1209 } else {
1210 return R__FORWARD_ERROR(res);
1211 }
1212 return size;
1213}
1214
1218{
1219 auto base = reinterpret_cast<const unsigned char *>(buffer);
1220 auto bytes = base;
1221 std::uint64_t frameSize;
1222 if (auto res = DeserializeFrameHeader(bytes, bufSize, frameSize)) {
1223 bytes += res.Unwrap();
1224 } else {
1225 return R__FORWARD_ERROR(res);
1226 }
1227
1228 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
1229 if (fnFrameSizeLeft() < 2 * sizeof(std::uint64_t))
1230 return R__FAIL("too short cluster summary");
1231
1232 bytes += DeserializeUInt64(bytes, clusterSummary.fFirstEntry);
1233 std::uint64_t nEntriesAndFlags;
1234 bytes += DeserializeUInt64(bytes, nEntriesAndFlags);
1235
1236 const std::uint64_t nEntries = (nEntriesAndFlags << 8) >> 8;
1237 const std::uint8_t flags = nEntriesAndFlags >> 56;
1238
1239 if (flags & 0x01) {
1240 return R__FAIL("sharded cluster flag set in cluster summary; sharded clusters are currently unsupported.");
1241 }
1242
1243 clusterSummary.fNEntries = nEntries;
1244 clusterSummary.fFlags = flags;
1245
1246 return frameSize;
1247}
1248
1251{
1252 auto base = reinterpret_cast<unsigned char *>(buffer);
1253 auto pos = base;
1254 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
1255
1256 auto frame = pos;
1257 pos += SerializeRecordFramePreamble(*where);
1258 pos += SerializeUInt64(clusterGroup.fMinEntry, *where);
1259 pos += SerializeUInt64(clusterGroup.fEntrySpan, *where);
1260 pos += SerializeUInt32(clusterGroup.fNClusters, *where);
1261 if (auto res = SerializeEnvelopeLink(clusterGroup.fPageListEnvelopeLink, *where)) {
1262 pos += res.Unwrap();
1263 } else {
1264 return R__FORWARD_ERROR(res);
1265 }
1266 auto size = pos - frame;
1267 if (auto res = SerializeFramePostscript(frame, size)) {
1268 return size;
1269 } else {
1270 return R__FORWARD_ERROR(res);
1271 }
1272}
1273
1275 std::uint64_t bufSize,
1277{
1278 auto base = reinterpret_cast<const unsigned char *>(buffer);
1279 auto bytes = base;
1280
1281 std::uint64_t frameSize;
1282 if (auto res = DeserializeFrameHeader(bytes, bufSize, frameSize)) {
1283 bytes += res.Unwrap();
1284 } else {
1285 return R__FORWARD_ERROR(res);
1286 }
1287
1288 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - base); };
1289 if (fnFrameSizeLeft() < sizeof(std::uint32_t) + 2 * sizeof(std::uint64_t))
1290 return R__FAIL("too short cluster group");
1291
1292 bytes += DeserializeUInt64(bytes, clusterGroup.fMinEntry);
1293 bytes += DeserializeUInt64(bytes, clusterGroup.fEntrySpan);
1294 bytes += DeserializeUInt32(bytes, clusterGroup.fNClusters);
1295 if (auto res = DeserializeEnvelopeLink(bytes, fnFrameSizeLeft(), clusterGroup.fPageListEnvelopeLink)) {
1296 bytes += res.Unwrap();
1297 } else {
1298 return R__FORWARD_ERROR(res);
1299 }
1300
1301 return frameSize;
1302}
1303
1305 bool forHeaderExtension)
1306{
1307 auto fieldZeroId = desc.GetFieldZeroId();
1308 auto depthFirstTraversal = [&](std::span<ROOT::DescriptorId_t> fieldTrees, auto doForEachField) {
1309 std::deque<ROOT::DescriptorId_t> idQueue{fieldTrees.begin(), fieldTrees.end()};
1310 while (!idQueue.empty()) {
1311 auto fieldId = idQueue.front();
1312 idQueue.pop_front();
1313 // Field zero has no physical representation nor columns of its own; recurse over its subfields only
1314 if (fieldId != fieldZeroId)
1316 unsigned i = 0;
1317 for (const auto &f : desc.GetFieldIterable(fieldId))
1318 idQueue.insert(idQueue.begin() + i++, f.GetId());
1319 }
1320 };
1321
1322 R__ASSERT(desc.GetNFields() > 0); // we must have at least a zero field
1323
1324 std::vector<ROOT::DescriptorId_t> fieldTrees;
1325 if (!forHeaderExtension) {
1326 fieldTrees.emplace_back(fieldZeroId);
1327 } else if (auto xHeader = desc.GetHeaderExtension()) {
1328 fieldTrees = xHeader->GetTopMostFields(desc);
1329 }
1332 for (const auto &c : desc.GetColumnIterable(fieldId)) {
1333 if (!c.IsAliasColumn()) {
1334 MapPhysicalColumnId(c.GetPhysicalId());
1335 }
1336 }
1337 });
1338
1339 if (forHeaderExtension) {
1340 // Create physical IDs for column representations that extend fields of the regular header.
1341 // First the physical columns then the alias columns.
1342 for (auto memId : desc.GetHeaderExtension()->GetExtendedColumnRepresentations()) {
1343 const auto &columnDesc = desc.GetColumnDescriptor(memId);
1344 if (!columnDesc.IsAliasColumn()) {
1345 MapPhysicalColumnId(columnDesc.GetPhysicalId());
1346 }
1347 }
1348 }
1349}
1350
1353 const RContext &context, bool forHeaderExtension)
1354{
1355 auto base = reinterpret_cast<unsigned char *>(buffer);
1356 auto pos = base;
1357 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
1358
1359 std::size_t nFields = 0, nColumns = 0, nAliasColumns = 0, fieldListOffset = 0;
1360 // Columns in the extension header that are attached to a field of the regular header
1361 std::vector<std::reference_wrapper<const ROOT::RColumnDescriptor>> extraColumns;
1362 if (forHeaderExtension) {
1363 // A call to `RNTupleDescriptorBuilder::BeginHeaderExtension()` is not strictly required after serializing the
1364 // header, which may happen, e.g., in unit tests. Ensure an empty schema extension is serialized in this case
1365 if (auto xHeader = desc.GetHeaderExtension()) {
1366 nFields = xHeader->GetNFields();
1367 nColumns = xHeader->GetNPhysicalColumns();
1368 nAliasColumns = xHeader->GetNLogicalColumns() - xHeader->GetNPhysicalColumns();
1369 fieldListOffset = desc.GetNFields() - nFields - 1;
1370
1371 extraColumns.reserve(xHeader->GetExtendedColumnRepresentations().size());
1372 for (auto columnId : xHeader->GetExtendedColumnRepresentations()) {
1373 extraColumns.emplace_back(desc.GetColumnDescriptor(columnId));
1374 }
1375 }
1376 } else {
1377 if (auto xHeader = desc.GetHeaderExtension()) {
1378 nFields = desc.GetNFields() - xHeader->GetNFields() - 1;
1379 nColumns = desc.GetNPhysicalColumns() - xHeader->GetNPhysicalColumns();
1381 (xHeader->GetNLogicalColumns() - xHeader->GetNPhysicalColumns());
1382 } else {
1383 nFields = desc.GetNFields() - 1;
1386 }
1387 }
1388 const auto nExtraTypeInfos = desc.GetNExtraTypeInfos();
1389 const auto &onDiskFields = context.GetOnDiskFieldList();
1391 std::span<const ROOT::DescriptorId_t> fieldList{onDiskFields.data() + fieldListOffset, nFields};
1392
1393 auto frame = pos;
1394 pos += SerializeListFramePreamble(nFields, *where);
1395 if (auto res = SerializeFieldList(desc, fieldList, /*firstOnDiskId=*/fieldListOffset, context, *where)) {
1396 pos += res.Unwrap();
1397 } else {
1398 return R__FORWARD_ERROR(res);
1399 }
1400 if (auto res = SerializeFramePostscript(buffer ? frame : nullptr, pos - frame)) {
1401 pos += res.Unwrap();
1402 } else {
1403 return R__FORWARD_ERROR(res);
1404 }
1405
1406 frame = pos;
1407 pos += SerializeListFramePreamble(nColumns, *where);
1408 if (auto res = SerializeColumnsOfFields(desc, fieldList, context, *where, forHeaderExtension)) {
1409 pos += res.Unwrap();
1410 } else {
1411 return R__FORWARD_ERROR(res);
1412 }
1413 for (const auto &c : extraColumns) {
1414 if (!c.get().IsAliasColumn()) {
1415 if (auto res = SerializePhysicalColumn(c.get(), context, *where)) {
1416 pos += res.Unwrap();
1417 } else {
1418 return R__FORWARD_ERROR(res);
1419 }
1420 }
1421 }
1422 if (auto res = SerializeFramePostscript(buffer ? frame : nullptr, pos - frame)) {
1423 pos += res.Unwrap();
1424 } else {
1425 return R__FORWARD_ERROR(res);
1426 }
1427
1428 frame = pos;
1429 pos += SerializeListFramePreamble(nAliasColumns, *where);
1431 for (const auto &c : extraColumns) {
1432 if (c.get().IsAliasColumn()) {
1433 pos += SerializeAliasColumn(c.get(), context, *where);
1434 }
1435 }
1436 if (auto res = SerializeFramePostscript(buffer ? frame : nullptr, pos - frame)) {
1437 pos += res.Unwrap();
1438 } else {
1439 return R__FORWARD_ERROR(res);
1440 }
1441
1442 frame = pos;
1443 // We only serialize the extra type info list in the header extension.
1444 if (forHeaderExtension) {
1445 pos += SerializeListFramePreamble(nExtraTypeInfos, *where);
1446 if (auto res = SerializeExtraTypeInfoList(desc, *where)) {
1447 pos += res.Unwrap();
1448 } else {
1449 return R__FORWARD_ERROR(res);
1450 }
1451 } else {
1452 pos += SerializeListFramePreamble(0, *where);
1453 }
1454 if (auto res = SerializeFramePostscript(buffer ? frame : nullptr, pos - frame)) {
1455 pos += res.Unwrap();
1456 } else {
1457 return R__FORWARD_ERROR(res);
1458 }
1459
1460 return static_cast<std::uint32_t>(pos - base);
1461}
1462
1466{
1467 auto base = reinterpret_cast<const unsigned char *>(buffer);
1468 auto bytes = base;
1469 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
1470
1471 std::uint64_t frameSize;
1472 auto frame = bytes;
1473 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - frame); };
1474
1475 std::uint32_t nFields;
1476 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nFields)) {
1477 bytes += res.Unwrap();
1478 } else {
1479 return R__FORWARD_ERROR(res);
1480 }
1481 // The zero field is always added before `DeserializeSchemaDescription()` is called
1482 const std::uint32_t fieldIdRangeBegin = descBuilder.GetDescriptor().GetNFields() - 1;
1483 for (unsigned i = 0; i < nFields; ++i) {
1484 std::uint32_t fieldId = fieldIdRangeBegin + i;
1486 if (auto res = DeserializeField(bytes, fnFrameSizeLeft(), fieldBuilder)) {
1487 bytes += res.Unwrap();
1488 } else {
1489 return R__FORWARD_ERROR(res);
1490 }
1491 if (fieldId == fieldBuilder.GetParentId())
1492 fieldBuilder.ParentId(kZeroFieldId);
1493 auto fieldDesc = fieldBuilder.FieldId(fieldId).MakeDescriptor();
1494 if (!fieldDesc)
1496 const auto parentId = fieldDesc.Inspect().GetParentId();
1497 const auto projectionSourceId = fieldDesc.Inspect().GetProjectionSourceId();
1498 descBuilder.AddField(fieldDesc.Unwrap());
1499 auto resVoid = descBuilder.AddFieldLink(parentId, fieldId);
1500 if (!resVoid)
1501 return R__FORWARD_ERROR(resVoid);
1503 resVoid = descBuilder.AddFieldProjection(projectionSourceId, fieldId);
1504 if (!resVoid)
1505 return R__FORWARD_ERROR(resVoid);
1506 }
1507 }
1508 bytes = frame + frameSize;
1509
1510 // As columns are added in order of representation index and column index, determine the column index
1511 // for the currently deserialized column from the columns already added.
1513 std::uint16_t representationIndex) -> std::uint32_t {
1514 const auto &existingColumns = descBuilder.GetDescriptor().GetFieldDescriptor(fieldId).GetLogicalColumnIds();
1515 if (existingColumns.empty())
1516 return 0;
1517 const auto &lastColumnDesc = descBuilder.GetDescriptor().GetColumnDescriptor(existingColumns.back());
1518 return (representationIndex == lastColumnDesc.GetRepresentationIndex()) ? (lastColumnDesc.GetIndex() + 1) : 0;
1519 };
1520
1521 std::uint32_t nColumns;
1522 frame = bytes;
1523 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nColumns)) {
1524 bytes += res.Unwrap();
1525 } else {
1526 return R__FORWARD_ERROR(res);
1527 }
1528
1529 if (descBuilder.GetDescriptor().GetNLogicalColumns() > descBuilder.GetDescriptor().GetNPhysicalColumns())
1530 descBuilder.ShiftAliasColumns(nColumns);
1531
1532 const std::uint32_t columnIdRangeBegin = descBuilder.GetDescriptor().GetNPhysicalColumns();
1533 for (unsigned i = 0; i < nColumns; ++i) {
1534 std::uint32_t columnId = columnIdRangeBegin + i;
1537 bytes += res.Unwrap();
1538 } else {
1539 return R__FORWARD_ERROR(res);
1540 }
1541
1542 columnBuilder.Index(fnNextColumnIndex(columnBuilder.GetFieldId(), columnBuilder.GetRepresentationIndex()));
1543 columnBuilder.LogicalColumnId(columnId);
1544 columnBuilder.PhysicalColumnId(columnId);
1545 auto columnDesc = columnBuilder.MakeDescriptor();
1546 if (!columnDesc)
1548 auto resVoid = descBuilder.AddColumn(columnDesc.Unwrap());
1549 if (!resVoid)
1550 return R__FORWARD_ERROR(resVoid);
1551 }
1552 bytes = frame + frameSize;
1553
1554 std::uint32_t nAliasColumns;
1555 frame = bytes;
1556 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nAliasColumns)) {
1557 bytes += res.Unwrap();
1558 } else {
1559 return R__FORWARD_ERROR(res);
1560 }
1561 const std::uint32_t aliasColumnIdRangeBegin = descBuilder.GetDescriptor().GetNLogicalColumns();
1562 for (unsigned i = 0; i < nAliasColumns; ++i) {
1563 std::uint32_t physicalId;
1564 std::uint32_t fieldId;
1566 bytes += res.Unwrap();
1567 } else {
1568 return R__FORWARD_ERROR(res);
1569 }
1570
1572 columnBuilder.LogicalColumnId(aliasColumnIdRangeBegin + i).PhysicalColumnId(physicalId).FieldId(fieldId);
1573 const auto &physicalColumnDesc = descBuilder.GetDescriptor().GetColumnDescriptor(physicalId);
1574 columnBuilder.BitsOnStorage(physicalColumnDesc.GetBitsOnStorage());
1575 columnBuilder.ValueRange(physicalColumnDesc.GetValueRange());
1576 columnBuilder.Type(physicalColumnDesc.GetType());
1577 columnBuilder.RepresentationIndex(physicalColumnDesc.GetRepresentationIndex());
1578 columnBuilder.Index(fnNextColumnIndex(columnBuilder.GetFieldId(), columnBuilder.GetRepresentationIndex()));
1579
1580 auto aliasColumnDesc = columnBuilder.MakeDescriptor();
1581 if (!aliasColumnDesc)
1583 auto resVoid = descBuilder.AddColumn(aliasColumnDesc.Unwrap());
1584 if (!resVoid)
1585 return R__FORWARD_ERROR(resVoid);
1586 }
1587 bytes = frame + frameSize;
1588
1589 std::uint32_t nExtraTypeInfos;
1590 frame = bytes;
1591 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nExtraTypeInfos)) {
1592 bytes += res.Unwrap();
1593 } else {
1594 return R__FORWARD_ERROR(res);
1595 }
1596 for (unsigned i = 0; i < nExtraTypeInfos; ++i) {
1599 bytes += res.Unwrap();
1600 } else {
1601 return R__FORWARD_ERROR(res);
1602 }
1603
1604 auto extraTypeInfoDesc = extraTypeInfoBuilder.MoveDescriptor();
1605 // We ignore unknown extra type information
1607 descBuilder.AddExtraTypeInfo(extraTypeInfoDesc.Unwrap());
1608 }
1609 bytes = frame + frameSize;
1610
1611 return bytes - base;
1612}
1613
1616{
1617 RContext context;
1618
1619 auto base = reinterpret_cast<unsigned char *>(buffer);
1620 auto pos = base;
1621 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
1622
1623 pos += SerializeEnvelopePreamble(kEnvelopeTypeHeader, *where);
1624 // So far we don't make use of feature flags
1625 if (auto res = SerializeFeatureFlags(desc.GetFeatureFlags(), *where)) {
1626 pos += res.Unwrap();
1627 } else {
1628 return R__FORWARD_ERROR(res);
1629 }
1630 pos += SerializeString(desc.GetName(), *where);
1631 pos += SerializeString(desc.GetDescription(), *where);
1632 pos += SerializeString(std::string("ROOT v") + ROOT_RELEASE, *where);
1633
1634 context.MapSchema(desc, /*forHeaderExtension=*/false);
1635
1636 if (auto res = SerializeSchemaDescription(*where, desc, context)) {
1637 pos += res.Unwrap();
1638 } else {
1639 return R__FORWARD_ERROR(res);
1640 }
1641
1642 std::uint64_t size = pos - base;
1643 std::uint64_t xxhash3 = 0;
1644 if (auto res = SerializeEnvelopePostscript(base, size, xxhash3)) {
1645 size += res.Unwrap();
1646 } else {
1647 return R__FORWARD_ERROR(res);
1648 }
1649
1650 context.SetHeaderSize(size);
1651 context.SetHeaderXxHash3(xxhash3);
1652 return context;
1653}
1654
1657 std::span<ROOT::DescriptorId_t> physClusterIDs,
1658 const RContext &context)
1659{
1660 auto base = reinterpret_cast<unsigned char *>(buffer);
1661 auto pos = base;
1662 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
1663
1664 pos += SerializeEnvelopePreamble(kEnvelopeTypePageList, *where);
1665
1666 pos += SerializeUInt64(context.GetHeaderXxHash3(), *where);
1667
1668 // Cluster summaries
1669 const auto nClusters = physClusterIDs.size();
1670 auto clusterSummaryFrame = pos;
1671 pos += SerializeListFramePreamble(nClusters, *where);
1672 for (auto clusterId : physClusterIDs) {
1673 const auto &clusterDesc = desc.GetClusterDescriptor(context.GetMemClusterId(clusterId));
1674 RClusterSummary summary{clusterDesc.GetFirstEntryIndex(), clusterDesc.GetNEntries(), 0};
1675 if (auto res = SerializeClusterSummary(summary, *where)) {
1676 pos += res.Unwrap();
1677 } else {
1678 return R__FORWARD_ERROR(res);
1679 }
1680 }
1681 if (auto res = SerializeFramePostscript(buffer ? clusterSummaryFrame : nullptr, pos - clusterSummaryFrame)) {
1682 pos += res.Unwrap();
1683 } else {
1684 return R__FORWARD_ERROR(res);
1685 }
1686
1687 // Page locations
1688 auto topMostFrame = pos;
1689 pos += SerializeListFramePreamble(nClusters, *where);
1690
1691 for (auto clusterId : physClusterIDs) {
1692 const auto &clusterDesc = desc.GetClusterDescriptor(context.GetMemClusterId(clusterId));
1693 // Get an ordered set of physical column ids
1694 std::set<ROOT::DescriptorId_t> onDiskColumnIds;
1695 for (const auto &columnRange : clusterDesc.GetColumnRangeIterable())
1696 onDiskColumnIds.insert(context.GetOnDiskColumnId(columnRange.GetPhysicalColumnId()));
1697
1698 auto outerFrame = pos;
1699 pos += SerializeListFramePreamble(onDiskColumnIds.size(), *where);
1700 for (auto onDiskId : onDiskColumnIds) {
1701 auto memId = context.GetMemColumnId(onDiskId);
1702 const auto &columnRange = clusterDesc.GetColumnRange(memId);
1703
1704 auto innerFrame = pos;
1705 if (columnRange.IsSuppressed()) {
1706 // Empty page range
1707 pos += SerializeListFramePreamble(0, *where);
1708 pos += SerializeInt64(kSuppressedColumnMarker, *where);
1709 } else {
1710 const auto &pageRange = clusterDesc.GetPageRange(memId);
1711 pos += SerializeListFramePreamble(pageRange.GetPageInfos().size(), *where);
1712
1713 for (const auto &pi : pageRange.GetPageInfos()) {
1714 std::int32_t nElements =
1715 pi.HasChecksum() ? -static_cast<std::int32_t>(pi.GetNElements()) : pi.GetNElements();
1716 pos += SerializeUInt32(nElements, *where);
1717 if (auto res = SerializeLocator(pi.GetLocator(), *where)) {
1718 pos += res.Unwrap();
1719 } else {
1720 return R__FORWARD_ERROR(res);
1721 }
1722 }
1723 pos += SerializeInt64(columnRange.GetFirstElementIndex(), *where);
1724 pos += SerializeUInt32(columnRange.GetCompressionSettings().value(), *where);
1725 }
1726
1727 if (auto res = SerializeFramePostscript(buffer ? innerFrame : nullptr, pos - innerFrame)) {
1728 pos += res.Unwrap();
1729 } else {
1730 return R__FORWARD_ERROR(res);
1731 }
1732 }
1733 if (auto res = SerializeFramePostscript(buffer ? outerFrame : nullptr, pos - outerFrame)) {
1734 pos += res.Unwrap();
1735 } else {
1736 return R__FORWARD_ERROR(res);
1737 }
1738 }
1739
1740 if (auto res = SerializeFramePostscript(buffer ? topMostFrame : nullptr, pos - topMostFrame)) {
1741 pos += res.Unwrap();
1742 } else {
1743 return R__FORWARD_ERROR(res);
1744 }
1745 std::uint64_t size = pos - base;
1746 if (auto res = SerializeEnvelopePostscript(base, size)) {
1747 size += res.Unwrap();
1748 } else {
1749 return R__FORWARD_ERROR(res);
1750 }
1751 return size;
1752}
1753
1755 const ROOT::RNTupleDescriptor &desc,
1756 const RContext &context)
1757{
1758 auto base = reinterpret_cast<unsigned char *>(buffer);
1759 auto pos = base;
1760 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
1761
1762 pos += SerializeEnvelopePreamble(kEnvelopeTypeFooter, *where);
1763
1764 // So far we don't make use of footer feature flags
1765 if (auto res = SerializeFeatureFlags(std::vector<std::uint64_t>(), *where)) {
1766 pos += res.Unwrap();
1767 } else {
1768 return R__FORWARD_ERROR(res);
1769 }
1770 pos += SerializeUInt64(context.GetHeaderXxHash3(), *where);
1771
1772 // Schema extension, i.e. incremental changes with respect to the header
1773 auto frame = pos;
1774 pos += SerializeRecordFramePreamble(*where);
1775 if (auto res = SerializeSchemaDescription(*where, desc, context, /*forHeaderExtension=*/true)) {
1776 pos += res.Unwrap();
1777 } else {
1778 return R__FORWARD_ERROR(res);
1779 }
1780 if (auto res = SerializeFramePostscript(buffer ? frame : nullptr, pos - frame)) {
1781 pos += res.Unwrap();
1782 } else {
1783 return R__FORWARD_ERROR(res);
1784 }
1785
1786 // Cluster groups
1787 frame = pos;
1788 const auto nClusterGroups = desc.GetNClusterGroups();
1789 pos += SerializeListFramePreamble(nClusterGroups, *where);
1790 for (unsigned int i = 0; i < nClusterGroups; ++i) {
1791 const auto &cgDesc = desc.GetClusterGroupDescriptor(context.GetMemClusterGroupId(i));
1793 clusterGroup.fMinEntry = cgDesc.GetMinEntry();
1794 clusterGroup.fEntrySpan = cgDesc.GetEntrySpan();
1795 clusterGroup.fNClusters = cgDesc.GetNClusters();
1796 clusterGroup.fPageListEnvelopeLink.fLength = cgDesc.GetPageListLength();
1797 clusterGroup.fPageListEnvelopeLink.fLocator = cgDesc.GetPageListLocator();
1798 if (auto res = SerializeClusterGroup(clusterGroup, *where)) {
1799 pos += res.Unwrap();
1800 } else {
1801 return R__FORWARD_ERROR(res);
1802 }
1803 }
1804 if (auto res = SerializeFramePostscript(buffer ? frame : nullptr, pos - frame)) {
1805 pos += res.Unwrap();
1806 } else {
1807 return R__FORWARD_ERROR(res);
1808 }
1809
1810 // Attributes
1811 frame = pos;
1812 const auto nAttributeSets = desc.GetNAttributeSets();
1813 if (nAttributeSets > 0) {
1814 R__LOG_WARNING(NTupleLog()) << "RNTuple Attributes are experimental. They are not guaranteed to be readable "
1815 "back in the future (but your main data is)";
1816 }
1817 pos += SerializeListFramePreamble(nAttributeSets, *where);
1818 for (const auto &attrSet : desc.GetAttrSetIterable()) {
1819 if (auto res = SerializeAttributeSet(attrSet, *where)) {
1820 pos += res.Unwrap();
1821 } else {
1822 return R__FORWARD_ERROR(res);
1823 }
1824 }
1825 if (auto res = SerializeFramePostscript(buffer ? frame : nullptr, pos - frame)) {
1826 pos += res.Unwrap();
1827 } else {
1828 return R__FORWARD_ERROR(res);
1829 }
1830
1831 std::uint32_t size = pos - base;
1832 if (auto res = SerializeEnvelopePostscript(base, size)) {
1833 size += res.Unwrap();
1834 } else {
1835 return R__FORWARD_ERROR(res);
1836 }
1837 return size;
1838}
1839
1842 void *buffer)
1843{
1844 auto base = reinterpret_cast<unsigned char *>(buffer);
1845 auto pos = base;
1846 void **where = (buffer == nullptr) ? &buffer : reinterpret_cast<void **>(&pos);
1847
1848 auto frame = pos;
1850 pos += SerializeUInt16(attrDesc.GetSchemaVersionMajor(), *where);
1851 pos += SerializeUInt16(attrDesc.GetSchemaVersionMinor(), *where);
1852 pos += SerializeUInt32(attrDesc.GetAnchorLength(), *where);
1853 if (auto res = SerializeLocator(attrDesc.GetAnchorLocator(), *where)) {
1854 pos += res.Unwrap();
1855 } else {
1856 return R__FORWARD_ERROR(res);
1857 }
1858 pos += SerializeString(attrDesc.GetName(), *where);
1859 auto size = pos - frame;
1860 if (auto res = SerializeFramePostscript(buffer ? frame : nullptr, size)) {
1861 return size;
1862 } else {
1863 return R__FORWARD_ERROR(res);
1864 }
1865}
1866
1869{
1870 auto base = reinterpret_cast<const unsigned char *>(buffer);
1871 auto bytes = base;
1872 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
1873
1874 std::uint64_t xxhash3{0};
1875 if (auto res = DeserializeEnvelope(bytes, fnBufSizeLeft(), kEnvelopeTypeHeader, xxhash3)) {
1876 bytes += res.Unwrap();
1877 } else {
1878 return R__FORWARD_ERROR(res);
1879 }
1880 descBuilder.SetOnDiskHeaderXxHash3(xxhash3);
1881
1882 std::vector<std::uint64_t> featureFlags;
1883 if (auto res = DeserializeFeatureFlags(bytes, fnBufSizeLeft(), featureFlags)) {
1884 bytes += res.Unwrap();
1885 } else {
1886 return R__FORWARD_ERROR(res);
1887 }
1888 for (std::size_t i = 0; i < featureFlags.size(); ++i) {
1889 if (!featureFlags[i])
1890 continue;
1891 unsigned int bit = 0;
1892 while (!(featureFlags[i] & (static_cast<uint64_t>(1) << bit)))
1893 bit++;
1894 return R__FAIL("unsupported format feature: " + std::to_string(i * 64 + bit));
1895 }
1896
1897 std::string name;
1898 std::string description;
1899 std::string writer;
1900 if (auto res = DeserializeString(bytes, fnBufSizeLeft(), name)) {
1901 bytes += res.Unwrap();
1902 } else {
1903 return R__FORWARD_ERROR(res);
1904 }
1905 if (auto res = DeserializeString(bytes, fnBufSizeLeft(), description)) {
1906 bytes += res.Unwrap();
1907 } else {
1908 return R__FORWARD_ERROR(res);
1909 }
1910 if (auto res = DeserializeString(bytes, fnBufSizeLeft(), writer)) {
1911 bytes += res.Unwrap();
1912 } else {
1913 return R__FORWARD_ERROR(res);
1914 }
1915 descBuilder.SetNTuple(name, description);
1916
1917 // Zero field
1919 .FieldId(kZeroFieldId)
1921 .MakeDescriptor()
1922 .Unwrap());
1923 if (auto res = DeserializeSchemaDescription(bytes, fnBufSizeLeft(), descBuilder)) {
1924 return RResult<void>::Success();
1925 } else {
1926 return R__FORWARD_ERROR(res);
1927 }
1928}
1929
1932{
1933 auto base = reinterpret_cast<const unsigned char *>(buffer);
1934 auto bytes = base;
1935 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
1936 if (auto res = DeserializeEnvelope(bytes, fnBufSizeLeft(), kEnvelopeTypeFooter)) {
1937 bytes += res.Unwrap();
1938 } else {
1939 return R__FORWARD_ERROR(res);
1940 }
1941
1942 std::vector<std::uint64_t> featureFlags;
1943 if (auto res = DeserializeFeatureFlags(bytes, fnBufSizeLeft(), featureFlags)) {
1944 bytes += res.Unwrap();
1945 } else {
1946 return R__FORWARD_ERROR(res);
1947 }
1948 for (auto f : featureFlags) {
1949 if (f)
1950 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "Unsupported feature flag! " << f;
1951 }
1952
1953 std::uint64_t xxhash3{0};
1954 if (fnBufSizeLeft() < static_cast<int>(sizeof(std::uint64_t)))
1955 return R__FAIL("footer too short");
1956 bytes += DeserializeUInt64(bytes, xxhash3);
1957 if (xxhash3 != descBuilder.GetDescriptor().GetOnDiskHeaderXxHash3())
1958 return R__FAIL("XxHash-3 mismatch between header and footer");
1959
1960 std::uint64_t frameSize;
1961 auto frame = bytes;
1962 auto fnFrameSizeLeft = [&]() { return frameSize - (bytes - frame); };
1963
1964 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize)) {
1965 bytes += res.Unwrap();
1966 } else {
1967 return R__FORWARD_ERROR(res);
1968 }
1969 if (fnFrameSizeLeft() > 0) {
1970 descBuilder.BeginHeaderExtension();
1971 if (auto res = DeserializeSchemaDescription(bytes, fnFrameSizeLeft(), descBuilder); !res) {
1972 return R__FORWARD_ERROR(res);
1973 }
1974 }
1975 bytes = frame + frameSize;
1976
1977 {
1978 std::uint32_t nClusterGroups;
1979 frame = bytes;
1980 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nClusterGroups)) {
1981 bytes += res.Unwrap();
1982 } else {
1983 return R__FORWARD_ERROR(res);
1984 }
1985 for (std::uint32_t groupId = 0; groupId < nClusterGroups; ++groupId) {
1987 if (auto res = DeserializeClusterGroup(bytes, fnFrameSizeLeft(), clusterGroup)) {
1988 bytes += res.Unwrap();
1989 } else {
1990 return R__FORWARD_ERROR(res);
1991 }
1992
1993 descBuilder.AddToOnDiskFooterSize(clusterGroup.fPageListEnvelopeLink.fLocator.GetNBytesOnStorage());
1995 clusterGroupBuilder.ClusterGroupId(groupId)
1996 .PageListLocator(clusterGroup.fPageListEnvelopeLink.fLocator)
1997 .PageListLength(clusterGroup.fPageListEnvelopeLink.fLength)
1998 .MinEntry(clusterGroup.fMinEntry)
1999 .EntrySpan(clusterGroup.fEntrySpan)
2000 .NClusters(clusterGroup.fNClusters);
2001 descBuilder.AddClusterGroup(clusterGroupBuilder.MoveDescriptor().Unwrap());
2002 }
2003 bytes = frame + frameSize;
2004 }
2005
2006 // NOTE: Attributes were introduced in v1.0.1.0, so this section may be missing.
2007 // Testing for > 8 because bufSize includes the checksum.
2008 if (fnBufSizeLeft() > 8) {
2009 std::uint32_t nAttributeSets;
2010 frame = bytes;
2011 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize, nAttributeSets)) {
2012 bytes += res.Unwrap();
2013 } else {
2014 return R__FORWARD_ERROR(res);
2015 }
2016 if (nAttributeSets > 0) {
2017 R__LOG_WARNING(NTupleLog()) << "RNTuple Attributes are experimental. They are not guaranteed to be readable "
2018 "back in the future (but your main data is)";
2019 }
2020 for (std::uint32_t attrSetId = 0; attrSetId < nAttributeSets; ++attrSetId) {
2022 if (auto res = DeserializeAttributeSet(bytes, fnBufSizeLeft(), attrSetDescBld)) {
2023 descBuilder.AddAttributeSet(attrSetDescBld.MoveDescriptor().Unwrap());
2024 bytes += res.Unwrap();
2025 } else {
2026 return R__FORWARD_ERROR(res);
2027 }
2028 }
2029 bytes = frame + frameSize;
2030 }
2031
2032 return RResult<void>::Success();
2033}
2034
2037{
2038 auto base = reinterpret_cast<const unsigned char *>(buffer);
2039 auto bytes = base;
2040 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
2041
2042 std::uint64_t frameSize;
2043 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), frameSize)) {
2044 bytes += res.Unwrap();
2045 } else {
2046 return R__FORWARD_ERROR(res);
2047 }
2048 if (fnBufSizeLeft() < static_cast<int>(sizeof(std::uint64_t)))
2049 return R__FAIL("record frame too short");
2050 std::uint16_t vMajor, vMinor;
2051 bytes += DeserializeUInt16(bytes, vMajor);
2052 bytes += DeserializeUInt16(bytes, vMinor);
2053 std::uint32_t anchorLen;
2054 bytes += DeserializeUInt32(bytes, anchorLen);
2056 if (auto res = DeserializeLocator(bytes, fnBufSizeLeft(), anchorLoc)) {
2057 bytes += res.Unwrap();
2058 } else {
2059 return R__FORWARD_ERROR(res);
2060 }
2061 std::string name;
2062 if (auto res = DeserializeString(bytes, fnBufSizeLeft(), name)) {
2063 bytes += res.Unwrap();
2064 } else {
2065 return R__FORWARD_ERROR(res);
2066 }
2067
2068 attrSetDescBld.SchemaVersion(vMajor, vMinor).AnchorLength(anchorLen).AnchorLocator(anchorLoc).Name(name);
2069
2070 return frameSize;
2071}
2072
2076 const ROOT::RNTupleDescriptor &desc)
2077{
2078 auto base = reinterpret_cast<const unsigned char *>(buffer);
2079 auto bytes = base;
2080 auto fnBufSizeLeft = [&]() { return bufSize - (bytes - base); };
2081
2082 if (auto res = DeserializeEnvelope(bytes, fnBufSizeLeft(), kEnvelopeTypePageList)) {
2083 bytes += res.Unwrap();
2084 } else {
2085 return R__FORWARD_ERROR(res);
2086 }
2087
2088 std::uint64_t xxhash3{0};
2089 if (fnBufSizeLeft() < static_cast<int>(sizeof(std::uint64_t)))
2090 return R__FAIL("page list too short");
2091 bytes += DeserializeUInt64(bytes, xxhash3);
2092 if (xxhash3 != desc.GetOnDiskHeaderXxHash3())
2093 return R__FAIL("XxHash-3 mismatch between header and page list");
2094
2095 std::vector<RClusterDescriptorBuilder> clusterBuilders;
2097 for (ROOT::DescriptorId_t i = 0; i < clusterGroupId; ++i) {
2098 firstClusterId = firstClusterId + desc.GetClusterGroupDescriptor(i).GetNClusters();
2099 }
2100
2101 std::uint64_t clusterSummaryFrameSize;
2104
2105 std::uint32_t nClusterSummaries;
2106 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), clusterSummaryFrameSize, nClusterSummaries)) {
2107 bytes += res.Unwrap();
2108 } else {
2109 return R__FORWARD_ERROR(res);
2110 }
2113 if (auto res = DeserializeClusterSummary(bytes, fnClusterSummaryFrameSizeLeft(), clusterSummary)) {
2114 bytes += res.Unwrap();
2115 } else {
2116 return R__FORWARD_ERROR(res);
2117 }
2118
2121 clusterBuilders.emplace_back(std::move(builder));
2122 }
2124
2125 std::uint64_t topMostFrameSize;
2126 auto topMostFrame = bytes;
2127 auto fnTopMostFrameSizeLeft = [&]() { return topMostFrameSize - (bytes - topMostFrame); };
2128
2129 std::uint32_t nClusters;
2130 if (auto res = DeserializeFrameHeader(bytes, fnBufSizeLeft(), topMostFrameSize, nClusters)) {
2131 bytes += res.Unwrap();
2132 } else {
2133 return R__FORWARD_ERROR(res);
2134 }
2135
2137 return R__FAIL("mismatch between number of clusters and number of cluster summaries");
2138
2139 for (std::uint32_t i = 0; i < nClusters; ++i) {
2140 std::uint64_t outerFrameSize;
2141 auto outerFrame = bytes;
2142 auto fnOuterFrameSizeLeft = [&]() { return outerFrameSize - (bytes - outerFrame); };
2143
2144 std::uint32_t nColumns;
2145 if (auto res = DeserializeFrameHeader(bytes, fnTopMostFrameSizeLeft(), outerFrameSize, nColumns)) {
2146 bytes += res.Unwrap();
2147 } else {
2148 return R__FORWARD_ERROR(res);
2149 }
2150
2151 for (std::uint32_t j = 0; j < nColumns; ++j) {
2152 std::uint64_t innerFrameSize;
2153 auto innerFrame = bytes;
2154 auto fnInnerFrameSizeLeft = [&]() { return innerFrameSize - (bytes - innerFrame); };
2155
2156 std::uint32_t nPages;
2157 if (auto res = DeserializeFrameHeader(bytes, fnOuterFrameSizeLeft(), innerFrameSize, nPages)) {
2158 bytes += res.Unwrap();
2159 } else {
2160 return R__FORWARD_ERROR(res);
2161 }
2162
2164 pageRange.SetPhysicalColumnId(j);
2165 for (std::uint32_t k = 0; k < nPages; ++k) {
2166 if (fnInnerFrameSizeLeft() < static_cast<int>(sizeof(std::uint32_t)))
2167 return R__FAIL("inner frame too short");
2168 std::int32_t nElements;
2169 bool hasChecksum = false;
2171 bytes += DeserializeInt32(bytes, nElements);
2172 if (nElements < 0) {
2174 hasChecksum = true;
2175 }
2176 if (auto res = DeserializeLocator(bytes, fnInnerFrameSizeLeft(), locator)) {
2177 bytes += res.Unwrap();
2178 } else {
2179 return R__FORWARD_ERROR(res);
2180 }
2181 pageRange.GetPageInfos().push_back({static_cast<std::uint32_t>(nElements), locator, hasChecksum});
2182 }
2183
2184 if (fnInnerFrameSizeLeft() < static_cast<int>(sizeof(std::int64_t)))
2185 return R__FAIL("page list frame too short");
2186 std::int64_t columnOffset;
2187 bytes += DeserializeInt64(bytes, columnOffset);
2188 if (columnOffset < 0) {
2189 if (nPages > 0)
2190 return R__FAIL("unexpected non-empty page list");
2191 clusterBuilders[i].MarkSuppressedColumnRange(j);
2192 } else {
2193 if (fnInnerFrameSizeLeft() < static_cast<int>(sizeof(std::uint32_t)))
2194 return R__FAIL("page list frame too short");
2195 std::uint32_t compressionSettings;
2196 bytes += DeserializeUInt32(bytes, compressionSettings);
2198 }
2199
2201 } // loop over columns
2202
2204 } // loop over clusters
2205
2206 return clusterBuilders;
2207}
2208
2213{
2215 if (!clusterBuildersRes)
2217
2218 auto clusterBuilders = clusterBuildersRes.Unwrap();
2219
2220 std::vector<ROOT::RClusterDescriptor> clusters;
2221 clusters.reserve(clusterBuilders.size());
2222
2223 // Conditionally fixup the clusters depending on the attach purpose
2224 switch (mode) {
2225 case EDescriptorDeserializeMode::kForReading:
2226 for (auto &builder : clusterBuilders) {
2227 if (auto res = builder.CommitSuppressedColumnRanges(desc); !res)
2228 return R__FORWARD_RESULT(res);
2229 builder.AddExtendedColumnRanges(desc);
2230 clusters.emplace_back(builder.MoveDescriptor().Unwrap());
2231 }
2232 break;
2233 case EDescriptorDeserializeMode::kForWriting:
2234 for (auto &builder : clusterBuilders) {
2235 if (auto res = builder.CommitSuppressedColumnRanges(desc); !res)
2236 return R__FORWARD_RESULT(res);
2237 clusters.emplace_back(builder.MoveDescriptor().Unwrap());
2238 }
2239 break;
2240 case EDescriptorDeserializeMode::kRaw:
2241 for (auto &builder : clusterBuilders)
2242 clusters.emplace_back(builder.MoveDescriptor().Unwrap());
2243 break;
2244 }
2245
2247
2248 return RResult<void>::Success();
2249}
2250
2252{
2254 for (auto si : infos) {
2255 assert(si.first == si.second->GetNumber());
2256 streamerInfos.Add(si.second);
2257 }
2259 buffer.WriteObject(&streamerInfos);
2260 assert(buffer.Length() > 0);
2261 return std::string{buffer.Buffer(), static_cast<UInt_t>(buffer.Length())};
2262}
2263
2266{
2268
2269 TBufferFile buffer(TBuffer::kRead, extraTypeInfoContent.length(), const_cast<char *>(extraTypeInfoContent.data()),
2270 false /* adopt */);
2271 auto infoList = reinterpret_cast<TList *>(buffer.ReadObject(TList::Class()));
2272
2273 TObjLink *lnk = infoList->FirstLink();
2274 while (lnk) {
2275 auto info = reinterpret_cast<TStreamerInfo *>(lnk->GetObject());
2276 info->BuildCheck();
2277 infoMap[info->GetNumber()] = info->GetClass()->GetStreamerInfo(info->GetClassVersion());
2278 assert(info->GetNumber() == infoMap[info->GetNumber()]->GetNumber());
2279 lnk = lnk->Next();
2280 }
2281
2282 delete infoList;
2283
2284 return infoMap;
2285}
#define R__FORWARD_ERROR(res)
Short-hand to return an RResult<T> in an error state (i.e. after checking)
Definition RError.hxx:304
#define R__FORWARD_RESULT(res)
Short-hand to return an RResult<T> value from a subroutine to the calling stack frame.
Definition RError.hxx:302
#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:300
#define R__LOG_WARNING(...)
Definition RLogger.hxx:358
#define R__LOG_DEBUG(DEBUGLEVEL,...)
Definition RLogger.hxx:360
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define ROOT_RELEASE
Definition RVersion.hxx:44
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
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 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 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 mode
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:157
The available trivial, native content types of a column.
Metadata stored for every Attribute Set linked to an RNTuple.
A helper class for piece-wise construction of an RClusterDescriptor.
RClusterDescriptorBuilder & NEntries(std::uint64_t nEntries)
RClusterDescriptorBuilder & ClusterId(ROOT::DescriptorId_t clusterId)
RClusterDescriptorBuilder & FirstEntryIndex(std::uint64_t firstEntryIndex)
A helper class for piece-wise construction of an RClusterGroupDescriptor.
A helper class for piece-wise construction of an RColumnDescriptor.
A helper class for piece-wise construction of an RExtraTypeInfoDescriptor.
RExtraTypeInfoDescriptorBuilder & ContentId(EExtraTypeInfoIds contentId)
RExtraTypeInfoDescriptorBuilder & TypeName(const std::string &typeName)
RExtraTypeInfoDescriptorBuilder & Content(const std::string &content)
RExtraTypeInfoDescriptorBuilder & TypeVersion(std::uint32_t typeVersion)
A helper class for piece-wise construction of an RFieldDescriptor.
A helper class for piece-wise construction of an RNTupleDescriptor.
The serialization context is used for the piecewise serialization of a descriptor.
ROOT::DescriptorId_t GetOnDiskFieldId(ROOT::DescriptorId_t memId) const
ROOT::DescriptorId_t GetMemColumnId(ROOT::DescriptorId_t onDiskId) const
ROOT::DescriptorId_t GetMemClusterGroupId(ROOT::DescriptorId_t onDiskId) const
ROOT::DescriptorId_t GetOnDiskColumnId(ROOT::DescriptorId_t memId) const
void MapSchema(const RNTupleDescriptor &desc, bool forHeaderExtension)
Map in-memory field and column IDs to their on-disk counterparts.
ROOT::DescriptorId_t GetMemClusterId(ROOT::DescriptorId_t onDiskId) const
const std::vector< ROOT::DescriptorId_t > & GetOnDiskFieldList() const
Return a vector containing the in-memory field ID for each on-disk counterpart, in order,...
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::vector< ROOT::Internal::RClusterDescriptorBuilder > > DeserializePageListRaw(const void *buffer, std::uint64_t bufSize, ROOT::DescriptorId_t clusterGroupId, const RNTupleDescriptor &desc)
static RResult< 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 > DeserializeString(const void *buffer, std::uint64_t bufSize, std::string &val)
static RResult< std::uint32_t > SerializeEnvelopeLink(const REnvelopeLink &envelopeLink, void *buffer)
static std::uint32_t SerializeInt32(std::int32_t val, void *buffer)
static RResult< std::uint32_t > DeserializeEnvelopeLink(const void *buffer, std::uint64_t bufSize, REnvelopeLink &envelopeLink)
static std::uint32_t SerializeUInt32(std::uint32_t val, void *buffer)
static RResult< std::uint32_t > SerializeAttributeSet(const Experimental::RNTupleAttrSetDescriptor &attrSetDesc, void *buffer)
static RResult< std::uint32_t > SerializeFieldStructure(ROOT::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 > SerializeEnvelopePostscript(unsigned char *envelope, std::uint64_t size)
static RResult< std::uint32_t > SerializeFeatureFlags(const std::vector< std::uint64_t > &flags, void *buffer)
static std::uint32_t DeserializeUInt32(const void *buffer, std::uint32_t &val)
static RResult< std::uint32_t > DeserializeFrameHeader(const void *buffer, std::uint64_t bufSize, std::uint64_t &frameSize, std::uint32_t &nitems)
static RResult< std::uint32_t > DeserializeAttributeSet(const void *buffer, std::uint64_t bufSize, Experimental::Internal::RNTupleAttrSetDescriptorBuilder &attrSetDescBld)
static RResult< std::uint32_t > DeserializeEnvelope(const void *buffer, std::uint64_t bufSize, std::uint16_t expectedType)
static RResult< std::uint32_t > SerializeColumnType(ROOT::ENTupleColumnType type, void *buffer)
static std::uint32_t SerializeListFramePreamble(std::uint32_t nitems, void *buffer)
static std::uint32_t SerializeInt16(std::int16_t val, void *buffer)
static RResult< std::uint32_t > SerializeFramePostscript(void *frame, std::uint64_t size)
static RResult< std::uint32_t > DeserializeClusterGroup(const void *buffer, std::uint64_t bufSize, RClusterGroup &clusterGroup)
static RResult< std::uint32_t > DeserializeLocator(const void *buffer, std::uint64_t bufSize, RNTupleLocator &locator)
static std::uint32_t SerializeUInt16(std::uint16_t val, void *buffer)
static RResult< void > DeserializePageList(const void *buffer, std::uint64_t bufSize, ROOT::DescriptorId_t clusterGroupId, RNTupleDescriptor &desc, EDescriptorDeserializeMode mode)
static RResult< void > DeserializeFooter(const void *buffer, std::uint64_t bufSize, ROOT::Internal::RNTupleDescriptorBuilder &descBuilder)
static std::uint32_t DeserializeInt64(const void *buffer, std::int64_t &val)
static std::uint32_t SerializeEnvelopePreamble(std::uint16_t envelopeType, void *buffer)
static std::uint32_t DeserializeInt32(const void *buffer, std::int32_t &val)
static std::uint32_t SerializeString(const std::string &val, void *buffer)
std::map< Int_t, TVirtualStreamerInfo * > StreamerInfoMap_t
static RResult< std::uint32_t > SerializeExtraTypeInfoId(ROOT::EExtraTypeInfoIds id, void *buffer)
static RResult< StreamerInfoMap_t > DeserializeStreamerInfos(const std::string &extraTypeInfoContent)
static std::uint32_t DeserializeUInt16(const void *buffer, std::uint16_t &val)
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::uint32_t > SerializeClusterSummary(const RClusterSummary &clusterSummary, void *buffer)
static RResult< std::uint32_t > DeserializeColumnType(const void *buffer, ROOT::ENTupleColumnType &type)
static std::uint32_t DeserializeInt16(const void *buffer, std::int16_t &val)
static RResult< std::uint32_t > DeserializeExtraTypeInfoId(const void *buffer, ROOT::EExtraTypeInfoIds &id)
static RResult< std::uint32_t > DeserializeClusterSummary(const void *buffer, std::uint64_t bufSize, RClusterSummary &clusterSummary)
static RResult< std::uint32_t > SerializeClusterGroup(const RClusterGroup &clusterGroup, void *buffer)
static std::uint32_t SerializeRecordFramePreamble(void *buffer)
static RResult< std::uint32_t > SerializePageList(void *buffer, const RNTupleDescriptor &desc, std::span< ROOT::DescriptorId_t > physClusterIDs, const RContext &context)
static RResult< std::uint32_t > DeserializeFieldStructure(const void *buffer, ROOT::ENTupleStructure &structure)
static std::uint32_t SerializeInt64(std::int64_t val, void *buffer)
static RResult< void > DeserializeHeader(const void *buffer, std::uint64_t bufSize, ROOT::Internal::RNTupleDescriptorBuilder &descBuilder)
static RResult< std::uint32_t > SerializeFooter(void *buffer, const RNTupleDescriptor &desc, const RContext &context)
static std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t &val)
static RResult< std::uint32_t > SerializeLocator(const RNTupleLocator &locator, void *buffer)
static RResult< std::uint32_t > DeserializeSchemaDescription(const void *buffer, std::uint64_t bufSize, ROOT::Internal::RNTupleDescriptorBuilder &descBuilder)
static std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer)
static RResult< std::uint32_t > DeserializeFeatureFlags(const void *buffer, std::uint64_t bufSize, std::vector< std::uint64_t > &flags)
static RResult< RContext > SerializeHeader(void *buffer, const RNTupleDescriptor &desc)
static std::string SerializeStreamerInfos(const StreamerInfoMap_t &infos)
Records the partition of data into pages for a particular column in a particular cluster.
Metadata stored for every column of an RNTuple.
Field specific extra type information from the header / extenstion header.
const std::string & GetContent() const
const std::string & GetTypeName() const
EExtraTypeInfoIds GetContentId() const
Metadata stored for every field of an RNTuple.
The on-storage metadata of an RNTuple.
const RClusterGroupDescriptor & GetClusterGroupDescriptor(ROOT::DescriptorId_t clusterGroupId) const
const RColumnDescriptor & GetColumnDescriptor(ROOT::DescriptorId_t columnId) const
RFieldDescriptorIterable GetFieldIterable(const RFieldDescriptor &fieldDesc) const
const RFieldDescriptor & GetFieldDescriptor(ROOT::DescriptorId_t fieldId) const
std::size_t GetNExtraTypeInfos() const
RColumnDescriptorIterable GetColumnIterable() const
const std::string & GetName() const
std::vector< std::uint64_t > GetFeatureFlags() const
ROOT::DescriptorId_t GetFieldZeroId() const
Returns the logical parent of all top-level RNTuple data fields.
std::size_t GetNAttributeSets() const
std::size_t GetNPhysicalColumns() const
const RHeaderExtension * GetHeaderExtension() const
Return header extension information; if the descriptor does not have a header extension,...
const RClusterDescriptor & GetClusterDescriptor(ROOT::DescriptorId_t clusterId) const
std::uint64_t GetOnDiskHeaderXxHash3() const
std::size_t GetNFields() const
RResult< void > AddClusterGroupDetails(ROOT::DescriptorId_t clusterGroupId, std::vector< RClusterDescriptor > &clusterDescs)
Methods to load and drop cluster group details (cluster IDs and page locations)
ROOT::Experimental::RNTupleAttrSetDescriptorIterable GetAttrSetIterable() const
std::size_t GetNLogicalColumns() const
std::size_t GetNClusterGroups() const
const std::string & GetDescription() const
RNTupleLocator payload that is common for object stores using 64bit location information.
Generic information about the physical location of data.
void SetType(ELocatorType type)
const_iterator begin() const
const_iterator end() 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:198
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition TBufferFile.h:47
TObject * ReadObject(const TClass *cl) override
Read object from I/O buffer.
void WriteObject(const TObject *obj, Bool_t cacheReuse=kTRUE) override
Write object to I/O buffer.
@ kWrite
Definition TBuffer.h:73
@ kRead
Definition TBuffer.h:73
Int_t Length() const
Definition TBuffer.h:100
char * Buffer() const
Definition TBuffer.h:96
A doubly linked list.
Definition TList.h:38
static TClass * Class()
Describes a persistent version of a class.
constexpr ROOT::ENTupleStructure kTestFutureFieldStructure
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
constexpr ENTupleColumnType kTestFutureColumnType
constexpr RNTupleLocator::ELocatorType kTestLocatorType
EExtraTypeInfoIds
Used in RExtraTypeInfoDescriptor.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr DescriptorId_t kInvalidDescriptorId
ENTupleStructure
The fields in the RNTuple data model tree can carry different structural information about the type s...
ENTupleColumnType