AARE
Data analysis library for PSI hybrid detectors
Loading...
Searching...
No Matches
FileInterface.hpp
Go to the documentation of this file.
1#pragma once
2#include "aare/core/DType.hpp"
3#include "aare/core/Frame.hpp"
4#include "aare/core/defs.hpp"
5#include <filesystem>
6#include <vector>
7
8namespace aare {
9
17struct FileConfig {
18 aare::DType dtype = aare::DType(typeid(uint16_t));
19 uint64_t rows;
20 uint64_t cols;
21 xy geometry{1, 1};
22 bool operator==(const FileConfig &other) const {
23 return dtype == other.dtype && rows == other.rows && cols == other.cols && geometry == other.geometry;
24 }
25 bool operator!=(const FileConfig &other) const { return !(*this == other); }
26};
27
34 public:
41 virtual void write(Frame &frame) = 0;
42
48 // virtual void write(std::vector<Frame> &frames) = 0;
49
54 virtual Frame read() = 0;
55
61 virtual std::vector<Frame> read(size_t n_frames) = 0; // Is this the right interface?
62
68 virtual void read_into(std::byte *image_buf) = 0;
69
76 virtual void read_into(std::byte *image_buf, size_t n_frames) = 0;
77
83 virtual size_t frame_number(size_t frame_index) = 0;
84
89 virtual size_t bytes_per_frame() = 0;
90
95 virtual size_t pixels() = 0;
96
102 virtual void seek(size_t frame_number) = 0;
103
108 virtual size_t tell() = 0;
109
114 virtual size_t total_frames() const = 0;
119 virtual ssize_t rows() const = 0;
124 virtual ssize_t cols() const = 0;
129 virtual ssize_t bitdepth() const = 0;
130
137 auto old_pos = tell();
139 Frame tmp = read();
140 seek(old_pos);
141 return tmp;
142 };
143
150 std::vector<Frame> iread(size_t frame_number, size_t n_frames) {
151 auto old_pos = tell();
153 std::vector<Frame> tmp = read(n_frames);
154 seek(old_pos);
155 return tmp;
156 }
157
158 // function to query the data type of the file
159 /*virtual DataType dtype = 0; */
160
161 virtual ~FileInterface(){
162
163 };
164
165 public:
166 std::string m_mode;
167 std::filesystem::path m_fname;
168 std::filesystem::path m_base_path;
169 std::string m_base_name, m_ext;
173 std::string version;
175 ssize_t m_rows{};
176 ssize_t m_cols{};
177 ssize_t m_bitdepth{};
179};
180
181} // namespace aare
Definition DType.hpp:20
FileInterface class to define the interface for file operations.
Definition FileInterface.hpp:33
virtual std::vector< Frame > read(size_t n_frames)=0
read n_frames from the file at the current position
std::vector< Frame > iread(size_t frame_number, size_t n_frames)
read n_frames from the file starting at the given frame number
Definition FileInterface.hpp:150
ssize_t m_bitdepth
Definition FileInterface.hpp:177
virtual ssize_t cols() const =0
get the number of columns in the file
int m_findex
Definition FileInterface.hpp:170
std::filesystem::path m_fname
Definition FileInterface.hpp:167
std::string version
Definition FileInterface.hpp:173
virtual void seek(size_t frame_number)=0
seek to the given frame number
virtual void read_into(std::byte *image_buf)=0
read one frame from the file at the current position and store it in the provided buffer
virtual void read_into(std::byte *image_buf, size_t n_frames)=0
read n_frames from the file at the current position and store them in the provided buffer
virtual void write(Frame &frame)=0
write a frame to the file
std::string m_ext
Definition FileInterface.hpp:169
virtual ~FileInterface()
Definition FileInterface.hpp:161
virtual ssize_t rows() const =0
get the number of rows in the file
virtual ssize_t bitdepth() const =0
get the bitdepth of the file
size_t m_total_frames
Definition FileInterface.hpp:171
DetectorType m_type
Definition FileInterface.hpp:174
virtual size_t pixels()=0
get the number of pixels in one frame
virtual Frame read()=0
write a vector of frames to the file
virtual size_t bytes_per_frame()=0
get the size of one frame in bytes
Frame iread(size_t frame_number)
read one frame from the file at the given frame number
Definition FileInterface.hpp:136
size_t max_frames_per_file
Definition FileInterface.hpp:172
std::string m_mode
Definition FileInterface.hpp:166
size_t current_frame
Definition FileInterface.hpp:178
virtual size_t tell()=0
get the current position of the file pointer
virtual size_t frame_number(size_t frame_index)=0
get the frame number at the given frame index
virtual size_t total_frames() const =0
get the total number of frames in the file
ssize_t m_cols
Definition FileInterface.hpp:176
std::string m_base_name
Definition FileInterface.hpp:169
ssize_t m_rows
Definition FileInterface.hpp:175
std::filesystem::path m_base_path
Definition FileInterface.hpp:168
Definition Frame.hpp:18
Frame class to represent a single frame of data model class should be able to work with streams comin...
Definition CircularFifo.hpp:11
DetectorType
Definition defs.hpp:41
FileConfig structure to store the configuration of a file dtype: data type of the file rows: number o...
Definition FileInterface.hpp:17
uint64_t cols
Definition FileInterface.hpp:20
xy geometry
Definition FileInterface.hpp:21
aare::DType dtype
Definition FileInterface.hpp:18
uint64_t rows
Definition FileInterface.hpp:19
bool operator!=(const FileConfig &other) const
Definition FileInterface.hpp:25
bool operator==(const FileConfig &other) const
Definition FileInterface.hpp:22
Definition defs.hpp:31