Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions structure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Structure

For the RNTuple Validation Suite, we assume that the structure is orthogonal to the supported types and serialized data.
Therefore all tests in this category write a single `Int32` field with type `std::int32_t` the entries have ascending values.

* [`clusters`](clusters): multiple clusters
* [`cluster_groups`](cluster_groups): multiple cluster groups
* [`empty`](empty): empty RNTuple without entries
3 changes: 3 additions & 0 deletions structure/cluster_groups/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cluster Groups

Two cluster groups with two clusters each and a total of four entries.
6 changes: 6 additions & 0 deletions structure/cluster_groups/read.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "../read_structure.hxx"

void read(std::string_view input = "structure.cluster_groups.root",
std::string_view output = "structure.cluster_groups.json") {
read_structure(input, output);
}
37 changes: 37 additions & 0 deletions structure/cluster_groups/write.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>

using ROOT::Experimental::RNTupleModel;
using ROOT::Experimental::RNTupleWriteOptions;
using ROOT::Experimental::RNTupleWriter;

#include <cstdint>
#include <string_view>

void write(std::string_view filename = "structure.cluster_groups.root") {
auto model = RNTupleModel::Create();

auto Int32 = model->MakeField<std::int32_t>("Int32");

RNTupleWriteOptions options;
options.SetCompression(0);
auto writer =
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);

*Int32 = 1;
writer->Fill();
writer->CommitCluster();

*Int32 = 2;
writer->Fill();
writer->CommitCluster(/*commitClusterGroup=*/true);

*Int32 = 3;
writer->Fill();
writer->CommitCluster();

*Int32 = 4;
writer->Fill();
writer->CommitCluster(/*commitClusterGroup=*/true);
}
3 changes: 3 additions & 0 deletions structure/clusters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Clusters

Two clusters with one entry each.
6 changes: 6 additions & 0 deletions structure/clusters/read.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "../read_structure.hxx"

void read(std::string_view input = "structure.clusters.root",
std::string_view output = "structure.clusters.json") {
read_structure(input, output);
}
29 changes: 29 additions & 0 deletions structure/clusters/write.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>

using ROOT::Experimental::RNTupleModel;
using ROOT::Experimental::RNTupleWriteOptions;
using ROOT::Experimental::RNTupleWriter;

#include <cstdint>
#include <string_view>

void write(std::string_view filename = "structure.clusters.root") {
auto model = RNTupleModel::Create();

auto Int32 = model->MakeField<std::int32_t>("Int32");

RNTupleWriteOptions options;
options.SetCompression(0);
auto writer =
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);

*Int32 = 1;
writer->Fill();
writer->CommitCluster();

*Int32 = 2;
writer->Fill();
writer->CommitCluster();
}
3 changes: 3 additions & 0 deletions structure/empty/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Empty RNTuple

An RNTuple with a field, but no entry.
6 changes: 6 additions & 0 deletions structure/empty/read.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "../read_structure.hxx"

void read(std::string_view input = "structure.empty.root",
std::string_view output = "structure.empty.json") {
read_structure(input, output);
}
24 changes: 24 additions & 0 deletions structure/empty/write.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>

using ROOT::Experimental::RNTupleModel;
using ROOT::Experimental::RNTupleWriteOptions;
using ROOT::Experimental::RNTupleWriter;

#include <cstdint>
#include <string_view>

void write(std::string_view filename = "structure.empty.root") {
auto model = RNTupleModel::Create();

auto Int32 = model->MakeField<std::int32_t>("Int32");

RNTupleWriteOptions options;
options.SetCompression(0);
auto writer =
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);

// Destruct the writer / commit the dataset without filling an entry.
writer.reset();
}
38 changes: 38 additions & 0 deletions structure/read_structure.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <ROOT/REntry.hxx>
#include <ROOT/RNTupleReader.hxx>

using ROOT::Experimental::RNTupleReader;

#include <cstdint>
#include <fstream>
#include <ostream>
#include <string>
#include <string_view>

void read_structure(std::string_view input, std::string_view output) {
std::ofstream os(std::string{output});
os << "[\n";

auto reader = RNTupleReader::Open("ntpl", input);
auto Int32 =
reader->GetModel().GetDefaultEntry().GetPtr<std::int32_t>("Int32");
bool first = true;
for (auto index : *reader) {
reader->LoadEntry(index);

if (first) {
first = false;
} else {
os << ",\n";
}
os << " {\n";
os << " \"Int32\": " << *Int32 << "\n";
os << " }";
// Newline is intentionally missing, may need to print a comma before the
// next entry.
}
if (!first) {
os << "\n";
}
os << "]\n";
}