Skip to content

Commit b5e8f43

Browse files
jalopezg-gitjblomer
authored andcommitted
[ntuple] DAOS support: added first simple tests
1 parent 19f5128 commit b5e8f43

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

tree/ntuple/v7/test/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,14 @@ ROOT_ADD_GTEST(ntuple_minifile ntuple_minifile.cxx LIBRARIES ROOTDataFrame ROOTN
4545
ROOT_ADD_GTEST(ntuple_show ntuple_show.cxx LIBRARIES ROOTDataFrame ROOTNTuple MathCore CustomStruct)
4646
ROOT_ADD_GTEST(ntuple_storage ntuple_storage.cxx LIBRARIES ROOTDataFrame ROOTNTuple MathCore CustomStruct)
4747
ROOT_ADD_GTEST(ntuple_extended ntuple_extended.cxx LIBRARIES ROOTDataFrame ROOTNTuple MathCore CustomStruct)
48+
49+
if(daos OR daos_mock)
50+
# UUID of the DAOS pool used for testing, if not provided (may be any for libdaos_mock).
51+
if(NOT daos_test_pool)
52+
set(daos_test_pool 1b245c52-765e-449d-80b1-8dce93bafc4b)
53+
endif()
54+
set_property(SOURCE ntuple_storage_daos.cxx
55+
APPEND PROPERTY COMPILE_OPTIONS -DR__DAOS_TEST_POOL="${daos_test_pool}")
56+
57+
ROOT_ADD_GTEST(ntuple_storage_daos ntuple_storage_daos.cxx LIBRARIES ROOTDataFrame ROOTNTuple MathCore CustomStruct)
58+
endif()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "ntuple_test.hxx"
2+
3+
TEST(RNTuple, Basics)
4+
{
5+
std::string daosUri("daos://" R__DAOS_TEST_POOL ":1/a947484e-e3bc-48cb-8f71-3292c19b59a4");
6+
7+
auto model = RNTupleModel::Create();
8+
auto wrPt = model->MakeField<float>("pt", 42.0);
9+
10+
{
11+
RNTupleWriteOptions options;
12+
options.SetContainerFormat(ENTupleContainerFormat::kBare);
13+
auto ntuple = RNTupleWriter::Recreate(std::move(model), "f", daosUri, options);
14+
ntuple->Fill();
15+
ntuple->CommitCluster();
16+
*wrPt = 24.0;
17+
ntuple->Fill();
18+
*wrPt = 12.0;
19+
ntuple->Fill();
20+
}
21+
22+
auto ntuple = RNTupleReader::Open("f", daosUri);
23+
EXPECT_EQ(3U, ntuple->GetNEntries());
24+
auto rdPt = ntuple->GetModel()->GetDefaultEntry()->Get<float>("pt");
25+
26+
ntuple->LoadEntry(0);
27+
EXPECT_EQ(42.0, *rdPt);
28+
ntuple->LoadEntry(1);
29+
EXPECT_EQ(24.0, *rdPt);
30+
ntuple->LoadEntry(2);
31+
EXPECT_EQ(12.0, *rdPt);
32+
}
33+
34+
TEST(RNTuple, Extended)
35+
{
36+
std::string daosUri("daos://" R__DAOS_TEST_POOL ":1/a947484e-e3bc-48cb-8f71-3292c19b59a4");
37+
38+
auto model = RNTupleModel::Create();
39+
auto wrVector = model->MakeField<std::vector<double>>("vector");
40+
41+
TRandom3 rnd(42);
42+
double chksumWrite = 0.0;
43+
{
44+
RNTupleWriteOptions options;
45+
options.SetContainerFormat(ENTupleContainerFormat::kBare);
46+
auto ntuple = RNTupleWriter::Recreate(std::move(model), "f", daosUri, options);
47+
constexpr unsigned int nEvents = 32000;
48+
for (unsigned int i = 0; i < nEvents; ++i) {
49+
auto nVec = 1 + floor(rnd.Rndm() * 1000.);
50+
wrVector->resize(nVec);
51+
for (unsigned int n = 0; n < nVec; ++n) {
52+
auto val = 1 + rnd.Rndm()*1000. - 500.;
53+
(*wrVector)[n] = val;
54+
chksumWrite += val;
55+
}
56+
ntuple->Fill();
57+
if (i % 1000 == 0)
58+
ntuple->CommitCluster();
59+
}
60+
}
61+
62+
auto ntuple = RNTupleReader::Open("f", daosUri);
63+
auto rdVector = ntuple->GetModel()->GetDefaultEntry()->Get<std::vector<double>>("vector");
64+
65+
double chksumRead = 0.0;
66+
for (auto entryId : *ntuple) {
67+
ntuple->LoadEntry(entryId);
68+
for (auto v : *rdVector)
69+
chksumRead += v;
70+
}
71+
EXPECT_EQ(chksumRead, chksumWrite);
72+
}

0 commit comments

Comments
 (0)