mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-06 12:50:40 +02:00
moving m_fname into respective class
This commit is contained in:
parent
e534cc0f25
commit
9854500a6f
@ -9,7 +9,7 @@ public:
|
||||
// - w writing (overwrites existing file)
|
||||
// - a appending (appends to existing file)
|
||||
// TODO! do we need to support w+, r+ and a+?
|
||||
FileInterface(std::filesystem::path& fname, const char* opts="r" ){};
|
||||
FileInterface(const std::filesystem::path& fname, const char* opts="r" ){};
|
||||
|
||||
// write one frame
|
||||
virtual void write(Frame& frame) = 0;
|
||||
|
@ -83,7 +83,7 @@ class FileInterface {
|
||||
|
||||
public:
|
||||
std::string mode;
|
||||
std::filesystem::path m_fname;
|
||||
// std::filesystem::path m_fname;
|
||||
std::filesystem::path m_base_path;
|
||||
std::string m_base_name, m_ext;
|
||||
int m_findex;
|
||||
|
@ -4,15 +4,21 @@
|
||||
#include "aare/defs.hpp"
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <filesystem>
|
||||
|
||||
namespace aare{
|
||||
|
||||
class NumpyFile : public FileInterface {
|
||||
FILE *fp = nullptr;
|
||||
size_t initial_header_len = 0;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
std::filesystem::path m_fname; //TO be made private!
|
||||
|
||||
NumpyFile(const std::filesystem::path& fname);
|
||||
NumpyFile(FileConfig, header_t);
|
||||
void write(Frame &frame) override;
|
||||
Frame read() override { return get_frame(this->current_frame++); }
|
||||
|
||||
@ -29,8 +35,6 @@ class NumpyFile : public FileInterface {
|
||||
ssize_t cols() const override { return header.shape[2]; }
|
||||
ssize_t bitdepth() const override { return header.dtype.bitdepth(); }
|
||||
|
||||
NumpyFile(std::filesystem::path fname);
|
||||
NumpyFile(FileConfig, header_t);
|
||||
header_t header;
|
||||
uint8_t major_ver_{};
|
||||
uint8_t minor_ver_{};
|
||||
|
@ -9,8 +9,10 @@ namespace aare {
|
||||
class RawFile : public FileInterface {
|
||||
|
||||
using config = RawFileConfig;
|
||||
|
||||
|
||||
public:
|
||||
std::filesystem::path m_fname; //TO be made private!
|
||||
void write(Frame &frame) override{};
|
||||
Frame read() override { return get_frame(this->current_frame++); };
|
||||
std::vector<Frame> read(size_t n_frames) override;
|
||||
|
@ -3,19 +3,8 @@
|
||||
|
||||
namespace aare{
|
||||
|
||||
void NumpyFile::write(Frame &frame) {
|
||||
if (fp == nullptr) {
|
||||
throw std::runtime_error("File not open");
|
||||
}
|
||||
if (not(mode == "w" or mode == "a")) {
|
||||
throw std::runtime_error("File not open for writing");
|
||||
}
|
||||
fseek(fp, 0, SEEK_END);
|
||||
fwrite(frame._get_data(), frame.size(), 1, fp);
|
||||
}
|
||||
|
||||
NumpyFile::NumpyFile(std::filesystem::path fname_) {
|
||||
this->m_fname = fname_;
|
||||
NumpyFile::NumpyFile(const std::filesystem::path& fname) {
|
||||
this->m_fname = fname;
|
||||
fp = fopen(this->m_fname.c_str(), "rb");
|
||||
}
|
||||
NumpyFile::NumpyFile(FileConfig config, header_t header) {
|
||||
@ -36,6 +25,19 @@ NumpyFile::NumpyFile(FileConfig config, header_t header) {
|
||||
aare::NumpyHelpers::write_header(std::filesystem::path(this->m_fname.c_str()), this->header);
|
||||
}
|
||||
|
||||
void NumpyFile::write(Frame &frame) {
|
||||
if (fp == nullptr) {
|
||||
throw std::runtime_error("File not open");
|
||||
}
|
||||
if (not(mode == "w" or mode == "a")) {
|
||||
throw std::runtime_error("File not open for writing");
|
||||
}
|
||||
fseek(fp, 0, SEEK_END);
|
||||
fwrite(frame._get_data(), frame.size(), 1, fp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Frame NumpyFile::get_frame(size_t frame_number) {
|
||||
Frame frame(header.shape[1], header.shape[2], header.dtype.bitdepth());
|
||||
get_frame_into(frame_number, frame._get_data());
|
||||
|
Loading…
x
Reference in New Issue
Block a user