diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 25015e2..10e21c5 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,14 +3,16 @@ { "name": "Linux", "includePath": [ - "${workspaceFolder}/**" + "${workspaceFolder}/**", + "/usr/include" ], "defines": [], "compilerPath": "/usr/bin/g++", "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "linux-gcc-x64", - "configurationProvider": "ms-vscode.cmake-tools" + "configurationProvider": "ms-vscode.cmake-tools", + "compilerArgs": [] } ], "version": 4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 98ac888..eb20097 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ project(aare cmake_policy(SET CMP0135 NEW) +include(GNUInstallDirs) include(FetchContent) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index ec461e6..84fba25 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,7 +1,5 @@ -target_include_directories(aare PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ) - target_include_directories(aare PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - +target_sources(aare PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/defs.cpp") diff --git a/src/common/defs.cpp b/src/common/defs.cpp new file mode 100644 index 0000000..81e4065 --- /dev/null +++ b/src/common/defs.cpp @@ -0,0 +1,27 @@ +#include "defs.hpp" + + template <> DetectorType StringTo(std::string name) { + if (name == "Jungfrau") + return DetectorType::Jungfrau; + else if (name == "Eiger") + return DetectorType::Eiger; + else if (name == "Mythen3") + return DetectorType::Mythen3; + else if (name == "Moench") + return DetectorType::Moench; + else { + auto msg = fmt::format("Could not decode dector from: \"{}\"", name); + throw std::runtime_error(msg); + } +} + +template <> TimingMode StringTo(std::string mode){ + if (mode == "auto") + return TimingMode::Auto; + else if(mode == "trigger") + return TimingMode::Trigger; + else{ + auto msg = fmt::format("Could not decode timing mode from: \"{}\"", mode); + throw std::runtime_error(msg); + } +} \ No newline at end of file diff --git a/src/common/defs.hpp b/src/common/defs.hpp new file mode 100644 index 0000000..0025f24 --- /dev/null +++ b/src/common/defs.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +typedef struct { + uint64_t frameNumber; + uint32_t expLength; + uint32_t packetNumber; + uint64_t bunchId; + uint64_t timestamp; + uint16_t modId; + uint16_t row; + uint16_t column; + uint16_t reserved; + uint32_t debug; + uint16_t roundRNumber; + uint8_t detType; + uint8_t version; + uint8_t packetMask[64]; +}__attribute__((packed)) sls_detector_header; + +struct xy { + int row; + int col; +}; + +using image_shape = std::array; +using dynamic_shape = std::vector; + +enum class DetectorType { Jungfrau, Eiger, Mythen3, Moench }; + +enum class TimingMode {Auto, Trigger}; + +template +T StringTo(std::string sv){ + return T(sv); +} + +template <> DetectorType StringTo(std::string); + +template <> TimingMode StringTo(std::string); + diff --git a/src/common/include/defs.hpp b/src/common/include/defs.hpp deleted file mode 100644 index e782527..0000000 --- a/src/common/include/defs.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - - - - -using image_shape = std::array; -using dynamic_shape = std::vector; - -enum class DetectorType { Jungfrau, Eiger, Mythen3, Moench }; - -enum class TimingMode {Auto, Trigger}; -DetectorType StringTo(std::string_view name); \ No newline at end of file diff --git a/src/file_io/file/File.hpp b/src/file_io/file/File.hpp index 9680348..ed101a5 100644 --- a/src/file_io/file/File.hpp +++ b/src/file_io/file/File.hpp @@ -7,6 +7,7 @@ class File { public: +std::filesystem::path fname; std::filesystem::path base_path; std::string base_name,ext; int findex, n_subfiles; @@ -16,6 +17,7 @@ public: DetectorType type; TimingMode timing_mode; int subfile_rows, subfile_cols; + bool quad {false}; @@ -23,18 +25,31 @@ public: ssize_t rows{}; ssize_t cols{}; uint8_t bitdepth{}; - DetectorType type{}; + std::vector positions; + // File(); // ~File(); + + inline size_t bytes_per_frame() const{ return rows*cols*bitdepth/8; - } inline size_t pixels() const{ return rows*cols; } + + // TODO! Deal with fast quad and missing files + inline void find_number_of_subfiles() { + int n_mod = 0; + while (std::filesystem::exists(data_fname(n_mod, 0))) { + n_mod++; + } + n_subfiles = n_mod; + } + + inline std::filesystem::path master_fname() { return base_path / fmt::format("{}_master_{}{}", base_name, findex, ext); } diff --git a/src/file_io/file_factory/FileFactory.cpp b/src/file_io/file_factory/FileFactory.cpp index b323ec0..601108e 100644 --- a/src/file_io/file_factory/FileFactory.cpp +++ b/src/file_io/file_factory/FileFactory.cpp @@ -39,3 +39,38 @@ void FileFactory::parse_fname(File& file) { pos = file.base_name.find("_master_"); file.base_name.erase(pos); } + +template + Header FileFactory::read_header(const std::filesystem::path &fname) { + Header h{}; + FILE *fp = fopen(fname.c_str(), "r"); + if (!fp) + throw std::runtime_error( + fmt::format("Could not open: {} for reading", fname.c_str())); + + size_t rc = fread(reinterpret_cast(&h), sizeof(h), 1, fp); + fclose(fp); + if (rc != 1) + throw std::runtime_error("Could not read header from file"); + return h; + +} + +void FileFactory::find_geometry(File& file) { + uint16_t r{}; + uint16_t c{}; + for (int i = 0; i != file.n_subfiles; ++i) { + auto h = this->read_header(file.data_fname(i, 0)); + r = std::max(r, h.row); + c = std::max(c, h.column); + + file.positions.push_back({h.row, h.column}); + } + r++; + c++; + + file.rows = r * file.subfile_rows; + file.cols = c * file.subfile_cols; + + file.rows += (r - 1) * cfg.module_gap_row; +} \ No newline at end of file diff --git a/src/file_io/file_factory/FileFactory.hpp b/src/file_io/file_factory/FileFactory.hpp index 247afd4..6bf251c 100644 --- a/src/file_io/file_factory/FileFactory.hpp +++ b/src/file_io/file_factory/FileFactory.hpp @@ -12,10 +12,13 @@ public: // virtual int deleteFile() = 0; virtual File loadFile(){};//TODO: add option to load all file to memory or keep it on disk virtual void parse_metadata(File&){}; - - // inline fs::path master_fname() const { - // return base_path / fmt::format("{}_master_{}{}", base_name, findex, ext);} - + + + void find_geometry(File&){}; void parse_fname(File&); + template Header read_header(const std::filesystem::path &fname); + + + }; diff --git a/src/file_io/file_factory/JsonFileFactory.cpp b/src/file_io/file_factory/JsonFileFactory.cpp index e62082f..9b46c99 100644 --- a/src/file_io/file_factory/JsonFileFactory.cpp +++ b/src/file_io/file_factory/JsonFileFactory.cpp @@ -3,13 +3,14 @@ #include "helpers.hpp" #include #include - +#include "defs.hpp" #include using json = nlohmann::json; + JsonFileFactory::JsonFileFactory(std::filesystem::path fpath){ if(not is_master_file(fpath)) throw std::runtime_error("Json file is not a master file"); @@ -23,19 +24,21 @@ void JsonFileFactory::parse_metadata(File& file){ ifs >> j; double v = j["Version"]; file.version = fmt::format("{:.1f}", v); - file.type = StringTo(j["Detector Type"].get()); + std::string tmp; + j["Detector Type"].get_to(tmp); + file.type = StringTo(tmp); file.timing_mode = StringTo(j["Timing Mode"].get()); file.total_frames = j["Frames in File"]; file.subfile_cols = j["Pixels"]["x"]; file.subfile_rows = j["Pixels"]["y"]; - if (type_ == DetectorType::Moench) - bitdepth_ = 16; + if (file.type == DetectorType::Moench) + file.bitdepth = 16; else - bitdepth_ = j["Dynamic Range"]; + file.bitdepth = j["Dynamic Range"]; // only Eiger had quad - if (type_ == DetectorType::Eiger) { - quad_ = (j["Quad"] == 1); + if (file.type == DetectorType::Eiger) { + file.quad = (j["Quad"] == 1); } @@ -46,8 +49,12 @@ void JsonFileFactory::parse_metadata(File& file){ File JsonFileFactory::loadFile(){ std::cout<<"Loading json file"<parse_fname(file); this->parse_metadata(file); + file.find_number_of_subfiles(); + this->find_geometry(file); + diff --git a/src/file_io/file_factory/JsonFileFactory.hpp b/src/file_io/file_factory/JsonFileFactory.hpp index 410db1c..42ef35d 100644 --- a/src/file_io/file_factory/JsonFileFactory.hpp +++ b/src/file_io/file_factory/JsonFileFactory.hpp @@ -9,5 +9,6 @@ public: void parse_metadata(File&) override; JsonFileFactory(std::filesystem::path fpath); + };