From 8be4c4db3f3a77fb9638680e34298ad9beada87c Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 21 Apr 2020 20:12:34 +0200 Subject: [PATCH] Add get path suffixes method to BufferUtils --- core-buffer/include/BufferUtils.hpp | 11 ++++++++++ core-buffer/src/BufferUtils.cpp | 31 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/core-buffer/include/BufferUtils.hpp b/core-buffer/include/BufferUtils.hpp index aa1ef2b..455da6b 100644 --- a/core-buffer/include/BufferUtils.hpp +++ b/core-buffer/include/BufferUtils.hpp @@ -2,6 +2,7 @@ #define BUFFER_UTILS_HPP #include +#include namespace BufferUtils { @@ -21,6 +22,16 @@ namespace BufferUtils const std::string& filename_to_write); std::string get_latest_file(const std::string& latest_filename); + + struct path_sufix { + uint64_t start_pulse_id; + uint64_t stop_pulse_id; + std::string path; + }; + + std::vector BufferUtils::get_path_suffixes( + const uint64_t start_pulse_id, + const uint64_t stop_pulse_id); } #endif //BUFFER_UTILS_HPP diff --git a/core-buffer/src/BufferUtils.cpp b/core-buffer/src/BufferUtils.cpp index 679abd4..ccfa5be 100644 --- a/core-buffer/src/BufferUtils.cpp +++ b/core-buffer/src/BufferUtils.cpp @@ -64,3 +64,34 @@ string BufferUtils::get_latest_file(const string& latest_filename) return filename.substr(0, filename.size()-1); } + +vector BufferUtils::get_path_suffixes ( + const uint64_t start_pulse_id, + const uint64_t stop_pulse_id) +{ + vector result; + + uint64_t start_file_base = start_pulse_id / FILE_MOD; + start_file_base *= FILE_MOD; + + for ( + uint64_t first_pulse_id=start_file_base; + first_pulse_id <= stop_pulse_id; + first_pulse_id += FILE_MOD) { + + uint64_t folder_base = first_pulse_id / FOLDER_MOD; + folder_base *= FOLDER_MOD; + + uint64_t file_base = first_pulse_id / FILE_MOD; + file_base *= FILE_MOD; + + stringstream folder; + folder << folder_base << "/"; + folder << file_base << FILE_EXTENSION; + + result.emplace_back( + {first_pulse_id, + first_pulse_id+FILE_MOD+1, + folder.str()}); + } +} \ No newline at end of file