|
| 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 | +} |
0 commit comments