From d7ef9bb1d8e933a6059bef9236a45f2150cc28d4 Mon Sep 17 00:00:00 2001 From: Mazzoleni Alice Francesca Date: Thu, 3 Apr 2025 11:36:15 +0200 Subject: [PATCH] missed some refactoring of datatypes --- include/aare/Cluster.hpp | 6 +++--- include/aare/ClusterCollector.hpp | 2 +- include/aare/ClusterFileSink.hpp | 6 +++--- include/aare/ClusterFinder.hpp | 27 ++++++++++++++------------- include/aare/ClusterFinderMT.hpp | 22 ++++++++++++++-------- include/aare/ClusterVector.hpp | 14 ++++++++++++++ include/aare/GainMap.hpp | 1 - 7 files changed, 49 insertions(+), 29 deletions(-) diff --git a/include/aare/Cluster.hpp b/include/aare/Cluster.hpp index 46be10d..ca2e01f 100644 --- a/include/aare/Cluster.hpp +++ b/include/aare/Cluster.hpp @@ -100,8 +100,8 @@ struct is_cluster> : std::true_type {}; // Cluster template constexpr bool is_cluster_v = is_cluster::value; -template >> +template +// typename = std::enable_if_t>> struct extract_template_arguments; // Forward declaration // helper struct to extract template argument @@ -110,7 +110,7 @@ template > { - using type = T; + using value_type = T; static constexpr int cluster_size_x = ClusterSizeX; static constexpr int cluster_size_y = ClusterSizeY; using coordtype = CoordType; diff --git a/include/aare/ClusterCollector.hpp b/include/aare/ClusterCollector.hpp index 0a53cd0..cb49f58 100644 --- a/include/aare/ClusterCollector.hpp +++ b/include/aare/ClusterCollector.hpp @@ -35,7 +35,7 @@ class ClusterCollector { } public: - ClusterCollector(ClusterFinderMT *source) { + ClusterCollector(ClusterFinderMT *source) { m_source = source->sink(); m_thread = std::thread(&ClusterCollector::process, this); } diff --git a/include/aare/ClusterFileSink.hpp b/include/aare/ClusterFileSink.hpp index 520fbe3..810e63c 100644 --- a/include/aare/ClusterFileSink.hpp +++ b/include/aare/ClusterFileSink.hpp @@ -10,8 +10,8 @@ namespace aare { template class ClusterFileSink { + typename = std::enable_if_t>> +class ClusterFileSink { ProducerConsumerQueue> *m_source; std::atomic m_stop_requested{false}; std::atomic m_stopped{true}; @@ -46,7 +46,7 @@ template *source, + ClusterFileSink(ClusterFinderMT *source, const std::filesystem::path &fname) { m_source = source->sink(); m_thread = std::thread(&ClusterFileSink::process, this); diff --git a/include/aare/ClusterFinder.hpp b/include/aare/ClusterFinder.hpp index 19ada67..120d39d 100644 --- a/include/aare/ClusterFinder.hpp +++ b/include/aare/ClusterFinder.hpp @@ -10,16 +10,21 @@ namespace aare { -template +template , + typename FRAME_TYPE = uint16_t, typename PEDESTAL_TYPE = double> class ClusterFinder { Shape<2> m_image_size; const PEDESTAL_TYPE m_nSigma; const PEDESTAL_TYPE c2; const PEDESTAL_TYPE c3; Pedestal m_pedestal; - ClusterVector> m_clusters; + ClusterVector m_clusters; + + static const uint8_t ClusterSizeX = + extract_template_arguments::cluster_size_x; + static const uint8_t ClusterSizeY = + extract_template_arguments::cluster_size_x; + using CT = typename extract_template_arguments::value_type; public: /** @@ -52,16 +57,13 @@ class ClusterFinder { * same capacity as the old one * */ - ClusterVector> + ClusterVector steal_clusters(bool realloc_same_capacity = false) { - ClusterVector> tmp = - std::move(m_clusters); + ClusterVector tmp = std::move(m_clusters); if (realloc_same_capacity) - m_clusters = ClusterVector>( - tmp.capacity()); + m_clusters = ClusterVector(tmp.capacity()); else - m_clusters = - ClusterVector>{}; + m_clusters = ClusterVector{}; return tmp; } void find_clusters(NDView frame, uint64_t frame_number = 0) { @@ -147,8 +149,7 @@ class ClusterFinder { // Add the cluster to the output ClusterVector m_clusters.push_back( - Cluster{ - ix, iy, cluster_data.data()}); + ClusterType{ix, iy, cluster_data.data()}); } } } diff --git a/include/aare/ClusterFinderMT.hpp b/include/aare/ClusterFinderMT.hpp index 1efb843..62046b7 100644 --- a/include/aare/ClusterFinderMT.hpp +++ b/include/aare/ClusterFinderMT.hpp @@ -30,14 +30,16 @@ struct FrameWrapper { * @tparam PEDESTAL_TYPE type of the pedestal data * @tparam CT type of the cluster data */ -template +template , + typename FRAME_TYPE = uint16_t, typename PEDESTAL_TYPE = double> class ClusterFinderMT { + + using CT = typename extract_template_arguments::value_type; size_t m_current_thread{0}; size_t m_n_threads{0}; - using Finder = ClusterFinder; + using Finder = ClusterFinder; using InputQueue = ProducerConsumerQueue; - using OutputQueue = ProducerConsumerQueue>; + using OutputQueue = ProducerConsumerQueue>; std::vector> m_input_queues; std::vector> m_output_queues; @@ -66,7 +68,8 @@ class ClusterFinderMT { switch (frame->type) { case FrameType::DATA: cf->find_clusters(frame->data.view(), frame->frame_number); - m_output_queues[thread_id]->write(cf->steal_clusters(realloc_same_capacity)); + m_output_queues[thread_id]->write( + cf->steal_clusters(realloc_same_capacity)); break; case FrameType::PEDESTAL: @@ -127,15 +130,18 @@ class ClusterFinderMT { m_input_queues.emplace_back(std::make_unique(200)); m_output_queues.emplace_back(std::make_unique(200)); } - //TODO! Should we start automatically? + // TODO! Should we start automatically? start(); } /** * @brief Return the sink queue where all the clusters are collected - * @warning You need to empty this queue otherwise the cluster finder will wait forever + * @warning You need to empty this queue otherwise the cluster finder will + * wait forever */ - ProducerConsumerQueue> *sink() { return &m_sink; } + ProducerConsumerQueue> *sink() { + return &m_sink; + } /** * @brief Start all processing threads diff --git a/include/aare/ClusterVector.hpp b/include/aare/ClusterVector.hpp index ca2fd4d..0beae3d 100644 --- a/include/aare/ClusterVector.hpp +++ b/include/aare/ClusterVector.hpp @@ -148,6 +148,20 @@ class ClusterVector> { return sums; } + /** + * @brief Sum the pixels in the 2x2 subcluster with the biggest pixel sum in + * each cluster + * @return std::vector vector of sums for each cluster + */ //TODO if underlying container is a vector use std::for_each + std::vector sum_2x2() { + std::vector sums_2x2(m_size); + + for (size_t i = 0; i < m_size; i++) { + sums_2x2[i] = at(i).max_sum_2x2; + } + return sums_2x2; + } + /** * @brief Return the number of clusters in the vector */ diff --git a/include/aare/GainMap.hpp b/include/aare/GainMap.hpp index 9eb7c11..a60c131 100644 --- a/include/aare/GainMap.hpp +++ b/include/aare/GainMap.hpp @@ -26,7 +26,6 @@ class GainMap { typename = std::enable_if_t>> void apply_gain_map(ClusterVector &clustervec) { // in principle we need to know the size of the image for this lookup - // TODO! check orientations size_t ClusterSizeX = clustervec.cluster_size_x(); size_t ClusterSizeY = clustervec.cluster_size_y();