Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RFieldSoA.hxx
Go to the documentation of this file.
1/// \file ROOT/RField/RFieldSoA.hxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \date 2026-03-03
4
5/*************************************************************************
6 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_RField_SoA
14#define ROOT_RField_SoA
15
16#ifndef ROOT_RField
17#error "Please include RField.hxx!"
18#endif
19
20#include <ROOT/RFieldBase.hxx>
21#include <ROOT/RNTupleTypes.hxx>
22
23#include <cstddef>
24#include <memory>
25#include <string_view>
26#include <typeinfo>
27#include <vector>
28
29class TClass;
30
31namespace ROOT {
32
33namespace Experimental {
34
35/// The SoA field provides I/O for an in-memory SoA layout linked to an on-disk collection of the underlying record.
36/// As a concrete example, for an underlying record type
37/// \code{.cpp}
38/// struct PointRecord {
39/// float px, py;
40/// };
41/// \endcode
42/// a corresponding SoA layout will look like
43/// \code{.cpp}
44/// struct PointSoA {
45/// ROOT::RVec<float> px;
46/// ROOT::RVec<float> py;
47/// };
48/// \endcode
49///
50/// The SoA type has to be marked in the dictionary with the rntupleSoARecord attribute.
51///
52/// Since the on-disk representation is a collection of record type, the class version and checksum of the SoA type
53/// itself is ignored.
54class RSoAField : public RFieldBase {
55 class RSoADeleter : public RDeleter {
56 private:
58
59 public:
60 explicit RSoADeleter(TClass *cl) : fSoAClass(cl) {}
61 void operator()(void *objPtr, bool dtorOnly) final;
62 };
63
64 TClass *fSoAClass = nullptr;
65 std::vector<RFieldBase *> fRecordMemberFields; ///< Direct access to the member fields of the underlying record
66 /// The offset of the RVec members in the SoA type in the order of subfields of the underlying record type.
67 /// In particular, the order is not necessarily the same then the order of RVec members in the SoA class.
68 std::vector<std::size_t> fSoAMemberOffsets;
69 std::size_t fMaxAlignment = 1;
71
72 RSoAField(std::string_view fieldName, const RSoAField &source); ///< Used by CloneImpl
73 RSoAField(std::string_view fieldName, TClass *clSoA);
74
75protected:
76 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
77
79 void GenerateColumns() final;
80 void GenerateColumns(const ROOT::RNTupleDescriptor &desc) final;
81
82 void ConstructValue(void *where) const final;
83 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RSoADeleter>(fSoAClass); }
84
85 std::size_t AppendImpl(const void *from) final;
86 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
87
89
90 void CommitClusterImpl() final { fNWritten = 0; }
91
92public:
93 RSoAField(std::string_view fieldName, std::string_view className);
94 RSoAField(RSoAField &&other) = default;
95 RSoAField &operator=(RSoAField &&other) = default;
96 ~RSoAField() override = default;
97
98 std::vector<RValue> SplitValue(const RValue &value) const final;
99 size_t GetValueSize() const final;
100 size_t GetAlignment() const final { return fMaxAlignment; }
101 std::uint32_t GetTypeVersion() const final;
102 std::uint32_t GetTypeChecksum() const final;
103 /// For polymorphic classes (that declare or inherit at least one virtual method), return the expected dynamic type
104 /// of any user object. If the class is not polymorphic, return nullptr.
105 /// TODO(jblomer): use information in unique pointer field
106 const std::type_info *GetPolymorphicTypeInfo() const;
107 // TODO(jblomer)
108 // void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
109
110 TClass *GetSoAClass() const { return fSoAClass; }
111};
112
113} // namespace Experimental
114} // namespace ROOT
115
116#endif // ROOT_RField_SoA
void operator()(void *objPtr, bool dtorOnly) final
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
~RSoAField() override=default
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
std::vector< std::size_t > fSoAMemberOffsets
The offset of the RVec members in the SoA type in the order of subfields of the underlying record typ...
Definition RFieldSoA.hxx:68
const std::type_info * GetPolymorphicTypeInfo() const
For polymorphic classes (that declare or inherit at least one virtual method), return the expected dy...
RSoAField & operator=(RSoAField &&other)=default
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
std::vector< RFieldBase * > fRecordMemberFields
Direct access to the member fields of the underlying record.
Definition RFieldSoA.hxx:65
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
RSoAField(std::string_view fieldName, const RSoAField &source)
Used by CloneImpl.
std::uint32_t GetTypeVersion() const final
Indicates an evolution of the C++ type itself.
std::unique_ptr< RDeleter > GetDeleter() const final
Definition RFieldSoA.hxx:83
std::uint32_t GetTypeChecksum() const final
Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
RSoAField(RSoAField &&other)=default
void ReconcileOnDiskField(const RNTupleDescriptor &) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
Definition RFieldSoA.hxx:88
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
ROOT::Internal::RColumnIndex fNWritten
Definition RFieldSoA.hxx:70
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
The in-memory representation of a 32bit or 64bit on-disk index column.
The list of column representations a field can have.
A functor to release the memory acquired by CreateValue() (memory and constructor).
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
RFieldBase(std::string_view name, std::string_view type, ROOT::ENTupleStructure structure, bool isSimple, std::size_t nRepetitions=0)
The constructor creates the underlying column objects and connects them to either a sink or a source.
The on-storage metadata of an RNTuple.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
STL class.
Namespace for ROOT features in testing.
Definition TROOT.h:100
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.