Skip to content

Commit

Permalink
link: make sonar happier
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger committed Aug 26, 2024
1 parent 280e084 commit 13a585d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 116 deletions.
6 changes: 3 additions & 3 deletions Core/include/Acts/Geometry/CompositePortalLink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CompositePortalLink final : public PortalLinkBase {

/// Print the composite portal link
/// @param os The output stream
void toStream(std::ostream& os) const final;
void toStream(std::ostream& os) const override;

/// Resolve the volume for a 2D position
/// @note This will transform the position to global coordinates before
Expand All @@ -62,7 +62,7 @@ class CompositePortalLink final : public PortalLinkBase {
/// @param tolerance The on-surface tolerance
Result<const TrackingVolume*> resolveVolume(
const GeometryContext& gctx, const Vector2& position,
double tolerance = s_onSurfaceTolerance) const final;
double tolerance = s_onSurfaceTolerance) const override;

/// Resolve the volume for a 3D position
/// @note @p position is assumed to be on surface
Expand All @@ -71,7 +71,7 @@ class CompositePortalLink final : public PortalLinkBase {
/// @param tolerance The tolerance
Result<const TrackingVolume*> resolveVolume(
const GeometryContext& gctx, const Vector3& position,
double tolerance = s_onSurfaceTolerance) const final;
double tolerance = s_onSurfaceTolerance) const override;

/// Get the depth of the composite tree
/// @return The depth
Expand Down
85 changes: 42 additions & 43 deletions Core/include/Acts/Geometry/GridPortalLink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,18 @@ class GridPortalLink : public PortalLinkBase {
static std::unique_ptr<GridPortalLinkT<axis_t>> make(
std::shared_ptr<RegularSurface> surface, BinningValue direction,
axis_t&& axis) {
using enum BinningValue;
if (dynamic_cast<const CylinderSurface*>(surface.get()) != nullptr) {
if (direction != BinningValue::binZ &&
direction != BinningValue::binRPhi) {
throw std::invalid_argument{"Invalid binning direction"};
}
} else if (dynamic_cast<const DiscSurface*>(surface.get()) != nullptr) {
if (direction != BinningValue::binR &&
direction != BinningValue::binPhi) {
if (direction != binZ && direction != binRPhi) {
throw std::invalid_argument{"Invalid binning direction"};
}
} else if (dynamic_cast<const DiscSurface*>(surface.get()) != nullptr &&
direction != binR && direction != binPhi) {
throw std::invalid_argument{"Invalid binning direction"};
}

return std::make_unique<GridPortalLinkT<axis_t>>(surface, direction,
std::move(axis));
return std::make_unique<GridPortalLinkT<axis_t>>(
surface, direction, std::forward<axis_t>(axis));
}

/// Factory function for a two-dimensional grid portal link, which allows
Expand Down Expand Up @@ -347,7 +345,7 @@ class GridPortalLink : public PortalLinkBase {
/// @param other The axis to use for the missing direction,
/// can be null for auto determination
/// @return A unique pointer to the 2D grid portal link
std::unique_ptr<GridPortalLink> extendTo2d(
std::unique_ptr<GridPortalLink> extendTo2dImpl(
const std::shared_ptr<CylinderSurface>& surface,
const IAxis* other) const;

Expand All @@ -356,7 +354,7 @@ class GridPortalLink : public PortalLinkBase {
/// @param other The axis to use for the missing direction,
/// can be null for auto determination
/// @return A unique pointer to the 2D grid portal link
std::unique_ptr<GridPortalLink> extendTo2d(
std::unique_ptr<GridPortalLink> extendTo2dImpl(
const std::shared_ptr<DiscSurface>& surface, const IAxis* other) const;

/// Helper enum to declare which local direction to fill
Expand Down Expand Up @@ -415,14 +413,16 @@ class GridPortalLinkT final : public GridPortalLink {
BinningValue direction, Axes&&... axes)
: GridPortalLink(std::move(surface), direction),
m_grid(std::tuple{std::move(axes)...}) {
using enum BinningValue;

if (const auto* cylinder =
dynamic_cast<const CylinderSurface*>(m_surface.get())) {
checkConsistency(*cylinder);

if (direction == BinningValue::binRPhi) {
m_projection = &projection<CylinderSurface, BinningValue::binRPhi>;
} else if (direction == BinningValue::binZ) {
m_projection = &projection<CylinderSurface, BinningValue::binZ>;
if (direction == binRPhi) {
m_projection = &projection<CylinderSurface, binRPhi>;
} else if (direction == binZ) {
m_projection = &projection<CylinderSurface, binZ>;
} else {
throw std::invalid_argument{"Invalid binning direction"};
}
Expand All @@ -431,10 +431,10 @@ class GridPortalLinkT final : public GridPortalLink {
dynamic_cast<const DiscSurface*>(m_surface.get())) {
checkConsistency(*disc);

if (direction == BinningValue::binR) {
m_projection = &projection<DiscSurface, BinningValue::binR>;
if (direction == binR) {
m_projection = &projection<DiscSurface, binR>;
} else if (direction == BinningValue::binPhi) {
m_projection = &projection<DiscSurface, BinningValue::binPhi>;
m_projection = &projection<DiscSurface, binPhi>;
} else {
throw std::invalid_argument{"Invalid binning direction"};
}
Expand All @@ -446,36 +446,37 @@ class GridPortalLinkT final : public GridPortalLink {

/// Get the grid
/// @return The grid
const GridType& grid() const final { return m_grid; }
const GridType& grid() const override { return m_grid; }

/// Get the grid
/// @return The grid
GridType& grid() { return m_grid; }

/// Get the number of dimensions of the grid
/// @return The number of dimensions
unsigned int dim() const final { return DIM; }
unsigned int dim() const override { return DIM; }

/// Prints an identification to the output stream
/// @param os The output stream
void toStream(std::ostream& os) const final {
void toStream(std::ostream& os) const override {
os << "GridPortalLink<dim=" << dim() << ">";
}

/// Makes a 2D grid from a 1D grid by extending it using an optional axis
/// @param other The axis to use for the missing direction,
/// can be null for auto determination
/// @return A unique pointer to the 2D grid portal link
std::unique_ptr<GridPortalLink> extendTo2d(const IAxis* other) const final {
std::unique_ptr<GridPortalLink> extendTo2d(
const IAxis* other) const override {
if constexpr (DIM == 2) {
return std::make_unique<GridPortalLinkT<Axes...>>(*this);
} else {
if (auto cylinder =
std::dynamic_pointer_cast<CylinderSurface>(m_surface)) {
return GridPortalLink::extendTo2d(cylinder, other);
return extendTo2dImpl(cylinder, other);
} else if (auto disc =
std::dynamic_pointer_cast<DiscSurface>(m_surface)) {
return GridPortalLink::extendTo2d(disc, other);
return extendTo2dImpl(disc, other);
} else {
throw std::logic_error{
"Surface type is not supported (this should not happen)"};
Expand All @@ -485,7 +486,7 @@ class GridPortalLinkT final : public GridPortalLink {

/// Set the volume on all grid bins
/// @param volume The volume to set
void setVolume(TrackingVolume* volume) final {
void setVolume(TrackingVolume* volume) override {
auto loc = m_grid.numLocalBins();
if constexpr (GridType::DIM == 1) {
for (std::size_t i = 1; i <= loc[0]; i++) {
Expand All @@ -508,7 +509,7 @@ class GridPortalLinkT final : public GridPortalLink {
/// @return The tracking volume (can be null)
Result<const TrackingVolume*> resolveVolume(
const GeometryContext& gctx, const Vector3& position,
double tolerance = s_onSurfaceTolerance) const final {
double tolerance = s_onSurfaceTolerance) const override {
auto res = m_surface->globalToLocal(gctx, position, tolerance);
if (!res.ok()) {
return res.error();
Expand All @@ -524,15 +525,15 @@ class GridPortalLinkT final : public GridPortalLink {
/// @return The tracking volume (can be null)
Result<const TrackingVolume*> resolveVolume(
const GeometryContext& /*gctx*/, const Vector2& position,
double /*tolerance*/ = s_onSurfaceTolerance) const final {
double /*tolerance*/ = s_onSurfaceTolerance) const override {
assert(surface().insideBounds(position, BoundaryTolerance::None()));
return m_grid.atPosition(m_projection(position));
}

protected:
/// Type erased access to the number of bins
/// @return The number of bins in each direction
IndexType numLocalBins() const final {
IndexType numLocalBins() const override {
typename GridType::index_t idx = m_grid.numLocalBins();
IndexType result;
for (std::size_t i = 0; i < DIM; i++) {
Expand All @@ -544,7 +545,7 @@ class GridPortalLinkT final : public GridPortalLink {
/// Type erased local bin access
/// @param indices The bin indices
/// @return The tracking volume at the bin
TrackingVolume*& atLocalBins(IndexType indices) final {
TrackingVolume*& atLocalBins(IndexType indices) override {
throw_assert(indices.size() == DIM, "Invalid number of indices");
typename GridType::index_t idx;
for (std::size_t i = 0; i < DIM; i++) {
Expand All @@ -556,7 +557,7 @@ class GridPortalLinkT final : public GridPortalLink {
/// Type erased local bin access
/// @param indices The bin indices
/// @return The tracking volume at the bin
TrackingVolume* atLocalBins(IndexType indices) const final {
TrackingVolume* atLocalBins(IndexType indices) const override {
throw_assert(indices.size() == DIM, "Invalid number of indices");
typename GridType::index_t idx;
for (std::size_t i = 0; i < DIM; i++) {
Expand All @@ -570,37 +571,35 @@ class GridPortalLinkT final : public GridPortalLink {
/// possible 1D grid.
template <class surface_t, BinningValue direction>
static ActsVector<DIM> projection(const Vector2& position) {
using enum BinningValue;
if constexpr (DIM == 2) {
return position;
} else {
if constexpr (std::is_same_v<surface_t, CylinderSurface>) {
static_assert(direction == BinningValue::binRPhi ||
direction == BinningValue::binZ,
static_assert(direction == binRPhi || direction == binZ,
"Invalid binning direction");

if constexpr (direction == BinningValue::binRPhi) {
if constexpr (direction == binRPhi) {
return ActsVector<1>{position[0]};
} else if constexpr (direction == BinningValue::binZ) {
} else if constexpr (direction == binZ) {
return ActsVector<1>{position[1]};
}
} else if constexpr (std::is_same_v<surface_t, DiscSurface>) {
static_assert(direction == BinningValue::binR ||
direction == BinningValue::binPhi,
static_assert(direction == binR || direction == binPhi,
"Invalid binning direction");

if constexpr (direction == BinningValue::binR) {
if constexpr (direction == binR) {
return ActsVector<1>{position[0]};
} else if constexpr (direction == BinningValue::binPhi) {
} else if constexpr (direction == binPhi) {
return ActsVector<1>{position[1]};
}
} else if constexpr (std::is_same_v<surface_t, PlaneSurface>) {
static_assert(
direction == BinningValue::binX || direction == BinningValue::binY,
"Invalid binning direction");
static_assert(direction == binX || direction == binY,
"Invalid binning direction");

if constexpr (direction == BinningValue::binX) {
if constexpr (direction == binX) {
return ActsVector<1>{position[0]};
} else if constexpr (direction == BinningValue::binY) {
} else if constexpr (direction == binY) {
return ActsVector<1>{position[1]};
}
}
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Geometry/TrivialPortalLink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TrivialPortalLink final : public PortalLinkBase {

/// Print the portal link to a stream
/// @param os output stream
void toStream(std::ostream& os) const final;
void toStream(std::ostream& os) const override;

/// Resolve the volume for a 2D position
/// @note Always returns the single target volume
Expand All @@ -45,7 +45,7 @@ class TrivialPortalLink final : public PortalLinkBase {
/// @return The target volume (can be null)
Result<const TrackingVolume*> resolveVolume(
const GeometryContext& gctx, const Vector2& position,
double tolerance = s_onSurfaceTolerance) const final;
double tolerance = s_onSurfaceTolerance) const override;

/// Resolve the volume for a 3D position
/// @note Always returns the single target volume
Expand All @@ -56,7 +56,7 @@ class TrivialPortalLink final : public PortalLinkBase {
/// @note The position is assumed to be on the associated surface.
Result<const TrackingVolume*> resolveVolume(
const GeometryContext& gctx, const Vector3& position,
double tolerance = s_onSurfaceTolerance) const final;
double tolerance = s_onSurfaceTolerance) const override;

private:
TrackingVolume* m_volume;
Expand Down
Loading

0 comments on commit 13a585d

Please sign in to comment.