All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlgContextSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
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  , m_algorithms ( 0 )
33  , m_inc ( 0 )
34  , m_check ( true )
35 {
36  declareProperty ( "Check" , m_check , "Flag to perform more checks" );
37 }
38 // ============================================================================
39 // Standard Destructor
40 // ============================================================================
42 // ============================================================================
43 // standard initialization of the service
44 // ============================================================================
46 {
47  // Initialize the base class
49  if ( sc.isFailure () ) { return sc ; }
50  // Incident Service
51  if ( 0 != m_inc )
52  {
53  m_inc -> removeListener ( this ) ;
54  m_inc -> release() ;
55  m_inc = 0 ;
56  }
57  // perform more checks?
58  if ( m_check )
59  {
60  sc = Service::service ( "IncidentSvc" , m_inc , true ) ;
61  if ( sc.isFailure() )
62  {
63  MsgStream log ( msgSvc() , name() ) ;
64  log << MSG::ERROR << "Could not locate 'IncidentSvc'" << sc << endmsg ;
65  return sc ; // RETURN
66  }
67  if ( 0 == m_inc )
68  {
69  MsgStream log ( msgSvc() , name() ) ;
70  log << MSG::ERROR << "Invalid pointer to IIncindentSvc" << endmsg ;
71  return StatusCode::FAILURE ; // RETURN
72  }
73  m_inc -> addListener ( this , IncidentType::BeginEvent ) ;
74  m_inc -> addListener ( this , IncidentType::EndEvent ) ;
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  return StatusCode::SUCCESS ;
84 }
85 // ============================================================================
86 // standard finalization of the service @see IService
87 // ============================================================================
89 {
90  if ( !m_algorithms.empty() )
91  {
92  MsgStream log ( msgSvc() , name() ) ;
93  log << MSG::WARNING
94  << "Non-empty stack of algorithms #"
95  << m_algorithms.size() << endmsg ;
96  }
97  // Incident Service
98  if ( 0 != m_inc )
99  {
100  m_inc -> removeListener ( this ) ;
101  m_inc -> release() ;
102  m_inc = 0 ;
103  }
104  // finalize the base class
105  return Service::finalize () ;
106 }
107 // ============================================================================
108 // set the currently executing algorithm ("push_back") @see IAlgContextSvc
109 // ============================================================================
111 {
112  if ( 0 == a )
113  {
114  MsgStream log ( msgSvc() , name() ) ;
115  log << MSG::WARNING << "IAlgorithm* points to NULL" << endmsg ;
116  //
117  return StatusCode::RECOVERABLE ; // RETURN
118  }
119  m_algorithms.push_back ( a ) ;
120  //
121  return StatusCode::SUCCESS ; // RETURN
122 }
123 // ============================================================================
124 // remove the algorithm ("pop_back") @see IAlgContextSvc
125 // ============================================================================
127 {
128  if ( 0 == a )
129  {
130  MsgStream log ( msgSvc() , name() ) ;
131  log << MSG::WARNING << "IAlgorithm* points to NULL" << endmsg ;
132  //
133  return StatusCode::RECOVERABLE ; // RETURN
134  }
135  if ( m_algorithms.empty() || m_algorithms.back() != a )
136  {
137  MsgStream log ( msgSvc() , name() ) ;
138  log << MSG::ERROR << "Algorithm stack is invalid" << endmsg ;
139  //
140  return StatusCode::FAILURE ;
141  }
142  //
143  m_algorithms.pop_back() ; // POP_BACK
144  //
145  return StatusCode::SUCCESS ;
146 }
147 // ============================================================================
149 // ============================================================================
151 { return m_algorithms.empty() ? 0 : m_algorithms.back() ; }
152 // ============================================================================
153 // handle incident @see IIncidentListener
154 // ============================================================================
156 {
157  if ( !m_algorithms.empty() )
158  {
159  MsgStream log ( msgSvc() , name() ) ;
160  log << MSG::ERROR
161  << "Non-empty stack of algorithms #"
162  << m_algorithms.size() << endmsg ;
163  }
164 }
165 // ============================================================================
166 
167 
168 
169 
170 // ============================================================================
172 // ============================================================================
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:63
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
virtual IAlgorithm * currentAlg() const
accessor to current algorithm:
virtual ~AlgContextSvc()
Standard Destructor.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
const std::string EndEvent
Processing of the last event has finished.
Definition: Incident.h:61
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:20
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:74
IIncidentSvc * m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:65
virtual unsigned long release()
Release Interface instance.
Definition: Service.cpp:24
virtual StatusCode unSetCurrentAlg(IAlgorithm *a)
remove the algorithm ("pop_back")
Base class for all Incidents (computing events).
Definition: Incident.h:16
Templated class to add the standard messaging functionalities.
virtual StatusCode finalize()
standard finalization of the service
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:142
virtual StatusCode setCurrentAlg(IAlgorithm *a)
set the currently executing algorithm ("push_back")
virtual StatusCode initialize()
standard initialization of the service
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:199
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual void handle(const Incident &)
handle incident