Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use std::ranges::sort and reverse #3596

Merged
merged 38 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4bfcfbe
reverse, rotate, copy_if
AJPfleger Sep 3, 2024
6041566
unique
AJPfleger Sep 3, 2024
c429376
some sort
AJPfleger Sep 3, 2024
dfec315
Update SensitiveSurfaceMapper.cpp
AJPfleger Sep 3, 2024
267f80e
Update MultiLayerNavigation.hpp
AJPfleger Sep 3, 2024
6ae5e5d
revert some unique
AJPfleger Sep 4, 2024
bb25898
sort where possible
AJPfleger Sep 4, 2024
4df1630
revert unique
AJPfleger Sep 4, 2024
0591e2b
revert copy_if
AJPfleger Sep 4, 2024
7eab62f
revert rotation
AJPfleger Sep 4, 2024
386497e
remaining sorts
AJPfleger Sep 4, 2024
c422c79
rever MeasurementSelector.ipp because of '|'
AJPfleger Sep 4, 2024
b854725
Merge branch 'acts-project:main' into ranges
AJPfleger Sep 4, 2024
a9fd373
Merge branch 'acts-project:main' into ranges
AJPfleger Sep 4, 2024
7366a40
Update MeasurementSelector.ipp
AJPfleger Sep 4, 2024
2311d1f
fix include
AJPfleger Sep 5, 2024
29993c5
missed stuff
AJPfleger Sep 5, 2024
3845f1c
Merge branch 'main' into ranges
AJPfleger Sep 5, 2024
13eb70f
missing years
AJPfleger Sep 5, 2024
dd5509c
Merge branch 'main' into ranges
AJPfleger Sep 5, 2024
b50210a
fix exatrkx - cantorEdge
AJPfleger Sep 6, 2024
e5591f7
fix exatrkx namespace cantoredge
AJPfleger Sep 7, 2024
16b3590
sonarcloud
AJPfleger Sep 7, 2024
10c7931
fix exatrakx cantorpair
AJPfleger Sep 7, 2024
39769aa
Merge branch 'main' into ranges
AJPfleger Sep 7, 2024
e91cc39
try projector
AJPfleger Sep 8, 2024
9dda03f
projector
AJPfleger Sep 8, 2024
16828c0
missed things
AJPfleger Sep 8, 2024
b217434
fix uninitilised and tie nMajorityHits
AJPfleger Sep 8, 2024
bafc568
trying to assert
AJPfleger Sep 8, 2024
561a879
typo
AJPfleger Sep 8, 2024
fab156c
fix fatras?
AJPfleger Sep 8, 2024
0dd8658
descending sorting
AJPfleger Sep 8, 2024
49fb1a9
hough - type?
AJPfleger Sep 8, 2024
f768342
hough - projector?
AJPfleger Sep 8, 2024
8b937bd
fix tie and exatrakx?
AJPfleger Sep 8, 2024
5c15c57
greater - we might need better testing
AJPfleger Sep 8, 2024
ee6b218
Merge branch 'main' into ranges
kodiakhq[bot] Sep 12, 2024
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
9 changes: 4 additions & 5 deletions Core/include/Acts/Clusterization/Clusterization.ipp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// This file is part of the Acts project.
//
// Copyright (C) 2022 CERN for the benefit of the Acts project
// Copyright (C) 2022-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <algorithm>
#include <array>
#include <vector>

