Skip to content

Commit 9f81268

Browse files
committed
Add tests for structure of RNTuple
... with clusters and cluster groups. Closes #29
1 parent 2b32351 commit 9f81268

8 files changed

Lines changed: 127 additions & 0 deletions

File tree

structure/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Structure
2+
3+
For the RNTuple Validation Suite, we assume that the structure is orthogonal to the supported types and serialized data.
4+
Therefore all tests in this category write a single `Int32` field with type `std::int32_t` the entries have ascending values.
5+
6+
* [`clusters`](clusters): multiple clusters
7+
* [`cluster_groups`](cluster_groups): multiple cluster groups

structure/cluster_groups/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Cluster Groups
2+
3+
Two cluster groups with two clusters each and a total of four entries.

structure/cluster_groups/read.C

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "../read_structure.hxx"
2+
3+
void read(std::string_view input = "structure.cluster_groups.root",
4+
std::string_view output = "structure.cluster_groups.json") {
5+
read_structure(input, output);
6+
}

structure/cluster_groups/write.C

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <ROOT/RNTupleModel.hxx>
2+
#include <ROOT/RNTupleWriteOptions.hxx>
3+
#include <ROOT/RNTupleWriter.hxx>
4+
5+
using ROOT::Experimental::RNTupleModel;
6+
using ROOT::Experimental::RNTupleWriteOptions;
7+
using ROOT::Experimental::RNTupleWriter;
8+
9+
#include <cstdint>
10+
#include <string_view>
11+
12+
void write(std::string_view filename = "structure.cluster_groups.root") {
13+
auto model = RNTupleModel::Create();
14+
15+
auto Int32 = model->MakeField<std::int32_t>("Int32");
16+
17+
RNTupleWriteOptions options;
18+
options.SetCompression(0);
19+
auto writer =
20+
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
21+
22+
*Int32 = 1;
23+
writer->Fill();
24+
writer->CommitCluster();
25+
26+
*Int32 = 2;
27+
writer->Fill();
28+
writer->CommitCluster(/*commitClusterGroup=*/true);
29+
30+
*Int32 = 3;
31+
writer->Fill();
32+
writer->CommitCluster();
33+
34+
*Int32 = 4;
35+
writer->Fill();
36+
writer->CommitCluster(/*commitClusterGroup=*/true);
37+
}

structure/clusters/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Clusters
2+
3+
Two clusters with one entry each.

structure/clusters/read.C

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "../read_structure.hxx"
2+
3+
void read(std::string_view input = "structure.clusters.root",
4+
std::string_view output = "structure.clusters.json") {
5+
read_structure(input, output);
6+
}

structure/clusters/write.C

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <ROOT/RNTupleModel.hxx>
2+
#include <ROOT/RNTupleWriteOptions.hxx>
3+
#include <ROOT/RNTupleWriter.hxx>
4+
5+
using ROOT::Experimental::RNTupleModel;
6+
using ROOT::Experimental::RNTupleWriteOptions;
7+
using ROOT::Experimental::RNTupleWriter;
8+
9+
#include <cstdint>
10+
#include <string_view>
11+
12+
void write(std::string_view filename = "structure.clusters.root") {
13+
auto model = RNTupleModel::Create();
14+
15+
auto Int32 = model->MakeField<std::int32_t>("Int32");
16+
17+
RNTupleWriteOptions options;
18+
options.SetCompression(0);
19+
auto writer =
20+
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
21+
22+
*Int32 = 1;
23+
writer->Fill();
24+
writer->CommitCluster();
25+
26+
*Int32 = 2;
27+
writer->Fill();
28+
writer->CommitCluster();
29+
}

structure/read_structure.hxx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <ROOT/REntry.hxx>
2+
#include <ROOT/RNTupleReader.hxx>
3+
4+
using ROOT::Experimental::RNTupleReader;
5+
6+
#include <cstdint>
7+
#include <fstream>
8+
#include <ostream>
9+
#include <string>
10+
#include <string_view>
11+
12+
void read_structure(std::string_view input, std::string_view output) {
13+
std::ofstream os(std::string{output});
14+
os << "[\n";
15+
16+
auto reader = RNTupleReader::Open("ntpl", input);
17+
auto Int32 =
18+
reader->GetModel().GetDefaultEntry().GetPtr<std::int32_t>("Int32");
19+
bool first = true;
20+
for (auto index : *reader) {
21+
reader->LoadEntry(index);
22+
23+
if (first) {
24+
first = false;
25+
} else {
26+
os << ",\n";
27+
}
28+
os << " {\n";
29+
os << " \"Int32\": " << *Int32 << "\n";
30+
os << " }";
31+
// Newline is intentionally missing, may need to print a comma before the
32+
// next entry.
33+
}
34+
os << "\n";
35+
os << "]\n";
36+
}

0 commit comments

Comments
 (0)