| The Gaudi Framework v27r1

- 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/SmartIF.h"
13 #include "GaudiKernel/INamedInterface.h"
14 #include "GaudiKernel/IExceptionSvc.h"
15 #include "GaudiKernel/IAuditor.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
117 ( OBJECT obj ,
118 FUNCTION fun ,
119 MsgStream& log ,
120 IExceptionSvc* svc = 0 )
121 {
122 try
123 {
124 // execute the functor:
125 m_sc = fun ( obj ) ;
126 // in the case of error try use Exception Service
127 if ( svc && m_sc.isFailure() ) { m_sc = svc->handleErr ( *obj , m_sc ) ; }
128 }
129 catch ( const GaudiException& e )
130 {
131 // Use the local handler and then (if possible) the Exception Service
132 handle ( e , log ) ;
133 if ( svc ) { m_sc = svc -> handle ( *obj , e ) ; }
134 }
135 catch ( const std::exception& e )
136 {
137 // Use the local handler and then (if possible) the Exception Service
138 handle ( e , log ) ;
139 if ( svc ) { m_sc = svc -> handle ( *obj , e ) ; }
140 }
141 catch ( ... )
142 {
143 // Use the local handler and then (if possible) the Exception Service
144 handle ( log ) ;
145 if ( svc ) { m_sc = svc -> handle ( *obj ) ; }
146 }
147 }
149 ~ExceptionGuard() ;
150 public:
152 const StatusCode& code () const { return m_sc ; }
154 operator const StatusCode&() const { return code() ; }
155 private:
156 // delete default/copy constructor and assignment
157 ExceptionGuard() = delete;
158 ExceptionGuard ( const ExceptionGuard& ) = delete;
159 ExceptionGuard& operator=( const ExceptionGuard& ) = delete;
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 private:
168 // status code: result of the function evaluation
169 StatusCode m_sc = StatusCode::FAILURE ;
170 } ;
171 // ========================================================================
214 class GAUDI_API AuditorGuard final
215 {
216 public:
218 AuditorGuard ( INamedInterface* obj ,
219 IAuditor* svc ,
220 IAuditor::StandardEventType evt ) ;
222 AuditorGuard ( INamedInterface* obj ,
223 IAuditor* svc ,
224 IAuditor::CustomEventTypeRef evt ) ;
225
227 AuditorGuard ( INamedInterface* obj ,
228 IAuditor* svc ,
229 IAuditor::StandardEventType evt ,
230 const StatusCode &sc ) ;
232 AuditorGuard ( INamedInterface* obj ,
233 IAuditor* svc ,
234 IAuditor::CustomEventTypeRef evt ,
235 const StatusCode &sc ) ;
237 AuditorGuard ( std::string name ,
238 IAuditor* svc ,
239 IAuditor::StandardEventType evt ) ;
241 AuditorGuard ( std::string name ,
242 IAuditor* svc ,
243 IAuditor::CustomEventTypeRef evt ) ;
244
246 AuditorGuard ( std::string name ,
247 IAuditor* svc ,
248 IAuditor::StandardEventType evt ,
249 const StatusCode &sc ) ;
251 AuditorGuard ( std::string name ,
252 IAuditor* svc ,
253 IAuditor::CustomEventTypeRef evt ,
254 const StatusCode &sc ) ;
255
257 ~AuditorGuard() ;
258 public:
259 // get the status code
260 const StatusCode &code () const { return *m_sc ; }
261 private:
262 // delete the default/copy constructor and assigment
263 AuditorGuard () = delete;
264 AuditorGuard ( const AuditorGuard& right ) = delete;
265 AuditorGuard& operator=( const AuditorGuard& right ) = delete;
266 private :
268 INamedInterface* m_obj = nullptr ;
270 std::string m_objName;
272 SmartIF<IAuditor> m_svc = nullptr;
274 IAuditor::StandardEventType m_evt ;
276 IAuditor::CustomEventType m_cevt ;
280 const StatusCode *m_sc = nullptr;
282 bool m_customEvtType = false;
283
284 inline void i_before() {
285 if ( m_svc ) { // if the service is not available, we cannot do anything
286 if (m_obj) {
287 if (m_customEvtType) {
288 m_svc->before(m_cevt,m_obj);
289 } else {
290 m_svc->before(m_evt,m_obj);
291 }
292 } else { // use object name
293 if (m_customEvtType) {
294 m_svc->before(m_cevt,m_objName);
295 } else {
296 m_svc->before(m_evt,m_objName);
297 }
298 }
299 }
300 }
301
302 inline void i_after() {
303 if ( m_svc ) { // if the service is not available, we cannot do anything
304 if ( m_obj) {
305 if (m_customEvtType) {
306 if ( m_sc) {
307 m_svc->after(m_cevt,m_obj,*m_sc);
308 } else {
309 m_svc->after(m_cevt,m_obj);
310 }
311 } else {
312 if (m_sc) {
313 m_svc->after(m_evt,m_obj,*m_sc);
314 } else {
315 m_svc->after(m_evt,m_obj);
316 }
317 }
318 } else { // use object name
319 if (m_customEvtType) {
320 if (m_sc) {
321 m_svc->after(m_cevt,m_objName,*m_sc);
322 } else {
323 m_svc->after(m_cevt,m_objName);
324 }
325 } else {
326 if (m_sc) {
327 m_svc->after(m_evt,m_objName,*m_sc);
328 } else {
329 m_svc->after(m_evt,m_objName);
330 }
331 }
332 }
333 m_svc.reset();
334 }
335 }
336 } ;
337 } // end of namespace Gaudi::Guards
338 } //end of namespace Gaudi
339
340
341 // ============================================================================
342 // The END
343 // ============================================================================
344 #endif // GAUDIKERNEL_GUARDS_H
345 // ============================================================================
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:274
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
Gaudi::Guards::AuditorGuard::i_after
void i_after()
Definition: Guards.h:302
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Gaudi::Guards::ExceptionGuard::code
const StatusCode & code() const
the result of function evaluation
Definition: Guards.h:152
IAuditor::StandardEventType
StandardEventType
Defines the standard (= used by the framework) auditable event types.
Definition: IAuditor.h:24
Gaudi::Guards::AuditorGuard::m_cevt
IAuditor::CustomEventType m_cevt
Event type (custom events)
Definition: Guards.h:276
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
IAuditor.h
merge_files.sc
int sc
Definition: merge_files.py:167
std::string
STL class.
INamedInterface.h
Gaudi::Guards::AuditorGuard::code
const StatusCode & code() const
Definition: Guards.h:260
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
read_lhcb_event_file.evt
tuple evt
Definition: read_lhcb_event_file.py:14
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:270
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
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:245
Gaudi::Guards::AuditorGuard::i_before
void i_before()
Definition: Guards.h:284
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
Gaudi::Guards::AuditorGuard
It is a simple guard, which "locks" the scope for the Auditor Service is am exception-safe way...
Definition: Guards.h:214
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
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
IExceptionSvc.h