The Gaudi Framework  v32r2 (46d42edc)
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 
45 
47 
49 
50  if ( !m_checked && !GaudiException::s_proc && !std::uncaught_exceptions() ) {
51 
52  auto msg = Gaudi::svcLocator()->as<IMessageSvc>();
53  auto scs = Gaudi::svcLocator()->service<IStatusCodeSvc>( "StatusCodeSvc" );
54 
55  const size_t depth = 21;
56  void* addresses[depth];
57 
58  std::string lib, fnc;
59  void* addr = nullptr;
61  if ( System::backTrace( addresses, depth ) ) {
62 
63  for ( size_t idx : {2, 3} ) {
64  // When running address sanitizer builds with -fno-omit-frame-pointer
65  // StatusCode::check() might appear as the function name, so skip.
66  if ( System::getStackLevel( addresses[idx], addr, fnc, lib ) && fnc != "StatusCode::~StatusCode()" &&
67  fnc != "StatusCode::check()" ) {
68  if ( scs ) {
69  scs->regFnc( fnc, lib );
70  } else {
71  MsgStream log( msg, "StatusCode" );
72  log << MSG::WARNING << "Unchecked in " << fnc << " (" << lib << ")" << endmsg;
73  }
74  break;
75  }
76  }
77  }
78  }
79 }
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)
bool m_checked
If the StatusCode has been checked.
Definition: StatusCode.h:226
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.
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()
virtual std::string message(code_t code) const
Description for code within this category.
Definition: StatusCode.h:71
#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
constexpr static const auto FAILURE
Definition: StatusCode.h:86
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:44
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