EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PropagatorError.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PropagatorError.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <iostream>
12 #include <string> // for string printing
13 #include <system_error> // bring in std::error_code et al
14 
15 namespace Acts {
16 // This is the custom error code enum
17 enum class PropagatorError {
18  Failure = 1,
19  WrongDirection = 2,
20  StepCountLimitReached = 3
21 };
22 
23 namespace detail {
24 // Define a custom error code category derived from std::error_category
25 class PropagatorErrorCategory : public std::error_category {
26  public:
27  // Return a short descriptive name for the category
28  const char* name() const noexcept final { return "PropagatorError"; }
29  // Return what each enum means in text
30  std::string message(int c) const final {
31  switch (static_cast<PropagatorError>(c)) {
32  case PropagatorError::Failure:
33  return "Propagation failed";
34  case PropagatorError::WrongDirection:
35  return "Propagation occurred in the wrong direction";
36  case PropagatorError::StepCountLimitReached:
37  return "Propagation reached the configured maximum number of steps";
38  default:
39  return "unknown";
40  }
41  }
42 };
43 } // namespace detail
44 
45 // Declare a global function returning a static instance of the custom category
48  return c;
49 }
50 
51 inline std::error_code make_error_code(Acts::PropagatorError e) {
52  return {static_cast<int>(e), Acts::PropagatorErrorCategory()};
53 }
54 } // namespace Acts
55 
56 namespace std {
57 // register with STL
58 template <>
59 struct is_error_code_enum<Acts::PropagatorError> : std::true_type {};
60 } // namespace std