The Gaudi Framework  master (42b00024)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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>
16 #include <GaudiKernel/IAlgorithm.h>
17 
18 class IAlgContextSvc;
19 
27 public:
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 
32 public:
33  using Auditor::Auditor;
34  StatusCode initialize() override;
35  StatusCode finalize() override;
36 
37 private:
39  AlgContextAuditor() = delete;
42 
43 private:
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  }
60  m_algMgr = serviceLocator();
61  if ( !m_algMgr ) {
62  error() << "Invalid pointer to IAlgManager" << endmsg;
63  return StatusCode::FAILURE; // RETURN
64  }
65  return StatusCode::SUCCESS;
66  } );
67 }
68 
70  m_svc.reset();
71  m_algMgr.reset();
72  return Auditor::finalize();
73 }
74 
75 void 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 
83 void 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 }
IAlgManager.h
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
AlgContextAuditor::after
void after(std::string const &, std::string const &, EventContext const &, StatusCode const &) override
Definition: AlgContextAuditor.cpp:83
Gaudi::IAuditor::Finalize
static constexpr std::string Finalize
Definition: IAuditor.h:53
AlgContextAuditor::finalize
StatusCode finalize() override
Definition: AlgContextAuditor.cpp:69
ManySmallAlgs.alg
alg
Definition: ManySmallAlgs.py:81
AlgContextAuditor::m_algMgr
SmartIF< IAlgManager > m_algMgr
the pointer to Algorithm Manager
Definition: AlgContextAuditor.cpp:47
AlgContextAuditor::operator=
AlgContextAuditor & operator=(const AlgContextAuditor &)=delete
StatusCode
Definition: StatusCode.h:65
AlgContextAuditor::initialize
StatusCode initialize() override
Definition: AlgContextAuditor.cpp:53
SmartIF< IAlgContextSvc >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
AlgContextAuditor::AlgContextAuditor
AlgContextAuditor()=delete
delete the default/copy constructor and assignment
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
IAlgContextSvc.h
AlgContextAuditor::m_svc
SmartIF< IAlgContextSvc > m_svc
the pointer to Algorithm Context Service
Definition: AlgContextAuditor.cpp:45
AlgContextAuditor::before
void before(std::string const &, std::string const &, EventContext const &) override
Definition: AlgContextAuditor.cpp:75
EventContext.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
EventContext
Definition: EventContext.h:34
IAlgContextSvc
Definition: IAlgContextSvc.h:33
Gaudi::IAuditor::Initialize
static constexpr std::string Initialize
Definition: IAuditor.h:47
IAlgorithm.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Auditor
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:33
Gaudi::IAuditor::Execute
static constexpr std::string Execute
Definition: IAuditor.h:51
AlgContextAuditor
Definition: AlgContextAuditor.cpp:26
AlgContextAuditor::AlgContextAuditor
AlgContextAuditor(const AlgContextAuditor &)=delete
Auditor.h