| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

GslSvc.cpp
Go to the documentation of this file.
1 // Include files
2 // from Gaudi
3 #include "GaudiKernel/ISvcLocator.h"
4 #include "GaudiKernel/IToolSvc.h"
5 #include "GaudiKernel/MsgStream.h"
6 #include "GaudiKernel/System.h"
7 // STD & STL
8 #include <algorithm>
9 #include <functional>
10 // GaudiGSL
11 #include "GaudiGSL/GslError.h"
12 #include "GaudiGSL/IGslErrorHandler.h"
13 // local
14 #include "GaudiGSL/GaudiGSL.h"
15 #include "GaudiGSL/GslErrorHandlers.h"
16 #include "GslSvc.h"
17 // gsl
18 #include "gsl/gsl_errno.h"
19
20 // ============================================================================
28 // ============================================================================
29 DECLARE_COMPONENT( GslSvc )
30 // ============================================================================
36 // ============================================================================
37 StatusCode GslSvc::initialize()
38 {
39 // initialize the base class
40 StatusCode sc = Service::initialize();
41 if ( sc.isFailure() ) {
42 error() << " Error in initialization of base class 'Service'" << endmsg;
43 return sc;
44 }
45 // activate the static accessor to the service
46 GaudiGSL::setGslSvc( this );
47 // set the error handlers
48 if ( "GSL" == m_errorPolicy ) { /* nothing to do */
49 } else if ( "Off" == m_errorPolicy ) {
50 gsl_set_error_handler_off();
51 } else if ( "Abort" == m_errorPolicy ) {
52 gsl_set_error_handler( nullptr );
53 } else if ( "Ignore" == m_errorPolicy ) {
54 gsl_set_error_handler( GslErrorHandlers::ignoreTheError );
55 } else if ( "Exception" == m_errorPolicy ) {
56 gsl_set_error_handler( GslErrorHandlers::throwException );
57 } else if ( "Handle" == m_errorPolicy ) {
58 gsl_set_error_handler( GslErrorHandlers::handleTheError );
59 } else {
60 error() << " Unknown Error policy '" << m_errorPolicy << "'"
61 << " Valid policies: "
62 << "[ 'GSL' , 'Off' , 'Abort' , 'Ignore' , 'Exception' , 'Handle' ]" << endmsg;
63 return StatusCode::FAILURE;
64 }
67 GslErrorHandler handler = gsl_set_error_handler( nullptr );
68 gsl_set_error_handler( handler );
69 if ( handler ) {
70 verbose() << " GSL Error Handler is '" << System::typeinfoName( typeid( *handler ) ) << "'" << endmsg;
71 } else {
72 info() << " Error Handler is NULL" << endmsg;
73 }
74
75 if ( !m_handlersTypeNames.empty() ) {
77 auto toolsvc = serviceLocator()->service<IToolSvc>( "ToolSvc" );
78 if ( !toolsvc ) {
79 error() << " Could not locate Tool Service! " << endmsg;
80 return StatusCode::FAILURE;
81 }
82 for ( const auto& it : m_handlersTypeNames ) {
83 auto pos = it.find( '/' );
84 IGslErrorHandler* eh = nullptr;
85 if ( pos != std::string::npos ) {
86 sc = toolsvc->retrieveTool( it.substr( 0, pos ), it.substr( pos + 1 ), eh, this );
87 } else {
88 sc = toolsvc->retrieveTool( it, it, eh, this );
89 }
90 if ( sc.isFailure() ) {
91 error() << " Could not retrieve tool '" << it << "'" << endmsg;
92 return sc;
93 }
94 if ( !eh ) {
95 error() << " Could not retrieve tool '" << it << "'" << endmsg;
96 return StatusCode::FAILURE;
97 }
98 m_handlers.push_back( eh );
99 }
100 }
101 //
102 return StatusCode::SUCCESS;
103 }
104 // ============================================================================
105
106 // ============================================================================
112 // ============================================================================
113 StatusCode GslSvc::finalize()
114 {
115 debug() << "==> Finalize" << endmsg;
116
117 // deactivate the static accessor to the service
118 GaudiGSL::setGslSvc( nullptr );
119
120 // finalize the base class
121 return Service::finalize();
122 }
123 // ============================================================================
124
125 // ============================================================================
129 // ============================================================================
130 IGslSvc::GslErrorHandler GslSvc::handler() const
131 {
132 GslErrorHandler hh = gsl_set_error_handler( nullptr );
133 gsl_set_error_handler( hh );
134 return hh;
135 }
136 // ============================================================================
137
138 // ============================================================================
143 // ============================================================================
144 IGslSvc::GslErrorHandler GslSvc::setHandler( IGslSvc::GslErrorHandler handler ) const
145 {
146 gsl_set_error_handler( handler );
147 {
148 debug() << " New GSL handler is set '" << ( handler ? System::typeinfoName( typeid( handler ) ) : "NULL" ) << "'"
149 << endmsg;
150 }
151 return handler;
152 }
153 // ============================================================================
154
155 // ============================================================================
160 // ============================================================================
161 StatusCode GslSvc::status( const int error ) const
162 {
163 if ( GSL_SUCCESS == error ) {
164 return StatusCode::SUCCESS;
165 }
166 StatusCode sc( error );
167 if ( sc.isSuccess() ) {
168 return StatusCode::FAILURE;
169 }
170 return sc;
171 }
172 // ============================================================================
173
174 // ============================================================================
179 // ============================================================================
180 StatusCode GslSvc::handle( const GslError& error ) const
181 {
182 StatusCode sc = StatusCode::SUCCESS;
183 // code to be ignored?
184 if ( m_ignore.end() != std::find( m_ignore.begin(), m_ignore.end(), error.code ) ) {
185 return sc;
186 }
187 // invoke all handlers
188 for ( auto handler = m_handlers.begin(); sc.isSuccess() && m_handlers.end() != handler; ++handler ) {
189 sc = ( *handler )->handle( error );
190 }
191 //
192 return sc;
193 }
194 // ============================================================================
195
196 // ============================================================================
197 // The END
198 // ============================================================================
GslErrorHandlers::handleTheError
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.
Definition: GslErrorHandlers.cpp:28
System.h
IToolSvc
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:19
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
StatusCode::SUCCESS
Definition: StatusCode.h:31
GslError
Helper class to represent GSL errors.
Definition: GslError.h:16
StatusCode::FAILURE
Definition: StatusCode.h:31
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:174
MsgStream.h
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:329
GslError::code
int code
error code (GSL)
Definition: GslError.h:26
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
GaudiGSL::setGslSvc
static const IGslSvc * setGslSvc(const IGslSvc *value)
set new value for static Gaudi GSL Service
Definition: GaudiGSL.cpp:38
IGslErrorHandler.h
IGslErrorHandler
The abstract interface for arbitrary GSL error handler.
Definition: IGslErrorHandler.h:15
GslSvc::m_ignore
Gaudi::Property< std::vector< int > > m_ignore
Definition: GslSvc.h:138
std::vector::end
T end(T...args)
GslErrorHandlers::throwException
GAUDI_API void throwException(const char *reason, const char *file, int line, int code)
The simple Gsl Error handler, it throwns the Gaudi Exception.
Definition: GslErrorHandlers.cpp:38
IToolSvc.h
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
GslSvc::finalize
StatusCode finalize() override
standard service finalization
Definition: GslSvc.cpp:113
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
GslSvc::setHandler
GslErrorHandler setHandler(GslErrorHandler handler) const override
set new GSL error handler
Definition: GslSvc.cpp:144
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
GslError.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
IGslSvc::GslErrorHandler
void(* GslErrorHandler)(const char *, const char *, int, int)
type definition of "standard" GSL error handler functions
Definition: IGslSvc.h:26
GslSvc
The implementation of IGslSvc interface.
Definition: GslSvc.h:83
GslSvc::handle
StatusCode handle(const GslError &error) const override
handle the GSL error
Definition: GslSvc.cpp:180
std::find
T find(T...args)
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:115
std::vector::begin
T begin(T...args)
genconfuser.verbose
verbose
Definition: genconfuser.py:19
GslSvc.h
GslSvc::handler
GslErrorHandler handler() const override
retrieve the current GSL error handler
Definition: GslSvc.cpp:130
GslSvc::m_handlers
std::vector< IGslErrorHandler * > m_handlers
Definition: GslSvc.h:140
GslErrorHandlers::ignoreTheError
GAUDI_API void ignoreTheError(const char *reason, const char *file, int line, int code)
The simplest Gsl Error handler, It simply ingnores the error.
Definition: GslErrorHandlers.cpp:23
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
GslErrorHandlers.h
GaudiGSL.h
GslSvc::status
StatusCode status(const int error) const override
transform GSL error code to Gaudi status code
Definition: GslSvc.cpp:161