From f14223bc0422aaf39326dbf1edd77906a9cc818f Mon Sep 17 00:00:00 2001 From: Matti Kortelainen Date: Tue, 14 Mar 2023 16:54:04 +0100 Subject: [PATCH] Use std::optional to work around maybe-uninitialized warning --- RecoTracker/TkDetLayers/src/TIBRing.cc | 23 +++++++++++------------ RecoTracker/TkDetLayers/src/TIBRing.h | 10 +++++----- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/RecoTracker/TkDetLayers/src/TIBRing.cc b/RecoTracker/TkDetLayers/src/TIBRing.cc index 0cd5568e68f53..5057bd9a03fa5 100644 --- a/RecoTracker/TkDetLayers/src/TIBRing.cc +++ b/RecoTracker/TkDetLayers/src/TIBRing.cc @@ -111,16 +111,15 @@ void TIBRing::groupedCompatibleDetsV(const TrajectoryStateOnSurface& tsos, const MeasurementEstimator& est, vector& result) const { vector closestResult; - SubRingCrossings crossings; - crossings = computeCrossings(tsos, prop.propagationDirection()); - if (!crossings.isValid_) + auto crossings = computeCrossings(tsos, prop.propagationDirection()); + if (not crossings) return; typedef CompatibleDetToGroupAdder Adder; - Adder::add(*theDets[theBinFinder.binIndex(crossings.closestIndex)], tsos, prop, est, closestResult); + Adder::add(*theDets[theBinFinder.binIndex(crossings->closestIndex)], tsos, prop, est, closestResult); if (closestResult.empty()) { - Adder::add(*theDets[theBinFinder.binIndex(crossings.nextIndex)], tsos, prop, est, result); + Adder::add(*theDets[theBinFinder.binIndex(crossings->nextIndex)], tsos, prop, est, result); return; } @@ -128,11 +127,11 @@ void TIBRing::groupedCompatibleDetsV(const TrajectoryStateOnSurface& tsos, float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est); float detWidth = closestGel.det()->surface().bounds().width(); - if (crossings.nextDistance < detWidth + window) { + if (crossings->nextDistance < detWidth + window) { vector nextResult; - if (Adder::add(*theDets[theBinFinder.binIndex(crossings.nextIndex)], tsos, prop, est, nextResult)) { + if (Adder::add(*theDets[theBinFinder.binIndex(crossings->nextIndex)], tsos, prop, est, nextResult)) { int crossingSide = LayerCrossingSide::barrelSide(tsos, prop); - if (crossings.closestIndex < crossings.nextIndex) { + if (crossings->closestIndex < crossings->nextIndex) { DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result, theHelicity, crossingSide); } else { @@ -148,7 +147,7 @@ void TIBRing::groupedCompatibleDetsV(const TrajectoryStateOnSurface& tsos, // only loop over neighbors (other than closest and next) if window is BIG if (window > 0.5f * detWidth) { - searchNeighbors(tsos, prop, est, crossings, window, result); + searchNeighbors(tsos, prop, est, *crossings, window, result); } } @@ -194,8 +193,8 @@ void TIBRing::searchNeighbors(const TrajectoryStateOnSurface& tsos, } } -TIBRing::SubRingCrossings TIBRing::computeCrossings(const TrajectoryStateOnSurface& startingState, - PropagationDirection propDir) const { +std::optional TIBRing::computeCrossings(const TrajectoryStateOnSurface& startingState, + PropagationDirection propDir) const { typedef HelixBarrelPlaneCrossing2OrderLocal Crossing; typedef MeasurementEstimator::Local2DVector Local2DVector; @@ -207,7 +206,7 @@ TIBRing::SubRingCrossings TIBRing::computeCrossings(const TrajectoryStateOnSurfa startPos, startDir, rho, propDir, specificSurface(), HelixBarrelCylinderCrossing::bestSol); if (!cylCrossing.hasSolution()) - return SubRingCrossings(); + return std::nullopt; GlobalPoint cylPoint(cylCrossing.position()); GlobalVector cylDir(cylCrossing.direction()); diff --git a/RecoTracker/TkDetLayers/src/TIBRing.h b/RecoTracker/TkDetLayers/src/TIBRing.h index 5e44a7e11f00c..67f44d2cf07c8 100644 --- a/RecoTracker/TkDetLayers/src/TIBRing.h +++ b/RecoTracker/TkDetLayers/src/TIBRing.h @@ -5,6 +5,8 @@ #include "DataFormats/GeometrySurface/interface/BoundCylinder.h" #include "Utilities/BinningTools/interface/PeriodicBinFinderInPhi.h" +#include + /** A concrete implementation for TIB rings */ @@ -49,10 +51,8 @@ class TIBRing final : public GeometricSearchDet { // methods for groupedCompatibleDets implementation struct SubRingCrossings { - SubRingCrossings() : isValid_(false){}; - SubRingCrossings(int ci, int ni, float nd) : isValid_(true), closestIndex(ci), nextIndex(ni), nextDistance(nd) {} + SubRingCrossings(int ci, int ni, float nd) : closestIndex(ci), nextIndex(ni), nextDistance(nd) {} - bool isValid_; int closestIndex; int nextIndex; float nextDistance; @@ -65,8 +65,8 @@ class TIBRing final : public GeometricSearchDet { float window, std::vector& result) const __attribute__((hot)); - SubRingCrossings computeCrossings(const TrajectoryStateOnSurface& startingState, PropagationDirection propDir) const - __attribute__((hot)); + std::optional computeCrossings(const TrajectoryStateOnSurface& startingState, + PropagationDirection propDir) const __attribute__((hot)); float computeWindowSize(const GeomDet* det, const TrajectoryStateOnSurface& tsos,