The Gaudi Framework
master (6507eef1)
Toggle main menu visibility
Loading...
Searching...
No Matches
Guards.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#pragma once
12
13
#include <
Gaudi/IAuditor.h
>
14
#include <
GaudiKernel/EventContext.h
>
15
#include <
GaudiKernel/IExceptionSvc.h
>
16
#include <
GaudiKernel/SmartIF.h
>
17
#include <exception>
18
19
class
GaudiException
;
20
21
namespace
Gaudi
{
72
namespace
Guards
{
104
*/
105
class
GAUDI_API
ExceptionGuard
{
106
public
:
107
/* constructor form the object/scope, function and log-stream
108
* @param obj the object/scope
109
* @param fun function to be used
110
* @param log output log-stream
111
*/
112
template
<
class
OBJECT,
class
FUNCTION>
113
ExceptionGuard
( OBJECT obj, FUNCTION fun,
MsgStream
& log,
IExceptionSvc
* svc = 0 ) {
114
try
{
115
// execute the functor:
116
m_sc
= fun( obj );
117
// in the case of error try use Exception Service
118
if
( svc &&
m_sc
.isFailure() ) {
m_sc
= svc->handleErr( *obj,
m_sc
); }
119
}
catch
(
const
GaudiException
& e ) {
120
// Use the local handler and then (if possible) the Exception Service
121
handle
( e, log );
122
if
( svc ) {
m_sc
= svc->handle( *obj, e ); }
123
}
catch
(
const
std::exception& e ) {
124
// Use the local handler and then (if possible) the Exception Service
125
handle
( e, log );
126
if
( svc ) {
m_sc
= svc->handle( *obj, e ); }
127
}
catch
( ... ) {
128
// Use the local handler and then (if possible) the Exception Service
129
handle
( log );
130
if
( svc ) {
m_sc
= svc->handle( *obj ); }
131
}
132
}
134
~ExceptionGuard
();
135
136
public
:
138
const
StatusCode
&
code
()
const
{
return
m_sc
; }
140
operator
const
StatusCode
&()
const
{
return
code
(); }
141
142
private
:
143
// delete default/copy constructor and assignment
144
ExceptionGuard
() =
delete
;
145
ExceptionGuard
(
const
ExceptionGuard
& ) =
delete
;
146
ExceptionGuard
&
operator=
(
const
ExceptionGuard
& ) =
delete
;
147
148
protected
:
150
void
handle
(
const
GaudiException
& e,
MsgStream
& s );
152
void
handle
(
const
std::exception& e,
MsgStream
& s );
154
void
handle
(
MsgStream
& s );
155
156
private
:
157
// status code: result of the function evaluation
158
StatusCode
m_sc
=
StatusCode::FAILURE
;
159
};
160
202
*/
203
class
GAUDI_API
AuditorGuard
final {
204
public
:
205
// user facing constructors
206
AuditorGuard
( std::string name,
IAuditor
* svc, std::string
const
& evt,
EventContext
const
& context = {} );
207
AuditorGuard
( std::string name,
IAuditor
* svc, std::string
const
& evt,
StatusCode
const
& sc,
208
EventContext
const
& context = {} );
209
210
~AuditorGuard
() {
i_after
(); }
211
212
public
:
213
// get the status code
214
const
StatusCode
code
()
const
{
return
m_sc
? *
m_sc
:
StatusCode::SUCCESS
; }
215
216
private
:
217
// delete the default/copy constructor and assigment
218
AuditorGuard
(
const
AuditorGuard
& right ) =
delete
;
219
AuditorGuard
&
operator=
(
const
AuditorGuard
& right ) =
delete
;
220
221
private
:
223
std::string
m_objName
;
225
SmartIF<IAuditor>
m_svc
=
nullptr
;
227
std::string
const
m_evt
;
231
StatusCode
const
*
m_sc
{};
235
const
EventContext
&
m_context
;
236
237
inline
void
i_before
() {
238
if
(
m_svc
) {
// if the service is not available, we cannot do anything
239
m_svc
->before(
m_evt
,
m_objName
,
m_context
);
240
}
241
}
242
243
inline
void
i_after
() {
244
if
(
m_svc
) {
// if the service is not available, we cannot do anything
245
if
(
m_sc
) {
246
m_svc
->after(
m_evt
,
m_objName
,
m_context
, *
m_sc
);
247
}
else
{
248
m_svc
->after(
m_evt
,
m_objName
,
m_context
);
249
}
250
m_svc
.reset();
251
}
252
}
253
};
254
}
// namespace Guards
255
}
// namespace Gaudi
EventContext.h
IAuditor.h
IExceptionSvc.h
GAUDI_API
#define GAUDI_API
Definition
Kernel.h:49
SmartIF.h
EventContext
This class represents an entry point to all the event specific data.
Definition
EventContext.h:35
Gaudi::Guards::AuditorGuard::code
const StatusCode code() const
Definition
Guards.h:213
Gaudi::Guards::AuditorGuard::m_evt
std::string const m_evt
Event type.
Definition
Guards.h:226
Gaudi::Guards::AuditorGuard::m_svc
SmartIF< IAuditor > m_svc
auditor service
Definition
Guards.h:224
Gaudi::Guards::AuditorGuard::m_context
const EventContext & m_context
Pointer to a EventContext instance, to be passed to the "before" and "after" function If given,...
Definition
Guards.h:234
Gaudi::Guards::AuditorGuard::i_before
void i_before()
Definition
Guards.h:236
Gaudi::Guards::AuditorGuard::operator=
AuditorGuard & operator=(const AuditorGuard &right)=delete
Gaudi::Guards::AuditorGuard::AuditorGuard
AuditorGuard(std::string name, IAuditor *svc, std::string const &evt, EventContext const &context={})
Definition
Guards.cpp:42
Gaudi::Guards::AuditorGuard::i_after
void i_after()
Definition
Guards.h:242
Gaudi::Guards::AuditorGuard::m_objName
std::string m_objName
the guarded object name (if there is no INamedInterface)
Definition
Guards.h:222
Gaudi::Guards::AuditorGuard::m_sc
StatusCode const * m_sc
Pointer to a status code instance, to be passed to the "after" function if needed The instance must h...
Definition
Guards.h:230
Gaudi::Guards::ExceptionGuard
The most simple guard - it execute the certain code withing typical "try {} catch" clause,...
Definition
Guards.h:104
Gaudi::Guards::ExceptionGuard::operator=
ExceptionGuard & operator=(const ExceptionGuard &)=delete
Gaudi::Guards::ExceptionGuard::handle
void handle(const GaudiException &e, MsgStream &s)
local handler of GaudiException
Definition
Guards.cpp:25
Gaudi::Guards::ExceptionGuard::ExceptionGuard
ExceptionGuard(const ExceptionGuard &)=delete
Gaudi::Guards::ExceptionGuard::m_sc
StatusCode m_sc
status code : result of function evaluation
Definition
Guards.h:157
Gaudi::Guards::ExceptionGuard::code
const StatusCode & code() const
the result of function evaluation
Definition
Guards.h:137
Gaudi::Guards::ExceptionGuard::ExceptionGuard
ExceptionGuard(OBJECT obj, FUNCTION fun, MsgStream &log, IExceptionSvc *svc=0)
Definition
Guards.h:112
Gaudi::IAuditor
The IAuditor is the interface implemented by the Auditor base class.
Definition
IAuditor.h:26
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
IExceptionSvc
The abstract interface for exception handling service.
Definition
IExceptionSvc.h:25
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition
MsgStream.h:29
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition
SmartIF.h:28
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi::Guards
Guards.h GaudiKernel/Guards.h Collection of very simple classes which allows to execution of some fun...
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
GaudiKernel
include
GaudiKernel
Guards.h
Generated on
for The Gaudi Framework by
1.17.0