Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFieldBase.cxx
Go to the documentation of this file.
1/// \file RFieldBase.cxx
2/// \author Jonas Hahnfeld <jonas.hahnfeld@cern.ch>
3/// \date 2024-11-19
4
5#include <ROOT/BitUtils.hxx>
6#include <ROOT/RError.hxx>
7#include <ROOT/RField.hxx>
8#include <ROOT/RFieldBase.hxx>
10#include <ROOT/RFieldUtils.hxx>
11#include <ROOT/RNTupleUtils.hxx>
12
13#include <TClass.h>
14#include <TClassEdit.h>
15#include <TEnum.h>
16
17#include <sstream>
18#include <string>
19#include <vector>
20
21namespace {
22
23/// Used as a thread local context storage for Create(); steers the behavior of the Create() call stack
24class CreateContextGuard;
25class CreateContext {
26 friend class CreateContextGuard;
27 /// All classes that were defined by Create() calls higher up in the stack. Finds cyclic type definitions.
28 std::vector<std::string> fClassesOnStack;
29 /// If set to true, Create() will create an RInvalidField on error instead of throwing an exception.
30 /// This is used in RFieldBase::Check() to identify unsupported sub fields.
31 bool fContinueOnError = false;
32
33public:
34 CreateContext() = default;
35 bool GetContinueOnError() const { return fContinueOnError; }
36};
37
38/// RAII for modifications of CreateContext
39class CreateContextGuard {
40 CreateContext &fCreateContext;
41 std::size_t fNOriginalClassesOnStack;
42 bool fOriginalContinueOnError;
43
44public:
45 CreateContextGuard(CreateContext &ctx)
46 : fCreateContext(ctx),
47 fNOriginalClassesOnStack(ctx.fClassesOnStack.size()),
48 fOriginalContinueOnError(ctx.fContinueOnError)
49 {
50 }
52 {
53 fCreateContext.fClassesOnStack.resize(fNOriginalClassesOnStack);
54 fCreateContext.fContinueOnError = fOriginalContinueOnError;
55 }
56
57 void AddClassToStack(const std::string &cl)
58 {
59 if (std::find(fCreateContext.fClassesOnStack.begin(), fCreateContext.fClassesOnStack.end(), cl) !=
60 fCreateContext.fClassesOnStack.end()) {
61 throw ROOT::RException(R__FAIL("cyclic class definition: " + cl));
62 }
63 fCreateContext.fClassesOnStack.emplace_back(cl);
64 }
65
66 void SetContinueOnError(bool value) { fCreateContext.fContinueOnError = value; }
67};
68
69} // anonymous namespace
70
88
90ROOT::Internal::CallFieldBaseCreate(const std::string &fieldName, const std::string &typeName,
93{
94 return RFieldBase::Create(fieldName, typeName, options, desc, fieldId);
95}
96
97//------------------------------------------------------------------------------
98
100{
101 operator delete(objPtr, std::align_val_t(fAlignment));
102}
103
104//------------------------------------------------------------------------------
105
107{
108 // A single representations with an empty set of columns
109 fSerializationTypes.emplace_back(ColumnRepresentation_t());
110 fDeserializationTypes.emplace_back(ColumnRepresentation_t());
111}
112
120
121//------------------------------------------------------------------------------
122
124{
125 // Set fObjPtr to an aliased shared_ptr of the input raw pointer. Note that
126 // fObjPtr will be non-empty but have use count zero.
128}
129
130//------------------------------------------------------------------------------
131
133 : fField(other.fField),
135 fCapacity(other.fCapacity),
137 fIsAdopted(other.fIsAdopted),
138 fNValidValues(other.fNValidValues),
139 fFirstIndex(other.fFirstIndex)
140{
141 std::swap(fDeleter, other.fDeleter);
142 std::swap(fValues, other.fValues);
143 std::swap(fMaskAvail, other.fMaskAvail);
144}
145
147{
148 std::swap(fField, other.fField);
149 std::swap(fDeleter, other.fDeleter);
150 std::swap(fValues, other.fValues);
151 std::swap(fValueSize, other.fValueSize);
152 std::swap(fCapacity, other.fCapacity);
153 std::swap(fSize, other.fSize);
154 std::swap(fIsAdopted, other.fIsAdopted);
155 std::swap(fMaskAvail, other.fMaskAvail);
156 std::swap(fNValidValues, other.fNValidValues);
157 std::swap(fFirstIndex, other.fFirstIndex);
158 return *this;
159}
160
162{
163 if (fValues)
164 ReleaseValues();
165}
166
168{
169 if (fIsAdopted)
170 return;
171
172 if (!(fField->GetTraits() & RFieldBase::kTraitTriviallyDestructible)) {
173 for (std::size_t i = 0; i < fCapacity; ++i) {
174 fDeleter->operator()(GetValuePtrAt(i), true /* dtorOnly */);
175 }
176 }
177
178 operator delete(fValues, std::align_val_t(fField->GetAlignment()));
179}
180
182{
183 if (fCapacity < size) {
184 if (fIsAdopted) {
185 throw RException(R__FAIL("invalid attempt to bulk read beyond the adopted buffer"));
186 }
187 ReleaseValues();
188 fValues = operator new(size * fValueSize, std::align_val_t(fField->GetAlignment()));
189
190 if (!(fField->GetTraits() & RFieldBase::kTraitTriviallyConstructible)) {
191 for (std::size_t i = 0; i < size; ++i) {
192 fField->ConstructValue(GetValuePtrAt(i));
193 }
194 }
195
196 fMaskAvail = std::make_unique<bool[]>(size);
197 fCapacity = size;
198 }
199
200 std::fill(fMaskAvail.get(), fMaskAvail.get() + size, false);
201 fNValidValues = 0;
202
203 fFirstIndex = firstIndex;
204 fSize = size;
205}
206
208{
209 ReleaseValues();
210 fValues = buf;
211 fCapacity = capacity;
212 fSize = capacity;
213
214 fMaskAvail = std::make_unique<bool[]>(capacity);
215
216 fFirstIndex = RNTupleLocalIndex();
217
218 fIsAdopted = true;
219}
220
221//------------------------------------------------------------------------------
222
224{
225 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "possibly leaking object from RField<T>::CreateObject<void>";
226}
227
228template <>
229std::unique_ptr<void, typename ROOT::RFieldBase::RCreateObjectDeleter<void>::deleter>
230ROOT::RFieldBase::CreateObject<void>() const
231{
233 return std::unique_ptr<void, RCreateObjectDeleter<void>::deleter>(CreateObjectRawPtr(), gDeleter);
234}
235
236//------------------------------------------------------------------------------
237
238ROOT::RFieldBase::RFieldBase(std::string_view name, std::string_view type, ROOT::ENTupleStructure structure,
239 bool isSimple, std::size_t nRepetitions)
240 : fName(name),
241 fType(type),
242 fStructure(structure),
245 fParent(nullptr),
246 fPrincipalColumn(nullptr),
248{
250}
251
253{
254 std::string result = GetFieldName();
255 auto parent = GetParent();
256 while (parent && !parent->GetFieldName().empty()) {
257 result = parent->GetFieldName() + "." + result;
258 parent = parent->GetParent();
259 }
260 return result;
261}
262
264ROOT::RFieldBase::Create(const std::string &fieldName, const std::string &typeName)
265{
266 return R__FORWARD_RESULT(
268}
269
270std::vector<ROOT::RFieldBase::RCheckResult>
271ROOT::RFieldBase::Check(const std::string &fieldName, const std::string &typeName)
272{
275 cfOpts.SetReturnInvalidOnError(true);
276 cfOpts.SetEmulateUnknownTypes(false);
277 fieldZero.Attach(RFieldBase::Create(fieldName, typeName, cfOpts, nullptr, kInvalidDescriptorId).Unwrap());
278
279 std::vector<RCheckResult> result;
280 for (const auto &f : fieldZero) {
281 const bool isInvalidField = f.GetTraits() & RFieldBase::kTraitInvalidField;
282 if (!isInvalidField)
283 continue;
284
285 const auto &invalidField = static_cast<const RInvalidField &>(f);
286 result.emplace_back(
287 RCheckResult{invalidField.GetQualifiedFieldName(), invalidField.GetTypeName(), invalidField.GetError()});
288 }
289 return result;
290}
291
293ROOT::RFieldBase::Create(const std::string &fieldName, const std::string &typeName,
296{
299
301
302 thread_local CreateContext createContext;
303 CreateContextGuard createContextGuard(createContext);
304 if (options.GetReturnInvalidOnError())
305 createContextGuard.SetContinueOnError(true);
306
307 auto fnFail = [&fieldName,
308 &resolvedType](const std::string &errMsg,
310 RInvalidField::ECategory::kTypeError) -> RResult<std::unique_ptr<RFieldBase>> {
311 if (createContext.GetContinueOnError()) {
312 return std::unique_ptr<RFieldBase>(std::make_unique<RInvalidField>(fieldName, resolvedType, errMsg, cat));
313 } else {
314 return R__FAIL(errMsg);
315 }
316 };
317
318 if (resolvedType.empty())
319 return R__FORWARD_RESULT(fnFail("no type name specified for field '" + fieldName + "'"));
320
321 std::unique_ptr<ROOT::RFieldBase> result;
322
323 const auto maybeGetChildId = [desc, fieldId](int childId) {
324 if (desc) {
325 const auto &fieldDesc = desc->GetFieldDescriptor(fieldId);
326 return fieldDesc.GetLinkIds().at(childId);
327 } else {
329 }
330 };
331
332 // try-catch block to intercept any exception that may be thrown by Unwrap() so that this
333 // function never throws but returns RResult::Error instead.
334 try {
335 if (resolvedType == "bool") {
336 result = std::make_unique<RField<bool>>(fieldName);
337 } else if (resolvedType == "char") {
338 result = std::make_unique<RField<char>>(fieldName);
339 } else if (resolvedType == "std::byte") {
340 result = std::make_unique<RField<std::byte>>(fieldName);
341 } else if (resolvedType == "std::int8_t") {
342 result = std::make_unique<RField<std::int8_t>>(fieldName);
343 } else if (resolvedType == "std::uint8_t") {
344 result = std::make_unique<RField<std::uint8_t>>(fieldName);
345 } else if (resolvedType == "std::int16_t") {
346 result = std::make_unique<RField<std::int16_t>>(fieldName);
347 } else if (resolvedType == "std::uint16_t") {
348 result = std::make_unique<RField<std::uint16_t>>(fieldName);
349 } else if (resolvedType == "std::int32_t") {
350 result = std::make_unique<RField<std::int32_t>>(fieldName);
351 } else if (resolvedType == "std::uint32_t") {
352 result = std::make_unique<RField<std::uint32_t>>(fieldName);
353 } else if (resolvedType == "std::int64_t") {
354 result = std::make_unique<RField<std::int64_t>>(fieldName);
355 } else if (resolvedType == "std::uint64_t") {
356 result = std::make_unique<RField<std::uint64_t>>(fieldName);
357 } else if (resolvedType == "float") {
358 result = std::make_unique<RField<float>>(fieldName);
359 } else if (resolvedType == "double") {
360 result = std::make_unique<RField<double>>(fieldName);
361 } else if (resolvedType == "Double32_t") {
362 result = std::make_unique<RField<double>>(fieldName);
363 static_cast<RField<double> *>(result.get())->SetDouble32();
364 // Prevent the type alias from being reset by returning early
365 return result;
366 } else if (resolvedType == "std::string") {
367 result = std::make_unique<RField<std::string>>(fieldName);
368 } else if (resolvedType == "TObject") {
369 result = std::make_unique<RField<TObject>>(fieldName);
370 } else if (resolvedType == "std::vector<bool>") {
371 result = std::make_unique<RField<std::vector<bool>>>(fieldName);
372 } else if (resolvedType.substr(0, 12) == "std::vector<") {
373 std::string itemTypeName = resolvedType.substr(12, resolvedType.length() - 13);
374 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0));
375 result = std::make_unique<RVectorField>(fieldName, itemField.Unwrap());
376 } else if (resolvedType.substr(0, 19) == "ROOT::VecOps::RVec<") {
377 std::string itemTypeName = resolvedType.substr(19, resolvedType.length() - 20);
378 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0));
379 result = std::make_unique<RRVecField>(fieldName, itemField.Unwrap());
380 } else if (resolvedType.substr(0, 11) == "std::array<") {
381 auto arrayDef = TokenizeTypeList(resolvedType.substr(11, resolvedType.length() - 12));
382 if (arrayDef.size() != 2) {
383 return R__FORWARD_RESULT(fnFail("the template list for std::array must have exactly two elements"));
384 }
386 auto itemField = Create("_0", arrayDef[0], options, desc, maybeGetChildId(0));
387 result = std::make_unique<RArrayField>(fieldName, itemField.Unwrap(), arrayLength);
388 } else if (resolvedType.substr(0, 13) == "std::variant<") {
389 auto innerTypes = TokenizeTypeList(resolvedType.substr(13, resolvedType.length() - 14));
390 std::vector<std::unique_ptr<RFieldBase>> items;
391 items.reserve(innerTypes.size());
392 for (unsigned int i = 0; i < innerTypes.size(); ++i) {
393 items.emplace_back(
394 Create("_" + std::to_string(i), innerTypes[i], options, desc, maybeGetChildId(i)).Unwrap());
395 }
396 result = std::make_unique<RVariantField>(fieldName, std::move(items));
397 } else if (resolvedType.substr(0, 10) == "std::pair<") {
398 auto innerTypes = TokenizeTypeList(resolvedType.substr(10, resolvedType.length() - 11));
399 if (innerTypes.size() != 2) {
400 return R__FORWARD_RESULT(fnFail("the type list for std::pair must have exactly two elements"));
401 }
402 std::array<std::unique_ptr<RFieldBase>, 2> items{
403 Create("_0", innerTypes[0], options, desc, maybeGetChildId(0)).Unwrap(),
404 Create("_1", innerTypes[1], options, desc, maybeGetChildId(1)).Unwrap()};
405 result = std::make_unique<RPairField>(fieldName, std::move(items));
406 } else if (resolvedType.substr(0, 11) == "std::tuple<") {
407 auto innerTypes = TokenizeTypeList(resolvedType.substr(11, resolvedType.length() - 12));
408 std::vector<std::unique_ptr<RFieldBase>> items;
409 items.reserve(innerTypes.size());
410 for (unsigned int i = 0; i < innerTypes.size(); ++i) {
411 items.emplace_back(
412 Create("_" + std::to_string(i), innerTypes[i], options, desc, maybeGetChildId(i)).Unwrap());
413 }
414 result = std::make_unique<RTupleField>(fieldName, std::move(items));
415 } else if (resolvedType.substr(0, 12) == "std::bitset<") {
416 auto size = ParseUIntTypeToken(resolvedType.substr(12, resolvedType.length() - 13));
417 result = std::make_unique<RBitsetField>(fieldName, size);
418 } else if (resolvedType.substr(0, 16) == "std::unique_ptr<") {
419 std::string itemTypeName = resolvedType.substr(16, resolvedType.length() - 17);
420 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
421 result = std::make_unique<RUniquePtrField>(fieldName, std::move(itemField));
422 } else if (resolvedType.substr(0, 14) == "std::optional<") {
423 std::string itemTypeName = resolvedType.substr(14, resolvedType.length() - 15);
424 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
425 result = std::make_unique<ROptionalField>(fieldName, std::move(itemField));
426 } else if (resolvedType.substr(0, 9) == "std::set<") {
427 std::string itemTypeName = resolvedType.substr(9, resolvedType.length() - 10);
428 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
429 result = std::make_unique<RSetField>(fieldName, RSetField::ESetType::kSet, std::move(itemField));
430 } else if (resolvedType.substr(0, 19) == "std::unordered_set<") {
431 std::string itemTypeName = resolvedType.substr(19, resolvedType.length() - 20);
432 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
433 result = std::make_unique<RSetField>(fieldName, RSetField::ESetType::kUnorderedSet, std::move(itemField));
434 } else if (resolvedType.substr(0, 14) == "std::multiset<") {
435 std::string itemTypeName = resolvedType.substr(14, resolvedType.length() - 15);
436 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
437 result = std::make_unique<RSetField>(fieldName, RSetField::ESetType::kMultiSet, std::move(itemField));
438 } else if (resolvedType.substr(0, 24) == "std::unordered_multiset<") {
439 std::string itemTypeName = resolvedType.substr(24, resolvedType.length() - 25);
440 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
441 result = std::make_unique<RSetField>(fieldName, RSetField::ESetType::kUnorderedMultiSet, std::move(itemField));
442 } else if (resolvedType.substr(0, 9) == "std::map<") {
443 auto innerTypes = TokenizeTypeList(resolvedType.substr(9, resolvedType.length() - 10));
444 if (innerTypes.size() != 2) {
445 return R__FORWARD_RESULT(fnFail("the type list for std::map must have exactly two elements"));
446 }
447 auto itemField =
448 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
449 .Unwrap();
450 result = std::make_unique<RMapField>(fieldName, RMapField::EMapType::kMap, std::move(itemField));
451 } else if (resolvedType.substr(0, 19) == "std::unordered_map<") {
452 auto innerTypes = TokenizeTypeList(resolvedType.substr(19, resolvedType.length() - 20));
453 if (innerTypes.size() != 2)
454 return R__FORWARD_RESULT(fnFail("the type list for std::unordered_map must have exactly two elements"));
455 auto itemField =
456 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
457 .Unwrap();
458 result = std::make_unique<RMapField>(fieldName, RMapField::EMapType::kUnorderedMap, std::move(itemField));
459 } else if (resolvedType.substr(0, 14) == "std::multimap<") {
460 auto innerTypes = TokenizeTypeList(resolvedType.substr(14, resolvedType.length() - 15));
461 if (innerTypes.size() != 2)
462 return R__FORWARD_RESULT(fnFail("the type list for std::multimap must have exactly two elements"));
463 auto itemField =
464 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
465 .Unwrap();
466 result = std::make_unique<RMapField>(fieldName, RMapField::EMapType::kMultiMap, std::move(itemField));
467 } else if (resolvedType.substr(0, 24) == "std::unordered_multimap<") {
468 auto innerTypes = TokenizeTypeList(resolvedType.substr(24, resolvedType.length() - 25));
469 if (innerTypes.size() != 2)
470 return R__FORWARD_RESULT(
471 fnFail("the type list for std::unordered_multimap must have exactly two elements"));
472 auto itemField =
473 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
474 .Unwrap();
475 result = std::make_unique<RMapField>(fieldName, RMapField::EMapType::kUnorderedMultiMap, std::move(itemField));
476 } else if (resolvedType.substr(0, 12) == "std::atomic<") {
477 std::string itemTypeName = resolvedType.substr(12, resolvedType.length() - 13);
478 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
479 result = std::make_unique<RAtomicField>(fieldName, std::move(itemField));
480 } else if (resolvedType.substr(0, 25) == "ROOT::RNTupleCardinality<") {
481 auto innerTypes = TokenizeTypeList(resolvedType.substr(25, resolvedType.length() - 26));
482 if (innerTypes.size() != 1)
483 return R__FORWARD_RESULT(fnFail("invalid cardinality template: " + resolvedType));
485 if (canonicalInnerType == "std::uint32_t") {
486 result = std::make_unique<RField<RNTupleCardinality<std::uint32_t>>>(fieldName);
487 } else if (canonicalInnerType == "std::uint64_t") {
488 result = std::make_unique<RField<RNTupleCardinality<std::uint64_t>>>(fieldName);
489 } else {
490 return R__FORWARD_RESULT(fnFail("invalid cardinality template: " + resolvedType));
491 }
492 }
493
494 if (!result) {
495 auto cl = TClass::GetClass(typeName.c_str());
496
497 if (cl && cl->GetState() > TClass::kForwardDeclared) {
498 createContextGuard.AddClassToStack(resolvedType);
499 if (cl->GetCollectionProxy()) {
500 result = std::make_unique<RProxiedCollectionField>(fieldName, typeName);
501 }
502 // NOTE: if the class is not at least "Interpreted" we currently don't try to construct
503 // the RClassField, as in that case we'd need to fetch the information from the StreamerInfo
504 // rather than from TClass. This might be desirable in the future, but for now in this
505 // situation we rely on field emulation instead.
506 else if (cl->GetState() >= TClass::kInterpreted) {
507 if (!ROOT::Internal::GetRNTupleSoARecord(cl).empty()) {
508 result = std::make_unique<ROOT::Experimental::RSoAField>(fieldName, typeName);
511 result = std::make_unique<RStreamerField>(fieldName, typeName);
512 } else {
513 result = std::make_unique<RClassField>(fieldName, typeName);
514 }
515 }
516 }
517
518 // If we get here then we failed to meet all the conditions to create a "properly typed" field.
519 // Resort to field emulation if the user asked us to.
520 if (!result && options.GetEmulateUnknownTypes()) {
521 assert(desc);
522 const auto &fieldDesc = desc->GetFieldDescriptor(fieldId);
523 if (fieldDesc.GetStructure() == ENTupleStructure::kRecord) {
524 std::vector<std::unique_ptr<RFieldBase>> memberFields;
525 memberFields.reserve(fieldDesc.GetLinkIds().size());
526 for (auto id : fieldDesc.GetLinkIds()) {
527 const auto &memberDesc = desc->GetFieldDescriptor(id);
528 auto field = Create(memberDesc.GetFieldName(), memberDesc.GetTypeName(), options, desc, id).Unwrap();
529 memberFields.emplace_back(std::move(field));
530 }
531 R__ASSERT(typeName == fieldDesc.GetTypeName());
532 auto recordField =
534 recordField->fTypeAlias = fieldDesc.GetTypeAlias();
535 return recordField;
536 } else if (fieldDesc.GetStructure() == ENTupleStructure::kCollection) {
537 if (fieldDesc.GetLinkIds().size() != 1)
538 throw ROOT::RException(R__FAIL("invalid structure for collection field " + fieldName));
539
540 auto itemFieldId = fieldDesc.GetLinkIds()[0];
541 const auto &itemFieldDesc = desc->GetFieldDescriptor(itemFieldId);
542 auto itemField =
543 Create(itemFieldDesc.GetFieldName(), itemFieldDesc.GetTypeName(), options, desc, itemFieldId)
544 .Unwrap();
545 auto vecField =
547 vecField->fTypeAlias = fieldDesc.GetTypeAlias();
548 return vecField;
550 R__ASSERT(!fieldDesc.GetLinkIds().empty());
551 auto underlyingIntFieldId = fieldDesc.GetLinkIds()[0];
552 const auto &underlyingIntFieldDesc = desc->GetFieldDescriptor(underlyingIntFieldId);
554 underlyingIntFieldDesc.GetTypeName());
555 enumField->fTypeAlias = fieldDesc.GetTypeAlias();
556 return enumField;
557 }
558 }
559 }
560
561 if (!result) {
562 auto e = TEnum::GetEnum(resolvedType.c_str());
563 if (e != nullptr) {
564 result = std::make_unique<REnumField>(fieldName, typeName);
565 }
566 }
567 } catch (const RException &e) {
568 auto error = e.GetError();
569 if (createContext.GetContinueOnError()) {
570 return std::unique_ptr<RFieldBase>(std::make_unique<RInvalidField>(fieldName, typeName, error.GetReport(),
572 } else {
573 return error;
574 }
575 } catch (const std::logic_error &e) {
576 // Integer parsing error
577 if (createContext.GetContinueOnError()) {
578 return std::unique_ptr<RFieldBase>(
579 std::make_unique<RInvalidField>(fieldName, typeName, e.what(), RInvalidField::ECategory::kGeneric));
580 } else {
581 return R__FAIL(e.what());
582 }
583 }
584
585 if (result) {
587 if (normOrigType != result->GetTypeName()) {
588 result->fTypeAlias = normOrigType;
589 }
590 return result;
591 }
592 return R__FORWARD_RESULT(fnFail("unknown type: " + typeName, RInvalidField::ECategory::kUnknownType));
593}
594
600
601std::unique_ptr<ROOT::RFieldBase> ROOT::RFieldBase::Clone(std::string_view newName) const
602{
603 auto clone = CloneImpl(newName);
604 clone->fTypeAlias = fTypeAlias;
605 clone->fOnDiskId = fOnDiskId;
606 clone->fDescription = fDescription;
607 // We can just copy the references because fColumnRepresentatives point into a static structure
608 clone->fColumnRepresentatives = fColumnRepresentatives;
609 return clone;
610}
611
612std::size_t ROOT::RFieldBase::AppendImpl(const void * /* from */)
613{
614 R__ASSERT(false && "A non-simple RField must implement its own AppendImpl");
615 return 0;
616}
617
619{
620 R__ASSERT(false);
621}
622
624{
625 ReadGlobalImpl(fPrincipalColumn->GetGlobalIndex(localIndex), to);
626}
627
629{
630 const auto valueSize = GetValueSize();
631 std::size_t nRead = 0;
632 for (std::size_t i = 0; i < bulkSpec.fCount; ++i) {
633 // Value not needed
634 if (bulkSpec.fMaskReq && !bulkSpec.fMaskReq[i])
635 continue;
636
637 // Value already present
638 if (bulkSpec.fMaskAvail[i])
639 continue;
640
641 Read(bulkSpec.fFirstIndex + i, reinterpret_cast<unsigned char *>(bulkSpec.fValues) + i * valueSize);
642 bulkSpec.fMaskAvail[i] = true;
643 nRead++;
644 }
645 return nRead;
646}
647
649{
650 const auto align = GetAlignment();
651 void *where;
652 if (align <= sizeof(std::max_align_t)) {
653 // We use the normal operator new for regularly aligned types to not complicate the user code that
654 // deletes objects returned by CreateObject()
655 where = operator new(GetValueSize());
656 } else {
657 where = operator new(GetValueSize(), std::align_val_t(GetAlignment()));
658 }
659 R__ASSERT(where != nullptr);
660 ConstructValue(where);
661 return where;
662}
663
665{
666 void *obj = CreateObjectRawPtr();
667 return RValue(this, std::shared_ptr<void>(obj, RSharedPtrDeleter(GetDeleter())));
668}
669
670std::vector<ROOT::RFieldBase::RValue> ROOT::RFieldBase::SplitValue(const RValue & /*value*/) const
671{
672 return std::vector<RValue>();
673}
674
675void ROOT::RFieldBase::Attach(std::unique_ptr<ROOT::RFieldBase> child, std::string_view expectedChildName)
676{
677 // Note that technically the zero field would not need to have the extensible trait: because only its sub fields
678 // get connected by RPageSink::UpdateSchema, it does not change its initial state.
679 if (!(fTraits & kTraitExtensible) && (fState != EState::kUnconnected))
680 throw RException(R__FAIL("invalid attempt to attach subfield to already connected, non-extensible field"));
681
682 if (!expectedChildName.empty() && child->GetFieldName() != expectedChildName) {
683 throw RException(R__FAIL(std::string("invalid subfield name: ") + child->GetFieldName() +
684 " expected: " + std::string(expectedChildName)));
685 }
686
687 child->fParent = this;
688 fSubfields.emplace_back(std::move(child));
689}
690
692{
694 for (auto f = this; f != nullptr; f = f->GetParent()) {
695 auto parent = f->GetParent();
696 if (parent && (parent->GetStructure() == ROOT::ENTupleStructure::kCollection ||
697 parent->GetStructure() == ROOT::ENTupleStructure::kVariant)) {
698 return 0U;
699 }
700 result *= std::max<ROOT::NTupleSize_t>(f->GetNRepetitions(), ROOT::NTupleSize_t{1U});
701 }
702 return result;
703}
704
705std::vector<ROOT::RFieldBase *> ROOT::RFieldBase::GetMutableSubfields()
706{
707 std::vector<RFieldBase *> result;
708 result.reserve(fSubfields.size());
709 for (const auto &f : fSubfields) {
710 result.emplace_back(f.get());
711 }
712 return result;
713}
714
715std::vector<const ROOT::RFieldBase *> ROOT::RFieldBase::GetConstSubfields() const
716{
717 std::vector<const RFieldBase *> result;
718 result.reserve(fSubfields.size());
719 for (const auto &f : fSubfields) {
720 result.emplace_back(f.get());
721 }
722 return result;
723}
724
726{
727 if (!fAvailableColumns.empty()) {
728 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
729 for (auto &column : fAvailableColumns) {
730 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
731 column->Flush();
732 }
733 }
734 }
735}
736
738{
739 if (!fAvailableColumns.empty()) {
740 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
741 for (auto &column : fAvailableColumns) {
742 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
743 column->Flush();
744 } else {
745 column->CommitSuppressed();
746 }
747 }
748 }
749 CommitClusterImpl();
750}
751
753{
754 if (fState != EState::kUnconnected)
755 throw RException(R__FAIL("cannot set field description once field is connected"));
756 fDescription = std::string(description);
757}
758
760{
761 if (fState != EState::kUnconnected)
762 throw RException(R__FAIL("cannot set field ID once field is connected"));
763 fOnDiskId = id;
764}
765
766/// Write the given value into columns. The value object has to be of the same type as the field.
767/// Returns the number of uncompressed bytes written.
768std::size_t ROOT::RFieldBase::Append(const void *from)
769{
770 if (~fTraits & kTraitMappable)
771 return AppendImpl(from);
772
773 fPrincipalColumn->Append(from);
774 return fPrincipalColumn->GetElement()->GetPackedSize();
775}
776
781
783{
784 return RValue(this, std::move(objPtr));
785}
786
788{
789 if (fIsSimple) {
790 /// For simple types, ignore the mask and memcopy the values into the destination
791 fPrincipalColumn->ReadV(bulkSpec.fFirstIndex, bulkSpec.fCount, bulkSpec.fValues);
792 std::fill(bulkSpec.fMaskAvail, bulkSpec.fMaskAvail + bulkSpec.fCount, true);
793 return RBulkSpec::kAllSet;
794 }
795
796 if (fIsArtificial || !fReadCallbacks.empty()) {
797 // Fields with schema evolution treatment must not go through an optimized read
799 }
800
801 return ReadBulkImpl(bulkSpec);
802}
803
805{
806 return fSubfields.empty() ? RSchemaIterator(this, -1) : RSchemaIterator(fSubfields[0].get(), 0);
807}
808
813
815{
816 return fSubfields.empty() ? RConstSchemaIterator(this, -1) : RConstSchemaIterator(fSubfields[0].get(), 0);
817}
818
823
825{
826 return fSubfields.empty() ? RConstSchemaIterator(this, -1) : RConstSchemaIterator(fSubfields[0].get(), 0);
827}
828
833
835{
836 if (fColumnRepresentatives.empty()) {
837 return {GetColumnRepresentations().GetSerializationDefault()};
838 }
839
841 result.reserve(fColumnRepresentatives.size());
842 for (const auto &r : fColumnRepresentatives) {
843 result.emplace_back(r.get());
844 }
845 return result;
846}
847
849{
850 if (fState != EState::kUnconnected)
851 throw RException(R__FAIL("cannot set column representative once field is connected"));
852 const auto &validTypes = GetColumnRepresentations().GetSerializationTypes();
853 fColumnRepresentatives.clear();
854 fColumnRepresentatives.reserve(representatives.size());
855 for (const auto &r : representatives) {
856 auto itRepresentative = std::find(validTypes.begin(), validTypes.end(), r);
857 if (itRepresentative == std::end(validTypes))
858 throw RException(R__FAIL("invalid column representative"));
859
860 fColumnRepresentatives.emplace_back(*itRepresentative);
861 }
862}
863
866 std::uint16_t representationIndex) const
867{
868 static const ColumnRepresentation_t kEmpty;
869
870 if (fOnDiskId == ROOT::kInvalidDescriptorId)
871 throw RException(R__FAIL("No on-disk field information for `" + GetQualifiedFieldName() + "`"));
872
874 for (const auto &c : desc.GetColumnIterable(fOnDiskId)) {
875 if (c.GetRepresentationIndex() == representationIndex)
876 onDiskTypes.emplace_back(c.GetType());
877 }
878 if (onDiskTypes.empty()) {
879 if (representationIndex == 0) {
880 throw RException(R__FAIL("No on-disk column information for field `" + GetQualifiedFieldName() + "`"));
881 }
882 return kEmpty;
883 }
884
885 for (const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
886 if (t == onDiskTypes)
887 return t;
888 }
889
890 std::string columnTypeNames;
891 for (const auto &t : onDiskTypes) {
892 if (!columnTypeNames.empty())
893 columnTypeNames += ", ";
895 }
896 throw RException(R__FAIL("On-disk column types {" + columnTypeNames + "} for field `" + GetQualifiedFieldName() +
897 "` cannot be matched to its in-memory type `" + GetTypeName() + "` " +
898 "(representation index: " + std::to_string(representationIndex) + ")"));
899}
900
902{
903 fReadCallbacks.push_back(func);
904 fIsSimple = false;
905 return fReadCallbacks.size() - 1;
906}
907
909{
910 fReadCallbacks.erase(fReadCallbacks.begin() + idx);
911 fIsSimple = (fTraits & kTraitMappable) && !fIsArtificial && fReadCallbacks.empty();
912}
913
939
941{
942 if (dynamic_cast<ROOT::RFieldZero *>(this))
943 throw RException(R__FAIL("invalid attempt to connect zero field to page sink"));
944 if (fState != EState::kUnconnected)
945 throw RException(R__FAIL("invalid attempt to connect an already connected field to a page sink"));
946
947 AutoAdjustColumnTypes(pageSink.GetWriteOptions());
948
949 GenerateColumns();
950 for (auto &column : fAvailableColumns) {
951 // Only the first column of every representation can be a deferred column. In all column representations,
952 // larger column indexes are data columns of collections (string, streamer) and thus
953 // they have no elements on late model extension
954 auto firstElementIndex = (column->GetIndex() == 0) ? EntryToColumnElementIndex(firstEntry) : 0;
955 column->ConnectPageSink(fOnDiskId, pageSink, firstElementIndex);
956 }
957
958 if (HasExtraTypeInfo()) {
959 pageSink.RegisterOnCommitDatasetCallback(
960 [this](ROOT::Internal::RPageSink &sink) { sink.UpdateExtraTypeInfo(GetExtraTypeInfo()); });
961 }
962
963 fState = EState::kConnectedToSink;
964}
965
967{
968 if (dynamic_cast<ROOT::RFieldZero *>(this)) {
969 for (auto &f : fSubfields)
970 f->ConnectPageSource(pageSource);
971 return;
972 }
973
974 if (fState != EState::kUnconnected)
975 throw RException(R__FAIL("invalid attempt to connect an already connected field to a page source"));
976
977 if (!fColumnRepresentatives.empty())
978 throw RException(R__FAIL("fixed column representative only valid when connecting to a page sink"));
979 if (!fDescription.empty())
980 throw RException(R__FAIL("setting description only valid when connecting to a page sink"));
981
982 if (!fIsArtificial) {
983 R__ASSERT(fOnDiskId != kInvalidDescriptorId);
984 // Handle moving from on-disk std::atomic<T> to (compatible of) T in memory centrally because otherwise
985 // we would need to handle it in each and every ReconcileOnDiskField()
986 // Note that we have to do this before calling BeforeConnectPageSource(), which already may compare the field
987 // to its on-disk description.
988 const auto &desc = pageSource.GetSharedDescriptorGuard().GetRef();
989 if (!dynamic_cast<RAtomicField *>(this) &&
990 Internal::IsStdAtomicFieldDesc(desc.GetFieldDescriptor(GetOnDiskId()))) {
991 SetOnDiskId(desc.GetFieldDescriptor(GetOnDiskId()).GetLinkIds()[0]);
992 }
993 }
994
995 auto substitute = BeforeConnectPageSource(pageSource);
996 if (substitute) {
997 const RFieldBase *itr = this;
998 while (itr->GetParent()) {
999 itr = itr->GetParent();
1000 }
1001 if (typeid(*itr) == typeid(RFieldZero) && static_cast<const RFieldZero *>(itr)->GetAllowFieldSubstitutions()) {
1002 for (auto &f : fParent->fSubfields) {
1003 if (f.get() != this)
1004 continue;
1005
1006 f = std::move(substitute);
1007 f->ConnectPageSource(pageSource);
1008 return;
1009 }
1010 R__ASSERT(false); // never here
1011 } else {
1012 throw RException(R__FAIL("invalid attempt to substitute field " + GetQualifiedFieldName()));
1013 }
1014 }
1015
1016 if (!fIsArtificial) {
1017 const auto &desc = pageSource.GetSharedDescriptorGuard().GetRef();
1018 ReconcileOnDiskField(desc);
1019 }
1020
1021 for (auto &f : fSubfields) {
1022 if (f->GetOnDiskId() == ROOT::kInvalidDescriptorId) {
1023 f->SetOnDiskId(pageSource.GetSharedDescriptorGuard()->FindFieldId(f->GetFieldName(), GetOnDiskId()));
1024 }
1025 f->ConnectPageSource(pageSource);
1026 }
1027
1028 // Do not generate columns nor set fColumnRepresentatives for artificial fields.
1029 if (!fIsArtificial) {
1030 const auto descriptorGuard = pageSource.GetSharedDescriptorGuard();
1032 GenerateColumns(desc);
1033 if (fColumnRepresentatives.empty()) {
1034 // If we didn't get columns from the descriptor, ensure that we actually expect a field without columns
1035 for (const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
1036 if (t.empty()) {
1037 fColumnRepresentatives = {t};
1038 break;
1039 }
1040 }
1041 }
1042 R__ASSERT(!fColumnRepresentatives.empty());
1043 if (fOnDiskId != ROOT::kInvalidDescriptorId) {
1044 const auto &fieldDesc = desc.GetFieldDescriptor(fOnDiskId);
1045 fOnDiskTypeVersion = fieldDesc.GetTypeVersion();
1046 if (fieldDesc.GetTypeChecksum().has_value())
1047 fOnDiskTypeChecksum = *fieldDesc.GetTypeChecksum();
1048 }
1049 }
1050 for (auto &column : fAvailableColumns)
1051 column->ConnectPageSource(fOnDiskId, pageSource);
1052
1053 fState = EState::kConnectedToSource;
1054}
1055
1057{
1058 // The default implementation throws an exception if there are any meaningful differences to the on-disk field.
1059 // Derived classes may overwrite this and relax the checks to support automatic schema evolution.
1060 EnsureMatchingOnDiskField(desc).ThrowOnError();
1061}
1062
1065{
1066 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1067 const std::uint32_t diffBits = CompareOnDiskField(fieldDesc, ignoreBits);
1068 if (diffBits == 0)
1069 return RResult<void>::Success();
1070
1071 std::ostringstream errMsg;
1072 errMsg << "in-memory field " << GetQualifiedFieldName() << " of type " << GetTypeName() << " is incompatible "
1073 << "with on-disk field " << fieldDesc.GetFieldName() << ":";
1074 if (diffBits & kDiffFieldVersion) {
1075 errMsg << " field version " << GetFieldVersion() << " vs. " << fieldDesc.GetFieldVersion() << ";";
1076 }
1077 if (diffBits & kDiffTypeVersion) {
1078 errMsg << " type version " << GetTypeVersion() << " vs. " << fieldDesc.GetTypeVersion() << ";";
1079 }
1080 if (diffBits & kDiffStructure) {
1081 errMsg << " structural role " << GetStructure() << " vs. " << fieldDesc.GetStructure() << ";";
1082 }
1083 if (diffBits & kDiffTypeName) {
1084 errMsg << " incompatible on-disk type name " << fieldDesc.GetTypeName() << ";";
1085 }
1086 if (diffBits & kDiffNRepetitions) {
1087 errMsg << " repetition count " << GetNRepetitions() << " vs. " << fieldDesc.GetNRepetitions() << ";";
1088 }
1089 return R__FAIL(errMsg.str() + "\n" + Internal::GetTypeTraceReport(*this, desc));
1090}
1091
1093{
1094 std::uint32_t ignoreBits = kDiffTypeName;
1095 if (desc.GetFieldDescriptor(GetOnDiskId()).IsSoACollection())
1096 ignoreBits |= kDiffTypeVersion;
1097 return EnsureMatchingOnDiskField(desc, ignoreBits);
1098}
1099
1101 const std::vector<std::string> &prefixes) const
1102{
1103 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1104 for (const auto &p : prefixes) {
1105 if (fieldDesc.GetTypeName().rfind(p, 0) == 0)
1106 return RResult<void>::Success();
1107 }
1108 return R__FAIL("incompatible type " + fieldDesc.GetTypeName() + " for field " + GetQualifiedFieldName() + "\n" +
1110}
1111
1113{
1114 std::uint32_t diffBits = 0;
1115 if ((~ignoreBits & kDiffFieldVersion) && (GetFieldVersion() != fieldDesc.GetFieldVersion()))
1116 diffBits |= kDiffFieldVersion;
1117 if ((~ignoreBits & kDiffTypeVersion) && (GetTypeVersion() != fieldDesc.GetTypeVersion()))
1118 diffBits |= kDiffTypeVersion;
1119 if ((~ignoreBits & kDiffStructure) && (GetStructure() != fieldDesc.GetStructure()))
1120 diffBits |= kDiffStructure;
1121 if ((~ignoreBits & kDiffTypeName) && (GetTypeName() != fieldDesc.GetTypeName()))
1122 diffBits |= kDiffTypeName;
1123 if ((~ignoreBits & kDiffNRepetitions) && (GetNRepetitions() != fieldDesc.GetNRepetitions()))
1124 diffBits |= kDiffNRepetitions;
1125
1126 return diffBits;
1127}
1128
1130{
1131 visitor.VisitField(*this);
1132}
size_t fValueSize
dim_t fSize
#define R__FORWARD_RESULT(res)
Short-hand to return an RResult<T> value from a subroutine to the calling stack frame.
Definition RError.hxx:324
#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:322
#define R__LOG_WARNING(...)
Definition RLogger.hxx:357
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
std::size_t capacity
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.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:130
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
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 GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
Abstract base class for classes implementing the visitor design pattern.
static const char * GetColumnTypeName(ROOT::ENTupleColumnType type)
Abstract interface to write data into an ntuple.
Abstract interface to read data from an ntuple.
Template specializations for C++ std::atomic.
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Points to an array of objects with RNTuple I/O support, used for bulk reading.
std::unique_ptr< bool[]> fMaskAvail
Masks invalid values in the array.
std::unique_ptr< RFieldBase::RDeleter > fDeleter
void Reset(RNTupleLocalIndex firstIndex, std::size_t size)
Sets a new range for the bulk.
void * fValues
Cached deleter of fField.
RBulkValues & operator=(const RBulkValues &)=delete
RBulkValues(RFieldBase *field)
void AdoptBuffer(void *buf, std::size_t capacity)
The list of column representations a field can have.
std::vector< ColumnRepresentation_t > Selection_t
A list of column representations.
Selection_t fDeserializationTypes
The union of the serialization types and the deserialization extra types passed during construction.
void DeleteAligned(void *objPtr) const
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
void BindRawPtr(void *rawPtr)
A field translates read and write calls from/to underlying columns to/from tree values.
RSchemaIterator end()
void Attach(std::unique_ptr< RFieldBase > child, std::string_view expectedChildName="")
Add a new subfield to the list of nested fields.
void SetColumnRepresentatives(const RColumnRepresentations::Selection_t &representatives)
Fixes a column representative.
ROOT::Internal::RColumn * fPrincipalColumn
All fields that have columns have a distinct main column.
virtual void ReconcileOnDiskField(const RNTupleDescriptor &desc)
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
ROOT::NTupleSize_t EntryToColumnElementIndex(ROOT::NTupleSize_t globalIndex) const
Translate an entry index to a column element index of the principal column.
virtual void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const
void FlushColumns()
Flushes data from active columns.
virtual void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to)
virtual const RColumnRepresentations & GetColumnRepresentations() const
Implementations in derived classes should return a static RColumnRepresentations object.
bool fIsSimple
A field qualifies as simple if it is mappable (which implies it has a single principal column),...
RConstSchemaIterator cbegin() const
void AutoAdjustColumnTypes(const ROOT::RNTupleWriteOptions &options)
When connecting a field to a page sink, the field's default column representation is subject to adjus...
@ 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.
@ kTraitMappable
A field of a fundamental type that can be directly mapped via RField<T>::Map(), i....
@ kTraitInvalidField
This field is an instance of RInvalidField and can be safely static_cast to it.
std::vector< const RFieldBase * > GetConstSubfields() const
void SetOnDiskId(ROOT::DescriptorId_t id)
void RemoveReadCallback(size_t idx)
size_t AddReadCallback(const ReadCallback_t &func)
Set a user-defined function to be called after reading a value, giving a chance to inspect and/or mod...
std::vector< RFieldBase * > GetMutableSubfields()
static std::vector< RCheckResult > Check(const std::string &fieldName, const std::string &typeName)
Checks if the given type is supported by RNTuple.
RSchemaIterator begin()
RResult< void > EnsureMatchingOnDiskCollection(const RNTupleDescriptor &desc) const
Convenience wrapper for the common case of calling EnsureMatchinOnDiskField() for collections.
RConstSchemaIterator cend() const
std::size_t fNRepetitions
For fixed sized arrays, the array length.
std::function< void(void *)> ReadCallback_t
std::size_t Append(const void *from)
Write the given value into columns.
RValue CreateValue()
Generates an object of the field's type, wraps it in a shared pointer and returns it as an RValue con...
const ColumnRepresentation_t & EnsureCompatibleColumnTypes(const ROOT::RNTupleDescriptor &desc, std::uint16_t representationIndex) const
Returns the on-disk column types found in the provided descriptor for fOnDiskId and the given represe...
virtual std::vector< RValue > SplitValue(const RValue &value) const
Creates the list of direct child values given an existing value for this field.
std::string GetQualifiedFieldName() const
Returns the field name and parent field names separated by dots (grandparent.parent....
RBulkValues CreateBulk()
Creates a new, initially empty bulk.
void ConnectPageSink(ROOT::Internal::RPageSink &pageSink, ROOT::NTupleSize_t firstEntry=0)
Fields and their columns live in the void until connected to a physical page storage.
std::size_t ReadBulk(const RBulkSpec &bulkSpec)
Returns the number of newly available values, that is the number of bools in bulkSpec....
std::vector< ROOT::ENTupleColumnType > ColumnRepresentation_t
RResult< void > EnsureMatchingOnDiskField(const RNTupleDescriptor &desc, std::uint32_t ignoreBits=0) const
Compares the field to the corresponding on-disk field information in the provided descriptor.
virtual void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to)
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
virtual std::size_t AppendImpl(const void *from)
Operations on values of complex types, e.g.
RFieldBase * fParent
Subfields point to their mother field.
RFieldBase(std::string_view name, std::string_view type, ROOT::ENTupleStructure structure, bool isSimple, std::size_t nRepetitions=0)
The constructor creates the underlying column objects and connects them to either a sink or a source.
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::uint32_t CompareOnDiskField(const RFieldDescriptor &fieldDesc, std::uint32_t ignoreBits) const
Returns a combination of kDiff... flags, indicating peroperties that are different between the field ...
std::string fType
The C++ type captured by this field.
RColumnRepresentations::Selection_t GetColumnRepresentatives() const
Returns the fColumnRepresentative pointee or, if unset (always the case for artificial fields),...
ROOT::ENTupleStructure fStructure
The role of this field in the data model structure.
RValue BindValue(std::shared_ptr< void > objPtr)
Creates a value from a memory location with an already constructed object.
void SetDescription(std::string_view description)
std::unique_ptr< RFieldBase > Clone(std::string_view newName) const
Copies the field and its subfields using a possibly new name and a new, unconnected set of columns.
std::string fName
The field name relative to its parent field.
void CommitCluster()
Flushes data from active columns to disk and calls CommitClusterImpl()
void ConnectPageSource(ROOT::Internal::RPageSource &pageSource)
Connects the field and its subfield tree to the given page source.
RResult< void > EnsureMatchingTypePrefix(const RNTupleDescriptor &desc, const std::vector< std::string > &prefixes) const
Many fields accept a range of type prefixes for schema evolution, e.g.
void * CreateObjectRawPtr() const
Factory method for the field's type. The caller owns the returned pointer.
virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec)
General implementation of bulk read.
Metadata stored for every field of an RNTuple.
The container field for an ntuple model, which itself has no physical representation.
Definition RField.hxx:58
Used in RFieldBase::Check() to record field creation failures.
Definition RField.hxx:96
@ kGeneric
Generic unrecoverable error.
@ kUnknownType
The type given to RFieldBase::Create was unknown.
@ kTypeError
The type given to RFieldBase::Create was invalid.
The on-storage metadata of an RNTuple.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Common user-tunable settings for storing RNTuples.
std::uint32_t GetCompression() const
const_iterator begin() const
const_iterator end() const
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
Definition RError.hxx:222
@ kInterpreted
Definition TClass.h:129
@ kForwardDeclared
Definition TClass.h:127
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:2999
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
Definition TEnum.cxx:181
std::vector< std::string > TokenizeTypeList(std::string_view templateType, std::size_t maxArgs=0)
Used in RFieldBase::Create() in order to get the comma-separated list of template types E....
std::unique_ptr< RFieldBase > CreateEmulatedVectorField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField, std::string_view emulatedFromType)
Definition RField.cxx:598
RResult< void > EnsureValidNameForRNTuple(std::string_view name, std::string_view where)
Check whether a given string is a valid name according to the RNTuple specification.
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
void CallCommitClusterOnField(RFieldBase &)
void CallConnectPageSourceOnField(RFieldBase &, ROOT::Internal::RPageSource &)
unsigned long long ParseUIntTypeToken(const std::string &uintToken)
std::unique_ptr< RFieldBase > CreateEmulatedRecordField(std::string_view fieldName, std::vector< std::unique_ptr< RFieldBase > > itemFields, std::string_view emulatedFromType)
Definition RField.cxx:590
std::string GetRNTupleSoARecord(const TClass *cl)
Checks if the "rntuple.SoARecord" class attribute is set in the dictionary.
ROOT::RResult< std::unique_ptr< ROOT::RFieldBase > > CallFieldBaseCreate(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId)
std::string GetTypeTraceReport(const RFieldBase &field, const RNTupleDescriptor &desc)
Prints the hierarchy of types with their field names and field IDs for the given in-memory field and ...
auto MakeAliasedSharedPtr(T *rawPtr)
std::string GetCanonicalTypePrefix(const std::string &typeName)
Applies RNTuple specific type name normalization rules (see specs) that help the string parsing in RF...
void CallFlushColumnsOnField(RFieldBase &)
std::unique_ptr< RFieldBase > CreateEmulatedEnumField(std::string_view fieldName, std::string_view emulatedFromType, std::string_view underlyingIntType)
bool IsCustomEnumFieldDesc(const RNTupleDescriptor &desc, const RFieldDescriptor &fieldDesc)
Tells if the field describes a user-defined enum type.
std::string GetNormalizedUnresolvedTypeName(const std::string &origName)
Applies all RNTuple type normalization rules except typedef resolution.
ERNTupleSerializationMode GetRNTupleSerializationMode(const TClass *cl)
bool IsStdAtomicFieldDesc(const RFieldDescriptor &fieldDesc)
Tells if the field describes a std::atomic<T> type.
void CallConnectPageSinkOnField(RFieldBase &, ROOT::Internal::RPageSink &, ROOT::NTupleSize_t firstEntry=0)
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
ENTupleStructure
The fields in the RNTuple data model tree can carry different structural information about the type s...
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
Input parameter to RFieldBase::ReadBulk() and RFieldBase::ReadBulkImpl().
Used in the return value of the Check() method.