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 const bool hasSources = std::any_of(rules.begin(), rules.end(), [](const auto &r) {
545 return r->GetSource() && (r->GetSource()->GetEntries() > 0);
546 });
547
548 // A staging class (conversion streamer info) only exists if there is at least one rule that has an
549 // on disk source member defined.
550 if (hasSources) {
551 SetStagingClass(fieldDesc.GetTypeName(), fieldDesc.GetTypeVersion());
552 PrepareStagingArea(rules, desc, fieldDesc);
553 for (auto &[_, si] : fStagingItems) {
555 si.fField = std::move(static_cast<RFieldZero *>(si.fField.get())->ReleaseSubfields()[0]);
556 }
557 }
558
559 // Remove target member of read rules from the list of regular members of the underlying on-disk field
560 for (const auto rule : rules) {
561 if (!rule->GetTarget())
562 continue;
563
564 for (const auto target : ROOT::Detail::TRangeStaticCast<const TObjString>(*rule->GetTarget())) {
565 regularSubfields.erase(std::string(target->GetString()));
566 }
567 }
568 }
569
570 for (const auto rule : rules) {
571 AddReadCallbacksFromIORule(rule);
572 }
573
574 // Iterate over all sub fields in memory and mark those as missing that are not in the descriptor.
575 int nInMemoryBaseClasses = 0;
576 for (auto &field : fSubfields) {
577 const auto &fieldName = field->GetFieldName();
578 if (regularSubfields.count(fieldName) == 0) {
579 CallSetArtificialOn(*field);
580 }
581 if (!fieldName.empty() && fieldName[0] == ':')
583 }
584
586 throw RException(R__FAIL(std::string("incompatible number of base classes for field ") + GetFieldName() + ": " +
587 GetTypeName() + ", " + std::to_string(nInMemoryBaseClasses) +
588 " base classes in memory "
589 " vs. " +
590 std::to_string(nOnDiskBaseClasses) + " base classes on-disk\n" +
591 Internal::GetTypeTraceReport(*this, pageSource.GetSharedDescriptorGuard().GetRef())));
592 }
593
594 return nullptr;
595}
596
598{
599 EnsureMatchingOnDiskField(desc, kDiffTypeVersion | kDiffTypeName).ThrowOnError();
600}
601
603{
604 fClass->New(where);
605}
606
608{
609 fClass->Destructor(objPtr, true /* dtorOnly */);
610 RDeleter::operator()(objPtr, dtorOnly);
611}
612
613std::vector<ROOT::RFieldBase::RValue> ROOT::RClassField::SplitValue(const RValue &value) const
614{
615 std::vector<RValue> result;
616 auto valuePtr = value.GetPtr<void>();
617 auto charPtr = static_cast<unsigned char *>(valuePtr.get());
618 result.reserve(fSubfields.size());
619 for (unsigned i = 0; i < fSubfields.size(); i++) {
620 result.emplace_back(
621 fSubfields[i]->BindValue(std::shared_ptr<void>(valuePtr, charPtr + fSubfieldsInfo[i].fOffset)));
622 }
623 return result;
624}
625
627{
628 return fClass->GetClassSize();
629}
630
632{
633 return fClass->GetClassVersion();
634}
635
637{
638 return fClass->GetCheckSum();
639}
640
641const std::type_info *ROOT::RClassField::GetPolymorphicTypeInfo() const
642{
643 bool polymorphic = fClass->ClassProperty() & kClassHasVirtual;
644 if (!polymorphic) {
645 return nullptr;
646 }
647 return fClass->GetTypeInfo();
648}
649
651{
652 visitor.VisitClassField(*this);
653}
654
655//------------------------------------------------------------------------------
656
658 : ROOT::RFieldBase(fieldName, source.GetTypeName(), ROOT::ENTupleStructure::kCollection, false /* isSimple */),
659 fSoAClass(source.fSoAClass),
660 fSoAMemberOffsets(source.fSoAMemberOffsets),
661 fRecordMemberIndexes(source.fRecordMemberIndexes),
662 fMaxAlignment(source.fMaxAlignment)
663{
664 fTraits = source.GetTraits();
665 Attach(source.fSubfields[0]->Clone(source.fSubfields[0]->GetFieldName()));
666 fRecordMemberFields = fSubfields[0]->GetMutableSubfields();
667}
668
669ROOT::Experimental::RSoAField::RSoAField(std::string_view fieldName, std::string_view className)
671{
672}
673
675 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(clSoA->GetName()), ROOT::ENTupleStructure::kCollection,
676 false /* isSimple */),
677 fSoAClass(clSoA)
678{
679 static std::once_flag once;
680 std::call_once(once, []() {
681 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "The SoA field is experimental and still under development.";
682 });
683
684 EnsureValidUserClass(fSoAClass, *this, "RSoAField");
686 if (recordTypeName.empty()) {
687 throw ROOT::RException(R__FAIL(std::string("class ") + GetTypeName() +
688 " is not marked with the rntupleSoARecord "
689 "dictionary option; cannot create corresponding RSoAField."));
690 }
691 try {
692 Attach(std::make_unique<ROOT::RClassField>("_0", recordTypeName));
693 } catch (ROOT::RException &e) {
694 throw RException(R__FAIL("invalid record type of SoA field " + GetTypeName() + " [" + e.what() + "]"));
695 }
696 fRecordMemberFields = fSubfields[0]->GetMutableSubfields();
697
698 std::unordered_map<std::string, std::size_t> recordFieldNameToIdx;
699 for (std::size_t i = 0; i < fRecordMemberFields.size(); ++i) {
700 const RFieldBase *f = fRecordMemberFields[i];
701 assert(!f->GetFieldName().empty());
702 if (f->GetFieldName()[0] == ':') {
703 throw RException(R__FAIL("SoA fields with inheritance are currently unsupported"));
704 }
705 recordFieldNameToIdx[f->GetFieldName()] = i;
706 }
707
708 const auto *bases = fSoAClass->GetListOfBases();
709 assert(bases);
711 if (baseClass->GetDelta() < 0) {
712 throw RException(R__FAIL(std::string("virtual inheritance is not supported: ") + GetTypeName() +
713 " virtually inherits from " + baseClass->GetName()));
714 }
715 // At a later point, we will support inheritance
716 throw RException(R__FAIL("SoA fields with inheritance are currently unsupported"));
717 }
718
720 if ((dataMember->Property() & kIsStatic) || !dataMember->IsPersistent())
721 continue;
722
723 if (dataMember->Property() & kIsArray) {
724 throw RException(R__FAIL(std::string("unsupported array type in SoA class: ") + dataMember->GetName()));
725 }
726
727 const std::string typeName{dataMember->GetTrueTypeName()};
728 auto subField = RFieldBase::Create(dataMember->GetName(), typeName).Unwrap();
729 auto vecFieldPtr = dynamic_cast<RRVecField *>(subField.get());
730 if (!vecFieldPtr) {
731 throw RException(R__FAIL("invalid field type in SoA class: " + subField->GetTypeName()));
732 }
733 subField.release();
734 auto vecField = std::unique_ptr<RRVecField>(vecFieldPtr);
735
736 auto itr = recordFieldNameToIdx.find(vecField->GetFieldName());
737 if (itr == recordFieldNameToIdx.end()) {
738 throw RException(R__FAIL(std::string("unexpected SoA member: ") + vecField->GetFieldName()));
739 }
741 if (vecField->begin()->GetTypeName() != memberField->GetTypeName() ||
742 vecField->begin()->GetTypeAlias() != memberField->GetTypeAlias()) {
743 const std::string leftType =
744 vecField->begin()->GetTypeName() +
745 (vecField->begin()->GetTypeAlias().empty() ? "" : " [" + vecField->begin()->GetTypeAlias() + "]");
746 const std::string rightType =
747 memberField->GetTypeName() +
748 (memberField->GetTypeAlias().empty() ? "" : " [" + memberField->GetTypeAlias() + "]");
749 throw RException(R__FAIL(std::string("SoA member type mismatch: ") + vecField->GetFieldName() + " (" +
750 leftType + " vs. " + rightType + ")"));
751 }
752
753 fMaxAlignment = std::max(fMaxAlignment, vecField->GetAlignment());
754
755 fSoAMemberOffsets.emplace_back(dataMember->GetOffset());
756 fRecordMemberIndexes.emplace_back(itr->second);
757 }
758 if (recordFieldNameToIdx.size() != fSoAMemberOffsets.size()) {
759 throw RException(R__FAIL("missing SoA members"));
760 }
762
763 std::string renormalizedAlias;
766
768}
769
770std::unique_ptr<ROOT::RFieldBase> ROOT::Experimental::RSoAField::CloneImpl(std::string_view newName) const
771{
772 return std::unique_ptr<RSoAField>(new RSoAField(newName, *this));
773}
774
784
789
794
795std::size_t ROOT::Experimental::RSoAField::AppendImpl(const void *from)
796{
797 const std::size_t nSoAMembers = fSoAMemberOffsets.size();
798
799 std::size_t N = 0; // Set by first SoA member and verified for the rest
800 for (std::size_t i = 0; i < nSoAMembers; ++i) {
801 const void *rvecPtr = static_cast<const unsigned char *>(from) + fSoAMemberOffsets[i];
803 assert(*sizePtr >= 0);
804 if (i == 0) {
805 N = *sizePtr;
806 } else {
807 if (static_cast<std::size_t>(*sizePtr) != N) {
808 const auto f = fRecordMemberFields[i];
809 throw RException(R__FAIL("SoA length mismatch for " + f->GetFieldName() + ": " + std::to_string(*sizePtr) +
810 " vs. " + std::to_string(N) + " (expected)"));
811 }
812 }
813 }
814
815 std::size_t nbytes = 0;
816 if (N > 0) {
817 for (std::size_t i = 0; i < nSoAMembers; ++i) {
818 const void *rvecPtr = static_cast<const unsigned char *>(from) + fSoAMemberOffsets[i];
820 RFieldBase *memberField = fRecordMemberFields[i];
821 if (memberField->IsSimple()) {
822 GetPrincipalColumnOf(*memberField)->AppendV(*beginPtr, N);
823 nbytes += N * GetPrincipalColumnOf(*memberField)->GetElement()->GetPackedSize();
824 } else {
825 for (std::size_t j = 0; j < N; ++j) {
826 nbytes += CallAppendOn(*memberField, *beginPtr + j * memberField->GetValueSize());
827 }
828 }
829 }
830 }
831
832 fNWritten += N;
833 fPrincipalColumn->Append(&fNWritten);
834 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
835}
836
838{
839 throw RException(R__FAIL("not yet implemented"));
840}
841
843{
844 fSoAClass->New(where);
845}
846
848{
849 fSoAClass->Destructor(objPtr, true /* dtorOnly */);
850 RDeleter::operator()(objPtr, dtorOnly);
851}
852
853std::vector<ROOT::RFieldBase::RValue> ROOT::Experimental::RSoAField::SplitValue(const RValue & /* value */) const
854{
855 throw RException(R__FAIL("not yet implemented"));
856 return std::vector<RValue>();
857}
858
860{
861 return fSoAClass->GetClassSize();
862}
863
865{
866 // TODO(jblomer): factor out
867 bool polymorphic = fSoAClass->ClassProperty() & kClassHasVirtual;
868 if (!polymorphic) {
869 return nullptr;
870 }
871 return fSoAClass->GetTypeInfo();
872}
873
874//------------------------------------------------------------------------------
875
876ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName)
878{
879}
880
882 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(enump->GetQualifiedName()), ROOT::ENTupleStructure::kPlain,
883 false /* isSimple */)
884{
885 // Avoid accidentally supporting std types through TEnum.
886 if (enump->Property() & kIsDefinedInStd) {
887 throw RException(R__FAIL(GetTypeName() + " is not supported"));
888 }
889
890 switch (enump->GetUnderlyingType()) {
891 case kBool_t: Attach(std::make_unique<RField<Bool_t>>("_0")); break;
892 case kChar_t: Attach(std::make_unique<RField<Char_t>>("_0")); break;
893 case kUChar_t: Attach(std::make_unique<RField<UChar_t>>("_0")); break;
894 case kShort_t: Attach(std::make_unique<RField<Short_t>>("_0")); break;
895 case kUShort_t: Attach(std::make_unique<RField<UShort_t>>("_0")); break;
896 case kInt_t: Attach(std::make_unique<RField<Int_t>>("_0")); break;
897 case kUInt_t: Attach(std::make_unique<RField<UInt_t>>("_0")); break;
898 case kLong_t: Attach(std::make_unique<RField<Long_t>>("_0")); break;
899 case kLong64_t: Attach(std::make_unique<RField<Long64_t>>("_0")); break;
900 case kULong_t: Attach(std::make_unique<RField<ULong_t>>("_0")); break;
901 case kULong64_t: Attach(std::make_unique<RField<ULong64_t>>("_0")); break;
902 default: throw RException(R__FAIL("Unsupported underlying integral type for enum type " + GetTypeName()));
903 }
904
906}
907
908ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName,
909 std::unique_ptr<RFieldBase> intField)
911{
912 Attach(std::move(intField));
914}
915
916std::unique_ptr<ROOT::RFieldBase> ROOT::REnumField::CloneImpl(std::string_view newName) const
917{
918 auto newIntField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
919 return std::unique_ptr<REnumField>(new REnumField(newName, GetTypeName(), std::move(newIntField)));
920}
921
923{
924 // TODO(jblomer): allow enum to enum conversion only by rename rule
925 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffTypeVersion).ThrowOnError();
926}
927
928std::vector<ROOT::RFieldBase::RValue> ROOT::REnumField::SplitValue(const RValue &value) const
929{
930 std::vector<RValue> result;
931 result.emplace_back(fSubfields[0]->BindValue(value.GetPtr<void>()));
932 return result;
933}
934
936{
937 visitor.VisitEnumField(*this);
938}
939
940//------------------------------------------------------------------------------
941
942ROOT::RPairField::RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields)
943 : ROOT::RRecordField(fieldName, "std::pair<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">")
944{
945 const std::string typeAlias = "std::pair<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
946 if (typeAlias != GetTypeName())
948
949 AttachItemFields(std::move(itemFields));
950
951 // ISO C++ does not guarantee any specific layout for `std::pair`; query TClass for the member offsets
952 auto *c = TClass::GetClass(GetTypeName().c_str());
953 if (!c)
954 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
955 fSize = c->Size();
956
957 auto firstElem = c->GetRealData("first");
958 if (!firstElem)
959 throw RException(R__FAIL("first: no such member"));
960 fOffsets.push_back(firstElem->GetThisOffset());
961
962 auto secondElem = c->GetRealData("second");
963 if (!secondElem)
964 throw RException(R__FAIL("second: no such member"));
965 fOffsets.push_back(secondElem->GetThisOffset());
966}
967
968std::unique_ptr<ROOT::RFieldBase> ROOT::RPairField::CloneImpl(std::string_view newName) const
969{
970 std::array<std::unique_ptr<RFieldBase>, 2> itemClones = {fSubfields[0]->Clone(fSubfields[0]->GetFieldName()),
971 fSubfields[1]->Clone(fSubfields[1]->GetFieldName())};
972 return std::unique_ptr<RPairField>(new RPairField(newName, std::move(itemClones)));
973}
974
976{
977 static const std::vector<std::string> prefixes = {"std::pair<", "std::tuple<"};
978
979 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
980 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
981
982 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
983 const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
984 if (nOnDiskSubfields != 2) {
985 throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::pair " +
986 std::to_string(nOnDiskSubfields) + "\n" +
987 Internal::GetTypeTraceReport(*this, desc)));
988 }
989}
990
991//------------------------------------------------------------------------------
992
995 bool readFromDisk)
996{
998 ifuncs.fCreateIterators = proxy->GetFunctionCreateIterators(readFromDisk);
999 ifuncs.fDeleteTwoIterators = proxy->GetFunctionDeleteTwoIterators(readFromDisk);
1000 ifuncs.fNext = proxy->GetFunctionNext(readFromDisk);
1001 R__ASSERT((ifuncs.fCreateIterators != nullptr) && (ifuncs.fDeleteTwoIterators != nullptr) &&
1002 (ifuncs.fNext != nullptr));
1003 return ifuncs;
1004}
1005
1007 : RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kCollection,
1008 false /* isSimple */),
1009 fNWritten(0)
1010{
1011 if (!classp->GetCollectionProxy())
1012 throw RException(R__FAIL(std::string(classp->GetName()) + " has no associated collection proxy"));
1013 if (classp->Property() & kIsDefinedInStd) {
1014 static const std::vector<std::string> supportedStdTypes = {
1015 "std::set<", "std::unordered_set<", "std::multiset<", "std::unordered_multiset<",
1016 "std::map<", "std::unordered_map<", "std::multimap<", "std::unordered_multimap<"};
1017 bool isSupported = false;
1018 for (const auto &tn : supportedStdTypes) {
1019 if (GetTypeName().rfind(tn, 0) == 0) {
1020 isSupported = true;
1021 break;
1022 }
1023 }
1024 if (!isSupported)
1025 throw RException(R__FAIL(std::string(GetTypeName()) + " is not supported"));
1026 }
1027
1028 std::string renormalizedAlias;
1031
1032 fProxy.reset(classp->GetCollectionProxy()->Generate());
1033 fProperties = fProxy->GetProperties();
1034 fCollectionType = fProxy->GetCollectionType();
1035 if (fProxy->HasPointers())
1036 throw RException(R__FAIL("collection proxies whose value type is a pointer are not supported"));
1037
1038 fIFuncsRead = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), true /* readFromDisk */);
1039 fIFuncsWrite = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), false /* readFromDisk */);
1040}
1041
1042ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldName, std::string_view typeName)
1044{
1045 // NOTE (fdegeus): std::map is supported, custom associative might be supported in the future if the need arises.
1047 throw RException(R__FAIL("custom associative collection proxies not supported"));
1048
1049 std::unique_ptr<ROOT::RFieldBase> itemField;
1050
1051 if (auto valueClass = fProxy->GetValueClass()) {
1052 // Element type is a class
1053 itemField = RFieldBase::Create("_0", valueClass->GetName()).Unwrap();
1054 } else {
1055 switch (fProxy->GetType()) {
1056 case EDataType::kChar_t: itemField = std::make_unique<RField<Char_t>>("_0"); break;
1057 case EDataType::kUChar_t: itemField = std::make_unique<RField<UChar_t>>("_0"); break;
1058 case EDataType::kShort_t: itemField = std::make_unique<RField<Short_t>>("_0"); break;
1059 case EDataType::kUShort_t: itemField = std::make_unique<RField<UShort_t>>("_0"); break;
1060 case EDataType::kInt_t: itemField = std::make_unique<RField<Int_t>>("_0"); break;
1061 case EDataType::kUInt_t: itemField = std::make_unique<RField<UInt_t>>("_0"); break;
1062 case EDataType::kLong_t: itemField = std::make_unique<RField<Long_t>>("_0"); break;
1063 case EDataType::kLong64_t: itemField = std::make_unique<RField<Long64_t>>("_0"); break;
1064 case EDataType::kULong_t: itemField = std::make_unique<RField<ULong_t>>("_0"); break;
1065 case EDataType::kULong64_t: itemField = std::make_unique<RField<ULong64_t>>("_0"); break;
1066 case EDataType::kFloat_t: itemField = std::make_unique<RField<Float_t>>("_0"); break;
1067 case EDataType::kDouble_t: itemField = std::make_unique<RField<Double_t>>("_0"); break;
1068 case EDataType::kBool_t: itemField = std::make_unique<RField<Bool_t>>("_0"); break;
1069 default: throw RException(R__FAIL("unsupported value type: " + std::to_string(fProxy->GetType())));
1070 }
1071 }
1072
1073 fItemSize = itemField->GetValueSize();
1074 Attach(std::move(itemField));
1075}
1076
1077std::unique_ptr<ROOT::RFieldBase> ROOT::RProxiedCollectionField::CloneImpl(std::string_view newName) const
1078{
1079 auto clone =
1080 std::unique_ptr<RProxiedCollectionField>(new RProxiedCollectionField(newName, fProxy->GetCollectionClass()));
1081 clone->fItemSize = fItemSize;
1082 clone->Attach(fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1083 return clone;
1084}
1085
1087{
1088 std::size_t nbytes = 0;
1089 unsigned count = 0;
1090 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), const_cast<void *>(from));
1091 for (auto ptr : RCollectionIterableOnce{const_cast<void *>(from), fIFuncsWrite, fProxy.get(),
1092 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
1093 nbytes += CallAppendOn(*fSubfields[0], ptr);
1094 count++;
1095 }
1096
1097 fNWritten += count;
1098 fPrincipalColumn->Append(&fNWritten);
1099 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
1100}
1101
1103{
1106 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
1107
1108 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), to);
1109 void *obj =
1110 fProxy->Allocate(static_cast<std::uint32_t>(nItems), (fProperties & TVirtualCollectionProxy::kNeedDelete));
1111
1112 unsigned i = 0;
1113 for (auto elementPtr : RCollectionIterableOnce{obj, fIFuncsRead, fProxy.get(),
1114 (fCollectionType == kSTLvector || obj != to ? fItemSize : 0U)}) {
1115 CallReadOn(*fSubfields[0], collectionStart + (i++), elementPtr);
1116 }
1117 if (obj != to)
1118 fProxy->Commit(obj);
1119}
1120
1130
1135
1140
1142{
1143 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1144}
1145
1147{
1148 fProxy->New(where);
1149}
1150
1151std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RProxiedCollectionField::GetDeleter() const
1152{
1153 if (fProperties & TVirtualCollectionProxy::kNeedDelete) {
1154 std::size_t itemSize = fCollectionType == kSTLvector ? fItemSize : 0U;
1155 return std::make_unique<RProxiedCollectionDeleter>(fProxy, GetDeleterOf(*fSubfields[0]), itemSize);
1156 }
1157 return std::make_unique<RProxiedCollectionDeleter>(fProxy);
1158}
1159
1161{
1162 if (fItemDeleter) {
1164 for (auto ptr : RCollectionIterableOnce{objPtr, fIFuncsWrite, fProxy.get(), fItemSize}) {
1165 fItemDeleter->operator()(ptr, true /* dtorOnly */);
1166 }
1167 }
1168 fProxy->Destructor(objPtr, true /* dtorOnly */);
1169 RDeleter::operator()(objPtr, dtorOnly);
1170}
1171
1172std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(const RValue &value) const
1173{
1174 std::vector<RValue> result;
1175 auto valueRawPtr = value.GetPtr<void>().get();
1177 for (auto ptr : RCollectionIterableOnce{valueRawPtr, fIFuncsWrite, fProxy.get(),
1178 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
1179 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), ptr)));
1180 }
1181 return result;
1182}
1183
1185{
1186 visitor.VisitProxiedCollectionField(*this);
1187}
1188
1189//------------------------------------------------------------------------------
1190
1191ROOT::RMapField::RMapField(std::string_view fieldName, EMapType mapType, std::unique_ptr<RFieldBase> itemField)
1193 EnsureValidClass(BuildMapTypeName(mapType, itemField.get(), false /* useTypeAliases */))),
1194 fMapType(mapType)
1195{
1196 if (!itemField->GetTypeAlias().empty())
1197 fTypeAlias = BuildMapTypeName(mapType, itemField.get(), true /* useTypeAliases */);
1198
1199 auto *itemClass = fProxy->GetValueClass();
1200 fItemSize = itemClass->GetClassSize();
1201
1202 Attach(std::move(itemField), "_0");
1203}
1204
1205std::unique_ptr<ROOT::RFieldBase> ROOT::RMapField::CloneImpl(std::string_view newName) const
1206{
1207 return std::make_unique<RMapField>(newName, fMapType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1208}
1209
1211{
1212 static const std::vector<std::string> prefixesRegular = {"std::map<", "std::unordered_map<"};
1213
1214 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1215
1216 switch (fMapType) {
1217 case EMapType::kMap:
1218 case EMapType::kUnorderedMap: EnsureMatchingTypePrefix(desc, prefixesRegular).ThrowOnError(); break;
1219 default:
1220 break;
1221 // no restrictions for multimaps
1222 }
1223}
1224
1225//------------------------------------------------------------------------------
1226
1227ROOT::RSetField::RSetField(std::string_view fieldName, ESetType setType, std::unique_ptr<RFieldBase> itemField)
1229 EnsureValidClass(BuildSetTypeName(setType, *itemField, false /* useTypeAlias */))),
1230 fSetType(setType)
1231{
1232 if (!itemField->GetTypeAlias().empty())
1233 fTypeAlias = BuildSetTypeName(setType, *itemField, true /* useTypeAlias */);
1234
1235 fItemSize = itemField->GetValueSize();
1236
1237 Attach(std::move(itemField), "_0");
1238}
1239
1240std::unique_ptr<ROOT::RFieldBase> ROOT::RSetField::CloneImpl(std::string_view newName) const
1241{
1242 return std::make_unique<RSetField>(newName, fSetType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1243}
1244
1246{
1247 static const std::vector<std::string> prefixesRegular = {"std::set<", "std::unordered_set<", "std::map<",
1248 "std::unordered_map<"};
1249
1250 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1251
1252 switch (fSetType) {
1253 case ESetType::kSet:
1254 case ESetType::kUnorderedSet: EnsureMatchingTypePrefix(desc, prefixesRegular).ThrowOnError(); break;
1255 default:
1256 break;
1257 // no restrictions for multisets
1258 }
1259}
1260
1261//------------------------------------------------------------------------------
1262
1263namespace {
1264
1265/// Used in RStreamerField::AppendImpl() in order to record the encountered streamer info records
1266class TBufferRecStreamer : public TBufferFile {
1267public:
1268 using RCallbackStreamerInfo = std::function<void(TVirtualStreamerInfo *)>;
1269
1270private:
1271 RCallbackStreamerInfo fCallbackStreamerInfo;
1272
1273public:
1274 TBufferRecStreamer(TBuffer::EMode mode, Int_t bufsize, RCallbackStreamerInfo callbackStreamerInfo)
1275 : TBufferFile(mode, bufsize), fCallbackStreamerInfo(callbackStreamerInfo)
1276 {
1277 }
1278 void TagStreamerInfo(TVirtualStreamerInfo *info) final { fCallbackStreamerInfo(info); }
1279};
1280
1281} // anonymous namespace
1282
1283ROOT::RStreamerField::RStreamerField(std::string_view fieldName, std::string_view className)
1285{
1286}
1287
1289 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kStreamer,
1290 false /* isSimple */),
1291 fClass(classp),
1292 fIndex(0)
1293{
1294 std::string renormalizedAlias;
1297
1299 // For RClassField, we only check for explicit constructors and destructors and then recursively combine traits from
1300 // all member subfields. For RStreamerField, we treat the class as a black box and additionally need to check for
1301 // implicit constructors and destructors.
1306}
1307
1308std::unique_ptr<ROOT::RFieldBase> ROOT::RStreamerField::CloneImpl(std::string_view newName) const
1309{
1310 return std::unique_ptr<RStreamerField>(new RStreamerField(newName, GetTypeName()));
1311}
1312
1313std::size_t ROOT::RStreamerField::AppendImpl(const void *from)
1314{
1315 TBufferRecStreamer buffer(TBuffer::kWrite, GetValueSize(),
1316 [this](TVirtualStreamerInfo *info) { fStreamerInfos[info->GetNumber()] = info; });
1317 fClass->Streamer(const_cast<void *>(from), buffer);
1318
1319 auto nbytes = buffer.Length();
1320 fAuxiliaryColumn->AppendV(buffer.Buffer(), buffer.Length());
1321 fIndex += nbytes;
1322 fPrincipalColumn->Append(&fIndex);
1323 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
1324}
1325
1327{
1330 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nbytes);
1331
1333 fAuxiliaryColumn->ReadV(collectionStart, nbytes, buffer.Buffer());
1334 fClass->Streamer(to, buffer);
1335}
1336
1346
1351
1356
1358{
1359 source.RegisterStreamerInfos();
1360 return nullptr;
1361}
1362
1364{
1365 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffTypeVersion).ThrowOnError();
1366}
1367
1369{
1370 fClass->New(where);
1371}
1372
1374{
1375 fClass->Destructor(objPtr, true /* dtorOnly */);
1376 RDeleter::operator()(objPtr, dtorOnly);
1377}
1378
1380{
1383 .TypeVersion(GetTypeVersion())
1384 .TypeName(GetTypeName())
1386 return extraTypeInfoBuilder.MoveDescriptor().Unwrap();
1387}
1388
1390{
1391 return std::min(alignof(std::max_align_t), GetValueSize()); // TODO(jblomer): fix me
1392}
1393
1395{
1396 return fClass->GetClassSize();
1397}
1398
1400{
1401 return fClass->GetClassVersion();
1402}
1403
1405{
1406 return fClass->GetCheckSum();
1407}
1408
1410{
1411 visitor.VisitStreamerField(*this);
1412}
1413
1414//------------------------------------------------------------------------------
1415
1417{
1418 if (auto dataMember = TObject::Class()->GetDataMember(name)) {
1419 return dataMember->GetOffset();
1420 }
1421 throw RException(R__FAIL('\'' + std::string(name) + '\'' + " is an invalid data member"));
1422}
1423
1425 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1426{
1428 Attach(source.GetConstSubfields()[0]->Clone("fUniqueID"));
1429 Attach(source.GetConstSubfields()[1]->Clone("fBits"));
1430}
1431
1433 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1434{
1435 assert(TObject::Class()->GetClassVersion() == 1);
1436
1438 Attach(std::make_unique<RField<UInt_t>>("fUniqueID"));
1439 Attach(std::make_unique<RField<UInt_t>>("fBits"));
1440}
1441
1442std::unique_ptr<ROOT::RFieldBase> ROOT::RField<TObject>::CloneImpl(std::string_view newName) const
1443{
1444 return std::unique_ptr<RField<TObject>>(new RField<TObject>(newName, *this));
1445}
1446
1447std::size_t ROOT::RField<TObject>::AppendImpl(const void *from)
1448{
1449 // Cf. TObject::Streamer()
1450
1451 auto *obj = static_cast<const TObject *>(from);
1452 if (obj->TestBit(TObject::kIsReferenced)) {
1453 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1454 }
1455
1456 std::size_t nbytes = 0;
1457 nbytes += CallAppendOn(*fSubfields[0], reinterpret_cast<const unsigned char *>(from) + GetOffsetUniqueID());
1458
1459 UInt_t bits = *reinterpret_cast<const UInt_t *>(reinterpret_cast<const unsigned char *>(from) + GetOffsetBits());
1460 bits &= (~TObject::kIsOnHeap & ~TObject::kNotDeleted);
1461 nbytes += CallAppendOn(*fSubfields[1], &bits);
1462
1463 return nbytes;
1464}
1465
1467{
1468 // Cf. TObject::Streamer()
1469
1470 auto *obj = static_cast<TObject *>(to);
1471 if (obj->TestBit(TObject::kIsReferenced)) {
1472 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1473 }
1474
1475 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetUniqueID()) = uniqueID;
1476
1477 const UInt_t bitIsOnHeap = obj->TestBit(TObject::kIsOnHeap) ? TObject::kIsOnHeap : 0;
1479 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetBits()) = bits;
1480}
1481
1483{
1484 UInt_t uniqueID, bits;
1485 CallReadOn(*fSubfields[0], globalIndex, &uniqueID);
1486 CallReadOn(*fSubfields[1], globalIndex, &bits);
1487 ReadTObject(to, uniqueID, bits);
1488}
1489
1491{
1492 UInt_t uniqueID, bits;
1493 CallReadOn(*fSubfields[0], localIndex, &uniqueID);
1494 CallReadOn(*fSubfields[1], localIndex, &bits);
1495 ReadTObject(to, uniqueID, bits);
1496}
1497
1499{
1500 return TObject::Class()->GetClassVersion();
1501}
1502
1504{
1505 return TObject::Class()->GetCheckSum();
1506}
1507
1509{
1510 new (where) TObject();
1511}
1512
1513std::vector<ROOT::RFieldBase::RValue> ROOT::RField<TObject>::SplitValue(const RValue &value) const
1514{
1515 std::vector<RValue> result;
1516 // Use GetPtr<TObject> to type-check
1517 std::shared_ptr<void> ptr = value.GetPtr<TObject>();
1518 auto charPtr = static_cast<unsigned char *>(ptr.get());
1519 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(ptr, charPtr + GetOffsetUniqueID())));
1520 result.emplace_back(fSubfields[1]->BindValue(std::shared_ptr<void>(ptr, charPtr + GetOffsetBits())));
1521 return result;
1522}
1523
1525{
1526 return sizeof(TObject);
1527}
1528
1530{
1531 return alignof(TObject);
1532}
1533
1535{
1536 visitor.VisitTObjectField(*this);
1537}
1538
1539//------------------------------------------------------------------------------
1540
1541ROOT::RTupleField::RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1542 : ROOT::RRecordField(fieldName, "std::tuple<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">")
1543{
1544 const std::string typeAlias = "std::tuple<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
1545 if (typeAlias != GetTypeName())
1547
1548 AttachItemFields(std::move(itemFields));
1549
1550 auto *c = TClass::GetClass(GetTypeName().c_str());
1551 if (!c)
1552 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
1553 fSize = c->Size();
1554
1555 // ISO C++ does not guarantee neither specific layout nor member names for `std::tuple`. However, most
1556 // implementations including libstdc++ (gcc), libc++ (llvm), and MSVC name members as `_0`, `_1`, ..., `_N-1`,
1557 // following the order of the type list.
1558 // Use TClass to get their offsets; in case a particular `std::tuple` implementation does not define such
1559 // members, the assertion below will fail.
1560 for (unsigned i = 0; i < fSubfields.size(); ++i) {
1561 std::string memberName("_" + std::to_string(i));
1562 auto member = c->GetRealData(memberName.c_str());
1563 if (!member)
1564 throw RException(R__FAIL(memberName + ": no such member"));
1565 fOffsets.push_back(member->GetThisOffset());
1566 }
1567}
1568
1569std::unique_ptr<ROOT::RFieldBase> ROOT::RTupleField::CloneImpl(std::string_view newName) const
1570{
1571 std::vector<std::unique_ptr<RFieldBase>> itemClones;
1572 itemClones.reserve(fSubfields.size());
1573 for (const auto &f : fSubfields) {
1574 itemClones.emplace_back(f->Clone(f->GetFieldName()));
1575 }
1576 return std::unique_ptr<RTupleField>(new RTupleField(newName, std::move(itemClones)));
1577}
1578
1580{
1581 static const std::vector<std::string> prefixes = {"std::pair<", "std::tuple<"};
1582
1583 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1584 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1585
1586 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1587 const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
1588 const auto nSubfields = fSubfields.size();
1590 throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::tuple " +
1591 std::to_string(nOnDiskSubfields) + " vs. " + std::to_string(nSubfields) + "\n" +
1592 Internal::GetTypeTraceReport(*this, desc)));
1593 }
1594}
1595
1596//------------------------------------------------------------------------------
1597
1598namespace {
1599
1600// Depending on the compiler, the variant tag is stored either in a trailing char or in a trailing unsigned int
1601constexpr std::size_t GetVariantTagSize()
1602{
1603 // Should be all zeros except for the tag, which is 1
1604 std::variant<char> t;
1605 constexpr auto sizeOfT = sizeof(t);
1606
1607 static_assert(sizeOfT == 2 || sizeOfT == 8, "unsupported std::variant layout");
1608 return sizeOfT == 2 ? 1 : 4;
1609}
1610
1611template <std::size_t VariantSizeT>
1612struct RVariantTag {
1613 using ValueType_t = typename std::conditional_t<VariantSizeT == 1, std::uint8_t,
1614 typename std::conditional_t<VariantSizeT == 4, std::uint32_t, void>>;
1615};
1616
1617} // anonymous namespace
1618
1620 : ROOT::RFieldBase(name, source.GetTypeName(), ROOT::ENTupleStructure::kVariant, false /* isSimple */),
1621 fMaxItemSize(source.fMaxItemSize),
1622 fMaxAlignment(source.fMaxAlignment),
1623 fTagOffset(source.fTagOffset),
1624 fVariantOffset(source.fVariantOffset),
1625 fNWritten(source.fNWritten.size(), 0)
1626{
1627 for (const auto &f : source.GetConstSubfields())
1628 Attach(f->Clone(f->GetFieldName()));
1629 fTraits = source.fTraits;
1630}
1631
1632ROOT::RVariantField::RVariantField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1633 : ROOT::RFieldBase(fieldName, "std::variant<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">",
1634 ROOT::ENTupleStructure::kVariant, false /* isSimple */)
1635{
1636 // The variant needs to initialize its own tag member
1638
1639 const std::string typeAlias = "std::variant<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
1640 if (typeAlias != GetTypeName())
1642
1643 auto nFields = itemFields.size();
1644 if (nFields == 0 || nFields > kMaxVariants) {
1645 throw RException(R__FAIL("invalid number of variant fields (outside [1.." + std::to_string(kMaxVariants) + ")"));
1646 }
1647 fNWritten.resize(nFields, 0);
1648 for (unsigned int i = 0; i < nFields; ++i) {
1651 fTraits &= itemFields[i]->GetTraits();
1652 Attach(std::move(itemFields[i]), "_" + std::to_string(i));
1653 }
1654
1655 // With certain template parameters, the union of members of an std::variant starts at an offset > 0.
1656 // For instance, std::variant<std::optional<int>> on macOS.
1657 auto cl = TClass::GetClass(GetTypeName().c_str());
1658 assert(cl);
1659 auto dm = reinterpret_cast<TDataMember *>(cl->GetListOfDataMembers()->First());
1660 if (dm)
1661 fVariantOffset = dm->GetOffset();
1662
1663 const auto tagSize = GetVariantTagSize();
1664 const auto padding = tagSize - (fMaxItemSize % tagSize);
1666}
1667
1668std::unique_ptr<ROOT::RFieldBase> ROOT::RVariantField::CloneImpl(std::string_view newName) const
1669{
1670 return std::unique_ptr<RVariantField>(new RVariantField(newName, *this));
1671}
1672
1673std::uint8_t ROOT::RVariantField::GetTag(const void *variantPtr, std::size_t tagOffset)
1674{
1675 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1676 auto tag = *reinterpret_cast<const TagType_t *>(reinterpret_cast<const unsigned char *>(variantPtr) + tagOffset);
1677 return (tag == TagType_t(-1)) ? 0 : tag + 1;
1678}
1679
1680void ROOT::RVariantField::SetTag(void *variantPtr, std::size_t tagOffset, std::uint8_t tag)
1681{
1682 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1683 auto tagPtr = reinterpret_cast<TagType_t *>(reinterpret_cast<unsigned char *>(variantPtr) + tagOffset);
1684 *tagPtr = (tag == 0) ? TagType_t(-1) : static_cast<TagType_t>(tag - 1);
1685}
1686
1687std::size_t ROOT::RVariantField::AppendImpl(const void *from)
1688{
1689 auto tag = GetTag(from, fTagOffset);
1690 std::size_t nbytes = 0;
1691 auto index = 0;
1692 if (tag > 0) {
1693 nbytes += CallAppendOn(*fSubfields[tag - 1], reinterpret_cast<const unsigned char *>(from) + fVariantOffset);
1694 index = fNWritten[tag - 1]++;
1695 }
1697 fPrincipalColumn->Append(&varSwitch);
1698 return nbytes + sizeof(ROOT::Internal::RColumnSwitch);
1699}
1700
1702{
1704 std::uint32_t tag;
1705 fPrincipalColumn->GetSwitchInfo(globalIndex, &variantIndex, &tag);
1706 R__ASSERT(tag < 256);
1707
1708 // If `tag` equals 0, the variant is in the invalid state, i.e, it does not hold any of the valid alternatives in
1709 // the type list. This happens, e.g., if the field was late added; in this case, keep the invalid tag, which makes
1710 // any `std::holds_alternative<T>` check fail later.
1711 if (R__likely(tag > 0)) {
1712 void *varPtr = reinterpret_cast<unsigned char *>(to) + fVariantOffset;
1713 CallConstructValueOn(*fSubfields[tag - 1], varPtr);
1714 CallReadOn(*fSubfields[tag - 1], variantIndex, varPtr);
1715 }
1716 SetTag(to, fTagOffset, tag);
1717}
1718
1724
1729
1734
1736{
1737 static const std::vector<std::string> prefixes = {"std::variant<"};
1738
1739 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1740 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1741
1742 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1743 if (fSubfields.size() != fieldDesc.GetLinkIds().size()) {
1744 throw RException(R__FAIL("number of variants on-disk do not match for " + GetQualifiedFieldName() + "\n" +
1745 Internal::GetTypeTraceReport(*this, desc)));
1746 }
1747}
1748
1750{
1751 memset(where, 0, GetValueSize());
1752 CallConstructValueOn(*fSubfields[0], reinterpret_cast<unsigned char *>(where) + fVariantOffset);
1753 SetTag(where, fTagOffset, 1);
1754}
1755
1757{
1758 auto tag = GetTag(objPtr, fTagOffset);
1759 if (tag > 0) {
1760 fItemDeleters[tag - 1]->operator()(reinterpret_cast<unsigned char *>(objPtr) + fVariantOffset, true /*dtorOnly*/);
1761 }
1762 RDeleter::operator()(objPtr, dtorOnly);
1763}
1764
1765std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RVariantField::GetDeleter() const
1766{
1767 std::vector<std::unique_ptr<RDeleter>> itemDeleters;
1768 itemDeleters.reserve(fSubfields.size());
1769 for (const auto &f : fSubfields) {
1770 itemDeleters.emplace_back(GetDeleterOf(*f));
1771 }
1772 return std::make_unique<RVariantDeleter>(fTagOffset, fVariantOffset, std::move(itemDeleters));
1773}
1774
1776{
1777 return std::max(fMaxAlignment, alignof(RVariantTag<GetVariantTagSize()>::ValueType_t));
1778}
1779
1781{
1782 const auto alignment = GetAlignment();
1783 const auto actualSize = fTagOffset + GetVariantTagSize();
1784 const auto padding = alignment - (actualSize % alignment);
1785 return actualSize + ((padding == alignment) ? 0 : padding);
1786}
1787
1789{
1790 std::fill(fNWritten.begin(), fNWritten.end(), 0);
1791}
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 r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize 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:148
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:2326
EState GetState() const
Definition TClass.h:504
void BuildRealData(void *pointer=nullptr, Bool_t isTransient=kFALSE)
Build a full list of persistent data members.
Definition TClass.cxx:2038
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3828
TList * GetListOfRealData() const
Definition TClass.h:468
Int_t Size() const
Return size of object of this class.
Definition TClass.cxx:5806
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3694
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:2918
Long_t ClassProperty() const
Return the C++ property of this class, eg.
Definition TClass.cxx:2403
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6191
@ 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:2994
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.