From a36b18aff029f83271ac1624900599a514f4664a Mon Sep 17 00:00:00 2001 From: Christos Anastopoulos <christos.anastopoulos@cern.ch> Date: Mon, 26 Oct 2020 10:32:00 +0000 Subject: [PATCH] GSF . clang-tidy checks. Including possible use after move bugfix --- .../src/GaussianSumFitter.cxx | 41 +++++++++++-------- .../src/GsfMaterialMixtureConvolution.cxx | 2 +- .../src/GsfMeasurementUpdator.cxx | 2 +- .../src/MultiComponentStateCombiner.cxx | 2 +- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx index 0935a410def..be6355212cf 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx @@ -10,9 +10,9 @@ */ #include "TrkGaussianSumFilter/GaussianSumFitter.h" -#include "TrkGaussianSumFilter/GsfConstants.h" #include "TrkEventUtils/MeasurementBaseComparisonFunction.h" #include "TrkEventUtils/PrepRawDataComparisonFunction.h" +#include "TrkGaussianSumFilter/GsfConstants.h" #include "TrkGaussianSumFilter/IMultiStateExtrapolator.h" #include "TrkGaussianSumFilter/MultiComponentStateCombiner.h" #include "TrkParameters/TrackParameters.h" @@ -709,14 +709,15 @@ Trk::GaussianSumFitter::makePerigee( } const Trk::MultiComponentStateOnSurface* perigeeMultiStateOnSurface = - new MultiComponentStateOnSurface( - nullptr, - combinedPerigee.release(), - Trk::MultiComponentStateHelpers::toPtr(std::move(stateExtrapolatedToPerigee)).release(), - nullptr, - nullptr, - pattern, - modeQoverP); + new MultiComponentStateOnSurface(nullptr, + combinedPerigee.release(), + Trk::MultiComponentStateHelpers::toPtr( + std::move(stateExtrapolatedToPerigee)) + .release(), + nullptr, + nullptr, + pattern, + modeQoverP); return perigeeMultiStateOnSurface; } @@ -964,6 +965,8 @@ Trk::GaussianSumFitter::stepForwardFit( } auto fitQuality = std::make_unique<Trk::FitQualityOnSurface>(); + //Here we need to clone as the extrapolated state can be used + //afterwards updatedState = m_updator.update( std::move(*(MultiComponentStateHelpers::clone(extrapolatedState))), *measurement, @@ -981,7 +984,8 @@ Trk::GaussianSumFitter::stepForwardFit( const Trk::MultiComponentStateOnSurface* multiComponentStateOnSurface = new MultiComponentStateOnSurface( measurement.release(), - Trk::MultiComponentStateHelpers::toPtr(std::move(extrapolatedState)).release(), + //used below for the updated state so clone + Trk::MultiComponentStateHelpers::clone(extrapolatedState).release(), fitQuality.release(), nullptr, type); @@ -993,7 +997,8 @@ Trk::GaussianSumFitter::stepForwardFit( const Trk::MultiComponentStateOnSurface* multiComponentStateOnSurface = new MultiComponentStateOnSurface( measurement.release(), - Trk::MultiComponentStateHelpers::toPtr(std::move(extrapolatedState)).release(), + Trk::MultiComponentStateHelpers::toPtr(std::move(extrapolatedState)) + .release(), fitQuality.release()); forwardTrajectory.push_back(multiComponentStateOnSurface); } @@ -1094,6 +1099,8 @@ Trk::GaussianSumFitter::fit( MultiComponentStateCombiner::combine(firstSmoothedState, true); /*Create updatedStateOnSurface which owned be the tragectory*/ + //we clone do not just move firstSmoothedState as used + //afterwards const Trk::MultiComponentStateOnSurface* updatedStateOnSurface = new MultiComponentStateOnSurface( firstSmootherMeasurementOnTrack, @@ -1131,7 +1138,7 @@ Trk::GaussianSumFitter::fit( MultiComponentStateHelpers::cloneWithScaledError( firstSmoothedState, 15., 5., 15., 5., 15.); - // Perform a measurement update on this new state + // Perform a measurement update on this new state before loop Trk::MultiComponentState updatedState = m_updator.update( std::move(*smoothedStateWithScaledError), *firstSmootherMeasurementOnTrack); @@ -1187,6 +1194,7 @@ Trk::GaussianSumFitter::fit( return nullptr; } + // In the following the updated state is reset // Original measurement was flagged as an outlier if (!(*trackStateOnSurface)->type(TrackStateOnSurface::Measurement)) { updatedState = std::move(extrapolatedState); @@ -1206,7 +1214,6 @@ Trk::GaussianSumFitter::fit( continue; } - updatedState = m_updator.update(std::move(extrapolatedState), *measurement, fitQuality); if (updatedState.empty()) { @@ -1259,7 +1266,8 @@ Trk::GaussianSumFitter::fit( const Trk::MultiComponentStateOnSurface* combinedStateOnSurface = new MultiComponentStateOnSurface( measurement.release(), - Trk::MultiComponentStateHelpers::toPtr(std::move(combinedState2)).release(), + Trk::MultiComponentStateHelpers::toPtr(std::move(combinedState2)) + .release(), combinedFitQuality.release()); smoothedTrajectory->push_back(combinedStateOnSurface); } else { @@ -1271,6 +1279,7 @@ Trk::GaussianSumFitter::fit( std::unique_ptr<Trk::TrackParameters> combinedLastState = MultiComponentStateCombiner::combine(updatedState, true); + //Here we can move the updated state we created above if (combinedLastState) { updatedStateOnSurface = new Trk::MultiComponentStateOnSurface( measurement.release(), @@ -1321,7 +1330,7 @@ Trk::GaussianSumFitter::combine( Loop over all components in forwards multi-state ================================================ */ - for (auto& forwardsComponent : forwardsMultiState) { + for (const auto & forwardsComponent : forwardsMultiState) { // Need to check that all components have associated weight matricies const AmgSymMatrix(5)* forwardMeasuredCov = forwardsComponent.first->covariance(); @@ -1330,7 +1339,7 @@ Trk::GaussianSumFitter::combine( Loop over all components in the smoother multi-state ==================================================== */ - for (auto& smootherComponent : smootherMultiState) { + for (const auto & smootherComponent : smootherMultiState) { // Need to check that all components have associated weight matricies const AmgSymMatrix(5)* smootherMeasuredCov = smootherComponent.first->covariance(); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialMixtureConvolution.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialMixtureConvolution.cxx index 84768baddc8..af30dd6e192 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialMixtureConvolution.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialMixtureConvolution.cxx @@ -307,7 +307,7 @@ Trk::GsfMaterialMixtureConvolution::update( } if (componentWithoutMeasurement) { - auto result = std::max_element( + auto *result = std::max_element( components.begin(), components.end(), [](const auto& a, const auto& b) { return a.weight < b.weight; }); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMeasurementUpdator.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMeasurementUpdator.cxx index 9e54822727b..8bd498699c0 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMeasurementUpdator.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMeasurementUpdator.cxx @@ -247,7 +247,7 @@ bool Trk::GsfMeasurementUpdator::invalidComponent( const Trk::TrackParameters* trackParameters) const { - auto measuredCov = trackParameters->covariance(); + const auto *measuredCov = trackParameters->covariance(); bool rebuildCov = false; if (!measuredCov) { rebuildCov = true; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateCombiner.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateCombiner.cxx index 1870407f4a9..bb7ceda8648 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateCombiner.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateCombiner.cxx @@ -262,7 +262,7 @@ Trk::MultiComponentStateCombiner::combineWithWeight( const double secondWeight) { double firstWeight = mergeTo.second; - auto trackParameters = mergeTo.first.get(); + auto *trackParameters = mergeTo.first.get(); const AmgVector(5)& firstParameters = trackParameters->parameters(); AmgVector(5) finalParameters(firstParameters); // Check to see if first track parameters are measured or not -- GitLab