diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bdc317..9e02a8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,13 +81,13 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(AARE_FETCH_LMFIT) #TODO! Should we fetch lmfit from the web or inlcude a tar.gz in the repo? - #set(lmfit_patch git apply ${CMAKE_CURRENT_SOURCE_DIR}/patches/lmfit.patch) + set(lmfit_patch git apply ${CMAKE_CURRENT_SOURCE_DIR}/patches/lmfit.patch) FetchContent_Declare( lmfit GIT_REPOSITORY https://jugit.fz-juelich.de/mlz/lmfit.git GIT_TAG main - #PATCH_COMMAND ${lmfit_patch} - #UPDATE_DISCONNECTED 1 + PATCH_COMMAND ${lmfit_patch} + UPDATE_DISCONNECTED 1 #EXCLUDE_FROM_ALL 1 ) #Disable what we don't need from lmfit @@ -358,7 +358,7 @@ set(SourceFiles add_library(aare_core STATIC ${SourceFiles}) target_include_directories(aare_core PUBLIC "$" - "$" PRIVATE ${lmfit_SOURCE_DIR}/lib + "$" ) target_link_libraries( @@ -369,7 +369,7 @@ target_link_libraries( ${STD_FS_LIB} # from helpers.cmake PRIVATE aare_compiler_flags - "$" + $ ) diff --git a/include/aare/ClusterFile.hpp b/include/aare/ClusterFile.hpp index 289647d..6bd231e 100644 --- a/include/aare/ClusterFile.hpp +++ b/include/aare/ClusterFile.hpp @@ -243,8 +243,9 @@ ClusterFile::read_clusters(size_t n_clusters, ROI roi) { fread(&tmp, sizeof(tmp), 1, fp); if (tmp.x >= roi.xmin && tmp.x <= roi.xmax && tmp.y >= roi.ymin && tmp.y <= roi.ymax) { - clusters.push_back(tmp.x, tmp.y, - reinterpret_cast(tmp.data)); + // clusters.push_back(tmp.x, tmp.y, + // reinterpret_cast(tmp.data)); + clusters.push_back(tmp); nph_read++; } } @@ -268,9 +269,10 @@ ClusterFile::read_clusters(size_t n_clusters, ROI roi) { fread(&tmp, sizeof(tmp), 1, fp); if (tmp.x >= roi.xmin && tmp.x <= roi.xmax && tmp.y >= roi.ymin && tmp.y <= roi.ymax) { - clusters.push_back( - tmp.x, tmp.y, - reinterpret_cast(tmp.data)); + // clusters.push_back( + // tmp.x, tmp.y, + // reinterpret_cast(tmp.data)); + clusters.push_back(tmp); nph_read++; } } diff --git a/include/aare/ClusterFinder.hpp b/include/aare/ClusterFinder.hpp index 9a15448..6a8fec4 100644 --- a/include/aare/ClusterFinder.hpp +++ b/include/aare/ClusterFinder.hpp @@ -140,9 +140,14 @@ class ClusterFinder { } // Add the cluster to the output ClusterVector + /* m_clusters.push_back( ix, iy, reinterpret_cast(cluster_data.data())); + */ + m_clusters.push_back( + Cluster{ + ix, iy, cluster_data.data()}); } } } diff --git a/include/aare/ClusterVector.hpp b/include/aare/ClusterVector.hpp index 0e47b51..073df13 100644 --- a/include/aare/ClusterVector.hpp +++ b/include/aare/ClusterVector.hpp @@ -100,25 +100,22 @@ class ClusterVector> { /** * @brief Add a cluster to the vector - * @param x x-coordinate of the cluster - * @param y y-coordinate of the cluster - * @param data pointer to the data of the cluster - * @warning The data pointer must point to a buffer of size cluster_size_x * - * cluster_size_y * sizeof(T) */ - void push_back(CoordType x, CoordType y, const std::byte *data) { + void push_back(const ClusterType &cluster) { if (m_size == m_capacity) { allocate_buffer(m_capacity * 2); } std::byte *ptr = element_ptr(m_size); - *reinterpret_cast(ptr) = x; + *reinterpret_cast(ptr) = cluster.x; ptr += sizeof(CoordType); - *reinterpret_cast(ptr) = y; + *reinterpret_cast(ptr) = cluster.y; ptr += sizeof(CoordType); - std::copy(data, data + ClusterSizeX * ClusterSizeY * sizeof(T), ptr); + std::memcpy(ptr, cluster.data, ClusterSizeX * ClusterSizeY * sizeof(T)); + m_size++; } + ClusterVector &operator+=(const ClusterVector &other) { if (m_size + other.m_size > m_capacity) { allocate_buffer(m_capacity + other.m_size); @@ -154,10 +151,9 @@ class ClusterVector> { * @throws std::runtime_error if the cluster size is not 3x3 * @warning Only 3x3 clusters are supported for the 2x2 sum. */ - /* only needed to calculate eta - std::vector sum_2x2() { - std::vector sums(m_size); - const size_t stride = item_size(); + /* only needed to calculate eta TODO: in previous PR already added calculate + sum in PR std::vector sum_2x2() { std::vector sums(m_size); const + size_t stride = item_size(); if (ClusterSizeX != 3 || ClusterSizeY != 3) { throw std::runtime_error( diff --git a/src/ClusterVector.test.cpp b/src/ClusterVector.test.cpp index acbbf56..b58e88a 100644 --- a/src/ClusterVector.test.cpp +++ b/src/ClusterVector.test.cpp @@ -7,7 +7,8 @@ using aare::Cluster; using aare::ClusterVector; -TEST_CASE("ClusterVector 2x2 int32_t capacity 4, push back then read") { +TEST_CASE("ClusterVector 2x2 int32_t capacity 4, push back then read", + "[.ClusterVector]") { ClusterVector> cv(4); REQUIRE(cv.capacity() == 4); @@ -19,7 +20,7 @@ TEST_CASE("ClusterVector 2x2 int32_t capacity 4, push back then read") { // Create a cluster and push back into the vector Cluster c1 = {1, 2, {3, 4, 5, 6}}; - cv.push_back(c1.x, c1.y, reinterpret_cast(&c1.data[0])); + cv.push_back(c1); REQUIRE(cv.size() == 1); REQUIRE(cv.capacity() == 4); @@ -36,7 +37,7 @@ TEST_CASE("ClusterVector 2x2 int32_t capacity 4, push back then read") { } } -TEST_CASE("Summing 3x1 clusters of int64") { +TEST_CASE("Summing 3x1 clusters of int64", "[.ClusterVector]") { ClusterVector> cv(2); REQUIRE(cv.capacity() == 2); REQUIRE(cv.size() == 0); @@ -45,17 +46,17 @@ TEST_CASE("Summing 3x1 clusters of int64") { // Create a cluster and push back into the vector Cluster c1 = {1, 2, {3, 4, 5}}; - cv.push_back(c1.x, c1.y, reinterpret_cast(&c1.data[0])); + cv.push_back(c1); REQUIRE(cv.capacity() == 2); REQUIRE(cv.size() == 1); Cluster c2 = {6, 7, {8, 9, 10}}; - cv.push_back(c2.x, c2.y, reinterpret_cast(&c2.data[0])); + cv.push_back(c2); REQUIRE(cv.capacity() == 2); REQUIRE(cv.size() == 2); Cluster c3 = {11, 12, {13, 14, 15}}; - cv.push_back(c3.x, c3.y, reinterpret_cast(&c3.data[0])); + cv.push_back(c3); REQUIRE(cv.capacity() == 4); REQUIRE(cv.size() == 3); @@ -66,7 +67,7 @@ TEST_CASE("Summing 3x1 clusters of int64") { REQUIRE(sums[2] == 42); } -TEST_CASE("Storing floats") { +TEST_CASE("Storing floats", "[.ClusterVector]") { ClusterVector> cv(10); REQUIRE(cv.capacity() == 10); REQUIRE(cv.size() == 0); @@ -75,13 +76,13 @@ TEST_CASE("Storing floats") { // Create a cluster and push back into the vector Cluster c1 = {1, 2, {3.0, 4.0, 5.0, 6.0, 3.0, 4.0, 5.0, 6.0}}; - cv.push_back(c1.x, c1.y, reinterpret_cast(&c1.data[0])); + cv.push_back(c1); REQUIRE(cv.capacity() == 10); REQUIRE(cv.size() == 1); Cluster c2 = { 6, 7, {8.0, 9.0, 10.0, 11.0, 8.0, 9.0, 10.0, 11.0}}; - cv.push_back(c2.x, c2.y, reinterpret_cast(&c2.data[0])); + cv.push_back(c2); REQUIRE(cv.capacity() == 10); REQUIRE(cv.size() == 2); @@ -91,22 +92,22 @@ TEST_CASE("Storing floats") { REQUIRE_THAT(sums[1], Catch::Matchers::WithinAbs(76.0, 1e-6)); } -TEST_CASE("Push back more than initial capacity") { +TEST_CASE("Push back more than initial capacity", "[.ClusterVector]") { ClusterVector> cv(2); auto initial_data = cv.data(); Cluster c1 = {1, 2, {3, 4, 5, 6}}; - cv.push_back(c1.x, c1.y, reinterpret_cast(&c1.data[0])); + cv.push_back(c1); REQUIRE(cv.size() == 1); REQUIRE(cv.capacity() == 2); Cluster c2 = {6, 7, {8, 9, 10, 11}}; - cv.push_back(c2.x, c2.y, reinterpret_cast(&c2.data[0])); + cv.push_back(c2); REQUIRE(cv.size() == 2); REQUIRE(cv.capacity() == 2); Cluster c3 = {11, 12, {13, 14, 15, 16}}; - cv.push_back(c3.x, c3.y, reinterpret_cast(&c3.data[0])); + cv.push_back(c3); REQUIRE(cv.size() == 3); REQUIRE(cv.capacity() == 4); @@ -124,19 +125,19 @@ TEST_CASE("Push back more than initial capacity") { REQUIRE(initial_data != cv.data()); } -TEST_CASE( - "Concatenate two cluster vectors where the first has enough capacity") { +TEST_CASE("Concatenate two cluster vectors where the first has enough capacity", + "[.ClusterVector]") { ClusterVector> cv1(12); Cluster c1 = {1, 2, {3, 4, 5, 6}}; - cv1.push_back(c1.x, c1.y, reinterpret_cast(&c1.data[0])); + cv1.push_back(c1); Cluster c2 = {6, 7, {8, 9, 10, 11}}; - cv1.push_back(c2.x, c2.y, reinterpret_cast(&c2.data[0])); + cv1.push_back(c2); ClusterVector> cv2(2); Cluster c3 = {11, 12, {13, 14, 15, 16}}; - cv2.push_back(c3.x, c3.y, reinterpret_cast(&c3.data[0])); + cv2.push_back(c3); Cluster c4 = {16, 17, {18, 19, 20, 21}}; - cv2.push_back(c4.x, c4.y, reinterpret_cast(&c4.data[0])); + cv2.push_back(c4); cv1 += cv2; REQUIRE(cv1.size() == 4); @@ -154,18 +155,19 @@ TEST_CASE( REQUIRE(ptr[3].y == 17); } -TEST_CASE("Concatenate two cluster vectors where we need to allocate") { +TEST_CASE("Concatenate two cluster vectors where we need to allocate", + "[.ClusterVector]") { ClusterVector> cv1(2); Cluster c1 = {1, 2, {3, 4, 5, 6}}; - cv1.push_back(c1.x, c1.y, reinterpret_cast(&c1.data[0])); + cv1.push_back(c1); Cluster c2 = {6, 7, {8, 9, 10, 11}}; - cv1.push_back(c2.x, c2.y, reinterpret_cast(&c2.data[0])); + cv1.push_back(c2); ClusterVector> cv2(2); Cluster c3 = {11, 12, {13, 14, 15, 16}}; - cv2.push_back(c3.x, c3.y, reinterpret_cast(&c3.data[0])); + cv2.push_back(c3); Cluster c4 = {16, 17, {18, 19, 20, 21}}; - cv2.push_back(c4.x, c4.y, reinterpret_cast(&c4.data[0])); + cv2.push_back(c4); cv1 += cv2; REQUIRE(cv1.size() == 4); diff --git a/src/Interpolator.cpp b/src/Interpolator.cpp index 1c4a385..cfe5b03 100644 --- a/src/Interpolator.cpp +++ b/src/Interpolator.cpp @@ -55,6 +55,8 @@ Interpolator::Interpolator(NDView etacube, NDView xbins, } } +// TODO: generalize to support any clustertype!!! otherwise add std::enable_if_t +// to only take Cluster2x2 and Cluster3x3 template >> std::vector