16#ifndef ROOT7_RFieldBase
17#define ROOT7_RFieldBase
34namespace Experimental {
38class RNTupleJoinProcessor;
41struct RFieldCallbackInjector;
42struct RFieldRepresentationModifier;
52 const RCreateFieldOptions &options,
const RNTupleDescriptor *desc, DescriptorId_t
fieldId);
107 template <
typename T>
112 std::destroy_at(
static_cast<T *
>(
objPtr));
252 field->SetArtificial();
316 if constexpr (
sizeof...(TailTs))
330 for (
unsigned i = 0; i <
N; ++i) {
348 for (std::size_t i = 0; i <
sizeof...(ColumnCppTs); ++i) {
385 virtual std::unique_ptr<RDeleter>
GetDeleter()
const {
return std::make_unique<RDeleter>(); }
392 virtual std::size_t
AppendImpl(
const void *from);
398 std::size_t
Append(
const void *from);
494 const RCreateFieldOptions &options,
const RNTupleDescriptor *desc,
498 template <
bool IsConstT>
499 class RSchemaIteratorTemplate;
504 template <
typename T>
528 std::unique_ptr<RFieldBase>
Clone(std::string_view
newName)
const;
536 static std::vector<RCheckResult>
Check(
const std::string &
fieldName,
const std::string &typeName);
547 template <
typename T>
548 std::unique_ptr<T, typename RCreateObjectDeleter<T>::deleter>
CreateObject()
const;
621template <
bool IsConstT>
625 using FieldPtr_t = std::conditional_t<IsConstT, const RFieldBase *, RFieldBase *>;
638 using value_type = std::conditional_t<IsConstT, const RFieldBase, RFieldBase>;
639 using pointer = std::conditional_t<IsConstT, const RFieldBase *, RFieldBase *>;
640 using reference = std::conditional_t<IsConstT, const RFieldBase &, RFieldBase &>;
650 if (!
itr->fFieldPtr->fSubFields.empty()) {
658 itr->fFieldPtr =
itr->fFieldPtr->fParent;
659 itr->fIdxInParent = -1;
712 template <
typename T>
715 return std::static_pointer_cast<T>(
fObjPtr);
718 template <
typename T>
721 return *
static_cast<T *
>(
fObjPtr.get());
730 static const std::size_t
kAllSet = std::size_t(-1);
845 const auto N =
field.fColumnRepresentatives[0].get().size();
849 if (
field.fAuxiliaryColumn) {
#define R__unlikely(expr)
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.
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
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 ...
void Read(const NTupleSize_t globalIndex, void *to)
Abstract interface to write data into an ntuple.
Abstract interface to read data from an ntuple.
The field for a class with dictionary.
Similar to RValue but manages an array of consecutive values.
bool fIsAdopted
True if the user provides the memory buffer for fValues.
void Reset(RNTupleLocalIndex firstIndex, std::size_t size)
Sets a new range for the bulk.
RFieldBase * fField
The field that created the array of values.
RNTupleLocalIndex fFirstIndex
Index of the first value of the array.
std::vector< unsigned char > fAuxData
Reading arrays of complex values may require additional memory, for instance for the elements of arra...
RBulk(const RBulk &)=delete
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)
void * GetValuePtrAt(std::size_t idx) const
RBulk & operator=(const RBulk &)=delete
void * ReadBulk(RNTupleClusterRange range)
Overload to read all elements in the given cluster range.
void * ReadBulk(RNTupleLocalIndex firstIndex, const bool *maskReq, std::size_t size)
Reads 'size' values from the associated field, starting from 'firstIndex'.
std::size_t fNValidValues
The sum of non-zero elements in the fMask.
bool ContainsRange(RNTupleLocalIndex firstIndex, std::size_t size) const
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.
const Selection_t & GetSerializationTypes() const
std::vector< ColumnRepresentation_t > Selection_t
A list of column representations.
Selection_t fSerializationTypes
const Selection_t & GetDeserializationTypes() const
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 ~RDeleter()=default
virtual void operator()(void *objPtr, bool dtorOnly)
Iterates over the sub tree of fields in depth-first search order.
reference operator*() const
RSchemaIteratorTemplate(pointer val, int idxInParent)
std::conditional_t< IsConstT, const RFieldBase *, RFieldBase * > pointer
RSchemaIteratorTemplate()
pointer operator->() const
std::vector< Position > fStack
The stack of nodes visited when walking down the tree of fields.
std::ptrdiff_t difference_type
~RSchemaIteratorTemplate()
void Advance()
Given that the iterator points to a valid field which is not the end iterator, go to the next field i...
bool operator!=(const iterator &rh) const
bool operator==(const iterator &rh) const
std::conditional_t< IsConstT, const RFieldBase, RFieldBase > value_type
std::forward_iterator_tag iterator_category
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
RValue(const RValue &)=default
void Read(RNTupleLocalIndex localIndex)
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()
void BindRawPtr(void *rawPtr)
std::shared_ptr< T > GetPtr() const
void Bind(std::shared_ptr< void > objPtr)
RValue(RFieldBase *field, std::shared_ptr< void > objPtr)
RValue(RValue &&other)=default
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.
const std::string & GetTypeAlias() const
const RFieldBase * GetParent() const
void Read(RNTupleLocalIndex localIndex, void *to)
Populate a single value with data from the field.
virtual void GenerateColumns()
Implementations in derived classes should create the backing columns corresponsing to the field type ...
std::uint32_t fTraits
Properties of the type that allow for optimizations of collections of that type.
void Attach(std::unique_ptr< RFieldBase > child)
Add a new subfield to the list of nested fields.
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...
RFieldBase & operator=(RFieldBase &&)=default
void SetColumnRepresentatives(const RColumnRepresentations::Selection_t &representatives)
Fixes a column representative.
ENTupleStructure fStructure
The role of this field in the data model structure.
std::vector< RFieldBase * > GetSubFields()
static std::vector< RCheckResult > Check(const std::string &fieldName, const std::string &typeName)
Checks if the given type is supported by RNTuple.
virtual void GenerateColumns(const RNTupleDescriptor &)
Implementations in derived classes should create the backing columns corresponsing to the field type ...
std::vector< ENTupleColumnType > ColumnRepresentation_t
virtual bool HasExtraTypeInfo() const
std::function< void(void *)> ReadCallback_t
EState fState
Changed by ConnectTo[Sink,Source], reset by Clone()
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
std::string fDescription
Free text set by the user.
virtual void ReadInClusterImpl(RNTupleLocalIndex localIndex, void *to)
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
bool HasReadCallbacks() const
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.
void FlushColumns()
Flushes data from active columns.
static std::size_t CallAppendOn(RFieldBase &other, const void *from)
Allow derived classes to call Append and Read on other (sub) fields.
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.
bool IsArtificial() const
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.
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 mappable (which implies it has a single principal column),...
static void CallReadOn(RFieldBase &other, RNTupleLocalIndex localIndex, void *to)
RConstSchemaIterator cend() const
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....
virtual std::uint32_t GetTypeVersion() const
Indicates an evolution of the C++ type itself.
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.
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.
RFieldBase(const RFieldBase &)=delete
@ kTraitTrivialType
Shorthand for types that are both trivially constructible and destructible.
@ kTraitEmulatedField
This field is a user defined type that was missing dictionaries and was reconstructed from the on-dis...
@ kTraitTriviallyConstructible
No constructor needs to be called, i.e.
@ kTraitMappable
A field of a fundamental type that can be directly mapped via RField<T>::Map(), i....
@ kTraitTypeChecksum
The TClass checksum is set and valid.
@ kTraitTriviallyDestructible
The type is cleaned up just by freeing its memory. I.e. the destructor performs a no-op.
@ kTraitInvalidField
This field is an instance of RInvalidField and can be safely static_cast to it.
bool fIsArtificial
A field that is not backed on disk but computed, e.g.
virtual void BeforeConnectPageSource(Internal::RPageSource &)
Called by ConnectPageSource() before connecting; derived classes may override this as appropriate.
void RemoveReadCallback(size_t idx)
void * CreateObjectRawPtr() const
Factory method for the field's type. The caller owns the returned pointer.
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.
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...
void ConnectPageSource(Internal::RPageSource &pageSource)
Connects the field and its sub field tree to the given page source.
RValue CreateValue()
Generates an object of the field type and wraps the created object in a shared pointer and returns it...
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.
std::size_t ReadBulk(const RBulkSpec &bulkSpec)
Returns the number of newly available values, that is the number of bools in bulkSpec....
virtual std::unique_ptr< RDeleter > GetDeleter() const
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
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...
virtual std::vector< RValue > SplitValue(const RValue &value) const
Creates the list of direct child values given a value for this field.
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)
std::size_t GetNRepetitions() const
RColumnRepresentations::Selection_t GetColumnRepresentatives() const
Returns the fColumnRepresentative pointee or, if unset (always the case for artificial fields),...
virtual ~RFieldBase()=default
std::uint32_t GetTraits() const
static void * CallCreateObjectRawPtrOn(RFieldBase &other)
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)
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.
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &canonicalType, const std::string &typeAlias, const RCreateFieldOptions &options={}, const RNTupleDescriptor *desc=nullptr, DescriptorId_t fieldId=kInvalidDescriptorId)
Factory method to resurrect a field from the stored on-disk type information.
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.
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)
NTupleSize_t EntryToColumnElementIndex(NTupleSize_t globalIndex) const
Translate an entry index to a column element index of the principal column and viceversa.
RValue BindValue(std::shared_ptr< void > objPtr)
Creates a value from a memory location with an already constructed object.
virtual void ReadGlobalImpl(NTupleSize_t globalIndex, void *to)
virtual void CommitClusterImpl()
void GenerateColumnsImpl()
For writing, use the currently set column representative.
RFieldBase(std::string_view name, std::string_view type, 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 const RColumnRepresentations & GetColumnRepresentations() const
Implementations in derived classes should return a static RColumnRepresentations object.
Used to loop over entries of collections in a single cluster.
The on-storage meta-data of an ntuple.
Processor specializiation for horizontally concatenated RNTuples (joins).
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
DescriptorId_t GetClusterId() const
NTupleSize_t GetIndexInCluster() const
Common user-tunable settings for storing ntuples.
const_iterator begin() const
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
void CallConnectPageSinkOnField(RFieldBase &, RPageSink &, NTupleSize_t firstEntry=0)
ROOT::RResult< std::unique_ptr< ROOT::Experimental::RFieldBase > > CallFieldBaseCreate(const std::string &fieldName, const std::string &canonicalType, const std::string &typeAlias, const RCreateFieldOptions &options, const RNTupleDescriptor *desc, DescriptorId_t fieldId)
void CallFlushColumnsOnField(RFieldBase &)
void CallConnectPageSourceOnField(RFieldBase &, RPageSource &)
void CallCommitClusterOnField(RFieldBase &)
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
ENTupleStructure
The fields in the ntuple model tree can carry different structural information about the type system.
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.
RNTupleLocalIndex fFirstIndex
Start of the bulk range.
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.
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::default_delete< T > deleter
Position(FieldPtr_t fieldPtr, int idxInParent)
std::conditional_t< IsConstT, const RFieldBase *, RFieldBase * > FieldPtr_t
void operator()(void *objPtr)
RSharedPtrDeleter(std::unique_ptr< RFieldBase::RDeleter > deleter)
std::unique_ptr< RFieldBase::RDeleter > fDeleter