13#ifndef ROOT_RField_Record
14#define ROOT_RField_Record
17#error "Please include RField.hxx!"
27#include <unordered_set>
41 std::vector<std::unique_ptr<RFieldBase>> itemFields,
42 std::string_view emulatedFromType);
44void AddItemToRecord(RRecordField &record, std::unique_ptr<RFieldBase> newItem);
50 friend std::unique_ptr<RFieldBase>
52 std::string_view emulatedFromType);
61 RRecordDeleter(std::vector<std::unique_ptr<RDeleter>> itemDeleters,
const std::vector<std::size_t> &offsets)
65 void operator()(
void *objPtr,
bool dtorOnly)
final;
75 RRecordField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields,
76 std::string_view emulatedFromType);
86 void AddItem(std::unique_ptr<RFieldBase> item);
93 std::size_t
GetItemPadding(std::size_t baseOffset, std::size_t itemAlignment)
const;
95 std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const override;
98 std::unique_ptr<RDeleter>
GetDeleter() const final;
100 std::
size_t AppendImpl(const
void *from) final;
108 template <typename ContainerT>
111 static_assert(std::is_same_v<typename ContainerT::value_type, std::unique_ptr<ROOT::RFieldBase>>,
112 "ContainerT must hold std::unique_ptr<ROOT::RFieldBase>");
116 fOffsets.reserve(itemFields.size());
120 for (
auto &&item : itemFields) {
135 RRecordField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields);
144 return std::max<size_t>(1ul,
fSize);
159 std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const final;
164 RPairField(std::string_view fieldName, std::array<std::unique_ptr<RFieldBase>, 2> itemFields);
170template <
typename T1,
typename T2>
172 using ContainerT =
typename std::pair<T1, T2>;
175 static std::array<std::unique_ptr<RFieldBase>, 2> BuildItemFields()
177 return {std::make_unique<RField<T1>>(
"_0"), std::make_unique<
RField<T2>>(
"_1")};
182 explicit RField(std::string_view
name) : RPairField(
name, BuildItemFields())
199 std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const final;
204 RTupleField(std::string_view fieldName, std::vector<std::unique_ptr<RFieldBase>> itemFields);
210template <
typename... ItemTs>
212 using ContainerT =
typename std::tuple<ItemTs...>;
215 template <
typename HeadT,
typename... TailTs>
216 static std::string BuildItemTypes()
219 if constexpr (
sizeof...(TailTs) > 0)
220 result +=
"," + BuildItemTypes<TailTs...>();
224 template <
typename HeadT,
typename... TailTs>
225 static void _BuildItemFields(std::vector<std::unique_ptr<RFieldBase>> &itemFields,
unsigned int index = 0)
227 itemFields.emplace_back(
new RField<HeadT>(
"_" + std::to_string(index)));
228 if constexpr (
sizeof...(TailTs) > 0)
229 _BuildItemFields<TailTs...>(itemFields, index + 1);
231 static std::vector<std::unique_ptr<RFieldBase>> BuildItemFields()
233 std::vector<std::unique_ptr<RFieldBase>> result;
234 _BuildItemFields<ItemTs...>(result);
239 static std::string
TypeName() {
return "std::tuple<" + BuildItemTypes<ItemTs...>() +
">"; }
240 explicit RField(std::string_view
name) : RTupleField(
name, BuildItemFields())
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Abstract base class for classes implementing the visitor design pattern.
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
std::size_t fMaxAlignment
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
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.
@ kTraitTrivialType
Shorthand for types that are both trivially constructible and destructible.
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
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.
const std::string & GetTypeName() const
Classes with dictionaries that can be inspected by TClass.
RField & operator=(RField &&other)=default
static std::string TypeName()
RField(std::string_view name)
The on-storage metadata of an RNTuple.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Template specializations for C++ std::pair.
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
RPairField(std::string_view fieldName, std::array< std::unique_ptr< RFieldBase >, 2 > itemFields)
~RPairField() override=default
RPairField(RPairField &&other)=default
RPairField & operator=(RPairField &&other)=default
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
std::vector< std::size_t > fOffsets
RRecordDeleter(std::vector< std::unique_ptr< RDeleter > > itemDeleters, const std::vector< std::size_t > &offsets)
std::vector< std::unique_ptr< RDeleter > > fItemDeleters
void operator()(void *objPtr, bool dtorOnly) final
The field for an untyped record.
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 fMaxAlignment
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const override
Called by Clone(), which additionally copies the on-disk ID.
void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to) final
size_t GetAlignment() const final
As a rule of thumb, the alignment is equal to the size of the type.
RRecordField & operator=(RRecordField &&other)=default
size_t GetValueSize() const final
The number of bytes taken by a value of the appropriate type.
std::unordered_set< std::string > fSubfieldNames
Efficient detection of duplicate field names.
RRecordField(std::string_view name, const RRecordField &source)
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
void AttachItemFields(ContainerT &&itemFields)
std::unique_ptr< RDeleter > GetDeleter() const final
RRecordField(RRecordField &&other)=default
bool IsPairOrTuple() const
std::size_t GetItemPadding(std::size_t baseOffset, std::size_t itemAlignment) const
void AddItem(std::unique_ptr< RFieldBase > item)
Adds an additional item field.
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final
~RRecordField() override=default
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< std::size_t > fOffsets
std::size_t AppendImpl(const void *from) final
Operations on values of complex types, e.g.
const std::vector< std::size_t > & GetOffsets() const
void ReconcileOnDiskField(const RNTupleDescriptor &desc) override
For non-artificial fields, check compatibility of the in-memory field and the on-disk field.
Template specializations for C++ std::tuple.
~RTupleField() override=default
RTupleField(RTupleField &&other)=default
RTupleField(std::string_view fieldName, std::vector< std::unique_ptr< RFieldBase > > itemFields)
RTupleField & operator=(RTupleField &&other)=default
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
std::unique_ptr< RFieldBase > CreateEmulatedRecordField(std::string_view fieldName, std::vector< std::unique_ptr< RFieldBase > > itemFields, std::string_view emulatedFromType)
void AddItemToRecord(RRecordField &record, std::unique_ptr< RFieldBase > newItem)
bool StartsWith(std::string_view string, std::string_view prefix)
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.