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