The Gaudi Framework  v33r1 (b1225454)
AlgContextAuditor.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 #include "AlgContextAuditor.h"
12 
15 #include "GaudiKernel/IAlgorithm.h"
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/SmartIF.h"
19 
20 #include <cassert>
21 
22 // ============================================================================
28 // ============================================================================
29 namespace {
30  template <StatusCode ( IAlgContextSvc::*fun )( IAlgorithm*, const EventContext& )>
31  void call( IAlgContextSvc* ctx, INamedInterface* a ) {
32  if ( ctx ) {
33  // make a safe cast using "smart interface"
36  if ( alg ) ( ctx->*fun )( alg.get(), ectx ).ignore();
37  }
38  }
39 } // namespace
40 // ============================================================================
41 // mandatory auditor factory, needed for instantiation
42 // ============================================================================
44 // ============================================================================
45 // standard constructor @see Auditor
46 // ============================================================================
47 AlgContextAuditor::AlgContextAuditor( const std::string& name, ISvcLocator* pSvc ) : Auditor( name, pSvc ) {}
48 // ============================================================================
49 // standard initialization, see @IAuditor
50 // ============================================================================
52  // initialize the base class
54  if ( sc.isFailure() ) { return sc; } // RETURN
55  m_svc = service( "AlgContextSvc", true );
56  if ( !m_svc ) {
57  error() << "Invalid pointer to IAlgContextSvc" << endmsg;
58  return StatusCode::FAILURE; // RETURN
59  }
60  return StatusCode::SUCCESS;
61 }
62 // ============================================================================
63 // standard finalization, see @IAuditor
64 // ============================================================================
66  m_svc.reset();
67  // finalize the base class
68  return Auditor::finalize();
69 }
70 // ============================================================================
71 void AlgContextAuditor::beforeInitialize( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
72 // ============================================================================
73 void AlgContextAuditor::afterInitialize( INamedInterface* a ) { call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a ); }
74 // ============================================================================
75 void AlgContextAuditor::beforeFinalize( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
76 // ============================================================================
77 void AlgContextAuditor::afterFinalize( INamedInterface* a ) { call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a ); }
78 // ============================================================================
79 void AlgContextAuditor::beforeExecute( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
80 // ============================================================================
82  call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a );
83 }
84 // ============================================================================
85 
86 // ============================================================================
87 // The END
88 // ============================================================================
StatusCode initialize() override
standard initialization,
virtual StatusCode finalize()
Definition: Auditor.cpp:186
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
Description: Register/Unregister the AlgContext of each algorithm before entering the algorithm and a...
void afterFinalize(INamedInterface *a) override
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
STL namespace.
SmartIF< IAlgContextSvc > m_svc
the pointer to Algorithm Context Service
void beforeInitialize(INamedInterface *a) override
void afterInitialize(INamedInterface *a) override
This class represents an entry point to all the event specific data.
Definition: EventContext.h:34
#define DECLARE_COMPONENT(type)
StatusCode service(std::string_view name, T *&svc, bool createIf=false) const
Access a service by name, creating it if it doesn't already exist.
Definition: Auditor.h:109
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
GAUDI_API const EventContext & currentContext()
StatusCode finalize() override
standard finalization,
IInterface compliant class extending IInterface with the name() method.
void beforeFinalize(INamedInterface *a) override
void afterExecute(INamedInterface *a, const StatusCode &s) override
constexpr static const auto FAILURE
Definition: StatusCode.h:101
An abstract interface for Algorithm Context Service.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
virtual StatusCode initialize()
Definition: Auditor.cpp:75
bool isFailure() const
Definition: StatusCode.h:145
void beforeExecute(INamedInterface *a) override
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:44