Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RNTupleModel.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleModel.hxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \date 2018-10-04
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_RNTupleModel
14#define ROOT_RNTupleModel
15
16#include <ROOT/REntry.hxx>
17#include <ROOT/RError.hxx>
18#include <ROOT/RField.hxx>
19#include <ROOT/RFieldToken.hxx>
20#include <ROOT/RNTupleTypes.hxx>
21#include <string_view>
22
23#include <cstdint>
24#include <functional>
25#include <memory>
26#include <string>
27#include <unordered_map>
28#include <unordered_set>
29#include <utility>
30
31namespace ROOT {
32
34class RNTupleModel;
35class RNTupleWriter;
36
37namespace Detail {
39} // namespace Detail
40
41namespace Internal {
43
44ROOT::RFieldZero &GetFieldZeroOfModel(RNTupleModel &model);
46const RProjectedFields &GetProjectedFieldsOfModel(const RNTupleModel &model);
47
48// clang-format off
49/**
50\class ROOT::Internal::RProjectedFields
51\ingroup NTuple
52\brief Container for the projected fields of an RNTupleModel
53
54Projected fields are fields whose columns are reused from existing fields. Projected fields are not attached
55to the model's zero field but form a separate hierarchy with their own zero field (which is stored in this class).
56Only the real source fields are written to: projected fields are stored as metadata
57(header) information only. Only top-level projected fields are supported because otherwise the layout of types
58could be altered in unexpected ways.
59This class owns the hierarchy of projected fields and keeps the mapping between them and their backing source fields.
60*/
61// clang-format on
63public:
64 /// The map keys are the projected target fields, the map values are the backing source fields
65 /// Note that sub fields are treated individually and indepently of their parent field
66 using FieldMap_t = std::unordered_map<const ROOT::RFieldBase *, const ROOT::RFieldBase *>;
67
68private:
69 explicit RProjectedFields(std::unique_ptr<ROOT::RFieldZero> fieldZero) : fFieldZero(std::move(fieldZero)) {}
70 /// The projected fields are attached to this zero field
71 std::unique_ptr<ROOT::RFieldZero> fFieldZero;
72 /// Maps the source fields from fModel to the target projected fields attached to fFieldZero
74 /// The model this set of projected fields belongs to
76
77 /// Asserts that the passed field is a valid target of the source field provided in the field map.
78 /// Checks the field without looking into sub fields.
79 RResult<void> EnsureValidMapping(const ROOT::RFieldBase *target, const FieldMap_t &fieldMap);
80
81public:
82 explicit RProjectedFields(const RNTupleModel &model)
83 : fFieldZero(std::make_unique<ROOT::RFieldZero>()), fModel(&model)
84 {
85 }
90 ~RProjectedFields() = default;
91
92 /// Clones this container and all the projected fields it owns. `newModel` must be a clone of the model
93 /// that this RProjectedFields was constructed with.
94 std::unique_ptr<RProjectedFields> Clone(const RNTupleModel &newModel) const;
95
97 const ROOT::RFieldBase *GetSourceField(const ROOT::RFieldBase *target) const;
98 /// Adds a new projected field. The field map needs to provide valid source fields of fModel for 'field'
99 /// and each of its sub fields.
100 RResult<void> Add(std::unique_ptr<ROOT::RFieldBase> field, const FieldMap_t &fieldMap);
101 bool IsEmpty() const { return fFieldZero->begin() == fFieldZero->end(); }
102};
103
104} // namespace Internal
105
106// clang-format off
107/**
108\class ROOT::RNTupleModel
109\ingroup NTuple
110\brief The RNTupleModel encapulates the schema of an RNTuple.
111
112The RNTupleModel comprises a collection of hierarchically organized fields. From a model, "entries"
113can be extracted or created. For convenience, the RNTupleModel provides a default entry unless it is created as a "bare model".
114Models have a unique model identifier that facilitates checking whether entries are compatible with it
115(i.e.: have been extracted from that model).
116
117A model is subject to state transitions during its lifetime: it starts in a *building* state, in which fields can be
118added and modified. Once the schema is finalized, the model gets *frozen*. Only frozen models can create entries.
119From frozen, models move into an *expired* state. In this state, the model is only partially usable: it can be cloned
120and queried, but it can't be unfrozen anymore and no new entries can be created. This state is used for models
121that were used for writing and are no longer connected to a page sink.
122
123```
124(Model gets created)
125 |
126 | (passed to a Sink (detached from
127 ____v______ or explicitly __________ Sink after ___________
128| | frozen) | | writing) | |
129| Building |---------------->| Frozen |-------------->| Expired |
130|___________|<----------------|__________| |___________|
131 (explicitly
132 unfrozen)
133```
134
135*/
136// clang-format on
141
142public:
143 /// User-provided function that describes the mapping of existing source fields to projected fields in terms
144 /// of fully qualified field names. The mapping function is called with the qualified field names of the provided
145 /// field and the subfields. It should return the qualified field names used as a mapping source.
146 /// See AddProjectedFields() for more details.
147 using FieldMappingFunc_t = std::function<std::string(const std::string &)>;
148
149 class RUpdater;
150
151private:
152 /// The states a model can be in. Possible transitions are between kBuilding and kFrozen
153 /// and from kFrozen to kExpired.
154 /// See RNTupleModel for the state transition graph.
160
161 /// Hierarchy of fields consisting of simple types and collections (sub trees)
162 std::unique_ptr<ROOT::RFieldZero> fFieldZero;
163 /// Contains field values corresponding to the created top-level fields, as well as registered subfields
164 std::unique_ptr<ROOT::REntry> fDefaultEntry;
165 /// Keeps track of which field names are taken, including projected field names.
166 std::unordered_set<std::string> fFieldNames;
167 /// Free text set by the user
168 std::string fDescription;
169 /// The set of projected top-level fields
170 std::unique_ptr<Internal::RProjectedFields> fProjectedFields;
171 /// Keeps track of which subfields have been registered to be included in entries belonging to this model.
172 std::unordered_set<std::string> fRegisteredSubfields;
173 /// Every model has a unique ID to distinguish it from other models. Entries are linked to models via the ID.
174 /// Cloned models get a new model ID. Expired models are cloned into frozen models.
175 std::uint64_t fModelId = 0;
176 /// Models have a separate schema ID to remember that the clone of a frozen model still has the same schema.
177 std::uint64_t fSchemaId = 0;
178 /// Changed by Freeze() / Unfreeze() and by the RUpdater.
180
181 /// Checks that user-provided field names are valid in the context of this RNTupleModel.
182 /// Throws an RException for invalid names, empty names (which is reserved for the zero field) and duplicate field
183 /// names.
184 void EnsureValidFieldName(std::string_view fieldName);
185
186 /// Throws an RException if fFrozen is true
187 void EnsureNotFrozen() const;
188
189 /// Throws an RException if fDefaultEntry is nullptr
190 void EnsureNotBare() const;
191
192 /// The field name can be a top-level field or a nested field. Returns nullptr if the field is not in the model.
193 ROOT::RFieldBase *FindField(std::string_view fieldName) const;
194
195 /// Add a subfield to the provided entry. If `initializeValue` is false, a nullptr will be bound to the entry value
196 /// (used in bare models).
197 void AddSubfield(std::string_view fieldName, ROOT::REntry &entry, bool initializeValue = true) const;
198
199 RNTupleModel(std::unique_ptr<ROOT::RFieldZero> fieldZero);
200
201public:
202 RNTupleModel(const RNTupleModel &) = delete;
206 ~RNTupleModel() = default;
207
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);
211 /// Creates a "bare model", i.e. an RNTupleModel with no default entry
212 static std::unique_ptr<RNTupleModel> CreateBare();
213 /// Creates a "bare model", i.e. an RNTupleModel with no default entry, with the given field zero.
214 static std::unique_ptr<RNTupleModel> CreateBare(std::unique_ptr<ROOT::RFieldZero> fieldZero);
215
216 /// Creates a new field given a `name` or `{name, description}` pair and a
217 /// corresponding, default-constructed value that is managed by a shared pointer.
218 ///
219 /// **Example: create some fields and fill an %RNTuple**
220 /// ~~~ {.cpp}
221 /// #include <ROOT/RNTupleModel.hxx>
222 /// #include <ROOT/RNTupleWriter.hxx>
223 /// using ROOT::RNTupleWriter;
224 ///
225 /// #include <vector>
226 ///
227 /// auto model = ROOT::RNTupleModel::Create();
228 /// auto pt = model->MakeField<float>("pt");
229 /// auto vec = model->MakeField<std::vector<int>>("vec");
230 ///
231 /// // The RNTuple is written to disk when the RNTupleWriter goes out of scope
232 /// {
233 /// auto writer = RNTupleWriter::Recreate(std::move(model), "myNTuple", "myFile.root");
234 /// for (int i = 0; i < 100; i++) {
235 /// *pt = static_cast<float>(i);
236 /// *vec = {i, i+1, i+2};
237 /// writer->Fill();
238 /// }
239 /// }
240 /// ~~~
241 ///
242 /// **Example: create a field with a description**
243 /// ~~~ {.cpp}
244 /// #include <ROOT/RNTupleModel.hxx>
245 ///
246 /// auto model = ROOT::RNTupleModel::Create();
247 /// auto hadronFlavour = model->MakeField<float>(
248 /// "hadronFlavour", "flavour from hadron ghost clustering"
249 /// );
250 /// ~~~
251 template <typename T>
252 std::shared_ptr<T> MakeField(std::string_view name, std::string_view description = "")
253 {
256 auto field = std::make_unique<ROOT::RField<T>>(name);
257 field->SetDescription(description);
258 std::shared_ptr<T> ptr;
259 if (fDefaultEntry)
260 ptr = fDefaultEntry->AddValue<T>(*field);
261 fFieldNames.insert(field->GetFieldName());
262 fFieldZero->Attach(std::move(field));
263 return ptr;
264 }
265
266 /// Adds a field whose type is not known at compile time. No shared pointer is returned in this case:
267 /// pointers should be retrieved or bound via REntry.
268 ///
269 /// Throws an RException if the field is null.
270 void AddField(std::unique_ptr<ROOT::RFieldBase> field);
271
272 /// Register a subfield so it can be accessed directly from entries belonging to the model. Because registering a
273 /// subfield does not fundamentally change the model, previously created entries will not be invalidated, nor
274 /// modified in any way; a registered subfield is merely an accessor added to the default entry (if present) and any
275 /// entries created afterwards. Note that previously created entries won't have this subfield added to them.
276 ///
277 /// Using models with registered subfields for writing is not allowed. Attempting to do so will result in an
278 /// exception.
279 ///
280 /// Throws an RException if the provided subfield could not be found in the model.
281 void RegisterSubfield(std::string_view qualifiedFieldName);
282
283 /// Adds a top-level field based on existing fields.
284 ///
285 /// The mapping function takes one argument, which is a string containing the name of the projected field. The return
286 /// value of the mapping function should be the name of the (existing) field onto which the projection is made.
287 /// **Example**
288 /// ~~~ {.cpp}
289 /// auto model = RNTupleModel::Create();
290 /// model->MakeField<float>("met");
291 /// auto metProjection = ROOT::RFieldBase::Create("missingE", "float").Unwrap();
292 /// model->AddProjectedField(std::move(metProjection), [](const std::string &) { return "met"; });
293 /// ~~~
294 ///
295 /// Adding projections for collection fields is also possible, as long as they follow the same schema structure. For
296 /// example, a projection of a collection of structs onto a collection of scalars is possible, but a projection of a
297 /// collection of a collection of scalars onto a collection of scalars is not.
298 ///
299 /// In the case of projections for nested fields, the mapping function must provide a mapping for every nesting
300 /// level.
301 /// **Example**
302 /// ~~~ {.cpp}
303 /// struct P { int x, y; };
304 ///
305 /// auto model = RNTupleModel::Create();
306 /// model->MakeField<std::vector<P>>("points");
307 /// auto pxProjection = ROOT::RFieldBase::Create("pxs", "std::vector<int>").Unwrap();
308 /// model->AddProjectedField(std::move(pxProjection), [](const std::string &fieldName) {
309 /// if (fieldName == "pxs")
310 /// return "points";
311 /// else
312 /// return "points._0.x";
313 /// });
314 /// ~~~
315 ///
316 /// Creating projections for fields containing `std::variant` or fixed-size arrays is unsupported.
317 RResult<void> AddProjectedField(std::unique_ptr<ROOT::RFieldBase> field, FieldMappingFunc_t mapping);
318
319 /// Transitions an RNTupleModel from the *building* state to the *frozen* state, disabling adding additional fields
320 /// and enabling creating entries from it. Freezing an already-frozen model is a no-op. Throws an RException if the
321 /// model is in the *expired* state. See RNTupleModel for more detailed explanation on the state transitions.
322 void Freeze();
323 /// Transitions an RNTupleModel from the *frozen* state back to the *building* state, invalidating all previously
324 /// created entries, re-enabling adding additional fields and disabling creating entries from it. Unfreezing a model
325 /// that is already in the *building* state is a no-op. Throws an RException if the model is in the *expired* state.
326 /// See RNTupleModel for a more detailed explanation on the state transitions.
327 void Unfreeze();
328 /// Transitions an RNTupleModel from the *frozen* state to the *expired* state, invalidating all previously created
329 /// entries, disabling creating new entries from it and disabling further state transitions. Expiring a model that is
330 /// already expired is a no-op. Throws an RException if the model is in the *building* state. See RNTupleModel for a
331 /// more detailed explanation on the state transitions.
332 void Expire();
333 /// \see Expire()
334 bool IsExpired() const { return fModelState == EState::kExpired; }
335 /// \see Freeze()
337 /// \see CreateBare()
338 bool IsBare() const { return !fDefaultEntry; }
339 std::uint64_t GetModelId() const { return fModelId; }
340 std::uint64_t GetSchemaId() const { return fSchemaId; }
341
342 /// Creates a new entry with default values for each field.
343 std::unique_ptr<REntry> CreateEntry() const;
344 /// Creates a "bare entry", i.e. a entry with all null values. The user needs to explicitly call BindValue() or
345 /// BindRawPtr() to set memory addresses before serializing / deserializing the entry.
346 std::unique_ptr<REntry> CreateBareEntry() const;
347 std::unique_ptr<Detail::RRawPtrWriteEntry> CreateRawPtrWriteEntry() const;
348 /// Creates a token to be used in REntry methods to address a field present in the entry
349 ROOT::RFieldToken GetToken(std::string_view fieldName) const;
350 /// Calls the given field's CreateBulk() method. Throws an RException if no field with the given name exists.
351 ROOT::RFieldBase::RBulkValues CreateBulk(std::string_view fieldName) const;
352
353 /// Retrieves the default entry of this model.
354 /// Throws an RException if this is a bare model (i.e. if it was created with CreateBare()).
356 /// \see GetDefaultEntry()
357 const REntry &GetDefaultEntry() const;
358
359 /// Retrieves the field zero of this model, i.e. the root of the field hierarchy.
360 /// This may be used to make adjustments on the field hierarchy before the model is frozen.
362 /// Retrieves the field zero of this model, i.e. the root of the field hierarchy.
364 /// Retrieves the field with fully-qualified name `fieldName`.
365 /// Dot-separated names are used to walk down the field hierarchy: e.g. `"parent.child"` should
366 /// be used to retrieve a field with name `"child"` whose parent is the top-level field with name `"parent"`.
367 /// Throws an RException if no field is found with the given name.
368 ROOT::RFieldBase &GetMutableField(std::string_view fieldName);
369 /// \see GetMutableField()
370 const ROOT::RFieldBase &GetConstField(std::string_view fieldName) const;
371
372 const std::string &GetDescription() const { return fDescription; }
373 void SetDescription(std::string_view description);
374
375 /// Get the names of the fields currently present in the model, including projected fields. Registered subfields
376 /// are not included, use GetRegisteredSubfieldnames() for this.
377 const std::unordered_set<std::string> &GetFieldNames() const { return fFieldNames; }
378 /// Get the (qualified) names of subfields that have been registered (via RegisterSubfield()) to be included in
379 /// entries from this model.
380 const std::unordered_set<std::string> &GetRegisteredSubfieldNames() const { return fRegisteredSubfields; }
381
382 /// Estimate the memory usage for this model during writing
383 ///
384 /// This will return an estimate in bytes for the internal page and compression buffers. The value should be
385 /// understood per sequential RNTupleWriter or per RNTupleFillContext created for an RNTupleParallelWriter
386 /// constructed with this model.
388};
389
390namespace Internal {
391
392// clang-format off
393/**
394\class ROOT::Internal::RNTupleModelChangeset
395\ingroup NTuple
396\brief The incremental changes to a `RNTupleModel`
397
398Represents a set of alterations to a `RNTupleModel` that happened after the model is used to initialize a `RPageSink`
399instance. This object can be used to communicate metadata updates to a `RPageSink`.
400You will not normally use this directly; see `RNTupleModel::RUpdater` instead.
401*/
402// clang-format on
405 /// Points to the fields in fModel that were added as part of an updater transaction
406 std::vector<ROOT::RFieldBase *> fAddedFields;
407 /// Points to the projected fields in fModel that were added as part of an updater transaction
408 std::vector<ROOT::RFieldBase *> fAddedProjectedFields;
409
411 bool IsEmpty() const { return fAddedFields.empty() && fAddedProjectedFields.empty(); }
412
413 // Returns the corresponding record field for parentName. Throws on error.
414 // Returns nullptr if parentName is empty (i.e. if the parent is the zero field).
415 ROOT::RRecordField *GetParentRecordField(std::string_view parentName) const;
416
417 void AddField(std::unique_ptr<ROOT::RFieldBase> field, std::string_view parentName = "");
418
419 /// \see RNTupleModel::AddProjectedField()
421 AddProjectedField(std::unique_ptr<ROOT::RFieldBase> field, RNTupleModel::FieldMappingFunc_t mapping);
422};
423
424} // namespace Internal
425
426/// A model is usually immutable after passing it to an `RNTupleWriter`. However, for the rare
427/// cases that require changing the model after the fact, `RUpdater` provides limited support for
428/// incremental updates, e.g. addition of new fields.
429///
430/// See `RNTupleWriter::CreateModelUpdater()` for an example.
432private:
435 std::uint64_t fNewModelId = 0; ///< The model ID after committing
436
437public:
439 ~RUpdater();
440 /// Begin a new set of alterations to the underlying model. As a side effect, all REntry
441 /// instances related to the model are invalidated.
442 void BeginUpdate();
443 /// Commit changes since the last call to `BeginUpdate()`. All the invalidated REntries remain
444 /// invalid. `CreateEntry()` or `CreateBareEntry()` can be used to create an REntry that
445 /// matches the new model. Upon completion, `BeginUpdate()` can be called again to begin a new set of changes.
446 void CommitUpdate();
447
448 template <typename T>
449 std::shared_ptr<T> MakeField(std::string_view name, std::string_view description = "")
450 {
451 auto field = std::make_unique<ROOT::RField<T>>(name);
452 field->SetDescription(description);
453 AddField(std::move(field));
454 if (fOpenChangeset.fModel.IsBare())
455 return std::shared_ptr<T>();
456 return fOpenChangeset.fModel.GetDefaultEntry().GetPtr<T>(name);
457 }
458
459 void AddField(std::unique_ptr<ROOT::RFieldBase> field, std::string_view parentName = "");
460
461 /// \see RNTupleModel::AddProjectedField()
462 RResult<void> AddProjectedField(std::unique_ptr<ROOT::RFieldBase> field, FieldMappingFunc_t mapping);
463};
464
465} // namespace ROOT
466
467#endif
char name[80]
Definition TGX11.cxx:148
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 & operator=(RProjectedFields &&)=default
The REntry is a collection of values in an RNTuple corresponding to a complete row in the data set.
Definition REntry.hxx:54
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.
Definition RField.hxx:58
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.
bool IsFrozen() const
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...
~RNTupleModel()=default
void Expire()
Transitions an RNTupleModel from the frozen state to the expired state, invalidating all previously c...
bool IsExpired() const
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...
Definition RError.hxx:197
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
Definition TObject.h:395
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