| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

Guards.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_GUARDS_H
2 #define GAUDIKERNEL_GUARDS_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <exception>
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/IAuditor.h"
13 #include "GaudiKernel/IExceptionSvc.h"
14 #include "GaudiKernel/INamedInterface.h"
15 #include "GaudiKernel/SmartIF.h"
16 // ============================================================================
17 // forward declaration
18 // ============================================================================
19 class GaudiException;
20 // ============================================================================
21 namespace Gaudi
22 {
73 namespace Guards
74 {
107 class GAUDI_API ExceptionGuard
108 {
109 public:
110 /* constructor form the object/scope, function and log-stream
111 * @param obj the object/scope
112 * @param fun function to be used
113 * @param log output log-stream
114 */
115 template <class OBJECT, class FUNCTION>
116 ExceptionGuard( OBJECT obj, FUNCTION fun, MsgStream& log, IExceptionSvc* svc = 0 )
117 {
118 try {
119 // execute the functor:
120 m_sc = fun( obj );
121 // in the case of error try use Exception Service
122 if ( svc && m_sc.isFailure() ) {
123 m_sc = svc->handleErr( *obj, m_sc );
124 }
125 } catch ( const GaudiException& e ) {
126 // Use the local handler and then (if possible) the Exception Service
127 handle( e, log );
128 if ( svc ) {
129 m_sc = svc->handle( *obj, e );
130 }
131 } catch ( const std::exception& e ) {
132 // Use the local handler and then (if possible) the Exception Service
133 handle( e, log );
134 if ( svc ) {
135 m_sc = svc->handle( *obj, e );
136 }
137 } catch ( ... ) {
138 // Use the local handler and then (if possible) the Exception Service
139 handle( log );
140 if ( svc ) {
141 m_sc = svc->handle( *obj );
142 }
143 }
144 }
146 ~ExceptionGuard();
147
148 public:
150 const StatusCode& code() const { return m_sc; }
152 operator const StatusCode&() const { return code(); }
153
154 private:
155 // delete default/copy constructor and assignment
156 ExceptionGuard() = delete;
157 ExceptionGuard( const ExceptionGuard& ) = delete;
158 ExceptionGuard& operator=( const ExceptionGuard& ) = delete;
159
160 protected:
162 void handle( const GaudiException& e, MsgStream& s );
164 void handle( const std::exception& e, MsgStream& s );
166 void handle( MsgStream& s );
167
168 private:
169 // status code: result of the function evaluation
170 StatusCode m_sc = StatusCode::FAILURE;
171 };
172 // ========================================================================
215 class GAUDI_API AuditorGuard final
216 {
217 public:
219 AuditorGuard( INamedInterface* obj, IAuditor* svc, IAuditor::StandardEventType evt );
221 AuditorGuard( INamedInterface* obj, IAuditor* svc, IAuditor::CustomEventTypeRef evt );
222
224 AuditorGuard( INamedInterface* obj, IAuditor* svc, IAuditor::StandardEventType evt, const StatusCode& sc );
226 AuditorGuard( INamedInterface* obj, IAuditor* svc, IAuditor::CustomEventTypeRef evt, const StatusCode& sc );
228 AuditorGuard( std::string name, IAuditor* svc, IAuditor::StandardEventType evt );
230 AuditorGuard( std::string name, IAuditor* svc, IAuditor::CustomEventTypeRef evt );
231
233 AuditorGuard( std::string name, IAuditor* svc, IAuditor::StandardEventType evt, const StatusCode& sc );
235 AuditorGuard( std::string name, IAuditor* svc, IAuditor::CustomEventTypeRef evt, const StatusCode& sc );
236
238 ~AuditorGuard();
239
240 public:
241 // get the status code
242 const StatusCode& code() const { return *m_sc; }
243
244 private:
245 // delete the default/copy constructor and assigment
246 AuditorGuard() = delete;
247 AuditorGuard( const AuditorGuard& right ) = delete;
248 AuditorGuard& operator=( const AuditorGuard& right ) = delete;
249
250 private:
252 INamedInterface* m_obj = nullptr;
254 std::string m_objName;
256 SmartIF<IAuditor> m_svc = nullptr;
258 IAuditor::StandardEventType m_evt;
260 IAuditor::CustomEventType m_cevt;
264 const StatusCode* m_sc = nullptr;
266 bool m_customEvtType = false;
267
268 inline void i_before()
269 {
270 if ( m_svc ) { // if the service is not available, we cannot do anything
271 if ( m_obj ) {
272 if ( m_customEvtType ) {
273 m_svc->before( m_cevt, m_obj );
274 } else {
275 m_svc->before( m_evt, m_obj );
276 }
277 } else { // use object name
278 if ( m_customEvtType ) {
279 m_svc->before( m_cevt, m_objName );
280 } else {
281 m_svc->before( m_evt, m_objName );
282 }
283 }
284 }
285 }
286
287 inline void i_after()
288 {
289 if ( m_svc ) { // if the service is not available, we cannot do anything
290 if ( m_obj ) {
291 if ( m_customEvtType ) {
292 if ( m_sc ) {
293 m_svc->after( m_cevt, m_obj, *m_sc );
294 } else {
295 m_svc->after( m_cevt, m_obj );
296 }
297 } else {
298 if ( m_sc ) {
299 m_svc->after( m_evt, m_obj, *m_sc );
300 } else {
301 m_svc->after( m_evt, m_obj );
302 }
303 }
304 } else { // use object name
305 if ( m_customEvtType ) {
306 if ( m_sc ) {
307 m_svc->after( m_cevt, m_objName, *m_sc );
308 } else {
309 m_svc->after( m_cevt, m_objName );
310 }
311 } else {
312 if ( m_sc ) {
313 m_svc->after( m_evt, m_objName, *m_sc );
314 } else {
315 m_svc->after( m_evt, m_objName );
316 }
317 }
318 }
319 m_svc.reset();
320 }
321 }
322 };
323 } // end of namespace Gaudi::Guards
324 } // end of namespace Gaudi
325
326 // ============================================================================
327 // The END
328 // ============================================================================
329 #endif // GAUDIKERNEL_GUARDS_H
330 // ============================================================================
IAuditor::before
virtual void before(StandardEventType, INamedInterface *)=0
Audit the start of a standard "event".
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
SmartIF< IAuditor >
Gaudi::Guards::AuditorGuard::m_evt
IAuditor::StandardEventType m_evt
Event type (standard events)
Definition: Guards.h:258
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
Gaudi::Guards::AuditorGuard::i_after
void i_after()
Definition: Guards.h:287
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
Gaudi::Guards::ExceptionGuard::code
const StatusCode & code() const
the result of function evaluation
Definition: Guards.h:150
IAuditor::StandardEventType
StandardEventType
Defines the standard (= used by the framework) auditable event types.
Definition: IAuditor.h:25
Gaudi::Guards::AuditorGuard::m_cevt
IAuditor::CustomEventType m_cevt
Event type (custom events)
Definition: Guards.h:260
IAuditor.h
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
std::string
STL class.
INamedInterface.h
Gaudi::Guards::AuditorGuard::code
const StatusCode & code() const
Definition: Guards.h:242
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
SmartIF.h
std::exception
STL class.
Gaudi::Guards::AuditorGuard::m_objName
std::string m_objName
the guarded object name (if there is no INamedInterface)
Definition: Guards.h:254
Gaudi::Guards::ExceptionGuard
The most simple guard - it execute the certain code withing typical "try {} catch" clause...
Definition: Guards.h:107
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
Gaudi::Guards::ExceptionGuard::ExceptionGuard
ExceptionGuard(OBJECT obj, FUNCTION fun, MsgStream &log, IExceptionSvc *svc=0)
Definition: Guards.h:116
fun
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
IAuditor::after
virtual void after(StandardEventType, INamedInterface *, const StatusCode &sc=StatusCode(StatusCode::SUCCESS, true))=0
Audit the end of a standard "event".
gaudirun.s
string s
Definition: gaudirun.py:253
Gaudi::Guards::AuditorGuard::i_before
void i_before()
Definition: Guards.h:268
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
StatusCode::FAILURE
Definition: StatusCode.h:29
Gaudi::Guards::AuditorGuard
It is a simple guard, which "locks" the scope for the Auditor Service is am exception-safe way...
Definition: Guards.h:215
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
IAuditor
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
IExceptionSvc
The abstract interface for exception handling service.
Definition: IExceptionSvc.h:24
IOTest.evt
evt
Definition: IOTest.py:96
Gaudi.Configuration.log
log
Definition: Configuration.py:13
IExceptionSvc.h