Skip to content

Commit e4c6e2f

Browse files
committed
[ntuple] test fixed-size array to vector evolution
1 parent 1a150be commit e4c6e2f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tree/ntuple/test/ntuple_evolution_type.cxx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,33 @@ TEST(RNTupleEvolution, ArrayAsRVec)
256256
EXPECT_EQ(2, a(0)[1]);
257257
}
258258

259+
TEST(RNTupleEvolution, ArrayAsVector)
260+
{
261+
FileRaii fileGuard("test_ntuple_evolution_array_as_vector.root");
262+
{
263+
auto model = ROOT::RNTupleModel::Create();
264+
auto a = model->MakeField<std::array<int, 2>>("a");
265+
auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "ntpl", fileGuard.GetPath());
266+
267+
*a = {0, 1};
268+
writer->Fill();
269+
}
270+
271+
auto reader = RNTupleReader::Open("ntpl", fileGuard.GetPath());
272+
273+
auto aAsShort = reader->GetView<std::vector<short>>("a");
274+
const auto &f = aAsShort.GetField(); // necessary to silence clang warning
275+
EXPECT_EQ(typeid(f), typeid(ROOT::RArrayAsVectorField));
276+
EXPECT_EQ(2u, aAsShort(0).size());
277+
EXPECT_EQ(0, aAsShort(0)[0]);
278+
EXPECT_EQ(1, aAsShort(0)[1]);
279+
280+
auto aAsBool = reader->GetView<std::vector<bool>>("a");
281+
EXPECT_EQ(2u, aAsBool(0).size());
282+
EXPECT_FALSE(aAsBool(0)[0]);
283+
EXPECT_TRUE(aAsBool(0)[1]);
284+
}
285+
259286
TEST(RNTupleEvolution, NullableToVector)
260287
{
261288
FileRaii fileGuard("test_ntuple_evolution_nullable_to_vector.root");

0 commit comments

Comments
 (0)