Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFieldBase.hxx
Go to the documentation of this file.
1/// \file ROOT/RFieldBase.hxx
2/// \ingroup NTuple
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-09
5
6/*************************************************************************
7 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#ifndef ROOT_RFieldBase
15#define ROOT_RFieldBase
16
17#include <ROOT/RColumn.hxx>
19#include <ROOT/RNTupleRange.hxx>
20#include <ROOT/RNTupleUtil.hxx>
21
22#include <cstddef>
23#include <functional>
24#include <iterator>
25#include <memory>
26#include <new>
27#include <string>
28#include <string_view>
29#include <vector>
30
31namespace ROOT {
32
33class RFieldBase;
34class RClassField;
35
36namespace Detail {
37class RFieldVisitor;
38} // namespace Detail
39
40namespace Experimental {
41
42namespace Detail {
43class RRawPtrWriteEntry;
44} // namespace Detail
45
46} // namespace Experimental
47
48namespace Internal {
49
50class RPageSink;
51class RPageSource;
52struct RFieldCallbackInjector;
53struct RFieldRepresentationModifier;
54
55// TODO(jblomer): find a better way to not have these methods in the RFieldBase public API
56void CallFlushColumnsOnField(RFieldBase &);
57void CallCommitClusterOnField(RFieldBase &);
61CallFieldBaseCreate(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options,
63
64} // namespace Internal
65
66// clang-format off
67/**
68\class ROOT::RFieldBase
69\ingroup NTuple
70\brief A field translates read and write calls from/to underlying columns to/from tree values
71
72A field is a serializable C++ type or a container for a collection of subfields. The RFieldBase and its
73type-safe descendants provide the object to column mapper. They map C++ objects to primitive columns. The
74mapping is trivial for simple types such as 'double'. Complex types resolve to multiple primitive columns.
75The field knows based on its type and the field name the type(s) and name(s) of the columns.
76
77Note: the class hierarchy starting at RFieldBase is not meant to be extended by user-provided child classes.
78This is and can only be partially enforced through C++.
79*/
80// clang-format on
82 friend class ROOT::RClassField; // to mark members as artificial
83 friend class ROOT::Experimental::Detail::RRawPtrWriteEntry; // to call Append()
84 friend struct ROOT::Internal::RFieldCallbackInjector; // used for unit tests
85 friend struct ROOT::Internal::RFieldRepresentationModifier; // used for unit tests
91 Internal::CallFieldBaseCreate(const std::string &fieldName, const std::string &typeName,
92 const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc,
94
95 using ReadCallback_t = std::function<void(void *)>;
96
97protected:
98 /// A functor to release the memory acquired by CreateValue() (memory and constructor).
99 /// This implementation works for types with a trivial destructor. More complex fields implement a derived deleter.
100 /// The deleter is operational without the field object and thus can be used to destruct/release a value after
101 /// the field has been destructed.
102 class RDeleter {
103 public:
104 virtual ~RDeleter() = default;
105 virtual void operator()(void *objPtr, bool dtorOnly)
106 {
107 if (!dtorOnly)
108 operator delete(objPtr);
109 }
110 };
111
112 /// A deleter for templated RFieldBase descendents where the value type is known.
113 template <typename T>
114 class RTypedDeleter : public RDeleter {
115 public:
116 void operator()(void *objPtr, bool dtorOnly) final
117 {
118 std::destroy_at(static_cast<T *>(objPtr));
120 }
121 };
122
123 // We cannot directly use RFieldBase::RDeleter as a shared pointer deleter due to splicing. We use this
124 // wrapper class to store a polymorphic pointer to the actual deleter.
126 std::unique_ptr<RFieldBase::RDeleter> fDeleter;
127 void operator()(void *objPtr) { fDeleter->operator()(objPtr, false /* dtorOnly*/); }
128 explicit RSharedPtrDeleter(std::unique_ptr<RFieldBase::RDeleter> deleter) : fDeleter(std::move(deleter)) {}
129 };
130
131public:
132 static constexpr std::uint32_t kInvalidTypeVersion = -1U;
133 enum {
134 /// No constructor needs to be called, i.e. any bit pattern in the allocated memory represents a valid type
135 /// A trivially constructible field has a no-op ConstructValue() implementation
137 /// The type is cleaned up just by freeing its memory. I.e. the destructor performs a no-op.
139 /// A field of a fundamental type that can be directly mapped via RField<T>::Map(), i.e. maps as-is to a single
140 /// column
142 /// The TClass checksum is set and valid
144 /// This field is an instance of RInvalidField and can be safely `static_cast` to it
146 /// This field is a user defined type that was missing dictionaries and was reconstructed from the on-disk
147 /// information
149
150 /// Shorthand for types that are both trivially constructible and destructible
152 };
153
154 using ColumnRepresentation_t = std::vector<ROOT::ENTupleColumnType>;
155
156 /// During its lifetime, a field undergoes the following possible state transitions:
157 ///
158 /// [*] --> Unconnected --> ConnectedToSink ----
159 /// | | |
160 /// | --> ConnectedToSource ---> [*]
161 /// | |
162 /// -------------------------------
163 enum class EState {
167 };
168
169 // clang-format off
170 /**
171 \class ROOT::RFieldBase::RColumnRepresentations
172 \ingroup NTuple
173 \brief The list of column representations a field can have.
174
175 Some fields have multiple possible column representations, e.g. with or without split encoding.
176 All column representations supported for writing also need to be supported for reading. In addition,
177 fields can support extra column representations for reading only, e.g. a 64bit integer reading from a
178 32bit column.
179 The defined column representations must be supported by corresponding column packing/unpacking implementations,
180 i.e. for the example above, the unpacking of 32bit ints to 64bit pages must be implemented in RColumnElement.hxx
181 */
182 // clang-format on
184 public:
185 /// A list of column representations
186 using Selection_t = std::vector<ColumnRepresentation_t>;
187
190
191 /// The first column list from `fSerializationTypes` is the default for writing.
195
196 private:
198 /// The union of the serialization types and the deserialization extra types passed during construction.
199 /// Duplicates the serialization types list but the benefit is that GetDeserializationTypes() does not need to
200 /// compile the list.
202 }; // class RColumnRepresentations
203
204 class RValue;
205 class RBulk;
206
207private:
208 /// The field name relative to its parent field
209 std::string fName;
210 /// The C++ type captured by this field
211 std::string fType;
212 /// The role of this field in the data model structure
214 /// For fixed sized arrays, the array length
215 std::size_t fNRepetitions;
216 /// A field qualifies as simple if it is mappable (which implies it has a single principal column),
217 /// and it is not an artificial field and has no post-read callback
219 /// A field that is not backed on disk but computed, e.g. a default-constructed missing field or
220 /// a field whose data is created by I/O customization rules. Subfields of artificial fields are
221 /// artificial, too.
222 bool fIsArtificial = false;
223 /// When the columns are connected to a page source or page sink, the field represents a field id in the
224 /// corresponding RNTuple descriptor. This on-disk ID is set in RPageSink::Create() for writing and by
225 /// RFieldDescriptor::CreateField() when recreating a field / model from the stored descriptor.
227 /// Free text set by the user
228 std::string fDescription;
229 /// Changed by ConnectTo[Sink,Source], reset by Clone()
231
233 {
234 for (const auto &func : fReadCallbacks)
235 func(target);
236 }
237
238 /// Translate an entry index to a column element index of the principal column and vice versa. These functions
239 /// take into account the role and number of repetitions on each level of the field hierarchy as follows:
240 /// - Top level fields: element index == entry index
241 /// - Record fields propagate their principal column index to the principal columns of direct descendant fields
242 /// - Collection and variant fields set the principal column index of their children to 0
243 ///
244 /// The column element index also depends on the number of repetitions of each field in the hierarchy, e.g., given a
245 /// field with type `std::array<std::array<float, 4>, 2>`, this function returns 8 for the innermost field.
247
248 /// Flushes data from active columns
249 void FlushColumns();
250 /// Flushes data from active columns to disk and calls CommitClusterImpl()
251 void CommitCluster();
252 /// Fields and their columns live in the void until connected to a physical page storage. Only once connected, data
253 /// can be read or written. In order to find the field in the page storage, the field's on-disk ID has to be set.
254 /// \param firstEntry The global index of the first entry with on-disk data for the connected field
256 /// Connects the field and its subfield tree to the given page source. Once connected, data can be read.
257 /// Only unconnected fields may be connected, i.e. the method is not idempotent. The field ID has to be set prior to
258 /// calling this function. For subfields, a field ID may or may not be set. If the field ID is unset, it will be
259 /// determined using the page source descriptor, based on the parent field ID and the subfield name.
261
263 {
264 fIsSimple = false;
265 fIsArtificial = true;
266 for (auto &field : fSubfields) {
267 field->SetArtificial();
268 }
269 }
270
271protected:
272 struct RBulkSpec;
273
274 /// Collections and classes own subfields
275 std::vector<std::unique_ptr<RFieldBase>> fSubfields;
276 /// Subfields point to their mother field
278 /// All fields that have columns have a distinct main column. E.g., for simple fields (`float`, `int`, ...), the
279 /// principal column corresponds to the field type. For collection fields except fixed-sized arrays,
280 /// the main column is the offset field. Class fields have no column of their own.
281 /// When reading, points to any column of the column team of the active representation. Usually, this is just
282 /// the first column.
283 /// When writing, points to the first column index of the currently active (not suppressed) column representation.
285 /// Some fields have a second column in its column representation. In this case, `fAuxiliaryColumn` points into
286 /// `fAvailableColumns` to the column that immediately follows the column `fPrincipalColumn` points to.
288 /// The columns are connected either to a sink or to a source (not to both); they are owned by the field.
289 /// Contains all columns of all representations in order of representation and column index.
290 std::vector<std::unique_ptr<ROOT::Internal::RColumn>> fAvailableColumns;
291 /// Properties of the type that allow for optimizations of collections of that type
292 std::uint32_t fTraits = 0;
293 /// A typedef or using name that was used when creating the field
294 std::string fTypeAlias;
295 /// List of functions to be called after reading a value
296 std::vector<ReadCallback_t> fReadCallbacks;
297 /// C++ type version cached from the descriptor after a call to ConnectPageSource()
299 /// TClass checksum cached from the descriptor after a call to ConnectPageSource(). Only set
300 /// for classes with dictionaries.
301 std::uint32_t fOnDiskTypeChecksum = 0;
302 /// Pointers into the static vector returned by RColumnRepresentations::GetSerializationTypes() when
303 /// SetColumnRepresentatives() is called. Otherwise (if empty) GetColumnRepresentatives() returns a vector
304 /// with a single element, the default representation. Always empty for artificial fields.
305 std::vector<std::reference_wrapper<const ColumnRepresentation_t>> fColumnRepresentatives;
306
307 /// Factory method for the field's type. The caller owns the returned pointer
308 void *CreateObjectRawPtr() const;
309
310 /// Helpers for generating columns. We use the fact that most fields have the same C++/memory types
311 /// for all their column representations.
312 /// Where possible, we call the helpers not from the header to reduce compilation time.
313 template <std::uint32_t ColumnIndexT, typename HeadT, typename... TailTs>
315 {
317 auto &column = fAvailableColumns.emplace_back(
318 ROOT::Internal::RColumn::Create<HeadT>(representation[ColumnIndexT], ColumnIndexT, representationIndex));
319
320 // Initially, the first two columns become the active column representation
322 fPrincipalColumn = column.get();
323 } else if (representationIndex == 0 && !fAuxiliaryColumn) {
324 fAuxiliaryColumn = column.get();
325 } else {
326 // We currently have no fields with more than 2 columns in its column representation
328 }
329
330 if constexpr (sizeof...(TailTs))
332 }
333
334 /// For writing, use the currently set column representative
335 template <typename... ColumnCppTs>
337 {
338 if (fColumnRepresentatives.empty()) {
339 fAvailableColumns.reserve(sizeof...(ColumnCppTs));
340 GenerateColumnsImpl<0, ColumnCppTs...>(GetColumnRepresentations().GetSerializationDefault(), 0);
341 } else {
342 const auto N = fColumnRepresentatives.size();
343 fAvailableColumns.reserve(N * sizeof...(ColumnCppTs));
344 for (unsigned i = 0; i < N; ++i) {
346 }
347 }
348 }
349
350 /// For reading, use the on-disk column list
351 template <typename... ColumnCppTs>
353 {
354 std::uint16_t representationIndex = 0;
355 do {
357 if (onDiskTypes.empty())
358 break;
361 if (representationIndex > 0) {
362 for (std::size_t i = 0; i < sizeof...(ColumnCppTs); ++i) {
363 fAvailableColumns[i]->MergeTeams(
364 *fAvailableColumns[representationIndex * sizeof...(ColumnCppTs) + i].get());
365 }
366 }
368 } while (true);
369 }
370
371 /// Implementations in derived classes should return a static RColumnRepresentations object. The default
372 /// implementation does not attach any columns to the field.
373 virtual const RColumnRepresentations &GetColumnRepresentations() const;
374 /// Implementations in derived classes should create the backing columns corresponding to the field type for
375 /// writing. The default implementation does not attach any columns to the field.
376 virtual void GenerateColumns() {}
377 /// Implementations in derived classes should create the backing columns corresponding to the field type for reading.
378 /// The default implementation does not attach any columns to the field. The method should check, using the page
379 /// source and `fOnDiskId`, if the column types match and throw if they don't.
380 virtual void GenerateColumns(const ROOT::RNTupleDescriptor & /*desc*/) {}
381 /// Returns the on-disk column types found in the provided descriptor for `fOnDiskId` and the given
382 /// representation index. If there are no columns for the given representation index, return an empty
383 /// ColumnRepresentation_t list. Otherwise, the returned reference points into the static array returned by
384 /// GetColumnRepresentations().
385 /// Throws an exception if the types on disk don't match any of the deserialization types from
386 /// GetColumnRepresentations().
389 /// When connecting a field to a page sink, the field's default column representation is subject
390 /// to adjustment according to the write options. E.g., if compression is turned off, encoded columns
391 /// are changed to their unencoded counterparts.
393
394 /// Called by Clone(), which additionally copies the on-disk ID
395 virtual std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const = 0;
396
397 /// Constructs value in a given location of size at least GetValueSize(). Called by the base class' CreateValue().
398 virtual void ConstructValue(void *where) const = 0;
399 virtual std::unique_ptr<RDeleter> GetDeleter() const { return std::make_unique<RDeleter>(); }
400 /// Allow derived classes to call ConstructValue(void *) and GetDeleter() on other (sub)fields.
401 static void CallConstructValueOn(const RFieldBase &other, void *where) { other.ConstructValue(where); }
402 static std::unique_ptr<RDeleter> GetDeleterOf(const RFieldBase &other) { return other.GetDeleter(); }
403
404 /// Operations on values of complex types, e.g. ones that involve multiple columns or for which no direct
405 /// column type exists.
406 virtual std::size_t AppendImpl(const void *from);
407 virtual void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to);
408 virtual void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to);
409
410 /// Write the given value into columns. The value object has to be of the same type as the field.
411 /// Returns the number of uncompressed bytes written.
412 std::size_t Append(const void *from);
413
414 /// Populate a single value with data from the field. The memory location pointed to by to needs to be of the
415 /// fitting type. The fast path is conditioned by the field qualifying as simple, i.e. maps as-is
416 /// to a single column and has no read callback.
418 {
419 if (fIsSimple)
420 return (void)fPrincipalColumn->Read(globalIndex, to);
421
422 if (!fIsArtificial) {
425 else
427 }
428 if (R__unlikely(!fReadCallbacks.empty()))
430 }
431
432 /// Populate a single value with data from the field. The memory location pointed to by to needs to be of the
433 /// fitting type. The fast path is conditioned by the field qualifying as simple, i.e. maps as-is
434 /// to a single column and has no read callback.
436 {
437 if (fIsSimple)
438 return (void)fPrincipalColumn->Read(localIndex, to);
439
440 if (!fIsArtificial) {
443 else
445 }
446 if (R__unlikely(!fReadCallbacks.empty()))
448 }
449
450 /// General implementation of bulk read. Loop over the required range and read values that are required
451 /// and not already present. Derived classes may implement more optimized versions of this method.
452 /// See ReadBulk() for the return value.
453 virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec);
454
455 /// Returns the number of newly available values, that is the number of bools in `bulkSpec.fMaskAvail` that
456 /// flipped from false to true. As a special return value, `kAllSet` can be used if all values are read
457 /// independent from the masks.
458 std::size_t ReadBulk(const RBulkSpec &bulkSpec);
459
460 /// Allow derived classes to call Append() and Read() on other (sub)fields.
461 static std::size_t CallAppendOn(RFieldBase &other, const void *from) { return other.Append(from); }
464 static void *CallCreateObjectRawPtrOn(RFieldBase &other) { return other.CreateObjectRawPtr(); }
465
466 /// Fields may need direct access to the principal column of their subfields, e.g. in RRVecField::ReadBulk()
467 static ROOT::Internal::RColumn *GetPrincipalColumnOf(const RFieldBase &other) { return other.fPrincipalColumn; }
468
469 /// Set a user-defined function to be called after reading a value, giving a chance to inspect and/or modify the
470 /// value object.
471 /// Returns an index that can be used to remove the callback.
472 size_t AddReadCallback(ReadCallback_t func);
473 void RemoveReadCallback(size_t idx);
474
475 // Perform housekeeping tasks for global to cluster-local index translation
476 virtual void CommitClusterImpl() {}
477 // The field can indicate that it needs to register extra type information in the on-disk schema.
478 // In this case, a callback from the page sink to the field will be registered on connect, so that the
479 // extra type information can be collected when the dataset gets committed.
480 virtual bool HasExtraTypeInfo() const { return false; }
481 // The page sink's callback when the data set gets committed will call this method to get the field's extra
482 // type information. This has to happen at the end of writing because the type information may change depending
483 // on the data that's written, e.g. for polymorphic types in the streamer field.
485
486 /// Add a new subfield to the list of nested fields
487 void Attach(std::unique_ptr<RFieldBase> child);
488
489 /// Called by ConnectPageSource() before connecting; derived classes may override this as appropriate
491
492 /// Called by ConnectPageSource() once connected; derived classes may override this as appropriate
493 virtual void AfterConnectPageSource() {}
494
495 /// Factory method to resurrect a field from the stored on-disk type information. This overload takes an already
496 /// normalized type name and type alias.
497 /// `desc` and `fieldId` must be passed if `options.fEmulateUnknownTypes` is true, otherwise they can be left blank.
499 Create(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options,
501
502public:
503 template <bool IsConstT>
504 class RSchemaIteratorTemplate;
507
508 // This is used in CreateObject() and is specialized for void
509 template <typename T>
511 using deleter = std::default_delete<T>;
512 };
513
514 /// Used in the return value of the Check() method
516 std::string fFieldName; ///< Qualified field name causing the error
517 std::string fTypeName; ///< Type name corresponding to the (sub)field
518 std::string fErrMsg; ///< Cause of the failure, e.g. unsupported type
519 };
520
521 /// The constructor creates the underlying column objects and connects them to either a sink or a source.
522 /// If `isSimple` is `true`, the trait `kTraitMappable` is automatically set on construction. However, the
523 /// field might be demoted to non-simple if a post-read callback is set.
524 RFieldBase(std::string_view name, std::string_view type, ROOT::ENTupleStructure structure, bool isSimple,
525 std::size_t nRepetitions = 0);
526 RFieldBase(const RFieldBase &) = delete;
527 RFieldBase(RFieldBase &&) = default;
528 RFieldBase &operator=(const RFieldBase &) = delete;
530 virtual ~RFieldBase() = default;
531
532 /// Copies the field and its subfields using a possibly new name and a new, unconnected set of columns
533 std::unique_ptr<RFieldBase> Clone(std::string_view newName) const;
534
535 /// Factory method to create a field from a certain type given as string.
536 /// Note that the provided type name must be a valid C++ type name. Template arguments of templated types
537 /// must be type names or integers (e.g., no expressions).
539 Create(const std::string &fieldName, const std::string &typeName);
540
541 /// Checks if the given type is supported by RNTuple. In case of success, the result vector is empty.
542 /// Otherwise there is an error record for each failing subfield (subtype).
543 static std::vector<RCheckResult> Check(const std::string &fieldName, const std::string &typeName);
544
545 /// Generates an object of the field type and allocates new initialized memory according to the type.
546 /// Implemented at the end of this header because the implementation is using RField<T>::TypeName()
547 /// The returned object can be released with `delete`, i.e. it is valid to call:
548 /// ~~~{.cpp}
549 /// auto ptr = field->CreateObject();
550 /// delete ptr.release();
551 /// ~~~
552 ///
553 /// Note that CreateObject<void>() is supported. The returned `unique_ptr` has a custom deleter that reports an error
554 /// if it is called. The intended use of the returned `unique_ptr<void>` is to call `release()`. In this way, the
555 /// transfer of pointer ownership is explicit.
556 template <typename T>
557 std::unique_ptr<T, typename RCreateObjectDeleter<T>::deleter> CreateObject() const;
558 /// Generates an object of the field's type, wraps it in a shared pointer and returns it as an RValue connected to
559 /// the field.
561 /// Creates a new, initially empty bulk.
562 /// RBulk::ReadBulk() will construct the array of values. The memory of the value array is managed by the RBulk
563 /// class.
565 /// Creates a value from a memory location with an already constructed object
566 RValue BindValue(std::shared_ptr<void> objPtr);
567 /// Creates the list of direct child values given an existing value for this field. E.g. a single value for the
568 /// correct `std::variant` or all the elements of a collection. The default implementation assumes no subvalues
569 /// and returns an empty vector.
570 virtual std::vector<RValue> SplitValue(const RValue &value) const;
571 /// The number of bytes taken by a value of the appropriate type
572 virtual size_t GetValueSize() const = 0;
573 /// As a rule of thumb, the alignment is equal to the size of the type. There are, however, various exceptions
574 /// to this rule depending on OS and CPU architecture. So enforce the alignment to be explicitly spelled out.
575 virtual size_t GetAlignment() const = 0;
576 std::uint32_t GetTraits() const { return fTraits; }
577 bool HasReadCallbacks() const { return !fReadCallbacks.empty(); }
578
579 const std::string &GetFieldName() const { return fName; }
580 /// Returns the field name and parent field names separated by dots (`grandparent.parent.child`)
581 std::string GetQualifiedFieldName() const;
582 const std::string &GetTypeName() const { return fType; }
583 const std::string &GetTypeAlias() const { return fTypeAlias; }
585 std::size_t GetNRepetitions() const { return fNRepetitions; }
586 const RFieldBase *GetParent() const { return fParent; }
587 std::vector<RFieldBase *> GetMutableSubfields();
588 std::vector<const RFieldBase *> GetConstSubfields() const;
589 bool IsSimple() const { return fIsSimple; }
590 bool IsArtificial() const { return fIsArtificial; }
591 /// Get the field's description
592 const std::string &GetDescription() const { return fDescription; }
593 void SetDescription(std::string_view description);
594 EState GetState() const { return fState; }
595
598
599 /// Returns the `fColumnRepresentative` pointee or, if unset (always the case for artificial fields), the field's
600 /// default representative
602 /// Fixes a column representative. This can only be done _before_ connecting the field to a page sink.
603 /// Otherwise, or if the provided representation is not in the list of GetColumnRepresentations(),
604 /// an exception is thrown
606 /// Whether or not an explicit column representative was set
608
609 /// Indicates an evolution of the mapping scheme from C++ type to columns
610 virtual std::uint32_t GetFieldVersion() const { return 0; }
611 /// Indicates an evolution of the C++ type itself
612 virtual std::uint32_t GetTypeVersion() const { return 0; }
613 /// Return the current TClass reported checksum of this class. Only valid if `kTraitTypeChecksum` is set.
614 virtual std::uint32_t GetTypeChecksum() const { return 0; }
615 /// Return the C++ type version stored in the field descriptor; only valid after a call to ConnectPageSource()
616 std::uint32_t GetOnDiskTypeVersion() const { return fOnDiskTypeVersion; }
617 /// Return checksum stored in the field descriptor; only valid after a call to ConnectPageSource(),
618 /// if the field stored a type checksum
619 std::uint32_t GetOnDiskTypeChecksum() const { return fOnDiskTypeChecksum; }
620
627
629}; // class RFieldBase
630
631/// Iterates over the subtree of fields in depth-first search order
632template <bool IsConstT>
634private:
635 struct Position {
636 using FieldPtr_t = std::conditional_t<IsConstT, const RFieldBase *, RFieldBase *>;
637 Position() : fFieldPtr(nullptr), fIdxInParent(-1) {}
641 };
642 /// The stack of nodes visited when walking down the tree of fields
643 std::vector<Position> fStack;
644
645public:
647 using iterator_category = std::forward_iterator_tag;
648 using difference_type = std::ptrdiff_t;
649 using value_type = std::conditional_t<IsConstT, const RFieldBase, RFieldBase>;
650 using pointer = std::conditional_t<IsConstT, const RFieldBase *, RFieldBase *>;
651 using reference = std::conditional_t<IsConstT, const RFieldBase &, RFieldBase &>;
652
656 /// Given that the iterator points to a valid field which is not the end iterator, go to the next field
657 /// in depth-first search order
658 void Advance()
659 {
660 auto itr = fStack.rbegin();
661 if (!itr->fFieldPtr->fSubfields.empty()) {
662 fStack.emplace_back(Position(itr->fFieldPtr->fSubfields[0].get(), 0));
663 return;
664 }
665
666 unsigned int nextIdxInParent = ++(itr->fIdxInParent);
667 while (nextIdxInParent >= itr->fFieldPtr->fParent->fSubfields.size()) {
668 if (fStack.size() == 1) {
669 itr->fFieldPtr = itr->fFieldPtr->fParent;
670 itr->fIdxInParent = -1;
671 return;
672 }
673 fStack.pop_back();
674 itr = fStack.rbegin();
675 nextIdxInParent = ++(itr->fIdxInParent);
676 }
677 itr->fFieldPtr = itr->fFieldPtr->fParent->fSubfields[nextIdxInParent].get();
678 }
679
680 iterator operator++(int) /* postfix */
681 {
682 auto r = *this;
683 Advance();
684 return r;
685 }
686 iterator &operator++() /* prefix */
687 {
688 Advance();
689 return *this;
690 }
691 reference operator*() const { return *fStack.back().fFieldPtr; }
692 pointer operator->() const { return fStack.back().fFieldPtr; }
693 bool operator==(const iterator &rh) const { return fStack.back().fFieldPtr == rh.fStack.back().fFieldPtr; }
694 bool operator!=(const iterator &rh) const { return fStack.back().fFieldPtr != rh.fStack.back().fFieldPtr; }
695};
696
697/// Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
698/// Fields can create RValue objects through RFieldBase::CreateValue(), RFieldBase::BindValue()) or
699/// RFieldBase::SplitValue().
701 friend class RFieldBase;
702
703private:
704 RFieldBase *fField = nullptr; ///< The field that created the RValue
705 /// Set by Bind() or by RFieldBase::CreateValue(), RFieldBase::SplitValue() or RFieldBase::BindValue()
706 std::shared_ptr<void> fObjPtr;
707 RValue(RFieldBase *field, std::shared_ptr<void> objPtr) : fField(field), fObjPtr(objPtr) {}
708
709public:
710 RValue(const RValue &) = default;
711 RValue &operator=(const RValue &) = default;
712 RValue(RValue &&other) = default;
714 ~RValue() = default;
715
716 std::size_t Append() { return fField->Append(fObjPtr.get()); }
719 void Bind(std::shared_ptr<void> objPtr) { fObjPtr = objPtr; }
720 void BindRawPtr(void *rawPtr);
721 /// Replace the current object pointer by a pointer to a new object constructed by the field
722 void EmplaceNew() { fObjPtr = fField->CreateValue().GetPtr<void>(); }
723
724 template <typename T>
725 std::shared_ptr<T> GetPtr() const
726 {
727 return std::static_pointer_cast<T>(fObjPtr);
728 }
729
730 template <typename T>
731 const T &GetRef() const
732 {
733 return *static_cast<T *>(fObjPtr.get());
734 }
735
736 const RFieldBase &GetField() const { return *fField; }
737};
738
739/// Input parameter to RFieldBase::ReadBulk() and RFieldBase::ReadBulkImpl().
740// See the RBulk class documentation for more information.
742 /// Possible return value of ReadBulk() and ReadBulkImpl(), which indicates that the full bulk range was read
743 /// independently of the provided masks.
744 static const std::size_t kAllSet = std::size_t(-1);
745
746 RNTupleLocalIndex fFirstIndex; ///< Start of the bulk range
747 std::size_t fCount = 0; ///< Size of the bulk range
748 /// A bool array of size fCount, indicating the required values in the requested range
749 const bool *fMaskReq = nullptr;
750 bool *fMaskAvail = nullptr; ///< A bool array of size `fCount`, indicating the valid values in fValues
751 /// The destination area, which has to be an array of valid objects of the correct type large enough to hold the bulk
752 /// range.
753 void *fValues = nullptr;
754 /// Reference to memory owned by the RBulk class. The field implementing BulkReadImpl() may use `fAuxData` as memory
755 /// that stays persistent between calls.
756 std::vector<unsigned char> *fAuxData = nullptr;
757};
758
759// clang-format off
760/**
761\class ROOT::RFieldBase::RBulk
762\ingroup NTuple
763\brief Points to an array of objects with RNTuple I/O support, used for bulk reading.
764
765Similar to RValue, but manages an array of consecutive values. Bulks have to come from the same cluster.
766Bulk I/O works with two bit masks: the mask of all the available entries in the current bulk and the mask
767of the required entries in a bulk read. The idea is that a single bulk may serve multiple read operations
768on the same range, where in each read operation a different subset of values is required.
769The memory of the value array is managed by the RBulk class.
770*/
771// clang-format on
773private:
774 friend class RFieldBase;
775
776 RFieldBase *fField = nullptr; ///< The field that created the array of values
777 std::unique_ptr<RFieldBase::RDeleter> fDeleter; /// Cached deleter of fField
778 void *fValues = nullptr; ///< Pointer to the start of the array
779 std::size_t fValueSize = 0; ///< Cached copy of RFieldBase::GetValueSize()
780 std::size_t fCapacity = 0; ///< The size of the array memory block in number of values
781 std::size_t fSize = 0; ///< The number of available values in the array (provided their mask is set)
782 bool fIsAdopted = false; ///< True if the user provides the memory buffer for fValues
783 std::unique_ptr<bool[]> fMaskAvail; ///< Masks invalid values in the array
784 std::size_t fNValidValues = 0; ///< The sum of non-zero elements in the fMask
785 RNTupleLocalIndex fFirstIndex; ///< Index of the first value of the array
786 /// Reading arrays of complex values may require additional memory, for instance for the elements of
787 /// arrays of vectors. A pointer to the `fAuxData` array is passed to the field's BulkRead method.
788 /// The RBulk class does not modify the array in-between calls to the field's BulkRead method.
789 std::vector<unsigned char> fAuxData;
790
791 void ReleaseValues();
792 /// Sets a new range for the bulk. If there is enough capacity, the `fValues` array will be reused.
793 /// Otherwise a new array is allocated. After reset, fMaskAvail is false for all values.
794 void Reset(RNTupleLocalIndex firstIndex, std::size_t size);
795 void CountValidValues();
796
798 {
799 if (firstIndex.GetClusterId() != fFirstIndex.GetClusterId())
800 return false;
801 return (firstIndex.GetIndexInCluster() >= fFirstIndex.GetIndexInCluster()) &&
802 ((firstIndex.GetIndexInCluster() + size) <= (fFirstIndex.GetIndexInCluster() + fSize));
803 }
804
805 void *GetValuePtrAt(std::size_t idx) const { return reinterpret_cast<unsigned char *>(fValues) + idx * fValueSize; }
806
810
811public:
812 ~RBulk();
813 RBulk(const RBulk &) = delete;
814 RBulk &operator=(const RBulk &) = delete;
815 RBulk(RBulk &&other);
817
818 // Sets `fValues` and `fSize`/`fCapacity` to the given values. The capacity is specified in number of values.
819 // Once a buffer is adopted, an attempt to read more values then available throws an exception.
820 void AdoptBuffer(void *buf, std::size_t capacity);
821
822 /// Reads `size` values from the associated field, starting from `firstIndex`. Note that the index is given
823 /// relative to a certain cluster. The return value points to the array of read objects.
824 /// The `maskReq` parameter is a bool array of at least `size` elements. Only objects for which the mask is
825 /// true are guaranteed to be read in the returned value array. A `nullptr` means to read all elements.
826 void *ReadBulk(RNTupleLocalIndex firstIndex, const bool *maskReq, std::size_t size)
827 {
830
831 // We may read a subrange of the currently available range
832 auto offset = firstIndex.GetIndexInCluster() - fFirstIndex.GetIndexInCluster();
833
834 if (fNValidValues == fSize)
835 return GetValuePtrAt(offset);
836
838 bulkSpec.fFirstIndex = firstIndex;
839 bulkSpec.fCount = size;
840 bulkSpec.fMaskReq = maskReq;
841 bulkSpec.fMaskAvail = &fMaskAvail[offset];
842 bulkSpec.fValues = GetValuePtrAt(offset);
843 bulkSpec.fAuxData = &fAuxData;
844 auto nRead = fField->ReadBulk(bulkSpec);
845 if (nRead == RBulkSpec::kAllSet) {
846 if ((offset == 0) && (size == fSize)) {
848 } else {
850 }
851 } else {
853 }
854 return GetValuePtrAt(offset);
855 }
856
857 /// Overload to read all elements in the given cluster range.
858 void *ReadBulk(ROOT::RNTupleLocalRange range) { return ReadBulk(*range.begin(), nullptr, range.size()); }
859};
860
861namespace Internal {
862// At some point, RFieldBase::OnClusterCommit() may allow for a user-defined callback to change the
863// column representation. For now, we inject this for testing and internal use only.
866 {
867 R__ASSERT(newRepresentationIdx < field.fColumnRepresentatives.size());
868 const auto N = field.fColumnRepresentatives[0].get().size();
869 R__ASSERT(N >= 1 && N <= 2);
870 R__ASSERT(field.fPrincipalColumn);
871 field.fPrincipalColumn = field.fAvailableColumns[newRepresentationIdx * N].get();
872 if (field.fAuxiliaryColumn) {
873 R__ASSERT(N == 2);
874 field.fAuxiliaryColumn = field.fAvailableColumns[newRepresentationIdx * N + 1].get();
875 }
876 }
877};
878} // namespace Internal
879} // namespace ROOT
880
881#endif
#define R__unlikely(expr)
Definition RConfig.hxx:594
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
#define N
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 offset
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 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 Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
Abstract base class for classes implementing the visitor design pattern.
A container of const raw pointers, corresponding to a row in the data set.
A column is a storage-backed array of a simple, fixed-size type, from which pages can be mapped into ...
Definition RColumn.hxx:38
void Read(const ROOT::NTupleSize_t globalIndex, void *to)
Definition RColumn.hxx:160
Abstract interface to write data into an ntuple.
Abstract interface to read data from an ntuple.
The field for a class with dictionary.
Definition RField.hxx:111
Field specific extra type information from the header / extenstion header.
Points to an array of objects with RNTuple I/O support, used for bulk reading.
std::size_t fValueSize
Cached copy of RFieldBase::GetValueSize()
RBulk(const RBulk &)=delete
std::size_t fNValidValues
The sum of non-zero elements in the fMask.
void * GetValuePtrAt(std::size_t idx) const
bool ContainsRange(RNTupleLocalIndex firstIndex, std::size_t size) const
void * ReadBulk(RNTupleLocalIndex firstIndex, const bool *maskReq, std::size_t size)
Reads size values from the associated field, starting from firstIndex.
RBulk(RFieldBase *field)
RNTupleLocalIndex fFirstIndex
Index of the first value of the array.
void * ReadBulk(ROOT::RNTupleLocalRange range)
Overload to read all elements in the given cluster range.
std::size_t fCapacity
The size of the array memory block in number of values.
void Reset(RNTupleLocalIndex firstIndex, std::size_t size)
Sets a new range for the bulk.
std::vector< unsigned char > fAuxData
Reading arrays of complex values may require additional memory, for instance for the elements of arra...
bool fIsAdopted
True if the user provides the memory buffer for fValues.
std::unique_ptr< RFieldBase::RDeleter > fDeleter
RFieldBase * fField
The field that created the array of values.
RBulk & operator=(const RBulk &)=delete
void * fValues
Cached deleter of fField.
std::unique_ptr< bool[]> fMaskAvail
Masks invalid values in the array.
void AdoptBuffer(void *buf, std::size_t capacity)
std::size_t fSize
The number of available values in the array (provided their mask is set)
The list of column representations a field can have.
const Selection_t & GetSerializationTypes() const
const Selection_t & GetDeserializationTypes() const
const ColumnRepresentation_t & GetSerializationDefault() const
The first column list from fSerializationTypes is the default for writing.
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.
A functor to release the memory acquired by CreateValue() (memory and constructor).
virtual void operator()(void *objPtr, bool dtorOnly)
virtual ~RDeleter()=default
Iterates over the subtree of fields in depth-first search order.
std::vector< Position > fStack
The stack of nodes visited when walking down the tree of fields.
bool operator==(const iterator &rh) const
std::conditional_t< IsConstT, const RFieldBase &, RFieldBase & > reference
std::conditional_t< IsConstT, const RFieldBase *, RFieldBase * > pointer
std::conditional_t< IsConstT, const RFieldBase, RFieldBase > value_type
std::forward_iterator_tag iterator_category
void Advance()
Given that the iterator points to a valid field which is not the end iterator, go to the next field i...
bool operator!=(const iterator &rh) const
RSchemaIteratorTemplate(pointer val, int idxInParent)
A deleter for templated RFieldBase descendents where the value type is known.
void operator()(void *objPtr, bool dtorOnly) final
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
std::shared_ptr< void > fObjPtr
Set by Bind() or by RFieldBase::CreateValue(), RFieldBase::SplitValue() or RFieldBase::BindValue()
void Read(ROOT::NTupleSize_t globalIndex)
void EmplaceNew()
Replace the current object pointer by a pointer to a new object constructed by the field.
void Bind(std::shared_ptr< void > objPtr)
void Read(RNTupleLocalIndex localIndex)
const RFieldBase & GetField() const
RValue(const RValue &)=default
RValue(RValue &&other)=default
std::shared_ptr< T > GetPtr() const
RFieldBase * fField
The field that created the RValue.
RValue(RFieldBase *field, std::shared_ptr< void > objPtr)
RValue & operator=(const RValue &)=default
RValue & operator=(RValue &&other)=default
void BindRawPtr(void *rawPtr)
const T & GetRef() const
A field translates read and write calls from/to underlying columns to/from tree values.
ROOT::DescriptorId_t fOnDiskId
When the columns are connected to a page source or page sink, the field represents a field id in the ...
ROOT::ENTupleStructure GetStructure() const
virtual size_t GetValueSize() const =0
The number of bytes taken by a value of the appropriate type.
static constexpr std::uint32_t kInvalidTypeVersion
RSchemaIterator end()
void SetColumnRepresentatives(const RColumnRepresentations::Selection_t &representatives)
Fixes a column representative.
void InvokeReadCallbacks(void *target)
ROOT::Internal::RColumn * fPrincipalColumn
All fields that have columns have a distinct main column.
virtual size_t GetAlignment() const =0
As a rule of thumb, the alignment is equal to the size of the type.
virtual std::unique_ptr< RDeleter > GetDeleter() const
ROOT::NTupleSize_t EntryToColumnElementIndex(ROOT::NTupleSize_t globalIndex) const
Translate an entry index to a column element index of the principal column and vice versa.
void Attach(std::unique_ptr< RFieldBase > child)
Add a new subfield to the list of nested fields.
virtual void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const
void FlushColumns()
Flushes data from active columns.
virtual void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to)
std::vector< std::unique_ptr< RFieldBase > > fSubfields
Collections and classes own subfields.
std::uint32_t GetOnDiskTypeVersion() const
Return the C++ type version stored in the field descriptor; only valid after a call to ConnectPageSou...
virtual const RColumnRepresentations & GetColumnRepresentations() const
Implementations in derived classes should return a static RColumnRepresentations object.
RBulk CreateBulk()
Creates a new, initially empty bulk.
EState
During its lifetime, a field undergoes the following possible state transitions:
bool fIsSimple
A field qualifies as simple if it is mappable (which implies it has a single principal column),...
RConstSchemaIterator cbegin() const
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:502
RFieldBase & operator=(const RFieldBase &)=delete
virtual void AfterConnectPageSource()
Called by ConnectPageSource() once connected; derived classes may override this as appropriate.
virtual void GenerateColumns(const ROOT::RNTupleDescriptor &)
Implementations in derived classes should create the backing columns corresponding to the field type ...
void AutoAdjustColumnTypes(const ROOT::RNTupleWriteOptions &options)
When connecting a field to a page sink, the field's default column representation is subject to adjus...
virtual void ConstructValue(void *where) const =0
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
std::vector< const RFieldBase * > GetConstSubfields() const
void SetOnDiskId(ROOT::DescriptorId_t id)
void RemoveReadCallback(size_t idx)
void GenerateColumnsImpl(const ROOT::RNTupleDescriptor &desc)
For reading, use the on-disk column list.
virtual void GenerateColumns()
Implementations in derived classes should create the backing columns corresponding to the field type ...
void Read(RNTupleLocalIndex localIndex, void *to)
Populate a single value with data from the field.
const RFieldBase * GetParent() const
std::vector< RFieldBase * > GetMutableSubfields()
std::string fDescription
Free text set by the user.
static std::unique_ptr< RDeleter > GetDeleterOf(const RFieldBase &other)
static ROOT::Internal::RColumn * GetPrincipalColumnOf(const RFieldBase &other)
Fields may need direct access to the principal column of their subfields, e.g. in RRVecField::ReadBul...
static std::vector< RCheckResult > Check(const std::string &fieldName, const std::string &typeName)
Checks if the given type is supported by RNTuple.
RSchemaIterator begin()
ROOT::Internal::RColumn * fAuxiliaryColumn
Some fields have a second column in its column representation.
size_t AddReadCallback(ReadCallback_t func)
Set a user-defined function to be called after reading a value, giving a chance to inspect and/or mod...
RConstSchemaIterator cend() const
std::size_t fNRepetitions
For fixed sized arrays, the array length.
std::function< void(void *)> ReadCallback_t
virtual void BeforeConnectPageSource(ROOT::Internal::RPageSource &)
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate.
std::size_t Append(const void *from)
Write the given value into columns.
RValue CreateValue()
Generates an object of the field's type, wraps it in a shared pointer and returns it as an RValue con...
RSchemaIteratorTemplate< false > RSchemaIterator
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...
RFieldBase(RFieldBase &&)=default
virtual std::vector< RValue > SplitValue(const RValue &value) const
Creates the list of direct child values given an existing value for this field.
virtual std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const =0
Called by Clone(), which additionally copies the on-disk ID.
std::string GetQualifiedFieldName() const
Returns the field name and parent field names separated by dots (grandparent.parent....
const std::string & GetFieldName() const
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
std::vector< ReadCallback_t > fReadCallbacks
List of functions to be called after reading a value.
RFieldBase & operator=(RFieldBase &&)=default
const std::string & GetTypeAlias() const
static void CallReadOn(RFieldBase &other, ROOT::NTupleSize_t globalIndex, void *to)
virtual ~RFieldBase()=default
static std::size_t CallAppendOn(RFieldBase &other, const void *from)
Allow derived classes to call Append() and Read() on other (sub)fields.
virtual void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to)
virtual void CommitClusterImpl()
std::vector< std::reference_wrapper< const ColumnRepresentation_t > > fColumnRepresentatives
Pointers into the static vector returned by RColumnRepresentations::GetSerializationTypes() when SetC...
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
friend struct ROOT::Internal::RFieldCallbackInjector
virtual std::size_t AppendImpl(const void *from)
Operations on values of complex types, e.g.
RFieldBase * fParent
Subfields point to their mother field.
std::vector< std::unique_ptr< ROOT::Internal::RColumn > > fAvailableColumns
The columns are connected either to a sink or to a source (not to both); they are owned by the 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.
@ kTraitEmulatedField
This field is a user defined type that was missing dictionaries and was reconstructed from the on-dis...
@ kTraitTrivialType
Shorthand for types that are both trivially constructible and destructible.
@ 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.
@ kTraitTypeChecksum
The TClass checksum is set and valid.
EState fState
Changed by ConnectTo[Sink,Source], reset by Clone()
static void * CallCreateObjectRawPtrOn(RFieldBase &other)
bool IsArtificial() const
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.
const std::string & GetDescription() const
Get the field's description.
bool HasReadCallbacks() const
std::string fTypeAlias
A typedef or using name that was used when creating the field.
virtual std::uint32_t GetFieldVersion() const
Indicates an evolution of the mapping scheme from C++ type to columns.
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),...
RSchemaIteratorTemplate< true > RConstSchemaIterator
virtual std::uint32_t GetTypeChecksum() const
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
bool IsSimple() const
std::uint32_t GetTraits() const
std::size_t GetNRepetitions() const
std::uint32_t fOnDiskTypeChecksum
TClass checksum cached from the descriptor after a call to ConnectPageSource().
const std::string & GetTypeName() const
ROOT::ENTupleStructure fStructure
The role of this field in the data model structure.
void GenerateColumnsImpl(const ColumnRepresentation_t &representation, std::uint16_t representationIndex)
Helpers for generating columns.
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)
static void CallReadOn(RFieldBase &other, RNTupleLocalIndex localIndex, void *to)
ROOT::DescriptorId_t GetOnDiskId() const
std::uint32_t fOnDiskTypeVersion
C++ type version cached from the descriptor after a call to ConnectPageSource()
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.
static void CallConstructValueOn(const RFieldBase &other, void *where)
Allow derived classes to call ConstructValue(void *) and GetDeleter() on other (sub)fields.
EState GetState() const
void GenerateColumnsImpl()
For writing, use the currently set column representative.
virtual ROOT::RExtraTypeInfoDescriptor GetExtraTypeInfo() const
virtual std::uint32_t GetTypeVersion() const
Indicates an evolution of the C++ type itself.
void * CreateObjectRawPtr() const
Factory method for the field's type. The caller owns the returned pointer.
void Read(ROOT::NTupleSize_t globalIndex, void *to)
Populate a single value with data from the field.
std::uint32_t GetOnDiskTypeChecksum() const
Return checksum stored in the field descriptor; only valid after a call to ConnectPageSource(),...
RFieldBase(const RFieldBase &)=delete
virtual bool HasExtraTypeInfo() const
bool fIsArtificial
A field that is not backed on disk but computed, e.g.
virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec)
General implementation of bulk read.
bool HasDefaultColumnRepresentative() const
Whether or not an explicit column representative was set.
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
ROOT::DescriptorId_t GetClusterId() const
Used to loop over entries of collections in a single cluster.
Common user-tunable settings for storing RNTuples.
const_iterator begin() 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:197
void CallCommitClusterOnField(RFieldBase &)
void CallConnectPageSourceOnField(RFieldBase &, ROOT::Internal::RPageSource &)
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)
void CallFlushColumnsOnField(RFieldBase &)
void CallConnectPageSinkOnField(RFieldBase &, ROOT::Internal::RPageSink &, ROOT::NTupleSize_t firstEntry=0)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
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 ntuple model tree can carry different structural information about the type system.
static void SetPrimaryColumnRepresentation(RFieldBase &field, std::uint16_t newRepresentationIdx)
Input parameter to RFieldBase::ReadBulk() and RFieldBase::ReadBulkImpl().
static const std::size_t kAllSet
Possible return value of ReadBulk() and ReadBulkImpl(), which indicates that the full bulk range was ...
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.
std::vector< unsigned char > * fAuxData
Reference to memory owned by the RBulk class.
Used in the return value of the Check() method.
std::string fFieldName
Qualified field name causing the error.
std::string fTypeName
Type name corresponding to the (sub)field.
std::string fErrMsg
Cause of the failure, e.g. unsupported type.
Position(FieldPtr_t fieldPtr, int idxInParent)
std::conditional_t< IsConstT, const RFieldBase *, RFieldBase * > FieldPtr_t
RSharedPtrDeleter(std::unique_ptr< RFieldBase::RDeleter > deleter)
std::unique_ptr< RFieldBase::RDeleter > fDeleter