Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RFieldSequenceContainer.hxx
Go to the documentation of this file.
1/// \file ROOT/RField/SequenceContainer.hxx
2/// \ingroup NTuple
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-09
5
6/*************************************************************************
7 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#ifndef ROOT_RField_SequenceContainer
15#define ROOT_RField_SequenceContainer
16
17#ifndef ROOT_RField
18#error "Please include RField.hxx!"
19#endif
20
21#include <ROOT/RFieldBase.hxx>
22#include <ROOT/RNTupleUtil.hxx>
23#include <ROOT/RVec.hxx>
24
25#include <array>
26#include <memory>
27#include <vector>
28
29namespace ROOT {
30
31namespace Detail {
32class RFieldVisitor;
33} // namespace Detail
34
35////////////////////////////////////////////////////////////////////////////////
36/// Template specializations for C++ std::array and C-style arrays
37////////////////////////////////////////////////////////////////////////////////
38
39/// The generic field for fixed size arrays, which do not need an offset column
40class RArrayField : public RFieldBase {
41private:
42 class RArrayDeleter : public RDeleter {
43 private:
44 std::size_t fItemSize = 0;
45 std::size_t fArrayLength = 0;
46 std::unique_ptr<RDeleter> fItemDeleter;
47
48 public:
49 RArrayDeleter(std::size_t itemSize, std::size_t arrayLength, std::unique_ptr<RDeleter> itemDeleter)
51 {
52 }
53 void operator()(void *objPtr, bool dtorOnly) final;
54 };
55
56 std::size_t fItemSize;
57 std::size_t fArrayLength;
58
59protected:
60 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
61
62 void ConstructValue(void *where) const final;
63 std::unique_ptr<RDeleter> GetDeleter() const final;
64
65 std::size_t AppendImpl(const void *from) final;
68
69public:
70 RArrayField(std::string_view fieldName, std::unique_ptr<RFieldBase> itemField, std::size_t arrayLength);
74
76 size_t GetLength() const { return fArrayLength; }
78 size_t GetAlignment() const final { return fSubfields[0]->GetAlignment(); }
80};
81
82template <typename ItemT, std::size_t N>
83class RField<std::array<ItemT, N>> : public RArrayField {
84public:
85 static std::string TypeName() { return "std::array<" + RField<ItemT>::TypeName() + "," + std::to_string(N) + ">"; }
86 explicit RField(std::string_view name) : RArrayField(name, std::make_unique<RField<ItemT>>("_0"), N) {}
87 RField(RField &&other) = default;
88 RField &operator=(RField &&other) = default;
89 ~RField() override = default;
90};
91
92template <typename ItemT, std::size_t N>
93class RField<ItemT[N]> final : public RField<std::array<ItemT, N>> {
94public:
95 explicit RField(std::string_view name) : RField<std::array<ItemT, N>>(name) {}
96 RField(RField &&other) = default;
99};
100
101////////////////////////////////////////////////////////////////////////////////
102/// Template specializations for ROOT's RVec
103////////////////////////////////////////////////////////////////////////////////
104
105/// The type-erased field for a RVec<Type>
107public:
108 /// the RRVecDeleter is also used by RArrayAsRVecField and therefore declared public
109 class RRVecDeleter : public RDeleter {
110 private:
111 std::size_t fItemAlignment;
112 std::size_t fItemSize = 0;
113 std::unique_ptr<RDeleter> fItemDeleter;
114
115 public:
116 explicit RRVecDeleter(std::size_t itemAlignment) : fItemAlignment(itemAlignment) {}
117 RRVecDeleter(std::size_t itemAlignment, std::size_t itemSize, std::unique_ptr<RDeleter> itemDeleter)
118 : fItemAlignment(itemAlignment), fItemSize(itemSize), fItemDeleter(std::move(itemDeleter))
119 {
120 }
121 void operator()(void *objPtr, bool dtorOnly) final;
122 };
123
124 std::unique_ptr<RDeleter> fItemDeleter;
125
126protected:
127 std::size_t fItemSize;
129 std::size_t fValueSize;
130
131 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
133 void GenerateColumns() final;
135
136 void ConstructValue(void *where) const final;
137 std::unique_ptr<RDeleter> GetDeleter() const final;
138
139 std::size_t AppendImpl(const void *from) final;
142
143 void CommitClusterImpl() final { fNWritten = 0; }
144
145public:
146 RRVecField(std::string_view fieldName, std::unique_ptr<RFieldBase> itemField);
147 RRVecField(RRVecField &&) = default;
149 RRVecField(const RRVecField &) = delete;
151 ~RRVecField() override = default;
152
153 std::vector<RValue> SplitValue(const RValue &value) const final;
154 size_t GetValueSize() const final;
155 size_t GetAlignment() const final;
157 void
162 void
167};
168
169template <typename ItemT>
170class RField<ROOT::VecOps::RVec<ItemT>> final : public RRVecField {
171public:
172 RField(std::string_view fieldName, std::unique_ptr<RFieldBase> itemField)
174 {
175 }
176
177 explicit RField(std::string_view name) : RField(name, std::make_unique<RField<ItemT>>("_0")) {}
178 RField(RField &&other) = default;
181
182 static std::string TypeName() { return "ROOT::VecOps::RVec<" + RField<ItemT>::TypeName() + ">"; }
183};
184
185////////////////////////////////////////////////////////////////////////////////
186/// Template specializations for C++ std::vector
187////////////////////////////////////////////////////////////////////////////////
188
189/// The generic field for a (nested) std::vector<Type> except for std::vector<bool>
190/// The field can be constructed as untyped collection through CreateUntyped().
191class RVectorField : public RFieldBase {
192private:
193 class RVectorDeleter : public RDeleter {
194 private:
195 std::size_t fItemSize = 0;
196 std::unique_ptr<RDeleter> fItemDeleter;
197
198 public:
199 RVectorDeleter() = default;
200 RVectorDeleter(std::size_t itemSize, std::unique_ptr<RDeleter> itemDeleter)
201 : fItemSize(itemSize), fItemDeleter(std::move(itemDeleter))
202 {
203 }
204 void operator()(void *objPtr, bool dtorOnly) final;
205 };
206
207 std::size_t fItemSize;
209 std::unique_ptr<RDeleter> fItemDeleter;
210
211protected:
212 RVectorField(std::string_view fieldName, std::unique_ptr<RFieldBase> itemField, bool isUntyped);
213
214 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
215
216 const RColumnRepresentations &GetColumnRepresentations() const final;
217 void GenerateColumns() final;
218 void GenerateColumns(const ROOT::RNTupleDescriptor &desc) final;
219
220 void ConstructValue(void *where) const final { new (where) std::vector<char>(); }
221 std::unique_ptr<RDeleter> GetDeleter() const final;
222
223 std::size_t AppendImpl(const void *from) final;
224 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
225
226 void CommitClusterImpl() final { fNWritten = 0; }
227
228public:
229 RVectorField(std::string_view fieldName, std::unique_ptr<RFieldBase> itemField);
232 ~RVectorField() override = default;
233
234 static std::unique_ptr<RVectorField>
235 CreateUntyped(std::string_view fieldName, std::unique_ptr<RFieldBase> itemField);
236
237 std::vector<RValue> SplitValue(const RValue &value) const final;
238 size_t GetValueSize() const final { return sizeof(std::vector<char>); }
239 size_t GetAlignment() const final { return std::alignment_of<std::vector<char>>(); }
240 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
241 void
246 void
251};
252
253template <typename ItemT>
254class RField<std::vector<ItemT>> final : public RVectorField {
255public:
256 static std::string TypeName() { return "std::vector<" + RField<ItemT>::TypeName() + ">"; }
257 explicit RField(std::string_view name) : RVectorField(name, std::make_unique<RField<ItemT>>("_0")) {}
258 RField(RField &&other) = default;
259 RField &operator=(RField &&other) = default;
261};
262
263// std::vector<bool> is a template specialization and needs special treatment
264template <>
265class RField<std::vector<bool>> final : public RFieldBase {
266private:
267 ROOT::Internal::RColumnIndex fNWritten{0};
268
269protected:
270 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final
271 {
272 return std::make_unique<RField>(newName);
273 }
274
275 const RColumnRepresentations &GetColumnRepresentations() const final;
276 void GenerateColumns() final;
277 void GenerateColumns(const ROOT::RNTupleDescriptor &desc) final;
278
279 void ConstructValue(void *where) const final { new (where) std::vector<bool>(); }
280 std::unique_ptr<RDeleter> GetDeleter() const final { return std::make_unique<RTypedDeleter<std::vector<bool>>>(); }
281
282 std::size_t AppendImpl(const void *from) final;
283 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
284
285 void CommitClusterImpl() final { fNWritten = 0; }
286
287public:
288 static std::string TypeName() { return "std::vector<bool>"; }
289 explicit RField(std::string_view name);
290 RField(RField &&other) = default;
291 RField &operator=(RField &&other) = default;
293
294 std::vector<RValue> SplitValue(const RValue &value) const final;
295
296 size_t GetValueSize() const final { return sizeof(std::vector<bool>); }
297 size_t GetAlignment() const final { return std::alignment_of<std::vector<bool>>(); }
299 void
300 GetCollectionInfo(ROOT::NTupleSize_t globalIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size) const
301 {
303 }
304 void
305 GetCollectionInfo(RNTupleLocalIndex localIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size) const
306 {
308 }
309};
310
311////////////////////////////////////////////////////////////////////////////////
312/// Additional classes related to sequence containers
313////////////////////////////////////////////////////////////////////////////////
314
315/**
316\class ROOT::Experimental::RArrayAsRVecField
317\brief A field for fixed-size arrays that are represented as RVecs in memory.
318\ingroup NTuple
319This class is used only for reading. In particular, it helps exposing
320arbitrarily-nested std::array on-disk fields as RVecs for usage in RDataFrame.
321*/
323private:
324 std::unique_ptr<RDeleter> fItemDeleter; /// Sub field deleter or nullptr for simple fields
325 std::size_t fItemSize; /// The size of a child field's item
326 std::size_t fArrayLength; /// The length of the arrays in this field
327 std::size_t fValueSize; /// The size of a value of this field, i.e. an RVec
328
329protected:
330 std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
331
332 void GenerateColumns() final { R__ASSERT(false && "RArrayAsRVec fields must only be used for reading"); }
333 using RFieldBase::GenerateColumns;
334
335 void ConstructValue(void *where) const final;
336 /// Returns an RRVecField::RRVecDeleter
337 std::unique_ptr<RDeleter> GetDeleter() const final;
338
339 void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
340 void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final;
341
342public:
343 /**
344 Constructor of the field. the \p itemField argument represents the inner
345 item of the on-disk array, i.e. for an `std::array<float>` it is the `float`
346 field and not the `std::array` itself.
347 */
348 RArrayAsRVecField(std::string_view fieldName, std::unique_ptr<RFieldBase> itemField, std::size_t arrayLength);
354
355 std::size_t GetValueSize() const final { return fValueSize; }
356 std::size_t GetAlignment() const final;
357
358 std::vector<RFieldBase::RValue> SplitValue(const RFieldBase::RValue &value) const final;
359 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final;
360};
361
362} // namespace ROOT
363
364#endif
size_t fValueSize
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#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 value
char name[80]
Definition TGX11.cxx:110
TRObject operator()(const T1 &t1) const
Abstract base class for classes implementing the visitor design pattern.
The in-memory representation of a 32bit or 64bit on-disk index column.
void GetCollectionInfo(const ROOT::NTupleSize_t globalIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *collectionSize)
For offset columns only, look at the two adjacent values that define a collection's coordinates.
Definition RColumn.hxx:283
std::unique_ptr< RDeleter > fItemDeleter
std::size_t fArrayLength
The size of a child field's item.
std::size_t fItemSize
Sub field deleter or nullptr for simple fields.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
std::size_t fValueSize
The length of the arrays in this field.
RArrayDeleter(std::size_t itemSize, std::size_t arrayLength, std::unique_ptr< RDeleter > itemDeleter)
std::unique_ptr< RDeleter > fItemDeleter
void operator()(void *objPtr, bool dtorOnly) final
Template specializations for C++ std::array and C-style arrays.
std::unique_ptr< RDeleter > GetDeleter() const final
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
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.
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
Definition RField.hxx:197
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
void ConstructValue(void *where) const final
Constructs value in a given location of size at least GetValueSize(). Called by the base class' Creat...
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given an existing value for this field.
std::unique_ptr< RDeleter > GetDeleter() const final
Definition RField.hxx:182
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.
ROOT::Internal::RColumn * fPrincipalColumn
All fields that have columns have a distinct main column.
std::vector< std::unique_ptr< RFieldBase > > fSubfields
Collections and classes own subfields.
virtual const RColumnRepresentations & GetColumnRepresentations() const
Implementations in derived classes should return a static RColumnRepresentations object.
virtual void GenerateColumns()
Implementations in derived classes should create the backing columns corresponding to the field type ...
virtual void CommitClusterImpl()
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.
virtual std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec)
General implementation of bulk read.
RField(RField &&other)=default
~RField() final=default
RField & operator=(RField &&other)=default
RField(std::string_view fieldName, std::unique_ptr< RFieldBase > itemField)
RField & operator=(RField &&other)=default
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:283
~RField() final=default
RField & operator=(RField &&other)=default
static std::string TypeName()
Definition RField.hxx:285
RField(std::string_view name)
Definition RField.hxx:286
The on-storage metadata of an RNTuple.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
the RRVecDeleter is also used by RArrayAsRVecField and therefore declared public
RRVecDeleter(std::size_t itemAlignment, std::size_t itemSize, std::unique_ptr< RDeleter > itemDeleter)
std::unique_ptr< RDeleter > fItemDeleter
RRVecDeleter(std::size_t itemAlignment)
Template specializations for ROOT's RVec.
RRVecField & operator=(RRVecField &&)=default
~RRVecField() override=default
void GetCollectionInfo(RNTupleLocalIndex localIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size) const
RRVecField(const RRVecField &)=delete
ROOT::Internal::RColumnIndex fNWritten
std::unique_ptr< RDeleter > fItemDeleter
RRVecField(RRVecField &&)=default
RRVecField & operator=(RRVecField &)=delete
RVectorDeleter(std::size_t itemSize, std::unique_ptr< RDeleter > itemDeleter)
Template specializations for C++ std::vector.
RVectorField(RVectorField &&other)=default
void GetCollectionInfo(ROOT::NTupleSize_t globalIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size) const
void GetCollectionInfo(RNTupleLocalIndex localIndex, RNTupleLocalIndex *collectionStart, ROOT::NTupleSize_t *size) const
~RVectorField() override=default
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
std::unique_ptr< RDeleter > fItemDeleter
ROOT::Internal::RColumnIndex fNWritten
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
RVectorField & operator=(RVectorField &&other)=default
A "std::vector"-like collection of values implementing handy operation to analyse them.
Definition RVec.hxx:1529
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Input parameter to RFieldBase::ReadBulk() and RFieldBase::ReadBulkImpl().