missed some refactoring of datatypes
Some checks failed
Build the package using cmake then documentation / build (ubuntu-latest, 3.12) (push) Failing after 49s

This commit is contained in:
Mazzoleni Alice Francesca 2025-04-03 11:36:15 +02:00
parent de9fc16e89
commit d7ef9bb1d8
7 changed files with 49 additions and 29 deletions

View File

@ -100,8 +100,8 @@ struct is_cluster<Cluster<T, X, Y, CoordType>> : std::true_type {}; // Cluster
template <typename T> constexpr bool is_cluster_v = is_cluster<T>::value; template <typename T> constexpr bool is_cluster_v = is_cluster<T>::value;
template <typename ClusterType, template <typename ClusterType>
typename = std::enable_if_t<is_cluster_v<ClusterType>>> // typename = std::enable_if_t<is_cluster_v<ClusterType>>>
struct extract_template_arguments; // Forward declaration struct extract_template_arguments; // Forward declaration
// helper struct to extract template argument // helper struct to extract template argument
@ -110,7 +110,7 @@ template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
struct extract_template_arguments< struct extract_template_arguments<
Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> { Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
using type = T; using value_type = T;
static constexpr int cluster_size_x = ClusterSizeX; static constexpr int cluster_size_x = ClusterSizeX;
static constexpr int cluster_size_y = ClusterSizeY; static constexpr int cluster_size_y = ClusterSizeY;
using coordtype = CoordType; using coordtype = CoordType;

View File

@ -35,7 +35,7 @@ class ClusterCollector {
} }
public: public:
ClusterCollector(ClusterFinderMT<uint16_t, double, int32_t> *source) { ClusterCollector(ClusterFinderMT<ClusterType, uint16_t, double> *source) {
m_source = source->sink(); m_source = source->sink();
m_thread = std::thread(&ClusterCollector::process, this); m_thread = std::thread(&ClusterCollector::process, this);
} }

View File

