16#ifndef ROOT7_RNTupleModel
17#define ROOT7_RNTupleModel
29#include <unordered_map>
30#include <unordered_set>
34namespace Experimental {
36class RNTupleCollectionWriter;
104 using FieldMap_t = std::unordered_map<const RFieldBase *, const RFieldBase *>;
162 template <
typename T,
typename... ArgsT>
167 auto it = std::find_if(fieldZero->begin(), fieldZero->end(),
168 [&](
const auto &
f) { return f.GetFieldName() == fieldNameDesc.fName; });
174 void AddField(std::unique_ptr<RFieldBase> field);
177 AddProjectedField(std::unique_ptr<RFieldBase> field, std::function<std::string(
const std::string &)> mapping);
217 std::unique_ptr<RNTupleModel>
Clone()
const;
218 static std::unique_ptr<RNTupleModel>
Create();
219 static std::unique_ptr<RNTupleModel>
Create(std::unique_ptr<RFieldZero> fieldZero);
221 static std::unique_ptr<RNTupleModel>
CreateBare();
222 static std::unique_ptr<RNTupleModel>
CreateBare(std::unique_ptr<RFieldZero> fieldZero);
270 template <
typename T,
typename... ArgsT>
275 auto field = std::make_unique<RField<T>>(fieldNameDesc.
fName);
277 std::shared_ptr<T> ptr;
279 ptr =
fDefaultEntry->AddValue<T>(*field, std::forward<ArgsT>(args)...);
288 void AddField(std::unique_ptr<RFieldBase> field);
294 AddProjectedField(std::unique_ptr<RFieldBase> field, std::function<std::string(
const std::string &)> mapping);
305 std::shared_ptr<RNTupleCollectionWriter>
306 MakeCollection(std::string_view fieldName, std::unique_ptr<RNTupleModel> collectionModel);
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 field token identifies a top-level 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.
Projected fields are fields whose columns are reused from existing fields.
FieldMap_t fFieldMap
Maps the source fields from fModel to the target projected fields attached to fFieldZero.
RFieldZero * GetFieldZero() const
RProjectedFields & operator=(RProjectedFields &&)=default
RProjectedFields(std::unique_ptr< RFieldZero > fieldZero)
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.
const RNTupleModel * fModel
The model this set of projected fields belongs to.
RProjectedFields(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 ...
std::unique_ptr< RFieldZero > fFieldZero
The projected fields are attached to this zero field.
RProjectedFields(const RProjectedFields &)=delete
const RFieldBase * GetSourceField(const RFieldBase *target) const
RProjectedFields & operator=(const RProjectedFields &)=delete
RResult< void > Add(std::unique_ptr< RFieldBase > field, const FieldMap_t &fieldMap)
Adds a new projected field.
~RProjectedFields()=default
RProjectedFields(const RNTupleModel *model)
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, std::function< std::string(const std::string &)> mapping)
void AddField(std::unique_ptr< RFieldBase > field)
The RNTupleModel encapulates the schema of an ntuple.
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 NTuple model.
std::uint64_t fModelId
Every model has a unique ID to distinguish it from other models.
std::uint64_t GetModelId() const
RNTupleModel(const RNTupleModel &)=delete
std::string GetDescription() const
REntry::RFieldToken GetToken(std::string_view fieldName) const
Creates a token to be used in REntry methods to address a top-level field.
RResult< void > AddProjectedField(std::unique_ptr< RFieldBase > field, std::function< std::string(const std::string &)> mapping)
Adds a top-level field based on existing fields.
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.
REntry & GetDefaultEntry()
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...
std::shared_ptr< RNTupleCollectionWriter > MakeCollection(std::string_view fieldName, std::unique_ptr< RNTupleModel > collectionModel)
Ingests a model for a sub collection and attaches it to the current model.
const RFieldBase & GetField(std::string_view fieldName) const
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::unique_ptr< RProjectedFields > fProjectedFields
The set of projected top-level fields.
const RFieldZero & GetFieldZero() const
void SetDescription(std::string_view description)
std::unique_ptr< REntry > fDefaultEntry
Contains field values corresponding to the created top-level fields.
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...
static std::unique_ptr< RNTupleModel > CreateBare()
A bare model has no default entry.
const RProjectedFields & GetProjectedFields() const
void AddField(std::unique_ptr< RFieldBase > field)
Adds a field whose type is not known at compile time.
RFieldZero & GetFieldZero()
Non-const access to the root field is used to commit clusters during writing and to set the on-disk f...
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)
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...
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