mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-01 17:05:03 +01:00
fix file test issues
This commit is contained in:
@@ -10,7 +10,7 @@ File::File(std::filesystem::path fname, std::string mode) {
|
||||
}
|
||||
|
||||
Frame File::read() { return file_impl->read(); }
|
||||
size_t File::total_frames() const { return file_impl->m_total_frames; }
|
||||
size_t File::total_frames() const { return file_impl->total_frames(); }
|
||||
std::vector<Frame> File::read(size_t n_frames) { return file_impl->read(n_frames); }
|
||||
void File::read_into(std::byte *image_buf) { file_impl->read_into(image_buf); }
|
||||
void File::read_into(std::byte *image_buf, size_t n_frames) { file_impl->read_into(image_buf, n_frames); }
|
||||
|
||||
@@ -13,16 +13,16 @@ FileFactory *FileFactory::get_factory(std::filesystem::path fpath) {
|
||||
}
|
||||
|
||||
if (fpath.extension() == ".raw" || fpath.extension() == ".json"){
|
||||
aare::logger::info("Loading",fpath.extension(),"file");
|
||||
aare::logger::debug("Loading",fpath.extension(),"file");
|
||||
return new RawFileFactory(fpath);
|
||||
}
|
||||
if (fpath.extension() == ".raw" || fpath.extension() == ".json"){
|
||||
aare::logger::info("Loading",fpath.extension(),"file");
|
||||
aare::logger::debug("Loading",fpath.extension(),"file");
|
||||
return new RawFileFactory(fpath);
|
||||
}
|
||||
// check if extension is numpy
|
||||
else if (fpath.extension() == ".npy") {
|
||||
aare::logger::info("Loading numpy file");
|
||||
aare::logger::debug("Loading numpy file");
|
||||
return new NumpyFileFactory(fpath);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#include "aare/NumpyFileFactory.hpp"
|
||||
#include "aare/NumpyHelpers.hpp"
|
||||
NumpyFileFactory::NumpyFileFactory(std::filesystem::path fpath) {
|
||||
this->m_fpath = fpath;
|
||||
}
|
||||
NumpyFileFactory::NumpyFileFactory(std::filesystem::path fpath) { this->m_fpath = fpath; }
|
||||
void NumpyFileFactory::parse_metadata(FileInterface *_file) {
|
||||
auto file = dynamic_cast<NumpyFile*>(_file);
|
||||
auto file = dynamic_cast<NumpyFile *>(_file);
|
||||
// open ifsteam to file
|
||||
f = std::ifstream(file->m_fname, std::ios::binary);
|
||||
// check if file exists
|
||||
@@ -46,7 +44,7 @@ void NumpyFileFactory::parse_metadata(FileInterface *_file) {
|
||||
// parse header
|
||||
|
||||
std::vector<std::string> keys{"descr", "fortran_order", "shape"};
|
||||
std::cout << "original header: " << '"' << header << '"' << std::endl;
|
||||
aare::logger::debug("original header: \"header\"");
|
||||
|
||||
auto dict_map = parse_dict(header, keys);
|
||||
if (dict_map.size() == 0)
|
||||
@@ -72,11 +70,8 @@ void NumpyFileFactory::parse_metadata(FileInterface *_file) {
|
||||
file->header = {dtype, fortran_order, shape};
|
||||
}
|
||||
|
||||
NumpyFile* NumpyFileFactory::load_file() {
|
||||
NumpyFile* file = new NumpyFile(this->m_fpath);
|
||||
NumpyFile *NumpyFileFactory::load_file() {
|
||||
NumpyFile *file = new NumpyFile(this->m_fpath);
|
||||
parse_metadata(file);
|
||||
std::cout << "parsed header: " << file->header.to_string() << std::endl;
|
||||
return file;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -87,7 +87,6 @@ void RawFileFactory::parse_json_metadata(RawFile *file) {
|
||||
json j;
|
||||
ifs >> j;
|
||||
double v = j["Version"];
|
||||
std::cout << "Version: " << v << std::endl;
|
||||
file->version = fmt::format("{:.1f}", v);
|
||||
file->m_type = StringTo<DetectorType>(j["Detector Type"].get<std::string>());
|
||||
file->timing_mode = StringTo<TimingMode>(j["Timing Mode"].get<std::string>());
|
||||
|
||||
@@ -10,7 +10,8 @@ SubFile::SubFile(std::filesystem::path fname, DetectorType detector, ssize_t row
|
||||
this->m_bitdepth = bitdepth;
|
||||
this->n_frames = std::filesystem::file_size(fname) / (sizeof(sls_detector_header) + rows * cols * bitdepth / 8);
|
||||
if (read_impl_map.find({detector, bitdepth}) == read_impl_map.end()) {
|
||||
throw std::runtime_error(LOCATION + "Unsupported detector/bitdepth combination");
|
||||
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);
|
||||
}
|
||||
this->read_impl = read_impl_map.at({detector, bitdepth});
|
||||
}
|
||||
@@ -88,7 +89,7 @@ size_t SubFile::frame_number(int frame_index) {
|
||||
FILE *fp = fopen(this->m_fname.c_str(), "r");
|
||||
if (!fp)
|
||||
throw std::runtime_error(fmt::format("Could not open: {} for reading", m_fname.c_str()));
|
||||
|
||||
fseek(fp, (sizeof(sls_detector_header) + bytes_per_part()) * frame_index, SEEK_SET);
|
||||
size_t rc = fread(reinterpret_cast<char *>(&h), sizeof(h), 1, fp);
|
||||
fclose(fp);
|
||||
if (rc != 1)
|
||||
|
||||
Reference in New Issue
Block a user