Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::Experimental::RVariantField Class Reference

Template specializations for C++ std::variant.

The generic field for std::variant types

Definition at line 330 of file RFieldSTLMisc.hxx.

Classes

class  RVariantDeleter
 

Public Member Functions

 RVariantField (RVariantField &&other)=default
 
 RVariantField (std::string_view fieldName, std::vector< std::unique_ptr< RFieldBase > > itemFields)
 
 ~RVariantField () override=default
 
size_t GetAlignment () const final
 As a rule of thumb, the alignment is equal to the size of the type.
 
size_t GetValueSize () const final
 The number of bytes taken by a value of the appropriate type.
 
RVariantFieldoperator= (RVariantField &&other)=default
 
- Public Member Functions inherited from ROOT::Experimental::RFieldBase
 RFieldBase (const RFieldBase &)=delete
 
 RFieldBase (RFieldBase &&)=default
 
 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 ~RFieldBase ()=default
 
virtual void AcceptVisitor (Detail::RFieldVisitor &visitor) const
 
RSchemaIterator begin ()
 
RConstSchemaIterator begin () const
 
RValue BindValue (std::shared_ptr< void > objPtr)
 Creates a value from a memory location with an already constructed object.
 
RConstSchemaIterator cbegin () const
 
RConstSchemaIterator cend () const
 
std::unique_ptr< RFieldBaseClone (std::string_view newName) const
 Copies the field and its sub fields using a possibly new name and a new, unconnected set of columns.
 
RBulk CreateBulk ()
 The returned bulk is initially empty; RBulk::ReadBulk will construct the array of values.
 
template<>
std::unique_ptr< void, typename RFieldBase::RCreateObjectDeleter< void >::deleter > CreateObject () const
 
template<typename T >
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.
 
template<>
std::unique_ptr< void, typename ROOT::Experimental::RFieldBase::RCreateObjectDeleter< void >::deleter > CreateObject () const
 
RValue CreateValue ()
 Generates an object of the field type and wraps the created object in a shared pointer and returns it an RValue connected to the field.
 
RSchemaIterator end ()
 
RConstSchemaIterator end () const
 
RColumnRepresentations::Selection_t GetColumnRepresentatives () const
 Returns the fColumnRepresentative pointee or, if unset, the field's default representative.
 
const std::string & GetDescription () const
 Get the field's description.
 
const std::string & GetFieldName () const
 
virtual std::uint32_t GetFieldVersion () const
 Indicates an evolution of the mapping scheme from C++ type to columns.
 
std::size_t GetNRepetitions () const
 
DescriptorId_t GetOnDiskId () const
 
std::uint32_t GetOnDiskTypeChecksum () const
 Return checksum stored in the field descriptor; only valid after a call to ConnectPageSource(), if the field stored a type checksum.
 
std::uint32_t GetOnDiskTypeVersion () const
 Return the C++ type version stored in the field descriptor; only valid after a call to ConnectPageSource()
 
const RFieldBaseGetParent () const
 
std::string GetQualifiedFieldName () const
 Returns the field name and parent field names separated by dots ("grandparent.parent.child")
 
EState GetState () const
 
ENTupleStructure GetStructure () const
 
std::vector< RFieldBase * > GetSubFields ()
 
std::vector< const RFieldBase * > GetSubFields () const
 
int GetTraits () const
 
const std::string & GetTypeAlias () const
 
virtual std::uint32_t GetTypeChecksum () const
 Return the current TClass reported checksum of this class. Only valid if kTraitTypeChecksum is set.
 
const std::string & GetTypeName () const
 
virtual std::uint32_t GetTypeVersion () const
 Indicates an evolution of the C++ type itself.
 
bool HasDefaultColumnRepresentative () const
 Whether or not an explicit column representative was set.
 
bool HasReadCallbacks () const
 
bool IsSimple () const
 
RFieldBaseoperator= (const RFieldBase &)=delete
 
RFieldBaseoperator= (RFieldBase &&)=default
 
