Skip to content

Commit

Permalink
fix more sonar cloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Oct 22, 2024
1 parent bb6a963 commit d674273
Show file tree
Hide file tree
Showing 112 changed files with 1,699 additions and 2,081 deletions.
3 changes: 2 additions & 1 deletion core/include/detray/builders/surface_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class surface_factory : public surface_factory_interface<detector_t> {
DETRAY_HOST
void push_back(surface_data_t &&sf_data) override {

auto [type, vlink, index, source, bounds, trf] = sf_data.get_data();
auto [type, vlink, index, source, bounds, trf] =
std::move(sf_data).get_data();

assert(bounds.size() == mask_shape_t::boundaries::e_size);

Expand Down
25 changes: 0 additions & 25 deletions core/include/detray/definitions/detail/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,6 @@ namespace detail {
using math::copysign;
using math::signbit;

/// Composes a floating point value with the magnitude of @param mag and the
/// sign of @param sgn
/*template <typename scalar_t>
DETRAY_HOST_DEVICE inline scalar_t copysign(scalar_t mag, scalar_t sgn) {
#if defined(__CUDACC__)
if constexpr (std::is_same_v<scalar_t, float>) {
return copysignf(mag, sgn);
} else {
return copysign(mag, sgn);
}
#elif !defined(__CUDACC__)
return math::copysign(mag, sgn);
#endif
}
/// Gets the signbit from a variable
template <typename scalar_t>
DETRAY_HOST_DEVICE inline bool signbit(scalar_t arg) {
#if defined(__CUDACC__)
return signbit(arg);
#elif !defined(__CUDACC__)
return math::signbit(arg);
#endif
}*/

} // namespace detail

} // namespace detray
2 changes: 1 addition & 1 deletion core/include/detray/geometry/detail/shape_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace detray::detail {
/// @return the opening angle of a chord the size of tol (= 2*arcsin(c/(2r)))
/// using a small angle approximation
template <typename scalar_t>
inline constexpr scalar_t phi_tolerance(scalar_t tol, scalar_t radius) {
constexpr scalar_t phi_tolerance(scalar_t tol, scalar_t radius) {
return tol / radius;
}

Expand Down
3 changes: 1 addition & 2 deletions core/include/detray/geometry/detail/volume_descriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ class volume_descriptor {
-> void {
auto& rg = sf_link<id>();
// Range not set yet - initialize
constexpr typename sf_link_type::index_type empty{};
if (rg == empty) {
if (constexpr typename sf_link_type::index_type empty{}; rg == empty) {
rg = {0u, static_cast<dindex>(n_surfaces)};
}
// Update
Expand Down
3 changes: 2 additions & 1 deletion core/include/detray/geometry/mask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class mask {
: _volume_link(link) {
assert(values.size() == boundaries::e_size &&
" Given number of boundaries does not match mask shape.");
std::copy(std::cbegin(values), std::cend(values), std::begin(_values));
std::ranges::copy(std::cbegin(values), std::cend(values),
std::begin(_values));
}

/// Assignment operator from an array, convenience function
Expand Down
9 changes: 4 additions & 5 deletions core/include/detray/grids/axis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ struct circular {
std::ranges::for_each(sequence, [&](auto &n) { n += m++; });
return sequence;
}
dindex vl =
static_cast<dindex>(n_bins - nh_range[0] + nh_range[1] + 1u);
dindex vl = n_bins - nh_range[0] + nh_range[1] + 1u;
dindex mi = 0;
dindex mo = 0;
dindex_sequence sequence(static_cast<dindex_sequence::size_type>(vl),
Expand Down Expand Up @@ -521,9 +520,9 @@ struct irregular {
int bins = static_cast<int>(boundaries.size()) - 1;
int ibinmin = static_cast<int>(ibin) - static_cast<int>(nhood[0]);
int ibinmax = static_cast<int>(ibin + nhood[1]);
dindex min_bin = (ibinmin >= 0) ? static_cast<dindex>(ibinmin) : 0u;
dindex max_bin = (ibinmax < bins) ? static_cast<dindex>(ibinmax)
: static_cast<dindex>(bins - 1);
auto min_bin = (ibinmin >= 0) ? static_cast<dindex>(ibinmin) : 0u;
auto max_bin = (ibinmax < bins) ? static_cast<dindex>(ibinmax)
: static_cast<dindex>(bins - 1);
return {min_bin, max_bin};
}

Expand Down
55 changes: 27 additions & 28 deletions core/include/detray/navigation/volume_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,13 @@ class volume_graph {
/// Constructor from an iterator on the detector volume container
/// and a reference to its surface container.
iterator(volume_iter &&vol_itr, const detector_t &det)
: m_vol_itr(vol_itr), m_det(det) {}
: m_vol_itr(std::move(vol_itr)), m_det(det) {}

/// Equality operator
bool operator==(const iterator &rhs) const {
return m_vol_itr == rhs.m_vol_itr;
}

/// Inequality operator
bool operator!=(const iterator &rhs) const {
return not(*this == rhs);
}

/// Dereference operator @returns a graph node
node operator*() { return node({m_det, m_vol_itr->index()}); }

Expand All @@ -151,24 +146,6 @@ class volume_graph {
return *this;
}

/// @returns an iterator that has been advanced by @param j
constexpr auto operator+(const difference_type j) const
-> iterator {
return {m_vol_itr + j, m_det};
}

/// @returns an iterator that has been advanced by - @param j
constexpr auto operator-(const difference_type j) const
-> iterator {
return *this + -j;
}

/// @returns distance between two iterators
constexpr auto operator-(const iterator &other) const
-> difference_type {
return m_vol_itr - other.m_vol_itr;
}

/// Advances iterator by @param j
constexpr auto operator+=(const difference_type j) -> iterator & {
m_vol_itr += j;
Expand All @@ -180,6 +157,27 @@ class volume_graph {
return *this += -j;
}

protected:
/// @returns an iterator that has been advanced by @param j
friend constexpr auto operator+(const difference_type j,
const iterator &itr) -> iterator {
return {itr.m_vol_itr + j, itr.m_det};
}

/// @returns an iterator that has been advanced by - @param j
friend constexpr auto operator-(const difference_type j,
const iterator &itr) -> iterator {
return itr + -j;
}

/// @returns distance between two iterators
friend constexpr auto operator-(const iterator &lhs,
const iterator &rhs)
-> difference_type {
return lhs.m_vol_itr - rhs.m_vol_itr;
}

private:
/// Iterator over the detector volume container.
volume_iter m_vol_itr;
/// Access to detector surfaces
Expand Down Expand Up @@ -230,7 +228,8 @@ class volume_graph {
dindex from() const { return _from; }
dindex to() const { return _to; }

dindex _from, _to;
dindex _from;
dindex _to;
};

/// Nested functor that fills the edges from a mask container
Expand Down Expand Up @@ -388,7 +387,7 @@ class volume_graph {
}*/

/// @returns the linking description as a string.
inline const std::string to_string() const {
inline std::string to_string() const {
std::stringstream stream;
dindex dim = n_nodes() + 1u;
for (const auto &n : _nodes) {
Expand All @@ -415,7 +414,7 @@ class volume_graph {
}

/// @returns the linking description as a string in DOT syntax.
inline const std::string to_dot_string() const {
inline std::string to_dot_string() const {
std::stringstream stream;
dindex dim = n_nodes() + 1u;

Expand All @@ -426,7 +425,7 @@ class volume_graph {
stream << " splines=true;" << std::endl;
stream << " mode=KK;" << std::endl;
stream << std::endl;
stream << " exit [label=\"OOB\",fillcolor=\"firebrick1\"];"
stream << R"( exit [label="OOB",fillcolor="firebrick1"];)"
<< std::endl;

for (const auto &n : _nodes) {
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/propagator/base_stepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class base_stepper {
matrix_operator()
.template identity<e_bound_size, e_bound_size>());

// A dummy barcode - should not be used
// An invalid barcode - should not be used
m_bound_params.set_surface_link(geometry::barcode{});

// Reset jacobian transport to identity matrix
Expand Down
17 changes: 5 additions & 12 deletions core/include/detray/utils/consistency_checker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,15 @@ inline void check_empty(const detector_t &det, const bool verbose) {
}
// In the brute force finder, also other surfaces can be contained, e.g.
// passive surfaces (depends on the detector)
for (const auto &pt_desc : det.portals()) {
if (pt_desc.is_portal()) {
return true;
}
}
return false;
return std::ranges::any_of(
det.portals(), [](auto pt_desc) { return pt_desc.is_portal(); });
};

// Check if there is at least one volume in the detector volume finder
auto find_volumes = [](const typename detector_t::volume_finder &vf) {
for (const auto &v : vf.all()) {
if (!detail::is_invalid_value(v)) {
return true;
}
}
return false;
return std::ranges::any_of(vf.all(), [](const auto &v) {
return !detail::is_invalid_value(v);
});
};

// Fatal errors
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/utils/grid/detail/axis_bounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ struct circular {
/// @returns an index of a remapped bin
DETRAY_HOST_DEVICE
constexpr int wrap(const int ibin, const std::size_t nbins) const {
const int bins = static_cast<int>(nbins);
const auto bins = static_cast<int>(nbins);
return (bins + (ibin % bins)) % bins;
}

Expand Down
7 changes: 4 additions & 3 deletions core/include/detray/utils/grid/detail/simple_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct simple_serializer<2> {
dindex nbins_axis0 = axes.template get_axis<0>().nbins();

dindex bin0{gbin % nbins_axis0};
auto bin1{static_cast<dindex>(gbin / nbins_axis0)};
dindex bin1{gbin / nbins_axis0};

return {bin0, bin1};
}
Expand Down Expand Up @@ -124,8 +124,9 @@ struct simple_serializer<3> {
dindex nbins_axis1 = axes.template get_axis<1>().nbins();

dindex bin0{gbin % nbins_axis0};
auto bin1{static_cast<dindex>(gbin / nbins_axis0) % nbins_axis1};
auto bin2{static_cast<dindex>(gbin / (nbins_axis0 * nbins_axis1))};
dindex bin1{(gbin / nbins_axis0) % nbins_axis1};
dindex bin2{gbin / (nbins_axis0 * nbins_axis1)};

return {bin0, bin1, bin2};
}
};
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/utils/ranges/static_join.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ requires std::input_iterator<
DETRAY_HOST_DEVICE
constexpr static_join_iterator(const iterator_coll_t &begins,
const iterator_coll_t &ends)
: m_begins(&begins), m_ends(&ends), m_iter{(*m_begins)[0]}, m_idx{0u} {}
: m_begins(&begins), m_ends(&ends), m_iter{(*m_begins)[0]} {}

/// Fully parametrized construction
DETRAY_HOST_DEVICE
Expand Down
4 changes: 3 additions & 1 deletion core/include/detray/utils/string_view_concat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct string_view_concat2 {
std::string_view s1;
std::string_view s2;

operator std::string() const { return std::string(s1) + std::string(s2); }
explicit operator std::string() const {
return std::string(s1) + std::string(s2);
}
};
} // namespace detray
8 changes: 2 additions & 6 deletions io/include/detray/io/common/detail/basic_converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
// System include(s)
#include <string_view>

namespace detray::io::detail {

// Convert basic information like links and header data
namespace basic_converter {
namespace detray::io::detail::basic_converter {

/// @returns a link from its io payload @param link_data
inline dindex convert(const single_link_payload& link_data) {
Expand Down Expand Up @@ -60,6 +58,4 @@ inline common_header_payload convert(const std::string_view det_name,
return header_data;
}

} // namespace basic_converter

} // namespace detray::io::detail
} // namespace detray::io::detail::basic_converter
2 changes: 1 addition & 1 deletion io/include/detray/io/common/detail/grid_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class grid_reader {
using algebra_t = typename detector_t::algebra_type;

// Throw expection if the accelerator link type id is invalid
auto print_error = [](io::accel_id grid_link) -> void {
auto print_error = [](io::accel_id grid_link) {
if (grid_link == io::accel_id::unknown) {
throw std::invalid_argument(
"Unknown accelerator id in geometry file!");
Expand Down
10 changes: 5 additions & 5 deletions io/include/detray/io/common/geometry_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class geometry_reader {
// Convert the volumes one-by-one
for (const auto& vol_data : det_data.volumes) {
// Get a generic volume builder first and decorate it later
auto vbuilder =
det_builder.new_volume(static_cast<volume_id>(vol_data.type));
auto vbuilder = det_builder.new_volume(vol_data.type);

// Set the volume name
name_map[vbuilder->vol_index() + 1u] = vol_data.name;
Expand All @@ -75,7 +74,8 @@ class geometry_reader {
convert<detector_t>(vol_data.transform));

// Prepare the surface factories (one per shape and surface type)
std::map<io_shape_id, sf_factory_ptr_t> pt_factories, sf_factories;
std::map<io_shape_id, sf_factory_ptr_t> pt_factories;
std::map<io_shape_id, sf_factory_ptr_t> sf_factories;

// Add the surfaces to the factories
for (const auto& sf_data : vol_data.surfaces) {
Expand Down Expand Up @@ -210,8 +210,8 @@ class geometry_reader {
}
}
// Test next shape id
constexpr int current_id{static_cast<int>(I)};
if constexpr (current_id > 0) {
if constexpr (constexpr int current_id{static_cast<int>(I)};
current_id > 0) {
return init_factory<static_cast<io_shape_id>(current_id - 1),
detector_t>(shape_id);
}
Expand Down
Loading

0 comments on commit d674273

Please sign in to comment.