24class CreateContextGuard;
26 friend class CreateContextGuard;
28 std::vector<std::string> fClassesOnStack;
31 bool fContinueOnError =
false;
34 CreateContext() =
default;
35 bool GetContinueOnError()
const {
return fContinueOnError; }
39class CreateContextGuard {
40 CreateContext &fCreateContext;
41 std::size_t fNOriginalClassesOnStack;
42 bool fOriginalContinueOnError;
45 CreateContextGuard(CreateContext &ctx)
46 : fCreateContext(ctx),
47 fNOriginalClassesOnStack(ctx.fClassesOnStack.
size()),
48 fOriginalContinueOnError(ctx.fContinueOnError)
53 fCreateContext.fClassesOnStack.resize(fNOriginalClassesOnStack);
54 fCreateContext.fContinueOnError = fOriginalContinueOnError;
57 void AddClassToStack(
const std::string &cl)
59 if (std::find(fCreateContext.fClassesOnStack.begin(), fCreateContext.fClassesOnStack.end(), cl) !=
60 fCreateContext.fClassesOnStack.end()) {
63 fCreateContext.fClassesOnStack.emplace_back(cl);
66 void SetContinueOnError(
bool value) { fCreateContext.fContinueOnError =
value; }
94 return RFieldBase::Create(fieldName, typeName, options, desc, fieldId);
101 operator delete(objPtr, std::align_val_t(
fAlignment));
115 : fSerializationTypes(serializationTypes), fDeserializationTypes(serializationTypes)
118 deserializationExtraTypes.end());
133 : fField(other.fField),
135 fCapacity(other.fCapacity),
137 fIsAdopted(other.fIsAdopted),
138 fNValidValues(other.fNValidValues),
139 fFirstIndex(other.fFirstIndex)
141 std::swap(
fDeleter, other.fDeleter);
142 std::swap(
fValues, other.fValues);
148 std::swap(fField, other.fField);
149 std::swap(fDeleter, other.fDeleter);
150 std::swap(fValues, other.fValues);
152 std::swap(fCapacity, other.fCapacity);
153 std::swap(
fSize, other.fSize);
154 std::swap(fIsAdopted, other.fIsAdopted);
155 std::swap(fMaskAvail, other.fMaskAvail);
156 std::swap(fNValidValues, other.fNValidValues);
157 std::swap(fFirstIndex, other.fFirstIndex);
173 for (std::size_t i = 0; i < fCapacity; ++i) {
174 fDeleter->operator()(GetValuePtrAt(i),
true );
178 operator delete(fValues, std::align_val_t(fField->GetAlignment()));
183 if (fCapacity <
size) {
185 throw RException(
R__FAIL(
"invalid attempt to bulk read beyond the adopted buffer"));
188 fValues =
operator new(
size *
fValueSize, std::align_val_t(fField->GetAlignment()));
191 for (std::size_t i = 0; i <
size; ++i) {
192 fField->ConstructValue(GetValuePtrAt(i));
196 fMaskAvail = std::make_unique<bool[]>(
size);
200 std::fill(fMaskAvail.get(), fMaskAvail.get() +
size,
false);
203 fFirstIndex = firstIndex;
214 fMaskAvail = std::make_unique<bool[]>(
capacity);
229std::unique_ptr<void, typename ROOT::RFieldBase::RCreateObjectDeleter<void>::deleter>
230ROOT::RFieldBase::CreateObject<void>()
const
233 return std::unique_ptr<void, RCreateObjectDeleter<void>::deleter>(
CreateObjectRawPtr(), gDeleter);
239 bool isSimple, std::size_t nRepetitions)
254 std::string
result = GetFieldName();
255 auto parent = GetParent();
256 while (parent && !parent->GetFieldName().empty()) {
258 parent = parent->GetParent();
270std::vector<ROOT::RFieldBase::RCheckResult>
276 cfOpts.SetEmulateUnknownTypes(
false);
279 std::vector<RCheckResult>
result;
280 for (
const auto &
f : fieldZero) {
287 RCheckResult{invalidField.GetQualifiedFieldName(), invalidField.GetTypeName(), invalidField.GetError()});
302 thread_local CreateContext createContext;
303 CreateContextGuard createContextGuard(createContext);
305 createContextGuard.SetContinueOnError(
true);
307 auto fnFail = [&fieldName,
308 &resolvedType](
const std::string &errMsg,
311 if (createContext.GetContinueOnError()) {
312 return std::unique_ptr<RFieldBase>(std::make_unique<RInvalidField>(fieldName, resolvedType, errMsg, cat));
318 if (resolvedType.empty())
319 return R__FORWARD_RESULT(fnFail(
"no type name specified for field '" + fieldName +
"'"));
321 std::unique_ptr<ROOT::RFieldBase>
result;
323 const auto maybeGetChildId = [desc, fieldId](
int childId) {
335 if (resolvedType ==
"bool") {
336 result = std::make_unique<RField<bool>>(fieldName);
337 }
else if (resolvedType ==
"char") {
338 result = std::make_unique<RField<char>>(fieldName);
339 }
else if (resolvedType ==
"std::byte") {
340 result = std::make_unique<RField<std::byte>>(fieldName);
341 }
else if (resolvedType ==
"std::int8_t") {
342 result = std::make_unique<RField<std::int8_t>>(fieldName);
343 }
else if (resolvedType ==
"std::uint8_t") {
344 result = std::make_unique<RField<std::uint8_t>>(fieldName);
345 }
else if (resolvedType ==
"std::int16_t") {
346 result = std::make_unique<RField<std::int16_t>>(fieldName);
347 }
else if (resolvedType ==
"std::uint16_t") {
348 result = std::make_unique<RField<std::uint16_t>>(fieldName);
349 }
else if (resolvedType ==
"std::int32_t") {
350 result = std::make_unique<RField<std::int32_t>>(fieldName);
351 }
else if (resolvedType ==
"std::uint32_t") {
352 result = std::make_unique<RField<std::uint32_t>>(fieldName);
353 }
else if (resolvedType ==
"std::int64_t") {
354 result = std::make_unique<RField<std::int64_t>>(fieldName);
355 }
else if (resolvedType ==
"std::uint64_t") {
356 result = std::make_unique<RField<std::uint64_t>>(fieldName);
357 }
else if (resolvedType ==
"float") {
358 result = std::make_unique<RField<float>>(fieldName);
359 }
else if (resolvedType ==
"double") {
360 result = std::make_unique<RField<double>>(fieldName);
361 }
else if (resolvedType ==
"Double32_t") {
362 result = std::make_unique<RField<double>>(fieldName);
366 }
else if (resolvedType ==
"std::string") {
367 result = std::make_unique<RField<std::string>>(fieldName);
368 }
else if (resolvedType ==
"TObject") {
369 result = std::make_unique<RField<TObject>>(fieldName);
370 }
else if (resolvedType ==
"std::vector<bool>") {
371 result = std::make_unique<RField<std::vector<bool>>>(fieldName);
372 }
else if (resolvedType.substr(0, 12) ==
"std::vector<") {
373 std::string itemTypeName = resolvedType.substr(12, resolvedType.length() - 13);
374 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0));
375 result = std::make_unique<RVectorField>(fieldName, itemField.Unwrap());
376 }
else if (resolvedType.substr(0, 19) ==
"ROOT::VecOps::RVec<") {
377 std::string itemTypeName = resolvedType.substr(19, resolvedType.length() - 20);
378 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0));
379 result = std::make_unique<RRVecField>(fieldName, itemField.Unwrap());
380 }
else if (resolvedType.substr(0, 11) ==
"std::array<") {
381 auto arrayDef =
TokenizeTypeList(resolvedType.substr(11, resolvedType.length() - 12));
382 if (arrayDef.size() != 2) {
383 return R__FORWARD_RESULT(fnFail(
"the template list for std::array must have exactly two elements"));
386 auto itemField = Create(
"_0", arrayDef[0], options, desc, maybeGetChildId(0));
387 result = std::make_unique<RArrayField>(fieldName, itemField.Unwrap(), arrayLength);
388 }
else if (resolvedType.substr(0, 13) ==
"std::variant<") {
389 auto innerTypes =
TokenizeTypeList(resolvedType.substr(13, resolvedType.length() - 14));
390 std::vector<std::unique_ptr<RFieldBase>> items;
391 items.reserve(innerTypes.size());
392 for (
unsigned int i = 0; i < innerTypes.size(); ++i) {
394 Create(
"_" + std::to_string(i), innerTypes[i], options, desc, maybeGetChildId(i)).Unwrap());
396 result = std::make_unique<RVariantField>(fieldName, std::move(items));
397 }
else if (resolvedType.substr(0, 10) ==
"std::pair<") {
398 auto innerTypes =
TokenizeTypeList(resolvedType.substr(10, resolvedType.length() - 11));
399 if (innerTypes.size() != 2) {
400 return R__FORWARD_RESULT(fnFail(
"the type list for std::pair must have exactly two elements"));
402 std::array<std::unique_ptr<RFieldBase>, 2> items{
403 Create(
"_0", innerTypes[0], options, desc, maybeGetChildId(0)).Unwrap(),
404 Create(
"_1", innerTypes[1], options, desc, maybeGetChildId(1)).Unwrap()};
405 result = std::make_unique<RPairField>(fieldName, std::move(items));
406 }
else if (resolvedType.substr(0, 11) ==
"std::tuple<") {
407 auto innerTypes =
TokenizeTypeList(resolvedType.substr(11, resolvedType.length() - 12));
408 std::vector<std::unique_ptr<RFieldBase>> items;
409 items.reserve(innerTypes.size());
410 for (
unsigned int i = 0; i < innerTypes.size(); ++i) {
412 Create(
"_" + std::to_string(i), innerTypes[i], options, desc, maybeGetChildId(i)).Unwrap());
414 result = std::make_unique<RTupleField>(fieldName, std::move(items));
415 }
else if (resolvedType.substr(0, 12) ==
"std::bitset<") {
417 result = std::make_unique<RBitsetField>(fieldName,
size);
418 }
else if (resolvedType.substr(0, 16) ==
"std::unique_ptr<") {
419 std::string itemTypeName = resolvedType.substr(16, resolvedType.length() - 17);
420 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
421 result = std::make_unique<RUniquePtrField>(fieldName, std::move(itemField));
422 }
else if (resolvedType.substr(0, 14) ==
"std::optional<") {
423 std::string itemTypeName = resolvedType.substr(14, resolvedType.length() - 15);
424 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
425 result = std::make_unique<ROptionalField>(fieldName, std::move(itemField));
426 }
else if (resolvedType.substr(0, 9) ==
"std::set<") {
427 std::string itemTypeName = resolvedType.substr(9, resolvedType.length() - 10);
428 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
430 }
else if (resolvedType.substr(0, 19) ==
"std::unordered_set<") {
431 std::string itemTypeName = resolvedType.substr(19, resolvedType.length() - 20);
432 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
434 }
else if (resolvedType.substr(0, 14) ==
"std::multiset<") {
435 std::string itemTypeName = resolvedType.substr(14, resolvedType.length() - 15);
436 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
438 }
else if (resolvedType.substr(0, 24) ==
"std::unordered_multiset<") {
439 std::string itemTypeName = resolvedType.substr(24, resolvedType.length() - 25);
440 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
442 }
else if (resolvedType.substr(0, 9) ==
"std::map<") {
443 auto innerTypes =
TokenizeTypeList(resolvedType.substr(9, resolvedType.length() - 10));
444 if (innerTypes.size() != 2) {
445 return R__FORWARD_RESULT(fnFail(
"the type list for std::map must have exactly two elements"));
448 Create(
"_0",
"std::pair<" + innerTypes[0] +
"," + innerTypes[1] +
">", options, desc, maybeGetChildId(0))
451 }
else if (resolvedType.substr(0, 19) ==
"std::unordered_map<") {
452 auto innerTypes =
TokenizeTypeList(resolvedType.substr(19, resolvedType.length() - 20));
453 if (innerTypes.size() != 2)
454 return R__FORWARD_RESULT(fnFail(
"the type list for std::unordered_map must have exactly two elements"));
456 Create(
"_0",
"std::pair<" + innerTypes[0] +
"," + innerTypes[1] +
">", options, desc, maybeGetChildId(0))
459 }
else if (resolvedType.substr(0, 14) ==
"std::multimap<") {
460 auto innerTypes =
TokenizeTypeList(resolvedType.substr(14, resolvedType.length() - 15));
461 if (innerTypes.size() != 2)
462 return R__FORWARD_RESULT(fnFail(
"the type list for std::multimap must have exactly two elements"));
464 Create(
"_0",
"std::pair<" + innerTypes[0] +
"," + innerTypes[1] +
">", options, desc, maybeGetChildId(0))
467 }
else if (resolvedType.substr(0, 24) ==
"std::unordered_multimap<") {
468 auto innerTypes =
TokenizeTypeList(resolvedType.substr(24, resolvedType.length() - 25));
469 if (innerTypes.size() != 2)
471 fnFail(
"the type list for std::unordered_multimap must have exactly two elements"));
473 Create(
"_0",
"std::pair<" + innerTypes[0] +
"," + innerTypes[1] +
">", options, desc, maybeGetChildId(0))
476 }
else if (resolvedType.substr(0, 12) ==
"std::atomic<") {
477 std::string itemTypeName = resolvedType.substr(12, resolvedType.length() - 13);
478 auto itemField = Create(
"_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
479 result = std::make_unique<RAtomicField>(fieldName, std::move(itemField));
480 }
else if (resolvedType.substr(0, 25) ==
"ROOT::RNTupleCardinality<") {
481 auto innerTypes =
TokenizeTypeList(resolvedType.substr(25, resolvedType.length() - 26));
482 if (innerTypes.size() != 1)
483 return R__FORWARD_RESULT(fnFail(
"invalid cardinality template: " + resolvedType));
485 if (canonicalInnerType ==
"std::uint32_t") {
486 result = std::make_unique<RField<RNTupleCardinality<std::uint32_t>>>(fieldName);
487 }
else if (canonicalInnerType ==
"std::uint64_t") {
488 result = std::make_unique<RField<RNTupleCardinality<std::uint64_t>>>(fieldName);
490 return R__FORWARD_RESULT(fnFail(
"invalid cardinality template: " + resolvedType));
498 createContextGuard.AddClassToStack(resolvedType);
499 if (cl->GetCollectionProxy()) {
500 result = std::make_unique<RProxiedCollectionField>(fieldName, typeName);
508 result = std::make_unique<ROOT::Experimental::RSoAField>(fieldName, typeName);
511 result = std::make_unique<RStreamerField>(fieldName, typeName);
513 result = std::make_unique<RClassField>(fieldName, typeName);
522 result = std::make_unique<REnumField>(fieldName, typeName);
532 auto streamerField = std::unique_ptr<RFieldBase>(
new RStreamerField(fieldName, typeName));
533 streamerField->fTypeAlias = fieldDesc.GetTypeAlias();
534 return streamerField;
536 std::vector<std::unique_ptr<RFieldBase>> memberFields;
537 memberFields.reserve(fieldDesc.GetLinkIds().size());
538 for (
auto id : fieldDesc.GetLinkIds()) {
540 auto field = Create(memberDesc.GetFieldName(), memberDesc.GetTypeName(), options, desc,
id).Unwrap();
541 memberFields.emplace_back(std::move(field));
543 R__ASSERT(typeName == fieldDesc.GetTypeName());
546 recordField->fTypeAlias = fieldDesc.GetTypeAlias();
549 if (fieldDesc.GetLinkIds().size() != 1)
552 auto itemFieldId = fieldDesc.GetLinkIds()[0];
555 Create(itemFieldDesc.GetFieldName(), itemFieldDesc.GetTypeName(), options, desc, itemFieldId).Unwrap();
558 vecField->fTypeAlias = fieldDesc.GetTypeAlias();
561 R__ASSERT(!fieldDesc.GetLinkIds().empty());
562 auto underlyingIntFieldId = fieldDesc.GetLinkIds()[0];
565 underlyingIntFieldDesc.GetTypeName());
566 enumField->fTypeAlias = fieldDesc.GetTypeAlias();
571 auto error =
e.GetError();
572 if (createContext.GetContinueOnError()) {
573 return std::unique_ptr<RFieldBase>(std::make_unique<RInvalidField>(fieldName, typeName, error.GetReport(),
578 }
catch (
const std::logic_error &
e) {
580 if (createContext.GetContinueOnError()) {
581 return std::unique_ptr<RFieldBase>(
590 if (normOrigType !=
result->GetTypeName()) {
591 result->fTypeAlias = normOrigType;
601 return representations;
606 auto clone = CloneImpl(newName);
607 clone->fTypeAlias = fTypeAlias;
608 clone->fOnDiskId = fOnDiskId;
609 clone->fDescription = fDescription;
611 clone->fColumnRepresentatives = fColumnRepresentatives;
617 R__ASSERT(
false &&
"A non-simple RField must implement its own AppendImpl");
628 ReadGlobalImpl(fPrincipalColumn->GetGlobalIndex(localIndex), to);
633 const auto valueSize = GetValueSize();
634 std::size_t nRead = 0;
635 for (std::size_t i = 0; i < bulkSpec.
fCount; ++i) {
644 Read(bulkSpec.
fFirstIndex + i,
reinterpret_cast<unsigned char *
>(bulkSpec.
fValues) + i * valueSize);
653 const auto align = GetAlignment();
655 if (align <=
sizeof(std::max_align_t)) {
658 where =
operator new(GetValueSize());
660 where =
operator new(GetValueSize(), std::align_val_t(GetAlignment()));
663 ConstructValue(where);
669 void *obj = CreateObjectRawPtr();
675 return std::vector<RValue>();
682 if (!(fTraits & kTraitExtensible) && (fState != EState::kUnconnected))
683 throw RException(
R__FAIL(
"invalid attempt to attach subfield to already connected, non-extensible field"));
685 if (!expectedChildName.empty() &&
child->GetFieldName() != expectedChildName) {
687 " expected: " + std::string(expectedChildName)));
690 child->fParent =
this;
691 fSubfields.emplace_back(std::move(
child));
697 for (
auto f =
this;
f !=
nullptr;
f =
f->GetParent()) {
698 auto parent =
f->GetParent();
710 std::vector<RFieldBase *>
result;
711 result.reserve(fSubfields.size());
712 for (
const auto &
f : fSubfields) {
720 std::vector<const RFieldBase *>
result;
721 result.reserve(fSubfields.size());
722 for (
const auto &
f : fSubfields) {
730 if (!fAvailableColumns.empty()) {
731 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
732 for (
auto &column : fAvailableColumns) {
733 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
742 if (!fAvailableColumns.empty()) {
743 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
744 for (
auto &column : fAvailableColumns) {
745 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
748 column->CommitSuppressed();
757 if (fState != EState::kUnconnected)
758 throw RException(
R__FAIL(
"cannot set field description once field is connected"));
759 fDescription = std::string(description);
764 if (fState != EState::kUnconnected)
773 if (~fTraits & kTraitMappable)
774 return AppendImpl(from);
776 fPrincipalColumn->Append(from);
777 return fPrincipalColumn->GetElement()->GetPackedSize();
787 return RValue(
this, std::move(objPtr));
796 return RBulkSpec::kAllSet;
799 if (fIsArtificial || !fReadCallbacks.empty()) {
804 return ReadBulkImpl(bulkSpec);
839 if (fColumnRepresentatives.empty()) {
840 return {GetColumnRepresentations().GetSerializationDefault()};
844 result.reserve(fColumnRepresentatives.size());
845 for (
const auto &
r : fColumnRepresentatives) {
853 if (fState != EState::kUnconnected)
854 throw RException(
R__FAIL(
"cannot set column representative once field is connected"));
855 const auto &validTypes = GetColumnRepresentations().GetSerializationTypes();
856 fColumnRepresentatives.clear();
857 fColumnRepresentatives.reserve(representatives.size());
858 for (
const auto &
r : representatives) {
859 auto itRepresentative = std::find(validTypes.begin(), validTypes.end(),
r);
860 if (itRepresentative == std::end(validTypes))
863 fColumnRepresentatives.emplace_back(*itRepresentative);
869 std::uint16_t representationIndex)
const
874 throw RException(
R__FAIL(
"No on-disk field information for `" + GetQualifiedFieldName() +
"`"));
878 if (
c.GetRepresentationIndex() == representationIndex)
879 onDiskTypes.emplace_back(
c.GetType());
881 if (onDiskTypes.empty()) {
882 if (representationIndex == 0) {
883 throw RException(
R__FAIL(
"No on-disk column information for field `" + GetQualifiedFieldName() +
"`"));
888 for (
const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
889 if (t == onDiskTypes)
893 std::string columnTypeNames;
894 for (
const auto &t : onDiskTypes) {
895 if (!columnTypeNames.empty())
896 columnTypeNames +=
", ";
899 throw RException(
R__FAIL(
"On-disk column types {" + columnTypeNames +
"} for field `" + GetQualifiedFieldName() +
900 "` cannot be matched to its in-memory type `" + GetTypeName() +
"` " +
901 "(representation index: " + std::to_string(representationIndex) +
")"));
906 fReadCallbacks.push_back(func);
908 return fReadCallbacks.size() - 1;
913 fReadCallbacks.erase(fReadCallbacks.begin() + idx);
914 fIsSimple = (fTraits & kTraitMappable) && !fIsArtificial && fReadCallbacks.empty();
920 const bool hadDefaultRepresentative = HasDefaultColumnRepresentative();
921 if ((options.
GetCompression() == 0) && hadDefaultRepresentative) {
923 for (
auto &colType : rep) {
938 SetColumnRepresentatives({rep});
944 if ((fTypeAlias ==
"Double32_t") && hadDefaultRepresentative) {
954 if ((fTypeAlias ==
"Double32_t") && !hadDefaultRepresentative) {
955 bool hasSubDoubleRep =
false;
956 for (
const auto &rep : GetColumnRepresentatives()) {
957 for (
const auto colType : rep) {
959 hasSubDoubleRep =
true;
966 if (!hasSubDoubleRep) {
967 throw RException(
R__FAIL(
"explicit column representations of Double32_t field `" + GetFieldName() +
968 "` must include a reduced-precision representation"));
977 if (fState != EState::kUnconnected)
978 throw RException(
R__FAIL(
"invalid attempt to connect an already connected field to a page sink"));
983 for (
auto &column : fAvailableColumns) {
987 auto firstElementIndex = (column->GetIndex() == 0) ? EntryToColumnElementIndex(firstEntry) : 0;
988 column->ConnectPageSink(fOnDiskId, pageSink, firstElementIndex);
991 if (HasExtraTypeInfo()) {
996 fState = EState::kConnectedToSink;
1002 for (
auto &
f : fSubfields)
1003 f->ConnectPageSource(pageSource);
1007 if (fState != EState::kUnconnected)
1008 throw RException(
R__FAIL(
"invalid attempt to connect an already connected field to a page source"));
1010 if (!fColumnRepresentatives.empty())
1011 throw RException(
R__FAIL(
"fixed column representative only valid when connecting to a page sink"));
1012 if (!fDescription.empty())
1013 throw RException(
R__FAIL(
"setting description only valid when connecting to a page sink"));
1015 if (!fIsArtificial) {
1024 SetOnDiskId(descGuard->GetFieldDescriptor(GetOnDiskId()).GetLinkIds()[0]);
1028 auto substitute = BeforeConnectPageSource(pageSource);
1034 if (
typeid(*itr) ==
typeid(
RFieldZero) &&
static_cast<const RFieldZero *
>(itr)->GetAllowFieldSubstitutions()) {
1035 for (
auto &
f : fParent->fSubfields) {
1036 if (
f.get() !=
this)
1039 f = std::move(substitute);
1040 f->ConnectPageSource(pageSource);
1045 throw RException(
R__FAIL(
"invalid attempt to substitute field " + GetQualifiedFieldName()));
1049 if (!fIsArtificial) {
1051 ReconcileOnDiskField(descGuard.GetConstRef());
1054 for (
auto &
f : fSubfields) {
1058 f->ConnectPageSource(pageSource);
1062 if (!fIsArtificial) {
1065 GenerateColumns(desc);
1066 if (fColumnRepresentatives.empty()) {
1068 for (
const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
1070 fColumnRepresentatives = {t};
1075 R__ASSERT(!fColumnRepresentatives.empty());
1079 if (fieldDesc.GetTypeChecksum().has_value())
1080 fOnDiskTypeChecksum = *fieldDesc.GetTypeChecksum();
1083 for (
auto &column : fAvailableColumns)
1084 column->ConnectPageSource(fOnDiskId, pageSource);
1086 fState = EState::kConnectedToSource;
1093 EnsureMatchingOnDiskField(desc).ThrowOnError();
1100 const std::uint32_t diffBits = CompareOnDiskField(fieldDesc, ignoreBits);
1104 std::ostringstream errMsg;
1105 errMsg <<
"in-memory field " << GetQualifiedFieldName() <<
" of type " << GetTypeName() <<
" is incompatible "
1106 <<
"with on-disk field " << fieldDesc.GetFieldName() <<
":";
1107 if (diffBits & kDiffFieldVersion) {
1108 errMsg <<
" field version " << GetFieldVersion() <<
" vs. " << fieldDesc.GetFieldVersion() <<
";";
1110 if (diffBits & kDiffTypeVersion) {
1111 errMsg <<
" type version " << GetTypeVersion() <<
" vs. " << fieldDesc.GetTypeVersion() <<
";";
1113 if (diffBits & kDiffStructure) {
1114 errMsg <<
" structural role " << GetStructure() <<
" vs. " << fieldDesc.GetStructure() <<
";";
1116 if (diffBits & kDiffTypeName) {
1117 errMsg <<
" incompatible on-disk type name " << fieldDesc.GetTypeName() <<
";";
1119 if (diffBits & kDiffNRepetitions) {
1120 errMsg <<
" repetition count " << GetNRepetitions() <<
" vs. " << fieldDesc.GetNRepetitions() <<
";";
1127 std::uint32_t ignoreBits = kDiffTypeName;
1129 ignoreBits |= kDiffTypeVersion;
1130 return EnsureMatchingOnDiskField(desc, ignoreBits);
1134 const std::vector<std::string> &prefixes)
const
1137 for (
const auto &
p : prefixes) {
1138 if (fieldDesc.GetTypeName().rfind(
p, 0) == 0)
1141 return R__FAIL(
"incompatible type " + fieldDesc.GetTypeName() +
" for field " + GetQualifiedFieldName() +
"\n" +
1147 std::uint32_t diffBits = 0;
1148 if ((~ignoreBits & kDiffFieldVersion) && (GetFieldVersion() != fieldDesc.
GetFieldVersion()))
1149 diffBits |= kDiffFieldVersion;
1150 if ((~ignoreBits & kDiffTypeVersion) && (GetTypeVersion() != fieldDesc.
GetTypeVersion()))
1151 diffBits |= kDiffTypeVersion;
1152 if ((~ignoreBits & kDiffStructure) && (GetStructure() != fieldDesc.
GetStructure()))
1153 diffBits |= kDiffStructure;
1154 if ((~ignoreBits & kDiffTypeName) && (GetTypeName() != fieldDesc.
GetTypeName()))
1155 diffBits |= kDiffTypeName;
1156 if ((~ignoreBits & kDiffNRepetitions) && (GetNRepetitions() != fieldDesc.
GetNRepetitions()))
1157 diffBits |= kDiffNRepetitions;
#define R__FORWARD_RESULT(res)
Short-hand to return an RResult<T> value from a subroutine to the calling stack frame.
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
#define R__LOG_WARNING(...)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
winID h TVirtualViewer3D TVirtualGLPainter p
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 r
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 id
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 child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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
Abstract base class for classes implementing the visitor design pattern.
virtual void VisitField(const ROOT::RFieldBase &field)=0
static const char * GetColumnTypeName(ROOT::ENTupleColumnType type)
Abstract interface to write data into an ntuple.
const ROOT::RNTupleWriteOptions & GetWriteOptions() const
Returns the sink's write options.
virtual void UpdateExtraTypeInfo(const ROOT::RExtraTypeInfoDescriptor &extraTypeInfo)=0
Adds an extra type information record to schema.
void RegisterOnCommitDatasetCallback(const Callback_t &cb)
The registered callback is executed at the beginning of CommitDataset();.
Abstract interface to read data from an ntuple.
RSharedDescriptorGuard GetSharedDescriptorGuard() const
Takes the read lock for the descriptor.
Template specializations for C++ std::atomic.
Base class for all ROOT issued exceptions.
Points to an array of objects with RNTuple I/O support, used for bulk reading.
std::unique_ptr< bool[]> fMaskAvail
Masks invalid values in the array.
std::unique_ptr< RFieldBase::RDeleter > fDeleter
void Reset(RNTupleLocalIndex firstIndex, std::size_t size)
Sets a new range for the bulk.
void * fValues
Cached deleter of fField.
RBulkValues & operator=(const RBulkValues &)=delete
RBulkValues(RFieldBase *field)
void AdoptBuffer(void *buf, std::size_t capacity)
The list of column representations a field can have.
std::vector< ColumnRepresentation_t > Selection_t
A list of column representations.
Selection_t fDeserializationTypes
The union of the serialization types and the deserialization extra types passed during construction.
void DeleteAligned(void *objPtr) const
Iterates over the subtree of fields in depth-first search order.
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
void BindRawPtr(void *rawPtr)
A field translates read and write calls from/to underlying columns to/from tree values.
void Attach(std::unique_ptr< RFieldBase > child, std::string_view expectedChildName="")
Add a new subfield to the list of nested fields.
void SetColumnRepresentatives(const RColumnRepresentations::Selection_t &representatives)
Fixes a column representative.
ROOT::Internal::RColumn * fPrincipalColumn
All fields that have columns have a distinct main column.
virtual void ReconcileOnDiskField(const RNTupleDescriptor &desc)
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
ROOT::NTupleSize_t EntryToColumnElementIndex(ROOT::NTupleSize_t globalIndex) const
Translate an entry index to a column element index of the principal column.
virtual void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const
void FlushColumns()
Flushes data from active columns.
virtual void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to)
virtual const RColumnRepresentations & GetColumnRepresentations() const
Implementations in derived classes should return a static RColumnRepresentations object.
bool fIsSimple
A field qualifies as simple if it is mappable (which implies it has a single principal column),...
RConstSchemaIterator cbegin() const
void AutoAdjustColumnTypes(const ROOT::RNTupleWriteOptions &options)
When connecting a field to a page sink, the field's default column representation is subject to adjus...
std::vector< const RFieldBase * > GetConstSubfields() const
void SetOnDiskId(ROOT::DescriptorId_t id)
void RemoveReadCallback(size_t idx)
size_t AddReadCallback(const ReadCallback_t &func)
Set a user-defined function to be called after reading a value, giving a chance to inspect and/or mod...
const RFieldBase * GetParent() const
std::vector< RFieldBase * > GetMutableSubfields()
static std::vector< RCheckResult > Check(const std::string &fieldName, const std::string &typeName)
Checks if the given type is supported by RNTuple.
RResult< void > EnsureMatchingOnDiskCollection(const RNTupleDescriptor &desc) const
Convenience wrapper for the common case of calling EnsureMatchinOnDiskField() for collections.
RConstSchemaIterator cend() const
std::size_t fNRepetitions
For fixed sized arrays, the array length.
std::function< void(void *)> ReadCallback_t
std::size_t Append(const void *from)
Write the given value into columns.
@ kTraitTriviallyDestructible
The type is cleaned up just by freeing its memory. I.e. the destructor performs a no-op.
@ kTraitTriviallyConstructible
No constructor needs to be called, i.e.
@ kTraitMappable
A field of a fundamental type that can be directly mapped via RField<T>::Map(), i....
@ kTraitInvalidField
This field is an instance of RInvalidField and can be safely static_cast to it.
RValue CreateValue()
Generates an object of the field's type, wraps it in a shared pointer and returns it as an RValue con...
const ColumnRepresentation_t & EnsureCompatibleColumnTypes(const ROOT::RNTupleDescriptor &desc, std::uint16_t representationIndex) const
Returns the on-disk column types found in the provided descriptor for fOnDiskId and the given represe...
virtual std::vector< RValue > SplitValue(const RValue &value) const
Creates the list of direct child values given an existing value for this field.
std::string GetQualifiedFieldName() const
Returns the field name and parent field names separated by dots (grandparent.parent....
RBulkValues CreateBulk()
Creates a new, initially empty bulk.
void ConnectPageSink(ROOT::Internal::RPageSink &pageSink, ROOT::NTupleSize_t firstEntry=0)
Fields and their columns live in the void until connected to a physical page storage.
std::size_t ReadBulk(const RBulkSpec &bulkSpec)
Returns the number of newly available values, that is the number of bools in bulkSpec....
std::vector< ROOT::ENTupleColumnType > ColumnRepresentation_t
RResult< void > EnsureMatchingOnDiskField(const RNTupleDescriptor &desc, std::uint32_t ignoreBits=0) const
Compares the field to the corresponding on-disk field information in the provided descriptor.
virtual void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to)
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
virtual std::size_t AppendImpl(const void *from)
Operations on values of complex types, e.g.
RFieldBase * fParent
Subfields point to their mother field.
RFieldBase(std::string_view name, std::string_view type, ROOT::ENTupleStructure structure, bool isSimple, std::size_t nRepetitions=0)
The constructor creates the underlying column objects and connects them to either a sink or a source.
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId)
Factory method to resurrect a field from the stored on-disk type information.
std::uint32_t CompareOnDiskField(const RFieldDescriptor &fieldDesc, std::uint32_t ignoreBits) const
Returns a combination of kDiff... flags, indicating peroperties that are different between the field ...
std::string fType
The C++ type captured by this field.
RColumnRepresentations::Selection_t GetColumnRepresentatives() const
Returns the fColumnRepresentative pointee or, if unset (always the case for artificial fields),...
ROOT::ENTupleStructure fStructure
The role of this field in the data model structure.
RValue BindValue(std::shared_ptr< void > objPtr)
Creates a value from a memory location with an already constructed object.
void SetDescription(std::string_view description)
std::unique_ptr< RFieldBase > Clone(std::string_view newName) const
Copies the field and its subfields using a possibly new name and a new, unconnected set of columns.
std::string fName
The field name relative to its parent field.
void CommitCluster()
Flushes data from active columns to disk and calls CommitClusterImpl()
void ConnectPageSource(ROOT::Internal::RPageSource &pageSource)
Connects the field and its subfield tree to the given page source.
RResult< void > EnsureMatchingTypePrefix(const RNTupleDescriptor &desc, const std::vector< std::string > &prefixes) const
Many fields accept a range of type prefixes for schema evolution, e.g.
void * CreateObjectRawPtr() const
Factory method for the field's type. The caller owns the returned pointer.
virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec)
General implementation of bulk read.
Metadata stored for every field of an RNTuple.
std::uint32_t GetFieldVersion() const
ROOT::ENTupleStructure GetStructure() const
const std::vector< ROOT::DescriptorId_t > & GetLinkIds() const
std::uint64_t GetNRepetitions() const
std::uint32_t GetTypeVersion() const
const std::string & GetTypeName() const
The container field for an ntuple model, which itself has no physical representation.
void Attach(std::unique_ptr< RFieldBase > child)
A public version of the Attach method that allows piece-wise construction of the zero field.
Classes with dictionaries that can be inspected by TClass.
Used in RFieldBase::Check() to record field creation failures.
@ kGeneric
Generic unrecoverable error.
@ kUnknownType
The type given to RFieldBase::Create was unknown.
@ kTypeError
The type given to RFieldBase::Create was invalid.
The on-storage metadata of an RNTuple.
const RFieldDescriptor & GetFieldDescriptor(ROOT::DescriptorId_t fieldId) const
RColumnDescriptorIterable GetColumnIterable() const
ROOT::DescriptorId_t FindFieldId(std::string_view fieldName, ROOT::DescriptorId_t parentId) const
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Common user-tunable settings for storing RNTuples.
std::uint32_t GetCompression() const
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
The field for a class using ROOT standard streaming.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
std::vector< std::string > TokenizeTypeList(std::string_view templateType, std::size_t maxArgs=0)
Used in RFieldBase::Create() in order to get the comma-separated list of template types E....
std::unique_ptr< RFieldBase > CreateEmulatedVectorField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField, std::string_view emulatedFromType)
RResult< void > EnsureValidNameForRNTuple(std::string_view name, std::string_view where)
Check whether a given string is a valid name according to the RNTuple specification.
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
void CallCommitClusterOnField(RFieldBase &)
void CallConnectPageSourceOnField(RFieldBase &, ROOT::Internal::RPageSource &)
unsigned long long ParseUIntTypeToken(const std::string &uintToken)
std::unique_ptr< RFieldBase > CreateEmulatedRecordField(std::string_view fieldName, std::vector< std::unique_ptr< RFieldBase > > itemFields, std::string_view emulatedFromType)
std::string GetRNTupleSoARecord(const TClass *cl)
Checks if the "rntuple.SoARecord" class attribute is set in the dictionary.
ROOT::RResult< std::unique_ptr< ROOT::RFieldBase > > CallFieldBaseCreate(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId)
std::string GetTypeTraceReport(const RFieldBase &field, const RNTupleDescriptor &desc)
Prints the hierarchy of types with their field names and field IDs for the given in-memory field and ...
auto MakeAliasedSharedPtr(T *rawPtr)
std::string GetCanonicalTypePrefix(const std::string &typeName)
Applies RNTuple specific type name normalization rules (see specs) that help the string parsing in RF...
void CallFlushColumnsOnField(RFieldBase &)
std::unique_ptr< RFieldBase > CreateEmulatedEnumField(std::string_view fieldName, std::string_view emulatedFromType, std::string_view underlyingIntType)
bool IsCustomEnumFieldDesc(const RNTupleDescriptor &desc, const RFieldDescriptor &fieldDesc)
Tells if the field describes a user-defined enum type.
std::string GetNormalizedUnresolvedTypeName(const std::string &origName)
Applies all RNTuple type normalization rules except typedef resolution.
ERNTupleSerializationMode GetRNTupleSerializationMode(const TClass *cl)
bool IsStdAtomicFieldDesc(const RFieldDescriptor &fieldDesc)
Tells if the field describes a std::atomic<T> type.
void CallConnectPageSinkOnField(RFieldBase &, ROOT::Internal::RPageSink &, ROOT::NTupleSize_t firstEntry=0)
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
ENTupleStructure
The fields in the RNTuple data model tree can carry different structural information about the type s...
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
void SetReturnInvalidOnError(bool v)
bool GetReturnInvalidOnError() const
bool GetEmulateUnknownTypes() const
Input parameter to RFieldBase::ReadBulk() and RFieldBase::ReadBulkImpl().
RNTupleLocalIndex fFirstIndex
Start of the bulk range.
void * fValues
The destination area, which has to be an array of valid objects of the correct type large enough to h...
std::size_t fCount
Size of the bulk range.
bool * fMaskAvail
A bool array of size fCount, indicating the valid values in fValues.
const bool * fMaskReq
A bool array of size fCount, indicating the required values in the requested range.
Used in the return value of the Check() method.
std::default_delete< T > deleter