@ -10,8 +10,8 @@
namespace aare { namespace aare {
template <typename ClusterType, template <typename ClusterType,
typename = std::enable_if_t < typename = std::enable_if_t<is_cluster_v<ClusterType>>>
is_cluster_v<ClusterType> class ClusterFileSink { class ClusterFileSink {
ProducerConsumerQueue<ClusterVector<ClusterType>> *m_source; ProducerConsumerQueue<ClusterVector<ClusterType>> *m_source;
std::atomic<bool> m_stop_requested{false}; std::atomic<bool> m_stop_requested{false};
std::atomic<bool> m_stopped{true}; std::atomic<bool> m_stopped{true};
@ -46,7 +46,7 @@ template <typename ClusterType,
} }
public: public:
ClusterFileSink(ClusterFinderMT<uint16_t, double, int32_t> *source, ClusterFileSink(ClusterFinderMT<ClusterType, uint16_t, double> *source,
const std::filesystem::path &fname) { const std::filesystem::path &fname) {
m_source = source->sink(); m_source = source->sink();
m_thread = std::thread(&ClusterFileSink::process, this); m_thread = std::thread(&ClusterFileSink::process, this);

View File

@ -10,16 +10,21 @@
namespace aare { namespace aare {
template <typename CT = int32_t, uint8_t ClusterSizeX = 3, template <typename ClusterType = Cluster<int32_t, 3, 3>,
uint8_t ClusterSizeY = 3, typename FRAME_TYPE = uint16_t, typename FRAME_TYPE = uint16_t, typename PEDESTAL_TYPE = double>
typename PEDESTAL_TYPE = double>
class ClusterFinder { class ClusterFinder {
Shape<2> m_image_size; Shape<2> m_image_size;
const PEDESTAL_TYPE m_nSigma; const PEDESTAL_TYPE m_nSigma;
const PEDESTAL_TYPE c2; const PEDESTAL_TYPE c2;
const PEDESTAL_TYPE c3; const PEDESTAL_TYPE c3;
Pedestal<PEDESTAL_TYPE> m_pedestal; Pedestal<PEDESTAL_TYPE> m_pedestal;
ClusterVector<Cluster<CT, ClusterSizeX, ClusterSizeY>> m_clusters; ClusterVector<ClusterType> m_clusters;
static const uint8_t ClusterSizeX =
extract_template_arguments<ClusterType>::cluster_size_x;
static const uint8_t ClusterSizeY =
extract_template_arguments<ClusterType>::cluster_size_x;
using CT = typename extract_template_arguments<ClusterType>::value_type;
public: public:
/** /**
@ -52,16 +57,13 @@ class ClusterFinder {
* same capacity as the old one * same capacity as the old one
* *
*/ */
ClusterVector<Cluster<CT, ClusterSizeX, ClusterSizeY>> ClusterVector<ClusterType>
steal_clusters(bool realloc_same_capacity = false) { steal_clusters(bool realloc_same_capacity = false) {
ClusterVector<Cluster<CT, ClusterSizeX, ClusterSizeY>> tmp = ClusterVector<ClusterType> tmp = std::move(m_clusters);
std::move(m_clusters);
if (realloc_same_capacity) if (realloc_same_capacity)
m_clusters = ClusterVector<Cluster<CT, ClusterSizeX, ClusterSizeY>>( m_clusters = ClusterVector<ClusterType>(tmp.capacity());
tmp.capacity());
else else
m_clusters = m_clusters = ClusterVector<ClusterType>{};
ClusterVector<Cluster<CT, ClusterSizeX, ClusterSizeY>>{};
return tmp; return tmp;
} }
void find_clusters(NDView<FRAME_TYPE, 2> frame, uint64_t frame_number = 0) { void find_clusters(NDView<FRAME_TYPE, 2> frame, uint64_t frame_number = 0) {
@ -147,8 +149,7 @@ class ClusterFinder {
// Add the cluster to the output ClusterVector // Add the cluster to the output ClusterVector
m_clusters.push_back( m_clusters.push_back(
Cluster<CT, ClusterSizeX, ClusterSizeY>{ ClusterType{ix, iy, cluster_data.data()});
ix, iy, cluster_data.data()});
} }
} }
} }

View File

@ -30,14 +30,16 @@ struct FrameWrapper {
* @tparam PEDESTAL_TYPE type of the pedestal data * @tparam PEDESTAL_TYPE type of the pedestal data
* @tparam CT type of the cluster data * @tparam CT type of the cluster data
*/ */
template <typename FRAME_TYPE = uint16_t, typename PEDESTAL_TYPE = double, template <typename ClusterType = Cluster<int32_t, 3, 3>,
typename CT = int32_t> typename FRAME_TYPE = uint16_t, typename PEDESTAL_TYPE = double>
class ClusterFinderMT { class ClusterFinderMT {
using CT = typename extract_template_arguments<ClusterType>::value_type;
size_t m_current_thread{0}; size_t m_current_thread{0};
size_t m_n_threads{0}; size_t m_n_threads{0};
using Finder = ClusterFinder<FRAME_TYPE, PEDESTAL_TYPE, CT>; using Finder = ClusterFinder<ClusterType, FRAME_TYPE, PEDESTAL_TYPE>;
using InputQueue = ProducerConsumerQueue<FrameWrapper>; using InputQueue = ProducerConsumerQueue<FrameWrapper>;
using OutputQueue = ProducerConsumerQueue<ClusterVector<int>>; using OutputQueue = ProducerConsumerQueue<ClusterVector<ClusterType>>;
std::vector<std::unique_ptr<InputQueue>> m_input_queues; std::vector<std::unique_ptr<InputQueue>> m_input_queues;
std::vector<std::unique_ptr<OutputQueue>> m_output_queues; std::vector<std::unique_ptr<OutputQueue>> m_output_queues;
@ -66,7 +68,8 @@ class ClusterFinderMT {
switch (frame->type) { switch (frame->type) {
case FrameType::DATA: case FrameType::DATA:
cf->find_clusters(frame->data.view(), frame->frame_number); 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; break;
case FrameType::PEDESTAL: case FrameType::PEDESTAL:
@ -133,9 +136,12 @@ class ClusterFinderMT {
/** /**
* @brief Return the sink queue where all the clusters are collected * @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<ClusterVector<int>> *sink() { return &m_sink; } ProducerConsumerQueue<ClusterVector<ClusterType>> *sink() {
return &m_sink;
}
/** /**
* @brief Start all processing threads * @brief Start all processing threads

View File

@ -148,6 +148,20 @@ class ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
return sums; return sums;
} }
/**
* @brief Sum the pixels in the 2x2 subcluster with the biggest pixel sum in
* each cluster
* @return std::vector<T> vector of sums for each cluster
*/ //TODO if underlying container is a vector use std::for_each
std::vector<T> sum_2x2() {
std::vector<T> 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 * @brief Return the number of clusters in the vector
*/ */

View File

@ -26,7 +26,6 @@ class GainMap {
typename = std::enable_if_t<is_cluster_v<ClusterType>>> typename = std::enable_if_t<is_cluster_v<ClusterType>>>
void apply_gain_map(ClusterVector<ClusterType> &clustervec) { void apply_gain_map(ClusterVector<ClusterType> &clustervec) {
// in principle we need to know the size of the image for this lookup // 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 ClusterSizeX = clustervec.cluster_size_x();
size_t ClusterSizeY = clustervec.cluster_size_y(); size_t ClusterSizeY = clustervec.cluster_size_y();