void SetColumnRepresentatives (const RColumnRepresentations::Selection_t &representatives)
 Fixes a column representative.
 
void SetDescription (std::string_view description)
 
void SetOnDiskId (DescriptorId_t id)
 
virtual std::vector< RValueSplitValue (const RValue &value) const
 Creates the list of direct child values given a value for this field.
 

Protected Member Functions

std::size_t AppendImpl (const void *from) final
 Operations on values of complex types, e.g.
 
std::unique_ptr< RFieldBaseCloneImpl (std::string_view newName) const final
 Called by Clone(), which additionally copies the on-disk ID.
 
void CommitClusterImpl () final
 
void ConstructValue (void *where) const final
 Constructs value in a given location of size at least GetValueSize(). Called by the base class' CreateValue().
 
void GenerateColumns () final
 Implementations in derived classes should create the backing columns corresponsing to the field type for writing.
 
void GenerateColumns (const RNTupleDescriptor &desc) final
 Implementations in derived classes should create the backing columns corresponsing to the field type for reading.
 
const RColumnRepresentationsGetColumnRepresentations () const final
 Implementations in derived classes should return a static RColumnRepresentations object.
 
std::unique_ptr< RDeleterGetDeleter () const final
 
void ReadGlobalImpl (NTupleSize_t globalIndex, void *to) final
 
- Protected Member Functions inherited from ROOT::Experimental::RFieldBase
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 modify the value object.
 
std::size_t Append (const void *from)
 Write the given value into columns.
 
void Attach (std::unique_ptr< RFieldBase > child)
 Add a new subfield to the list of nested fields.
 
void AutoAdjustColumnTypes (const RNTupleWriteOptions &options)
 When connecting a field to a page sink, the field's default column representation is subject to adjustment according to the write options.
 
void * CreateObjectRawPtr () const
 Factory method for the field's type. The caller owns the returned pointer.
 
const ColumnRepresentation_tEnsureCompatibleColumnTypes (const RNTupleDescriptor &desc, std::uint16_t representationIndex) const
 Returns the on-disk column types found in the provided descriptor for fOnDiskId and the given representation index.
 
template<typename... ColumnCppTs>
void GenerateColumnsImpl ()
 For writing, use the currently set column representative.
 
template<std::uint32_t ColumnIndexT, typename HeadT , typename... TailTs>
void GenerateColumnsImpl (const ColumnRepresentation_t &representation, std::uint16_t representationIndex)
 Helpers for generating columns.
 
template<typename... ColumnCppTs>
void GenerateColumnsImpl (const RNTupleDescriptor &desc)
 For reading, use the on-disk column list.
 
virtual RExtraTypeInfoDescriptor GetExtraTypeInfo () const
 
virtual bool HasExtraTypeInfo () const
 
virtual void OnConnectPageSource ()
 Called by ConnectPageSource() once connected; derived classes may override this as appropriate.
 
void Read (NTupleSize_t globalIndex, void *to)
 Populate a single value with data from the field.
 
void Read (RClusterIndex clusterIndex, void *to)
 Populate a single value with data from the field.
 
std::size_t ReadBulk (const RBulkSpec &bulkSpec)
 Returns the number of newly available values, that is the number of bools in bulkSpec.fMaskAvail that flipped from false to true.
 
virtual std::size_t ReadBulkImpl (const RBulkSpec &bulkSpec)
 General implementation of bulk read.
 
virtual void ReadInClusterImpl (RClusterIndex clusterIndex, void *to)
 
void RemoveReadCallback (size_t idx)
 

Private Member Functions

 RVariantField (std::string_view name, const RVariantField &source)
 

Static Private Member Functions

static std::uint8_t GetTag (const void *variantPtr, std::size_t tagOffset)
 Extracts the index from an std::variant and transforms it into the 1-based index used for the switch column The implementation supports two memory layouts that are in use: a trailing unsigned byte, zero-indexed, having the exception caused empty state encoded by the max tag value, or a trailing unsigned int instead of a char.
 
static std::string GetTypeList (const std::vector< std::unique_ptr< RFieldBase > > &itemFields)
 
