Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Core/include/Acts/EventData/SubspaceHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Acts/Utilities/AlgebraHelpers.hpp"
#include "Acts/Utilities/Enumerate.hpp"

#include <algorithm>
#include <cstddef>
#include <ranges>

Expand Down Expand Up @@ -48,7 +49,8 @@ inline static bool checkSubspaceIndices(const index_range_t& indexRange,
return false;
}
++it;
if (std::find(it, indexRange.end(), index) != indexRange.end()) {
if (const auto tail = std::ranges::subrange(it, indexRange.end());
std::ranges::find(tail, index) != tail.end()) {
return false;
}
}
Expand Down Expand Up @@ -119,11 +121,15 @@ class SubspaceHelperBase {
auto end() const { return self().end(); }

bool contains(std::uint8_t index) const {
return std::find(begin(), end(), index) != end();
const auto r = std::ranges::subrange(begin(), end());
return std::ranges::find(r, index) != r.end();
}
std::size_t indexOf(std::uint8_t index) const {
auto it = std::find(begin(), end(), index);
return it != end() ? std::distance(begin(), it) : kFullSize;
const auto r = std::ranges::subrange(begin(), end());
const auto it = std::ranges::find(r, index);
return it != r.end()
? static_cast<std::size_t>(std::ranges::distance(r.begin(), it))
: kFullSize;
Comment thread
asalzburger marked this conversation as resolved.
}

template <typename EigenDerived>
Expand Down Expand Up @@ -202,8 +208,9 @@ class VariableSubspaceHelper
assert(checkSubspaceIndices(indices, kFullSize, indices.size()) &&
"Invalid indices");
m_indices.resize(indices.size());
std::transform(indices.begin(), indices.end(), m_indices.begin(),
[](auto index) { return static_cast<IndexType>(index); });
std::ranges::transform(indices, m_indices.begin(), [](auto index) {
return static_cast<IndexType>(index);
});
}

/// Check if the subspace is empty
Expand Down Expand Up @@ -280,8 +287,9 @@ class FixedSubspaceHelper
explicit FixedSubspaceHelper(const other_index_range_t& indices) {
assert(checkSubspaceIndices(indices, kFullSize, kSubspaceSize) &&
"Invalid indices");
std::transform(indices.begin(), indices.end(), m_indices.begin(),
[](auto index) { return static_cast<IndexType>(index); });
std::ranges::transform(indices, m_indices.begin(), [](auto index) {
return static_cast<IndexType>(index);
});
}

