GslSvc Class Reference

The implementation of IGslSvc interface. More...

#include <src/Components/GslSvc.h>

Inheritance diagram for GslSvc:
Collaboration diagram for GslSvc:

Public Member Functions

StatusCode handle (const GslError &error) const override
 handle the GSL error More...
 
GslErrorHandler handler () const override
 retrieve the current GSL error handler More...
 
GslErrorHandler setHandler (GslErrorHandler handler) const override
 set new GSL error handler More...
 
StatusCode status (const int error) const override
 transform GSL error code to Gaudi status code More...
 
StatusCode initialize () override
 standard service initialization More...
 
StatusCode finalize () override
 standard service finalization More...
 
 GslSvc (const std::string &name, ISvcLocator *svc)
 Standard constructor. More...
 
 ~GslSvc () override=default
 destructor, virtual and protected More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Types

typedef std::vector< std::string > Names
 external handlers More...
 
typedef std::vector< IGslErrorHandler * > Handlers
 

Private Member Functions

 GslSvc ()
 default constructor is private More...
 
 GslSvc (const GslSvc &)
 copy constructor is private More...
 
GslSvcoperator= (const GslSvc &)
 assignment operator is private More...
 

Private Attributes

std::string m_errorPolicy = "GSL"
 error policy More...
 
Names m_handlersTypeNames
 
Handlers m_handlers
 
std::vector< int > m_ignore
 codes to be ignored More...
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

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..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru
Date
29/04/2002

Definition at line 83 of file GslSvc.h.

Member Typedef Documentation

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

Definition at line 157 of file GslSvc.h.

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

external handlers

Definition at line 155 of file GslSvc.h.

Constructor & Destructor Documentation

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

Standard constructor.

See also
Service
Parameters
nameservice name
scvpointer to service locator
nameservice name
scvpointer to service locator

Definition at line 38 of file GslSvc.cpp.

40  : base_class ( name , svc )
41 {
42  declareProperty( "ErrorPolicy" , m_errorPolicy ) ;
43  declareProperty( "Handlers" , m_handlersTypeNames ) ;
44  declareProperty( "IgnoreCodes" , m_ignore ) ;
45 }
std::vector< int > m_ignore
codes to be ignored
Definition: GslSvc.h:161
extends base_class
Typedef to this class.
Definition: extends.h:14
Names m_handlersTypeNames
Definition: GslSvc.h:156
std::string m_errorPolicy
error policy
Definition: GslSvc.h:152
GslSvc::~GslSvc ( )
overridedefault

destructor, virtual and protected

GslSvc::GslSvc ( )
private

default constructor is private

GslSvc::GslSvc ( const GslSvc )
private

copy constructor is private

Member Function Documentation

StatusCode GslSvc::finalize ( )
override

standard service finalization

See also
Service
IGslSvc
IService
Returns
status code
See also
Service
IService
Returns
status code

Definition at line 140 of file GslSvc.cpp.

