Skip to content
Snippets Groups Projects
Commit 1c7fb371 authored by Moritz Kiehn's avatar Moritz Kiehn Committed by Moritz Kiehn
Browse files

Fatras: add error codes for simulator

parent 0fd481fc
No related branches found
No related tags found
1 merge request!783Allow partial event simulation in case of errors
Pipeline #1498866 passed
...@@ -4,6 +4,7 @@ add_library( ...@@ -4,6 +4,7 @@ add_library(
src/Particle.cpp src/Particle.cpp
src/ParticleData.cpp src/ParticleData.cpp
src/ProcessType.cpp src/ProcessType.cpp
src/SimulatorError.cpp
src/StandardPhysicsLists.cpp) src/StandardPhysicsLists.cpp)
target_compile_features( target_compile_features(
ActsFatras ActsFatras
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "ActsFatras/EventData/Hit.hpp" #include "ActsFatras/EventData/Hit.hpp"
#include "ActsFatras/EventData/Particle.hpp" #include "ActsFatras/EventData/Particle.hpp"
#include "ActsFatras/Kernel/Interactor.hpp" #include "ActsFatras/Kernel/Interactor.hpp"
#include "ActsFatras/Kernel/detail/SimulatorError.hpp"
namespace ActsFatras { namespace ActsFatras {
...@@ -209,8 +210,7 @@ struct Simulator { ...@@ -209,8 +210,7 @@ struct Simulator {
// required to allow correct particle id numbering for secondaries later // required to allow correct particle id numbering for secondaries later
if ((inputParticle.particleId().generation() != 0u) or if ((inputParticle.particleId().generation() != 0u) or
(inputParticle.particleId().subParticle() != 0u)) { (inputParticle.particleId().subParticle() != 0u)) {
// TODO add meaningfull error code return detail::SimulatorError::eInvalidInputParticleId;
return std::error_code(-1, std::generic_category());
} }
// Do a *depth-first* simulation of the particle and its secondaries, // Do a *depth-first* simulation of the particle and its secondaries,
......
// This file is part of the Acts project.
//
// Copyright (C) 2020 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <system_error>
namespace ActsFatras {
namespace detail {
enum class SimulatorError {
// ensure all errors are non-null
eInvalidInputParticleId = 1,
};
/// Construct and error_code from the enum.
///
/// Must use snake_case naming for STL compatibility.
std::error_code make_error_code(SimulatorError e);
} // namespace detail
} // namespace ActsFatras
// Register the error enum as STL-compatible.
namespace std {
template <>
struct is_error_code_enum<ActsFatras::detail::SimulatorError> : std::true_type {
};
} // namespace std
// This file is part of the Acts project.
//
// Copyright (C) 2020 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "ActsFatras/Kernel/detail/SimulatorError.hpp"
namespace ActsFatras {
namespace detail {
namespace {
// Define a custom error code category derived from std::error_category
class SimulatorErrorCategory final : public std::error_category {
public:
const char* name() const noexcept final { return "SimulatorError"; }
std::string message(int c) const final {
switch (static_cast<SimulatorError>(c)) {
case SimulatorError::eInvalidInputParticleId:
return "Input particle id with non-zero generation or sub-particle";
default:
return "unknown";
}
}
};
const SimulatorErrorCategory s_simulatorErrorCategory;
} // namespace
std::error_code make_error_code(SimulatorError e) {
return {static_cast<int>(e), s_simulatorErrorCategory};
}
} // namespace detail
} // namespace ActsFatras
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment