mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-24 04:17:58 +02:00
WIP
This commit is contained in:
22
src/CtbRawFile.cpp
Normal file
22
src/CtbRawFile.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "aare/CtbRawFile.hpp"
|
||||
|
||||
|
||||
|
||||
namespace aare{
|
||||
|
||||
CtbRawFile::CtbRawFile(const std::filesystem::path &fname){
|
||||
|
||||
if(!std::filesystem::exists(fname)){
|
||||
throw std::runtime_error(LOCATION + "File does not exist");
|
||||
}
|
||||
|
||||
m_fnc = parse_fname(fname);
|
||||
if(!m_fnc.valid){
|
||||
throw std::runtime_error(LOCATION + "Could not parse master file name");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace aare
|
@ -71,11 +71,11 @@ void RawFile::find_number_of_subfiles() {
|
||||
;
|
||||
n_subfiles = n_mod;
|
||||
}
|
||||
inline std::filesystem::path RawFile::data_fname(size_t mod_id, size_t file_id) {
|
||||
std::filesystem::path RawFile::data_fname(size_t mod_id, size_t file_id) {
|
||||
return this->m_base_path / fmt::format("{}_d{}_f{}_{}.raw", this->m_base_name, file_id, mod_id, this->m_findex);
|
||||
}
|
||||
|
||||
inline std::filesystem::path RawFile::master_fname() {
|
||||
std::filesystem::path RawFile::master_fname() {
|
||||
return this->m_base_path / fmt::format("{}_master_{}{}", this->m_base_name, this->m_findex, this->m_ext);
|
||||
}
|
||||
|
||||
|
33
src/file_utils.cpp
Normal file
33
src/file_utils.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "aare/file_utils.hpp"
|
||||
|
||||
namespace aare {
|
||||
|
||||
|
||||
|
||||
bool is_master_file(const std::filesystem::path &fpath) {
|
||||
std::string const stem = fpath.stem().string();
|
||||
return stem.find("_master_") != std::string::npos;
|
||||
}
|
||||
|
||||
FileNameComponents parse_fname(const std::filesystem::path &fname) {
|
||||
FileNameComponents fnc;
|
||||
fnc.base_path = fname.parent_path();
|
||||
fnc.base_name = fname.stem();
|
||||
fnc.ext = fname.extension();
|
||||
try {
|
||||
auto pos = fnc.base_name.rfind('_');
|
||||
fnc.findex = std::stoi(fnc.base_name.substr(pos + 1));
|
||||
} catch (const std::invalid_argument &e) {
|
||||
fnc.valid = false;
|
||||
}
|
||||
auto pos = fnc.base_name.find("_master_");
|
||||
if (pos != std::string::npos) {
|
||||
fnc.base_name.erase(pos);
|
||||
}else{
|
||||
fnc.valid = false;
|
||||
}
|
||||
fnc.valid = true;
|
||||
return fnc;
|
||||
}
|
||||
|
||||
} // namespace aare
|
20
src/file_utils.test.cpp
Normal file
20
src/file_utils.test.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "aare/file_utils.hpp"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
using namespace aare;
|
||||
|
||||
TEST_CASE("Use filename to determine if it is a master file") {
|
||||
|
||||
REQUIRE(is_master_file("test_master_1.json"));
|
||||
}
|
||||
|
||||
TEST_CASE("Parse a master file fname"){
|
||||
auto fnc = parse_fname("test_master_1.json");
|
||||
REQUIRE(fnc.base_name == "test");
|
||||
REQUIRE(fnc.ext == ".json");
|
||||
REQUIRE(fnc.findex == 1);
|
||||
|
||||
REQUIRE(fnc.master_fname() == "test_master_1.json");
|
||||
REQUIRE(fnc.data_fname(1, 2) == "test_d2_f1_1.raw");
|
||||
}
|
Reference in New Issue
Block a user