From 0a6030aa3ee37945f10ae368d1b56d13b9ad923f Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 2 Apr 2024 12:26:51 +0200 Subject: [PATCH] moving code into aare:: namespace --- core/include/aare/Frame.hpp | 3 +++ core/include/aare/NDArray.hpp | 2 ++ core/include/aare/NDView.hpp | 3 +++ core/include/aare/VariableSizeClusterFinder.hpp | 4 ++-- core/include/aare/defs.hpp | 6 +++++- core/src/Frame.cpp | 5 ++++- core/src/defs.cpp | 6 +++++- core/test/NDArray.test.cpp | 6 ++++-- core/test/NDView.test.cpp | 3 ++- core/test/defs.test.cpp | 2 +- core/test/wrappers.test.cpp | 4 ++++ examples/json_example.cpp | 3 +++ examples/multiport_example.cpp | 3 +++ examples/mythen_example.cpp | 3 +++ examples/numpy_read_example.cpp | 3 +++ examples/numpy_write_example.cpp | 4 ++++ examples/raw_example.cpp | 3 +++ file_io/include/aare/File.hpp | 4 +++- file_io/include/aare/FileFactory.hpp | 4 ++++ file_io/include/aare/FileInterface.hpp | 4 ++++ file_io/include/aare/NumpyFile.hpp | 6 +++++- file_io/include/aare/NumpyFileFactory.hpp | 6 ++++-- file_io/include/aare/RawFile.hpp | 6 +++++- file_io/include/aare/RawFileFactory.hpp | 5 +++++ file_io/include/aare/SubFile.hpp | 4 ++++ file_io/include/aare/helpers.hpp | 3 +++ file_io/src/File.cpp | 4 ++++ file_io/src/FileFactory.cpp | 5 ++++- file_io/src/NumpyFile.cpp | 6 +++++- file_io/src/NumpyFileFactory.cpp | 4 +++- file_io/src/RawFile.cpp | 4 ++++ file_io/src/RawFileFactory.cpp | 4 ++++ file_io/src/SubFile.cpp | 4 ++++ file_io/src/helpers.cpp | 2 ++ file_io/test/RawFile.test.cpp | 1 + 35 files changed, 122 insertions(+), 17 deletions(-) diff --git a/core/include/aare/Frame.hpp b/core/include/aare/Frame.hpp index 4c3149f..73fd59a 100644 --- a/core/include/aare/Frame.hpp +++ b/core/include/aare/Frame.hpp @@ -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 \ No newline at end of file diff --git a/core/include/aare/NDArray.hpp b/core/include/aare/NDArray.hpp index fb3378a..284c4bf 100644 --- a/core/include/aare/NDArray.hpp +++ b/core/include/aare/NDArray.hpp @@ -18,6 +18,7 @@ TODO! Add expression templates for operators #include #include +namespace aare { template class NDArray { public: @@ -427,3 +428,4 @@ NDArray load(const std::string &pathname, } +} // namespace aare \ No newline at end of file diff --git a/core/include/aare/NDView.hpp b/core/include/aare/NDView.hpp index 9e07d41..8528e97 100644 --- a/core/include/aare/NDView.hpp +++ b/core/include/aare/NDView.hpp @@ -6,6 +6,8 @@ #include #include +namespace aare { + template using Shape = std::array; template ssize_t element_offset(const Strides &) { return 0; } @@ -125,3 +127,4 @@ template class NDView { template class NDView; +} // namespace aare \ No newline at end of file diff --git a/core/include/aare/VariableSizeClusterFinder.hpp b/core/include/aare/VariableSizeClusterFinder.hpp index dcf95f0..d1da285 100644 --- a/core/include/aare/VariableSizeClusterFinder.hpp +++ b/core/include/aare/VariableSizeClusterFinder.hpp @@ -9,7 +9,7 @@ #include "aare/NDArray.hpp" const int MAX_CLUSTER_SIZE = 200; -namespace pl { +namespace aare { template class ClusterFinder { public: @@ -307,4 +307,4 @@ template void ClusterFinder::store_clusters() { } -} // namespace pl +} // namespace aare diff --git a/core/include/aare/defs.hpp b/core/include/aare/defs.hpp index 8c31923..f28a5eb 100644 --- a/core/include/aare/defs.hpp +++ b/core/include/aare/defs.hpp @@ -9,6 +9,8 @@ #include #include +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 endian_chars = {little_endian_char, big_endian_char, no_endian_char}; -const std::array numtype_chars = {'f', 'i', 'u', 'c'}; \ No newline at end of file +const std::array numtype_chars = {'f', 'i', 'u', 'c'}; + +} // namespace aare \ No newline at end of file diff --git a/core/src/Frame.cpp b/core/src/Frame.cpp index 018f454..ecc7751 100644 --- a/core/src/Frame.cpp +++ b/core/src/Frame.cpp @@ -2,6 +2,9 @@ #include "aare/utils/logger.hpp" #include #include + +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 diff --git a/core/src/defs.cpp b/core/src/defs.cpp index 104bdb2..4d6e6f8 100644 --- a/core/src/defs.cpp +++ b/core/src/defs.cpp @@ -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(std::string mode); \ No newline at end of file +// template <> TimingMode StringTo(std::string mode); + +} // namespace aare \ No newline at end of file diff --git a/core/test/NDArray.test.cpp b/core/test/NDArray.test.cpp index d9fa19a..1670b44 100644 --- a/core/test/NDArray.test.cpp +++ b/core/test/NDArray.test.cpp @@ -3,8 +3,10 @@ #include -// 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") { diff --git a/core/test/NDView.test.cpp b/core/test/NDView.test.cpp index f03229d..28ccb2f 100644 --- a/core/test/NDView.test.cpp +++ b/core/test/NDView.test.cpp @@ -4,7 +4,8 @@ #include #include - +using aare::NDView; +using aare::Shape; TEST_CASE("Element reference 1D") { std::vector vec; diff --git a/core/test/defs.test.cpp b/core/test/defs.test.cpp index ecad682..6928c66 100644 --- a/core/test/defs.test.cpp +++ b/core/test/defs.test.cpp @@ -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"); } \ No newline at end of file diff --git a/core/test/wrappers.test.cpp b/core/test/wrappers.test.cpp index ae0f12e..f3a9e7e 100644 --- a/core/test/wrappers.test.cpp +++ b/core/test/wrappers.test.cpp @@ -4,6 +4,10 @@ #include #include +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++) { diff --git a/examples/json_example.cpp b/examples/json_example.cpp index 1541d93..a4ed915 100644 --- a/examples/json_example.cpp +++ b/examples/json_example.cpp @@ -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); diff --git a/examples/multiport_example.cpp b/examples/multiport_example.cpp index 8b17bee..96ffe01 100644 --- a/examples/multiport_example.cpp +++ b/examples/multiport_example.cpp @@ -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); diff --git a/examples/mythen_example.cpp b/examples/mythen_example.cpp index 64b5f0e..c7960bc 100644 --- a/examples/mythen_example.cpp +++ b/examples/mythen_example.cpp @@ -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); diff --git a/examples/numpy_read_example.cpp b/examples/numpy_read_example.cpp index 3c71708..7befecd 100644 --- a/examples/numpy_read_example.cpp +++ b/examples/numpy_read_example.cpp @@ -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); diff --git a/examples/numpy_write_example.cpp b/examples/numpy_write_example.cpp index 27aa77c..3cf7e2f 100644 --- a/examples/numpy_write_example.cpp +++ b/examples/numpy_write_example.cpp @@ -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"); diff --git a/examples/raw_example.cpp b/examples/raw_example.cpp index 84a5760..b442f5d 100644 --- a/examples/raw_example.cpp +++ b/examples/raw_example.cpp @@ -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); diff --git a/file_io/include/aare/File.hpp b/file_io/include/aare/File.hpp index 03314ed..30aa12b 100644 --- a/file_io/include/aare/File.hpp +++ b/file_io/include/aare/File.hpp @@ -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 \ No newline at end of file diff --git a/file_io/include/aare/FileFactory.hpp b/file_io/include/aare/FileFactory.hpp index 50baf9c..d61e422 100644 --- a/file_io/include/aare/FileFactory.hpp +++ b/file_io/include/aare/FileFactory.hpp @@ -4,6 +4,8 @@ #include "aare/utils/logger.hpp" #include +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 \ No newline at end of file diff --git a/file_io/include/aare/FileInterface.hpp b/file_io/include/aare/FileInterface.hpp index bb07414..7e2dfb6 100644 --- a/file_io/include/aare/FileInterface.hpp +++ b/file_io/include/aare/FileInterface.hpp @@ -6,6 +6,8 @@ #include #include +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{}; }; + +} \ No newline at end of file diff --git a/file_io/include/aare/NumpyFile.hpp b/file_io/include/aare/NumpyFile.hpp index 6d72537..7f8192f 100644 --- a/file_io/include/aare/NumpyFile.hpp +++ b/file_io/include/aare/NumpyFile.hpp @@ -5,6 +5,8 @@ #include #include +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); -}; \ No newline at end of file +}; + +} // namespace aare \ No newline at end of file diff --git a/file_io/include/aare/NumpyFileFactory.hpp b/file_io/include/aare/NumpyFileFactory.hpp index bd9a11b..8fb7a43 100644 --- a/file_io/include/aare/NumpyFileFactory.hpp +++ b/file_io/include/aare/NumpyFileFactory.hpp @@ -4,7 +4,7 @@ #include "aare/defs.hpp" #include - +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{}; -}; \ No newline at end of file +}; + +} // namespace aare \ No newline at end of file diff --git a/file_io/include/aare/RawFile.hpp b/file_io/include/aare/RawFile.hpp index a7a669e..59300db 100644 --- a/file_io/include/aare/RawFile.hpp +++ b/file_io/include/aare/RawFile.hpp @@ -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); -}; \ No newline at end of file +}; + +} \ No newline at end of file diff --git a/file_io/include/aare/RawFileFactory.hpp b/file_io/include/aare/RawFileFactory.hpp index 634731e..4b9c77a 100644 --- a/file_io/include/aare/RawFileFactory.hpp +++ b/file_io/include/aare/RawFileFactory.hpp @@ -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 *); }; + +} \ No newline at end of file diff --git a/file_io/include/aare/SubFile.hpp b/file_io/include/aare/SubFile.hpp index d8080d5..4a8212a 100644 --- a/file_io/include/aare/SubFile.hpp +++ b/file_io/include/aare/SubFile.hpp @@ -5,6 +5,8 @@ #include #include +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 \ No newline at end of file diff --git a/file_io/include/aare/helpers.hpp b/file_io/include/aare/helpers.hpp index bf39d55..f8d52fb 100644 --- a/file_io/include/aare/helpers.hpp +++ b/file_io/include/aare/helpers.hpp @@ -4,5 +4,8 @@ #include #include +namespace aare { + bool is_master_file(std::filesystem::path fpath); +} \ No newline at end of file diff --git a/file_io/src/File.cpp b/file_io/src/File.cpp index 73655ce..613e005 100644 --- a/file_io/src/File.cpp +++ b/file_io/src/File.cpp @@ -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 + +} \ No newline at end of file diff --git a/file_io/src/FileFactory.cpp b/file_io/src/FileFactory.cpp index b48cc6a..a73782a 100644 --- a/file_io/src/FileFactory.cpp +++ b/file_io/src/FileFactory.cpp @@ -6,6 +6,8 @@ #include "aare/utils/logger.hpp" #include +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 diff --git a/file_io/src/NumpyFile.cpp b/file_io/src/NumpyFile.cpp index 85da8a4..0d7df8d 100644 --- a/file_io/src/NumpyFile.cpp +++ b/file_io/src/NumpyFile.cpp @@ -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); } -} \ No newline at end of file +} + +} // namespace aare \ No newline at end of file diff --git a/file_io/src/NumpyFileFactory.cpp b/file_io/src/NumpyFileFactory.cpp index 57d11f8..7d3681b 100644 --- a/file_io/src/NumpyFileFactory.cpp +++ b/file_io/src/NumpyFileFactory.cpp @@ -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 \ No newline at end of file diff --git a/file_io/src/RawFile.cpp b/file_io/src/RawFile.cpp index cd2b65d..e3e52d4 100644 --- a/file_io/src/RawFile.cpp +++ b/file_io/src/RawFile.cpp @@ -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 \ No newline at end of file diff --git a/file_io/src/RawFileFactory.cpp b/file_io/src/RawFileFactory.cpp index 1361f27..75af2fa 100644 --- a/file_io/src/RawFileFactory.cpp +++ b/file_io/src/RawFileFactory.cpp @@ -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 \ No newline at end of file diff --git a/file_io/src/SubFile.cpp b/file_io/src/SubFile.cpp index cc7ac89..bba97eb 100644 --- a/file_io/src/SubFile.cpp +++ b/file_io/src/SubFile.cpp @@ -3,6 +3,8 @@ #include // #include +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 \ No newline at end of file diff --git a/file_io/src/helpers.cpp b/file_io/src/helpers.cpp index 9c7ceeb..61b894f 100644 --- a/file_io/src/helpers.cpp +++ b/file_io/src/helpers.cpp @@ -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 \ No newline at end of file diff --git a/file_io/test/RawFile.test.cpp b/file_io/test/RawFile.test.cpp index dfbcc44..a2d6e70 100644 --- a/file_io/test/RawFile.test.cpp +++ b/file_io/test/RawFile.test.cpp @@ -5,6 +5,7 @@ #include "test_config.hpp" +using aare::File; TEST_CASE("Read number of frames from a jungfrau raw file") {