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