diff --git a/include/aare/ClusterFinderMT.hpp b/include/aare/ClusterFinderMT.hpp index d4ff001..677c2ee 100644 --- a/include/aare/ClusterFinderMT.hpp +++ b/include/aare/ClusterFinderMT.hpp @@ -41,6 +41,7 @@ class ClusterFinderMT { using CT = typename ClusterType::value_type; size_t m_current_thread{0}; size_t m_n_threads{0}; + bool m_update_pedestal; using Finder = ClusterFinder; using InputQueue = ProducerConsumerQueue; using OutputQueue = ProducerConsumerQueue>; @@ -72,7 +73,8 @@ class ClusterFinderMT { switch (frame->type) { case FrameType::DATA: - cf->find_clusters(frame->data.view(), frame->frame_number); + cf->find_clusters(frame->data.view(), frame->frame_number, + m_update_pedestal); while (!m_output_queues[thread_id]->write( cf->steal_clusters(realloc_same_capacity))) { std::this_thread::sleep_for(m_default_wait); @@ -124,10 +126,13 @@ class ClusterFinderMT { * @param capacity initial capacity of the cluster vector. Should match * expected number of clusters in a frame per frame. * @param n_threads number of threads to use + * @param update_pedestal if true the pedestal will be updated during + * find_clusters */ ClusterFinderMT(Shape<2> image_size, PEDESTAL_TYPE nSigma = 5.0, - size_t capacity = 2000, size_t n_threads = 3) - : m_n_threads(n_threads) { + size_t capacity = 2000, size_t n_threads = 3, + bool update_pedestal = true) + : m_n_threads(n_threads), m_update_pedestal(update_pedestal) { LOG(logDEBUG1) << "ClusterFinderMT: " << "image_size: " << image_size[0] << "x" diff --git a/python/aare/ClusterFinder.py b/python/aare/ClusterFinder.py index eae7ad7..2a5cbe0 100644 --- a/python/aare/ClusterFinder.py +++ b/python/aare/ClusterFinder.py @@ -39,14 +39,14 @@ def ClusterFinder(image_size, cluster_size=(3,3), n_sigma=5, dtype = np.int32, c -def ClusterFinderMT(image_size, cluster_size = (3,3), dtype=np.int32, n_sigma=5, capacity = 1024, n_threads = 3): +def ClusterFinderMT(image_size, cluster_size = (3,3), dtype=np.int32, n_sigma=5, capacity = 1024, n_threads = 3, update_pedestal = True): """ Factory function to create a ClusterFinderMT object. Provides a cleaner syntax for the templated ClusterFinderMT in C++. """ cls = _get_class("ClusterFinderMT", cluster_size, dtype) - return cls(image_size, n_sigma=n_sigma, capacity=capacity, n_threads=n_threads) + return cls(image_size, n_sigma=n_sigma, capacity=capacity, n_threads=n_threads, update_pedestal=update_pedestal) def ClusterCollector(clusterfindermt, dtype=np.int32): diff --git a/python/src/bind_ClusterFinder.hpp b/python/src/bind_ClusterFinder.hpp index da479dc..46739c8 100644 --- a/python/src/bind_ClusterFinder.hpp +++ b/python/src/bind_ClusterFinder.hpp @@ -74,12 +74,14 @@ void define_ClusterFinder(py::module &m, const std::string &typestr) { .def( "find_clusters", [](ClusterFinder &self, - py::array_t frame, uint64_t frame_number) { + py::array_t frame, uint64_t frame_number, + bool update_pedestal) { auto view = make_view_2d(frame); - self.find_clusters(view, frame_number); + self.find_clusters(view, frame_number, update_pedestal); return; }, - py::arg(), py::arg("frame_number") = 0); + py::arg(), py::arg("frame_number") = 0, + py::arg("update_pedestal") = true); } #pragma GCC diagnostic pop \ No newline at end of file diff --git a/python/src/bind_ClusterFinderMT.hpp b/python/src/bind_ClusterFinderMT.hpp index 4bb8101..59bc9b8 100644 --- a/python/src/bind_ClusterFinderMT.hpp +++ b/python/src/bind_ClusterFinderMT.hpp @@ -31,9 +31,10 @@ void define_ClusterFinderMT(py::module &m, const std::string &typestr) { py::class_>( m, class_name.c_str()) - .def(py::init, pd_type, size_t, size_t>(), + .def(py::init, pd_type, size_t, size_t, bool>(), py::arg("image_size"), py::arg("n_sigma") = 5.0, - py::arg("capacity") = 2048, py::arg("n_threads") = 3) + py::arg("capacity") = 2048, py::arg("n_threads") = 3, + py::arg("update_pedestal") = true) .def("push_pedestal_frame", [](ClusterFinderMT &self, py::array_t frame) { diff --git a/src/ClusterFinderMT.test.cpp b/src/ClusterFinderMT.test.cpp index e890481..6fa9622 100644 --- a/src/ClusterFinderMT.test.cpp +++ b/src/ClusterFinderMT.test.cpp @@ -21,9 +21,10 @@ class ClusterFinderMTWrapper public: ClusterFinderMTWrapper(Shape<2> image_size, PEDESTAL_TYPE nSigma = 5.0, - size_t capacity = 2000, size_t n_threads = 3) + size_t capacity = 2000, size_t n_threads = 3, + bool update_pedestal = true) : ClusterFinderMT( - image_size, nSigma, capacity, n_threads) {} + image_size, nSigma, capacity, n_threads, update_pedestal) {} size_t get_m_input_queues_size() const { return this->m_input_queues.size(); @@ -72,7 +73,8 @@ TEST_CASE("multithreaded cluster finder", "[.with-data]") { ClusterFinderMTWrapper cf( {static_cast(file.rows()), static_cast(file.cols())}, - 5, 2000, n_threads); // no idea what frame type is!!! default uint16_t + 5, 2000, n_threads, + true); // no idea what frame type is!!! default uint16_t CHECK(cf.get_m_input_queues_size() == n_threads); CHECK(cf.get_m_output_queues_size() == n_threads);