From a07a7b2a985b4f1e827a892ff184431773158dc0 Mon Sep 17 00:00:00 2001 From: Alice Faure <alice.faure@umontpellier.fr> Date: Tue, 18 Feb 2025 17:00:54 +0100 Subject: [PATCH] replace auto& with auto const& in iterators when possible --- .../random_iterator/detail/Random123/uniform.hpp | 6 +++--- corsika/detail/framework/utility/QuarticSolver.inl | 2 +- corsika/detail/modules/ParticleCut.inl | 2 +- corsika/detail/modules/proposal/ContinuousProcess.inl | 4 ++-- corsika/detail/modules/proposal/InteractionModel.inl | 4 ++-- .../detail/modules/proposal/ProposalProcessBase.inl | 10 +++++----- corsika/detail/modules/pythia8/Decay.inl | 6 +++--- corsika/detail/modules/sibyll/Decay.inl | 8 ++++---- .../detail/modules/sibyll/HadronInteractionModel.inl | 4 ++-- .../detail/modules/tracking/TrackingLeapFrogCurved.inl | 2 +- examples/cascade_examples/em_shower.cpp | 2 +- examples/cascade_examples/radio_em_shower.cpp | 2 +- examples/framework_examples/known_particles.cpp | 2 +- tests/modules/testOnShellCheck.cpp | 4 ++-- tests/modules/testParticleCut.cpp | 10 +++++----- tests/modules/testUrQMD.cpp | 2 +- tests/output/testInteractionWriter.cpp | 2 +- 17 files changed, 36 insertions(+), 36 deletions(-) diff --git a/corsika/detail/framework/random/random_iterator/detail/Random123/uniform.hpp b/corsika/detail/framework/random/random_iterator/detail/Random123/uniform.hpp index 55cb8e940..3b5a7891d 100644 --- a/corsika/detail/framework/random/random_iterator/detail/Random123/uniform.hpp +++ b/corsika/detail/framework/random/random_iterator/detail/Random123/uniform.hpp @@ -286,7 +286,7 @@ namespace random_iterator_r123 { static inline std::array<Ftype, CollType::static_size> u01all(CollType in) { std::array<Ftype, CollType::static_size> ret; size_t i = 0; - for (auto& e : in) { ret[i++] = u01<Ftype>(e); } + for (auto const& e : in) { ret[i++] = u01<Ftype>(e); } return ret; } @@ -300,7 +300,7 @@ namespace random_iterator_r123 { static inline std::array<Ftype, CollType::static_size> uneg11all(CollType in) { std::array<Ftype, CollType::static_size> ret; size_t i = 0; - for (auto& e : in) { ret[i++] = uneg11<Ftype>(e); } + for (auto const& e : in) { ret[i++] = uneg11<Ftype>(e); } return ret; } @@ -314,7 +314,7 @@ namespace random_iterator_r123 { static inline std::array<Ftype, CollType::static_size> u01fixedptall(CollType in) { std::array<Ftype, CollType::static_size> ret; size_t i = 0; - for (auto& e : in) { ret[i++] = u01fixedpt<Ftype>(e); } + for (auto const& e : in) { ret[i++] = u01fixedpt<Ftype>(e); } return ret; } #endif // __cplusplus >= 201103L diff --git a/corsika/detail/framework/utility/QuarticSolver.inl b/corsika/detail/framework/utility/QuarticSolver.inl index 150f658a9..b3eead4d5 100644 --- a/corsika/detail/framework/utility/QuarticSolver.inl +++ b/corsika/detail/framework/utility/QuarticSolver.inl @@ -79,7 +79,7 @@ namespace corsika { std::vector<double> quad1 = solve_quadratic_real(1, p1, q1, 1e-5); std::vector<double> quad2 = solve_quadratic_real(1, p2, q2, 1e-5); if (quad2.size() > 0) { - for (auto& val : quad2) quad1.push_back(val); + for (auto const& val : quad2) quad1.push_back(val); } return quad1; } diff --git a/corsika/detail/modules/ParticleCut.inl b/corsika/detail/modules/ParticleCut.inl index cadf431a7..f470a475e 100644 --- a/corsika/detail/modules/ParticleCut.inl +++ b/corsika/detail/modules/ParticleCut.inl @@ -26,7 +26,7 @@ namespace corsika { , cut_muons_(eMuCut) , cut_tau_(eTauCut) , doCutInv_(inv) { - for (auto& p : get_all_particles()) { + for (auto const& p : get_all_particles()) { if (is_hadron(p)) // nuclei are also hadrons set_kinetic_energy_propagation_threshold(p, eHadCut); else if (is_muon(p)) diff --git a/corsika/detail/modules/proposal/ContinuousProcess.inl b/corsika/detail/modules/proposal/ContinuousProcess.inl index 6a27c105c..7961d7223 100644 --- a/corsika/detail/modules/proposal/ContinuousProcess.inl +++ b/corsika/detail/modules/proposal/ContinuousProcess.inl @@ -50,8 +50,8 @@ namespace corsika::proposal { : ProposalProcessBase(_env) , TOutput(args...) { //! Initialize PROPOSAL tables for all media and all particles - for (auto& medium : media) { - for (auto& particle_code : tracked) { + for (auto const& medium : media) { + for (auto const& particle_code : tracked) { buildCalculator(particle_code, medium.first); } } diff --git a/corsika/detail/modules/proposal/InteractionModel.inl b/corsika/detail/modules/proposal/InteractionModel.inl index 846bd5b41..b903fdde2 100644 --- a/corsika/detail/modules/proposal/InteractionModel.inl +++ b/corsika/detail/modules/proposal/InteractionModel.inl @@ -28,8 +28,8 @@ namespace corsika::proposal { , HadronicPhotonModel<THadronicLEModel, THadronicHEModel>(_hadintLE, _hadintHE, _enthreshold) { //! Initialize PROPOSAL tables for all media and all particles - for (auto& medium : media) { - for (auto& particle_code : tracked) { + for (auto const& medium : media) { + for (auto const& particle_code : tracked) { buildCalculator(particle_code, medium.first); } } diff --git a/corsika/detail/modules/proposal/ProposalProcessBase.inl b/corsika/detail/modules/proposal/ProposalProcessBase.inl index 47d7e8d28..b0f503222 100644 --- a/corsika/detail/modules/proposal/ProposalProcessBase.inl +++ b/corsika/detail/modules/proposal/ProposalProcessBase.inl @@ -33,7 +33,7 @@ namespace corsika::proposal { HEPEnergyType lowest_table_value = 0_GeV; // find tables for EnergyCuts closest (but still smaller than) production_threshold - for (auto& table_energy : energycut_table_values) { + for (auto const& table_energy : energycut_table_values) { if (table_energy <= production_threshold && table_energy > lowest_table_value) { lowest_table_value = table_energy; } @@ -57,7 +57,7 @@ namespace corsika::proposal { auto comp_vec = std::vector<PROPOSAL::Component>(); const auto& comp = prop.getNuclearComposition(); auto frac_iter = comp.getFractions().cbegin(); - for (auto& pcode : comp.getComponents()) { + for (auto const& pcode : comp.getComponents()) { comp_vec.emplace_back(std::string(get_name(pcode)), get_nucleus_Z(pcode), get_nucleus_A(pcode), *frac_iter); ++frac_iter; @@ -76,7 +76,7 @@ namespace corsika::proposal { PROPOSAL::InterpolationSettings::TABLES_PATH = corsika_data("PROPOSAL").c_str(); //! Initialize EnergyCutSettings - for (auto& particle_code : tracked) { + for (auto const& particle_code : tracked) { if (particle_code == Code::Photon) { // no EnergyCut for photon, only-stochastic propagation continue; @@ -89,8 +89,8 @@ namespace corsika::proposal { } //! Initialize PROPOSAL tables for all media and all particles - for (auto& medium : media) { - for (auto& particle_code : tracked) { + for (auto const& medium : media) { + for (auto const& particle_code : tracked) { buildTables(medium.second, particle_code, proposal_energycutsettings[particle_code]); } diff --git a/corsika/detail/modules/pythia8/Decay.inl b/corsika/detail/modules/pythia8/Decay.inl index 780ce272a..d98a43a45 100644 --- a/corsika/detail/modules/pythia8/Decay.inl +++ b/corsika/detail/modules/pythia8/Decay.inl @@ -88,7 +88,7 @@ namespace corsika::pythia8 { inline void Decay::setHandleDecay(std::vector<Code> const& vParticleList) { handleAllDecays_ = false; - for (auto& p : vParticleList) setHandleDecay(p); + for (auto const& p : vParticleList) setHandleDecay(p); } inline bool Decay::isDecayHandled(Code const vParticleCode) { @@ -99,7 +99,7 @@ namespace corsika::pythia8 { } inline void Decay::setStable(std::vector<Code> const& particleList) { - for (auto& p : particleList) Decay::setStable(p); + for (auto const& p : particleList) Decay::setStable(p); } inline void Decay::setUnstable(Code const pCode) { @@ -134,7 +134,7 @@ namespace corsika::pythia8 { if (handleAllDecays_) CORSIKA_LOG_INFO(" all particles known to Pythia are handled by Pythia::Decay!"); else - for (auto& pCode : handledDecays_) + for (auto const& pCode : handledDecays_) CORSIKA_LOG_INFO("Decay of {} is handled by Pythia!", pCode); } diff --git a/corsika/detail/modules/sibyll/Decay.inl b/corsika/detail/modules/sibyll/Decay.inl index fd843a732..1910626d2 100644 --- a/corsika/detail/modules/sibyll/Decay.inl +++ b/corsika/detail/modules/sibyll/Decay.inl @@ -63,7 +63,7 @@ namespace corsika::sibyll { inline void Decay::setHandleDecay(std::vector<Code> const& vParticleList) { handleAllDecays_ = false; - for (auto& p : vParticleList) Decay::setHandleDecay(p); + for (auto const& p : vParticleList) Decay::setHandleDecay(p); } inline bool Decay::isDecayHandled(corsika::Code const vParticleCode) { @@ -76,11 +76,11 @@ namespace corsika::sibyll { } inline void Decay::setStable(std::vector<Code> const& vParticleList) { - for (auto& p : vParticleList) Decay::setStable(p); + for (auto const& p : vParticleList) Decay::setStable(p); } inline void Decay::setUnstable(std::vector<Code> const& vParticleList) { - for (auto& p : vParticleList) Decay::setUnstable(p); + for (auto const& p : vParticleList) Decay::setUnstable(p); } inline bool Decay::isStable(Code const vCode) { @@ -130,7 +130,7 @@ namespace corsika::sibyll { logger_, " all particles known to Sibyll are handled by Sibyll::Decay!"); } else { - for ([[maybe_unused]] auto& pCode : handledDecays_) { + for ([[maybe_unused]] auto const& pCode : handledDecays_) { CORSIKA_LOGGER_DEBUG(logger_, " Decay of {} is handled by Sibyll!", pCode); } } diff --git a/corsika/detail/modules/sibyll/HadronInteractionModel.inl b/corsika/detail/modules/sibyll/HadronInteractionModel.inl index a841d5d22..8cb74a96e 100644 --- a/corsika/detail/modules/sibyll/HadronInteractionModel.inl +++ b/corsika/detail/modules/sibyll/HadronInteractionModel.inl @@ -58,7 +58,7 @@ namespace corsika::sibyll { inline void HadronInteractionModel::setParticleListStable(std::set<Code> vList) { // de-activate specific decays in SIBYLL - for (auto& p : vList) { + for (auto const& p : vList) { CORSIKA_LOGGER_DEBUG(logger_, "setting {} as \"stable\". ", p); auto const sib_code = sibyll::convertToSibyll(p); if (sib_code != corsika::sibyll::SibyllCode::Unknown) { @@ -196,7 +196,7 @@ namespace corsika::sibyll { auto const& originalCS = boost.getOriginalCS(); MomentumVector Plab_final(originalCS, {0.0_GeV, 0.0_GeV, 0.0_GeV}); HEPEnergyType Elab_final = 0_GeV, Ecm_final = 0_GeV; - for (auto& psib : ss) { + for (auto const& psib : ss) { // abort on particles that have decayed in Sibyll. Should not happen! if (psib.hasDecayed()) { // LCOV_EXCL_START if (internal_decays_) { diff --git a/corsika/detail/modules/tracking/TrackingLeapFrogCurved.inl b/corsika/detail/modules/tracking/TrackingLeapFrogCurved.inl index 909b8660a..6874eeb22 100644 --- a/corsika/detail/modules/tracking/TrackingLeapFrogCurved.inl +++ b/corsika/detail/modules/tracking/TrackingLeapFrogCurved.inl @@ -193,7 +193,7 @@ namespace corsika { if (!solutions.size()) { return Intersections(); } LengthType d_enter, d_exit; int first = 0, first_entry = 0, first_exit = 0; - for (auto& solution : solutions) { + for (auto const& solution : solutions) { LengthType const dist = solution * 1_m; CORSIKA_LOG_TRACE( "Solution (real) for current Volume: deltaL/2*2={} (deltaL/2*2/v={}) ", dist, diff --git a/examples/cascade_examples/em_shower.cpp b/examples/cascade_examples/em_shower.cpp index 0aaf3b029..4c3b15d8b 100644 --- a/examples/cascade_examples/em_shower.cpp +++ b/examples/cascade_examples/em_shower.cpp @@ -105,7 +105,7 @@ int main(int argc, char** argv) { {Code::Positron, 5_MeV}, {Code::Photon, 5_MeV}, }; - for (auto& [pcode, energy] : energy_resolution) + for (auto const& [pcode, energy] : energy_resolution) set_energy_production_threshold(pcode, energy); const Code beamCode = Code::Electron; diff --git a/examples/cascade_examples/radio_em_shower.cpp b/examples/cascade_examples/radio_em_shower.cpp index 06aa5bc10..abd4fa3f8 100644 --- a/examples/cascade_examples/radio_em_shower.cpp +++ b/examples/cascade_examples/radio_em_shower.cpp @@ -129,7 +129,7 @@ int main(int argc, char** argv) { {Code::Positron, 5_MeV}, {Code::Photon, 5_MeV}, }; - for (auto& [pcode, energy] : energy_resolution) + for (auto const& [pcode, energy] : energy_resolution) set_energy_production_threshold(pcode, energy); Code const beamCode = Code::Electron; diff --git a/examples/framework_examples/known_particles.cpp b/examples/framework_examples/known_particles.cpp index 92adf881d..94ad08285 100644 --- a/examples/framework_examples/known_particles.cpp +++ b/examples/framework_examples/known_particles.cpp @@ -41,7 +41,7 @@ int main() { "PDG-mass (GeV) | " "SIBYLL-mass (GeV)|"); logging::info("{:->{}}", ' ', width); - for (auto& p : get_all_particles()) { + for (auto const& p : get_all_particles()) { if (!is_nucleus(p)) { corsika::sibyll::SibyllCode sib_id = corsika::sibyll::convertToSibyll(p); auto const sib_mass = (sib_id != corsika::sibyll::SibyllCode::Unknown diff --git a/tests/modules/testOnShellCheck.cpp b/tests/modules/testOnShellCheck.cpp index 33724e408..697e0ae58 100644 --- a/tests/modules/testOnShellCheck.cpp +++ b/tests/modules/testOnShellCheck.cpp @@ -57,7 +57,7 @@ TEST_CASE("OnShellCheck", "[processes]") { // add secondaries, all with energies above the threshold // only cut is by species int count = -1; - for (auto& proType : particleList) { + for (auto const& proType : particleList) { count++; const auto pz = sqrt((E - get_mass(proType) * mass_shifts[count]) * (E + get_mass(proType) * mass_shifts[count])); @@ -67,7 +67,7 @@ TEST_CASE("OnShellCheck", "[processes]") { } check.doSecondaries(view); int i = -1; - for (auto& p : view) { + for (auto const& p : view) { i++; auto const Plab = FourVector(p.getEnergy(), p.getMomentum()); auto const m_kinetic = Plab.getNorm(); diff --git a/tests/modules/testParticleCut.cpp b/tests/modules/testParticleCut.cpp index 7bed87e2c..85b344faa 100644 --- a/tests/modules/testParticleCut.cpp +++ b/tests/modules/testParticleCut.cpp @@ -69,7 +69,7 @@ TEST_CASE("ParticleCut", "process,continuous,secondary") { auto projectile = view.getProjectile(); // add secondaries, all with energies above the threshold // only cut is by species - for (auto& proType : particleList) + for (auto const& proType : particleList) projectile.addSecondary( std::make_tuple(proType, Eabove, DirectionVector(rootCS, {1, 0, 0}))); CHECK(view.getEntries() == 11); @@ -94,7 +94,7 @@ TEST_CASE("ParticleCut", "process,continuous,secondary") { auto projectile = view.getProjectile(); // add secondaries, all with energies above the threshold // only cut is by species - for (auto& proType : particleList) { + for (auto const& proType : particleList) { projectile.addSecondary( std::make_tuple(proType, Eabove, DirectionVector(rootCS, {1, 0, 0}))); } @@ -116,7 +116,7 @@ TEST_CASE("ParticleCut", "process,continuous,secondary") { auto projectile = view.getProjectile(); // add secondaries, all with energies below the threshold // only cut is by species - for (auto& proType : particleList) + for (auto const& proType : particleList) projectile.addSecondary( std::make_tuple(proType, Ebelow, DirectionVector(rootCS, {1, 0, 0}))); unsigned short A = 18; @@ -189,7 +189,7 @@ TEST_CASE("ParticleCut", "process,continuous,secondary") { auto projectile = view.getProjectile(); // add secondaries, all with energies above the threshold // only cut is by time - for (auto& proType : particleList) { + for (auto const& proType : particleList) { projectile.addSecondary( std::make_tuple(proType, Eabove, DirectionVector(rootCS, {1, 0, 0}))); } @@ -208,7 +208,7 @@ TEST_CASE("ParticleCut", "process,continuous,secondary") { // add particles, all with energies above the threshold // only cut is by species - for (auto& proType : particleList) { + for (auto const& proType : particleList) { auto particle = stack.addParticle( std::make_tuple(proType, Eabove - get_mass(proType), DirectionVector(rootCS, {1, 0, 0}), point0, 0_ns)); diff --git a/tests/modules/testUrQMD.cpp b/tests/modules/testUrQMD.cpp index 0bdf1313c..676d97269 100644 --- a/tests/modules/testUrQMD.cpp +++ b/tests/modules/testUrQMD.cpp @@ -94,7 +94,7 @@ TEST_CASE("UrQMD") { 303_mb, 189_mb, 198_mb, 172_mb}; int i = 0; - for (auto& code : validProjectileCodes) { + for (auto const& code : validProjectileCodes) { FourMomentum const projectileP4{ sqrt(static_pow<2>(get_mass(code)) + static_pow<2>(P0)), {rootCS, {0_GeV, 0_GeV, P0}}}; diff --git a/tests/output/testInteractionWriter.cpp b/tests/output/testInteractionWriter.cpp index 0bcb3bf1f..9d4d3e3bd 100644 --- a/tests/output/testInteractionWriter.cpp +++ b/tests/output/testInteractionWriter.cpp @@ -87,7 +87,7 @@ TEST_CASE("InteractionWriter", "process") { Code::Electron, Code::MuPlus, Code::NuE, Code::Neutron, Code::NuMu}; - for (auto& proType : particleList) + for (auto const& proType : particleList) projectile.addSecondary( std::make_tuple(proType, 1_GeV, DirectionVector(rootCS, {1, 0, 0}))); -- GitLab