Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
pull_request:

jobs:
root-v634:
name: ROOT 6.34
root-v636:
name: ROOT 6.36
runs-on: ubuntu-latest
container: rootproject/root:6.34.00-ubuntu24.04
container: rootproject/root:6.36.00-ubuntu25.04
steps:
- name: Check out repository
uses: actions/checkout@v5
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ More tests are planned in the future, please [consult the list of issues](https:
## Reference Implementation

This repository also contains a reference implementation with ROOT macros.
They currently target ROOT v6.34 with the first official version of the RNTuple on-disk binary format.
In this release, the API is not yet finalized and all classes are in the `ROOT::Experimental` namespace.
We rely on this version to produce a first set of reference files that can be used to test backwards compatibility.
Afterwards, the implementation will be updated for the stable API (available since ROOT v6.36).
They target the stable API released with ROOT v6.36 and should work on newer versions.
Compatibility with ROOT v6.34 can be tested with version v1.0 of the RNTuple Validation Suite.
It was the first official version of the RNTuple on-disk binary format, but the API was not yet finalized and all classes were in the `ROOT::Experimental` namespace.

### How to Run

Expand Down
19 changes: 9 additions & 10 deletions compression/algorithms/write_algorithm.hxx
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
#include <ROOT/RNTupleModel.hxx>
#if __has_include(<ROOT/RNTupleTypes.hxx>)
#include <ROOT/RNTupleTypes.hxx>
#else
#include <ROOT/RNTupleUtil.hxx>
#endif
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>

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

#include <cstdint>
#include <memory>
#include <string_view>

void write_algorithm(std::string_view filename, std::uint32_t compression) {
auto model = RNTupleModel::Create();
auto model = ROOT::RNTupleModel::Create();

auto Int64 = model->MakeField<std::int64_t>("Int64");
model->GetMutableField("Int64").SetColumnRepresentatives(
{{EColumnType::kSplitInt64}});
{{ROOT::ENTupleColumnType::kSplitInt64}});

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

// Write 32 entries to make sure the compression block is not too small.
for (int i = 0; i < 32; i++) {
Expand Down
19 changes: 9 additions & 10 deletions compression/block/big/write.C
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
#include <ROOT/RNTupleModel.hxx>
#if __has_include(<ROOT/RNTupleTypes.hxx>)
#include <ROOT/RNTupleTypes.hxx>
#else
#include <ROOT/RNTupleUtil.hxx>
#endif
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>

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

#include <cstdint>
#include <memory>
#include <string_view>

void write(std::string_view filename = "compression.block.big.root") {
auto model = RNTupleModel::Create();
auto model = ROOT::RNTupleModel::Create();

auto Int64 = model->MakeField<std::int64_t>("Int64");
model->GetMutableField("Int64").SetColumnRepresentatives(
{{EColumnType::kSplitInt64}});
{{ROOT::ENTupleColumnType::kSplitInt64}});

RNTupleWriteOptions options;
ROOT::RNTupleWriteOptions options;
// Crank up the zstd compression level to reduce the output file size by
// approximately a factor 6 (from 76K with 505 to 12K).
options.SetCompression(509);
// Increase the maximum unzipped page size to make it bigger than the maximum
// size of a compression block, which is 16 MiB.
options.SetMaxUnzippedPageSize(128 * 1024 * 1024);
auto writer =
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "ntpl",
filename, options);

// Write 40 MiB of entries that will be split into three compression blocks.
static constexpr int Entries = 40 * 1024 * 1024 / sizeof(std::int64_t);
Expand Down
19 changes: 9 additions & 10 deletions compression/block/short/write.C
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
#include <ROOT/RNTupleModel.hxx>
#if __has_include(<ROOT/RNTupleTypes.hxx>)
#include <ROOT/RNTupleTypes.hxx>
#else
#include <ROOT/RNTupleUtil.hxx>
#endif
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>

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

#include <cstdint>
#include <memory>
#include <string_view>

void write(std::string_view filename = "compression.block.short.root") {
auto model = RNTupleModel::Create();
auto model = ROOT::RNTupleModel::Create();

auto Int64 = model->MakeField<std::int64_t>("Int64");
model->GetMutableField("Int64").SetColumnRepresentatives(
{{EColumnType::kSplitInt64}});
{{ROOT::ENTupleColumnType::kSplitInt64}});

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

// Write only 2 entries to make sure the compression block is small and
// actually stored uncompressed.
Expand Down
5 changes: 1 addition & 4 deletions compression/read_compression.hxx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#include <ROOT/REntry.hxx>
#include <ROOT/RNTupleReader.hxx>

using ROOT::Experimental::REntry;
using ROOT::Experimental::RNTupleReader;

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

void read_compression(std::string_view input, std::string_view output) {
auto reader = RNTupleReader::Open("ntpl", input);
auto reader = ROOT::RNTupleReader::Open("ntpl", input);
auto Int64 =
reader->GetModel().GetDefaultEntry().GetPtr<std::int64_t>("Int64");
std::int64_t sum = 0;
Expand Down
13 changes: 7 additions & 6 deletions projections/cardinality/read.C
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <ROOT/REntry.hxx>
#include <ROOT/RNTupleReader.hxx>
#if __has_include(<ROOT/RNTupleTypes.hxx>)
#include <ROOT/RNTupleTypes.hxx>
#else
#include <ROOT/RNTupleUtil.hxx>

using ROOT::Experimental::REntry;
using ROOT::Experimental::RNTupleReader;
#endif

#include <cstdint>
#include <fstream>
Expand All @@ -14,7 +15,7 @@ using ROOT::Experimental::RNTupleReader;

using Vector = std::vector<std::int32_t>;

static void PrintVectorValue(const REntry &entry, std::string_view name,
static void PrintVectorValue(const ROOT::REntry &entry, std::string_view name,
std::ostream &os, bool last = false) {
Vector &value = *entry.GetPtr<Vector>(name);
os << " \"" << name << "\": [";
Expand All @@ -38,7 +39,7 @@ static void PrintVectorValue(const REntry &entry, std::string_view name,
}

template <typename T>
static void PrintCardinality(const REntry &entry, std::string_view name,
static void PrintCardinality(const ROOT::REntry &entry, std::string_view name,
std::ostream &os, bool last = false) {
T value = *entry.GetPtr<ROOT::RNTupleCardinality<T>>(name);
os << " \"" << name << "\": " << value;
Expand All @@ -53,7 +54,7 @@ void read(std::string_view input = "projections.cardinality.root",
std::ofstream os(std::string{output});
os << "[\n";

auto reader = RNTupleReader::Open("ntpl", input);
auto reader = ROOT::RNTupleReader::Open("ntpl", input);
auto &entry = reader->GetModel().GetDefaultEntry();
bool first = true;
for (auto index : *reader) {
Expand Down
45 changes: 23 additions & 22 deletions projections/cardinality/write.C
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include <ROOT/RField.hxx>
#include <ROOT/RNTupleModel.hxx>
#if __has_include(<ROOT/RNTupleTypes.hxx>)
#include <ROOT/RNTupleTypes.hxx>
#else
#include <ROOT/RNTupleUtil.hxx>
#endif
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>

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

#include <cstdint>
#include <memory>
#include <string>
Expand All @@ -18,37 +16,40 @@ using ROOT::Experimental::RNTupleWriter;

using Vector = std::vector<std::int32_t>;

static std::shared_ptr<Vector> MakeVectorField(RNTupleModel &model,
std::string_view name,
EColumnType indexType) {
auto field = std::make_unique<RField<Vector>>(name);
static std::shared_ptr<Vector>
MakeVectorField(ROOT::RNTupleModel &model, std::string_view name,
ROOT::ENTupleColumnType indexType) {
auto field = std::make_unique<ROOT::RField<Vector>>(name);
field->SetColumnRepresentatives({{indexType}});
model.AddField(std::move(field));
return model.GetDefaultEntry().GetPtr<Vector>(name);
}

template <typename T>
static void AddProjectedCardinalityField(RNTupleModel &model,
static void AddProjectedCardinalityField(ROOT::RNTupleModel &model,
std::string_view name,
std::string_view source) {
auto field = std::make_unique<RField<ROOT::RNTupleCardinality<T>>>(name);
auto field =
std::make_unique<ROOT::RField<ROOT::RNTupleCardinality<T>>>(name);
model.AddProjectedField(std::move(field), [&source](const std::string &) {
return std::string{source};
});
}

void write(std::string_view filename = "projections.cardinality.root") {
auto model = RNTupleModel::Create();
auto model = ROOT::RNTupleModel::Create();

// Non-split index encoding
auto Index32 = MakeVectorField(*model, "Index32", EColumnType::kIndex32);
auto Index64 = MakeVectorField(*model, "Index64", EColumnType::kIndex64);
auto Index32 =
MakeVectorField(*model, "Index32", ROOT::ENTupleColumnType::kIndex32);
auto Index64 =
MakeVectorField(*model, "Index64", ROOT::ENTupleColumnType::kIndex64);

// Split index encoding
auto SplitIndex32 =
MakeVectorField(*model, "SplitIndex32", EColumnType::kSplitIndex32);
auto SplitIndex64 =
MakeVectorField(*model, "SplitIndex64", EColumnType::kSplitIndex64);
auto SplitIndex32 = MakeVectorField(*model, "SplitIndex32",
ROOT::ENTupleColumnType::kSplitIndex32);
auto SplitIndex64 = MakeVectorField(*model, "SplitIndex64",
ROOT::ENTupleColumnType::kSplitIndex64);

// Create RNTupleCardinality projections
AddProjectedCardinalityField<std::uint32_t>(*model, "Index32Cardinality",
Expand All @@ -60,10 +61,10 @@ void write(std::string_view filename = "projections.cardinality.root") {
AddProjectedCardinalityField<std::uint64_t>(*model, "SplitIndex64Cardinality",
"SplitIndex64");

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

// First entry: single-element vectors, with ascending values
*Index32 = {1};
Expand Down
10 changes: 4 additions & 6 deletions projections/collection/read.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include <ROOT/RNTupleReader.hxx>
#include <ROOT/RVec.hxx>

using ROOT::Experimental::REntry;
using ROOT::Experimental::RNTupleReader;

#include <cstdint>
#include <fstream>
#include <ostream>
Expand All @@ -13,8 +10,9 @@ using ROOT::Experimental::RNTupleReader;
#include <vector>

template <typename C>
static void PrintCollectionValue(const REntry &entry, std::string_view name,
std::ostream &os, bool last = false) {
static void PrintCollectionValue(const ROOT::REntry &entry,
std::string_view name, std::ostream &os,
bool last = false) {
C &value = *entry.GetPtr<C>(name);
os << " \"" << name << "\": [";
bool first = true;
Expand All @@ -41,7 +39,7 @@ void read(std::string_view input = "projections.collection.root",
std::ofstream os(std::string{output});
os << "[\n";

auto reader = RNTupleReader::Open("ntpl", input);
auto reader = ROOT::RNTupleReader::Open("ntpl", input);
auto &entry = reader->GetModel().GetDefaultEntry();
bool first = true;
for (auto index : *reader) {
Expand Down
15 changes: 5 additions & 10 deletions projections/collection/write.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RVec.hxx>

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

#include <cstdint>
#include <memory>
#include <string>
#include <string_view>
#include <vector>

void write(std::string_view filename = "projections.collection.root") {
auto model = RNTupleModel::Create();
auto model = ROOT::RNTupleModel::Create();

auto Vector = model->MakeField<std::vector<std::int32_t>>("Vector");
auto Projected =
std::make_unique<RField<ROOT::RVec<std::int32_t>>>("Projected");
std::make_unique<ROOT::RField<ROOT::RVec<std::int32_t>>>("Projected");
model->AddProjectedField(std::move(Projected),
[](const std::string &fieldName) {
if (fieldName == "Projected") {
Expand All @@ -30,10 +25,10 @@ void write(std::string_view filename = "projections.collection.root") {
}
});

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

// First entry: ascending values
*Vector = {1, 2};
Expand Down
Loading