Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (f31105fd)
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 #include "AlgContextAuditor.h"
12 
15 #include <GaudiKernel/IAlgorithm.h>
16 #include <GaudiKernel/MsgStream.h>
17 #include <GaudiKernel/SmartIF.h>
19 
20 #include <cassert>
21 
27 namespace {
28  template <StatusCode ( IAlgContextSvc::*fun )( IAlgorithm*, const EventContext& )>
29  void call( IAlgContextSvc* ctx, INamedInterface* a ) {
30  if ( ctx ) {
31  // make a safe cast using "smart interface"
34  if ( alg ) ( ctx->*fun )( alg.get(), ectx ).ignore();
35  }
36  }
37 } // namespace
38 
39 // mandatory auditor factory, needed for instantiation
41 
43  return Auditor::initialize().andThen( [&] {
44  m_svc = service( "AlgContextSvc", true );
45  if ( !m_svc ) {
46  error() << "Invalid pointer to IAlgContextSvc" << endmsg;
47  return StatusCode::FAILURE; // RETURN
48  }
49  return StatusCode::SUCCESS;
50  } );
51 }
52 
54  m_svc.reset();
55  return Auditor::finalize();
56 }
57 
58 void AlgContextAuditor::before( StandardEventType evt, INamedInterface* a ) {
59  switch ( evt ) {
60  case Initialize:
61  case Execute:
62  case Finalize:
63  return call<&IAlgContextSvc::setCurrentAlg>( m_svc, a );
64  default:
65  return;
66  }
67 }
68 
69 void AlgContextAuditor::after( StandardEventType evt, INamedInterface* a, const StatusCode& ) {
70  switch ( evt ) {
71  case Initialize:
72  case Execute:
73  case Finalize:
74  return call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a );
75  default:
76  return;
77  }
78 }
IOTest.evt
evt
Definition: IOTest.py:107
Auditor::initialize
virtual StatusCode initialize()
Definition: Auditor.h:77
StatusCode::andThen
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition: StatusCode.h:164
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:30
AlgContextAuditor::before
void before(StandardEventType evt, INamedInterface *a) override
Definition: AlgContextAuditor.cpp:58
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
AlgContextAuditor.h
AlgContextAuditor::finalize
StatusCode finalize() override
Definition: AlgContextAuditor.cpp:53
ManySmallAlgs.alg
alg
Definition: ManySmallAlgs.py:81
SmartIF.h
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
Auditor::finalize
virtual StatusCode finalize()
Definition: Auditor.h:78
SmartIF< IAlgorithm >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
ThreadLocalContext.h
INamedInterface
Definition: INamedInterface.h:25
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.h:45
EventContext.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
EventContext
Definition: EventContext.h:34
IAlgContextSvc
Definition: IAlgContextSvc.h:33
AlgContextAuditor::after
void after(StandardEventType evt, INamedInterface *obj, const StatusCode &sc) override
Definition: AlgContextAuditor.cpp:69
IAlgorithm.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
AlgContextAuditor
Definition: AlgContextAuditor.h:24
MsgStream.h