merge numpy changes with project structure

This commit is contained in:
Bechir
2024-03-08 11:47:27 +01:00
parent 0d552d6f75
commit 47d381d299
14 changed files with 396 additions and 114 deletions

View File

@ -3,23 +3,11 @@
#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 {
@ -27,54 +15,29 @@ class File {
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;
int findex;
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();
};
};

View File

@ -1,7 +1,6 @@
#pragma once
#include <filesystem>
#include "aare/File.hpp"
template <DetectorType detector,typename DataType>
class FileFactory{
// Class that will be used to create File objects
@ -13,14 +12,9 @@ public:
// 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>*);
virtual void parse_fname(File<detector,DataType>*)=0;
sls_detector_header read_header(const std::filesystem::path &fname);
};

View File

@ -1,9 +1,40 @@
#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> {
#include "aare/Frame.hpp"
#include "aare/File.hpp"
template <DetectorType detector, typename DataType> class JsonFile : public File<detector, DataType> {
using config = RawFileConfig;
public:
Frame<DataType> *get_frame(int frame_number);
int n_subfiles;
std::vector<SubFile *> subfiles;
int subfile_rows, subfile_cols;
std::vector<xy> positions;
config cfg{0, 0};
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 this->base_path / fmt::format("{}_master_{}{}", this->base_name, this->findex, this->ext);
}
inline std::filesystem::path data_fname(int mod_id, int file_id) {
return this->base_path / fmt::format("{}_d{}_f{}_{}.raw", this->base_name, file_id, mod_id, this->findex);
}
~JsonFile();
};

View File

@ -7,10 +7,13 @@ private:
public:
File<detector,DataType>* load_file() override;
void parse_metadata(File<detector,DataType>*) override;
void parse_fname(File<detector,DataType>*) override;
JsonFileFactory<detector,DataType>(std::filesystem::path fpath);
void open_subfiles(File<detector,DataType>*);
sls_detector_header read_header(const std::filesystem::path &fname);
void find_geometry(File<detector,DataType>*);
};

View File

@ -0,0 +1,9 @@
#include "aare/File.hpp"
#include "aare/defs.hpp"
template <DetectorType detector, typename DataType>
class NumpyFile : public File<detector, DataType>
{
};

View File

@ -0,0 +1,29 @@
#include "aare/defs.hpp"
#include "aare/FileFactory.hpp"
#include "aare/NumpyFile.hpp"
#include <algorithm>
#include <array>
#include <filesystem>
#include <fstream>
#include <string>
#include <unordered_map>
#include <vector>
template <DetectorType detector, typename DataType> class NumpyFileFactory : public FileFactory<detector, DataType> {
public:
NumpyFileFactory(std::filesystem::path fpath);
void parse_metadata(File<detector, DataType> *_file) override;
void open_subfiles(File<detector, DataType> *_file) override;
File<detector, DataType> *load_file() override;
uint8_t major_ver() const noexcept { return major_ver_; }
uint8_t minor_ver() const noexcept { return minor_ver_; }
private:
static constexpr std::array<char, 6> magic_str{'\x93', 'N', 'U', 'M', 'P', 'Y'};
uint8_t major_ver_{};
uint8_t minor_ver_{};
uint32_t header_len{};
uint8_t header_len_size{};
const uint8_t magic_string_length{6};
};