Skip to content

Commit 9cbca08

Browse files
committed
Add tests for compression blocks
1 parent 5cbecd8 commit 9cbca08

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

compression/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 `Int64` field with type `std
55
The entries have ascending values and the reference `.json` files only contain the sum of all elements.
66

77
* [`algorithms`](algorithms): `zlib`, `lzma`, `lz4`, `zstd`
8+
* [`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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <ROOT/RNTupleModel.hxx>
2+
#include <ROOT/RNTupleUtil.hxx>
3+
#include <ROOT/RNTupleWriteOptions.hxx>
4+
#include <ROOT/RNTupleWriter.hxx>
5+
6+
using ROOT::Experimental::EColumnType;
7+
using ROOT::Experimental::RNTupleModel;
8+
using ROOT::Experimental::RNTupleWriteOptions;
9+
using ROOT::Experimental::RNTupleWriter;
10+
11+
#include <cstdint>
12+
#include <memory>
13+
#include <string_view>
14+
15+
void write(std::string_view filename = "compression.block.big.root") {
16+
auto model = RNTupleModel::Create();
17+
18+
auto Int64 = model->MakeField<std::int64_t>("Int64");
19+
model->GetMutableField("Int64").SetColumnRepresentatives(
20+
{{EColumnType::kSplitInt64}});
21+
22+
RNTupleWriteOptions options;
23+
// Crank up the zstd compression level to reduce the output file size by
24+
// approximately a factor 6 (from 76K with 505 to 12K).
25+
options.SetCompression(509);
26+
// Increase the maximum unzipped page size to make it bigger than the maximum
27+
// size of a compression block, which is 16 MiB.
28+
options.SetMaxUnzippedPageSize(128 * 1024 * 1024);
29+
auto writer =
30+
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
31+
32+
// Write 40 MiB of entries that will be split into three compression blocks.
33+
static constexpr int Entries = 40 * 1024 * 1024 / sizeof(std::int64_t);
34+
for (int i = 0; i < Entries; i++) {
35+
*Int64 = i;
36+
writer->Fill();
37+
}
38+
}

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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <ROOT/RNTupleModel.hxx>
2+
#include <ROOT/RNTupleUtil.hxx>
3+
#include <ROOT/RNTupleWriteOptions.hxx>
4+
#include <ROOT/RNTupleWriter.hxx>
5+
6+
using ROOT::Experimental::EColumnType;
7+
using ROOT::Experimental::RNTupleModel;
8+
using ROOT::Experimental::RNTupleWriteOptions;
9+
using ROOT::Experimental::RNTupleWriter;
10+
11+
#include <cstdint>
12+
#include <memory>
13+
#include <string_view>
14+
15+
void write(std::string_view filename = "compression.block.short.root") {
16+
auto model = RNTupleModel::Create();
17+
18+
auto Int64 = model->MakeField<std::int64_t>("Int64");
19+
model->GetMutableField("Int64").SetColumnRepresentatives(
20+
{{EColumnType::kSplitInt64}});
21+
22+
RNTupleWriteOptions options;
23+
options.SetCompression(505);
24+
auto writer =
25+
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
26+
27+
// Write only 2 entries to make sure the compression block is small and
28+
// actually stored uncompressed.
29+
for (int i = 0; i < 2; i++) {
30+
*Int64 = i;
31+
writer->Fill();
32+
}
33+
}

0 commit comments

Comments
 (0)