static void SetTag (void *variantPtr, std::size_t tagOffset, std::uint8_t tag)
 

Private Attributes

size_t fMaxAlignment = 1
 
size_t fMaxItemSize = 0
 
std::vector< ClusterSize_t::ValueTypefNWritten
 
size_t fTagOffset = 0
 In the std::variant memory layout, at which byte number is the index stored.
 
size_t fVariantOffset = 0
 In the std::variant memory layout, the actual union of types may start at an offset > 0.
 

Static Private Attributes

static constexpr std::size_t kMaxVariants = 125
 

Additional Inherited Members

- Public Types inherited from ROOT::Experimental::RFieldBase
using ColumnRepresentation_t = std::vector< EColumnType >
 
enum class  EState { kUnconnected , kConnectedToSink , kConnectedToSource }
 During its lifetime, a field undergoes the following possible state transitions: More...
 
using RConstSchemaIterator = RSchemaIteratorTemplate< true >
 
using RSchemaIterator = RSchemaIteratorTemplate< false >
 
- Static Public Member Functions inherited from ROOT::Experimental::RFieldBase
static std::vector< RCheckResultCheck (const std::string &fieldName, const std::string &typeName)
 Checks if the given type is supported by RNTuple.
 
static RResult< std::unique_ptr< RFieldBase > > Create (const std::string &fieldName, const std::string &typeName)
 Factory method to resurrect a field from the stored on-disk type information.
 
static RResult< void > EnsureValidFieldName (std::string_view fieldName)
 Check whether a given string is a valid field name.
 
- Static Public Attributes inherited from ROOT::Experimental::RFieldBase
static constexpr std::uint32_t kInvalidTypeVersion = -1U
 
static constexpr int kTraitMappable = 0x04
 A field of a fundamental type that can be directly mapped via RField<T>::Map(), i.e.
 
static constexpr int kTraitTriviallyConstructible = 0x01
 No constructor needs to be called, i.e.
 
static constexpr int kTraitTriviallyDestructible = 0x02
 The type is cleaned up just by freeing its memory. I.e. the destructor performs a no-op.
 
static constexpr int kTraitTrivialType = kTraitTriviallyConstructible | kTraitTriviallyDestructible
 Shorthand for types that are both trivially constructible and destructible.
 
static constexpr int kTraitTypeChecksum = 0x08
 The TClass checksum is set and valid.
 
- Static Protected Member Functions inherited from ROOT::Experimental::RFieldBase
static std::size_t CallAppendOn (RFieldBase &other, const void *from)
 Allow derived classes to call Append and Read on other (sub) fields.
 
static void CallConstructValueOn (const RFieldBase &other, void *where)
 Allow derived classes to call ConstructValue(void *) and GetDeleter on other (sub) fields.
 
static void * CallCreateObjectRawPtrOn (RFieldBase &other)
 
static void CallReadOn (RFieldBase &other, NTupleSize_t globalIndex, void *to)
 
static void CallReadOn (RFieldBase &other, RClusterIndex clusterIndex, void *to)
 
static RResult< std::unique_ptr< RFieldBase > > Create (const std::string &fieldName, const std::string &canonicalType, const std::string &typeAlias, bool continueOnError=false)
 Factory method to resurrect a field from the stored on-disk type information.
 
static std::unique_ptr< RDeleterGetDeleterOf (const RFieldBase &other)
 
static Internal::RColumnGetPrincipalColumnOf (const RFieldBase &other)
 Fields may need direct access to the principal column of their sub fields, e.g. in RRVecField::ReadBulk.
 
- Protected Attributes inherited from ROOT::Experimental::RFieldBase
Internal::RColumnfAuxiliaryColumn = nullptr
 Some fields have a second column in its column representation.
 
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.
 
std::vector< std::reference_wrapper< const ColumnRepresentation_t > > fColumnRepresentatives
 Pointers into the static vector GetColumnRepresentations().GetSerializationTypes() when SetColumnRepresentatives is called.
 
