| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ExceptionSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // STD & STL
5 // ============================================================================
6 #include <cassert>
7 #include <algorithm>
8 // ============================================================================
9 // GaudiKernel
10 // ============================================================================
11 #include "GaudiKernel/ISvcLocator.h"
12 #include "GaudiKernel/Tokenizer.h"
13 // ============================================================================
14 //Local
15 // ============================================================================
16 #include "ExceptionSvc.h"
17 // ============================================================================
18
19 using namespace std;
20
21 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22
23 DECLARE_COMPONENT(ExceptionSvc)
24
25 inline void toupper(std::string &s)
26 {
27 std::transform(s.begin(), s.end(), s.begin(),
28 (int(*)(int)) toupper);
29 }
30
31 //
33 //
34
35 ExceptionSvc::ExceptionSvc( const std::string& name, ISvcLocator* svc )
36 : base_class( name, svc )
37 , m_mode_exc ( ALL ), m_mode_err( NONE )
38 , m_log(msgSvc(), name )
39 {
40 // for exceptions
41 declareProperty( "Catch" , m_mode_exc_s="ALL" ) ;
42
43 // for return codes
44 declareProperty( "Errors" , m_mode_err_s="NONE" ) ;
45 }
46
47 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
48
49 ExceptionSvc::~ExceptionSvc() {
50
51 }
52
53
54 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
55
56 StatusCode
57 ExceptionSvc::initialize() {
58 StatusCode status = Service::initialize();
59 m_log.setLevel( m_outputLevel.value() );
60
61 if ( status.isFailure() ) { return status ; } // RETURN
62
63 string key = m_mode_exc_s.value();
64
65 string::size_type loc = key.find(" ");
66 std::string mode;
67 if (loc == std::string::npos) {
68 mode = key;
69 } else {
70 mode = key.substr(0,loc);
71 }
72
73 toupper(mode);
74
75 if (mode == "NONE") {
76 m_mode_exc = NONE;
77 } else if (mode == "ALL") {
78 m_mode_exc = ALL;
79 } else {
80 m_log << MSG::ERROR << "Unknown mode for Exception handling: \"" << mode
81 << "\". Default must be one of \"ALL\" or \"NONE\"" << endmsg;
82 m_state = Gaudi::StateMachine::OFFLINE;
83 return StatusCode::FAILURE;
84 }
85
86 if (loc == string::npos) {
87 key = "";
88 } else {
89 key = key.substr(loc+1,key.length());
90 }
91
92 Tokenizer tok(true);
93 std::string val,VAL,TAG;
94
95 tok.analyse( key, " ", "", "", "=", "", "");
96
97 for ( Tokenizer::Items::iterator i = tok.items().begin();
98 i != tok.items().end(); i++) {
99 const std::string& tag = (*i).tag();
100 TAG = tag;
101
102 val = (*i).value();
103 VAL = val;
104 toupper(VAL);
105
106 if (VAL == "SUCCESS") {
107 m_retCodesExc[TAG] = SUCCESS;
108 } else if ( VAL == "FAILURE" ) {
109 m_retCodesExc[TAG] = FAILURE;
110 } else if ( VAL == "REVOVERABLE" ) {
111 m_retCodesExc[TAG] = RECOVERABLE;
112 } else if ( VAL == "RETHROW" ) {
113 m_retCodesExc[TAG] = RETHROW;
114 } else if ( VAL == "DEFAULT" ) {
115 m_retCodesExc[TAG] = DEFAULT;
116 } else {
117 m_log << MSG::ERROR << "In JobOpts: unknown return code \"" << VAL
118 << "\" for Algorithm " << TAG << std::endl
119 << " Must be one of: DEFAULT, SUCCESS, FAILURE, RECOVERABLE, RETHROW"
120 << endmsg;
121 m_state = Gaudi::StateMachine::OFFLINE;
122 return StatusCode::FAILURE;
123 }
124
125 m_log << MSG::DEBUG << "Will catch exceptions thrown by: " << TAG
126 << " -> action: " << VAL << endmsg;
127
128 }
129
130 // now process errors
131
132 key = m_mode_err_s.value();
133
134 loc = key.find(" ");
135 if (loc == std::string::npos) {
136 mode = key;
137 } else {
138 mode = key.substr(0,loc);
139 }
140
141 toupper(mode);
142
143 if (mode == "NONE") {
144 m_mode_err = NONE;
145 } else if (mode == "ALL") {
146 m_mode_err = ALL;
147 } else {
148 m_log << MSG::ERROR << "Unknown mode for Error handling: \"" << mode
149 << "\". Default must be one of \"ALL\" or \"NONE\"" << endmsg;
150 m_state = Gaudi::StateMachine::OFFLINE;
151 return StatusCode::FAILURE;
152 }
153
154 if (loc == string::npos) {
155 key = "";
156 } else {
157 key = key.substr(loc+1,key.length());
158 }
159
160 Tokenizer tok2(true);
161 tok2.analyse( key, " ", "", "", "=", "", "");
162
163 for ( Tokenizer::Items::iterator i = tok2.items().begin();
164 i != tok2.items().end(); i++) {
165 const std::string& tag = (*i).tag();
166 TAG = tag;
167
168 val = (*i).value();
169 VAL = val;
170 toupper(VAL);
171
172 if (VAL == "SUCCESS") {
173 m_retCodesErr[TAG] = SUCCESS;
174 } else if ( VAL == "FAILURE" ) {
175 m_retCodesErr[TAG] = FAILURE;
176 } else if ( VAL == "RECOVERABLE" ) {
177 m_retCodesErr[TAG] = RECOVERABLE;
178 } else {
179 m_log << MSG::ERROR << "In JobOpts: unknown return code \"" << VAL
180 << "\" for Algorithm " << TAG << std::endl
181 << " Must be one of: SUCCESS, FAILURE, RECOVERABLE"
182 << endmsg;
183 m_state = Gaudi::StateMachine::OFFLINE;
184 return StatusCode::FAILURE;
185 }
186
187 m_log << MSG::DEBUG << "Will process Errors returned by: " << TAG
188 << " -> action: " << VAL << endmsg;
189
190 }
191
192 return status;
193 }
194
195 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
196
197 StatusCode
198 ExceptionSvc::finalize() {
199 StatusCode status = Service::finalize();
200
201 return status;
202 }
203
204 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
205
206 StatusCode ExceptionSvc::handleErr
207 ( const INamedInterface& alg ,
208 const StatusCode& st ) const
209 {
210 m_log << MSG::DEBUG << "Handling Error from " << alg.name() << endmsg;
211
212 // is this Alg special?
213 if (m_retCodesErr.find(alg.name()) != m_retCodesErr.end()) {
214 ReturnState iret = m_retCodesErr.find(alg.name())->second;
215
216 switch ( iret ) {
217 case SUCCESS:
218 return StatusCode::SUCCESS;
219 case FAILURE:
220 return StatusCode::FAILURE;
221 case RECOVERABLE:
222 return StatusCode::RECOVERABLE;
223 case RETHROW:
224 // should never get here
225 break;
226 case DEFAULT:
227 // should never get here
228 break;
229 }
230
231 } else {
232
233 if (m_mode_err == ALL) {
234 // turn it into a FAILURE
235 return StatusCode::FAILURE;
236
237 } else {
238 assert (m_mode_err == NONE );
239 // don't touch the return code
240 return st;
241 }
242 }
243
244 return StatusCode::FAILURE;
245 }
246 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
247
248 StatusCode ExceptionSvc::process
249 ( const INamedInterface& alg ) const
250 {
251
252 // is this Alg special?
253 if (m_retCodesExc.find(alg.name()) != m_retCodesExc.end()) {
254 ReturnState iret = m_retCodesExc.find(alg.name())->second;
255
256 switch ( iret ) {
257 case DEFAULT:
258 // there is no default
259 return StatusCode::FAILURE;
260 case SUCCESS:
261 return StatusCode::SUCCESS;
262 case FAILURE:
263 return StatusCode::FAILURE;
264 case RECOVERABLE:
265 return StatusCode::RECOVERABLE;
266 case RETHROW:
267 throw;
268 }
269
270 } else {
271
272 if (m_mode_exc == ALL) {
273 throw;
274 } else {
275 assert (m_mode_exc == NONE);
276 return StatusCode::FAILURE;
277 }
278 }
279
280 return StatusCode::FAILURE;
281 }
282 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
283
284 StatusCode ExceptionSvc::handle
285 ( const INamedInterface& alg ) const
286 {
287 m_log << MSG::DEBUG << "Handling unknown exception for " << alg.name()
288 << endmsg;
289
290 return process(alg);
291 }
292 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
293
294 StatusCode ExceptionSvc::handle
295 ( const INamedInterface& alg ,
296 const std::exception & exc ) const
297 {
298 m_log << MSG::DEBUG << "Handling std:except: \"" << exc.what() << "\" for "
299 << alg.name() << endmsg;
300
301 return process(alg) ;
302
303 }
304 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
305
306 StatusCode ExceptionSvc::handle
307 ( const INamedInterface& alg ,
308 const GaudiException & exc ) const
309 {
310 m_log << MSG::DEBUG << "Handling GaudiException: \"" << exc << "\" for "
311 << alg.name() << endmsg;
312
313 return process(alg);
314
315 }
316
317 // ============================================================================
318 // The END
319 // ============================================================================