Gaudi Framework, version v20r2

Generated: 18 Jul 2008

GslSvc Class Reference

#include <GslSvc.h>

Inheritance diagram for GslSvc:

Inheritance graph
[legend]
Collaboration diagram for GslSvc:

Collaboration graph
[legend]
List of all members.

Detailed Description

The implementation of IGslSvc interface.

The Gsl Service is teh service which perform intelligent error handling for GSL (GNU Scientific Library)

It provides a choice between different "Error Handling Policies"

Current implementation supports the several "error handling policies", which are driven by "ErrorPolicy" property of class GslSvc:

Attention:
The error handling could be "turned off" for selected error codes (e.g. GSL_SUCCESS or GSL_CONTINUE ) using "IgnoreCodes" property. This feature is active only for "Handle" error policy.
See also:
GslErrorHandlers

GslErrorHandlers::ingnoreTheError

GslErrorHandlers::throwException

GslErrorHandlers::handleTheError

IGslSvc

IGslErrorHandler

GslErrorCount

GslErrorPrint

GslErrorException

Author:
Vanya Belyaev Ivan.Belyaev@itep.ru
Date:
29/04/2002

Definition at line 86 of file GslSvc.h.

Public Member Functions

virtual StatusCode handle (const GslError &error) const
 handle the GSL error
virtual GslErrorHandler handler () const
 retrieve the current GSL error handler
virtual GslErrorHandler setHandler (GslErrorHandler handler) const
 set new GSL error handler
virtual StatusCode status (const int error) const
 transform GSL error code to Gaudi status code
virtual StatusCode initialize ()
 standard service initialization
virtual StatusCode finalize ()
 standard service finalization
virtual StatusCode queryInterface (const InterfaceID &iid, void **ppi)
 query the interface
 GslSvc (const std::string &name, ISvcLocator *svc)
 Standard constructor.
virtual ~GslSvc ()
 destructor, virtual and protected

Private Types

typedef std::vector< std::stringNames
 external hanlers
typedef std::vector< IGslErrorHandler * > Handlers

Private Member Functions

 GslSvc ()
 default constructor is private
 GslSvc (const GslSvc &)
 copy constructor is private
GslSvcoperator= (const GslSvc &)
 assignement operator is private

Private Attributes

std::string m_errorPolicy
 error policy
Names m_handlersTypeNames
Handlers m_handlers
std::vector< int > m_ignore
 codes to be ignored

Friends

class SvcFactory< GslSvc >
 friend factrory for instantiation


Member Typedef Documentation

typedef std::vector<std::string> GslSvc::Names [private]

external hanlers

Definition at line 177 of file GslSvc.h.

typedef std::vector<IGslErrorHandler*> GslSvc::Handlers [private]

Definition at line 179 of file GslSvc.h.


Constructor & Destructor Documentation

GslSvc::GslSvc ( const std::string name,
ISvcLocator svc 
)

Standard constructor.

See also:
Service
Parameters:
name service name
scv pointer to service locator

Definition at line 49 of file GslSvc.cpp.

00051   : Service ( name , svc ) 
00052   , m_errorPolicy       ( "GSL" )
00053   , m_handlersTypeNames ()
00054   , m_handlers          ()
00055   , m_ignore            ()
00056 {
00057   declareProperty( "ErrorPolicy" , m_errorPolicy       ) ;  
00058   declareProperty( "Handlers"    , m_handlersTypeNames ) ;
00059   declareProperty( "IgnoreCodes" , m_ignore            ) ;
00060 };

GslSvc::~GslSvc (  )  [virtual]

destructor, virtual and protected

Definition at line 66 of file GslSvc.cpp.

00066 {}; 

GslSvc::GslSvc (  )  [private]

default constructor is private

GslSvc::GslSvc ( const GslSvc  )  [private]

copy constructor is private


Member Function Documentation

StatusCode GslSvc::handle ( const GslError error  )  const [virtual]

handle the GSL error

See also:
IGslSvc
Parameters:
err error
Returns:
status code

Implements IGslSvc.

Definition at line 268 of file GslSvc.cpp.

References GslError::code, std::find(), StatusCode::isSuccess(), and StatusCode::SUCCESS.

00269 {
00270   StatusCode sc = StatusCode::SUCCESS ;
00271   // code to be ignored? 
00272   if( m_ignore.end() != std::find( m_ignore.begin () ,
00273                                    m_ignore.end   () , 
00274                                    error.code        ) ) { return sc ; }
00275   // invoke all handlers 
00276   for( Handlers::const_iterator handler = m_handlers.begin() ;
00277        sc.isSuccess() && m_handlers.end() != handler ; ++handler ) 
00278     { sc = (*handler)->handle( error  ); }
00279   //
00280   return sc ;
00281 };

IGslSvc::GslErrorHandler GslSvc::handler (  )  const [virtual]

retrieve the current GSL error handler

See also:
IGslSvc
Returns:
current GSL error handler

Implements IGslSvc.

Definition at line 217 of file GslSvc.cpp.

Referenced by initialize().

00218 {
00219   GslErrorHandler hh = gsl_set_error_handler( 0 );
00220   gsl_set_error_handler( hh );  
00221   return hh ;
00222 };

virtual GslErrorHandler GslSvc::setHandler ( GslErrorHandler  handler  )  const [virtual]

set new GSL error handler

See also:
IGslSvc
Parameters:
handler new GSL error handler
Returns:
GSL error handler

StatusCode GslSvc::status ( const int  error  )  const [virtual]

transform GSL error code to Gaudi status code

See also:
IGslSvc
Parameters:
error GLS error code
Returns:
status code

Implements IGslSvc.

Definition at line 252 of file GslSvc.cpp.

References StatusCode::FAILURE, StatusCode::isSuccess(), and StatusCode::SUCCESS.

00253 {
00254   if( GSL_SUCCESS == error ){ return StatusCode::SUCCESS ; }
00255   StatusCode sc( error );
00256   if( sc.isSuccess()       ){ return StatusCode::FAILURE ; }
00257   return sc ;
00258 };

StatusCode GslSvc::initialize (  )  [virtual]

standard service initialization

See also:
Service

IGslSvc

IService

Returns:
status code

Prints the type of used handler get the handler

Get Tool Service

Reimplemented from Service.

Definition at line 76 of file GslSvc.cpp.

References std::vector< _Tp, _Alloc >::begin(), std::vector< _Tp, _Alloc >::empty(), std::vector< _Tp, _Alloc >::end(), endreq(), MSG::ERROR, StatusCode::FAILURE, std::find(), handler(), GslErrorHandlers::handleTheError(), GslErrorHandlers::ignoreTheError(), MSG::INFO, Service::initialize(), StatusCode::isFailure(), std::basic_string< _CharT, _Traits, _Alloc >::length(), m_errorPolicy, m_handlers, m_handlersTypeNames, Service::msgSvc(), Service::name(), std::vector< _Tp, _Alloc >::push_back(), ISvcLocator::service(), Service::serviceLocator(), GaudiGSL::setGslSvc(), StatusCode::SUCCESS, GslErrorHandlers::throwException(), System::typeinfoName(), and MSG::VERBOSE.

00077 {
00078   // initialize the base class 
00079   StatusCode sc = Service::initialize();      
00080   MsgStream log( msgSvc() , name() );
00081   if( sc.isFailure() )
00082     { log << MSG::ERROR 
00083           << " Error in initialization of base class 'Service'"<< endreq;
00084     return sc;
00085     }
00086   // activate the static accessor to the service  
00087   GaudiGSL::setGslSvc( this );
00088   // set the error handlers 
00089   if      ( "GSL"       == m_errorPolicy ) { /* nothing to do */ }
00090   else if ( "Off"       == m_errorPolicy )
00091     { gsl_set_error_handler_off()                                ; }
00092   else if ( "Abort"     == m_errorPolicy )
00093     { gsl_set_error_handler ( 0 )                                ; }
00094   else if ( "Ignore"    == m_errorPolicy )
00095     { gsl_set_error_handler ( GslErrorHandlers::ignoreTheError ) ; }
00096   else if ( "Exception" == m_errorPolicy ) 
00097     { gsl_set_error_handler ( GslErrorHandlers::throwException ) ; }
00098   else if ( "Handle"    == m_errorPolicy )
00099     { gsl_set_error_handler ( GslErrorHandlers::handleTheError ) ; }
00100   else 
00101     { log << MSG::ERROR 
00102           << " Unknown Error policy '" << m_errorPolicy << "'" 
00103           << " Valid policies: " 
00104           << "[ 'GSL' , 'Off' , 'Abort' , 'Ignore' , 'Exception' , 'Handle' ]"
00105           << endreq;
00106     return StatusCode::FAILURE ;
00107     }
00110   GslErrorHandler handler = gsl_set_error_handler( 0 );
00111   gsl_set_error_handler( handler );
00112   if( 0 != handler )
00113     { log << MSG::VERBOSE
00114           << " GSL Error Handler is '" 
00115           << System::typeinfoName( typeid(*handler) ) << "'"
00116           << endreq; }
00117   else { log << MSG::INFO << " Error Handler is NULL" << endreq ; }
00118   
00119   if( !m_handlersTypeNames.empty() )
00120     {
00122       IToolSvc* toolsvc = 0 ;
00123       StatusCode sc = 
00124         serviceLocator()->service( "ToolSvc" , toolsvc , true );
00125       if ( sc.isFailure() )
00126         { log << MSG::ERROR << " Could not locate Tool Service! " << endreq ;
00127         return sc ; }
00128       if ( 0 == toolsvc   ) 
00129         { log << MSG::ERROR << " Could not locate Tool Service! " << endreq ;
00130         return StatusCode::FAILURE ; }      
00131       for( Names::const_iterator it = m_handlersTypeNames.begin() ;
00132            m_handlersTypeNames.end() != it ; ++it )
00133         {
00134           std::string::const_iterator ipos = 
00135             std::find( it->begin() , it->end() , '/');
00136           const std::string::size_type pos = ipos - it->begin() ;
00137           IGslErrorHandler* eh = 0 ;
00138           if( it->end() != ipos ) 
00139             { sc = toolsvc->retrieveTool 
00140                 ( std::string( *it , 0 , pos )       , 
00141                   std::string( *it , pos + 1, it->length() ), eh , this ) ; }
00142           else 
00143             { sc = toolsvc->retrieveTool 
00144                 ( *it , std::string( *it , pos + 1, it->length() ) , 
00145                   eh , this ) ; }
00146           if( sc.isFailure() )
00147             { log << MSG::ERROR 
00148                   << " Could not retrieve tool '" << *it << "'"<< endreq ;
00149             return sc ; }
00150           if( 0 == eh )
00151             { log << MSG::ERROR 
00152                   << " Could not retrieve tool '" << *it << "'"<< endreq ;
00153             return StatusCode::FAILURE  ; }
00154           m_handlers.push_back( eh );
00155         }
00156     }    
00157   //
00158   return StatusCode::SUCCESS;
00159 };

