Logo ROOT  
Reference Guide
ROOT::Experimental::RNTupleModel Class Reference

The RNTupleModel encapulates the schema of an ntuple.

The ntuple model comprises a collection of hierarchically organized fields. From a model, "entries" can be extracted. For convenience, the model provides a default entry. Models have a unique model identifier that faciliates checking whether entries are compatible with it (i.e.: have been extracted from that model).

Definition at line 46 of file RNTupleModel.hxx.

Public Member Functions

 RNTupleModel (const RNTupleModel &)=delete
 
 ~RNTupleModel ()=default
 
template<typename T >
void AddField (std::pair< std::string_view, std::string_view > fieldNameDesc, T *fromWhere)
 Throws an exception if fromWhere is null. More...
 
template<typename T >
void AddField (std::string_view fieldName, T *fromWhere)
 Throws an exception if fromWhere is null. More...
 
void AddField (std::unique_ptr< Detail::RFieldBase > field)
 Adds a field whose type is not known at compile time. More...
 
std::unique_ptr< RNTupleModelClone () const
 
std::unique_ptr< REntryCreateBareEntry () const
 In a bare entry, all values point to nullptr. More...
 
std::unique_ptr< REntryCreateEntry () const
 
void Freeze ()
 
template<typename T >
T * Get (std::string_view fieldName) const
 
REntryGetDefaultEntry () const
 
std::string GetDescription () const
 
const Detail::RFieldBaseGetField (std::string_view fieldName) const
 
RFieldZeroGetFieldZero () const
 
std::uint64_t GetModelId () const
 
bool IsFrozen () const
 
std::shared_ptr< RCollectionNTupleWriterMakeCollection (std::string_view fieldName, std::unique_ptr< RNTupleModel > collectionModel)
 Ingests a model for a sub collection and attaches it to the current model. More...
 
template<typename T , typename... ArgsT>
std::shared_ptr< T > MakeField (std::pair< std::string_view, std::string_view > fieldNameDesc, ArgsT &&... args)
 Creates a new field given a {name, description} pair and a corresponding tree value that is managed by a shared pointer. More...
 
template<typename T , typename... ArgsT>
std::shared_ptr< T > MakeField (std::string_view fieldName, ArgsT &&... args)
 Creates a new field and a corresponding tree value that is managed by a shared pointer. More...
 
RNTupleModeloperator= (const RNTupleModel &)=delete
 
void SetDescription (std::string_view description)
 

Static Public Member Functions

static std::unique_ptr< RNTupleModelCreate ()
 
static std::unique_ptr< RNTupleModelCreateBare ()
 A bare model has no default entry. More...
 

Private Member Functions

 RNTupleModel ()
 
void EnsureNotBare () const
 Throws an RException if fDefaultEntry is nullptr. More...
 
void EnsureNotFrozen () const
 Throws an RException if fFrozen is true. More...
 
void EnsureValidFieldName (std::string_view fieldName)
 Checks that user-provided field names are valid in the context of this NTuple model. More...
 

Private Attributes

std::unique_ptr< REntryfDefaultEntry
 Contains field values corresponding to the created top-level fields. More...
 
std::string fDescription
 Free text set by the user. More...
 
std::unordered_set< std::string > fFieldNames
 Keeps track of which field names are taken. More...
 
std::unique_ptr< RFieldZerofFieldZero
 Hierarchy of fields consisting of simple types and collections (sub trees) More...
 
std::uint64_t fModelId = 0
 Upon freezing, every model has a unique ID to distingusish it from other models. More...
 

#include <ROOT/RNTupleModel.hxx>

Constructor & Destructor Documentation

◆ RNTupleModel() [1/2]

ROOT::Experimental::RNTupleModel::RNTupleModel ( )
private

Definition at line 52 of file RNTupleModel.cxx.

◆ RNTupleModel() [2/2]

ROOT::Experimental::RNTupleModel::RNTupleModel ( const RNTupleModel )
delete

◆ ~RNTupleModel()

ROOT::Experimental::RNTupleModel::~RNTupleModel ( )
default

Member Function Documentation

◆ AddField() [1/3]

template<typename T >
void ROOT::Experimental::RNTupleModel::AddField ( std::pair< std::string_view, std::string_view fieldNameDesc,
T *  fromWhere 
)
inline

