The Gaudi Framework  v30r3 (a5ef0a68)
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 
15 namespace
16 {
18  struct DefaultCategory : public StatusCode::Category {
19 
20  const char* name() const override { return "Gaudi"; }
21 
22  std::string message( StatusCode::code_t code ) const override
23  {
24  switch ( static_cast<StatusCode::ErrorCode>( code ) ) {
26  return "SUCCESS";
28  return "FAILURE";
30  return "RECOVERABLE";
31  default:
32  return "UNKNOWN(" + std::to_string( code ) + ")";
33  }
34  }
35  };
36 }
37 
39 
40 void StatusCode::enableChecking() { s_checking = true; }
41 
42 void StatusCode::disableChecking() { s_checking = false; }
43 
45 
47 {
48 
49  if ( !m_checked && !GaudiException::s_proc && !std::uncaught_exception() ) {
50 
51  auto msg = Gaudi::svcLocator()->as<IMessageSvc>();
52  auto scs = Gaudi::svcLocator()->service<IStatusCodeSvc>( "StatusCodeSvc" );
53 
54  const size_t depth = 21;
55  void* addresses[depth];
56 
57  std::string lib, fnc;
58  void* addr = nullptr;
60  if ( System::backTrace( addresses, depth ) ) {
61 
62  for ( size_t idx : {2, 3} ) {
63  if ( System::getStackLevel( addresses[idx], addr, fnc, lib ) && fnc != "StatusCode::~StatusCode()" ) {
64 
65  if ( scs ) {
66  scs->regFnc( fnc, lib );
67  } else {
68  MsgStream log( msg, "StatusCode" );
69  log << MSG::WARNING << "Unchecked in " << fnc << " (" << lib << ")" << endmsg;
70  }
71  break;
72  }
73  }
74  }
75  }
76 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
void check()
Do StatusCode check.
Definition: StatusCode.cpp:46
GAUDI_API bool getStackLevel(void *addresses, void *&addr, std::string &fnc, std::string &lib)
The category assigned to a StatusCode.
Definition: StatusCode.h:65
static bool s_proc
"previous" element in the linked list
T to_string(T...args)
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:109
static GAUDI_API bool checkingEnabled()
Definition: StatusCode.cpp:44
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:79
GAUDI_API ISvcLocator * svcLocator()
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM ) ...
Definition: StatusCode.h:267
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:38
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:246
T uncaught_exception(T...args)
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:42
virtual std::string message(code_t code) const
Description for code within this category.
Definition: StatusCode.h:73
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:54