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 }
51 ~CreateContextGuard()
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
80 ROOT::NTupleSize_t firstEntry)
81{
82 field.ConnectPageSink(sink, firstEntry);
83}
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
114 const Selection_t &deserializationExtraTypes)
115 : fSerializationTypes(serializationTypes), fDeserializationTypes(serializationTypes)
116{
117 fDeserializationTypes.insert(fDeserializationTypes.end(), deserializationExtraTypes.begin(),
118 deserializationExtraTypes.end());
119}
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.
127 fObjPtr = ROOT::Internal::MakeAliasedSharedPtr(rawPtr);
128}
129
130//------------------------------------------------------------------------------
131
133 : fField(other.fField),
134 fValueSize(other.fValueSize),
135 fCapacity(other.fCapacity),
136 fSize(other.fSize),
137 fIsAdopted(other.fIsAdopted),
138 fNValidValues(other.fNValidValues),
139 fFirstIndex(other.fFirstIndex)
140{
141 std::swap(fDeleter, other.fDeleter);
142 std::swap(fValues, other.fValues);
143 std::swap(fMaskAvail, other.fMaskAvail);
144}
145
147{
148 std::swap(fField, other.fField);
149 std::swap(fDeleter, other.fDeleter);
150 std::swap(fValues, other.fValues);
151 std::swap(fValueSize, other.fValueSize);
152 std::swap(fCapacity, other.fCapacity);
153 std::swap(fSize, other.fSize);
154 std::swap(fIsAdopted, other.fIsAdopted);
155 std::swap(fMaskAvail, other.fMaskAvail);
156 std::swap(fNValidValues, other.fNValidValues);
157 std::swap(fFirstIndex, other.fFirstIndex);
158 return *this;
159}
160
162{
163 if (fValues)
164 ReleaseValues();
165}
166
168{
169 if (fIsAdopted)
170 return;
171
172 if (!(fField->GetTraits() & RFieldBase::kTraitTriviallyDestructible)) {
173 for (std::size_t i = 0; i < fCapacity; ++i) {
174 fDeleter->operator()(GetValuePtrAt(i), true /* dtorOnly */);
175 }
176 }
177
178 operator delete(fValues, std::align_val_t(fField->GetAlignment()));
179}
180
182{
183 if (fCapacity < size) {
184 if (fIsAdopted) {
185 throw RException(R__FAIL("invalid attempt to bulk read beyond the adopted buffer"));
186 }
187 ReleaseValues();
188 fValues = operator new(size * fValueSize, std::align_val_t(fField->GetAlignment()));
189
190 if (!(fField->GetTraits() & RFieldBase::kTraitTriviallyConstructible)) {
191 for (std::size_t i = 0; i < size; ++i) {
192 fField->ConstructValue(GetValuePtrAt(i));
193 }
194 }
195
196 fMaskAvail = std::make_unique<bool[]>(size);
197 fCapacity = size;
198 }
199
200 std::fill(fMaskAvail.get(), fMaskAvail.get() + size, false);
201 fNValidValues = 0;
202
203 fFirstIndex = firstIndex;
204 fSize = size;
205}
206
208{
209 ReleaseValues();
210 fValues = buf;
211 fCapacity = capacity;
212 fSize = capacity;
213
214 fMaskAvail = std::make_unique<bool[]>(capacity);
215
216 fFirstIndex = RNTupleLocalIndex();
217
218 fIsAdopted = true;
219}
220
221//------------------------------------------------------------------------------
222
224{
225 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "possibly leaking object from RField<T>::CreateObject<void>";
226}
227
228template <>
229std::unique_ptr<void, typename ROOT::RFieldBase::RCreateObjectDeleter<void>::deleter>
230ROOT::RFieldBase::CreateObject<void>() const
231{
233 return std::unique_ptr<void, RCreateObjectDeleter<void>::deleter>(CreateObjectRawPtr(), gDeleter);
234}
235
236//------------------------------------------------------------------------------
237
238ROOT::RFieldBase::RFieldBase(std::string_view name, std::string_view type, ROOT::ENTupleStructure structure,
239 bool isSimple, std::size_t nRepetitions)
240 : fName(name),
241 fType(type),
242 fStructure(structure),
243 fNRepetitions(nRepetitions),
244 fIsSimple(isSimple),
245 fParent(nullptr),
246 fPrincipalColumn(nullptr),
247 fTraits(isSimple ? kTraitMappable : 0)
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{
273 RFieldZero fieldZero;
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,
295 ROOT::DescriptorId_t fieldId)
296{
299
300 const auto resolvedType = ROOT::Internal::GetCanonicalTypePrefix(TClassEdit::ResolveTypedef(typeName.c_str()));
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 }
385 auto arrayLength = ParseUIntTypeToken(arrayDef[1]);
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));
484 const auto canonicalInnerType = ROOT::Internal::GetCanonicalTypePrefix(innerTypes[0]);
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
519 if (!result) {
520 auto e = TEnum::GetEnum(resolvedType.c_str());
521 if (e != nullptr) {
522 result = std::make_unique<REnumField>(fieldName, typeName);
523 }
524 }
525
526 // If we get here then we failed to meet all the conditions to create a "properly typed" field.
527 // Resort to field emulation if the user asked us to.
528 if (!result && options.GetEmulateUnknownTypes()) {
529 assert(desc);
530 const auto &fieldDesc = desc->GetFieldDescriptor(fieldId);
531 if (fieldDesc.GetStructure() == ENTupleStructure::kStreamer) {
532 auto streamerField = std::unique_ptr<RFieldBase>(new RStreamerField(fieldName, typeName));
533 streamerField->fTypeAlias = fieldDesc.GetTypeAlias();
534 return streamerField;
535 } else if (fieldDesc.GetStructure() == ENTupleStructure::kRecord) {
536 std::vector<std::unique_ptr<RFieldBase>> memberFields;
537 memberFields.reserve(fieldDesc.GetLinkIds().size());
538 for (auto id : fieldDesc.GetLinkIds()) {
539 const auto &memberDesc = desc->GetFieldDescriptor(id);
540 auto field = Create(memberDesc.GetFieldName(), memberDesc.GetTypeName(), options, desc, id).Unwrap();
541 memberFields.emplace_back(std::move(field));
542 }
543 R__ASSERT(typeName == fieldDesc.GetTypeName());
544 auto recordField =
545 Internal::CreateEmulatedRecordField(fieldName, std::move(memberFields), fieldDesc.GetTypeName());
546 recordField->fTypeAlias = fieldDesc.GetTypeAlias();
547 return recordField;
548 } else if (fieldDesc.GetStructure() == ENTupleStructure::kCollection) {
549 if (fieldDesc.GetLinkIds().size() != 1)
550 throw ROOT::RException(R__FAIL("invalid structure for collection field " + fieldName));
551
552 auto itemFieldId = fieldDesc.GetLinkIds()[0];
553 const auto &itemFieldDesc = desc->GetFieldDescriptor(itemFieldId);
554 auto itemField =
555 Create(itemFieldDesc.GetFieldName(), itemFieldDesc.GetTypeName(), options, desc, itemFieldId).Unwrap();
556 auto vecField =
557 ROOT::Internal::CreateEmulatedVectorField(fieldName, std::move(itemField), fieldDesc.GetTypeName());
558 vecField->fTypeAlias = fieldDesc.GetTypeAlias();
559 return vecField;
560 } else if (ROOT::Internal::IsCustomEnumFieldDesc(*desc, fieldDesc)) {
561 R__ASSERT(!fieldDesc.GetLinkIds().empty());
562 auto underlyingIntFieldId = fieldDesc.GetLinkIds()[0];
563 const auto &underlyingIntFieldDesc = desc->GetFieldDescriptor(underlyingIntFieldId);
564 auto enumField = ROOT::Internal::CreateEmulatedEnumField(fieldName, fieldDesc.GetTypeName(),
565 underlyingIntFieldDesc.GetTypeName());
566 enumField->fTypeAlias = fieldDesc.GetTypeAlias();
567 return enumField;
568 }
569 }
570 } catch (const RException &e) {
571 auto error = e.GetError();
572 if (createContext.GetContinueOnError()) {
573 return std::unique_ptr<RFieldBase>(std::make_unique<RInvalidField>(fieldName, typeName, error.GetReport(),
575 } else {
576 return error;
577 }
578 } catch (const std::logic_error &e) {
579 // Integer parsing error
580 if (createContext.GetContinueOnError()) {
581 return std::unique_ptr<RFieldBase>(
582 std::make_unique<RInvalidField>(fieldName, typeName, e.what(), RInvalidField::ECategory::kGeneric));
583 } else {
584 return R__FAIL(e.what());
585 }
586 }
587
588 if (result) {
589 const auto normOrigType = ROOT::Internal::GetNormalizedUnresolvedTypeName(typeName);
590 if (normOrigType != result->GetTypeName()) {
591 result->fTypeAlias = normOrigType;
592 }
593 return result;
594 }
595 return R__FORWARD_RESULT(fnFail("unknown type: " + typeName, RInvalidField::ECategory::kUnknownType));
596}
597
599{
600 static RColumnRepresentations representations;
601 return representations;
602}
603
604std::unique_ptr<ROOT::RFieldBase> ROOT::RFieldBase::Clone(std::string_view newName) const
605{
606 auto clone = CloneImpl(newName);
607 clone->fTypeAlias = fTypeAlias;
608 clone->fOnDiskId = fOnDiskId;
609 clone->fDescription = fDescription;
610 // We can just copy the references because fColumnRepresentatives point into a static structure
611 clone->fColumnRepresentatives = fColumnRepresentatives;
612 return clone;
613}
614
615std::size_t ROOT::RFieldBase::AppendImpl(const void * /* from */)
616{
617 R__ASSERT(false && "A non-simple RField must implement its own AppendImpl");
618 return 0;
619}
620
622{
623 R__ASSERT(false);
624}
625
627{
628 ReadGlobalImpl(fPrincipalColumn->GetGlobalIndex(localIndex), to);
629}
630
631std::size_t ROOT::RFieldBase::ReadBulkImpl(const RBulkSpec &bulkSpec)
632{
633 const auto valueSize = GetValueSize();
634 std::size_t nRead = 0;
635 for (std::size_t i = 0; i < bulkSpec.fCount; ++i) {
636 // Value not needed
637 if (bulkSpec.fMaskReq && !bulkSpec.fMaskReq[i])
638 continue;
639
640 // Value already present
641 if (bulkSpec.fMaskAvail[i])
642 continue;
643
644 Read(bulkSpec.fFirstIndex + i, reinterpret_cast<unsigned char *>(bulkSpec.fValues) + i * valueSize);
645 bulkSpec.fMaskAvail[i] = true;
646 nRead++;
647 }
648 return nRead;
649}
650
652{
653 const auto align = GetAlignment();
654 void *where;
655 if (align <= sizeof(std::max_align_t)) {
656 // We use the normal operator new for regularly aligned types to not complicate the user code that
657 // deletes objects returned by CreateObject()
658 where = operator new(GetValueSize());
659 } else {
660 where = operator new(GetValueSize(), std::align_val_t(GetAlignment()));
661 }
662 R__ASSERT(where != nullptr);
663 ConstructValue(where);
664 return where;
665}
666
668{
669 void *obj = CreateObjectRawPtr();
670 return RValue(this, std::shared_ptr<void>(obj, RSharedPtrDeleter(GetDeleter())));
671}
672
673std::vector<ROOT::RFieldBase::RValue> ROOT::RFieldBase::SplitValue(const RValue & /*value*/) const
674{
675 return std::vector<RValue>();
676}
677
678void ROOT::RFieldBase::Attach(std::unique_ptr<ROOT::RFieldBase> child, std::string_view expectedChildName)
679{
680 // Note that technically the zero field would not need to have the extensible trait: because only its sub fields
681 // get connected by RPageSink::UpdateSchema, it does not change its initial state.
682 if (!(fTraits & kTraitExtensible) && (fState != EState::kUnconnected))
683 throw RException(R__FAIL("invalid attempt to attach subfield to already connected, non-extensible field"));
684
685 if (!expectedChildName.empty() && child->GetFieldName() != expectedChildName) {
686 throw RException(R__FAIL(std::string("invalid subfield name: ") + child->GetFieldName() +
687 " expected: " + std::string(expectedChildName)));
688 }
689
690 child->fParent = this;
691 fSubfields.emplace_back(std::move(child));
692}
693
695{
696 ROOT::NTupleSize_t result = globalIndex;
697 for (auto f = this; f != nullptr; f = f->GetParent()) {
698 auto parent = f->GetParent();
699 if (parent && (parent->GetStructure() == ROOT::ENTupleStructure::kCollection ||
700 parent->GetStructure() == ROOT::ENTupleStructure::kVariant)) {
701 return 0U;
702 }
703 result *= std::max<ROOT::NTupleSize_t>(f->GetNRepetitions(), ROOT::NTupleSize_t{1U});
704 }
705 return result;
706}
707
708std::vector<ROOT::RFieldBase *> ROOT::RFieldBase::GetMutableSubfields()
709{
710 std::vector<RFieldBase *> result;
711 result.reserve(fSubfields.size());
712 for (const auto &f : fSubfields) {
713 result.emplace_back(f.get());
714 }
715 return result;
716}
717
718std::vector<const ROOT::RFieldBase *> ROOT::RFieldBase::GetConstSubfields() const
719{
720 std::vector<const RFieldBase *> result;
721 result.reserve(fSubfields.size());
722 for (const auto &f : fSubfields) {
723 result.emplace_back(f.get());
724 }
725 return result;
726}
727
729{
730 if (!fAvailableColumns.empty()) {
731 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
732 for (auto &column : fAvailableColumns) {
733 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
734 column->Flush();
735 }
736 }
737 }
738}
739
741{
742 if (!fAvailableColumns.empty()) {
743 const auto activeRepresentationIndex = fPrincipalColumn->GetRepresentationIndex();
744 for (auto &column : fAvailableColumns) {
745 if (column->GetRepresentationIndex() == activeRepresentationIndex) {
746 column->Flush();
747 } else {
748 column->CommitSuppressed();
749 }
750 }
751 }
752 CommitClusterImpl();
753}
754
755void ROOT::RFieldBase::SetDescription(std::string_view description)
756{
757 if (fState != EState::kUnconnected)
758 throw RException(R__FAIL("cannot set field description once field is connected"));
759 fDescription = std::string(description);
760}
761
763{
764 if (fState != EState::kUnconnected)
765 throw RException(R__FAIL("cannot set field ID once field is connected"));
766 fOnDiskId = id;
767}
768
769/// Write the given value into columns. The value object has to be of the same type as the field.
770/// Returns the number of uncompressed bytes written.
771std::size_t ROOT::RFieldBase::Append(const void *from)
772{
773 if (~fTraits & kTraitMappable)
774 return AppendImpl(from);
775
776 fPrincipalColumn->Append(from);
777 return fPrincipalColumn->GetElement()->GetPackedSize();
778}
779
784
786{
787 return RValue(this, std::move(objPtr));
788}
789
790std::size_t ROOT::RFieldBase::ReadBulk(const RBulkSpec &bulkSpec)
791{
792 if (fIsSimple) {
793 /// For simple types, ignore the mask and memcopy the values into the destination
794 fPrincipalColumn->ReadV(bulkSpec.fFirstIndex, bulkSpec.fCount, bulkSpec.fValues);
795 std::fill(bulkSpec.fMaskAvail, bulkSpec.fMaskAvail + bulkSpec.fCount, true);
796 return RBulkSpec::kAllSet;
797 }
798
799 if (fIsArtificial || !fReadCallbacks.empty()) {
800 // Fields with schema evolution treatment must not go through an optimized read
801 return RFieldBase::ReadBulkImpl(bulkSpec);
802 }
803
804 return ReadBulkImpl(bulkSpec);
805}
806
808{
809 return fSubfields.empty() ? RSchemaIterator(this, -1) : RSchemaIterator(fSubfields[0].get(), 0);
810}
811
816
818{
819 return fSubfields.empty() ? RConstSchemaIterator(this, -1) : RConstSchemaIterator(fSubfields[0].get(), 0);
820}
821
826
828{
829 return fSubfields.empty() ? RConstSchemaIterator(this, -1) : RConstSchemaIterator(fSubfields[0].get(), 0);
830}
831
836
838{
839 if (fColumnRepresentatives.empty()) {
840 return {GetColumnRepresentations().GetSerializationDefault()};
841 }
842
844 result.reserve(fColumnRepresentatives.size());
845 for (const auto &r : fColumnRepresentatives) {
846 result.emplace_back(r.get());
847 }
848 return result;
849}
850
852{
853 if (fState != EState::kUnconnected)
854 throw RException(R__FAIL("cannot set column representative once field is connected"));
855 const auto &validTypes = GetColumnRepresentations().GetSerializationTypes();
856 fColumnRepresentatives.clear();
857 fColumnRepresentatives.reserve(representatives.size());
858 for (const auto &r : representatives) {
859 auto itRepresentative = std::find(validTypes.begin(), validTypes.end(), r);
860 if (itRepresentative == std::end(validTypes))
861 throw RException(R__FAIL("invalid column representative"));
862
863 fColumnRepresentatives.emplace_back(*itRepresentative);
864 }
865}
866
869 std::uint16_t representationIndex) const
870{
871 static const ColumnRepresentation_t kEmpty;
872
873 if (fOnDiskId == ROOT::kInvalidDescriptorId)
874 throw RException(R__FAIL("No on-disk field information for `" + GetQualifiedFieldName() + "`"));
875
876 ColumnRepresentation_t onDiskTypes;
877 for (const auto &c : desc.GetColumnIterable(fOnDiskId)) {
878 if (c.GetRepresentationIndex() == representationIndex)
879 onDiskTypes.emplace_back(c.GetType());
880 }
881 if (onDiskTypes.empty()) {
882 if (representationIndex == 0) {
883 throw RException(R__FAIL("No on-disk column information for field `" + GetQualifiedFieldName() + "`"));
884 }
885 return kEmpty;
886 }
887
888 for (const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
889 if (t == onDiskTypes)
890 return t;
891 }
892
893 std::string columnTypeNames;
894 for (const auto &t : onDiskTypes) {
895 if (!columnTypeNames.empty())
896 columnTypeNames += ", ";
897 columnTypeNames += std::string("`") + ROOT::Internal::RColumnElementBase::GetColumnTypeName(t) + "`";
898 }
899 throw RException(R__FAIL("On-disk column types {" + columnTypeNames + "} for field `" + GetQualifiedFieldName() +
900 "` cannot be matched to its in-memory type `" + GetTypeName() + "` " +
901 "(representation index: " + std::to_string(representationIndex) + ")"));
902}
903
905{
906 fReadCallbacks.push_back(func);
907 fIsSimple = false;
908 return fReadCallbacks.size() - 1;
909}
910
912{
913 fReadCallbacks.erase(fReadCallbacks.begin() + idx);
914 fIsSimple = (fTraits & kTraitMappable) && !fIsArtificial && fReadCallbacks.empty();
915}
916
918{
919 // Sampled upfront: the block below sets representatives, which would clear the "default" state.
920 const bool hadDefaultRepresentative = HasDefaultColumnRepresentative();
921 if ((options.GetCompression() == 0) && hadDefaultRepresentative) {
922 ColumnRepresentation_t rep = GetColumnRepresentations().GetSerializationDefault();
923 for (auto &colType : rep) {
924 switch (colType) {
935 default: break;
936 }
937 }
938 SetColumnRepresentatives({rep});
939 }
940
941 // Only adjust Double32_t when the user did not pin a representation: an explicit representative must
942 // survive (see RNTupleMerger::ExtendDestinationModel), otherwise merging would silently reinterpret the
943 // raw copies of the source pages under a different encoding.
944 if ((fTypeAlias == "Double32_t") && hadDefaultRepresentative) {
945 if (options.GetCompression() != 0)
946 SetColumnRepresentatives({{ROOT::ENTupleColumnType::kSplitReal32}});
947 else
948 SetColumnRepresentatives({{ROOT::ENTupleColumnType::kReal32}});
949 }
950
951 // An explicit representation pinned on a Double32_t field must contain a reduced-precision encoding:
952 // a 64-bit-only selection would store full doubles while the field promises Double32_t precision.
953 // A multi-column selection that also includes a reduced-precision representative stays legal.
954 if ((fTypeAlias == "Double32_t") && !hadDefaultRepresentative) {
955 bool hasSubDoubleRep = false;
956 for (const auto &rep : GetColumnRepresentatives()) {
957 for (const auto colType : rep) {
959 hasSubDoubleRep = true;
960 break;
961 }
962 }
963 if (hasSubDoubleRep)
964 break;
965 }
966 if (!hasSubDoubleRep) {
967 throw RException(R__FAIL("explicit column representations of Double32_t field `" + GetFieldName() +
968 "` must include a reduced-precision representation"));
969 }
970 }
971}
972
974{
975 if (dynamic_cast<ROOT::RFieldZero *>(this))
976 throw RException(R__FAIL("invalid attempt to connect zero field to page sink"));
977 if (fState != EState::kUnconnected)
978 throw RException(R__FAIL("invalid attempt to connect an already connected field to a page sink"));
979
980 AutoAdjustColumnTypes(pageSink.GetWriteOptions());
981
982 GenerateColumns();
983 for (auto &column : fAvailableColumns) {
984 // Only the first column of every representation can be a deferred column. In all column representations,
985 // larger column indexes are data columns of collections (string, streamer) and thus
986 // they have no elements on late model extension
987 auto firstElementIndex = (column->GetIndex() == 0) ? EntryToColumnElementIndex(firstEntry) : 0;
988 column->ConnectPageSink(fOnDiskId, pageSink, firstElementIndex);
989 }
990
991 if (HasExtraTypeInfo()) {
993 [this](ROOT::Internal::RPageSink &sink) { sink.UpdateExtraTypeInfo(GetExtraTypeInfo()); });
994 }
995
996 fState = EState::kConnectedToSink;
997}
998
1000{
1001 if (dynamic_cast<ROOT::RFieldZero *>(this)) {
1002 for (auto &f : fSubfields)
1003 f->ConnectPageSource(pageSource);
1004 return;
1005 }
1006
1007 if (fState != EState::kUnconnected)
1008 throw RException(R__FAIL("invalid attempt to connect an already connected field to a page source"));
1009
1010 if (!fColumnRepresentatives.empty())
1011 throw RException(R__FAIL("fixed column representative only valid when connecting to a page sink"));
1012 if (!fDescription.empty())
1013 throw RException(R__FAIL("setting description only valid when connecting to a page sink"));
1014
1015 if (!fIsArtificial) {
1016 R__ASSERT(fOnDiskId != kInvalidDescriptorId);
1017 // Handle moving from on-disk std::atomic<T> to (compatible of) T in memory centrally because otherwise
1018 // we would need to handle it in each and every ReconcileOnDiskField()
1019 // Note that we have to do this before calling BeforeConnectPageSource(), which already may compare the field
1020 // to its on-disk description.
1021 auto descGuard = pageSource.GetSharedDescriptorGuard();
1022 if (!dynamic_cast<RAtomicField *>(this) &&
1023 Internal::IsStdAtomicFieldDesc(descGuard->GetFieldDescriptor(GetOnDiskId()))) {
1024 SetOnDiskId(descGuard->GetFieldDescriptor(GetOnDiskId()).GetLinkIds()[0]);
1025 }
1026 }
1027
1028 auto substitute = BeforeConnectPageSource(pageSource);
1029 if (substitute) {
1030 const RFieldBase *itr = this;
1031 while (itr->GetParent()) {
1032 itr = itr->GetParent();
1033 }
1034 if (typeid(*itr) == typeid(RFieldZero) && static_cast<const RFieldZero *>(itr)->GetAllowFieldSubstitutions()) {
1035 for (auto &f : fParent->fSubfields) {
1036 if (f.get() != this)
1037 continue;
1038
1039 f = std::move(substitute);
1040 f->ConnectPageSource(pageSource);
1041 return;
1042 }
1043 R__ASSERT(false); // never here
1044 } else {
1045 throw RException(R__FAIL("invalid attempt to substitute field " + GetQualifiedFieldName()));
1046 }
1047 }
1048
1049 if (!fIsArtificial) {
1050 auto descGuard = pageSource.GetSharedDescriptorGuard();
1051 ReconcileOnDiskField(descGuard.GetConstRef());
1052 }
1053
1054 for (auto &f : fSubfields) {
1055 if (f->GetOnDiskId() == ROOT::kInvalidDescriptorId) {
1056 f->SetOnDiskId(pageSource.GetSharedDescriptorGuard()->FindFieldId(f->GetFieldName(), GetOnDiskId()));
1057 }
1058 f->ConnectPageSource(pageSource);
1059 }
1060
1061 // Do not generate columns nor set fColumnRepresentatives for artificial fields.
1062 if (!fIsArtificial) {
1063 const auto descriptorGuard = pageSource.GetSharedDescriptorGuard();
1064 const ROOT::RNTupleDescriptor &desc = descriptorGuard.GetConstRef();
1065 GenerateColumns(desc);
1066 if (fColumnRepresentatives.empty()) {
1067 // If we didn't get columns from the descriptor, ensure that we actually expect a field without columns
1068 for (const auto &t : GetColumnRepresentations().GetDeserializationTypes()) {
1069 if (t.empty()) {
1070 fColumnRepresentatives = {t};
1071 break;
1072 }
1073 }
1074 }
1075 R__ASSERT(!fColumnRepresentatives.empty());
1076 if (fOnDiskId != ROOT::kInvalidDescriptorId) {
1077 const auto &fieldDesc = desc.GetFieldDescriptor(fOnDiskId);
1078 fOnDiskTypeVersion = fieldDesc.GetTypeVersion();
1079 if (fieldDesc.GetTypeChecksum().has_value())
1080 fOnDiskTypeChecksum = *fieldDesc.GetTypeChecksum();
1081 }
1082 }
1083 for (auto &column : fAvailableColumns)
1084 column->ConnectPageSource(fOnDiskId, pageSource);
1085
1086 fState = EState::kConnectedToSource;
1087}
1088
1090{
1091 // The default implementation throws an exception if there are any meaningful differences to the on-disk field.
1092 // Derived classes may overwrite this and relax the checks to support automatic schema evolution.
1093 EnsureMatchingOnDiskField(desc).ThrowOnError();
1094}
1095
1097ROOT::RFieldBase::EnsureMatchingOnDiskField(const RNTupleDescriptor &desc, std::uint32_t ignoreBits) const
1098{
1099 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1100 const std::uint32_t diffBits = CompareOnDiskField(fieldDesc, ignoreBits);
1101 if (diffBits == 0)
1102 return RResult<void>::Success();
1103
1104 std::ostringstream errMsg;
1105 errMsg << "in-memory field " << GetQualifiedFieldName() << " of type " << GetTypeName() << " is incompatible "
1106 << "with on-disk field " << fieldDesc.GetFieldName() << ":";
1107 if (diffBits & kDiffFieldVersion) {
1108 errMsg << " field version " << GetFieldVersion() << " vs. " << fieldDesc.GetFieldVersion() << ";";
1109 }
1110 if (diffBits & kDiffTypeVersion) {
1111 errMsg << " type version " << GetTypeVersion() << " vs. " << fieldDesc.GetTypeVersion() << ";";
1112 }
1113 if (diffBits & kDiffStructure) {
1114 errMsg << " structural role " << GetStructure() << " vs. " << fieldDesc.GetStructure() << ";";
1115 }
1116 if (diffBits & kDiffTypeName) {
1117 errMsg << " incompatible on-disk type name " << fieldDesc.GetTypeName() << ";";
1118 }
1119 if (diffBits & kDiffNRepetitions) {
1120 errMsg << " repetition count " << GetNRepetitions() << " vs. " << fieldDesc.GetNRepetitions() << ";";
1121 }
1122 return R__FAIL(errMsg.str() + "\n" + Internal::GetTypeTraceReport(*this, desc));
1123}
1124
1126{
1127 std::uint32_t ignoreBits = kDiffTypeName;
1128 if (desc.GetFieldDescriptor(GetOnDiskId()).IsSoACollection())
1129 ignoreBits |= kDiffTypeVersion;
1130 return EnsureMatchingOnDiskField(desc, ignoreBits);
1131}
1132
1134 const std::vector<std::string> &prefixes) const
1135{
1136 const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
1137 for (const auto &p : prefixes) {
1138 if (fieldDesc.GetTypeName().rfind(p, 0) == 0)
1139 return RResult<void>::Success();
1140 }
1141 return R__FAIL("incompatible type " + fieldDesc.GetTypeName() + " for field " + GetQualifiedFieldName() + "\n" +
1142 Internal::GetTypeTraceReport(*this, desc));
1143}
1144
1145std::uint32_t ROOT::RFieldBase::CompareOnDiskField(const RFieldDescriptor &fieldDesc, std::uint32_t ignoreBits) const
1146{
1147 std::uint32_t diffBits = 0;
1148 if ((~ignoreBits & kDiffFieldVersion) && (GetFieldVersion() != fieldDesc.GetFieldVersion()))
1149 diffBits |= kDiffFieldVersion;
1150 if ((~ignoreBits & kDiffTypeVersion) && (GetTypeVersion() != fieldDesc.GetTypeVersion()))
1151 diffBits |= kDiffTypeVersion;
1152 if ((~ignoreBits & kDiffStructure) && (GetStructure() != fieldDesc.GetStructure()))
1153 diffBits |= kDiffStructure;
1154 if ((~ignoreBits & kDiffTypeName) && (GetTypeName() != fieldDesc.GetTypeName()))
1155 diffBits |= kDiffTypeName;
1156 if ((~ignoreBits & kDiffNRepetitions) && (GetNRepetitions() != fieldDesc.GetNRepetitions()))
1157 diffBits |= kDiffNRepetitions;
1158
1159 return diffBits;
1160}
1161
1163{
1164 visitor.VisitField(*this);
1165}
size_t fValueSize
dim_t fSize
#define R__FORWARD_RESULT(res)
Short-hand to return an RResult<T> value from a subroutine to the calling stack frame.
Definition RError.hxx:324
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:322
#define R__LOG_WARNING(...)
Definition RLogger.hxx:357
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
std::size_t capacity
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:139
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
Abstract base class for classes implementing the visitor design pattern.
virtual void VisitField(const ROOT::RFieldBase &field)=0
static const char * GetColumnTypeName(ROOT::ENTupleColumnType type)
Abstract interface to write data into an ntuple.
const ROOT::RNTupleWriteOptions & GetWriteOptions() const
Returns the sink's write options.
virtual void UpdateExtraTypeInfo(const ROOT::RExtraTypeInfoDescriptor &extraTypeInfo)=0
Adds an extra type information record to schema.
void RegisterOnCommitDatasetCallback(const Callback_t &cb)
The registered callback is executed at the beginning of CommitDataset();.
Abstract interface to read data from an ntuple.
RSharedDescriptorGuard GetSharedDescriptorGuard() const
Takes the read lock for the descriptor.
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
Iterates over the subtree of fields in depth-first search order.
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...
const RFieldBase * GetParent() const
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.
@ 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.
RValue CreateValue()
Generates an object of the field's type, wraps it in a shared pointer and returns it as an RValue con...
const ColumnRepresentation_t & EnsureCompatibleColumnTypes(const ROOT::RNTupleDescriptor &desc, std::uint16_t representationIndex) const
Returns the on-disk column types found in the provided descriptor for fOnDiskId and the given represe...
virtual std::vector< RValue > SplitValue(const RValue &value) const
Creates the list of direct child values given an existing value for this field.
std::string GetQualifiedFieldName() const
Returns the field name and parent field names separated by dots (grandparent.parent....
RBulkValues CreateBulk()
Creates a new, initially empty bulk.
void ConnectPageSink(ROOT::Internal::RPageSink &pageSink, ROOT::NTupleSize_t firstEntry=0)
Fields and their columns live in the void until connected to a physical page storage.
std::size_t ReadBulk(const RBulkSpec &bulkSpec)
Returns the number of newly available values, that is the number of bools in bulkSpec....
std::vector< ROOT::ENTupleColumnType > ColumnRepresentation_t
RResult< void > EnsureMatchingOnDiskField(const RNTupleDescriptor &desc, std::uint32_t ignoreBits=0) const
Compares the field to the corresponding on-disk field information in the provided descriptor.
virtual void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to)
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
virtual std::size_t AppendImpl(const void *from)
Operations on values of complex types, e.g.
RFieldBase * fParent
Subfields point to their mother field.
RFieldBase(std::string_view name, std::string_view type, ROOT::ENTupleStructure structure, bool isSimple, std::size_t nRepetitions=0)
The constructor creates the underlying column objects and connects them to either a sink or a source.
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId)
Factory method to resurrect a field from the stored on-disk type information.
std::uint32_t CompareOnDiskField(const RFieldDescriptor &fieldDesc, std::uint32_t ignoreBits) const
Returns a combination of kDiff... flags, indicating peroperties that are different between the field ...
std::string fType
The C++ type captured by this field.
RColumnRepresentations::Selection_t GetColumnRepresentatives() const
Returns the fColumnRepresentative pointee or, if unset (always the case for artificial fields),...
ROOT::ENTupleStructure fStructure
The role of this field in the data model structure.
RValue BindValue(std::shared_ptr< void > objPtr)
Creates a value from a memory location with an already constructed object.
void SetDescription(std::string_view description)
std::unique_ptr< RFieldBase > Clone(std::string_view newName) const
Copies the field and its subfields using a possibly new name and a new, unconnected set of columns.
std::string fName
The field name relative to its parent field.
void CommitCluster()
Flushes data from active columns to disk and calls CommitClusterImpl()
void ConnectPageSource(ROOT::Internal::RPageSource &pageSource)
Connects the field and its subfield tree to the given page source.
RResult< void > EnsureMatchingTypePrefix(const RNTupleDescriptor &desc, const std::vector< std::string > &prefixes) const
Many fields accept a range of type prefixes for schema evolution, e.g.
void * CreateObjectRawPtr() const
Factory method for the field's type. The caller owns the returned pointer.
virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec)
General implementation of bulk read.
Metadata stored for every field of an RNTuple.
std::uint32_t GetFieldVersion() const
ROOT::ENTupleStructure GetStructure() const
const std::vector< ROOT::DescriptorId_t > & GetLinkIds() const
std::uint64_t GetNRepetitions() const
std::uint32_t GetTypeVersion() const
const std::string & GetTypeName() const
The container field for an ntuple model, which itself has no physical representation.
Definition RField.hxx:58
void Attach(std::unique_ptr< RFieldBase > child)
A public version of the Attach method that allows piece-wise construction of the zero field.
Definition RField.cxx:40
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:342
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
ROOT::DescriptorId_t FindFieldId(std::string_view fieldName, ROOT::DescriptorId_t parentId) const
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Common user-tunable settings for storing RNTuples.
std::uint32_t GetCompression() 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
The field for a class using ROOT standard streaming.
Definition RField.hxx:245
@ kInterpreted
Definition TClass.h:129
@ kForwardDeclared
Definition TClass.h:127
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2999
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
Definition TEnum.cxx:181
std::vector< std::string > TokenizeTypeList(std::string_view templateType, std::size_t maxArgs=0)
Used in RFieldBase::Create() in order to get the comma-separated list of template types E....
std::unique_ptr< RFieldBase > CreateEmulatedVectorField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField, std::string_view emulatedFromType)
Definition RField.cxx:598
RResult< void > EnsureValidNameForRNTuple(std::string_view name, std::string_view where)
Check whether a given string is a valid name according to the RNTuple specification.
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
void CallCommitClusterOnField(RFieldBase &)
void CallConnectPageSourceOnField(RFieldBase &, ROOT::Internal::RPageSource &)
unsigned long long ParseUIntTypeToken(const std::string &uintToken)
std::unique_ptr< RFieldBase > CreateEmulatedRecordField(std::string_view fieldName, std::vector< std::unique_ptr< RFieldBase > > itemFields, std::string_view emulatedFromType)
Definition RField.cxx:590
std::string GetRNTupleSoARecord(const TClass *cl)
Checks if the "rntuple.SoARecord" class attribute is set in the dictionary.
ROOT::RResult< std::unique_ptr< ROOT::RFieldBase > > CallFieldBaseCreate(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId)
std::string GetTypeTraceReport(const RFieldBase &field, const RNTupleDescriptor &desc)
Prints the hierarchy of types with their field names and field IDs for the given in-memory field and ...
auto MakeAliasedSharedPtr(T *rawPtr)
std::string GetCanonicalTypePrefix(const std::string &typeName)
Applies RNTuple specific type name normalization rules (see specs) that help the string parsing in RF...
void CallFlushColumnsOnField(RFieldBase &)
std::unique_ptr< RFieldBase > CreateEmulatedEnumField(std::string_view fieldName, std::string_view emulatedFromType, std::string_view underlyingIntType)
bool IsCustomEnumFieldDesc(const RNTupleDescriptor &desc, const RFieldDescriptor &fieldDesc)
Tells if the field describes a user-defined enum type.
std::string GetNormalizedUnresolvedTypeName(const std::string &origName)
Applies all RNTuple type normalization rules except typedef resolution.
ERNTupleSerializationMode GetRNTupleSerializationMode(const TClass *cl)
bool IsStdAtomicFieldDesc(const RFieldDescriptor &fieldDesc)
Tells if the field describes a std::atomic<T> type.
void CallConnectPageSinkOnField(RFieldBase &, ROOT::Internal::RPageSink &, ROOT::NTupleSize_t firstEntry=0)
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
ENTupleStructure
The fields in the RNTuple data model tree can carry different structural information about the type s...
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
Input parameter to RFieldBase::ReadBulk() and RFieldBase::ReadBulkImpl().
RNTupleLocalIndex fFirstIndex
Start of the bulk range.
void * fValues
The destination area, which has to be an array of valid objects of the correct type large enough to h...
std::size_t fCount
Size of the bulk range.
bool * fMaskAvail
A bool array of size fCount, indicating the valid values in fValues.
const bool * fMaskReq
A bool array of size fCount, indicating the required values in the requested range.
Used in the return value of the Check() method.