StatusCode GslSvc::finalize (  )  [virtual]

standard service finalization

See also:
Service

IGslSvc

IService

Returns:
status code

Reimplemented from Service.

Definition at line 169 of file GslSvc.cpp.

References MSG::DEBUG, endreq(), Service::finalize(), Service::msgSvc(), Service::name(), and GaudiGSL::setGslSvc().

00170 {
00171   MsgStream log(msgSvc(), name());
00172   log << MSG::DEBUG << "==> Finalize" << endreq;
00173   
00174   // deactivate the static accessor to the service  
00175   GaudiGSL::setGslSvc( 0 );
00176   
00177   // finalize the base class 
00178   return Service::finalize() ;
00179 };

StatusCode GslSvc::queryInterface ( const InterfaceID iid,
void **  ppi 
) [virtual]

query the interface

See also:
Service

IGslSvc

IService

IInterface

Parameters:
iid the unique interface
ppi the placeholder to put the interface
Returns:
status code

Reimplemented from Service.

Definition at line 193 of file GslSvc.cpp.

References StatusCode::FAILURE, IInterface::interfaceID(), IService::interfaceID(), IGslSvc::interfaceID(), Service::queryInterface(), and StatusCode::SUCCESS.

00195 {
00196   if     ( 0 == ppi                          ) { return StatusCode::FAILURE ; }
00197   if     ( IGslSvc::    interfaceID() == iid )
00198     { *ppi = static_cast<IGslSvc*>    ( this ); }
00199   else if( IService::   interfaceID() == iid )
00200     { *ppi = static_cast<IService*>   ( this ); }
00201   else if( IInterface:: interfaceID() == iid )
00202     { *ppi = static_cast<IInterface*> ( this ); }
00203   else 
00204     { return Service::queryInterface( iid , ppi ) ; }      // RETURN !
00205   //
00206   addRef();
00207   //
00208   return StatusCode::SUCCESS ;
00209 };

GslSvc& GslSvc::operator= ( const GslSvc  )  [private]

assignement operator is private


Friends And Related Function Documentation

friend class SvcFactory< GslSvc > [friend]

friend factrory for instantiation

Definition at line 91 of file GslSvc.h.


Member Data Documentation

std::string GslSvc::m_errorPolicy [private]

error policy

Definition at line 174 of file GslSvc.h.

Referenced by initialize().

Names GslSvc::m_handlersTypeNames [private]

Definition at line 178 of file GslSvc.h.

Referenced by initialize().

Handlers GslSvc::m_handlers [private]

Definition at line 180 of file GslSvc.h.

Referenced by initialize().

std::vector<int> GslSvc::m_ignore [private]

codes to be ignored

Definition at line 183 of file GslSvc.h.


The documentation for this class was generated from the following files:
Generated at Fri Jul 18 12:07:46 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004