From eebeb36c4bd97348dfcf53d60239598225f18a03 Mon Sep 17 00:00:00 2001 From: "Alexander J. Pfleger" <70842573+AJPfleger@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:54:14 +0200 Subject: [PATCH 1/5] refactor: replace `Acts::min_max` with `std::ranges::minmax_element` (#3601) --- Core/include/Acts/Utilities/Helpers.hpp | 22 ++++--------------- .../detail/CylindricalDetectorHelper.cpp | 6 ++--- .../UnitTests/Core/Utilities/HelpersTests.cpp | 14 ------------ 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/Core/include/Acts/Utilities/Helpers.hpp b/Core/include/Acts/Utilities/Helpers.hpp index 5d9d2ab22eb..99d068cf361 100644 --- a/Core/include/Acts/Utilities/Helpers.hpp +++ b/Core/include/Acts/Utilities/Helpers.hpp @@ -164,21 +164,7 @@ T clampValue(U value) { static_cast(std::numeric_limits::max())); } -/// Return min/max from a (optionally) sorted series, obsolete with C++20 -/// (ranges) -/// -/// @tparam T a numeric series -/// -/// @param tseries is the number series -/// -/// @return [ min, max ] in an array of length 2 -template -std::array min_max(const T& tseries) { - return {*std::min_element(tseries.begin(), tseries.end()), - *std::max_element(tseries.begin(), tseries.end())}; -} - -/// Return range and medium of a sorted numeric series +/// Return range and medium of an unsorted numeric series /// /// @tparam T a numeric series /// @@ -187,9 +173,9 @@ std::array min_max(const T& tseries) { /// @return [ range, medium ] in an tuple template std::tuple range_medium(const T& tseries) { - auto [min, max] = min_max(tseries); - typename T::value_type range = (max - min); - ActsScalar medium = static_cast((max + min) * 0.5); + auto [minIt, maxIt] = std::ranges::minmax_element(tseries); + typename T::value_type range = (*maxIt - *minIt); + ActsScalar medium = static_cast((*maxIt + *minIt) * 0.5); return std::tie(range, medium); } diff --git a/Core/src/Detector/detail/CylindricalDetectorHelper.cpp b/Core/src/Detector/detail/CylindricalDetectorHelper.cpp index 1a15d527765..7fce725b4f6 100644 --- a/Core/src/Detector/detail/CylindricalDetectorHelper.cpp +++ b/Core/src/Detector/detail/CylindricalDetectorHelper.cpp @@ -88,12 +88,12 @@ Acts::Experimental::PortalReplacement createDiscReplacement( ? Acts::BinningValue::binR : Acts::BinningValue::binPhi; // Estimate ranges - auto [minR, maxR] = Acts::min_max(rBoundaries); + auto [minRit, maxRit] = std::ranges::minmax_element(rBoundaries); auto [sectorPhi, avgPhi] = Acts::range_medium(phiBoundaries); // Transform and bounds - auto bounds = - std::make_unique(minR, maxR, 0.5 * sectorPhi, avgPhi); + auto bounds = std::make_unique(*minRit, *maxRit, + 0.5 * sectorPhi, avgPhi); // A new surface on the negative side over the full range auto surface = Acts::Surface::makeShared( transform, std::move(bounds)); diff --git a/Tests/UnitTests/Core/Utilities/HelpersTests.cpp b/Tests/UnitTests/Core/Utilities/HelpersTests.cpp index 28390a9089c..a92defd466c 100644 --- a/Tests/UnitTests/Core/Utilities/HelpersTests.cpp +++ b/Tests/UnitTests/Core/Utilities/HelpersTests.cpp @@ -193,20 +193,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(BlockedMatrixMultiplication, Matrices, } } -BOOST_AUTO_TEST_CASE(min_max) { - std::vector ordered = {-3., -2., -1., 0., 1., 2., 3.}; - auto [min0, max0] = Acts::min_max(ordered); - - CHECK_CLOSE_ABS(min0, -3., std::numeric_limits::epsilon()); - CHECK_CLOSE_ABS(max0, 3., std::numeric_limits::epsilon()); - - std::vector unordered = {3., -3., -2., -1., 0., 1., 2.}; - auto [min1, max1] = Acts::min_max(unordered); - - CHECK_CLOSE_ABS(min1, -3., std::numeric_limits::epsilon()); - CHECK_CLOSE_ABS(max1, 3., std::numeric_limits::epsilon()); -} - BOOST_AUTO_TEST_CASE(range_medium) { std::vector ordered = {-3., -2., -1., 0., 1., 2., 3.}; auto [range0, medium0] = Acts::range_medium(ordered); From c836ca50bbcad3365e60a211d88158d7bc7e962a Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Tue, 10 Sep 2024 17:46:20 +0200 Subject: [PATCH 2/5] refactor!: Rename `EigenStepper` dense extension (#3603) During Athena integration I realized that the naming is a bit inconsistent with `EigenStepperDefaultExtension` and `EigenStepperDenseEnvironmentExtension`. I think `EigenStepperDenseExtension` fits better. --- ...ion.hpp => EigenStepperDenseExtension.hpp} | 2 +- .../PropagationDenseConstant.cpp | 4 ++-- .../Core/Propagator/EigenStepperTests.cpp | 20 +++++++++---------- .../Core/Propagator/PropagatorTests.cpp | 4 ++-- docs/core/propagation.md | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) rename Core/include/Acts/Propagator/{EigenStepperDenseEnvironmentExtension.hpp => EigenStepperDenseExtension.hpp} (99%) diff --git a/Core/include/Acts/Propagator/EigenStepperDenseEnvironmentExtension.hpp b/Core/include/Acts/Propagator/EigenStepperDenseExtension.hpp similarity index 99% rename from Core/include/Acts/Propagator/EigenStepperDenseEnvironmentExtension.hpp rename to Core/include/Acts/Propagator/EigenStepperDenseExtension.hpp index befab8f96ce..155bc1637bc 100644 --- a/Core/include/Acts/Propagator/EigenStepperDenseEnvironmentExtension.hpp +++ b/Core/include/Acts/Propagator/EigenStepperDenseExtension.hpp @@ -25,7 +25,7 @@ namespace Acts { /// ioninisation, bremsstrahlung, pair production and photonuclear interaction /// in the propagation and the jacobian. These effects will only occur if the /// propagation is in a TrackingVolume with attached material. -struct EigenStepperDenseEnvironmentExtension { +struct EigenStepperDenseExtension { using Scalar = ActsScalar; /// @brief Vector3 replacement for the custom scalar type using ThisVector3 = Eigen::Matrix; diff --git a/Tests/IntegrationTests/PropagationDenseConstant.cpp b/Tests/IntegrationTests/PropagationDenseConstant.cpp index c27e38088b4..e95b0bc01a1 100644 --- a/Tests/IntegrationTests/PropagationDenseConstant.cpp +++ b/Tests/IntegrationTests/PropagationDenseConstant.cpp @@ -16,7 +16,7 @@ #include "Acts/MagneticField/MagneticFieldContext.hpp" #include "Acts/Material/HomogeneousVolumeMaterial.hpp" #include "Acts/Propagator/EigenStepper.hpp" -#include "Acts/Propagator/EigenStepperDenseEnvironmentExtension.hpp" +#include "Acts/Propagator/EigenStepperDenseExtension.hpp" #include "Acts/Propagator/Navigator.hpp" #include "Acts/Propagator/Propagator.hpp" #include "Acts/Propagator/RiddersPropagator.hpp" @@ -34,7 +34,7 @@ namespace ds = ActsTests::PropagationDatasets; using namespace Acts::UnitLiterals; using MagneticField = Acts::ConstantBField; -using Stepper = Acts::EigenStepper; +using Stepper = Acts::EigenStepper; using Propagator = Acts::Propagator; using RiddersPropagator = Acts::RiddersPropagator; diff --git a/Tests/UnitTests/Core/Propagator/EigenStepperTests.cpp b/Tests/UnitTests/Core/Propagator/EigenStepperTests.cpp index fc7175aaf85..bea4039ad3d 100644 --- a/Tests/UnitTests/Core/Propagator/EigenStepperTests.cpp +++ b/Tests/UnitTests/Core/Propagator/EigenStepperTests.cpp @@ -35,7 +35,7 @@ #include "Acts/Propagator/ConstrainedStep.hpp" #include "Acts/Propagator/EigenStepper.hpp" #include "Acts/Propagator/EigenStepperDefaultExtension.hpp" -#include "Acts/Propagator/EigenStepperDenseEnvironmentExtension.hpp" +#include "Acts/Propagator/EigenStepperDenseExtension.hpp" #include "Acts/Propagator/EigenStepperError.hpp" #include "Acts/Propagator/MaterialInteractor.hpp" #include "Acts/Propagator/Navigator.hpp" @@ -537,7 +537,7 @@ BOOST_AUTO_TEST_CASE(eigen_stepper_test) { } /// @brief This function tests the EigenStepper with the EigenStepperDefaultExtension and -/// the EigenStepperDenseEnvironmentExtension. The focus of this tests lies in +/// the EigenStepperDenseExtension. The focus of this tests lies in /// the choosing of the right extension for the individual use case. This is /// performed with three different detectors: /// a) Pure vacuum -> DefaultExtension needs to act @@ -577,7 +577,7 @@ BOOST_AUTO_TEST_CASE(step_extension_vacuum_test) { const CurvilinearTrackParameters sbtp(Vector4::Zero(), startDir, 1_e / 1_GeV, cov, ParticleHypothesis::pion()); - using Stepper = EigenStepper; + using Stepper = EigenStepper; using Propagator = Propagator; using PropagatorOptions = Propagator::Options, AbortList>; @@ -609,7 +609,7 @@ BOOST_AUTO_TEST_CASE(step_extension_vacuum_test) { CHECK_CLOSE_ABS(mom, startMom, 1_keV); } - using DefStepper = EigenStepper; + using DefStepper = EigenStepper; using DefPropagator = Acts::Propagator; using DefPropagatorOptions = DefPropagator::Options, AbortList>; @@ -672,7 +672,7 @@ BOOST_AUTO_TEST_CASE(step_extension_material_test) { const CurvilinearTrackParameters sbtp(Vector4::Zero(), startDir, 1_e / 5_GeV, cov, ParticleHypothesis::pion()); - using Stepper = EigenStepper; + using Stepper = EigenStepper; using Propagator = Propagator; using PropagatorOptions = Propagator::Options, AbortList>; @@ -713,7 +713,7 @@ BOOST_AUTO_TEST_CASE(step_extension_material_test) { } } - using DenseStepper = EigenStepper; + using DenseStepper = EigenStepper; using DensePropagator = Acts::Propagator; using DensePropagatorOptions = DensePropagator::Options, @@ -818,7 +818,7 @@ BOOST_AUTO_TEST_CASE(step_extension_vacmatvac_test) { 1_e / 5_GeV, Covariance::Identity(), ParticleHypothesis::pion()); - using Stepper = EigenStepper; + using Stepper = EigenStepper; using Propagator = Acts::Propagator; using PropagatorOptions = Propagator::Options, AbortList>; @@ -872,7 +872,7 @@ BOOST_AUTO_TEST_CASE(step_extension_vacmatvac_test) { // Build launcher through vacuum // Set options for propagator - using DefStepper = EigenStepper; + using DefStepper = EigenStepper; using DefPropagator = Acts::Propagator; using DefPropagatorOptions = DefPropagator::Options, AbortList>; @@ -922,7 +922,7 @@ BOOST_AUTO_TEST_CASE(step_extension_vacmatvac_test) { // Set initial parameters for the particle track by using the result of the // first volume - using DenseStepper = EigenStepper; + using DenseStepper = EigenStepper; using DensePropagator = Acts::Propagator; using DensePropagatorOptions = DensePropagator::Options, @@ -1052,7 +1052,7 @@ BOOST_AUTO_TEST_CASE(step_extension_trackercalomdt_test) { 1_e / 1_GeV, Covariance::Identity(), ParticleHypothesis::pion()); - using Stepper = EigenStepper; + using Stepper = EigenStepper; using Propagator = Acts::Propagator; using PropagatorOptions = Propagator::Options, diff --git a/Tests/UnitTests/Core/Propagator/PropagatorTests.cpp b/Tests/UnitTests/Core/Propagator/PropagatorTests.cpp index d53ae87eb96..4dbdc303771 100644 --- a/Tests/UnitTests/Core/Propagator/PropagatorTests.cpp +++ b/Tests/UnitTests/Core/Propagator/PropagatorTests.cpp @@ -24,7 +24,7 @@ #include "Acts/Propagator/ActionList.hpp" #include "Acts/Propagator/ConstrainedStep.hpp" #include "Acts/Propagator/EigenStepper.hpp" -#include "Acts/Propagator/EigenStepperDenseEnvironmentExtension.hpp" +#include "Acts/Propagator/EigenStepperDenseExtension.hpp" #include "Acts/Propagator/Navigator.hpp" #include "Acts/Propagator/Propagator.hpp" #include "Acts/Propagator/StandardAborters.hpp" @@ -476,7 +476,7 @@ BOOST_AUTO_TEST_CASE(BasicPropagatorInterface) { BOOST_CHECK(resultCurv.ok()); } - EigenStepper denseEigenStepper{field}; + EigenStepper denseEigenStepper{field}; { Propagator propagator{denseEigenStepper, navigator}; diff --git a/docs/core/propagation.md b/docs/core/propagation.md index 0c9b8259f76..dbd7b37a1b9 100644 --- a/docs/core/propagation.md +++ b/docs/core/propagation.md @@ -110,15 +110,15 @@ The {class}`Acts::StraightLineStepper` is a very stripped down stepper that just The {class}`Acts::EigenStepper` implements the same functionality as the ATLAS stepper, however, the stepping code is rewritten by using `Eigen` primitives. Thus, it also uses a 4th-order Runge-Kutta algorithm for the integration of the EOM. Additionally, the {class}`Acts::EigenStepper` allows to customize the concrete integration step via **extension**. -The extension encapsulate the relevant equations for different environments. There exists a {struct}`Acts::EigenStepperDefaultExtension` that is suited for propagation in a vacuum, and the {struct}`Acts::EigenStepperDenseEnvironmentExtension`, that contains additional code to handle the propagation inside materials. Which extension is used is decided by the user. +The extension encapsulate the relevant equations for different environments. There exists a {struct}`Acts::EigenStepperDefaultExtension` that is suited for propagation in a vacuum, and the {struct}`Acts::EigenStepperDenseExtension`, that contains additional code to handle the propagation inside materials. Which extension is used is decided by the user. The extension can be configured via the {class}`Acts::EigenStepper`: ```c++ -using Stepper = Acts::EigenStepper; +using Stepper = Acts::EigenStepper; ``` -By default, the {class}`Acts::EigenStepper` only uses the {struct}`Acts::EigenStepperDenseEnvironmentExtension`. +By default, the {class}`Acts::EigenStepper` only uses the {struct}`Acts::EigenStepperDenseExtension`. ### MultiEigenStepperLoop From 415b4e0e512fcbb9beb30fb983e42561d5eeeb91 Mon Sep 17 00:00:00 2001 From: "Alexander J. Pfleger" <70842573+AJPfleger@users.noreply.github.com> Date: Tue, 10 Sep 2024 20:13:30 +0200 Subject: [PATCH 3/5] refactor: update `to_array` (#3600) "This can be abandoned with C++20 to use the `std::to_array` method" I think this is not true, since `std::array` doesn't work with dynamically sized vectors. --- Core/include/Acts/Utilities/Helpers.hpp | 31 ++++++++++--------- Core/src/Detector/VolumeStructureBuilder.cpp | 12 +++---- .../GenericCuboidVolumeBoundsTests.cpp | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Core/include/Acts/Utilities/Helpers.hpp b/Core/include/Acts/Utilities/Helpers.hpp index 99d068cf361..53ca997e29d 100644 --- a/Core/include/Acts/Utilities/Helpers.hpp +++ b/Core/include/Acts/Utilities/Helpers.hpp @@ -11,6 +11,7 @@ #include "Acts/Definitions/Algebra.hpp" #include +#include #include #include #include @@ -71,22 +72,24 @@ std::vector unpack_shared_const_vector( return rawPtrs; } -/// This can be abandoned with C++20 to use the std::to_array method +/// @brief Converts a vector to a fixed-size array with truncating or padding. /// -/// @note only the first kDIM elements will obviously be filled, if the -/// vector tends to be longer, it is truncated +/// This function copies elements from the input vector into a fixed-size array. +/// If the vector contains more than `kDIM` elements, the array is truncated to +/// fit. If the vector contains fewer elements than `kDIM`, the remaining array +/// elements are value-initialized (default-initialized, i.e., filled with zero +/// or default values). /// -/// @param vecvals the vector of bound values to be converted -/// @return an array with the filled values -template -std::array to_array(const std::vector& vecvals) { - std::array rarray = {}; - for (const auto [iv, v] : enumerate(vecvals)) { - if (iv < kDIM) { - rarray[iv] = v; - } - } - return rarray; +/// @tparam kDIM The size of the resulting array. +/// @tparam value_t The type of elements in the vector and the array. +/// @param vecvals The input vector to be converted to an array. +/// +/// @return An array containing the first `kDIM` elements of the vector. +template +std::array toArray(const std::vector& vecvals) { + std::array arr = {}; + std::copy_n(vecvals.begin(), std::min(vecvals.size(), kDIM), arr.begin()); + return arr; } /// @brief Dispatch a call based on a runtime value on a function taking the diff --git a/Core/src/Detector/VolumeStructureBuilder.cpp b/Core/src/Detector/VolumeStructureBuilder.cpp index 49dba260a52..afa10e45cd7 100644 --- a/Core/src/Detector/VolumeStructureBuilder.cpp +++ b/Core/src/Detector/VolumeStructureBuilder.cpp @@ -62,7 +62,7 @@ Acts::Experimental::VolumeStructureBuilder::construct( "object. It needs at least 5 parameters, while " + std::to_string(boundValues.size()) + " where given"); } - auto bArray = to_array( + auto bArray = toArray( boundValues); volumeBounds = std::make_unique(bArray); } break; @@ -94,7 +94,7 @@ Acts::Experimental::VolumeStructureBuilder::construct( std::to_string(boundValues.size()) + " where given"); } auto bArray = - to_array(boundValues); + toArray(boundValues); volumeBounds = std::make_unique(bArray); } break; case VolumeBounds::BoundsType::eCutoutCylinder: { @@ -108,7 +108,7 @@ Acts::Experimental::VolumeStructureBuilder::construct( std::to_string(boundValues.size()) + " where given"); } auto bArray = - to_array(boundValues); + toArray(boundValues); volumeBounds = std::make_unique(bArray); } break; case VolumeBounds::BoundsType::eCylinder: { @@ -150,7 +150,7 @@ Acts::Experimental::VolumeStructureBuilder::construct( << boundValues[2] << ", " << boundValues[3] << ", " << boundValues[4]); auto bArray = - to_array(boundValues); + toArray(boundValues); volumeBounds = std::make_unique(bArray); } break; case VolumeBounds::BoundsType::eGenericCuboid: { @@ -164,7 +164,7 @@ Acts::Experimental::VolumeStructureBuilder::construct( std::to_string(boundValues.size()) + " where given"); } auto bArray = - to_array(boundValues); + toArray(boundValues); volumeBounds = std::make_unique(bArray); } break; case VolumeBounds::BoundsType::eTrapezoid: { @@ -178,7 +178,7 @@ Acts::Experimental::VolumeStructureBuilder::construct( std::to_string(boundValues.size()) + " where given"); } auto bArray = - to_array(boundValues); + toArray(boundValues); volumeBounds = std::make_unique(bArray); } break; default: diff --git a/Tests/UnitTests/Core/Geometry/GenericCuboidVolumeBoundsTests.cpp b/Tests/UnitTests/Core/Geometry/GenericCuboidVolumeBoundsTests.cpp index 2fc5a25ca85..b62758ec815 100644 --- a/Tests/UnitTests/Core/Geometry/GenericCuboidVolumeBoundsTests.cpp +++ b/Tests/UnitTests/Core/Geometry/GenericCuboidVolumeBoundsTests.cpp @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(bounding_box_creation) { BOOST_CHECK_EQUAL(boundValues.size(), 24u); auto bValueArrray = - to_array( + toArray( boundValues); GenericCuboidVolumeBounds gcvbCopy(bValueArrray); BOOST_CHECK_EQUAL(gcvbCopy.values().size(), 24u); From f774b270244352df5949ee0f5f0d44c64218f825 Mon Sep 17 00:00:00 2001 From: "Alexander J. Pfleger" <70842573+AJPfleger@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:57:17 +0200 Subject: [PATCH 4/5] refactor: modernise GeometryHierarchyMap (#3594) - remove template `iterator_t` - remove iterators - range based loop - pass heavy objects by reference - readability --- .../Acts/Geometry/GeometryHierarchyMap.hpp | 70 ++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/Core/include/Acts/Geometry/GeometryHierarchyMap.hpp b/Core/include/Acts/Geometry/GeometryHierarchyMap.hpp index 1106761d372..b2b10b9e52f 100644 --- a/Core/include/Acts/Geometry/GeometryHierarchyMap.hpp +++ b/Core/include/Acts/Geometry/GeometryHierarchyMap.hpp @@ -64,13 +64,13 @@ class GeometryHierarchyMap { /// Combined geometry identifier and value element. Only used for input. using InputElement = typename std::pair; using Iterator = typename std::vector::const_iterator; - using Size = typename std::vector::size_type; using Value = value_t; /// Construct the container from the given elements. /// /// @param elements input elements (must be unique with respect to identifier) GeometryHierarchyMap(std::vector elements); + /// Construct the container from an initializer list. /// /// @param elements input initializer list @@ -86,21 +86,25 @@ class GeometryHierarchyMap { /// Return an iterator pointing to the beginning of the stored values. Iterator begin() const { return m_values.begin(); } + /// Return an iterator pointing to the end of the stored values. Iterator end() const { return m_values.end(); } + /// Check if any elements are stored. bool empty() const { return m_values.empty(); } + /// Return the number of stored elements. - Size size() const { return m_values.size(); } + std::size_t size() const { return m_values.size(); } /// Access the geometry identifier for the i-th element with bounds check. /// /// @throws std::out_of_range for invalid indices - GeometryIdentifier idAt(Size index) const { return m_ids.at(index); } + GeometryIdentifier idAt(std::size_t index) const { return m_ids.at(index); } + /// Access the value of the i-th element in the container with bounds check. /// /// @throws std::out_of_range for invalid indices - const Value& valueAt(Size index) const { return m_values.at(index); } + const Value& valueAt(std::size_t index) const { return m_values.at(index); } /// Find the most specific value for a given geometry identifier. /// @@ -111,7 +115,7 @@ class GeometryHierarchyMap { /// @param id geometry identifier for which information is requested /// @retval iterator to an existing value /// @retval `.end()` iterator if no matching element exists - Iterator find(GeometryIdentifier id) const; + Iterator find(const GeometryIdentifier& id) const; private: // NOTE this class assumes that it knows the ordering of the levels within @@ -171,25 +175,26 @@ class GeometryHierarchyMap { // no valid levels; all bits are zero. return Identifier{0u}; } + /// Construct a mask where only the highest level is set. static constexpr Identifier makeHighestLevelMask() { return makeLeadingLevelsMask(GeometryIdentifier(0u).setVolume(1u)); } + /// Compare the two identifiers only within the masked bits. static constexpr bool equalWithinMask(Identifier lhs, Identifier rhs, Identifier mask) { return (lhs & mask) == (rhs & mask); } + /// Ensure identifier ordering and uniqueness. - template - static void sortAndCheckDuplicates(iterator_t beg, iterator_t end); + static void sortAndCheckDuplicates(std::vector& elements); /// Fill the container from the input elements. /// /// This assumes that the elements are ordered and unique with respect to /// their identifiers. - template - void fill(iterator_t beg, iterator_t end); + void fill(const std::vector& elements); }; // implementations @@ -197,8 +202,8 @@ class GeometryHierarchyMap { template inline GeometryHierarchyMap::GeometryHierarchyMap( std::vector elements) { - sortAndCheckDuplicates(elements.begin(), elements.end()); - fill(elements.begin(), elements.end()); + sortAndCheckDuplicates(elements); + fill(elements); } template @@ -208,43 +213,44 @@ inline GeometryHierarchyMap::GeometryHierarchyMap( std::vector(elements.begin(), elements.end())) {} template -template inline void GeometryHierarchyMap::sortAndCheckDuplicates( - iterator_t beg, iterator_t end) { + std::vector& elements) { // ensure elements are sorted by identifier - std::sort(beg, end, [=](const auto& lhs, const auto& rhs) { + std::ranges::sort(elements, [=](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); - // check that all elements have unique identifier - auto dup = std::adjacent_find(beg, end, [](const auto& lhs, const auto& rhs) { - return lhs.first == rhs.first; - }); - if (dup != end) { + + // Check that all elements have unique identifier + auto dup = std::ranges::adjacent_find( + elements, + [](const auto& lhs, const auto& rhs) { return lhs.first == rhs.first; }); + + if (dup != elements.end()) { throw std::invalid_argument("Input elements contain duplicates"); } } template -template -inline void GeometryHierarchyMap::fill(iterator_t beg, - iterator_t end) { - const auto n = std::distance(beg, end); +inline void GeometryHierarchyMap::fill( + const std::vector& elements) { m_ids.clear(); - m_ids.reserve(n); m_masks.clear(); - m_masks.reserve(n); m_values.clear(); - m_values.reserve(n); - for (; beg != end; ++beg) { - m_ids.push_back(beg->first.value()); - m_masks.push_back(makeLeadingLevelsMask(beg->first.value())); - m_values.push_back(std::move(beg->second)); + + m_ids.reserve(elements.size()); + m_masks.reserve(elements.size()); + m_values.reserve(elements.size()); + + for (const auto& element : elements) { + m_ids.push_back(element.first.value()); + m_masks.push_back(makeLeadingLevelsMask(element.first.value())); + m_values.push_back(std::move(element.second)); } } template -inline auto GeometryHierarchyMap::find(GeometryIdentifier id) const - -> Iterator { +inline auto GeometryHierarchyMap::find( + const GeometryIdentifier& id) const -> Iterator { assert((m_ids.size() == m_values.size()) && "Inconsistent container state: #ids != # values"); assert((m_masks.size() == m_values.size()) && From ae0c21d3e3fc33e3da77a145f4c62465781a4d6b Mon Sep 17 00:00:00 2001 From: "Alexander J. Pfleger" <70842573+AJPfleger@users.noreply.github.com> Date: Wed, 11 Sep 2024 00:58:56 +0200 Subject: [PATCH 5/5] refactor: add C++23 `std::ranges::contains` place holder (#3598) Search-based algorithm that checks whether or not a given range contains a value with iterator-sentinel pairs. This utility simplifies range-based searches and will be replaceable with [`std::ranges::contains`](https://en.cppreference.com/w/cpp/algorithm/ranges/contains) in C++23. --- .../Detector/detail/IndexedGridFiller.hpp | 7 +- .../Acts/EventData/MultiTrajectoryHelpers.hpp | 4 +- .../Acts/TrackFitting/GaussianSumFitter.hpp | 5 +- .../Acts/TrackFitting/detail/GsfActor.hpp | 5 +- Core/include/Acts/Utilities/BinnedArrayXD.hpp | 7 +- Core/include/Acts/Utilities/Helpers.hpp | 17 +++ Core/src/Detector/LayerStructureBuilder.cpp | 5 +- .../detail/CuboidalDetectorHelper.cpp | 5 +- .../detail/CylindricalDetectorHelper.cpp | 25 +-- Core/src/Geometry/Layer.cpp | 5 +- .../Vertexing/AdaptiveMultiVertexFitter.cpp | 3 +- .../Digitization/src/ModuleClusters.cpp | 10 +- .../Geant4/src/SensitiveSurfaceMapper.cpp | 13 +- .../Geant4HepMC/src/EventAction.cpp | 5 +- .../Geant4HepMC/src/SteppingAction.cpp | 10 +- .../src/TrackFindingAlgorithmExaTrkX.cpp | 7 +- .../Framework/ML/src/NeuralCalibrator.cpp | 4 +- .../ActsExamples/Io/Csv/CsvInputOutput.hpp | 7 +- .../TrackFitterPerformanceWriter.cpp | 6 +- Examples/Python/src/Geometry.cpp | 9 +- Examples/Python/src/Svg.cpp | 18 +-- .../MaterialMapping/Mat_map_detector_plot.C | 4 +- .../Detray/src/DetrayMaterialConverter.cpp | 9 +- .../GeoModel/src/GeoModelBlueprintCreater.cpp | 4 +- Plugins/Json/src/DetectorJsonConverter.cpp | 2 +- .../Plugins/Podio/PodioTrackContainer.hpp | 4 +- .../Podio/PodioTrackStateContainer.hpp | 9 +- .../Clusterization/ClusterizationTests2D.cpp | 3 +- .../UnitTests/Core/Utilities/KDTreeTests.cpp | 142 +++++++++--------- .../ExaTrkXBoostTrackBuildingTests.cpp | 4 +- 30 files changed, 172 insertions(+), 186 deletions(-) diff --git a/Core/include/Acts/Detector/detail/IndexedGridFiller.hpp b/Core/include/Acts/Detector/detail/IndexedGridFiller.hpp index b79cafa93ad..c8f7d416f31 100644 --- a/Core/include/Acts/Detector/detail/IndexedGridFiller.hpp +++ b/Core/include/Acts/Detector/detail/IndexedGridFiller.hpp @@ -17,6 +17,7 @@ #include "Acts/Utilities/Delegate.hpp" #include "Acts/Utilities/Enumerate.hpp" #include "Acts/Utilities/GridAccessHelpers.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/IAxis.hpp" #include "Acts/Utilities/Logger.hpp" @@ -193,7 +194,7 @@ struct IndexedGridFiller { // Loop over the surfaces to be filled for (auto [io, o] : enumerate(iObjects)) { // Exclude indices that should be handled differently - if (std::find(aToAll.begin(), aToAll.end(), io) != aToAll.end()) { + if (rangeContainsValue(aToAll, io)) { continue; } // Get the reference positions @@ -216,7 +217,7 @@ struct IndexedGridFiller { // Now fill the surface indices for (const auto& li : lIndices) { auto& bContent = iGrid.grid.atLocalBins(li); - if (std::find(bContent.begin(), bContent.end(), io) == bContent.end()) { + if (!rangeContainsValue(bContent, io)) { bContent.push_back(io); } } @@ -238,7 +239,7 @@ struct IndexedGridFiller { for (std::size_t gi = 0; gi < iGrid.grid.size(true); ++gi) { auto& bContent = iGrid.grid.at(gi); for (const auto& io : idcs) { - if (std::find(bContent.begin(), bContent.end(), io) == bContent.end()) { + if (!rangeContainsValue(bContent, io)) { bContent.push_back(io); } } diff --git a/Core/include/Acts/EventData/MultiTrajectoryHelpers.hpp b/Core/include/Acts/EventData/MultiTrajectoryHelpers.hpp index 84d4c763a7b..2a5fac9b2d6 100644 --- a/Core/include/Acts/EventData/MultiTrajectoryHelpers.hpp +++ b/Core/include/Acts/EventData/MultiTrajectoryHelpers.hpp @@ -14,6 +14,7 @@ #include "Acts/Geometry/Layer.hpp" #include "Acts/Geometry/TrackingVolume.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Utilities/Helpers.hpp" #include #include @@ -102,8 +103,7 @@ VolumeTrajectoryStateContainer trajectoryState( const auto& volume = geoID.volume(); const auto& layer = geoID.layer(); // Check if the track info for this sub-detector is requested - auto it = std::find(volumeIds.begin(), volumeIds.end(), volume); - if (it == volumeIds.end()) { + if (!rangeContainsValue(volumeIds, volume)) { return true; } // The trajectory state for this volume diff --git a/Core/include/Acts/TrackFitting/GaussianSumFitter.hpp b/Core/include/Acts/TrackFitting/GaussianSumFitter.hpp index ada401ba401..e94ab519902 100644 --- a/Core/include/Acts/TrackFitting/GaussianSumFitter.hpp +++ b/Core/include/Acts/TrackFitting/GaussianSumFitter.hpp @@ -16,6 +16,7 @@ #include "Acts/Surfaces/BoundaryTolerance.hpp" #include "Acts/TrackFitting/GsfOptions.hpp" #include "Acts/TrackFitting/detail/GsfActor.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/Logger.hpp" #include "Acts/Utilities/TrackHelpers.hpp" @@ -432,8 +433,8 @@ struct GaussianSumFitter { for (auto state : fwdGsfResult.fittedStates->reverseTrackStateRange( fwdGsfResult.currentTip)) { - const bool found = std::find(foundBwd.begin(), foundBwd.end(), - &state.referenceSurface()) != foundBwd.end(); + const bool found = + rangeContainsValue(foundBwd, &state.referenceSurface()); if (!found && state.typeFlags().test(MeasurementFlag)) { state.typeFlags().set(OutlierFlag); state.typeFlags().reset(MeasurementFlag); diff --git a/Core/include/Acts/TrackFitting/detail/GsfActor.hpp b/Core/include/Acts/TrackFitting/detail/GsfActor.hpp index 56d6cecd262..7db377d1ced 100644 --- a/Core/include/Acts/TrackFitting/detail/GsfActor.hpp +++ b/Core/include/Acts/TrackFitting/detail/GsfActor.hpp @@ -23,6 +23,7 @@ #include "Acts/TrackFitting/detail/GsfComponentMerging.hpp" #include "Acts/TrackFitting/detail/GsfUtils.hpp" #include "Acts/TrackFitting/detail/KalmanUpdateHelpers.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/Zip.hpp" #include @@ -195,9 +196,7 @@ struct GsfActor { // Early return if we already were on this surface TODO why is this // necessary - const bool visited = - std::find(result.visitedSurfaces.begin(), result.visitedSurfaces.end(), - &surface) != result.visitedSurfaces.end(); + const bool visited = rangeContainsValue(result.visitedSurfaces, &surface); if (visited) { ACTS_VERBOSE("Already visited surface, return"); diff --git a/Core/include/Acts/Utilities/BinnedArrayXD.hpp b/Core/include/Acts/Utilities/BinnedArrayXD.hpp index 4b78b1026bc..281bd9d11b3 100644 --- a/Core/include/Acts/Utilities/BinnedArrayXD.hpp +++ b/Core/include/Acts/Utilities/BinnedArrayXD.hpp @@ -13,6 +13,7 @@ #pragma once #include "Acts/Utilities/BinUtility.hpp" #include "Acts/Utilities/BinnedArray.hpp" +#include "Acts/Utilities/Helpers.hpp" #include #include @@ -74,8 +75,7 @@ class BinnedArrayXD : public BinnedArray { /// fill the data m_objectGrid[bins[2]][bins[1]][bins[0]] = tap.first; /// fill the unique m_arrayObjects - if (std::find(m_arrayObjects.begin(), m_arrayObjects.end(), - tap.first) == m_arrayObjects.end()) { + if (!rangeContainsValue(m_arrayObjects, tap.first)) { m_arrayObjects.push_back(tap.first); } } @@ -103,8 +103,7 @@ class BinnedArrayXD : public BinnedArray { for (auto& o0 : o1) { if (o0) { /// fill the unique m_arrayObjects - if (std::find(m_arrayObjects.begin(), m_arrayObjects.end(), o0) == - m_arrayObjects.end()) { + if (!rangeContainsValue(m_arrayObjects, o0)) { m_arrayObjects.push_back(o0); } } diff --git a/Core/include/Acts/Utilities/Helpers.hpp b/Core/include/Acts/Utilities/Helpers.hpp index 53ca997e29d..34248fd9047 100644 --- a/Core/include/Acts/Utilities/Helpers.hpp +++ b/Core/include/Acts/Utilities/Helpers.hpp @@ -187,4 +187,21 @@ constexpr std::underlying_type_t toUnderlying(enum_t value) { return static_cast>(value); } +/// This can be replaced with C++23 to use the std::ranges::contains method +/// +/// This function searches through the given range for a specified value +/// and returns `true` if the value is found, or `false` otherwise. +/// +/// @tparam R The type of the range (e.g., vector, list, array). +/// @tparam T The type of the value to search for within the range. +/// +/// @param range The range to search within. This can be any range-compatible container. +/// @param value The value to search for in the range. +/// +/// @return `true` if the value is found within the range, `false` otherwise. +template +bool rangeContainsValue(const R& range, const T& value) { + return std::ranges::find(range, value) != std::ranges::end(range); +} + } // namespace Acts diff --git a/Core/src/Detector/LayerStructureBuilder.cpp b/Core/src/Detector/LayerStructureBuilder.cpp index 6a421671cf1..260cecf656a 100644 --- a/Core/src/Detector/LayerStructureBuilder.cpp +++ b/Core/src/Detector/LayerStructureBuilder.cpp @@ -23,6 +23,7 @@ #include "Acts/Utilities/Enumerate.hpp" #include "Acts/Utilities/Grid.hpp" #include "Acts/Utilities/GridAxisGenerators.hpp" +#include "Acts/Utilities/Helpers.hpp" #include #include @@ -242,9 +243,7 @@ Acts::Experimental::LayerStructureBuilder::construct( // the binning value that are not constrained by the internal surfaces for (const auto& bv : allBinningValues()) { if (support.volumeExtent.constrains(bv) && - std::find(support.internalConstraints.begin(), - support.internalConstraints.end(), - bv) == support.internalConstraints.end()) { + !rangeContainsValue(support.internalConstraints, bv)) { ACTS_VERBOSE(" Support surface is constrained by volume extent in " << binningValueName(bv)); supportExtent.set(bv, support.volumeExtent.min(bv), diff --git a/Core/src/Detector/detail/CuboidalDetectorHelper.cpp b/Core/src/Detector/detail/CuboidalDetectorHelper.cpp index 4bf7edbabd2..b292db6b15f 100644 --- a/Core/src/Detector/detail/CuboidalDetectorHelper.cpp +++ b/Core/src/Detector/detail/CuboidalDetectorHelper.cpp @@ -19,6 +19,7 @@ #include "Acts/Surfaces/Surface.hpp" #include "Acts/Utilities/BinningData.hpp" #include "Acts/Utilities/Enumerate.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/StringHelpers.hpp" #include @@ -190,9 +191,7 @@ Acts::Experimental::detail::CuboidalDetectorHelper::connect( for (auto [is, index] : enumerate(portalSets[toUnderlying(mergeValue)])) { // Check if you need to skip due to selections - if (!selectedOnly.empty() && - std::find(selectedOnly.begin(), selectedOnly.end(), index) == - selectedOnly.end()) { + if (!selectedOnly.empty() && !rangeContainsValue(selectedOnly, index)) { continue; } diff --git a/Core/src/Detector/detail/CylindricalDetectorHelper.cpp b/Core/src/Detector/detail/CylindricalDetectorHelper.cpp index 7fce725b4f6..2ed29f0b35a 100644 --- a/Core/src/Detector/detail/CylindricalDetectorHelper.cpp +++ b/Core/src/Detector/detail/CylindricalDetectorHelper.cpp @@ -325,9 +325,7 @@ Acts::Experimental::detail::CylindricalDetectorHelper::connectInR( rBoundaries.push_back(refValues[CylinderVolumeBounds::BoundValues::eMaxR]); // Connect in R ? (2u is the index of the outer cylinder) - bool connectR = selectedOnly.empty() || - std::find(selectedOnly.begin(), selectedOnly.end(), 2u) != - selectedOnly.end(); + bool connectR = selectedOnly.empty() || rangeContainsValue(selectedOnly, 2u); // Get phi sector and average phi ActsScalar phiSector = @@ -376,9 +374,7 @@ Acts::Experimental::detail::CylindricalDetectorHelper::connectInR( std::vector discDirs = {Acts::Direction::Forward, Acts::Direction::Backward}; for (const auto [iu, idir] : enumerate(discDirs)) { - if (selectedOnly.empty() || - std::find(selectedOnly.begin(), selectedOnly.end(), iu) != - selectedOnly.end()) { + if (selectedOnly.empty() || rangeContainsValue(selectedOnly, iu)) { const Surface& refSurface = volumes[0u]->portals()[iu]->surface(); const Transform3& refTransform = refSurface.transform(gctx); pReplacements.push_back(createDiscReplacement( @@ -397,9 +393,7 @@ Acts::Experimental::detail::CylindricalDetectorHelper::connectInR( for (const auto [iu, idir] : enumerate(sectorDirs)) { // (iu + 4u) corresponds to the indices of the phi-low and phi-high sector // planes. - if (selectedOnly.empty() || - std::find(selectedOnly.begin(), selectedOnly.end(), iu + 4u) != - selectedOnly.end()) { + if (selectedOnly.empty() || rangeContainsValue(selectedOnly, iu + 4u)) { // As it is r-wrapping, the inner tube is guaranteed const Surface& refSurface = volumes[volumes.size() - 1u]->portals()[iu + 4u]->surface(); @@ -471,9 +465,8 @@ Acts::Experimental::detail::CylindricalDetectorHelper::connectInZ( // Connect in Z ? // - 1u corresponds to the index of the high-z disc portal for the reference // volume. - bool connectZ = selectedOnly.empty() || - std::find(selectedOnly.begin(), selectedOnly.end(), 1u) != - selectedOnly.end(); + const bool connectZ = + selectedOnly.empty() || rangeContainsValue(selectedOnly, 1u); // Reference z axis const auto rotation = volumes[0u]->transform(gctx).rotation(); @@ -586,9 +579,7 @@ Acts::Experimental::detail::CylindricalDetectorHelper::connectInZ( unsigned int iSecOffset = innerPresent ? 4u : 3u; // Prepare the cylinder replacements for (const auto [iu, idir] : enumerate(cylinderDirs)) { - if (selectedOnly.empty() || - std::find(selectedOnly.begin(), selectedOnly.end(), iu + 2u) != - selectedOnly.end()) { + if (selectedOnly.empty() || rangeContainsValue(selectedOnly, iu + 2u)) { pReplacements.push_back(createCylinderReplacement( combinedTransform, cylinderR[iu], zBoundaries, {avgPhi - phiSector, avgPhi + phiSector}, iu + 2u, idir)); @@ -603,9 +594,7 @@ Acts::Experimental::detail::CylindricalDetectorHelper::connectInZ( Acts::Direction::Backward}; for (const auto [iu, idir] : enumerate(sectorDirs)) { // Access with 3u or 4u but always write 4u (to be caught later) - if (selectedOnly.empty() || - std::find(selectedOnly.begin(), selectedOnly.end(), iu + 4u) != - selectedOnly.end()) { + if (selectedOnly.empty() || rangeContainsValue(selectedOnly, iu + 4u)) { const Surface& refSurface = volumes[0u]->portals()[iu + iSecOffset]->surface(); pReplacements.push_back(createSectorReplacement( diff --git a/Core/src/Geometry/Layer.cpp b/Core/src/Geometry/Layer.cpp index 5598a854a41..af9ea08da42 100644 --- a/Core/src/Geometry/Layer.cpp +++ b/Core/src/Geometry/Layer.cpp @@ -14,6 +14,7 @@ #include "Acts/Propagator/Navigator.hpp" #include "Acts/Surfaces/BoundaryTolerance.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/Intersection.hpp" #include @@ -159,9 +160,7 @@ Acts::Layer::compatibleSurfaces( return; } BoundaryTolerance boundaryTolerance = options.boundaryTolerance; - if (std::find(options.externalSurfaces.begin(), - options.externalSurfaces.end(), - sf.geometryId()) != options.externalSurfaces.end()) { + if (rangeContainsValue(options.externalSurfaces, sf.geometryId())) { boundaryTolerance = BoundaryTolerance::Infinite(); } // the surface intersection diff --git a/Core/src/Vertexing/AdaptiveMultiVertexFitter.cpp b/Core/src/Vertexing/AdaptiveMultiVertexFitter.cpp index 6a6a879278a..cc70cee6b15 100644 --- a/Core/src/Vertexing/AdaptiveMultiVertexFitter.cpp +++ b/Core/src/Vertexing/AdaptiveMultiVertexFitter.cpp @@ -9,6 +9,7 @@ #include "Acts/Vertexing/AdaptiveMultiVertexFitter.hpp" #include "Acts/Surfaces/PerigeeSurface.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Vertexing/KalmanVertexUpdater.hpp" #include "Acts/Vertexing/VertexingError.hpp" @@ -189,7 +190,7 @@ Acts::Result Acts::AdaptiveMultiVertexFitter::addVtxToFit( bool Acts::AdaptiveMultiVertexFitter::isAlreadyInList( Vertex* vtx, const std::vector& vertices) const { - return std::find(vertices.begin(), vertices.end(), vtx) != vertices.end(); + return rangeContainsValue(vertices, vtx); } Acts::Result Acts::AdaptiveMultiVertexFitter::prepareVertexForFit( diff --git a/Examples/Algorithms/Digitization/src/ModuleClusters.cpp b/Examples/Algorithms/Digitization/src/ModuleClusters.cpp index f82ec7063c4..b5e7ab8e462 100644 --- a/Examples/Algorithms/Digitization/src/ModuleClusters.cpp +++ b/Examples/Algorithms/Digitization/src/ModuleClusters.cpp @@ -9,6 +9,7 @@ #include "ActsExamples/Digitization/ModuleClusters.hpp" #include "Acts/Clusterization/Clusterization.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "ActsExamples/Digitization/MeasurementCreation.hpp" #include "ActsFatras/Digitization/Channelizer.hpp" @@ -139,8 +140,7 @@ std::vector ModuleClusters::nonGeoEntries( std::vector retv; for (std::size_t i = 0; i < indices.size(); i++) { auto idx = indices.at(i); - if (std::find(m_geoIndices.begin(), m_geoIndices.end(), idx) == - m_geoIndices.end()) { + if (!rangeContainsValue(m_geoIndices, idx)) { retv.push_back(i); } } @@ -245,10 +245,8 @@ ModuleValue ModuleClusters::squash(std::vector& values) { ModuleValue& other = values.at(i); for (std::size_t j = 0; j < other.paramIndices.size(); j++) { auto idx = other.paramIndices.at(j); - if (std::find(m_geoIndices.begin(), m_geoIndices.end(), idx) == - m_geoIndices.end()) { - if (std::find(mval.paramIndices.begin(), mval.paramIndices.end(), - idx) == mval.paramIndices.end()) { + if (!rangeContainsValue(m_geoIndices, idx)) { + if (!rangeContainsValue(mval.paramIndices, idx)) { mval.paramIndices.push_back(idx); } if (mval.paramValues.size() < (j + 1)) { diff --git a/Examples/Algorithms/Geant4/src/SensitiveSurfaceMapper.cpp b/Examples/Algorithms/Geant4/src/SensitiveSurfaceMapper.cpp index 341e0531b07..9500671c7b3 100644 --- a/Examples/Algorithms/Geant4/src/SensitiveSurfaceMapper.cpp +++ b/Examples/Algorithms/Geant4/src/SensitiveSurfaceMapper.cpp @@ -11,6 +11,7 @@ #include "Acts/Definitions/Units.hpp" #include "Acts/Surfaces/AnnulusBounds.hpp" #include "Acts/Surfaces/ConvexPolygonBounds.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Visualization/GeometryView3D.hpp" #include "Acts/Visualization/ObjVisualization3D.hpp" @@ -185,13 +186,11 @@ void ActsExamples::SensitiveSurfaceMapper::remapSensitiveNames( std::string volumeName = g4LogicalVolume->GetName(); std::string volumeMaterialName = g4LogicalVolume->GetMaterial()->GetName(); - bool isSensitive = g4SensitiveDetector != nullptr; - bool isMappedMaterial = - std::find(m_cfg.materialMappings.begin(), m_cfg.materialMappings.end(), - volumeMaterialName) != m_cfg.materialMappings.end(); - bool isMappedVolume = - std::find(m_cfg.volumeMappings.begin(), m_cfg.volumeMappings.end(), - volumeName) != m_cfg.volumeMappings.end(); + const bool isSensitive = g4SensitiveDetector != nullptr; + const bool isMappedMaterial = + Acts::rangeContainsValue(m_cfg.materialMappings, volumeMaterialName); + const bool isMappedVolume = + Acts::rangeContainsValue(m_cfg.volumeMappings, volumeName); if (!(isSensitive || isMappedMaterial || isMappedVolume)) { ACTS_VERBOSE("Did not try mapping '" diff --git a/Examples/Algorithms/Geant4HepMC/src/EventAction.cpp b/Examples/Algorithms/Geant4HepMC/src/EventAction.cpp index b9e5b07c22f..eb5de237061 100644 --- a/Examples/Algorithms/Geant4HepMC/src/EventAction.cpp +++ b/Examples/Algorithms/Geant4HepMC/src/EventAction.cpp @@ -8,6 +8,8 @@ #include "EventAction.hpp" +#include "Acts/Utilities/Helpers.hpp" + #include #include @@ -32,8 +34,7 @@ bool findAttribute(const HepMC3::ConstGenVertexPtr& vertex, const std::vector vertexAttributes = vertex->attribute_names(); for (const auto& att : vertexAttributes) { const std::string process = vertex->attribute_as_string(att); - if (std::find(processFilter.begin(), processFilter.end(), process) != - processFilter.end()) { + if (Acts::rangeContainsValue(processFilter, process)) { return true; } } diff --git a/Examples/Algorithms/Geant4HepMC/src/SteppingAction.cpp b/Examples/Algorithms/Geant4HepMC/src/SteppingAction.cpp index ad9b91ac7b4..8852349dc60 100644 --- a/Examples/Algorithms/Geant4HepMC/src/SteppingAction.cpp +++ b/Examples/Algorithms/Geant4HepMC/src/SteppingAction.cpp @@ -8,6 +8,8 @@ #include "SteppingAction.hpp" +#include "Acts/Utilities/Helpers.hpp" + #include #include @@ -43,10 +45,10 @@ SteppingAction::~SteppingAction() { void SteppingAction::UserSteppingAction(const G4Step* step) { // Test if the event should be aborted - if (std::find(m_eventRejectionProcess.begin(), m_eventRejectionProcess.end(), - step->GetPostStepPoint() - ->GetProcessDefinedStep() - ->GetProcessName()) != m_eventRejectionProcess.end()) { + if (Acts::rangeContainsValue(m_eventRejectionProcess, + step->GetPostStepPoint() + ->GetProcessDefinedStep() + ->GetProcessName())) { m_eventAborted = true; G4RunManager::GetRunManager()->AbortEvent(); return; diff --git a/Examples/Algorithms/TrackFindingExaTrkX/src/TrackFindingAlgorithmExaTrkX.cpp b/Examples/Algorithms/TrackFindingExaTrkX/src/TrackFindingAlgorithmExaTrkX.cpp index 6bd254a0120..dbc123fc4d3 100644 --- a/Examples/Algorithms/TrackFindingExaTrkX/src/TrackFindingAlgorithmExaTrkX.cpp +++ b/Examples/Algorithms/TrackFindingExaTrkX/src/TrackFindingAlgorithmExaTrkX.cpp @@ -11,6 +11,7 @@ #include "Acts/Definitions/Units.hpp" #include "Acts/Plugins/ExaTrkX/TorchGraphStoreHook.hpp" #include "Acts/Plugins/ExaTrkX/TorchTruthGraphMetricsHook.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/Zip.hpp" #include "ActsExamples/EventData/Index.hpp" #include "ActsExamples/EventData/IndexSourceLink.hpp" @@ -97,10 +98,8 @@ ActsExamples::TrackFindingAlgorithmExaTrkX::TrackFindingAlgorithmExaTrkX( NodeFeature::eCellSum, NodeFeature::eCluster1R, NodeFeature::eCluster2R}; auto wantClFeatures = std::any_of( - m_cfg.nodeFeatures.begin(), m_cfg.nodeFeatures.end(), [&](const auto& f) { - return std::find(clFeatures.begin(), clFeatures.end(), f) != - clFeatures.end(); - }); + m_cfg.nodeFeatures.begin(), m_cfg.nodeFeatures.end(), + [&](const auto& f) { return Acts::rangeContainsValue(clFeatures, f); }); if (wantClFeatures && !m_inputClusters.isInitialized()) { throw std::invalid_argument("Cluster features requested, but not provided"); diff --git a/Examples/Framework/ML/src/NeuralCalibrator.cpp b/Examples/Framework/ML/src/NeuralCalibrator.cpp index 54003b3bfc1..8b0e07f1a62 100644 --- a/Examples/Framework/ML/src/NeuralCalibrator.cpp +++ b/Examples/Framework/ML/src/NeuralCalibrator.cpp @@ -12,6 +12,7 @@ #include "Acts/EventData/MeasurementHelpers.hpp" #include "Acts/EventData/SourceLink.hpp" #include "Acts/Utilities/CalibrationContext.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/UnitVectors.hpp" #include "ActsExamples/EventData/Measurement.hpp" @@ -84,8 +85,7 @@ void ActsExamples::NeuralCalibrator::calibrate( assert((idxSourceLink.index() < measurements.size()) and "Source link index is outside the container bounds"); - if (std::find(m_volumeIds.begin(), m_volumeIds.end(), - idxSourceLink.geometryId().volume()) == m_volumeIds.end()) { + if (!rangeContainsValue(m_volumeIds, idxSourceLink.geometryId())) { m_fallback.calibrate(measurements, clusters, gctx, cctx, sourceLink, trackState); return; diff --git a/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvInputOutput.hpp b/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvInputOutput.hpp index 7c4ede4659c..3006f498cc6 100644 --- a/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvInputOutput.hpp +++ b/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvInputOutput.hpp @@ -36,6 +36,7 @@ // SOFTWARE. #include "Acts/Utilities/Concepts.hpp" +#include "Acts/Utilities/Helpers.hpp" #include #include @@ -590,13 +591,11 @@ inline void NamedTupleDsvReader::parse_header( // check that all non-optional columns are available for (const auto& name : names) { // no need to for availability if the column is optional - auto o = std::find(optional_columns.begin(), optional_columns.end(), name); - if (o != optional_columns.end()) { + if (Acts::rangeContainsValue(optional_columns, name)) { continue; } // missing, non-optional column mean we can not continue - auto c = std::find(m_columns.begin(), m_columns.end(), name); - if (c == m_columns.end()) { + if (!Acts::rangeContainsValue(m_columns, name)) { throw std::runtime_error("Missing header column '" + name + "'"); } } diff --git a/Examples/Io/Performance/ActsExamples/Io/Performance/TrackFitterPerformanceWriter.cpp b/Examples/Io/Performance/ActsExamples/Io/Performance/TrackFitterPerformanceWriter.cpp index 3c4c263b533..a420d07aee0 100644 --- a/Examples/Io/Performance/ActsExamples/Io/Performance/TrackFitterPerformanceWriter.cpp +++ b/Examples/Io/Performance/ActsExamples/Io/Performance/TrackFitterPerformanceWriter.cpp @@ -161,10 +161,8 @@ ActsExamples::ProcessCode ActsExamples::TrackFitterPerformanceWriter::writeT( // one truth track) for (const auto& particle : particles) { bool isReconstructed = false; - // Find if the particle has been reconstructed - auto it = std::find(reconParticleIds.begin(), reconParticleIds.end(), - particle.particleId()); - if (it != reconParticleIds.end()) { + // Check if the particle has been reconstructed + if (rangeContainsValue(reconParticleIds, particle.particleId())) { isReconstructed = true; } // Loop over all the other truth particle and find the distance to the diff --git a/Examples/Python/src/Geometry.cpp b/Examples/Python/src/Geometry.cpp index 4f4752aa4ef..89e2493c764 100644 --- a/Examples/Python/src/Geometry.cpp +++ b/Examples/Python/src/Geometry.cpp @@ -35,6 +35,7 @@ #include "Acts/Plugins/Python/Utilities.hpp" #include "Acts/Surfaces/Surface.hpp" #include "Acts/Surfaces/SurfaceArray.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/RangeXD.hpp" #include "ActsExamples/Geometry/VolumeAssociationTest.hpp" @@ -66,11 +67,9 @@ struct MaterialSurfaceSelector { /// @param surface is the test surface void operator()(const Acts::Surface* surface) { - if (surface->surfaceMaterial() != nullptr) { - if (std::find(surfaces.begin(), surfaces.end(), surface) == - surfaces.end()) { - surfaces.push_back(surface); - } + if (surface->surfaceMaterial() != nullptr && + !rangeContainsValue(surfaces, surface)) { + surfaces.push_back(surface); } } }; diff --git a/Examples/Python/src/Svg.cpp b/Examples/Python/src/Svg.cpp index 74d6197ea2f..36bec574e22 100644 --- a/Examples/Python/src/Svg.cpp +++ b/Examples/Python/src/Svg.cpp @@ -20,6 +20,7 @@ #include "Acts/Plugins/ActSVG/TrackingGeometrySvgConverter.hpp" #include "Acts/Plugins/Python/Utilities.hpp" #include "Acts/Utilities/Enumerate.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "ActsExamples/EventData/GeometryContainers.hpp" #include "ActsExamples/EventData/SimHit.hpp" #include "ActsExamples/EventData/SimSpacePoint.hpp" @@ -68,17 +69,13 @@ actsvg::svg::object viewDetectorVolume(const Svg::ProtoVolume& pVolume, svgDet._id = identification; svgDet._tag = "g"; - auto [view, selection, viewRange] = viewAndRange; + const auto& [view, selection, viewRange] = viewAndRange; // Translate selection into booleans - bool all = - std::find(selection.begin(), selection.end(), "all") != selection.end(); - bool sensitives = std::find(selection.begin(), selection.end(), - "sensitives") != selection.end(); - bool portals = std::find(selection.begin(), selection.end(), "portals") != - selection.end(); - bool materials = std::find(selection.begin(), selection.end(), "materials") != - selection.end(); + const bool all = rangeContainsValue(selection, "all"); + const bool sensitives = rangeContainsValue(selection, "sensitives"); + const bool portals = rangeContainsValue(selection, "portals"); + const bool materials = rangeContainsValue(selection, "materials"); // Helper lambda for material selection auto materialSel = [&](const Svg::ProtoSurface& s) -> bool { @@ -138,8 +135,7 @@ actsvg::svg::object viewDetectorVolume(const Svg::ProtoVolume& pVolume, gpIDs = pgID->second._id; } - if (std::find(portalCache.begin(), portalCache.end(), gpIDs) != - portalCache.end()) { + if (rangeContainsValue(portalCache, gpIDs)) { continue; } diff --git a/Examples/Scripts/MaterialMapping/Mat_map_detector_plot.C b/Examples/Scripts/MaterialMapping/Mat_map_detector_plot.C index deeb7c275a3..ae4c7c5588b 100644 --- a/Examples/Scripts/MaterialMapping/Mat_map_detector_plot.C +++ b/Examples/Scripts/MaterialMapping/Mat_map_detector_plot.C @@ -8,6 +8,8 @@ #include +#include "Acts/Utilities/Helpers.hpp" + #include "materialPlotHelper.cpp" #include @@ -153,7 +155,7 @@ void Fill(std::vector& detector_hist, const std::string& input_file, std: } // Check if the volume/surface is part of the selected ones - if(std::find(detectors.begin(), detectors.end(), ID.volume()) != detectors.end()) { + if(rangeContainsValue(detectors, ID.volume())) { matX0 += mat_step_length->at(j) / mat_X0->at(j); matL0 += mat_step_length->at(j) / mat_L0->at(j); } diff --git a/Plugins/Detray/src/DetrayMaterialConverter.cpp b/Plugins/Detray/src/DetrayMaterialConverter.cpp index 14fdd2163df..b31a1d2e81a 100644 --- a/Plugins/Detray/src/DetrayMaterialConverter.cpp +++ b/Plugins/Detray/src/DetrayMaterialConverter.cpp @@ -16,6 +16,7 @@ #include "Acts/Surfaces/Surface.hpp" #include "Acts/Utilities/BinUtility.hpp" #include "Acts/Utilities/BinningType.hpp" +#include "Acts/Utilities/Helpers.hpp" #include @@ -26,11 +27,9 @@ struct MaterialSurfaceSelector { /// @param surface is the test surface void operator()(const Acts::Surface* surface) { - if (surface->surfaceMaterial() != nullptr) { - if (std::find(surfaces.begin(), surfaces.end(), surface) == - surfaces.end()) { - surfaces.push_back(surface); - } + if (surface->surfaceMaterial() != nullptr && + !rangeContainsValue(surfaces, surface)) { + surfaces.push_back(surface); } } }; diff --git a/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp b/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp index 7495f8cca39..84a6476a8e4 100644 --- a/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp +++ b/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp @@ -17,6 +17,7 @@ #include "Acts/Plugins/GeoModel/detail/GeoModelExtentHelper.hpp" #include "Acts/Utilities/BinningType.hpp" #include "Acts/Utilities/Enumerate.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/RangeXD.hpp" #include @@ -147,8 +148,7 @@ Acts::GeoModelBlueprintCreater::createNode( detail::GeoModelExentHelper::readBinningConstraints(entry.binnings); // Concatenate the binning constraints for (const auto& bc : binningConstraints) { - if (std::find(internalConstraints.begin(), internalConstraints.end(), bc) == - internalConstraints.end()) { + if (!rangeContainsValue(internalConstraints, bc)) { internalConstraints.push_back(bc); } } diff --git a/Plugins/Json/src/DetectorJsonConverter.cpp b/Plugins/Json/src/DetectorJsonConverter.cpp index 0dd8d7520f8..80b737b3447 100644 --- a/Plugins/Json/src/DetectorJsonConverter.cpp +++ b/Plugins/Json/src/DetectorJsonConverter.cpp @@ -44,7 +44,7 @@ nlohmann::json Acts::DetectorJsonConverter::toJson( for (const auto* volume : detector.volumes()) { nSurfaces += volume->surfaces().size(); for (const auto& portal : volume->portals()) { - if (std::find(portals.begin(), portals.end(), portal) == portals.end()) { + if (!rangeContainsValue(portals, portal)) { portals.push_back(portal); } } diff --git a/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp b/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp index a4c71eb2c7c..f04cf6d7c6a 100644 --- a/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp +++ b/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp @@ -15,6 +15,7 @@ #include "Acts/EventData/detail/DynamicColumn.hpp" #include "Acts/Plugins/Podio/PodioDynamicColumns.hpp" #include "Acts/Plugins/Podio/PodioUtil.hpp" +#include "Acts/Utilities/Helpers.hpp" #include "ActsPodioEdm/Surface.h" #pragma GCC diagnostic push @@ -339,8 +340,7 @@ class ConstPodioTrackContainer : public PodioTrackContainerBase { std::string tracksKey = "tracks" + s; std::vector available = frame.getAvailableCollections(); - if (std::find(available.begin(), available.end(), tracksKey) == - available.end()) { + if (!rangeContainsValue(available, tracksKey)) { throw std::runtime_error{"Track collection '" + tracksKey + "' not found in frame"}; } diff --git a/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackStateContainer.hpp b/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackStateContainer.hpp index 60951942618..590d62a8d87 100644 --- a/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackStateContainer.hpp +++ b/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackStateContainer.hpp @@ -224,20 +224,17 @@ class ConstPodioTrackStateContainer final std::string paramsKey = "trackStateParameters" + s; std::string jacsKey = "trackStateJacobians" + s; - if (std::find(available.begin(), available.end(), trackStatesKey) == - available.end()) { + if (!rangeContainsValue(available, trackStatesKey)) { throw std::runtime_error{"Track state collection '" + trackStatesKey + "' not found in frame"}; } - if (std::find(available.begin(), available.end(), paramsKey) == - available.end()) { + if (!rangeContainsValue(available, paramsKey)) { throw std::runtime_error{"Track state parameters collection '" + paramsKey + "' not found in frame"}; } - if (std::find(available.begin(), available.end(), jacsKey) == - available.end()) { + if (!rangeContainsValue(available, jacsKey)) { throw std::runtime_error{"Track state jacobian collection '" + jacsKey + "' not found in frame"}; } diff --git a/Tests/UnitTests/Core/Clusterization/ClusterizationTests2D.cpp b/Tests/UnitTests/Core/Clusterization/ClusterizationTests2D.cpp index e850d213551..d4ebb6f2c37 100644 --- a/Tests/UnitTests/Core/Clusterization/ClusterizationTests2D.cpp +++ b/Tests/UnitTests/Core/Clusterization/ClusterizationTests2D.cpp @@ -9,6 +9,7 @@ #include #include "Acts/Clusterization/Clusterization.hpp" +#include "Acts/Utilities/Helpers.hpp" #include #include @@ -133,7 +134,7 @@ void genclusterw(int x, int y, int x0, int y0, int x1, int y1, auto maybe_add = [&](int x_, int y_) { Cell2D c(x_, y_); if (std::uniform_real_distribution()(rng) < startp && - std::find(cells.begin(), cells.end(), c) == cells.end()) { + !rangeContainsValue(cells, c)) { cells.push_back(c); add.push_back(c); } diff --git a/Tests/UnitTests/Core/Utilities/KDTreeTests.cpp b/Tests/UnitTests/Core/Utilities/KDTreeTests.cpp index 9c4a4d2fe64..d1fd310d1c5 100644 --- a/Tests/UnitTests/Core/Utilities/KDTreeTests.cpp +++ b/Tests/UnitTests/Core/Utilities/KDTreeTests.cpp @@ -8,6 +8,7 @@ #include +#include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/KDTree.hpp" #include "Acts/Utilities/RangeXD.hpp" @@ -236,12 +237,12 @@ BOOST_FIXTURE_TEST_CASE(range_search_1, TreeFixture1DDoubleInt2) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 3); - BOOST_CHECK((std::find(result.begin(), result.end(), 5) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 6) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 10) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 7) == result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 2) == result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 9) == result.end())); + BOOST_CHECK(rangeContainsValue(result, 5)); + BOOST_CHECK(rangeContainsValue(result, 6)); + BOOST_CHECK(rangeContainsValue(result, 10)); + BOOST_CHECK(!rangeContainsValue(result, 7)); + BOOST_CHECK(!rangeContainsValue(result, 2)); + BOOST_CHECK(!rangeContainsValue(result, 9)); } BOOST_FIXTURE_TEST_CASE(range_search_2, TreeFixture1DDoubleInt2) { @@ -250,13 +251,13 @@ BOOST_FIXTURE_TEST_CASE(range_search_2, TreeFixture1DDoubleInt2) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 7); - BOOST_CHECK((std::find(result.begin(), result.end(), 1) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 2) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 3) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 5) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 6) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 9) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 10) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 1)); + BOOST_CHECK(rangeContainsValue(result, 2)); + BOOST_CHECK(rangeContainsValue(result, 3)); + BOOST_CHECK(rangeContainsValue(result, 5)); + BOOST_CHECK(rangeContainsValue(result, 6)); + BOOST_CHECK(rangeContainsValue(result, 9)); + BOOST_CHECK(rangeContainsValue(result, 10)); } BOOST_FIXTURE_TEST_CASE(range_search_3, TreeFixture1DDoubleInt2) { @@ -274,7 +275,7 @@ BOOST_FIXTURE_TEST_CASE(range_search_4, TreeFixture2DDoubleInt1) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 1); - BOOST_CHECK((std::find(result.begin(), result.end(), 5) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 5)); } BOOST_FIXTURE_TEST_CASE(range_search_5, TreeFixture2DDoubleInt1) { @@ -284,8 +285,8 @@ BOOST_FIXTURE_TEST_CASE(range_search_5, TreeFixture2DDoubleInt1) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 2); - BOOST_CHECK((std::find(result.begin(), result.end(), 5) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 6) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 5)); + BOOST_CHECK(rangeContainsValue(result, 6)); } BOOST_FIXTURE_TEST_CASE(range_search_6, TreeFixture10DDoubleInt1) { @@ -294,11 +295,11 @@ BOOST_FIXTURE_TEST_CASE(range_search_6, TreeFixture10DDoubleInt1) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 5); - BOOST_CHECK((std::find(result.begin(), result.end(), -66) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -51) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -19) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -13) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -83) != result.end())); + BOOST_CHECK(rangeContainsValue(result, -66)); + BOOST_CHECK(rangeContainsValue(result, -51)); + BOOST_CHECK(rangeContainsValue(result, -19)); + BOOST_CHECK(rangeContainsValue(result, -13)); + BOOST_CHECK(rangeContainsValue(result, -83)); } BOOST_FIXTURE_TEST_CASE(range_search_7, TreeFixture10DDoubleInt1) { @@ -307,8 +308,8 @@ BOOST_FIXTURE_TEST_CASE(range_search_7, TreeFixture10DDoubleInt1) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 2); - BOOST_CHECK((std::find(result.begin(), result.end(), 27) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -56) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 27)); + BOOST_CHECK(rangeContainsValue(result, -56)); } BOOST_FIXTURE_TEST_CASE(range_search_8, TreeFixture3DDoubleString1) { @@ -319,8 +320,7 @@ BOOST_FIXTURE_TEST_CASE(range_search_8, TreeFixture3DDoubleString1) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 1); - BOOST_CHECK( - (std::find(result.begin(), result.end(), "string0") != result.end())); + BOOST_CHECK(rangeContainsValue(result, "string0")); } BOOST_FIXTURE_TEST_CASE(range_search_9, TreeFixture3DDoubleString1) { @@ -331,14 +331,10 @@ BOOST_FIXTURE_TEST_CASE(range_search_9, TreeFixture3DDoubleString1) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 4); - BOOST_CHECK( - (std::find(result.begin(), result.end(), "string0") != result.end())); - BOOST_CHECK( - (std::find(result.begin(), result.end(), "string3") != result.end())); - BOOST_CHECK( - (std::find(result.begin(), result.end(), "string4") != result.end())); - BOOST_CHECK( - (std::find(result.begin(), result.end(), "string9") != result.end())); + BOOST_CHECK(rangeContainsValue(result, "string0")); + BOOST_CHECK(rangeContainsValue(result, "string3")); + BOOST_CHECK(rangeContainsValue(result, "string4")); + BOOST_CHECK(rangeContainsValue(result, "string9")); } BOOST_FIXTURE_TEST_CASE(range_search_10, TreeFixture1DIntInt1) { @@ -347,8 +343,8 @@ BOOST_FIXTURE_TEST_CASE(range_search_10, TreeFixture1DIntInt1) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 2); - BOOST_CHECK((std::find(result.begin(), result.end(), 5) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 6) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 5)); + BOOST_CHECK(rangeContainsValue(result, 6)); } BOOST_FIXTURE_TEST_CASE(range_search_11, TreeFixture2DIntInt1) { @@ -357,8 +353,8 @@ BOOST_FIXTURE_TEST_CASE(range_search_11, TreeFixture2DIntInt1) { std::vector result = tree.rangeSearch(range); BOOST_CHECK_EQUAL(result.size(), 2); - BOOST_CHECK((std::find(result.begin(), result.end(), 5) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 6) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 5)); + BOOST_CHECK(rangeContainsValue(result, 6)); } BOOST_FIXTURE_TEST_CASE(range_search_inplace_1, TreeFixture10DDoubleInt1) { @@ -369,11 +365,11 @@ BOOST_FIXTURE_TEST_CASE(range_search_inplace_1, TreeFixture10DDoubleInt1) { tree.rangeSearch(range, result); BOOST_CHECK_EQUAL(result.size(), 5); - BOOST_CHECK((std::find(result.begin(), result.end(), -66) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -51) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -19) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -13) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -83) != result.end())); + BOOST_CHECK(rangeContainsValue(result, -66)); + BOOST_CHECK(rangeContainsValue(result, -51)); + BOOST_CHECK(rangeContainsValue(result, -19)); + BOOST_CHECK(rangeContainsValue(result, -13)); + BOOST_CHECK(rangeContainsValue(result, -83)); } BOOST_FIXTURE_TEST_CASE(range_search_inserter_1, TreeFixture10DDoubleInt1) { @@ -384,11 +380,11 @@ BOOST_FIXTURE_TEST_CASE(range_search_inserter_1, TreeFixture10DDoubleInt1) { tree.rangeSearchInserter(range, std::back_inserter(result)); BOOST_CHECK_EQUAL(result.size(), 5); - BOOST_CHECK((std::find(result.begin(), result.end(), -66) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -51) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -19) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -13) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -83) != result.end())); + BOOST_CHECK(rangeContainsValue(result, -66)); + BOOST_CHECK(rangeContainsValue(result, -51)); + BOOST_CHECK(rangeContainsValue(result, -19)); + BOOST_CHECK(rangeContainsValue(result, -13)); + BOOST_CHECK(rangeContainsValue(result, -83)); } BOOST_FIXTURE_TEST_CASE(range_search_map_1, TreeFixture10DDoubleInt1) { @@ -400,11 +396,11 @@ BOOST_FIXTURE_TEST_CASE(range_search_map_1, TreeFixture10DDoubleInt1) { [](const std::array&, const int& i) -> int { return 2 * i; }); BOOST_CHECK_EQUAL(result.size(), 5); - BOOST_CHECK((std::find(result.begin(), result.end(), -132) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -102) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -38) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -26) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), -166) != result.end())); + BOOST_CHECK(rangeContainsValue(result, -132)); + BOOST_CHECK(rangeContainsValue(result, -102)); + BOOST_CHECK(rangeContainsValue(result, -38)); + BOOST_CHECK(rangeContainsValue(result, -26)); + BOOST_CHECK(rangeContainsValue(result, -166)); } BOOST_FIXTURE_TEST_CASE(range_search_map_inserter_1, TreeFixture10DDoubleInt1) { @@ -421,11 +417,11 @@ BOOST_FIXTURE_TEST_CASE(range_search_map_inserter_1, TreeFixture10DDoubleInt1) { std::back_inserter(result)); BOOST_CHECK_EQUAL(result.size(), 5); - BOOST_CHECK((std::find(result.begin(), result.end(), "-66") != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), "-51") != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), "-19") != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), "-13") != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), "-83") != result.end())); + BOOST_CHECK(rangeContainsValue(result, "-66")); + BOOST_CHECK(rangeContainsValue(result, "-51")); + BOOST_CHECK(rangeContainsValue(result, "-19")); + BOOST_CHECK(rangeContainsValue(result, "-13")); + BOOST_CHECK(rangeContainsValue(result, "-83")); } BOOST_FIXTURE_TEST_CASE(range_search_map_inserter_2, TreeFixture2DIntInt1) { @@ -441,8 +437,8 @@ BOOST_FIXTURE_TEST_CASE(range_search_map_inserter_2, TreeFixture2DIntInt1) { std::back_inserter(result)); BOOST_CHECK_EQUAL(result.size(), 2); - BOOST_CHECK((std::find(result.begin(), result.end(), 40) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 18) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 40)); + BOOST_CHECK(rangeContainsValue(result, 18)); } BOOST_FIXTURE_TEST_CASE(range_search_map_discard_1, TreeFixture2DIntInt1) { @@ -500,8 +496,7 @@ BOOST_FIXTURE_TEST_CASE(range_search_combinatorial, TreeFixture3DDoubleInt2) { BOOST_CHECK_EQUAL(result.size(), valid.size()); for (int j : valid) { - BOOST_CHECK((std::find(result.begin(), result.end(), j) != - result.end())); + BOOST_CHECK(rangeContainsValue(result, j)); } } } @@ -517,10 +512,10 @@ BOOST_FIXTURE_TEST_CASE(range_search_dominate1, TreeFixture3DDoubleInt3) { std::vector result = tree.rangeSearch(range1); BOOST_CHECK_EQUAL(result.size(), 4); - BOOST_CHECK((std::find(result.begin(), result.end(), 0) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 1) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 2) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 3) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 0)); + BOOST_CHECK(rangeContainsValue(result, 1)); + BOOST_CHECK(rangeContainsValue(result, 2)); + BOOST_CHECK(rangeContainsValue(result, 3)); } BOOST_FIXTURE_TEST_CASE(range_search_dominate2, TreeFixture3DDoubleInt3) { @@ -529,10 +524,10 @@ BOOST_FIXTURE_TEST_CASE(range_search_dominate2, TreeFixture3DDoubleInt3) { std::vector result = tree.rangeSearch(range1); BOOST_CHECK_EQUAL(result.size(), 4); - BOOST_CHECK((std::find(result.begin(), result.end(), 4) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 5) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 6) != result.end())); - BOOST_CHECK((std::find(result.begin(), result.end(), 7) != result.end())); + BOOST_CHECK(rangeContainsValue(result, 4)); + BOOST_CHECK(rangeContainsValue(result, 5)); + BOOST_CHECK(rangeContainsValue(result, 6)); + BOOST_CHECK(rangeContainsValue(result, 7)); } BOOST_AUTO_TEST_CASE(range_search_very_big) { @@ -580,8 +575,7 @@ BOOST_AUTO_TEST_CASE(range_search_very_big) { BOOST_CHECK_EQUAL(result.size(), valid.size()); for (int j : valid) { - BOOST_CHECK( - (std::find(result.begin(), result.end(), j) != result.end())); + BOOST_CHECK(rangeContainsValue(result, j)); } } } @@ -620,13 +614,11 @@ BOOST_AUTO_TEST_CASE(range_search_many_same) { BOOST_CHECK_EQUAL(result2.size(), 50); for (int i = 0; i < 50; ++i) { - BOOST_CHECK( - (std::find(result1.begin(), result1.end(), i) != result1.end())); + BOOST_CHECK(rangeContainsValue(result1, i)); } for (int i = 50; i < 100; ++i) { - BOOST_CHECK( - (std::find(result2.begin(), result2.end(), i) != result2.end())); + BOOST_CHECK(rangeContainsValue(result2, i)); } } diff --git a/Tests/UnitTests/Plugins/ExaTrkX/ExaTrkXBoostTrackBuildingTests.cpp b/Tests/UnitTests/Plugins/ExaTrkX/ExaTrkXBoostTrackBuildingTests.cpp index 7fad2d0b071..65261563e34 100644 --- a/Tests/UnitTests/Plugins/ExaTrkX/ExaTrkXBoostTrackBuildingTests.cpp +++ b/Tests/UnitTests/Plugins/ExaTrkX/ExaTrkXBoostTrackBuildingTests.cpp @@ -10,6 +10,7 @@ #include "Acts/Plugins/ExaTrkX/BoostTrackBuilding.hpp" #include "Acts/Plugins/ExaTrkX/detail/TensorVectorConversion.hpp" +#include "Acts/Utilities/Helpers.hpp" #include @@ -56,7 +57,6 @@ BOOST_AUTO_TEST_CASE(test_track_building) { // Check what we have here for (const auto &refTrack : refTracks) { - auto found = std::find(testTracks.begin(), testTracks.end(), refTrack); - BOOST_CHECK(found != testTracks.end()); + BOOST_CHECK(Acts::rangeContainsValue(testTracks, refTrack)); } }