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