From ec611322961b7860f952722e6f9296c762e62f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Thu, 31 Oct 2024 10:29:07 +0100 Subject: [PATCH] WIP --- include/aare/RawFile.hpp | 24 +++++++----- include/aare/defs.hpp | 85 ++++++++++++++++++++++++++++------------ src/RawFile.cpp | 26 ++++++++++++ src/defs.cpp | 8 ++++ 4 files changed, 110 insertions(+), 33 deletions(-) diff --git a/include/aare/RawFile.hpp b/include/aare/RawFile.hpp index d9b7c1c..2e81796 100644 --- a/include/aare/RawFile.hpp +++ b/include/aare/RawFile.hpp @@ -24,6 +24,20 @@ struct ModuleConfig { * @note documentation can also be found in the FileInterface class */ class RawFile : public FileInterface { + size_t n_subfiles{}; + size_t n_subfile_parts{}; + std::vector> subfiles; + size_t subfile_rows{}, subfile_cols{}; + xy m_geometry{}; + std::vector positions; + ModuleConfig cfg{0, 0}; + TimingMode timing_mode{}; + bool quad{false}; + + //Stuff that we might need with Ctb files + uint32_t m_analog_samples{}; + uint32_t m_digital_samples{}; + public: /** * @brief RawFile constructor @@ -176,15 +190,7 @@ class RawFile : public FileInterface { void open_subfiles(); void parse_config(const FileConfig &config); - size_t n_subfiles{}; - size_t n_subfile_parts{}; - std::vector> subfiles; - size_t subfile_rows{}, subfile_cols{}; - xy m_geometry{}; - std::vector positions; - ModuleConfig cfg{0, 0}; - TimingMode timing_mode{}; - bool quad{false}; + }; } // namespace aare \ No newline at end of file diff --git a/include/aare/defs.hpp b/include/aare/defs.hpp index 1db17f2..89d5b19 100644 --- a/include/aare/defs.hpp +++ b/include/aare/defs.hpp @@ -17,8 +17,9 @@ /** * @brief LOCATION macro to get the current location in the code */ -#define LOCATION std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + ":" + std::string(__func__) + ":" - +#define LOCATION \ + std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + \ + ":" + std::string(__func__) + ":" namespace aare { @@ -34,12 +35,15 @@ class Cluster { std::byte *m_data; public: - Cluster(int cluster_sizeX_, int cluster_sizeY_, Dtype dt_ = Dtype(typeid(int32_t))) - : cluster_sizeX(cluster_sizeX_), cluster_sizeY(cluster_sizeY_), dt(dt_) { + Cluster(int cluster_sizeX_, int cluster_sizeY_, + Dtype dt_ = Dtype(typeid(int32_t))) + : cluster_sizeX(cluster_sizeX_), cluster_sizeY(cluster_sizeY_), + dt(dt_) { m_data = new std::byte[cluster_sizeX * cluster_sizeY * dt.bytes()]{}; } Cluster() : Cluster(3, 3) {} - Cluster(const Cluster &other) : Cluster(other.cluster_sizeX, other.cluster_sizeY, other.dt) { + Cluster(const Cluster &other) + : Cluster(other.cluster_sizeX, other.cluster_sizeY, other.dt) { if (this == &other) return; x = other.x; @@ -54,18 +58,23 @@ class Cluster { return *this; } Cluster(Cluster &&other) noexcept - : cluster_sizeX(other.cluster_sizeX), cluster_sizeY(other.cluster_sizeY), x(other.x), y(other.y), dt(other.dt), - m_data(other.m_data) { + : cluster_sizeX(other.cluster_sizeX), + cluster_sizeY(other.cluster_sizeY), x(other.x), y(other.y), + dt(other.dt), m_data(other.m_data) { other.m_data = nullptr; other.dt = Dtype(Dtype::TypeIndex::ERROR); } ~Cluster() { delete[] m_data; } template T get(int idx) { - (sizeof(T) == dt.bytes()) ? 0 : throw std::invalid_argument("[ERROR] Type size mismatch"); + (sizeof(T) == dt.bytes()) + ? 0 + : throw std::invalid_argument("[ERROR] Type size mismatch"); return *reinterpret_cast(m_data + idx * dt.bytes()); } template auto set(int idx, T val) { - (sizeof(T) == dt.bytes()) ? 0 : throw std::invalid_argument("[ERROR] Type size mismatch"); + (sizeof(T) == dt.bytes()) + ? 0 + : throw std::invalid_argument("[ERROR] Type size mismatch"); return memcpy(m_data + idx * dt.bytes(), &val, (size_t)dt.bytes()); } // auto x() const { return x; } @@ -74,10 +83,15 @@ class Cluster { // auto y(int16_t y_) { return y = y_; } template std::string to_string() const { - (sizeof(T) == dt.bytes()) ? 0 : throw std::invalid_argument("[ERROR] Type size mismatch"); - std::string s = "x: " + std::to_string(x) + " y: " + std::to_string(y) + "\nm_data: ["; + (sizeof(T) == dt.bytes()) + ? 0 + : throw std::invalid_argument("[ERROR] Type size mismatch"); + std::string s = "x: " + std::to_string(x) + " y: " + std::to_string(y) + + "\nm_data: ["; for (int i = 0; i < cluster_sizeX * cluster_sizeY; i++) { - s += std::to_string(*reinterpret_cast(m_data + i * dt.bytes())) + " "; + s += std::to_string( + *reinterpret_cast(m_data + i * dt.bytes())) + + " "; } s += "]"; return s; @@ -85,10 +99,12 @@ class Cluster { /** * @brief size of the cluster in bytes when saved to a file */ - size_t size() const { return cluster_sizeX * cluster_sizeY ; } + size_t size() const { return cluster_sizeX * cluster_sizeY; } size_t bytes() const { return cluster_sizeX * cluster_sizeY * dt.bytes(); } auto begin() const { return m_data; } - auto end() const { return m_data + cluster_sizeX * cluster_sizeY * dt.bytes(); } + auto end() const { + return m_data + cluster_sizeX * cluster_sizeY * dt.bytes(); + } std::byte *data() { return m_data; } }; @@ -117,28 +133,49 @@ struct sls_detector_header { } packetMaskStr += "]"; - return "frameNumber: " + std::to_string(frameNumber) + "\n" + "expLength: " + std::to_string(expLength) + "\n" + - "packetNumber: " + std::to_string(packetNumber) + "\n" + "bunchId: " + std::to_string(bunchId) + "\n" + - "timestamp: " + std::to_string(timestamp) + "\n" + "modId: " + std::to_string(modId) + "\n" + - "row: " + std::to_string(row) + "\n" + "column: " + std::to_string(column) + "\n" + - "reserved: " + std::to_string(reserved) + "\n" + "debug: " + std::to_string(debug) + "\n" + - "roundRNumber: " + std::to_string(roundRNumber) + "\n" + "detType: " + std::to_string(detType) + "\n" + - "version: " + std::to_string(version) + "\n" + "packetMask: " + packetMaskStr + "\n"; + return "frameNumber: " + std::to_string(frameNumber) + "\n" + + "expLength: " + std::to_string(expLength) + "\n" + + "packetNumber: " + std::to_string(packetNumber) + "\n" + + "bunchId: " + std::to_string(bunchId) + "\n" + + "timestamp: " + std::to_string(timestamp) + "\n" + + "modId: " + std::to_string(modId) + "\n" + + "row: " + std::to_string(row) + "\n" + + "column: " + std::to_string(column) + "\n" + + "reserved: " + std::to_string(reserved) + "\n" + + "debug: " + std::to_string(debug) + "\n" + + "roundRNumber: " + std::to_string(roundRNumber) + "\n" + + "detType: " + std::to_string(detType) + "\n" + + "version: " + std::to_string(version) + "\n" + + "packetMask: " + packetMaskStr + "\n"; } }; template struct t_xy { T row; T col; - bool operator==(const t_xy &other) const { return row == other.row && col == other.col; } + bool operator==(const t_xy &other) const { + return row == other.row && col == other.col; + } bool operator!=(const t_xy &other) const { return !(*this == other); } - std::string to_string() const { return "{ x: " + std::to_string(row) + " y: " + std::to_string(col) + " }"; } + std::string to_string() const { + return "{ x: " + std::to_string(row) + " y: " + std::to_string(col) + + " }"; + } }; using xy = t_xy; using dynamic_shape = std::vector; -enum class DetectorType { Jungfrau, Eiger, Mythen3, Moench, ChipTestBoard, Unknown }; +enum class DetectorType { + Jungfrau, + Eiger, + Mythen3, + Moench, + Moench03, + Moench03_old, + ChipTestBoard, + Unknown +}; enum class TimingMode { Auto, Trigger }; diff --git a/src/RawFile.cpp b/src/RawFile.cpp index 79cdd02..b8fc036 100644 --- a/src/RawFile.cpp +++ b/src/RawFile.cpp @@ -223,6 +223,28 @@ void RawFile::parse_json_metadata() { } catch (const json::out_of_range &e) { m_bitdepth = 16; } + + try { + m_analog_samples = j.at("Analog Samples"); + }catch (const json::out_of_range &e) { + m_analog_samples = 0; + } + try { + m_digital_samples = j.at("Digital Samples"); + }catch (const json::out_of_range &e) { + m_digital_samples = 0; + } + + //Update detector type for Moench + if (m_type == DetectorType::Moench && m_analog_samples == 0 && m_rows == 400) { + m_type = DetectorType::Moench03; + }else if (m_type == DetectorType::Moench && m_rows == 400 && m_analog_samples == 5000) { + m_type = DetectorType::Moench03_old; + }else{ + throw std::runtime_error(LOCATION + "Could not determine Moench detector type"); + } + + // only Eiger had quad if (m_type == DetectorType::Eiger) { quad = (j["Quad"] == 1); @@ -301,6 +323,10 @@ Frame RawFile::get_frame(size_t frame_index) { auto f = Frame(this->m_rows, this->m_cols, Dtype::from_bitdepth(this->m_bitdepth)); std::byte *frame_buffer = f.data(); get_frame_into(frame_index, frame_buffer); + + //here would be the place to run a transform before returning the frame + if (m_type == DetectorType::Moench03_old) + fmt::print("Moench03_old\n"); return f; } diff --git a/src/defs.cpp b/src/defs.cpp index f3cf9d9..a51104b 100644 --- a/src/defs.cpp +++ b/src/defs.cpp @@ -19,6 +19,10 @@ template <> std::string toString(DetectorType arg) { return "Mythen3"; case DetectorType::Moench: return "Moench"; + case DetectorType::Moench03: + return "Moench03"; + case DetectorType::Moench03_old: + return "Moench03_old"; case DetectorType::ChipTestBoard: return "ChipTestBoard"; default: @@ -41,6 +45,10 @@ template <> DetectorType StringTo(const std::string &arg) { return DetectorType::Mythen3; if (arg == "Moench") return DetectorType::Moench; + if (arg == "Moench03") + return DetectorType::Moench03; + if (arg == "Moench03_old") + return DetectorType::Moench03_old; if (arg == "ChipTestBoard") return DetectorType::ChipTestBoard; throw std::runtime_error("Could not decode dector from: \"" + arg + "\"");