AlgContextSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
6 #include "GaudiKernel/MsgStream.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/IIncidentSvc.h"
9 // ============================================================================
10 // Local
11 // ============================================================================
12 #include "AlgContextSvc.h"
13 // ============================================================================
20 // ============================================================================
25 // ============================================================================
26 // Standard Constructor
27 // ============================================================================
29 ( const std::string& name ,
30  ISvcLocator* svc )
31  : base_class ( name , svc )
32 {
33  declareProperty ( "Check" , m_check , "Flag to perform more checks" );
34 }
35 // ============================================================================
36 // standard initialization of the service
37 // ============================================================================
39 {
40  // Initialize the base class
42  if ( sc.isFailure () ) { return sc ; }
43  // Incident Service
44  if ( m_inc )
45  {
46  m_inc -> removeListener ( this ) ;
47  m_inc.reset();
48  }
49  // perform more checks?
50  if ( m_check )
51  {
52  m_inc = Service::service ( "IncidentSvc" , true ) ;
53  if ( !m_inc )
54  {
55  MsgStream log ( msgSvc() , name() ) ;
56  log << MSG::ERROR << "Could not locate 'IncidentSvc'" << endmsg ;
57  return StatusCode::FAILURE ; // RETURN
58  }
59  m_inc -> addListener ( this , IncidentType::BeginEvent ) ;
60  m_inc -> addListener ( this , IncidentType::EndEvent ) ;
61  }
62  if ( !m_algorithms.empty() )
63  {
64  MsgStream log ( msgSvc() , name() ) ;
65  log << MSG::WARNING
66  << "Non-empty stack of algorithms #"
67  << m_algorithms.size() << endmsg ;
68  }
69  return StatusCode::SUCCESS ;
70 }
71 // ============================================================================
72 // standard finalization of the service @see IService
73 // ============================================================================
75 {
76  if ( !m_algorithms.empty() )
77  {
78  MsgStream log ( msgSvc() , name() ) ;
79  log << MSG::WARNING
80  << "Non-empty stack of algorithms #"
81  << m_algorithms.size() << endmsg ;
82  }
83  // Incident Service
84  if ( m_inc )
85  {
86  m_inc -> removeListener ( this ) ;
87  m_inc.reset();
88  }
89  // finalize the base class
90  return Service::finalize () ;
91 }
92 // ============================================================================
93 // set the currently executing algorithm ("push_back") @see IAlgContextSvc
94 // ============================================================================
96 {
97  if ( !a )
98  {
99  MsgStream log ( msgSvc() , name() ) ;
100  log << MSG::WARNING << "IAlgorithm* points to NULL" << endmsg ;
101  //
102  return StatusCode::RECOVERABLE ; // RETURN
103  }
104  m_algorithms.push_back ( a ) ;
105  //
106  return StatusCode::SUCCESS ; // RETURN
107 }
108 // ============================================================================
109 // remove the algorithm ("pop_back") @see IAlgContextSvc
110 // ============================================================================
112 {
113  if ( !a )
114  {
115  MsgStream log ( msgSvc() , name() ) ;
116  log << MSG::WARNING << "IAlgorithm* points to NULL" << endmsg ;
117  //
118  return StatusCode::RECOVERABLE ; // RETURN
119  }
120  if ( m_algorithms.empty() || m_algorithms.back() != a )
121  {
122  MsgStream log ( msgSvc() , name() ) ;
123  log << MSG::ERROR << "Algorithm stack is invalid" << endmsg ;
124  //
125  return StatusCode::FAILURE ;
126  }
127  //
128  m_algorithms.pop_back() ; // POP_BACK
129  //
130  return StatusCode::SUCCESS ;
131 }
132 // ============================================================================
134 // ============================================================================
136 { return m_algorithms.empty() ? nullptr : m_algorithms.back() ; }
137 // ============================================================================
138 // handle incident @see IIncidentListener
139 // ============================================================================
141 {
142  if ( !m_algorithms.empty() )
143  {
144  MsgStream log ( msgSvc() , name() ) ;
145  log << MSG::ERROR
146  << "Non-empty stack of algorithms #"
147  << m_algorithms.size() << endmsg ;
148  }
149 }
150 // ============================================================================
151 
152 
153 // ============================================================================
155 // ============================================================================
const std::string BeginEvent
Processing of a new event has started.
Definition: Incident.h:60
IAlgContextSvc::Algorithms m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:60
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:62
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
StatusCode finalize() override
Definition: Service.cpp:187
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void handle(const Incident &) override
handle incident
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:62
STL namespace.
StatusCode unSetCurrentAlg(IAlgorithm *a) override
remove the algorithm ("pop_back")
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
const std::string EndEvent
Processing of the last event has finished.
Definition: Incident.h:61
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:19
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
Base class for all Incidents (computing events).
Definition: Incident.h:16
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:139
StatusCode initialize() override
standard initialization of the service
StatusCode finalize() override
standard finalization of the service
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
StatusCode setCurrentAlg(IAlgorithm *a) override
set the currently executing algorithm ("push_back")
IAlgorithm * currentAlg() const override
accessor to current algorithm: