Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFieldBase.cxx
Go to the documentation of this file.
1/// \file RFieldBase.cxx
2/// \ingroup NTuple
3/// \author Jonas Hahnfeld <jonas.hahnfeld@cern.ch>
4/// \date 2024-11-19
5
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 // A single representations with an empty set of columns
104}
105
113
114//------------------------------------------------------------------------------
115
117{
118 // Set fObjPtr to an aliased shared_ptr of the input raw pointer. Note that
119 // fObjPtr will be non-empty but have use count zero.
121}
122
123//------------------------------------------------------------------------------
124
126 : fField(other.fField),
128 fCapacity(other.fCapacity),
130 fIsAdopted(other.fIsAdopted),
131 fNValidValues(other.fNValidValues),
132 fFirstIndex(other.fFirstIndex)
133{
134 std::swap(fDeleter, other.fDeleter);
135 std::swap(fValues, other.fValues);
136 std::swap(fMaskAvail, other.fMaskAvail);
137}
138
140{
141 std::swap(fField, other.fField);
142 std::swap(fDeleter, other.fDeleter);
143 std::swap(fValues, other.fValues);
144 std::swap(fValueSize, other.fValueSize);
145 std::swap(fCapacity, other.fCapacity);
146 std::swap(fSize, other.fSize);
147 std::swap(fIsAdopted, other.fIsAdopted);
148 std::swap(fMaskAvail, other.fMaskAvail);
149 std::swap(fNValidValues, other.fNValidValues);
150 std::swap(fFirstIndex, other.fFirstIndex);
151 return *this;
152}
153
155{
156 if (fValues)
157 ReleaseValues();
158}
159
161{
162 if (fIsAdopted)
163 return;
164
165 if (!(fField->GetTraits() & RFieldBase::kTraitTriviallyDestructible)) {
166 for (std::size_t i = 0; i < fCapacity; ++i) {
167 fDeleter->operator()(GetValuePtrAt(i), true /* dtorOnly */);
168 }
169 }
170
171 operator delete(fValues);
172}
173
175{
176 if (fCapacity < size) {
177 if (fIsAdopted) {
178 throw RException(R__FAIL("invalid attempt to bulk read beyond the adopted buffer"));
179 }
180 ReleaseValues();
181 fValues = operator new(size * fValueSize);
182
183 if (!(fField->GetTraits() & RFieldBase::kTraitTriviallyConstructible)) {
184 for (std::size_t i = 0; i < size; ++i) {
185 fField->ConstructValue(GetValuePtrAt(i));
186 }
187 }
188
189 fMaskAvail = std::make_unique<bool[]>(size);
190 fCapacity = size;
191 }
192
193 std::fill(fMaskAvail.get(), fMaskAvail.get() + size, false);
194 fNValidValues = 0;
195
196 fFirstIndex = firstIndex;
197 fSize = size;
198}
199
201{
202 fNValidValues = 0;
203 for (std::size_t i = 0; i < fSize; ++i)
204 fNValidValues += static_cast<std::size_t>(fMaskAvail[i]);
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 auto normalizedInnerTypeName = itemField->GetTypeName();
422 result = std::make_unique<RUniquePtrField>(fieldName, "std::unique_ptr<" + normalizedInnerTypeName + ">",
423 std::move(itemField));
424 } else if (resolvedType.substr(0, 14) == "std::optional<") {
425 std::string itemTypeName = resolvedType.substr(14, resolvedType.length() - 15);
426 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
427 auto normalizedInnerTypeName = itemField->GetTypeName();
428 result = std::make_unique<ROptionalField>(fieldName, "std::optional<" + normalizedInnerTypeName + ">",
429 std::move(itemField));
430 } else if (resolvedType.substr(0, 9) == "std::set<") {
431 std::string itemTypeName = resolvedType.substr(9, resolvedType.length() - 10);
432 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
433 auto normalizedInnerTypeName = itemField->GetTypeName();
434 result =
435 std::make_unique<RSetField>(fieldName, "std::set<" + normalizedInnerTypeName + ">", std::move(itemField));
436 } else if (resolvedType.substr(0, 19) == "std::unordered_set<") {
437 std::string itemTypeName = resolvedType.substr(19, resolvedType.length() - 20);
438 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
439 auto normalizedInnerTypeName = itemField->GetTypeName();
440 result = std::make_unique<RSetField>(fieldName, "std::unordered_set<" + normalizedInnerTypeName + ">",
441 std::move(itemField));
442 } else if (resolvedType.substr(0, 14) == "std::multiset<") {
443 std::string itemTypeName = resolvedType.substr(14, resolvedType.length() - 15);
444 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
445 auto normalizedInnerTypeName = itemField->GetTypeName();
446 result = std::make_unique<RSetField>(fieldName, "std::multiset<" + normalizedInnerTypeName + ">",
447 std::move(itemField));
448 } else if (resolvedType.substr(0, 24) == "std::unordered_multiset<") {
449 std::string itemTypeName = resolvedType.substr(24, resolvedType.length() - 25);
450 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
451 auto normalizedInnerTypeName = itemField->GetTypeName();
452 result = std::make_unique<RSetField>(fieldName, "std::unordered_multiset<" + normalizedInnerTypeName + ">",
453 std::move(itemField));
454 } else if (resolvedType.substr(0, 9) == "std::map<") {
455 auto innerTypes = TokenizeTypeList(resolvedType.substr(9, resolvedType.length() - 10));
456 if (innerTypes.size() != 2) {
457 return R__FORWARD_RESULT(fnFail("the type list for std::map must have exactly two elements"));
458 }
459
460 auto itemField =
461 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
462 .Unwrap();
463
464 // We use the type names of subfields of the newly created item fields to create the map's type name to
465 // ensure the inner type names are properly normalized.
466 auto keyTypeName = itemField->GetConstSubfields()[0]->GetTypeName();
467 auto valueTypeName = itemField->GetConstSubfields()[1]->GetTypeName();
468
469 result = std::make_unique<RMapField>(fieldName, "std::map<" + keyTypeName + "," + valueTypeName + ">",
470 std::move(itemField));
471 } else if (resolvedType.substr(0, 19) == "std::unordered_map<") {
472 auto innerTypes = TokenizeTypeList(resolvedType.substr(19, resolvedType.length() - 20));
473 if (innerTypes.size() != 2)
474 return R__FORWARD_RESULT(fnFail("the type list for std::unordered_map must have exactly two elements"));
475
476 auto itemField =
477 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
478 .Unwrap();
479
480 // We use the type names of subfields of the newly created item fields to create the map's type name to
481 // ensure the inner type names are properly normalized.
482 auto keyTypeName = itemField->GetConstSubfields()[0]->GetTypeName();
483 auto valueTypeName = itemField->GetConstSubfields()[1]->GetTypeName();
484
485 result = std::make_unique<RMapField>(
486 fieldName, "std::unordered_map<" + keyTypeName + "," + valueTypeName + ">", std::move(itemField));
487 } else if (resolvedType.substr(0, 14) == "std::multimap<") {
488 auto innerTypes = TokenizeTypeList(resolvedType.substr(14, resolvedType.length() - 15));
489 if (innerTypes.size() != 2)
490 return R__FORWARD_RESULT(fnFail("the type list for std::multimap must have exactly two elements"));
491
492 auto itemField =
493 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
494 .Unwrap();
495
496 // We use the type names of subfields of the newly created item fields to create the map's type name to
497 // ensure the inner type names are properly normalized.
498 auto keyTypeName = itemField->GetConstSubfields()[0]->GetTypeName();
499 auto valueTypeName = itemField->GetConstSubfields()[1]->GetTypeName();
500
501 result = std::make_unique<RMapField>(fieldName, "std::multimap<" + keyTypeName + "," + valueTypeName + ">",
502 std::move(itemField));
503 } else if (resolvedType.substr(0, 24) == "std::unordered_multimap<") {
504 auto innerTypes = TokenizeTypeList(resolvedType.substr(24, resolvedType.length() - 25));
505 if (innerTypes.size() != 2)
506 return R__FORWARD_RESULT(
507 fnFail("the type list for std::unordered_multimap must have exactly two elements"));
508
509 auto itemField =
510 Create("_0", "std::pair<" + innerTypes[0] + "," + innerTypes[1] + ">", options, desc, maybeGetChildId(0))
511 .Unwrap();
512
513 // We use the type names of subfields of the newly created item fields to create the map's type name to
514 // ensure the inner type names are properly normalized.
515 auto keyTypeName = itemField->GetConstSubfields()[0]->GetTypeName();
516 auto valueTypeName = itemField->GetConstSubfields()[1]->GetTypeName();
517
518 result = std::make_unique<RMapField>(
519 fieldName, "std::unordered_multimap<" + keyTypeName + "," + valueTypeName + ">", std::move(itemField));
520 } else if (resolvedType.substr(0, 12) == "std::atomic<") {
521 std::string itemTypeName = resolvedType.substr(12, resolvedType.length() - 13);
522 auto itemField = Create("_0", itemTypeName, options, desc, maybeGetChildId(0)).Unwrap();
523 auto normalizedInnerTypeName = itemField->GetTypeName();
524 result = std::make_unique<RAtomicField>(fieldName, "std::atomic<" + normalizedInnerTypeName + ">",
525 std::move(itemField));
526 } else if (resolvedType.substr(0, 25) == "ROOT::RNTupleCardinality<") {
527 auto innerTypes = TokenizeTypeList(resolvedType.substr(25, resolvedType.length() - 26));
528 if (innerTypes.size() != 1)
529 return R__FORWARD_RESULT(fnFail("invalid cardinality template: " + resolvedType));
531 if (canonicalInnerType == "std::uint32_t") {
532 result = std::make_unique<RField<RNTupleCardinality<std::uint32_t>>>(fieldName);
533 } else if (canonicalInnerType == "std::uint64_t") {
534 result = std::make_unique<RField<RNTupleCardinality<std::uint64_t>>>(fieldName);
535 } else {
536 return R__FORWARD_RESULT(fnFail("invalid cardinality template: " + resolvedType));
537 }
538 }
539
540 if (!result) {
541 auto e = TEnum::GetEnum(resolvedType.c_str());
542 if (e != nullptr) {
543 result = std::make_unique<REnumField>(fieldName, typeName);
544 }
545 }
546
547 if (!result) {
548 auto cl = TClass::GetClass(typeName.c_str());
549
550 if (cl && cl->GetState() > TClass::kForwardDeclared) {
551 createContextGuard.AddClassToStack(resolvedType);
552 if (cl->GetCollectionProxy()) {
553 result = std::make_unique<RProxiedCollectionField>(fieldName, typeName);
554 }
555 // NOTE: if the class is not at least "Interpreted" we currently don't try to construct
556 // the RClassField, as in that case we'd need to fetch the information from the StreamerInfo
557 // rather than from TClass. This might be desirable in the future, but for now in this
558 // situation we rely on field emulation instead.
559 else if (cl->GetState() >= TClass::kInterpreted) {
562 result = std::make_unique<RStreamerField>(fieldName, typeName);
563 } else {
564 result = std::make_unique<RClassField>(fieldName, typeName);
565 }
566 }
567 }
568
569 // If we get here then we failed to meet all the conditions to create a "properly typed" field.
570 // Resort to field emulation if the user asked us to.
571 if (!result && options.GetEmulateUnknownTypes()) {
572 assert(desc);
573 const auto &fieldDesc = desc->GetFieldDescriptor(fieldId);
574 if (fieldDesc.GetStructure() == ENTupleStructure::kRecord) {
575 std::vector<std::unique_ptr<RFieldBase>> memberFields;
576 memberFields.reserve(fieldDesc.GetLinkIds().size());
577 for (auto id : fieldDesc.GetLinkIds()) {
578 const auto &memberDesc = desc->GetFieldDescriptor(id);
579 auto field = Create(memberDesc.GetFieldName(), memberDesc.GetTypeName(), options, desc, id).Unwrap();
580 memberFields.emplace_back(std::move(field));
581 }
582 R__ASSERT(typeName == fieldDesc.GetTypeName());
583 auto recordField =
585 recordField->fTypeAlias = fieldDesc.GetTypeAlias();
586 return recordField;
587 } else if (fieldDesc.GetStructure() == ENTupleStructure::kCollection) {
588 if (fieldDesc.GetLinkIds().size() != 1)
589 throw ROOT::RException(R__FAIL("invalid structure for collection field " + fieldName));
590
591 auto itemFieldId = fieldDesc.GetLinkIds()[0];
592 const auto &itemFieldDesc = desc->GetFieldDescriptor(itemFieldId);
593 auto itemField =
594 Create(itemFieldDesc.GetFieldName(), itemFieldDesc.GetTypeName(), options, desc, itemFieldId)
595 .Unwrap();
596 auto vecField =
598 vecField->fTypeAlias = fieldDesc.GetTypeAlias();
599 return vecField;
600 }
601 }
602 }
603 } catch (const RException &e) {
604 auto error = e.GetError();
605 if (createContext.GetContinueOnError()) {
606 return std::unique_ptr<RFieldBase>(std::make_unique<RInvalidField>(fieldName, typeName, error.GetReport(),
608 } else {
609 return error;
610 }
611 } catch (const std::logic_error &e) {
612 // Integer parsing error
613 if (createContext.GetContinueOnError()) {
614 return std::unique_ptr<RFieldBase>(
615 std::make_unique<RInvalidField>(fieldName, typeName, e.what(), RInvalidField::ECategory::kGeneric));
616 } else {
617 return R__FAIL(e.what());
618 }
619 }
620
621 if (result) {
623 if (normOrigType != result->GetTypeName()) {
624 result->fTypeAlias = normOrigType;
625 }
626 return result;
627 }
628 return R__FORWARD_RESULT(fnFail("unknown type: " + typeName, RInvalidField::ECategory::kUnknownType));
629}
630
636
637std::unique_ptr<ROOT::RFieldBase> ROOT::RFieldBase::Clone(std::string_view newName) const
638{
639 auto clone = CloneImpl(newName);
640 clone->fTypeAlias = fTypeAlias;
641 clone->fOnDiskId = fOnDiskId;
642 clone->fDescription = fDescription;
643 // We can just copy the references because fColumnRepresentatives point into a static structure
644 clone->fColumnRepresentatives = fColumnRepresentatives;
645 return clone;
646}
647
648std::size_t ROOT::RFieldBase::AppendImpl(const void * /* from */)
649{
650 R__ASSERT(false && "A non-simple RField must implement its own AppendImpl");
651 return 0;
652}
653
655{
656 R__ASSERT(false);
657}
658
660{
661 ReadGlobalImpl(fPrincipalColumn->GetGlobalIndex(localIndex), to);
662}
663
665{
666 const auto valueSize = GetValueSize();
667 std::size_t nRead = 0;
668 for (std::size_t i = 0; i < bulkSpec.fCount; ++i) {
669 // Value not needed
670 if (bulkSpec.fMaskReq && !bulkSpec.fMaskReq[i])
671 continue;
672
673 // Value already present
674 if (bulkSpec.fMaskAvail[i])
675 continue;
676
677 Read(bulkSpec.fFirstIndex + i, reinterpret_cast<unsigned char *>(bulkSpec.fValues) + i * valueSize);
678 bulkSpec.fMaskAvail[i] = true;
679 nRead++;
680 }
681 return nRead;
682}
683
685{
686 void *where = operator new(GetValueSize());
687 R__ASSERT(where != nullptr);
688 ConstructValue(where);
689 return where;
690}
691
693{
694 void *obj = CreateObjectRawPtr();
695 return RValue(this, std::shared_ptr<void>(obj, RSharedPtrDeleter(GetDeleter())));
696}
697
698std::vector<ROOT::RFieldBase::RValue> ROOT::RFieldBase::SplitValue(const RValue & /*value*/) const
699{
700 return std::vector<RValue>();
701}
702
703void ROOT::RFieldBase::Attach(std::unique_ptr<ROOT::RFieldBase> child)
704{
705 // Note that during a model update, new fields will be attached to the zero field. The zero field, however,
706 // does not change its inital state because only its sub fields get connected by RPageSink::UpdateSchema.
707 if (fState != EState::kUnconnected)
708 throw RException(R__FAIL("invalid attempt to attach subfield to already connected field"));
709 child->fParent = this;
710 fSubfields.emplace_back(std::move(child));
711}
712
714{
715 std::size_t result = globalIndex;
716 for (auto f = this; f != nullptr; f = f->GetParent()) {
717 auto parent = f->GetParent();
718 if (parent && (parent->GetStructure() == ROOT::ENTupleStructure::kCollection ||
719 parent->GetStructure() == ROOT::ENTupleStructure::kVariant)) {
720 return 0U;
721 }
722 result *= std::max(f->GetNRepetitions(), std::size_t{1U});
723 }
724 return result;
725}
726
727std::vector<ROOT::RFieldBase *> ROOT::RFieldBase::GetMutableSubfields()
728{
729 std::vector<RFieldBase *> result;
730 result.reserve(fSubfields.size());
731 for (const auto &f : fSubfields) {
732 result.emplace_back(f.get());
733 }
734 return result;
735}
736
737std::vector<const ROOT::RFieldBase *> ROOT::RFieldBase::GetConstSubfields() const
738{
739 std::vector<const RFieldBase *> result;
740 result.reserve(fSubfields.size());
741 for (const auto &f : fSubfields) {
742 result.emplace_back(f.get());
743 }
744 return result;
745}
746
748{
749 if (!fAvailableColumns.empty()) {
750 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
751 for (auto &column : fAvailableColumns) {
752 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
753 column->Flush();
754 }
755 }
756 }
757}
758
760{
761 if (!fAvailableColumns.empty()) {
762 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
763 for (auto &column : fAvailableColumns) {
764 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
765 column->Flush();
766 } else {
767 column->CommitSuppressed();
768 }
769 }
770 }
771 CommitClusterImpl();
772}
773
775{
776 if (fState != EState::kUnconnected)
777 throw RException(R__FAIL("cannot set field description once field is connected"));
778 fDescription = std::string(description);
779}
780
782{
783 if (fState != EState::kUnconnected)
784 throw RException(R__FAIL("cannot set field ID once field is connected"));
785 fOnDiskId = id;
786}
787
788/// Write the given value into columns. The value object has to be of the same type as the field.
789/// Returns the number of uncompressed bytes written.
790std::size_t ROOT::RFieldBase::Append(const void *from)
791{
792 if (~fTraits & kTraitMappable)
793 return AppendImpl(from);
794
795 fPrincipalColumn->Append(from);
796 return fPrincipalColumn->GetElement()->GetPackedSize();
797}
798
803
805{
806 return RValue(this, objPtr);
807}
808
810{
811 if (fIsSimple) {
812 /// For simple types, ignore the mask and memcopy the values into the destination
813 fPrincipalColumn->ReadV(bulkSpec.fFirstIndex, bulkSpec.fCount, bulkSpec.fValues);
814 std::fill(bulkSpec.fMaskAvail, bulkSpec.fMaskAvail + bulkSpec.fCount, true);
815 return RBulkSpec::kAllSet;
816 }
817
818 if (fIsArtificial || !fReadCallbacks.empty()) {
819 // Fields with schema evolution treatment must not go through an optimized read
821 }
822
823 return ReadBulkImpl(bulkSpec);
824}
825
827{
828 return fSubfields.empty() ? RSchemaIterator(this, -1) : RSchemaIterator(fSubfields[0].get(), 0);
829}
830
835
837{
838 return fSubfields.empty() ? RConstSchemaIterator(this, -1) : RConstSchemaIterator(fSubfields[0].get(), 0);
839}
840
845
847{
848 return fSubfields.empty() ? RConstSchemaIterator(this, -1) : RConstSchemaIterator(fSubfields[0].get(), 0);
849}
850
855
857{
858 if (fColumnRepresentatives.empty()) {
859 return {GetColumnRepresentations().GetSerializationDefault()};
860 }
861
863 result.reserve(fColumnRepresentatives.size());
864 for (const auto &r : fColumnRepresentatives) {
865 result.emplace_back(r.get());
866 }
867 return result;
868}
869
871{
872 if (fState != EState::kUnconnected)
873 throw RException(R__FAIL("cannot set column representative once field is connected"));
874 const auto &validTypes = GetColumnRepresentations().GetSerializationTypes();
875 fColumnRepresentatives.clear();
876 fColumnRepresentatives.reserve(representatives.size());
877 for (const auto &r : representatives) {
878 auto itRepresentative = std::find(validTypes.begin(), validTypes.end(), r);
879 if (itRepresentative == std::end(validTypes))
880 throw RException(R__FAIL("invalid column representative"));
881
882 // don't add a duplicate representation
883 if (std::find_if(fColumnRepresentatives.begin(), fColumnRepresentatives.end(),
884 [&r](const auto &rep) { return r == rep.get(); }) == fColumnRepresentatives.end())
885 fColumnRepresentatives.emplace_back(*itRepresentative);
886 }
887}
888
891 std::uint16_t representationIndex) const
892{
893 static const ColumnRepresentation_t kEmpty;
894
895 if (fOnDiskId == ROOT::kInvalidDescriptorId)
896 throw RException(R__FAIL("No on-disk field information for `" + GetQualifiedFieldName() + "`"));
897
899 for (const auto &c : desc.GetColumnIterable(fOnDiskId)) {
900 if (c.GetRepresentationIndex() == representationIndex)
901 onDiskTypes.emplace_back(c.GetType());
902 }
903 if (onDiskTypes.empty()) {
904 if (representationIndex == 0) {
905 throw RException(R__FAIL("No on-disk column information for field `" + GetQualifiedFieldName() + "`"));
906 }
907 return kEmpty;
908 }
909
910 for (const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
911 if (t == onDiskTypes)
912 return t;
913 }
914
915 std::string columnTypeNames;
916 for (const auto &t : onDiskTypes) {
917 if (!columnTypeNames.empty())
918 columnTypeNames += ", ";
920 }
921 throw RException(R__FAIL("On-disk column types {" + columnTypeNames + "} for field `" + GetQualifiedFieldName() +
922 "` cannot be matched to its in-memory type `" + GetTypeName() + "` " +
923 "(representation index: " + std::to_string(representationIndex) + ")"));
924}
925
927{
928 fReadCallbacks.push_back(func);
929 fIsSimple = false;
930 return fReadCallbacks.size() - 1;
931}
932
934{
935 fReadCallbacks.erase(fReadCallbacks.begin() + idx);
936 fIsSimple = (fTraits & kTraitMappable) && !fIsArtificial && fReadCallbacks.empty();
937}
938
964
966{
967 if (dynamic_cast<ROOT::RFieldZero *>(this))
968 throw RException(R__FAIL("invalid attempt to connect zero field to page sink"));
969 if (fState != EState::kUnconnected)
970 throw RException(R__FAIL("invalid attempt to connect an already connected field to a page sink"));
971
972 AutoAdjustColumnTypes(pageSink.GetWriteOptions());
973
974 GenerateColumns();
975 for (auto &column : fAvailableColumns) {
976 // Only the first column of every representation can be a deferred column. In all column representations,
977 // larger column indexes are data columns of collections (string, streamer) and thus
978 // they have no elements on late model extension
979 auto firstElementIndex = (column->GetIndex() == 0) ? EntryToColumnElementIndex(firstEntry) : 0;
980 column->ConnectPageSink(fOnDiskId, pageSink, firstElementIndex);
981 }
982
983 if (HasExtraTypeInfo()) {
984 pageSink.RegisterOnCommitDatasetCallback(
985 [this](ROOT::Internal::RPageSink &sink) { sink.UpdateExtraTypeInfo(GetExtraTypeInfo()); });
986 }
987
988 fState = EState::kConnectedToSink;
989}
990
992{
993 if (dynamic_cast<ROOT::RFieldZero *>(this))
994 throw RException(R__FAIL("invalid attempt to connect zero field to page source"));
995 if (fState != EState::kUnconnected)
996 throw RException(R__FAIL("invalid attempt to connect an already connected field to a page source"));
997
998 if (!fColumnRepresentatives.empty())
999 throw RException(R__FAIL("fixed column representative only valid when connecting to a page sink"));
1000 if (!fDescription.empty())
1001 throw RException(R__FAIL("setting description only valid when connecting to a page sink"));
1002
1003 BeforeConnectPageSource(pageSource);
1004
1005 if (!fIsArtificial) {
1006 R__ASSERT(fOnDiskId != kInvalidDescriptorId);
1007 ReconcileOnDiskField(pageSource.GetSharedDescriptorGuard().GetRef());
1008 }
1009
1010 for (auto &f : fSubfields) {
1011 if (f->GetOnDiskId() == ROOT::kInvalidDescriptorId) {
1012 f->SetOnDiskId(pageSource.GetSharedDescriptorGuard()->FindFieldId(f->GetFieldName(), GetOnDiskId()));
1013 }
1014 f->ConnectPageSource(pageSource);
1015 }
1016
1017 // Do not generate columns nor set fColumnRepresentatives for artificial fields.
1018 if (!fIsArtificial) {
1019 const auto descriptorGuard = pageSource.GetSharedDescriptorGuard();
1020 const ROOT::RNTupleDescriptor &desc = descriptorGuard.GetRef();
1021 GenerateColumns(desc);
1022 if (fColumnRepresentatives.empty()) {
1023 // If we didn't get columns from the descriptor, ensure that we actually expect a field without columns
1024 for (const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
1025 if (t.empty()) {
1026 fColumnRepresentatives = {t};
1027 break;
1028 }
1029 }
1030 }
1031 R__ASSERT(!fColumnRepresentatives.empty());
1032 if (fOnDiskId != ROOT::kInvalidDescriptorId) {
1033 const auto &fieldDesc = desc.GetFieldDescriptor(fOnDiskId);
1034 fOnDiskTypeVersion = fieldDesc.GetTypeVersion();
1035 if (fieldDesc.GetTypeChecksum().has_value())
1036 fOnDiskTypeChecksum = *fieldDesc.GetTypeChecksum();
1037 }
1038 }
1039 for (auto &column : fAvailableColumns)
1040 column->ConnectPageSource(fOnDiskId, pageSource);
1041
1042 fState = EState::kConnectedToSource;
1043}
1044
1046{
1047 // The default implementation throws an exception if the on-disk ID is set and there are any meaningful differences
1048 // to the on-disk field. Derived classes may overwrite this and relax the checks to support automatic schema
1049 // evolution.
1050 EnsureMatchingOnDiskField(desc.GetFieldDescriptor(fOnDiskId));
1051}
1052
1054{
1055 const std::uint32_t diffBits = CompareOnDiskField(fieldDesc, ignoreBits);
1056 if (diffBits == 0)
1057 return;
1058
1059 std::ostringstream errMsg;
1060 errMsg << "in-memory field " << GetQualifiedFieldName() << " of type " << GetTypeName() << " is incompatible "
1061 << "with on-disk field " << fieldDesc.GetFieldName() << ":";
1062 if (diffBits & kDiffFieldVersion) {
1063 errMsg << " field version " << GetFieldVersion() << " vs. " << fieldDesc.GetFieldVersion() << ";";
1064 }
1065 if (diffBits & kDiffTypeVersion) {
1066 errMsg << " type version " << GetTypeVersion() << " vs. " << fieldDesc.GetTypeVersion() << ";";
1067 }
1068 if (diffBits & kDiffStructure) {
1069 errMsg << " structural role " << GetStructure() << " vs. " << fieldDesc.GetStructure() << ";";
1070 }
1071 if (diffBits & kDiffTypeName) {
1072 errMsg << " incompatible on-disk type name " << fieldDesc.GetTypeName() << ";";
1073 }
1074 if (diffBits & kDiffNRepetitions) {
1075 errMsg << " repetition count " << GetNRepetitions() << " vs. " << fieldDesc.GetNRepetitions() << ";";
1076 }
1077 throw RException(R__FAIL(errMsg.str()));
1078}
1079
1081 const std::vector<std::string> &prefixes) const
1082{
1083 for (const auto &p : prefixes) {
1084 if (fieldDesc.GetTypeName().rfind(p, 0) == 0)
1085 return;
1086 }
1087 throw RException(R__FAIL("incompatible type " + fieldDesc.GetTypeName() + " for field " + GetQualifiedFieldName()));
1088}
1089
1091{
1092 std::uint32_t diffBits = 0;
1093 if ((~ignoreBits & kDiffFieldVersion) && (GetFieldVersion() != fieldDesc.GetFieldVersion()))
1094 diffBits |= kDiffFieldVersion;
1095 if ((~ignoreBits & kDiffTypeVersion) && (GetTypeVersion() != fieldDesc.GetTypeVersion()))
1096 diffBits |= kDiffTypeVersion;
1097 if ((~ignoreBits & kDiffStructure) && (GetStructure() != fieldDesc.GetStructure()))
1098 diffBits |= kDiffStructure;
1099 if ((~ignoreBits & kDiffTypeName) && (GetTypeName() != fieldDesc.GetTypeName()))
1100 diffBits |= kDiffTypeName;
1101 if ((~ignoreBits & kDiffNRepetitions) && (GetNRepetitions() != fieldDesc.GetNRepetitions()))
1102 diffBits |= kDiffNRepetitions;
1103
1104 return diffBits;
1105}
1106
1108{
1109 visitor.VisitField(*this);
1110}
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:302
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:300
#define R__LOG_WARNING(...)
Definition RLogger.hxx:358
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#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:110
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.
Base class for all ROOT issued exceptions.
Definition RError.hxx:79
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.
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 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 and vice versa.
void Attach(std::unique_ptr< RFieldBase > child)
Add a new subfield to the list of nested fields.
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...
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
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.
void EnsureMatchingTypePrefix(const RFieldDescriptor &fieldDesc, const std::vector< std::string > &prefixes) const
Many fields accept a range of type prefixes for schema evolution, e.g.
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),...
void EnsureMatchingOnDiskField(const RFieldDescriptor &fieldDesc, std::uint32_t ignoreBits=0) const
Compares the field to the provieded on-disk field descriptor.
@ 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.
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.
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:54
Used in RFieldBase::Check() to record field creation failures.
Definition RField.hxx:72
@ 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:198
@ 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:2973
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:537
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:529
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)
ERNTupleSerializationMode GetRNTupleSerializationMode(TClass *cl)
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.
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.