Gaudi Framework, version v24r2

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

Generated at Wed Dec 4 2013 14:33:10 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004