Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFieldMeta.cxx
Go to the documentation of this file.
1/// \file RFieldMeta.cxx
2/// \ingroup NTuple
3/// \author Jonas Hahnfeld <jonas.hahnfeld@cern.ch>
4/// \date 2024-11-19
5
6// This file has concrete RField implementations that depend on ROOT Meta:
7// - RClassField
8// - RSoAField
9// - REnumField
10// - RPairField
11// - RProxiedCollectionField
12// - RMapField
13// - RSetField
14// - RStreamerField
15// - RField<TObject>
16// - RVariantField
17
18#include <ROOT/RField.hxx>
19#include <ROOT/RFieldBase.hxx>
20#include <ROOT/RFieldUtils.hxx>
22#include <ROOT/RNTupleUtils.hxx>
23#include <ROOT/RSpan.hxx>
24
25#include <TBaseClass.h>
26#include <TBufferFile.h>
27#include <TClass.h>
28#include <TClassEdit.h>
29#include <TDataMember.h>
30#include <TEnum.h>
31#include <TObject.h>
32#include <TObjArray.h>
33#include <TObjString.h>
34#include <TRealData.h>
35#include <TSchemaRule.h>
36#include <TSchemaRuleSet.h>
37#include <TStreamerElement.h>
38#include <TVirtualObject.h>
40
41#include <algorithm>
42#include <array>
43#include <cstddef> // std::size_t
44#include <cstdint> // std::uint32_t et al.
45#include <cstring> // for memset
46#include <memory>
47#include <mutex>
48#include <string>
49#include <string_view>
50#include <unordered_set>
51#include <utility>
52#include <variant>
53
55
56namespace {
57
58TClass *EnsureValidClass(std::string_view className)
59{
60 auto cl = TClass::GetClass(std::string(className).c_str());
61 if (cl == nullptr) {
62 throw ROOT::RException(R__FAIL("RField: no I/O support for type " + std::string(className)));
63 }
64 return cl;
65}
66
67/// Common checks used both by RClassField and RSoAField
68void EnsureValidUserClass(TClass *cl, const ROOT::RFieldBase &field, std::string_view fieldType)
69{
70 if (cl->GetState() < TClass::kInterpreted) {
71 throw ROOT::RException(R__FAIL(std::string(fieldType) + " " + cl->GetName() +
72 " cannot be constructed from a class that's not at least Interpreted"));
73 }
74 // Avoid accidentally supporting std types through TClass.
75 if (cl->Property() & kIsDefinedInStd) {
76 throw ROOT::RException(R__FAIL(field.GetTypeName() + " is not supported"));
77 }
78 if (field.GetTypeName() == "TObject") {
79 throw ROOT::RException(R__FAIL("TObject is only supported through RField<TObject>"));
80 }
81 if (cl->GetCollectionProxy()) {
82 throw ROOT::RException(R__FAIL(field.GetTypeName() + " has an associated collection proxy; "
83 "use RProxiedCollectionField instead"));
84 }
85 // Classes with, e.g., custom streamers are not supported through this field. Empty classes, however, are.
86 // Can be overwritten with the "rntuple.streamerMode=true" class attribute
87 if (!cl->CanSplit() && cl->Size() > 1 &&
89 throw ROOT::RException(R__FAIL(field.GetTypeName() + " cannot be stored natively in RNTuple"));
90 }
93 throw ROOT::RException(
94 R__FAIL(field.GetTypeName() + " has streamer mode enforced, not supported as native RNTuple class"));
95 }
96 // Detect custom streamers set on individual members at runtime via
97 // TClass::SetMemberStreamer() or TClass::AdoptMemberStreamer().
98 // CanSplit() only checks for custom streamers set at compile time (fHasCustomStreamerMember),
99 // but runtime streamers are stored in TRealData and must be checked here.
100 if (!cl->GetListOfRealData()) {
101 cl->BuildRealData();
102 }
103 for (auto realMember : ROOT::Detail::TRangeStaticCast<TRealData>(*cl->GetListOfRealData())) {
104 if (realMember->GetStreamer()) {
105 throw ROOT::RException(R__FAIL(std::string(field.GetTypeName()) + " has member " + realMember->GetName() +
106 " with a custom streamer; not supported natively in RNTuple"));
107 }
108 }
109}
110
111TEnum *EnsureValidEnum(std::string_view enumName)
112{
113 auto e = TEnum::GetEnum(std::string(enumName).c_str());
114 if (e == nullptr) {
115 throw ROOT::RException(R__FAIL("RField: no I/O support for enum type " + std::string(enumName)));
116 }
117 return e;
118}
119
120/// Create a comma-separated list of type names from the given fields. Uses either the real type names or the
121/// type aliases (if there are any, otherwise the actual type name). Used to construct template argument lists
122/// for templated types such as std::pair<...>, std::tuple<...>, std::variant<...>.
123std::string GetTypeList(std::span<std::unique_ptr<ROOT::RFieldBase>> itemFields, bool useTypeAliases)
124{
125 std::string result;
126 for (size_t i = 0; i < itemFields.size(); ++i) {
127 if (useTypeAliases && !itemFields[i]->GetTypeAlias().empty()) {
128 result += itemFields[i]->GetTypeAlias();
129 } else {
130 result += itemFields[i]->GetTypeName();
131 }
132 result.push_back(',');
133 }
134 if (result.empty()) {
135 throw ROOT::RException(R__FAIL("invalid empty type list provided as template argument"));
136 }
137 result.pop_back(); // remove trailing comma
138 return result;
139}
140
142{
143 std::string typePrefix;
144 switch (setType) {
145 case ROOT::RSetField::ESetType::kSet: typePrefix = "std::set<"; break;
146 case ROOT::RSetField::ESetType::kUnorderedSet: typePrefix = "std::unordered_set<"; break;
147 case ROOT::RSetField::ESetType::kMultiSet: typePrefix = "std::multiset<"; break;
148 case ROOT::RSetField::ESetType::kUnorderedMultiSet: typePrefix = "std::unordered_multiset<"; break;
149 default: R__ASSERT(false);
150 }
151 return typePrefix +
152 ((useTypeAlias && !innerField.GetTypeAlias().empty()) ? innerField.GetTypeAlias()
153 : innerField.GetTypeName()) +
154 ">";
155}
156
158{
159 if (const auto pairField = dynamic_cast<const ROOT::RPairField *>(innerField)) {
160 std::string typePrefix;
161 switch (mapType) {
162 case ROOT::RMapField::EMapType::kMap: typePrefix = "std::map<"; break;
163 case ROOT::RMapField::EMapType::kUnorderedMap: typePrefix = "std::unordered_map<"; break;
164 case ROOT::RMapField::EMapType::kMultiMap: typePrefix = "std::multimap<"; break;
165 case ROOT::RMapField::EMapType::kUnorderedMultiMap: typePrefix = "std::unordered_multimap<"; break;
166 default: R__ASSERT(false);
167 }
168 const auto &items = pairField->GetConstSubfields();
169 std::string type = typePrefix;
170 for (int i : {0, 1}) {
171 if (useTypeAliases && !items[i]->GetTypeAlias().empty()) {
172 type += items[i]->GetTypeAlias();
173 } else {
174 type += items[i]->GetTypeName();
175 }
176 if (i == 0)
177 type.push_back(',');
178 }
179 return type + ">";
180 }
181
182 throw ROOT::RException(R__FAIL("RMapField inner field type must be of RPairField"));
183}
184
185} // anonymous namespace
186
188 : ROOT::RFieldBase(fieldName, source.GetTypeName(), ROOT::ENTupleStructure::kRecord, false /* isSimple */),
190 fSubfieldsInfo(source.fSubfieldsInfo),
191 fMaxAlignment(source.fMaxAlignment)
192{
193 for (const auto &f : source.GetConstSubfields()) {
194 RFieldBase::Attach(f->Clone(f->GetFieldName()));
195 }
196 fTraits = source.GetTraits();
197}
198
199ROOT::RClassField::RClassField(std::string_view fieldName, std::string_view className)
201{
202}
203
205 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kRecord,
206 false /* isSimple */),
208{
209 EnsureValidUserClass(fClass, *this, "RClassField");
210
212 throw ROOT::RException(R__FAIL(GetTypeName() + " is a SoA field and connot be used through RClassField"));
213 }
214
219
220 std::string renormalizedAlias;
223
224 int i = 0;
225 const auto *bases = fClass->GetListOfBases();
226 assert(bases);
228 if (baseClass->GetDelta() < 0) {
229 throw RException(R__FAIL(std::string("virtual inheritance is not supported: ") + GetTypeName() +
230 " virtually inherits from " + baseClass->GetName()));
231 }
232 TClass *c = baseClass->GetClassPointer();
233 auto subField =
234 RFieldBase::Create(std::string(kPrefixInherited) + "_" + std::to_string(i), c->GetName()).Unwrap();
235 fTraits &= subField->GetTraits();
236 Attach(std::move(subField), RSubfieldInfo{kBaseClass, static_cast<std::size_t>(baseClass->GetDelta())});
237 i++;
238 }
240 // Skip, for instance, unscoped enum constants defined in the class
241 if (dataMember->Property() & kIsStatic)
242 continue;
243 // Skip members explicitly marked as transient by user comment
244 if (!dataMember->IsPersistent()) {
245 // TODO(jblomer): we could do better
247 continue;
248 }
249
250 // NOTE: we use the already-resolved type name for the fields, otherwise TClass::GetClass may fail to resolve
251 // context-dependent types (e.g. typedefs defined in the class itself - which will not be fully qualified in
252 // the string returned by dataMember->GetFullTypeName())
253 std::string typeName{dataMember->GetTrueTypeName()};
254
255 // For C-style arrays, complete the type name with the size for each dimension, e.g. `int[4][2]`
256 if (dataMember->Property() & kIsArray) {
257 for (int dim = 0, n = dataMember->GetArrayDim(); dim < n; ++dim) {
258 typeName += "[" + std::to_string(dataMember->GetMaxIndex(dim)) + "]";
259 }
260 }
261
262 auto subField = RFieldBase::Create(dataMember->GetName(), typeName).Unwrap();
263
264 fTraits &= subField->GetTraits();
265 Attach(std::move(subField), RSubfieldInfo{kDataMember, static_cast<std::size_t>(dataMember->GetOffset())});
266 }
268}
269
271{
272 if (fStagingArea) {
273 for (const auto &[_, si] : fStagingItems) {
274 if (!(si.fField->GetTraits() & kTraitTriviallyDestructible)) {
275 auto deleter = GetDeleterOf(*si.fField);
276 deleter->operator()(fStagingArea.get() + si.fOffset, true /* dtorOnly */);
277 }
278 }
279 }
280}
281
282void ROOT::RClassField::Attach(std::unique_ptr<RFieldBase> child, RSubfieldInfo info)
283{
284 fMaxAlignment = std::max(fMaxAlignment, child->GetAlignment());
285 fSubfieldsInfo.push_back(info);
286 RFieldBase::Attach(std::move(child));
287}
288
289std::vector<const ROOT::TSchemaRule *> ROOT::RClassField::FindRules(const ROOT::RFieldDescriptor *fieldDesc)
290{
292 const auto ruleset = fClass->GetSchemaRules();
293 if (!ruleset)
294 return rules;
295
296 if (!fieldDesc) {
297 // If we have no on-disk information for the field, we still process the rules on the current in-memory version
298 // of the class
299 rules = ruleset->FindRules(fClass->GetName(), fClass->GetClassVersion(), fClass->GetCheckSum());
300 } else {
301 // We need to change (back) the name normalization from RNTuple to ROOT Meta
302 std::string normalizedName;
304 // We do have an on-disk field that correspond to the current RClassField instance. Ask for rules matching the
305 // on-disk version of the field.
306 if (fieldDesc->GetTypeChecksum()) {
307 rules = ruleset->FindRules(normalizedName, fieldDesc->GetTypeVersion(), *fieldDesc->GetTypeChecksum());
308 } else {
309 rules = ruleset->FindRules(normalizedName, fieldDesc->GetTypeVersion());
310 }
311 }
312
313 // Cleanup and sort rules
314 // Check that any any given source member uses the same type in all rules
315 std::unordered_map<std::string, std::string> sourceNameAndType;
316 std::size_t nskip = 0; // skip whole-object-rules that were moved to the end of the rules vector
317 for (auto itr = rules.begin(); itr != rules.end() - nskip;) {
318 const auto rule = *itr;
319
320 // Erase unknown rule types
321 if (rule->GetRuleType() != ROOT::TSchemaRule::kReadRule) {
323 << "ignoring I/O customization rule with unsupported type: " << rule->GetRuleType();
324 itr = rules.erase(itr);
325 continue;
326 }
327
328 bool hasConflictingSourceMembers = false;
329 for (auto source : TRangeDynCast<TSchemaRule::TSources>(rule->GetSource())) {
330 auto memberType = source->GetTypeForDeclaration() + source->GetDimensions();
331 auto [itrSrc, isNew] = sourceNameAndType.emplace(source->GetName(), memberType);
332 if (!isNew && (itrSrc->second != memberType)) {
334 << "ignoring I/O customization rule due to conflicting source member type: " << itrSrc->second << " vs. "
335 << memberType << " for member " << source->GetName();
337 break;
338 }
339 }
341 itr = rules.erase(itr);
342 continue;
343 }
344
345 // Rules targeting the entire object need to be executed at the end
346 if (rule->GetTarget() == nullptr) {
347 nskip++;
348 if (itr != rules.end() - nskip)
349 std::iter_swap(itr++, rules.end() - nskip);
350 continue;
351 }
352
353 ++itr;
354 }
355
356 return rules;
357}
358
359std::unique_ptr<ROOT::RFieldBase> ROOT::RClassField::CloneImpl(std::string_view newName) const
360{
361 return std::unique_ptr<RClassField>(new RClassField(newName, *this));
362}
363
364std::size_t ROOT::RClassField::AppendImpl(const void *from)
365{
366 std::size_t nbytes = 0;
367 for (unsigned i = 0; i < fSubfields.size(); i++) {
368 nbytes += CallAppendOn(*fSubfields[i], static_cast<const unsigned char *>(from) + fSubfieldsInfo[i].fOffset);
369 }
370 return nbytes;
371}
372
374{
375 for (const auto &[_, si] : fStagingItems) {
376 CallReadOn(*si.fField, globalIndex, fStagingArea.get() + si.fOffset);
377 }
378 for (unsigned i = 0; i < fSubfields.size(); i++) {
379 CallReadOn(*fSubfields[i], globalIndex, static_cast<unsigned char *>(to) + fSubfieldsInfo[i].fOffset);
380 }
381}
382
384{
385 for (const auto &[_, si] : fStagingItems) {
386 CallReadOn(*si.fField, localIndex, fStagingArea.get() + si.fOffset);
387 }
388 for (unsigned i = 0; i < fSubfields.size(); i++) {
389 CallReadOn(*fSubfields[i], localIndex, static_cast<unsigned char *>(to) + fSubfieldsInfo[i].fOffset);
390 }
391}
392
395{
398 return idSourceMember;
399
400 for (const auto &subFieldDesc : desc.GetFieldIterable(classFieldId)) {
401 const auto subFieldName = subFieldDesc.GetFieldName();
402 if (subFieldName.length() > 2 && subFieldName[0] == ':' && subFieldName[1] == '_') {
403 idSourceMember = LookupMember(desc, memberName, subFieldDesc.GetId());
405 return idSourceMember;
406 }
407 }
408
410}
411
412void ROOT::RClassField::SetStagingClass(const std::string &className, unsigned int classVersion)
413{
414 TClass::GetClass(className.c_str())->GetStreamerInfo(classVersion);
415 if (classVersion != GetTypeVersion() || className != GetTypeName()) {
416 fStagingClass = TClass::GetClass((className + std::string("@@") + std::to_string(classVersion)).c_str());
417 if (!fStagingClass) {
418 // For a rename rule, we may simply ask for the old class name
419 fStagingClass = TClass::GetClass(className.c_str());
420 }
421 } else {
422 fStagingClass = fClass;
423 }
424 R__ASSERT(fStagingClass);
425 R__ASSERT(static_cast<unsigned int>(fStagingClass->GetClassVersion()) == classVersion);
426}
427
428void ROOT::RClassField::PrepareStagingArea(const std::vector<const TSchemaRule *> &rules,
429 const ROOT::RNTupleDescriptor &desc,
431{
432 std::size_t stagingAreaSize = 0;
433 for (const auto rule : rules) {
434 for (auto source : TRangeDynCast<TSchemaRule::TSources>(rule->GetSource())) {
435 auto [itr, isNew] = fStagingItems.emplace(source->GetName(), RStagingItem());
436 if (!isNew) {
437 // This source member has already been processed by another rule (and we only support one type per member)
438 continue;
439 }
440 RStagingItem &stagingItem = itr->second;
441
442 const auto memberFieldId = LookupMember(desc, source->GetName(), classFieldDesc.GetId());
444 throw RException(R__FAIL(std::string("cannot find on disk rule source member ") + GetTypeName() + "." +
445 source->GetName()));
446 }
447
448 auto memberType = source->GetTypeForDeclaration() + source->GetDimensions();
449 auto memberField = Create("" /* we don't need a field name */, std::string(memberType)).Unwrap();
450 memberField->SetOnDiskId(memberFieldId);
451 auto fieldZero = std::make_unique<RFieldZero>();
453 fieldZero->Attach(std::move(memberField));
454 stagingItem.fField = std::move(fieldZero);
455
456 stagingItem.fOffset = fStagingClass->GetDataMemberOffset(source->GetName());
457 // Since we successfully looked up the source member in the RNTuple on-disk metadata, we expect it
458 // to be present in the TClass instance, too.
460 stagingAreaSize = std::max(stagingAreaSize, stagingItem.fOffset + stagingItem.fField->begin()->GetValueSize());
461 }
462 }
463
464 if (stagingAreaSize) {
465 R__ASSERT(static_cast<Int_t>(stagingAreaSize) <= fStagingClass->Size()); // we may have removed rules
466 // We use std::make_unique instead of MakeUninitArray to zero-initialize the staging area.
467 fStagingArea = std::make_unique<unsigned char[]>(stagingAreaSize);
468
469 for (const auto &[_, si] : fStagingItems) {
470 const auto &memberField = *si.fField->cbegin();
471 if (!(memberField.GetTraits() & kTraitTriviallyConstructible)) {
472 CallConstructValueOn(memberField, fStagingArea.get() + si.fOffset);
473 }
474 }
475 }
476}
477
479{
480 auto func = rule->GetReadFunctionPointer();
481 if (func == nullptr) {
482 // Can happen for rename rules
483 return;
484 }
485 fReadCallbacks.emplace_back([func, stagingClass = fStagingClass, stagingArea = fStagingArea.get()](void *target) {
486 TVirtualObject onfileObj{nullptr};
487 onfileObj.fClass = stagingClass;
488 onfileObj.fObject = stagingArea;
489 func(static_cast<char *>(target), &onfileObj);
490 onfileObj.fObject = nullptr; // TVirtualObject does not own the value
491 });
492}
493
495{
496 std::vector<const TSchemaRule *> rules;
497 // On-disk members that are not targeted by an I/O rule; all other sub fields of the in-memory class
498 // will be marked as artificial (added member in a new class version or member set by rule).
499 std::unordered_set<std::string> regularSubfields;
500 // We generally don't support changing the number of base classes, with the exception of changing from/to zero
501 // base classes. The variable stores the number of on-disk base classes.
502 int nOnDiskBaseClasses = 0;
503
504 if (GetOnDiskId() == kInvalidDescriptorId) {
505 // This can happen for added base classes or added members of class type
506 rules = FindRules(nullptr);
507 if (!rules.empty())
508 SetStagingClass(GetTypeName(), GetTypeVersion());
509 } else {
510 const auto descriptorGuard = pageSource.GetSharedDescriptorGuard();
511 const ROOT::RNTupleDescriptor &desc = descriptorGuard.GetRef();
512 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
513
514 if (fieldDesc.GetStructure() == ENTupleStructure::kStreamer) {
515 // Streamer field on disk but meanwhile the type can be represented as a class field; replace this field
516 // by a streamer field to read the data from disk.
517 auto substitute = std::make_unique<RStreamerField>(GetFieldName(), GetTypeName());
518 substitute->SetOnDiskId(GetOnDiskId());
519 return substitute;
520 }
521
522 for (auto linkId : fieldDesc.GetLinkIds()) {
523 const auto &subFieldDesc = desc.GetFieldDescriptor(linkId);
524 regularSubfields.insert(subFieldDesc.GetFieldName());
525 if (!subFieldDesc.GetFieldName().empty() && subFieldDesc.GetFieldName()[0] == ':')
527 }
528
529 rules = FindRules(&fieldDesc);
530
531 // If we found a rule, we know it is valid to read on-disk data because we found the rule according to the on-disk
532 // (source) type name and version/checksum.
533 if (rules.empty()) {
534 // Otherwise we require compatible type names, after renormalization. GetTypeName() is already renormalized,
535 // but RNTuple data written with ROOT v6.34 might not have renormalized the field type name. Ask the
536 // RNTupleDescriptor, which knows about the spec version, for a fixed up type name.
538 if (GetTypeName() != descTypeName) {
539 throw RException(R__FAIL("incompatible type name for field " + GetFieldName() + ": " + GetTypeName() +
540 " vs. " + descTypeName));
541 }
542 }
543
544 if (!rules.empty()) {
545 SetStagingClass(fieldDesc.GetTypeName(), fieldDesc.GetTypeVersion());
546 PrepareStagingArea(rules, desc, fieldDesc);
547 for (auto &[_, si] : fStagingItems) {
549 si.fField = std::move(static_cast<RFieldZero *>(si.fField.get())->ReleaseSubfields()[0]);
550 }
551
552 // Remove target member of read rules from the list of regular members of the underlying on-disk field
553 for (const auto rule : rules) {
554 if (!rule->GetTarget())
555 continue;
556
557 for (const auto target : ROOT::Detail::TRangeStaticCast<const TObjString>(*rule->GetTarget())) {
558 regularSubfields.erase(std::string(target->GetString()));
559 }
560 }
561 }
562 }
563
564 for (const auto rule : rules) {
565 AddReadCallbacksFromIORule(rule);
566 }
567
568 // Iterate over all sub fields in memory and mark those as missing that are not in the descriptor.
569 int nInMemoryBaseClasses = 0;
570 for (auto &field : fSubfields) {
571 const auto &fieldName = field->GetFieldName();
572 if (regularSubfields.count(fieldName) == 0) {
573 CallSetArtificialOn(*field);
574 }
575 if (!fieldName.empty() && fieldName[0] == ':')
577 }
578
580 throw RException(R__FAIL(std::string("incompatible number of base classes for field ") + GetFieldName() + ": " +
581 GetTypeName() + ", " + std::to_string(nInMemoryBaseClasses) +
582 " base classes in memory "
583 " vs. " +
584 std::to_string(nOnDiskBaseClasses) + " base classes on-disk\n" +
585 Internal::GetTypeTraceReport(*this, pageSource.GetSharedDescriptorGuard().GetRef())));
586 }
587
588 return nullptr;
589}
590
592{
593 EnsureMatchingOnDiskField(desc, kDiffTypeVersion | kDiffTypeName).ThrowOnError();
594}
595
597{
598 fClass->New(where);
599}
600
602{
603 fClass->Destructor(objPtr, true /* dtorOnly */);
604 RDeleter::operator()(objPtr, dtorOnly);
605}
606
607std::vector<ROOT::RFieldBase::RValue> ROOT::RClassField::SplitValue(const RValue &value) const
608{
609 std::vector<RValue> result;
610 auto valuePtr = value.GetPtr<void>();
611 auto charPtr = static_cast<unsigned char *>(valuePtr.get());
612 result.reserve(fSubfields.size());
613 for (unsigned i = 0; i < fSubfields.size(); i++) {
614 result.emplace_back(
615 fSubfields[i]->BindValue(std::shared_ptr<void>(valuePtr, charPtr + fSubfieldsInfo[i].fOffset)));
616 }
617 return result;
618}
619
621{
622 return fClass->GetClassSize();
623}
624
626{
627 return fClass->GetClassVersion();
628}
629
631{
632 return fClass->GetCheckSum();
633}
634
635const std::type_info *ROOT::RClassField::GetPolymorphicTypeInfo() const
636{
637 bool polymorphic = fClass->ClassProperty() & kClassHasVirtual;
638 if (!polymorphic) {
639 return nullptr;
640 }
641 return fClass->GetTypeInfo();
642}
643
645{
646 visitor.VisitClassField(*this);
647}
648
649//------------------------------------------------------------------------------
650
652 : ROOT::RFieldBase(fieldName, source.GetTypeName(), ROOT::ENTupleStructure::kCollection, false /* isSimple */),
653 fSoAClass(source.fSoAClass),
654 fSoAMemberOffsets(source.fSoAMemberOffsets),
655 fRecordMemberIndexes(source.fRecordMemberIndexes),
656 fMaxAlignment(source.fMaxAlignment)
657{
658 fTraits = source.GetTraits();
659 Attach(source.fSubfields[0]->Clone(source.fSubfields[0]->GetFieldName()));
660 fRecordMemberFields = fSubfields[0]->GetMutableSubfields();
661}
662
663ROOT::Experimental::RSoAField::RSoAField(std::string_view fieldName, std::string_view className)
665{
666}
667
669 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(clSoA->GetName()), ROOT::ENTupleStructure::kCollection,
670 false /* isSimple */),
671 fSoAClass(clSoA)
672{
673 static std::once_flag once;
674 std::call_once(once, []() {
675 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "The SoA field is experimental and still under development.";
676 });
677
678 EnsureValidUserClass(fSoAClass, *this, "RSoAField");
680 if (recordTypeName.empty()) {
681 throw ROOT::RException(R__FAIL(std::string("class ") + GetTypeName() +
682 " is not marked with the rntupleSoARecord "
683 "dictionary option; cannot create corresponding RSoAField."));
684 }
685 try {
686 Attach(std::make_unique<ROOT::RClassField>("_0", recordTypeName));
687 } catch (ROOT::RException &e) {
688 throw RException(R__FAIL("invalid record type of SoA field " + GetTypeName() + " [" + e.what() + "]"));
689 }
690 fRecordMemberFields = fSubfields[0]->GetMutableSubfields();
691
692 std::unordered_map<std::string, std::size_t> recordFieldNameToIdx;
693 for (std::size_t i = 0; i < fRecordMemberFields.size(); ++i) {
694 const RFieldBase *f = fRecordMemberFields[i];
695 assert(!f->GetFieldName().empty());
696 if (f->GetFieldName()[0] == ':') {
697 throw RException(R__FAIL("SoA fields with inheritance are currently unsupported"));
698 }
699 recordFieldNameToIdx[f->GetFieldName()] = i;
700 }
701
702 const auto *bases = fSoAClass->GetListOfBases();
703 assert(bases);
705 if (baseClass->GetDelta() < 0) {
706 throw RException(R__FAIL(std::string("virtual inheritance is not supported: ") + GetTypeName() +
707 " virtually inherits from " + baseClass->GetName()));
708 }
709 // At a later point, we will support inheritance
710 throw RException(R__FAIL("SoA fields with inheritance are currently unsupported"));
711 }
712
714 if ((dataMember->Property() & kIsStatic) || !dataMember->IsPersistent())
715 continue;
716
717 if (dataMember->Property() & kIsArray) {
718 throw RException(R__FAIL(std::string("unsupported array type in SoA class: ") + dataMember->GetName()));
719 }
720
721 const std::string typeName{dataMember->GetTrueTypeName()};
722 auto subField = RFieldBase::Create(dataMember->GetName(), typeName).Unwrap();
723 auto vecFieldPtr = dynamic_cast<RRVecField *>(subField.get());
724 if (!vecFieldPtr) {
725 throw RException(R__FAIL("invalid field type in SoA class: " + subField->GetTypeName()));
726 }
727 subField.release();
728 auto vecField = std::unique_ptr<RRVecField>(vecFieldPtr);
729
730 auto itr = recordFieldNameToIdx.find(vecField->GetFieldName());
731 if (itr == recordFieldNameToIdx.end()) {
732 throw RException(R__FAIL(std::string("unexpected SoA member: ") + vecField->GetFieldName()));
733 }
735 if (vecField->begin()->GetTypeName() != memberField->GetTypeName() ||
736 vecField->begin()->GetTypeAlias() != memberField->GetTypeAlias()) {
737 const std::string leftType =
738 vecField->begin()->GetTypeName() +
739 (vecField->begin()->GetTypeAlias().empty() ? "" : " [" + vecField->begin()->GetTypeAlias() + "]");
740 const std::string rightType =
741 memberField->GetTypeName() +
742 (memberField->GetTypeAlias().empty() ? "" : " [" + memberField->GetTypeAlias() + "]");
743 throw RException(R__FAIL(std::string("SoA member type mismatch: ") + vecField->GetFieldName() + " (" +
744 leftType + " vs. " + rightType + ")"));
745 }
746
747 fMaxAlignment = std::max(fMaxAlignment, vecField->GetAlignment());
748
749 fSoAMemberOffsets.emplace_back(dataMember->GetOffset());
750 fRecordMemberIndexes.emplace_back(itr->second);
751 }
752 if (recordFieldNameToIdx.size() != fSoAMemberOffsets.size()) {
753 throw RException(R__FAIL("missing SoA members"));
754 }
756
757 std::string renormalizedAlias;
760
762}
763
764std::unique_ptr<ROOT::RFieldBase> ROOT::Experimental::RSoAField::CloneImpl(std::string_view newName) const
765{
766 return std::unique_ptr<RSoAField>(new RSoAField(newName, *this));
767}
768
778
783
788
789std::size_t ROOT::Experimental::RSoAField::AppendImpl(const void *from)
790{
791 const std::size_t nSoAMembers = fSoAMemberOffsets.size();
792
793 std::size_t N = 0; // Set by first SoA member and verified for the rest
794 for (std::size_t i = 0; i < nSoAMembers; ++i) {
795 const void *rvecPtr = static_cast<const unsigned char *>(from) + fSoAMemberOffsets[i];
797 assert(*sizePtr >= 0);
798 if (i == 0) {
799 N = *sizePtr;
800 } else {
801 if (static_cast<std::size_t>(*sizePtr) != N) {
802 const auto f = fRecordMemberFields[i];
803 throw RException(R__FAIL("SoA length mismatch for " + f->GetFieldName() + ": " + std::to_string(*sizePtr) +
804 " vs. " + std::to_string(N) + " (expected)"));
805 }
806 }
807 }
808
809 std::size_t nbytes = 0;
810 if (N > 0) {
811 for (std::size_t i = 0; i < nSoAMembers; ++i) {
812 const void *rvecPtr = static_cast<const unsigned char *>(from) + fSoAMemberOffsets[i];
814 RFieldBase *memberField = fRecordMemberFields[i];
815 if (memberField->IsSimple()) {
816 GetPrincipalColumnOf(*memberField)->AppendV(*beginPtr, N);
817 nbytes += N * GetPrincipalColumnOf(*memberField)->GetElement()->GetPackedSize();
818 } else {
819 for (std::size_t j = 0; j < N; ++j) {
820 nbytes += CallAppendOn(*memberField, *beginPtr + j * memberField->GetValueSize());
821 }
822 }
823 }
824 }
825
826 fNWritten += N;
827 fPrincipalColumn->Append(&fNWritten);
828 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
829}
830
832{
833 throw RException(R__FAIL("not yet implemented"));
834}
835
837{
838 fSoAClass->New(where);
839}
840
842{
843 fSoAClass->Destructor(objPtr, true /* dtorOnly */);
844 RDeleter::operator()(objPtr, dtorOnly);
845}
846
847std::vector<ROOT::RFieldBase::RValue> ROOT::Experimental::RSoAField::SplitValue(const RValue & /* value */) const
848{
849 throw RException(R__FAIL("not yet implemented"));
850 return std::vector<RValue>();
851}
852
854{
855 return fSoAClass->GetClassSize();
856}
857
859{
860 // TODO(jblomer): factor out
861 bool polymorphic = fSoAClass->ClassProperty() & kClassHasVirtual;
862 if (!polymorphic) {
863 return nullptr;
864 }
865 return fSoAClass->GetTypeInfo();
866}
867
868//------------------------------------------------------------------------------
869
870ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName)
872{
873}
874
876 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(enump->GetQualifiedName()), ROOT::ENTupleStructure::kPlain,
877 false /* isSimple */)
878{
879 // Avoid accidentally supporting std types through TEnum.
880 if (enump->Property() & kIsDefinedInStd) {
881 throw RException(R__FAIL(GetTypeName() + " is not supported"));
882 }
883
884 switch (enump->GetUnderlyingType()) {
885 case kBool_t: Attach(std::make_unique<RField<Bool_t>>("_0")); break;
886 case kChar_t: Attach(std::make_unique<RField<Char_t>>("_0")); break;
887 case kUChar_t: Attach(std::make_unique<RField<UChar_t>>("_0")); break;
888 case kShort_t: Attach(std::make_unique<RField<Short_t>>("_0")); break;
889 case kUShort_t: Attach(std::make_unique<RField<UShort_t>>("_0")); break;
890 case kInt_t: Attach(std::make_unique<RField<Int_t>>("_0")); break;
891 case kUInt_t: Attach(std::make_unique<RField<UInt_t>>("_0")); break;
892 case kLong_t: Attach(std::make_unique<RField<Long_t>>("_0")); break;
893 case kLong64_t: Attach(std::make_unique<RField<Long64_t>>("_0")); break;
894 case kULong_t: Attach(std::make_unique<RField<ULong_t>>("_0")); break;
895 case kULong64_t: Attach(std::make_unique<RField<ULong64_t>>("_0")); break;
896 default: throw RException(R__FAIL("Unsupported underlying integral type for enum type " + GetTypeName()));
897 }
898
900}
901
902ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName,
903 std::unique_ptr<RFieldBase> intField)
905{
906 Attach(std::move(intField));
908}
909
910std::unique_ptr<ROOT::RFieldBase> ROOT::REnumField::CloneImpl(std::string_view newName) const
911{
912 auto newIntField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
913 return std::unique_ptr<REnumField>(new REnumField(newName, GetTypeName(), std::move(newIntField)));
914}
915
917{
918 // TODO(jblomer): allow enum to enum conversion only by rename rule
919 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffTypeVersion).ThrowOnError();
920}
921
922std::vector<ROOT::RFieldBase::RValue> ROOT::REnumField::SplitValue(const RValue &value) const
923{
924 std::vector<RValue> result;
925 result.emplace_back(fSubfields[0]->BindValue(value.GetPtr<void>()));
926 return result;
927}
928
930{
931 visitor.VisitEnumField(*this);
932}
933
934//------------------------------------------------------------------------------
935
936ROOT::RPairField::RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields)
937 : ROOT::RRecordField(fieldName, "std::pair<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">")
938{
939 const std::string typeAlias = "std::pair<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
940 if (typeAlias != GetTypeName())
942
943 AttachItemFields(std::move(itemFields));
944
945 // ISO C++ does not guarantee any specific layout for `std::pair`; query TClass for the member offsets
946 auto *c = TClass::GetClass(GetTypeName().c_str());
947 if (!c)
948 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
949 fSize = c->Size();
950
951 auto firstElem = c->GetRealData("first");
952 if (!firstElem)
953 throw RException(R__FAIL("first: no such member"));
954 fOffsets.push_back(firstElem->GetThisOffset());
955
956 auto secondElem = c->GetRealData("second");
957 if (!secondElem)
958 throw RException(R__FAIL("second: no such member"));
959 fOffsets.push_back(secondElem->GetThisOffset());
960}
961
962std::unique_ptr<ROOT::RFieldBase> ROOT::RPairField::CloneImpl(std::string_view newName) const
963{
964 std::array<std::unique_ptr<RFieldBase>, 2> itemClones = {fSubfields[0]->Clone(fSubfields[0]->GetFieldName()),
965 fSubfields[1]->Clone(fSubfields[1]->GetFieldName())};
966 return std::unique_ptr<RPairField>(new RPairField(newName, std::move(itemClones)));
967}
968
970{
971 static const std::vector<std::string> prefixes = {"std::pair<", "std::tuple<"};
972
973 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
974 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
975
976 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
977 const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
978 if (nOnDiskSubfields != 2) {
979 throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::pair " +
980 std::to_string(nOnDiskSubfields) + "\n" +
981 Internal::GetTypeTraceReport(*this, desc)));
982 }
983}
984
985//------------------------------------------------------------------------------
986
989 bool readFromDisk)
990{
992 ifuncs.fCreateIterators = proxy->GetFunctionCreateIterators(readFromDisk);
993 ifuncs.fDeleteTwoIterators = proxy->GetFunctionDeleteTwoIterators(readFromDisk);
994 ifuncs.fNext = proxy->GetFunctionNext(readFromDisk);
995 R__ASSERT((ifuncs.fCreateIterators != nullptr) && (ifuncs.fDeleteTwoIterators != nullptr) &&
996 (ifuncs.fNext != nullptr));
997 return ifuncs;
998}
999
1001 : RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kCollection,
1002 false /* isSimple */),
1003 fNWritten(0)
1004{
1005 if (!classp->GetCollectionProxy())
1006 throw RException(R__FAIL(std::string(classp->GetName()) + " has no associated collection proxy"));
1007 if (classp->Property() & kIsDefinedInStd) {
1008 static const std::vector<std::string> supportedStdTypes = {
1009 "std::set<", "std::unordered_set<", "std::multiset<", "std::unordered_multiset<",
1010 "std::map<", "std::unordered_map<", "std::multimap<", "std::unordered_multimap<"};
1011 bool isSupported = false;
1012 for (const auto &tn : supportedStdTypes) {
1013 if (GetTypeName().rfind(tn, 0) == 0) {
1014 isSupported = true;
1015 break;
1016 }
1017 }
1018 if (!isSupported)
1019 throw RException(R__FAIL(std::string(GetTypeName()) + " is not supported"));
1020 }
1021
1022 std::string renormalizedAlias;
1025
1026 fProxy.reset(classp->GetCollectionProxy()->Generate());
1027 fProperties = fProxy->GetProperties();
1028 fCollectionType = fProxy->GetCollectionType();
1029 if (fProxy->HasPointers())
1030 throw RException(R__FAIL("collection proxies whose value type is a pointer are not supported"));
1031
1032 fIFuncsRead = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), true /* readFromDisk */);
1033 fIFuncsWrite = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), false /* readFromDisk */);
1034}
1035
1036ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldName, std::string_view typeName)
1038{
1039 // NOTE (fdegeus): std::map is supported, custom associative might be supported in the future if the need arises.
1041 throw RException(R__FAIL("custom associative collection proxies not supported"));
1042
1043 std::unique_ptr<ROOT::RFieldBase> itemField;
1044
1045 if (auto valueClass = fProxy->GetValueClass()) {
1046 // Element type is a class
1047 itemField = RFieldBase::Create("_0", valueClass->GetName()).Unwrap();
1048 } else {
1049 switch (fProxy->GetType()) {
1050 case EDataType::kChar_t: itemField = std::make_unique<RField<Char_t>>("_0"); break;
1051 case EDataType::kUChar_t: itemField = std::make_unique<RField<UChar_t>>("_0"); break;
1052 case EDataType::kShort_t: itemField = std::make_unique<RField<Short_t>>("_0"); break;
1053 case EDataType::kUShort_t: itemField = std::make_unique<RField<UShort_t>>("_0"); break;
1054 case EDataType::kInt_t: itemField = std::make_unique<RField<Int_t>>("_0"); break;
1055 case EDataType::kUInt_t: itemField = std::make_unique<RField<UInt_t>>("_0"); break;
1056 case EDataType::kLong_t: itemField = std::make_unique<RField<Long_t>>("_0"); break;
1057 case EDataType::kLong64_t: itemField = std::make_unique<RField<Long64_t>>("_0"); break;
1058 case EDataType::kULong_t: itemField = std::make_unique<RField<ULong_t>>("_0"); break;
1059 case EDataType::kULong64_t: itemField = std::make_unique<RField<ULong64_t>>("_0"); break;
1060 case EDataType::kFloat_t: itemField = std::make_unique<RField<Float_t>>("_0"); break;
1061 case EDataType::kDouble_t: itemField = std::make_unique<RField<Double_t>>("_0"); break;
1062 case EDataType::kBool_t: itemField = std::make_unique<RField<Bool_t>>("_0"); break;
1063 default: throw RException(R__FAIL("unsupported value type: " + std::to_string(fProxy->GetType())));
1064 }
1065 }
1066
1067 fItemSize = itemField->GetValueSize();
1068 Attach(std::move(itemField));
1069}
1070
1071std::unique_ptr<ROOT::RFieldBase> ROOT::RProxiedCollectionField::CloneImpl(std::string_view newName) const
1072{
1073 auto clone =
1074 std::unique_ptr<RProxiedCollectionField>(new RProxiedCollectionField(newName, fProxy->GetCollectionClass()));
1075 clone->fItemSize = fItemSize;
1076 clone->Attach(fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1077 return clone;
1078}
1079
1081{
1082 std::size_t nbytes = 0;
1083 unsigned count = 0;
1084 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), const_cast<void *>(from));
1085 for (auto ptr : RCollectionIterableOnce{const_cast<void *>(from), fIFuncsWrite, fProxy.get(),
1086 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
1087 nbytes += CallAppendOn(*fSubfields[0], ptr);
1088 count++;
1089 }
1090
1091 fNWritten += count;
1092 fPrincipalColumn->Append(&fNWritten);
1093 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
1094}
1095
1097{
1100 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
1101
1102 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), to);
1103 void *obj =
1104 fProxy->Allocate(static_cast<std::uint32_t>(nItems), (fProperties & TVirtualCollectionProxy::kNeedDelete));
1105
1106 unsigned i = 0;
1107 for (auto elementPtr : RCollectionIterableOnce{obj, fIFuncsRead, fProxy.get(),
1108 (fCollectionType == kSTLvector || obj != to ? fItemSize : 0U)}) {
1109 CallReadOn(*fSubfields[0], collectionStart + (i++), elementPtr);
1110 }
1111 if (obj != to)
1112 fProxy->Commit(obj);
1113}
1114
1124
1129
1134
1136{
1137 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1138}
1139
1141{
1142 fProxy->New(where);
1143}
1144
1145std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RProxiedCollectionField::GetDeleter() const
1146{
1147 if (fProperties & TVirtualCollectionProxy::kNeedDelete) {
1148 std::size_t itemSize = fCollectionType == kSTLvector ? fItemSize : 0U;
1149 return std::make_unique<RProxiedCollectionDeleter>(fProxy, GetDeleterOf(*fSubfields[0]), itemSize);
1150 }
1151 return std::make_unique<RProxiedCollectionDeleter>(fProxy);
1152}
1153
1155{
1156 if (fItemDeleter) {
1158 for (auto ptr : RCollectionIterableOnce{objPtr, fIFuncsWrite, fProxy.get(), fItemSize}) {
1159 fItemDeleter->operator()(ptr, true /* dtorOnly */);
1160 }
1161 }
1162 fProxy->Destructor(objPtr, true /* dtorOnly */);
1163 RDeleter::operator()(objPtr, dtorOnly);
1164}
1165
1166std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(const RValue &value) const
1167{
1168 std::vector<RValue> result;
1169 auto valueRawPtr = value.GetPtr<void>().get();
1171 for (auto ptr : RCollectionIterableOnce{valueRawPtr, fIFuncsWrite, fProxy.get(),
1172 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
1173 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), ptr)));
1174 }
1175 return result;
1176}
1177
1179{
1180 visitor.VisitProxiedCollectionField(*this);
1181}
1182
1183//------------------------------------------------------------------------------
1184
1185ROOT::RMapField::RMapField(std::string_view fieldName, EMapType mapType, std::unique_ptr<RFieldBase> itemField)
1187 EnsureValidClass(BuildMapTypeName(mapType, itemField.get(), false /* useTypeAliases */))),
1188 fMapType(mapType)
1189{
1190 if (!itemField->GetTypeAlias().empty())
1191 fTypeAlias = BuildMapTypeName(mapType, itemField.get(), true /* useTypeAliases */);
1192
1193 auto *itemClass = fProxy->GetValueClass();
1194 fItemSize = itemClass->GetClassSize();
1195
1196 Attach(std::move(itemField), "_0");
1197}
1198
1199std::unique_ptr<ROOT::RFieldBase> ROOT::RMapField::CloneImpl(std::string_view newName) const
1200{
1201 return std::make_unique<RMapField>(newName, fMapType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1202}
1203
1205{
1206 static const std::vector<std::string> prefixesRegular = {"std::map<", "std::unordered_map<"};
1207
1208 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1209
1210 switch (fMapType) {
1211 case EMapType::kMap:
1212 case EMapType::kUnorderedMap: EnsureMatchingTypePrefix(desc, prefixesRegular).ThrowOnError(); break;
1213 default:
1214 break;
1215 // no restrictions for multimaps
1216 }
1217}
1218
1219//------------------------------------------------------------------------------
1220
1221ROOT::RSetField::RSetField(std::string_view fieldName, ESetType setType, std::unique_ptr<RFieldBase> itemField)
1223 EnsureValidClass(BuildSetTypeName(setType, *itemField, false /* useTypeAlias */))),
1224 fSetType(setType)
1225{
1226 if (!itemField->GetTypeAlias().empty())
1227 fTypeAlias = BuildSetTypeName(setType, *itemField, true /* useTypeAlias */);
1228
1229 fItemSize = itemField->GetValueSize();
1230
1231 Attach(std::move(itemField), "_0");
1232}
1233
1234std::unique_ptr<ROOT::RFieldBase> ROOT::RSetField::CloneImpl(std::string_view newName) const
1235{
1236 return std::make_unique<RSetField>(newName, fSetType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1237}
1238
1240{
1241 static const std::vector<std::string> prefixesRegular = {"std::set<", "std::unordered_set<", "std::map<",
1242 "std::unordered_map<"};
1243
1244 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1245
1246 switch (fSetType) {
1247 case ESetType::kSet:
1248 case ESetType::kUnorderedSet: EnsureMatchingTypePrefix(desc, prefixesRegular).ThrowOnError(); break;
1249 default:
1250 break;
1251 // no restrictions for multisets
1252 }
1253}
1254
1255//------------------------------------------------------------------------------
1256
1257namespace {
1258
1259/// Used in RStreamerField::AppendImpl() in order to record the encountered streamer info records
1260class TBufferRecStreamer : public TBufferFile {
1261public:
1262 using RCallbackStreamerInfo = std::function<void(TVirtualStreamerInfo *)>;
1263
1264private:
1265 RCallbackStreamerInfo fCallbackStreamerInfo;
1266
1267public:
1268 TBufferRecStreamer(TBuffer::EMode mode, Int_t bufsize, RCallbackStreamerInfo callbackStreamerInfo)
1269 : TBufferFile(mode, bufsize), fCallbackStreamerInfo(callbackStreamerInfo)
1270 {
1271 }
1272 void TagStreamerInfo(TVirtualStreamerInfo *info) final { fCallbackStreamerInfo(info); }
1273};
1274
1275} // anonymous namespace
1276
1277ROOT::RStreamerField::RStreamerField(std::string_view fieldName, std::string_view className)
1279{
1280}
1281
1283 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kStreamer,
1284 false /* isSimple */),
1285 fClass(classp),
1286 fIndex(0)
1287{
1288 std::string renormalizedAlias;
1291
1293 // For RClassField, we only check for explicit constructors and destructors and then recursively combine traits from
1294 // all member subfields. For RStreamerField, we treat the class as a black box and additionally need to check for
1295 // implicit constructors and destructors.
1300}
1301
1302std::unique_ptr<ROOT::RFieldBase> ROOT::RStreamerField::CloneImpl(std::string_view newName) const
1303{
1304 return std::unique_ptr<RStreamerField>(new RStreamerField(newName, GetTypeName()));
1305}
1306
1307std::size_t ROOT::RStreamerField::AppendImpl(const void *from)
1308{
1309 TBufferRecStreamer buffer(TBuffer::kWrite, GetValueSize(),
1310 [this](TVirtualStreamerInfo *info) { fStreamerInfos[info->GetNumber()] = info; });
1311 fClass->Streamer(const_cast<void *>(from), buffer);
1312
1313 auto nbytes = buffer.Length();
1314 fAuxiliaryColumn->AppendV(buffer.Buffer(), buffer.Length());
1315 fIndex += nbytes;
1316 fPrincipalColumn->Append(&fIndex);
1317 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
1318}
1319
1321{
1324 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nbytes);
1325
1327 fAuxiliaryColumn->ReadV(collectionStart, nbytes, buffer.Buffer());
1328 fClass->Streamer(to, buffer);
1329}
1330
1340
1345
1350
1352{
1353 source.RegisterStreamerInfos();
1354 return nullptr;
1355}
1356
1358{
1359 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffTypeVersion).ThrowOnError();
1360}
1361
1363{
1364 fClass->New(where);
1365}
1366
1368{
1369 fClass->Destructor(objPtr, true /* dtorOnly */);
1370 RDeleter::operator()(objPtr, dtorOnly);
1371}
1372
1374{
1377 .TypeVersion(GetTypeVersion())
1378 .TypeName(GetTypeName())
1380 return extraTypeInfoBuilder.MoveDescriptor().Unwrap();
1381}
1382
1384{
1385 return std::min(alignof(std::max_align_t), GetValueSize()); // TODO(jblomer): fix me
1386}
1387
1389{
1390 return fClass->GetClassSize();
1391}
1392
1394{
1395 return fClass->GetClassVersion();
1396}
1397
1399{
1400 return fClass->GetCheckSum();
1401}
1402
1404{
1405 visitor.VisitStreamerField(*this);
1406}
1407
1408//------------------------------------------------------------------------------
1409
1411{
1412 if (auto dataMember = TObject::Class()->GetDataMember(name)) {
1413 return dataMember->GetOffset();
1414 }
1415 throw RException(R__FAIL('\'' + std::string(name) + '\'' + " is an invalid data member"));
1416}
1417
1419 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1420{
1422 Attach(source.GetConstSubfields()[0]->Clone("fUniqueID"));
1423 Attach(source.GetConstSubfields()[1]->Clone("fBits"));
1424}
1425
1427 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1428{
1429 assert(TObject::Class()->GetClassVersion() == 1);
1430
1432 Attach(std::make_unique<RField<UInt_t>>("fUniqueID"));
1433 Attach(std::make_unique<RField<UInt_t>>("fBits"));
1434}
1435
1436std::unique_ptr<ROOT::RFieldBase> ROOT::RField<TObject>::CloneImpl(std::string_view newName) const
1437{
1438 return std::unique_ptr<RField<TObject>>(new RField<TObject>(newName, *this));
1439}
1440
1441std::size_t ROOT::RField<TObject>::AppendImpl(const void *from)
1442{
1443 // Cf. TObject::Streamer()
1444
1445 auto *obj = static_cast<const TObject *>(from);
1446 if (obj->TestBit(TObject::kIsReferenced)) {
1447 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1448 }
1449
1450 std::size_t nbytes = 0;
1451 nbytes += CallAppendOn(*fSubfields[0], reinterpret_cast<const unsigned char *>(from) + GetOffsetUniqueID());
1452
1453 UInt_t bits = *reinterpret_cast<const UInt_t *>(reinterpret_cast<const unsigned char *>(from) + GetOffsetBits());
1454 bits &= (~TObject::kIsOnHeap & ~TObject::kNotDeleted);
1455 nbytes += CallAppendOn(*fSubfields[1], &bits);
1456
1457 return nbytes;
1458}
1459
1461{
1462 // Cf. TObject::Streamer()
1463
1464 auto *obj = static_cast<TObject *>(to);
1465 if (obj->TestBit(TObject::kIsReferenced)) {
1466 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1467 }
1468
1469 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetUniqueID()) = uniqueID;
1470
1471 const UInt_t bitIsOnHeap = obj->TestBit(TObject::kIsOnHeap) ? TObject::kIsOnHeap : 0;
1473 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetBits()) = bits;
1474}
1475
1477{
1478 UInt_t uniqueID, bits;
1479 CallReadOn(*fSubfields[0], globalIndex, &uniqueID);
1480 CallReadOn(*fSubfields[1], globalIndex, &bits);
1481 ReadTObject(to, uniqueID, bits);
1482}
1483
1485{
1486 UInt_t uniqueID, bits;
1487 CallReadOn(*fSubfields[0], localIndex, &uniqueID);
1488 CallReadOn(*fSubfields[1], localIndex, &bits);
1489 ReadTObject(to, uniqueID, bits);
1490}
1491
1493{
1494 return TObject::Class()->GetClassVersion();
1495}
1496
1498{
1499 return TObject::Class()->GetCheckSum();
1500}
1501
1503{
1504 new (where) TObject();
1505}
1506
1507std::vector<ROOT::RFieldBase::RValue> ROOT::RField<TObject>::SplitValue(const RValue &value) const
1508{
1509 std::vector<RValue> result;
1510 // Use GetPtr<TObject> to type-check
1511 std::shared_ptr<void> ptr = value.GetPtr<TObject>();
1512 auto charPtr = static_cast<unsigned char *>(ptr.get());
1513 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(ptr, charPtr + GetOffsetUniqueID())));
1514 result.emplace_back(fSubfields[1]->BindValue(std::shared_ptr<void>(ptr, charPtr + GetOffsetBits())));
1515 return result;
1516}
1517
1519{
1520 return sizeof(TObject);
1521}
1522
1524{
1525 return alignof(TObject);
1526}
1527
1529{
1530 visitor.VisitTObjectField(*this);
1531}
1532
1533//------------------------------------------------------------------------------
1534
1535ROOT::RTupleField::RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1536 : ROOT::RRecordField(fieldName, "std::tuple<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">")
1537{
1538 const std::string typeAlias = "std::tuple<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
1539 if (typeAlias != GetTypeName())
1541
1542 AttachItemFields(std::move(itemFields));
1543
1544 auto *c = TClass::GetClass(GetTypeName().c_str());
1545 if (!c)
1546 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
1547 fSize = c->Size();
1548
1549 // ISO C++ does not guarantee neither specific layout nor member names for `std::tuple`. However, most
1550 // implementations including libstdc++ (gcc), libc++ (llvm), and MSVC name members as `_0`, `_1`, ..., `_N-1`,
1551 // following the order of the type list.
1552 // Use TClass to get their offsets; in case a particular `std::tuple` implementation does not define such
1553 // members, the assertion below will fail.
1554 for (unsigned i = 0; i < fSubfields.size(); ++i) {
1555 std::string memberName("_" + std::to_string(i));
1556 auto member = c->GetRealData(memberName.c_str());
1557 if (!member)
1558 throw RException(R__FAIL(memberName + ": no such member"));
1559 fOffsets.push_back(member->GetThisOffset());
1560 }
1561}
1562
1563std::unique_ptr<ROOT::RFieldBase> ROOT::RTupleField::CloneImpl(std::string_view newName) const
1564{
1565 std::vector<std::unique_ptr<RFieldBase>> itemClones;
1566 itemClones.reserve(fSubfields.size());
1567 for (const auto &f : fSubfields) {
1568 itemClones.emplace_back(f->Clone(f->GetFieldName()));
1569 }
1570 return std::unique_ptr<RTupleField>(new RTupleField(newName, std::move(itemClones)));
1571}
1572
1574{
1575 static const std::vector<std::string> prefixes = {"std::pair<", "std::tuple<"};
1576
1577 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1578 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1579
1580 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1581 const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
1582 const auto nSubfields = fSubfields.size();
1584 throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::tuple " +
1585 std::to_string(nOnDiskSubfields) + " vs. " + std::to_string(nSubfields) + "\n" +
1586 Internal::GetTypeTraceReport(*this, desc)));
1587 }
1588}
1589
1590//------------------------------------------------------------------------------
1591
1592namespace {
1593
1594// Depending on the compiler, the variant tag is stored either in a trailing char or in a trailing unsigned int
1595constexpr std::size_t GetVariantTagSize()
1596{
1597 // Should be all zeros except for the tag, which is 1
1598 std::variant<char> t;
1599 constexpr auto sizeOfT = sizeof(t);
1600
1601 static_assert(sizeOfT == 2 || sizeOfT == 8, "unsupported std::variant layout");
1602 return sizeOfT == 2 ? 1 : 4;
1603}
1604
1605template <std::size_t VariantSizeT>
1606struct RVariantTag {
1607 using ValueType_t = typename std::conditional_t<VariantSizeT == 1, std::uint8_t,
1608 typename std::conditional_t<VariantSizeT == 4, std::uint32_t, void>>;
1609};
1610
1611} // anonymous namespace
1612
1614 : ROOT::RFieldBase(name, source.GetTypeName(), ROOT::ENTupleStructure::kVariant, false /* isSimple */),
1615 fMaxItemSize(source.fMaxItemSize),
1616 fMaxAlignment(source.fMaxAlignment),
1617 fTagOffset(source.fTagOffset),
1618 fVariantOffset(source.fVariantOffset),
1619 fNWritten(source.fNWritten.size(), 0)
1620{
1621 for (const auto &f : source.GetConstSubfields())
1622 Attach(f->Clone(f->GetFieldName()));
1623 fTraits = source.fTraits;
1624}
1625
1626ROOT::RVariantField::RVariantField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1627 : ROOT::RFieldBase(fieldName, "std::variant<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">",
1628 ROOT::ENTupleStructure::kVariant, false /* isSimple */)
1629{
1630 // The variant needs to initialize its own tag member
1632
1633 const std::string typeAlias = "std::variant<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
1634 if (typeAlias != GetTypeName())
1636
1637 auto nFields = itemFields.size();
1638 if (nFields == 0 || nFields > kMaxVariants) {
1639 throw RException(R__FAIL("invalid number of variant fields (outside [1.." + std::to_string(kMaxVariants) + ")"));
1640 }
1641 fNWritten.resize(nFields, 0);
1642 for (unsigned int i = 0; i < nFields; ++i) {
1645 fTraits &= itemFields[i]->GetTraits();
1646 Attach(std::move(itemFields[i]), "_" + std::to_string(i));
1647 }
1648
1649 // With certain template parameters, the union of members of an std::variant starts at an offset > 0.
1650 // For instance, std::variant<std::optional<int>> on macOS.
1651 auto cl = TClass::GetClass(GetTypeName().c_str());
1652 assert(cl);
1653 auto dm = reinterpret_cast<TDataMember *>(cl->GetListOfDataMembers()->First());
1654 if (dm)
1655 fVariantOffset = dm->GetOffset();
1656
1657 const auto tagSize = GetVariantTagSize();
1658 const auto padding = tagSize - (fMaxItemSize % tagSize);
1660}
1661
1662std::unique_ptr<ROOT::RFieldBase> ROOT::RVariantField::CloneImpl(std::string_view newName) const
1663{
1664 return std::unique_ptr<RVariantField>(new RVariantField(newName, *this));
1665}
1666
1667std::uint8_t ROOT::RVariantField::GetTag(const void *variantPtr, std::size_t tagOffset)
1668{
1669 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1670 auto tag = *reinterpret_cast<const TagType_t *>(reinterpret_cast<const unsigned char *>(variantPtr) + tagOffset);
1671 return (tag == TagType_t(-1)) ? 0 : tag + 1;
1672}
1673
1674void ROOT::RVariantField::SetTag(void *variantPtr, std::size_t tagOffset, std::uint8_t tag)
1675{
1676 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1677 auto tagPtr = reinterpret_cast<TagType_t *>(reinterpret_cast<unsigned char *>(variantPtr) + tagOffset);
1678 *tagPtr = (tag == 0) ? TagType_t(-1) : static_cast<TagType_t>(tag - 1);
1679}
1680
1681std::size_t ROOT::RVariantField::AppendImpl(const void *from)
1682{
1683 auto tag = GetTag(from, fTagOffset);
1684 std::size_t nbytes = 0;
1685 auto index = 0;
1686 if (tag > 0) {
1687 nbytes += CallAppendOn(*fSubfields[tag - 1], reinterpret_cast<const unsigned char *>(from) + fVariantOffset);
1688 index = fNWritten[tag - 1]++;
1689 }
1691 fPrincipalColumn->Append(&varSwitch);
1692 return nbytes + sizeof(ROOT::Internal::RColumnSwitch);
1693}
1694
1696{
1698 std::uint32_t tag;
1699 fPrincipalColumn->GetSwitchInfo(globalIndex, &variantIndex, &tag);
1700 R__ASSERT(tag < 256);
1701
1702 // If `tag` equals 0, the variant is in the invalid state, i.e, it does not hold any of the valid alternatives in
1703 // the type list. This happens, e.g., if the field was late added; in this case, keep the invalid tag, which makes
1704 // any `std::holds_alternative<T>` check fail later.
1705 if (R__likely(tag > 0)) {
1706 void *varPtr = reinterpret_cast<unsigned char *>(to) + fVariantOffset;
1707 CallConstructValueOn(*fSubfields[tag - 1], varPtr);
1708 CallReadOn(*fSubfields[tag - 1], variantIndex, varPtr);
1709 }
1710 SetTag(to, fTagOffset, tag);
1711}
1712
1718
1723
1728
1730{
1731 static const std::vector<std::string> prefixes = {"std::variant<"};
1732
1733 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1734 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1735
1736 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1737 if (fSubfields.size() != fieldDesc.GetLinkIds().size()) {
1738 throw RException(R__FAIL("number of variants on-disk do not match for " + GetQualifiedFieldName() + "\n" +
1739 Internal::GetTypeTraceReport(*this, desc)));
1740 }
1741}
1742
1744{
1745 memset(where, 0, GetValueSize());
1746 CallConstructValueOn(*fSubfields[0], reinterpret_cast<unsigned char *>(where) + fVariantOffset);
1747 SetTag(where, fTagOffset, 1);
1748}
1749
1751{
1752 auto tag = GetTag(objPtr, fTagOffset);
1753 if (tag > 0) {
1754 fItemDeleters[tag - 1]->operator()(reinterpret_cast<unsigned char *>(objPtr) + fVariantOffset, true /*dtorOnly*/);
1755 }
1756 RDeleter::operator()(objPtr, dtorOnly);
1757}
1758
1759std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RVariantField::GetDeleter() const
1760{
1761 std::vector<std::unique_ptr<RDeleter>> itemDeleters;
1762 itemDeleters.reserve(fSubfields.size());
1763 for (const auto &f : fSubfields) {
1764 itemDeleters.emplace_back(GetDeleterOf(*f));
1765 }
1766 return std::make_unique<RVariantDeleter>(fTagOffset, fVariantOffset, std::move(itemDeleters));
1767}
1768
1770{
1771 return std::max(fMaxAlignment, alignof(RVariantTag<GetVariantTagSize()>::ValueType_t));
1772}
1773
1775{
1776 const auto alignment = GetAlignment();
1777 const auto actualSize = fTagOffset + GetVariantTagSize();
1778 const auto padding = alignment - (actualSize % alignment);
1779 return actualSize + ((padding == alignment) ? 0 : padding);
1780}
1781
1783{
1784 std::fill(fNWritten.begin(), fNWritten.end(), 0);
1785}
Cppyy::TCppType_t fClass
#define R__likely(expr)
Definition RConfig.hxx:593
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:300
#define R__LOG_WARNING(...)
Definition RLogger.hxx:358
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kFloat_t
Definition TDataType.h:31
@ kULong64_t
Definition TDataType.h:32
@ kInt_t
Definition TDataType.h:30
@ kLong_t
Definition TDataType.h:30
@ kShort_t
Definition TDataType.h:29
@ kBool_t
Definition TDataType.h:32
@ kULong_t
Definition TDataType.h:30
@ kLong64_t
Definition TDataType.h:32
@ kUShort_t
Definition TDataType.h:29
@ kDouble_t
Definition TDataType.h:31
@ kChar_t
Definition TDataType.h:29
@ kUChar_t
Definition TDataType.h:29
@ kUInt_t
Definition TDataType.h:30
@ kClassHasExplicitCtor
@ kClassHasImplicitCtor
@ kClassHasVirtual
@ kClassHasExplicitDtor
@ kClassHasImplicitDtor
@ kIsArray
Definition TDictionary.h:79
@ kIsStatic
Definition TDictionary.h:80
@ kIsDefinedInStd
Definition TDictionary.h:98
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
#define N
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 target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
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 mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:157
TCanvas * alignment()
Definition alignment.C:1
#define _(A, B)
Definition cfortran.h:108
Abstract base class for classes implementing the visitor design pattern.
void operator()(void *objPtr, bool dtorOnly) final
The SoA field provides I/O for an in-memory SoA layout linked to an on-disk collection of the underly...
Definition RFieldSoA.hxx:55
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
std::vector< std::size_t > fSoAMemberOffsets
The offset of the RVec members in the SoA type.
Definition RFieldSoA.hxx:66
const std::type_info * GetPolymorphicTypeInfo() const
For polymorphic classes (that declare or inherit at least one virtual method), return the expected dy...
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
std::vector< RFieldBase * > fRecordMemberFields
Direct access to the member fields of the underlying record.
Definition RFieldSoA.hxx:68
RSoAField(std::string_view fieldName, const RSoAField &source)
Used by CloneImpl.
std::vector< std::size_t > fRecordMemberIndexes
Maps the SoA members to the members of the underlying record.
Definition RFieldSoA.hxx:67
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.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
Holds the index and the tag of a kSwitch column.
A helper class for piece-wise construction of an RExtraTypeInfoDescriptor.
static std::string SerializeStreamerInfos(const StreamerInfoMap_t &infos)
Abstract interface to read data from an ntuple.
void operator()(void *objPtr, bool dtorOnly) final
The field for a class with dictionary.
Definition RField.hxx:138
std::unique_ptr< RFieldBase > BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate,...
void AddReadCallbacksFromIORule(const TSchemaRule *rule)
Register post-read callback corresponding to a ROOT I/O customization rules.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
void Attach(std::unique_ptr< RFieldBase > child, RSubfieldInfo info)
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
Definition RField.hxx:226
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...
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
std::vector< const TSchemaRule * > FindRules(const ROOT::RFieldDescriptor *fieldDesc)
Given the on-disk information from the page source, find all the I/O customization rules that apply t...
ROOT::DescriptorId_t LookupMember(const ROOT::RNTupleDescriptor &desc, std::string_view memberName, ROOT::DescriptorId_t classFieldId)
Returns the id of member 'name' in the class field given by 'fieldId', or kInvalidDescriptorId if no ...
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
TClass * fClass
Definition RField.hxx:167
std::uint32_t GetTypeVersion() const final
Indicates an evolution of the C++ type itself.
RClassField(std::string_view fieldName, const RClassField &source)
Used by CloneImpl.
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
void PrepareStagingArea(const std::vector< const TSchemaRule * > &rules, const ROOT::RNTupleDescriptor &desc, const ROOT::RFieldDescriptor &classFieldId)
If there are rules with inputs (source members), create the staging area according to the TClass inst...
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
const std::type_info * GetPolymorphicTypeInfo() const
For polymorphic classes (that declare or inherit at least one virtual method), return the expected dy...
~RClassField() override
std::uint32_t GetTypeChecksum() const final
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
static constexpr const char * kPrefixInherited
Prefix used in the subfield names generated for base classes.
Definition RField.hxx:156
void SetStagingClass(const std::string &className, unsigned int classVersion)
Sets fStagingClass according to the given name and version.
The field for an unscoped or scoped enum with dictionary.
Definition RField.hxx:293
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
REnumField(std::string_view fieldName, TEnum *enump)
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
Base class for all ROOT issued exceptions.
Definition RError.hxx:79
Field specific extra type information from the header / extenstion header.
The list of column representations a field can have.
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.
void Attach(std::unique_ptr< RFieldBase > child, std::string_view expectedChildName="")
Add a new subfield to the list of nested fields.
std::vector< std::unique_ptr< RFieldBase > > fSubfields
Collections and classes own subfields.
@ 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.
@ kTraitSoACollection
The field represents a collection in SoA layout.
@ kTraitTypeChecksum
The TClass checksum is set and valid.
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
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::string fTypeAlias
A typedef or using name that was used when creating the field.
const std::string & GetTypeName() const
Metadata stored for every field of an RNTuple.
The container field for an ntuple model, which itself has no physical representation.
Definition RField.hxx:59
std::vector< std::unique_ptr< RFieldBase > > ReleaseSubfields()
Moves all subfields into the returned vector.
Definition RField.cxx:65
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:323
RField(std::string_view name)
Definition RField.hxx:326
RMapField(std::string_view fieldName, EMapType mapType, 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 > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
The on-storage metadata of an RNTuple.
RFieldDescriptorIterable GetFieldIterable(const RFieldDescriptor &fieldDesc) const
const RFieldDescriptor & GetFieldDescriptor(ROOT::DescriptorId_t fieldId) const
std::string GetTypeNameForComparison(const RFieldDescriptor &fieldDesc) const
Adjust the type name of the passed RFieldDescriptor for comparison with another renormalized type nam...
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...
Template specializations for C++ std::pair.
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
RPairField(std::string_view fieldName, std::array< std::unique_ptr< RFieldBase >, 2 > itemFields)
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
Allows for iterating over the elements of a proxied collection.
static RIteratorFuncs GetIteratorFuncs(TVirtualCollectionProxy *proxy, bool readFromDisk)
void operator()(void *objPtr, bool dtorOnly) final
The field for a class representing a collection of elements via TVirtualCollectionProxy.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const override
Called by Clone(), which additionally copies the on-disk ID.
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
RProxiedCollectionField(std::string_view fieldName, TClass *classp)
Constructor used when the value type of the collection is not known in advance, i....
RCollectionIterableOnce::RIteratorFuncs fIFuncsWrite
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
RCollectionIterableOnce::RIteratorFuncs fIFuncsRead
Two sets of functions to operate on iterators, to be used depending on the access type.
std::shared_ptr< TVirtualCollectionProxy > fProxy
The collection proxy is needed by the deleters and thus defined as a shared pointer.
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
std::unique_ptr< RDeleter > GetDeleter() const final
void ReconcileOnDiskField(const RNTupleDescriptor &desc) override
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.
Template specializations for ROOT's RVec.
const_iterator begin() const
const_iterator end() const
The field for an untyped record.
void AttachItemFields(ContainerT &&itemFields)
std::vector< std::size_t > fOffsets
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.
RSetField(std::string_view fieldName, ESetType setType, std::unique_ptr< RFieldBase > itemField)
void operator()(void *objPtr, bool dtorOnly) final
The field for a class using ROOT standard streaming.
Definition RField.hxx:238
ROOT::RExtraTypeInfoDescriptor GetExtraTypeInfo() const final
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::uint32_t GetTypeVersion() const final
Indicates an evolution of the C++ type itself.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
std::uint32_t GetTypeChecksum() const final
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
std::unique_ptr< RFieldBase > BeforeConnectPageSource(ROOT::Internal::RPageSource &source) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate,...
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
RStreamerField(std::string_view fieldName, TClass *classp)
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
Template specializations for C++ std::tuple.
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
RTupleField(std::string_view fieldName, std::vector< std::unique_ptr< RFieldBase > > itemFields)
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
void operator()(void *objPtr, bool dtorOnly) final
Template specializations for C++ std::variant.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
static constexpr std::size_t kMaxVariants
std::vector< ROOT::Internal::RColumnIndex::ValueType > fNWritten
static std::uint8_t GetTag(const void *variantPtr, std::size_t tagOffset)
Extracts the index from an std::variant and transforms it into the 1-based index used for the switch ...
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
size_t fVariantOffset
In the std::variant memory layout, the actual union of types may start at an offset > 0.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
std::unique_ptr< RDeleter > GetDeleter() const final
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
size_t fTagOffset
In the std::variant memory layout, at which byte number is the index stored.
RVariantField(std::string_view name, const RVariantField &source)
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
static void SetTag(void *variantPtr, std::size_t tagOffset, std::uint8_t tag)
void CommitClusterImpl() final
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition TBufferFile.h:47
@ kWrite
Definition TBuffer.h:73
@ kRead
Definition TBuffer.h:73
char * Buffer() const
Definition TBuffer.h:96
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Bool_t CanSplit() const
Return true if the data member of this TClass can be saved separately.
Definition TClass.cxx:2325
EState GetState() const
Definition TClass.h:501
void BuildRealData(void *pointer=nullptr, Bool_t isTransient=kFALSE)
Build a full list of persistent data members.
Definition TClass.cxx:2037
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3813
TList * GetListOfRealData() const
Definition TClass.h:465
Int_t Size() const
Return size of object of this class.
Definition TClass.cxx:5759
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3679
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:2903
Long_t ClassProperty() const
Return the C++ property of this class, eg.
Definition TClass.cxx:2402
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6144
@ kInterpreted
Definition TClass.h:129
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.
Definition TClass.cxx:2979
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
The TEnum class implements the enum type.
Definition TEnum.h:33
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
Definition TEnum.cxx:181
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:789
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Mother of all ROOT objects.
Definition TObject.h:42
@ kIsOnHeap
object is on heap
Definition TObject.h:90
@ kNotDeleted
object has not been deleted
Definition TObject.h:91
static TClass * Class()
@ kIsReferenced
if object is referenced by a TRef or TRefArray
Definition TObject.h:74
The TRealData class manages the effective list of all data members for a given class.
Definition TRealData.h:30
RAII helper class that ensures that PushProxy() / PopProxy() are called when entering / leaving a C++...
Defines a common interface to inspect/change the contents of an object that represents a collection.
@ kNeedDelete
The collection contains directly or indirectly (via other collection) some pointers that need explici...
Abstract Interface class describing Streamer information for one class.
const Int_t n
Definition legend1.C:16
TRangeCast< T, false > TRangeStaticCast
TRangeStaticCast is an adapter class that allows the typed iteration through a TCollection.
void SetAllowFieldSubstitutions(RFieldZero &fieldZero, bool val)
Definition RField.cxx:36
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...
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
void CallConnectPageSourceOnField(RFieldBase &, ROOT::Internal::RPageSource &)
std::string GetRNTupleSoARecord(const TClass *cl)
Checks if the "rntuple.SoARecord" class attribute is set in the dictionary.
bool NeedsMetaNameAsAlias(const std::string &metaNormalizedName, std::string &renormalizedAlias, bool isArgInTemplatedUserClass=false)
Checks if the meta normalized name is different from the RNTuple normalized name in a way that would ...
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 ...
ERNTupleSerializationMode GetRNTupleSerializationMode(const TClass *cl)
std::string GetRenormalizedTypeName(const std::string &metaNormalizedName)
Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
@ kSTLvector
Definition ESTLType.h:30
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...
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.