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;
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
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/// The field for a class with dictionary
135class RClassField : public RFieldBase {
136private:
143 std::size_t fOffset;
144 };
145 // Information to read into the staging area a field that is used as an input to an I/O customization rule
147 /// The field used to read the on-disk data. The fields type may be different from the on-disk type as long
148 /// as the on-disk type can be converted to the fields type (through type cast / schema evolution).
149 std::unique_ptr<RFieldBase> fField;
150 std::size_t fOffset; ///< offset in fStagingArea
151 };
152 /// Prefix used in the subfield names generated for base classes
153 static constexpr const char *kPrefixInherited{":"};
154
155 class RClassDeleter : public RDeleter {
156 private:
158
159 public:
160 explicit RClassDeleter(TClass *cl) : fClass(cl) {}
161 void operator()(void *objPtr, bool dtorOnly) final;
162 };
163
165 /// Additional information kept for each entry in `fSubfields`
166 std::vector<RSubfieldInfo> fSubfieldsInfo;
167 std::size_t fMaxAlignment = 1;
168
169 /// The staging area stores inputs to I/O rules according to the offsets given by the streamer info of
170 /// "TypeName@@Version". The area is allocated depending on I/O rules resp. the source members of the I/O rules.
171 std::unique_ptr<unsigned char[]> fStagingArea;
172 /// The TClass instance that corresponds to the staging area.
173 /// The staging class exists as <class name>@@<on-disk version> if the on-disk version is different from the
174 /// current in-memory version, or it can be accessed by the first @@alloc streamer element of the current streamer
175 /// info.
177 std::unordered_map<std::string, RStagingItem> fStagingItems; ///< Lookup staging items by member name
178
179private:
180 RClassField(std::string_view fieldName, const RClassField &source); ///< Used by CloneImpl
181 RClassField(std::string_view fieldName, TClass *classp);
182 void Attach(std::unique_ptr<RFieldBase> child, RSubfieldInfo info);
183
184 /// Returns the id of member 'name' in the class field given by 'fieldId', or kInvalidDescriptorId if no such
185 /// member exist. Looks recursively in base classes.
187 LookupMember(const ROOT::RNTupleDescriptor &desc, std::string_view memberName, ROOT::DescriptorId_t classFieldId);
188 /// Sets fStagingClass according to the given name and version
189 void SetStagingClass(const std::string &className, unsigned int classVersion);
190 /// If there are rules with inputs (source members), create the staging area according to the TClass instance
191 /// that corresponds to the on-disk field.
192 void PrepareStagingArea(const std::vector<const TSchemaRule *> &rules, const ROOT::RNTupleDescriptor &desc,
193 const ROOT::RFieldDescriptor &classFieldId);
194 /// Register post-read callback corresponding to a ROOT I/O customization rules.
195 void AddReadCallbacksFromIORule(const TSchemaRule *rule);
196 /// Given the on-disk information from the page source, find all the I/O customization rules that apply
197 /// to the class field at hand, to which the fieldDesc descriptor, if provided, must correspond.
198 /// Fields may not have an on-disk representation (e.g., when inserted by schema evolution), in which case the passed
199 /// field descriptor is nullptr.
200 std::vector<const TSchemaRule *> FindRules(const ROOT::RFieldDescriptor *fieldDesc);
201
202protected:
203 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
204
205 void ConstructValue(void *where) const final;
206 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RClassDeleter>(fClass); }
207
208 std::size_t AppendImpl(const void *from) final;
209 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
210 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final;
211
212 std::unique_ptr<RFieldBase> BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final;
213 void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
214
215public:
216 RClassField(std::string_view fieldName, std::string_view className);
217 RClassField(RClassField &&other) = default;
218 RClassField &operator=(RClassField &&other) = default;
219 ~RClassField() override;
220
221 std::vector<RValue> SplitValue(const RValue &value) const final;
222 size_t GetValueSize() const final;
223 size_t GetAlignment() const final { return fMaxAlignment; }
224 std::uint32_t GetTypeVersion() const final;
225 std::uint32_t GetTypeChecksum() const final;
226 /// For polymorphic classes (that declare or inherit at least one virtual method), return the expected dynamic type
227 /// of any user object. If the class is not polymorphic, return nullptr.
228 const std::type_info *GetPolymorphicTypeInfo() const;
229 /// Return the TClass instance backing this field.
230 const TClass *GetClass() const { return fClass; }
231 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
232};
233
234/// The field for a class using ROOT standard streaming
235class RStreamerField final : public RFieldBase {
236private:
238 private:
240
241 public:
242 explicit RStreamerFieldDeleter(TClass *cl) : fClass(cl) {}
243 void operator()(void *objPtr, bool dtorOnly) final;
244 };
245
246 TClass *fClass = nullptr;
247 ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t fStreamerInfos; ///< streamer info records seen during writing
248 ROOT::Internal::RColumnIndex fIndex; ///< number of bytes written in the current cluster
249
250private:
251 RStreamerField(std::string_view fieldName, TClass *classp);
252
253protected:
254 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
255
257 void GenerateColumns() final;
258 void GenerateColumns(const ROOT::RNTupleDescriptor &) final;
259
260 void ConstructValue(void *where) const final;
261 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RStreamerFieldDeleter>(fClass); }
262
263 std::size_t AppendImpl(const void *from) final;
264 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
265
266 void CommitClusterImpl() final { fIndex = 0; }
267
268 bool HasExtraTypeInfo() const final { return true; }
269 // Returns the list of seen streamer infos
271
273 void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
274
275public:
276 RStreamerField(std::string_view fieldName, std::string_view className);
277 RStreamerField(RStreamerField &&other) = default;
278 RStreamerField &operator=(RStreamerField &&other) = default;
279 ~RStreamerField() final = default;
280
281 size_t GetValueSize() const final;
282 size_t GetAlignment() const final;
283 std::uint32_t GetTypeVersion() const final;
284 std::uint32_t GetTypeChecksum() const final;
285 TClass *GetClass() const { return fClass; }
286 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
287};
288
289/// The field for an unscoped or scoped enum with dictionary
290class REnumField : public RFieldBase {
291private:
292 REnumField(std::string_view fieldName, TEnum *enump);
293 REnumField(std::string_view fieldName, std::string_view enumName, std::unique_ptr<RFieldBase> intField);
294
295protected:
296 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
297
298 void ConstructValue(void *where) const final { CallConstructValueOn(*fSubfields[0], where); }
299
300 std::size_t AppendImpl(const void *from) final { return CallAppendOn(*fSubfields[0], from); }
301 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final { CallReadOn(*fSubfields[0], globalIndex, to); }
302 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final { CallReadOn(*fSubfields[0], localIndex, to); }
303
304 void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
305
306public:
307 REnumField(std::string_view fieldName, std::string_view enumName);
308 REnumField(REnumField &&other) = default;
309 REnumField &operator=(REnumField &&other) = default;
310 ~REnumField() override = default;
311
312 std::vector<RValue> SplitValue(const RValue &value) const final;
313 size_t GetValueSize() const final { return fSubfields[0]->GetValueSize(); }
314 size_t GetAlignment() const final { return fSubfields[0]->GetAlignment(); }
315 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
316};
317
318/// Classes with dictionaries that can be inspected by TClass
319template <typename T, typename = void>
320class RField final : public RClassField {
321public:
322 static std::string TypeName() { return ROOT::Internal::GetRenormalizedTypeName(typeid(T)); }
323 RField(std::string_view name) : RClassField(name, Internal::GetDemangledTypeName(typeid(T)))
324 {
325 static_assert(std::is_class_v<T>, "no I/O support for this basic C++ type");
326 }
327 RField(RField &&other) = default;
328 RField &operator=(RField &&other) = default;
329 ~RField() final = default;
330};
331
332template <typename T>
333class RField<T, typename std::enable_if<std::is_enum_v<T>>::type> final : public REnumField {
334public:
335 static std::string TypeName() { return ROOT::Internal::GetRenormalizedTypeName(typeid(T)); }
336 RField(std::string_view name) : REnumField(name, TypeName()) {}
337 RField(RField &&other) = default;
338 RField &operator=(RField &&other) = default;
339 ~RField() final = default;
340};
341
342/// An artificial field that transforms an RNTuple column that contains the offset of collections into
343/// collection sizes. It is only used for reading, e.g. as projected field or as an artificial field that provides the
344/// "number of" RDF columns for collections (e.g. `R_rdf_sizeof_jets` for a collection named `jets`).
345/// It is used in the templated RField<RNTupleCardinality<SizeT>> form, which represents the collection sizes either
346/// as 32bit unsigned int (std::uint32_t) or as 64bit unsigned int (std::uint64_t).
348 friend class ROOT::RNTupleCollectionView; // to access GetCollectionInfo()
349
350private:
352 {
353 fPrincipalColumn->GetCollectionInfo(globalIndex, collectionStart, size);
354 }
356 {
357 fPrincipalColumn->GetCollectionInfo(localIndex, collectionStart, size);
358 }
359
360protected:
361 RCardinalityField(std::string_view fieldName, std::string_view typeName)
362 : RFieldBase(fieldName, typeName, ROOT::ENTupleStructure::kPlain, false /* isSimple */)
363 {
364 }
365
366 const RColumnRepresentations &GetColumnRepresentations() const final;
367 // Field is only used for reading
368 void GenerateColumns() final { throw RException(R__FAIL("Cardinality fields must only be used for reading")); }
369 void GenerateColumns(const ROOT::RNTupleDescriptor &) final;
370
371 void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
372
373public:
376 ~RCardinalityField() override = default;
377
378 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
379
382};
383
384template <typename T>
385class RSimpleField : public RFieldBase {
388
389protected:
392
393 void ConstructValue(void *where) const final { new (where) T{0}; }
394
395 void ReconcileOnDiskField(const RNTupleDescriptor &desc) override
396 {
397 if constexpr (std::is_integral_v<T>) {
399 } else if constexpr (std::is_floating_point_v<T>) {
401 } else {
403 }
404 }
405
406 RSimpleField(std::string_view name, std::string_view type)
407 : RFieldBase(name, type, ROOT::ENTupleStructure::kPlain, true /* isSimple */)
408 {
410 }
411
412public:
413 RSimpleField(RSimpleField &&other) = default;
415 ~RSimpleField() override = default;
416
417 T *Map(ROOT::NTupleSize_t globalIndex) { return fPrincipalColumn->Map<T>(globalIndex); }
418 T *Map(RNTupleLocalIndex localIndex) { return fPrincipalColumn->Map<T>(localIndex); }
420 {
421 return fPrincipalColumn->MapV<T>(globalIndex, nItems);
422 }
424 {
425 return fPrincipalColumn->MapV<T>(localIndex, nItems);
426 }
427
428 size_t GetValueSize() const final { return sizeof(T); }
429 size_t GetAlignment() const final { return alignof(T); }
430};
431
432////////////////////////////////////////////////////////////////////////////////
433/// Template specializations for concrete C++ types
434////////////////////////////////////////////////////////////////////////////////
435
436} // namespace ROOT
437
442#include "RField/RFieldSoA.hxx"
444
445namespace ROOT {
446
447template <typename SizeT>
448class RField<RNTupleCardinality<SizeT>> final : public RCardinalityField {
450
451protected:
452 std::unique_ptr<ROOT::RFieldBase> CloneImpl(std::string_view newName) const final
453 {
454 return std::make_unique<RField>(newName);
455 }
456 void ConstructValue(void *where) const final { new (where) CardinalityType(0); }
457
458 /// Get the number of elements of the collection identified by globalIndex
459 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
460 {
461 RNTupleLocalIndex collectionStart;
463 fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &size);
464 *static_cast<CardinalityType *>(to) = size;
465 }
466
467 /// Get the number of elements of the collection identified by clusterIndex
468 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
469 {
470 RNTupleLocalIndex collectionStart;
472 fPrincipalColumn->GetCollectionInfo(localIndex, &collectionStart, &size);
473 *static_cast<CardinalityType *>(to) = size;
474 }
475
476 std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec) final
477 {
478 RNTupleLocalIndex collectionStart;
479 ROOT::NTupleSize_t collectionSize;
480 fPrincipalColumn->GetCollectionInfo(bulkSpec.fFirstIndex, &collectionStart, &collectionSize);
481
482 auto typedValues = static_cast<CardinalityType *>(bulkSpec.fValues);
483 typedValues[0] = collectionSize;
484
485 auto lastOffset = collectionStart.GetIndexInCluster() + collectionSize;
486 ROOT::NTupleSize_t nRemainingEntries = bulkSpec.fCount - 1;
487 std::size_t nEntries = 1;
488 while (nRemainingEntries > 0) {
489 ROOT::NTupleSize_t nItemsUntilPageEnd;
490 auto offsets =
491 fPrincipalColumn->MapV<ROOT::Internal::RColumnIndex>(bulkSpec.fFirstIndex + nEntries, nItemsUntilPageEnd);
492 std::size_t nBatch = std::min(nRemainingEntries, nItemsUntilPageEnd);
493 for (std::size_t i = 0; i < nBatch; ++i) {
494 typedValues[nEntries + i] = offsets[i] - lastOffset;
495 lastOffset = offsets[i];
496 }
497 nRemainingEntries -= nBatch;
498 nEntries += nBatch;
499 }
500 return RBulkSpec::kAllSet;
501 }
502
503public:
504 static std::string TypeName() { return "ROOT::RNTupleCardinality<" + RField<SizeT>::TypeName() + ">"; }
505 explicit RField(std::string_view name) : RCardinalityField(name, TypeName()) {}
506 RField(RField &&other) = default;
507 RField &operator=(RField &&other) = default;
508 ~RField() final = default;
509
510 size_t GetValueSize() const final { return sizeof(CardinalityType); }
511 size_t GetAlignment() const final { return alignof(CardinalityType); }
512};
513
514/// TObject requires special handling of the fBits and fUniqueID members
515template <>
516class RField<TObject> final : public RFieldBase {
517 static std::size_t GetOffsetOfMember(const char *name);
518 static std::size_t GetOffsetUniqueID() { return GetOffsetOfMember("fUniqueID"); }
519 static std::size_t GetOffsetBits() { return GetOffsetOfMember("fBits"); }
520
521private:
522 RField(std::string_view fieldName, const RField<TObject> &source); ///< Used by CloneImpl()
523
524protected:
525 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
526
527 void ConstructValue(void *where) const final;
528 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RTypedDeleter<TObject>>(); }
529
530 std::size_t AppendImpl(const void *from) final;
531 void ReadTObject(void *to, UInt_t uniqueID, UInt_t bits);
532 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
533 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final;
534
535public:
536 static std::string TypeName() { return "TObject"; }
537
538 RField(std::string_view fieldName);
539 RField(RField &&other) = default;
540 RField &operator=(RField &&other) = default;
541 ~RField() final = default;
542
543 std::vector<RValue> SplitValue(const RValue &value) const final;
544 size_t GetValueSize() const final;
545 size_t GetAlignment() const final;
546 std::uint32_t GetTypeVersion() const final;
547 std::uint32_t GetTypeChecksum() const final;
548 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
549};
550
551// Have to be implemented after the definition of all RField<T> types
552
553namespace Internal {
554
555/// Helper to check if a given type name is the one expected of Field<T>. Usually, this check can be done by
556/// type renormalization of the demangled type name T. The failure case, however, needs to additionally check for
557/// ROOT-specific special cases.
558template <class T>
559bool IsMatchingFieldType(const std::string &actualTypeName)
560{
561 return IsMatchingFieldType(actualTypeName, ROOT::RField<T>::TypeName(), typeid(T));
562}
563
564} // namespace Internal
565
566template <typename T>
567std::unique_ptr<T, typename RFieldBase::RCreateObjectDeleter<T>::deleter> RFieldBase::CreateObject() const
568{
570 throw RException(
571 R__FAIL("type mismatch for field " + GetFieldName() + ": " + GetTypeName() + " vs. " + RField<T>::TypeName()));
572 }
573 return std::unique_ptr<T>(static_cast<T *>(CreateObjectRawPtr()));
574}
575
576// The void type is specialized in RField.cxx
577
578template <>
583
584template <>
585std::unique_ptr<void, typename RFieldBase::RCreateObjectDeleter<void>::deleter>
587
588} // namespace ROOT
589
590#endif
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:299
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:60
char name[80]
Definition TGX11.cxx:148
TRObject operator()(const T1 &t1) const
Abstract base class for classes implementing the visitor design pattern.
The in-memory representation of a 32bit or 64bit on-disk index column.
std::map< Int_t, TVirtualStreamerInfo * > StreamerInfoMap_t
Abstract interface to read data from an ntuple.
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
Definition RField.cxx:117
RCardinalityField(RCardinalityField &&other)=default
void GetCollectionInfo(ROOT::NTupleSize_t globalIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size)
Definition RField.hxx:351
const RField< RNTupleCardinality< std::uint32_t > > * As32Bit() const
Definition RField.cxx:122
RCardinalityField & operator=(RCardinalityField &&other)=default
void GetCollectionInfo(RNTupleLocalIndex localIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size)
Definition RField.hxx:355
~RCardinalityField() override=default
const RField< RNTupleCardinality< std::uint64_t > > * As64Bit() const
Definition RField.cxx:127
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
Definition RField.hxx:368
RCardinalityField(std::string_view fieldName, std::string_view typeName)
Definition RField.hxx:361
void operator()(void *objPtr, bool dtorOnly) final
const TClass * GetClass() const
Return the TClass instance backing this field.
Definition RField.hxx:230
std::unique_ptr< RFieldBase > BeforeConnectPageSource(ROOT::Internal::RPageSource &pageSource) final
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate,...
void AddReadCallbacksFromIORule(const TSchemaRule *rule)
Register post-read callback corresponding to a ROOT I/O customization rules.
TClass * fStagingClass
The TClass instance that corresponds to the staging area.
Definition RField.hxx:176
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 fMaxAlignment
Definition RField.hxx:167
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:166
void Attach(std::unique_ptr< RFieldBase > child, RSubfieldInfo info)
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:171
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
Definition RField.hxx:223
RClassField & operator=(RClassField &&other)=default
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
std::vector< const TSchemaRule * > FindRules(const ROOT::RFieldDescriptor *fieldDesc)
Given the on-disk information from the page source, find all the I/O customization rules that apply t...
ROOT::DescriptorId_t LookupMember(const ROOT::RNTupleDescriptor &desc, std::string_view memberName, ROOT::DescriptorId_t classFieldId)
Returns the id of member 'name' in the class field given by 'fieldId', or kInvalidDescriptorId if no ...
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
TClass * fClass
Definition RField.hxx:164
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.
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
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< 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:206
std::unordered_map< std::string, RStagingItem > fStagingItems
Lookup staging items by member name.
Definition RField.hxx:177
static constexpr const char * kPrefixInherited
Prefix used in the subfield names generated for base classes.
Definition RField.hxx:153
void SetStagingClass(const std::string &className, unsigned int classVersion)
Sets fStagingClass according to the given name and version.
The field for an unscoped or scoped enum with dictionary.
Definition RField.hxx:290
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
The number of bytes taken by a value of the appropriate type.
Definition RField.hxx:313
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
Definition RField.hxx:314
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:298
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
Definition RField.hxx:302
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
Definition RField.hxx:301
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:300
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.
virtual void ReconcileOnDiskField(const RNTupleDescriptor &desc)
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
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:567
@ kTraitTrivialType
Shorthand for types that are both trivially constructible and destructible.
@ kTraitInvalidField
This field is an instance of RInvalidField and can be safely static_cast to it.
const std::string & GetFieldName() const
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.
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.
const std::string & GetTypeName() const
void GenerateColumnsImpl(const ColumnRepresentation_t &representation, std::uint16_t representationIndex)
Helpers for generating columns.
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
The number of bytes taken by a value of the appropriate type.
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
As a rule of thumb, the alignment is equal to the size of the type.
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:459
RField & operator=(RField &&other)=default
RNTupleCardinality< SizeT > CardinalityType
Definition RField.hxx:449
std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec) final
General implementation of bulk read.
Definition RField.hxx:476
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
Definition RField.hxx:510
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:456
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
Get the number of elements of the collection identified by clusterIndex.
Definition RField.hxx:468
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:452
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
Definition RField.hxx:511
RField(RField &&other)=default
RField & operator=(RField &&other)=default
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
~RField() final=default
static std::string TypeName()
Definition RField.hxx:536
std::uint32_t GetTypeChecksum() const final
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
std::uint32_t GetTypeVersion() const final
Indicates an evolution of the C++ type itself.
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
static std::size_t GetOffsetOfMember(const char *name)
std::unique_ptr< RDeleter > GetDeleter() const final
Definition RField.hxx:528
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
RField(std::string_view fieldName, const RField< TObject > &source)
Used by CloneImpl().
static std::size_t GetOffsetBits()
Definition RField.hxx:519
static std::size_t GetOffsetUniqueID()
Definition RField.hxx:518
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:320
~RField() final=default
RField(RField &&other)=default
RField & operator=(RField &&other)=default
static std::string TypeName()
Definition RField.hxx:322
RField(std::string_view name)
Definition RField.hxx:323
RInvalidField(std::string_view name, std::string_view type, std::string_view error, ECategory category)
Definition RField.hxx:121
@ kGeneric
Generic unrecoverable error.
Definition RField.hxx:100
@ kUnknownType
The type given to RFieldBase::Create was unknown.
Definition RField.hxx:104
@ kTypeError
The type given to RFieldBase::Create was invalid.
Definition RField.hxx:102
@ kUnknownStructure
The field could not be created because its descriptor had an unknown structural role.
Definition RField.hxx:106
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
As a rule of thumb, the alignment is equal to the size of the type.
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
The number of bytes taken by a value of the appropriate type.
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
void GenerateColumns() override
Implementations in derived classes should create the backing columns corresponding to the field type ...
Definition RField.hxx:390
void ReconcileIntegralField(const RNTupleDescriptor &desc)
Definition RField.cxx:135
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
Definition RField.hxx:429
RSimpleField & operator=(RSimpleField &&other)=default
RSimpleField(std::string_view name, std::string_view type)
Definition RField.hxx:406
T * Map(RNTupleLocalIndex localIndex)
Definition RField.hxx:418
~RSimpleField() override=default
T * Map(ROOT::NTupleSize_t globalIndex)
Definition RField.hxx:417
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
Definition RField.hxx:428
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:395
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:393
void ReconcileFloatingPointField(const RNTupleDescriptor &desc)
Definition RField.cxx:156
T * MapV(ROOT::NTupleSize_t globalIndex, ROOT::NTupleSize_t &nItems)
Definition RField.hxx:419
void GenerateColumns(const ROOT::RNTupleDescriptor &desc) override
Implementations in derived classes should create the backing columns corresponding to the field type ...
Definition RField.hxx:391
T * MapV(RNTupleLocalIndex localIndex, ROOT::NTupleSize_t &nItems)
Definition RField.hxx:423
void operator()(void *objPtr, bool dtorOnly) final
The field for a class using ROOT standard streaming.
Definition RField.hxx:235
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:247
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:248
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:268
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:266
RStreamerField(std::string_view fieldName, TClass *classp)
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
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:261
TClass * GetClass() const
Definition RField.hxx:285
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
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.
STL class.
STL class.
STL class.
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
Definition TObject.h:395
void SetAllowFieldSubstitutions(RFieldZero &fieldZero, bool val)
Definition RField.cxx:35
bool IsMatchingFieldType(const std::string &actualTypeName)
Helper to check if a given type name is the one expected of Field<T>.
Definition RField.hxx:559
std::string GetDemangledTypeName(const std::type_info &)
Returns a string with the demangled and normalized name for the given type.
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::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...
std::size_t fOffset
offset in fStagingArea
Definition RField.hxx:150
std::unique_ptr< RFieldBase > fField
The field used to read the on-disk data.
Definition RField.hxx:149
Input parameter to RFieldBase::ReadBulk() and RFieldBase::ReadBulkImpl().
RCreateObjectDeleter< void > deleter
Definition RField.hxx:580
Helper types to present an offset column as array of collection sizes.