AARE
Data analysis library for PSI hybrid detectors
Loading...
Searching...
No Matches
RawFile.hpp
Go to the documentation of this file.
1#pragma once
2#include "aare/core/Frame.hpp"
5
6namespace aare {
7
13class RawFile : public FileInterface {
14 public:
21 RawFile(const std::filesystem::path &fname, const std::string &mode = "r", const FileConfig &cfg = {});
22
27 void write(Frame &frame) override { throw std::runtime_error("Not implemented"); };
28 Frame read() override { return get_frame(this->current_frame++); };
29 std::vector<Frame> read(size_t n_frames) override;
30 void read_into(std::byte *image_buf) override { return get_frame_into(this->current_frame++, image_buf); };
31 void read_into(std::byte *image_buf, size_t n_frames) override;
32 size_t frame_number(size_t frame_index) override;
33
38 size_t bytes_per_frame() override { return m_rows * m_cols * m_bitdepth / 8; }
39
44 size_t pixels() override { return m_rows * m_cols; }
45
46 // goto frame number
47 void seek(size_t frame_number) override { this->current_frame = frame_number; };
48
49 // return the position of the file pointer (in number of frames)
50 size_t tell() override { return this->current_frame; };
51
56 static bool is_master_file(std::filesystem::path fpath);
57
63 inline void set_config(int row, int col) {
64 cfg.module_gap_row = row;
65 cfg.module_gap_col = col;
66 }
67 // TODO! Deal with fast quad and missing files
68
74
79 inline std::filesystem::path master_fname();
86 inline std::filesystem::path data_fname(int mod_id, int file_id);
87
91 ~RawFile();
92
93 size_t total_frames() const override { return m_total_frames; }
94 ssize_t rows() const override { return m_rows; }
95 ssize_t cols() const override { return m_cols; }
96 ssize_t bitdepth() const override { return m_bitdepth; }
97
98 private:
104 void get_frame_into(size_t frame_number, std::byte *image_buf);
105
112
116 void parse_fname();
117
121 void parse_metadata();
122
126 void parse_raw_metadata();
127
131 void parse_json_metadata();
132
136 void find_geometry();
137
143 sls_detector_header read_header(const std::filesystem::path &fname);
144
148 void open_subfiles();
149
152 std::vector<std::vector<SubFile *>> subfiles;
155 std::vector<xy> positions;
158 bool quad{false};
159};
160
161} // namespace aare
FileInterface class to define the interface for file operations.
Definition FileInterface.hpp:33
ssize_t m_bitdepth
Definition FileInterface.hpp:177
size_t m_total_frames
Definition FileInterface.hpp:171
size_t current_frame
Definition FileInterface.hpp:178
ssize_t m_cols
Definition FileInterface.hpp:176
ssize_t m_rows
Definition FileInterface.hpp:175
Definition Frame.hpp:18
RawFile class to read .raw and .json files.
Definition RawFile.hpp:13
void parse_metadata()
parse the metadata from the file
Definition RawFile.cpp:95
std::vector< std::vector< SubFile * > > subfiles
Definition RawFile.hpp:152
TimingMode timing_mode
Definition RawFile.hpp:157
std::filesystem::path data_fname(int mod_id, int file_id)
get the data file name path for the RawFile with the given module id and file id
Definition RawFile.cpp:65
size_t frame_number(size_t frame_index) override
get the frame number at the given frame index
Definition RawFile.cpp:251
ssize_t rows() const override
get the number of rows in the file
Definition RawFile.hpp:94
void parse_fname()
parse the file name to get the extension, base name and index
Definition RawFile.cpp:182
void seek(size_t frame_number) override
seek to the given frame number
Definition RawFile.hpp:47
RawFileConfig cfg
Definition RawFile.hpp:156
void open_subfiles()
open the subfiles
Definition RawFile.cpp:29
Frame get_frame(size_t frame_number)
get the frame at the given frame number
Definition RawFile.cpp:192
sls_detector_header read_header(const std::filesystem::path &fname)
read the header of the file
Definition RawFile.cpp:39
size_t total_frames() const override
get the total number of frames in the file
Definition RawFile.hpp:93
ssize_t cols() const override
get the number of columns in the file
Definition RawFile.hpp:95
std::vector< xy > positions
Definition RawFile.hpp:155
xy geometry
Definition RawFile.hpp:154
size_t tell() override
get the current position of the file pointer
Definition RawFile.hpp:50
static bool is_master_file(std::filesystem::path fpath)
check if the file is a master file
Definition RawFile.cpp:51
int subfile_rows
Definition RawFile.hpp:153
~RawFile()
destructor: will delete the subfiles
Definition RawFile.cpp:259
size_t pixels() override
get the number of pixels in the frame
Definition RawFile.hpp:44
size_t n_subfile_parts
Definition RawFile.hpp:151
size_t bytes_per_frame() override
get the number of bytess per frame
Definition RawFile.hpp:38
void get_frame_into(size_t frame_number, std::byte *image_buf)
read the frame at the given frame number into the image buffer
Definition RawFile.cpp:199
void find_geometry()
finds the geometry of the file
Definition RawFile.cpp:73
size_t n_subfiles
Definition RawFile.hpp:150
bool quad
Definition RawFile.hpp:158
std::filesystem::path master_fname()
get the master file name path for the RawFile
Definition RawFile.cpp:69
void parse_raw_metadata()
parse the metadata of a .raw file
Definition RawFile.cpp:139
void find_number_of_subfiles()
get the number of subfiles for the RawFile
Definition RawFile.cpp:59
int subfile_cols
Definition RawFile.hpp:153
ssize_t bitdepth() const override
get the bitdepth of the file
Definition RawFile.hpp:96
void parse_json_metadata()
parse the metadata of a .json file
Definition RawFile.cpp:115
void write(Frame &frame) override
write function is not implemented for RawFile
Definition RawFile.hpp:27
void set_config(int row, int col)
set the module gap row and column
Definition RawFile.hpp:63
void read_into(std::byte *image_buf) override
read one frame from the file at the current position and store it in the provided buffer
Definition RawFile.hpp:30
Frame read() override
write a vector of frames to the file
Definition RawFile.hpp:28
Frame class to represent a single frame of data model class should be able to work with streams comin...
Definition CircularFifo.hpp:11
TimingMode
Definition defs.hpp:43
FileConfig structure to store the configuration of a file dtype: data type of the file rows: number o...
Definition FileInterface.hpp:17
Definition defs.hpp:56
int module_gap_col
Definition defs.hpp:58
int module_gap_row
Definition defs.hpp:57
Definition defs.hpp:14
Definition defs.hpp:31