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// - REnumField
9// - RPairField
10// - RProxiedCollectionField
11// - RMapField
12// - RSetField
13// - RStreamerField
14// - RPairField
15// - RField<TObject>
16// - RVariantField
17
18#include <ROOT/RField.hxx>
19#include <ROOT/RFieldBase.hxx>
20#include <ROOT/RFieldUtils.hxx>
22#include <ROOT/RSpan.hxx>
23
24#include <TBaseClass.h>
25#include <TBufferFile.h>
26#include <TClass.h>
27#include <TClassEdit.h>
28#include <TDataMember.h>
29#include <TEnum.h>
30#include <TObject.h>
31#include <TObjArray.h>
32#include <TObjString.h>
33#include <TRealData.h>
34#include <TSchemaRule.h>
35#include <TSchemaRuleSet.h>
36#include <TStreamerElement.h>
37#include <TVirtualObject.h>
39
40#include <algorithm>
41#include <array>
42#include <cstddef> // std::size_t
43#include <cstdint> // std::uint32_t et al.
44#include <cstring> // for memset
45#include <memory>
46#include <string>
47#include <string_view>
48#include <unordered_set>
49#include <utility>
50#include <variant>
51
53
54namespace {
55
56TClass *EnsureValidClass(std::string_view className)
57{
58 auto cl = TClass::GetClass(std::string(className).c_str());
59 if (cl == nullptr) {
60 throw ROOT::RException(R__FAIL("RField: no I/O support for type " + std::string(className)));
61 }
62 return cl;
63}
64
65TEnum *EnsureValidEnum(std::string_view enumName)
66{
67 auto e = TEnum::GetEnum(std::string(enumName).c_str());
68 if (e == nullptr) {
69 throw ROOT::RException(R__FAIL("RField: no I/O support for enum type " + std::string(enumName)));
70 }
71 return e;
72}
73
74} // anonymous namespace
75
77 : ROOT::RFieldBase(fieldName, source.GetTypeName(), ROOT::ENTupleStructure::kRecord, false /* isSimple */),
79 fSubfieldsInfo(source.fSubfieldsInfo),
80 fMaxAlignment(source.fMaxAlignment)
81{
82 for (const auto &f : source.GetConstSubfields()) {
83 RFieldBase::Attach(f->Clone(f->GetFieldName()));
84 }
85 fTraits = source.GetTraits();
86}
87
88ROOT::RClassField::RClassField(std::string_view fieldName, std::string_view className)
90{
91}
92
94 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kRecord,
95 false /* isSimple */),
97{
99 throw RException(R__FAIL(std::string("RField: RClassField \"") + classp->GetName() +
100 " cannot be constructed from a class that's not at least Interpreted"));
101 }
102 // Avoid accidentally supporting std types through TClass.
104 throw RException(R__FAIL(std::string(GetTypeName()) + " is not supported"));
105 }
106 if (GetTypeName() == "TObject") {
107 throw RException(R__FAIL("TObject is only supported through RField<TObject>"));
108 }
109 if (fClass->GetCollectionProxy()) {
110 throw RException(R__FAIL(std::string(GetTypeName()) + " has an associated collection proxy; "
111 "use RProxiedCollectionField instead"));
112 }
113 // Classes with, e.g., custom streamers are not supported through this field. Empty classes, however, are.
114 // Can be overwritten with the "rntuple.streamerMode=true" class attribute
115 if (!fClass->CanSplit() && fClass->Size() > 1 &&
118 throw RException(R__FAIL(GetTypeName() + " cannot be stored natively in RNTuple"));
119 }
122 throw RException(R__FAIL(GetTypeName() + " has streamer mode enforced, not supported as native RNTuple class"));
123 }
124
129
130 std::string renormalizedAlias;
133
134 int i = 0;
135 const auto *bases = fClass->GetListOfBases();
136 assert(bases);
138 if (baseClass->GetDelta() < 0) {
139 throw RException(R__FAIL(std::string("virtual inheritance is not supported: ") + GetTypeName() +
140 " virtually inherits from " + baseClass->GetName()));
141 }
142 TClass *c = baseClass->GetClassPointer();
143 auto subField =
144 RFieldBase::Create(std::string(kPrefixInherited) + "_" + std::to_string(i), c->GetName()).Unwrap();
145 fTraits &= subField->GetTraits();
146 Attach(std::move(subField), RSubFieldInfo{kBaseClass, static_cast<std::size_t>(baseClass->GetDelta())});
147 i++;
148 }
150 // Skip, for instance, unscoped enum constants defined in the class
151 if (dataMember->Property() & kIsStatic)
152 continue;
153 // Skip members explicitly marked as transient by user comment
154 if (!dataMember->IsPersistent()) {
155 // TODO(jblomer): we could do better
157 continue;
158 }
159
160 // NOTE: we use the already-resolved type name for the fields, otherwise TClass::GetClass may fail to resolve
161 // context-dependent types (e.g. typedefs defined in the class itself - which will not be fully qualified in
162 // the string returned by dataMember->GetFullTypeName())
163 std::string typeName{dataMember->GetTrueTypeName()};
164 // RFieldBase::Create() set subField->fTypeAlias based on the assumption that the user specified typeName, which
165 // already went through one round of type resolution.
166 std::string origTypeName{dataMember->GetFullTypeName()};
167
168 // For C-style arrays, complete the type name with the size for each dimension, e.g. `int[4][2]`
169 if (dataMember->Property() & kIsArray) {
170 for (int dim = 0, n = dataMember->GetArrayDim(); dim < n; ++dim) {
171 const auto addedStr = "[" + std::to_string(dataMember->GetMaxIndex(dim)) + "]";
172 typeName += addedStr;
174 }
175 }
176
177 auto subField = RFieldBase::Create(dataMember->GetName(), typeName).Unwrap();
178
180 if (normTypeName == subField->GetTypeName()) {
181 subField->fTypeAlias = "";
182 } else {
183 subField->fTypeAlias = normTypeName;
184 }
185
186 fTraits &= subField->GetTraits();
187 Attach(std::move(subField), RSubFieldInfo{kDataMember, static_cast<std::size_t>(dataMember->GetOffset())});
188 }
190}
191
193{
194 if (fStagingArea) {
195 for (const auto &[_, si] : fStagingItems) {
196 if (!(si.fField->GetTraits() & kTraitTriviallyDestructible)) {
197 auto deleter = si.fField->GetDeleter();
198 deleter->operator()(fStagingArea.get() + si.fOffset, true /* dtorOnly */);
199 }
200 }
201 }
202}
203
204void ROOT::RClassField::Attach(std::unique_ptr<RFieldBase> child, RSubFieldInfo info)
205{
206 fMaxAlignment = std::max(fMaxAlignment, child->GetAlignment());
207 fSubfieldsInfo.push_back(info);
208 RFieldBase::Attach(std::move(child));
209}
210
211std::vector<const ROOT::TSchemaRule *> ROOT::RClassField::FindRules(const ROOT::RFieldDescriptor *fieldDesc)
212{
214 const auto ruleset = fClass->GetSchemaRules();
215 if (!ruleset)
216 return rules;
217
218 if (!fieldDesc) {
219 // If we have no on-disk information for the field, we still process the rules on the current in-memory version
220 // of the class
221 rules = ruleset->FindRules(fClass->GetName(), fClass->GetClassVersion(), fClass->GetCheckSum());
222 } else {
223 // We need to change (back) the name normalization from RNTuple to ROOT Meta
224 std::string normalizedName;
226 // We do have an on-disk field that correspond to the current RClassField instance. Ask for rules matching the
227 // on-disk version of the field.
228 if (fieldDesc->GetTypeChecksum()) {
229 rules = ruleset->FindRules(normalizedName, fieldDesc->GetTypeVersion(), *fieldDesc->GetTypeChecksum());
230 } else {
231 rules = ruleset->FindRules(normalizedName, fieldDesc->GetTypeVersion());
232 }
233 }
234
235 // Cleanup and sort rules
236 // Check that any any given source member uses the same type in all rules
237 std::unordered_map<std::string, std::string> sourceNameAndType;
238 std::size_t nskip = 0; // skip whole-object-rules that were moved to the end of the rules vector
239 for (auto itr = rules.begin(); itr != rules.end() - nskip;) {
240 const auto rule = *itr;
241
242 // Erase unknown rule types
243 if (rule->GetRuleType() != ROOT::TSchemaRule::kReadRule) {
245 << "ignoring I/O customization rule with unsupported type: " << rule->GetRuleType();
246 itr = rules.erase(itr);
247 continue;
248 }
249
250 bool hasConflictingSourceMembers = false;
251 for (auto source : TRangeDynCast<TSchemaRule::TSources>(rule->GetSource())) {
252 auto memberType = source->GetTypeForDeclaration() + source->GetDimensions();
253 auto [itrSrc, isNew] = sourceNameAndType.emplace(source->GetName(), memberType);
254 if (!isNew && (itrSrc->second != memberType)) {
256 << "ignoring I/O customization rule due to conflicting source member type: " << itrSrc->second << " vs. "
257 << memberType << " for member " << source->GetName();
259 break;
260 }
261 }
263 itr = rules.erase(itr);
264 continue;
265 }
266
267 // Rules targeting the entire object need to be executed at the end
268 if (rule->GetTarget() == nullptr) {
269 nskip++;
270 if (itr != rules.end() - nskip)
271 std::iter_swap(itr++, rules.end() - nskip);
272 continue;
273 }
274
275 ++itr;
276 }
277
278 return rules;
279}
280
281std::unique_ptr<ROOT::RFieldBase> ROOT::RClassField::CloneImpl(std::string_view newName) const
282{
283 return std::unique_ptr<RClassField>(new RClassField(newName, *this));
284}
285
286std::size_t ROOT::RClassField::AppendImpl(const void *from)
287{
288 std::size_t nbytes = 0;
289 for (unsigned i = 0; i < fSubfields.size(); i++) {
290 nbytes += CallAppendOn(*fSubfields[i], static_cast<const unsigned char *>(from) + fSubfieldsInfo[i].fOffset);
291 }
292 return nbytes;
293}
294
296{
297 for (const auto &[_, si] : fStagingItems) {
298 CallReadOn(*si.fField, globalIndex, fStagingArea.get() + si.fOffset);
299 }
300 for (unsigned i = 0; i < fSubfields.size(); i++) {
301 CallReadOn(*fSubfields[i], globalIndex, static_cast<unsigned char *>(to) + fSubfieldsInfo[i].fOffset);
302 }
303}
304
306{
307 for (const auto &[_, si] : fStagingItems) {
308 CallReadOn(*si.fField, localIndex, fStagingArea.get() + si.fOffset);
309 }
310 for (unsigned i = 0; i < fSubfields.size(); i++) {
311 CallReadOn(*fSubfields[i], localIndex, static_cast<unsigned char *>(to) + fSubfieldsInfo[i].fOffset);
312 }
313}
314
317{
320 return idSourceMember;
321
322 for (const auto &subFieldDesc : desc.GetFieldIterable(classFieldId)) {
323 const auto subFieldName = subFieldDesc.GetFieldName();
324 if (subFieldName.length() > 2 && subFieldName[0] == ':' && subFieldName[1] == '_') {
325 idSourceMember = LookupMember(desc, memberName, subFieldDesc.GetId());
327 return idSourceMember;
328 }
329 }
330
332}
333
334void ROOT::RClassField::SetStagingClass(const std::string &className, unsigned int classVersion)
335{
336 TClass::GetClass(className.c_str())->GetStreamerInfo(classVersion);
337 if (classVersion != GetTypeVersion() || className != GetTypeName()) {
338 fStagingClass = TClass::GetClass((className + std::string("@@") + std::to_string(classVersion)).c_str());
339 if (!fStagingClass) {
340 // For a rename rule, we may simply ask for the old class name
341 fStagingClass = TClass::GetClass(className.c_str());
342 }
343 } else {
344 fStagingClass = fClass;
345 }
346 R__ASSERT(fStagingClass);
347 R__ASSERT(static_cast<unsigned int>(fStagingClass->GetClassVersion()) == classVersion);
348}
349
350void ROOT::RClassField::PrepareStagingArea(const std::vector<const TSchemaRule *> &rules,
351 const ROOT::RNTupleDescriptor &desc,
353{
354 std::size_t stagingAreaSize = 0;
355 for (const auto rule : rules) {
356 for (auto source : TRangeDynCast<TSchemaRule::TSources>(rule->GetSource())) {
357 auto [itr, isNew] = fStagingItems.emplace(source->GetName(), RStagingItem());
358 if (!isNew) {
359 // This source member has already been processed by another rule (and we only support one type per member)
360 continue;
361 }
362 RStagingItem &stagingItem = itr->second;
363
364 const auto memberFieldId = LookupMember(desc, source->GetName(), classFieldDesc.GetId());
366 throw RException(R__FAIL(std::string("cannot find on disk rule source member ") + GetTypeName() + "." +
367 source->GetName()));
368 }
370
371 auto memberType = source->GetTypeForDeclaration() + source->GetDimensions();
372 stagingItem.fField = Create("" /* we don't need a field name */, std::string(memberType)).Unwrap();
373 stagingItem.fField->SetOnDiskId(memberFieldDesc.GetId());
374
375 stagingItem.fOffset = fStagingClass->GetDataMemberOffset(source->GetName());
376 // Since we successfully looked up the source member in the RNTuple on-disk metadata, we expect it
377 // to be present in the TClass instance, too.
379 stagingAreaSize = std::max(stagingAreaSize, stagingItem.fOffset + stagingItem.fField->GetValueSize());
380 }
381 }
382
383 if (stagingAreaSize) {
384 R__ASSERT(static_cast<Int_t>(stagingAreaSize) <= fStagingClass->Size()); // we may have removed rules
385 // We use std::make_unique instead of MakeUninitArray to zero-initialize the staging area.
386 fStagingArea = std::make_unique<unsigned char[]>(stagingAreaSize);
387
388 for (const auto &[_, si] : fStagingItems) {
389 if (!(si.fField->GetTraits() & kTraitTriviallyConstructible)) {
390 CallConstructValueOn(*si.fField, fStagingArea.get() + si.fOffset);
391 }
392 }
393 }
394}
395
397{
398 auto func = rule->GetReadFunctionPointer();
399 if (func == nullptr) {
400 // Can happen for rename rules
401 return;
402 }
403 fReadCallbacks.emplace_back([func, stagingClass = fStagingClass, stagingArea = fStagingArea.get()](void *target) {
404 TVirtualObject onfileObj{nullptr};
405 onfileObj.fClass = stagingClass;
406 onfileObj.fObject = stagingArea;
407 func(static_cast<char *>(target), &onfileObj);
408 onfileObj.fObject = nullptr; // TVirtualObject does not own the value
409 });
410}
411
413{
414 std::vector<const TSchemaRule *> rules;
415 // On-disk members that are not targeted by an I/O rule; all other sub fields of the in-memory class
416 // will be marked as artificial (added member in a new class version or member set by rule).
417 std::unordered_set<std::string> regularSubfields;
418
419 if (GetOnDiskId() == kInvalidDescriptorId) {
420 // This can happen for added base classes or added members of class type
421 rules = FindRules(nullptr);
422 if (!rules.empty())
423 SetStagingClass(GetTypeName(), GetTypeVersion());
424 } else {
425 const auto descriptorGuard = pageSource.GetSharedDescriptorGuard();
426 const ROOT::RNTupleDescriptor &desc = descriptorGuard.GetRef();
427 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
428
429 for (auto linkId : fieldDesc.GetLinkIds()) {
430 const auto &subFieldDesc = desc.GetFieldDescriptor(linkId);
431 regularSubfields.insert(subFieldDesc.GetFieldName());
432 }
433
434 rules = FindRules(&fieldDesc);
435
436 // 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
437 // (source) type name and version/checksum.
438 if (rules.empty()) {
439 // Otherwise we require compatible type names, after renormalization. GetTypeName() is already renormalized,
440 // but RNTuple data written with ROOT v6.34 might not have renormalized the field type name. Ask the
441 // RNTupleDescriptor, which knows about the spec version, for a fixed up type name.
443 if (GetTypeName() != descTypeName) {
444 throw RException(R__FAIL("incompatible type name for field " + GetFieldName() + ": " + GetTypeName() +
445 " vs. " + descTypeName));
446 }
447 }
448
449 if (!rules.empty()) {
450 SetStagingClass(fieldDesc.GetTypeName(), fieldDesc.GetTypeVersion());
451 PrepareStagingArea(rules, desc, fieldDesc);
452 for (auto &[_, si] : fStagingItems)
454
455 // Remove target member of read rules from the list of regular members of the underlying on-disk field
456 for (const auto rule : rules) {
457 if (!rule->GetTarget())
458 continue;
459
460 for (const auto target : ROOT::Detail::TRangeStaticCast<const TObjString>(*rule->GetTarget())) {
461 regularSubfields.erase(std::string(target->GetString()));
462 }
463 }
464 }
465 }
466
467 for (const auto rule : rules) {
468 AddReadCallbacksFromIORule(rule);
469 }
470
471 // Iterate over all sub fields in memory and mark those as missing that are not in the descriptor.
472 for (auto &field : fSubfields) {
473 if (regularSubfields.count(field->GetFieldName()) == 0) {
474 field->SetArtificial();
475 }
476 }
477}
478
480{
481 fClass->New(where);
482}
483
485{
486 fClass->Destructor(objPtr, true /* dtorOnly */);
487 RDeleter::operator()(objPtr, dtorOnly);
488}
489
490std::vector<ROOT::RFieldBase::RValue> ROOT::RClassField::SplitValue(const RValue &value) const
491{
492 std::vector<RValue> result;
493 auto basePtr = value.GetPtr<unsigned char>().get();
494 result.reserve(fSubfields.size());
495 for (unsigned i = 0; i < fSubfields.size(); i++) {
496 result.emplace_back(
497 fSubfields[i]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), basePtr + fSubfieldsInfo[i].fOffset)));
498 }
499 return result;
500}
501
503{
504 return fClass->GetClassSize();
505}
506
508{
509 return fClass->GetClassVersion();
510}
511
513{
514 return fClass->GetCheckSum();
515}
516
518{
519 visitor.VisitClassField(*this);
520}
521
522//------------------------------------------------------------------------------
523
524ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName)
526{
527}
528
530 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(enump->GetQualifiedName()), ROOT::ENTupleStructure::kLeaf,
531 false /* isSimple */)
532{
533 // Avoid accidentally supporting std types through TEnum.
534 if (enump->Property() & kIsDefinedInStd) {
535 throw RException(R__FAIL(GetTypeName() + " is not supported"));
536 }
537
538 switch (enump->GetUnderlyingType()) {
539 case kBool_t: Attach(std::make_unique<RField<Bool_t>>("_0")); break;
540 case kChar_t: Attach(std::make_unique<RField<Char_t>>("_0")); break;
541 case kUChar_t: Attach(std::make_unique<RField<UChar_t>>("_0")); break;
542 case kShort_t: Attach(std::make_unique<RField<Short_t>>("_0")); break;
543 case kUShort_t: Attach(std::make_unique<RField<UShort_t>>("_0")); break;
544 case kInt_t: Attach(std::make_unique<RField<Int_t>>("_0")); break;
545 case kUInt_t: Attach(std::make_unique<RField<UInt_t>>("_0")); break;
546 case kLong_t: Attach(std::make_unique<RField<Long_t>>("_0")); break;
547 case kLong64_t: Attach(std::make_unique<RField<Long64_t>>("_0")); break;
548 case kULong_t: Attach(std::make_unique<RField<ULong_t>>("_0")); break;
549 case kULong64_t: Attach(std::make_unique<RField<ULong64_t>>("_0")); break;
550 default: throw RException(R__FAIL("Unsupported underlying integral type for enum type " + GetTypeName()));
551 }
552
554}
555
556ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName,
557 std::unique_ptr<RFieldBase> intField)
559{
560 Attach(std::move(intField));
562}
563
564std::unique_ptr<ROOT::RFieldBase> ROOT::REnumField::CloneImpl(std::string_view newName) const
565{
566 auto newIntField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
567 return std::unique_ptr<REnumField>(new REnumField(newName, GetTypeName(), std::move(newIntField)));
568}
569
570std::vector<ROOT::RFieldBase::RValue> ROOT::REnumField::SplitValue(const RValue &value) const
571{
572 std::vector<RValue> result;
573 result.emplace_back(fSubfields[0]->BindValue(value.GetPtr<void>()));
574 return result;
575}
576
578{
579 visitor.VisitEnumField(*this);
580}
581
582//------------------------------------------------------------------------------
583
584std::string ROOT::RPairField::RPairField::GetTypeList(const std::array<std::unique_ptr<RFieldBase>, 2> &itemFields)
585{
586 return itemFields[0]->GetTypeName() + "," + itemFields[1]->GetTypeName();
587}
588
589ROOT::RPairField::RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields,
590 const std::array<std::size_t, 2> &offsets)
591 : ROOT::RRecordField(fieldName, "std::pair<" + GetTypeList(itemFields) + ">")
592{
593 AttachItemFields(std::move(itemFields));
594 fOffsets.push_back(offsets[0]);
595 fOffsets.push_back(offsets[1]);
596}
597
598ROOT::RPairField::RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields)
599 : ROOT::RRecordField(fieldName, "std::pair<" + GetTypeList(itemFields) + ">")
600{
601 AttachItemFields(std::move(itemFields));
602
603 // ISO C++ does not guarantee any specific layout for `std::pair`; query TClass for the member offsets
604 auto *c = TClass::GetClass(GetTypeName().c_str());
605 if (!c)
606 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
607 fSize = c->Size();
608
609 auto firstElem = c->GetRealData("first");
610 if (!firstElem)
611 throw RException(R__FAIL("first: no such member"));
612 fOffsets.push_back(firstElem->GetThisOffset());
613
614 auto secondElem = c->GetRealData("second");
615 if (!secondElem)
616 throw RException(R__FAIL("second: no such member"));
617 fOffsets.push_back(secondElem->GetThisOffset());
618}
619
620//------------------------------------------------------------------------------
621
624 bool readFromDisk)
625{
627 ifuncs.fCreateIterators = proxy->GetFunctionCreateIterators(readFromDisk);
628 ifuncs.fDeleteTwoIterators = proxy->GetFunctionDeleteTwoIterators(readFromDisk);
629 ifuncs.fNext = proxy->GetFunctionNext(readFromDisk);
630 R__ASSERT((ifuncs.fCreateIterators != nullptr) && (ifuncs.fDeleteTwoIterators != nullptr) &&
631 (ifuncs.fNext != nullptr));
632 return ifuncs;
633}
634
636 : RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kCollection,
637 false /* isSimple */),
638 fNWritten(0)
639{
640 if (!classp->GetCollectionProxy())
641 throw RException(R__FAIL(std::string(classp->GetName()) + " has no associated collection proxy"));
642 if (classp->Property() & kIsDefinedInStd) {
643 static const std::vector<std::string> supportedStdTypes = {
644 "std::set<", "std::unordered_set<", "std::multiset<", "std::unordered_multiset<",
645 "std::map<", "std::unordered_map<", "std::multimap<", "std::unordered_multimap<"};
646 bool isSupported = false;
647 for (const auto &tn : supportedStdTypes) {
648 if (GetTypeName().rfind(tn, 0) == 0) {
649 isSupported = true;
650 break;
651 }
652 }
653 if (!isSupported)
654 throw RException(R__FAIL(std::string(GetTypeName()) + " is not supported"));
655 }
656
657 std::string renormalizedAlias;
660
661 fProxy.reset(classp->GetCollectionProxy()->Generate());
662 fProperties = fProxy->GetProperties();
663 fCollectionType = fProxy->GetCollectionType();
664 if (fProxy->HasPointers())
665 throw RException(R__FAIL("collection proxies whose value type is a pointer are not supported"));
666
667 fIFuncsRead = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), true /* readFromDisk */);
668 fIFuncsWrite = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), false /* readFromDisk */);
669}
670
671ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldName, std::string_view typeName,
672 std::unique_ptr<RFieldBase> itemField)
674{
675 fItemSize = itemField->GetValueSize();
676 Attach(std::move(itemField));
677}
678
679ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldName, std::string_view typeName)
681{
682 // NOTE (fdegeus): std::map is supported, custom associative might be supported in the future if the need arises.
684 throw RException(R__FAIL("custom associative collection proxies not supported"));
685
686 std::unique_ptr<ROOT::RFieldBase> itemField;
687
688 if (auto valueClass = fProxy->GetValueClass()) {
689 // Element type is a class
690 itemField = RFieldBase::Create("_0", valueClass->GetName()).Unwrap();
691 } else {
692 switch (fProxy->GetType()) {
693 case EDataType::kChar_t: itemField = std::make_unique<RField<Char_t>>("_0"); break;
694 case EDataType::kUChar_t: itemField = std::make_unique<RField<UChar_t>>("_0"); break;
695 case EDataType::kShort_t: itemField = std::make_unique<RField<Short_t>>("_0"); break;
696 case EDataType::kUShort_t: itemField = std::make_unique<RField<UShort_t>>("_0"); break;
697 case EDataType::kInt_t: itemField = std::make_unique<RField<Int_t>>("_0"); break;
698 case EDataType::kUInt_t: itemField = std::make_unique<RField<UInt_t>>("_0"); break;
699 case EDataType::kLong_t: itemField = std::make_unique<RField<Long_t>>("_0"); break;
700 case EDataType::kLong64_t: itemField = std::make_unique<RField<Long64_t>>("_0"); break;
701 case EDataType::kULong_t: itemField = std::make_unique<RField<ULong_t>>("_0"); break;
702 case EDataType::kULong64_t: itemField = std::make_unique<RField<ULong64_t>>("_0"); break;
703 case EDataType::kFloat_t: itemField = std::make_unique<RField<Float_t>>("_0"); break;
704 case EDataType::kDouble_t: itemField = std::make_unique<RField<Double_t>>("_0"); break;
705 case EDataType::kBool_t: itemField = std::make_unique<RField<Bool_t>>("_0"); break;
706 default: throw RException(R__FAIL("unsupported value type: " + std::to_string(fProxy->GetType())));
707 }
708 }
709
710 fItemSize = itemField->GetValueSize();
711 Attach(std::move(itemField));
712}
713
714std::unique_ptr<ROOT::RFieldBase> ROOT::RProxiedCollectionField::CloneImpl(std::string_view newName) const
715{
716 auto newItemField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
717 return std::unique_ptr<RProxiedCollectionField>(
718 new RProxiedCollectionField(newName, GetTypeName(), std::move(newItemField)));
719}
720
721std::size_t ROOT::RProxiedCollectionField::AppendImpl(const void *from)
722{
723 std::size_t nbytes = 0;
724 unsigned count = 0;
725 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), const_cast<void *>(from));
726 for (auto ptr : RCollectionIterableOnce{const_cast<void *>(from), fIFuncsWrite, fProxy.get(),
727 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
728 nbytes += CallAppendOn(*fSubfields[0], ptr);
729 count++;
730 }
731
732 fNWritten += count;
733 fPrincipalColumn->Append(&fNWritten);
734 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
735}
736
738{
741 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
742
743 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), to);
744 void *obj =
745 fProxy->Allocate(static_cast<std::uint32_t>(nItems), (fProperties & TVirtualCollectionProxy::kNeedDelete));
746
747 unsigned i = 0;
748 for (auto elementPtr : RCollectionIterableOnce{obj, fIFuncsRead, fProxy.get(),
749 (fCollectionType == kSTLvector || obj != to ? fItemSize : 0U)}) {
750 CallReadOn(*fSubfields[0], collectionStart + (i++), elementPtr);
751 }
752 if (obj != to)
753 fProxy->Commit(obj);
754}
755
765
770
775
777{
778 fProxy->New(where);
779}
780
781std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RProxiedCollectionField::GetDeleter() const
782{
783 if (fProperties & TVirtualCollectionProxy::kNeedDelete) {
784 std::size_t itemSize = fCollectionType == kSTLvector ? fItemSize : 0U;
785 return std::make_unique<RProxiedCollectionDeleter>(fProxy, GetDeleterOf(*fSubfields[0]), itemSize);
786 }
787 return std::make_unique<RProxiedCollectionDeleter>(fProxy);
788}
789
791{
792 if (fItemDeleter) {
794 for (auto ptr : RCollectionIterableOnce{objPtr, fIFuncsWrite, fProxy.get(), fItemSize}) {
795 fItemDeleter->operator()(ptr, true /* dtorOnly */);
796 }
797 }
798 fProxy->Destructor(objPtr, true /* dtorOnly */);
799 RDeleter::operator()(objPtr, dtorOnly);
800}
801
802std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(const RValue &value) const
803{
804 std::vector<RValue> result;
805 auto valueRawPtr = value.GetPtr<void>().get();
807 for (auto ptr : RCollectionIterableOnce{valueRawPtr, fIFuncsWrite, fProxy.get(),
808 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
809 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), ptr)));
810 }
811 return result;
812}
813
815{
816 visitor.VisitProxiedCollectionField(*this);
817}
818
819//------------------------------------------------------------------------------
820
821ROOT::RMapField::RMapField(std::string_view fieldName, std::string_view typeName, std::unique_ptr<RFieldBase> itemField)
823{
824 if (!dynamic_cast<RPairField *>(itemField.get()))
825 throw RException(R__FAIL("RMapField inner field type must be of RPairField"));
826
827 auto *itemClass = fProxy->GetValueClass();
828 fItemSize = itemClass->GetClassSize();
829
830 Attach(std::move(itemField));
831}
832
833//------------------------------------------------------------------------------
834
835ROOT::RSetField::RSetField(std::string_view fieldName, std::string_view typeName, std::unique_ptr<RFieldBase> itemField)
837{
838}
839
840//------------------------------------------------------------------------------
841
842namespace {
843
844/// Used in RStreamerField::AppendImpl() in order to record the encountered streamer info records
845class TBufferRecStreamer : public TBufferFile {
846public:
847 using RCallbackStreamerInfo = std::function<void(TVirtualStreamerInfo *)>;
848
849private:
850 RCallbackStreamerInfo fCallbackStreamerInfo;
851
852public:
853 TBufferRecStreamer(TBuffer::EMode mode, Int_t bufsize, RCallbackStreamerInfo callbackStreamerInfo)
854 : TBufferFile(mode, bufsize), fCallbackStreamerInfo(callbackStreamerInfo)
855 {
856 }
857 void TagStreamerInfo(TVirtualStreamerInfo *info) final { fCallbackStreamerInfo(info); }
858};
859
860} // anonymous namespace
861
862ROOT::RStreamerField::RStreamerField(std::string_view fieldName, std::string_view className)
864{
865}
866
868 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kStreamer,
869 false /* isSimple */),
870 fClass(classp),
871 fIndex(0)
872{
873 std::string renormalizedAlias;
876
878 // For RClassField, we only check for explicit constructors and destructors and then recursively combine traits from
879 // all member subfields. For RStreamerField, we treat the class as a black box and additionally need to check for
880 // implicit constructors and destructors.
885}
886
891
892std::unique_ptr<ROOT::RFieldBase> ROOT::RStreamerField::CloneImpl(std::string_view newName) const
893{
894 return std::unique_ptr<RStreamerField>(new RStreamerField(newName, GetTypeName()));
895}
896
897std::size_t ROOT::RStreamerField::AppendImpl(const void *from)
898{
899 TBufferRecStreamer buffer(TBuffer::kWrite, GetValueSize(),
900 [this](TVirtualStreamerInfo *info) { fStreamerInfos[info->GetNumber()] = info; });
901 fClass->Streamer(const_cast<void *>(from), buffer);
902
903 auto nbytes = buffer.Length();
904 fAuxiliaryColumn->AppendV(buffer.Buffer(), buffer.Length());
905 fIndex += nbytes;
906 fPrincipalColumn->Append(&fIndex);
907 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
908}
909
911{
914 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nbytes);
915
917 fAuxiliaryColumn->ReadV(collectionStart, nbytes, buffer.Buffer());
918 fClass->Streamer(to, buffer);
919}
920
930
935
940
942{
943 fClass->New(where);
944}
945
947{
948 fClass->Destructor(objPtr, true /* dtorOnly */);
949 RDeleter::operator()(objPtr, dtorOnly);
950}
951
961
963{
964 return std::min(alignof(std::max_align_t), GetValueSize()); // TODO(jblomer): fix me
965}
966
968{
969 return fClass->GetClassSize();
970}
971
973{
974 return fClass->GetClassVersion();
975}
976
978{
979 return fClass->GetCheckSum();
980}
981
983{
984 visitor.VisitStreamerField(*this);
985}
986
987//------------------------------------------------------------------------------
988
990{
991 if (auto dataMember = TObject::Class()->GetDataMember(name)) {
992 return dataMember->GetOffset();
993 }
994 throw RException(R__FAIL('\'' + std::string(name) + '\'' + " is an invalid data member"));
995}
996
998 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
999{
1001 Attach(source.GetConstSubfields()[0]->Clone("fUniqueID"));
1002 Attach(source.GetConstSubfields()[1]->Clone("fBits"));
1003}
1004
1006 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
1007{
1008 assert(TObject::Class()->GetClassVersion() == 1);
1009
1011 Attach(std::make_unique<RField<UInt_t>>("fUniqueID"));
1012 Attach(std::make_unique<RField<UInt_t>>("fBits"));
1013}
1014
1015std::unique_ptr<ROOT::RFieldBase> ROOT::RField<TObject>::CloneImpl(std::string_view newName) const
1016{
1017 return std::unique_ptr<RField<TObject>>(new RField<TObject>(newName, *this));
1018}
1019
1020std::size_t ROOT::RField<TObject>::AppendImpl(const void *from)
1021{
1022 // Cf. TObject::Streamer()
1023
1024 auto *obj = static_cast<const TObject *>(from);
1025 if (obj->TestBit(TObject::kIsReferenced)) {
1026 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1027 }
1028
1029 std::size_t nbytes = 0;
1030 nbytes += CallAppendOn(*fSubfields[0], reinterpret_cast<const unsigned char *>(from) + GetOffsetUniqueID());
1031
1032 UInt_t bits = *reinterpret_cast<const UInt_t *>(reinterpret_cast<const unsigned char *>(from) + GetOffsetBits());
1033 bits &= (~TObject::kIsOnHeap & ~TObject::kNotDeleted);
1034 nbytes += CallAppendOn(*fSubfields[1], &bits);
1035
1036 return nbytes;
1037}
1038
1040{
1041 // Cf. TObject::Streamer()
1042
1043 auto *obj = static_cast<TObject *>(to);
1044 if (obj->TestBit(TObject::kIsReferenced)) {
1045 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
1046 }
1047
1048 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetUniqueID()) = uniqueID;
1049
1050 const UInt_t bitIsOnHeap = obj->TestBit(TObject::kIsOnHeap) ? TObject::kIsOnHeap : 0;
1052 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetBits()) = bits;
1053}
1054
1056{
1057 UInt_t uniqueID, bits;
1058 CallReadOn(*fSubfields[0], globalIndex, &uniqueID);
1059 CallReadOn(*fSubfields[1], globalIndex, &bits);
1060 ReadTObject(to, uniqueID, bits);
1061}
1062
1064{
1065 UInt_t uniqueID, bits;
1066 CallReadOn(*fSubfields[0], localIndex, &uniqueID);
1067 CallReadOn(*fSubfields[1], localIndex, &bits);
1068 ReadTObject(to, uniqueID, bits);
1069}
1070
1072{
1073 if (GetOnDiskTypeVersion() != 1) {
1074 throw RException(R__FAIL("unsupported on-disk version of TObject: " + std::to_string(GetTypeVersion())));
1075 }
1076}
1077
1079{
1080 return TObject::Class()->GetClassVersion();
1081}
1082
1084{
1085 return TObject::Class()->GetCheckSum();
1086}
1087
1089{
1090 new (where) TObject();
1091}
1092
1093std::vector<ROOT::RFieldBase::RValue> ROOT::RField<TObject>::SplitValue(const RValue &value) const
1094{
1095 std::vector<RValue> result;
1096 auto basePtr = value.GetPtr<unsigned char>().get();
1097 result.emplace_back(
1098 fSubfields[0]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), basePtr + GetOffsetUniqueID())));
1099 result.emplace_back(
1100 fSubfields[1]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), basePtr + GetOffsetBits())));
1101 return result;
1102}
1103
1105{
1106 return sizeof(TObject);
1107}
1108
1110{
1111 return alignof(TObject);
1112}
1113
1115{
1116 visitor.VisitTObjectField(*this);
1117}
1118
1119//------------------------------------------------------------------------------
1120
1121std::string ROOT::RTupleField::RTupleField::GetTypeList(const std::vector<std::unique_ptr<RFieldBase>> &itemFields)
1122{
1123 std::string result;
1124 if (itemFields.empty())
1125 throw RException(R__FAIL("the type list for std::tuple must have at least one element"));
1126 for (size_t i = 0; i < itemFields.size(); ++i) {
1127 result += itemFields[i]->GetTypeName() + ",";
1128 }
1129 result.pop_back(); // remove trailing comma
1130 return result;
1131}
1132
1133ROOT::RTupleField::RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields,
1134 const std::vector<std::size_t> &offsets)
1135 : ROOT::RRecordField(fieldName, "std::tuple<" + GetTypeList(itemFields) + ">")
1136{
1137 AttachItemFields(std::move(itemFields));
1138 fOffsets = offsets;
1139}
1140
1141ROOT::RTupleField::RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1142 : ROOT::RRecordField(fieldName, "std::tuple<" + GetTypeList(itemFields) + ">")
1143{
1144 AttachItemFields(std::move(itemFields));
1145
1146 auto *c = TClass::GetClass(GetTypeName().c_str());
1147 if (!c)
1148 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
1149 fSize = c->Size();
1150
1151 // ISO C++ does not guarantee neither specific layout nor member names for `std::tuple`. However, most
1152 // implementations including libstdc++ (gcc), libc++ (llvm), and MSVC name members as `_0`, `_1`, ..., `_N-1`,
1153 // following the order of the type list.
1154 // Use TClass to get their offsets; in case a particular `std::tuple` implementation does not define such
1155 // members, the assertion below will fail.
1156 for (unsigned i = 0; i < fSubfields.size(); ++i) {
1157 std::string memberName("_" + std::to_string(i));
1158 auto member = c->GetRealData(memberName.c_str());
1159 if (!member)
1160 throw RException(R__FAIL(memberName + ": no such member"));
1161 fOffsets.push_back(member->GetThisOffset());
1162 }
1163}
1164
1165//------------------------------------------------------------------------------
1166
1167namespace {
1168
1169// Depending on the compiler, the variant tag is stored either in a trailing char or in a trailing unsigned int
1170constexpr std::size_t GetVariantTagSize()
1171{
1172 // Should be all zeros except for the tag, which is 1
1173 std::variant<char> t;
1174 constexpr auto sizeOfT = sizeof(t);
1175
1176 static_assert(sizeOfT == 2 || sizeOfT == 8, "unsupported std::variant layout");
1177 return sizeOfT == 2 ? 1 : 4;
1178}
1179
1180template <std::size_t VariantSizeT>
1181struct RVariantTag {
1182 using ValueType_t = typename std::conditional_t<VariantSizeT == 1, std::uint8_t,
1183 typename std::conditional_t<VariantSizeT == 4, std::uint32_t, void>>;
1184};
1185
1186} // anonymous namespace
1187
1188std::string ROOT::RVariantField::GetTypeList(const std::vector<std::unique_ptr<RFieldBase>> &itemFields)
1189{
1190 std::string result;
1191 for (size_t i = 0; i < itemFields.size(); ++i) {
1192 result += itemFields[i]->GetTypeName() + ",";
1193 }
1194 R__ASSERT(!result.empty()); // there is always at least one variant
1195 result.pop_back(); // remove trailing comma
1196 return result;
1197}
1198
1200 : ROOT::RFieldBase(name, source.GetTypeName(), ROOT::ENTupleStructure::kVariant, false /* isSimple */),
1201 fMaxItemSize(source.fMaxItemSize),
1202 fMaxAlignment(source.fMaxAlignment),
1203 fTagOffset(source.fTagOffset),
1204 fVariantOffset(source.fVariantOffset),
1205 fNWritten(source.fNWritten.size(), 0)
1206{
1207 for (const auto &f : source.GetConstSubfields())
1208 Attach(f->Clone(f->GetFieldName()));
1209 fTraits = source.fTraits;
1210}
1211
1212ROOT::RVariantField::RVariantField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1213 : ROOT::RFieldBase(fieldName, "std::variant<" + GetTypeList(itemFields) + ">", ROOT::ENTupleStructure::kVariant,
1214 false /* isSimple */)
1215{
1216 // The variant needs to initialize its own tag member
1218
1219 auto nFields = itemFields.size();
1220 if (nFields == 0 || nFields > kMaxVariants) {
1221 throw RException(R__FAIL("invalid number of variant fields (outside [1.." + std::to_string(kMaxVariants) + ")"));
1222 }
1223 fNWritten.resize(nFields, 0);
1224 for (unsigned int i = 0; i < nFields; ++i) {
1227 fTraits &= itemFields[i]->GetTraits();
1228 Attach(std::move(itemFields[i]));
1229 }
1230
1231 // With certain template parameters, the union of members of an std::variant starts at an offset > 0.
1232 // For instance, std::variant<std::optional<int>> on macOS.
1233 auto cl = TClass::GetClass(GetTypeName().c_str());
1234 assert(cl);
1235 auto dm = reinterpret_cast<TDataMember *>(cl->GetListOfDataMembers()->First());
1236 if (dm)
1237 fVariantOffset = dm->GetOffset();
1238
1239 const auto tagSize = GetVariantTagSize();
1240 const auto padding = tagSize - (fMaxItemSize % tagSize);
1242}
1243
1244std::unique_ptr<ROOT::RFieldBase> ROOT::RVariantField::CloneImpl(std::string_view newName) const
1245{
1246 return std::unique_ptr<RVariantField>(new RVariantField(newName, *this));
1247}
1248
1249std::uint8_t ROOT::RVariantField::GetTag(const void *variantPtr, std::size_t tagOffset)
1250{
1251 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1252 auto tag = *reinterpret_cast<const TagType_t *>(reinterpret_cast<const unsigned char *>(variantPtr) + tagOffset);
1253 return (tag == TagType_t(-1)) ? 0 : tag + 1;
1254}
1255
1256void ROOT::RVariantField::SetTag(void *variantPtr, std::size_t tagOffset, std::uint8_t tag)
1257{
1258 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1259 auto tagPtr = reinterpret_cast<TagType_t *>(reinterpret_cast<unsigned char *>(variantPtr) + tagOffset);
1260 *tagPtr = (tag == 0) ? TagType_t(-1) : static_cast<TagType_t>(tag - 1);
1261}
1262
1263std::size_t ROOT::RVariantField::AppendImpl(const void *from)
1264{
1265 auto tag = GetTag(from, fTagOffset);
1266 std::size_t nbytes = 0;
1267 auto index = 0;
1268 if (tag > 0) {
1269 nbytes += CallAppendOn(*fSubfields[tag - 1], reinterpret_cast<const unsigned char *>(from) + fVariantOffset);
1270 index = fNWritten[tag - 1]++;
1271 }
1273 fPrincipalColumn->Append(&varSwitch);
1274 return nbytes + sizeof(ROOT::Internal::RColumnSwitch);
1275}
1276
1278{
1280 std::uint32_t tag;
1281 fPrincipalColumn->GetSwitchInfo(globalIndex, &variantIndex, &tag);
1282 R__ASSERT(tag < 256);
1283
1284 // If `tag` equals 0, the variant is in the invalid state, i.e, it does not hold any of the valid alternatives in
1285 // the type list. This happens, e.g., if the field was late added; in this case, keep the invalid tag, which makes
1286 // any `std::holds_alternative<T>` check fail later.
1287 if (R__likely(tag > 0)) {
1288 void *varPtr = reinterpret_cast<unsigned char *>(to) + fVariantOffset;
1289 CallConstructValueOn(*fSubfields[tag - 1], varPtr);
1290 CallReadOn(*fSubfields[tag - 1], variantIndex, varPtr);
1291 }
1292 SetTag(to, fTagOffset, tag);
1293}
1294
1300
1305
1310
1312{
1313 memset(where, 0, GetValueSize());
1314 CallConstructValueOn(*fSubfields[0], reinterpret_cast<unsigned char *>(where) + fVariantOffset);
1315 SetTag(where, fTagOffset, 1);
1316}
1317
1319{
1320 auto tag = GetTag(objPtr, fTagOffset);
1321 if (tag > 0) {
1322 fItemDeleters[tag - 1]->operator()(reinterpret_cast<unsigned char *>(objPtr) + fVariantOffset, true /*dtorOnly*/);
1323 }
1324 RDeleter::operator()(objPtr, dtorOnly);
1325}
1326
1327std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RVariantField::GetDeleter() const
1328{
1329 std::vector<std::unique_ptr<RDeleter>> itemDeleters;
1330 itemDeleters.reserve(fSubfields.size());
1331 for (const auto &f : fSubfields) {
1332 itemDeleters.emplace_back(GetDeleterOf(*f));
1333 }
1334 return std::make_unique<RVariantDeleter>(fTagOffset, fVariantOffset, std::move(itemDeleters));
1335}
1336
1338{
1339 return std::max(fMaxAlignment, alignof(RVariantTag<GetVariantTagSize()>::ValueType_t));
1340}
1341
1343{
1344 const auto alignment = GetAlignment();
1345 const auto actualSize = fTagOffset + GetVariantTagSize();
1346 const auto padding = alignment - (actualSize % alignment);
1347 return actualSize + ((padding == alignment) ? 0 : padding);
1348}
1349
1351{
1352 std::fill(fNWritten.begin(), fNWritten.end(), 0);
1353}
Cppyy::TCppType_t fClass
#define R__likely(expr)
Definition RConfig.hxx:600
#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:299
#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
@ 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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
TCanvas * alignment()
Definition alignment.C:1
#define _(A, B)
Definition cfortran.h:108
Abstract base class for classes implementing the visitor design pattern.
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:111
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.
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
Definition RField.hxx:197
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
void Attach(std::unique_ptr< RFieldBase > child, RSubFieldInfo info)
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:140
std::uint32_t GetTypeVersion() const final
Indicates an evolution of the C++ type itself.
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
void PrepareStagingArea(const std::vector< const TSchemaRule * > &rules, const ROOT::RNTupleDescriptor &desc, const ROOT::RFieldDescriptor &classFieldId)
If there are rules with inputs (source members), create the staging area according to the TClass inst...
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
~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:129
void SetStagingClass(const std::string &className, unsigned int classVersion)
Sets fStagingClass according to the given name and version.
void BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate.
The field for an unscoped or scoped enum with dictionary.
Definition RField.hxx:260
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)
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)
Add a new subfield to the list of nested fields.
std::vector< std::unique_ptr< RFieldBase > > fSubfields
Collections and classes own subfields.
virtual void AfterConnectPageSource()
Called by ConnectPageSource() once connected; derived classes may override this as appropriate.
friend class ROOT::RClassField
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
@ 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.
@ kTraitTypeChecksum
The TClass checksum is set and valid.
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.
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:288
RField(std::string_view name)
Definition RField.hxx:291
RMapField(std::string_view fieldName, std::string_view typeName, std::unique_ptr< RFieldBase > itemField)
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.
RPairField(std::string_view fieldName, std::array< std::unique_ptr< RFieldBase >, 2 > itemFields, const std::array< std::size_t, 2 > &offsets)
Allows for iterating over the elements of a proxied collection.
static RIteratorFuncs GetIteratorFuncs(TVirtualCollectionProxy *proxy, bool readFromDisk)
void operator()(void *objPtr, bool dtorOnly) final
The field for a class representing a collection of elements via TVirtualCollectionProxy.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
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
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
const_iterator begin() const
const_iterator end() const
The field for an untyped record.
void AttachItemFields(std::vector< std::unique_ptr< RFieldBase > > itemFields)
Definition RField.cxx:498
std::vector< std::size_t > fOffsets
RSetField(std::string_view fieldName, std::string_view typeName, std::unique_ptr< RFieldBase > itemField)
void operator()(void *objPtr, bool dtorOnly) final
The field for a class using ROOT standard streaming.
Definition RField.hxx:206
ROOT::RExtraTypeInfoDescriptor GetExtraTypeInfo() const final
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
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...
void BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate.
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 > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
RStreamerField(std::string_view fieldName, TClass *classp)
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
RTupleField(std::string_view fieldName, std::vector< std::unique_ptr< RFieldBase > > itemFields, const std::vector< std::size_t > &offsets)
void operator()(void *objPtr, bool dtorOnly) final
Template specializations for C++ std::variant.
static std::string GetTypeList(const std::vector< std::unique_ptr< RFieldBase > > &itemFields)
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
static constexpr std::size_t kMaxVariants
std::vector< ROOT::Internal::RColumnIndex::ValueType > fNWritten
static std::uint8_t GetTag(const void *variantPtr, std::size_t tagOffset)
Extracts the index from an std::variant and transforms it into the 1-based index used for the switch ...
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
size_t fVariantOffset
In the std::variant memory layout, the actual union of types may start at an offset > 0.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
std::unique_ptr< RDeleter > GetDeleter() const final
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:2425
EState GetState() const
Definition TClass.h:495
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3898
Int_t Size() const
Return size of object of this class.
Definition TClass.cxx:5844
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3764
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:3003
Long_t ClassProperty() const
Return the C++ property of this class, eg.
Definition TClass.cxx:2502
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6229
@ kInterpreted
Definition TClass.h:129
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:3074
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:182
Mother of all ROOT objects.
Definition TObject.h:41
@ kIsOnHeap
object is on heap
Definition TObject.h:87
@ kNotDeleted
object has not been deleted
Definition TObject.h:88
static TClass * Class()
@ kIsReferenced
if object is referenced by a TRef or TRefArray
Definition TObject.h:71
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
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
void CallConnectPageSourceOnField(RFieldBase &, ROOT::Internal::RPageSource &)
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 ...
ERNTupleSerializationMode GetRNTupleSerializationMode(TClass *cl)
std::string GetNormalizedUnresolvedTypeName(const std::string &origName)
Applies all RNTuple type normalization rules except typedef resolution.
std::string GetRenormalizedTypeName(const std::string &metaNormalizedName)
Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
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 ntuple model tree can carry different structural information about the type system.
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.