file reading

This commit is contained in:
Erik Fröjdh
2024-10-30 14:53:50 +01:00
parent be019b9769
commit f754e0f769
13 changed files with 84 additions and 114 deletions

View File

@ -12,7 +12,6 @@ namespace aare {
class File {
private:
FileInterface *file_impl;
bool is_npy;
public:
/**
@ -24,14 +23,16 @@ class File {
* @throws std::invalid_argument if the file mode is not supported
*
*/
File(const std::filesystem::path &fname, const std::string &mode, const FileConfig &cfg = {});
void write(Frame &frame, sls_detector_header header = {});
Frame read();
Frame iread(size_t frame_number);
std::vector<Frame> read(size_t n_frames);
File(const std::filesystem::path &fname, const std::string &mode="r", const FileConfig &cfg = {});
Frame read_frame(); //!< read one frame from the file at the current position
Frame read_frame(size_t frame_number); //!< read the frame at the position given by frame number
std::vector<Frame> read_n(size_t n_frames); //!< read n_frames from the file at the current position
void read_into(std::byte *image_buf);
void read_into(std::byte *image_buf, size_t n_frames);
size_t frame_number(size_t frame_index);
size_t frame_number(size_t frame_index); //!< get the frame number at the given frame index
size_t bytes_per_frame();
size_t pixels_per_frame();
void seek(size_t frame_number);
@ -43,17 +44,8 @@ class File {
size_t bytes_per_pixel() const;
void set_total_frames(size_t total_frames);
DetectorType detector_type() const;
xy geometry() const;
/**
* @brief Move constructor
* @param other File object to move from
*/
File(File &&other) noexcept;
/**
* @brief destructor: will only delete the FileInterface object
*/
~File();
};

View File

@ -47,32 +47,24 @@ struct FileConfig {
class FileInterface {
public:
/**
* @brief write a frame to the file
* @param frame frame to write
* @return void
* @throws std::runtime_error if the function is not implemented
*/
// virtual void write(Frame &frame) = 0;
/**
* @brief write a vector of frames to the file
* @param frames vector of frames to write
* @return void
*/
// virtual void write(std::vector<Frame> &frames) = 0;
/**
* @brief read one frame from the file at the current position
* @brief one frame from the file at the current position
* @return Frame
*/
virtual Frame read() = 0;
virtual Frame read_frame() = 0;
/**
* @brief read one frame from the file at the given frame number
* @param frame_number frame number to read
* @return frame
*/
virtual Frame read_frame(size_t frame_number) = 0;
/**
* @brief read n_frames from the file at the current position
* @param n_frames number of frames to read
* @return vector of frames
*/
virtual std::vector<Frame> read(size_t n_frames) = 0; // Is this the right interface?
virtual std::vector<Frame> read_n(size_t n_frames) = 0; // Is this the right interface?
/**
* @brief read one frame from the file at the current position and store it in the provided buffer
@ -142,32 +134,7 @@ class FileInterface {
*/
virtual size_t bitdepth() const = 0;
/**
* @brief read one frame from the file at the given frame number
* @param frame_number frame number to read
* @return frame
*/
Frame iread(size_t frame_number) {
auto old_pos = tell();
seek(frame_number);
Frame tmp = read();
seek(old_pos);
return tmp;
};
/**
* @brief read n_frames from the file starting at the given frame number
* @param frame_number frame number to start reading from
* @param n_frames number of frames to read
* @return vector of frames
*/
std::vector<Frame> iread(size_t frame_number, size_t n_frames) {
auto old_pos = tell();
seek(frame_number);
std::vector<Frame> tmp = read(n_frames);
seek(old_pos);
return tmp;
}
DetectorType detector_type() const { return m_type; }
// function to query the data type of the file
@ -175,8 +142,6 @@ class FileInterface {
virtual ~FileInterface() = default;
void set_total_frames(size_t total_frames) { m_total_frames = total_frames; }
protected:
std::string m_mode{};
std::filesystem::path m_fname{};

View File

@ -31,9 +31,10 @@ class NumpyFile : public FileInterface {
explicit NumpyFile(const std::filesystem::path &fname, const std::string &mode = "r", FileConfig cfg = {});
void write(Frame &frame);
Frame read() override { return get_frame(this->current_frame++); }
Frame read_frame() override { return get_frame(this->current_frame++); }
Frame read_frame(size_t frame_number) override { return get_frame(frame_number); }
std::vector<Frame> read(size_t n_frames) override;
std::vector<Frame> read_n(size_t n_frames) override;
void read_into(std::byte *image_buf) override { return get_frame_into(this->current_frame++, image_buf); }
void read_into(std::byte *image_buf, size_t n_frames) override;
size_t frame_number(size_t frame_index) override { return frame_index; };

View File

@ -39,8 +39,12 @@ class RawFile : public FileInterface {
* @param frame frame to write
*/
void write(Frame &frame, sls_detector_header header);
Frame read() override { return get_frame(this->current_frame++); };
std::vector<Frame> read(size_t n_frames) override;
Frame read_frame() override { return get_frame(this->current_frame++); };
Frame read_frame(size_t frame_number) override{
seek(frame_number);
return read_frame();
}
std::vector<Frame> read_n(size_t n_frames) override;
void read_into(std::byte *image_buf) override { return get_frame_into(this->current_frame++, image_buf); };
void read_into(std::byte *image_buf, size_t n_frames) override;
size_t frame_number(size_t frame_index) override;