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 SetStagingClass(fieldDesc.GetTypeName(), fieldDesc.GetTypeVersion());
557 PrepareStagingArea(rules, desc, fieldDesc);
558 for (auto &[_, si] : fStagingItems) {
560 si.fField = std::move(static_cast<RFieldZero *>(si.fField.get())->ReleaseSubfields()[0]);
561 }
562 }
563
564 // Remove target member of read rules from the list of regular members of the underlying on-disk field
565 for (const auto rule : rules) {
566 if (!rule->GetTarget())
567 continue;
568
569 for (const auto target : ROOT::Detail::TRangeStaticCast<const TObjString>(*rule->GetTarget())) {
570 regularSubfields.erase(std::string(target->GetString()));
571 }
572 }
573 }
574
575 for (const auto rule : rules) {
576 AddReadCallbacksFromIORule(rule);
577 }
578
579 // Iterate over all sub fields in memory and mark those as missing that are not in the descriptor.
580 int nInMemoryBaseClasses = 0;
581 for (auto &field : fSubfields) {
582 const auto &fieldName = field->GetFieldName();
583 if (regularSubfields.count(fieldName) == 0) {
584 CallSetArtificialOn(*field);
585 }
586 if (!fieldName.empty() && fieldName[0] == ':')
588 }
589
591 throw RException(R__FAIL(std::string("incompatible number of base classes for field ") + GetFieldName() + ": " +
592 GetTypeName() + ", " + std::to_string(nInMemoryBaseClasses) +
593 " base classes in memory "
594 " vs. " +
595 std::to_string(nOnDiskBaseClasses) + " base classes on-disk\n" +
596 Internal::GetTypeTraceReport(*this, pageSource.GetSharedDescriptorGuard().GetRef())));
597 }
598
599 return nullptr;
600}
601
603{
604 EnsureMatchingOnDiskField(desc, kDiffTypeVersion | kDiffTypeName).ThrowOnError();
605}
606
608{
609 fClass->New(where);
610}
611
613{
614 fClass->Destructor(objPtr, true /* dtorOnly */);
615 RDeleter::operator()(objPtr, dtorOnly);
616}
617
618std::vector<ROOT::RFieldBase::RValue> ROOT::RClassField::SplitValue(const RValue &value) const
619{
620 std::vector<RValue> result;
621 auto valuePtr = value.GetPtr<void>();
622 auto charPtr = static_cast<unsigned char *>(valuePtr.get());
623 result.reserve(fSubfields.size());
624 for (unsigned i = 0; i < fSubfields.size(); i++) {
625 result.emplace_back(
626 fSubfields[i]->BindValue(std::shared_ptr<void>(valuePtr, charPtr + fSubfieldsInfo[i].fOffset)));
627 }
628 return result;
629}
630
632{
633 return fClass->GetClassSize();
634}
635
637{
638 const auto align = fClass->GetClassAlignment();
640 return align;
641}
642
644{
645 return fClass->GetClassVersion();
646}
647
649{
650 return fClass->GetCheckSum();
651}
652
653const std::type_info *ROOT::RClassField::GetPolymorphicTypeInfo() const
654{
655 bool polymorphic = fClass->ClassProperty() & kClassHasVirtual;
656 if (!polymorphic) {
657 return nullptr;
658 }
659 return fClass->GetTypeInfo();
660}
661
663{
664 visitor.VisitClassField(*this);
665}
666
667//------------------------------------------------------------------------------
668
670 : ROOT::RFieldBase(fieldName, source.GetTypeName(), ROOT::ENTupleStructure::kCollection, false /* isSimple */),
671 fSoAClass(source.fSoAClass),
672 fSoAMemberOffsets(source.fSoAMemberOffsets)
673{
674 fTraits = source.GetTraits();
675 Attach(source.fSubfields[0]->Clone(source.fSubfields[0]->GetFieldName()));
676 fRecordMemberFields = fSubfields[0]->GetMutableSubfields();
677}
678
679ROOT::Experimental::RSoAField::RSoAField(std::string_view fieldName, std::string_view className)
681{
682}
683
685 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(clSoA->GetName()), ROOT::ENTupleStructure::kCollection,
686 false /* isSimple */),
687 fSoAClass(clSoA)
688{
689 static std::once_flag once;
690 std::call_once(once, []() {
691 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "The SoA field is experimental and still under development.";
692 });
693
694 EnsureValidUserClass(fSoAClass, *this, "RSoAField");
696 if (recordTypeName.empty()) {
697 throw ROOT::RException(R__FAIL(std::string("class ") + GetTypeName() +
698 " is not marked with the rntupleSoARecord "
699 "dictionary option; cannot create corresponding RSoAField."));
700 }
701 try {
702 Attach(std::make_unique<ROOT::RClassField>("_0", recordTypeName));
703 } catch (ROOT::RException &e) {
704 throw RException(R__FAIL("invalid record type of SoA field " + GetTypeName() + " [" + e.what() + "]"));
705 }
707 if (static_cast<std::uint32_t>(fSoAClass->GetClassVersion()) != fSubfields[0]->GetTypeVersion()) {
708 throw RException(R__FAIL(std::string("version mismatch between SoA type and underlying record type: ") +
709 std::to_string(fSoAClass->GetClassVersion()) + " vs. " +
710 std::to_string(fSubfields[0]->GetTypeVersion())));
711 }
712 fRecordMemberFields = fSubfields[0]->GetMutableSubfields();
713
714 std::unordered_map<std::string, std::size_t> recordFieldNameToIdx;
715 for (std::size_t i = 0; i < fRecordMemberFields.size(); ++i) {
716 const RFieldBase *f = fRecordMemberFields[i];
717 assert(!f->GetFieldName().empty());
718 if (f->GetFieldName()[0] == ':') {
719 throw RException(R__FAIL("SoA fields with inheritance are currently unsupported"));
720 }
721 recordFieldNameToIdx[f->GetFieldName()] = i;
722 }
723
724 const auto *bases = fSoAClass->GetListOfBases();
725 assert(bases);
727 if (baseClass->GetDelta() < 0) {
728 throw RException(R__FAIL(std::string("virtual inheritance is not supported: ") + GetTypeName() +
729 " virtually inherits from " + baseClass->GetName()));
730 }
731 // At a later point, we will support inheritance
732 throw RException(R__FAIL("SoA fields with inheritance are currently unsupported"));
733 }
734
736 unsigned int nMembers = 0;
738 if ((dataMember->Property() & kIsStatic) || !dataMember->IsPersistent())
739 continue;
740
741 if (dataMember->Property() & kIsArray) {
742 throw RException(R__FAIL(std::string("unsupported array type in SoA class: ") + dataMember->GetName()));
743 }
744
745 const std::string typeName{dataMember->GetTrueTypeName()};
746 auto subField = RFieldBase::Create(dataMember->GetName(), typeName).Unwrap();
747 auto vecFieldPtr = dynamic_cast<RRVecField *>(subField.get());
748 if (!vecFieldPtr) {
749 throw RException(R__FAIL("invalid field type in SoA class: " + subField->GetTypeName()));
750 }
751 subField.release();
752 auto vecField = std::unique_ptr<RRVecField>(vecFieldPtr);
753
754 auto itr = recordFieldNameToIdx.find(vecField->GetFieldName());
755 if (itr == recordFieldNameToIdx.end()) {
756 throw RException(R__FAIL(std::string("unexpected SoA member: ") + vecField->GetFieldName()));
757 }
759 if (vecField->begin()->GetTypeName() != memberField->GetTypeName() ||
760 vecField->begin()->GetTypeAlias() != memberField->GetTypeAlias()) {
761 const std::string leftType =
762 vecField->begin()->GetTypeName() +
763 (vecField->begin()->GetTypeAlias().empty() ? "" : " [" + vecField->begin()->GetTypeAlias() + "]");
764 const std::string rightType =
765 memberField->GetTypeName() +
766 (memberField->GetTypeAlias().empty() ? "" : " [" + memberField->GetTypeAlias() + "]");
767 throw RException(R__FAIL(std::string("SoA member type mismatch: ") + vecField->GetFieldName() + " (" +
768 leftType + " vs. " + rightType + ")"));
769 }
770
771 assert(itr->second < fSoAMemberOffsets.size());
772 fSoAMemberOffsets[itr->second] = dataMember->GetOffset();
773 nMembers++;
774 }
775 if (recordFieldNameToIdx.size() != nMembers) {
776 throw RException(R__FAIL("missing SoA members"));
777 }
778
779 std::string renormalizedAlias;
782
784}
785
786std::unique_ptr<ROOT::RFieldBase> ROOT::Experimental::RSoAField::CloneImpl(std::string_view newName) const
787{
788 return std::unique_ptr<RSoAField>(new RSoAField(newName, *this));
789}
790
800
805
810
811std::size_t ROOT::Experimental::RSoAField::AppendImpl(const void *from)
812{
813 const std::size_t nSoAMembers = fSoAMemberOffsets.size();
814
815 std::size_t N = 0; // Set by first SoA member and verified for the rest
816 for (std::size_t i = 0; i < nSoAMembers; ++i) {
817 const void *rvecPtr = static_cast<const unsigned char *>(from) + fSoAMemberOffsets[i];
819 assert(*sizePtr >= 0);
820 if (i == 0) {
821 N = *sizePtr;
822 } else {
823 if (static_cast<std::size_t>(*sizePtr) != N) {
824 const auto f = fRecordMemberFields[i];
825 throw RException(R__FAIL("SoA length mismatch for " + f->GetFieldName() + ": " + std::to_string(*sizePtr) +
826 " vs. " + std::to_string(N) + " (expected)"));
827 }
828 }
829 }
830
831 std::size_t nbytes = 0;
832 if (N > 0) {
833 for (std::size_t i = 0; i < nSoAMembers; ++i) {
834 const void *rvecPtr = static_cast<const unsigned char *>(from) + fSoAMemberOffsets[i];
836 RFieldBase *memberField = fRecordMemberFields[i];
837 if (memberField->IsSimple()) {
838 GetPrincipalColumnOf(*memberField)->AppendV(*beginPtr, N);
839 nbytes += N * GetPrincipalColumnOf(*memberField)->GetElement()->GetPackedSize();
840 } else {
841 for (std::size_t j = 0; j < N; ++j) {
842 nbytes += CallAppendOn(*memberField, *beginPtr + j * memberField->GetValueSize());
843 }
844 }
845 }
846 }
847
848 fNWritten += N;
849 fPrincipalColumn->Append(&fNWritten);
850 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
851}
852
854{
855 throw RException(R__FAIL("not yet implemented"));
856}
857
859{
860 fSoAClass->New(where);
861}
862
864{
865 fSoAClass->Destructor(objPtr, true /* dtorOnly */);
866 RDeleter::operator()(objPtr, dtorOnly);
867}
868
869std::vector<ROOT::RFieldBase::RValue> ROOT::Experimental::RSoAField::SplitValue(const RValue & /* value */) const
870{
871 throw RException(R__FAIL("not yet implemented"));
872 return std::vector<RValue>();
873}
874
876{
877 return fSoAClass->GetClassSize();
878}
879
881{
882 return fSoAClass->GetClassVersion();
883}
884
886{
887 return fSoAClass->GetCheckSum();
888}
889
891{
892 const auto align = fSoAClass->GetClassAlignment();
894 return align;
895}
896
898{
899 // TODO(jblomer): factor out
900 bool polymorphic = fSoAClass->ClassProperty() & kClassHasVirtual;
901 if (!polymorphic) {
902 return nullptr;
903 }
904 return fSoAClass->GetTypeInfo();
905}
906
907//------------------------------------------------------------------------------
908
909ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName)
911{
912}
913
915 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(enump->GetQualifiedName()), ROOT::ENTupleStructure::kPlain,
916 false /* isSimple */)
917{
918 // Avoid accidentally supporting std types through TEnum.
919 if (enump->Property() & kIsDefinedInStd) {
920 throw RException(R__FAIL(GetTypeName() + " is not supported"));
921 }
922
923 switch (enump->GetUnderlyingType()) {
924 case kBool_t: Attach(std::make_unique<RField<Bool_t>>("_0")); break;
925 case kChar_t: Attach(std::make_unique<RField<Char_t>>("_0")); break;
926 case kUChar_t: Attach(std::make_unique<RField<UChar_t>>("_0")); break;
927 case kShort_t: Attach(std::make_unique<RField<Short_t>>("_0")); break;
928 case kUShort_t: Attach(std::make_unique<RField<UShort_t>>("_0")); break;
929 case kInt_t: Attach(std::make_unique<RField<Int_t>>("_0")); break;
930 case kUInt_t: Attach(std::make_unique<RField<UInt_t>>("_0")); break;
931 case kLong_t: Attach(std::make_unique<RField<Long_t>>("_0")); break;
932 case kLong64_t: Attach(std::make_unique<RField<Long64_t>>("_0")); break;
933 case kULong_t: Attach(std::make_unique<RField<ULong_t>>("_0")); break;
934 case kULong64_t: Attach(std::make_unique<RField<ULong64_t>>("_0")); break;
935 default: throw RException(R__FAIL("Unsupported underlying integral type for enum type " + GetTypeName()));
936 }
937
939}
940
941ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName,
942 std::unique_ptr<RFieldBase> intField)
944{
945 Attach(std::move(intField));
947}
948
949std::unique_ptr<ROOT::RFieldBase> ROOT::REnumField::CloneImpl(std::string_view newName) const
950{
951 auto newIntField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
952 return std::unique_ptr<REnumField>(new REnumField(newName, GetTypeName(), std::move(newIntField)));
953}
954
956{
957 // TODO(jblomer): allow enum to enum conversion only by rename rule
958 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffTypeVersion).ThrowOnError();
959}
960
961std::vector<ROOT::RFieldBase::RValue> ROOT::REnumField::SplitValue(const RValue &value) const
962{
963 std::vector<RValue> result;
964 result.emplace_back(fSubfields[0]->BindValue(value.GetPtr<void>()));
965 return result;
966}
967
969{
970 visitor.VisitEnumField(*this);
971}
972
973//------------------------------------------------------------------------------
974
975ROOT::RPairField::RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields)
976 : ROOT::RRecordField(fieldName, "std::pair<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">")
977{
978 const std::string typeAlias = "std::pair<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
979 if (typeAlias != GetTypeName())
981
982 AttachItemFields(std::move(itemFields));
983
984 // ISO C++ does not guarantee any specific layout for `std::pair`; query TClass for the member offsets
985 auto *c = TClass::GetClass(GetTypeName().c_str());
986 if (!c)
987 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
988 fSize = c->Size();
989
990 auto firstElem = c->GetRealData("first");
991 if (!firstElem)
992 throw RException(R__FAIL("first: no such member"));
993 fOffsets.push_back(firstElem->GetThisOffset());
994
995 auto secondElem = c->GetRealData("second");
996 if (!secondElem)
997 throw RException(R__FAIL("second: no such member"));
998 fOffsets.push_back(secondElem->GetThisOffset());
999}
1000
1001std::unique_ptr<ROOT::RFieldBase> ROOT::RPairField::CloneImpl(std::string_view newName) const
1002{
1003 std::array<std::unique_ptr<RFieldBase>, 2> itemClones = {fSubfields[0]->Clone(fSubfields[0]->GetFieldName()),
1004 fSubfields[1]->Clone(fSubfields[1]->GetFieldName())};
1005 return std::unique_ptr<RPairField>(new RPairField(newName, std::move(itemClones)));
1006}
1007
1009{
1010 static const std::vector<std::string> prefixes = {"std::pair<", "std::tuple<"};
1011
1012 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1013 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1014
1015 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1016 const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
1017 if (nOnDiskSubfields != 2) {
1018 throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::pair " +
1019 std::to_string(nOnDiskSubfields) + "\n" +
1020 Internal::GetTypeTraceReport(*this, desc)));
1021 }
1022}
1023
1024//------------------------------------------------------------------------------
1025
1028 bool readFromDisk)
1029{
1031 ifuncs.fCreateIterators = proxy->GetFunctionCreateIterators(readFromDisk);
1032 ifuncs.fDeleteTwoIterators = proxy->GetFunctionDeleteTwoIterators(readFromDisk);
1033 ifuncs.fNext = proxy->GetFunctionNext(readFromDisk);
1034 R__ASSERT((ifuncs.fCreateIterators != nullptr) && (ifuncs.fDeleteTwoIterators != nullptr) &&
1035 (ifuncs.fNext != nullptr));
1036 return ifuncs;
1037}
1038
1040 : RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kCollection,
1041 false /* isSimple */),
1042 fNWritten(0)
1043{
1044 if (!classp->GetCollectionProxy())
1045 throw RException(R__FAIL(std::string(classp->GetName()) + " has no associated collection proxy"));
1046 if (classp->Property() & kIsDefinedInStd) {
1047 static const std::vector<std::string> supportedStdTypes = {
1048 "std::set<", "std::unordered_set<", "std::multiset<", "std::unordered_multiset<",
1049 "std::map<", "std::unordered_map<", "std::multimap<", "std::unordered_multimap<"};
1050 bool isSupported = false;
1051 for (const auto &tn : supportedStdTypes) {
1052 if (GetTypeName().rfind(tn, 0) == 0) {
1053 isSupported = true;
1054 break;
1055 }
1056 }
1057 if (!isSupported)
1058 throw RException(R__FAIL(std::string(GetTypeName()) + " is not supported"));
1059 }
1060
1061 std::string renormalizedAlias;
1064
1065 fProxy.reset(classp->GetCollectionProxy()->Generate());
1066 fProperties = fProxy->GetProperties();
1067 fCollectionType = fProxy->GetCollectionType();
1068 if (fProxy->HasPointers())
1069 throw RException(R__FAIL("collection proxies whose value type is a pointer are not supported"));
1070
1071 fIFuncsRead = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), true /* readFromDisk */);
1072 fIFuncsWrite = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), false /* readFromDisk */);
1073}
1074
1075ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldName, std::string_view typeName)
1077{
1078 // NOTE (fdegeus): std::map is supported, custom associative might be supported in the future if the need arises.
1080 throw RException(R__FAIL("custom associative collection proxies not supported"));
1081
1082 std::unique_ptr<ROOT::RFieldBase> itemField;
1083
1084 if (auto valueClass = fProxy->GetValueClass()) {
1085 // Element type is a class
1086 itemField = RFieldBase::Create("_0", valueClass->GetName()).Unwrap();
1087 } else {
1088 switch (fProxy->GetType()) {
1089 case EDataType::kChar_t: itemField = std::make_unique<RField<Char_t>>("_0"); break;
1090 case EDataType::kUChar_t: itemField = std::make_unique<RField<UChar_t>>("_0"); break;
1091 case EDataType::kShort_t: itemField = std::make_unique<RField<Short_t>>("_0"); break;
1092 case EDataType::kUShort_t: itemField = std::make_unique<RField<UShort_t>>("_0"); break;
1093 case EDataType::kInt_t: itemField = std::make_unique<RField<Int_t>>("_0"); break;
1094 case EDataType::kUInt_t: itemField = std::make_unique<RField<UInt_t>>("_0"); break;
1095 case EDataType::kLong_t: itemField = std::make_unique<RField<Long_t>>("_0"); break;
1096 case EDataType::kLong64_t: itemField = std::make_unique<RField<Long64_t>>("_0"); break;
1097 case EDataType::kULong_t: itemField = std::make_unique<RField<ULong_t>>("_0"); break;
1098 case EDataType::kULong64_t: itemField = std::make_unique<RField<ULong64_t>>("_0"); break;
1099 case EDataType::kFloat_t: itemField = std::make_unique<RField<Float_t>>("_0"); break;
1100 case EDataType::kDouble_t: itemField = std::make_unique<RField<Double_t>>("_0"); break;
1101 case EDataType::kBool_t: itemField = std::make_unique<RField<Bool_t>>("_0"); break;
1102 default: throw RException(R__FAIL("unsupported value type: " + std::to_string(fProxy->GetType())));
1103 }
1104 }
1105
1106 fItemSize = itemField->GetValueSize();
1107 Attach(std::move(itemField));
1108}
1109
1110std::unique_ptr<ROOT::RFieldBase> ROOT::RProxiedCollectionField::CloneImpl(std::string_view newName) const
1111{
1112 auto clone =
1113 std::unique_ptr<RProxiedCollectionField>(new RProxiedCollectionField(newName, fProxy->GetCollectionClass()));
1114 clone->fItemSize = fItemSize;
1115 clone->Attach(fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1116 return clone;
1117}
1118
1120{
1121 std::size_t nbytes = 0;
1122 unsigned count = 0;
1123 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), const_cast<void *>(from));
1124 for (auto ptr : RCollectionIterableOnce{const_cast<void *>(from), fIFuncsWrite, fProxy.get(),
1125 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
1126 nbytes += CallAppendOn(*fSubfields[0], ptr);
1127 count++;
1128 }
1129
1130 fNWritten += count;
1131 fPrincipalColumn->Append(&fNWritten);
1132 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
1133}
1134
1136{
1139 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
1140
1141 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), to);
1142 void *obj =
1143 fProxy->Allocate(static_cast<std::uint32_t>(nItems), (fProperties & TVirtualCollectionProxy::kNeedDelete));
1144
1145 unsigned i = 0;
1146 for (auto elementPtr : RCollectionIterableOnce{obj, fIFuncsRead, fProxy.get(),
1147 (fCollectionType == kSTLvector || obj != to ? fItemSize : 0U)}) {
1148 CallReadOn(*fSubfields[0], collectionStart + (i++), elementPtr);
1149 }
1150 if (obj != to)
1151 fProxy->Commit(obj);
1152}
1153
1163
1168
1173
1175{
1176 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
1177}
1178
1180{
1181 fProxy->New(where);
1182}
1183
1184std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RProxiedCollectionField::GetDeleter() const
1185{
1186 if (fProperties & TVirtualCollectionProxy::kNeedDelete) {
1187 std::size_t itemSize = fCollectionType == kSTLvector ? fItemSize : 0U;
1188 return std::make_unique<RProxiedCollectionDeleter>(fProxy, GetDeleterOf(*fSubfields[0]), itemSize);
1189 }
1190 return std::make_unique<RProxiedCollectionDeleter>(fProxy);
1191}
1192
1194{
1195 if (fItemDeleter) {
1197 for (auto ptr : RCollectionIterableOnce{objPtr, fIFuncsWrite, fProxy.get(), fItemSize}) {
1198 fItemDeleter->operator()(ptr, true /* dtorOnly */);
1199 }
1200 }
1201 fProxy->Destructor(objPtr, true /* dtorOnly */);
1202 RDeleter::operator()(objPtr, dtorOnly);
1203}
1204
1205std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(const RValue &value) const
1206{
1207 std::vector<RValue> result;
1208 auto valueRawPtr = value.GetPtr<void>().get();
1210 for (auto ptr : RCollectionIterableOnce{valueRawPtr, fIFuncsWrite, fProxy.get(),
1211 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
1212 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), ptr)));
1213 }
1214 return result;
1215}
1216
1218{
1219 return fProxy->Sizeof();
1220}
1221
1223{
1224 const auto align = fProxy->GetCollectionClass()->GetClassAlignment();
1225 EnsureValidAlignment(align);
1226 return align;
1227}
1228
1230{
1231 visitor.VisitProxiedCollectionField(*this);
1232}
1233
1234//------------------------------------------------------------------------------
1235
1236ROOT::RMapField::RMapField(std::string_view fieldName, EMapType mapType, std::unique_ptr<RFieldBase> itemField)
1238 EnsureValidClass(BuildMapTypeName(mapType, itemField.get(), false /* useTypeAliases */))),
1239 fMapType(mapType)
1240{
1241 if (!itemField->GetTypeAlias().empty())
1242 fTypeAlias = BuildMapTypeName(mapType, itemField.get(), true /* useTypeAliases */);
1243
1244 auto *itemClass = fProxy->GetValueClass();
1245 fItemSize = itemClass->GetClassSize();
1246
1247 Attach(std::move(itemField), "_0");
1248}
1249
1250std::unique_ptr<ROOT::RFieldBase> ROOT::RMapField::CloneImpl(std::string_view newName) const
1251{
1252 return std::make_unique<RMapField>(newName, fMapType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1253}
1254
1256{
1257 static const std::vector<std::string> prefixesRegular = {"std::map<", "std::unordered_map<"};
1258
1259 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
1260
1261 switch (fMapType) {
1262 case EMapType::kMap:
1263 case EMapType::kUnorderedMap: EnsureMatchingTypePrefix(desc, prefixesRegular).ThrowOnError(); break;
1264 default:
1265 break;
1266 // no restrictions for multimaps
1267 }
1268}
1269
1270//------------------------------------------------------------------------------
1271
1272ROOT::RSetField::RSetField(std::string_view fieldName, ESetType setType, std::unique_ptr<RFieldBase> itemField)
1274 EnsureValidClass(BuildSetTypeName(setType, *itemField, false /* useTypeAlias */))),
1275 fSetType(setType)
1276{
1277 if (!itemField->GetTypeAlias().empty())
1278 fTypeAlias = BuildSetTypeName(setType, *itemField, true /* useTypeAlias */);
1279
1280 fItemSize = itemField->GetValueSize();
1281
1282 Attach(std::move(itemField), "_0");
1283}
1284
1285std::unique_ptr<ROOT::RFieldBase> ROOT::RSetField::CloneImpl(std::string_view newName) const
1286{
1287 return std::make_unique<RSetField>(newName, fSetType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
1288}
1289
1291{
1292 static const std::vector<std::string> prefixesRegular = {"std::set<", "std::unordered_set<", "std::map<",
1293 "std::unordered_map<"};
1294
1295 EnsureMatchingOnDiskCollection(desc).ThrowOnError();
1296
1297 switch (fSetType) {
1298 case ESetType::kSet:
1299 case ESetType::kUnorderedSet: EnsureMatchingTypePrefix(desc, prefixesRegular).ThrowOnError(); break;
1300 default:
1301 break;
1302 // no restrictions for multisets
1303 }
1304}
1305
1306//------------------------------------------------------------------------------
1307
1308namespace {
1309
1310/// Used in RStreamerField::AppendImpl() in order to record the encountered streamer info records
1311class TBufferRecStreamer : public TBufferFile {
1312public:
1313 using RCallbackStreamerInfo = std::function<void(TVirtualStreamerInfo *)>;
1314
1315private:
1316 RCallbackStreamerInfo fCallbackStreamerInfo;
1317
1318public:
1319 TBufferRecStreamer(TBuffer::EMode mode, Int_t bufsize, RCallbackStreamerInfo callbackStreamerInfo)
1320 : TBufferFile(mode, bufsize), fCallbackStreamerInfo(callbackStreamerInfo)
1321 {
1322 }
1323 void TagStreamerInfo(TVirtualStreamerInfo *info) final { fCallbackStreamerInfo(info); }
1324};
1325
1326} // anonymous namespace
1327
1328ROOT::RStreamerField::RStreamerField(std::string_view fieldName, std::string_view className)
1330{
1331}
1332
1334 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kStreamer,
1335 false /* isSimple */),
1336 fClass(classp),
1337 fIndex(0)
1338{
1339 std::string renormalizedAlias;
1342
1344 // For RClassField, we only check for explicit constructors and destructors and then recursively combine traits from
1345 // all member subfields. For RStreamerField, we treat the class as a black box and additionally need to check for
1346 // implicit constructors and destructors.
1351}
1352
1353std::unique_ptr<ROOT::RFieldBase> ROOT::RStreamerField::CloneImpl(std::string_view newName) const
1354{
1355 return std::unique_ptr<RStreamerField>(new RStreamerField(newName, GetTypeName()));
1356}
1357
1358std::size_t ROOT::RStreamerField::AppendImpl(const void *from)
1359{
1360 TBufferRecStreamer buffer(TBuffer::kWrite, GetValueSize(),
1361 [this](TVirtualStreamerInfo *info) { fStreamerInfos[info->GetNumber()] = info; });
1362 fClass->Streamer(const_cast<void *>(from), buffer);
1363
1364 auto nbytes = buffer.Length();
1365 fAuxiliaryColumn->AppendV(buffer.Buffer(), buffer.Length());
1366 fIndex += nbytes;
1367 fPrincipalColumn->Append(&fIndex);
1368 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
1369}
1370
1372{
1375 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nbytes);
1376
1378 fAuxiliaryColumn->ReadV(collectionStart, nbytes, buffer.Buffer());
1379 fClass->Streamer(to, buffer);
1380}
1381
1391
1396
1401
1403{
1404 source.RegisterStreamerInfos();
1405 return nullptr;
1406}
1407
1409{
1410 EnsureMatchingOnDiskField(desc, kDiffTypeName | kDiffTypeVersion).ThrowOnError();
1411}
1412
1414{
1415 fClass->New(where);
1416}
1417
1419{
1420 fClass->Destructor(objPtr, true /* dtorOnly */);
1421 RDeleter::operator()(objPtr, dtorOnly);
1422}
1423
1425{
1428 .TypeVersion(GetTypeVersion())
1429 .TypeName(GetTypeName())
1431 return extraTypeInfoBuilder.MoveDescriptor().Unwrap();
1432}
1433
1435{
1436 const auto align = fClass->GetClassAlignment();
1437 EnsureValidAlignment(align);
1438 return align;
1439}
1440
1442{
1443 return fClass->GetClassSize();
1444}
1445
1447{
1448 return fClass->GetClassVersion();
1449}
1450
1452{
1453 return fClass->GetCheckSum();
1454}
1455
1457{
1458 visitor.VisitStreamerField(*this);
1459}
1460
1461//------------------------------------------------------------------------------
1462
1464{
1465 if (auto dataMember = TObject::Class()->GetDataMember(name)) {
1466 return dataMember->GetOffset();
1467 }
1468 throw RException(R__FAIL('\'' + std::string(name) + '\'' + " is an invalid data member"));
1469}
1470
1472 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1473{
1475 Attach(source.GetConstSubfields()[0]->Clone("fUniqueID"));
1476 Attach(source.GetConstSubfields()[1]->Clone("fBits"));
1477}
1478
1480 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1481{
1482 assert(TObject::Class()->GetClassVersion() == 1);
1483
1485 Attach(std::make_unique<RField<UInt_t>>("fUniqueID"));
1486 Attach(std::make_unique<RField<UInt_t>>("fBits"));
1487}
1488
1489std::unique_ptr<ROOT::RFieldBase> ROOT::RField<TObject>::CloneImpl(std::string_view newName) const
1490{
1491 return std::unique_ptr<RField<TObject>>(new RField<TObject>(newName, *this));
1492}
1493
1494std::size_t ROOT::RField<TObject>::AppendImpl(const void *from)
1495{
1496 // Cf. TObject::Streamer()
1497
1498 auto *obj = static_cast<const TObject *>(from);
1499 if (obj->TestBit(TObject::kIsReferenced)) {
1500 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1501 }
1502
1503 std::size_t nbytes = 0;
1504 nbytes += CallAppendOn(*fSubfields[0], reinterpret_cast<const unsigned char *>(from) + GetOffsetUniqueID());
1505
1506 UInt_t bits = *reinterpret_cast<const UInt_t *>(reinterpret_cast<const unsigned char *>(from) + GetOffsetBits());
1507 bits &= (~TObject::kIsOnHeap & ~TObject::kNotDeleted);
1508 nbytes += CallAppendOn(*fSubfields[1], &bits);
1509
1510 return nbytes;
1511}
1512
1514{
1515 // Cf. TObject::Streamer()
1516
1517 auto *obj = static_cast<TObject *>(to);
1518 if (obj->TestBit(TObject::kIsReferenced)) {
1519 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1520 }
1521
1522 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetUniqueID()) = uniqueID;
1523
1524 const UInt_t bitIsOnHeap = obj->TestBit(TObject::kIsOnHeap) ? TObject::kIsOnHeap : 0;
1526 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetBits()) = bits;
1527}
1528
1530{
1531 UInt_t uniqueID, bits;
1532 CallReadOn(*fSubfields[0], globalIndex, &uniqueID);
1533 CallReadOn(*fSubfields[1], globalIndex, &bits);
1534 ReadTObject(to, uniqueID, bits);
1535}
1536
1538{
1539 UInt_t uniqueID, bits;
1540 CallReadOn(*fSubfields[0], localIndex, &uniqueID);
1541 CallReadOn(*fSubfields[1], localIndex, &bits);
1542 ReadTObject(to, uniqueID, bits);
1543}
1544
1546{
1547 return TObject::Class()->GetClassVersion();
1548}
1549
1551{
1552 return TObject::Class()->GetCheckSum();
1553}
1554
1556{
1557 new (where) TObject();
1558}
1559
1560std::vector<ROOT::RFieldBase::RValue> ROOT::RField<TObject>::SplitValue(const RValue &value) const
1561{
1562 std::vector<RValue> result;
1563 // Use GetPtr<TObject> to type-check
1564 std::shared_ptr<void> ptr = value.GetPtr<TObject>();
1565 auto charPtr = static_cast<unsigned char *>(ptr.get());
1566 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(ptr, charPtr + GetOffsetUniqueID())));
1567 result.emplace_back(fSubfields[1]->BindValue(std::shared_ptr<void>(ptr, charPtr + GetOffsetBits())));
1568 return result;
1569}
1570
1572{
1573 return sizeof(TObject);
1574}
1575
1577{
1578 return alignof(TObject);
1579}
1580
1582{
1583 visitor.VisitTObjectField(*this);
1584}
1585
1586//------------------------------------------------------------------------------
1587
1588ROOT::RTupleField::RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1589 : ROOT::RRecordField(fieldName, "std::tuple<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">")
1590{
1591 const std::string typeAlias = "std::tuple<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
1592 if (typeAlias != GetTypeName())
1594
1595 AttachItemFields(std::move(itemFields));
1596
1597 auto *c = TClass::GetClass(GetTypeName().c_str());
1598 if (!c)
1599 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
1600 fSize = c->Size();
1601
1602 // ISO C++ does not guarantee neither specific layout nor member names for `std::tuple`. However, most
1603 // implementations including libstdc++ (gcc), libc++ (llvm), and MSVC name members as `_0`, `_1`, ..., `_N-1`,
1604 // following the order of the type list.
1605 // Use TClass to get their offsets; in case a particular `std::tuple` implementation does not define such
1606 // members, the assertion below will fail.
1607 for (unsigned i = 0; i < fSubfields.size(); ++i) {
1608 std::string memberName("_" + std::to_string(i));
1609 auto member = c->GetRealData(memberName.c_str());
1610 if (!member)
1611 throw RException(R__FAIL(memberName + ": no such member"));
1612 fOffsets.push_back(member->GetThisOffset());
1613 }
1614}
1615
1616std::unique_ptr<ROOT::RFieldBase> ROOT::RTupleField::CloneImpl(std::string_view newName) const
1617{
1618 std::vector<std::unique_ptr<RFieldBase>> itemClones;
1619 itemClones.reserve(fSubfields.size());
1620 for (const auto &f : fSubfields) {
1621 itemClones.emplace_back(f->Clone(f->GetFieldName()));
1622 }
1623 return std::unique_ptr<RTupleField>(new RTupleField(newName, std::move(itemClones)));
1624}
1625
1627{
1628 static const std::vector<std::string> prefixes = {"std::pair<", "std::tuple<"};
1629
1630 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1631 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1632
1633 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1634 const auto nOnDiskSubfields = fieldDesc.GetLinkIds().size();
1635 const auto nSubfields = fSubfields.size();
1637 throw ROOT::RException(R__FAIL("invalid number of on-disk subfields for std::tuple " +
1638 std::to_string(nOnDiskSubfields) + " vs. " + std::to_string(nSubfields) + "\n" +
1639 Internal::GetTypeTraceReport(*this, desc)));
1640 }
1641}
1642
1643//------------------------------------------------------------------------------
1644
1645namespace {
1646
1647// Depending on the compiler, the variant tag is stored either in a trailing char or in a trailing unsigned int
1648constexpr std::size_t GetVariantTagSize()
1649{
1650 // Should be all zeros except for the tag, which is 1
1651 std::variant<char> t;
1652 constexpr auto sizeOfT = sizeof(t);
1653
1654 static_assert(sizeOfT == 2 || sizeOfT == 8, "unsupported std::variant layout");
1655 return sizeOfT == 2 ? 1 : 4;
1656}
1657
1658template <std::size_t VariantSizeT>
1659struct RVariantTag {
1660 using ValueType_t = typename std::conditional_t<VariantSizeT == 1, std::uint8_t,
1661 typename std::conditional_t<VariantSizeT == 4, std::uint32_t, void>>;
1662};
1663
1664} // anonymous namespace
1665
1667 : ROOT::RFieldBase(name, source.GetTypeName(), ROOT::ENTupleStructure::kVariant, false /* isSimple */),
1668 fMaxItemSize(source.fMaxItemSize),
1669 fMaxAlignment(source.fMaxAlignment),
1670 fTagOffset(source.fTagOffset),
1671 fVariantOffset(source.fVariantOffset),
1672 fNWritten(source.fNWritten.size(), 0)
1673{
1674 for (const auto &f : source.GetConstSubfields())
1675 Attach(f->Clone(f->GetFieldName()));
1676 fTraits = source.fTraits;
1677}
1678
1679ROOT::RVariantField::RVariantField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1680 : ROOT::RFieldBase(fieldName, "std::variant<" + GetTypeList(itemFields, false /* useTypeAliases */) + ">",
1681 ROOT::ENTupleStructure::kVariant, false /* isSimple */)
1682{
1683 // The variant needs to initialize its own tag member
1685
1686 const std::string typeAlias = "std::variant<" + GetTypeList(itemFields, true /* useTypeAliases */) + ">";
1687 if (typeAlias != GetTypeName())
1689
1690 auto nFields = itemFields.size();
1691 if (nFields == 0 || nFields > kMaxVariants) {
1692 throw RException(R__FAIL("invalid number of variant fields (outside [1.." + std::to_string(kMaxVariants) + ")"));
1693 }
1694 fNWritten.resize(nFields, 0);
1695 for (unsigned int i = 0; i < nFields; ++i) {
1698 fTraits &= itemFields[i]->GetTraits();
1699 Attach(std::move(itemFields[i]), "_" + std::to_string(i));
1700 }
1701
1702 // With certain template parameters, the union of members of an std::variant starts at an offset > 0.
1703 // For instance, std::variant<std::optional<int>> on macOS.
1704 auto cl = TClass::GetClass(GetTypeName().c_str());
1705 assert(cl);
1706 auto dm = reinterpret_cast<TDataMember *>(cl->GetListOfDataMembers()->First());
1707 if (dm)
1708 fVariantOffset = dm->GetOffset();
1709
1710 const auto tagSize = GetVariantTagSize();
1711 const auto padding = tagSize - (fMaxItemSize % tagSize);
1713}
1714
1715std::unique_ptr<ROOT::RFieldBase> ROOT::RVariantField::CloneImpl(std::string_view newName) const
1716{
1717 return std::unique_ptr<RVariantField>(new RVariantField(newName, *this));
1718}
1719
1720std::uint8_t ROOT::RVariantField::GetTag(const void *variantPtr, std::size_t tagOffset)
1721{
1722 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1723 auto tag = *reinterpret_cast<const TagType_t *>(reinterpret_cast<const unsigned char *>(variantPtr) + tagOffset);
1724 return (tag == TagType_t(-1)) ? 0 : tag + 1;
1725}
1726
1727void ROOT::RVariantField::SetTag(void *variantPtr, std::size_t tagOffset, std::uint8_t tag)
1728{
1729 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1730 auto tagPtr = reinterpret_cast<TagType_t *>(reinterpret_cast<unsigned char *>(variantPtr) + tagOffset);
1731 *tagPtr = (tag == 0) ? TagType_t(-1) : static_cast<TagType_t>(tag - 1);
1732}
1733
1734std::size_t ROOT::RVariantField::AppendImpl(const void *from)
1735{
1736 auto tag = GetTag(from, fTagOffset);
1737 std::size_t nbytes = 0;
1738 auto index = 0;
1739 if (tag > 0) {
1740 nbytes += CallAppendOn(*fSubfields[tag - 1], reinterpret_cast<const unsigned char *>(from) + fVariantOffset);
1741 index = fNWritten[tag - 1]++;
1742 }
1744 fPrincipalColumn->Append(&varSwitch);
1745 return nbytes + sizeof(ROOT::Internal::RColumnSwitch);
1746}
1747
1749{
1751 std::uint32_t tag;
1752 fPrincipalColumn->GetSwitchInfo(globalIndex, &variantIndex, &tag);
1753 R__ASSERT(tag < 256);
1754
1755 // If `tag` equals 0, the variant is in the invalid state, i.e, it does not hold any of the valid alternatives in
1756 // the type list. This happens, e.g., if the field was late added; in this case, keep the invalid tag, which makes
1757 // any `std::holds_alternative<T>` check fail later.
1758 if (R__likely(tag > 0)) {
1759 void *varPtr = reinterpret_cast<unsigned char *>(to) + fVariantOffset;
1760 CallConstructValueOn(*fSubfields[tag - 1], varPtr);
1761 CallReadOn(*fSubfields[tag - 1], variantIndex, varPtr);
1762 }
1763 SetTag(to, fTagOffset, tag);
1764}
1765
1771
1776
1781
1783{
1784 static const std::vector<std::string> prefixes = {"std::variant<"};
1785
1786 EnsureMatchingOnDiskField(desc, kDiffTypeName).ThrowOnError();
1787 EnsureMatchingTypePrefix(desc, prefixes).ThrowOnError();
1788
1789 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1790 if (fSubfields.size() != fieldDesc.GetLinkIds().size()) {
1791 throw RException(R__FAIL("number of variants on-disk do not match for " + GetQualifiedFieldName() + "\n" +
1792 Internal::GetTypeTraceReport(*this, desc)));
1793 }
1794}
1795
1797{
1798 memset(where, 0, GetValueSize());
1799 CallConstructValueOn(*fSubfields[0], reinterpret_cast<unsigned char *>(where) + fVariantOffset);
1800 SetTag(where, fTagOffset, 1);
1801}
1802
1804{
1805 auto tag = GetTag(objPtr, fTagOffset);
1806 if (tag > 0) {
1807 fItemDeleters[tag - 1]->operator()(reinterpret_cast<unsigned char *>(objPtr) + fVariantOffset, true /*dtorOnly*/);
1808 }
1809 RDeleter::operator()(objPtr, dtorOnly);
1810}
1811
1812std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RVariantField::GetDeleter() const
1813{
1814 std::vector<std::unique_ptr<RDeleter>> itemDeleters;
1815 itemDeleters.reserve(fSubfields.size());
1816 for (const auto &f : fSubfields) {
1817 itemDeleters.emplace_back(GetDeleterOf(*f));
1818 }
1819 return std::make_unique<RVariantDeleter>(fTagOffset, fVariantOffset, std::move(itemDeleters));
1820}
1821
1823{
1824 return std::max(fMaxAlignment, alignof(RVariantTag<GetVariantTagSize()>::ValueType_t));
1825}
1826
1828{
1829 const auto alignment = GetAlignment();
1830 const auto actualSize = fTagOffset + GetVariantTagSize();
1831 const auto padding = alignment - (actualSize % alignment);
1832 return actualSize + ((padding == alignment) ? 0 : padding);
1833}
1834
1836{
1837 std::fill(fNWritten.begin(), fNWritten.end(), 0);
1838}
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.