16#ifndef ROOT7_RNTupleModel
17#define ROOT7_RNTupleModel
29#include <unordered_map>
30#include <unordered_set>
34namespace Experimental {
38class RNTupleWriteOptions;
41class RProjectedFields;
63 using FieldMap_t = std::unordered_map<const RFieldBase *, const RFieldBase *>;
179 template <
typename T,
typename... ArgsT>
184 auto it = std::find_if(fieldZero->begin(), fieldZero->end(),
185 [&](
const auto &
f) { return f.GetFieldName() == fieldNameDesc.fName; });
191 void AddField(std::unique_ptr<RFieldBase> field);
233 void AddSubfield(std::string_view fieldName,
REntry &entry,
bool initializeValue =
true)
const;
242 std::unique_ptr<RNTupleModel>
Clone()
const;
243 static std::unique_ptr<RNTupleModel>
Create();
244 static std::unique_ptr<RNTupleModel>
Create(std::unique_ptr<RFieldZero> fieldZero);
246 static std::unique_ptr<RNTupleModel>
CreateBare();
247 static std::unique_ptr<RNTupleModel>
CreateBare(std::unique_ptr<RFieldZero> fieldZero);
295 template <
typename T,
typename... ArgsT>
300 auto field = std::make_unique<RField<T>>(fieldNameDesc.
fName);
302 std::shared_ptr<T> ptr;
304 ptr =
fDefaultEntry->AddValue<T>(*field, std::forward<ArgsT>(args)...);
313 void AddField(std::unique_ptr<RFieldBase> field);
#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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
The projected fields of a RNTupleModel
FieldMap_t fFieldMap
Maps the source fields from fModel to the target projected fields attached to fFieldZero.
const RNTupleModel * fModel
The model this set of projected fields belongs to.
RProjectedFields(const RNTupleModel &model)
~RProjectedFields()=default
std::unique_ptr< RProjectedFields > Clone(const RNTupleModel &newModel) const
The new model needs to be a clone of fModel.
RResult< void > EnsureValidMapping(const RFieldBase *target, const FieldMap_t &fieldMap)
Asserts that the passed field is a valid target of the source field provided in the field map.
RProjectedFields(const RProjectedFields &)=delete
RProjectedFields & operator=(RProjectedFields &&)=default
std::unordered_map< const RFieldBase *, const RFieldBase * > FieldMap_t
The map keys are the projected target fields, the map values are the backing source fields Note that ...
const RFieldBase * GetSourceField(const RFieldBase *target) const
RProjectedFields(std::unique_ptr< RFieldZero > fieldZero)
RProjectedFields(RProjectedFields &&)=default
RResult< void > Add(std::unique_ptr< RFieldBase > field, const FieldMap_t &fieldMap)
Adds a new projected field.
RFieldZero & GetFieldZero()
RProjectedFields & operator=(const RProjectedFields &)=delete
std::unique_ptr< RFieldZero > fFieldZero
The projected fields are attached to this zero field.
The field token identifies a (sub)field in this entry.
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Similar to RValue but manages an array of consecutive values.
A field translates read and write calls from/to underlying columns to/from tree values.
The container field for an ntuple model, which itself has no physical representation.
A model is usually immutable after passing it to an RNTupleWriter.
Internal::RNTupleModelChangeset fOpenChangeset
void CommitUpdate()
Commit changes since the last call to BeginUpdate().
void BeginUpdate()
Begin a new set of alterations to the underlying model.
std::uint64_t fNewModelId
The model ID after committing.
std::shared_ptr< T > MakeField(const NameWithDescription_t &fieldNameDesc, ArgsT &&...args)
RResult< void > AddProjectedField(std::unique_ptr< RFieldBase > field, FieldMappingFunc_t mapping)
void AddField(std::unique_ptr< RFieldBase > field)
The RNTupleModel encapulates the schema of an ntuple.
std::unordered_set< std::string > fRegisteredSubfields
Keeps track of which subfields have been registered to be included in entries belonging to this model...
std::unordered_set< std::string > fFieldNames
Keeps track of which field names are taken, including projected field names.
std::string fDescription
Free text set by the user.
void EnsureValidFieldName(std::string_view fieldName)
Checks that user-provided field names are valid in the context of this RNTuple model.
std::uint64_t fModelId
Every model has a unique ID to distinguish it from other models.
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...
std::unique_ptr< Internal::RProjectedFields > fProjectedFields
The set of projected top-level fields.
std::uint64_t GetModelId() const
const RFieldZero & GetConstFieldZero() const
const RFieldBase & GetConstField(std::string_view fieldName) const
RNTupleModel(const RNTupleModel &)=delete
std::uint64_t fSchemaId
Models have a separate schema ID to remember that the clone of a frozen model still has the same sche...
REntry::RFieldToken GetToken(std::string_view fieldName) const
Creates a token to be used in REntry methods to address a field present in the entry.
void EnsureNotBare() const
Throws an RException if fDefaultEntry is nullptr.
std::unique_ptr< RNTupleModel > Clone() const
void EnsureNotFrozen() const
Throws an RException if fFrozen is true.
RFieldZero & GetMutableFieldZero()
Mutable access to the root field is used to make adjustments to the fields.
REntry & GetDefaultEntry()
std::size_t EstimateWriteMemoryUsage(const RNTupleWriteOptions &options=RNTupleWriteOptions()) const
Estimate the memory usage for this model during writing.
std::shared_ptr< T > MakeField(const NameWithDescription_t &fieldNameDesc, ArgsT &&...args)
Creates a new field given a name or {name, description} pair and a corresponding value that is manage...
const std::unordered_set< std::string > & GetRegisteredSubfields() const
Get the (qualified) names of subfields that have been registered to be included in entries from this ...
std::unique_ptr< REntry > CreateBareEntry() const
In a bare entry, all values point to nullptr.
std::unique_ptr< REntry > CreateEntry() const
RFieldBase::RBulk CreateBulk(std::string_view fieldName) const
Calls the given field's CreateBulk() method. Throws an exception if no field with the given name exis...
static std::unique_ptr< RNTupleModel > Create()
std::uint64_t GetSchemaId() const
void AddSubfield(std::string_view fieldName, REntry &entry, bool initializeValue=true) const
Add a subfield to the provided entry.
RResult< void > AddProjectedField(std::unique_ptr< RFieldBase > field, FieldMappingFunc_t mapping)
Adds a top-level field based on existing fields.
void SetDescription(std::string_view description)
std::unique_ptr< REntry > fDefaultEntry
Contains field values corresponding to the created top-level fields, as well as registered subfields.
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...
RFieldBase & GetMutableField(std::string_view fieldName)
static std::unique_ptr< RNTupleModel > CreateBare()
A bare model has no default entry.
const std::string & GetDescription() const
void AddField(std::unique_ptr< RFieldBase > field)
Adds a field whose type is not known at compile time.
void RegisterSubfield(std::string_view qualifiedFieldName)
Register a subfield so it can be accessed directly from entries belonging to the model.
RNTupleModel & operator=(const RNTupleModel &)=delete
bool fIsFrozen
Changed by Freeze() / Unfreeze() and by the RUpdater.
std::unique_ptr< RFieldZero > fFieldZero
Hierarchy of fields consisting of simple types and collections (sub trees)
Common user-tunable settings for storing ntuples.
An RNTuple that gets filled with entries (data) and writes them to storage.
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
RProjectedFields & GetProjectedFieldsOfModel(RNTupleModel &model)
RFieldZero & GetFieldZeroOfModel(RNTupleModel &model)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
The incremental changes to a RNTupleModel
std::vector< RFieldBase * > fAddedProjectedFields
Points to the projected fields in fModel that were added as part of an updater transaction.
std::vector< RFieldBase * > fAddedFields
Points to the fields in fModel that were added as part of an updater transaction.
RNTupleModelChangeset(RNTupleModel &model)
A wrapper over a field name and an optional description; used in AddField() and RUpdater::AddField()
NameWithDescription_t(const std::string &name)
NameWithDescription_t(std::string_view name)
NameWithDescription_t(std::string_view name, std::string_view descr)
NameWithDescription_t(const char *name)
std::string_view fDescription