Expand Down Expand Up @@ -273,7 +274,7 @@ void labelClusters(CellCollection& cells, Connect connect) {
internal::DisjointSets ds{};

// Sort cells by position to enable in-order scan
std::sort(cells.begin(), cells.end(), internal::Compare<Cell, GridDim>());
std::ranges::sort(cells, internal::Compare<Cell, GridDim>());

// First pass: Allocate labels and record equivalences
for (auto it = cells.begin(); it != cells.end(); ++it) {
Expand Down Expand Up @@ -308,9 +309,7 @@ ClusterCollection mergeClusters(CellCollection& cells) {
if constexpr (GridDim > 1) {
// Sort the cells by their cluster label, only needed if more than
// one spatial dimension
std::sort(cells.begin(), cells.end(), [](Cell& lhs, Cell& rhs) {
return getCellLabel(lhs) < getCellLabel(rhs);
});
std::ranges::sort(cells, {}, [](Cell& c) { return getCellLabel(c); });
AJPfleger marked this conversation as resolved.
Show resolved Hide resolved
}

return internal::mergeClustersImpl<CellCollection, ClusterCollection>(cells);
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Material/MaterialComposition.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2018-2020 CERN for the benefit of the Acts project
// Copyright (C) 2018-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -100,10 +100,10 @@ class MaterialComposition {
/// Rescales the fractions so they all add up to unity within the accuracy.
MaterialComposition(std::vector<ElementFraction> elements)
: m_elements(std::move(elements)) {
std::sort(m_elements.begin(), m_elements.end());
std::ranges::sort(m_elements, std::less<ElementFraction>{});
// compute the total weight first
unsigned total = 0u;
for (auto element : m_elements) {
for (const auto& element : m_elements) {
total += element.m_fraction;
}
// compute scale factor into the [0, 256) range
Expand Down
13 changes: 5 additions & 8 deletions Core/include/Acts/Navigation/DetectorNavigator.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
// Copyright (C) 2023-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -22,6 +22,7 @@
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <algorithm>
#include <iomanip>
#include <iterator>
#include <sstream>
Expand Down Expand Up @@ -405,13 +406,9 @@ class DetectorNavigator {

// Sort properly the surface candidates
auto& nCandidates = nState.surfaceCandidates;
std::sort(nCandidates.begin(), nCandidates.end(),
[&](const auto& a, const auto& b) {
// The two path lengths
ActsScalar pathToA = a.objectIntersection.pathLength();
ActsScalar pathToB = b.objectIntersection.pathLength();
return pathToA < pathToB;
});
std::ranges::sort(nCandidates, {}, [](const auto& c) {
return c.objectIntersection.pathLength();
});
// Set the surface candidate
nState.surfaceCandidateIndex = 0;
}
Expand Down
19 changes: 8 additions & 11 deletions Core/include/Acts/Navigation/MultiLayerNavigation.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2022 CERN for the benefit of the Acts project
// Copyright (C) 2022-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -14,8 +14,10 @@
#include "Acts/Navigation/NavigationStateUpdaters.hpp"
#include "Acts/Utilities/VectorHelpers.hpp"

#include <algorithm>
#include <array>
#include <memory>
#include <tuple>

namespace Acts::Experimental {

Expand Down Expand Up @@ -105,16 +107,11 @@ class MultiLayerNavigation : public IInternalNavigation {
void resolveDuplicates(const GeometryContext& gctx,
std::vector<const Acts::Surface*>& surfaces) const {
// sorting the surfaces according to their radial distance
std::sort(surfaces.begin(), surfaces.end(),
[&gctx](const auto& surf1, const auto& surf2) {
if (surf1->center(gctx).x() != surf2->center(gctx).x()) {
return surf1->center(gctx).x() < surf2->center(gctx).x();
}
if (surf1->center(gctx).y() != surf2->center(gctx).y()) {
return surf1->center(gctx).y() < surf2->center(gctx).y();
}
return surf1->center(gctx).z() < surf2->center(gctx).z();
});
std::ranges::sort(surfaces, {}, [&gctx](const auto& s) {
assert(s != nullptr && "Uninitialized surface");
const auto& center = s->center(gctx);
return std::make_tuple(center.x(), center.y(), center.z());
});

// Remove the duplicates
surfaces.erase(std::unique(surfaces.begin(), surfaces.end()),
Expand Down
11 changes: 5 additions & 6 deletions Core/include/Acts/Navigation/NavigationStateUpdaters.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2022 CERN for the benefit of the Acts project
// Copyright (C) 2022-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -20,6 +20,7 @@
#include "Acts/Utilities/IAxis.hpp"
#include "Acts/Utilities/VectorHelpers.hpp"

#include <algorithm>
#include <array>
#include <memory>

Expand Down Expand Up @@ -65,11 +66,9 @@ inline void intitializeCandidates(const GeometryContext& gctx,
}
}

std::sort(confirmedCandidates.begin(), confirmedCandidates.end(),
[&](const auto& a, const auto& b) {
return a.objectIntersection.pathLength() <
b.objectIntersection.pathLength();
});
std::ranges::sort(confirmedCandidates, {}, [](const auto& c) {
return c.objectIntersection.pathLength();
});

nState.surfaceCandidates = std::move(confirmedCandidates);
nState.surfaceCandidateIndex = 0;
Expand Down
24 changes: 11 additions & 13 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/StringHelpers.hpp"

#include <algorithm>
#include <sstream>
#include <string>

Expand Down Expand Up @@ -889,11 +890,10 @@ class Navigator {
state.geoContext, stepper.position(state.stepping),
state.options.direction * stepper.direction(state.stepping),
navOpts, logger());
std::sort(state.navigation.navBoundaries.begin(),
state.navigation.navBoundaries.end(),
[](const auto& a, const auto& b) {
return SurfaceIntersection::pathLengthOrder(a.first, b.first);
});
std::ranges::sort(
state.navigation.navBoundaries, [](const auto& a, const auto& b) {
return SurfaceIntersection::pathLengthOrder(a.first, b.first);
});

// Print boundary information
if (logger().doPrint(Logging::VERBOSE)) {
Expand Down Expand Up @@ -1011,9 +1011,8 @@ class Navigator {
state.navigation.navSurfaces = currentLayer->compatibleSurfaces(
state.geoContext, stepper.position(state.stepping),
state.options.direction * stepper.direction(state.stepping), navOpts);
std::sort(state.navigation.navSurfaces.begin(),
state.navigation.navSurfaces.end(),
SurfaceIntersection::pathLengthOrder);
std::ranges::sort(state.navigation.navSurfaces,
SurfaceIntersection::pathLengthOrder);

// Print surface information
if (logger().doPrint(Logging::VERBOSE)) {
Expand Down Expand Up @@ -1079,11 +1078,10 @@ class Navigator {
state.geoContext, stepper.position(state.stepping),
state.options.direction * stepper.direction(state.stepping),
navOpts);
std::sort(state.navigation.navLayers.begin(),
state.navigation.navLayers.end(),
[](const auto& a, const auto& b) {
return SurfaceIntersection::pathLengthOrder(a.first, b.first);
});
std::ranges::sort(
state.navigation.navLayers, [](const auto& a, const auto& b) {
return SurfaceIntersection::pathLengthOrder(a.first, b.first);
});

// Print layer information
if (logger().doPrint(Logging::VERBOSE)) {
Expand Down
9 changes: 4 additions & 5 deletions Core/include/Acts/Propagator/TryAllNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ class TryAllNavigator : public TryAllNavigatorBase {
}
}

std::sort(intersectionCandidates.begin(), intersectionCandidates.end(),
detail::IntersectionCandidate::forwardOrder);
std::ranges::sort(intersectionCandidates,
detail::IntersectionCandidate::forwardOrder);

ACTS_VERBOSE(volInfo(state) << "found " << intersectionCandidates.size()
<< " intersections");
Expand Down Expand Up @@ -766,9 +766,8 @@ class TryAllOverstepNavigator : public TryAllNavigatorBase {
}
}

std::sort(state.navigation.activeCandidates.begin(),
state.navigation.activeCandidates.end(),
detail::IntersectionCandidate::forwardOrder);
std::ranges::sort(state.navigation.activeCandidates,
detail::IntersectionCandidate::forwardOrder);

state.navigation.activeCandidateIndex = 0;

Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Seeding/GbtsDataStorage.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2021 CERN for the benefit of the Acts project
// Copyright (C) 2021-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -105,8 +105,8 @@ class GbtsEtaBin {
}

void sortByPhi() {
std::sort(m_vn.begin(), m_vn.end(),
typename Acts::GbtsNode<space_point_t>::CompareByPhi());
std::ranges::sort(m_vn,
typename Acts::GbtsNode<space_point_t>::CompareByPhi());
}

bool empty() const { return m_vn.empty(); }
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Seeding/GbtsTrackingFilter.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2021 CERN for the benefit of the Acts project
// Copyright (C) 2021-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -138,8 +138,8 @@ class GbtsTrackingFilter {
if (m_stateVec.empty()) {
return;
}
std::sort(m_stateVec.begin(), m_stateVec.end(),
typename GbtsEdgeState<external_spacepoint_t>::Compare());
std::ranges::sort(m_stateVec,
typename GbtsEdgeState<external_spacepoint_t>::Compare());

GbtsEdgeState<external_spacepoint_t>* best = (*m_stateVec.begin());

Expand Down
16 changes: 5 additions & 11 deletions Core/include/Acts/Seeding/HoughTransformUtils.ipp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
// Copyright (C) 2023-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <algorithm>
#include <tuple>

template <class identifier_t>
template <class PointType>
Expand Down Expand Up @@ -263,16 +264,9 @@ Acts::HoughTransformUtils::PeakFinders::IslandsAroundMax<
}
}
// sort the candidate cells descending in content
std::sort(candidates.begin(), candidates.end(),
[&yieldMap](const std::size_t bin1, const std::size_t bin2) {
YieldType h1 = yieldMap[bin1];
YieldType h2 = yieldMap[bin2];

if (h1 != h2) {
return h1 > h2;
}
return bin1 > bin2;
});
std::ranges::sort(candidates, std::greater{}, [&yieldMap](std::size_t c) {
return std::make_tuple(yieldMap[c], c);
});

// now we build islands from the candidate cells, starting with the most
// populated one
Expand Down
11 changes: 5 additions & 6 deletions Core/include/Acts/Seeding/SeedFilter.ipp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
// Copyright (C) 2023-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -69,11 +69,10 @@ void SeedFilter<external_spacepoint_t>::filterSeeds_2SpFixed(

if (topSpVec.size() > 2) {
// sort indexes based on comparing values in invHelixDiameterVec
std::sort(
topSPIndexVec.begin(), topSPIndexVec.end(),
[&invHelixDiameterVec](const std::size_t i1, const std::size_t i2) {
return invHelixDiameterVec[i1] < invHelixDiameterVec[i2];
});
std::ranges::sort(topSPIndexVec, {},
[&invHelixDiameterVec](const std::size_t t) {
return invHelixDiameterVec[t];
});
}

// vector containing the radius of all compatible seeds
Expand Down
18 changes: 7 additions & 11 deletions Core/include/Acts/Seeding/SeedFinder.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -496,17 +496,13 @@ SeedFinder<external_spacepoint_t, grid_t, platform_t>::filterCandidates(

if constexpr (detailedMeasurement ==
Acts::DetectorMeasurementInfo::eDefault) {
std::sort(sorted_bottoms.begin(), sorted_bottoms.end(),
[&state](const std::size_t a, const std::size_t b) -> bool {
return state.linCircleBottom[a].cotTheta <
state.linCircleBottom[b].cotTheta;
});

std::sort(sorted_tops.begin(), sorted_tops.end(),
[&state](const std::size_t a, const std::size_t b) -> bool {
return state.linCircleTop[a].cotTheta <
state.linCircleTop[b].cotTheta;
});
std::ranges::sort(sorted_bottoms, {}, [&state](const std::size_t s) {
return state.linCircleBottom[s].cotTheta;
});

std::ranges::sort(sorted_tops, {}, [&state](const std::size_t s) {
return state.linCircleTop[s].cotTheta;
});
}

// Reserve enough space, in case current capacity is too little
Expand Down
11 changes: 6 additions & 5 deletions Core/include/Acts/Seeding/SeedFinderGbts.ipp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2021 CERN for the benefit of the Acts project
// Copyright (C) 2021-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -17,6 +17,7 @@
#include "Acts/Seeding/SeedFinderUtils.hpp"
#include "Acts/Utilities/BinningType.hpp"

#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
Expand Down Expand Up @@ -352,8 +353,8 @@ void SeedFinderGbts<external_spacepoint_t>::runGbts_TrackFinder(
out_sort[outIdx].first = pS->m_p[0];
}

std::sort(in_sort.begin(), in_sort.end());
std::sort(out_sort.begin(), out_sort.end());
std::ranges::sort(in_sort);
std::ranges::sort(out_sort);

unsigned int last_out = 0;

Expand Down Expand Up @@ -495,8 +496,8 @@ void SeedFinderGbts<external_spacepoint_t>::runGbts_TrackFinder(

m_triplets.clear();

std::sort(vSeeds.begin(), vSeeds.end(),
typename Acts::GbtsEdge<external_spacepoint_t>::CompareLevel());
std::ranges::sort(
vSeeds, typename Acts::GbtsEdge<external_spacepoint_t>::CompareLevel());

if (vSeeds.empty()) {
return;
Expand Down
Loading
Loading