Skip to content

Commit 7e0301b

Browse files
committed
Add tests for compression blocks
1 parent 516dd85 commit 7e0301b

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

compression/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ In this category, all tests write a single `Int64` field with type `std::int64_t
44
The entries have ascending values and the reference `.json` files only contain the sum of all elements.
55

66
* [`algorithms`](algorithms): `zlib`, `lzma`, `lz4`, `zstd`
7+
* [`block`](block): big and short compression blocks

compression/block/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Compression Blocks
2+
3+
* [`big`](big): big compression blocks, larger than 16 MiB
4+
* [`short`](short): a "short" compression that is actually uncompressed

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

compression/block/big/write.C

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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(std::string_view filename = "compression.block.big.root") {
14+
auto model = RNTupleModel::Create();
15+
16+
auto Int64 = model->MakeField<std::int64_t>("Int64");
17+
18+
RNTupleWriteOptions options;
19+
// Crank up the zstd compression level to reduce the output file size by
20+
// approximately a factor 6 (from 76K with 505 to 12K).
21+
options.SetCompression(509);
22+
// Increase the maximum unzipped page size to make it bigger than the maximum
23+
// size of a compression block, which is 16 MiB.
24+
options.SetMaxUnzippedPageSize(128 * 1024 * 1024);
25+
auto writer =
26+
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
27+
28+
// Write 40 MiB of entries that will be split into three compression blocks.
29+
static constexpr int Entries = 40 * 1024 * 1024 / sizeof(std::int64_t);
30+
for (int i = 0; i < Entries; i++) {
31+
*Int64 = i;
32+
writer->Fill();
33+
}
34+
}

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

compression/block/short/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 <memory>
11+
#include <string_view>
12+
13+
void write(std::string_view filename = "compression.block.short.root") {
14+
auto model = RNTupleModel::Create();
15+
16+
auto Int64 = model->MakeField<std::int64_t>("Int64");
17+
18+
RNTupleWriteOptions options;
19+
options.SetCompression(505);
20+
auto writer =
21+
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
22+
23+
// Write only 2 entries to make sure the compression block is small and
24+
// actually stored uncompressed.
25+
for (int i = 0; i < 2; i++) {
26+
*Int64 = i;
27+
writer->Fill();
28+
}
29+
}

0 commit comments

Comments
 (0)