Throws an exception if fromWhere is null.

Definition at line 160 of file RNTupleModel.hxx.

◆ AddField() [2/3]

template<typename T >
void ROOT::Experimental::RNTupleModel::AddField ( std::string_view  fieldName,
T *  fromWhere 
)
inline

Throws an exception if fromWhere is null.

Definition at line 154 of file RNTupleModel.hxx.

◆ AddField() [3/3]

void ROOT::Experimental::RNTupleModel::AddField ( std::unique_ptr< Detail::RFieldBase field)

Adds a field whose type is not known at compile time.

Thus there is no shared pointer returned.

Throws an exception if the field is null.

Definition at line 81 of file RNTupleModel.cxx.

◆ Clone()

std::unique_ptr< ROOT::Experimental::RNTupleModel > ROOT::Experimental::RNTupleModel::Clone ( ) const

Definition at line 63 of file RNTupleModel.cxx.

◆ Create()

std::unique_ptr< ROOT::Experimental::RNTupleModel > ROOT::Experimental::RNTupleModel::Create ( )
static

Definition at line 56 of file RNTupleModel.cxx.

◆ CreateBare()

static std::unique_ptr< RNTupleModel > ROOT::Experimental::RNTupleModel::CreateBare ( )
inlinestatic

A bare model has no default entry.

Definition at line 79 of file RNTupleModel.hxx.

◆ CreateBareEntry()

std::unique_ptr< ROOT::Experimental::REntry > ROOT::Experimental::RNTupleModel::CreateBareEntry ( ) const

In a bare entry, all values point to nullptr.

The resulting entry shall use CaptureValueUnsafe() in order set memory addresses to be serialized / deserialized

Definition at line 152 of file RNTupleModel.cxx.

◆ CreateEntry()

std::unique_ptr< ROOT::Experimental::REntry > ROOT::Experimental::RNTupleModel::CreateEntry ( ) const

Definition at line 140 of file RNTupleModel.cxx.

◆ EnsureNotBare()

void ROOT::Experimental::RNTupleModel::EnsureNotBare ( ) const
private

Throws an RException if fDefaultEntry is nullptr.

Definition at line 46 of file RNTupleModel.cxx.

◆ EnsureNotFrozen()

void ROOT::Experimental::RNTupleModel::EnsureNotFrozen ( ) const
private

Throws an RException if fFrozen is true.

Definition at line 40 of file RNTupleModel.cxx.

◆ EnsureValidFieldName()

void ROOT::Experimental::RNTupleModel::EnsureValidFieldName ( std::string_view  fieldName)
private

Checks that user-provided field names are valid in the context of this NTuple model.

Throws an RException for invalid names.

Definition at line 28 of file RNTupleModel.cxx.

◆ Freeze()

void ROOT::Experimental::RNTupleModel::Freeze ( )

Definition at line 164 of file RNTupleModel.cxx.

◆ Get()

template<typename T >
T * ROOT::Experimental::RNTupleModel::Get ( std::string_view  fieldName) const
inline

Definition at line 174 of file RNTupleModel.hxx.

◆ GetDefaultEntry()

ROOT::Experimental::REntry * ROOT::Experimental::RNTupleModel::GetDefaultEntry ( ) const

Definition at line 132 of file RNTupleModel.cxx.

◆ GetDescription()

std::string ROOT::Experimental::RNTupleModel::GetDescription ( ) const
inline

Definition at line 200 of file RNTupleModel.hxx.

◆ GetField()

const ROOT::Experimental::Detail::RFieldBase * ROOT::Experimental::RNTupleModel::GetField ( std::string_view  fieldName) const

Definition at line 111 of file RNTupleModel.cxx.

◆ GetFieldZero()

RFieldZero * ROOT::Experimental::RNTupleModel::GetFieldZero ( ) const
inline

Definition at line 197 of file RNTupleModel.hxx.

◆ GetModelId()

std::uint64_t ROOT::Experimental::RNTupleModel::GetModelId ( ) const
inline

Definition at line 182 of file RNTupleModel.hxx.

◆ IsFrozen()

bool ROOT::Experimental::RNTupleModel::IsFrozen ( ) const
inline

Definition at line 181 of file RNTupleModel.hxx.

