Skip to content

Commit

Permalink
fix: Protection against wrong configuration of Seed finder config (#2129
Browse files Browse the repository at this point in the history
)

In case a misconfiguration of the `SeedFinderConfig`  happens, and the `seedFilter` is a nullptr, the code crashes.

This PR adds a protection against this eventuality. This happens in the `toInternalUnits` function, that now takes responsibility for checking the validity of its parameters.

It checks that the seedFilter is not a `nullptr` and that its config is already in internal units.
  • Loading branch information
CarloVarni committed May 26, 2023
1 parent 672b144 commit 5ba3b8d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Core/include/Acts/Seeding/SeedFinderConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ struct SeedFinderConfig {
throw std::runtime_error(
"Repeated conversion to internal units for SeedFinderConfig");
}
// Make sure the shared ptr to the seed filter is not a nullptr
// And make sure the seed filter config is in internal units as well
if (not seedFilter) {
throw std::runtime_error(
"Invalid values for the seed filter inside the seed filter config: "
"nullptr");
}
if (not seedFilter->getSeedFilterConfig().isInInternalUnits) {
throw std::runtime_error(
"The internal Seed Filter configuration, contained in the seed "
"finder config, is not in internal units.");
}

using namespace Acts::UnitLiterals;
SeedFinderConfig config = *this;
config.isInInternalUnits = true;
Expand Down
7 changes: 6 additions & 1 deletion Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
ActsExamples::SeedingAlgorithm::SeedingAlgorithm(
ActsExamples::SeedingAlgorithm::Config cfg, Acts::Logging::Level lvl)
: ActsExamples::IAlgorithm("SeedingAlgorithm", lvl), m_cfg(std::move(cfg)) {
// Seed Finder config requires Seed Filter object before convertion to
// internal units
m_cfg.seedFilterConfig = m_cfg.seedFilterConfig.toInternalUnits();
m_cfg.seedFinderConfig.seedFilter =
std::make_unique<Acts::SeedFilter<SimSpacePoint>>(m_cfg.seedFilterConfig);

m_cfg.seedFinderConfig =
m_cfg.seedFinderConfig.toInternalUnits().calculateDerivedQuantities();
m_cfg.seedFinderOptions =
m_cfg.seedFinderOptions.toInternalUnits().calculateDerivedQuantities(
m_cfg.seedFinderConfig);
m_cfg.seedFilterConfig = m_cfg.seedFilterConfig.toInternalUnits();
m_cfg.gridConfig = m_cfg.gridConfig.toInternalUnits();
m_cfg.gridOptions = m_cfg.gridOptions.toInternalUnits();
if (m_cfg.inputSpacePoints.empty()) {
Expand Down

0 comments on commit 5ba3b8d

Please sign in to comment.