Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Guards.h
Go to the documentation of this file.
1 // $Id: Guards.h,v 1.2 2008/04/03 14:40:19 marcocle Exp $
2 // ============================================================================
3 #ifndef GAUDIKERNEL_GUARDS_H
4 #define GAUDIKERNEL_GUARDS_H 1
5 // ============================================================================
6 // Include files
7 // ============================================================================
8 // STD & STL
9 // ============================================================================
10 #include <exception>
11 // ============================================================================
12 // GaudiKernel
13 // ============================================================================
16 #include "GaudiKernel/IAuditor.h"
17 // ============================================================================
18 // forward declaration
19 // ============================================================================
20 class GaudiException ;
21 // ============================================================================
22 namespace Gaudi
23 {
74  namespace Guards
75  {
109  {
110  public:
111  /* constructor form the object/scope, function and log-stream
112  * @param obj the object/scope
113  * @param fun function to be used
114  * @param log output log-stream
115  */
116  template <class OBJECT, class FUNCTION>
118  ( OBJECT obj ,
119  FUNCTION fun ,
120  MsgStream& log ,
121  IExceptionSvc* svc = 0 )
122  : m_sc ( StatusCode::FAILURE )
123  {
124  try
125  {
126  // execute the functor:
127  m_sc = fun ( obj ) ;
128  // in the case of error try use Exception Service
129  if ( 0 != svc && m_sc.isFailure() ) { m_sc = svc->handleErr ( *obj , m_sc ) ; }
130  }
131  catch ( const GaudiException& e )
132  {
133  // Use the local handler and then (if possible) the Exception Service
134  handle ( e , log ) ;
135  if ( 0 != svc ) { m_sc = svc -> handle ( *obj , e ) ; }
136  }
137  catch ( const std::exception& e )
138  {
139  // Use the local handler and then (if possible) the Exception Service
140  handle ( e , log ) ;
141  if ( 0 != svc ) { m_sc = svc -> handle ( *obj , e ) ; }
142  }
143  catch ( ... )
144  {
145  // Use the local handler and then (if possible) the Exception Service
146  handle ( log ) ;
147  if ( 0 != svc ) { m_sc = svc -> handle ( *obj ) ; }
148  }
149  }
151  ~ExceptionGuard() ;
152  public:
154  const StatusCode& code () const { return m_sc ; }
156  operator const StatusCode&() const { return code() ; }
157  private:
158  // default constructor is disabled
159  ExceptionGuard() ;
160  // copy constructor is disabled
161  ExceptionGuard ( const ExceptionGuard& ) ;
162  // assignment operator is disabled
163  ExceptionGuard& operator=( const ExceptionGuard& ) ;
164  protected:
166  void handle ( const GaudiException& e , MsgStream& s ) ;
168  void handle ( const std::exception& e , MsgStream& s ) ;
170  void handle ( MsgStream& s ) ;
171  private:
172  // status code: result of the function evaluation
174  } ;
175  // ========================================================================
219  {
220  public:
223  IAuditor* svc ,
227  IAuditor* svc ,
229 
232  IAuditor* svc ,
234  const StatusCode &sc ) ;
237  IAuditor* svc ,
239  const StatusCode &sc ) ;
241  AuditorGuard ( const std::string &name ,
242  IAuditor* svc ,
245  AuditorGuard ( const std::string &name ,
246  IAuditor* svc ,
248 
250  AuditorGuard ( const std::string &name ,
251  IAuditor* svc ,
253  const StatusCode &sc ) ;
255  AuditorGuard ( const std::string &name ,
256  IAuditor* svc ,
258  const StatusCode &sc ) ;
259 
261  ~AuditorGuard() ;
262  public:
263  // get the status code
264  const StatusCode &code () const { return *m_sc ; }
265  private:
266  // the default constructor is disabled
267  AuditorGuard () ;
268  // the copy constructor is disabled
269  AuditorGuard ( const AuditorGuard& right ) ;
270  // assignement operator is disabled
271  AuditorGuard& operator=( const AuditorGuard& right ) ;
272  private :
286  const StatusCode *m_sc ;
289 
290  inline void i_before() {
291  if ( 0 != m_svc ) { // if the service is not available, we cannot do anything
292  m_svc->addRef(); // increase the reference counting
293  if (0 != m_obj) {
294  if (m_customEvtType) {
295  m_svc->before(m_cevt,m_obj);
296  } else {
297  m_svc->before(m_evt,m_obj);
298  }
299  } else { // use object name
300  if (m_customEvtType) {
301  m_svc->before(m_cevt,m_objName);
302  } else {
303  m_svc->before(m_evt,m_objName);
304  }
305  }
306  }
307  }
308 
309  inline void i_after() {
310  if ( 0 != m_svc ) { // if the service is not available, we cannot do anything
311  if (0 != m_obj) {
312  if (m_customEvtType) {
313  if (0 != m_sc) {
314  m_svc->after(m_cevt,m_obj,*m_sc);
315  } else {
316  m_svc->after(m_cevt,m_obj);
317  }
318  } else {
319  if (0 != m_sc) {
320  m_svc->after(m_evt,m_obj,*m_sc);
321  } else {
322  m_svc->after(m_evt,m_obj);
323  }
324  }
325  } else { // use object name
326  if (m_customEvtType) {
327  if (0 != m_sc) {
328  m_svc->after(m_cevt,m_objName,*m_sc);
329  } else {
330  m_svc->after(m_cevt,m_objName);
331  }
332  } else {
333  if (0 != m_sc) {
334  m_svc->after(m_evt,m_objName,*m_sc);
335  } else {
336  m_svc->after(m_evt,m_objName);
337  }
338  }
339  }
340  m_svc->release(); // we do not need the service anymore
341  m_svc = 0 ;
342  }
343  }
344  } ;
345  } // end of namespace Gaudi::Guards
346 } //end of namespace Gaudi
347 
348 
349 // ============================================================================
350 // The END
351 // ============================================================================
352 #endif // GAUDIKERNEL_GUARDS_H
353 // ============================================================================

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