mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-18 18:27:13 +02:00
new folder structure
This commit is contained in:
80
file_io/include/aare/File.hpp
Normal file
80
file_io/include/aare/File.hpp
Normal file
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "aare/defs.hpp"
|
||||
#include "aare/Frame.hpp"
|
||||
#include "SubFile.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fmt/core.h>
|
||||
#include <iostream>
|
||||
|
||||
struct RawFileConfig {
|
||||
int module_gap_row{};
|
||||
int module_gap_col{};
|
||||
|
||||
bool operator==(const RawFileConfig &other) const {
|
||||
if (module_gap_col != other.module_gap_col)
|
||||
return false;
|
||||
if (module_gap_row != other.module_gap_row)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
template <DetectorType detector, typename DataType>
|
||||
class File {
|
||||
|
||||
public:
|
||||
virtual Frame<DataType>* get_frame(int frame_number) = 0;
|
||||
|
||||
private:
|
||||
using config = RawFileConfig;
|
||||
|
||||
public:
|
||||
std::vector<SubFile*> subfiles;
|
||||
std::filesystem::path fname;
|
||||
std::filesystem::path base_path;
|
||||
std::string base_name, ext;
|
||||
int findex, n_subfiles;
|
||||
size_t total_frames{};
|
||||
size_t max_frames_per_file{};
|
||||
|
||||
std::string version;
|
||||
DetectorType type;
|
||||
TimingMode timing_mode;
|
||||
int subfile_rows, subfile_cols;
|
||||
bool quad{false};
|
||||
|
||||
ssize_t rows{};
|
||||
ssize_t cols{};
|
||||
uint8_t bitdepth{};
|
||||
using data_type = uint16_t;
|
||||
std::vector<xy> positions;
|
||||
|
||||
config cfg{0, 0};
|
||||
// File();
|
||||
~File();
|
||||
|
||||
inline size_t bytes_per_frame() const { return rows * cols * bitdepth / 8; }
|
||||
inline size_t pixels() const { return rows * cols; }
|
||||
inline void set_config(int row, int col) {
|
||||
cfg.module_gap_row = row;
|
||||
cfg.module_gap_col = col;
|
||||
}
|
||||
|
||||
// TODO! Deal with fast quad and missing files
|
||||
void find_number_of_subfiles() {
|
||||
int n_mod = 0;
|
||||
while (std::filesystem::exists(data_fname(++n_mod, 0)))
|
||||
;
|
||||
n_subfiles = n_mod;
|
||||
}
|
||||
|
||||
inline std::filesystem::path master_fname() {
|
||||
return base_path / fmt::format("{}_master_{}{}", base_name, findex, ext);
|
||||
}
|
||||
inline std::filesystem::path data_fname(int mod_id, int file_id) {
|
||||
return base_path / fmt::format("{}_d{}_f{}_{}.raw", base_name, file_id, mod_id, findex);
|
||||
}
|
||||
|
||||
// size_t total_frames();
|
||||
};
|
26
file_io/include/aare/FileFactory.hpp
Normal file
26
file_io/include/aare/FileFactory.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include "aare/File.hpp"
|
||||
|
||||
template <DetectorType detector,typename DataType>
|
||||
class FileFactory{
|
||||
// Class that will be used to create File objects
|
||||
// follows the factory pattern
|
||||
protected:
|
||||
std::filesystem::path fpath;
|
||||
public:
|
||||
static FileFactory<detector,DataType>* get_factory(std::filesystem::path);
|
||||
// virtual int deleteFile() = 0;
|
||||
virtual File<detector,DataType>* load_file()=0;//TODO: add option to load all file to memory or keep it on disk
|
||||
virtual void parse_metadata(File<detector,DataType>*)=0;
|
||||
|
||||
|
||||
void find_geometry(File<detector,DataType>*);
|
||||
void parse_fname(File<detector,DataType>*);
|
||||
|
||||
sls_detector_header read_header(const std::filesystem::path &fname);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
29
file_io/include/aare/FileHandler.hpp
Normal file
29
file_io/include/aare/FileHandler.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <filesystem>
|
||||
#include "aare/FileFactory.hpp"
|
||||
#include "aare/File.hpp"
|
||||
|
||||
template <DetectorType detector,typename DataType>
|
||||
class FileHandler{
|
||||
private:
|
||||
std::filesystem::path fpath;
|
||||
FileFactory<detector,DataType>* fileFactory;
|
||||
File<detector,DataType>* f;
|
||||
|
||||
public:
|
||||
FileHandler<detector,DataType>(std::filesystem::path fpath){
|
||||
this->fpath = fpath;
|
||||
this->fileFactory= FileFactory<detector,DataType>::get_factory(fpath);
|
||||
this->f= fileFactory->load_file();
|
||||
delete fileFactory;
|
||||
}
|
||||
|
||||
Frame<DataType>* get_frame(int index){
|
||||
return f->get_frame(index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
~FileHandler(){
|
||||
delete f;
|
||||
}
|
||||
};
|
9
file_io/include/aare/JsonFile.hpp
Normal file
9
file_io/include/aare/JsonFile.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "aare/File.hpp"
|
||||
#include "aare/Frame.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
template <DetectorType detector, typename DataType>
|
||||
class JsonFile : public File<detector, DataType> {
|
||||
|
||||
Frame<DataType> *get_frame(int frame_number);
|
||||
};
|
16
file_io/include/aare/JsonFileFactory.hpp
Normal file
16
file_io/include/aare/JsonFileFactory.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "aare/FileFactory.hpp"
|
||||
template <DetectorType detector,typename DataType>
|
||||
class JsonFileFactory: public FileFactory<detector,DataType>
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
File<detector,DataType>* load_file() override;
|
||||
void parse_metadata(File<detector,DataType>*) override;
|
||||
JsonFileFactory<detector,DataType>(std::filesystem::path fpath);
|
||||
void open_subfiles(File<detector,DataType>*);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
9
file_io/include/aare/RawFileFactory.hpp
Normal file
9
file_io/include/aare/RawFileFactory.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "aare/File.hpp"
|
||||
#include <filesystem>
|
||||
template<DetectorType detector,typename DataType>
|
||||
class RawFileFactory{
|
||||
public:
|
||||
// RawFileFactory();
|
||||
// ~RawFileFactory();
|
||||
File<detector,DataType> loadFile(std::filesystem::path fpath);
|
||||
};
|
32
file_io/include/aare/SubFile.hpp
Normal file
32
file_io/include/aare/SubFile.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "aare/defs.hpp"
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <variant>
|
||||
|
||||
class SubFile {
|
||||
protected:
|
||||
FILE *fp = nullptr;
|
||||
uint16_t bitdepth;
|
||||
|
||||
public:
|
||||
// pointer to a read_impl function. pointer will be set to the appropriate read_impl function in the constructor
|
||||
size_t (SubFile::*read_impl)(std::byte *buffer) = nullptr;
|
||||
size_t read_impl_normal(std::byte *buffer);
|
||||
template <typename DataType> size_t read_impl_flip(std::byte *buffer);
|
||||
template <typename DataType> size_t read_impl_reorder(std::byte *buffer);
|
||||
|
||||
|
||||
SubFile(std::filesystem::path fname,DetectorType detector, ssize_t rows, ssize_t cols, uint16_t bitdepth);
|
||||
|
||||
size_t get_frame(std::byte *buffer, int frame_number);
|
||||
|
||||
// TODO: define the inlines as variables and assign them in constructor
|
||||
inline size_t bytes_per_frame() { return (bitdepth / 8) * rows * cols; }
|
||||
inline size_t pixels_per_frame() { return rows * cols; }
|
||||
std::filesystem::path fname;
|
||||
ssize_t rows{};
|
||||
ssize_t cols{};
|
||||
ssize_t n_frames{};
|
||||
int sub_file_index_{};
|
||||
};
|
8
file_io/include/aare/helpers.hpp
Normal file
8
file_io/include/aare/helpers.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "aare/File.hpp"
|
||||
#include <filesystem>
|
||||
#include <fmt/core.h>
|
||||
|
||||
bool is_master_file(std::filesystem::path fpath);
|
||||
|
Reference in New Issue
Block a user