add documentation for file_io files

This commit is contained in:
Bechir Braham
2024-04-10 18:08:54 +02:00
parent 530feca830
commit 111b421476
15 changed files with 354 additions and 198 deletions

View File

@@ -7,6 +7,9 @@
namespace aare {
File::File(std::filesystem::path fname, std::string mode, FileConfig cfg) {
if (mode != "r" && mode != "w" && mode != "a") {
throw std::invalid_argument("Unsupported file mode");
}
if ((mode == "r" or mode == "a") and not std::filesystem::exists(fname)) {
throw std::runtime_error(fmt::format("File does not exist: {}", fname.c_str()));

View File

@@ -15,7 +15,6 @@ RawFile::RawFile(const std::filesystem::path &fname, const std::string &mode, co
aare::logger::warn(
"In read mode it is not necessary to provide a config, the provided config will be ignored");
}
aare::logger::debug("XXXXXXXXLoading raw file");
parse_fname();
parse_metadata();
find_number_of_subfiles();
@@ -49,6 +48,27 @@ sls_detector_header RawFile::read_header(const std::filesystem::path &fname) {
throw std::runtime_error("Could not read header from file");
return h;
}
bool RawFile::is_master_file(std::filesystem::path fpath) {
std::string stem = fpath.stem();
if (stem.find("_master_") != std::string::npos)
return true;
else
return false;
}
void RawFile::find_number_of_subfiles() {
int n_mod = 0;
while (std::filesystem::exists(data_fname(++n_mod, 0)))
;
n_subfiles = n_mod;
}
inline std::filesystem::path RawFile::data_fname(int mod_id, int 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() {
return this->m_base_path / fmt::format("{}_master_{}{}", this->m_base_name, this->m_findex, this->m_ext);
}
void RawFile::find_geometry() {
uint16_t r{};
@@ -163,7 +183,6 @@ void RawFile::parse_fname() {
m_base_path = m_fname.parent_path();
m_base_name = m_fname.stem();
m_ext = m_fname.extension();
aare::logger::debug("EXTEXT", m_ext);
auto pos = m_base_name.rfind("_");
m_findex = std::stoi(m_base_name.substr(pos + 1));
pos = m_base_name.find("_master_");

View File

@@ -1,32 +0,0 @@
#include "aare/file_io/RawFileFactory.hpp"
#include "aare/core/defs.hpp"
#include "aare/file_io/RawFile.hpp"
#include "aare/file_io/SubFile.hpp"
#include "aare/file_io/helpers.hpp"
#include "aare/utils/logger.hpp"
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace aare::RawFileHelpers {
} // namespace aare

View File

@@ -16,7 +16,7 @@ SubFile::SubFile(std::filesystem::path fname, DetectorType detector, ssize_t row
if (read_impl_map.find({detector, bitdepth}) == read_impl_map.end()) {
auto error_msg = LOCATION + "No read_impl function found for detector: " + toString(detector) +
" and bitdepth: " + std::to_string(bitdepth);
throw std::runtime_error(error_msg);
throw std::invalid_argument(error_msg);
}
this->read_impl = read_impl_map.at({detector, bitdepth});
}

View File

@@ -1,13 +0,0 @@
#include "aare/file_io/helpers.hpp"
namespace aare {
bool is_master_file(std::filesystem::path fpath) {
std::string stem = fpath.stem();
if (stem.find("_master_") != std::string::npos)
return true;
else
return false;
}
} // namespace aare