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