Skip to content

Commit

Permalink
refactor: use structured bindings (#3632)
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger authored Oct 21, 2024
1 parent c83597c commit 7b71164
Show file tree
Hide file tree
Showing 21 changed files with 87 additions and 105 deletions.
6 changes: 2 additions & 4 deletions Core/include/Acts/Utilities/BoundingBox.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ template <typename entity_t, typename value_t, std::size_t DIM>
Acts::AxisAlignedBoundingBox<entity_t, value_t, DIM>
Acts::AxisAlignedBoundingBox<entity_t, value_t, DIM>::transformed(
const transform_type& trf) const {
VertexType vmin, vmax;
std::tie(vmin, vmax) = transformVertices(trf);
const auto [vmin, vmax] = transformVertices(trf);
return self_t(m_entity, vmin, vmax);
}

Expand Down Expand Up @@ -463,8 +462,7 @@ box_t* octree_inner(std::vector<std::unique_ptr<box_t>>& store,

std::array<std::vector<box_t*>, 8> octants;
// calc center of boxes
VertexType vmin, vmax;
std::tie(vmin, vmax) = box_t::wrap(lprims);
const auto [vmin, vmax] = box_t::wrap(lprims);
VertexType glob_ctr = (vmin + vmax) / 2.;

for (auto* box : lprims) {
Expand Down
8 changes: 4 additions & 4 deletions Core/include/Acts/Utilities/GridAxisGenerators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct EqEq {
nBins0);
Acts::Axis<Acts::AxisType::Equidistant, bType> bEq(range1[0u], range1[1u],
nBins1);
return std::tie(aEq, bEq);
return {aEq, bEq};
}
};

Expand Down Expand Up @@ -160,7 +160,7 @@ struct EqVar {
Acts::Axis<Acts::AxisType::Equidistant, aType> eqA(range[0u], range[1u],
nBins);
Acts::Axis<Acts::AxisType::Variable, bType> varB(edges);
return std::tie(eqA, varB);
return {eqA, varB};
}
};

Expand Down Expand Up @@ -210,7 +210,7 @@ struct VarEq {
Acts::Axis<Acts::AxisType::Variable, aType> varA(edges);
Acts::Axis<Acts::AxisType::Equidistant, bType> eqB(range[0u], range[1u],
nBins);
return std::tie(varA, eqB);
return {varA, eqB};
}
};

Expand Down Expand Up @@ -257,7 +257,7 @@ struct VarVar {
return_type operator()() const {
Acts::Axis<Acts::AxisType::Variable, aType> varA(edges0);
Acts::Axis<Acts::AxisType::Variable, bType> varB(edges1);
return std::tie(varA, varB);
return {varA, varB};
}
};

Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/Helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ std::tuple<typename T::value_type, ActsScalar> range_medium(const T& tseries) {
auto [minIt, maxIt] = std::ranges::minmax_element(tseries);
typename T::value_type range = (*maxIt - *minIt);
ActsScalar medium = static_cast<ActsScalar>((*maxIt + *minIt) * 0.5);
return std::tie(range, medium);
return {range, medium};
}

