forked from sPHENIX-Collaboration/acts
/
KalmanFitterError.hpp
67 lines (60 loc) · 2.15 KB
/
KalmanFitterError.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// This file is part of the Acts project.
//
// Copyright (C) 2019 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 <iostream>
#include <string> // for string printing
#include <system_error> // bring in std::error_code et al
namespace Acts {
// This is the custom error code enum
enum class KalmanFitterError {
ForwardUpdateFailed = 1,
BackwardUpdateFailed = 2,
SmoothFailed = 3,
OutputConversionFailed = 4,
NoMeasurementFound = 5
};
namespace detail {
// Define a custom error code category derived from std::error_category
class KalmanFitterErrorCategory : public std::error_category {
public:
// Return a short descriptive name for the category
const char* name() const noexcept final { return "KalmanFitterError"; }
// Return what each enum means in text
std::string message(int c) const final {
switch (static_cast<KalmanFitterError>(c)) {
case KalmanFitterError::ForwardUpdateFailed:
return "Kalman forward update failed";
case KalmanFitterError::BackwardUpdateFailed:
return "Kalman backward update failed";
case KalmanFitterError::SmoothFailed:
return "Kalman smooth failed";
case KalmanFitterError::OutputConversionFailed:
return "Kalman output conversion failed";
case KalmanFitterError::NoMeasurementFound:
return "No measurement detected during the propagation";
default:
return "unknown";
}
}
};
} // namespace detail
// Declare a global function returning a static instance of the custom category
extern inline const detail::KalmanFitterErrorCategory&
KalmanFitterErrorCategory() {
static detail::KalmanFitterErrorCategory c;
return c;
}
inline std::error_code make_error_code(Acts::KalmanFitterError e) {
return {static_cast<int>(e), Acts::KalmanFitterErrorCategory()};
}
} // namespace Acts
namespace std {
// register with STL
template <>
struct is_error_code_enum<Acts::KalmanFitterError> : std::true_type {};
} // namespace std