17std::vector<ROOT::RFieldBase::RValue> SplitVector(
const std::shared_ptr<void> &valuePtr,
ROOT::RFieldBase &itemField)
19 auto *vec =
static_cast<std::vector<char> *
>(valuePtr.get());
23 const auto nItems = vec->size() / itemSize;
24 std::vector<ROOT::RFieldBase::RValue>
result;
26 for (
unsigned i = 0; i < nItems; ++i) {
27 result.emplace_back(itemField.
BindValue(std::shared_ptr<void>(valuePtr, vec->data() + (i * itemSize))));
32std::size_t GetSizeOfVector()
34 return sizeof(std::vector<char>);
37std::size_t GetAlignOfVector()
39 return alignof(std::vector<char>);
42void ConstructVector(
void *where, std::size_t alignOfValue)
46 switch (alignOfValue) {
60 default:
throw ROOT::RException(
R__FAIL(std::string(
"Unsupported alignment: ") + std::to_string(alignOfValue)));
68 std::size_t arrayLength)
70 "std::array<" + itemField->GetTypeName() +
"," +
73 fItemSize(itemField->GetValueSize()),
74 fArrayLength(arrayLength)
77 if (arrayLength == 0) {
80 fTraits |= itemField->GetTraits() & ~kTraitMappable;
81 if (!itemField->GetTypeAlias().empty()) {
82 fTypeAlias =
"std::array<" + itemField->GetTypeAlias() +
"," +
85 Attach(std::move(itemField),
"_0");
90 auto newItemField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
91 return std::make_unique<RArrayField>(newName, std::move(newItemField), fArrayLength);
96 std::size_t nbytes = 0;
97 if (fSubfields[0]->IsSimple()) {
98 GetPrincipalColumnOf(*fSubfields[0])->AppendV(from, fArrayLength);
99 nbytes += fArrayLength * GetPrincipalColumnOf(*fSubfields[0])->GetElement()->GetPackedSize();
101 auto arrayPtr =
static_cast<const unsigned char *
>(from);
102 for (
unsigned i = 0; i < fArrayLength; ++i) {
103 nbytes += CallAppendOn(*fSubfields[0], arrayPtr + (i * fItemSize));
111 if (fSubfields[0]->IsSimple()) {
112 GetPrincipalColumnOf(*fSubfields[0])->ReadV(globalIndex * fArrayLength, fArrayLength, to);
114 auto arrayPtr =
static_cast<unsigned char *
>(to);
115 for (
unsigned i = 0; i < fArrayLength; ++i) {
116 CallReadOn(*fSubfields[0], globalIndex * fArrayLength + i, arrayPtr + (i * fItemSize));
123 if (fSubfields[0]->IsSimple()) {
124 GetPrincipalColumnOf(*fSubfields[0])->ReadV(localIndex * fArrayLength, fArrayLength, to);
126 auto arrayPtr =
static_cast<unsigned char *
>(to);
127 for (
unsigned i = 0; i < fArrayLength; ++i) {
128 CallReadOn(*fSubfields[0], localIndex * fArrayLength + i, arrayPtr + (i * fItemSize));
135 if (!fSubfields[0]->IsSimple())
138 GetPrincipalColumnOf(*fSubfields[0])
140 return RBulkSpec::kAllSet;
145 static const std::vector<std::string> prefixes = {
"std::array<"};
147 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
148 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
153 if (fSubfields[0]->GetTraits() & kTraitTriviallyConstructible)
156 auto arrayPtr =
reinterpret_cast<unsigned char *
>(where);
157 for (
unsigned i = 0; i < fArrayLength; ++i) {
158 CallConstructValueOn(*fSubfields[0], arrayPtr + (i * fItemSize));
165 for (
unsigned i = 0; i < fArrayLength; ++i) {
166 fItemDeleter->operator()(
reinterpret_cast<unsigned char *
>(objPtr) + i * fItemSize,
true );
169 RDeleter::operator()(objPtr, dtorOnly);
174 if (!(fSubfields[0]->GetTraits() & kTraitTriviallyDestructible))
175 return std::make_unique<RArrayDeleter>(fItemSize, fArrayLength, GetAlignment(), GetDeleterOf(*fSubfields[0]));
176 return std::make_unique<RDeleter>(GetAlignment());
181 auto valuePtr =
value.GetPtr<
void>();
182 auto arrayPtr =
static_cast<unsigned char *
>(valuePtr.get());
183 std::vector<RValue>
result;
184 result.reserve(fArrayLength);
185 for (
unsigned i = 0; i < fArrayLength; ++i) {
186 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(valuePtr, arrayPtr + (i * fItemSize))));
199 :
ROOT::
RFieldBase(fieldName,
"ROOT::VecOps::RVec<" + itemField->GetTypeName() +
">",
201 fItemSize(itemField->GetValueSize()),
205 if (itemField->GetAlignment() >
sizeof(std::max_align_t)) {
212 if (!itemField->GetTypeAlias().empty())
213 fTypeAlias =
"ROOT::VecOps::RVec<" + itemField->GetTypeAlias() +
">";
214 Attach(std::move(itemField),
"_0");
223 auto grandChildFields =
fSubfields[0]->GetMutableSubfields();
224 if (grandChildFields[0]->
IsSimple()) {
234 auto newItemField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
235 return std::make_unique<RRVecField>(newName, std::move(newItemField));
242 std::size_t nbytes = 0;
243 if (fSubfields[0]->IsSimple() && *sizePtr) {
244 GetPrincipalColumnOf(*fSubfields[0])->AppendV(*beginPtr, *sizePtr);
245 nbytes += *sizePtr * GetPrincipalColumnOf(*fSubfields[0])->GetElement()->GetPackedSize();
247 for (std::int32_t i = 0; i < *sizePtr; ++i) {
248 nbytes += CallAppendOn(*fSubfields[0], *beginPtr + i * fItemSize);
252 fNWritten += *sizePtr;
253 fPrincipalColumn->Append(&fNWritten);
254 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
261 if (nItems >
static_cast<std::size_t
>(std::numeric_limits<std::int32_t>::max())) {
266 const std::size_t oldSize = *sizePtr;
268 if (oldSize == nItems) {
277 const bool owns = (*capacityPtr != -1);
278 const bool needsConstruct = !(itemField->
GetTraits() & kTraitTriviallyConstructible);
279 const bool needsDestruct = owns && itemDeleter;
283 for (std::size_t i = nItems; i < oldSize; ++i) {
284 itemDeleter->operator()(*beginPtr + (i * itemSize),
true );
294 static constexpr std::int32_t kSmallThreshold = 16;
295 if ((std::int32_t(nItems) > *capacityPtr) ||
296 ((std::int32_t(nItems) > kSmallThreshold) && (std::int32_t(nItems) < *capacityPtr / 4))) {
301 for (std::size_t i = 0u; i < std::min(oldSize, nItems); ++i) {
302 itemDeleter->operator()(*beginPtr + (i * itemSize),
true );
307 std::size_t newCapacity = nItems;
308 if (*capacityPtr > 0) {
309 constexpr std::size_t maxSize =
static_cast<std::size_t
>(std::numeric_limits<std::int32_t>::max());
310 const std::size_t oldCap =
static_cast<std::size_t
>(*capacityPtr);
311 if (nItems > oldCap) {
312 const std::size_t grown = oldCap + ((oldCap < kSmallThreshold) ? oldCap : (oldCap / 2));
313 newCapacity = std::min(maxSize, std::max(nItems, grown));
315 newCapacity = oldCap / 2;
316 assert(nItems <= newCapacity);
322 *beginPtr =
static_cast<unsigned char *
>(::operator
new(newCapacity * itemSize, std::nothrow));
324 *capacityPtr =
static_cast<std::int32_t
>(newCapacity);
330 if (needsConstruct) {
331 for (std::size_t i = 0u; i < std::min(oldSize, nItems); ++i)
332 CallConstructValueOn(*itemField, *beginPtr + (i * itemSize));
338 if (needsConstruct) {
339 for (std::size_t i = oldSize; i < nItems; ++i)
340 CallConstructValueOn(*itemField, *beginPtr + (i * itemSize));
354 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
356 auto begin = ResizeRVec(to, nItems, fItemSize, fSubfields[0].get(), fItemDeleter.get());
358 if (fSubfields[0]->IsSimple() && nItems) {
359 GetPrincipalColumnOf(*fSubfields[0])->ReadV(collectionStart, nItems, begin);
364 for (std::size_t i = 0; i < nItems; ++i) {
365 CallReadOn(*fSubfields[0], collectionStart + i, begin + (i * fItemSize));
377 bulkSpec.
fAuxData->resize(
sizeof(std::size_t));
378 *
reinterpret_cast<std::size_t *
>(bulkSpec.
fAuxData->data()) = fBulkNRepetition * fBulkSubfield->GetValueSize();
380 const auto itemValueSize = *
reinterpret_cast<std::size_t *
>(bulkSpec.
fAuxData->data());
381 unsigned char *itemValueArray = bulkSpec.
fAuxData->data() +
sizeof(std::size_t);
387 fPrincipalColumn->GetCollectionInfo(bulkSpec.
fFirstIndex, &firstItemIndex, &collectionSize);
388 *beginPtr = itemValueArray;
389 *sizePtr = collectionSize;
397 std::size_t nValues = 1;
398 std::size_t nItems = collectionSize;
399 while (nRemainingValues > 0) {
403 const std::size_t nBatch = std::min(nRemainingValues, nElementsUntilPageEnd);
404 for (std::size_t i = 0; i < nBatch; ++i) {
405 const auto size = offsets[i] - lastOffset;
407 reinterpret_cast<unsigned char *
>(bulkSpec.
fValues) + (nValues + i) *
fValueSize);
408 *beginPtr = itemValueArray + nItems * itemValueSize;
413 lastOffset = offsets[i];
415 nRemainingValues -= nBatch;
419 bulkSpec.
fAuxData->resize(
sizeof(std::size_t) + nItems * itemValueSize);
421 const auto delta = itemValueArray - (bulkSpec.
fAuxData->data() +
sizeof(std::size_t));
423 auto beginPtrAsUChar =
reinterpret_cast<unsigned char *
>(bulkSpec.
fValues);
424 for (std::size_t i = 0; i < bulkSpec.
fCount; ++i) {
425 *
reinterpret_cast<unsigned char **
>(beginPtrAsUChar) -= delta;
430 GetPrincipalColumnOf(*fBulkSubfield)
431 ->ReadV(firstItemIndex * fBulkNRepetition, nItems * fBulkNRepetition, itemValueArray - delta);
432 return RBulkSpec::kAllSet;
442 return representations;
447 GenerateColumnsImpl<ROOT::Internal::RColumnIndex>();
452 GenerateColumnsImpl<ROOT::Internal::RColumnIndex>(desc);
462 if (fieldDesc.GetTypeName().rfind(
"std::array<", 0) == 0) {
463 auto substitute = std::make_unique<RArrayAsRVecField>(
464 GetFieldName(), fSubfields[0]->Clone(fSubfields[0]->GetFieldName()), fieldDesc.GetNRepetitions());
465 substitute->SetOnDiskId(GetOnDiskId());
473 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
480 void **beginPtr =
new (where)(
void *)(
nullptr);
481 std::int32_t *sizePtr =
new (
reinterpret_cast<void *
>(beginPtr + 1)) std::int32_t(0);
482 new (sizePtr + 1) std::int32_t(-1);
490 for (std::int32_t i = 0; i < *sizePtr; ++i) {
491 fItemDeleter->operator()(*beginPtr + i * fItemSize,
true );
496 RDeleter::operator()(objPtr, dtorOnly);
502 return std::make_unique<RRVecDeleter>(fSubfields[0]->GetAlignment(), fItemSize, GetDeleterOf(*fSubfields[0]));
503 return std::make_unique<RRVecDeleter>(fSubfields[0]->GetAlignment());
510 std::vector<RValue>
result;
512 for (std::int32_t i = 0; i < *sizePtr; ++i) {
514 fSubfields[0]->BindValue(std::shared_ptr<void>(
value.GetPtr<
void>(), *beginPtr + i * fItemSize)));
539 emulatedFrom ? emulatedFrom->GetTypeName() :
"std::vector<" + itemField->GetTypeName() +
">",
541 fItemSize(itemField->GetValueSize()),
546 R__FAIL(std::string(
"Unsupported vector item alignment: ") + std::to_string(itemField->GetAlignment())));
549 if (emulatedFrom && !emulatedFrom->
GetTypeName().empty()) {
557 if (!itemField->GetTypeAlias().empty())
558 fTypeAlias =
"std::vector<" + itemField->GetTypeAlias() +
">";
562 Attach(std::move(itemField),
"_0");
566 :
RVectorField(fieldName, std::move(itemField), nullptr)
571std::unique_ptr<ROOT::RVectorField>
575 return std::unique_ptr<ROOT::RVectorField>(
new RVectorField(fieldName, itemField->Clone(
"_0"), &desc));
580 auto newItemField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
581 auto isUntyped = GetTypeName().empty() || ((fTraits & kTraitEmulatedField) != 0);
586 .TypeChecksum(GetTypeChecksum())
587 .TypeName(GetTypeName())
595 return std::unique_ptr<ROOT::RVectorField>(
596 new RVectorField(newName, std::move(newItemField), isUntyped ? &desc :
nullptr));
601 auto typedValue =
static_cast<const std::vector<char> *
>(from);
606 auto count = typedValue->size() / fItemSize;
607 R__ASSERT((typedValue->size() % fItemSize) == 0);
608 std::size_t nbytes = 0;
610 if (fSubfields[0]->IsSimple() && count) {
611 GetPrincipalColumnOf(*fSubfields[0])->AppendV(typedValue->data(), count);
612 nbytes += count * GetPrincipalColumnOf(*fSubfields[0])->GetElement()->GetPackedSize();
614 for (
unsigned i = 0; i < count; ++i) {
615 nbytes += CallAppendOn(*fSubfields[0], typedValue->data() + (i * fItemSize));
620 fPrincipalColumn->Append(&fNWritten);
621 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
627 auto typedValue =
static_cast<std::vector<char> *
>(vec);
630 assert(itemSize > 0);
631 const auto oldNItems = typedValue->size() / itemSize;
632 const auto availNItems = typedValue->capacity() / itemSize;
633 assert((typedValue->size() % itemSize == 0) && (typedValue->capacity() % itemSize == 0));
635 const bool canRealloc = availNItems < nItems;
636 bool allDeallocated =
false;
638 allDeallocated = canRealloc;
639 for (std::size_t i = allDeallocated ? 0 : nItems; i < oldNItems; ++i) {
640 itemDeleter->operator()(typedValue->data() + (i * itemSize),
true );
646 const auto nbytes = nItems * itemSize;
648 auto fnAlignedResize = [](
auto &vecOfAlignedStorage, std::size_t targetSize) {
649 constexpr auto valueTypeSize =
sizeof(
typename std::decay_t<
decltype(vecOfAlignedStorage)>::value_type);
650 constexpr auto valueTypeAlignment =
alignof(
typename std::decay_t<
decltype(vecOfAlignedStorage)>::value_type);
653 static_assert(valueTypeSize == valueTypeAlignment);
654 assert(targetSize % valueTypeAlignment == 0);
655 vecOfAlignedStorage.resize(targetSize / valueTypeSize);
658 static_assert(kMaxItemAlignment == 4096);
660 switch (itemAlignment) {
661 case 1: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 1>
> *>(vec), nbytes);
break;
662 case 2: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 2>
> *>(vec), nbytes);
break;
663 case 4: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 4>
> *>(vec), nbytes);
break;
664 case 8: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 8>
> *>(vec), nbytes);
break;
665 case 16: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 16>
> *>(vec), nbytes);
break;
666 case 32: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 32>
> *>(vec), nbytes);
break;
667 case 64: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 64>
> *>(vec), nbytes);
break;
668 case 128: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 128>
> *>(vec), nbytes);
break;
669 case 256: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 256>
> *>(vec), nbytes);
break;
670 case 512: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage< 512>
> *>(vec), nbytes);
break;
671 case 1024: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage<1024>
> *>(vec), nbytes);
break;
672 case 2048: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage<2048>
> *>(vec), nbytes);
break;
673 case 4096: fnAlignedResize(*
static_cast<std::vector<Internal::RAlignedStorage<4096>
> *>(vec), nbytes);
break;
674 default:
throw RException(
R__FAIL(std::string(
"Unsupported alignment: ") + std::to_string(itemAlignment)));
678 if (!(itemField.
GetTraits() & kTraitTriviallyConstructible)) {
679 for (std::size_t i = allDeallocated ? 0 : oldNItems; i < nItems; ++i) {
680 CallConstructValueOn(itemField, typedValue->data() + (i * itemSize));
687 auto typedValue =
static_cast<std::vector<char> *
>(to);
691 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
693 if (fSubfields[0]->IsSimple()) {
694 typedValue->resize(nItems * fItemSize);
696 GetPrincipalColumnOf(*fSubfields[0])->ReadV(collectionStart, nItems, typedValue->data());
700 ResizeVector(to, nItems, fItemSize, *fSubfields[0], fItemDeleter.get());
702 for (std::size_t i = 0; i < nItems; ++i) {
703 CallReadOn(*fSubfields[0], collectionStart + i, typedValue->data() + (i * fItemSize));
714 return representations;
719 GenerateColumnsImpl<ROOT::Internal::RColumnIndex>();
724 GenerateColumnsImpl<ROOT::Internal::RColumnIndex>(desc);
734 if (fieldDesc.GetTypeName().rfind(
"std::array<", 0) == 0) {
735 auto substitute = std::make_unique<RArrayAsVectorField>(
736 GetFieldName(), fSubfields[0]->Clone(fSubfields[0]->GetFieldName()), fieldDesc.GetNRepetitions());
737 substitute->SetOnDiskId(GetOnDiskId());
745 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
750 ConstructVector(where, fSubfields[0]->GetAlignment());
754 :
RDeleter(GetAlignOfVector()), fItemAlignment(itemAlignment)
759 std::unique_ptr<RDeleter> itemDeleter)
762 fItemAlignment(itemAlignment),
769 auto vecPtr =
static_cast<std::vector<char> *
>(objPtr);
772 auto nItems = vecPtr->size() /
fItemSize;
773 assert((vecPtr->size() %
fItemSize) == 0);
774 for (std::size_t i = 0; i < nItems; ++i) {
781 switch (fItemAlignment) {
782 case 1: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 1>
> *>(objPtr));
break;
783 case 2: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 2>
> *>(objPtr));
break;
784 case 4: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 4>
> *>(objPtr));
break;
785 case 8: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 8>
> *>(objPtr));
break;
786 case 16: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 16>
> *>(objPtr));
break;
787 case 32: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 32>
> *>(objPtr));
break;
788 case 64: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 64>
> *>(objPtr));
break;
789 case 128: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 128>
> *>(objPtr));
break;
790 case 256: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 256>
> *>(objPtr));
break;
791 case 512: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage< 512>
> *>(objPtr));
break;
792 case 1024: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage<1024>
> *>(objPtr));
break;
793 case 2048: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage<2048>
> *>(objPtr));
break;
794 case 4096: std::destroy_at(
static_cast<std::vector<Internal::RAlignedStorage<4096>
> *>(objPtr));
break;
795 default:
throw ROOT::RException(
R__FAIL(std::string(
"Unsupported alignment: ") + std::to_string(fItemAlignment)));
799 RDeleter::operator()(objPtr, dtorOnly);
816 return GetSizeOfVector();
821 return GetAlignOfVector();
839 auto typedValue =
static_cast<const std::vector<bool> *
>(from);
840 auto count = typedValue->size();
841 for (
unsigned i = 0; i < count; ++i) {
842 bool bval = (*typedValue)[i];
843 CallAppendOn(*fSubfields[0], &bval);
846 fPrincipalColumn->Append(&fNWritten);
847 return count + fPrincipalColumn->GetElement()->GetPackedSize();
852 auto typedValue =
static_cast<std::vector<bool> *
>(to);
854 if (fOnDiskNRepetitions == 0) {
856 RNTupleLocalIndex collectionStart;
857 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
858 typedValue->resize(nItems);
859 for (std::size_t i = 0; i < nItems; ++i) {
861 CallReadOn(*fSubfields[0], collectionStart + i, &bval);
862 (*typedValue)[i] = bval;
865 typedValue->resize(fOnDiskNRepetitions);
866 for (std::size_t i = 0; i < fOnDiskNRepetitions; ++i) {
868 CallReadOn(*fSubfields[0], globalIndex * fOnDiskNRepetitions + i, &bval);
869 (*typedValue)[i] = bval;
876 auto typedValue =
static_cast<std::vector<bool> *
>(to);
878 if (fOnDiskNRepetitions == 0) {
880 RNTupleLocalIndex collectionStart;
881 fPrincipalColumn->GetCollectionInfo(localIndex, &collectionStart, &nItems);
882 typedValue->resize(nItems);
883 for (std::size_t i = 0; i < nItems; ++i) {
885 CallReadOn(*fSubfields[0], collectionStart + i, &bval);
886 (*typedValue)[i] = bval;
889 typedValue->resize(fOnDiskNRepetitions);
890 for (std::size_t i = 0; i < fOnDiskNRepetitions; ++i) {
892 CallReadOn(*fSubfields[0], localIndex * fOnDiskNRepetitions + i, &bval);
893 (*typedValue)[i] = bval;
905 return representations;
911 GenerateColumnsImpl<ROOT::Internal::RColumnIndex>();
916 if (fOnDiskNRepetitions == 0)
917 GenerateColumnsImpl<ROOT::Internal::RColumnIndex>(desc);
922 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
924 if (fieldDesc.GetTypeName().rfind(
"std::array<", 0) == 0) {
925 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffStructure | kDiffNRepetitions).ThrowOnError();
927 if (fieldDesc.GetNRepetitions() == 0) {
928 throw RException(
R__FAIL(
"fixed-size array --> std::vector<bool>: expected repetition count > 0\n" +
932 throw RException(
R__FAIL(
"fixed-size array --> std::vector<bool>: expected plain on-disk field\n" +
935 fOnDiskNRepetitions = fieldDesc.GetNRepetitions();
937 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
943 const auto &typedValue =
value.GetRef<std::vector<bool>>();
944 auto count = typedValue.size();
945 std::vector<RValue>
result;
947 for (
unsigned i = 0; i < count; ++i) {
949 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<bool>(
new bool(
true))));
951 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<bool>(
new bool(
false))));
965 std::size_t arrayLength)
966 :
ROOT::
RFieldBase(fieldName,
"ROOT::VecOps::RVec<" + itemField->GetTypeName() +
">",
968 fItemSize(itemField->GetValueSize()),
969 fArrayLength(arrayLength)
971 if (!itemField->GetTypeAlias().empty())
972 fTypeAlias =
"ROOT::VecOps::RVec<" + itemField->GetTypeAlias() +
">";
973 Attach(std::move(itemField),
"_0");
982 auto newItemField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
983 return std::make_unique<RArrayAsRVecField>(newName, std::move(newItemField), fArrayLength);
990 void **beginPtr =
new (where)(
void *)(
nullptr);
991 std::int32_t *sizePtr =
new (
static_cast<void *
>(beginPtr + 1)) std::int32_t(0);
992 new (sizePtr + 1) std::int32_t(-1);
998 return std::make_unique<RRVecField::RRVecDeleter>(fSubfields[0]->GetAlignment(), fItemSize,
999 GetDeleterOf(*fSubfields[0]));
1001 return std::make_unique<RRVecField::RRVecDeleter>(fSubfields[0]->GetAlignment());
1006 auto begin =
RRVecField::ResizeRVec(to, fArrayLength, fItemSize, fSubfields[0].get(), fItemDeleter.get());
1008 if (fSubfields[0]->IsSimple()) {
1009 GetPrincipalColumnOf(*fSubfields[0])->ReadV(globalIndex * fArrayLength, fArrayLength, begin);
1014 for (std::size_t i = 0; i < fArrayLength; ++i) {
1015 CallReadOn(*fSubfields[0], globalIndex * fArrayLength + i, begin + (i * fItemSize));
1021 auto begin =
RRVecField::ResizeRVec(to, fArrayLength, fItemSize, fSubfields[0].get(), fItemDeleter.get());
1023 if (fSubfields[0]->IsSimple()) {
1024 GetPrincipalColumnOf(*fSubfields[0])->ReadV(localIndex * fArrayLength, fArrayLength, begin);
1029 for (std::size_t i = 0; i < fArrayLength; ++i) {
1030 CallReadOn(*fSubfields[0], localIndex * fArrayLength + i, begin + (i * fItemSize));
1036 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffStructure | kDiffNRepetitions).ThrowOnError();
1038 if (fieldDesc.GetTypeName().rfind(
"std::array<", 0) != 0) {
1039 throw RException(
R__FAIL(
"RArrayAsRVecField " + GetQualifiedFieldName() +
" expects an on-disk array field\n" +
1051 auto arrayPtr =
value.GetPtr<
unsigned char>().get();
1052 std::vector<ROOT::RFieldBase::RValue>
result;
1053 result.reserve(fArrayLength);
1054 for (
unsigned i = 0; i < fArrayLength; ++i) {
1056 fSubfields[0]->BindValue(std::shared_ptr<void>(
value.GetPtr<
void>(), arrayPtr + (i * fItemSize))));
1069 std::size_t arrayLength)
1072 fItemSize(itemField->GetValueSize()),
1073 fArrayLength(arrayLength)
1075 if (!itemField->GetTypeAlias().empty())
1076 fTypeAlias =
"std::vector<" + itemField->GetTypeAlias() +
">";
1077 Attach(std::move(itemField),
"_0");
1084 auto newItemField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
1085 return std::make_unique<RArrayAsVectorField>(newName, std::move(newItemField), fArrayLength);
1090 throw RException(
R__FAIL(
"RArrayAsVectorField fields must only be used for reading"));
1095 ConstructVector(where, fSubfields[0]->GetAlignment());
1101 return std::make_unique<RVectorField::RVectorDeleter>(fItemSize, fSubfields[0]->GetAlignment(),
1102 GetDeleterOf(*fSubfields[0]));
1104 return std::make_unique<RVectorField::RVectorDeleter>(fSubfields[0]->GetAlignment());
1109 auto typedValue =
static_cast<std::vector<char> *
>(to);
1111 if (fSubfields[0]->IsSimple()) {
1112 typedValue->resize(fArrayLength * fItemSize);
1113 GetPrincipalColumnOf(*fSubfields[0])->ReadV(globalIndex * fArrayLength, fArrayLength, typedValue->data());
1119 for (std::size_t i = 0; i < fArrayLength; ++i) {
1120 CallReadOn(*fSubfields[0], globalIndex * fArrayLength + i, typedValue->data() + (i * fItemSize));
1126 auto typedValue =
static_cast<std::vector<char> *
>(to);
1128 if (fSubfields[0]->IsSimple()) {
1129 typedValue->resize(fArrayLength * fItemSize);
1130 GetPrincipalColumnOf(*fSubfields[0])->ReadV(localIndex * fArrayLength, fArrayLength, typedValue->data());
1136 for (std::size_t i = 0; i < fArrayLength; ++i) {
1137 CallReadOn(*fSubfields[0], localIndex * fArrayLength + i, typedValue->data() + (i * fItemSize));
1143 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffStructure | kDiffNRepetitions);
1146 if (fieldDesc.GetTypeName().rfind(
"std::array<", 0) != 0) {
1147 throw RException(
R__FAIL(
"RArrayAsVectorField " + GetQualifiedFieldName() +
" expects an on-disk array field\n" +
1154 return SplitVector(
value.GetPtr<
void>(), *fSubfields[0]);
1159 return GetSizeOfVector();
1164 return GetAlignOfVector();
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
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.
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 value
Abstract base class for classes implementing the visitor design pattern.
virtual void VisitVectorField(const ROOT::RVectorField &field)
virtual void VisitVectorBoolField(const ROOT::RField< std::vector< bool > > &field)
virtual void VisitRVecField(const ROOT::RRVecField &field)
virtual void VisitArrayAsRVecField(const ROOT::RArrayAsRVecField &field)
virtual void VisitArrayAsVectorField(const ROOT::RArrayAsVectorField &field)
virtual void VisitArrayField(const ROOT::RArrayField &field)
The in-memory representation of a 32bit or 64bit on-disk index column.
A helper class for piece-wise construction of an RFieldDescriptor.
RResult< RFieldDescriptor > MoveDescriptor()
Attempt to make a field descriptor.
RFieldDescriptorBuilder & Structure(const ROOT::ENTupleStructure &structure)
RFieldDescriptorBuilder & TypeVersion(std::uint32_t typeVersion)
Abstract interface to read data from an ntuple.
RSharedDescriptorGuard GetSharedDescriptorGuard() const
Takes the read lock for the descriptor.
std::unique_ptr< RDeleter > fItemDeleter
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
RArrayAsRVecField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField, std::size_t arrayLength)
Constructor of the field.
std::size_t GetAlignment() const final
What alignof(T) for this type returns.
std::unique_ptr< RDeleter > GetDeleter() const final
Returns an RRVecField::RRVecDeleter.
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
The size of a value of this field, i.e. an RVec.
std::vector< RFieldBase::RValue > SplitValue(const RFieldBase::RValue &value) const final
Creates the list of direct child values given an existing value for this field.
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
std::size_t fValueSize
The length of the arrays in this field.
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
std::unique_ptr< RDeleter > GetDeleter() const final
Returns an RVectorField::RVectorDeleter.
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
std::unique_ptr< RDeleter > fItemDeleter
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
RArrayAsVectorField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField, std::size_t arrayLength)
The itemField argument represents the inner item of the on-disk array, i.e.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
std::vector< RFieldBase::RValue > SplitValue(const RFieldBase::RValue &value) const final
Creates the list of direct child values given an existing value for this field.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
The length of the arrays in this field.
std::size_t GetAlignment() const final
What alignof(T) for this type returns.
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
void operator()(void *objPtr, bool dtorOnly) final
Template specializations for C++ std::array and C-style arrays.
std::unique_ptr< RDeleter > GetDeleter() const final
RArrayField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField, std::size_t arrayLength)
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec) final
General implementation of bulk read.
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
Base class for all ROOT issued exceptions.
The list of column representations a field can have.
A functor to release the memory acquired by CreateValue() (memory and constructor).
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
A field translates read and write calls from/to underlying columns to/from tree values.
virtual size_t GetValueSize() const =0
What sizeof(T) for this type returns.
void Attach(std::unique_ptr< RFieldBase > child, std::string_view expectedChildName="")
Add a new subfield to the list of nested fields.
virtual size_t GetAlignment() const =0
What alignof(T) for this type returns.
std::vector< std::unique_ptr< RFieldBase > > fSubfields
Collections and classes own subfields.
static std::unique_ptr< RDeleter > GetDeleterOf(const RFieldBase &other)
std::string GetQualifiedFieldName() const
Returns the field name and parent field names separated by dots (grandparent.parent....
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
std::string fTypeAlias
A typedef or using name that was used when creating the field.
std::uint32_t GetTraits() const
RValue BindValue(std::shared_ptr< void > objPtr)
Creates a value from a memory location with an already constructed object.
@ kTraitEmulatedField
This field is a user defined type that was missing dictionaries and was reconstructed from the on-dis...
@ kTraitTriviallyDestructible
The type is cleaned up just by freeing its memory. I.e. the destructor performs a no-op.
@ kTraitSoACollection
The field represents a collection in SoA layout.
virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec)
General implementation of bulk read.
Metadata stored for every field of an RNTuple.
bool IsSoACollection() const
std::optional< std::uint32_t > GetTypeChecksum() const
std::uint32_t GetTypeVersion() const
const std::string & GetTypeName() const
Classes with dictionaries that can be inspected by TClass.
The on-storage metadata of an RNTuple.
const RFieldDescriptor & GetFieldDescriptor(ROOT::DescriptorId_t fieldId) const
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
ROOT::NTupleSize_t GetIndexInCluster() const
void operator()(void *objPtr, bool dtorOnly) final
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
size_t GetAlignment() const final
What alignof(T) for this type returns.
std::size_t fBulkNRepetition
std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec) final
General implementation of bulk read.
RRVecField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField)
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::unique_ptr< RFieldBase > BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate,...
size_t GetValueSize() const final
What sizeof(T) for this type returns.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
static unsigned char * ResizeRVec(void *rvec, std::size_t nItems, std::size_t itemSize, const RFieldBase *itemField, RDeleter *itemDeleter)
std::unique_ptr< RDeleter > fItemDeleter
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
RFieldBase * fBulkSubfield
May be a direct PoD subfield or a sub-subfield of a fixed-size array of PoD.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
std::unique_ptr< RDeleter > GetDeleter() const final
void operator()(void *objPtr, bool dtorOnly) final
RVectorDeleter(std::size_t itemAlignment)
Template specializations for C++ std::vector.
static std::unique_ptr< RVectorField > CreateUntyped(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField)
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
std::unique_ptr< RFieldBase > BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate,...
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
static void ResizeVector(void *vec, std::size_t nItems, std::size_t itemSize, const RFieldBase &itemField, RDeleter *itemDeleter)
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
RVectorField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField, const ROOT::RFieldDescriptor *emulatedFrom)
Creates a possibly-untyped VectorField.
std::size_t GetAlignment() const final
What alignof(T) for this type returns.
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
std::uint32_t fEmulatedTypeChecksum
std::unique_ptr< RDeleter > fItemDeleter
static constexpr std::size_t kMaxItemAlignment
Maximum alignment of the vector's value type.
std::unique_ptr< RDeleter > GetDeleter() const final
std::uint32_t fEmulatedTypeVersion
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
std::tuple< unsigned char **, std::int32_t *, std::int32_t * > GetRVecDataMembers(void *rvecPtr)
Retrieve the addresses of the data members of a generic RVec from a pointer to the beginning of the R...
void DestroyRVecWithChecks(std::size_t alignOfT, unsigned char **beginPtr, std::int32_t *capacityPtr)
std::string GetNormalizedInteger(const std::string &intTemplateArg)
Appends 'll' or 'ull' to the where necessary and strips the suffix if not needed.
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 ...
void EnsureTypedChildField(const RFieldBase &child, const RFieldBase &parent)
Makes sure that the type name is not empty. Used to prevent untyped fields as C++ inner types.
std::size_t EvalRVecAlignment(std::size_t alignOfSubfield)
std::size_t EvalRVecValueSize(std::size_t alignOfT, std::size_t sizeOfT, std::size_t alignOfRVecT)
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...
Storage type whose alignment matches AlignT bytes.
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.
std::vector< unsigned char > * fAuxData
Reference to memory owned by the RBulkValues class.