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 <mutex>
26#include <string_view>
27#include <typeinfo>
28#include <vector>
29
30class TClass;
31
32namespace ROOT {
33
34namespace Experimental {
35
36/// The SoA field provides I/O for an in-memory SoA layout linked to an on-disk collection of the underlying record.
37/// As a concrete example, for an underlying record type
38/// \code{.cpp}
39/// struct PointRecord {
40/// float px, py;
41/// };
42/// \endcode
43/// a corresponding SoA layout will look like
44/// \code{.cpp}
45/// struct PointSoA {
46/// ROOT::RVec<float> px;
47/// ROOT::RVec<float> py;
48/// };
49/// \endcode
50///
51/// The SoA type has to be marked in the dictionary with the rntupleSoARecord attribute.
52///
53/// Since the on-disk representation is a collection of record type, the class version and checksum of the SoA type
54/// itself is ignored.
55class RSoAField : public RFieldBase {
56 class RSoADeleter : public RDeleter {
57 private:
59
60 public:
61 explicit RSoADeleter(TClass *cl);
62 void operator()(void *objPtr, bool dtorOnly) final;
63 };
64
65 TClass *fSoAClass = nullptr;
66 std::vector<RFieldBase *> fRecordMemberFields; ///< Direct access to the member fields of the underlying record
67 /// The offset of the RVec members in the SoA type in the order of subfields of the underlying record type.
68 /// In particular, the order is not necessarily the same then the order of RVec members in the SoA class.
69 std::vector<std::size_t> fSoAMemberOffsets;
70 ///< A deleter returned by each record member's GetDeleter()
71 std::vector<std::unique_ptr<RDeleter>> fRecordMemberDeleters;
73
74 /// For reading and writing, the RVecs of the SoA class do not have a dedicated field. The in-memory RVecs of the
75 /// SoA object are used directly with the subfields of the underlying record type. For splitting a SoA class object
76 /// (SplitValue()), however, we need actual RRVecFields so that we can recursively split the in-memory SoA value.
77 /// The split fields are created only when SplitField() is called.
78 mutable std::unique_ptr<std::vector<std::unique_ptr<ROOT::RRVecField>>> fSplitFields;
79 mutable std::unique_ptr<std::mutex> fLockSplitFields; ///< protects the fSplitFields member.
80
81 RSoAField(std::string_view fieldName, const RSoAField &source); ///< Used by CloneImpl
82 RSoAField(std::string_view fieldName, TClass *clSoA);
83
84protected:
85 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
86
90
91 void ConstructValue(void *where) const final;
92 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RSoADeleter>(fSoAClass); }
93
94 std::size_t AppendImpl(const void *from) final;
95 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
96
98
99public:
100 RSoAField(std::string_view fieldName, std::string_view className);
103 ~RSoAField() override = default;
104
105 std::vector<RValue> SplitValue(const RValue &value) const final;
106 size_t GetValueSize() const final;
107 size_t GetAlignment() const final;
108 std::uint32_t GetTypeVersion() const final;
109 std::uint32_t GetTypeChecksum() const final;
110 /// For polymorphic classes (that declare or inherit at least one virtual method), return the expected dynamic type
111 /// of any user object. If the class is not polymorphic, return nullptr.
112 /// TODO(jblomer): use information in unique pointer field
115
116 TClass *GetSoAClass() const { return fSoAClass; }
117};
118
119} // namespace Experimental
120} // namespace ROOT
121
122#endif // ROOT_RField_SoA
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Abstract base class for classes implementing the visitor design pattern.
void operator()(void *objPtr, bool dtorOnly) final
The SoA field provides I/O for an in-memory SoA layout linked to an on-disk collection of the underly...
Definition RFieldSoA.hxx:55
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:69
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
const std::type_info * GetPolymorphicTypeInfo() const
For polymorphic classes (that declare or inherit at least one virtual method), return the expected dy...
size_t GetValueSize() const final
What sizeof(T) for this type returns.
std::vector< std::unique_ptr< RDeleter > > fRecordMemberDeleters
Definition RFieldSoA.hxx:71
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.
size_t GetAlignment() const final
What alignof(T) for this type returns.
std::vector< RFieldBase * > fRecordMemberFields
Direct access to the member fields of the underlying record.
Definition RFieldSoA.hxx:66
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:92
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
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:72
std::unique_ptr< std::vector< std::unique_ptr< ROOT::RRVecField > > > fSplitFields
For reading and writing, the RVecs of the SoA class do not have a dedicated field.
Definition RFieldSoA.hxx:78
std::unique_ptr< std::mutex > fLockSplitFields
protects the fSplitFields member.
Definition RFieldSoA.hxx:79
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.
A field translates read and write calls from/to underlying columns to/from tree values.
The on-storage metadata of an RNTuple.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.