mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-23 11:57:58 +02:00
format headers
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "aare/FileInterface.hpp"
|
||||
|
||||
namespace aare{
|
||||
namespace aare {
|
||||
class File {
|
||||
private:
|
||||
FileInterface *file_impl;
|
||||
@ -12,8 +12,8 @@ class File {
|
||||
// - w writing (overwrites existing file)
|
||||
// - a appending (appends to existing file)
|
||||
// TODO! do we need to support w+, r+ and a+?
|
||||
File(std::filesystem::path fname, std::string mode,FileConfig cfg = {});
|
||||
void write(Frame& frame);
|
||||
File(std::filesystem::path fname, std::string mode, FileConfig cfg = {});
|
||||
void write(Frame &frame);
|
||||
Frame read();
|
||||
Frame iread(size_t frame_number);
|
||||
std::vector<Frame> read(size_t n_frames);
|
||||
@ -27,10 +27,9 @@ class File {
|
||||
size_t total_frames() const;
|
||||
ssize_t rows() const;
|
||||
ssize_t cols() const;
|
||||
ssize_t bitdepth() const;
|
||||
ssize_t bitdepth() const;
|
||||
File(File &&other);
|
||||
|
||||
|
||||
~File();
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
namespace aare{
|
||||
namespace aare {
|
||||
|
||||
class FileFactory {
|
||||
// Class that will be used to create FileInterface objects
|
||||
@ -17,7 +17,7 @@ class FileFactory {
|
||||
// virtual int deleteFile() = 0;
|
||||
static FileInterface *load_file(std::filesystem::path p, std::string mode, FileConfig cfg = {}) {
|
||||
if ((mode == "r" or mode == "a") and not std::filesystem::exists(p)) {
|
||||
throw std::runtime_error(LOCATION+"File does not exist");
|
||||
throw std::runtime_error(LOCATION + "File does not exist");
|
||||
}
|
||||
|
||||
auto factory = get_factory(p);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "aare/DType.hpp"
|
||||
#include "aare/Frame.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
#include "aare/DType.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
@ -96,4 +96,4 @@ class FileInterface {
|
||||
ssize_t m_bitdepth{};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace aare
|
@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
#include "aare/DType.hpp"
|
||||
#include "aare/FileInterface.hpp"
|
||||
#include "aare/NumpyHelpers.hpp"
|
||||
#include "aare/DType.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <filesystem>
|
||||
|
||||
namespace aare{
|
||||
namespace aare {
|
||||
|
||||
class NumpyFile : public FileInterface {
|
||||
FILE *fp = nullptr;
|
||||
size_t initial_header_len = 0;
|
||||
size_t current_frame{};
|
||||
std::filesystem::path m_fname;
|
||||
std::filesystem::path m_fname;
|
||||
uint32_t header_len{};
|
||||
uint8_t header_len_size{};
|
||||
ssize_t header_size{};
|
||||
@ -26,9 +26,7 @@ class NumpyFile : public FileInterface {
|
||||
Frame get_frame(size_t frame_number);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
NumpyFile(const std::filesystem::path& fname);
|
||||
NumpyFile(const std::filesystem::path &fname);
|
||||
NumpyFile(FileConfig, NumpyHeader);
|
||||
void write(Frame &frame) override;
|
||||
Frame read() override { return get_frame(this->current_frame++); }
|
||||
@ -48,11 +46,10 @@ class NumpyFile : public FileInterface {
|
||||
|
||||
DType dtype() const { return m_header.dtype; }
|
||||
std::vector<size_t> shape() const { return m_header.shape; }
|
||||
|
||||
//load the full numpy file into a NDArray
|
||||
template<typename T, size_t NDim>
|
||||
NDArray<T,NDim> load(){
|
||||
NDArray<T,NDim> arr(make_shape<NDim>(m_header.shape));
|
||||
|
||||
// load the full numpy file into a NDArray
|
||||
template <typename T, size_t NDim> NDArray<T, NDim> load() {
|
||||
NDArray<T, NDim> arr(make_shape<NDim>(m_header.shape));
|
||||
fseek(fp, header_size, SEEK_SET);
|
||||
fread(arr.data(), sizeof(T), arr.size(), fp);
|
||||
return arr;
|
||||
|
@ -14,10 +14,9 @@ class NumpyFileFactory : public FileFactory {
|
||||
public:
|
||||
NumpyFileFactory(std::filesystem::path fpath);
|
||||
void parse_metadata(FileInterface *_file) override{/*TODO! remove after refactor*/};
|
||||
NumpyFile* load_file_read() override;
|
||||
NumpyFile* load_file_write(FileConfig) override;
|
||||
void parse_fname(FileInterface*)override{};
|
||||
|
||||
NumpyFile *load_file_read() override;
|
||||
NumpyFile *load_file_write(FileConfig) override;
|
||||
void parse_fname(FileInterface *) override{};
|
||||
};
|
||||
|
||||
} // namespace aare
|
@ -21,7 +21,7 @@ using shape_t = std::vector<size_t>;
|
||||
struct NumpyHeader {
|
||||
DType dtype{aare::DType::ERROR};
|
||||
bool fortran_order{false};
|
||||
shape_t shape{};
|
||||
shape_t shape{};
|
||||
|
||||
std::string to_string() const;
|
||||
};
|
||||
@ -51,9 +51,8 @@ template <typename T, size_t N> bool in_array(T val, const std::array<T, N> &arr
|
||||
bool is_digits(const std::string &str);
|
||||
|
||||
aare::DType parse_descr(std::string typestring);
|
||||
size_t write_header(std::filesystem::path fname, const NumpyHeader &header) ;
|
||||
size_t write_header(std::ostream &out, const NumpyHeader &header) ;
|
||||
|
||||
size_t write_header(std::filesystem::path fname, const NumpyHeader &header);
|
||||
size_t write_header(std::ostream &out, const NumpyHeader &header);
|
||||
|
||||
} // namespace NumpyHelpers
|
||||
} // namespace aare
|
@ -9,10 +9,9 @@ namespace aare {
|
||||
class RawFile : public FileInterface {
|
||||
|
||||
using config = RawFileConfig;
|
||||
|
||||
|
||||
public:
|
||||
std::filesystem::path m_fname; //TO be made private!
|
||||
std::filesystem::path m_fname; // TO be made private!
|
||||
void write(Frame &frame) override{};
|
||||
Frame read() override { return get_frame(this->current_frame++); };
|
||||
std::vector<Frame> read(size_t n_frames) override;
|
||||
@ -27,10 +26,10 @@ class RawFile : public FileInterface {
|
||||
size_t pixels() override { return m_rows * m_cols; }
|
||||
|
||||
// goto frame number
|
||||
void seek(size_t frame_number) override{ this->current_frame = frame_number; };
|
||||
void seek(size_t frame_number) override { this->current_frame = frame_number; };
|
||||
|
||||
// return the position of the file pointer (in number of frames)
|
||||
size_t tell() override{ return this->current_frame; };
|
||||
size_t tell() override { return this->current_frame; };
|
||||
|
||||
size_t n_subfiles;
|
||||
size_t n_subfile_parts;
|
||||
@ -66,8 +65,8 @@ class RawFile : public FileInterface {
|
||||
|
||||
size_t total_frames() const override { return m_total_frames; }
|
||||
ssize_t rows() const override { return m_rows; }
|
||||
ssize_t cols() const override{ return m_cols; }
|
||||
ssize_t bitdepth() const override{ return m_bitdepth; }
|
||||
ssize_t cols() const override { return m_cols; }
|
||||
ssize_t bitdepth() const override { return m_bitdepth; }
|
||||
|
||||
private:
|
||||
size_t current_frame{};
|
||||
@ -75,4 +74,4 @@ class RawFile : public FileInterface {
|
||||
Frame get_frame(size_t frame_number);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace aare
|
@ -10,10 +10,9 @@ class RawFileFactory : public FileFactory {
|
||||
void parse_raw_metadata(RawFile *file);
|
||||
|
||||
public:
|
||||
|
||||
RawFileFactory(std::filesystem::path fpath);
|
||||
RawFile *load_file_read() override;
|
||||
RawFile *load_file_write(FileConfig) override{return new RawFile();};
|
||||
RawFile *load_file_write(FileConfig) override { return new RawFile(); };
|
||||
void parse_metadata(FileInterface *) override;
|
||||
void parse_fname(FileInterface *) override;
|
||||
void open_subfiles(FileInterface *);
|
||||
@ -21,4 +20,4 @@ class RawFileFactory : public FileFactory {
|
||||
void find_geometry(FileInterface *);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace aare
|
Reference in New Issue
Block a user