33 auto fieldNameStr = std::string(fieldName);
34 if (
fFieldNames.insert(fieldNameStr).second ==
false) {
35 throw RException(
R__FAIL(
"field name '" + fieldNameStr +
"' already exists in NTuple model"));
41 , fDefaultEntry(std::make_unique<
REntry>())
46 auto cloneModel = std::make_unique<RNTupleModel>();
47 auto cloneFieldZero = fFieldZero->Clone(
"");
48 cloneModel->fFieldZero = std::unique_ptr<RFieldZero>(
static_cast<RFieldZero *
>(cloneFieldZero.release()));
49 cloneModel->fDefaultEntry = cloneModel->fFieldZero->GenerateEntry();
50 cloneModel->fFieldNames = fFieldNames;
51 cloneModel->fDescription = fDescription;
61 EnsureValidFieldName(field->GetName());
62 fDefaultEntry->AddValue(field->GenerateValue());
63 fFieldZero->Attach(std::move(field));
68 std::string_view fieldName, std::unique_ptr<RNTupleModel> collectionModel)
70 EnsureValidFieldName(fieldName);
71 if (!collectionModel) {
74 auto collectionNTuple = std::make_shared<RCollectionNTupleWriter>(std::move(collectionModel->fDefaultEntry));
75 auto field = std::make_unique<RCollectionField>(fieldName, collectionNTuple, std::move(collectionModel));
76 fDefaultEntry->CaptureValue(field->CaptureValue(collectionNTuple->GetOffsetPtr()));
77 fFieldZero->Attach(std::move(field));
78 return collectionNTuple;
83 if (fieldName.empty())
87 for (
auto subfieldName :
ROOT::Split(fieldName,
".")) {
90 std::find_if(subfields.begin(), subfields.end(), [&](
const auto *
f) { return f->GetName() == subfieldName; });
91 if (it != subfields.end()) {
104 auto entry = std::make_unique<REntry>();
105 for (
auto&
f : *fFieldZero) {
106 if (
f.GetParent() != GetFieldZero())
108 entry->AddValue(
f.GenerateValue());
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
static RResult< void > EnsureValidFieldName(std::string_view fieldName)
Check whether a given string is a valid field name.
std::vector< RFieldBase * > GetSubFields() const
void Throw()
Throws an RException with fError.
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.
std::unordered_set< std::string > fFieldNames
Keeps track of which field names are taken.
void EnsureValidFieldName(std::string_view fieldName)
Checks that user-provided field names are valid in the context of this NTuple model.
std::unique_ptr< RNTupleModel > Clone() const
std::unique_ptr< REntry > CreateEntry()
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.
Detail::RFieldBase * GetField(std::string_view fieldName)
void AddField(std::unique_ptr< Detail::RFieldBase > field)
Adds a field whose type is not known at compile time.
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.