The Gaudi Framework  master (d98a2936)
Gaudi::Guards::AuditorGuard Class Referencefinal

#include <GaudiKernel/Guards.h>

Collaboration diagram for Gaudi::Guards::AuditorGuard:

Public Member Functions

 AuditorGuard (std::string name, IAuditor *svc, std::string const &evt, EventContext const &context={})
 
 AuditorGuard (std::string name, IAuditor *svc, std::string const &evt, StatusCode const &sc, EventContext const &context={})
 
 ~AuditorGuard ()
 
const StatusCode code () const
 

Private Member Functions

 AuditorGuard (const AuditorGuard &right)=delete
 
AuditorGuardoperator= (const AuditorGuard &right)=delete
 
void i_before ()
 
void i_after ()
 

Private Attributes

std::string m_objName
 the guarded object name (if there is no INamedInterface) More...
 
SmartIF< IAuditorm_svc = nullptr
 auditor service More...
 
std::string const m_evt
 Event type. More...
 
StatusCode const * m_sc {}
 Pointer to a status code instance, to be passed to the "after" function if needed The instance must have a scope larger than the one of the guard. More...
 
const EventContextm_context
 Pointer to a EventContext instance, to be passed to the "before" and "after" function If given, the instance must have a scope larger than the one of the guard. More...
 

Detailed Description

It is a simple guard, which "locks" the scope for the Auditor Service is am exception-safe way

The pattern ensures that "post-action" will be always executed

{
AuditorGuard auditor ( this ,
auditSvc() ,
...
StatusCode sc = ... ;
...
return sc ;
}
{
AuditorGuard auditor ( this ,
auditSvc() ,
...
StatusCode sc = ... ;
...
auditor.setCode ( sc ) ;
...
return sc ;
}
Author
Vanya BELYAEV ibely.nosp@m.aev@.nosp@m.physi.nosp@m.cs.s.nosp@m.yr.ed.nosp@m.u
Date
2007-03-07

Definition at line 203 of file Guards.h.

Constructor & Destructor Documentation

◆ AuditorGuard() [1/3]

Gaudi::Guards::AuditorGuard::AuditorGuard ( std::string  name,
IAuditor svc,
std::string const &  evt,
EventContext const &  context = {} 
)

Definition at line 42 of file Guards.cpp.

44  : m_objName( name ), m_svc( svc ), m_evt( evt ), m_context( context ) {
45  i_before();
46 }

◆ AuditorGuard() [2/3]

Gaudi::Guards::AuditorGuard::AuditorGuard ( std::string  name,
IAuditor svc,
std::string const &  evt,
StatusCode const &  sc,
EventContext const &  context = {} 
)

Definition at line 48 of file Guards.cpp.

50  : m_objName( name ), m_svc( svc ), m_evt( evt ), m_sc( &sc ), m_context( context ) {
51  i_before();
52 }

◆ ~AuditorGuard()

Gaudi::Guards::AuditorGuard::~AuditorGuard ( )
inline

Definition at line 210 of file Guards.h.

210 { i_after(); }

◆ AuditorGuard() [3/3]

Gaudi::Guards::AuditorGuard::AuditorGuard ( const AuditorGuard right)
privatedelete

Member Function Documentation

◆ code()

const StatusCode Gaudi::Guards::AuditorGuard::code ( ) const
inline

Definition at line 214 of file Guards.h.

214 { return m_sc ? *m_sc : StatusCode::SUCCESS; }

◆ i_after()

void Gaudi::Guards::AuditorGuard::i_after ( )
inlineprivate

Definition at line 243 of file Guards.h.

243  {
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  }

◆ i_before()

void Gaudi::Guards::AuditorGuard::i_before ( )
inlineprivate

Definition at line 237 of file Guards.h.

237  {
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  }

◆ operator=()

AuditorGuard& Gaudi::Guards::AuditorGuard::operator= ( const AuditorGuard right)
privatedelete

Member Data Documentation

◆ m_context

const EventContext& Gaudi::Guards::AuditorGuard::m_context
private

Pointer to a EventContext instance, to be passed to the "before" and "after" function If given, the instance must have a scope larger than the one of the guard.

No check is performed.

Definition at line 235 of file Guards.h.

◆ m_evt

std::string const Gaudi::Guards::AuditorGuard::m_evt
private

Event type.

Definition at line 227 of file Guards.h.

◆ m_objName

std::string Gaudi::Guards::AuditorGuard::m_objName
private

the guarded object name (if there is no INamedInterface)

Definition at line 223 of file Guards.h.

◆ m_sc

StatusCode const* Gaudi::Guards::AuditorGuard::m_sc {}
private

Pointer to a status code instance, to be passed to the "after" function if needed The instance must have a scope larger than the one of the guard.

No check is performed.

Definition at line 231 of file Guards.h.

◆ m_svc

SmartIF<IAuditor> Gaudi::Guards::AuditorGuard::m_svc = nullptr
private

auditor service

Definition at line 225 of file Guards.h.


The documentation for this class was generated from the following files:
IOTest.evt
evt
Definition: IOTest.py:107
Gaudi::Algorithm::sysExecute
StatusCode sysExecute(const EventContext &ctx) override
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:322
Gaudi::IAuditor::Initialize
static const std::string Initialize
Definition: IAuditor.h:47
Gaudi::Guards::AuditorGuard::AuditorGuard
AuditorGuard(std::string name, IAuditor *svc, std::string const &evt, EventContext const &context={})
Definition: Guards.cpp:42
Gaudi::Guards::AuditorGuard::m_evt
std::string const m_evt
Event type.
Definition: Guards.h:227
Gaudi::Guards::AuditorGuard::m_svc
SmartIF< IAuditor > m_svc
auditor service
Definition: Guards.h:225
StatusCode
Definition: StatusCode.h:64
Gaudi::Guards::AuditorGuard::m_objName
std::string m_objName
the guarded object name (if there is no INamedInterface)
Definition: Guards.h:223
GaudiPython.Pythonizations.execute
execute
Definition: Pythonizations.py:578
Gaudi::Algorithm::sysInitialize
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Algorithm.cpp:53
Gaudi::Guards::AuditorGuard::i_before
void i_before()
Definition: Guards.h:237
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:235
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:231
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:99
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi::Guards::AuditorGuard::i_after
void i_after()
Definition: Guards.h:243