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,
91 const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc,
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
207void ROOT::RFieldBase::RBulkValues::AdoptBuffer(void *buf, std::size_t capacity)
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,
294 const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc,
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 auto normalizedInnerTypeName = itemField->GetTypeName();
442 result = std::make_unique<RSetField>(fieldName, RSetField::ESetType::kUnorderedMultiSet, std::move(itemField));
443 } else if (resolvedType.substr(0, 9) == "std::map<") {
444 auto innerTypes = TokenizeTypeList(resolvedType.substr(9, resolvedType.length() - 10));
445 if (innerTypes.size() != 2) {
446 return R__FORWARD_RESULT(fnFail("the type list for std::map must have exactly two elements"));
447 }
448 auto itemField =
449 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
450 .Unwrap();
451 result = std::make_unique<RMapField>(fieldName, RMapField::EMapType::kMap, std::move(itemField));
452 } else if (resolvedType.substr(0, 19) == "std::unordered_map<") {
453 auto innerTypes = TokenizeTypeList(resolvedType.substr(19, resolvedType.length() - 20));
454 if (innerTypes.size() != 2)
455 return R__FORWARD_RESULT(fnFail("the type list for std::unordered_map must have exactly two elements"));
456 auto itemField =
457 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
458 .Unwrap();
459 result = std::make_unique<RMapField>(fieldName, RMapField::EMapType::kUnorderedMap, std::move(itemField));
460 } else if (resolvedType.substr(0, 14) == "std::multimap<") {
461 auto innerTypes = TokenizeTypeList(resolvedType.substr(14, resolvedType.length() - 15));
462 if (innerTypes.size() != 2)
463 return R__FORWARD_RESULT(fnFail("the type list for std::multimap must have exactly two elements"));
464 auto itemField =
465 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
466 .Unwrap();
467 result = std::make_unique<RMapField>(fieldName, RMapField::EMapType::kMultiMap, std::move(itemField));
468 } else if (resolvedType.substr(0, 24) == "std::unordered_multimap<") {
469 auto innerTypes = TokenizeTypeList(resolvedType.substr(24, resolvedType.length() - 25));
470 if (innerTypes.size() != 2)
471 return R__FORWARD_RESULT(
472 fnFail("the type list for std::unordered_multimap must have exactly two elements"));
473 auto itemField =
474 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
475 .Unwrap();
476 result = std::make_unique<RMapField>(fieldName, RMapField::EMapType::kUnorderedMultiMap, std::move(itemField));
477 } else if (resolvedType.substr(0, 12) == "std::atomic<") {
478 std::string itemTypeName = resolvedType.substr(12, resolvedType.length() - 13);
479 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
480 result = std::make_unique<RAtomicField>(fieldName, std::move(itemField));
481 } else if (resolvedType.substr(0, 25) == "ROOT::RNTupleCardinality<") {
482 auto innerTypes = TokenizeTypeList(resolvedType.substr(25, resolvedType.length() - 26));
483 if (innerTypes.size() != 1)
484 return R__FORWARD_RESULT(fnFail("invalid cardinality template: " + resolvedType));
486 if (canonicalInnerType == "std::uint32_t") {
487 result = std::make_unique<RField<RNTupleCardinality<std::uint32_t>>>(fieldName);
488 } else if (canonicalInnerType == "std::uint64_t") {
489 result = std::make_unique<RField<RNTupleCardinality<std::uint64_t>>>(fieldName);
490 } else {
491 return R__FORWARD_RESULT(fnFail("invalid cardinality template: " + resolvedType));
492 }
493 }
494
495 if (!result) {
496 auto cl = TClass::GetClass(typeName.c_str());
497
498 if (cl && cl->GetState() > TClass::kForwardDeclared) {
499 createContextGuard.AddClassToStack(resolvedType);
500 if (cl->GetCollectionProxy()) {
501 result = std::make_unique<RProxiedCollectionField>(fieldName, typeName);
502 }
503 // NOTE: if the class is not at least "Interpreted" we currently don't try to construct
504 // the RClassField, as in that case we'd need to fetch the information from the StreamerInfo
505 // rather than from TClass. This might be desirable in the future, but for now in this
506 // situation we rely on field emulation instead.
507 else if (cl->GetState() >= TClass::kInterpreted) {
508 if (!ROOT::Internal::GetRNTupleSoARecord(cl).empty()) {
509 result = std::make_unique<ROOT::Experimental::RSoAField>(fieldName, typeName);
512 result = std::make_unique<RStreamerField>(fieldName, typeName);
513 } else {
514 result = std::make_unique<RClassField>(fieldName, typeName);
515 }
516 }
517 }
518
519 // If we get here then we failed to meet all the conditions to create a "properly typed" field.
520 // Resort to field emulation if the user asked us to.
521 if (!result && options.GetEmulateUnknownTypes()) {
522 assert(desc);
523 const auto &fieldDesc = desc->GetFieldDescriptor(fieldId);
524 if (fieldDesc.GetStructure() == ENTupleStructure::kRecord) {
525 std::vector<std::unique_ptr<RFieldBase>> memberFields;
526 memberFields.reserve(fieldDesc.GetLinkIds().size());
527 for (auto id : fieldDesc.GetLinkIds()) {
528 const auto &memberDesc = desc->GetFieldDescriptor(id);
529 auto field = Create(memberDesc.GetFieldName(), memberDesc.GetTypeName(), options, desc, id).Unwrap();
530 memberFields.emplace_back(std::move(field));
531 }
532 R__ASSERT(typeName == fieldDesc.GetTypeName());
533 auto recordField =
535 recordField->fTypeAlias = fieldDesc.GetTypeAlias();
536 return recordField;
537 } else if (fieldDesc.GetStructure() == ENTupleStructure::kCollection) {
538 if (fieldDesc.GetLinkIds().size() != 1)
539 throw ROOT::RException(R__FAIL("invalid structure for collection field " + fieldName));
540
541 auto itemFieldId = fieldDesc.GetLinkIds()[0];
542 const auto &itemFieldDesc = desc->GetFieldDescriptor(itemFieldId);
543 auto itemField =
544 Create(itemFieldDesc.GetFieldName(), itemFieldDesc.GetTypeName(), options, desc, itemFieldId)
545 .Unwrap();
546 auto vecField =
548 vecField->fTypeAlias = fieldDesc.GetTypeAlias();
549 return vecField;
550 }
551 }
552 }
553
554 if (!result) {
555 auto e = TEnum::GetEnum(resolvedType.c_str());
556 if (e != nullptr) {
557 result = std::make_unique<REnumField>(fieldName, typeName);
558 }
559 }
560 } catch (const RException &e) {
561 auto error = e.GetError();
562 if (createContext.GetContinueOnError()) {
563 return std::unique_ptr<RFieldBase>(std::make_unique<RInvalidField>(fieldName, typeName, error.GetReport(),
565 } else {
566 return error;
567 }
568 } catch (const std::logic_error &e) {
569 // Integer parsing error
570 if (createContext.GetContinueOnError()) {
571 return std::unique_ptr<RFieldBase>(
572 std::make_unique<RInvalidField>(fieldName, typeName, e.what(), RInvalidField::ECategory::kGeneric));
573 } else {
574 return R__FAIL(e.what());
575 }
576 }
577
578 if (result) {
580 if (normOrigType != result->GetTypeName()) {
581 result->fTypeAlias = normOrigType;
582 }
583 return result;
584 }
585 return R__FORWARD_RESULT(fnFail("unknown type: " + typeName, RInvalidField::ECategory::kUnknownType));
586}
587
593
594std::unique_ptr<ROOT::RFieldBase> ROOT::RFieldBase::Clone(std::string_view newName) const
595{
596 auto clone = CloneImpl(newName);
597 clone->fTypeAlias = fTypeAlias;
598 clone->fOnDiskId = fOnDiskId;
599 clone->fDescription = fDescription;
600 // We can just copy the references because fColumnRepresentatives point into a static structure
601 clone->fColumnRepresentatives = fColumnRepresentatives;
602 return clone;
603}
604
605std::size_t ROOT::RFieldBase::AppendImpl(const void * /* from */)
606{
607 R__ASSERT(false && "A non-simple RField must implement its own AppendImpl");
608 return 0;
609}
610
612{
613 R__ASSERT(false);
614}
615
617{
618 ReadGlobalImpl(fPrincipalColumn->GetGlobalIndex(localIndex), to);
619}
620
622{
623 const auto valueSize = GetValueSize();
624 std::size_t nRead = 0;
625 for (std::size_t i = 0; i < bulkSpec.fCount; ++i) {
626 // Value not needed
627 if (bulkSpec.fMaskReq && !bulkSpec.fMaskReq[i])
628 continue;
629
630 // Value already present
631 if (bulkSpec.fMaskAvail[i])
632 continue;
633
634 Read(bulkSpec.fFirstIndex + i, reinterpret_cast<unsigned char *>(bulkSpec.fValues) + i * valueSize);
635 bulkSpec.fMaskAvail[i] = true;
636 nRead++;
637 }
638 return nRead;
639}
640
642{
643 const auto align = GetAlignment();
644 void *where;
645 if (align <= sizeof(std::max_align_t)) {
646 // We use the normal operator new for regularly aligned types to not complicate the user code that
647 // deletes objects returned by CreateObject()
648 where = operator new(GetValueSize());
649 } else {
650 where = operator new(GetValueSize(), std::align_val_t(GetAlignment()));
651 }
652 R__ASSERT(where != nullptr);
653 ConstructValue(where);
654 return where;
655}
656
658{
659 void *obj = CreateObjectRawPtr();
660 return RValue(this, std::shared_ptr<void>(obj, RSharedPtrDeleter(GetDeleter())));
661}
662
663std::vector<ROOT::RFieldBase::RValue> ROOT::RFieldBase::SplitValue(const RValue & /*value*/) const
664{
665 return std::vector<RValue>();
666}
667
668void ROOT::RFieldBase::Attach(std::unique_ptr<ROOT::RFieldBase> child, std::string_view expectedChildName)
669{
670 // Note that technically the zero field would not need to have the extensible trait: because only its sub fields
671 // get connected by RPageSink::UpdateSchema, it does not change its initial state.
672 if (!(fTraits & kTraitExtensible) && (fState != EState::kUnconnected))
673 throw RException(R__FAIL("invalid attempt to attach subfield to already connected, non-extensible field"));
674
675 if (!expectedChildName.empty() && child->GetFieldName() != expectedChildName) {
676 throw RException(R__FAIL(std::string("invalid subfield name: ") + child->GetFieldName() +
677 " expected: " + std::string(expectedChildName)));
678 }
679
680 child->fParent = this;
681 fSubfields.emplace_back(std::move(child));
682}
683
685{
687 for (auto f = this; f != nullptr; f = f->GetParent()) {
688 auto parent = f->GetParent();
689 if (parent && (parent->GetStructure() == ROOT::ENTupleStructure::kCollection ||
690 parent->GetStructure() == ROOT::ENTupleStructure::kVariant)) {
691 return 0U;
692 }
693 result *= std::max<ROOT::NTupleSize_t>(f->GetNRepetitions(), ROOT::NTupleSize_t{1U});
694 }
695 return result;
696}
697
698std::vector<ROOT::RFieldBase *> ROOT::RFieldBase::GetMutableSubfields()
699{
700 std::vector<RFieldBase *> result;
701 result.reserve(fSubfields.size());
702 for (const auto &f : fSubfields) {
703 result.emplace_back(f.get());
704 }
705 return result;
706}
707
708std::vector<const ROOT::RFieldBase *> ROOT::RFieldBase::GetConstSubfields() const
709{
710 std::vector<const RFieldBase *> result;
711 result.reserve(fSubfields.size());
712 for (const auto &f : fSubfields) {
713 result.emplace_back(f.get());
714 }
715 return result;
716}
717
719{
720 if (!fAvailableColumns.empty()) {
721 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
722 for (auto &column : fAvailableColumns) {
723 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
724 column->Flush();
725 }
726 }
727 }
728}
729
731{
732 if (!fAvailableColumns.empty()) {
733 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
734 for (auto &column : fAvailableColumns) {
735 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
736 column->Flush();
737 } else {
738 column->CommitSuppressed();
739 }
740 }
741 }
742 CommitClusterImpl();
743}
744
746{
747 if (fState != EState::kUnconnected)
748 throw RException(R__FAIL("cannot set field description once field is connected"));
749 fDescription = std::string(description);
750}
751
753{
754 if (fState != EState::kUnconnected)
755 throw RException(R__FAIL("cannot set field ID once field is connected"));
756 fOnDiskId = id;
757}
758
759/// Write the given value into columns. The value object has to be of the same type as the field.
760/// Returns the number of uncompressed bytes written.
761std::size_t ROOT::RFieldBase::Append(const void *from)
762{
763 if (~fTraits & kTraitMappable)
764 return AppendImpl(from);
765
766 fPrincipalColumn->Append(from);
767 return fPrincipalColumn->GetElement()->GetPackedSize();
768}
769
774
776{
777 return RValue(this, objPtr);
778}
779
781{
782 if (fIsSimple) {
783 /// For simple types, ignore the mask and memcopy the values into the destination
784 fPrincipalColumn->ReadV(bulkSpec.fFirstIndex, bulkSpec.fCount, bulkSpec.fValues);
785 std::fill(bulkSpec.fMaskAvail, bulkSpec.fMaskAvail + bulkSpec.fCount, true);
786 return RBulkSpec::kAllSet;
787 }
788
789 if (fIsArtificial || !fReadCallbacks.empty()) {
790 // Fields with schema evolution treatment must not go through an optimized read
792 }
793
794 return ReadBulkImpl(bulkSpec);
795}
796
798{
799 return fSubfields.empty() ? RSchemaIterator(this, -1) : RSchemaIterator(fSubfields[0].get(), 0);
800}
801
806
808{
809 return fSubfields.empty() ? RConstSchemaIterator(this, -1) : RConstSchemaIterator(fSubfields[0].get(), 0);
810}
811
816
818{
819 return fSubfields.empty() ? RConstSchemaIterator(this, -1) : RConstSchemaIterator(fSubfields[0].get(), 0);
820}
821
826
828{
829 if (fColumnRepresentatives.empty()) {
830 return {GetColumnRepresentations().GetSerializationDefault()};
831 }
832
834 result.reserve(fColumnRepresentatives.size());
835 for (const auto &r : fColumnRepresentatives) {
836 result.emplace_back(r.get());
837 }
838 return result;
839}
840
842{
843 if (fState != EState::kUnconnected)
844 throw RException(R__FAIL("cannot set column representative once field is connected"));
845 const auto &validTypes = GetColumnRepresentations().GetSerializationTypes();
846 fColumnRepresentatives.clear();
847 fColumnRepresentatives.reserve(representatives.size());
848 for (const auto &r : representatives) {
849 auto itRepresentative = std::find(validTypes.begin(), validTypes.end(), r);
850 if (itRepresentative == std::end(validTypes))
851 throw RException(R__FAIL("invalid column representative"));
852
853 fColumnRepresentatives.emplace_back(*itRepresentative);
854 }
855}
856
859 std::uint16_t representationIndex) const
860{
861 static const ColumnRepresentation_t kEmpty;
862
863 if (fOnDiskId == ROOT::kInvalidDescriptorId)
864 throw RException(R__FAIL("No on-disk field information for `" + GetQualifiedFieldName() + "`"));
865
867 for (const auto &c : desc.GetColumnIterable(fOnDiskId)) {
868 if (c.GetRepresentationIndex() == representationIndex)
869 onDiskTypes.emplace_back(c.GetType());
870 }
871 if (onDiskTypes.empty()) {
872 if (representationIndex == 0) {
873 throw RException(R__FAIL("No on-disk column information for field `" + GetQualifiedFieldName() + "`"));
874 }
875 return kEmpty;
876 }
877
878 for (const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
879 if (t == onDiskTypes)
880 return t;
881 }
882
883 std::string columnTypeNames;
884 for (const auto &t : onDiskTypes) {
885 if (!columnTypeNames.empty())
886 columnTypeNames += ", ";
888 }
889 throw RException(R__FAIL("On-disk column types {" + columnTypeNames + "} for field `" + GetQualifiedFieldName() +
890 "` cannot be matched to its in-memory type `" + GetTypeName() + "` " +
891 "(representation index: " + std::to_string(representationIndex) + ")"));
892}
893
895{
896 fReadCallbacks.push_back(func);
897 fIsSimple = false;
898 return fReadCallbacks.size() - 1;
899}
900
902{
903 fReadCallbacks.erase(fReadCallbacks.begin() + idx);
904 fIsSimple = (fTraits & kTraitMappable) && !fIsArtificial && fReadCallbacks.empty();
905}
906
932
934{
935 if (dynamic_cast<ROOT::RFieldZero *>(this))
936 throw RException(R__FAIL("invalid attempt to connect zero field to page sink"));
937 if (fState != EState::kUnconnected)
938 throw RException(R__FAIL("invalid attempt to connect an already connected field to a page sink"));
939
940 AutoAdjustColumnTypes(pageSink.GetWriteOptions());
941
942 GenerateColumns();
943 for (auto &column : fAvailableColumns) {
944 // Only the first column of every representation can be a deferred column. In all column representations,
945 // larger column indexes are data columns of collections (string, streamer) and thus
946 // they have no elements on late model extension
947 auto firstElementIndex = (column->GetIndex() == 0) ? EntryToColumnElementIndex(firstEntry) : 0;
948 column->ConnectPageSink(fOnDiskId, pageSink, firstElementIndex);
949 }
950
951 if (HasExtraTypeInfo()) {
952 pageSink.RegisterOnCommitDatasetCallback(
953 [this](ROOT::Internal::RPageSink &sink) { sink.UpdateExtraTypeInfo(GetExtraTypeInfo()); });
954 }
955
956 fState = EState::kConnectedToSink;
957}
958
960{
961 if (dynamic_cast<ROOT::RFieldZero *>(this)) {
962 for (auto &f : fSubfields)
963 f->ConnectPageSource(pageSource);
964 return;
965 }
966
967 if (fState != EState::kUnconnected)
968 throw RException(R__FAIL("invalid attempt to connect an already connected field to a page source"));
969
970 if (!fColumnRepresentatives.empty())
971 throw RException(R__FAIL("fixed column representative only valid when connecting to a page sink"));
972 if (!fDescription.empty())
973 throw RException(R__FAIL("setting description only valid when connecting to a page sink"));
974
975 if (!fIsArtificial) {
976 R__ASSERT(fOnDiskId != kInvalidDescriptorId);
977 // Handle moving from on-disk std::atomic<T> to (compatible of) T in memory centrally because otherwise
978 // we would need to handle it in each and every ReconcileOnDiskField()
979 // Note that we have to do this before calling BeforeConnectPageSource(), which already may compare the field
980 // to its on-disk description.
981 const auto &desc = pageSource.GetSharedDescriptorGuard().GetRef();
982 if (!dynamic_cast<RAtomicField *>(this) &&
983 Internal::IsStdAtomicFieldDesc(desc.GetFieldDescriptor(GetOnDiskId()))) {
984 SetOnDiskId(desc.GetFieldDescriptor(GetOnDiskId()).GetLinkIds()[0]);
985 }
986 }
987
988 auto substitute = BeforeConnectPageSource(pageSource);
989 if (substitute) {
990 const RFieldBase *itr = this;
991 while (itr->GetParent()) {
992 itr = itr->GetParent();
993 }
994 if (typeid(*itr) == typeid(RFieldZero) && static_cast<const RFieldZero *>(itr)->GetAllowFieldSubstitutions()) {
995 for (auto &f : fParent->fSubfields) {
996 if (f.get() != this)
997 continue;
998
999 f = std::move(substitute);
1000 f->ConnectPageSource(pageSource);
1001 return;
1002 }
1003 R__ASSERT(false); // never here
1004 } else {
1005 throw RException(R__FAIL("invalid attempt to substitute field " + GetQualifiedFieldName()));
1006 }
1007 }
1008
1009 if (!fIsArtificial) {
1010 const auto &desc = pageSource.GetSharedDescriptorGuard().GetRef();
1011 ReconcileOnDiskField(desc);
1012 }
1013
1014 for (auto &f : fSubfields) {
1015 if (f->GetOnDiskId() == ROOT::kInvalidDescriptorId) {
1016 f->SetOnDiskId(pageSource.GetSharedDescriptorGuard()->FindFieldId(f->GetFieldName(), GetOnDiskId()));
1017 }
1018 f->ConnectPageSource(pageSource);
1019 }
1020
1021 // Do not generate columns nor set fColumnRepresentatives for artificial fields.
1022 if (!fIsArtificial) {
1023 const auto descriptorGuard = pageSource.GetSharedDescriptorGuard();
1024 const ROOT::RNTupleDescriptor &desc = descriptorGuard.GetRef();
1025 GenerateColumns(desc);
1026 if (fColumnRepresentatives.empty()) {
1027 // If we didn't get columns from the descriptor, ensure that we actually expect a field without columns
1028 for (const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
1029 if (t.empty()) {
1030 fColumnRepresentatives = {t};
1031 break;
1032 }
1033 }
1034 }
1035 R__ASSERT(!fColumnRepresentatives.empty());
1036 if (fOnDiskId != ROOT::kInvalidDescriptorId) {
1037 const auto &fieldDesc = desc.GetFieldDescriptor(fOnDiskId);
1038 fOnDiskTypeVersion = fieldDesc.GetTypeVersion();
1039 if (fieldDesc.GetTypeChecksum().has_value())
1040 fOnDiskTypeChecksum = *fieldDesc.GetTypeChecksum();
1041 }
1042 }
1043 for (auto &column : fAvailableColumns)
1044 column->ConnectPageSource(fOnDiskId, pageSource);
1045
1046 fState = EState::kConnectedToSource;
1047}
1048
1050{
1051 // The default implementation throws an exception if there are any meaningful differences to the on-disk field.
1052 // Derived classes may overwrite this and relax the checks to support automatic schema evolution.
1053 EnsureMatchingOnDiskField(desc).ThrowOnError();
1054}
1055
1058{
1059 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1060 const std::uint32_t diffBits = CompareOnDiskField(fieldDesc, ignoreBits);
1061 if (diffBits == 0)
1062 return RResult<void>::Success();
1063
1064 std::ostringstream errMsg;
1065 errMsg << "in-memory field " << GetQualifiedFieldName() << " of type " << GetTypeName() << " is incompatible "
1066 << "with on-disk field " << fieldDesc.GetFieldName() << ":";
1067 if (diffBits & kDiffFieldVersion) {
1068 errMsg << " field version " << GetFieldVersion() << " vs. " << fieldDesc.GetFieldVersion() << ";";
1069 }
1070 if (diffBits & kDiffTypeVersion) {
1071 errMsg << " type version " << GetTypeVersion() << " vs. " << fieldDesc.GetTypeVersion() << ";";
1072 }
1073 if (diffBits & kDiffStructure) {
1074 errMsg << " structural role " << GetStructure() << " vs. " << fieldDesc.GetStructure() << ";";
1075 }
1076 if (diffBits & kDiffTypeName) {
1077 errMsg << " incompatible on-disk type name " << fieldDesc.GetTypeName() << ";";
1078 }
1079 if (diffBits & kDiffNRepetitions) {
1080 errMsg << " repetition count " << GetNRepetitions() << " vs. " << fieldDesc.GetNRepetitions() << ";";
1081 }
1082 return R__FAIL(errMsg.str() + "\n" + Internal::GetTypeTraceReport(*this, desc));
1083}
1084
1086{
1087 std::uint32_t ignoreBits = kDiffTypeName;
1088 if (desc.GetFieldDescriptor(GetOnDiskId()).IsSoACollection())
1089 ignoreBits |= kDiffTypeVersion;
1090 return EnsureMatchingOnDiskField(desc, ignoreBits);
1091}
1092
1094 const std::vector<std::string> &prefixes) const
1095{
1096 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1097 for (const auto &p : prefixes) {
1098 if (fieldDesc.GetTypeName().rfind(p, 0) == 0)
1099 return RResult<void>::Success();
1100 }
1101 return R__FAIL("incompatible type " + fieldDesc.GetTypeName() + " for field " + GetQualifiedFieldName() + "\n" +
1102 Internal::GetTypeTraceReport(*this, desc));
1103}
1104
1106{
1107 std::uint32_t diffBits = 0;
1108 if ((~ignoreBits & kDiffFieldVersion) && (GetFieldVersion() != fieldDesc.GetFieldVersion()))
1109 diffBits |= kDiffFieldVersion;
1110 if ((~ignoreBits & kDiffTypeVersion) && (GetTypeVersion() != fieldDesc.GetTypeVersion()))
1111 diffBits |= kDiffTypeVersion;
1112 if ((~ignoreBits & kDiffStructure) && (GetStructure() != fieldDesc.GetStructure()))
1113 diffBits |= kDiffStructure;
1114 if ((~ignoreBits & kDiffTypeName) && (GetTypeName() != fieldDesc.GetTypeName()))
1115 diffBits |= kDiffTypeName;
1116 if ((~ignoreBits & kDiffNRepetitions) && (GetNRepetitions() != fieldDesc.GetNRepetitions()))
1117 diffBits |= kDiffNRepetitions;
1118
1119 return diffBits;
1120}
1121
1123{
1124 visitor.VisitField(*this);
1125}
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:301
#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:357
#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.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
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:148
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...
std::vector< const RFieldBase * > GetConstSubfields() const
void SetOnDiskId(ROOT::DescriptorId_t id)
void RemoveReadCallback(size_t idx)
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()
size_t AddReadCallback(ReadCallback_t func)
Set a user-defined function to be called after reading a value, giving a chance to inspect and/or mod...
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.
@ 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.
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.
const RFieldDescriptor & GetFieldDescriptor(ROOT::DescriptorId_t fieldId) const
RColumnDescriptorIterable GetColumnIterable() const
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:197
@ 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:2994
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::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.