template <typename enum_t>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ void updateVertexWithTrackImpl(Vertex& vtx, TrackAtVertex& trk, int sign) {
calculateUpdate(vtx, trk.linearizedState, trackWeight, sign, cache);

// Get fit quality parameters wrt to old vertex
double chi2 = 0.;
double ndf = 0.;
std::tie(chi2, ndf) = vtx.fitQuality();
auto [chi2, ndf] = vtx.fitQuality();

// Chi2 of the track parameters
double trkChi2 = trackParametersChi2(trk.linearizedState, cache);
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Detector/detail/CuboidalDetectorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Acts::Experimental::detail::CuboidalDetectorHelper::xyzBoundaries(
}

for (auto [im, map] : enumerate(valueMaps)) {
for (auto [key, value] : map) {
for (auto [key, _] : map) {
boundaries[im].push_back(key);
}
std::ranges::sort(boundaries[im]);
Expand Down
9 changes: 3 additions & 6 deletions Core/src/MagneticField/BFieldMapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,9 @@ Acts::solenoidFieldMap(std::pair<double, double> rlim,
std::pair<double, double> zlim,
std::pair<std::size_t, std::size_t> nbins,
const SolenoidBField& field) {
double rMin = 0, rMax = 0, zMin = 0, zMax = 0;
std::tie(rMin, rMax) = rlim;
std::tie(zMin, zMax) = zlim;

std::size_t nBinsR = 0, nBinsZ = 0;
std::tie(nBinsR, nBinsZ) = nbins;
auto [rMin, rMax] = rlim;
auto [zMin, zMax] = zlim;
const auto [nBinsR, nBinsZ] = nbins;

double stepZ = std::abs(zMax - zMin) / (nBinsZ - 1);
double stepR = std::abs(rMax - rMin) / (nBinsR - 1);
Expand Down
6 changes: 3 additions & 3 deletions Core/src/Material/BinnedSurfaceMaterialAccumulater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ void Acts::BinnedSurfaceMaterialAccumulater::accumulate(
}

// After mapping this track, average the touched bins
for (auto tmapBin : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {tmapBin.second};
tmapBin.first->trackAverage(trackBins, true);
for (const auto& [key, value] : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {value};
key->trackAverage(trackBins, true);
}

// Empty bin correction
Expand Down
20 changes: 10 additions & 10 deletions Core/src/Material/SurfaceMaterialMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,19 +416,19 @@ void Acts::SurfaceMaterialMapper::mapInteraction(
}

// After mapping this track, average the touched bins
for (auto tmapBin : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {tmapBin.second};
for (const auto& [key, value] : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {value};
if (m_cfg.computeVariance) {
// This only makes sense for the binned material
auto binnedMaterial = dynamic_cast<const BinnedSurfaceMaterial*>(
touchedMaterialBin[tmapBin.first].get());
touchedMaterialBin[key].get());
if (binnedMaterial != nullptr) {
tmapBin.first->trackVariance(
key->trackVariance(
trackBins,
binnedMaterial->fullMaterial()[trackBins[0][1]][trackBins[0][0]]);
}
}
tmapBin.first->trackAverage(trackBins);
key->trackAverage(trackBins);
}

// After mapping this track, average the untouched but intersected bins
Expand Down Expand Up @@ -493,21 +493,21 @@ void Acts::SurfaceMaterialMapper::mapSurfaceInteraction(
}

// After mapping this track, average the touched bins
for (auto tmapBin : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {tmapBin.second};
for (const auto& [key, value] : touchedMapBins) {
std::vector<std::array<std::size_t, 3>> trackBins = {value};
if (m_cfg.computeVariance) {
// This only makes sense for the binned material
auto binnedMaterial = dynamic_cast<const BinnedSurfaceMaterial*>(
touchedMaterialBin[tmapBin.first].get());
touchedMaterialBin[key].get());
if (binnedMaterial != nullptr) {
tmapBin.first->trackVariance(
key->trackVariance(
trackBins,
binnedMaterial->fullMaterial()[trackBins[0][1]][trackBins[0][0]],
true);
}
}
// No need to do an extra pass for untouched surfaces they would have been
// added to the material interaction in the initial mapping
tmapBin.first->trackAverage(trackBins, true);
key->trackAverage(trackBins, true);
}
}
16 changes: 8 additions & 8 deletions Core/src/TrackFinding/AmbiguityTrackClustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ Acts::detail::clusterDuplicateTracks(
std::unordered_map<std::size_t, std::size_t> hitToTrack;

// Loop over all the tracks
for (auto track = trackMap.rbegin(); track != trackMap.rend(); ++track) {
std::vector<std::size_t> hits = track->second.second;
for (const auto& [_, trackValue] : trackMap) {
std::vector<std::size_t> hits = trackValue.second;
auto matchedTrack = hitToTrack.end();
// Loop over all the hits in the track
for (auto hit = hits.begin(); hit != hits.end(); hit++) {
for (const auto& hit : hits) {
// Check if the hit is already associated to a track
matchedTrack = hitToTrack.find(*hit);
matchedTrack = hitToTrack.find(hit);
if (matchedTrack != hitToTrack.end()) {
// Add the track to the cluster associated to the matched track
cluster.at(matchedTrack->second).push_back(track->second.first);
cluster.at(matchedTrack->second).push_back(trackValue.first);
break;
}
}
// None of the hits have been matched to a track create a new cluster
if (matchedTrack == hitToTrack.end()) {
cluster.emplace(track->second.first,
std::vector<std::size_t>(1, track->second.first));
cluster.emplace(trackValue.first,
std::vector<std::size_t>(1, trackValue.first));
for (const auto& hit : hits) {
// Add the hits of the new cluster to the hitToTrack
hitToTrack.emplace(hit, track->second.first);
hitToTrack.emplace(hit, trackValue.first);
}
}
}
Expand Down
48 changes: 18 additions & 30 deletions Core/src/TrackFinding/GbtsConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// TODO: update to C++17 style
#include "Acts/TrackFinding/GbtsConnector.hpp"

#include <algorithm>
#include <fstream>
#include <iostream>
#include <list>
Expand Down Expand Up @@ -57,15 +58,8 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {
continue;
}

std::map<int, std::vector<GbtsConnection *>>::iterator it =
m_connMap.find(stage);

if (it == m_connMap.end()) {
std::vector<GbtsConnection *> v(1, pC);
m_connMap.insert(std::make_pair(stage, v));
} else {
(*it).second.push_back(pC);
}
auto &connections = m_connMap[stage];
connections.push_back(pC);
}

// re-arrange the connection stages
Expand All @@ -74,9 +68,8 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {

std::map<int, std::vector<const GbtsConnection *>> newConnMap;

for (const auto &conn : m_connMap) {
std::copy(conn.second.begin(), conn.second.end(),
std::back_inserter(lConns));
for (const auto &[_, value] : m_connMap) {
std::ranges::copy(value, std::back_inserter(lConns));
}

int stageCounter = 0;
Expand Down Expand Up @@ -111,19 +104,19 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {

std::set<unsigned int> zeroLayers;

for (const auto &layerCounts : mCounter) {
if (layerCounts.second.second != 0) {
for (const auto &[key, value] : mCounter) {
if (value.second != 0) {
continue;
}

zeroLayers.insert(layerCounts.first);
zeroLayers.insert(key);
}

// remove connections which use zeroLayer as destination

std::vector<const GbtsConnection *> theStage;

std::list<const GbtsConnection *>::iterator cIt = lConns.begin();
auto cIt = lConns.begin();

while (cIt != lConns.end()) {
if (zeroLayers.contains((*cIt)->m_dst)) {
Expand All @@ -144,10 +137,9 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {
// the doublet making is done using "outside-in" approach hence the reverse
// iterations

for (std::map<int, std::vector<const GbtsConnection *>>::reverse_iterator it =
newConnMap.rbegin();
it != newConnMap.rend(); ++it, currentStage++) {
const std::vector<const GbtsConnection *> &vConn = (*it).second;
for (auto it = newConnMap.rbegin(); it != newConnMap.rend();
it++, currentStage++) {
const auto &[_, vConn] = *it;

// loop over links, extract all connections for the stage, group sources by
// L1 (dst) index
Expand All @@ -157,8 +149,7 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {
for (const auto *conn : vConn) {
unsigned int dst = conn->m_dst;

std::map<unsigned int, std::vector<const GbtsConnection *>>::iterator
l1MapIt = l1ConnMap.find(dst);
auto l1MapIt = l1ConnMap.find(dst);
if (l1MapIt != l1ConnMap.end()) {
(*l1MapIt).second.push_back(conn);
} else {
Expand All @@ -171,8 +162,8 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {

lgv.reserve(l1ConnMap.size());

for (const auto &l1Group : l1ConnMap) {
lgv.push_back(LayerGroup(l1Group.first, l1Group.second));
for (const auto &[key, value] : l1ConnMap) {
lgv.emplace_back(LayerGroup(key, value));
}

m_layerGroups.insert(std::make_pair(currentStage, lgv));
Expand All @@ -183,12 +174,9 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) {

GbtsConnector::~GbtsConnector() {
m_layerGroups.clear();
for (std::map<int, std::vector<GbtsConnection *>>::iterator it =
m_connMap.begin();
it != m_connMap.end(); ++it) {
for (std::vector<GbtsConnection *>::iterator cIt = (*it).second.begin();
cIt != (*it).second.end(); ++cIt) {
delete (*cIt);
for (const auto &[_, connections] : m_connMap) {
for (auto *conn : connections) {
delete conn;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Core/src/Vertexing/AdaptiveMultiVertexFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@ Result<void> AdaptiveMultiVertexFinder::deleteLastVertex(
return removeResult.error();
}

for (auto& entry : fitterState.tracksAtVerticesMap) {
for (auto& [key, value] : fitterState.tracksAtVerticesMap) {
// Delete all linearized tracks for current (bad) vertex
if (entry.first.second == &vtx) {
entry.second.isLinearized = false;
if (key.second == &vtx) {
value.isLinearized = false;
}
}

Expand Down
15 changes: 9 additions & 6 deletions Examples/Framework/src/Validation/TrackClassification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ void ActsExamples::identifyContributingParticles(

for (auto hitIndex : protoTrack) {
// register all particles that generated this hit
for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, hitParticle.second);
for (const auto& [_, value] :
makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, value);
}
}
sortHitCount(particleHitCounts);
Expand All @@ -79,8 +80,9 @@ void ActsExamples::identifyContributingParticles(
IndexSourceLink sl =
state.getUncalibratedSourceLink().template get<IndexSourceLink>();
auto hitIndex = sl.index();
for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, hitParticle.second);
for (const auto& [_, value] :
makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, value);
}
return true;
});
Expand All @@ -102,8 +104,9 @@ void ActsExamples::identifyContributingParticles(
IndexSourceLink sl =
state.getUncalibratedSourceLink().template get<IndexSourceLink>();
auto hitIndex = sl.index();
for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, hitParticle.second);
for (const auto& [_, value] :
makeRange(hitParticlesMap.equal_range(hitIndex))) {
increaseHitCount(particleHitCounts, value);
}
}
sortHitCount(particleHitCounts);
Expand Down
Loading

0 comments on commit 7b71164

Please sign in to comment.