| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# GslSvc Class Reference

The implementation of IGslSvc interface. More...

`#include <GslSvc.h>`

Inheritance diagram for GslSvc:
[legend]
Collaboration diagram for GslSvc:
[legend]

List of all members.

## 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
| GslSvc (const std::string &name, ISvcLocator *svc)
| Standard constructor.
virtual | ~GslSvc ()
| destructor, virtual and protected
## Private Types
typedef std::vector< std::string > | Names
| external handlers
typedef std::vector < IGslErrorHandler * > | Handlers
## Private Member Functions
| GslSvc ()
| default constructor is private
| GslSvc (const GslSvc &)
| copy constructor is private
GslSvc & | operator= (const GslSvc &)
| assignment 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 factory for instantiation

## 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:

- "GSL": The simplest error policy, no action, the error hadling defined in GSL does not redefined

- "Off": The GSL empty error handling is used, what means the ignorance of all GSL errors. Program continues after any error, so the return values from any library routines must be checked. This policy is recommended by GSL team for production programs

- "Abort" The default GSL error policy, causes abort on error.

- "Ignore" The policy which is essentially the same as "Off", but performed with local error handler GslErrorHandlers::ignoreTheError

- "Exception" This policy throws the GaudiException with tag *GSL Error" to be thrown at the error. The policy implemented by local error handler GslErrorHandlers::throwException

- "Handle" The policy which uses the call back from local error handler GslErrorHandlers::handleTheError to IGslSvc::handle method. Current implementation of this method is sequential execution of declared handlers, defined through the property "Handlers" of class GslSvc in a format: GslSvc.Handlers = { "H1Type/H1Name" , "H2Type/H2Name" , "H3ype/3Name" }; The "handlers" must implement IGslErrorHandler interface The concrete handlers are provided in GaudiGSL package: class GslErorCount, GslErrorPrint and GslErrorException.

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.

## Member Typedef Documentation

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

external handlers

Definition at line 161 of file GslSvc.h.

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

Definition at line 163 of file GslSvc.h.

## Constructor & Destructor Documentation

GslSvc::GslSvc | ( | const std::string & | name,
|  | ISvcLocator * | svc |
| ) |  |  |

Standard constructor.

mandatory static factory for service instantiation

See also:
  Service

Parameters:

  | name | service name
  | scv | pointer to service locator

See also:
  SvcFactory

  ISvcFactory

  IFactory Standard constructor

Parameters:

  | name | service name
  | scv | pointer to service locator

Definition at line 48 of file GslSvc.cpp.

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

GslSvc::~GslSvc | ( |  | ) | `[virtual]`

destructor, virtual and protected

destructor

Definition at line 65 of file GslSvc.cpp.

    00065 {}

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

Parameters:

  | error | error

Returns:
  status code

Implements IGslSvc.

Definition at line 233 of file GslSvc.cpp.

    00234 {
    00235   StatusCode sc = StatusCode::SUCCESS ;
    00236   // code to be ignored?
    00237   if( m_ignore.end() != std::find( m_ignore.begin () ,
    00238                                    m_ignore.end   () ,
    00239                                    error.code        ) ) { return sc ; }
    00240   // invoke all handlers
    00241   for( Handlers::const_iterator handler = m_handlers.begin() ;
    00242        sc.isSuccess() && m_handlers.end() != handler ; ++handler )
    00243     { sc = (*handler)->handle( error  ); }
    00244   //
    00245   return sc ;
    00246 }

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

retrieve the current GSL error handler

See also:
  IGslSvc

Returns:
  current GSL error handler

  current GSL error handler

Implements IGslSvc.

Definition at line 182 of file GslSvc.cpp.

    00183 {
    00184   GslErrorHandler hh = gsl_set_error_handler( 0 );
    00185   gsl_set_error_handler( hh );
    00186   return hh ;
    00187 }

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

Parameters:

  | error | GLS error code

Returns:
  status code

Implements IGslSvc.

Definition at line 217 of file GslSvc.cpp.

    00218 {
    00219   if( GSL_SUCCESS == error ){ return StatusCode::SUCCESS ; }
    00220   StatusCode sc( error );
    00221   if( sc.isSuccess()       ){ return StatusCode::FAILURE ; }
    00222   return sc ;
    00223 }

StatusCode GslSvc::initialize | ( |  | ) | `[virtual]`

standard service initialization

See also:
  Service

  IGslSvc

  IService

Returns:
  status code

See also:
  Service

  IService

Returns:
  status code

Prints the type of used handler get the handler

Get Tool Service

Reimplemented from Service.

Definition at line 75 of file GslSvc.cpp.

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

StatusCode GslSvc::finalize | ( |  | ) | `[virtual]`

standard service finalization

See also:
  Service

  IGslSvc

  IService

Returns:
  status code

See also:
  Service

  IService

Returns:
  status code

Reimplemented from Service.

Definition at line 164 of file GslSvc.cpp.

    00165 {
    00166   MsgStream log(msgSvc(), name());
    00167   log << MSG::DEBUG << "==> Finalize" << endmsg;
    00168
    00169   // deactivate the static accessor to the service
    00170   GaudiGSL::setGslSvc( 0 );
    00171
    00172   // finalize the base class
    00173   return Service::finalize() ;
    00174 }

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

assignment operator is private

## Friends And Related Function Documentation

friend class SvcFactory< GslSvc >`[friend]`

friend factory for instantiation

Definition at line 88 of file GslSvc.h.

## Member Data Documentation

std::string GslSvc::m_errorPolicy`[private]`

error policy

Definition at line 158 of file GslSvc.h.

Names GslSvc::m_handlersTypeNames`[private]`

Definition at line 162 of file GslSvc.h.

Handlers GslSvc::m_handlers`[private]`

Definition at line 164 of file GslSvc.h.

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

codes to be ignored

Definition at line 167 of file GslSvc.h.

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r11/GaudiGSL/src/Components/GslSvc.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r11/GaudiGSL/src/Components/GslSvc.cpp