Skip to content

Commit

Permalink
root compression algo as option
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Aug 18, 2024
1 parent 84d76d5 commit 38e20b8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ int main(int argc, char** argv) {
std::string input_file;
std::string output_file;
int verbose_level = -1;
std::string root_compression_algorithm = "LZMA";

CLI::App app{"mclient"};

Expand All @@ -152,7 +153,10 @@ int main(int argc, char** argv) {
->check(CLI::Range(0, 4));
app.add_flag("--read-only", readOnly, "Read-only mode")
->group("General");
// format option, defaults to "root", can be any value of "root", "aqs", "ascii" or multiple
app.add_flag("--share-buffer", shareBuffer, "Share buffer")->group("General");
app.add_option("--root-compression-algorithm", root_compression_algorithm, "Root compression algorithm (default: LZMA)")
->group("File Options")
->check(CLI::IsMember({"ZLIB", "LZMA", "LZ4"}));

CLI11_PARSE(app, argc, argv);

Expand All @@ -161,6 +165,8 @@ int main(int argc, char** argv) {
verbose = 1;
}

mclient_storage::StorageManager::Instance().compression_algorithm = root_compression_algorithm;

femarray.verbose = verbose;
cmdfetcher.verbose = verbose;

Expand Down
12 changes: 11 additions & 1 deletion src/root/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ void StorageManager::Initialize(const string& filename) {
}

file = std::make_unique<TFile>(filename.c_str(), "RECREATE");
file->SetCompressionAlgorithm(ROOT::kLZMA); // biggest compression ratio but slowest

if (compression_algorithm == "ZLIB") {
file->SetCompressionAlgorithm(ROOT::kZLIB); // good compression ratio and fast (old root default)
} else if (compression_algorithm == "LZ4") {
file->SetCompressionAlgorithm(ROOT::kLZ4); // good compression ratio and fast (new root default)
} else if (compression_algorithm == "LZMA") {
file->SetCompressionAlgorithm(ROOT::kLZMA); // biggest compression ratio but slowest
} else {
throw std::runtime_error("Unknown compression algorithm: " + compression_algorithm);
}

// file->SetCompressionLevel(9); // max compression level, but it's very slow, probably not worth it

cout << "ROOT file will be saved to " << file->GetName() << endl;
Expand Down
2 changes: 2 additions & 0 deletions src/root/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class StorageManager {
std::unique_ptr<TTree> run_tree;
Event event;

std::string compression_algorithm;

unsigned long long run_number = 0;
unsigned long long run_time_start = 0;

Expand Down

0 comments on commit 38e20b8

Please sign in to comment.