Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GslSvc.cpp
Go to the documentation of this file.
1 // Include files
2 // from Gaudi
4 #include "GaudiKernel/System.h"
6 #include "GaudiKernel/IToolSvc.h"
7 // STD & STL
8 #include <algorithm>
9 #include <functional>
10 // GaudiGSL
12 #include "GaudiGSL/GslError.h"
13 // local
14 #include "GaudiGSL/GaudiGSL.h"
15 #include "GslSvc.h"
17 // gsl
18 #include "gsl/gsl_errno.h"
19 
20 // ============================================================================
28 // ============================================================================
30 // ============================================================================
31 
32 // ============================================================================
37 // ============================================================================
38 GslSvc::GslSvc( const std::string& name ,
39  ISvcLocator* svc )
40  : base_class ( name , svc )
41  , m_errorPolicy ( "GSL" )
42  , m_handlersTypeNames ()
43  , m_handlers ()
44  , m_ignore ()
45 {
46  declareProperty( "ErrorPolicy" , m_errorPolicy ) ;
47  declareProperty( "Handlers" , m_handlersTypeNames ) ;
48  declareProperty( "IgnoreCodes" , m_ignore ) ;
49 }
50 // ============================================================================
51 
52 // ============================================================================
54 // ============================================================================
56 // ============================================================================
57 
58 // ============================================================================
64 // ============================================================================
66 {
67  // initialize the base class
69  MsgStream log( msgSvc() , name() );
70  if( sc.isFailure() )
71  { log << MSG::ERROR
72  << " Error in initialization of base class 'Service'"<< endmsg;
73  return sc;
74  }
75  // activate the static accessor to the service
76  GaudiGSL::setGslSvc( this );
77  // set the error handlers
78  if ( "GSL" == m_errorPolicy ) { /* nothing to do */ }
79  else if ( "Off" == m_errorPolicy )
80  { gsl_set_error_handler_off() ; }
81  else if ( "Abort" == m_errorPolicy )
82  { gsl_set_error_handler ( 0 ) ; }
83  else if ( "Ignore" == m_errorPolicy )
84  { gsl_set_error_handler ( GslErrorHandlers::ignoreTheError ) ; }
85  else if ( "Exception" == m_errorPolicy )
86  { gsl_set_error_handler ( GslErrorHandlers::throwException ) ; }
87  else if ( "Handle" == m_errorPolicy )
88  { gsl_set_error_handler ( GslErrorHandlers::handleTheError ) ; }
89  else
90  { log << MSG::ERROR
91  << " Unknown Error policy '" << m_errorPolicy << "'"
92  << " Valid policies: "
93  << "[ 'GSL' , 'Off' , 'Abort' , 'Ignore' , 'Exception' , 'Handle' ]"
94  << endmsg;
95  return StatusCode::FAILURE ;
96  }
99  GslErrorHandler handler = gsl_set_error_handler( 0 );
100  gsl_set_error_handler( handler );
101  if( 0 != handler )
102  { log << MSG::VERBOSE
103  << " GSL Error Handler is '"
104  << System::typeinfoName( typeid(*handler) ) << "'"
105  << endmsg; }
106  else { log << MSG::INFO << " Error Handler is NULL" << endmsg ; }
107 
108  if( !m_handlersTypeNames.empty() )
109  {
111  SmartIF<IToolSvc> toolsvc(serviceLocator()->service("ToolSvc"));
112  if (!toolsvc.isValid()) {
113  log << MSG::ERROR << " Could not locate Tool Service! " << endmsg;
114  return StatusCode::FAILURE;
115  }
117  m_handlersTypeNames.end() != it ; ++it )
118  {
120  std::find( it->begin() , it->end() , '/');
121  const std::string::size_type pos = ipos - it->begin() ;
122  IGslErrorHandler* eh = 0 ;
123  if( it->end() != ipos )
124  { sc = toolsvc->retrieveTool
125  ( std::string( *it , 0 , pos ) ,
126  std::string( *it , pos + 1, it->length() ), eh , this ) ; }
127  else
128  { sc = toolsvc->retrieveTool
129  ( *it , std::string( *it , pos + 1, it->length() ) ,
130  eh , this ) ; }
131  if( sc.isFailure() )
132  { log << MSG::ERROR
133  << " Could not retrieve tool '" << *it << "'"<< endmsg ;
134  return sc ; }
135  if( 0 == eh )
136  { log << MSG::ERROR
137  << " Could not retrieve tool '" << *it << "'"<< endmsg ;
138  return StatusCode::FAILURE ; }
139  m_handlers.push_back( eh );
140  }
141  }
142  //
143  return StatusCode::SUCCESS;
144 }
145 // ============================================================================
146 
147 // ============================================================================
153 // ============================================================================
155 {
156  MsgStream log(msgSvc(), name());
157  log << MSG::DEBUG << "==> Finalize" << endmsg;
158 
159  // deactivate the static accessor to the service
160  GaudiGSL::setGslSvc( 0 );
161 
162  // finalize the base class
163  return Service::finalize() ;
164 }
165 // ============================================================================
166 
167 // ============================================================================
171 // ============================================================================
173 {
174  GslErrorHandler hh = gsl_set_error_handler( 0 );
175  gsl_set_error_handler( hh );
176  return hh ;
177 }
178 // ============================================================================
179 
180 // ============================================================================
185 // ============================================================================
187 ( IGslSvc::GslErrorHandler handler ) const
188 {
189  gsl_set_error_handler( handler );
190  {
191  MsgStream log( msgSvc(), name() );
192  log << MSG::DEBUG << " New GSL handler is set '" ;
193  if( 0 == handler ) { log << "NULL" ; }
194  else { log << System::typeinfoName( typeid(handler) ) ; }
195  log << "'" << endmsg ;
196  }
197  return handler ;
198 }
199 // ============================================================================
200 
201 // ============================================================================
206 // ============================================================================
207 StatusCode GslSvc::status ( const int error ) const
208 {
209  if( GSL_SUCCESS == error ){ return StatusCode::SUCCESS ; }
210  StatusCode sc( error );
211  if( sc.isSuccess() ){ return StatusCode::FAILURE ; }
212  return sc ;
213 }
214 // ============================================================================
215 
216 // ============================================================================
221 // ============================================================================
223 ( const GslError& error ) const
224 {
226  // code to be ignored?
227  if( m_ignore.end() != std::find( m_ignore.begin () ,
228  m_ignore.end () ,
229  error.code ) ) { return sc ; }
230  // invoke all handlers
231  for( Handlers::const_iterator handler = m_handlers.begin() ;
232  sc.isSuccess() && m_handlers.end() != handler ; ++handler )
233  { sc = (*handler)->handle( error ); }
234  //
235  return sc ;
236 }
237 // ============================================================================
238 
239 // ============================================================================
240 // The END
241 // ============================================================================
242 
243 
244 

Generated at Mon Feb 17 2014 14:37:41 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004