16#ifndef ROOT7_RNTupleModel
17#define ROOT7_RNTupleModel
29#include <unordered_map>
30#include <unordered_set>
34namespace Experimental {
36class RCollectionNTupleWriter;
98 using FieldMap_t = std::unordered_map<const Detail::RFieldBase *, const Detail::RFieldBase *>;
155 void AddField(std::unique_ptr<Detail::RFieldBase> field);
156 template <
typename T>
161 auto it = std::find_if(fieldZero->begin(), fieldZero->end(),
162 [&](
const auto &
f) { return f.GetName() == fieldNameDesc.fName; });
168 std::function<std::string(
const std::string &)> mapping);
203 std::unique_ptr<RNTupleModel>
Clone()
const;
204 static std::unique_ptr<RNTupleModel>
Create();
206 static std::unique_ptr<RNTupleModel>
CreateBare();
253 template <
typename T,
typename... ArgsT>
259 auto field = std::make_unique<RField<T>>(fieldNameDesc.
fName);
261 std::shared_ptr<T> ptr;
263 ptr =
fDefaultEntry->AddValue<T>(field.get(), std::forward<ArgsT>(args)...);
271 void AddField(std::unique_ptr<Detail::RFieldBase> field);
274 template <
typename T>
282 auto field = std::make_unique<RField<T>>(fieldNameDesc.
fName);
292 std::function<std::string(
const std::string &)> mapping);
294 template <
typename T>
295 T *
Get(std::string_view fieldName)
const
312 std::string_view fieldName,
313 std::unique_ptr<RNTupleModel> collectionModel);
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
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
A field translates read and write calls from/to underlying columns to/from tree values.
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Base class for all ROOT issued exceptions.
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
std::unordered_map< const Detail::RFieldBase *, const Detail::RFieldBase * > FieldMap_t
The map keys are the projected target fields, the map values are the backing source fields Note that ...
RProjectedFields & operator=(RProjectedFields &&)=default
RProjectedFields(std::unique_ptr< RFieldZero > fieldZero)
const RNTupleModel * fModel
The model this set of projected fields belongs to.
RProjectedFields(RProjectedFields &&)=default
RResult< void > Add(std::unique_ptr< Detail::RFieldBase > field, const FieldMap_t &fieldMap)
Adds a new projected field.
std::unique_ptr< RFieldZero > fFieldZero
The projected fields are attached to this zero field.
RProjectedFields(const RProjectedFields &)=delete
RProjectedFields & operator=(const RProjectedFields &)=delete
RResult< void > EnsureValidMapping(const Detail::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 Detail::RFieldBase * GetSourceField(const Detail::RFieldBase *target) const
~RProjectedFields()=default
RProjectedFields(const RNTupleModel *model)
A model is usually immutable after passing it to an RNTupleWriter.
void AddField(const NameWithDescription_t &fieldNameDesc, T *fromWhere)
void CommitUpdate()
Commit changes since the last call to BeginUpdate().
Detail::RNTupleModelChangeset fOpenChangeset
void BeginUpdate()
Begin a new set of alterations to the underlying model.
void AddField(std::unique_ptr< Detail::RFieldBase > field)
RResult< void > AddProjectedField(std::unique_ptr< Detail::RFieldBase > field, std::function< std::string(const std::string &)> mapping)
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.
void AddField(const NameWithDescription_t &fieldNameDesc, T *fromWhere)
Throws an exception if fromWhere is null.
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
Upon freezing, every model has a unique ID to distingusish it from other models.
std::uint64_t GetModelId() const
RNTupleModel(const RNTupleModel &)=delete
std::string GetDescription() const
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 tree value that is m...
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() const
std::unique_ptr< REntry > CreateBareEntry() const
In a bare entry, all values point to nullptr.
std::unique_ptr< REntry > CreateEntry() const
static std::unique_ptr< RNTupleModel > Create()
std::unique_ptr< RProjectedFields > fProjectedFields
The set of projected top-level fields.
void SetDescription(std::string_view description)
std::unique_ptr< REntry > fDefaultEntry
Contains field values corresponding to the created top-level fields.
std::shared_ptr< RCollectionNTupleWriter > MakeCollection(std::string_view fieldName, std::unique_ptr< RNTupleModel > collectionModel)
Ingests a model for a sub collection and attaches it to the current model.
RResult< void > AddProjectedField(std::unique_ptr< Detail::RFieldBase > field, std::function< std::string(const std::string &)> mapping)
Adds a top-level field based on existing fields.
const Detail::RFieldBase * GetField(std::string_view fieldName) const
RFieldZero * GetFieldZero() const
static std::unique_ptr< RNTupleModel > CreateBare()
A bare model has no default entry.
T * Get(std::string_view fieldName) const
const RProjectedFields & GetProjectedFields() const
RNTupleModel & operator=(const RNTupleModel &)=delete
void AddField(std::unique_ptr< Detail::RFieldBase > field)
Adds a field whose type is not known at compile time.
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...
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
The incremental changes to a RNTupleModel
std::vector< RFieldBase * > fAddedFields
Points to the fields in fModel that were added as part of an updater transaction.
RNTupleModelChangeset(RNTupleModel &model)
std::vector< RFieldBase * > fAddedProjectedFields
Points to the projected fields in fModel that were added as part of an updater transaction.
A wrapper over a field name and an optional description; used in AddField() and RUpdater::AddField()
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