mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-13 15:57:14 +02:00
moving code into aare:: namespace
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
#include "aare/FileInterface.hpp"
|
||||
|
||||
|
||||
namespace aare{
|
||||
class File {
|
||||
private:
|
||||
FileInterface *file_impl;
|
||||
@ -32,3 +32,5 @@ class File {
|
||||
|
||||
~File();
|
||||
};
|
||||
|
||||
} // namespace aare
|
@ -4,6 +4,8 @@
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
namespace aare{
|
||||
|
||||
class FileFactory {
|
||||
// Class that will be used to create FileInterface objects
|
||||
// follows the factory pattern
|
||||
@ -35,3 +37,5 @@ class FileFactory {
|
||||
virtual void parse_fname(FileInterface *) = 0;
|
||||
virtual ~FileFactory() = default;
|
||||
};
|
||||
|
||||
} // namespace aare
|
@ -6,6 +6,8 @@
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
|
||||
namespace aare {
|
||||
|
||||
struct FileConfig {
|
||||
std::filesystem::path fname;
|
||||
aare::DType dtype = aare::DType(typeid(uint16_t));
|
||||
@ -93,3 +95,5 @@ class FileInterface {
|
||||
ssize_t m_cols{};
|
||||
ssize_t m_bitdepth{};
|
||||
};
|
||||
|
||||
}
|
@ -5,6 +5,8 @@
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
namespace aare{
|
||||
|
||||
class NumpyFile : public FileInterface {
|
||||
FILE *fp = nullptr;
|
||||
size_t initial_header_len = 0;
|
||||
@ -42,4 +44,6 @@ class NumpyFile : public FileInterface {
|
||||
size_t current_frame{};
|
||||
void get_frame_into(size_t, std::byte *);
|
||||
Frame get_frame(size_t frame_number);
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace aare
|
@ -4,7 +4,7 @@
|
||||
#include "aare/defs.hpp"
|
||||
#include <fstream>
|
||||
|
||||
|
||||
namespace aare {
|
||||
|
||||
class NumpyFileFactory : public FileFactory {
|
||||
private:
|
||||
@ -18,4 +18,6 @@ class NumpyFileFactory : public FileFactory {
|
||||
NumpyFile* load_file_write(FileConfig) override;
|
||||
void parse_fname(FileInterface*)override{};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace aare
|
@ -4,6 +4,8 @@
|
||||
#include "aare/SubFile.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
|
||||
namespace aare {
|
||||
|
||||
class RawFile : public FileInterface {
|
||||
|
||||
using config = RawFileConfig;
|
||||
@ -69,4 +71,6 @@ class RawFile : public FileInterface {
|
||||
size_t current_frame{};
|
||||
void get_frame_into(size_t frame_number, std::byte *image_buf);
|
||||
Frame get_frame(size_t frame_number);
|
||||
};
|
||||
};
|
||||
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
#include "aare/FileFactory.hpp"
|
||||
#include "aare/RawFile.hpp"
|
||||
|
||||
namespace aare {
|
||||
|
||||
class RawFileFactory : public FileFactory {
|
||||
private:
|
||||
void parse_json_metadata(RawFile *file);
|
||||
@ -16,3 +19,5 @@ class RawFileFactory : public FileFactory {
|
||||
sls_detector_header read_header(const std::filesystem::path &fname);
|
||||
void find_geometry(FileInterface *);
|
||||
};
|
||||
|
||||
}
|
@ -5,6 +5,8 @@
|
||||
#include <map>
|
||||
#include <variant>
|
||||
|
||||
namespace aare {
|
||||
|
||||
class SubFile {
|
||||
protected:
|
||||
FILE *fp = nullptr;
|
||||
@ -42,3 +44,5 @@ class SubFile {
|
||||
inline size_t bytes_per_part() { return (m_bitdepth / 8) * m_rows * m_cols; }
|
||||
inline size_t pixels_per_part() { return m_rows * m_cols; }
|
||||
};
|
||||
|
||||
} // namespace aare
|
@ -4,5 +4,8 @@
|
||||
#include <filesystem>
|
||||
#include <fmt/core.h>
|
||||
|
||||
namespace aare {
|
||||
|
||||
bool is_master_file(std::filesystem::path fpath);
|
||||
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
#include "aare/FileFactory.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
|
||||
namespace aare {
|
||||
|
||||
File::File(std::filesystem::path fname, std::string mode, FileConfig cfg) {
|
||||
file_impl = FileFactory::load_file(fname, mode, cfg);
|
||||
}
|
||||
@ -30,3 +32,5 @@ File::File(File &&other) {
|
||||
}
|
||||
|
||||
// write move assignment operator
|
||||
|
||||
}
|
@ -6,6 +6,8 @@
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace aare {
|
||||
|
||||
FileFactory *FileFactory::get_factory(std::filesystem::path fpath) {
|
||||
if (fpath.extension() == ".raw" || fpath.extension() == ".json"){
|
||||
aare::logger::debug("Loading",fpath.extension(),"file");
|
||||
@ -18,11 +20,12 @@ FileFactory *FileFactory::get_factory(std::filesystem::path fpath) {
|
||||
// check if extension is numpy
|
||||
else if (fpath.extension() == ".npy") {
|
||||
aare::logger::debug("Loading numpy file");
|
||||
return new NumpyFileFactory(fpath);
|
||||
return new aare::NumpyFileFactory(fpath);
|
||||
}
|
||||
|
||||
throw std::runtime_error("Unsupported file type");
|
||||
}
|
||||
|
||||
} // namespace aare
|
||||
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
|
||||
#include "aare/NumpyFile.hpp"
|
||||
|
||||
namespace aare{
|
||||
|
||||
void NumpyFile::write(Frame &frame) {
|
||||
if (fp == nullptr) {
|
||||
throw std::runtime_error("File not open");
|
||||
@ -96,4 +98,6 @@ NumpyFile::~NumpyFile() {
|
||||
fclose(fp);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aare
|
@ -1,7 +1,7 @@
|
||||
#include "aare/NumpyFileFactory.hpp"
|
||||
#include "aare/NumpyHelpers.hpp"
|
||||
|
||||
using namespace aare;
|
||||
namespace aare {
|
||||
|
||||
NumpyFileFactory::NumpyFileFactory(std::filesystem::path fpath) { this->m_fpath = fpath; }
|
||||
void NumpyFileFactory::parse_metadata(FileInterface *_file) {
|
||||
@ -86,3 +86,5 @@ NumpyFile *NumpyFileFactory::load_file_write(FileConfig config) {
|
||||
|
||||
return file;
|
||||
};
|
||||
|
||||
} // namespace aare
|
@ -1,6 +1,8 @@
|
||||
#include "aare/RawFile.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
|
||||
namespace aare{
|
||||
|
||||
Frame RawFile::get_frame(size_t frame_number) {
|
||||
auto f = Frame(this->m_rows, this->m_cols, this->m_bitdepth);
|
||||
std::byte *frame_buffer = f._get_data();
|
||||
@ -77,3 +79,5 @@ RawFile::~RawFile() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aare
|
@ -11,6 +11,8 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace aare {
|
||||
|
||||
RawFileFactory::RawFileFactory(std::filesystem::path fpath) {
|
||||
if (not is_master_file(fpath))
|
||||
throw std::runtime_error("Json file is not a master file");
|
||||
@ -180,3 +182,5 @@ void RawFileFactory::parse_fname(FileInterface *file) {
|
||||
pos = file->m_base_name.find("_master_");
|
||||
file->m_base_name.erase(pos);
|
||||
}
|
||||
|
||||
} // namespace aare
|
@ -3,6 +3,8 @@
|
||||
#include <iostream>
|
||||
// #include <filesystem>
|
||||
|
||||
namespace aare {
|
||||
|
||||
SubFile::SubFile(std::filesystem::path fname, DetectorType detector, ssize_t rows, ssize_t cols, uint16_t bitdepth) {
|
||||
this->m_rows = rows;
|
||||
this->m_cols = cols;
|
||||
@ -97,3 +99,5 @@ size_t SubFile::frame_number(int frame_index) {
|
||||
|
||||
return h.frameNumber;
|
||||
}
|
||||
|
||||
} // namespace aare
|
@ -1,5 +1,6 @@
|
||||
#include "aare/helpers.hpp"
|
||||
|
||||
namespace aare {
|
||||
|
||||
bool is_master_file(std::filesystem::path fpath) {
|
||||
std::string stem = fpath.stem();
|
||||
@ -9,3 +10,4 @@ bool is_master_file(std::filesystem::path fpath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}// namespace aare
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "test_config.hpp"
|
||||
|
||||
using aare::File;
|
||||
|
||||
TEST_CASE("Read number of frames from a jungfrau raw file") {
|
||||
|
||||
|
Reference in New Issue
Block a user