Skip to content

Commit

Permalink
Merge pull request #41164 from makortel/tibringOptional
Browse files Browse the repository at this point in the history
Use std::optional to work around maybe-uninitialized warning
  • Loading branch information
cmsbuild authored Apr 17, 2023
2 parents 2c216a2 + f14223b commit 107dcfb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
23 changes: 11 additions & 12 deletions RecoTracker/TkDetLayers/src/TIBRing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,27 @@ void TIBRing::groupedCompatibleDetsV(const TrajectoryStateOnSurface& tsos,
const MeasurementEstimator& est,
vector<DetGroup>& result) const {
vector<DetGroup> 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;
}

DetGroupElement closestGel(closestResult.front().front());
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<DetGroup> 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 {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -194,8 +193,8 @@ void TIBRing::searchNeighbors(const TrajectoryStateOnSurface& tsos,
}
}

TIBRing::SubRingCrossings TIBRing::computeCrossings(const TrajectoryStateOnSurface& startingState,
PropagationDirection propDir) const {
std::optional<TIBRing::SubRingCrossings> TIBRing::computeCrossings(const TrajectoryStateOnSurface& startingState,
PropagationDirection propDir) const {
typedef HelixBarrelPlaneCrossing2OrderLocal Crossing;
typedef MeasurementEstimator::Local2DVector Local2DVector;

Expand All @@ -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());
Expand Down
10 changes: 5 additions & 5 deletions RecoTracker/TkDetLayers/src/TIBRing.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "DataFormats/GeometrySurface/interface/BoundCylinder.h"
#include "Utilities/BinningTools/interface/PeriodicBinFinderInPhi.h"

#include <optional>

/** A concrete implementation for TIB rings
*/

Expand Down Expand Up @@ -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;
Expand All @@ -65,8 +65,8 @@ class TIBRing final : public GeometricSearchDet {
float window,
std::vector<DetGroup>& result) const __attribute__((hot));

SubRingCrossings computeCrossings(const TrajectoryStateOnSurface& startingState, PropagationDirection propDir) const
__attribute__((hot));
std::optional<SubRingCrossings> computeCrossings(const TrajectoryStateOnSurface& startingState,
PropagationDirection propDir) const __attribute__((hot));

float computeWindowSize(const GeomDet* det,
const TrajectoryStateOnSurface& tsos,
Expand Down

0 comments on commit 107dcfb

Please sign in to comment.