Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleModel.cxx
Go to the documentation of this file.
1/// \file RNTupleModel.cxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-15
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#include <ROOT/RError.hxx>
17#include <ROOT/RField.hxx>
18#include <ROOT/RNTupleModel.hxx>
20#include <ROOT/StringUtils.hxx>
21
22#include <atomic>
23#include <cstdlib>
24#include <memory>
25#include <utility>
26
27namespace {
28std::uint64_t GetNewModelId()
29{
30 static std::atomic<std::uint64_t> gLastModelId = 0;
31 return ++gLastModelId;
32}
33} // anonymous namespace
34
37{
38 if (model.IsExpired()) {
39 throw RException(R__FAIL("invalid use of expired model"));
40 }
41 return *model.fFieldZero;
42}
43
46{
47 if (model.IsExpired()) {
48 throw RException(R__FAIL("invalid use of expired model"));
49 }
50 return *model.fProjectedFields;
51}
52
53//------------------------------------------------------------------------------
54
57{
58 auto source = fieldMap.at(target);
59 const bool hasCompatibleStructure = (source->GetStructure() == target->GetStructure()) ||
60 ((source->GetStructure() == ROOT::ENTupleStructure::kCollection) &&
61 dynamic_cast<const RCardinalityField *>(target));
63 return R__FAIL("field mapping structural mismatch: " + source->GetFieldName() + " --> " + target->GetFieldName());
64 if ((source->GetStructure() == ROOT::ENTupleStructure::kLeaf) ||
65 (source->GetStructure() == ROOT::ENTupleStructure::kStreamer)) {
66 if (target->GetTypeName() != source->GetTypeName())
67 return R__FAIL("field mapping type mismatch: " + source->GetFieldName() + " --> " + target->GetFieldName());
68 }
69
70 auto fnHasArrayParent = [](const RFieldBase &f) -> bool {
71 auto parent = f.GetParent();
72 while (parent) {
73 if (parent->GetNRepetitions() > 0)
74 return true;
75 parent = parent->GetParent();
76 }
77 return false;
78 };
80 return R__FAIL("unsupported field mapping across fixed-size arrays");
81 }
82
83 // We support projections only across records and collections. In the following, we check that the projected
84 // field is on the same path of collection fields in the field tree than the source field.
85
86 // Finds the first non-record parent field of the input field
87 auto fnBreakPoint = [](const RFieldBase *f) -> const RFieldBase * {
88 auto parent = f->GetParent();
89 while (parent) {
90 if ((parent->GetStructure() != ROOT::ENTupleStructure::kRecord) &&
91 (parent->GetStructure() != ROOT::ENTupleStructure::kLeaf)) {
92 return parent;
93 }
94 parent = parent->GetParent();
95 }
96 // We reached the zero field
97 return nullptr;
98 };
99
100 // If source or target has a variant or reference as a parent, error out
103 return R__FAIL("unsupported field mapping (source structure)");
106 return R__FAIL("unsupported field mapping (target structure)");
107
109 // Source and target have no collections as parent
110 return RResult<void>::Success();
111 }
114 // Source and target are children of the same collection
115 return RResult<void>::Success();
116 }
117 if (auto it = fieldMap.find(targetBreakPoint); it != fieldMap.end() && it->second == sourceBreakPoint) {
118 // The parent collection of parent is mapped to the parent collection of the source
119 return RResult<void>::Success();
120 }
121 // Source and target are children of different collections
122 return R__FAIL("field mapping structure mismatch: " + source->GetFieldName() + " --> " + target->GetFieldName());
123 }
124
125 // Either source or target have no collection as a parent, but the other one has; that doesn't fit
126 return R__FAIL("field mapping structure mismatch: " + source->GetFieldName() + " --> " + target->GetFieldName());
127}
128
131{
132 auto result = EnsureValidMapping(field.get(), fieldMap);
133 if (!result)
134 return R__FORWARD_ERROR(result);
135 for (const auto &f : *field) {
136 result = EnsureValidMapping(&f, fieldMap);
137 if (!result)
138 return R__FORWARD_ERROR(result);
139 }
140
141 fFieldMap.insert(fieldMap.begin(), fieldMap.end());
142 fFieldZero->Attach(std::move(field));
143 return RResult<void>::Success();
144}
145
148{
149 if (auto it = fFieldMap.find(target); it != fFieldMap.end())
150 return it->second;
151 return nullptr;
152}
153
154std::unique_ptr<ROOT::Experimental::Internal::RProjectedFields>
156{
157 auto cloneFieldZero = std::unique_ptr<RFieldZero>(static_cast<RFieldZero *>(fFieldZero->Clone("").release()));
158 auto clone = std::unique_ptr<RProjectedFields>(new RProjectedFields(std::move(cloneFieldZero)));
159 clone->fModel = &newModel;
160 // TODO(jblomer): improve quadratic search to re-wire the field mappings given the new model and the cloned
161 // projected fields. Not too critical as we generally expect a limited number of projected fields
162 for (const auto &[k, v] : fFieldMap) {
163 for (const auto &f : clone->GetFieldZero()) {
164 if (f.GetQualifiedFieldName() == k->GetQualifiedFieldName()) {
165 clone->fFieldMap[&f] = &newModel.GetConstField(v->GetQualifiedFieldName());
166 break;
167 }
168 }
169 }
170 return clone;
171}
172
174 : fWriter(writer), fOpenChangeset(fWriter.GetUpdatableModel())
175{
176}
177
179{
180 fOpenChangeset.fModel.Unfreeze();
181 // We set the model ID to zero until CommitUpdate(). That prevents calls to RNTupleWriter::Fill() in the middle
182 // of updates
183 std::swap(fOpenChangeset.fModel.fModelId, fNewModelId);
184}
185
187{
188 fOpenChangeset.fModel.Freeze();
189 std::swap(fOpenChangeset.fModel.fModelId, fNewModelId);
190 if (fOpenChangeset.IsEmpty())
191 return;
192 Internal::RNTupleModelChangeset toCommit{fOpenChangeset.fModel};
193 std::swap(fOpenChangeset.fAddedFields, toCommit.fAddedFields);
194 std::swap(fOpenChangeset.fAddedProjectedFields, toCommit.fAddedProjectedFields);
195 fWriter.GetSink().UpdateSchema(toCommit, fWriter.GetNEntries());
196}
197
199{
200 auto fieldp = field.get();
201 fOpenChangeset.fModel.AddField(std::move(field));
202 fOpenChangeset.fAddedFields.emplace_back(fieldp);
203}
204
207{
208 auto fieldp = field.get();
209 auto result = fOpenChangeset.fModel.AddProjectedField(std::move(field), mapping);
210 if (result)
211 fOpenChangeset.fAddedProjectedFields.emplace_back(fieldp);
213}
214
216{
218 if (!nameValid) {
219 nameValid.Throw();
220 }
221 if (fieldName.empty()) {
222 throw RException(R__FAIL("name cannot be empty string \"\""));
223 }
224 auto fieldNameStr = std::string(fieldName);
225 if (fFieldNames.count(fieldNameStr) > 0)
226 throw RException(R__FAIL("field name '" + fieldNameStr + "' already exists in NTuple model"));
227}
228
230{
231 if (IsFrozen())
232 throw RException(R__FAIL("invalid attempt to modify frozen model"));
233}
234
236{
237 if (IsBare())
238 throw RException(R__FAIL("invalid attempt to use default entry of bare model"));
239}
240
244
245std::unique_ptr<ROOT::Experimental::RNTupleModel> ROOT::Experimental::RNTupleModel::CreateBare()
246{
247 return CreateBare(std::make_unique<RFieldZero>());
248}
249
250std::unique_ptr<ROOT::Experimental::RNTupleModel>
252{
253 auto model = std::unique_ptr<RNTupleModel>(new RNTupleModel(std::move(fieldZero)));
254 model->fProjectedFields = std::make_unique<Internal::RProjectedFields>(*model);
255 return model;
256}
257
258std::unique_ptr<ROOT::Experimental::RNTupleModel> ROOT::Experimental::RNTupleModel::Create()
259{
260 return Create(std::make_unique<RFieldZero>());
261}
262
263std::unique_ptr<ROOT::Experimental::RNTupleModel>
265{
266 auto model = CreateBare(std::move(fieldZero));
267 model->fDefaultEntry = std::unique_ptr<REntry>(new REntry(model->fModelId, model->fSchemaId));
268 return model;
269}
270
271std::unique_ptr<ROOT::Experimental::RNTupleModel> ROOT::Experimental::RNTupleModel::Clone() const
272{
273 auto cloneModel = std::unique_ptr<RNTupleModel>(
274 new RNTupleModel(std::unique_ptr<RFieldZero>(static_cast<RFieldZero *>(fFieldZero->Clone("").release()))));
275 cloneModel->fModelId = GetNewModelId();
276 // For a frozen model, we can keep the schema id because adding new fields is forbidden. It is reset in Unfreeze()
277 // if called by the user.
278 if (IsFrozen()) {
279 cloneModel->fSchemaId = fSchemaId;
280 } else {
281 cloneModel->fSchemaId = cloneModel->fModelId;
282 }
283 cloneModel->fModelState = (fModelState == EState::kExpired) ? EState::kFrozen : fModelState;
284 cloneModel->fFieldNames = fFieldNames;
285 cloneModel->fDescription = fDescription;
286 cloneModel->fProjectedFields = fProjectedFields->Clone(*cloneModel);
287 cloneModel->fRegisteredSubfields = fRegisteredSubfields;
288 if (fDefaultEntry) {
289 cloneModel->fDefaultEntry = std::unique_ptr<REntry>(new REntry(cloneModel->fModelId, cloneModel->fSchemaId));
290 for (const auto &f : cloneModel->fFieldZero->GetSubFields()) {
291 cloneModel->fDefaultEntry->AddValue(f->CreateValue());
292 }
293 for (const auto &f : cloneModel->fRegisteredSubfields) {
294 cloneModel->AddSubfield(f, *cloneModel->fDefaultEntry);
295 }
296 }
297 return cloneModel;
298}
299
301{
302 if (fieldName.empty())
303 return nullptr;
304
305 auto *field = static_cast<ROOT::Experimental::RFieldBase *>(fFieldZero.get());
306 for (auto subfieldName : ROOT::Split(fieldName, ".")) {
307 const auto subfields = field->GetSubFields();
308 auto it = std::find_if(subfields.begin(), subfields.end(),
309 [&](const auto *f) { return f->GetFieldName() == subfieldName; });
310 if (it != subfields.end()) {
311 field = *it;
312 } else {
313 field = nullptr;
314 break;
315 }
316 }
317
318 return field;
319}
320
321void ROOT::Experimental::RNTupleModel::AddField(std::unique_ptr<RFieldBase> field)
322{
323 EnsureNotFrozen();
324 if (!field)
325 throw RException(R__FAIL("null field"));
326 EnsureValidFieldName(field->GetFieldName());
327
328 if (fDefaultEntry)
329 fDefaultEntry->AddValue(field->CreateValue());
330 fFieldNames.insert(field->GetFieldName());
331 fFieldZero->Attach(std::move(field));
332}
333
335 bool initializeValue) const
336{
337 auto field = FindField(qualifiedFieldName);
338 if (initializeValue)
339 entry.AddValue(field->CreateValue());
340 else
341 entry.AddValue(field->BindValue(nullptr));
342}
343
345{
346 if (qualifiedFieldName.empty())
347 throw RException(R__FAIL("no field name provided"));
348
349 if (fFieldNames.find(std::string(qualifiedFieldName)) != fFieldNames.end()) {
350 throw RException(
351 R__FAIL("cannot register top-level field \"" + std::string(qualifiedFieldName) + "\" as a subfield"));
352 }
353
354 if (fRegisteredSubfields.find(std::string(qualifiedFieldName)) != fRegisteredSubfields.end())
355 throw RException(R__FAIL("subfield \"" + std::string(qualifiedFieldName) + "\" already registered"));
356
357 EnsureNotFrozen();
358
359 auto *field = FindField(qualifiedFieldName);
360 if (!field) {
361 throw RException(R__FAIL("could not find subfield \"" + std::string(qualifiedFieldName) + "\" in model"));
362 }
363
364 auto parent = field->GetParent();
365 while (parent && !parent->GetFieldName().empty()) {
366 if (parent->GetStructure() == ROOT::ENTupleStructure::kCollection || parent->GetNRepetitions() > 0 ||
367 parent->GetStructure() == ROOT::ENTupleStructure::kVariant) {
368 throw RException(R__FAIL(
369 "registering a subfield as part of a collection, fixed-sized array or std::variant is not supported"));
370 }
371 parent = parent->GetParent();
372 }
373
374 if (fDefaultEntry)
375 AddSubfield(qualifiedFieldName, *fDefaultEntry);
376 fRegisteredSubfields.emplace(qualifiedFieldName);
377}
378
381{
382 EnsureNotFrozen();
383 if (!field)
384 return R__FAIL("null field");
385 auto fieldName = field->GetFieldName();
386
388 auto sourceField = FindField(mapping(fieldName));
389 if (!sourceField)
390 return R__FAIL("no such field: " + mapping(fieldName));
391 fieldMap[field.get()] = sourceField;
392 for (const auto &subField : *field) {
393 sourceField = FindField(mapping(subField.GetQualifiedFieldName()));
394 if (!sourceField)
395 return R__FAIL("no such field: " + mapping(subField.GetQualifiedFieldName()));
397 }
398
399 EnsureValidFieldName(fieldName);
400 auto result = fProjectedFields->Add(std::move(field), fieldMap);
401 if (!result) {
402 return R__FORWARD_ERROR(result);
403 }
404 fFieldNames.insert(fieldName);
405 return RResult<void>::Success();
406}
407
409{
410 if (IsFrozen())
411 throw RException(R__FAIL("invalid attempt to get mutable zero field of frozen model"));
412 return *fFieldZero;
413}
414
416{
417 if (IsFrozen())
418 throw RException(R__FAIL("invalid attempt to get mutable field of frozen model"));
419 auto f = FindField(fieldName);
420 if (!f)
421 throw RException(R__FAIL("invalid field: " + std::string(fieldName)));
422
423 return *f;
424}
425
427{
428 auto f = FindField(fieldName);
429 if (!f)
430 throw RException(R__FAIL("invalid field: " + std::string(fieldName)));
431
432 return *f;
433}
434
436{
437 EnsureNotBare();
438 return *fDefaultEntry;
439}
440
442{
443 if (!IsFrozen())
444 throw RException(R__FAIL("invalid attempt to get default entry of unfrozen model"));
445 EnsureNotBare();
446 return *fDefaultEntry;
447}
448
449std::unique_ptr<ROOT::Experimental::REntry> ROOT::Experimental::RNTupleModel::CreateEntry() const
450{
451 switch (fModelState) {
452 case EState::kBuilding: throw RException(R__FAIL("invalid attempt to create entry of unfrozen model"));
453 case EState::kExpired: throw RException(R__FAIL("invalid attempt to create entry of expired model"));
454 case EState::kFrozen: break;
455 }
456
457 auto entry = std::unique_ptr<REntry>(new REntry(fModelId, fSchemaId));
458 for (const auto &f : fFieldZero->GetSubFields()) {
459 entry->AddValue(f->CreateValue());
460 }
461 for (const auto &f : fRegisteredSubfields) {
462 AddSubfield(f, *entry);
463 }
464 return entry;
465}
466
467std::unique_ptr<ROOT::Experimental::REntry> ROOT::Experimental::RNTupleModel::CreateBareEntry() const
468{
469 switch (fModelState) {
470 case EState::kBuilding: throw RException(R__FAIL("invalid attempt to create entry of unfrozen model"));
471 case EState::kExpired: throw RException(R__FAIL("invalid attempt to create entry of expired model"));
472 case EState::kFrozen: break;
473 }
474
475 auto entry = std::unique_ptr<REntry>(new REntry(fModelId, fSchemaId));
476 for (const auto &f : fFieldZero->GetSubFields()) {
477 entry->AddValue(f->BindValue(nullptr));
478 }
479 for (const auto &f : fRegisteredSubfields) {
480 AddSubfield(f, *entry, false /* initializeValue */);
481 }
482 return entry;
483}
484
486{
487 const auto &topLevelFields = fFieldZero->GetSubFields();
488 auto it = std::find_if(topLevelFields.begin(), topLevelFields.end(),
489 [&fieldName](const RFieldBase *f) { return f->GetFieldName() == fieldName; });
490
491 if (it == topLevelFields.end()) {
492 throw RException(R__FAIL("invalid field name: " + std::string(fieldName)));
493 }
494 return REntry::RFieldToken(std::distance(topLevelFields.begin(), it), fSchemaId);
495}
496
498{
499 switch (fModelState) {
500 case EState::kBuilding: throw RException(R__FAIL("invalid attempt to create bulk of unfrozen model"));
501 case EState::kExpired: throw RException(R__FAIL("invalid attempt to create bulk of expired model"));
502 case EState::kFrozen: break;
503 }
504
505 auto f = FindField(fieldName);
506 if (!f)
507 throw RException(R__FAIL("no such field: " + std::string(fieldName)));
508 return f->CreateBulk();
509}
510
512{
513 switch (fModelState) {
514 case EState::kExpired: return;
515 case EState::kBuilding: throw RException(R__FAIL("invalid attempt to expire unfrozen model"));
516 case EState::kFrozen: break;
517 }
518
519 // Ensure that Fill() does not work anymore
520 fModelId = 0;
521 fModelState = EState::kExpired;
522}
523
525{
526 switch (fModelState) {
527 case EState::kBuilding: return;
528 case EState::kExpired: throw RException(R__FAIL("invalid attempt to unfreeze expired model"));
529 case EState::kFrozen: break;
530 }
531
532 fModelId = GetNewModelId();
533 fSchemaId = fModelId;
534 if (fDefaultEntry) {
535 fDefaultEntry->fModelId = fModelId;
536 fDefaultEntry->fSchemaId = fSchemaId;
537 }
538 fModelState = EState::kBuilding;
539}
540
542{
543 if (fModelState == EState::kExpired)
544 throw RException(R__FAIL("invalid attempt to freeze expired model"));
545
546 fModelState = EState::kFrozen;
547}
548
550{
551 EnsureNotFrozen();
552 fDescription = std::string(description);
553}
554
556{
557 std::size_t bytes = 0;
558 std::size_t minPageBufferSize = 0;
559
560 // Start with the size of the page buffers used to fill a persistent sink
561 std::size_t nColumns = 0;
562 for (auto &&field : *fFieldZero) {
563 for (const auto &r : field.GetColumnRepresentatives()) {
564 nColumns += r.size();
565 minPageBufferSize += r.size() * options.GetInitialUnzippedPageSize();
566 }
567 }
568 bytes = std::min(options.GetPageBufferBudget(), nColumns * options.GetMaxUnzippedPageSize());
569
570 // If using buffered writing with RPageSinkBuf, we create a clone of the model and keep at least
571 // the compressed pages in memory.
572 if (options.GetUseBufferedWrite()) {
574 // Use the target cluster size as an estimate for all compressed pages combined.
576 int compression = options.GetCompression();
578 // With IMT, compression happens asynchronously which means that the uncompressed pages also stay around. Use a
579 // compression factor of 2x as a very rough estimate.
580 bytes += 2 * options.GetApproxZippedClusterSize();
581 }
582 }
583
584 return bytes;
585}
#define R__FORWARD_ERROR(res)
Short-hand to return an RResult<T> in an error state (i.e. after checking)
Definition RError.hxx:303
#define R__FORWARD_RESULT(res)
Short-hand to return an RResult<T> value from a subroutine to the calling stack frame.
Definition RError.hxx:301
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:299
#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.
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
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 r
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 result
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 bytes
The projected fields of a RNTupleModel
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.
std::unique_ptr< RProjectedFields > Clone(const RNTupleModel &newModel) const
The new model needs to be a clone of fModel.
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 ...
RResult< void > Add(std::unique_ptr< RFieldBase > field, const FieldMap_t &fieldMap)
Adds a new projected field.
const RFieldBase * GetSourceField(const RFieldBase *target) const
An artificial field that transforms an RNTuple column that contains the offset of collections into co...
Definition RField.hxx:314
The field token identifies a (sub)field in this entry.
Definition REntry.hxx:63
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition REntry.hxx:51
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.
const RFieldBase * GetParent() const
The container field for an ntuple model, which itself has no physical representation.
Definition RField.hxx:58
RResult< void > AddProjectedField(std::unique_ptr< RFieldBase > field, FieldMappingFunc_t mapping)
void CommitUpdate()
Commit changes since the last call to BeginUpdate().
void BeginUpdate()
Begin a new set of alterations to the underlying model.
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.
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.
const RFieldBase & GetConstField(std::string_view fieldName) 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...
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.
std::size_t EstimateWriteMemoryUsage(const RNTupleWriteOptions &options=RNTupleWriteOptions()) const
Estimate the memory usage for this model during writing.
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()
void AddSubfield(std::string_view fieldName, REntry &entry, bool initializeValue=true) const
Add a subfield to the provided entry.
void SetDescription(std::string_view description)
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...
RResult< void > AddProjectedField(std::unique_ptr< RFieldBase > field, FieldMappingFunc_t mapping)
Adds a top-level field based on existing fields.
RNTupleModel(std::unique_ptr< RFieldZero > fieldZero)
RFieldBase & GetMutableField(std::string_view fieldName)
static std::unique_ptr< RNTupleModel > CreateBare()
A bare model has no default entry.
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.
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.
Base class for all ROOT issued exceptions.
Definition RError.hxx:79
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
RResult< void > EnsureValidNameForRNTuple(std::string_view name, std::string_view where)
Check whether a given string is a valid name according to the RNTuple specification.
RProjectedFields & GetProjectedFieldsOfModel(RNTupleModel &model)
RFieldZero & GetFieldZeroOfModel(RNTupleModel &model)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
The incremental changes to a RNTupleModel