Skip to content

Commit 516dd85

Browse files
committed
Add tests for compression algorithms
1 parent a91c84c commit 516dd85

File tree

12 files changed

+111
-0
lines changed

12 files changed

+111
-0
lines changed

compression/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Compression
2+
3+
In this category, all tests write a single `Int64` field with type `std::int64_t`.
4+
The entries have ascending values and the reference `.json` files only contain the sum of all elements.
5+
6+
* [`algorithms`](algorithms): `zlib`, `lzma`, `lz4`, `zstd`

compression/algorithms/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Compression Algorithms
2+
3+
* [`zlib`](zlib): compression settings `101`
4+
* [`lzma`](lzma): level 7 (`207`)
5+
* [`lz4`](lz4): level 4 (`404`)
6+
* [`zstd`](zstd): level 5 (`505`)

compression/algorithms/lz4/read.C

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

compression/algorithms/lz4/write.C

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "../write_algorithm.hxx"
2+
3+
void write(std::string_view filename = "compression.algorithms.lz4.root") {
4+
write_algorithm(filename, 404);
5+
}

compression/algorithms/lzma/read.C

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

compression/algorithms/lzma/write.C

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "../write_algorithm.hxx"
2+
3+
void write(std::string_view filename = "compression.algorithms.lzma.root") {
4+
write_algorithm(filename, 207);
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 <memory>
11+
#include <string_view>
12+
13+
void write_algorithm(std::string_view filename, std::uint32_t compression) {
14+
auto model = RNTupleModel::Create();
15+
16+
auto Int64 = model->MakeField<std::int64_t>("Int64");
17+
18+
RNTupleWriteOptions options;
19+
options.SetCompression(compression);
20+
auto writer =
21+
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
22+
23+
// Write 32 entries to make sure the compression block is not too small.
24+
for (int i = 0; i < 32; i++) {
25+
*Int64 = i;
26+
writer->Fill();
27+
}
28+
}

compression/algorithms/zlib/read.C

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

compression/algorithms/zlib/write.C

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "../write_algorithm.hxx"
2+
3+
void write(std::string_view filename = "compression.algorithms.zlib.root") {
4+
write_algorithm(filename, 101);
5+
}

compression/algorithms/zstd/read.C

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

compression/algorithms/zstd/write.C

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "../write_algorithm.hxx"
2+
3+
void write(std::string_view filename = "compression.algorithms.zstd.root") {
4+
write_algorithm(filename, 505);
5+
}

compression/read_compression.hxx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <ROOT/REntry.hxx>
2+
#include <ROOT/RNTupleReader.hxx>
3+
4+
using ROOT::Experimental::REntry;
5+
using ROOT::Experimental::RNTupleReader;
6+
7+
#include <cstdint>
8+
#include <fstream>
9+
#include <ostream>
10+
#include <string>
11+
#include <string_view>
12+
13+
void read_compression(std::string_view input, std::string_view output) {
14+
auto reader = RNTupleReader::Open("ntpl", input);
15+
auto Int64 =
16+
reader->GetModel().GetDefaultEntry().GetPtr<std::int64_t>("Int64");
17+
std::int64_t sum = 0;
18+
for (auto index : *reader) {
19+
reader->LoadEntry(index);
20+
sum += *Int64;
21+
}
22+
23+
std::ofstream os(std::string{output});
24+
os << "{\n";
25+
os << " \"Int64\": " << sum << "\n";
26+
os << "}\n";
27+
}

0 commit comments

Comments
 (0)