Skip to content

Commit 84876ff

Browse files
committed
Add test for empty RNTuple
Closes #33
1 parent 9f81268 commit 84876ff

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

structure/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Therefore all tests in this category write a single `Int32` field with type `std
55

66
* [`clusters`](clusters): multiple clusters
77
* [`cluster_groups`](cluster_groups): multiple cluster groups
8+
* [`empty`](empty): empty RNTuple without entries

structure/empty/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Empty RNTuple
2+
3+
An RNTuple with a field, but no entry.

structure/empty/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.empty.root",
4+
std::string_view output = "structure.empty.json") {
5+
read_structure(input, output);
6+
}

structure/empty/write.C

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.empty.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+
// Destruct the writer / commit the dataset without filling an entry.
23+
writer.reset();
24+
}

structure/read_structure.hxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ void read_structure(std::string_view input, std::string_view output) {
3131
// Newline is intentionally missing, may need to print a comma before the
3232
// next entry.
3333
}
34-
os << "\n";
34+
if (!first) {
35+
os << "\n";
36+
}
3537
os << "]\n";
3638
}

0 commit comments

Comments
 (0)