/// Check if the subspace is empty
Expand Down
5 changes: 2 additions & 3 deletions Core/include/Acts/EventData/TrackStateProxyCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,8 @@ class TrackStateProxyCommon {
assert(derived().template has<detail_tsp::kProjectorKey>());
assert(subspaceIndices.size() <= eBoundSize);
BoundSubspaceIndices boundSubspace{};
std::transform(subspaceIndices.begin(), subspaceIndices.end(),
boundSubspace.begin(),
[](auto i) { return static_cast<std::uint8_t>(i); });
std::ranges::transform(subspaceIndices, boundSubspace.begin(),
[](auto i) { return static_cast<std::uint8_t>(i); });
derived()
.template component<SerializedSubspaceIndices,
detail_tsp::kProjectorKey>() =
Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/Geometry/GeometryHierarchyMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ inline auto GeometryHierarchyMap<value_t>::find(
// might be stored at a higher level. ids for higher levels would always
// be sorted before the requested id. searching for the first element
// after the requested ensures that we include the full hierarchy.
const auto it = std::upper_bound(m_ids.begin(), m_ids.end(), id.value());
auto i = std::distance(m_ids.begin(), it);
const auto it = std::ranges::upper_bound(m_ids, id.value());
auto i = std::ranges::distance(m_ids.begin(), it);

// now go up the hierarchy to find the first matching element.
// example: the container stores four identifiers
Expand Down
7 changes: 4 additions & 3 deletions Core/include/Acts/Geometry/SurfaceArrayCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ class SurfaceArrayCreator {
return static_cast<std::size_t>(std::floor((x - min) / w));
} else {
// variable
const auto it =
std::upper_bound(std::begin(binEdges), std::end(binEdges), x);
return std::distance(std::begin(binEdges), it) - 1;
const auto it = std::ranges::upper_bound(binEdges, x);
return static_cast<std::size_t>(
std::ranges::distance(binEdges.begin(), it)) -
1;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Propagator/ConstrainedStep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ConstrainedStep {
/// returns the min step size
/// @return The minimum constrained step size considering all constraints
constexpr double value() const {
double min = *std::min_element(m_values.begin(), m_values.end());
double min = *std::ranges::min_element(m_values);
// accuracy is always positive and therefore handled separately
double result = std::min(std::abs(min), m_accuracy);
return std::signbit(min) ? -result : result;
Expand Down
12 changes: 6 additions & 6 deletions Core/include/Acts/Propagator/MultiStepperLoop.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "Acts/Propagator/MultiStepperError.hpp"

#include <algorithm>
#include <vector>

namespace Acts {
Expand Down Expand Up @@ -144,9 +145,9 @@ Result<double> MultiStepperLoop<S, R>::step(
// If at least one component is on a surface, we can remove all missed
// components before the step. If not, we must keep them for the case that all
// components miss and we need to retarget
const auto cmpsOnSurface = std::count_if(
components.cbegin(), components.cend(),
[&](auto& cmp) { return cmp.status == IntersectionStatus::onSurface; });
const auto cmpsOnSurface = std::ranges::count_if(components, [&](auto& cmp) {
return cmp.status == IntersectionStatus::onSurface;
});

if (cmpsOnSurface > 0) {
removeMissedComponents(state);
Expand Down Expand Up @@ -184,9 +185,8 @@ Result<double> MultiStepperLoop<S, R>::step(
};

// Loop over components and remove errorous components
components.erase(
std::remove_if(components.begin(), components.end(), errorInStep),
components.end());
const auto removedTail = std::ranges::remove_if(components, errorInStep);
components.erase(removedTail.begin(), removedTail.end());

// Reweight if necessary
if (reweightNecessary) {
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/TrackFinding/TrackSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Utilities/AngleHelpers.hpp"

#include <algorithm>
#include <cmath>
#include <functional>
#include <limits>
Expand Down Expand Up @@ -404,9 +405,8 @@ inline std::size_t TrackSelector::EtaBinnedConfig::binIndex(double eta) const {

inline std::size_t TrackSelector::EtaBinnedConfig::binIndexNoCheck(
double eta) const {
auto binIt =
std::upper_bound(absEtaEdges.begin(), absEtaEdges.end(), std::abs(eta));
std::size_t index = std::distance(absEtaEdges.begin(), binIt);
auto binIt = std::ranges::upper_bound(absEtaEdges, std::abs(eta));
std::size_t index = std::ranges::distance(absEtaEdges.begin(), binIt);
if (index == 0) {
index = absEtaEdges.size() + 1; // positive value to check for underflow
}
Expand Down
22 changes: 11 additions & 11 deletions Core/include/Acts/TrackFitting/detail/GsfUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/Zip.hpp"

#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
Expand All @@ -43,8 +44,8 @@ bool weightsAreNormalized(const component_range_t &cmps,
double tol = s_normalizationTolerance) {
double sumOfWeights = 0.0;

for (auto it = cmps.begin(); it != cmps.end(); ++it) {
sumOfWeights += proj(*it);
for (auto &&cmp : cmps) {
sumOfWeights += proj(cmp);
}

return std::abs(sumOfWeights - 1.0) < tol;
Expand All @@ -56,16 +57,14 @@ void normalizeWeights(component_range_t &cmps, const projector_t &proj) {

// we need decltype(auto) here to support proxy-types with reference
// semantics, otherwise there is a `cannot bind ... to ...` error
for (auto it = cmps.begin(); it != cmps.end(); ++it) {
decltype(auto) cmp = *it;
for (auto &&cmp : cmps) {
assert(std::isfinite(proj(cmp)) && "weight not finite in normalization");
sumOfWeights += proj(cmp);
}

assert(sumOfWeights > 0 && "sum of weights is not > 0");

for (auto it = cmps.begin(); it != cmps.end(); ++it) {
decltype(auto) cmp = *it;
for (auto &&cmp : cmps) {
proj(cmp) /= sumOfWeights;
}
}
Expand Down Expand Up @@ -172,11 +171,12 @@ void computePosteriorWeights(const traj_t &mt,
// Find minChi2, this can be used to factor some things later in the
// exponentiation
const auto minChi2 =
mt.getTrackState(*std::min_element(tips.begin(), tips.end(),
[&](const auto &a, const auto &b) {
return mt.getTrackState(a).chi2() <
mt.getTrackState(b).chi2();
}))
mt.getTrackState(
*std::ranges::min_element(tips,
[&](const auto &a, const auto &b) {
return mt.getTrackState(a).chi2() <
mt.getTrackState(b).chi2();
}))
.chi2();

// Loop over the tips and compute new weights
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Utilities/Axis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,9 @@ class Axis<AxisType::Variable, bdt> : public IAxis {
/// @note Bin indices start at @c 1. The underflow bin has the index @c 0
/// while the index <tt>nBins + 1</tt> indicates the overflow bin .
std::size_t getBin(double x) const final {
const auto it =
std::upper_bound(std::begin(m_binEdges), std::end(m_binEdges), x);
return wrapBin(std::distance(std::begin(m_binEdges), it));
const auto it = std::ranges::upper_bound(m_binEdges, x);
return wrapBin(
static_cast<int>(std::ranges::distance(m_binEdges.begin(), it)));
}

/// @brief get bin width
Expand Down
12 changes: 4 additions & 8 deletions Core/include/Acts/Utilities/BinUtility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Acts/Utilities/Enumerate.hpp"
#include "Acts/Utilities/ProtoAxis.hpp"

#include <algorithm>
#include <array>
#include <cstddef>
#include <iostream>
Expand Down Expand Up @@ -255,14 +256,9 @@ class BinUtility {
bool inside(const Vector3& position) const {
/// transform or not
const Vector3& bPosition = m_itransform * position;
// loop and break
for (auto& bData : m_binningData) {
if (!(bData.inside(bPosition))) {
return false;
}
}
// survived all the checks
return true;
return std::ranges::all_of(m_binningData, [&](const auto& bData) {
return bData.inside(bPosition);
});
}

/// First bin maximal value
Expand Down
5 changes: 2 additions & 3 deletions Core/include/Acts/Utilities/BinningData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,9 @@ class BinningData {
return (bData.option == closed) ? 0 : (bData.m_bins - 1);
}

auto lb = std::lower_bound(bData.m_boundaries.begin(),
bData.m_boundaries.end(), value);
auto lb = std::ranges::lower_bound(bData.m_boundaries, value);
return static_cast<std::size_t>(
std::distance(bData.m_boundaries.begin(), lb) - 1);
std::ranges::distance(bData.m_boundaries.begin(), lb) - 1);
}

public:
Expand Down
10 changes: 6 additions & 4 deletions Core/include/Acts/Utilities/BoundingBox.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "Acts/Utilities/BoundingBox.hpp"

#include <algorithm>

template <typename entity_t, typename value_t, std::size_t DIM>
Acts::AxisAlignedBoundingBox<entity_t, value_t, DIM>::AxisAlignedBoundingBox(
const entity_t* entity, const VertexType& vmin, const VertexType& vmax)
Expand Down Expand Up @@ -92,8 +94,8 @@ Acts::AxisAlignedBoundingBox<entity_t, value_t, DIM>::wrap(
assert(boxes.size() > 1);
std::vector<const self_t*> box_ptrs;
box_ptrs.reserve(boxes.size());
std::transform(boxes.begin(), boxes.end(), std::back_inserter(box_ptrs),
[](const auto* box) { return box; });
std::ranges::transform(boxes, std::back_inserter(box_ptrs),
[](const auto* box) { return box; });
return wrap(box_ptrs, envelope);
}

Expand All @@ -106,8 +108,8 @@ Acts::AxisAlignedBoundingBox<entity_t, value_t, DIM>::wrap(
assert(boxes.size() > 1);
std::vector<const self_t*> box_ptrs;
box_ptrs.reserve(boxes.size());
std::transform(boxes.begin(), boxes.end(), std::back_inserter(box_ptrs),
[](auto& box) { return &box; });
std::ranges::transform(boxes, std::back_inserter(box_ptrs),
[](auto& box) { return &box; });
return wrap(box_ptrs, envelope);
}

Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/Utilities/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Acts/Utilities/detail/grid_helper.hpp"
#include "Acts/Utilities/detail/interpolation_impl.hpp"

#include <algorithm>
#include <any>
#include <array>
#include <tuple>
Expand Down Expand Up @@ -675,7 +676,7 @@ class Grid final : public IGrid {
boost::container::small_vector<const IAxis*, 3> axes() const override {
boost::container::small_vector<const IAxis*, 3> result;
auto axes = detail::grid_helper::getAxes(m_axes);
std::copy(axes.begin(), axes.end(), std::back_inserter(result));
std::ranges::copy(axes, std::back_inserter(result));
return result;
}

Expand Down
12 changes: 9 additions & 3 deletions Core/include/Acts/Utilities/Helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <iostream>
#include <limits>
#include <memory>
#include <ranges>
#include <type_traits>
#include <vector>

Expand Down Expand Up @@ -270,7 +271,9 @@
///
/// The computation is performed as follows:
/// 1. Sorts the input vector using @c std::ranges::sort to prepare for uniqueness.
/// 2. Determines the number of unique values using @c std::unique and calculates the bin count.
/// 2. Determines the number of unique values using @c std::ranges::unique and
/// calculates the bin count from the size of the unique prefix (not the tail
/// subrange).
/// 3. Calculates the minimum and maximum using @c std::ranges::minmax.
/// 4. Adjusts the maximum to include an additional bin by adding the bin step
/// size.
Expand All @@ -287,8 +290,11 @@
std::ranges::sort(xPos);

// get the number of bins over unique values
auto it = std::unique(xPos.begin(), xPos.end());
const std::size_t xBinCount = std::distance(xPos.begin(), it);
// ranges::unique returns [ret, end): duplicate tail; unique elements are
// [begin, ret)
const auto uniqueTail = std::ranges::unique(xPos);
const std::size_t xBinCount = static_cast<std::size_t>(

Check warning on line 296 in Core/include/Acts/Utilities/Helpers.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=acts-project_acts&issues=AZ1Qij2KX-FulIBzr_0q&open=AZ1Qij2KX-FulIBzr_0q&pullRequest=5311
std::ranges::distance(xPos.begin(), uniqueTail.begin()));

// get the minimum and maximum
auto [xMin, xMax] = std::ranges::minmax(xPos);
Expand Down
16 changes: 9 additions & 7 deletions Core/include/Acts/Utilities/Table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cctype>
#include <format>
#include <ostream>
#include <ranges>
#include <stdexcept>
#include <string>
#include <vector>
Expand Down Expand Up @@ -115,20 +116,19 @@ class Table {

// Build header row
result += "|";
for (std::size_t i = 0; i < m_columns.size(); ++i) {
for (const auto& col : m_columns) {
result += std::format(
" {} |", formatAligned(m_columns[i].header, m_columns[i].width,
m_columns[i].alignment));
" {} |", formatAligned(col.header, col.width, col.alignment));
}
result += "\n";

// Build separator row
result += "|";
for (std::size_t i = 0; i < m_columns.size(); ++i) {
std::size_t contentWidth = m_columns[i].width;
for (const auto& col : m_columns) {
std::size_t contentWidth = col.width;

if (m_includeMarkdownMarkers) {
switch (m_columns[i].alignment) {
switch (col.alignment) {
case Alignment::Left:
result += std::format(":{:-<{}}", "", contentWidth + 1);
break;
Expand Down Expand Up @@ -169,7 +169,9 @@ class Table {
/// @throws std::invalid_argument if alignment string is not recognized
static Alignment parseAlignment(const std::string& alignment) {
std::string lower = alignment;
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
std::ranges::transform(lower, lower.begin(), [](unsigned char c) {
return static_cast<char>(std::tolower(c));
});

if (lower == "left" || lower == "l") {
return Alignment::Left;
Expand Down
Loading
Loading