std::uint32_t fOnDiskTypeChecksum = 0
 TClass checksum cached from the descriptor after a call to ConnectPageSource().
 
std::uint32_t fOnDiskTypeVersion = kInvalidTypeVersion
 C++ type version cached from the descriptor after a call to ConnectPageSource()
 
RFieldBasefParent
 Sub fields point to their mother field.
 
Internal::RColumnfPrincipalColumn = nullptr
 All fields that have columns have a distinct main column.
 
std::vector< ReadCallback_tfReadCallbacks
 List of functions to be called after reading a value.
 
std::vector< std::unique_ptr< RFieldBase > > fSubFields
 Collections and classes own sub fields.
 
int fTraits = 0
 Properties of the type that allow for optimizations of collections of that type.
 
std::string fTypeAlias
 A typedef or using name that was used when creating the field.
 

#include <ROOT/RField/RFieldSTLMisc.hxx>

Inheritance diagram for ROOT::Experimental::RVariantField:
[legend]

Constructor & Destructor Documentation

◆ RVariantField() [1/3]

ROOT::Experimental::RVariantField::RVariantField ( std::string_view  name,
const RVariantField source 
)
private

Definition at line 3443 of file RField.cxx.

◆ RVariantField() [2/3]

ROOT::Experimental::RVariantField::RVariantField ( std::string_view  fieldName,
std::vector< std::unique_ptr< RFieldBase > >  itemFields 
)

Definition at line 3456 of file RField.cxx.

◆ RVariantField() [3/3]

ROOT::Experimental::RVariantField::RVariantField ( RVariantField &&  other)
default

◆ ~RVariantField()

ROOT::Experimental::RVariantField::~RVariantField ( )
overridedefault

Member Function Documentation

◆ AppendImpl()

std::size_t ROOT::Experimental::RVariantField::AppendImpl ( const void *  from)
finalprotectedvirtual

Operations on values of complex types, e.g.

ones that involve multiple columns or for which no direct column type exists.

Reimplemented from ROOT::Experimental::RFieldBase.

Definition at line 3509 of file RField.cxx.

◆ CloneImpl()

std::unique_ptr< ROOT::Experimental::RFieldBase > ROOT::Experimental::RVariantField::CloneImpl ( std::string_view  newName) const
finalprotectedvirtual

Called by Clone(), which additionally copies the on-disk ID.

Implements ROOT::Experimental::RFieldBase.

Definition at line 3490 of file RField.cxx.

◆ CommitClusterImpl()

void ROOT::Experimental::RVariantField::CommitClusterImpl ( )
finalprotectedvirtual

Reimplemented from ROOT::Experimental::RFieldBase.

Definition at line 3597 of file RField.cxx.

◆ ConstructValue()

void ROOT::Experimental::RVariantField::ConstructValue ( void *  where) const
finalprotectedvirtual

Constructs value in a given location of size at least GetValueSize(). Called by the base class' CreateValue().

Implements ROOT::Experimental::RFieldBase.

Definition at line 3558 of file RField.cxx.

◆ GenerateColumns() [1/2]

void ROOT::Experimental::RVariantField::GenerateColumns ( )
finalprotectedvirtual

Implementations in derived classes should create the backing columns corresponsing to the field type for writing.

The default implementation does not attach any columns to the field.

Reimplemented from ROOT::Experimental::RFieldBase.

Definition at line 3548 of file RField.cxx.

◆ GenerateColumns() [2/2]

void ROOT::Experimental::RVariantField::GenerateColumns ( const RNTupleDescriptor )
finalprotectedvirtual

Implementations in derived classes should create the backing columns corresponsing to the field type for reading.

The default implementation does not attach any columns to the field. The method should check, using the page source and fOnDiskId, if the column types match and throw if they don't.

Reimplemented from ROOT::Experimental::RFieldBase.

Definition at line 3553 of file RField.cxx.

◆ GetAlignment()

size_t ROOT::Experimental::RVariantField::GetAlignment ( ) const
finalvirtual

