Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GslSvc.cpp
Go to the documentation of this file.
1 // $Id: GslSvc.cpp,v 1.2 2006/01/10 20:00:05 hmd Exp $
2 // Include files
3 // from Gaudi
6 #include "GaudiKernel/System.h"
8 #include "GaudiKernel/IToolSvc.h"
9 // STD & STL
10 #include <algorithm>
11 #include <functional>
12 // GaudiGSL
14 #include "GaudiGSL/GslError.h"
15 // local
16 #include "GaudiGSL/GaudiGSL.h"
17 #include "GslSvc.h"
19 // gsl
20 #include "gsl/gsl_errno.h"
21 
22 // ============================================================================
30 // ============================================================================
31 
32 // ============================================================================
38 // ============================================================================
40 // ============================================================================
41 
42 // ============================================================================
47 // ============================================================================
48 GslSvc::GslSvc( const std::string& name ,
49  ISvcLocator* svc )
50  : base_class ( name , svc )
51  , m_errorPolicy ( "GSL" )
52  , m_handlersTypeNames ()
53  , m_handlers ()
54  , m_ignore ()
55 {
56  declareProperty( "ErrorPolicy" , m_errorPolicy ) ;
57  declareProperty( "Handlers" , m_handlersTypeNames ) ;
58  declareProperty( "IgnoreCodes" , m_ignore ) ;
59 }
60 // ============================================================================
61 
62 // ============================================================================
64 // ============================================================================
66 // ============================================================================
67 
68 // ============================================================================
74 // ============================================================================
76 {
77  // initialize the base class
79  MsgStream log( msgSvc() , name() );
80  if( sc.isFailure() )
81  { log << MSG::ERROR
82  << " Error in initialization of base class 'Service'"<< endmsg;
83  return sc;
84  }
85  // activate the static accessor to the service
86  GaudiGSL::setGslSvc( this );
87  // set the error handlers
88  if ( "GSL" == m_errorPolicy ) { /* nothing to do */ }
89  else if ( "Off" == m_errorPolicy )
90  { gsl_set_error_handler_off() ; }
91  else if ( "Abort" == m_errorPolicy )
92  { gsl_set_error_handler ( 0 ) ; }
93  else if ( "Ignore" == m_errorPolicy )
94  { gsl_set_error_handler ( GslErrorHandlers::ignoreTheError ) ; }
95  else if ( "Exception" == m_errorPolicy )
96  { gsl_set_error_handler ( GslErrorHandlers::throwException ) ; }
97  else if ( "Handle" == m_errorPolicy )
98  { gsl_set_error_handler ( GslErrorHandlers::handleTheError ) ; }
99  else
100  { log << MSG::ERROR
101  << " Unknown Error policy '" << m_errorPolicy << "'"
102  << " Valid policies: "
103  << "[ 'GSL' , 'Off' , 'Abort' , 'Ignore' , 'Exception' , 'Handle' ]"
104  << endmsg;
105  return StatusCode::FAILURE ;
106  }
109  GslErrorHandler handler = gsl_set_error_handler( 0 );
110  gsl_set_error_handler( handler );
111  if( 0 != handler )
112  { log << MSG::VERBOSE
113  << " GSL Error Handler is '"
114  << System::typeinfoName( typeid(*handler) ) << "'"
115  << endmsg; }
116  else { log << MSG::INFO << " Error Handler is NULL" << endmsg ; }
117 
118  if( !m_handlersTypeNames.empty() )
119  {
121  SmartIF<IToolSvc> toolsvc(serviceLocator()->service("ToolSvc"));
122  if (!toolsvc.isValid()) {
123  log << MSG::ERROR << " Could not locate Tool Service! " << endmsg;
124  return StatusCode::FAILURE;
125  }
127  m_handlersTypeNames.end() != it ; ++it )
128  {
130  std::find( it->begin() , it->end() , '/');
131  const std::string::size_type pos = ipos - it->begin() ;
132  IGslErrorHandler* eh = 0 ;
133  if( it->end() != ipos )
134  { sc = toolsvc->retrieveTool
135  ( std::string( *it , 0 , pos ) ,
136  std::string( *it , pos + 1, it->length() ), eh , this ) ; }
137  else
138  { sc = toolsvc->retrieveTool
139  ( *it , std::string( *it , pos + 1, it->length() ) ,
140  eh , this ) ; }
141  if( sc.isFailure() )
142  { log << MSG::ERROR
143  << " Could not retrieve tool '" << *it << "'"<< endmsg ;
144  return sc ; }
145  if( 0 == eh )
146  { log << MSG::ERROR
147  << " Could not retrieve tool '" << *it << "'"<< endmsg ;
148  return StatusCode::FAILURE ; }
149  m_handlers.push_back( eh );
150  }
151  }
152  //
153  return StatusCode::SUCCESS;
154 }
155 // ============================================================================
156 
157 // ============================================================================
163 // ============================================================================
165 {
166  MsgStream log(msgSvc(), name());
167  log << MSG::DEBUG << "==> Finalize" << endmsg;
168 
169  // deactivate the static accessor to the service
170  GaudiGSL::setGslSvc( 0 );
171 
172  // finalize the base class
173  return Service::finalize() ;
174 }
175 // ============================================================================
176 
177 // ============================================================================
181 // ============================================================================
183 {
184  GslErrorHandler hh = gsl_set_error_handler( 0 );
185  gsl_set_error_handler( hh );
186  return hh ;
187 }
188 // ============================================================================
189 
190 // ============================================================================
195 // ============================================================================
197 ( IGslSvc::GslErrorHandler handler ) const
198 {
199  gsl_set_error_handler( handler );
200  {
201  MsgStream log( msgSvc(), name() );
202  log << MSG::DEBUG << " New GSL handler is set '" ;
203  if( 0 == handler ) { log << "NULL" ; }
204  else { log << System::typeinfoName( typeid(handler) ) ; }
205  log << "'" << endmsg ;
206  }
207  return handler ;
208 }
209 // ============================================================================
210 
211 // ============================================================================
216 // ============================================================================
217 StatusCode GslSvc::status ( const int error ) const
218 {
219  if( GSL_SUCCESS == error ){ return StatusCode::SUCCESS ; }
220  StatusCode sc( error );
221  if( sc.isSuccess() ){ return StatusCode::FAILURE ; }
222  return sc ;
223 }
224 // ============================================================================
225 
226 // ============================================================================
231 // ============================================================================
233 ( const GslError& error ) const
234 {
236  // code to be ignored?
237  if( m_ignore.end() != std::find( m_ignore.begin () ,
238  m_ignore.end () ,
239  error.code ) ) { return sc ; }
240  // invoke all handlers
241  for( Handlers::const_iterator handler = m_handlers.begin() ;
242  sc.isSuccess() && m_handlers.end() != handler ; ++handler )
243  { sc = (*handler)->handle( error ); }
244  //
245  return sc ;
246 }
247 // ============================================================================
248 
249 // ============================================================================
250 // The END
251 // ============================================================================
252 
253 
254 

Generated at Wed Dec 4 2013 14:33:08 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004