Skip to content

Commit c14ae13

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

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
@@ -253,3 +253,30 @@ TEST(RNTupleEvolution, ArrayAsRVec)
253253
EXPECT_EQ(1, a(0)[0]);
254254
EXPECT_EQ(2, a(0)[1]);
255255
}
256+
257+
TEST(RNTupleEvolution, ArrayAsVector)
258+
{
259+
FileRaii fileGuard("test_ntuple_evolution_array_as_vector.root");
260+
{
261+
auto model = ROOT::RNTupleModel::Create();
262+
auto a = model->MakeField<std::array<int, 2>>("a");
263+
auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "ntpl", fileGuard.GetPath());
264+
265+
*a = {0, 1};
266+
writer->Fill();
267+
}
268+
269+
auto reader = RNTupleReader::Open("ntpl", fileGuard.GetPath());
270+
271+
auto aAsShort = reader->GetView<std::vector<short>>("a");
272+
const auto &f = aAsShort.GetField(); // necessary to silence clang warning
273+
EXPECT_EQ(typeid(f), typeid(ROOT::RArrayAsVectorField));
274+
EXPECT_EQ(2u, aAsShort(0).size());
275+
EXPECT_EQ(0, aAsShort(0)[0]);
276+
EXPECT_EQ(1, aAsShort(0)[1]);
277+
278+
auto aAsBool = reader->GetView<std::vector<bool>>("a");
279+
EXPECT_EQ(2u, aAsBool(0).size());
280+
EXPECT_FALSE(aAsBool(0)[0]);
281+
EXPECT_TRUE(aAsBool(0)[1]);
282+
}

0 commit comments

Comments
 (0)