| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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/MsgStream.h"
4 #include "GaudiKernel/System.h"
5 #include "GaudiKernel/ISvcLocator.h"
6 #include "GaudiKernel/IToolSvc.h"
7 // STD & STL
8 #include <algorithm>
9 #include <functional>
10 // GaudiGSL
11 #include "GaudiGSL/IGslErrorHandler.h"
12 #include "GaudiGSL/GslError.h"
13 // local
14 #include "GaudiGSL/GaudiGSL.h"
15 #include "GslSvc.h"
16 #include "GaudiGSL/GslErrorHandlers.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()
43 << " Error in initialization of base class 'Service'"<< endmsg;
44 return sc;
45 }
46 // activate the static accessor to the service
47 GaudiGSL::setGslSvc( this );
48 // set the error handlers
49 if ( "GSL" == m_errorPolicy ) { /* nothing to do */ }
50 else if ( "Off" == m_errorPolicy )
51 { gsl_set_error_handler_off() ; }
52 else if ( "Abort" == m_errorPolicy )
53 { gsl_set_error_handler ( nullptr ) ; }
54 else if ( "Ignore" == m_errorPolicy )
55 { gsl_set_error_handler ( GslErrorHandlers::ignoreTheError ) ; }
56 else if ( "Exception" == m_errorPolicy )
57 { gsl_set_error_handler ( GslErrorHandlers::throwException ) ; }
58 else if ( "Handle" == m_errorPolicy )
59 { gsl_set_error_handler ( GslErrorHandlers::handleTheError ) ; }
60 else
61 { error()
62 << " Unknown Error policy '" << m_errorPolicy << "'"
63 << " Valid policies: "
64 << "[ 'GSL' , 'Off' , 'Abort' , 'Ignore' , 'Exception' , 'Handle' ]"
65 << endmsg;
66 return StatusCode::FAILURE ;
67 }
70 GslErrorHandler handler = gsl_set_error_handler( nullptr );
71 gsl_set_error_handler( handler );
72 if( handler )
73 { verbose()
74 << " GSL Error Handler is '"
75 << System::typeinfoName( typeid(*handler) ) << "'"
76 << endmsg; }
77 else { info() << " Error Handler is NULL" << endmsg ; }
78
79 if( !m_handlersTypeNames.empty() )
80 {
82 auto toolsvc = serviceLocator()->service<IToolSvc>("ToolSvc");
83 if (!toolsvc) {
84 error() << " Could not locate Tool Service! " << endmsg;
85 return StatusCode::FAILURE;
86 }
87 for( const auto& it : m_handlersTypeNames )
88 {
89 auto pos = it.find('/');
90 IGslErrorHandler* eh = nullptr ;
91 if( pos != std::string::npos ) {
92 sc = toolsvc->retrieveTool
93 ( it.substr( 0 , pos ), it.substr( pos + 1 ), eh , this ) ;
94 } else {
95 sc = toolsvc->retrieveTool( it , it , eh , this ) ;
96 }
97 if( sc.isFailure() )
98 { error()
99 << " Could not retrieve tool '" << it << "'"<< endmsg ;
100 return sc ; }
101 if( !eh )
102 { error()
103 << " Could not retrieve tool '" << it << "'"<< endmsg ;
104 return StatusCode::FAILURE ; }
105 m_handlers.push_back( eh );
106 }
107 }
108 //
109 return StatusCode::SUCCESS;
110 }
111 // ============================================================================
112
113 // ============================================================================
119 // ============================================================================
120 StatusCode GslSvc::finalize()
121 {
122 debug() << "==> Finalize" << endmsg;
123
124 // deactivate the static accessor to the service
125 GaudiGSL::setGslSvc( nullptr );
126
127 // finalize the base class
128 return Service::finalize() ;
129 }
130 // ============================================================================
131
132 // ============================================================================
136 // ============================================================================
137 IGslSvc::GslErrorHandler GslSvc::handler () const
138 {
139 GslErrorHandler hh = gsl_set_error_handler( nullptr );
140 gsl_set_error_handler( hh );
141 return hh ;
142 }
143 // ============================================================================
144
145 // ============================================================================
150 // ============================================================================
151 IGslSvc::GslErrorHandler GslSvc::setHandler
152 ( IGslSvc::GslErrorHandler handler ) const
153 {
154 gsl_set_error_handler( handler );
155 {
156 debug() << " New GSL handler is set '"
157 << ( handler ? System::typeinfoName( typeid(handler) ) : "NULL" )
158 << "'" << endmsg ;
159 }
160 return handler ;
161 }
162 // ============================================================================
163
164 // ============================================================================
169 // ============================================================================
170 StatusCode GslSvc::status ( const int error ) const
171 {
172 if( GSL_SUCCESS == error ){ return StatusCode::SUCCESS ; }
173 StatusCode sc( error );
174 if( sc.isSuccess() ){ return StatusCode::FAILURE ; }
175 return sc ;
176 }
177 // ============================================================================
178
179 // ============================================================================
184 // ============================================================================
185 StatusCode GslSvc::handle
186 ( const GslError& error ) const
187 {
188 StatusCode sc = StatusCode::SUCCESS ;
189 // code to be ignored?
190 if( m_ignore.end() != std::find( m_ignore.begin () ,
191 m_ignore.end () ,
192 error.code ) ) { return sc ; }
193 // invoke all handlers
194 for( auto handler = m_handlers.begin() ;
195 sc.isSuccess() && m_handlers.end() != handler ; ++handler )
196 { sc = (*handler)->handle( error ); }
197 //
198 return sc ;
199 }
200 // ============================================================================
201
202 // ============================================================================
203 // The END
204 // ============================================================================
IGslErrorHandler
The abstract interface for arbitrary GSL error handler.
Definition: IGslErrorHandler.h:15
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:31
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:30
GslError
Helper class to represent GSL errors.
Definition: GslError.h:15
StatusCode::FAILURE
Definition: StatusCode.h:29
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:299
GslError::code
int code
error code (GSL)
Definition: GslError.h:25
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
IGslErrorHandler.h
IGslSvc::GslErrorHandler
void(* GslErrorHandler)(const char *, const char *, int, int)
type definition of "standard" GSL error handler functions
Definition: IGslSvc.h:28
GslSvc::m_ignore
Gaudi::Property< std::vector< int > > m_ignore
Definition: GslSvc.h:145
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:43
IToolSvc.h
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
GslSvc::finalize
StatusCode finalize() override
standard service finalization
Definition: GslSvc.cpp:120
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
GslSvc::setHandler
GslErrorHandler setHandler(GslErrorHandler handler) const override
set new GSL error handler
Definition: GslSvc.cpp:152
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
GslError.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GslSvc::m_handlers
Handlers m_handlers
Definition: GslSvc.h:148
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:186
std::find
T find(T...args)
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:126
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:137
GaudiGSL::setGslSvc
static const IGslSvc * setGslSvc(const IGslSvc *value)
set new value for static Gaudi GSL Service
Definition: GaudiGSL.cpp:35
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:24
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
GslErrorHandlers.h
GaudiGSL.h
GslSvc::status
StatusCode status(const int error) const override
transform GSL error code to Gaudi status code
Definition: GslSvc.cpp:170