Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RField.hxx
Go to the documentation of this file.
1/// \file ROOT/RField.hxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \date 2018-10-09
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_RField
14#define ROOT_RField
15
16#include <ROOT/RError.hxx>
17#include <ROOT/RFieldBase.hxx>
18#include <ROOT/RFieldUtils.hxx>
20#include <ROOT/RNTupleTypes.hxx>
21#include <ROOT/RSpan.hxx>
22#include <string_view>
23#include <ROOT/TypeTraits.hxx>
24
25#include <TGenericClassInfo.h>
26
27#include <algorithm>
28#include <array>
29#include <cstddef>
30#include <iostream>
31#include <memory>
32#include <string>
33#include <type_traits>
34#include <typeinfo>
35#include <vector>
36
37class TClass;
38class TEnum;
39class TObject;
41
42namespace ROOT {
43
44class TSchemaRule;
45class RNTupleCollectionView;
46
47namespace Detail {
48class RFieldVisitor;
49} // namespace Detail
50
51class RFieldZero;
52namespace Internal {
53void SetAllowFieldSubstitutions(RFieldZero &fieldZero, bool val);
54}
55
56/// The container field for an ntuple model, which itself has no physical representation.
57/// Therefore, the zero field must not be connected to a page source or sink.
58class RFieldZero final : public RFieldBase {
60
61 /// If field substitutions are allowed, upon connecting to a page source the field hierarchy will replace created
62 /// fields by fields that match the on-disk schema. This happens for
63 /// - Vector fields (RVectorField, RRVecField) that connect to an on-disk fixed-size array
64 /// - Streamer fields that connect to an on-disk class field
65 /// Field substitutions must not be enabled when the field hierarchy already handed out RValue objects because
66 /// they would leave dangling field pointers to the replaced fields. This is used in cases when the field/model
67 /// is created by RNTuple (not imposed), before it is made available to the user.
68 /// This flag is reset on Clone().
70
71 std::unordered_set<std::string> fSubfieldNames; ///< Efficient detection of duplicate field names
72
73protected:
74 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
75 void ConstructValue(void *) const final {}
76
77public:
78 RFieldZero();
79
80 /// A public version of the Attach method that allows piece-wise construction of the zero field.
81 /// Will throw on duplicate subfield names.
82 void Attach(std::unique_ptr<RFieldBase> child);
83 size_t GetValueSize() const final { return 0; }
84 size_t GetAlignment() const final { return 0; }
85
86 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
87
89 /// Moves all subfields into the returned vector.
90 std::vector<std::unique_ptr<RFieldBase>> ReleaseSubfields();
91};
92
93/// Used in RFieldBase::Check() to record field creation failures.
94/// Also used when deserializing a field that contains unknown values that may come from
95/// future RNTuple versions (e.g. an unknown Structure)
96class RInvalidField final : public RFieldBase {
97public:
98 enum class ECategory {
99 /// Generic unrecoverable error
100 kGeneric,
101 /// The type given to RFieldBase::Create was invalid
103 /// The type given to RFieldBase::Create was unknown
105 /// The field could not be created because its descriptor had an unknown structural role
107 };
108
109private:
110 std::string fError;
112
113protected:
114 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final
115 {
116 return std::make_unique<RInvalidField>(newName, GetTypeName(), fError, fCategory);
117 }
118 void ConstructValue(void *) const final {}
119
120public:
121 RInvalidField(std::string_view name, std::string_view type, std::string_view error, ECategory category)
122 : RFieldBase(name, type, ROOT::ENTupleStructure::kPlain, false /* isSimple */), fError(error), fCategory(category)
123 {
125 }
126
127 const std::string &GetError() const { return fError; }
128 ECategory GetCategory() const { return fCategory; }
129
130 size_t GetValueSize() const final { return 0; }
131 size_t GetAlignment() const final { return 0; }
132}; // RInvalidField
133
134/// Base class for fields that are subject to I/O customization rules. Used by the class field and the SoA field.
135class RRuleField : public RFieldBase {
136protected:
137 // The read rule function receives a pointer to the in-memory object
138 using RuleFunc_t = std::function<void(void *)>;
139
140 // Information to read into the staging area a field that is used as an input to an I/O customization rule
142 /// The field used to read the on-disk data. The fields type may be different from the on-disk type as long
143 /// as the on-disk type can be converted to the fields type (through type cast / schema evolution).
144 std::unique_ptr<RFieldBase> fField;
145 std::size_t fOffset; ///< offset in fStagingArea
146 };
147 /// Prefix used in the subfield names generated for base classes
148 static constexpr const char *kPrefixInherited{":"};
149
150 /// Set by derived class to the TClass instance representing the current in-memory layout.
151 TClass *fClass = nullptr;
152
153 /// The staging area stores inputs to I/O rules according to the offsets given by the streamer info of
154 /// "TypeName@@Version". The area is allocated depending on I/O rules resp. the source members of the I/O rules.
155 std::unique_ptr<unsigned char[]> fStagingArea;
156 /// The TClass instance that corresponds to the staging area.
157 /// The staging class exists as <class name>@@<on-disk version> if the on-disk version is different from the
158 /// current in-memory version, or it can be accessed by the first @@alloc streamer element of the current streamer
159 /// info.
161 std::unordered_map<std::string, RStagingItem> fStagingItems; ///< Lookup staging items by member name
162
163 /// List of functions to be called after reading a value
164 std::vector<RuleFunc_t> fRuleFuncs;
165
166 RRuleField(std::string_view name, std::string_view type, TClass *classp, ROOT::ENTupleStructure structure);
167
168 /// Returns the id of member 'name' in the class field given by 'fieldId', or kInvalidDescriptorId if no such
169 /// member exist. Looks recursively in base classes.
170 ROOT::DescriptorId_t LookupMember(const ROOT::RNTupleDescriptor &desc, std::string_view memberName,
171 ROOT::DescriptorId_t classFieldId) const;
172 /// Sets fStagingClass according to the given name and version
173 void SetStagingClass(const std::string &className, unsigned int classVersion);
174 /// If there are rules with inputs (source members), create the staging area according to the TClass instance
175 /// that corresponds to the on-disk field.
176 void PrepareStagingArea(const std::vector<const TSchemaRule *> &rules, const ROOT::RNTupleDescriptor &desc,
177 const ROOT::RFieldDescriptor &classFieldId);
178 /// Register post-read functions corresponding to a ROOT I/O customization rules.
179 /// The sub object offset allows to apply the rule to a nested object within the passed target.
180 /// This is used to execute rules on base classes and nested classes in a SoA field.
181 void AddFuncsFromIORule(const TSchemaRule *rule, std::size_t subObjectOffset = 0);
182 /// Apply the I/O rules to the provided in-memory object
183 void InvokeRuleFuncs(void *target);
184 /// Given the on-disk information from the page source, find all the I/O customization rules that apply
185 /// to the class field at hand, to which the fieldDesc descriptor, if provided, must correspond.
186 /// Fields may not have an on-disk representation (e.g., when inserted by schema evolution), in which case the passed
187 /// field descriptor is nullptr.
188 std::vector<const TSchemaRule *> FindRules(const ROOT::RFieldDescriptor *fieldDesc) const;
189
190 bool HasReadCallbacks() const final { return !fRuleFuncs.empty(); }
191};
192
193/// The field for a class with dictionary
194class RClassField : public RRuleField {
195private:
202 std::size_t fOffset;
203 };
204
205 class RClassDeleter : public RDeleter {
206 private:
208
209 public:
210 explicit RClassDeleter(TClass *cl);
211 void operator()(void *objPtr, bool dtorOnly) final;
212 };
213
214 /// Additional information kept for each entry in `fSubfields`
215 std::vector<RSubfieldInfo> fSubfieldsInfo;
216
217private:
218 RClassField(std::string_view fieldName, const RClassField &source); ///< Used by CloneImpl
219 RClassField(std::string_view fieldName, TClass *classp);
220 void Attach(std::unique_ptr<RFieldBase> child, RSubfieldInfo info);
221
222protected:
223 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
224
225 void ConstructValue(void *where) const final;
226 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RClassDeleter>(fClass); }
227
228 std::size_t AppendImpl(const void *from) final;
229 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
230 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final;
231
232 std::unique_ptr<RFieldBase> BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final;
233 void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
234
235public:
236 RClassField(std::string_view fieldName, std::string_view className);
237 RClassField(RClassField &&other) = default;
238 RClassField &operator=(RClassField &&other) = default;
239 ~RClassField() override;
240
241 std::vector<RValue> SplitValue(const RValue &value) const final;
242 std::size_t GetValueSize() const final;
243 std::size_t GetAlignment() const final;
244 std::uint32_t GetTypeVersion() const final;
245 std::uint32_t GetTypeChecksum() const final;
246 /// For polymorphic classes (that declare or inherit at least one virtual method), return the expected dynamic type
247 /// of any user object. If the class is not polymorphic, return nullptr.
248 const std::type_info *GetPolymorphicTypeInfo() const;
249 /// Return the TClass instance backing this field.
250 const TClass *GetClass() const { return fClass; }
251 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
252};
253
254/// The field for a class using ROOT standard streaming
255class RStreamerField final : public RFieldBase {
256private:
258 private:
260
261 public:
262 explicit RStreamerFieldDeleter(TClass *cl);
263 void operator()(void *objPtr, bool dtorOnly) final;
264 };
265
266 TClass *fClass = nullptr;
267 ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t fStreamerInfos; ///< streamer info records seen during writing
268 ROOT::Internal::RColumnIndex fIndex; ///< number of bytes written in the current cluster
269
270private:
271 RStreamerField(std::string_view fieldName, TClass *classp);
272
273protected:
274 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
275
277 void GenerateColumns() final;
278 void GenerateColumns(const ROOT::RNTupleDescriptor &) final;
279
280 void ConstructValue(void *where) const final;
281 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RStreamerFieldDeleter>(fClass); }
282
283 std::size_t AppendImpl(const void *from) final;
284 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
285
286 void CommitClusterImpl() final { fIndex = 0; }
287
288 bool HasExtraTypeInfo() const final { return true; }
289 // Returns the list of seen streamer infos
291
292 std::unique_ptr<RFieldBase> BeforeConnectPageSource(ROOT::Internal::RPageSource &source) final;
293 void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
294
295public:
296 RStreamerField(std::string_view fieldName, std::string_view className);
297 RStreamerField(RStreamerField &&other) = default;
298 RStreamerField &operator=(RStreamerField &&other) = default;
299 ~RStreamerField() final = default;
300
301 size_t GetValueSize() const final;
302 size_t GetAlignment() const final;
303 std::uint32_t GetTypeVersion() const final;
304 std::uint32_t GetTypeChecksum() const final;
305 TClass *GetClass() const { return fClass; }
306 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
307};
308
309namespace Internal {
310std::unique_ptr<RFieldBase> CreateEmulatedEnumField(std::string_view fieldName, std::string_view emulatedFromType,
311 std::string_view underlyingIntType);
312}
313
314/// The field for an unscoped or scoped enum with dictionary
315class REnumField : public RFieldBase {
316 friend std::unique_ptr<RFieldBase> Internal::CreateEmulatedEnumField(std::string_view fieldName,
317 std::string_view emulatedFromType,
318 std::string_view underlyingIntType);
319
320private:
321 REnumField(std::string_view fieldName, TEnum *enump);
322 // Used by CloneImpl()
323 REnumField(std::string_view fieldName, std::string_view enumName, std::unique_ptr<RFieldBase> intField);
324 // Used by field emulation
325 REnumField(std::string_view fieldName, std::string_view emulatedFromType, std::string_view underlyingIntType);
326
327protected:
328 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
329
330 void ConstructValue(void *where) const final { CallConstructValueOn(*fSubfields[0], where); }
331
332 std::size_t AppendImpl(const void *from) final { return CallAppendOn(*fSubfields[0], from); }
333 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final { CallReadOn(*fSubfields[0], globalIndex, to); }
334 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final { CallReadOn(*fSubfields[0], localIndex, to); }
335
336 void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
337
338public:
339 REnumField(std::string_view fieldName, std::string_view enumName);
340 REnumField(REnumField &&other) = default;
341 REnumField &operator=(REnumField &&other) = default;
342 ~REnumField() override = default;
343
344 std::vector<RValue> SplitValue(const RValue &value) const final;
345 size_t GetValueSize() const final { return fSubfields[0]->GetValueSize(); }
346 size_t GetAlignment() const final { return fSubfields[0]->GetAlignment(); }
347 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
348};
349
350/// Classes with dictionaries that can be inspected by TClass
351template <typename T, typename = void>
352class RField final : public RClassField {
353public:
354 static std::string TypeName() { return ROOT::Internal::GetRenormalizedTypeName(typeid(T)); }
355 RField(std::string_view name) : RClassField(name, Internal::GetDemangledTypeName(typeid(T)))
356 {
357 static_assert(std::is_class_v<T>, "no I/O support for this basic C++ type");
358 }
359 RField(RField &&other) = default;
360 RField &operator=(RField &&other) = default;
361 ~RField() final = default;
362};
363
364template <typename T>
365class RField<T, typename std::enable_if<std::is_enum_v<T>>::type> final : public REnumField {
366public:
367 static std::string TypeName() { return ROOT::Internal::GetRenormalizedTypeName(typeid(T)); }
368 RField(std::string_view name) : REnumField(name, TypeName()) {}
369 RField(RField &&other) = default;
370 RField &operator=(RField &&other) = default;
371 ~RField() final = default;
372};
373
374/// An artificial field that transforms an RNTuple column that contains the offset of collections into
375/// collection sizes. It is only used for reading, e.g. as projected field or as an artificial field that provides the
376/// "number of" RDF columns for collections (e.g. `R_rdf_sizeof_jets` for a collection named `jets`).
377/// It is used in the templated RField<RNTupleCardinality<SizeT>> form, which represents the collection sizes either
378/// as 32bit unsigned int (std::uint32_t) or as 64bit unsigned int (std::uint64_t).
380 friend class ROOT::RNTupleCollectionView; // to access GetCollectionInfo()
381
382private:
384 {
385 fPrincipalColumn->ForReading()->GetCollectionInfo(globalIndex, collectionStart, size);
386 }
388 {
389 fPrincipalColumn->ForReading()->GetCollectionInfo(localIndex, collectionStart, size);
390 }
391
392protected:
393 RCardinalityField(std::string_view fieldName, std::string_view typeName)
394 : RFieldBase(fieldName, typeName, ROOT::ENTupleStructure::kPlain, false /* isSimple */)
395 {
396 }
397
398 const RColumnRepresentations &GetColumnRepresentations() const final;
399 // Field is only used for reading
400 void GenerateColumns() final { throw RException(R__FAIL("Cardinality fields must only be used for reading")); }
401 void GenerateColumns(const ROOT::RNTupleDescriptor &) final;
402
403 void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
404
405public:
408 ~RCardinalityField() override = default;
409
410 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
411
412 const RField<RNTupleCardinality<std::uint32_t>> *As32Bit() const;
413 const RField<RNTupleCardinality<std::uint64_t>> *As64Bit() const;
414};
415
416template <typename T>
417class RSimpleField : public RFieldBase {
418 void ReconcileIntegralField(const RNTupleDescriptor &desc);
419 void ReconcileFloatingPointField(const RNTupleDescriptor &desc);
420
421protected:
422 void GenerateColumns() override { GenerateColumnsImpl<T>(); }
423 void GenerateColumns(const ROOT::RNTupleDescriptor &desc) override { GenerateColumnsImpl<T>(desc); }
424
425 void ConstructValue(void *where) const final { new (where) T{0}; }
426
427 void ReconcileOnDiskField(const RNTupleDescriptor &desc) override
428 {
429 if constexpr (std::is_integral_v<T>) {
430 ReconcileIntegralField(desc);
431 } else if constexpr (std::is_floating_point_v<T>) {
432 ReconcileFloatingPointField(desc);
433 } else {
434 RFieldBase::ReconcileOnDiskField(desc);
435 }
436 }
437
438 RSimpleField(std::string_view name, std::string_view type)
439 : RFieldBase(name, type, ROOT::ENTupleStructure::kPlain, true /* isSimple */)
440 {
441 fTraits |= kTraitTrivialType;
442 }
443
444public:
445 RSimpleField(RSimpleField &&other) = default;
447 ~RSimpleField() override = default;
448
449 T *Map(ROOT::NTupleSize_t globalIndex) { return fPrincipalColumn->ForReading()->Map<T>(globalIndex); }
450 T *Map(RNTupleLocalIndex localIndex) { return fPrincipalColumn->ForReading()->Map<T>(localIndex); }
452 {
453 return fPrincipalColumn->ForReading()->MapV<T>(globalIndex, nItems);
454 }
456 {
457 return fPrincipalColumn->ForReading()->MapV<T>(localIndex, nItems);
458 }
459
460 size_t GetValueSize() const final { return sizeof(T); }
461 size_t GetAlignment() const final { return alignof(T); }
462};
463
464////////////////////////////////////////////////////////////////////////////////
465/// Template specializations for concrete C++ types
466////////////////////////////////////////////////////////////////////////////////
467
468} // namespace ROOT
469
474#include "RField/RFieldSoA.hxx"
476
477namespace ROOT {
478
479template <typename SizeT>
480class RField<RNTupleCardinality<SizeT>> final : public RCardinalityField {
482
483protected:
484 std::unique_ptr<ROOT::RFieldBase> CloneImpl(std::string_view newName) const final
485 {
486 return std::make_unique<RField>(newName);
487 }
488 void ConstructValue(void *where) const final { new (where) CardinalityType(0); }
489
490 /// Get the number of elements of the collection identified by globalIndex
491 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
492 {
493 RNTupleLocalIndex collectionStart;
495 fPrincipalColumn->ForReading()->GetCollectionInfo(globalIndex, &collectionStart, &size);
496 *static_cast<CardinalityType *>(to) = size;
497 }
498
499 /// Get the number of elements of the collection identified by clusterIndex
500 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
501 {
502 RNTupleLocalIndex collectionStart;
504 fPrincipalColumn->ForReading()->GetCollectionInfo(localIndex, &collectionStart, &size);
505 *static_cast<CardinalityType *>(to) = size;
506 }
507
508 std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec) final
509 {
510 RNTupleLocalIndex collectionStart;
511 ROOT::NTupleSize_t collectionSize;
512 fPrincipalColumn->ForReading()->GetCollectionInfo(bulkSpec.fFirstIndex, &collectionStart, &collectionSize);
513
514 auto typedValues = static_cast<CardinalityType *>(bulkSpec.fValues);
515 typedValues[0] = collectionSize;
516
517 auto lastOffset = collectionStart.GetIndexInCluster() + collectionSize;
518 ROOT::NTupleSize_t nRemainingEntries = bulkSpec.fCount - 1;
519 std::size_t nEntries = 1;
520 while (nRemainingEntries > 0) {
521 ROOT::NTupleSize_t nItemsUntilPageEnd;
523 bulkSpec.fFirstIndex + nEntries, nItemsUntilPageEnd);
524 std::size_t nBatch = std::min(nRemainingEntries, nItemsUntilPageEnd);
525 for (std::size_t i = 0; i < nBatch; ++i) {
526 typedValues[nEntries + i] = offsets[i] - lastOffset;
527 lastOffset = offsets[i];
528 }
529 nRemainingEntries -= nBatch;
530 nEntries += nBatch;
531 }
532 return RBulkSpec::kAllSet;
533 }
534
535public:
536 static std::string TypeName() { return "ROOT::RNTupleCardinality<" + RField<SizeT>::TypeName() + ">"; }
537 explicit RField(std::string_view name) : RCardinalityField(name, TypeName()) {}
538 RField(RField &&other) = default;
539 RField &operator=(RField &&other) = default;
540 ~RField() final = default;
541
542 size_t GetValueSize() const final { return sizeof(CardinalityType); }
543 size_t GetAlignment() const final { return alignof(CardinalityType); }
544};
545
546/// TObject requires special handling of the fBits and fUniqueID members
547template <>
548class RField<TObject> final : public RFieldBase {
549 static std::size_t GetOffsetOfMember(const char *name);
550 static std::size_t GetOffsetUniqueID() { return GetOffsetOfMember("fUniqueID"); }
551 static std::size_t GetOffsetBits() { return GetOffsetOfMember("fBits"); }
552
553private:
554 RField(std::string_view fieldName, const RField<TObject> &source); ///< Used by CloneImpl()
555
556protected:
557 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
558
559 void ConstructValue(void *where) const final;
560 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RTypedDeleter<TObject>>(); }
561
562 std::size_t AppendImpl(const void *from) final;
563 void ReadTObject(void *to, UInt_t uniqueID, UInt_t bits);
564 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
565 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final;
566
567public:
568 static std::string TypeName() { return "TObject"; }
569
570 RField(std::string_view fieldName);
571 RField(RField &&other) = default;
572 RField &operator=(RField &&other) = default;
573 ~RField() final = default;
574
575 std::vector<RValue> SplitValue(const RValue &value) const final;
576 size_t GetValueSize() const final;
577 size_t GetAlignment() const final;
578 std::uint32_t GetTypeVersion() const final;
579 std::uint32_t GetTypeChecksum() const final;
580 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
581};
582
583// Have to be implemented after the definition of all RField<T> types
584
585namespace Internal {
586
587/// Helper to check if a given type name is the one expected of Field<T>. Usually, this check can be done by
588/// type renormalization of the demangled type name T. The failure case, however, needs to additionally check for
589/// ROOT-specific special cases.
590template <class T>
591bool IsMatchingFieldType(const std::string &actualTypeName)
592{
593 return IsMatchingFieldType(actualTypeName, ROOT::RField<T>::TypeName(), typeid(T));
594}
595
596} // namespace Internal
597
598template <typename T>
599std::unique_ptr<T, typename RFieldBase::RCreateObjectDeleter<T>::deleter> RFieldBase::CreateObject() const
600{
601 if (!Internal::IsMatchingFieldType<T>(GetTypeName())) {
602 throw RException(
603 R__FAIL("type mismatch for field " + GetFieldName() + ": " + GetTypeName() + " vs. " + RField<T>::TypeName()));
604 }
605 return std::unique_ptr<T>(static_cast<T *>(CreateObjectRawPtr()));
606}
607
608// The void type is specialized in RField.cxx
609
610template <>
613 void operator()(void *);
614};
615
616template <>
617std::unique_ptr<void, typename RFieldBase::RCreateObjectDeleter<void>::deleter>
618ROOT::RFieldBase::CreateObject<void>() const;
619
620} // namespace ROOT
621
622#endif
std::string className
Definition JSONIO.cxx:31
#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
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
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 target
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.
The in-memory representation of a 32bit or 64bit on-disk index column.
RReadColumn * ForReading()
Definition RColumn.hxx:411
std::map< Int_t, TVirtualStreamerInfo * > StreamerInfoMap_t
Abstract interface to read data from an ntuple.
void GetCollectionInfo(const ROOT::NTupleSize_t globalIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *collectionSize)
For offset columns only, look at the two adjacent values that define a collection's coordinates.
Definition RColumn.hxx:254
CppT * MapV(const ROOT::NTupleSize_t globalIndex, ROOT::NTupleSize_t &nItems)
Definition RColumn.hxx:212
An artificial field that transforms an RNTuple column that contains the offset of collections into co...
Definition RField.hxx:379
RCardinalityField(RCardinalityField &&other)=default
void GetCollectionInfo(ROOT::NTupleSize_t globalIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size)
Definition RField.hxx:383
RCardinalityField & operator=(RCardinalityField &&other)=default
void GetCollectionInfo(RNTupleLocalIndex localIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size)
Definition RField.hxx:387
~RCardinalityField() override=default
RCardinalityField(std::string_view fieldName, std::string_view typeName)
Definition RField.hxx:393
void operator()(void *objPtr, bool dtorOnly) final
The field for a class with dictionary.
Definition RField.hxx:194
const TClass * GetClass() const
Return the TClass instance backing this field.
Definition RField.hxx:250
std::unique_ptr< RFieldBase > BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate,...
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
RClassField(RClassField &&other)=default
std::size_t GetAlignment() const final
What alignof(T) for this type returns.
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::vector< RSubfieldInfo > fSubfieldsInfo
Additional information kept for each entry in fSubfields
Definition RField.hxx:215
void Attach(std::unique_ptr< RFieldBase > child, RSubfieldInfo info)
RClassField & operator=(RClassField &&other)=default
std::size_t GetValueSize() const final
What sizeof(T) for this type returns.
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
std::uint32_t GetTypeVersion() const final
Indicates an evolution of the C++ type itself.
RClassField(std::string_view fieldName, const RClassField &source)
Used by CloneImpl.
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
const std::type_info * GetPolymorphicTypeInfo() const
For polymorphic classes (that declare or inherit at least one virtual method), return the expected dy...
~RClassField() override
std::uint32_t GetTypeChecksum() const final
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
std::unique_ptr< RDeleter > GetDeleter() const final
Definition RField.hxx:226
The field for an unscoped or scoped enum with dictionary.
Definition RField.hxx:315
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
size_t GetValueSize() const final
What sizeof(T) for this type returns.
Definition RField.hxx:345
size_t GetAlignment() const final
What alignof(T) for this type returns.
Definition RField.hxx:346
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
~REnumField() override=default
REnumField(REnumField &&other)=default
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
Definition RField.hxx:330
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
Definition RField.hxx:334
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
Definition RField.hxx:333
REnumField & operator=(REnumField &&other)=default
REnumField(std::string_view fieldName, TEnum *enump)
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
Definition RField.hxx:332
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Field specific extra type information from the header / extenstion header.
The list of column representations a field can have.
A functor to release the memory acquired by CreateValue() (memory and constructor).
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
A field translates read and write calls from/to underlying columns to/from tree values.
ROOT::Internal::RColumn * fPrincipalColumn
All fields that have columns have a distinct main column.
std::vector< std::unique_ptr< RFieldBase > > fSubfields
Collections and classes own subfields.
std::unique_ptr< T, typename RCreateObjectDeleter< T >::deleter > CreateObject() const
Generates an object of the field type and allocates new initialized memory according to the type.
Definition RField.hxx:599
const std::string & GetFieldName() const
@ kTraitInvalidField
This field is an instance of RInvalidField and can be safely static_cast to it.
static std::size_t CallAppendOn(RFieldBase &other, const void *from)
Allow derived classes to call Append() and Read() on other (sub)fields.
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
const std::string & GetTypeName() const
static void CallReadOn(RFieldBase &other, RNTupleLocalIndex localIndex, void *to)
static void CallConstructValueOn(const RFieldBase &other, void *where)
Allow derived classes to call ConstructValue(void *) and GetDeleter() on other (sub)fields.
void * CreateObjectRawPtr() const
Factory method for the field's type. The caller owns the returned pointer.
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
std::unordered_set< std::string > fSubfieldNames
Efficient detection of duplicate field names.
Definition RField.hxx:71
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
Definition RField.cxx:73
size_t GetValueSize() const final
What sizeof(T) for this type returns.
Definition RField.hxx:83
bool GetAllowFieldSubstitutions() const
Definition RField.hxx:88
void ConstructValue(void *) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
Definition RField.hxx:75
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
Definition RField.cxx:54
size_t GetAlignment() const final
What alignof(T) for this type returns.
Definition RField.hxx:84
std::vector< std::unique_ptr< RFieldBase > > ReleaseSubfields()
Moves all subfields into the returned vector.
Definition RField.cxx:64
bool fAllowFieldSubstitutions
If field substitutions are allowed, upon connecting to a page source the field hierarchy will replace...
Definition RField.hxx:69
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
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
Get the number of elements of the collection identified by globalIndex.
Definition RField.hxx:491
RField & operator=(RField &&other)=default
std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec) final
General implementation of bulk read.
Definition RField.hxx:508
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
Definition RField.hxx:488
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
Get the number of elements of the collection identified by clusterIndex.
Definition RField.hxx:500
std::unique_ptr< ROOT::RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
Definition RField.hxx:484
size_t GetAlignment() const final
What alignof(T) for this type returns.
Definition RField.hxx:543
RField(RField &&other)=default
RField & operator=(RField &&other)=default
~RField() final=default
static std::string TypeName()
Definition RField.hxx:568
std::unique_ptr< RDeleter > GetDeleter() const final
Definition RField.hxx:560
static std::size_t GetOffsetBits()
Definition RField.hxx:551
static std::size_t GetOffsetUniqueID()
Definition RField.hxx:550
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:352
~RField() final=default
RField(RField &&other)=default
RField & operator=(RField &&other)=default
static std::string TypeName()
Definition RField.hxx:354
RField(std::string_view name)
Definition RField.hxx:355
Used in RFieldBase::Check() to record field creation failures.
Definition RField.hxx:96
RInvalidField(std::string_view name, std::string_view type, std::string_view error, ECategory category)
Definition RField.hxx:121
@ kGeneric
Generic unrecoverable error.
@ kUnknownType
The type given to RFieldBase::Create was unknown.
@ kTypeError
The type given to RFieldBase::Create was invalid.
@ kUnknownStructure
The field could not be created because its descriptor had an unknown structural role.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
Definition RField.hxx:114
ECategory fCategory
Definition RField.hxx:111
size_t GetAlignment() const final
What alignof(T) for this type returns.
Definition RField.hxx:131
std::string fError
Definition RField.hxx:110
const std::string & GetError() const
Definition RField.hxx:127
ECategory GetCategory() const
Definition RField.hxx:128
size_t GetValueSize() const final
What sizeof(T) for this type returns.
Definition RField.hxx:130
void ConstructValue(void *) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
Definition RField.hxx:118
A view for a collection, that can itself generate new ntuple views for its nested fields.
The on-storage metadata of an RNTuple.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
ROOT::NTupleSize_t GetIndexInCluster() const
Base class for fields that are subject to I/O customization rules. Used by the class field and the So...
Definition RField.hxx:135
std::vector< const TSchemaRule * > FindRules(const ROOT::RFieldDescriptor *fieldDesc) const
Given the on-disk information from the page source, find all the I/O customization rules that apply t...
static constexpr const char * kPrefixInherited
Prefix used in the subfield names generated for base classes.
Definition RField.hxx:148
std::unique_ptr< unsigned char[]> fStagingArea
The staging area stores inputs to I/O rules according to the offsets given by the streamer info of "T...
Definition RField.hxx:155
ROOT::DescriptorId_t LookupMember(const ROOT::RNTupleDescriptor &desc, std::string_view memberName, ROOT::DescriptorId_t classFieldId) const
Returns the id of member 'name' in the class field given by 'fieldId', or kInvalidDescriptorId if no ...
TClass * fStagingClass
The TClass instance that corresponds to the staging area.
Definition RField.hxx:160
void AddFuncsFromIORule(const TSchemaRule *rule, std::size_t subObjectOffset=0)
Register post-read functions corresponding to a ROOT I/O customization rules.
std::unordered_map< std::string, RStagingItem > fStagingItems
Lookup staging items by member name.
Definition RField.hxx:161
RRuleField(std::string_view name, std::string_view type, TClass *classp, ROOT::ENTupleStructure structure)
std::function< void(void *)> RuleFunc_t
Definition RField.hxx:138
void PrepareStagingArea(const std::vector< const TSchemaRule * > &rules, const ROOT::RNTupleDescriptor &desc, const ROOT::RFieldDescriptor &classFieldId)
If there are rules with inputs (source members), create the staging area according to the TClass inst...
std::vector< RuleFunc_t > fRuleFuncs
List of functions to be called after reading a value.
Definition RField.hxx:164
bool HasReadCallbacks() const final
Definition RField.hxx:190
TClass * fClass
Set by derived class to the TClass instance representing the current in-memory layout.
Definition RField.hxx:151
void InvokeRuleFuncs(void *target)
Apply the I/O rules to the provided in-memory object.
void SetStagingClass(const std::string &className, unsigned int classVersion)
Sets fStagingClass according to the given name and version.
void GenerateColumns() override
Implementations in derived classes should create the backing columns corresponding to the field type ...
Definition RField.hxx:422
size_t GetAlignment() const final
What alignof(T) for this type returns.
Definition RField.hxx:461
RSimpleField & operator=(RSimpleField &&other)=default
RSimpleField(std::string_view name, std::string_view type)
Definition RField.hxx:438
T * Map(RNTupleLocalIndex localIndex)
Definition RField.hxx:450
~RSimpleField() override=default
T * Map(ROOT::NTupleSize_t globalIndex)
Definition RField.hxx:449
size_t GetValueSize() const final
What sizeof(T) for this type returns.
Definition RField.hxx:460
void ReconcileOnDiskField(const RNTupleDescriptor &desc) override
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
Definition RField.hxx:427
RSimpleField(RSimpleField &&other)=default
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
Definition RField.hxx:425
T * MapV(ROOT::NTupleSize_t globalIndex, ROOT::NTupleSize_t &nItems)
Definition RField.hxx:451
void GenerateColumns(const ROOT::RNTupleDescriptor &desc) override
Implementations in derived classes should create the backing columns corresponding to the field type ...
Definition RField.hxx:423
T * MapV(RNTupleLocalIndex localIndex, ROOT::NTupleSize_t &nItems)
Definition RField.hxx:455
void operator()(void *objPtr, bool dtorOnly) final
The field for a class using ROOT standard streaming.
Definition RField.hxx:255
ROOT::RExtraTypeInfoDescriptor GetExtraTypeInfo() const final
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t fStreamerInfos
streamer info records seen during writing
Definition RField.hxx:267
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
std::uint32_t GetTypeVersion() const final
Indicates an evolution of the C++ type itself.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
ROOT::Internal::RColumnIndex fIndex
number of bytes written in the current cluster
Definition RField.hxx:268
std::uint32_t GetTypeChecksum() const final
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
std::unique_ptr< RFieldBase > BeforeConnectPageSource(ROOT::Internal::RPageSource &source) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate,...
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
bool HasExtraTypeInfo() const final
Definition RField.hxx:288
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
void CommitClusterImpl() final
Definition RField.hxx:286
RStreamerField(std::string_view fieldName, TClass *classp)
size_t GetAlignment() const final
What alignof(T) for this type returns.
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
std::unique_ptr< RDeleter > GetDeleter() const final
Definition RField.hxx:281
TClass * GetClass() const
Definition RField.hxx:305
size_t GetValueSize() const final
What sizeof(T) for this type returns.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
The TEnum class implements the enum type.
Definition TEnum.h:33
Mother of all ROOT objects.
Definition TObject.h:42
Abstract Interface class describing Streamer information for one class.
void SetAllowFieldSubstitutions(RFieldZero &fieldZero, bool val)
Definition RField.cxx:35
std::unique_ptr< RFieldBase > CreateEmulatedEnumField(std::string_view fieldName, std::string_view emulatedFromType, std::string_view underlyingIntType)
bool IsMatchingFieldType(const std::string &actualTypeName)
Helper to check if a given type name is the one expected of Field<T>.
Definition RField.hxx:591
std::string GetRenormalizedTypeName(const std::string &metaNormalizedName)
Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
std::string GetDemangledTypeName(const std::type_info &t)
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.
ENTupleStructure
The fields in the RNTuple data model tree can carry different structural information about the type s...
Input parameter to RFieldBase::ReadBulk() and RFieldBase::ReadBulkImpl().
Helper types to present an offset column as array of collection sizes.
std::unique_ptr< RFieldBase > fField
The field used to read the on-disk data.
Definition RField.hxx:144
std::size_t fOffset
offset in fStagingArea
Definition RField.hxx:145