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 ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-09
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#ifndef ROOT7_RFieldBase
17#define ROOT7_RFieldBase
18
19#include <ROOT/RColumn.hxx>
20#include <ROOT/RNTupleRange.hxx>
21#include <ROOT/RNTupleUtil.hxx>
22
23#include <cstddef>
24#include <functional>
25#include <iterator>
26#include <memory>
27#include <new>
28#include <string>
29#include <string_view>
30#include <vector>
31
32namespace ROOT {
33namespace Experimental {
34
35class RFieldBase;
36class RNTupleJoinProcessor;
37
38namespace Internal {
39struct RFieldCallbackInjector;
40struct RFieldRepresentationModifier;
41class RPageSink;
42class RPageSource;
43// TODO(jblomer): find a better way to not have these four methods in the RFieldBase public API
44void CallFlushColumnsOnField(RFieldBase &);
45void CallCommitClusterOnField(RFieldBase &);
46void CallConnectPageSinkOnField(RFieldBase &, RPageSink &, NTupleSize_t firstEntry = 0);
47void CallConnectPageSourceOnField(RFieldBase &, RPageSource &);
48} // namespace Internal
49
50namespace Detail {
51class RFieldVisitor;
52} // namespace Detail
53
54// clang-format off
55/**
56\class ROOT::Experimental::RFieldBase
57\ingroup NTuple
58\brief A field translates read and write calls from/to underlying columns to/from tree values
59
60A field is a serializable C++ type or a container for a collection of sub fields. The RFieldBase and its
61type-safe descendants provide the object to column mapper. They map C++ objects to primitive columns. The
62mapping is trivial for simple types such as 'double'. Complex types resolve to multiple primitive columns.
63The field knows based on its type and the field name the type(s) and name(s) of the columns.
64
65Note: the class hierarchy starting at RFieldBase is not meant to be extended by user-provided child classes.
66This is and can only be partially enforced through C++.
67*/
68// clang-format on
70 friend class ROOT::Experimental::RNTupleJoinProcessor; // needs ConstuctValue
71 friend struct ROOT::Experimental::Internal::RFieldCallbackInjector; // used for unit tests
77 using ReadCallback_t = std::function<void(void *)>;
78
79protected:
80 /// A functor to release the memory acquired by CreateValue (memory and constructor).
81 /// This implementation works for types with a trivial destructor. More complex fields implement a derived deleter.
82 /// The deleter is operational without the field object and thus can be used to destruct/release a value after
83 /// the field has been destructed.
84 class RDeleter {
85 public:
86 virtual ~RDeleter() = default;
87 virtual void operator()(void *objPtr, bool dtorOnly)
88 {
89 if (!dtorOnly)
90 operator delete(objPtr);
91 }
92 };
93
94 /// A deleter for templated RFieldBase descendents where the value type is known.
95 template <typename T>
96 class RTypedDeleter : public RDeleter {
97 public:
98 void operator()(void *objPtr, bool dtorOnly) final
99 {
100 std::destroy_at(static_cast<T *>(objPtr));
101 RDeleter::operator()(objPtr, dtorOnly);
102 }
103 };
104
105 // We cannot directly use RFieldBase::RDeleter as a shared pointer deleter due to splicing. We use this
106 // wrapper class to store a polymorphic pointer to the actual deleter.
108 std::unique_ptr<RFieldBase::RDeleter> fDeleter;
109 void operator()(void *objPtr) { fDeleter->operator()(objPtr, false /* dtorOnly*/); }
110 explicit RSharedPtrDeleter(std::unique_ptr<RFieldBase::RDeleter> deleter) : fDeleter(std::move(deleter)) {}
111 };
112
113public:
114 static constexpr std::uint32_t kInvalidTypeVersion = -1U;
115 /// No constructor needs to be called, i.e. any bit pattern in the allocated memory represents a valid type
116 /// A trivially constructible field has a no-op ConstructValue() implementation
117 static constexpr int kTraitTriviallyConstructible = 0x01;
118 /// The type is cleaned up just by freeing its memory. I.e. the destructor performs a no-op.
119 static constexpr int kTraitTriviallyDestructible = 0x02;
120 /// A field of a fundamental type that can be directly mapped via `RField<T>::Map()`, i.e. maps as-is to a single
121 /// column
122 static constexpr int kTraitMappable = 0x04;
123 /// The TClass checksum is set and valid
124 static constexpr int kTraitTypeChecksum = 0x08;
125 /// Shorthand for types that are both trivially constructible and destructible
127
128 using ColumnRepresentation_t = std::vector<EColumnType>;
129
130 /// During its lifetime, a field undergoes the following possible state transitions:
131 ///
132 /// [*] --> Unconnected --> ConnectedToSink ----
133 /// | | |
134 /// | --> ConnectedToSource ---> [*]
135 /// | |
136 /// -------------------------------
138
139 /// Some fields have multiple possible column representations, e.g. with or without split encoding.
140 /// All column representations supported for writing also need to be supported for reading. In addition,
141 /// fields can support extra column representations for reading only, e.g. a 64bit integer reading from a
142 /// 32bit column.
143 /// The defined column representations must be supported by corresponding column packing/unpacking implementations,
144 /// i.e. for the example above, the unpacking of 32bit ints to 64bit pages must be implemented in RColumnElement.hxx
146 public:
147 /// A list of column representations
148 using Selection_t = std::vector<ColumnRepresentation_t>;
149
151 RColumnRepresentations(const Selection_t &serializationTypes, const Selection_t &deserializationExtraTypes);
152
153 /// The first column list from fSerializationTypes is the default for writing.
157
158 private:
160 /// The union of the serialization types and the deserialization extra types. Duplicates the serialization types
161 /// list but the benenfit is that GetDeserializationTypes does not need to compile the list.
163 }; // class RColumnRepresentations
164
165 class RValue;
166 class RBulk;
167
168private:
169 /// The field name relative to its parent field
170 std::string fName;
171 /// The C++ type captured by this field
172 std::string fType;
173 /// The role of this field in the data model structure
175 /// For fixed sized arrays, the array length
176 std::size_t fNRepetitions;
177 /// A field qualifies as simple if it is both mappable and has no post-read callback
179 /// When the columns are connected to a page source or page sink, the field represents a field id in the
180 /// corresponding RNTuple descriptor. This on-disk ID is set in RPageSink::Create() for writing and by
181 /// RFieldDescriptor::CreateField() when recreating a field / model from the stored descriptor.
183 /// Free text set by the user
184 std::string fDescription;
185 /// Changed by ConnectTo[Sink,Source], reset by Clone()
187
189 {
190 for (const auto &func : fReadCallbacks)
191 func(target);
192 }
193
194 /// Translate an entry index to a column element index of the principal column and viceversa. These functions
195 /// take into account the role and number of repetitions on each level of the field hierarchy as follows:
196 /// - Top level fields: element index == entry index
197 /// - Record fields propagate their principal column index to the principal columns of direct descendant fields
198 /// - Collection and variant fields set the principal column index of their childs to 0
199 ///
200 /// The column element index also depends on the number of repetitions of each field in the hierarchy, e.g., given a
201 /// field with type `std::array<std::array<float, 4>, 2>`, this function returns 8 for the inner-most field.
203
204 /// Flushes data from active columns
205 void FlushColumns();
206 /// Flushes data from active columns to disk and calls CommitClusterImpl
207 void CommitCluster();
208 /// Fields and their columns live in the void until connected to a physical page storage. Only once connected, data
209 /// 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.
210 /// \param firstEntry The global index of the first entry with on-disk data for the connected field
211 void ConnectPageSink(Internal::RPageSink &pageSink, NTupleSize_t firstEntry = 0);
212 /// Connects the field and its sub field tree to the given page source. Once connected, data can be read.
213 /// Only unconnected fields may be connected, i.e. the method is not idempotent. The field ID has to be set prior to
214 /// calling this function. For sub fields, a field ID may or may not be set. If the field ID is unset, it will be
215 /// determined using the page source descriptor, based on the parent field ID and the sub field name.
217
218protected:
219 /// Input parameter to ReadBulk() and ReadBulkImpl(). See RBulk class for more information
220 struct RBulkSpec;
221
222 /// Collections and classes own sub fields
223 std::vector<std::unique_ptr<RFieldBase>> fSubFields;
224 /// Sub fields point to their mother field
226 /// All fields that have columns have a distinct main column. E.g., for simple fields (float, int, ...), the
227 /// principal column corresponds to the field type. For collection fields except fixed-sized arrays,
228 /// the main column is the offset field. Class fields have no column of their own.
229 /// When reading, points to any column of the column team of the active representation. Usually, this is just
230 /// the first column.
231 /// When writing, points to the first column index of the currently active (not suppressed) column representation.
233 /// Some fields have a second column in its column representation. In this case, fAuxiliaryColumn points into
234 /// fAvailableColumns to the column that immediately follows the column fPrincipalColumn points to.
236 /// The columns are connected either to a sink or to a source (not to both); they are owned by the field.
237 /// Contains all columns of all representations in order of representation and column index.
238 std::vector<std::unique_ptr<Internal::RColumn>> fAvailableColumns;
239 /// Properties of the type that allow for optimizations of collections of that type
240 int fTraits = 0;
241 /// A typedef or using name that was used when creating the field
242 std::string fTypeAlias;
243 /// List of functions to be called after reading a value
244 std::vector<ReadCallback_t> fReadCallbacks;
245 /// C++ type version cached from the descriptor after a call to `ConnectPageSource()`
247 /// TClass checksum cached from the descriptor after a call to `ConnectPageSource()`. Only set
248 /// for classes with dictionaries.
249 std::uint32_t fOnDiskTypeChecksum = 0;
250 /// Pointers into the static vector GetColumnRepresentations().GetSerializationTypes() when
251 /// SetColumnRepresentatives is called. Otherwise (if empty) GetColumnRepresentatives() returns a vector
252 /// with a single element, the default representation.
253 std::vector<std::reference_wrapper<const ColumnRepresentation_t>> fColumnRepresentatives;
254
255 /// Factory method for the field's type. The caller owns the returned pointer
256 void *CreateObjectRawPtr() const;
257
258 /// Helpers for generating columns. We use the fact that most fields have the same C++/memory types
259 /// for all their column representations.
260 /// Where possible, we call the helpers not from the header to reduce compilation time.
261 template <std::uint32_t ColumnIndexT, typename HeadT, typename... TailTs>
262 void GenerateColumnsImpl(const ColumnRepresentation_t &representation, std::uint16_t representationIndex)
263 {
264 assert(ColumnIndexT < representation.size());
265 auto &column = fAvailableColumns.emplace_back(
266 Internal::RColumn::Create<HeadT>(representation[ColumnIndexT], ColumnIndexT, representationIndex));
267
268 // Initially, the first two columns become the active column representation
269 if (representationIndex == 0 && !fPrincipalColumn) {
270 fPrincipalColumn = column.get();
271 } else if (representationIndex == 0 && !fAuxiliaryColumn) {
272 fAuxiliaryColumn = column.get();
273 } else {
274 // We currently have no fields with more than 2 columns in its column representation
275 R__ASSERT(representationIndex > 0);
276 }
277
278 if constexpr (sizeof...(TailTs))
279 GenerateColumnsImpl<ColumnIndexT + 1, TailTs...>(representation, representationIndex);
280 }
281
282 /// For writing, use the currently set column representative
283 template <typename... ColumnCppTs>
285 {
286 if (fColumnRepresentatives.empty()) {
287 fAvailableColumns.reserve(sizeof...(ColumnCppTs));
289 } else {
290 const auto N = fColumnRepresentatives.size();
291 fAvailableColumns.reserve(N * sizeof...(ColumnCppTs));
292 for (unsigned i = 0; i < N; ++i) {
293 GenerateColumnsImpl<0, ColumnCppTs...>(fColumnRepresentatives[i].get(), i);
294 }
295 }
296 }
297
298 /// For reading, use the on-disk column list
299 template <typename... ColumnCppTs>
301 {
302 std::uint16_t representationIndex = 0;
303 do {
304 const auto &onDiskTypes = EnsureCompatibleColumnTypes(desc, representationIndex);
305 if (onDiskTypes.empty())
306 break;
307 GenerateColumnsImpl<0, ColumnCppTs...>(onDiskTypes, representationIndex);
308 fColumnRepresentatives.emplace_back(onDiskTypes);
309 if (representationIndex > 0) {
310 for (std::size_t i = 0; i < sizeof...(ColumnCppTs); ++i) {
311 fAvailableColumns[i]->MergeTeams(
312 *fAvailableColumns[representationIndex * sizeof...(ColumnCppTs) + i].get());
313 }
314 }
315 representationIndex++;
316 } while (true);
317 }
318
319 /// Implementations in derived classes should return a static RColumnRepresentations object. The default
320 /// implementation does not attach any columns to the field.
321 virtual const RColumnRepresentations &GetColumnRepresentations() const;
322 /// Implementations in derived classes should create the backing columns corresponsing to the field type for
323 /// writing. The default implementation does not attach any columns to the field.
324 virtual void GenerateColumns() {}
325 /// Implementations in derived classes should create the backing columns corresponsing to the field type for reading.
326 /// The default implementation does not attach any columns to the field. The method should check, using the page
327 /// source and fOnDiskId, if the column types match and throw if they don't.
328 virtual void GenerateColumns(const RNTupleDescriptor & /*desc*/) {}
329 /// Returns the on-disk column types found in the provided descriptor for fOnDiskId and the given
330 /// representation index. If there are no columns for the given representation index, return an empty
331 /// ColumnRepresentation_t list. Otherwise, the returned reference points into the static array returned by
332 /// GetColumnRepresentations().
333 /// Throws an exception if the types on disk don't match any of the deserialization types from
334 /// GetColumnRepresentations().
336 EnsureCompatibleColumnTypes(const RNTupleDescriptor &desc, std::uint16_t representationIndex) const;
337 /// When connecting a field to a page sink, the field's default column representation is subject
338 /// to adjustment according to the write options. E.g., if compression is turned off, encoded columns
339 /// are changed to their unencoded counterparts.
340 void AutoAdjustColumnTypes(const RNTupleWriteOptions &options);
341
342 /// Called by Clone(), which additionally copies the on-disk ID
343 virtual std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const = 0;
344
345 /// Constructs value in a given location of size at least GetValueSize(). Called by the base class' CreateValue().
346 virtual void ConstructValue(void *where) const = 0;
347 virtual std::unique_ptr<RDeleter> GetDeleter() const { return std::make_unique<RDeleter>(); }
348 /// Allow derived classes to call ConstructValue(void *) and GetDeleter on other (sub) fields.
349 static void CallConstructValueOn(const RFieldBase &other, void *where) { other.ConstructValue(where); }
350 static std::unique_ptr<RDeleter> GetDeleterOf(const RFieldBase &other) { return other.GetDeleter(); }
351
352 /// Operations on values of complex types, e.g. ones that involve multiple columns or for which no direct
353 /// column type exists.
354 virtual std::size_t AppendImpl(const void *from);
355 virtual void ReadGlobalImpl(NTupleSize_t globalIndex, void *to);
356 virtual void ReadInClusterImpl(RClusterIndex clusterIndex, void *to);
357
358 /// Write the given value into columns. The value object has to be of the same type as the field.
359 /// Returns the number of uncompressed bytes written.
360 std::size_t Append(const void *from);
361
362 /// Populate a single value with data from the field. The memory location pointed to by to needs to be of the
363 /// fitting type. The fast path is conditioned by the field qualifying as simple, i.e. maps as-is
364 /// to a single column and has no read callback.
365 void Read(NTupleSize_t globalIndex, void *to)
366 {
367 if (fIsSimple)
368 return (void)fPrincipalColumn->Read(globalIndex, to);
369
371 fPrincipalColumn->Read(globalIndex, to);
372 else
373 ReadGlobalImpl(globalIndex, to);
374 if (R__unlikely(!fReadCallbacks.empty()))
376 }
377
378 /// Populate a single value with data from the field. The memory location pointed to by to needs to be of the
379 /// fitting type. The fast path is conditioned by the field qualifying as simple, i.e. maps as-is
380 /// to a single column and has no read callback.
381 void Read(RClusterIndex clusterIndex, void *to)
382 {
383 if (fIsSimple)
384 return (void)fPrincipalColumn->Read(clusterIndex, to);
385
387 fPrincipalColumn->Read(clusterIndex, to);
388 else
389 ReadInClusterImpl(clusterIndex, to);
390 if (R__unlikely(!fReadCallbacks.empty()))
392 }
393
394 /// General implementation of bulk read. Loop over the required range and read values that are required
395 /// and not already present. Derived classes may implement more optimized versions of this method.
396 /// See ReadBulk() for the return value.
397 virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec);
398
399 /// Returns the number of newly available values, that is the number of bools in bulkSpec.fMaskAvail that
400 /// flipped from false to true. As a special return value, kAllSet can be used if all values are read
401 /// independent from the masks.
402 std::size_t ReadBulk(const RBulkSpec &bulkSpec);
403
404 /// Allow derived classes to call Append and Read on other (sub) fields.
405 static std::size_t CallAppendOn(RFieldBase &other, const void *from) { return other.Append(from); }
406 static void CallReadOn(RFieldBase &other, RClusterIndex clusterIndex, void *to) { other.Read(clusterIndex, to); }
407 static void CallReadOn(RFieldBase &other, NTupleSize_t globalIndex, void *to) { other.Read(globalIndex, to); }
408 static void *CallCreateObjectRawPtrOn(RFieldBase &other) { return other.CreateObjectRawPtr(); }
409
410 /// Fields may need direct access to the principal column of their sub fields, e.g. in RRVecField::ReadBulk
412
413 /// Set a user-defined function to be called after reading a value, giving a chance to inspect and/or modify the
414 /// value object.
415 /// Returns an index that can be used to remove the callback.
416 size_t AddReadCallback(ReadCallback_t func);
417 void RemoveReadCallback(size_t idx);
418
419 // Perform housekeeping tasks for global to cluster-local index translation
420 virtual void CommitClusterImpl() {}
421 // The field can indicate that it needs to register extra type information in the on-disk schema.
422 // In this case, a callback from the page sink to the field will be registered on connect, so that the
423 // extra type information can be collected when the dataset gets committed.
424 virtual bool HasExtraTypeInfo() const { return false; }
425 // The page sink's callback when the data set gets committed will call this method to get the field's extra
426 // type information. This has to happen at the end of writing because the type information may change depending
427 // on the data that's written, e.g. for polymorphic types in the streamer field.
429
430 /// Add a new subfield to the list of nested fields
431 void Attach(std::unique_ptr<RFieldBase> child);
432
433 /// Called by `ConnectPageSource()` once connected; derived classes may override this as appropriate
434 virtual void OnConnectPageSource() {}
435
436 /// Factory method to resurrect a field from the stored on-disk type information. This overload takes an already
437 /// normalized type name and type alias
438 /// TODO(jalopezg): this overload may eventually be removed leaving only the `RFieldBase::Create()` that takes a
439 /// single type name
440 static RResult<std::unique_ptr<RFieldBase>> Create(const std::string &fieldName, const std::string &canonicalType,
441 const std::string &typeAlias, bool continueOnError = false);
442
443public:
444 template <bool IsConstT>
445 class RSchemaIteratorTemplate;
448
449 // This is used in CreateObject and is specialized for void
450 template <typename T>
452 using deleter = std::default_delete<T>;
453 };
454
455 /// Used in the return value of the Check() method
457 std::string fFieldName; ///< Qualified field name causing the error
458 std::string fTypeName; ///< Type name corresponding to the (sub) field
459 std::string fErrMsg; ///< Cause of the failure, e.g. unsupported type
460 };
461
462 /// The constructor creates the underlying column objects and connects them to either a sink or a source.
463 /// If `isSimple` is `true`, the trait `kTraitMappable` is automatically set on construction. However, the
464 /// field might be demoted to non-simple if a post-read callback is set.
465 RFieldBase(std::string_view name, std::string_view type, ENTupleStructure structure, bool isSimple,
466 std::size_t nRepetitions = 0);
467 RFieldBase(const RFieldBase &) = delete;
468 RFieldBase(RFieldBase &&) = default;
469 RFieldBase &operator=(const RFieldBase &) = delete;
471 virtual ~RFieldBase() = default;
472
473 /// Copies the field and its sub fields using a possibly new name and a new, unconnected set of columns
474 std::unique_ptr<RFieldBase> Clone(std::string_view newName) const;
475
476 /// Factory method to resurrect a field from the stored on-disk type information
477 static RResult<std::unique_ptr<RFieldBase>> Create(const std::string &fieldName, const std::string &typeName);
478 /// Checks if the given type is supported by RNTuple. In case of success, the result vector is empty.
479 /// Otherwise there is an error record for each failing sub field (sub type).
480 static std::vector<RCheckResult> Check(const std::string &fieldName, const std::string &typeName);
481
482 /// Generates an object of the field type and allocates new initialized memory according to the type.
483 /// Implemented at the end of this header because the implementation is using RField<T>::TypeName()
484 /// The returned object can be released with `delete`, i.e. it is valid to call
485 /// auto ptr = field->CreateObject();
486 /// delete ptr.release();
487 ///
488 /// Note that CreateObject<void> is supported. The returned unique_ptr has a custom deleter that reports an error
489 /// if it is called. The intended use of the returned unique_ptr<void> is to call `release()`. In this way, the
490 /// transfer of pointer ownership is explicit.
491 template <typename T>
492 std::unique_ptr<T, typename RCreateObjectDeleter<T>::deleter> CreateObject() const;
493 /// Generates an object of the field type and wraps the created object in a shared pointer and returns it an RValue
494 /// connected to the field.
496 /// The returned bulk is initially empty; RBulk::ReadBulk will construct the array of values
498 /// Creates a value from a memory location with an already constructed object
499 RValue BindValue(std::shared_ptr<void> objPtr);
500 /// Creates the list of direct child values given a value for this field. E.g. a single value for the
501 /// correct variant or all the elements of a collection. The default implementation assumes no sub values
502 /// and returns an empty vector.
503 virtual std::vector<RValue> SplitValue(const RValue &value) const;
504 /// The number of bytes taken by a value of the appropriate type
505 virtual size_t GetValueSize() const = 0;
506 /// As a rule of thumb, the alignment is equal to the size of the type. There are, however, various exceptions
507 /// to this rule depending on OS and CPU architecture. So enforce the alignment to be explicitly spelled out.
508 virtual size_t GetAlignment() const = 0;
509 int GetTraits() const { return fTraits; }
510 bool HasReadCallbacks() const { return !fReadCallbacks.empty(); }
511
512 const std::string &GetFieldName() const { return fName; }
513 /// Returns the field name and parent field names separated by dots ("grandparent.parent.child")
514 std::string GetQualifiedFieldName() const;
515 const std::string &GetTypeName() const { return fType; }
516 const std::string &GetTypeAlias() const { return fTypeAlias; }
518 std::size_t GetNRepetitions() const { return fNRepetitions; }
519 const RFieldBase *GetParent() const { return fParent; }
520 std::vector<RFieldBase *> GetSubFields();
521 std::vector<const RFieldBase *> GetSubFields() const;
522 bool IsSimple() const { return fIsSimple; }
523 /// Get the field's description
524 const std::string &GetDescription() const { return fDescription; }
525 void SetDescription(std::string_view description);
526 EState GetState() const { return fState; }
527
530
531 /// Returns the fColumnRepresentative pointee or, if unset, the field's default representative
533 /// Fixes a column representative. This can only be done _before_ connecting the field to a page sink.
534 /// Otherwise, or if the provided representation is not in the list of GetColumnRepresentations,
535 /// an exception is thrown
537 /// Whether or not an explicit column representative was set
539
540 /// Indicates an evolution of the mapping scheme from C++ type to columns
541 virtual std::uint32_t GetFieldVersion() const { return 0; }
542 /// Indicates an evolution of the C++ type itself
543 virtual std::uint32_t GetTypeVersion() const { return 0; }
544 /// Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
545 virtual std::uint32_t GetTypeChecksum() const { return 0; }
546 /// Return the C++ type version stored in the field descriptor; only valid after a call to `ConnectPageSource()`
547 std::uint32_t GetOnDiskTypeVersion() const { return fOnDiskTypeVersion; }
548 /// Return checksum stored in the field descriptor; only valid after a call to `ConnectPageSource()`,
549 /// if the field stored a type checksum
550 std::uint32_t GetOnDiskTypeChecksum() const { return fOnDiskTypeChecksum; }
551
558
559 virtual void AcceptVisitor(Detail::RFieldVisitor &visitor) const;
560}; // class RFieldBase
561
562/// Iterates over the sub tree of fields in depth-first search order
563template <bool IsConstT>
565private:
566 struct Position {
567 using FieldPtr_t = std::conditional_t<IsConstT, const RFieldBase *, RFieldBase *>;
568 Position() : fFieldPtr(nullptr), fIdxInParent(-1) {}
569 Position(FieldPtr_t fieldPtr, int idxInParent) : fFieldPtr(fieldPtr), fIdxInParent(idxInParent) {}
572 };
573 /// The stack of nodes visited when walking down the tree of fields
574 std::vector<Position> fStack;
575
576public:
578 using iterator_category = std::forward_iterator_tag;
579 using difference_type = std::ptrdiff_t;
580 using value_type = std::conditional_t<IsConstT, const RFieldBase, RFieldBase>;
581 using pointer = std::conditional_t<IsConstT, const RFieldBase *, RFieldBase *>;
582 using reference = std::conditional_t<IsConstT, const RFieldBase &, RFieldBase &>;
583
585 RSchemaIteratorTemplate(pointer val, int idxInParent) { fStack.emplace_back(Position(val, idxInParent)); }
587 /// Given that the iterator points to a valid field which is not the end iterator, go to the next field
588 /// in depth-first search order
589 void Advance()
590 {
591 auto itr = fStack.rbegin();
592 if (!itr->fFieldPtr->fSubFields.empty()) {
593 fStack.emplace_back(Position(itr->fFieldPtr->fSubFields[0].get(), 0));
594 return;
595 }
596
597 unsigned int nextIdxInParent = ++(itr->fIdxInParent);
598 while (nextIdxInParent >= itr->fFieldPtr->fParent->fSubFields.size()) {
599 if (fStack.size() == 1) {
600 itr->fFieldPtr = itr->fFieldPtr->fParent;
601 itr->fIdxInParent = -1;
602 return;
603 }
604 fStack.pop_back();
605 itr = fStack.rbegin();
606 nextIdxInParent = ++(itr->fIdxInParent);
607 }
608 itr->fFieldPtr = itr->fFieldPtr->fParent->fSubFields[nextIdxInParent].get();
609 }
610
611 iterator operator++(int) /* postfix */
612 {
613 auto r = *this;
614 Advance();
615 return r;
616 }
617 iterator &operator++() /* prefix */
618 {
619 Advance();
620 return *this;
621 }
622 reference operator*() const { return *fStack.back().fFieldPtr; }
623 pointer operator->() const { return fStack.back().fFieldPtr; }
624 bool operator==(const iterator &rh) const { return fStack.back().fFieldPtr == rh.fStack.back().fFieldPtr; }
625 bool operator!=(const iterator &rh) const { return fStack.back().fFieldPtr != rh.fStack.back().fFieldPtr; }
626};
627
628/// Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
629/// Only fields can create RValue objects through generation, binding or splitting.
631 friend class RFieldBase;
632
633private:
634 RFieldBase *fField = nullptr; ///< The field that created the RValue
635 std::shared_ptr<void> fObjPtr; ///< Set by Bind() or by RFieldBase::CreateValue(), SplitValue() or BindValue()
636
637 RValue(RFieldBase *field, std::shared_ptr<void> objPtr) : fField(field), fObjPtr(objPtr) {}
638
639public:
640 RValue(const RValue &) = default;
641 RValue &operator=(const RValue &) = default;
642 RValue(RValue &&other) = default;
643 RValue &operator=(RValue &&other) = default;
644 ~RValue() = default;
645
646 std::size_t Append() { return fField->Append(fObjPtr.get()); }
647 void Read(NTupleSize_t globalIndex) { fField->Read(globalIndex, fObjPtr.get()); }
648 void Read(RClusterIndex clusterIndex) { fField->Read(clusterIndex, fObjPtr.get()); }
649 void Bind(std::shared_ptr<void> objPtr) { fObjPtr = objPtr; }
650 void BindRawPtr(void *rawPtr);
651 /// Replace the current object pointer by a pointer to a new object constructed by the field
652 void EmplaceNew() { fObjPtr = fField->CreateValue().GetPtr<void>(); }
653
654 template <typename T>
655 std::shared_ptr<T> GetPtr() const
656 {
657 return std::static_pointer_cast<T>(fObjPtr);
658 }
659
660 template <typename T>
661 const T &GetRef() const
662 {
663 return *static_cast<T *>(fObjPtr.get());
664 }
665
666 const RFieldBase &GetField() const { return *fField; }
667};
668
670 /// As a return value of ReadBulk and ReadBulkImpl(), indicates that the full bulk range was read
671 /// independent of the provided masks.
672 static const std::size_t kAllSet = std::size_t(-1);
673
674 RClusterIndex fFirstIndex; ///< Start of the bulk range
675 std::size_t fCount = 0; ///< Size of the bulk range
676 /// A bool array of size fCount, indicating the required values in the requested range
677 const bool *fMaskReq = nullptr;
678 bool *fMaskAvail = nullptr; ///< A bool array of size fCount, indicating the valid values in fValues
679 /// The destination area, which has to be a big enough array of valid objects of the correct type
680 void *fValues = nullptr;
681 /// Reference to memory owned by the RBulk class. The field implementing BulkReadImpl may use fAuxData
682 /// as memory that stays persistent between calls.
683 std::vector<unsigned char> *fAuxData = nullptr;
684};
685
686/// Similar to RValue but manages an array of consecutive values. Bulks have to come from the same cluster.
687/// Bulk I/O works with two bit masks: the mask of all the available entries in the current bulk and the mask
688/// of the required entries in a bulk read. The idea is that a single bulk may serve multiple read operations
689/// on the same range, where in each read operation a different subset of values is required.
690/// The memory of the value array is managed by the RBulk class.
692private:
693 friend class RFieldBase;
694
695 RFieldBase *fField = nullptr; ///< The field that created the array of values
696 std::unique_ptr<RFieldBase::RDeleter> fDeleter; /// Cached deleter of fField
697 void *fValues = nullptr; ///< Pointer to the start of the array
698 std::size_t fValueSize = 0; ///< Cached copy of fField->GetValueSize()
699 std::size_t fCapacity = 0; ///< The size of the array memory block in number of values
700 std::size_t fSize = 0; ///< The number of available values in the array (provided their mask is set)
701 bool fIsAdopted = false; ///< True if the user provides the memory buffer for fValues
702 std::unique_ptr<bool[]> fMaskAvail; ///< Masks invalid values in the array
703 std::size_t fNValidValues = 0; ///< The sum of non-zero elements in the fMask
704 RClusterIndex fFirstIndex; ///< Index of the first value of the array
705 /// Reading arrays of complex values may require additional memory, for instance for the elements of
706 /// arrays of vectors. A pointer to the fAuxData array is passed to the field's BulkRead method.
707 /// The RBulk class does not modify the array in-between calls to the field's BulkRead method.
708 std::vector<unsigned char> fAuxData;
709
710 void ReleaseValues();
711 /// Sets a new range for the bulk. If there is enough capacity, the fValues array will be reused.
712 /// Otherwise a new array is allocated. After reset, fMaskAvail is false for all values.
713 void Reset(RClusterIndex firstIndex, std::size_t size);
714 void CountValidValues();
715
716 bool ContainsRange(RClusterIndex firstIndex, std::size_t size) const
717 {
718 if (firstIndex.GetClusterId() != fFirstIndex.GetClusterId())
719 return false;
720 return (firstIndex.GetIndex() >= fFirstIndex.GetIndex()) &&
721 ((firstIndex.GetIndex() + size) <= (fFirstIndex.GetIndex() + fSize));
722 }
723
724 void *GetValuePtrAt(std::size_t idx) const { return reinterpret_cast<unsigned char *>(fValues) + idx * fValueSize; }
725
726 explicit RBulk(RFieldBase *field) : fField(field), fDeleter(field->GetDeleter()), fValueSize(field->GetValueSize())
727 {
728 }
729
730public:
731 ~RBulk();
732 RBulk(const RBulk &) = delete;
733 RBulk &operator=(const RBulk &) = delete;
734 RBulk(RBulk &&other);
735 RBulk &operator=(RBulk &&other);
736
737 // Sets fValues and fSize/fCapacity to the given values. The capacity is specified in number of values.
738 // Once a buffer is adopted, an attempt to read more values then available throws an exception.
739 void AdoptBuffer(void *buf, std::size_t capacity);
740
741 /// Reads 'size' values from the associated field, starting from 'firstIndex'. Note that the index is given
742 /// relative to a certain cluster. The return value points to the array of read objects.
743 /// The 'maskReq' parameter is a bool array of at least 'size' elements. Only objects for which the mask is
744 /// true are guaranteed to be read in the returned value array. A 'nullptr' means to read all elements.
745 void *ReadBulk(RClusterIndex firstIndex, const bool *maskReq, std::size_t size)
746 {
747 if (!ContainsRange(firstIndex, size))
748 Reset(firstIndex, size);
749
750 // We may read a sub range of the currently available range
751 auto offset = firstIndex.GetIndex() - fFirstIndex.GetIndex();
752
753 if (fNValidValues == fSize)
754 return GetValuePtrAt(offset);
755
756 RBulkSpec bulkSpec;
757 bulkSpec.fFirstIndex = firstIndex;
758 bulkSpec.fCount = size;
759 bulkSpec.fMaskReq = maskReq;
760 bulkSpec.fMaskAvail = &fMaskAvail[offset];
761 bulkSpec.fValues = GetValuePtrAt(offset);
762 bulkSpec.fAuxData = &fAuxData;
763 auto nRead = fField->ReadBulk(bulkSpec);
764 if (nRead == RBulkSpec::kAllSet) {
765 if ((offset == 0) && (size == fSize)) {
767 } else {
769 }
770 } else {
771 fNValidValues += nRead;
772 }
773 return GetValuePtrAt(offset);
774 }
775
776 /// Overload to read all elements in the given cluster range.
777 void *ReadBulk(RNTupleClusterRange range) { return ReadBulk(*range.begin(), nullptr, range.size()); }
778};
779
780namespace Internal {
781// At some point, RFieldBase::OnClusterCommit() may allow for a user-defined callback to change the
782// column representation. For now, we inject this for testing and internal use only.
784 static void SetPrimaryColumnRepresentation(RFieldBase &field, std::uint16_t newRepresentationIdx)
785 {
786 R__ASSERT(newRepresentationIdx < field.fColumnRepresentatives.size());
787 const auto N = field.fColumnRepresentatives[0].get().size();
788 R__ASSERT(N >= 1 && N <= 2);
790 field.fPrincipalColumn = field.fAvailableColumns[newRepresentationIdx * N].get();
791 if (field.fAuxiliaryColumn) {
792 R__ASSERT(N == 2);
793 field.fAuxiliaryColumn = field.fAvailableColumns[newRepresentationIdx * N + 1].get();
794 }
795 }
796};
797} // namespace Internal
798
799} // namespace Experimental
800} // namespace ROOT
801
802#endif
#define R__unlikely(expr)
Definition RConfig.hxx:594
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h: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 column is a storage-backed array of a simple, fixed-size type, from which pages can be mapped into ...
Definition RColumn.hxx:40
void Read(const 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.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
DescriptorId_t GetClusterId() const
ClusterSize_t::ValueType GetIndex() const
Field specific extra type information from the header / extenstion header.
Similar to RValue but manages an array of consecutive values.
bool fIsAdopted
True if the user provides the memory buffer for fValues.
void * ReadBulk(RClusterIndex firstIndex, const bool *maskReq, std::size_t size)
Reads 'size' values from the associated field, starting from 'firstIndex'.
RFieldBase * fField
The field that created the array of values.
std::vector< unsigned char > fAuxData
Reading arrays of complex values may require additional memory, for instance for the elements of arra...
bool ContainsRange(RClusterIndex firstIndex, std::size_t size) const
std::size_t fCapacity
The size of the array memory block in number of values.
std::unique_ptr< bool[]> fMaskAvail
Masks invalid values in the array.
std::size_t fValueSize
Cached copy of fField->GetValueSize()
void AdoptBuffer(void *buf, std::size_t capacity)
void * GetValuePtrAt(std::size_t idx) const
RBulk & operator=(const RBulk &)=delete
void Reset(RClusterIndex firstIndex, std::size_t size)
Sets a new range for the bulk.
void * ReadBulk(RNTupleClusterRange range)
Overload to read all elements in the given cluster range.
std::size_t fNValidValues
The sum of non-zero elements in the fMask.
RClusterIndex fFirstIndex
Index of the first value of the array.
std::size_t fSize
The number of available values in the array (provided their mask is set)
void * fValues
Cached deleter of fField.
std::unique_ptr< RFieldBase::RDeleter > fDeleter
Some fields have multiple possible column representations, e.g.
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.
const ColumnRepresentation_t & GetSerializationDefault() const
The first column list from fSerializationTypes is the default for writing.
A functor to release the memory acquired by CreateValue (memory and constructor).
virtual void operator()(void *objPtr, bool dtorOnly)
Iterates over the sub tree of fields in depth-first search order.
std::conditional_t< IsConstT, const RFieldBase *, RFieldBase * > pointer
std::vector< Position > fStack
The stack of nodes visited when walking down the tree of fields.
void Advance()
Given that the iterator points to a valid field which is not the end iterator, go to the next field i...
std::conditional_t< IsConstT, const RFieldBase, RFieldBase > value_type
std::conditional_t< IsConstT, const RFieldBase &, RFieldBase & > reference
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.
RValue & operator=(RValue &&other)=default
void Read(NTupleSize_t globalIndex)
RFieldBase * fField
The field that created the RValue.
RValue & operator=(const RValue &)=default
const RFieldBase & GetField() const
void EmplaceNew()
Replace the current object pointer by a pointer to a new object constructed by the field.
std::shared_ptr< void > fObjPtr
Set by Bind() or by RFieldBase::CreateValue(), SplitValue() or BindValue()
std::shared_ptr< T > GetPtr() const
void Read(RClusterIndex clusterIndex)
void Bind(std::shared_ptr< void > objPtr)
RValue(RFieldBase *field, std::shared_ptr< void > objPtr)
A field translates read and write calls from/to underlying columns to/from tree values.
static constexpr std::uint32_t kInvalidTypeVersion
RBulk CreateBulk()
The returned bulk is initially empty; RBulk::ReadBulk will construct the array of values.
static constexpr int kTraitTriviallyDestructible
The type is cleaned up just by freeing its memory. I.e. the destructor performs a no-op.
const std::string & GetTypeAlias() const
const RFieldBase * GetParent() const
virtual void GenerateColumns()
Implementations in derived classes should create the backing columns corresponsing to the field type ...
void Attach(std::unique_ptr< RFieldBase > child)
Add a new subfield to the list of nested fields.
bool HasDefaultColumnRepresentative() const
Whether or not an explicit column representative was set.
std::uint32_t fOnDiskTypeVersion
C++ type version cached from the descriptor after a call to ConnectPageSource()
std::uint32_t GetOnDiskTypeChecksum() const
Return checksum stored in the field descriptor; only valid after a call to ConnectPageSource(),...
void AutoAdjustColumnTypes(const RNTupleWriteOptions &options)
When connecting a field to a page sink, the field's default column representation is subject to adjus...
RFieldBase & operator=(RFieldBase &&)=default
void SetColumnRepresentatives(const RColumnRepresentations::Selection_t &representatives)
Fixes a column representative.
ENTupleStructure fStructure
The role of this field in the data model structure.
std::vector< RFieldBase * > GetSubFields()
static std::vector< RCheckResult > Check(const std::string &fieldName, const std::string &typeName)
Checks if the given type is supported by RNTuple.
virtual void GenerateColumns(const RNTupleDescriptor &)
Implementations in derived classes should create the backing columns corresponsing to the field type ...
static constexpr int kTraitMappable
A field of a fundamental type that can be directly mapped via RField<T>::Map(), i....
virtual bool HasExtraTypeInfo() const
std::function< void(void *)> ReadCallback_t
EState fState
Changed by ConnectTo[Sink,Source], reset by Clone()
static constexpr int kTraitTriviallyConstructible
No constructor needs to be called, i.e.
std::string fTypeAlias
A typedef or using name that was used when creating the field.
const std::string & GetDescription() const
Get the field's description.
const std::string & GetFieldName() const
RSchemaIteratorTemplate< false > RSchemaIterator
ENTupleStructure GetStructure() const
const std::string & GetTypeName() const
RFieldBase(RFieldBase &&)=default
virtual void AcceptVisitor(Detail::RFieldVisitor &visitor) const
std::string fDescription
Free text set by the user.
static Internal::RColumn * GetPrincipalColumnOf(const RFieldBase &other)
Fields may need direct access to the principal column of their sub fields, e.g. in RRVecField::ReadBu...
friend struct ROOT::Experimental::Internal::RFieldCallbackInjector
std::size_t fNRepetitions
For fixed sized arrays, the array length.
RFieldBase & operator=(const RFieldBase &)=delete
RFieldBase * fParent
Sub fields point to their mother field.
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:451
void FlushColumns()
Flushes data from active columns.
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &canonicalType, const std::string &typeAlias, bool continueOnError=false)
Factory method to resurrect a field from the stored on-disk type information.
static std::size_t CallAppendOn(RFieldBase &other, const void *from)
Allow derived classes to call Append and Read on other (sub) fields.
int fTraits
Properties of the type that allow for optimizations of collections of that type.
static std::unique_ptr< RDeleter > GetDeleterOf(const RFieldBase &other)
Internal::RColumn * fAuxiliaryColumn
Some fields have a second column in its column representation.
void ConnectPageSink(Internal::RPageSink &pageSink, NTupleSize_t firstEntry=0)
Fields and their columns live in the void until connected to a physical page storage.
DescriptorId_t fOnDiskId
When the columns are connected to a page source or page sink, the field represents a field id in the ...
virtual std::size_t AppendImpl(const void *from)
Operations on values of complex types, e.g.
static constexpr int kTraitTypeChecksum
The TClass checksum is set and valid.
void Read(NTupleSize_t globalIndex, void *to)
Populate a single value with data from the field.
bool fIsSimple
A field qualifies as simple if it is both mappable and has no post-read callback.
RConstSchemaIterator cend() const
virtual RExtraTypeInfoDescriptor GetExtraTypeInfo() const
std::vector< std::reference_wrapper< const ColumnRepresentation_t > > fColumnRepresentatives
Pointers into the static vector GetColumnRepresentations().GetSerializationTypes() when SetColumnRepr...
std::uint32_t GetOnDiskTypeVersion() const
Return the C++ type version stored in the field descriptor; only valid after a call to ConnectPageSou...
std::string GetQualifiedFieldName() const
Returns the field name and parent field names separated by dots ("grandparent.parent....
virtual std::uint32_t GetTypeVersion() const
Indicates an evolution of the C++ type itself.
std::vector< EColumnType > ColumnRepresentation_t
void GenerateColumnsImpl(const RNTupleDescriptor &desc)
For reading, use the on-disk column list.
virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec)
General implementation of bulk read.
void GenerateColumnsImpl(const ColumnRepresentation_t &representation, std::uint16_t representationIndex)
Helpers for generating columns.
virtual std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const =0
Called by Clone(), which additionally copies the on-disk ID.
std::size_t Append(const void *from)
Write the given value into columns.
RFieldBase(const RFieldBase &)=delete
virtual void ReadInClusterImpl(RClusterIndex clusterIndex, void *to)
void RemoveReadCallback(size_t idx)
void * CreateObjectRawPtr() const
Factory method for the field's type. The caller owns the returned pointer.
virtual std::uint32_t GetTypeChecksum() const
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
void CommitCluster()
Flushes data from active columns to disk and calls CommitClusterImpl.
const ColumnRepresentation_t & EnsureCompatibleColumnTypes(const RNTupleDescriptor &desc, std::uint16_t representationIndex) const
Returns the on-disk column types found in the provided descriptor for fOnDiskId and the given represe...
void ConnectPageSource(Internal::RPageSource &pageSource)
Connects the field and its sub field tree to the given page source.
RValue CreateValue()
Generates an object of the field type and wraps the created object in a shared pointer and returns it...
std::unique_ptr< RFieldBase > Clone(std::string_view newName) const
Copies the field and its sub fields using a possibly new name and a new, unconnected set of columns.
std::size_t ReadBulk(const RBulkSpec &bulkSpec)
Returns the number of newly available values, that is the number of bools in bulkSpec....
virtual std::unique_ptr< RDeleter > GetDeleter() const
static void CallReadOn(RFieldBase &other, RClusterIndex clusterIndex, void *to)
virtual std::uint32_t GetFieldVersion() const
Indicates an evolution of the mapping scheme from C++ type to columns.
virtual void ConstructValue(void *where) const =0
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
RConstSchemaIterator cbegin() const
RSchemaIteratorTemplate< true > RConstSchemaIterator
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...
virtual std::vector< RValue > SplitValue(const RValue &value) const
Creates the list of direct child values given a value for this field.
std::vector< std::unique_ptr< Internal::RColumn > > fAvailableColumns
The columns are connected either to a sink or to a source (not to both); they are owned by the field.
void SetOnDiskId(DescriptorId_t id)
std::size_t GetNRepetitions() const
RColumnRepresentations::Selection_t GetColumnRepresentatives() const
Returns the fColumnRepresentative pointee or, if unset, the field's default representative.
virtual ~RFieldBase()=default
static void * CallCreateObjectRawPtrOn(RFieldBase &other)
std::string fName
The field name relative to its parent field.
virtual size_t GetAlignment() const =0
As a rule of thumb, the alignment is equal to the size of the type.
void InvokeReadCallbacks(void *target)
std::uint32_t fOnDiskTypeChecksum
TClass checksum cached from the descriptor after a call to ConnectPageSource().
virtual void OnConnectPageSource()
Called by ConnectPageSource() once connected; derived classes may override this as appropriate.
static void CallReadOn(RFieldBase &other, NTupleSize_t globalIndex, void *to)
void Read(RClusterIndex clusterIndex, void *to)
Populate a single value with data from the field.
static void CallConstructValueOn(const RFieldBase &other, void *where)
Allow derived classes to call ConstructValue(void *) and GetDeleter on other (sub) fields.
std::vector< std::unique_ptr< RFieldBase > > fSubFields
Collections and classes own sub fields.
std::string fType
The C++ type captured by this field.
Internal::RColumn * fPrincipalColumn
All fields that have columns have a distinct main column.
DescriptorId_t GetOnDiskId() const
virtual size_t GetValueSize() const =0
The number of bytes taken by a value of the appropriate type.
static constexpr int kTraitTrivialType
Shorthand for types that are both trivially constructible and destructible.
EState
During its lifetime, a field undergoes the following possible state transitions:
std::vector< ReadCallback_t > fReadCallbacks
List of functions to be called after reading a value.
void SetDescription(std::string_view description)
NTupleSize_t EntryToColumnElementIndex(NTupleSize_t globalIndex) const
Translate an entry index to a column element index of the principal column and viceversa.
RValue BindValue(std::shared_ptr< void > objPtr)
Creates a value from a memory location with an already constructed object.
virtual void ReadGlobalImpl(NTupleSize_t globalIndex, void *to)
void GenerateColumnsImpl()
For writing, use the currently set column representative.
virtual const RColumnRepresentations & GetColumnRepresentations() const
Implementations in derived classes should return a static RColumnRepresentations object.
Used to loop over entries of collections in a single cluster.
The on-storage meta-data of an ntuple.
Processor specializiation for horizontally concatenated RNTuples (joins).
Common user-tunable settings for storing ntuples.
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:194
void CallConnectPageSinkOnField(RFieldBase &, RPageSink &, NTupleSize_t firstEntry=0)
void CallFlushColumnsOnField(RFieldBase &)
void CallConnectPageSourceOnField(RFieldBase &, RPageSource &)
void CallCommitClusterOnField(RFieldBase &)
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
ENTupleStructure
The fields in the ntuple model tree can carry different structural information about the type system.
constexpr DescriptorId_t kInvalidDescriptorId
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static void SetPrimaryColumnRepresentation(RFieldBase &field, std::uint16_t newRepresentationIdx)
void * fValues
The destination area, which has to be a big enough array of valid objects of the correct type.
const bool * fMaskReq
A bool array of size fCount, indicating the required values in the requested range.
bool * fMaskAvail
A bool array of size fCount, indicating the valid values in fValues.
std::size_t fCount
Size of the bulk range.
RClusterIndex fFirstIndex
Start of the bulk range.
std::vector< unsigned char > * fAuxData
Reference to memory owned by the RBulk class.
static const std::size_t kAllSet
As a return value of ReadBulk and ReadBulkImpl(), indicates that the full bulk range was read indepen...
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.
std::conditional_t< IsConstT, const RFieldBase *, RFieldBase * > FieldPtr_t
RSharedPtrDeleter(std::unique_ptr< RFieldBase::RDeleter > deleter)
std::unique_ptr< RFieldBase::RDeleter > fDeleter