◆ MakeCollection()

std::shared_ptr< ROOT::Experimental::RCollectionNTupleWriter > ROOT::Experimental::RNTupleModel::MakeCollection ( std::string_view  fieldName,
std::unique_ptr< RNTupleModel collectionModel 
)

Ingests a model for a sub collection and attaches it to the current model.

Throws an exception if collectionModel is null.

Definition at line 94 of file RNTupleModel.cxx.

◆ MakeField() [1/2]

template<typename T , typename... ArgsT>
std::shared_ptr< T > ROOT::Experimental::RNTupleModel::MakeField ( std::pair< std::string_view, std::string_view fieldNameDesc,
ArgsT &&...  args 
)
inline

Creates a new field given a {name, description} pair and a corresponding tree value that is managed by a shared pointer.

Example: create a field with a description

#include <ROOT/RNTuple.hxx>
auto model = RNTupleModel::Create();
auto hadronFlavour = model->MakeField<float>({
"hadronFlavour", "flavour from hadron ghost clustering"
});
The RNTupleModel encapulates the schema of an ntuple.
static std::unique_ptr< RNTupleModel > Create()

Definition at line 133 of file RNTupleModel.hxx.

◆ MakeField() [2/2]

template<typename T , typename... ArgsT>
std::shared_ptr< T > ROOT::Experimental::RNTupleModel::MakeField ( std::string_view  fieldName,
ArgsT &&...  args 
)
inline

Creates a new field and a corresponding tree value that is managed by a shared pointer.

Example: create some fields and fill an RNTuple

#include <ROOT/RNTuple.hxx>
#include <vector>
auto model = RNTupleModel::Create();
auto pt = model->MakeField<float>("pt");
auto vec = model->MakeField<std::vector<int>>("vec");
// The RNTuple is written to disk when the RNTupleWriter goes out of scope
{
auto ntuple = RNTupleWriter::Recreate(std::move(model), "myNTuple", "myFile.root");
for (int i = 0; i < 100; i++) {
*pt = static_cast<float>(i);
*vec = {i, i+1, i+2};
ntuple->Fill();
}
}
An RNTuple that gets filled with entries (data) and writes them to storage.
Definition: RNTuple.hxx:359
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const RNTupleWriteOptions &options=RNTupleWriteOptions())
Throws an exception if the model is null.
Definition: RNTuple.cxx:323
TPaveText * pt
Definition: civetweb.c:1856

Example: create a field with an initial value

#include <ROOT/RNTuple.hxx>
auto model = RNTupleModel::Create();
// pt's initial value is 42.0
auto pt = model->MakeField<float>("pt", 42.0);

Definition at line 115 of file RNTupleModel.hxx.

◆ operator=()

RNTupleModel & ROOT::Experimental::RNTupleModel::operator= ( const RNTupleModel )
delete

◆ SetDescription()

void ROOT::Experimental::RNTupleModel::SetDescription ( std::string_view  description)

Definition at line 175 of file RNTupleModel.cxx.

Member Data Documentation

◆ fDefaultEntry

std::unique_ptr<REntry> ROOT::Experimental::RNTupleModel::fDefaultEntry
private

Contains field values corresponding to the created top-level fields.

Definition at line 50 of file RNTupleModel.hxx.

◆ fDescription

std::string ROOT::Experimental::RNTupleModel::fDescription
private

Free text set by the user.

Definition at line 54 of file RNTupleModel.hxx.

◆ fFieldNames

std::unordered_set<std::string> ROOT::Experimental::RNTupleModel::fFieldNames
private

Keeps track of which field names are taken.

Definition at line 52 of file RNTupleModel.hxx.

◆ fFieldZero

std::unique_ptr<RFieldZero> ROOT::Experimental::RNTupleModel::fFieldZero
private

Hierarchy of fields consisting of simple types and collections (sub trees)

Definition at line 48 of file RNTupleModel.hxx.

◆ fModelId

std::uint64_t ROOT::Experimental::RNTupleModel::fModelId = 0
private

Upon freezing, every model has a unique ID to distingusish it from other models.

Cloning preserves the ID. Entries are linked to models via the ID.

Definition at line 57 of file RNTupleModel.hxx.

Libraries for ROOT::Experimental::RNTupleModel:
[legend]

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