EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceError.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SurfaceError.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 <string> // for string printing
12 #include <system_error> // bring in std::error_code et al
13 
14 namespace Acts {
15 // This is the custom error code enum
16 enum class SurfaceError { GlobalPositionNotOnSurface = 1 };
17 
18 namespace detail {
19 // Define a custom error code category derived from std::error_category
20 class SurfaceErrorCategory : public std::error_category {
21  public:
22  // Return a short descriptive name for the category
23  const char* name() const noexcept final { return "SurfaceError"; }
24  // Return what each enum means in text
25  std::string message(int c) const final {
26  switch (static_cast<SurfaceError>(c)) {
27  case SurfaceError::GlobalPositionNotOnSurface:
28  return "Global to local transformation failed: position not on "
29  "surface.";
30  default:
31  return "unknown";
32  }
33  }
34 };
35 } // namespace detail
36 
37 // Declare a global function returning a static instance of the custom category
40  return c;
41 }
42 
43 inline std::error_code make_error_code(Acts::SurfaceError e) {
44  return {static_cast<int>(e), Acts::SurfaceErrorCategory()};
45 }
46 } // namespace Acts
47 
48 namespace std {
49 // register with STL
50 template <>
51 struct is_error_code_enum<Acts::SurfaceError> : std::true_type {};
52 } // namespace std