141 {
142  MsgStream log(msgSvc(), name());
143  log << MSG::DEBUG << "==> Finalize" << endmsg;
144 
145  // deactivate the static accessor to the service
146  GaudiGSL::setGslSvc( nullptr );
147 
148  // finalize the base class
149  return Service::finalize() ;
150 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode finalize() override
Definition: Service.cpp:188
static const IGslSvc * setGslSvc(const IGslSvc *value)
set new value for static Gaudi GSL Service
Definition: GaudiGSL.cpp:35
StatusCode GslSvc::handle ( const GslError error) const
override

handle the GSL error

See also
IGslSvc
Parameters
errerror
Returns
status code
Parameters
errorerror
Returns
status code

Definition at line 209 of file GslSvc.cpp.

210 {
212  // code to be ignored?
213  if( m_ignore.end() != std::find( m_ignore.begin () ,
214  m_ignore.end () ,
215  error.code ) ) { return sc ; }
216  // invoke all handlers
217  for( auto handler = m_handlers.begin() ;
218  sc.isSuccess() && m_handlers.end() != handler ; ++handler )
219  { sc = (*handler)->handle( error ); }
220  //
221  return sc ;
222 }
std::vector< int > m_ignore
codes to be ignored
Definition: GslSvc.h:161
int code
error code (GSL)
Definition: GslError.h:25
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Handlers m_handlers
Definition: GslSvc.h:158
GslErrorHandler handler() const override
retrieve the current GSL error handler
Definition: GslSvc.cpp:158
IGslSvc::GslErrorHandler GslSvc::handler ( ) const
override

retrieve the current GSL error handler

See also
IGslSvc
Returns
current GSL error handler
current GSL error handler

Definition at line 158 of file GslSvc.cpp.

159 {
160  GslErrorHandler hh = gsl_set_error_handler( nullptr );
161  gsl_set_error_handler( hh );
162  return hh ;
163 }
StatusCode GslSvc::initialize ( )
override

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

Definition at line 56 of file GslSvc.cpp.

57 {
58  // initialize the base class
60  MsgStream log( msgSvc() , name() );
61  if( sc.isFailure() )
62  { log << MSG::ERROR
63  << " Error in initialization of base class 'Service'"<< endmsg;
64  return sc;
65  }
66  // activate the static accessor to the service
67  GaudiGSL::setGslSvc( this );
68  // set the error handlers
69  if ( "GSL" == m_errorPolicy ) { /* nothing to do */ }
70  else if ( "Off" == m_errorPolicy )
71  { gsl_set_error_handler_off() ; }
72  else if ( "Abort" == m_errorPolicy )
73  { gsl_set_error_handler ( nullptr ) ; }
74  else if ( "Ignore" == m_errorPolicy )
75  { gsl_set_error_handler ( GslErrorHandlers::ignoreTheError ) ; }
76  else if ( "Exception" == m_errorPolicy )
77  { gsl_set_error_handler ( GslErrorHandlers::throwException ) ; }
78  else if ( "Handle" == m_errorPolicy )
79  { gsl_set_error_handler ( GslErrorHandlers::handleTheError ) ; }
80  else
81  { log << MSG::ERROR
82  << " Unknown Error policy '" << m_errorPolicy << "'"
83  << " Valid policies: "
84  << "[ 'GSL' , 'Off' , 'Abort' , 'Ignore' , 'Exception' , 'Handle' ]"
85  << endmsg;
86  return StatusCode::FAILURE ;
87  }
90  GslErrorHandler handler = gsl_set_error_handler( nullptr );
91  gsl_set_error_handler( handler );
92  if( handler )
93  { log << MSG::VERBOSE
94  << " GSL Error Handler is '"
95  << System::typeinfoName( typeid(*handler) ) << "'"
96  << endmsg; }
97  else { log << MSG::INFO << " Error Handler is NULL" << endmsg ; }
98 
99  if( !m_handlersTypeNames.empty() )
100  {
102  auto toolsvc = serviceLocator()->service<IToolSvc>("ToolSvc");
103  if (!toolsvc) {
104  log << MSG::ERROR << " Could not locate Tool Service! " << endmsg;
105  return StatusCode::FAILURE;
106  }
107  for( const auto& it : m_handlersTypeNames )
108  {
109  auto pos = it.find('/');
110  IGslErrorHandler* eh = nullptr ;
111  if( pos != std::string::npos ) {
112  sc = toolsvc->retrieveTool
113  ( it.substr( 0 , pos ), it.substr( pos + 1 ), eh , this ) ;
114  } else {
115  sc = toolsvc->retrieveTool( it , it , eh , this ) ;
116  }
117  if( sc.isFailure() )
118  { log << MSG::ERROR
119  << " Could not retrieve tool '" << it << "'"<< endmsg ;
120  return sc ; }
121  if( !eh )
122  { log << MSG::ERROR
123  << " Could not retrieve tool '" << it << "'"<< endmsg ;
124  return StatusCode::FAILURE ; }
125  m_handlers.push_back( eh );
126  }
127  }
128  //
129  return StatusCode::SUCCESS;
130 }
The abstract interface for arbitrary GSL error handler.
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:18
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:63
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:297
Names m_handlersTypeNames
Definition: GslSvc.h:156
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GAUDI_API void throwException(const char *reason, const char *file, int line, int code)
The simple Gsl Error handler, it throwns the Gaudi Exception.
Handlers m_handlers
Definition: GslSvc.h:158
std::string m_errorPolicy
error policy
Definition: GslSvc.h:152
GslErrorHandler handler() const override
retrieve the current GSL error handler
Definition: GslSvc.cpp:158
GAUDI_API void handleTheError(const char *reason, const char *file, int line, int code)
The simplest Gsl Error handler, It delegates the actual error handling to GSL Service.
GAUDI_API void ignoreTheError(const char *reason, const char *file, int line, int code)
The simplest Gsl Error handler, It simply ingnores the error.
static const IGslSvc * setGslSvc(const IGslSvc *value)
set new value for static Gaudi GSL Service
Definition: GaudiGSL.cpp:35
GslSvc& GslSvc::operator= ( const GslSvc )
private

assignment operator is private

IGslSvc::GslErrorHandler GslSvc::setHandler ( GslErrorHandler  handler) const
override

set new GSL error handler

See also
IGslSvc
Parameters
handlernew GSL error handler
Returns
GSL error handler
Parameters
handlernew GSL error handler
Returns
GSL error handler

Definition at line 173 of file GslSvc.cpp.

174 {
175  gsl_set_error_handler( handler );
176  {
177  MsgStream log( msgSvc(), name() );
178  log << MSG::DEBUG << " New GSL handler is set '" ;
179  if( !handler ) { log << "NULL" ; }
180  else { log << System::typeinfoName( typeid(handler) ) ; }
181  log << "'" << endmsg ;
182  }
183  return handler ;
184 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:297
GslErrorHandler handler() const override
retrieve the current GSL error handler
Definition: GslSvc.cpp:158
StatusCode GslSvc::status ( const int  error) const
override

transform GSL error code to Gaudi status code

See also
IGslSvc
Parameters
errorGLS error code
Returns
status code
Parameters
errorGLS error code
Returns
status code

Definition at line 193 of file GslSvc.cpp.

194 {
195  if( GSL_SUCCESS == error ){ return StatusCode::SUCCESS ; }
196  StatusCode sc( error );
197  if( sc.isSuccess() ){ return StatusCode::FAILURE ; }
198  return sc ;
199 }
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26

Member Data Documentation

std::string GslSvc::m_errorPolicy = "GSL"
private

error policy

Definition at line 152 of file GslSvc.h.

Handlers GslSvc::m_handlers
private

Definition at line 158 of file GslSvc.h.

Names GslSvc::m_handlersTypeNames
private

Definition at line 156 of file GslSvc.h.

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

codes to be ignored

Definition at line 161 of file GslSvc.h.


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