16#ifndef ROOT7_RFieldBase
17#define ROOT7_RFieldBase
32namespace Experimental {
34class RCollectionField;
38struct RFieldCallbackInjector;
39struct RFieldRepresentationModifier;
89 operator delete(objPtr);
99 std::destroy_at(
static_cast<T *
>(objPtr));
260 template <std::uint32_t ColumnIndexT,
typename HeadT,
typename... TailTs>
263 assert(ColumnIndexT < representation.size());
265 Internal::RColumn::Create<HeadT>(representation[ColumnIndexT], ColumnIndexT, representationIndex));
277 if constexpr (
sizeof...(TailTs))
282 template <
typename... ColumnCppTs>
291 for (
unsigned i = 0; i <
N; ++i) {
298 template <
typename... ColumnCppTs>
301 std::uint16_t representationIndex = 0;
304 if (onDiskTypes.empty())
308 if (representationIndex > 0) {
309 for (std::size_t i = 0; i <
sizeof...(ColumnCppTs); ++i) {
314 representationIndex++;
342 virtual std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const = 0;
346 virtual std::unique_ptr<RDeleter>
GetDeleter()
const {
return std::make_unique<RDeleter>(); }
353 virtual std::size_t
AppendImpl(
const void *from);
359 std::size_t
Append(
const void *from);
396 virtual std::size_t
ReadBulkImpl(
const RBulkSpec &bulkSpec);
401 std::size_t
ReadBulk(
const RBulkSpec &bulkSpec);
439 const std::string &typeAlias,
bool fContinueOnError =
false);
442 template <
bool IsConstT>
443 class RSchemaIteratorTemplate;
448 template <
typename T>
464 std::size_t nRepetitions = 0);
472 std::unique_ptr<RFieldBase>
Clone(std::string_view newName)
const;
478 static std::vector<RCheckResult>
Check(
const std::string &fieldName,
const std::string &typeName);
491 template <
typename T>
492 std::unique_ptr<T, typename RCreateObjectDeleter<T>::deleter>
CreateObject()
const;
562template <
bool IsConstT>
566 using FieldPtr_t = std::conditional_t<IsConstT, const RFieldBase *, RFieldBase *>;
579 using value_type = std::conditional_t<IsConstT, const RFieldBase, RFieldBase>;
580 using pointer = std::conditional_t<IsConstT, const RFieldBase *, RFieldBase *>;
581 using reference = std::conditional_t<IsConstT, const RFieldBase &, RFieldBase &>;
590 auto itr =
fStack.rbegin();
591 if (!itr->fFieldPtr->fSubFields.empty()) {
592 fStack.emplace_back(
Position(itr->fFieldPtr->fSubFields[0].get(), 0));
596 unsigned int nextIdxInParent = ++(itr->fIdxInParent);
597 while (nextIdxInParent >= itr->fFieldPtr->fParent->fSubFields.size()) {
599 itr->fFieldPtr = itr->fFieldPtr->fParent;
600 itr->fIdxInParent = -1;
605 nextIdxInParent = ++(itr->fIdxInParent);
607 itr->fFieldPtr = itr->fFieldPtr->fParent->fSubFields[nextIdxInParent].get();
653 template <
typename T>
656 return std::static_pointer_cast<T>(
fObjPtr);
659 template <
typename T>
662 return *
static_cast<T *
>(
fObjPtr.get());
671 static const std::size_t
kAllSet = std::size_t(-1);
#define R__unlikely(expr)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#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)
NTupleSize_t GetNElements() const
Abstract interface to write data into an ntuple.
Abstract interface to read data from an ntuple.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
DescriptorId_t GetClusterId() const
ClusterSize_t::ValueType GetIndex() const
The collection field is only used for writing; when reading, untyped collections are projected to an ...
Similar to RValue but manages an array of consecutive values.
bool fIsAdopted
True if the user provides the memory buffer for fValues.
void * ReadBulk(RClusterIndex firstIndex, const bool *maskReq, std::size_t size)
Reads 'size' values from the associated field, starting from 'firstIndex'.
RFieldBase * fField
The field that created the array of values.
std::vector< unsigned char > fAuxData
Reading arrays of complex values may require additional memory, for instance for the elements of arra...
bool ContainsRange(RClusterIndex firstIndex, std::size_t size) const
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 Reset(RClusterIndex firstIndex, std::size_t size)
Sets a new range for the bulk.
std::size_t fNValidValues
The sum of non-zero elements in the fMask.
RClusterIndex fFirstIndex
Index of the first value of the array.
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(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 Read(RClusterIndex clusterIndex)
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.
static constexpr int kTraitTriviallyDestructible
The type is cleaned up just by freeing its memory. I.e. the destructor performs a no-op.
const std::string & GetTypeAlias() const
const RFieldBase * GetParent() const
virtual void GenerateColumns()
Implementations in derived classes should create the backing columns corresponsing to the field 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 ...
static constexpr int kTraitMappable
A field of a fundamental type that can be directly mapped via RField<T>::Map(), i....
virtual bool HasExtraTypeInfo() const
std::function< void(void *)> ReadCallback_t
EState fState
Changed by ConnectTo[Sink,Source], reset by Clone()
static constexpr int kTraitTriviallyConstructible
No constructor needs to be called, i.e.
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.
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.
int fTraits
Properties of the type that allow for optimizations of collections of that type.
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.
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.
static constexpr int kTraitTypeChecksum
The TClass checksum is set and valid.
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 both mappable and has no post-read callback.
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.
std::vector< EColumnType > ColumnRepresentation_t
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
virtual void ReadInClusterImpl(RClusterIndex clusterIndex, void *to)
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
static void CallReadOn(RFieldBase &other, RClusterIndex clusterIndex, void *to)
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
static RResult< std::unique_ptr< RFieldBase > > Create(const std::string &fieldName, const std::string &canonicalType, const std::string &typeAlias, bool fContinueOnError=false)
Factory method to resurrect a field from the stored on-disk type information.
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, the field's default representative.
virtual ~RFieldBase()=default
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)
void Read(RClusterIndex clusterIndex, void *to)
Populate a single value with data from the field.
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.
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.
static constexpr int kTraitTrivialType
Shorthand for types that are both trivially constructible and destructible.
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)
static RResult< void > EnsureValidFieldName(std::string_view fieldName)
Check whether a given string is a valid field name.
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)
NTupleSize_t GetNElements() const
virtual void CommitClusterImpl()
void GenerateColumnsImpl()
For writing, use the currently set column representative.
virtual const RColumnRepresentations & GetColumnRepresentations() const
Implementations in derived classes should return a static RColumnRepresentations object.
The on-storage meta-data of an ntuple.
Common user-tunable settings for storing ntuples.
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)
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.
ENTupleStructure
The fields in the ntuple model tree can carry different structural information about the type system.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
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.
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.
RClusterIndex fFirstIndex
Start 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