Skip to content

Commit

Permalink
[ntuple] forbid RNTuple I/O of unsplittable classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jblomer committed Mar 6, 2024
1 parent ce7f33d commit 3ecb224
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions tree/ntuple/v7/doc/specifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ User defined C++ classes are supported with the following limitations
- All persistent members and base classes must be themselves types with RNTuple I/O support
- Transient members must be marked by a `//!` comment
- The class must not be in the `std` namespace
- The class must be empty or splittable (e.g., the class must not provide a custom streamer)
- There is no support for polymorphism,
i.e. a field of class `A` cannot store class `B` that derives from `A`

Expand Down
4 changes: 4 additions & 0 deletions tree/ntuple/v7/src/RField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,10 @@ ROOT::Experimental::RClassField::RClassField(std::string_view fieldName, std::st
throw RException(
R__FAIL(std::string(className) + " has an associated collection proxy; use RProxiedCollectionField instead"));
}
// Classes with, e.g., custom streamers are not supported through this field. Empty classes, however, are.
if (!fClass->CanSplit() && fClass->Size() > 1) {
throw RException(R__FAIL(std::string(className) + " cannot be split"));
}

if (!(fClass->ClassProperty() & kClassHasExplicitCtor))
fTraits |= kTraitTriviallyConstructible;
Expand Down
3 changes: 3 additions & 0 deletions tree/ntuple/v7/test/rfield_class.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ TEST(RNTuple, TClass) {
auto model = RNTupleModel::Create();
auto ptrKlass = model->MakeField<CustomStruct>("klass");

// TDatime would be a supported class layout but it is unsplittable due to its custom streamer
EXPECT_THROW(model->MakeField<TDatime>("datime"), RException);

FileRaii fileGuard("test_ntuple_tclass.root");
auto ntuple = RNTupleWriter::Recreate(std::move(model), "f", fileGuard.GetPath());
}

0 comments on commit 3ecb224

Please sign in to comment.