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
19#include <ROOT/RField.hxx>
20#include <ROOT/RFieldBase.hxx>
21#include <ROOT/RFieldUtils.hxx>
23#include <ROOT/RNTupleUtils.hxx>
24#include <ROOT/RSpan.hxx>
25
26#include <TBaseClass.h>
27#include <TBufferFile.h>
28#include <TClass.h>
29#include <TClassEdit.h>
30#include <TDataMember.h>
31#include <TEnum.h>
32#include <TObject.h>
33#include <TObjArray.h>
34#include <TObjString.h>
35#include <TRealData.h>
36#include <TSchemaRule.h>
37#include <TSchemaRuleSet.h>
38#include <TStreamerElement.h>
39#include <TVirtualObject.h>
41
42#include <algorithm>
43#include <array>
44#include <cstddef> // std::size_t
45#include <cstdint> // std::uint32_t et al.
46#include <cstring> // for memset
47#include <memory>
48#include <mutex>
49#include <string>
50#include <string_view>
51#include <unordered_set>
52#include <utility>
53#include <variant>
54
56
57namespace {
58
59TClass *EnsureValidClass(std::string_view className)
60{
61 auto cl = TClass::GetClass(std::string(className).c_str());
62 if (cl == nullptr) {
63 throw ROOT::RException(R__FAIL("RField: no I/O support for type " + std::string(className)));
64 }
65 return cl;
66}
67
68/// Common checks used both by RClassField and RSoAField
69void EnsureValidUserClass(TClass *cl, const ROOT::RFieldBase &field, std::string_view fieldType)
70{
71 if (cl->GetState() < TClass::kInterpreted) {
72 throw ROOT::RException(R__FAIL(std::string(fieldType) + " " + cl->GetName() +
73 " cannot be constructed from a class that's not at least Interpreted"));
74 }
75 // Avoid accidentally supporting std types through TClass.
76 if (cl->Property() & kIsDefinedInStd) {
77 throw ROOT::RException(R__FAIL(field.GetTypeName() + " is not supported"));
78 }
79 if (field.GetTypeName() == "TObject") {
80 throw ROOT::RException(R__FAIL("TObject is only supported through RField<TObject>"));
81 }
82 if (cl->GetCollectionProxy()) {
83 throw ROOT::RException(R__FAIL(field.GetTypeName() + " has an associated collection proxy; "
84 "use RProxiedCollectionField instead"));
85 }
86 // Classes with, e.g., custom streamers are not supported through this field. Empty classes, however, are.
87 // Can be overwritten with the "rntuple.streamerMode=true" class attribute
88 if (!cl->CanSplit() && cl->Size() > 1 &&
90 throw ROOT::RException(R__FAIL(field.GetTypeName() + " cannot be stored natively in RNTuple"));
91 }
94 throw ROOT::RException(
95 R__FAIL(field.GetTypeName() + " has streamer mode enforced, not supported as native RNTuple class"));
96 }
97 // Detect custom streamers set on individual members at runtime via
98 // TClass::SetMemberStreamer() or TClass::AdoptMemberStreamer().
99 // CanSplit() only checks for custom streamers set at compile time (fHasCustomStreamerMember),
100 // but runtime streamers are stored in TRealData and must be checked here.
101 if (!cl->GetListOfRealData()) {
102 cl->BuildRealData();
103 }
104 for (auto realMember : ROOT::Detail::TRangeStaticCast<TRealData>(*cl->GetListOfRealData())) {
105 if (realMember->GetStreamer()) {
106 throw ROOT::RException(R__FAIL(std::string(field.GetTypeName()) + " has member " + realMember->GetName() +
107 " with a custom streamer; not supported natively in RNTuple"));
108 }
109 }
110}
111
112TEnum *EnsureValidEnum(std::string_view enumName)
113{
114 auto e = TEnum::GetEnum(std::string(enumName).c_str());
115 if (e == nullptr) {
116 throw ROOT::RException(R__FAIL("RField: no I/O support for enum type " + std::string(enumName)));
117 }
118 return e;
119}
120
121void EnsureValidAlignment(std::size_t align)
122{
124 throw ROOT::RException(R__FAIL(std::string("invalid alignment: ") + std::to_string(align)));
125}
126
127/// Create a comma-separated list of type names from the given fields. Uses either the real type names or the
128/// type aliases (if there are any, otherwise the actual type name). Used to construct template argument lists
129/// for templated types such as std::pair<...>, std::tuple<...>, std::variant<...>.
130std::string GetTypeList(std::span<std::unique_ptr<ROOT::RFieldBase>> itemFields, bool useTypeAliases)
131{
132 std::string result;
133 for (size_t i = 0; i < itemFields.size(); ++i) {
134 if (useTypeAliases && !itemFields[i]->GetTypeAlias().empty()) {
135 result += itemFields[i]->GetTypeAlias();
136 } else {
137 result += itemFields[i]->GetTypeName();
138 }
139 result.push_back(',');
140 }
141 if (result.empty()) {
142 throw ROOT::RException(R__FAIL("invalid empty type list provided as template argument"));
143 }
144 result.pop_back(); // remove trailing comma
145 return result;
146}
147
149{
150 std::string typePrefix;
151 switch (setType) {
152 case ROOT::RSetField::ESetType::kSet: typePrefix = "std::set<"; break;
153 case ROOT::RSetField::ESetType::kUnorderedSet: typePrefix = "std::unordered_set<"; break;
154 case ROOT::RSetField::ESetType::kMultiSet: typePrefix = "std::multiset<"; break;
155 case ROOT::RSetField::ESetType::kUnorderedMultiSet: typePrefix = "std::unordered_multiset<"; break;
156 default: R__ASSERT(false);
157 }
158 return typePrefix +
159 ((useTypeAlias && !innerField.GetTypeAlias().empty()) ? innerField.GetTypeAlias()
160 : innerField.GetTypeName()) +
161 ">";
162}
163
165{
166 if (const auto pairField = dynamic_cast<const ROOT::RPairField *>(innerField)) {
167 std::string typePrefix;
168 switch (mapType) {
169 case ROOT::RMapField::EMapType::kMap: typePrefix = "std::map<"; break;
170 case ROOT::RMapField::EMapType::kUnorderedMap: typePrefix = "std::unordered_map<"; break;
171 case ROOT::RMapField::EMapType::kMultiMap: typePrefix = "std::multimap<"; break;
172 case ROOT::RMapField::EMapType::kUnorderedMultiMap: typePrefix = "std::unordered_multimap<"; break;
173 default: R__ASSERT(false);
174 }
175 const auto &items = pairField->GetConstSubfields();
176 std::string type = typePrefix;
177 for (int i : {0, 1}) {
178 if (useTypeAliases && !items[i]->GetTypeAlias().empty()) {
179 type += items[i]->GetTypeAlias();
180 } else {
181 type += items[i]->GetTypeName();
182 }
183 if (i == 0)
184 type.push_back(',');
185 }
186 return type + ">";
187 }
188
189 throw ROOT::RException(R__FAIL("RMapField inner field type must be of RPairField"));
190}
191
192} // anonymous namespace
193
195 : ROOT::RFieldBase(fieldName, source.GetTypeName(), ROOT::ENTupleStructure::kRecord, false /* isSimple */),
197 fSubfieldsInfo(source.fSubfieldsInfo)
198{
199 for (const auto &f : source.GetConstSubfields()) {
200 RFieldBase::Attach(f->Clone(f->GetFieldName()));
201 }
202 fTraits = source.GetTraits();
203}
204
205ROOT::RClassField::RClassField(std::string_view fieldName, std::string_view className)
207{
208}
209
211 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kRecord,
212 false /* isSimple */),
214{
215 EnsureValidUserClass(fClass, *this, "RClassField");
216
218 throw ROOT::RException(R__FAIL(GetTypeName() + " is a SoA field and connot be used through RClassField"));
219 }
220
225
226 std::string renormalizedAlias;
229
230 int i = 0;
231 const auto *bases = fClass->GetListOfBases();
232 assert(bases);
234 if (baseClass->GetDelta() < 0) {
235 throw RException(R__FAIL(std::string("virtual inheritance is not supported: ") + GetTypeName() +
236 " virtually inherits from " + baseClass->GetName()));
237 }
238 TClass *c = baseClass->GetClassPointer();
239 auto subField =
240 RFieldBase::Create(std::string(kPrefixInherited) + "_" + std::to_string(i), c->GetName()).Unwrap();
241 fTraits &= subField->GetTraits();
242 Attach(std::move(subField), RSubfieldInfo{kBaseClass, static_cast<std::size_t>(baseClass->GetDelta())});
243 i++;
244 }
246 // Skip, for instance, unscoped enum constants defined in the class
247 if (dataMember->Property() & kIsStatic)
248 continue;
249 // Skip members explicitly marked as transient by user comment
250 if (!dataMember->IsPersistent()) {
251 // TODO(jblomer): we could do better
253 continue;
254 }
255
256 // NOTE: we use the already-resolved type name for the fields, otherwise TClass::GetClass may fail to resolve
257 // context-dependent types (e.g. typedefs defined in the class itself - which will not be fully qualified in
258 // the string returned by dataMember->GetFullTypeName())
259 std::string typeName{dataMember->GetTrueTypeName()};
260
261 // For C-style arrays, complete the type name with the size for each dimension, e.g. `int[4][2]`
262 if (dataMember->Property() & kIsArray) {
263 for (int dim = 0, n = dataMember->GetArrayDim(); dim < n; ++dim) {
264 typeName += "[" + std::to_string(dataMember->GetMaxIndex(dim)) + "]";
265 }
266 }
267
268 auto subField = RFieldBase::Create(dataMember->GetName(), typeName).Unwrap();
269
270 fTraits &= subField->GetTraits();
271 Attach(std::move(subField), RSubfieldInfo{kDataMember, static_cast<std::size_t>(dataMember->GetOffset())});
272 }
274}
275
277{
278 if (fStagingArea) {
279 for (const auto &[_, si] : fStagingItems) {
280 if (!(si.fField->GetTraits() & kTraitTriviallyDestructible)) {
281 auto deleter = GetDeleterOf(*si.fField);
282 deleter->operator()(fStagingArea.get() + si.fOffset, true /* dtorOnly */);
283 }
284 }
285 }
286}
287
288void ROOT::RClassField::Attach(std::unique_ptr<RFieldBase> child, RSubfieldInfo info)
289{
290 fSubfieldsInfo.push_back(info);
291 RFieldBase::Attach(std::move(child));
292}
293
294std::vector<const ROOT::TSchemaRule *> ROOT::RClassField::FindRules(const ROOT::RFieldDescriptor *fieldDesc)
295{
297 const auto ruleset = fClass->GetSchemaRules();
298 if (!ruleset)
299 return rules;
300
301 if (!fieldDesc) {
302 // If we have no on-disk information for the field, we still process the rules on the current in-memory version
303 // of the class
304 rules = ruleset->FindRules(fClass->GetName(), fClass->GetClassVersion(), fClass->GetCheckSum());
305 } else {
306 // We need to change (back) the name normalization from RNTuple to ROOT Meta
307 std::string normalizedName;
309 // We do have an on-disk field that correspond to the current RClassField instance. Ask for rules matching the
310 // on-disk version of the field.
311 if (fieldDesc->GetTypeChecksum()) {
312 rules = ruleset->FindRules(normalizedName, fieldDesc->GetTypeVersion(), *fieldDesc->GetTypeChecksum());
313 } else {
314 rules = ruleset->FindRules(normalizedName, fieldDesc->GetTypeVersion());
315 }
316 }
317
318 // Cleanup and sort rules
319 // Check that any any given source member uses the same type in all rules
320 std::unordered_map<std::string, std::string> sourceNameAndType;
321 std::size_t nskip = 0; // skip whole-object-rules that were moved to the end of the rules vector
322 for (auto itr = rules.begin(); itr != rules.end() - nskip;) {
323 const auto rule = *itr;
324
325 // Erase unknown rule types
326 if (rule->GetRuleType() != ROOT::TSchemaRule::kReadRule) {
328 << "ignoring I/O customization rule with unsupported type: " << rule->GetRuleType();
329 itr = rules.erase(itr);
330 continue;
331 }
332
333 bool hasConflictingSourceMembers = false;
334 for (auto source : TRangeDynCast<TSchemaRule::TSources>(rule->GetSource())) {
335 auto memberType = source->GetTypeForDeclaration() + source->GetDimensions();
336 auto [itrSrc, isNew] = sourceNameAndType.emplace(source->GetName(), memberType);
337 if (!isNew && (itrSrc->second != memberType)) {
339 << "ignoring I/O customization rule due to conflicting source member type: " << itrSrc->second << " vs. "
340 << memberType << " for member " << source->GetName();
342 break;
343 }
344 }
346 itr = rules.erase(itr);
347 continue;
348 }
349
350 // Rules targeting the entire object need to be executed at the end
351 if (rule->GetTarget() == nullptr) {
352 nskip++;
353 if (itr != rules.end() - nskip)
354 std::iter_swap(itr++, rules.end() - nskip);
355 continue;
356 }
357
358 ++itr;
359 }
360
361 return rules;
362}
363
364std::unique_ptr<ROOT::RFieldBase> ROOT::RClassField::CloneImpl(std::string_view newName) const
365{
366 return std::unique_ptr<RClassField>(new RClassField(newName, *this));
367}
368
369std::size_t ROOT::RClassField::AppendImpl(const void *from)
370{
371 std::size_t nbytes = 0;
372 for (unsigned i = 0; i < fSubfields.size(); i++) {
373 nbytes += CallAppendOn(*fSubfields[i], static_cast<const unsigned char *>(from) + fSubfieldsInfo[i].fOffset);
374 }
375 return nbytes;
376}
377
379{
380 for (const auto &[_, si] : fStagingItems) {
381 CallReadOn(*si.fField, globalIndex, fStagingArea.get() + si.fOffset);
382 }
383 for (unsigned i = 0; i < fSubfields.size(); i++) {
384 CallReadOn(*fSubfields[i], globalIndex, static_cast<unsigned char *>(to) + fSubfieldsInfo[i].fOffset);
385 }
386}
387
389{
390 for (const auto &[_, si] : fStagingItems) {
391 CallReadOn(*si.fField, localIndex, fStagingArea.get() + si.fOffset);
392 }
393 for (unsigned i = 0; i < fSubfields.size(); i++) {
394 CallReadOn(*fSubfields[i], localIndex, static_cast<unsigned char *>(to) + fSubfieldsInfo[i].fOffset);
395 }
396}
397
400{
403 return idSourceMember;
404
405 for (const auto &subFieldDesc : desc.GetFieldIterable(classFieldId)) {
406 const auto subFieldName = subFieldDesc.GetFieldName();
407 if (subFieldName.length() > 2 && subFieldName[0] == ':' && subFieldName[1] == '_') {
408 idSourceMember = LookupMember(desc, memberName, subFieldDesc.GetId());
410 return idSourceMember;
411 }
412 }
413
415}
416
417void ROOT::RClassField::SetStagingClass(const std::string &className, unsigned int classVersion)
418{
419 TClass::GetClass(className.c_str())->GetStreamerInfo(classVersion);
420 if (classVersion != GetTypeVersion() || className != GetTypeName()) {
421 fStagingClass = TClass::GetClass((className + std::string("@@") + std::to_string(classVersion)).c_str());
422 if (!fStagingClass) {
423 // For a rename rule, we may simply ask for the old class name
424 fStagingClass = TClass::GetClass(className.c_str());
425 }
426 } else {
427 fStagingClass = fClass;
428 }
429 R__ASSERT(fStagingClass);
430 R__ASSERT(static_cast<unsigned int>(fStagingClass->GetClassVersion()) == classVersion);
431}
432
433void ROOT::RClassField::PrepareStagingArea(const std::vector<const TSchemaRule *> &rules,
434 const ROOT::RNTupleDescriptor &desc,
436{
437 std::size_t stagingAreaSize = 0;
438 for (const auto rule : rules) {
439 for (auto source : TRangeDynCast<TSchemaRule::TSources>(rule->GetSource())) {
440 auto [itr, isNew] = fStagingItems.emplace(source->GetName(), RStagingItem());
441 if (!isNew) {
442 // This source member has already been processed by another rule (and we only support one type per member)
443 continue;
444 }
445 RStagingItem &stagingItem = itr->second;
446
447 const auto memberFieldId = LookupMember(desc, source->GetName(), classFieldDesc.GetId());
449 throw RException(R__FAIL(std::string("cannot find on disk rule source member ") + GetTypeName() + "." +
450 source->GetName()));
451 }
452
453 auto memberType = source->GetTypeForDeclaration() + source->GetDimensions();
454 auto memberField = Create("" /* we don't need a field name */, std::string(memberType)).Unwrap();
455 memberField->SetOnDiskId(memberFieldId);
456 auto fieldZero = std::make_unique<RFieldZero>();
458 fieldZero->Attach(std::move(memberField));
459 stagingItem.fField = std::move(fieldZero);
460
461 stagingItem.fOffset = fStagingClass->GetDataMemberOffset(source->GetName());
462 // Since we successfully looked up the source member in the RNTuple on-disk metadata, we expect it
463 // to be present in the TClass instance, too.
465 stagingAreaSize = std::max(stagingAreaSize, stagingItem.fOffset + stagingItem.fField->begin()->GetValueSize());
466 }
467 }
468
469 if (stagingAreaSize) {
470 R__ASSERT(static_cast<Int_t>(stagingAreaSize) <= fStagingClass->Size()); // we may have removed rules
471 // We use std::make_unique instead of MakeUninitArray to zero-initialize the staging area.
472 fStagingArea = std::make_unique<unsigned char[]>(stagingAreaSize);
473
474 for (const auto &[_, si] : fStagingItems) {
475 const auto &memberField = *si.fField->cbegin();
476 if (!(memberField.GetTraits() & kTraitTriviallyConstructible)) {
477 CallConstructValueOn(memberField, fStagingArea.get() + si.fOffset);
478 }
479 }
480 }
481}
482
484{
485 auto func = rule->GetReadFunctionPointer();
486 if (func == nullptr) {
487 // Can happen for rename rules
488 return;
489 }
490 fReadCallbacks.emplace_back([func, stagingClass = fStagingClass, stagingArea = fStagingArea.get()](void *target) {
491 TVirtualObject onfileObj{nullptr};
492 onfileObj.fClass = stagingClass;
493 onfileObj.fObject = stagingArea;
494 func(static_cast<char *>(target), &onfileObj);
495 onfileObj.fObject = nullptr; // TVirtualObject does not own the value
496 });
497}
498
500{
501 std::vector<const TSchemaRule *> rules;
502 // On-disk members that are not targeted by an I/O rule; all other sub fields of the in-memory class
503 // will be marked as artificial (added member in a new class version or member set by rule).
504 std::unordered_set<std::string> regularSubfields;
505 // We generally don't support changing the number of base classes, with the exception of changing from/to zero
506 // base classes. The variable stores the number of on-disk base classes.
507 int nOnDiskBaseClasses = 0;
508
509 if (GetOnDiskId() == kInvalidDescriptorId) {
510 // This can happen for added base classes or added members of class type
511 rules = FindRules(nullptr);
512 if (!rules.empty())
513 SetStagingClass(GetTypeName(), GetTypeVersion());
514 } else {
515 const auto descriptorGuard = pageSource.GetSharedDescriptorGuard();
516 const ROOT::RNTupleDescriptor &desc = descriptorGuard.GetRef();
517 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
518
519 if (fieldDesc.GetStructure() == ENTupleStructure::kStreamer) {
520 // Streamer field on disk but meanwhile the type can be represented as a class field; replace this field
521 // by a streamer field to read the data from disk.
522 auto substitute = std::make_unique<RStreamerField>(GetFieldName(), GetTypeName());
523 substitute->SetOnDiskId(GetOnDiskId());
524 return substitute;
525 }
526
527 for (auto linkId : fieldDesc.GetLinkIds()) {
528 const auto &subFieldDesc = desc.GetFieldDescriptor(linkId);
529 regularSubfields.insert(subFieldDesc.GetFieldName());
530 if (!subFieldDesc.GetFieldName().empty() && subFieldDesc.GetFieldName()[0] == ':')
532 }
533
534 rules = FindRules(&fieldDesc);
535
536 // 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
537 // (source) type name and version/checksum.
538 if (rules.empty()) {
539 // Otherwise we require compatible type names, after renormalization. GetTypeName() is already renormalized,
540 // but RNTuple data written with ROOT v6.34 might not have renormalized the field type name. Ask the
541 // RNTupleDescriptor, which knows about the spec version, for a fixed up type name.
543 if (GetTypeName() != descTypeName) {
544 throw RException(R__FAIL("incompatible type name for field " + GetFieldName() + ": " + GetTypeName() +
545 " vs. " + descTypeName));
546 }
547 }
548
549 const bool hasSources = std::any_of(rules.begin(), rules.end(), [](const auto &r) {
550 return r->GetSource() && (r->GetSource()->GetEntries() > 0);
551 });
552
553 // A staging class (conversion streamer info) only exists if there is at least one rule that has an
554 // on disk source member defined.
555 if (hasSources) {
556 // For unversioned classes, the in-memory layout may by chance have the same transient version number
557 // than the recorded (transient, at the time of writing) on-disk version. Therefore, we also need to compare
558 // the checksums to find out if we need a conversion streamer info.
559 std::uint32_t assignedVersionForOnDiskLayout = fieldDesc.GetTypeVersion();
560 R__ASSERT(fieldDesc.GetTypeChecksum());
561 if (fieldDesc.GetTypeVersion() != GetTypeVersion() || *fieldDesc.GetTypeChecksum() != fClass->GetCheckSum() ||
562 fieldDesc.GetTypeName() != GetTypeName()) {
563 // We need the on-disk streamer info for the conversion streamer info
564 pageSource.LoadStreamerInfo();
565
566 auto oldCl = TClass::GetClass(fieldDesc.GetTypeName().c_str());
568 auto onDiskStreamerInfo = oldCl->FindStreamerInfo(*fieldDesc.GetTypeChecksum());
571 }
572 SetStagingClass(fieldDesc.GetTypeName(), assignedVersionForOnDiskLayout);
573 PrepareStagingArea(rules, desc, fieldDesc);
574 for (auto &[_, si] : fStagingItems) {
576 si.fField = std::move(static_cast<RFieldZero *>(si.fField.get())->ReleaseSubfields()[0]);
577 }
578 }
579
580 // Remove target member of read rules from the list of regular members of the underlying on-disk field
581 for (const auto rule : rules) {
582 if (!rule->GetTarget())
583 continue;
584
585 for (const auto target : ROOT::Detail::TRangeStaticCast<const TObjString>(*rule->GetTarget())) {
586 regularSubfields.erase(std::string(target->GetString()));
587 }
588 }
589 }
590
591 for (const auto rule : rules) {
592 AddReadCallbacksFromIORule(rule);
593 }
594
595 // Iterate over all sub fields in memory and mark those as missing that are not in the descriptor.
596 int nInMemoryBaseClasses = 0;
597 for (auto &field : fSubfields) {
598 const auto &fieldName = field->GetFieldName();
599 if (regularSubfields.count(fieldName) == 0) {
600 CallSetArtificialOn(*field);
601 }
602 if (!fieldName.empty() && fieldName[0] == ':')
604 }
605
607 throw RException(R__FAIL(std::string("incompatible number of base classes for field ") + GetFieldName() + ": " +
608 GetTypeName() + ", " + std::to_string(nInMemoryBaseClasses) +
609 " base classes in memory "
610 " vs. " +
611 std::to_string(nOnDiskBaseClasses) + " base classes on-disk\n" +
612 Internal::GetTypeTraceReport(*this, pageSource.GetSharedDescriptorGuard().GetRef())));
613 }
614
615 return nullptr;
616}
617
619{
620 EnsureMatchingOnDiskField(desc, kDiffTypeVersion | kDiffTypeName).ThrowOnError();
621}
622
624{
625 fClass->New(where);
626}
627
629{
630 fClass->Destructor(objPtr, true /* dtorOnly */);
631 RDeleter::operator()(objPtr, dtorOnly);
632}
633
634std::vector<ROOT::RFieldBase::RValue> ROOT::RClassField::SplitValue(const RValue &value) const
635{
636 std::vector<RValue> result;
637 auto valuePtr = value.GetPtr<void>();
638 auto charPtr = static_cast<unsigned char *>(valuePtr.get());
639 result.reserve(fSubfields.size());
640 for (unsigned i = 0; i < fSubfields.size(); i++) {
641 result.emplace_back(
642 fSubfields[i]->BindValue(std::shared_ptr<void>(valuePtr, charPtr + fSubfieldsInfo[i].fOffset)));
643 }
644 return result;
645}
646
648{
649 return fClass->GetClassSize();
650}
651
653{
654 const auto align = fClass->GetClassAlignment();
656 return align;
657}
658
660{
661 return fClass->GetClassVersion();
662}
663
665{
666 return fClass->GetCheckSum();
667}
668
669const std::type_info *ROOT::RClassField::GetPolymorphicTypeInfo() const
670{
671 bool polymorphic = fClass->ClassProperty() & kClassHasVirtual;
672 if (!polymorphic) {
673 return nullptr;
674 }
675 return fClass->GetTypeInfo();
676}
677
679{
680 visitor.VisitClassField(*this);
681}
682
683//------------------------------------------------------------------------------
684
686 : ROOT::RFieldBase(fieldName, source.GetTypeName(), ROOT::ENTupleStructure::kCollection, false /* isSimple */),
687 fSoAClass(source.fSoAClass),
688 fSoAMemberOffsets(source.fSoAMemberOffsets)
689{
690 fTraits = source.GetTraits();
691 Attach(source.fSubfields[0]->Clone(source.fSubfields[0]->GetFieldName()));
692 fRecordMemberFields = fSubfields[0]->GetMutableSubfields();
693}
694
695ROOT::Experimental::RSoAField::RSoAField(std::string_view fieldName, std::string_view className)
697{
698}
699
701 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(clSoA->GetName()), ROOT::ENTupleStructure::kCollection,
702 false /* isSimple */),
703 fSoAClass(clSoA)
704{
705 static std::once_flag once;
706 std::call_once(once, []() {
707 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "The SoA field is experimental and still under development.";
708 });
709
710 EnsureValidUserClass(fSoAClass, *this, "RSoAField");
712 if (recordTypeName.empty()) {
713 throw ROOT::RException(R__FAIL(std::string("class ") + GetTypeName() +
714 " is not marked with the rntupleSoARecord "
715 "dictionary option; cannot create corresponding RSoAField."));
716 }
717 try {
718 Attach(std::make_unique<ROOT::RClassField>("_0", recordTypeName));
719 } catch (ROOT::RException &e) {
720 throw RException(R__FAIL("invalid record type of SoA field " + GetTypeName() + " [" + e.what() + "]"));
721 }
723 if (static_cast<std::uint32_t>(fSoAClass->GetClassVersion()) != fSubfields[0]->GetTypeVersion()) {
724 throw RException(R__FAIL(std::string("version mismatch between SoA type and underlying record type: ") +
725 std::to_string(fSoAClass->GetClassVersion()) + " vs. " +
726 std::to_string(fSubfields[0]->GetTypeVersion())));
727 }
728 fRecordMemberFields = fSubfields[0]->GetMutableSubfields();
729
730 std::unordered_map<std::string, std::size_t> recordFieldNameToIdx;
731 for (std::size_t i = 0; i < fRecordMemberFields.size(); ++i) {
732 const RFieldBase *f = fRecordMemberFields[i];
733 assert(!f->GetFieldName().empty());
734 if (f->GetFieldName()[0] == ':') {
735 throw RException(R__FAIL("SoA fields with inheritance are currently unsupported"));
736 }
737 recordFieldNameToIdx[f->GetFieldName()] = i;
738 }
739
740 const auto *bases = fSoAClass->GetListOfBases();
741 assert(bases);
743 if (baseClass->GetDelta() < 0) {
744 throw RException(R__FAIL(std::string("virtual inheritance is not supported: ") + GetTypeName() +
745 " virtually inherits from " + baseClass->GetName()));
746 }
747 // At a later point, we will support inheritance
748 throw RException(R__FAIL("SoA fields with inheritance are currently unsupported"));
749 }
750
752 unsigned int nMembers = 0;
754 if ((dataMember->Property() & kIsStatic) || !dataMember->IsPersistent())
755 continue;
756
757 if (dataMember->Property() & kIsArray) {
758 throw RException(R__FAIL(std::string("unsupported array type in SoA class: ") + dataMember->GetName()));
759 }
760
761 const std::string typeName{dataMember->GetTrueTypeName()};
762 auto subField = RFieldBase::Create(dataMember->GetName(), typeName).Unwrap();
763 auto vecFieldPtr = dynamic_cast<RRVecField *>(subField.get());
764 if (!vecFieldPtr) {
765 throw RException(R__FAIL("invalid field type in SoA class: " + subField->GetTypeName()));
766 }
767 subField.release();
768 auto vecField = std::unique_ptr<RRVecField>(vecFieldPtr);
769
770 auto itr = recordFieldNameToIdx.find(vecField->GetFieldName());
771 if (itr == recordFieldNameToIdx.end()) {
772 throw RException(R__FAIL(std::string("unexpected SoA member: ") + vecField->GetFieldName()));
773 }
775 if (vecField->begin()->GetTypeName() != memberField->GetTypeName() ||
776 vecField->begin()->GetTypeAlias() != memberField->GetTypeAlias()) {
777 const std::string leftType =
778 vecField->begin()->GetTypeName() +
779 (vecField->begin()->GetTypeAlias().empty() ? "" : " [" + vecField->begin()->GetTypeAlias() + "]");
780 const std::string rightType =
781 memberField->GetTypeName() +
782 (memberField->GetTypeAlias().empty() ? "" : " [" + memberField->GetTypeAlias() + "]");
783 throw RException(R__FAIL(std::string("SoA member type mismatch: ") + vecField->GetFieldName() + " (" +
784 leftType + " vs. " + rightType + ")"));
785 }
786
787 assert(itr->second < fSoAMemberOffsets.size());
788 fSoAMemberOffsets[itr->second] = dataMember->GetOffset();
789 nMembers++;
790 }
791 if (recordFieldNameToIdx.size() != nMembers) {
792 throw RException(R__FAIL("missing SoA members"));
793 }
794
795 std::string renormalizedAlias;
798
800}
801
802std::unique_ptr<ROOT::RFieldBase> ROOT::Experimental::RSoAField::CloneImpl(std::string_view newName) const
803{
804 return std::unique_ptr<RSoAField>(new RSoAField(newName, *this));
805}
806
816
821
826
827std::size_t ROOT::Experimental::RSoAField::AppendImpl(const void *from)
828{
829 const std::size_t nSoAMembers = fSoAMemberOffsets.size();
830
831 std::size_t N = 0; // Set by first SoA member and verified for the rest
832 for (std::size_t i = 0; i < nSoAMembers; ++i) {
833 const void *rvecPtr = static_cast<const unsigned char *>(from) + fSoAMemberOffsets[i];
835 assert(*sizePtr >= 0);
836 if (i == 0) {
837 N = *sizePtr;
838 } else {
839 if (static_cast<std::size_t>(*sizePtr) != N) {
840 const auto f = fRecordMemberFields[i];
841 throw RException(R__FAIL("SoA length mismatch for " + f->GetFieldName() + ": " + std::to_string(*sizePtr) +
842 " vs. " + std::to_string(N) + " (expected)"));
843 }
844 }
845 }
846
847 std::size_t nbytes = 0;
848 if (N > 0) {
849 for (std::size_t i = 0; i < nSoAMembers; ++i) {
850 const void *rvecPtr = static_cast<const unsigned char *>(from) + fSoAMemberOffsets[i];
852 RFieldBase *memberField = fRecordMemberFields[i];
853 if (memberField->IsSimple()) {
854 GetPrincipalColumnOf(*memberField)->AppendV(*beginPtr, N);
855 nbytes += N * GetPrincipalColumnOf(*memberField)->GetElement()->GetPackedSize();
856 } else {
857 for (std::size_t j = 0; j < N; ++j) {
858 nbytes += CallAppendOn(*memberField, *beginPtr + j * memberField->GetValueSize());
859 }
860 }
861 }
862 }
863
864 fNWritten += N;
865 fPrincipalColumn->Append(&fNWritten);
866 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
867}
868
870{
871 throw RException(R__FAIL("not yet implemented"));
872}
873
875{
876 fSoAClass->New(where);
877}
878
880{
881 fSoAClass->Destructor(objPtr, true /* dtorOnly */);
882 RDeleter::operator()(objPtr, dtorOnly);
883}
884
885std::vector<ROOT::RFieldBase::RValue> ROOT::Experimental::RSoAField::SplitValue(const RValue & /* value */) const
886{
887 throw RException(R__FAIL("not yet implemented"));
888 return std::vector<RValue>();
889}
890
892{
893 return fSoAClass->GetClassSize();
894}
895
897{
898 return fSoAClass->GetClassVersion();
899}
900
902{
903 return fSoAClass->GetCheckSum();
904}
905
907{
908 const auto align = fSoAClass->GetClassAlignment();
910 return align;
911}
912
914{
915 // TODO(jblomer): factor out
916 bool polymorphic = fSoAClass->ClassProperty() & kClassHasVirtual;
917 if (!polymorphic) {
918 return nullptr;
919 }
920 return fSoAClass->GetTypeInfo();
921}
922
923//------------------------------------------------------------------------------
924
925ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName)
927{
928}
929
931 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(enump->GetQualifiedName()), ROOT::ENTupleStructure::kPlain,
932 false /* isSimple */)
933{
934 // Avoid accidentally supporting std types through TEnum.
935 if (enump->Property() & kIsDefinedInStd) {
936 throw RException(R__FAIL(GetTypeName() + " is not supported"));
937 }
938
939 switch (enump->GetUnderlyingType()) {
940 case kBool_t: Attach(std::make_unique<RField<Bool_t>>("_0")); break;
941 case kChar_t: Attach(std::make_unique<RField<Char_t>>("_0")); break;
942 case kUChar_t: Attach(std::make_unique<RField<UChar_t>>("_0")); break;
943 case kShort_t: Attach(std::make_unique<RField<Short_t>>("_0")); break;
944 case kUShort_t: Attach(std::make_unique<RField<UShort_t>>("_0")); break;
945 case kInt_t: Attach(std::make_unique<RField<Int_t>>("_0")); break;
946 case kUInt_t: Attach(std::make_unique<RField<UInt_t>>("_0")); break;
947 case kLong_t: Attach(std::make_unique<RField<Long_t>>("_0")); break;
948 case kLong64_t: Attach(std::make_unique<RField<Long64_t>>("_0")); break;
949 case kULong_t: Attach(std::make_unique<RField<ULong_t>>("_0")); break;
950 case kULong64_t: Attach(std::make_unique<RField<ULong64_t>>("_0")); break;
951 default: throw RException(R__FAIL("Unsupported underlying integral type for enum type " + GetTypeName()));
952 }
953
955}
956
957ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName,
958 std::unique_ptr<RFieldBase> intField)
960{
961 Attach(std::move(intField));
963}
964
965std::unique_ptr<ROOT::RFieldBase> ROOT::REnumField::CloneImpl(std::string_view newName) const
966{
967 auto newIntField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
968 return std::unique_ptr<REnumField>(new REnumField(newName, GetTypeName(), std::move(newIntField)));
969}
970
972{
973 // TODO(jblomer): allow enum to enum conversion only by rename rule
974 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffTypeVersion).ThrowOnError();
975}
976
977std::vector<ROOT::RFieldBase::RValue> ROOT::REnumField::SplitValue(const RValue &value) const
978{
979 std::vector<RValue> result;
980 result.emplace_back(fSubfields[0]->BindValue(value.GetPtr<void>()));
981 return result;
982}
983
985{
986 visitor.VisitEnumField(*this);
987}
988
989//------------------------------------------------------------------------------
990
991ROOT::RPairField::RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields)
992 : ROOT::RRecordField(fieldName, "std::pair<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">")
993{
994 const std::string typeAlias = "std::pair<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
995 if (typeAlias != GetTypeName())
997
998 AttachItemFields(std::move(itemFields));
999
1000 // ISO C++ does not guarantee any specific layout for `std::pair`; query TClass for the member offsets
1001 auto *c = TClass::GetClass(GetTypeName().c_str());
1002 if (!c)
1003 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
1004 fSize = c->Size();
1005
1006 auto firstElem = c->GetRealData("first");
1007 if (!firstElem)
1008 throw RException(R__FAIL("first: no such member"));
1009 fOffsets.push_back(firstElem->GetThisOffset());
1010
1011 auto secondElem = c->GetRealData("second");
1012 if (!secondElem)
1013 throw RException(R__FAIL("second: no such member"));
1014 fOffsets.push_back(secondElem->GetThisOffset());
1015}
1016
1017std::unique_ptr<ROOT::RFieldBase> ROOT::RPairField::CloneImpl(std::string_view newName) const
1018{
1019 std::array<std::unique_ptr<RFieldBase>, 2> itemClones = {fSubfields[0]->Clone(fSubfields[0]->GetFieldName()),
1020 fSubfields[1]->Clone(fSubfields[1]->GetFieldName())};
1021 return std::unique_ptr<RPairField>(new RPairField(newName, std::move(itemClones)));
1022}
1023
1025{
1026 static const std::vector<std::string> prefixes = {"std::pair<", "std::tuple<"};
1027
1028 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1029 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1030
1031 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1032 const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
1033 if (nOnDiskSubfields != 2) {
1034 throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::pair " +
1035 std::to_string(nOnDiskSubfields) + "\n" +
1036 Internal::GetTypeTraceReport(*this, desc)));
1037 }
1038}
1039
1040//------------------------------------------------------------------------------
1041
1044 bool readFromDisk)
1045{
1047 ifuncs.fCreateIterators = proxy->GetFunctionCreateIterators(readFromDisk);
1048 ifuncs.fDeleteTwoIterators = proxy->GetFunctionDeleteTwoIterators(readFromDisk);
1049 ifuncs.fNext = proxy->GetFunctionNext(readFromDisk);
1050 R__ASSERT((ifuncs.fCreateIterators != nullptr) && (ifuncs.fDeleteTwoIterators != nullptr) &&
1051 (ifuncs.fNext != nullptr));
1052 return ifuncs;
1053}
1054
1056 : RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kCollection,
1057 false /* isSimple */),
1058 fNWritten(0)
1059{
1060 if (!classp->GetCollectionProxy())
1061 throw RException(R__FAIL(std::string(classp->GetName()) + " has no associated collection proxy"));
1062 if (classp->Property() & kIsDefinedInStd) {
1063 static const std::vector<std::string> supportedStdTypes = {
1064 "std::set<", "std::unordered_set<", "std::multiset<", "std::unordered_multiset<",
1065 "std::map<", "std::unordered_map<", "std::multimap<", "std::unordered_multimap<"};
1066 bool isSupported = false;
1067 for (const auto &tn : supportedStdTypes) {
1068 if (GetTypeName().rfind(tn, 0) == 0) {
1069 isSupported = true;
1070 break;
1071 }
1072 }
1073 if (!isSupported)
1074 throw RException(R__FAIL(std::string(GetTypeName()) + " is not supported"));
1075 }
1076
1077 std::string renormalizedAlias;
1080
1081 fProxy.reset(classp->GetCollectionProxy()->Generate());
1082 fProperties = fProxy->GetProperties();
1083 fCollectionType = fProxy->GetCollectionType();
1084 if (fProxy->HasPointers())
1085 throw RException(R__FAIL("collection proxies whose value type is a pointer are not supported"));
1086
1087 fIFuncsRead = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), true /* readFromDisk */);
1088 fIFuncsWrite = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), false /* readFromDisk */);
1089}
1090
1091ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldName, std::string_view typeName)
1093{
1094 // NOTE (fdegeus): std::map is supported, custom associative might be supported in the future if the need arises.
1096 throw RException(R__FAIL("custom associative collection proxies not supported"));
1097
1098 std::unique_ptr<ROOT::RFieldBase> itemField;
1099
1100 if (auto valueClass = fProxy->GetValueClass()) {
1101 // Element type is a class
1102 itemField = RFieldBase::Create("_0", valueClass->GetName()).Unwrap();
1103 } else {
1104 switch (fProxy->GetType()) {
1105 case EDataType::kChar_t: itemField = std::make_unique<RField<Char_t>>("_0"); break;
1106 case EDataType::kUChar_t: itemField = std::make_unique<RField<UChar_t>>("_0"); break;
1107 case EDataType::kShort_t: itemField = std::make_unique<RField<Short_t>>("_0"); break;
1108 case EDataType::kUShort_t: itemField = std::make_unique<RField<UShort_t>>("_0"); break;
1109 case EDataType::kInt_t: itemField = std::make_unique<RField<Int_t>>("_0"); break;
1110 case EDataType::kUInt_t: itemField = std::make_unique<RField<UInt_t>>("_0"); break;
1111 case EDataType::kLong_t: itemField = std::make_unique<RField<Long_t>>("_0"); break;
1112 case EDataType::kLong64_t: itemField = std::make_unique<RField<Long64_t>>("_0"); break;
1113 case EDataType::kULong_t: itemField = std::make_unique<RField<ULong_t>>("_0"); break;
1114 case EDataType::kULong64_t: itemField = std::make_unique<RField<ULong64_t>>("_0"); break;
1115 case EDataType::kFloat_t: itemField = std::make_unique<RField<Float_t>>("_0"); break;
1116 case EDataType::kDouble_t: itemField = std::make_unique<RField<Double_t>>("_0"); break;
1117 case EDataType::kBool_t: itemField = std::make_unique<RField<Bool_t>>("_0"); break;
1118 default: throw RException(R__FAIL("unsupported value type: " + std::to_string(fProxy->GetType())));
1119 }
1120 }
1121
1122 fItemSize = itemField->GetValueSize();
1123 Attach(std::move(itemField));
1124}
1125
1126std::unique_ptr<ROOT::RFieldBase> ROOT::RProxiedCollectionField::CloneImpl(std::string_view newName) const
1127{
1128 auto clone =
1129 std::unique_ptr<RProxiedCollectionField>(new RProxiedCollectionField(newName, fProxy->GetCollectionClass()));
1130 clone->fItemSize = fItemSize;
1131 clone->Attach(fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1132 return clone;
1133}
1134
1136{
1137 std::size_t nbytes = 0;
1138 unsigned count = 0;
1139 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), const_cast<void *>(from));
1140 for (auto ptr : RCollectionIterableOnce{const_cast<void *>(from), fIFuncsWrite, fProxy.get(),
1141 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
1142 nbytes += CallAppendOn(*fSubfields[0], ptr);
1143 count++;
1144 }
1145
1146 fNWritten += count;
1147 fPrincipalColumn->Append(&fNWritten);
1148 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
1149}
1150
1152{
1155 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
1156
1157 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), to);
1158 void *obj =
1159 fProxy->Allocate(static_cast<std::uint32_t>(nItems), (fProperties & TVirtualCollectionProxy::kNeedDelete));
1160
1161 unsigned i = 0;
1162 for (auto elementPtr : RCollectionIterableOnce{obj, fIFuncsRead, fProxy.get(),
1163 (fCollectionType == kSTLvector || obj != to ? fItemSize : 0U)}) {
1164 CallReadOn(*fSubfields[0], collectionStart + (i++), elementPtr);
1165 }
1166 if (obj != to)
1167 fProxy->Commit(obj);
1168}
1169
1179
1184
1189
1191{
1192 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
1193}
1194
1196{
1197 fProxy->New(where);
1198}
1199
1200std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RProxiedCollectionField::GetDeleter() const
1201{
1202 if (fProperties & TVirtualCollectionProxy::kNeedDelete) {
1203 std::size_t itemSize = fCollectionType == kSTLvector ? fItemSize : 0U;
1204 return std::make_unique<RProxiedCollectionDeleter>(fProxy, GetDeleterOf(*fSubfields[0]), itemSize);
1205 }
1206 return std::make_unique<RProxiedCollectionDeleter>(fProxy);
1207}
1208
1210{
1211 if (fItemDeleter) {
1213 for (auto ptr : RCollectionIterableOnce{objPtr, fIFuncsWrite, fProxy.get(), fItemSize}) {
1214 fItemDeleter->operator()(ptr, true /* dtorOnly */);
1215 }
1216 }
1217 fProxy->Destructor(objPtr, true /* dtorOnly */);
1218 RDeleter::operator()(objPtr, dtorOnly);
1219}
1220
1221std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(const RValue &value) const
1222{
1223 std::vector<RValue> result;
1224 auto valueRawPtr = value.GetPtr<void>().get();
1226 for (auto ptr : RCollectionIterableOnce{valueRawPtr, fIFuncsWrite, fProxy.get(),
1227 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
1228 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), ptr)));
1229 }
1230 return result;
1231}
1232
1234{
1235 return fProxy->Sizeof();
1236}
1237
1239{
1240 const auto align = fProxy->GetCollectionClass()->GetClassAlignment();
1241 EnsureValidAlignment(align);
1242 return align;
1243}
1244
1246{
1247 visitor.VisitProxiedCollectionField(*this);
1248}
1249
1250//------------------------------------------------------------------------------
1251
1252ROOT::RMapField::RMapField(std::string_view fieldName, EMapType mapType, std::unique_ptr<RFieldBase> itemField)
1254 EnsureValidClass(BuildMapTypeName(mapType, itemField.get(), false /* useTypeAliases */))),
1255 fMapType(mapType)
1256{
1257 if (!itemField->GetTypeAlias().empty())
1258 fTypeAlias = BuildMapTypeName(mapType, itemField.get(), true /* useTypeAliases */);
1259
1260 auto *itemClass = fProxy->GetValueClass();
1261 fItemSize = itemClass->GetClassSize();
1262
1263 Attach(std::move(itemField), "_0");
1264}
1265
1266std::unique_ptr<ROOT::RFieldBase> ROOT::RMapField::CloneImpl(std::string_view newName) const
1267{
1268 return std::make_unique<RMapField>(newName, fMapType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1269}
1270
1272{
1273 static const std::vector<std::string> prefixesRegular = {"std::map<", "std::unordered_map<"};
1274
1275 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
1276
1277 switch (fMapType) {
1278 case EMapType::kMap:
1279 case EMapType::kUnorderedMap: EnsureMatchingTypePrefix(desc, prefixesRegular).ThrowOnError(); break;
1280 default:
1281 break;
1282 // no restrictions for multimaps
1283 }
1284}
1285
1286//------------------------------------------------------------------------------
1287
1288ROOT::RSetField::RSetField(std::string_view fieldName, ESetType setType, std::unique_ptr<RFieldBase> itemField)
1290 EnsureValidClass(BuildSetTypeName(setType, *itemField, false /* useTypeAlias */))),
1291 fSetType(setType)
1292{
1293 if (!itemField->GetTypeAlias().empty())
1294 fTypeAlias = BuildSetTypeName(setType, *itemField, true /* useTypeAlias */);
1295
1296 fItemSize = itemField->GetValueSize();
1297
1298 Attach(std::move(itemField), "_0");
1299}
1300
1301std::unique_ptr<ROOT::RFieldBase> ROOT::RSetField::CloneImpl(std::string_view newName) const
1302{
1303 return std::make_unique<RSetField>(newName, fSetType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1304}
1305
1307{
1308 static const std::vector<std::string> prefixesRegular = {"std::set<", "std::unordered_set<", "std::map<",
1309 "std::unordered_map<"};
1310
1311 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
1312
1313 switch (fSetType) {
1314 case ESetType::kSet:
1315 case ESetType::kUnorderedSet: EnsureMatchingTypePrefix(desc, prefixesRegular).ThrowOnError(); break;
1316 default:
1317 break;
1318 // no restrictions for multisets
1319 }
1320}
1321
1322//------------------------------------------------------------------------------
1323
1324namespace {
1325
1326/// Used in RStreamerField::AppendImpl() in order to record the encountered streamer info records
1327class TBufferRecStreamer : public TBufferFile {
1328public:
1329 using RCallbackStreamerInfo = std::function<void(TVirtualStreamerInfo *)>;
1330
1331private:
1332 RCallbackStreamerInfo fCallbackStreamerInfo;
1333
1334public:
1335 TBufferRecStreamer(TBuffer::EMode mode, Int_t bufsize, RCallbackStreamerInfo callbackStreamerInfo)
1336 : TBufferFile(mode, bufsize), fCallbackStreamerInfo(callbackStreamerInfo)
1337 {
1338 }
1339 void TagStreamerInfo(TVirtualStreamerInfo *info) final { fCallbackStreamerInfo(info); }
1340};
1341
1342} // anonymous namespace
1343
1344ROOT::RStreamerField::RStreamerField(std::string_view fieldName, std::string_view className)
1346{
1347}
1348
1350 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kStreamer,
1351 false /* isSimple */),
1352 fClass(classp),
1353 fIndex(0)
1354{
1355 std::string renormalizedAlias;
1358
1360 // For RClassField, we only check for explicit constructors and destructors and then recursively combine traits from
1361 // all member subfields. For RStreamerField, we treat the class as a black box and additionally need to check for
1362 // implicit constructors and destructors.
1367}
1368
1369std::unique_ptr<ROOT::RFieldBase> ROOT::RStreamerField::CloneImpl(std::string_view newName) const
1370{
1371 // To get the correct TClass instance in the clone, we clone using the un-normalized type name
1372 return std::unique_ptr<RStreamerField>(new RStreamerField(newName, fClass->GetName()));
1373}
1374
1375std::size_t ROOT::RStreamerField::AppendImpl(const void *from)
1376{
1377 TBufferRecStreamer buffer(TBuffer::kWrite, GetValueSize(),
1378 [this](TVirtualStreamerInfo *info) { fStreamerInfos[info->GetNumber()] = info; });
1379 fClass->Streamer(const_cast<void *>(from), buffer);
1380
1381 auto nbytes = buffer.Length();
1382 fAuxiliaryColumn->AppendV(buffer.Buffer(), buffer.Length());
1383 fIndex += nbytes;
1384 fPrincipalColumn->Append(&fIndex);
1385 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
1386}
1387
1389{
1392 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nbytes);
1393
1395 fAuxiliaryColumn->ReadV(collectionStart, nbytes, buffer.Buffer());
1396 fClass->Streamer(to, buffer);
1397}
1398
1408
1413
1418
1420{
1421 source.RegisterStreamerInfos();
1422 return nullptr;
1423}
1424
1426{
1427 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffTypeVersion).ThrowOnError();
1428}
1429
1431{
1432 fClass->New(where);
1433}
1434
1436{
1437 fClass->Destructor(objPtr, true /* dtorOnly */);
1438 RDeleter::operator()(objPtr, dtorOnly);
1439}
1440
1442{
1445 .TypeVersion(GetTypeVersion())
1446 .TypeName(GetTypeName())
1448 return extraTypeInfoBuilder.MoveDescriptor().Unwrap();
1449}
1450
1452{
1453 const auto align = fClass->GetClassAlignment();
1454 EnsureValidAlignment(align);
1455 return align;
1456}
1457
1459{
1460 return fClass->GetClassSize();
1461}
1462
1464{
1465 return fClass->GetClassVersion();
1466}
1467
1469{
1470 return fClass->GetCheckSum();
1471}
1472
1474{
1475 visitor.VisitStreamerField(*this);
1476}
1477
1478//------------------------------------------------------------------------------
1479
1481{
1482 if (auto dataMember = TObject::Class()->GetDataMember(name)) {
1483 return dataMember->GetOffset();
1484 }
1485 throw RException(R__FAIL('\'' + std::string(name) + '\'' + " is an invalid data member"));
1486}
1487
1489 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1490{
1492 Attach(source.GetConstSubfields()[0]->Clone("fUniqueID"));
1493 Attach(source.GetConstSubfields()[1]->Clone("fBits"));
1494}
1495
1497 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1498{
1499 assert(TObject::Class()->GetClassVersion() == 1);
1500
1502 Attach(std::make_unique<RField<UInt_t>>("fUniqueID"));
1503 Attach(std::make_unique<RField<UInt_t>>("fBits"));
1504}
1505
1506std::unique_ptr<ROOT::RFieldBase> ROOT::RField<TObject>::CloneImpl(std::string_view newName) const
1507{
1508 return std::unique_ptr<RField<TObject>>(new RField<TObject>(newName, *this));
1509}
1510
1511std::size_t ROOT::RField<TObject>::AppendImpl(const void *from)
1512{
1513 // Cf. TObject::Streamer()
1514
1515 auto *obj = static_cast<const TObject *>(from);
1516 if (obj->TestBit(TObject::kIsReferenced)) {
1517 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1518 }
1519
1520 std::size_t nbytes = 0;
1521 nbytes += CallAppendOn(*fSubfields[0], reinterpret_cast<const unsigned char *>(from) + GetOffsetUniqueID());
1522
1523 UInt_t bits = *reinterpret_cast<const UInt_t *>(reinterpret_cast<const unsigned char *>(from) + GetOffsetBits());
1524 bits &= (~TObject::kIsOnHeap & ~TObject::kNotDeleted);
1525 nbytes += CallAppendOn(*fSubfields[1], &bits);
1526
1527 return nbytes;
1528}
1529
1531{
1532 // Cf. TObject::Streamer()
1533
1534 auto *obj = static_cast<TObject *>(to);
1535 if (obj->TestBit(TObject::kIsReferenced)) {
1536 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1537 }
1538
1539 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetUniqueID()) = uniqueID;
1540
1541 const UInt_t bitIsOnHeap = obj->TestBit(TObject::kIsOnHeap) ? TObject::kIsOnHeap : 0;
1543 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetBits()) = bits;
1544}
1545
1547{
1548 UInt_t uniqueID, bits;
1549 CallReadOn(*fSubfields[0], globalIndex, &uniqueID);
1550 CallReadOn(*fSubfields[1], globalIndex, &bits);
1551 ReadTObject(to, uniqueID, bits);
1552}
1553
1555{
1556 UInt_t uniqueID, bits;
1557 CallReadOn(*fSubfields[0], localIndex, &uniqueID);
1558 CallReadOn(*fSubfields[1], localIndex, &bits);
1559 ReadTObject(to, uniqueID, bits);
1560}
1561
1563{
1564 return TObject::Class()->GetClassVersion();
1565}
1566
1568{
1569 return TObject::Class()->GetCheckSum();
1570}
1571
1573{
1574 new (where) TObject();
1575}
1576
1577std::vector<ROOT::RFieldBase::RValue> ROOT::RField<TObject>::SplitValue(const RValue &value) const
1578{
1579 std::vector<RValue> result;
1580 // Use GetPtr<TObject> to type-check
1581 std::shared_ptr<void> ptr = value.GetPtr<TObject>();
1582 auto charPtr = static_cast<unsigned char *>(ptr.get());
1583 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(ptr, charPtr + GetOffsetUniqueID())));
1584 result.emplace_back(fSubfields[1]->BindValue(std::shared_ptr<void>(ptr, charPtr + GetOffsetBits())));
1585 return result;
1586}
1587
1589{
1590 return sizeof(TObject);
1591}
1592
1594{
1595 return alignof(TObject);
1596}
1597
1599{
1600 visitor.VisitTObjectField(*this);
1601}
1602
1603//------------------------------------------------------------------------------
1604
1605ROOT::RTupleField::RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1606 : ROOT::RRecordField(fieldName, "std::tuple<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">")
1607{
1608 const std::string typeAlias = "std::tuple<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
1609 if (typeAlias != GetTypeName())
1611
1612 AttachItemFields(std::move(itemFields));
1613
1614 auto *c = TClass::GetClass(GetTypeName().c_str());
1615 if (!c)
1616 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
1617 fSize = c->Size();
1618
1619 // ISO C++ does not guarantee neither specific layout nor member names for `std::tuple`. However, most
1620 // implementations including libstdc++ (gcc), libc++ (llvm), and MSVC name members as `_0`, `_1`, ..., `_N-1`,
1621 // following the order of the type list.
1622 // Use TClass to get their offsets; in case a particular `std::tuple` implementation does not define such
1623 // members, the assertion below will fail.
1624 for (unsigned i = 0; i < fSubfields.size(); ++i) {
1625 std::string memberName("_" + std::to_string(i));
1626 auto member = c->GetRealData(memberName.c_str());
1627 if (!member)
1628 throw RException(R__FAIL(memberName + ": no such member"));
1629 fOffsets.push_back(member->GetThisOffset());
1630 }
1631}
1632
1633std::unique_ptr<ROOT::RFieldBase> ROOT::RTupleField::CloneImpl(std::string_view newName) const
1634{
1635 std::vector<std::unique_ptr<RFieldBase>> itemClones;
1636 itemClones.reserve(fSubfields.size());
1637 for (const auto &f : fSubfields) {
1638 itemClones.emplace_back(f->Clone(f->GetFieldName()));
1639 }
1640 return std::unique_ptr<RTupleField>(new RTupleField(newName, std::move(itemClones)));
1641}
1642
1644{
1645 static const std::vector<std::string> prefixes = {"std::pair<", "std::tuple<"};
1646
1647 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1648 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1649
1650 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1651 const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
1652 const auto nSubfields = fSubfields.size();
1654 throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::tuple " +
1655 std::to_string(nOnDiskSubfields) + " vs. " + std::to_string(nSubfields) + "\n" +
1656 Internal::GetTypeTraceReport(*this, desc)));
1657 }
1658}
1659
1660//------------------------------------------------------------------------------
1661
1662namespace {
1663
1664// Depending on the compiler, the variant tag is stored either in a trailing char or in a trailing unsigned int
1665constexpr std::size_t GetVariantTagSize()
1666{
1667 // Should be all zeros except for the tag, which is 1
1668 std::variant<char> t;
1669 constexpr auto sizeOfT = sizeof(t);
1670
1671 static_assert(sizeOfT == 2 || sizeOfT == 8, "unsupported std::variant layout");
1672 return sizeOfT == 2 ? 1 : 4;
1673}
1674
1675template <std::size_t VariantSizeT>
1676struct RVariantTag {
1677 using ValueType_t = typename std::conditional_t<VariantSizeT == 1, std::uint8_t,
1678 typename std::conditional_t<VariantSizeT == 4, std::uint32_t, void>>;
1679};
1680
1681} // anonymous namespace
1682
1684 : ROOT::RFieldBase(name, source.GetTypeName(), ROOT::ENTupleStructure::kVariant, false /* isSimple */),
1685 fMaxItemSize(source.fMaxItemSize),
1686 fMaxAlignment(source.fMaxAlignment),
1687 fTagOffset(source.fTagOffset),
1688 fVariantOffset(source.fVariantOffset),
1689 fNWritten(source.fNWritten.size(), 0)
1690{
1691 for (const auto &f : source.GetConstSubfields())
1692 Attach(f->Clone(f->GetFieldName()));
1693 fTraits = source.fTraits;
1694}
1695
1696ROOT::RVariantField::RVariantField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1697 : ROOT::RFieldBase(fieldName, "std::variant<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">",
1698 ROOT::ENTupleStructure::kVariant, false /* isSimple */)
1699{
1700 // The variant needs to initialize its own tag member
1702
1703 const std::string typeAlias = "std::variant<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
1704 if (typeAlias != GetTypeName())
1706
1707 auto nFields = itemFields.size();
1708 if (nFields == 0 || nFields > kMaxVariants) {
1709 throw RException(R__FAIL("invalid number of variant fields (outside [1.." + std::to_string(kMaxVariants) + ")"));
1710 }
1711 fNWritten.resize(nFields, 0);
1712 for (unsigned int i = 0; i < nFields; ++i) {
1715 fTraits &= itemFields[i]->GetTraits();
1716 Attach(std::move(itemFields[i]), "_" + std::to_string(i));
1717 }
1718
1719 // With certain template parameters, the union of members of an std::variant starts at an offset > 0.
1720 // For instance, std::variant<std::optional<int>> on macOS.
1721 auto cl = TClass::GetClass(GetTypeName().c_str());
1722 assert(cl);
1723 auto dm = reinterpret_cast<TDataMember *>(cl->GetListOfDataMembers()->First());
1724 if (dm)
1725 fVariantOffset = dm->GetOffset();
1726
1727 const auto tagSize = GetVariantTagSize();
1728 const auto padding = tagSize - (fMaxItemSize % tagSize);
1730}
1731
1732std::unique_ptr<ROOT::RFieldBase> ROOT::RVariantField::CloneImpl(std::string_view newName) const
1733{
1734 return std::unique_ptr<RVariantField>(new RVariantField(newName, *this));
1735}
1736
1737std::uint8_t ROOT::RVariantField::GetTag(const void *variantPtr, std::size_t tagOffset)
1738{
1739 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1740 auto tag = *reinterpret_cast<const TagType_t *>(reinterpret_cast<const unsigned char *>(variantPtr) + tagOffset);
1741 return (tag == TagType_t(-1)) ? 0 : tag + 1;
1742}
1743
1744void ROOT::RVariantField::SetTag(void *variantPtr, std::size_t tagOffset, std::uint8_t tag)
1745{
1746 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1747 auto tagPtr = reinterpret_cast<TagType_t *>(reinterpret_cast<unsigned char *>(variantPtr) + tagOffset);
1748 *tagPtr = (tag == 0) ? TagType_t(-1) : static_cast<TagType_t>(tag - 1);
1749}
1750
1751std::size_t ROOT::RVariantField::AppendImpl(const void *from)
1752{
1753 auto tag = GetTag(from, fTagOffset);
1754 std::size_t nbytes = 0;
1755 auto index = 0;
1756 if (tag > 0) {
1757 nbytes += CallAppendOn(*fSubfields[tag - 1], reinterpret_cast<const unsigned char *>(from) + fVariantOffset);
1758 index = fNWritten[tag - 1]++;
1759 }
1761 fPrincipalColumn->Append(&varSwitch);
1762 return nbytes + sizeof(ROOT::Internal::RColumnSwitch);
1763}
1764
1766{
1768 std::uint32_t tag;
1769 fPrincipalColumn->GetSwitchInfo(globalIndex, &variantIndex, &tag);
1770 R__ASSERT(tag < 256);
1771
1772 // If `tag` equals 0, the variant is in the invalid state, i.e, it does not hold any of the valid alternatives in
1773 // the type list. This happens, e.g., if the field was late added; in this case, keep the invalid tag, which makes
1774 // any `std::holds_alternative<T>` check fail later.
1775 if (R__likely(tag > 0)) {
1776 void *varPtr = reinterpret_cast<unsigned char *>(to) + fVariantOffset;
1777 CallConstructValueOn(*fSubfields[tag - 1], varPtr);
1778 CallReadOn(*fSubfields[tag - 1], variantIndex, varPtr);
1779 }
1780 SetTag(to, fTagOffset, tag);
1781}
1782
1788
1793
1798
1800{
1801 static const std::vector<std::string> prefixes = {"std::variant<"};
1802
1803 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1804 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1805
1806 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1807 if (fSubfields.size() != fieldDesc.GetLinkIds().size()) {
1808 throw RException(R__FAIL("number of variants on-disk do not match for " + GetQualifiedFieldName() + "\n" +
1809 Internal::GetTypeTraceReport(*this, desc)));
1810 }
1811}
1812
1814{
1815 memset(where, 0, GetValueSize());
1816 CallConstructValueOn(*fSubfields[0], reinterpret_cast<unsigned char *>(where) + fVariantOffset);
1817 SetTag(where, fTagOffset, 1);
1818}
1819
1821{
1822 auto tag = GetTag(objPtr, fTagOffset);
1823 if (tag > 0) {
1824 fItemDeleters[tag - 1]->operator()(reinterpret_cast<unsigned char *>(objPtr) + fVariantOffset, true /*dtorOnly*/);
1825 }
1826 RDeleter::operator()(objPtr, dtorOnly);
1827}
1828
1829std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RVariantField::GetDeleter() const
1830{
1831 std::vector<std::unique_ptr<RDeleter>> itemDeleters;
1832 itemDeleters.reserve(fSubfields.size());
1833 for (const auto &f : fSubfields) {
1834 itemDeleters.emplace_back(GetDeleterOf(*f));
1835 }
1836 return std::make_unique<RVariantDeleter>(fTagOffset, fVariantOffset, std::move(itemDeleters));
1837}
1838
1840{
1841 return std::max(fMaxAlignment, alignof(RVariantTag<GetVariantTagSize()>::ValueType_t));
1842}
1843
1845{
1846 const auto alignment = GetAlignment();
1847 const auto actualSize = fTagOffset + GetVariantTagSize();
1848 const auto padding = alignment - (actualSize % alignment);
1849 return actualSize + ((padding == alignment) ? 0 : padding);
1850}
1851
1853{
1854 std::fill(fNWritten.begin(), fNWritten.end(), 0);
1855}
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:145
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 in the order of subfields of the underlying record typ...
Definition RFieldSoA.hxx:69
const std::type_info * GetPolymorphicTypeInfo() const
For polymorphic classes (that declare or inherit at least one virtual method), return the expected dy...
size_t GetValueSize() const final
What sizeof(T) for this type returns.
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
size_t GetAlignment() const final
What alignof(T) for this type returns.
std::vector< RFieldBase * > fRecordMemberFields
Direct access to the member fields of the underlying record.
Definition RFieldSoA.hxx:66
RSoAField(std::string_view fieldName, const RSoAField &source)
Used by CloneImpl.
std::uint32_t GetTypeVersion() const final
Indicates an evolution of the C++ type itself.
std::uint32_t GetTypeChecksum() const final
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
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 ...
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.
std::size_t GetAlignment() const final
What alignof(T) for this type returns.
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)
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
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.
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:292
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:322
RField(std::string_view name)
Definition RField.hxx:325
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.
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
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::size_t GetAlignment() const final
What alignof(T) for this type returns.
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:237
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
What alignof(T) for this type returns.
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
size_t GetValueSize() const final
What sizeof(T) for this type returns.
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.
std::size_t GetAlignment() const final
What alignof(T) for this type returns.
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.
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
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
Version_t GetClassVersion() const
Definition TClass.h:434
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.
constexpr bool IsValidAlignment(std::size_t align) noexcept
Return true if align is a valid C++ alignment value: strictly positive and a power of two.
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.