The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
AlgContextAuditor.cpp
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
12#include <Gaudi/Auditor.h>
17
18class IAlgContextSvc;
19
27public:
28 // IAuditor implementation
29 void before( std::string const&, std::string const&, EventContext const& ) override;
30 void after( std::string const&, std::string const&, EventContext const&, StatusCode const& ) override;
31
32public:
33 using Auditor::Auditor;
34 StatusCode initialize() override;
35 StatusCode finalize() override;
36
37private:
42
43private:
48};
49
50// mandatory auditor factory, needed for instantiation
52
54 return Auditor::initialize().andThen( [&] {
55 m_svc = service( "AlgContextSvc", true );
56 if ( !m_svc ) {
57 error() << "Invalid pointer to IAlgContextSvc" << endmsg;
58 return StatusCode::FAILURE; // RETURN
59 }
61 if ( !m_algMgr ) {
62 error() << "Invalid pointer to IAlgManager" << endmsg;
63 return StatusCode::FAILURE; // RETURN
64 }
66 } );
67}
68
70 m_svc.reset();
71 m_algMgr.reset();
72 return Auditor::finalize();
73}
74
75void AlgContextAuditor::before( std::string const& event, std::string const& caller, EventContext const& context ) {
76 if ( m_svc && ( event == Gaudi::IAuditor::Initialize || event == Gaudi::IAuditor::Execute ||
77 event == Gaudi::IAuditor::Finalize ) ) {
78 SmartIF<IAlgorithm>& alg = m_algMgr->algorithm( caller, false );
79 if ( alg ) m_svc->setCurrentAlg( alg, context ).ignore();
80 }
81}
82
83void AlgContextAuditor::after( std::string const& event, std::string const& caller, EventContext const& context,
84 StatusCode const& ) {
85 if ( m_svc && ( event == Gaudi::IAuditor::Initialize || event == Gaudi::IAuditor::Execute ||
86 event == Gaudi::IAuditor::Finalize ) ) {
87 SmartIF<IAlgorithm>& alg = m_algMgr->algorithm( caller, false );
88 if ( alg ) m_svc->unSetCurrentAlg( alg, context ).ignore();
89 }
90}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
Description: Register/Unregister the AlgContext of each algorithm before entering the algorithm and a...
SmartIF< IAlgManager > m_algMgr
the pointer to Algorithm Manager
StatusCode initialize() override
AlgContextAuditor & operator=(const AlgContextAuditor &)=delete
void after(std::string const &, std::string const &, EventContext const &, StatusCode const &) override
AlgContextAuditor(const AlgContextAuditor &)=delete
AlgContextAuditor()=delete
delete the default/copy constructor and assignment
StatusCode finalize() override
SmartIF< IAlgContextSvc > m_svc
the pointer to Algorithm Context Service
void before(std::string const &, std::string const &, EventContext const &) override
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class represents an entry point to all the event specific data.
Base class from which all concrete auditor classes should be derived.
Definition Auditor.h:33
SmartIF< T > service(std::string_view name, bool createIf=false) const
Access a service by name, creating it if it doesn't already exist.
Definition Auditor.h:63
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition Auditor.h:59
static const std::string Initialize
Definition IAuditor.h:47
static const std::string Finalize
Definition IAuditor.h:53
static const std::string Execute
Definition IAuditor.h:51
An abstract interface for Algorithm Context Service.
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100