![]() |
|
|
Generated: 8 Jan 2009 |
00001 // $Id: ExceptionSvc.cpp,v 1.7 2008/06/02 14:21:35 marcocle Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: $ , version $Revision: 1.7 $ 00004 // ============================================================================ 00005 // Include files 00006 // ============================================================================ 00007 // STD & STL 00008 // ============================================================================ 00009 #include <cassert> 00010 // ============================================================================ 00011 // GaudiKernel 00012 // ============================================================================ 00013 #include "GaudiKernel/SvcFactory.h" 00014 #include "GaudiKernel/ISvcLocator.h" 00015 #include "GaudiKernel/MsgStream.h" 00016 // ============================================================================ 00017 //Local 00018 // ============================================================================ 00019 #include "ExceptionSvc.h" 00020 // ============================================================================ 00021 00022 00023 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00024 00025 DECLARE_SERVICE_FACTORY(ExceptionSvc) 00026 00027 // 00029 // 00030 00031 ExceptionSvc::ExceptionSvc( const std::string& name, ISvcLocator* svc ) 00032 : Service( name, svc ) 00033 , m_mode_s ( "all" ) 00034 , m_algs_v ( ) 00035 { 00036 declareProperty( "Catch" , m_mode_s ) ; 00037 declareProperty( "Algorithms" , m_algs_v ) ; 00038 } 00039 00040 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00041 00042 ExceptionSvc::~ExceptionSvc() { 00043 00044 } 00045 00046 00047 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00048 00049 StatusCode 00050 ExceptionSvc::initialize() { 00051 MsgStream log( msgSvc(), name() ); 00052 00053 StatusCode status = Service::initialize(); 00054 00055 if ( status.isFailure() ) { return status ; } // RETURN 00056 00057 if (m_mode_s == "all" || m_mode_s == "All" || m_mode_s == "ALL") { 00058 m_mode = ALL; 00059 } else if (m_mode_s == "none" || m_mode_s == "None" || 00060 m_mode_s == "NONE") { 00061 m_mode = NONE; 00062 } else if (m_mode_s == "list" || m_mode_s == "List" || 00063 m_mode_s == "LIST") { 00064 m_mode = LIST; 00065 } else { 00066 log << MSG::ERROR << "Unknown value for property \"State\". Must be" 00067 << " one of \"all\", \"none\", or \"list\"" << endreq; 00068 m_state = Gaudi::StateMachine::OFFLINE; 00069 return StatusCode::FAILURE; 00070 } 00071 00072 std::vector<std::string>::const_iterator itr; 00073 for (itr = m_algs_v.value().begin(); itr != m_algs_v.value().end(); ++itr) { 00074 std::string a = *itr; 00075 std::string alg(a); 00076 ReturnState ret(RETHROW); 00077 00078 std::string::size_type ieq = a.find("="); 00079 if (ieq != std::string::npos) { 00080 alg = a; 00081 alg.erase(ieq,alg.length()); 00082 a.erase(0,ieq+1); 00083 00084 if ( a == "DEFAULT" ) { 00085 ret = DEFAULT; 00086 } else if ( a == "SUCCESS" ) { 00087 log << MSG::WARNING << "Unusual custom error return code SUCCESS for" 00088 << " Algorithm \"" << alg << "\"" <<endreq; 00089 ret = SUCCESS; 00090 } else if ( a == "FAILURE" ) { 00091 ret = FAILURE; 00092 } else if ( a == "RECOVERABLE" ) { 00093 ret = RECOVERABLE; 00094 } else if ( a == "RETHROW" ) { 00095 ret = RETHROW; 00096 } else { 00097 log << MSG::ERROR << "In JobOpts: unknown return code \"" << a 00098 << "\" for Algorithm " << alg << std::endl 00099 << "Must be one of: DEFAULT, SUCCESS, FAILURE, RECOVERABLE, RETHROW" 00100 << endreq; 00101 m_state = Gaudi::StateMachine::OFFLINE; 00102 return StatusCode::FAILURE; 00103 } 00104 } 00105 00106 m_algs.insert( alg ); 00107 m_retCodes[alg] = ret; 00108 } 00109 00110 if (m_algs.size() > 0 && m_mode != NONE) { 00111 m_mode = LIST; 00112 00113 log << MSG::DEBUG << "Will catch exceptions thrown by: " << std::endl; 00114 std::set<std::string>::const_iterator it; 00115 for (it = m_algs.begin(); it != m_algs.end(); ++it) { 00116 log << " " << *it << " action: "; 00117 00118 ReturnState ret = m_retCodes.find(*it)->second; 00119 00120 switch( ret ) { 00121 case( DEFAULT ): 00122 log << "DEFAULT"; 00123 break; 00124 case( SUCCESS ): 00125 log << "SUCCESS"; 00126 break; 00127 case( FAILURE ): 00128 log << "FAILURE"; 00129 break; 00130 case( RECOVERABLE ): 00131 log << "RECOVERABLE"; 00132 break; 00133 case( RETHROW ): 00134 log << "RETHROW"; 00135 break; 00136 } 00137 00138 log << std::endl; 00139 } 00140 log << endreq; 00141 00142 } 00143 00144 return status; 00145 } 00146 00147 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00148 00149 StatusCode 00150 ExceptionSvc::finalize() { 00151 MsgStream log( msgSvc(), name() ); 00152 00153 StatusCode status = Service::finalize(); 00154 00155 return status; 00156 } 00157 00158 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00159 00160 StatusCode 00161 ExceptionSvc::queryInterface 00162 ( const InterfaceID& iid , 00163 void** ppvi ) 00164 { 00165 // invalid placeholder 00166 if ( 0 == ppvi ) { return StatusCode::FAILURE ; } // RETURN 00167 // check the identidier 00168 if ( IExceptionSvc::interfaceID().versionMatch( iid ) ) 00169 { *ppvi = static_cast<IExceptionSvc*> ( this ) ; } // OK ! 00170 else // ask for base class 00171 { return Service::queryInterface ( iid , ppvi ) ; } // RETURN 00172 // increment the reference counter 00173 addRef() ; 00174 // 00175 return StatusCode::SUCCESS ; // RETURN 00176 } 00177 00178 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00179 00180 StatusCode ExceptionSvc::handleErr 00181 ( const INamedInterface& alg , 00182 const StatusCode& st ) const 00183 { 00184 MsgStream log( msgSvc(), name() ); 00185 00186 log << MSG::DEBUG << "Handling Error " << alg.name() << endreq; 00187 00188 // Don't do anything 00189 if (m_mode == NONE) { 00190 return st; 00191 } 00192 00193 if (m_mode == ALL) { 00194 return StatusCode::FAILURE; 00195 } 00196 00197 assert (m_mode == LIST); 00198 00199 // Not one of the requested algs 00200 if (m_algs.find(alg.name()) == m_algs.end()) { 00201 return st; 00202 } 00203 00204 // Requested to do something with this alg 00205 ReturnState iret = m_retCodes.find(alg.name())->second; 00206 00207 switch ( iret ) { 00208 case DEFAULT: 00209 // there is no default 00210 return st; 00211 case SUCCESS: 00212 return StatusCode::SUCCESS; 00213 case FAILURE: 00214 return StatusCode::FAILURE; 00215 case RECOVERABLE: 00216 return StatusCode::RECOVERABLE; 00217 case RETHROW: 00218 return st; 00219 } 00220 00221 return st; 00222 00223 } 00224 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00225 00226 StatusCode ExceptionSvc::handle 00227 ( const INamedInterface& alg ) const 00228 { 00229 MsgStream log( msgSvc(), name() ); 00230 00231 log << MSG::DEBUG << "Handling unknown exception for " << alg.name() << endreq; 00232 00233 // Don't do anything 00234 if (m_mode == NONE) { 00235 return StatusCode::FAILURE; 00236 } 00237 00238 if (m_mode == ALL) { 00239 throw; 00240 } 00241 00242 assert (m_mode == LIST); 00243 00244 // Not one of the requested algs 00245 if (m_algs.find(alg.name()) == m_algs.end()) { 00246 return StatusCode::FAILURE; 00247 } 00248 00249 // Requested to do something with this alg 00250 ReturnState iret = m_retCodes.find(alg.name())->second; 00251 00252 switch ( iret ) { 00253 case DEFAULT: 00254 // there is no default 00255 return StatusCode::FAILURE; 00256 case SUCCESS: 00257 return StatusCode::SUCCESS; 00258 case FAILURE: 00259 return StatusCode::FAILURE; 00260 case RECOVERABLE: 00261 return StatusCode::RECOVERABLE; 00262 case RETHROW: 00263 throw; 00264 } 00265 00266 return StatusCode::FAILURE; 00267 00268 } 00269 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00270 00271 StatusCode ExceptionSvc::handle 00272 ( const INamedInterface& alg , 00273 const std::exception & exc ) const 00274 { 00275 MsgStream log( msgSvc(), name() ); 00276 00277 log << MSG::DEBUG << "Handling std:except for " << alg.name() << endreq; 00278 00279 // Don't do anything 00280 if (m_mode == NONE) { 00281 return StatusCode::FAILURE; 00282 } 00283 00284 if (m_mode == ALL) { 00285 throw ( exc ); 00286 } 00287 00288 assert (m_mode == LIST); 00289 00290 // Not one of the requested algs 00291 if (m_algs.find(alg.name()) == m_algs.end()) { 00292 return StatusCode::FAILURE; 00293 } 00294 00295 // Requested to do something with this alg 00296 ReturnState iret = m_retCodes.find(alg.name())->second; 00297 00298 switch ( iret ) { 00299 case DEFAULT: 00300 // there is no default 00301 return StatusCode::FAILURE; 00302 break; 00303 case SUCCESS: 00304 return StatusCode::SUCCESS; 00305 break; 00306 case FAILURE: 00307 return StatusCode::FAILURE; 00308 break; 00309 case RECOVERABLE: 00310 return StatusCode::RECOVERABLE; 00311 break; 00312 case RETHROW: 00313 throw ( exc ); 00314 } 00315 00316 return StatusCode::FAILURE; 00317 00318 } 00319 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00320 00321 StatusCode ExceptionSvc::handle 00322 ( const INamedInterface& alg , 00323 const GaudiException & exc ) const 00324 { 00325 00326 MsgStream log( msgSvc(), name() ); 00327 log << MSG::DEBUG << "Handling GaudiExcept for " << alg.name() << endreq; 00328 00329 // Don't do anything 00330 if (m_mode == NONE) { 00331 return StatusCode::FAILURE; 00332 } 00333 00334 // rethrow 00335 if (m_mode == ALL) { 00336 throw (exc); 00337 return StatusCode::FAILURE; 00338 } 00339 00340 assert(m_mode == LIST); 00341 00342 // Not one of the requested algs 00343 if (m_algs.find(alg.name()) == m_algs.end()) { 00344 return StatusCode::FAILURE; 00345 } 00346 00347 // Requested to do something with this alg 00348 ReturnState iret = m_retCodes.find(alg.name())->second; 00349 00350 switch ( iret ) { 00351 case DEFAULT: 00352 return exc.code(); 00353 case SUCCESS: 00354 return StatusCode::SUCCESS; 00355 case FAILURE: 00356 return StatusCode::FAILURE; 00357 case RECOVERABLE: 00358 return StatusCode::RECOVERABLE; 00359 case RETHROW: 00360 throw ( exc ); 00361 } 00362 00363 return StatusCode::FAILURE; 00364 00365 } 00366 00367 // ============================================================================ 00368 // The END 00369 // ============================================================================