13#ifndef ROOT_RNTupleModel
14#define ROOT_RNTupleModel
27#include <unordered_map>
28#include <unordered_set>
66 using FieldMap_t = std::unordered_map<const ROOT::RFieldBase *, const ROOT::RFieldBase *>;
199 RNTupleModel(std::unique_ptr<ROOT::RFieldZero> fieldZero);
208 std::unique_ptr<RNTupleModel>
Clone()
const;
209 static std::unique_ptr<RNTupleModel>
Create();
210 static std::unique_ptr<RNTupleModel>
Create(std::unique_ptr<ROOT::RFieldZero> fieldZero);
212 static std::unique_ptr<RNTupleModel>
CreateBare();
214 static std::unique_ptr<RNTupleModel>
CreateBare(std::unique_ptr<ROOT::RFieldZero> fieldZero);
251 template <
typename T>
252 std::shared_ptr<T>
MakeField(std::string_view
name, std::string_view description =
"")
256 auto field = std::make_unique<ROOT::RField<T>>(
name);
257 field->SetDescription(description);
258 std::shared_ptr<T> ptr;
270 void AddField(std::unique_ptr<ROOT::RFieldBase> field);
417 void AddField(std::unique_ptr<ROOT::RFieldBase> field, std::string_view parentName =
"");
448 template <
typename T>
449 std::shared_ptr<T>
MakeField(std::string_view
name, std::string_view description =
"")
451 auto field = std::make_unique<ROOT::RField<T>>(
name);
452 field->SetDescription(description);
455 return std::shared_ptr<T>();
459 void AddField(std::unique_ptr<ROOT::RFieldBase> field, std::string_view parentName =
"");
A model is usually immutable after passing it to an RNTupleWriter.
RNTupleModel(std::unique_ptr< ROOT::RFieldZero > fieldZero)
A container of const raw pointers, corresponding to a row in the data set.
Container for the projected fields of an RNTupleModel.
const ROOT::RFieldBase * GetSourceField(const ROOT::RFieldBase *target) const
const RNTupleModel * fModel
The model this set of projected fields belongs to.
std::unordered_map< const ROOT::RFieldBase *, const ROOT::RFieldBase * > FieldMap_t
The map keys are the projected target fields, the map values are the backing source fields Note that ...
RResult< void > Add(std::unique_ptr< ROOT::RFieldBase > field, const FieldMap_t &fieldMap)
Adds a new projected field.
RProjectedFields(RProjectedFields &&)=default
RProjectedFields(std::unique_ptr< ROOT::RFieldZero > fieldZero)
RProjectedFields(const RNTupleModel &model)
std::unique_ptr< RProjectedFields > Clone(const RNTupleModel &newModel) const
Clones this container and all the projected fields it owns.
RProjectedFields & operator=(const RProjectedFields &)=delete
FieldMap_t fFieldMap
Maps the source fields from fModel to the target projected fields attached to fFieldZero.
std::unique_ptr< ROOT::RFieldZero > fFieldZero
The projected fields are attached to this zero field.
RProjectedFields(const RProjectedFields &)=delete
RResult< void > EnsureValidMapping(const ROOT::RFieldBase *target, const FieldMap_t &fieldMap)
Asserts that the passed field is a valid target of the source field provided in the field map.
ROOT::RFieldZero & GetFieldZero()
~RProjectedFields()=default
RProjectedFields & operator=(RProjectedFields &&)=default
The REntry is a collection of values in an RNTuple corresponding to a complete row in the data set.
Points to an array of objects with RNTuple I/O support, used for bulk reading.
A field translates read and write calls from/to underlying columns to/from tree values.
A field token identifies a (sub)field in an entry.
The container field for an ntuple model, which itself has no physical representation.
A model is usually immutable after passing it to an RNTupleWriter.
ROOT::RNTupleWriter & fWriter
std::uint64_t fNewModelId
The model ID after committing.
void CommitUpdate()
Commit changes since the last call to BeginUpdate().
RResult< void > AddProjectedField(std::unique_ptr< ROOT::RFieldBase > field, FieldMappingFunc_t mapping)
RUpdater(ROOT::RNTupleWriter &writer)
Internal::RNTupleModelChangeset fOpenChangeset
std::shared_ptr< T > MakeField(std::string_view name, std::string_view description="")
void AddField(std::unique_ptr< ROOT::RFieldBase > field, std::string_view parentName="")
void BeginUpdate()
Begin a new set of alterations to the underlying model.
The RNTupleModel encapulates the schema of an RNTuple.
std::unique_ptr< REntry > CreateEntry() const
Creates a new entry with default values for each field.
RNTupleModel(std::unique_ptr< ROOT::RFieldZero > fieldZero)
void AddSubfield(std::string_view fieldName, ROOT::REntry &entry, bool initializeValue=true) const
Add a subfield to the provided entry.
std::unique_ptr< RNTupleModel > Clone() const
std::uint64_t fModelId
Every model has a unique ID to distinguish it from other models.
void EnsureValidFieldName(std::string_view fieldName)
Checks that user-provided field names are valid in the context of this RNTupleModel.
RNTupleModel & operator=(const RNTupleModel &)=delete
std::uint64_t GetModelId() const
ROOT::RFieldZero & GetMutableFieldZero()
Retrieves the field zero of this model, i.e.
const std::unordered_set< std::string > & GetFieldNames() const
Get the names of the fields currently present in the model, including projected fields.
std::unordered_set< std::string > fRegisteredSubfields
Keeps track of which subfields have been registered to be included in entries belonging to this model...
const ROOT::RFieldZero & GetConstFieldZero() const
Retrieves the field zero of this model, i.e. the root of the field hierarchy.
std::size_t EstimateWriteMemoryUsage(const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions()) const
Estimate the memory usage for this model during writing.
EState fModelState
Changed by Freeze() / Unfreeze() and by the RUpdater.
EState
The states a model can be in.
RNTupleModel(RNTupleModel &&)=delete
void Unfreeze()
Transitions an RNTupleModel from the frozen state back to the building state, invalidating all previo...
REntry & GetDefaultEntry()
Retrieves the default entry of this model.
ROOT::RFieldBase::RBulkValues CreateBulk(std::string_view fieldName) const
Calls the given field's CreateBulk() method. Throws an RException if no field with the given name exi...
void EnsureNotFrozen() const
Throws an RException if fFrozen is true.
void AddField(std::unique_ptr< ROOT::RFieldBase > field)
Adds a field whose type is not known at compile time.
static std::unique_ptr< RNTupleModel > Create()
std::string fDescription
Free text set by the user.
void SetDescription(std::string_view description)
std::unique_ptr< Internal::RProjectedFields > fProjectedFields
The set of projected top-level fields.
RNTupleModel(const RNTupleModel &)=delete
const std::string & GetDescription() const
std::unique_ptr< Detail::RRawPtrWriteEntry > CreateRawPtrWriteEntry() const
RResult< void > AddProjectedField(std::unique_ptr< ROOT::RFieldBase > field, FieldMappingFunc_t mapping)
Adds a top-level field based on existing fields.
ROOT::RFieldToken GetToken(std::string_view fieldName) const
Creates a token to be used in REntry methods to address a field present in the entry.
std::unordered_set< std::string > fFieldNames
Keeps track of which field names are taken, including projected field names.
std::unique_ptr< ROOT::RFieldZero > fFieldZero
Hierarchy of fields consisting of simple types and collections (sub trees).
void EnsureNotBare() const
Throws an RException if fDefaultEntry is nullptr.
void RegisterSubfield(std::string_view qualifiedFieldName)
Register a subfield so it can be accessed directly from entries belonging to the model.
ROOT::RFieldBase * FindField(std::string_view fieldName) const
The field name can be a top-level field or a nested field. Returns nullptr if the field is not in the...
std::shared_ptr< T > MakeField(std::string_view name, std::string_view description="")
Creates a new field given a name or {name, description} pair and a corresponding, default-constructed...
std::unique_ptr< ROOT::REntry > fDefaultEntry
Contains field values corresponding to the created top-level fields, as well as registered subfields.
void Freeze()
Transitions an RNTupleModel from the building state to the frozen state, disabling adding additional ...
ROOT::RFieldBase & GetMutableField(std::string_view fieldName)
Retrieves the field with fully-qualified name fieldName.
const std::unordered_set< std::string > & GetRegisteredSubfieldNames() const
Get the (qualified) names of subfields that have been registered (via RegisterSubfield()) to be inclu...
std::uint64_t GetSchemaId() const
static std::unique_ptr< RNTupleModel > CreateBare()
Creates a "bare model", i.e. an RNTupleModel with no default entry.
std::function< std::string(const std::string &)> FieldMappingFunc_t
User-provided function that describes the mapping of existing source fields to projected fields in te...
void Expire()
Transitions an RNTupleModel from the frozen state to the expired state, invalidating all previously c...
std::uint64_t fSchemaId
Models have a separate schema ID to remember that the clone of a frozen model still has the same sche...
RNTupleModel & operator=(RNTupleModel &&)=delete
const ROOT::RFieldBase & GetConstField(std::string_view fieldName) const
std::unique_ptr< REntry > CreateBareEntry() const
Creates a "bare entry", i.e.
Common user-tunable settings for storing RNTuples.
An RNTuple that gets filled with entries (data) and writes them to storage.
The field for an untyped record.
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
ROOT::RFieldZero & GetFieldZeroOfModel(RNTupleModel &model)
RProjectedFields & GetProjectedFieldsOfModel(RNTupleModel &model)
The incremental changes to a RNTupleModel.
void AddField(std::unique_ptr< ROOT::RFieldBase > field, std::string_view parentName="")
std::vector< ROOT::RFieldBase * > fAddedProjectedFields
Points to the projected fields in fModel that were added as part of an updater transaction.
std::vector< ROOT::RFieldBase * > fAddedFields
Points to the fields in fModel that were added as part of an updater transaction.
ROOT::RResult< void > AddProjectedField(std::unique_ptr< ROOT::RFieldBase > field, RNTupleModel::FieldMappingFunc_t mapping)
ROOT::RRecordField * GetParentRecordField(std::string_view parentName) const
RNTupleModelChangeset(RNTupleModel &model)