mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-05 12:30:39 +02:00
Merge pull request #39 from slsdetectorgroup/namespace
moving code into aare:: namespace
This commit is contained in:
commit
e534cc0f25
@ -14,6 +14,8 @@
|
||||
* should be able to work with streams coming from files or network
|
||||
*/
|
||||
|
||||
namespace aare {
|
||||
|
||||
class Frame {
|
||||
ssize_t m_rows;
|
||||
ssize_t m_cols;
|
||||
@ -65,3 +67,4 @@ class Frame {
|
||||
};
|
||||
|
||||
|
||||
} // namespace aare
|
@ -18,6 +18,7 @@ TODO! Add expression templates for operators
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
namespace aare {
|
||||
|
||||
template <typename T, ssize_t Ndim = 2> class NDArray {
|
||||
public:
|
||||
@ -427,3 +428,4 @@ NDArray<T, Ndim> load(const std::string &pathname,
|
||||
}
|
||||
|
||||
|
||||
} // namespace aare
|
@ -6,6 +6,8 @@
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
namespace aare {
|
||||
|
||||
template <ssize_t Ndim> using Shape = std::array<ssize_t, Ndim>;
|
||||
|
||||
template <ssize_t Dim = 0, typename Strides> ssize_t element_offset(const Strides &) { return 0; }
|
||||
@ -125,3 +127,4 @@ template <typename T, ssize_t Ndim=2> class NDView {
|
||||
|
||||
template class NDView<uint16_t, 2>;
|
||||
|
||||
} // namespace aare
|
@ -9,7 +9,7 @@
|
||||
#include "aare/NDArray.hpp"
|
||||
|
||||
const int MAX_CLUSTER_SIZE = 200;
|
||||
namespace pl {
|
||||
namespace aare {
|
||||
|
||||
template <typename T> class ClusterFinder {
|
||||
public:
|
||||
@ -307,4 +307,4 @@ template <typename T> void ClusterFinder<T>::store_clusters() {
|
||||
|
||||
}
|
||||
|
||||
} // namespace pl
|
||||
} // namespace aare
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <fmt/format.h>
|
||||
#include <variant>
|
||||
|
||||
namespace aare{
|
||||
|
||||
typedef struct {
|
||||
uint64_t frameNumber;
|
||||
uint32_t expLength;
|
||||
@ -75,4 +77,6 @@ const char big_endian_char = '>';
|
||||
const char no_endian_char = '|';
|
||||
|
||||
const std::array<char, 3> endian_chars = {little_endian_char, big_endian_char, no_endian_char};
|
||||
const std::array<char, 4> numtype_chars = {'f', 'i', 'u', 'c'};
|
||||
const std::array<char, 4> numtype_chars = {'f', 'i', 'u', 'c'};
|
||||
|
||||
} // namespace aare
|
@ -2,6 +2,9 @@
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
namespace aare {
|
||||
|
||||
Frame::Frame(std::byte* bytes, ssize_t rows, ssize_t cols, ssize_t bitdepth):
|
||||
m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
||||
m_data = new std::byte[rows*cols*bitdepth/8];
|
||||
@ -48,4 +51,4 @@ template void Frame::set(int row, int col, uint32_t data);
|
||||
// return array;
|
||||
// }
|
||||
|
||||
|
||||
} // namespace aare
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "aare/defs.hpp"
|
||||
|
||||
namespace aare {
|
||||
|
||||
template <> std::string toString(DetectorType type) {
|
||||
switch (type) {
|
||||
case DetectorType::Jungfrau:
|
||||
@ -45,4 +47,6 @@ template <> TimingMode StringTo(std::string mode) {
|
||||
}
|
||||
}
|
||||
|
||||
// template <> TimingMode StringTo<TimingMode>(std::string mode);
|
||||
// template <> TimingMode StringTo<TimingMode>(std::string mode);
|
||||
|
||||
} // namespace aare
|
@ -3,8 +3,10 @@
|
||||
#include <array>
|
||||
|
||||
|
||||
// using reuss::DataSpan;
|
||||
// using reuss::Shape;
|
||||
using aare::NDArray;
|
||||
using aare::NDView;
|
||||
using aare::Shape;
|
||||
|
||||
|
||||
TEST_CASE("Initial size is zero if no size is specified")
|
||||
{
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using aare::NDView;
|
||||
using aare::Shape;
|
||||
|
||||
TEST_CASE("Element reference 1D") {
|
||||
std::vector<int> vec;
|
||||
|
@ -4,5 +4,5 @@
|
||||
TEST_CASE("Enum to string conversion"){
|
||||
//By the way I don't think the enum string conversions should be in the defs.hpp file
|
||||
//but let's use this to show a test
|
||||
REQUIRE(toString(DetectorType::Jungfrau) == "Jungfrau");
|
||||
REQUIRE(toString(aare::DetectorType::Jungfrau) == "Jungfrau");
|
||||
}
|
@ -4,6 +4,10 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
using aare::Frame;
|
||||
using aare::NDView;
|
||||
using aare::NDArray;
|
||||
|
||||
TEST_CASE("Frame") {
|
||||
auto data = new uint16_t[100];
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
|
||||
void test(File& f, int frame_number) {
|
||||
std::cout << "frame number: " << frame_number << std::endl;
|
||||
Frame frame = f.iread(frame_number);
|
||||
|
@ -6,6 +6,9 @@
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
|
||||
void test(File &f, int frame_number) {
|
||||
std::cout << "frame number: " << frame_number << std::endl;
|
||||
Frame frame = f.iread(frame_number);
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
|
||||
void test1(File &f, int frame_number) {
|
||||
std::cout << "frame number: " << frame_number << std::endl;
|
||||
Frame frame = f.iread(frame_number);
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
|
||||
void test(File& f, int frame_number) {
|
||||
std::cout << "frame number: " << frame_number << std::endl;
|
||||
Frame frame = f.iread(frame_number);
|
||||
|
@ -5,6 +5,10 @@
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
using aare::File;
|
||||
using aare::FileConfig;
|
||||
using aare::Frame;
|
||||
|
||||
|
||||
int main() {
|
||||
auto path = std::filesystem::path("/tmp/test.npy");
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
|
||||
void test(File& f, int frame_number) {
|
||||
std::cout << "frame number: " << frame_number << std::endl;
|
||||
Frame frame = f.iread(frame_number);
|
||||
|
@ -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") {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user