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