Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 int i = 0;
131 const auto *bases = fClass->GetListOfBases();
132 assert(bases);
134 if (baseClass->GetDelta() < 0) {
135 throw RException(R__FAIL(std::string("virtual inheritance is not supported: ") + GetTypeName() +
136 " virtually inherits from " + baseClass->GetName()));
137 }
138 TClass *c = baseClass->GetClassPointer();
139 auto subField =
140 RFieldBase::Create(std::string(kPrefixInherited) + "_" + std::to_string(i), c->GetName()).Unwrap();
141 fTraits &= subField->GetTraits();
142 Attach(std::move(subField), RSubFieldInfo{kBaseClass, static_cast<std::size_t>(baseClass->GetDelta())});
143 i++;
144 }
146 // Skip, for instance, unscoped enum constants defined in the class
147 if (dataMember->Property() & kIsStatic)
148 continue;
149 // Skip members explicitly marked as transient by user comment
150 if (!dataMember->IsPersistent()) {
151 // TODO(jblomer): we could do better
153 continue;
154 }
155
156 // NOTE: we use the already-resolved type name for the fields, otherwise TClass::GetClass may fail to resolve
157 // context-dependent types (e.g. typedefs defined in the class itself - which will not be fully qualified in
158 // the string returned by dataMember->GetFullTypeName())
159 std::string typeName{dataMember->GetTrueTypeName()};
160 // RFieldBase::Create() set subField->fTypeAlias based on the assumption that the user specified typeName, which
161 // already went through one round of type resolution.
162 std::string origTypeName{dataMember->GetFullTypeName()};
163
164 // For C-style arrays, complete the type name with the size for each dimension, e.g. `int[4][2]`
165 if (dataMember->Property() & kIsArray) {
166 for (int dim = 0, n = dataMember->GetArrayDim(); dim < n; ++dim) {
167 const auto addedStr = "[" + std::to_string(dataMember->GetMaxIndex(dim)) + "]";
168 typeName += addedStr;
170 }
171 }
172
173 auto subField = RFieldBase::Create(dataMember->GetName(), typeName).Unwrap();
174
176 if (normTypeName == subField->GetTypeName()) {
177 subField->fTypeAlias = "";
178 } else {
179 subField->fTypeAlias = normTypeName;
180 }
181
182 fTraits &= subField->GetTraits();
183 Attach(std::move(subField), RSubFieldInfo{kDataMember, static_cast<std::size_t>(dataMember->GetOffset())});
184 }
186}
187
188void ROOT::RClassField::Attach(std::unique_ptr<RFieldBase> child, RSubFieldInfo info)
189{
190 fMaxAlignment = std::max(fMaxAlignment, child->GetAlignment());
191 fSubfieldsInfo.push_back(info);
192 RFieldBase::Attach(std::move(child));
193}
194
195std::vector<const ROOT::TSchemaRule *> ROOT::RClassField::FindRules(const ROOT::RFieldDescriptor *fieldDesc)
196{
198 const auto ruleset = fClass->GetSchemaRules();
199 if (!ruleset)
200 return rules;
201
202 if (!fieldDesc) {
203 // If we have no on-disk information for the field, we still process the rules on the current in-memory version
204 // of the class
205 rules = ruleset->FindRules(fClass->GetName(), fClass->GetClassVersion(), fClass->GetCheckSum());
206 } else {
207 // We need to change (back) the name normalization from RNTuple to ROOT Meta
208 std::string normalizedName;
210 // We do have an on-disk field that correspond to the current RClassField instance. Ask for rules matching the
211 // on-disk version of the field.
212 if (fieldDesc->GetTypeChecksum()) {
213 rules = ruleset->FindRules(normalizedName, fieldDesc->GetTypeVersion(), *fieldDesc->GetTypeChecksum());
214 } else {
215 rules = ruleset->FindRules(normalizedName, fieldDesc->GetTypeVersion());
216 }
217 }
218
219 // Cleanup and sort rules
220 // Check that any any given source member uses the same type in all rules
221 std::unordered_map<std::string, std::string> sourceNameAndType;
222 std::size_t nskip = 0; // skip whole-object-rules that were moved to the end of the rules vector
223 for (auto itr = rules.begin(); itr != rules.end() - nskip;) {
224 const auto rule = *itr;
225
226 // Erase unknown rule types
227 if (rule->GetRuleType() != ROOT::TSchemaRule::kReadRule) {
229 << "ignoring I/O customization rule with unsupported type: " << rule->GetRuleType();
230 itr = rules.erase(itr);
231 continue;
232 }
233
234 bool hasConflictingSourceMembers = false;
235 for (auto source : TRangeDynCast<TSchemaRule::TSources>(rule->GetSource())) {
236 auto memberType = source->GetTypeForDeclaration() + source->GetDimensions();
237 auto [itrSrc, isNew] = sourceNameAndType.emplace(source->GetName(), memberType);
238 if (!isNew && (itrSrc->second != memberType)) {
240 << "ignoring I/O customization rule due to conflicting source member type: " << itrSrc->second << " vs. "
241 << memberType << " for member " << source->GetName();
243 break;
244 }
245 }
247 itr = rules.erase(itr);
248 continue;
249 }
250
251 // Rules targeting the entire object need to be executed at the end
252 if (rule->GetTarget() == nullptr) {
253 nskip++;
254 if (itr != rules.end() - nskip)
255 std::iter_swap(itr++, rules.end() - nskip);
256 continue;
257 }
258
259 ++itr;
260 }
261
262 return rules;
263}
264
265std::unique_ptr<ROOT::RFieldBase> ROOT::RClassField::CloneImpl(std::string_view newName) const
266{
267 return std::unique_ptr<RClassField>(new RClassField(newName, *this));
268}
269
270std::size_t ROOT::RClassField::AppendImpl(const void *from)
271{
272 std::size_t nbytes = 0;
273 for (unsigned i = 0; i < fSubfields.size(); i++) {
274 nbytes += CallAppendOn(*fSubfields[i], static_cast<const unsigned char *>(from) + fSubfieldsInfo[i].fOffset);
275 }
276 return nbytes;
277}
278
280{
281 for (const auto &[_, si] : fStagingItems) {
282 CallReadOn(*si.fField, globalIndex, fStagingArea.get() + si.fOffset);
283 }
284 for (unsigned i = 0; i < fSubfields.size(); i++) {
285 CallReadOn(*fSubfields[i], globalIndex, static_cast<unsigned char *>(to) + fSubfieldsInfo[i].fOffset);
286 }
287}
288
290{
291 for (const auto &[_, si] : fStagingItems) {
292 CallReadOn(*si.fField, localIndex, fStagingArea.get() + si.fOffset);
293 }
294 for (unsigned i = 0; i < fSubfields.size(); i++) {
295 CallReadOn(*fSubfields[i], localIndex, static_cast<unsigned char *>(to) + fSubfieldsInfo[i].fOffset);
296 }
297}
298
301{
304 return idSourceMember;
305
306 for (const auto &subFieldDesc : desc.GetFieldIterable(classFieldId)) {
307 const auto subFieldName = subFieldDesc.GetFieldName();
308 if (subFieldName.length() > 2 && subFieldName[0] == ':' && subFieldName[1] == '_') {
309 idSourceMember = LookupMember(desc, memberName, subFieldDesc.GetId());
311 return idSourceMember;
312 }
313 }
314
316}
317
318void ROOT::RClassField::SetStagingClass(const std::string &className, unsigned int classVersion)
319{
320 TClass::GetClass(className.c_str())->GetStreamerInfo(classVersion);
321 if (classVersion != GetTypeVersion()) {
322 fStagingClass = TClass::GetClass((className + std::string("@@") + std::to_string(classVersion)).c_str());
323 if (!fStagingClass) {
324 // For a rename rule, we may simply ask for the old class name
325 fStagingClass = TClass::GetClass(className.c_str());
326 }
327 } else {
328 fStagingClass = fClass;
329 }
330 R__ASSERT(fStagingClass);
331 R__ASSERT(static_cast<unsigned int>(fStagingClass->GetClassVersion()) == classVersion);
332}
333
334void ROOT::RClassField::PrepareStagingArea(const std::vector<const TSchemaRule *> &rules,
335 const ROOT::RNTupleDescriptor &desc,
337{
338 std::size_t stagingAreaSize = 0;
339 for (const auto rule : rules) {
340 for (auto source : TRangeDynCast<TSchemaRule::TSources>(rule->GetSource())) {
341 auto [itr, isNew] = fStagingItems.emplace(source->GetName(), RStagingItem());
342 if (!isNew) {
343 // This source member has already been processed by another rule (and we only support one type per member)
344 continue;
345 }
346 RStagingItem &stagingItem = itr->second;
347
348 const auto memberFieldId = LookupMember(desc, source->GetName(), classFieldDesc.GetId());
350 throw RException(R__FAIL(std::string("cannot find on disk rule source member ") + GetTypeName() + "." +
351 source->GetName()));
352 }
354
355 auto memberType = source->GetTypeForDeclaration() + source->GetDimensions();
356 stagingItem.fField = Create("" /* we don't need a field name */, std::string(memberType)).Unwrap();
357 stagingItem.fField->SetOnDiskId(memberFieldDesc.GetId());
358
359 stagingItem.fOffset = fStagingClass->GetDataMemberOffset(source->GetName());
360 // Since we successfully looked up the source member in the RNTuple on-disk metadata, we expect it
361 // to be present in the TClass instance, too.
363 stagingAreaSize = std::max(stagingAreaSize, stagingItem.fOffset + stagingItem.fField->GetValueSize());
364 }
365 }
366
367 if (stagingAreaSize) {
368 R__ASSERT(static_cast<Int_t>(stagingAreaSize) <= fStagingClass->Size()); // we may have removed rules
369 fStagingArea = ROOT::Internal::MakeUninitArray<unsigned char>(stagingAreaSize);
370 }
371}
372
374{
375 auto func = rule->GetReadFunctionPointer();
376 if (func == nullptr) {
377 // Can happen for rename rules
378 return;
379 }
380 fReadCallbacks.emplace_back([func, stagingClass = fStagingClass, stagingArea = fStagingArea.get()](void *target) {
381 TVirtualObject onfileObj{nullptr};
382 onfileObj.fClass = stagingClass;
383 onfileObj.fObject = stagingArea;
384 func(static_cast<char *>(target), &onfileObj);
385 onfileObj.fObject = nullptr; // TVirtualObject does not own the value
386 });
387}
388
390{
391 std::vector<const TSchemaRule *> rules;
392 // On-disk members that are not targeted by an I/O rule; all other sub fields of the in-memory class
393 // will be marked as artificial (added member in a new class version or member set by rule).
394 std::unordered_set<std::string> regularSubfields;
395
396 if (GetOnDiskId() == kInvalidDescriptorId) {
397 // This can happen for added base classes or added members of class type
398 rules = FindRules(nullptr);
399 if (!rules.empty())
400 SetStagingClass(GetTypeName(), GetTypeVersion());
401 } else {
402 const auto descriptorGuard = pageSource.GetSharedDescriptorGuard();
403 const ROOT::RNTupleDescriptor &desc = descriptorGuard.GetRef();
404 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
405
406 for (auto linkId : fieldDesc.GetLinkIds()) {
407 const auto &subFieldDesc = desc.GetFieldDescriptor(linkId);
408 regularSubfields.insert(subFieldDesc.GetFieldName());
409 }
410
411 rules = FindRules(&fieldDesc);
412
413 // If the field's type name is not the on-disk name but we found a rule, we know it is valid to read
414 // on-disk data because we found the rule according to the on-disk (source) type name and version/checksum.
415 if ((GetTypeName() != fieldDesc.GetTypeName()) && rules.empty()) {
416 throw RException(R__FAIL("incompatible type name for field " + GetFieldName() + ": " + GetTypeName() +
417 " vs. " + fieldDesc.GetTypeName()));
418 }
419
420 if (!rules.empty()) {
421 SetStagingClass(fieldDesc.GetTypeName(), fieldDesc.GetTypeVersion());
422 PrepareStagingArea(rules, desc, fieldDesc);
423 for (auto &[_, si] : fStagingItems)
425
426 // Remove target member of read rules from the list of regular members of the underlying on-disk field
427 for (const auto rule : rules) {
428 if (!rule->GetTarget())
429 continue;
430
431 for (const auto target : ROOT::Detail::TRangeStaticCast<const TObjString>(*rule->GetTarget())) {
432 regularSubfields.erase(std::string(target->GetString()));
433 }
434 }
435 }
436 }
437
438 for (const auto rule : rules) {
439 AddReadCallbacksFromIORule(rule);
440 }
441
442 // Iterate over all sub fields in memory and mark those as missing that are not in the descriptor.
443 for (auto &field : fSubfields) {
444 if (regularSubfields.count(field->GetFieldName()) == 0) {
445 field->SetArtificial();
446 }
447 }
448}
449
451{
452 fClass->New(where);
453}
454
456{
457 fClass->Destructor(objPtr, true /* dtorOnly */);
458 RDeleter::operator()(objPtr, dtorOnly);
459}
460
461std::vector<ROOT::RFieldBase::RValue> ROOT::RClassField::SplitValue(const RValue &value) const
462{
463 std::vector<RValue> result;
464 auto basePtr = value.GetPtr<unsigned char>().get();
465 result.reserve(fSubfields.size());
466 for (unsigned i = 0; i < fSubfields.size(); i++) {
467 result.emplace_back(
468 fSubfields[i]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), basePtr + fSubfieldsInfo[i].fOffset)));
469 }
470 return result;
471}
472
474{
475 return fClass->GetClassSize();
476}
477
479{
480 return fClass->GetClassVersion();
481}
482
484{
485 return fClass->GetCheckSum();
486}
487
489{
490 visitor.VisitClassField(*this);
491}
492
493//------------------------------------------------------------------------------
494
495ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName)
497{
498}
499
501 : ROOT::RFieldBase(fieldName, GetRenormalizedTypeName(enump->GetQualifiedName()), ROOT::ENTupleStructure::kLeaf,
502 false /* isSimple */)
503{
504 // Avoid accidentally supporting std types through TEnum.
505 if (enump->Property() & kIsDefinedInStd) {
506 throw RException(R__FAIL(GetTypeName() + " is not supported"));
507 }
508
509 switch (enump->GetUnderlyingType()) {
510 case kChar_t: Attach(std::make_unique<RField<int8_t>>("_0")); break;
511 case kUChar_t: Attach(std::make_unique<RField<uint8_t>>("_0")); break;
512 case kShort_t: Attach(std::make_unique<RField<int16_t>>("_0")); break;
513 case kUShort_t: Attach(std::make_unique<RField<uint16_t>>("_0")); break;
514 case kInt_t: Attach(std::make_unique<RField<int32_t>>("_0")); break;
515 case kUInt_t: Attach(std::make_unique<RField<uint32_t>>("_0")); break;
516 case kLong_t:
517 case kLong64_t: Attach(std::make_unique<RField<int64_t>>("_0")); break;
518 case kULong_t:
519 case kULong64_t: Attach(std::make_unique<RField<uint64_t>>("_0")); break;
520 default: throw RException(R__FAIL("Unsupported underlying integral type for enum type " + GetTypeName()));
521 }
522
524}
525
526ROOT::REnumField::REnumField(std::string_view fieldName, std::string_view enumName,
527 std::unique_ptr<RFieldBase> intField)
529{
530 Attach(std::move(intField));
532}
533
534std::unique_ptr<ROOT::RFieldBase> ROOT::REnumField::CloneImpl(std::string_view newName) const
535{
536 auto newIntField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
537 return std::unique_ptr<REnumField>(new REnumField(newName, GetTypeName(), std::move(newIntField)));
538}
539
540std::vector<ROOT::RFieldBase::RValue> ROOT::REnumField::SplitValue(const RValue &value) const
541{
542 std::vector<RValue> result;
543 result.emplace_back(fSubfields[0]->BindValue(value.GetPtr<void>()));
544 return result;
545}
546
548{
549 visitor.VisitEnumField(*this);
550}
551
552//------------------------------------------------------------------------------
553
554std::string ROOT::RPairField::RPairField::GetTypeList(const std::array<std::unique_ptr<RFieldBase>, 2> &itemFields)
555{
556 return itemFields[0]->GetTypeName() + "," + itemFields[1]->GetTypeName();
557}
558
559ROOT::RPairField::RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields,
560 const std::array<std::size_t, 2> &offsets)
561 : ROOT::RRecordField(fieldName, "std::pair<" + GetTypeList(itemFields) + ">")
562{
563 AttachItemFields(std::move(itemFields));
564 fOffsets.push_back(offsets[0]);
565 fOffsets.push_back(offsets[1]);
566}
567
568ROOT::RPairField::RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields)
569 : ROOT::RRecordField(fieldName, "std::pair<" + GetTypeList(itemFields) + ">")
570{
571 AttachItemFields(std::move(itemFields));
572
573 // ISO C++ does not guarantee any specific layout for `std::pair`; query TClass for the member offsets
574 auto *c = TClass::GetClass(GetTypeName().c_str());
575 if (!c)
576 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
577 fSize = c->Size();
578
579 auto firstElem = c->GetRealData("first");
580 if (!firstElem)
581 throw RException(R__FAIL("first: no such member"));
582 fOffsets.push_back(firstElem->GetThisOffset());
583
584 auto secondElem = c->GetRealData("second");
585 if (!secondElem)
586 throw RException(R__FAIL("second: no such member"));
587 fOffsets.push_back(secondElem->GetThisOffset());
588}
589
590//------------------------------------------------------------------------------
591
594 bool readFromDisk)
595{
597 ifuncs.fCreateIterators = proxy->GetFunctionCreateIterators(readFromDisk);
598 ifuncs.fDeleteTwoIterators = proxy->GetFunctionDeleteTwoIterators(readFromDisk);
599 ifuncs.fNext = proxy->GetFunctionNext(readFromDisk);
600 R__ASSERT((ifuncs.fCreateIterators != nullptr) && (ifuncs.fDeleteTwoIterators != nullptr) &&
601 (ifuncs.fNext != nullptr));
602 return ifuncs;
603}
604
606 : RFieldBase(fieldName, GetRenormalizedTypeName(classp->GetName()), ROOT::ENTupleStructure::kCollection,
607 false /* isSimple */),
608 fNWritten(0)
609{
610 if (!classp->GetCollectionProxy())
611 throw RException(R__FAIL(std::string(GetTypeName()) + " has no associated collection proxy"));
612
613 fProxy.reset(classp->GetCollectionProxy()->Generate());
614 fProperties = fProxy->GetProperties();
615 fCollectionType = fProxy->GetCollectionType();
616 if (fProxy->HasPointers())
617 throw RException(R__FAIL("collection proxies whose value type is a pointer are not supported"));
618 if (!fProxy->GetCollectionClass()->HasDictionary()) {
619 throw RException(R__FAIL("dictionary not available for type " +
620 GetRenormalizedTypeName(fProxy->GetCollectionClass()->GetName())));
621 }
622
623 fIFuncsRead = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), true /* readFromDisk */);
624 fIFuncsWrite = RCollectionIterableOnce::GetIteratorFuncs(fProxy.get(), false /* readFromDisk */);
625}
626
627ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldName, std::string_view typeName,
628 std::unique_ptr<RFieldBase> itemField)
630{
631 fItemSize = itemField->GetValueSize();
632 Attach(std::move(itemField));
633}
634
635ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldName, std::string_view typeName)
637{
638 // NOTE (fdegeus): std::map is supported, custom associative might be supported in the future if the need arises.
640 throw RException(R__FAIL("custom associative collection proxies not supported"));
641
642 std::unique_ptr<ROOT::RFieldBase> itemField;
643
644 if (auto valueClass = fProxy->GetValueClass()) {
645 // Element type is a class
646 itemField = RFieldBase::Create("_0", valueClass->GetName()).Unwrap();
647 } else {
648 switch (fProxy->GetType()) {
649 case EDataType::kChar_t: itemField = std::make_unique<RField<char>>("_0"); break;
650 case EDataType::kUChar_t: itemField = std::make_unique<RField<std::uint8_t>>("_0"); break;
651 case EDataType::kShort_t: itemField = std::make_unique<RField<std::int16_t>>("_0"); break;
652 case EDataType::kUShort_t: itemField = std::make_unique<RField<std::uint16_t>>("_0"); break;
653 case EDataType::kInt_t: itemField = std::make_unique<RField<std::int32_t>>("_0"); break;
654 case EDataType::kUInt_t: itemField = std::make_unique<RField<std::uint32_t>>("_0"); break;
656 case EDataType::kLong64_t: itemField = std::make_unique<RField<std::int64_t>>("_0"); break;
658 case EDataType::kULong64_t: itemField = std::make_unique<RField<std::uint64_t>>("_0"); break;
659 case EDataType::kFloat_t: itemField = std::make_unique<RField<float>>("_0"); break;
660 case EDataType::kDouble_t: itemField = std::make_unique<RField<double>>("_0"); break;
661 case EDataType::kBool_t: itemField = std::make_unique<RField<bool>>("_0"); break;
662 default: throw RException(R__FAIL("unsupported value type"));
663 }
664 }
665
666 fItemSize = itemField->GetValueSize();
667 Attach(std::move(itemField));
668}
669
670std::unique_ptr<ROOT::RFieldBase> ROOT::RProxiedCollectionField::CloneImpl(std::string_view newName) const
671{
672 auto newItemField = fSubfields[0]->Clone(fSubfields[0]->GetFieldName());
673 return std::unique_ptr<RProxiedCollectionField>(
674 new RProxiedCollectionField(newName, GetTypeName(), std::move(newItemField)));
675}
676
677std::size_t ROOT::RProxiedCollectionField::AppendImpl(const void *from)
678{
679 std::size_t nbytes = 0;
680 unsigned count = 0;
681 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), const_cast<void *>(from));
682 for (auto ptr : RCollectionIterableOnce{const_cast<void *>(from), fIFuncsWrite, fProxy.get(),
683 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
684 nbytes += CallAppendOn(*fSubfields[0], ptr);
685 count++;
686 }
687
688 fNWritten += count;
689 fPrincipalColumn->Append(&fNWritten);
690 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
691}
692
694{
697 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems);
698
699 TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), to);
700 void *obj =
701 fProxy->Allocate(static_cast<std::uint32_t>(nItems), (fProperties & TVirtualCollectionProxy::kNeedDelete));
702
703 unsigned i = 0;
704 for (auto elementPtr : RCollectionIterableOnce{obj, fIFuncsRead, fProxy.get(),
705 (fCollectionType == kSTLvector || obj != to ? fItemSize : 0U)}) {
706 CallReadOn(*fSubfields[0], collectionStart + (i++), elementPtr);
707 }
708 if (obj != to)
709 fProxy->Commit(obj);
710}
711
721
726
731
733{
734 fProxy->New(where);
735}
736
737std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RProxiedCollectionField::GetDeleter() const
738{
739 if (fProperties & TVirtualCollectionProxy::kNeedDelete) {
740 std::size_t itemSize = fCollectionType == kSTLvector ? fItemSize : 0U;
741 return std::make_unique<RProxiedCollectionDeleter>(fProxy, GetDeleterOf(*fSubfields[0]), itemSize);
742 }
743 return std::make_unique<RProxiedCollectionDeleter>(fProxy);
744}
745
747{
748 if (fItemDeleter) {
750 for (auto ptr : RCollectionIterableOnce{objPtr, fIFuncsWrite, fProxy.get(), fItemSize}) {
751 fItemDeleter->operator()(ptr, true /* dtorOnly */);
752 }
753 }
754 fProxy->Destructor(objPtr, true /* dtorOnly */);
755 RDeleter::operator()(objPtr, dtorOnly);
756}
757
758std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(const RValue &value) const
759{
760 std::vector<RValue> result;
761 auto valueRawPtr = value.GetPtr<void>().get();
763 for (auto ptr : RCollectionIterableOnce{valueRawPtr, fIFuncsWrite, fProxy.get(),
764 (fCollectionType == kSTLvector ? fItemSize : 0U)}) {
765 result.emplace_back(fSubfields[0]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), ptr)));
766 }
767 return result;
768}
769
771{
772 visitor.VisitProxiedCollectionField(*this);
773}
774
775//------------------------------------------------------------------------------
776
777ROOT::RMapField::RMapField(std::string_view fieldName, std::string_view typeName, std::unique_ptr<RFieldBase> itemField)
779{
780 if (!dynamic_cast<RPairField *>(itemField.get()))
781 throw RException(R__FAIL("RMapField inner field type must be of RPairField"));
782
783 auto *itemClass = fProxy->GetValueClass();
784 fItemSize = itemClass->GetClassSize();
785
786 Attach(std::move(itemField));
787}
788
789//------------------------------------------------------------------------------
790
791ROOT::RSetField::RSetField(std::string_view fieldName, std::string_view typeName, std::unique_ptr<RFieldBase> itemField)
793{
794}
795
796//------------------------------------------------------------------------------
797
798namespace {
799
800/// Used in RStreamerField::AppendImpl() in order to record the encountered streamer info records
801class TBufferRecStreamer : public TBufferFile {
802public:
803 using RCallbackStreamerInfo = std::function<void(TVirtualStreamerInfo *)>;
804
805private:
806 RCallbackStreamerInfo fCallbackStreamerInfo;
807
808public:
809 TBufferRecStreamer(TBuffer::EMode mode, Int_t bufsiz, RCallbackStreamerInfo callbackStreamerInfo)
810 : TBufferFile(mode, bufsiz), fCallbackStreamerInfo(callbackStreamerInfo)
811 {
812 }
813 void TagStreamerInfo(TVirtualStreamerInfo *info) final { fCallbackStreamerInfo(info); }
814};
815
816} // anonymous namespace
817
818ROOT::RStreamerField::RStreamerField(std::string_view fieldName, std::string_view className, std::string_view typeAlias)
820{
822}
823
836
837std::unique_ptr<ROOT::RFieldBase> ROOT::RStreamerField::CloneImpl(std::string_view newName) const
838{
839 return std::unique_ptr<RStreamerField>(new RStreamerField(newName, GetTypeName(), GetTypeAlias()));
840}
841
842std::size_t ROOT::RStreamerField::AppendImpl(const void *from)
843{
844 TBufferRecStreamer buffer(TBuffer::kWrite, GetValueSize(),
845 [this](TVirtualStreamerInfo *info) { fStreamerInfos[info->GetNumber()] = info; });
846 fClass->Streamer(const_cast<void *>(from), buffer);
847
848 auto nbytes = buffer.Length();
849 fAuxiliaryColumn->AppendV(buffer.Buffer(), buffer.Length());
850 fIndex += nbytes;
851 fPrincipalColumn->Append(&fIndex);
852 return nbytes + fPrincipalColumn->GetElement()->GetPackedSize();
853}
854
856{
859 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nbytes);
860
862 fAuxiliaryColumn->ReadV(collectionStart, nbytes, buffer.Buffer());
863 fClass->Streamer(to, buffer);
864}
865
875
880
885
887{
888 fClass->New(where);
889}
890
892{
893 fClass->Destructor(objPtr, true /* dtorOnly */);
894 RDeleter::operator()(objPtr, dtorOnly);
895}
896
906
908{
909 return std::min(alignof(std::max_align_t), GetValueSize()); // TODO(jblomer): fix me
910}
911
913{
914 return fClass->GetClassSize();
915}
916
918{
919 return fClass->GetClassVersion();
920}
921
923{
924 return fClass->GetCheckSum();
925}
926
928{
929 visitor.VisitStreamerField(*this);
930}
931
932//------------------------------------------------------------------------------
933
935{
936 if (auto dataMember = TObject::Class()->GetDataMember(name)) {
937 return dataMember->GetOffset();
938 }
939 throw RException(R__FAIL('\'' + std::string(name) + '\'' + " is an invalid data member"));
940}
941
943 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
944{
946 Attach(source.GetConstSubfields()[0]->Clone("fUniqueID"));
947 Attach(source.GetConstSubfields()[1]->Clone("fBits"));
948}
949
951 : ROOT::RFieldBase(fieldName, "TObject", ROOT::ENTupleStructure::kRecord, false /* isSimple */)
952{
953 assert(TObject::Class()->GetClassVersion() == 1);
954
956 Attach(std::make_unique<RField<UInt_t>>("fUniqueID"));
957 Attach(std::make_unique<RField<UInt_t>>("fBits"));
958}
959
960std::unique_ptr<ROOT::RFieldBase> ROOT::RField<TObject>::CloneImpl(std::string_view newName) const
961{
962 return std::unique_ptr<RField<TObject>>(new RField<TObject>(newName, *this));
963}
964
965std::size_t ROOT::RField<TObject>::AppendImpl(const void *from)
966{
967 // Cf. TObject::Streamer()
968
969 auto *obj = static_cast<const TObject *>(from);
970 if (obj->TestBit(TObject::kIsReferenced)) {
971 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
972 }
973
974 std::size_t nbytes = 0;
975 nbytes += CallAppendOn(*fSubfields[0], reinterpret_cast<const unsigned char *>(from) + GetOffsetUniqueID());
976
977 UInt_t bits = *reinterpret_cast<const UInt_t *>(reinterpret_cast<const unsigned char *>(from) + GetOffsetBits());
978 bits &= (~TObject::kIsOnHeap & ~TObject::kNotDeleted);
979 nbytes += CallAppendOn(*fSubfields[1], &bits);
980
981 return nbytes;
982}
983
985{
986 // Cf. TObject::Streamer()
987
988 auto *obj = static_cast<TObject *>(to);
989 if (obj->TestBit(TObject::kIsReferenced)) {
990 throw RException(R__FAIL("RNTuple I/O on referenced TObject is unsupported"));
991 }
992
993 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetUniqueID()) = uniqueID;
994
995 const UInt_t bitIsOnHeap = obj->TestBit(TObject::kIsOnHeap) ? TObject::kIsOnHeap : 0;
997 *reinterpret_cast<UInt_t *>(reinterpret_cast<unsigned char *>(to) + GetOffsetBits()) = bits;
998}
999
1001{
1002 UInt_t uniqueID, bits;
1003 CallReadOn(*fSubfields[0], globalIndex, &uniqueID);
1004 CallReadOn(*fSubfields[1], globalIndex, &bits);
1005 ReadTObject(to, uniqueID, bits);
1006}
1007
1009{
1010 UInt_t uniqueID, bits;
1011 CallReadOn(*fSubfields[0], localIndex, &uniqueID);
1012 CallReadOn(*fSubfields[1], localIndex, &bits);
1013 ReadTObject(to, uniqueID, bits);
1014}
1015
1017{
1018 if (GetOnDiskTypeVersion() != 1) {
1019 throw RException(R__FAIL("unsupported on-disk version of TObject: " + std::to_string(GetTypeVersion())));
1020 }
1021}
1022
1024{
1025 return TObject::Class()->GetClassVersion();
1026}
1027
1029{
1030 return TObject::Class()->GetCheckSum();
1031}
1032
1034{
1035 new (where) TObject();
1036}
1037
1038std::vector<ROOT::RFieldBase::RValue> ROOT::RField<TObject>::SplitValue(const RValue &value) const
1039{
1040 std::vector<RValue> result;
1041 auto basePtr = value.GetPtr<unsigned char>().get();
1042 result.emplace_back(
1043 fSubfields[0]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), basePtr + GetOffsetUniqueID())));
1044 result.emplace_back(
1045 fSubfields[1]->BindValue(std::shared_ptr<void>(value.GetPtr<void>(), basePtr + GetOffsetBits())));
1046 return result;
1047}
1048
1050{
1051 return sizeof(TObject);
1052}
1053
1055{
1056 return alignof(TObject);
1057}
1058
1060{
1061 visitor.VisitTObjectField(*this);
1062}
1063
1064//------------------------------------------------------------------------------
1065
1066std::string ROOT::RTupleField::RTupleField::GetTypeList(const std::vector<std::unique_ptr<RFieldBase>> &itemFields)
1067{
1068 std::string result;
1069 if (itemFields.empty())
1070 throw RException(R__FAIL("the type list for std::tuple must have at least one element"));
1071 for (size_t i = 0; i < itemFields.size(); ++i) {
1072 result += itemFields[i]->GetTypeName() + ",";
1073 }
1074 result.pop_back(); // remove trailing comma
1075 return result;
1076}
1077
1078ROOT::RTupleField::RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields,
1079 const std::vector<std::size_t> &offsets)
1080 : ROOT::RRecordField(fieldName, "std::tuple<" + GetTypeList(itemFields) + ">")
1081{
1082 AttachItemFields(std::move(itemFields));
1083 fOffsets = offsets;
1084}
1085
1086ROOT::RTupleField::RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1087 : ROOT::RRecordField(fieldName, "std::tuple<" + GetTypeList(itemFields) + ">")
1088{
1089 AttachItemFields(std::move(itemFields));
1090
1091 auto *c = TClass::GetClass(GetTypeName().c_str());
1092 if (!c)
1093 throw RException(R__FAIL("cannot get type information for " + GetTypeName()));
1094 fSize = c->Size();
1095
1096 // ISO C++ does not guarantee neither specific layout nor member names for `std::tuple`. However, most
1097 // implementations including libstdc++ (gcc), libc++ (llvm), and MSVC name members as `_0`, `_1`, ..., `_N-1`,
1098 // following the order of the type list.
1099 // Use TClass to get their offsets; in case a particular `std::tuple` implementation does not define such
1100 // members, the assertion below will fail.
1101 for (unsigned i = 0; i < fSubfields.size(); ++i) {
1102 std::string memberName("_" + std::to_string(i));
1103 auto member = c->GetRealData(memberName.c_str());
1104 if (!member)
1105 throw RException(R__FAIL(memberName + ": no such member"));
1106 fOffsets.push_back(member->GetThisOffset());
1107 }
1108}
1109
1110//------------------------------------------------------------------------------
1111
1112namespace {
1113
1114// Depending on the compiler, the variant tag is stored either in a trailing char or in a trailing unsigned int
1115constexpr std::size_t GetVariantTagSize()
1116{
1117 // Should be all zeros except for the tag, which is 1
1118 std::variant<char> t;
1119 constexpr auto sizeOfT = sizeof(t);
1120
1121 static_assert(sizeOfT == 2 || sizeOfT == 8, "unsupported std::variant layout");
1122 return sizeOfT == 2 ? 1 : 4;
1123}
1124
1125template <std::size_t VariantSizeT>
1126struct RVariantTag {
1127 using ValueType_t = typename std::conditional_t<VariantSizeT == 1, std::uint8_t,
1128 typename std::conditional_t<VariantSizeT == 4, std::uint32_t, void>>;
1129};
1130
1131} // anonymous namespace
1132
1133std::string ROOT::RVariantField::GetTypeList(const std::vector<std::unique_ptr<RFieldBase>> &itemFields)
1134{
1135 std::string result;
1136 for (size_t i = 0; i < itemFields.size(); ++i) {
1137 result += itemFields[i]->GetTypeName() + ",";
1138 }
1139 R__ASSERT(!result.empty()); // there is always at least one variant
1140 result.pop_back(); // remove trailing comma
1141 return result;
1142}
1143
1145 : ROOT::RFieldBase(name, source.GetTypeName(), ROOT::ENTupleStructure::kVariant, false /* isSimple */),
1146 fMaxItemSize(source.fMaxItemSize),
1147 fMaxAlignment(source.fMaxAlignment),
1148 fTagOffset(source.fTagOffset),
1149 fVariantOffset(source.fVariantOffset),
1150 fNWritten(source.fNWritten.size(), 0)
1151{
1152 for (const auto &f : source.GetConstSubfields())
1153 Attach(f->Clone(f->GetFieldName()));
1154 fTraits = source.fTraits;
1155}
1156
1157ROOT::RVariantField::RVariantField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields)
1158 : ROOT::RFieldBase(fieldName, "std::variant<" + GetTypeList(itemFields) + ">", ROOT::ENTupleStructure::kVariant,
1159 false /* isSimple */)
1160{
1161 // The variant needs to initialize its own tag member
1163
1164 auto nFields = itemFields.size();
1165 if (nFields == 0 || nFields > kMaxVariants) {
1166 throw RException(R__FAIL("invalid number of variant fields (outside [1.." + std::to_string(kMaxVariants) + ")"));
1167 }
1168 fNWritten.resize(nFields, 0);
1169 for (unsigned int i = 0; i < nFields; ++i) {
1172 fTraits &= itemFields[i]->GetTraits();
1173 Attach(std::move(itemFields[i]));
1174 }
1175
1176 // With certain template parameters, the union of members of an std::variant starts at an offset > 0.
1177 // For instance, std::variant<std::optional<int>> on macOS.
1178 auto cl = TClass::GetClass(GetTypeName().c_str());
1179 assert(cl);
1180 auto dm = reinterpret_cast<TDataMember *>(cl->GetListOfDataMembers()->First());
1181 if (dm)
1182 fVariantOffset = dm->GetOffset();
1183
1184 const auto tagSize = GetVariantTagSize();
1185 const auto padding = tagSize - (fMaxItemSize % tagSize);
1187}
1188
1189std::unique_ptr<ROOT::RFieldBase> ROOT::RVariantField::CloneImpl(std::string_view newName) const
1190{
1191 return std::unique_ptr<RVariantField>(new RVariantField(newName, *this));
1192}
1193
1194std::uint8_t ROOT::RVariantField::GetTag(const void *variantPtr, std::size_t tagOffset)
1195{
1196 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1197 auto tag = *reinterpret_cast<const TagType_t *>(reinterpret_cast<const unsigned char *>(variantPtr) + tagOffset);
1198 return (tag == TagType_t(-1)) ? 0 : tag + 1;
1199}
1200
1201void ROOT::RVariantField::SetTag(void *variantPtr, std::size_t tagOffset, std::uint8_t tag)
1202{
1203 using TagType_t = RVariantTag<GetVariantTagSize()>::ValueType_t;
1204 auto tagPtr = reinterpret_cast<TagType_t *>(reinterpret_cast<unsigned char *>(variantPtr) + tagOffset);
1205 *tagPtr = (tag == 0) ? TagType_t(-1) : static_cast<TagType_t>(tag - 1);
1206}
1207
1208std::size_t ROOT::RVariantField::AppendImpl(const void *from)
1209{
1210 auto tag = GetTag(from, fTagOffset);
1211 std::size_t nbytes = 0;
1212 auto index = 0;
1213 if (tag > 0) {
1214 nbytes += CallAppendOn(*fSubfields[tag - 1], reinterpret_cast<const unsigned char *>(from) + fVariantOffset);
1215 index = fNWritten[tag - 1]++;
1216 }
1218 fPrincipalColumn->Append(&varSwitch);
1219 return nbytes + sizeof(ROOT::Internal::RColumnSwitch);
1220}
1221
1223{
1225 std::uint32_t tag;
1226 fPrincipalColumn->GetSwitchInfo(globalIndex, &variantIndex, &tag);
1227 R__ASSERT(tag < 256);
1228
1229 // If `tag` equals 0, the variant is in the invalid state, i.e, it does not hold any of the valid alternatives in
1230 // the type list. This happens, e.g., if the field was late added; in this case, keep the invalid tag, which makes
1231 // any `std::holds_alternative<T>` check fail later.
1232 if (R__likely(tag > 0)) {
1233 void *varPtr = reinterpret_cast<unsigned char *>(to) + fVariantOffset;
1234 CallConstructValueOn(*fSubfields[tag - 1], varPtr);
1235 CallReadOn(*fSubfields[tag - 1], variantIndex, varPtr);
1236 }
1237 SetTag(to, fTagOffset, tag);
1238}
1239
1245
1250
1255
1257{
1258 memset(where, 0, GetValueSize());
1259 CallConstructValueOn(*fSubfields[0], reinterpret_cast<unsigned char *>(where) + fVariantOffset);
1260 SetTag(where, fTagOffset, 1);
1261}
1262
1264{
1265 auto tag = GetTag(objPtr, fTagOffset);
1266 if (tag > 0) {
1267 fItemDeleters[tag - 1]->operator()(reinterpret_cast<unsigned char *>(objPtr) + fVariantOffset, true /*dtorOnly*/);
1268 }
1269 RDeleter::operator()(objPtr, dtorOnly);
1270}
1271
1272std::unique_ptr<ROOT::RFieldBase::RDeleter> ROOT::RVariantField::GetDeleter() const
1273{
1274 std::vector<std::unique_ptr<RDeleter>> itemDeleters;
1275 itemDeleters.reserve(fSubfields.size());
1276 for (const auto &f : fSubfields) {
1277 itemDeleters.emplace_back(GetDeleterOf(*f));
1278 }
1279 return std::make_unique<RVariantDeleter>(fTagOffset, fVariantOffset, std::move(itemDeleters));
1280}
1281
1283{
1284 return std::max(fMaxAlignment, alignof(RVariantTag<GetVariantTagSize()>::ValueType_t));
1285}
1286
1288{
1289 const auto alignment = GetAlignment();
1290 const auto actualSize = fTagOffset + GetVariantTagSize();
1291 const auto padding = alignment - (actualSize % alignment);
1292 return actualSize + ((padding == alignment) ? 0 : padding);
1293}
1294
1296{
1297 std::fill(fNWritten.begin(), fNWritten.end(), 0);
1298}
Cppyy::TCppType_t fClass
#define R__likely(expr)
Definition RConfig.hxx:603
#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
@ kClassHasExplicitDtor
@ 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.
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:255
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:283
RField(std::string_view name)
Definition RField.hxx:286
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
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:204
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...
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:2424
EState GetState() const
Definition TClass.h:495
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3884
Int_t Size() const
Return size of object of this class.
Definition TClass.cxx:5830
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3750
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:3002
Long_t ClassProperty() const
Return the C++ property of this class, eg.
Definition TClass.cxx:2501
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6212
@ 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:3073
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 &)
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.