Skip to content

Commit 6b9e13c

Browse files
authored
Clean out sonar clous issues for core (acts-project#840)
Remove some of the issues marked as bugs and remove many issues for the core library.
1 parent 90c9593 commit 6b9e13c

File tree

100 files changed

+957
-1047
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+957
-1047
lines changed

core/include/detray/builders/cylinder_portal_generator.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ class cylinder_portal_generator final
128128
public:
129129
/// Save the boundaries of the cylinder after autofitting the portals
130130
struct boundaries {
131-
scalar_t inner_radius{0.f}, outer_radius{0.f}, lower_z{0.f},
132-
upper_z{0.f};
131+
scalar_t inner_radius{0.f};
132+
scalar_t outer_radius{0.f};
133+
scalar_t lower_z{0.f};
134+
scalar_t upper_z{0.f};
133135
};
134136

135137
/// Construct from configuration @param cfg

core/include/detray/builders/detail/associator.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ struct center_of_gravity_generic {
7979
}
8080
cgs = 1.f / static_cast<scalar>(surface_contour.size()) * cgs;
8181

82-
std::size_t i, j = 0u;
82+
std::size_t i = 0u;
83+
std::size_t j = 0u;
8384
std::size_t num_points = bin_contour.size();
8485

8586
bool inside = false;
@@ -112,7 +113,7 @@ struct edges_intersect_generic {
112113
const std::vector<point2_t> &surface_contour) {
113114

114115
auto intersect = [](const point2_t &pi, const point2_t &pj,
115-
const point2_t &pk, const point2_t &pl) -> bool {
116+
const point2_t &pk, const point2_t &pl) {
116117
scalar d = (pj[0] - pi[0]) * (pl[1] - pk[1]) -
117118
(pj[1] - pi[1]) * (pl[0] - pk[0]);
118119

core/include/detray/builders/grid_factory.hpp

+4-76
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ class grid_factory {
6666
explicit grid_factory(vecmem::memory_resource &resource)
6767
: m_resource(&resource) {}
6868

69-
/// Print grid - up to three dimensions
70-
/// @note will likely become obsolete with the actsvg implementation
71-
template <typename grid_t>
72-
auto to_string(const grid_t &) const noexcept -> void;
73-
7469
//
7570
// annulus 2D
7671
//
@@ -513,8 +508,8 @@ class grid_factory {
513508
std::enable_if_t<std::is_object_v<typename grid_frame_t::loc_point>,
514509
bool> = true>
515510
auto new_grid(
516-
const std::vector<scalar_type> spans,
517-
const std::vector<std::size_t> n_bins,
511+
const std::vector<scalar_type> &spans,
512+
const std::vector<std::size_t> &n_bins,
518513
const std::vector<std::pair<axis::multi_bin<sizeof...(bound_ts)>,
519514
dindex>> &bin_capacities = {},
520515
const std::vector<std::vector<scalar_type>> &ax_bin_edges = {},
@@ -539,8 +534,8 @@ class grid_factory {
539534
std::enable_if_t<std::is_enum_v<typename grid_shape_t::boundaries>,
540535
bool> = true>
541536
auto new_grid(
542-
const std::vector<scalar_type> spans,
543-
const std::vector<std::size_t> n_bins,
537+
const std::vector<scalar_type> &spans,
538+
const std::vector<std::size_t> &n_bins,
544539
const std::vector<std::pair<axis::multi_bin<sizeof...(bound_ts)>,
545540
dindex>> &bin_capacities = {},
546541
const std::vector<std::vector<scalar_type>> &ax_bin_edges = {},
@@ -705,73 +700,6 @@ class grid_factory {
705700
vecmem::memory_resource *m_resource{};
706701
};
707702

708-
template <typename bin_t, template <std::size_t> class serializer_t,
709-
typename algebra_t>
710-
template <typename grid_t>
711-
auto grid_factory<bin_t, serializer_t, algebra_t>::to_string(
712-
const grid_t &gr) const noexcept -> void {
713-
714-
using entry_t = typename grid_t::bin_type;
715-
716-
// Loop over the first dimension
717-
const auto &ax0 = gr.template get_axis<0>();
718-
std::cout << "{";
719-
for (unsigned int i{0u}; i < ax0.nbins(); ++i) {
720-
721-
// Loop over the second dimension
722-
if constexpr (grid_t::dim > 1u) {
723-
const auto &ax1 = gr.template get_axis<1>();
724-
std::cout << "{";
725-
for (unsigned int j{0u}; j < ax1.nbins(); ++j) {
726-
727-
// Loop over the third dimension
728-
if constexpr (grid_t::dim > 2) {
729-
const auto &ax2 = gr.template get_axis<2>();
730-
std::cout << "{";
731-
for (unsigned int k{0u}; k < ax2.nbins(); ++k) {
732-
733-
// Print the bin content - three dimensions
734-
std::cout << "( ";
735-
for (const auto &entry : gr.bin(i, j, k)) {
736-
if (entry == detail::invalid_value<entry_t>()) {
737-
std::cout << "none ";
738-
} else {
739-
std::cout << entry << " ";
740-
}
741-
}
742-
std::cout << ")";
743-
}
744-
std::cout << "}" << std::endl << std::endl;
745-
} else {
746-
// Print the bin content - two dimensions
747-
std::cout << "( ";
748-
for (const auto &entry : gr.bin(i, j)) {
749-
if (entry == detail::invalid_value<entry_t>()) {
750-
std::cout << "none ";
751-
} else {
752-
std::cout << entry << " ";
753-
}
754-
}
755-
std::cout << ")";
756-
}
757-
}
758-
std::cout << "}" << std::endl;
759-
} else {
760-
// Print the bin content - one dimension
761-
std::cout << "( ";
762-
for (const auto &entry : gr.bin(i)) {
763-
if (entry == detail::invalid_value<entry_t>()) {
764-
std::cout << "none ";
765-
} else {
766-
std::cout << entry << " ";
767-
}
768-
}
769-
std::cout << ")" << std::endl;
770-
}
771-
}
772-
std::cout << "}" << std::endl;
773-
}
774-
775703
// Infer a grid factory type from an already completely assembled grid type
776704
template <typename grid_t, typename algebra_t = ALGEBRA_PLUGIN<detray::scalar>>
777705
using grid_factory_type =

core/include/detray/builders/homogeneous_material_factory.hpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <cassert>
2020
#include <memory>
2121
#include <numeric>
22+
#include <ranges>
2223
#include <tuple>
2324
#include <type_traits>
2425
#include <vector>
@@ -36,7 +37,7 @@ class material_data {
3637
DETRAY_HOST
3738
explicit constexpr material_data(
3839
const std::size_t sf_idx = detail::invalid_value<std::size_t>())
39-
: m_sf_index{sf_idx}, m_mat{}, m_thickness{} {}
40+
: m_sf_index{sf_idx} {}
4041

4142
/// Construct from a predefined material
4243
///
@@ -97,12 +98,12 @@ class material_data {
9798
DETRAY_HOST
9899
void append(material_data &&other) {
99100
m_mat.reserve(m_mat.size() + other.m_mat.size());
100-
std::move(other.m_mat.begin(), other.m_mat.end(),
101-
std::back_inserter(m_mat));
101+
std::ranges::move(other.m_mat.begin(), other.m_mat.end(),
102+
std::back_inserter(m_mat));
102103

103104
m_thickness.reserve(m_thickness.size() + other.m_thickness.size());
104-
std::move(other.m_thickness.begin(), other.m_thickness.end(),
105-
std::back_inserter(m_thickness));
105+
std::ranges::move(other.m_thickness.begin(), other.m_thickness.end(),
106+
std::back_inserter(m_thickness));
106107
}
107108

108109
/// Append new material
@@ -130,7 +131,7 @@ class material_data {
130131
/// The material parametrization
131132
std::vector<material<scalar_t>> m_mat{};
132133
/// Thickness/radius of the material slab/rod
133-
std::vector<scalar_t> m_thickness{0.f};
134+
std::vector<scalar_t> m_thickness{};
134135
};
135136

136137
/// @brief Factory class for homogeneous material.
@@ -203,7 +204,11 @@ class homogeneous_material_factory final
203204
material_id id, material_data<scalar_type> &&mat_data,
204205
std::size_t index = detail::invalid_value<std::size_t>()) {
205206

206-
auto [sf_index, mat, thickness] = mat_data.get_data();
207+
auto [sf_index, mat, thickness] = std::move(mat_data).get_data();
208+
209+
// Only one homogeneous material slab/rod per surface
210+
assert(mat.size() == 1u);
211+
assert(thickness.size() == 1u);
207212

208213
m_links.push_back(std::make_pair(id, static_cast<dindex>(index)));
209214
m_indices.push_back(sf_index);

core/include/detray/builders/homogeneous_material_generator.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ class homogeneous_material_generator final
159159
err_stream.str());
160160
break;
161161
}
162-
};
162+
default: {
163+
break;
164+
}
165+
}
163166

164167
// Found suitable material for this surface?
165168
if (mat_ptr == nullptr) {

core/include/detray/builders/material_map_builder.hpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ class material_map_builder final : public volume_decorator<detector_t> {
112112
auto vol = tracking_volume{det, this->vol_index()};
113113
for (const auto& sf_desc : vol.surfaces()) {
114114

115-
if (!surface_has_map(sf_idx++)) {
115+
if (!surface_has_map(sf_idx)) {
116+
sf_idx++;
116117
continue;
117118
}
118119

119120
// Construct and append the material map for a given surface shape
120121
std::array<std::vector<scalar_type>, DIM> axis_spans{};
121-
auto axis_spans_itr = m_axis_spans.find(sf_idx - 1u);
122+
auto axis_spans_itr = m_axis_spans.find(sf_idx);
122123
if (axis_spans_itr != m_axis_spans.end()) {
123124
axis_spans = axis_spans_itr->second;
124125
}
@@ -127,12 +128,13 @@ class material_map_builder final : public volume_decorator<detector_t> {
127128
auto sf = tracking_surface{det, sf_desc};
128129
[[maybe_unused]] auto [mat_id, mat_idx] = sf.template visit_mask<
129130
detail::add_sf_material_map<materials_t>>(
130-
m_factory, m_bin_data.at(sf_idx - 1u), m_n_bins.at(sf_idx - 1u),
131+
m_factory, m_bin_data.at(sf_idx), m_n_bins.at(sf_idx),
131132
axis_spans, det.material_store());
132133

133134
// Make sure the linking was precomputed correctly
134135
assert(mat_id == sf_desc.material().id());
135136
assert(mat_idx == sf_desc.material().index());
137+
sf_idx++;
136138
}
137139

138140
// Give the volume to the next decorator
@@ -155,7 +157,8 @@ class material_map_builder final : public volume_decorator<detector_t> {
155157

156158
dindex sf_idx{0u};
157159
for (auto& sf_desc : this->surfaces()) {
158-
if (!surface_has_map(sf_idx++)) {
160+
if (!surface_has_map(sf_idx)) {
161+
sf_idx++;
159162
continue;
160163
}
161164

@@ -168,6 +171,7 @@ class material_map_builder final : public volume_decorator<detector_t> {
168171
}
169172

170173
sf_desc.material().set_index(mat_type_count.at(id));
174+
sf_idx++;
171175
}
172176

173177
// Current sizes of the material stores
@@ -178,11 +182,13 @@ class material_map_builder final : public volume_decorator<detector_t> {
178182
// Update the counts with the detector offset
179183
sf_idx = 0u;
180184
for (auto& sf_desc : this->surfaces()) {
181-
if (!surface_has_map(sf_idx++)) {
185+
if (!surface_has_map(sf_idx)) {
186+
sf_idx++;
182187
continue;
183188
}
184189
auto coll_idx{static_cast<std::size_t>(sf_desc.material().id())};
185190
sf_desc.material() += size_map.at(coll_idx);
191+
sf_idx++;
186192
}
187193
}
188194

core/include/detray/builders/material_map_factory.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class material_map_factory final : public factory_decorator<detector_t> {
108108
std::vector<std::vector<scalar_type>> &&axis_spans,
109109
std::vector<index_type> &&indices) {
110110

111-
auto [sf_index, mat, thickness] = mat_data.get_data();
111+
auto [sf_index, mat, thickness] = std::move(mat_data).get_data();
112112

113113
m_links[sf_index] = std::make_pair(id, std::move(indices));
114114
m_n_bins[sf_index] = std::move(n_bins);

core/include/detray/builders/material_map_generator.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct material_map_config {
123123
bool has_config(mask_id_t map_type, surface_id sf_type) const {
124124
const auto key =
125125
std::make_pair(static_cast<unsigned int>(map_type), sf_type);
126-
return (m_map_configs.find(key) != m_map_configs.end());
126+
return m_map_configs.contains(key);
127127
}
128128
template <typename mask_id_t>
129129
const auto &get_map_config(mask_id_t map_type, surface_id sf_type) const {

core/include/detray/builders/surface_factory.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class surface_factory : public surface_factory_interface<detector_t> {
150150
typename detector_t::geometry_context ctx = {})
151151
-> dindex_range override {
152152
// In case the surfaces container is prefilled with other surfaces
153-
const dindex surfaces_offset = static_cast<dindex>(surfaces.size());
153+
const auto surfaces_offset{static_cast<dindex>(surfaces.size())};
154154

155155
// Nothing to construct
156156
if (size() == 0u) {

core/include/detray/builders/volume_builder.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class volume_builder : public volume_builder_interface<detector_t> {
3939
///
4040
/// @param id flags the type of volume geometry (e.g. cylindrical, cuboid)
4141
/// @param idx the index of the volume in the detector volume container
42-
volume_builder(const volume_id id, const dindex idx = 0)
43-
: m_has_accel{false}, m_volume{id} {
42+
volume_builder(const volume_id id, const dindex idx = 0) : m_volume{id} {
4443

4544
m_volume.set_index(idx);
4645
m_volume.set_material(volume_type::material_id::e_none, 0u);

core/include/detray/core/detail/container_buffers.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,11 @@ auto get_buffer(
173173

174174
// TODO: Move this to detray copy util, which bundles vecmem copy object and
175175
// stream handle and gets this switch case right automatically
176-
switch (cpy_type) {
177-
case detray::copy::async:
178-
cpy(vec_view, buff /*, stream*/);
179-
break;
180-
default:
181-
cpy(vec_view, buff)->wait();
182-
};
176+
if (cpy_type == detray::copy::async) {
177+
cpy(vec_view, buff /*, stream*/);
178+
} else {
179+
cpy(vec_view, buff)->wait();
180+
}
183181

184182
return buff;
185183
}

0 commit comments

Comments
 (0)