Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
StatusCode.cpp
Go to the documentation of this file.
1 #define GAUDIKERNEL_STATUSCODE_CPP 1
2 
9 #include "GaudiKernel/System.h"
10 #include <exception>
11 
12 // statics
13 bool StatusCode::s_checking( false );
14 
18 
19 namespace {
21  struct DefaultCategory : public StatusCode::Category {
22 
23  const char* name() const override { return "Gaudi"; }
24 
25  std::string message( StatusCode::code_t code ) const override {
26  switch ( static_cast<StatusCode::ErrorCode>( code ) ) {
28  return "SUCCESS";
30  return "FAILURE";
32  return "RECOVERABLE";
33  default:
34  return "UNKNOWN(" + std::to_string( code ) + ")";
35  }
36  }
37  };
38 } // namespace
39 
41 
42 void StatusCode::enableChecking() { s_checking = true; }
43 
44 void StatusCode::disableChecking() { s_checking = false; }
45 
47 
49 
50  if ( !m_checked && !GaudiException::s_proc &&
51 #if __cplusplus > 201402L // c++17
52  !std::uncaught_exceptions()
53 #else
55 #endif
56  ) {
57 
58  auto msg = Gaudi::svcLocator()->as<IMessageSvc>();
59  auto scs = Gaudi::svcLocator()->service<IStatusCodeSvc>( "StatusCodeSvc" );
60 
61  const size_t depth = 21;
62  void* addresses[depth];
63 
64  std::string lib, fnc;
65  void* addr = nullptr;
67  if ( System::backTrace( addresses, depth ) ) {
68 
69  for ( size_t idx : {2, 3} ) {
70  // When running address sanitizer builds with -fno-omit-frame-pointer
71  // StatusCode::check() might appear as the function name, so skip.
72  if ( System::getStackLevel( addresses[idx], addr, fnc, lib ) && fnc != "StatusCode::~StatusCode()" &&
73  fnc != "StatusCode::check()" ) {
74  if ( scs ) {
75  scs->regFnc( fnc, lib );
76  } else {
77  MsgStream log( msg, "StatusCode" );
78  log << MSG::WARNING << "Unchecked in " << fnc << " (" << lib << ")" << endmsg;
79  }
80  break;
81  }
82  }
83  }
84  }
85 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
void check()
Do StatusCode check.
Definition: StatusCode.cpp:48
GAUDI_API bool getStackLevel(void *addresses, void *&addr, std::string &fnc, std::string &lib)
The category assigned to a StatusCode.
Definition: StatusCode.h:63
static bool s_proc
"previous" element in the linked list
constexpr static const auto RECOVERABLE
Definition: StatusCode.h:87
T to_string(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
virtual const char * name() const =0
Name of the category.
class MergingTransformer< Out(const vector_of_const_< In > void
SmartIF< IFace > as()
Definition: ISvcLocator.h:103
static GAUDI_API bool checkingEnabled()
Definition: StatusCode.cpp:46
GAUDI_API int backTrace(void **addresses, const int depth)
STL class.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
GAUDI_API ISvcLocator * svcLocator()
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM ) ...
Definition: StatusCode.h:248
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:37
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:227
T uncaught_exception(T...args)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:44
virtual std::string message(code_t code) const
Description for code within this category.
Definition: StatusCode.h:71
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:52