As a rule of thumb, the alignment is equal to the size of the type.

There are, however, various exceptions to this rule depending on OS and CPU architecture. So enforce the alignment to be explicitly spelled out.

Implements ROOT::Experimental::RFieldBase.

Definition at line 3584 of file RField.cxx.

◆ GetColumnRepresentations()

const ROOT::Experimental::RFieldBase::RColumnRepresentations & ROOT::Experimental::RVariantField::GetColumnRepresentations ( ) const
finalprotectedvirtual

Implementations in derived classes should return a static RColumnRepresentations object.

The default implementation does not attach any columns to the field.

Reimplemented from ROOT::Experimental::RFieldBase.

Definition at line 3542 of file RField.cxx.

◆ GetDeleter()

std::unique_ptr< ROOT::Experimental::RFieldBase::RDeleter > ROOT::Experimental::RVariantField::GetDeleter ( ) const
finalprotectedvirtual

Reimplemented from ROOT::Experimental::RFieldBase.

Definition at line 3574 of file RField.cxx.

◆ GetTag()

std::uint8_t ROOT::Experimental::RVariantField::GetTag ( const void *  variantPtr,
std::size_t  tagOffset 
)
staticprivate

Extracts the index from an std::variant and transforms it into the 1-based index used for the switch column The implementation supports two memory layouts that are in use: a trailing unsigned byte, zero-indexed, having the exception caused empty state encoded by the max tag value, or a trailing unsigned int instead of a char.

Definition at line 3495 of file RField.cxx.

◆ GetTypeList()

std::string ROOT::Experimental::RVariantField::GetTypeList ( const std::vector< std::unique_ptr< RFieldBase > > &  itemFields)
staticprivate

Definition at line 3432 of file RField.cxx.

◆ GetValueSize()

size_t ROOT::Experimental::RVariantField::GetValueSize ( ) const
finalvirtual

The number of bytes taken by a value of the appropriate type.

Implements ROOT::Experimental::RFieldBase.

Definition at line 3589 of file RField.cxx.

◆ operator=()

RVariantField & ROOT::Experimental::RVariantField::operator= ( RVariantField &&  other)
default

◆ ReadGlobalImpl()

void ROOT::Experimental::RVariantField::ReadGlobalImpl ( NTupleSize_t  globalIndex,
void *  to 
)
finalprotectedvirtual

Reimplemented from ROOT::Experimental::RFieldBase.

Definition at line 3523 of file RField.cxx.

◆ SetTag()

void ROOT::Experimental::RVariantField::SetTag ( void *  variantPtr,
std::size_t  tagOffset,
std::uint8_t  tag 
)
staticprivate

Definition at line 3502 of file RField.cxx.

Member Data Documentation

◆ fMaxAlignment

size_t ROOT::Experimental::RVariantField::fMaxAlignment = 1
private

Definition at line 354 of file RFieldSTLMisc.hxx.

◆ fMaxItemSize

size_t ROOT::Experimental::RVariantField::fMaxItemSize = 0
private

Definition at line 353 of file RFieldSTLMisc.hxx.

◆ fNWritten

std::vector<ClusterSize_t::ValueType> ROOT::Experimental::RVariantField::fNWritten
private

Definition at line 359 of file RFieldSTLMisc.hxx.

◆ fTagOffset

size_t ROOT::Experimental::RVariantField::fTagOffset = 0
private

In the std::variant memory layout, at which byte number is the index stored.

Definition at line 356 of file RFieldSTLMisc.hxx.

◆ fVariantOffset

size_t ROOT::Experimental::RVariantField::fVariantOffset = 0
private

In the std::variant memory layout, the actual union of types may start at an offset > 0.

Definition at line 358 of file RFieldSTLMisc.hxx.

◆ kMaxVariants

constexpr std::size_t ROOT::Experimental::RVariantField::kMaxVariants = 125
staticconstexprprivate

Definition at line 336 of file RFieldSTLMisc.hxx.

Libraries for ROOT::Experimental::RVariantField:

The documentation for this class was generated from the following files: