| The Gaudi Framework v32r1 (f65d50dc)

StatusCode.cpp
Go to the documentation of this file.
1 #define GAUDIKERNEL_STATUSCODE_CPP 1
2
3 #include "GaudiKernel/StatusCode.h"
4 #include "GaudiKernel/Bootstrap.h"
5 #include "GaudiKernel/IMessageSvc.h"
6 #include "GaudiKernel/IStatusCodeSvc.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/MsgStream.h"
9 #include "GaudiKernel/System.h"
10 #include <exception>
11
12 // statics
13 bool StatusCode::s_checking( false );
14
15 constexpr const StatusCode::ErrorCode StatusCode::SUCCESS;
16 constexpr const StatusCode::ErrorCode StatusCode::FAILURE;
17 constexpr const StatusCode::ErrorCode StatusCode::RECOVERABLE;
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 ) ) {
27 case StatusCode::ErrorCode::SUCCESS:
28 return "SUCCESS";
29 case StatusCode::ErrorCode::FAILURE:
30 return "FAILURE";
31 case StatusCode::ErrorCode::RECOVERABLE:
32 return "RECOVERABLE";
33 default:
34 return "UNKNOWN(" + std::to_string( code ) + ")";
35 }
36 }
37 };
38 } // namespace
39
40 STATUSCODE_ENUM_IMPL( StatusCode::ErrorCode, DefaultCategory )
41
42 void StatusCode::enableChecking() { s_checking = true; }
43
44 void StatusCode::disableChecking() { s_checking = false; }
45
46 bool StatusCode::checkingEnabled() { return s_checking; }
47
48 void StatusCode::check() {
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 }
System.h
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode::ErrorCode
ErrorCode
Definition: StatusCode.h:54
StatusCode::check
void check()
Do StatusCode check.
Definition: StatusCode.cpp:48
MsgStream.h
System::getStackLevel
GAUDI_API bool getStackLevel(void *addresses, void *&addr, std::string &fnc, std::string &lib)
StatusCode::m_checked
bool m_checked
If the StatusCode has been checked.
Definition: StatusCode.h:226
StatusCode::Category
The category assigned to a StatusCode.
Definition: StatusCode.h:63
GaudiException::s_proc
static bool s_proc
"previous" element in the linked list
Definition: GaudiException.h:108
StatusCode::RECOVERABLE
constexpr static const auto RECOVERABLE
Definition: StatusCode.h:87
AvalancheSchedulerErrorTest.scs
scs
Definition: AvalancheSchedulerErrorTest.py:31
std::to_string
T to_string(T... args)
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
StatusCode::Category::name
virtual const char * name() const =0
Name of the category.
Bootstrap.h
ISvcLocator::as
SmartIF< IFace > as()
Definition: ISvcLocator.h:103
StatusCode::ErrorCode::SUCCESS
StatusCode::checkingEnabled
static GAUDI_API bool checkingEnabled()
Definition: StatusCode.cpp:46
System::backTrace
GAUDI_API int backTrace(void **addresses, const int depth)
IStatusCodeSvc.h
std::string
STL class.
ISvcLocator::service
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::svcLocator
GAUDI_API ISvcLocator * svcLocator()
StatusCode::Category::message
virtual std::string message(code_t code) const
Description for code within this category.
Definition: StatusCode.h:71
STATUSCODE_ENUM_IMPL
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM )
Definition: StatusCode.h:248
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:37
StatusCode::s_checking
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:227
IMessageSvc.h
StatusCode::ErrorCode::FAILURE
StatusCode::ErrorCode::RECOVERABLE
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
StatusCode::disableChecking
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:44
MSG::WARNING
Definition: IMessageSvc.h:15
StatusCode.h
IStatusCodeSvc
Definition: IStatusCodeSvc.h:7
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi.Configuration.log
log
Definition: Configuration.py:13
StatusCode::code_t
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:52