53std::uint32_t SerializeInt64(std::int64_t val,
void *buffer)
55 if (buffer !=
nullptr) {
56 auto bytes =
reinterpret_cast<unsigned char *
>(buffer);
57 bytes[0] = (val & 0x00000000000000FF);
58 bytes[1] = (val & 0x000000000000FF00) >> 8;
59 bytes[2] = (val & 0x0000000000FF0000) >> 16;
60 bytes[3] = (val & 0x00000000FF000000) >> 24;
61 bytes[4] = (val & 0x000000FF00000000) >> 32;
62 bytes[5] = (val & 0x0000FF0000000000) >> 40;
63 bytes[6] = (val & 0x00FF000000000000) >> 48;
64 bytes[7] = (val & 0xFF00000000000000) >> 56;
69std::uint32_t SerializeUInt64(std::uint64_t val,
void *buffer)
71 return SerializeInt64(val, buffer);
74std::uint32_t DeserializeInt64(
const void *buffer, std::int64_t *val)
76 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
77 *val = std::int64_t(bytes[0]) + (std::int64_t(bytes[1]) << 8) +
78 (std::int64_t(bytes[2]) << 16) + (std::int64_t(bytes[3]) << 24) +
79 (std::int64_t(bytes[4]) << 32) + (std::int64_t(bytes[5]) << 40) +
80 (std::int64_t(bytes[6]) << 48) + (std::int64_t(bytes[7]) << 56);
84std::uint32_t DeserializeUInt64(
const void *buffer, std::uint64_t *val)
86 return DeserializeInt64(buffer,
reinterpret_cast<std::int64_t *
>(val));
89std::uint32_t SerializeInt32(std::int32_t val,
void *buffer)
91 if (buffer !=
nullptr) {
92 auto bytes =
reinterpret_cast<unsigned char *
>(buffer);
93 bytes[0] = (val & 0x000000FF);
94 bytes[1] = (val & 0x0000FF00) >> 8;
95 bytes[2] = (val & 0x00FF0000) >> 16;
96 bytes[3] = (val & 0xFF000000) >> 24;
101std::uint32_t SerializeUInt32(std::uint32_t val,
void *buffer)
103 return SerializeInt32(val, buffer);
106std::uint32_t DeserializeInt32(
const void *buffer, std::int32_t *val)
108 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
109 *val = std::int32_t(bytes[0]) + (std::int32_t(bytes[1]) << 8) +
110 (std::int32_t(bytes[2]) << 16) + (std::int32_t(bytes[3]) << 24);
114std::uint32_t DeserializeUInt32(
const void *buffer, std::uint32_t *val)
116 return DeserializeInt32(buffer,
reinterpret_cast<std::int32_t *
>(val));
119std::uint32_t SerializeInt16(std::int16_t val,
void *buffer)
121 if (buffer !=
nullptr) {
122 auto bytes =
reinterpret_cast<unsigned char *
>(buffer);
123 bytes[0] = (val & 0x00FF);
124 bytes[1] = (val & 0xFF00) >> 8;
129std::uint32_t SerializeUInt16(std::uint16_t val,
void *buffer)
131 return SerializeInt16(val, buffer);
134std::uint32_t DeserializeInt16(
const void *buffer, std::int16_t *val)
136 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
137 *val = std::int16_t(bytes[0]) + (std::int16_t(bytes[1]) << 8);
141std::uint32_t DeserializeUInt16(
const void *buffer, std::uint16_t *val)
143 return DeserializeInt16(buffer,
reinterpret_cast<std::int16_t *
>(val));
148 return SerializeUInt32(val, buffer);
154 auto nbytes = DeserializeUInt32(buffer, &size);
159std::uint32_t SerializeString(
const std::string &val,
void *buffer)
161 if (buffer !=
nullptr) {
162 auto pos =
reinterpret_cast<unsigned char *
>(buffer);
163 pos += SerializeUInt32(val.length(), pos);
164 memcpy(pos, val.data(), val.length());
166 return SerializeUInt32(val.length(),
nullptr) + val.length();
169std::uint32_t DeserializeString(
const void *buffer, std::string *val)
171 auto base =
reinterpret_cast<const unsigned char *
>(buffer);
173 std::uint32_t length;
174 bytes += DeserializeUInt32(buffer, &length);
176 memcpy(&(*val)[0], bytes, length);
177 return bytes + length - base;
183 if (buffer !=
nullptr) {
184 auto pos =
reinterpret_cast<unsigned char *
>(buffer);
185 pos += SerializeInt64(val.
fPosition, pos);
187 pos += SerializeString(val.
fUrl, pos);
189 return SerializeString(val.
fUrl,
nullptr) + 12;
194 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
195 bytes += DeserializeInt64(bytes, &val->
fPosition);
197 bytes += DeserializeString(bytes, &val->
fUrl);
198 return SerializeString(val->
fUrl,
nullptr) + 12;
201std::uint32_t SerializeFrame(std::uint16_t protocolVersionCurrent, std::uint16_t protocolVersionMin,
void *buffer,
204 if (buffer !=
nullptr) {
205 auto pos =
reinterpret_cast<unsigned char *
>(buffer);
206 pos += SerializeUInt16(protocolVersionCurrent, pos);
207 pos += SerializeUInt16(protocolVersionMin, pos);
209 pos += SerializeUInt32(0, pos);
214std::uint32_t DeserializeFrame(std::uint16_t protocolVersion,
const void *buffer, std::uint32_t *size)
216 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
217 std::uint16_t protocolVersionAtWrite;
218 std::uint16_t protocolVersionMinRequired;
219 bytes += DeserializeUInt16(bytes, &protocolVersionAtWrite);
220 bytes += DeserializeUInt16(bytes, &protocolVersionMinRequired);
221 R__ASSERT(protocolVersionAtWrite >= protocolVersionMinRequired);
222 R__ASSERT(protocolVersion >= protocolVersionMinRequired);
223 bytes += DeserializeUInt32(bytes, size);
229 auto base =
reinterpret_cast<unsigned char *
>((buffer !=
nullptr) ? buffer : 0);
231 void** where = (buffer ==
nullptr) ? &buffer : reinterpret_cast<
void**>(&pos);
233 void *ptrSize =
nullptr;
234 pos += SerializeFrame(0, 0, *where, &ptrSize);
238 pos += SerializeUInt64(val.
GetFlags(), *where);
240 auto size = pos - base;
241 SerializeUInt32(size, ptrSize);
247 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
248 std::uint32_t frameSize;
249 bytes += DeserializeFrame(0, bytes, &frameSize);
251 std::uint32_t versionUse;
252 std::uint32_t versionMin;
254 bytes += DeserializeUInt32(bytes, &versionUse);
255 bytes += DeserializeUInt32(bytes, &versionMin);
256 bytes += DeserializeUInt64(bytes, &flags);
264 auto base =
reinterpret_cast<unsigned char *
>((buffer !=
nullptr) ? buffer : 0);
266 void** where = (buffer ==
nullptr) ? &buffer : reinterpret_cast<
void**>(&pos);
268 void *ptrSize =
nullptr;
269 pos += SerializeFrame(0, 0, *where, &ptrSize);
271 pos += SerializeString(val, *where);
273 auto size = pos - base;
274 SerializeUInt32(size, ptrSize);
280 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
281 std::uint32_t frameSize;
282 bytes += DeserializeFrame(0, bytes, &frameSize);
284 bytes += DeserializeString(bytes, uuid);
291 auto base =
reinterpret_cast<unsigned char *
>((buffer !=
nullptr) ? buffer : 0);
293 void** where = (buffer ==
nullptr) ? &buffer : reinterpret_cast<
void**>(&pos);
295 void *ptrSize =
nullptr;
296 pos += SerializeFrame(0, 0, *where, &ptrSize);
298 pos += SerializeInt32(
static_cast<int>(val.
GetType()), *where);
299 pos += SerializeInt32(
static_cast<int>(val.
GetIsSorted()), *where);
301 auto size = pos - base;
302 SerializeUInt32(size, ptrSize);
308 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
309 std::uint32_t frameSize;
310 bytes += DeserializeFrame(0, bytes, &frameSize);
313 std::int32_t isSorted;
314 bytes += DeserializeInt32(bytes, &
type);
315 bytes += DeserializeInt32(bytes, &isSorted);
321std::uint32_t SerializeTimeStamp(
const std::chrono::system_clock::time_point &val,
void *buffer)
323 return SerializeInt64(std::chrono::system_clock::to_time_t(val), buffer);
326std::uint32_t DeserializeTimeStamp(
const void *buffer, std::chrono::system_clock::time_point *timeStamp)
328 std::int64_t secSinceUnixEpoch;
329 auto size = DeserializeInt64(buffer, &secSinceUnixEpoch);
330 *timeStamp = std::chrono::system_clock::from_time_t(secSinceUnixEpoch);
337 if (buffer !=
nullptr) {
338 auto pos =
reinterpret_cast<unsigned char *
>(buffer);
341 pos += SerializeClusterSize(val.
fNElements, pos);
347std::uint32_t DeserializeColumnRange(
const void *buffer,
350 auto bytes =
reinterpret_cast<const unsigned char *
>(buffer);
353 bytes += DeserializeClusterSize(bytes, &columnRange->
fNElements);
361 if (buffer !=
nullptr) {
362 auto pos =
reinterpret_cast<unsigned char *
>(buffer);
364 pos += SerializeClusterSize(val.
fNElements, pos);
365 pos += SerializeLocator(val.
fLocator, pos);
367 return 4 + SerializeLocator(val.
fLocator,
nullptr);
370std::uint32_t DeserializePageInfo(
const void *buffer,
373 auto base =
reinterpret_cast<const unsigned char *
>(buffer);
376 bytes += DeserializeClusterSize(bytes, &pageInfo->
fNElements);
377 bytes += DeserializeLocator(bytes, &pageInfo->
fLocator);
381std::uint32_t SerializeCrc32(
const unsigned char *data, std::uint32_t length,
void *buffer)
383 auto checksum = R__crc32(0,
nullptr, 0);
384 if (buffer !=
nullptr) {
385 checksum = R__crc32(checksum, data, length);
386 SerializeUInt32(checksum, buffer);
391void VerifyCrc32(
const unsigned char *data, std::uint32_t length)
393 auto checksumReal = R__crc32(0,
nullptr, 0);
394 checksumReal = R__crc32(checksumReal, data, length);
395 std::uint32_t checksumFound;
396 DeserializeUInt32(data + length, &checksumFound);
397 R__ASSERT(checksumFound == checksumReal);
402 auto base =
reinterpret_cast<unsigned char *
>((buffer !=
nullptr) ? buffer : 0);
404 void** where = (buffer ==
nullptr) ? &buffer : reinterpret_cast<
void**>(&pos);
406 void *ptrSize =
nullptr;
410 pos += SerializeUInt64(val.
GetId(), *where);
417 pos += SerializeUInt32(
static_cast<int>(val.
GetStructure()), *where);
419 pos += SerializeUInt32(val.
GetLinkIds().size(), *where);
420 for (
const auto&
l : val.GetLinkIds())
421 pos += SerializeUInt64(
l, *where);
423 auto size = pos - base;
424 SerializeUInt32(size, ptrSize);
430 auto base =
reinterpret_cast<unsigned char *
>((buffer !=
nullptr) ? buffer : 0);
432 void** where = (buffer ==
nullptr) ? &buffer : reinterpret_cast<
void**>(&pos);
434 void *ptrSize =
nullptr;
438 pos += SerializeUInt64(val.
GetId(), *where);
439 pos += SerializeVersion(val.
GetVersion(), *where);
440 pos += SerializeColumnModel(val.
GetModel(), *where);
441 pos += SerializeUInt64(val.
GetFieldId(), *where);
442 pos += SerializeUInt32(val.
GetIndex(), *where);
444 auto size = pos - base;
445 SerializeUInt32(size, ptrSize);
451 auto base =
reinterpret_cast<unsigned char *
>((buffer !=
nullptr) ? buffer : 0);
453 void** where = (buffer ==
nullptr) ? &buffer : reinterpret_cast<
void**>(&pos);
455 void *ptrSize =
nullptr;
459 pos += SerializeUInt64(val.
GetId(), *where);
460 pos += SerializeVersion(val.
GetVersion(), *where);
463 pos += SerializeLocator(val.
GetLocator(), *where);
465 auto size = pos - base;
466 SerializeUInt32(size, ptrSize);
536 return fName == other.
fName &&
553 auto base =
reinterpret_cast<unsigned char *
>((buffer !=
nullptr) ? buffer : 0);
555 void** where = (buffer ==
nullptr) ? &buffer :
reinterpret_cast<void**
>(&pos);
557 void *ptrSize =
nullptr;
558 pos += SerializeFrame(
560 pos += SerializeUInt64(0, *where);
562 pos += SerializeString(fName, *where);
563 pos += SerializeString(fDescription, *where);
564 pos += SerializeString(fAuthor, *where);
565 pos += SerializeString(fCustodian, *where);
566 pos += SerializeTimeStamp(fTimeStampData, *where);
567 pos += SerializeTimeStamp(fTimeStampWritten, *where);
568 pos += SerializeVersion(fVersion, *where);
569 pos += SerializeUuid(fOwnUuid, *where);
570 pos += SerializeUuid(fGroupUuid, *where);
571 pos += SerializeUInt32(fFieldDescriptors.size(), *where);
572 for (
const auto&
f : fFieldDescriptors) {
573 pos += SerializeField(
f.second, *where);
575 pos += SerializeUInt32(fColumnDescriptors.size(), *where);
576 for (
const auto&
c : fColumnDescriptors) {
577 pos += SerializeColumn(
c.second, *where);
580 std::uint32_t size = pos - base;
581 SerializeUInt32(size, ptrSize);
582 size += SerializeCrc32(base, size, *where);
589 auto base =
reinterpret_cast<unsigned char *
>((buffer !=
nullptr) ? buffer : 0);
591 void** where = (buffer ==
nullptr) ? &buffer :
reinterpret_cast<void**
>(&pos);
593 void *ptrSize =
nullptr;
594 pos += SerializeFrame(
596 pos += SerializeUInt64(0, *where);
598 pos += SerializeUInt64(fClusterDescriptors.size(), *where);
599 for (
const auto& cluster : fClusterDescriptors) {
600 pos += SerializeUuid(fOwnUuid, *where);
601 pos += SerializeClusterSummary(cluster.second, *where);
603 pos += SerializeUInt32(fColumnDescriptors.size(), *where);
604 for (
const auto& column : fColumnDescriptors) {
605 auto columnId = column.first;
606 pos += SerializeUInt64(columnId, *where);
608 const auto &columnRange = cluster.second.GetColumnRange(columnId);
609 R__ASSERT(columnRange.fColumnId == columnId);
610 pos += SerializeColumnRange(columnRange, *where);
612 const auto &pageRange = cluster.second.GetPageRange(columnId);
613 R__ASSERT(pageRange.fColumnId == columnId);
614 auto nPages = pageRange.fPageInfos.size();
615 pos += SerializeUInt32(nPages, *where);
616 for (
unsigned int i = 0; i < nPages; ++i) {
617 pos += SerializePageInfo(pageRange.fPageInfos[i], *where);
623 pos += SerializeUInt16(kFrameVersionCurrent, *where);
624 pos += SerializeUInt16(kFrameVersionMin, *where);
626 pos += SerializeUInt32(GetHeaderSize(), *where);
627 std::uint32_t size = pos - base + 4;
628 pos += SerializeUInt32(size + 4, *where);
629 size += SerializeCrc32(base, size, *where);
636 const void *postscript, std::uint32_t &szHeader, std::uint32_t &szFooter)
638 auto pos =
reinterpret_cast<const unsigned char *
>(postscript);
640 pos += DeserializeUInt16(pos, &dummy);
641 pos += DeserializeUInt16(pos, &dummy);
642 pos += DeserializeUInt32(pos, &szHeader);
643 pos += DeserializeUInt32(pos, &szFooter);
650 for (
const auto &cd : fClusterDescriptors) {
651 result = std::max(result, cd.second.GetFirstEntryIndex() + cd.second.GetNEntries());
659 for (
const auto &cd : fClusterDescriptors) {
660 auto columnRange = cd.second.GetColumnRange(columnId);
661 result = std::max(result, columnRange.fFirstElementIndex + columnRange.fNElements);
670 std::string leafName(fieldName);
671 auto posDot = leafName.find_last_of(
'.');
672 if (posDot != std::string::npos) {
673 auto parentName = leafName.substr(0, posDot);
674 leafName = leafName.substr(posDot + 1);
675 parentId = FindFieldId(parentName, parentId);
677 for (
const auto &fd : fFieldDescriptors) {
678 if (fd.second.GetParentId() == parentId && fd.second.GetFieldName() == leafName)
679 return fd.second.GetId();
690 const auto &fieldDescriptor = fFieldDescriptors.at(fieldId);
691 auto prefix = GetQualifiedFieldName(fieldDescriptor.GetParentId());
693 return fieldDescriptor.GetFieldName();
694 return prefix +
"." + fieldDescriptor.GetFieldName();
708 return FindFieldId(fieldName, GetFieldZeroId());
715 for (
const auto &cd : fColumnDescriptors) {
716 if (cd.second.GetFieldId() == fieldId && cd.second.GetIndex() == columnIndex)
717 return cd.second.GetId();
727 for (
const auto &cd : fClusterDescriptors) {
728 auto columnRange = cd.second.GetColumnRange(columnId);
729 if (columnRange.Contains(index))
730 return cd.second.GetId();
739 const auto &clusterDesc = GetClusterDescriptor(clusterId);
740 auto firstEntryInNextCluster = clusterDesc.GetFirstEntryIndex() + clusterDesc.GetNEntries();
742 for (
const auto &cd : fClusterDescriptors) {
743 if (cd.second.GetFirstEntryIndex() == firstEntryInNextCluster)
744 return cd.second.GetId();
753 const auto &clusterDesc = GetClusterDescriptor(clusterId);
755 for (
const auto &cd : fClusterDescriptors) {
756 if (cd.second.GetFirstEntryIndex() + cd.second.GetNEntries() == clusterDesc.GetFirstEntryIndex())
757 return cd.second.GetId();
765 auto model = std::make_unique<RNTupleModel>();
766 for (
const auto &topDesc : GetTopLevelFields()) {
768 model->AddField(field.Unwrap());
785 for (
const auto& key_val: fDescriptor.fFieldDescriptors) {
786 const auto&
id = key_val.first;
787 const auto& desc = key_val.second;
790 return R__FAIL(
"field with id '" + std::to_string(
id) +
"' has an invalid parent id");
799 std::swap(result, fDescriptor);
805 auto pos =
reinterpret_cast<unsigned char *
>(headerBuffer);
808 std::uint32_t frameSize;
810 VerifyCrc32(base, frameSize);
811 std::uint64_t reserved;
812 pos += DeserializeUInt64(pos, &reserved);
814 pos += DeserializeString(pos, &fDescriptor.fName);
815 pos += DeserializeString(pos, &fDescriptor.fDescription);
816 pos += DeserializeString(pos, &fDescriptor.fAuthor);
817 pos += DeserializeString(pos, &fDescriptor.fCustodian);
818 pos += DeserializeTimeStamp(pos, &fDescriptor.fTimeStampData);
819 pos += DeserializeTimeStamp(pos, &fDescriptor.fTimeStampWritten);
820 pos += DeserializeVersion(pos, &fDescriptor.fVersion);
821 pos += DeserializeUuid(pos, &fDescriptor.fOwnUuid);
822 pos += DeserializeUuid(pos, &fDescriptor.fGroupUuid);
824 std::uint32_t nFields;
825 pos += DeserializeUInt32(pos, &nFields);
826 for (std::uint32_t i = 0; i < nFields; ++i) {
827 auto fieldBase = pos;
831 pos += DeserializeUInt64(pos, &
f.fFieldId);
832 pos += DeserializeVersion(pos, &
f.fFieldVersion);
833 pos += DeserializeVersion(pos, &
f.fTypeVersion);
834 pos += DeserializeString(pos, &
f.fFieldName);
835 pos += DeserializeString(pos, &
f.fFieldDescription);
836 pos += DeserializeString(pos, &
f.fTypeName);
837 pos += DeserializeUInt64(pos, &
f.fNRepetitions);
838 std::int32_t structure;
839 pos += DeserializeInt32(pos, &structure);
841 pos += DeserializeUInt64(pos, &
f.fParentId);
843 std::uint32_t nLinks;
844 pos += DeserializeUInt32(pos, &nLinks);
845 f.fLinkIds.resize(nLinks);
846 for (std::uint32_t j = 0; j < nLinks; ++j) {
847 pos += DeserializeUInt64(pos, &
f.fLinkIds[j]);
850 pos = fieldBase + frameSize;
851 fDescriptor.fFieldDescriptors.emplace(
f.fFieldId, std::move(
f));
854 std::uint32_t nColumns;
855 pos += DeserializeUInt32(pos, &nColumns);
856 for (std::uint32_t i = 0; i < nColumns; ++i) {
857 auto columnBase = pos;
861 pos += DeserializeUInt64(pos, &
c.fColumnId);
862 pos += DeserializeVersion(pos, &
c.fVersion);
863 pos += DeserializeColumnModel(pos, &
c.fModel);
864 pos += DeserializeUInt64(pos, &
c.fFieldId);
865 pos += DeserializeUInt32(pos, &
c.fIndex);
867 pos = columnBase + frameSize;
868 fDescriptor.fColumnDescriptors.emplace(
c.fColumnId, std::move(
c));
873 auto pos =
reinterpret_cast<unsigned char *
>(footerBuffer);
876 std::uint32_t frameSize;
878 VerifyCrc32(base, frameSize);
879 std::uint64_t reserved;
880 pos += DeserializeUInt64(pos, &reserved);
882 std::uint64_t nClusters;
883 pos += DeserializeUInt64(pos, &nClusters);
884 for (std::uint64_t i = 0; i < nClusters; ++i) {
886 pos += DeserializeUuid(pos, &uuid);
888 auto clusterBase = pos;
891 std::uint64_t clusterId;
893 std::uint64_t firstEntry;
894 std::uint64_t nEntries;
895 pos += DeserializeUInt64(pos, &clusterId);
896 pos += DeserializeVersion(pos, &version);
897 pos += DeserializeUInt64(pos, &firstEntry);
898 pos += DeserializeUInt64(pos, &nEntries);
901 pos += DeserializeLocator(pos, &locator);
902 SetClusterLocator(clusterId, locator);
904 pos = clusterBase + frameSize;
906 std::uint32_t nColumns;
907 pos += DeserializeUInt32(pos, &nColumns);
908 for (std::uint32_t j = 0; j < nColumns; ++j) {
910 pos += DeserializeUInt64(pos, &columnId);
914 pos += DeserializeColumnRange(pos, &columnRange);
915 AddClusterColumnRange(clusterId, columnRange);
920 pos += DeserializeUInt32(pos, &nPages);
921 for (
unsigned int k = 0; k < nPages; ++k) {
923 pos += DeserializePageInfo(pos, &pageInfo);
926 AddClusterPageRange(clusterId, std::move(pageRange));
932 const std::string_view
name,
const std::string_view description,
const std::string_view author,
935 fDescriptor.fName = std::string(
name);
936 fDescriptor.fDescription = std::string(description);
937 fDescriptor.fAuthor = std::string(author);
938 fDescriptor.fVersion = version;
939 fDescriptor.fOwnUuid = uuid;
940 fDescriptor.fGroupUuid = uuid;
965 return R__FAIL(
"invalid field id");
968 return R__FAIL(
"invalid field structure");
977 return fField.Clone();
981 fDescriptor.fFieldDescriptors.emplace(fieldDesc.
GetId(), fieldDesc.
Clone());
988 return R__FAIL(
"cannot make FieldZero a child field");
990 if (fDescriptor.fFieldDescriptors.count(fieldId) == 0) {
991 return R__FAIL(
"field with id '" + std::to_string(fieldId) +
"' doesn't exist in NTuple");
993 if (fDescriptor.fFieldDescriptors.count(linkId) == 0) {
994 return R__FAIL(
"child field with id '" + std::to_string(linkId) +
"' doesn't exist in NTuple");
997 auto parentId = fDescriptor.fFieldDescriptors.at(linkId).GetParentId();
999 return R__FAIL(
"field '" + std::to_string(linkId) +
"' already has a parent ('" +
1000 std::to_string(parentId) +
")");
1002 if (fieldId == linkId) {
1003 return R__FAIL(
"cannot make field '" + std::to_string(fieldId) +
"' a child of itself");
1005 fDescriptor.fFieldDescriptors.at(linkId).fParentId = fieldId;
1006 fDescriptor.fFieldDescriptors.at(fieldId).fLinkIds.push_back(linkId);
1012 std::uint32_t index)
1016 c.fFieldId = fieldId;
1017 c.fVersion = version;
1020 fDescriptor.fColumnDescriptors.emplace(columnId, std::move(
c));
1028 c.fVersion = version;
1029 c.fFirstEntryIndex = firstEntryIndex;
1030 c.fNEntries = nEntries;
1031 fDescriptor.fClusterDescriptors.emplace(clusterId, std::move(
c));
1037 fDescriptor.fClusterDescriptors[clusterId].fLocator = locator;
1043 fDescriptor.fClusterDescriptors[clusterId].fColumnRanges[columnRange.
fColumnId] = columnRange;
1049 fDescriptor.fClusterDescriptors[clusterId].fPageRanges.emplace(pageRange.fColumnId, std::move(pageRange));
#define R__FORWARD_ERROR(res)
Short-hand to return an RResult<T> in an error state (i.e. after checking)
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
typedef void((*Func_t)())
std::string GetName() const
std::size_t GetNRepetitions() const
virtual RNTupleVersion GetTypeVersion() const
Indicates an evolution of the C++ type itself.
std::string GetType() const
static RResult< void > EnsureValidFieldName(std::string_view fieldName)
Check whether a given string is a valid field name.
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &typeName)
Factory method to resurrect a field from the stored on-disk type information.
virtual RNTupleVersion GetFieldVersion() const
Indicates an evolution of the mapping scheme from C++ type to columns.
ENTupleStructure GetStructure() const
The available trivial, native content types of a column.
Meta-data for a set of ntuple clusters.
std::unordered_map< DescriptorId_t, RPageRange > fPageRanges
RNTupleVersion fVersion
Future versions of the cluster descriptor might add more meta-data, e.g. a semantic checksum.
RLocator fLocator
For pre-fetching / caching an entire contiguous cluster.
static constexpr std::uint16_t kFrameVersionMin
RNTupleVersion GetVersion() const
NTupleSize_t fFirstEntryIndex
Clusters can be swapped by adjusting the entry offsets.
DescriptorId_t fClusterId
RLocator GetLocator() const
NTupleSize_t GetFirstEntryIndex() const
std::unordered_map< DescriptorId_t, RColumnRange > fColumnRanges
bool operator==(const RClusterDescriptor &other) const
ClusterSize_t GetNEntries() const
static constexpr std::uint16_t kFrameVersionCurrent
In order to handle changes to the serialization routine in future ntuple versions.
DescriptorId_t GetId() const
Meta-data stored for every column of an ntuple.
RNTupleVersion GetVersion() const
RColumnModel GetModel() const
static constexpr std::uint16_t kFrameVersionCurrent
In order to handle changes to the serialization routine in future ntuple versions.
DescriptorId_t GetId() const
DescriptorId_t fFieldId
Every column belongs to one and only one field.
DescriptorId_t GetFieldId() const
RColumnModel fModel
Contains the column type and whether it is sorted.
static constexpr std::uint16_t kFrameVersionMin
RNTupleVersion fVersion
Versions can change, e.g., when new column types are added.
std::uint32_t GetIndex() const
std::uint32_t fIndex
A field can be serialized into several columns, which are numbered from zero to $n$.
bool operator==(const RColumnDescriptor &other) const
Holds the static meta-data of a column in a tree.
EColumnType GetType() const
A helper class for piece-wise construction of an RFieldDescriptor.
RDanglingFieldDescriptor & TypeVersion(const RNTupleVersion &typeVersion)
RDanglingFieldDescriptor & FieldVersion(const RNTupleVersion &fieldVersion)
RDanglingFieldDescriptor & Structure(const ENTupleStructure &structure)
RResult< RFieldDescriptor > MakeDescriptor() const
Attempt to make a field descriptor.
static RDanglingFieldDescriptor FromField(const Detail::RFieldBase &field)
Make a new RDanglingFieldDescriptor based off a live NTuple field.
RDanglingFieldDescriptor & NRepetitions(std::uint64_t nRepetitions)
RDanglingFieldDescriptor & FieldName(const std::string &fieldName)
RDanglingFieldDescriptor & TypeName(const std::string &typeName)
RDanglingFieldDescriptor()=default
Make an empty dangling field descriptor.
Meta-data stored for every field of an ntuple.
std::vector< DescriptorId_t > fLinkIds
The pointers in the other direction from parent to children.
DescriptorId_t GetParentId() const
RNTupleVersion GetTypeVersion() const
RNTupleVersion fFieldVersion
The version of the C++-type-to-column translation mechanics.
RNTupleVersion GetFieldVersion() const
std::string GetFieldName() const
std::string fFieldDescription
Free text set by the user.
static constexpr std::uint16_t kFrameVersionMin
std::string fFieldName
The leaf name, not including parent fields.
DescriptorId_t GetId() const
const std::vector< DescriptorId_t > & GetLinkIds() const
std::string GetFieldDescription() const
std::string GetTypeName() const
DescriptorId_t fParentId
Establishes sub field relationships, such as classes and collections.
RNTupleVersion fTypeVersion
The version of the C++ type itself.
std::uint64_t GetNRepetitions() const
RFieldDescriptor Clone() const
Get a copy of the descriptor.
bool operator==(const RFieldDescriptor &other) const
ENTupleStructure fStructure
The structural information carried by this field in the data model tree.
ENTupleStructure GetStructure() const
std::string fTypeName
The C++ type that was used when writing the field.
std::uint64_t fNRepetitions
The number of elements per entry for fixed-size arrays.
static constexpr std::uint16_t kFrameVersionCurrent
In order to handle changes to the serialization routine in future ntuple versions.
RNTupleDescriptor MoveDescriptor()
RResult< void > EnsureValidDescriptor() const
Checks whether invariants hold:
void SetFromHeader(void *headerBuffer)
void AddCluster(DescriptorId_t clusterId, RNTupleVersion version, NTupleSize_t firstEntryIndex, ClusterSize_t nEntries)
RResult< void > AddFieldLink(DescriptorId_t fieldId, DescriptorId_t linkId)
void AddColumn(DescriptorId_t columnId, DescriptorId_t fieldId, const RNTupleVersion &version, const RColumnModel &model, std::uint32_t index)
void SetClusterLocator(DescriptorId_t clusterId, RClusterDescriptor::RLocator locator)
void AddClusterColumnRange(DescriptorId_t clusterId, const RClusterDescriptor::RColumnRange &columnRange)
void AddClustersFromFooter(void *footerBuffer)
void SetNTuple(const std::string_view name, const std::string_view description, const std::string_view author, const RNTupleVersion &version, const RNTupleUuid &uuid)
void AddClusterPageRange(DescriptorId_t clusterId, RClusterDescriptor::RPageRange &&pageRange)
void AddField(const RFieldDescriptor &fieldDesc)
The on-storage meta-data of an ntuple.
std::unordered_map< DescriptorId_t, RClusterDescriptor > fClusterDescriptors
May contain only a subset of all the available clusters, e.g.
RNTupleUuid fGroupUuid
Column sets that are created as derived sets from existing NTuples share the same group id.
std::unique_ptr< RNTupleModel > GenerateModel() const
Re-create the C++ model from the stored meta-data.
std::chrono::system_clock::time_point fTimeStampWritten
The time stamp of writing the data to storage, which gets updated when re-written.
DescriptorId_t FindNextClusterId(DescriptorId_t clusterId) const
std::uint32_t SerializeHeader(void *buffer) const
We deliberately do not use ROOT's built-in serialization in order to allow for use of RNTuple's witho...
DescriptorId_t FindPrevClusterId(DescriptorId_t clusterId) const
DescriptorId_t GetFieldZeroId() const
Returns the logical parent of all top-level NTuple data fields.
std::unordered_map< DescriptorId_t, RColumnDescriptor > fColumnDescriptors
NTupleSize_t GetNEntries() const
std::string fName
The ntuple name needs to be unique in a given storage location (file)
std::uint32_t SerializeFooter(void *buffer) const
Serializes cluster meta data. Returns the number of bytes and fills buffer if it is not nullptr.
std::string fAuthor
The origin of the data.
std::unordered_map< DescriptorId_t, RFieldDescriptor > fFieldDescriptors
static constexpr std::uint16_t kFrameVersionMin
RNTupleVersion fVersion
The version evolves with the ntuple summary meta-data.
bool operator==(const RNTupleDescriptor &other) const
std::string GetQualifiedFieldName(DescriptorId_t fieldId) const
Walks up the parents of the field ID and returns a field name of the form a.b.c.d In case of invalid ...
DescriptorId_t FindFieldId(std::string_view fieldName, DescriptorId_t parentId) const
std::string fCustodian
The current responsible for storing the data.
DescriptorId_t FindColumnId(DescriptorId_t fieldId, std::uint32_t columnIndex) const
NTupleSize_t GetNElements(DescriptorId_t columnId) const
static void LocateMetadata(const void *postscript, std::uint32_t &szHeader, std::uint32_t &szFooter)
Given kNBytesPostscript bytes, extract the header and footer lengths in bytes.
std::string fDescription
Free text from the user.
static constexpr std::uint16_t kFrameVersionCurrent
In order to handle changes to the serialization routine in future ntuple versions.
RNTupleUuid fOwnUuid
Every NTuple gets a unique identifier.
std::chrono::system_clock::time_point fTimeStampData
The time stamp of the ntuple data (immutable)
DescriptorId_t FindClusterId(DescriptorId_t columnId, NTupleSize_t index) const
For forward and backward compatibility, attach version information to the consitituents of the file f...
std::uint32_t GetVersionUse() const
NTupleFlags_t GetFlags() const
std::uint32_t GetVersionMin() const
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
ENTupleStructure
The fields in the ntuple model tree can carry different structural information about the type system.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::string RNTupleUuid
Every NTuple is identified by a UUID. TODO(jblomer): should this be a TUUID?
constexpr DescriptorId_t kInvalidDescriptorId
The window of element indexes of a particular column in a particular cluster.
std::int64_t fCompressionSettings
The usual format for ROOT compression settings (see Compression.h).
NTupleSize_t fFirstElementIndex
A 64bit element index.
ClusterSize_t fNElements
A 32bit value for the number of column elements in the cluster.
Generic information about the physical location of data.
std::uint32_t fBytesOnStorage
Wrap the 32bit integer in a struct in order to avoid template specialization clash with std::uint32_t...