diff --git a/CMakeLists.txt b/CMakeLists.txt index 4772f0b..568d868 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) # General options -option(AARE_PYTHON_BINDINGS "Build python bindings" ON) +option(AARE_PYTHON_BINDINGS "Build python bindings" OFF) option(AARE_TESTS "Build tests" OFF) option(AARE_BENCHMARKS "Build benchmarks" OFF) option(AARE_EXAMPLES "Build examples" OFF) @@ -307,7 +307,8 @@ endif() set(PUBLICHEADERS include/aare/ArrayExpr.hpp - include/aare/ClusterFinder.hpp + include/aare/Cluster.hpp + #include/aare/ClusterFinder.hpp include/aare/ClusterFile.hpp include/aare/CtbRawFile.hpp include/aare/ClusterVector.hpp @@ -328,7 +329,7 @@ set(PUBLICHEADERS include/aare/RawFile.hpp include/aare/RawMasterFile.hpp include/aare/RawSubFile.hpp - include/aare/VarClusterFinder.hpp + #include/aare/VarClusterFinder.hpp include/aare/utils/task.hpp ) @@ -336,7 +337,7 @@ set(PUBLICHEADERS set(SourceFiles ${CMAKE_CURRENT_SOURCE_DIR}/src/CtbRawFile.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFile.cpp + #${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/defs.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Dtype.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/decode.cpp @@ -394,8 +395,9 @@ if(AARE_TESTS) ${CMAKE_CURRENT_SOURCE_DIR}/src/RawMasterFile.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/NDArray.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/NDView.test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFinder.test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterVector.test.cpp + #${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFinder.test.cpp + #${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterVector.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Cluster.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Pedestal.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyHelpers.test.cpp diff --git a/include/aare/ClusterFile.hpp b/include/aare/ClusterFile.hpp index d61ee2b..3a7dab8 100644 --- a/include/aare/ClusterFile.hpp +++ b/include/aare/ClusterFile.hpp @@ -28,10 +28,11 @@ typedef enum { pTopRight = 8 } pixel; +// TODO: maybe template this!!!!!! why int32_t???? struct Eta2 { double x; double y; - corner c; + int c; int32_t sum; }; @@ -131,22 +132,22 @@ int analyze_cluster(Cluster &cl, int32_t *t2, int32_t *t3, char *quad, double *eta2x, double *eta2y, double *eta3x, double *eta3y); -template >> -NDArray calculate_eta2(ClusterVector &clusters); +// template >> +// NDArray calculate_eta2(ClusterVector &clusters); // TODO: do we need rquire clauses? -template Eta2 calculate_eta2(const Cluster &cl); +// template Eta2 calculate_eta2(const Cluster &cl); -template Eta2 calculate_eta2(const Cluster &cl); +// template Eta2 calculate_eta2(const Cluster &cl); -template >> -Eta2 calculate_eta2(const ClusterType &cl); +// template >> +// Eta2 calculate_eta2(const ClusterType &cl); -template -Eta2 calculate_eta2( - const Cluster &cl); +// template +// Eta2 calculate_eta2( +// const Cluster &cl); template ClusterFile::ClusterFile( @@ -379,7 +380,7 @@ NDArray calculate_eta2(const ClusterVector &clusters) { NDArray eta2({static_cast(clusters.size()), 2}); for (size_t i = 0; i < clusters.size(); i++) { - auto e = calculate_eta2(clusters.at(i)); + auto e = calculate_eta2(clusters.at(i)); eta2(i, 0) = e.x; eta2(i, 1) = e.y; } @@ -417,25 +418,23 @@ Eta2 calculate_eta2( eta.sum = sum_2x2_subcluster[c]; - eta.x = static_cast(cl.data[(c + 1) * ClusterSizeX + 1]) / - (cl.data[0] + cl.data[1]); + size_t index_bottom_left_max_2x2_subcluster = + (int(c / (ClusterSizeX - 1))) * ClusterSizeX + c % (ClusterSizeX - 1); - size_t index_top_left_2x2_subcluster = - (int(c / (ClusterSizeX - 1)) + 1) * ClusterSizeX + - c % (ClusterSizeX - 1) * 2 + 1; - if ((cl.data[index_top_left_2x2_subcluster] + - cl.data[index_top_left_2x2_subcluster - 1]) != 0) - eta.x = - static_cast(cl.data[index_top_left_2x2_subcluster] / - (cl.data[index_top_left_2x2_subcluster] + - cl.data[index_top_left_2x2_subcluster - 1])); + if ((cl.data[index_bottom_left_max_2x2_subcluster] + + cl.data[index_bottom_left_max_2x2_subcluster + 1]) != 0) + eta.x = static_cast( + cl.data[index_bottom_left_max_2x2_subcluster + 1]) / + (cl.data[index_bottom_left_max_2x2_subcluster] + + cl.data[index_bottom_left_max_2x2_subcluster + 1]); - if ((cl.data[index_top_left_2x2_subcluster] + - cl.data[index_top_left_2x2_subcluster - ClusterSizeX]) != 0) - eta.y = static_cast( - cl.data[index_top_left_2x2_subcluster] / - (cl.data[index_top_left_2x2_subcluster] + - cl.data[index_top_left_2x2_subcluster - ClusterSizeX])); + if ((cl.data[index_bottom_left_max_2x2_subcluster] + + cl.data[index_bottom_left_max_2x2_subcluster + ClusterSizeX]) != 0) + eta.y = + static_cast( + cl.data[index_bottom_left_max_2x2_subcluster + ClusterSizeX]) / + (cl.data[index_bottom_left_max_2x2_subcluster] + + cl.data[index_bottom_left_max_2x2_subcluster + ClusterSizeX]); eta.c = c; // TODO only supported for 2x2 and 3x3 clusters -> at least no // underyling enum class @@ -446,6 +445,7 @@ Eta2 calculate_eta2( * @brief Calculate the eta2 values for a 3x3 cluster and return them in a Eta2 * struct containing etay, etax and the corner of the cluster. */ +/* template Eta2 calculate_eta2(const Cluster &cl) { Eta2 eta{}; @@ -489,7 +489,9 @@ template Eta2 calculate_eta2(const Cluster &cl) { } return eta; } +*/ +/* template Eta2 calculate_eta2(const Cluster &cl) { Eta2 eta{}; @@ -499,6 +501,7 @@ template Eta2 calculate_eta2(const Cluster &cl) { eta.c = cBottomLeft; // TODO! This is not correct, but need to put something return eta; } +*/ // TODO complicated API simplify? int analyze_cluster(Cluster &cl, int32_t *t2, int32_t *t3, diff --git a/src/Cluster.test.cpp b/src/Cluster.test.cpp new file mode 100644 index 0000000..de53e6e --- /dev/null +++ b/src/Cluster.test.cpp @@ -0,0 +1,65 @@ +/************************************************ + * @file test-Cluster.cpp + * @short test case for generic Cluster, ClusterVector, and calculate_eta2 + ***********************************************/ + +#include "aare/Cluster.hpp" +#include "aare/ClusterFile.hpp" + +// #include "catch.hpp" +#include +#include +#include + +using namespace aare; + +/* +TEST_CASE("Correct Instantiation of Cluster and ClusterVector", + "[.cluster][.instantiation]") { + + + REQUIRE(not std::is_constructible_v>); + + // all 1,2 and 0,4 are not defined!! + std::make_tuple(Cluster, ), + std::make_tuple(Cluster, ) + + +} +*/ + +using ClusterTypes = + std::variant, Cluster, Cluster, + Cluster, Cluster>; + +TEST_CASE("calculate_eta2", "[.cluster][.instantiation]") { + + // weird expect cluster_start to be in bottom_left corner -> row major -> + // check how its used should be an image!! + + auto [cluster, expected_eta] = GENERATE( + std::make_tuple(ClusterTypes{Cluster{0, 0, {1, 2, 3, 1}}}, + Eta2{2. / 3, 3. / 4, corner::cBottomLeft, 7}), + std::make_tuple( + ClusterTypes{Cluster{0, 0, {1, 2, 3, 4, 5, 6, 1, 2, 7}}}, + Eta2{6. / 11, 2. / 7, corner::cTopRight, 20}), + std::make_tuple(ClusterTypes{Cluster{ + 0, 0, {1, 6, 7, 6, 5, 4, 3, 2, 1, 8, 8, 9, 2, + 1, 4, 5, 6, 7, 8, 4, 1, 1, 1, 1, 1}}}, + Eta2{9. / 17, 5. / 13, 8, 28}), + std::make_tuple( + ClusterTypes{Cluster{0, 0, {1, 4, 7, 2, 5, 6, 4, 3}}}, + Eta2{7. / 11, 6. / 10, 1, 21}), + std::make_tuple( + ClusterTypes{Cluster{0, 0, {1, 3, 2, 3, 4, 2}}}, + Eta2{3. / 5, 4. / 6, 1, 11})); + + Eta2 eta = std::visit( + [](const auto &clustertype) { return calculate_eta2(clustertype); }, + cluster); + + CHECK(eta.x == expected_eta.x); + CHECK(eta.y == expected_eta.y); + CHECK(eta.c == expected_eta.c); + CHECK(eta.sum == expected_eta.sum); +}