The Gaudi Framework
master (0ea74171)
Toggle main menu visibility
Loading...
Searching...
No Matches
ExceptionSvc.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
// ============================================================================
12
// Include files
13
// ============================================================================
14
// STD & STL
15
// ============================================================================
16
#include <algorithm>
17
#include <cassert>
18
// ============================================================================
19
// GaudiKernel
20
// ============================================================================
21
#include <
GaudiKernel/ISvcLocator.h
>
22
// ============================================================================
23
// Local
24
// ============================================================================
25
#include "
ExceptionSvc.h
"
26
// ============================================================================
27
28
#include <boost/regex.hpp>
29
30
using namespace
std
;
31
32
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
33
34
DECLARE_COMPONENT
(
ExceptionSvc
)
35
36
inline
void
toupper
(
std
::
string
& s ) { std::transform( s.begin(), s.end(), s.begin(), (int ( * )(
int
))
toupper
); }
37
38
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
39
40
StatusCode
ExceptionSvc::initialize
() {
41
StatusCode
status =
Service::initialize
();
42
if
( status.
isFailure
() ) {
return
status; }
43
44
string
key =
m_mode_exc_s
.value();
45
46
auto
loc = key.find(
" "
);
47
std::string mode = key.substr( 0, loc );
48
49
toupper
( mode );
50
51
if
( mode ==
"NONE"
) {
52
m_mode_exc
=
NONE
;
53
}
else
if
( mode ==
"ALL"
) {
54
m_mode_exc
=
ALL
;
55
}
else
{
56
error
() <<
"Unknown mode for Exception handling: \""
<< mode <<
"\". Default must be one of \"ALL\" or \"NONE\""
57
<<
endmsg
;
58
m_state
=
Gaudi::StateMachine::OFFLINE
;
59
return
StatusCode::FAILURE
;
60
}
61
62
if
( loc == string::npos ) {
63
key.clear();
64
}
else
{
65
key = key.substr( loc + 1 );
66
}
67
68
std::string VAL, TAG;
69
70
static
const
boost::regex exp{
"[[:space:]]*([^[:space:]]+)[[:space:]]*=[[:space:]]*([^[:space:]]+)"
};
71
static
const
auto
tok_end = boost::sregex_iterator();
72
for
(
auto
tok_iter = boost::sregex_iterator( begin( key ), end( key ), exp ); tok_iter != tok_end; ++tok_iter ) {
73
TAG = ( *tok_iter )[1];
74
VAL = ( *tok_iter )[2];
75
toupper
( VAL );
76
77
if
( VAL ==
"SUCCESS"
) {
78
m_retCodesExc
[TAG] =
SUCCESS
;
79
}
else
if
( VAL ==
"FAILURE"
) {
80
m_retCodesExc
[TAG] =
FAILURE
;
81
}
else
if
( VAL ==
"REVOVERABLE"
) {
82
m_retCodesExc
[TAG] =
RECOVERABLE
;
83
}
else
if
( VAL ==
"RETHROW"
) {
84
m_retCodesExc
[TAG] =
RETHROW
;
85
}
else
if
( VAL ==
"DEFAULT"
) {
86
m_retCodesExc
[TAG] =
DEFAULT
;
87
}
else
{
88
error
() <<
"In JobOpts: unknown return code \""
<< VAL <<
"\" for Algorithm "
<< TAG << std::endl
89
<<
" Must be one of: DEFAULT, SUCCESS, FAILURE, RECOVERABLE, RETHROW"
<<
endmsg
;
90
m_state
=
Gaudi::StateMachine::OFFLINE
;
91
return
StatusCode::FAILURE
;
92
}
93
94
if
(
msgLevel
(
MSG::DEBUG
) )
95
debug
() <<
"Will catch exceptions thrown by: "
<< TAG <<
" -> action: "
<< VAL <<
endmsg
;
96
}
97
98
// now process errors
99
key =
m_mode_err_s
.value();
100
101
loc = key.find(
" "
);
102
mode = key.substr( 0, loc );
103
104
toupper
( mode );
105
106
if
( mode ==
"NONE"
) {
107
m_mode_err
=
NONE
;
108
}
else
if
( mode ==
"ALL"
) {
109
m_mode_err
=
ALL
;
110
}
else
{
111
error
() <<
"Unknown mode for Error handling: \""
<< mode <<
"\". Default must be one of \"ALL\" or \"NONE\""
112
<<
endmsg
;
113
m_state
=
Gaudi::StateMachine::OFFLINE
;
114
return
StatusCode::FAILURE
;
115
}
116
117
if
( loc == string::npos ) {
118
key.clear();
119
}
else
{
120
key = key.substr( loc + 1 );
121
}
122
123
for
(
auto
tok_iter = boost::sregex_iterator( begin( key ), end( key ), exp ); tok_iter != tok_end; ++tok_iter ) {
124
TAG = ( *tok_iter )[1];
125
VAL = ( *tok_iter )[2];
126
toupper
( VAL );
127
128
if
( VAL ==
"SUCCESS"
) {
129
m_retCodesErr
[TAG] =
SUCCESS
;
130
}
else
if
( VAL ==
"FAILURE"
) {
131
m_retCodesErr
[TAG] =
FAILURE
;
132
}
else
if
( VAL ==
"RECOVERABLE"
) {
133
m_retCodesErr
[TAG] =
RECOVERABLE
;
134
}
else
{
135
error
() <<
"In JobOpts: unknown return code \""
<< VAL <<
"\" for Algorithm "
<< TAG << std::endl
136
<<
" Must be one of: SUCCESS, FAILURE, RECOVERABLE"
<<
endmsg
;
137
m_state
=
Gaudi::StateMachine::OFFLINE
;
138
return
StatusCode::FAILURE
;
139
}
140
141
if
(
msgLevel
(
MSG::DEBUG
) )
142
debug
() <<
"Will process Errors returned by: "
<< TAG <<
" -> action: "
<< VAL <<
endmsg
;
143
}
144
return
status;
145
}
146
147
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
148
149
StatusCode
ExceptionSvc::handleErr
(
const
INamedInterface
& alg,
const
StatusCode
& st )
const
{
150
if
(
msgLevel
(
MSG::DEBUG
) )
debug
() <<
"Handling Error from "
<< alg.name() <<
endmsg
;
151
152
// is this Alg special?
153
auto
i =
m_retCodesErr
.find( alg.name() );
154
if
( i !=
m_retCodesErr
.end() ) {
155
switch
( i->second ) {
156
case
SUCCESS
:
157
return
StatusCode::SUCCESS
;
158
case
FAILURE
:
159
return
StatusCode::FAILURE
;
160
case
RECOVERABLE
:
161
return
StatusCode::RECOVERABLE
;
162
// should never get here
163
case
RETHROW
:
164
break
;
165
case
DEFAULT
:
166
break
;
167
}
168
169
}
else
{
170
171
if
(
m_mode_err
==
ALL
)
return
StatusCode::FAILURE
;
// turn it into FAILURE
172
assert(
m_mode_err
==
NONE
);
173
// don't touch the return code
174
return
st;
175
}
176
return
StatusCode::FAILURE
;
177
}
178
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
179
180
StatusCode
ExceptionSvc::process
(
const
INamedInterface
& alg )
const
{
181
182
// is this Alg special?
183
auto
i =
m_retCodesExc
.find( alg.name() );
184
if
( i !=
m_retCodesExc
.end() ) {
185
186
switch
( i->second ) {
187
case
DEFAULT
:
188
return
StatusCode::FAILURE
;
// there is no default
189
case
SUCCESS
:
190
return
StatusCode::SUCCESS
;
191
case
FAILURE
:
192
return
StatusCode::FAILURE
;
193
case
RECOVERABLE
:
194
return
StatusCode::RECOVERABLE
;
195
case
RETHROW
:
196
throw
;
// cppcheck-suppress rethrowNoCurrentException
197
}
198
}
199
200
if
(
m_mode_exc
==
ALL
) {
throw
; }
// cppcheck-suppress rethrowNoCurrentException
201
assert(
m_mode_exc
==
NONE
);
202
return
StatusCode::FAILURE
;
203
}
204
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
205
206
StatusCode
ExceptionSvc::handle
(
const
INamedInterface
& alg )
const
{
207
if
(
msgLevel
(
MSG::DEBUG
) )
debug
() <<
"Handling unknown exception for "
<< alg.name() <<
endmsg
;
208
return
process
( alg );
209
}
210
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
211
212
StatusCode
ExceptionSvc::handle
(
const
INamedInterface
& alg,
const
std::exception& exc )
const
{
213
if
(
msgLevel
(
MSG::DEBUG
) )
debug
() <<
"Handling std:except: \""
<< exc.what() <<
"\" for "
<< alg.name() <<
endmsg
;
214
return
process
( alg );
215
}
216
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
217
218
StatusCode
ExceptionSvc::handle
(
const
INamedInterface
& alg,
const
GaudiException
& exc )
const
{
219
if
(
msgLevel
(
MSG::DEBUG
) )
debug
() <<
"Handling GaudiException: \""
<< exc <<
"\" for "
<< alg.name() <<
endmsg
;
220
return
process
( alg );
221
}
222
223
// ============================================================================
224
// The END
225
// ============================================================================
toupper
void toupper(std::string &s)
Definition
ExceptionSvc.cpp:36
ExceptionSvc.h
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition
CommonMessaging.h:118
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition
CommonMessaging.h:127
ExceptionSvc
Simple implementation of IExceptionSvc abstract interface.
Definition
ExceptionSvc.h:28
ExceptionSvc::m_mode_err
Policy m_mode_err
Definition
ExceptionSvc.h:59
ExceptionSvc::m_retCodesErr
std::map< std::string, ReturnState > m_retCodesErr
Definition
ExceptionSvc.h:60
ExceptionSvc::m_mode_exc
Policy m_mode_exc
Definition
ExceptionSvc.h:59
ExceptionSvc::handle
StatusCode handle(const INamedInterface &o, const GaudiException &e) const override
Handle caught GaudiExceptions.
Definition
ExceptionSvc.cpp:218
ExceptionSvc::handleErr
StatusCode handleErr(const INamedInterface &o, const StatusCode &s) const override
Handle errors.
Definition
ExceptionSvc.cpp:149
ExceptionSvc::m_mode_exc_s
Gaudi::Property< std::string > m_mode_exc_s
Definition
ExceptionSvc.h:62
ExceptionSvc::initialize
StatusCode initialize() override
initialize the service
Definition
ExceptionSvc.cpp:40
ExceptionSvc::m_mode_err_s
Gaudi::Property< std::string > m_mode_err_s
Definition
ExceptionSvc.h:63
ExceptionSvc::m_retCodesExc
std::map< std::string, ReturnState > m_retCodesExc
Definition
ExceptionSvc.h:60
ExceptionSvc::process
virtual StatusCode process(const INamedInterface &o) const
Definition
ExceptionSvc.cpp:180
ExceptionSvc::ALL
@ ALL
Definition
ExceptionSvc.h:56
ExceptionSvc::NONE
@ NONE
Definition
ExceptionSvc.h:56
ExceptionSvc::RETHROW
@ RETHROW
Definition
ExceptionSvc.h:57
ExceptionSvc::FAILURE
@ FAILURE
Definition
ExceptionSvc.h:57
ExceptionSvc::SUCCESS
@ SUCCESS
Definition
ExceptionSvc.h:57
ExceptionSvc::RECOVERABLE
@ RECOVERABLE
Definition
ExceptionSvc.h:57
ExceptionSvc::DEFAULT
@ DEFAULT
Definition
ExceptionSvc.h:57
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition
INamedInterface.h:23
Service::m_state
Gaudi::StateMachine::State m_state
Service state.
Definition
Service.h:155
Service::initialize
StatusCode initialize() override
Definition
Service.cpp:118
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::RECOVERABLE
constexpr static const auto RECOVERABLE
Definition
StatusCode.h:101
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi::StateMachine::OFFLINE
@ OFFLINE
Definition
StateMachine.h:22
MSG::DEBUG
@ DEBUG
Definition
IMessageSvc.h:22
std
STL namespace.
GaudiMonitor
src
ExceptionSvc.cpp
Generated on
for The Gaudi Framework by
1.17.0