diff --git a/include/chopper/sketch/toolbox.hpp b/include/chopper/sketch/toolbox.hpp index 9136bd5e..365befad 100644 --- a/include/chopper/sketch/toolbox.hpp +++ b/include/chopper/sketch/toolbox.hpp @@ -9,6 +9,7 @@ #include #include +#include "execute.hpp" namespace chopper::sketch { @@ -106,11 +107,21 @@ class toolbox std::sort(positions.begin(), positions.end(), cardinality_compare); } + + static void read_hll_files_into(std::filesystem::path const & hll_dir, + std::vector const & target_filenames, + std::vector & target) + { + chopper::configuration config; // Create default configuration + read_hll_files_into(hll_dir, target_filenames, target, config); + } + /*!\brief Restore the HLL sketches from the files in hll_dir and target_filenames into target container. */ static void read_hll_files_into(std::filesystem::path const & hll_dir, std::vector const & target_filenames, - std::vector & target) + std::vector & target, + chopper::configuration & config) { assert(std::filesystem::exists(hll_dir) && !std::filesystem::is_empty(hll_dir)); // checked in chopper_layout @@ -120,18 +131,21 @@ class toolbox { for (auto const & filename : target_filenames) { - if (std::filesystem::path(filename).extension() != ".empty_bin") - { //Myrthe + if (std::filesystem::path(filename).extension() != ".empty_bin") { //Myrthe std::filesystem::path path = hll_dir / std::filesystem::path(filename).stem(); path += ".hll"; std::ifstream hll_fin(path, std::ios::binary); + try { + if (!hll_fin.good()) + throw std::runtime_error{"Could not open file " + path.string()}; - if (!hll_fin.good()) - throw std::runtime_error{"Could not open file " + path.string()}; - - // the sketch bits will be automatically read from the files - target.emplace_back().restore(hll_fin); + target.emplace_back().restore(hll_fin); // the sketch bits will be automatically read from the files + } + catch (std::runtime_error const & ) { + auto filename_input = std::vector {filename}; + chopper::sketch::execute(config, filename_input, target); + } } } }