All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AlgContextSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // Local
5 // ============================================================================
6 #include "AlgContextSvc.h"
7 // ============================================================================
8 // GaudiKernel
9 // ============================================================================
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/ISvcLocator.h"
12 #include "GaudiKernel/IIncidentSvc.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.get() && !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.get() && !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  return StatusCode::RECOVERABLE ; // RETURN
102  }
103  // check whether thread-local algorithm list already exists
104  // if not, create it
105  if ( ! m_algorithms.get()) {
107  }
108  m_algorithms->push_back ( a ) ;
109 
110  return StatusCode::SUCCESS ; // RETURN
111 }
112 // ============================================================================
113 // remove the algorithm ("pop_back") @see IAlgContextSvc
114 // ============================================================================
116 {
117  // check whether thread-local algorithm list already exists
118  // if not, create it
119  if ( ! m_algorithms.get()) {
121  }
122 
123  if ( !a )
124  {
125  MsgStream log ( msgSvc() , name() ) ;
126  log << MSG::WARNING << "IAlgorithm* points to NULL" << endmsg ;
127  return StatusCode::RECOVERABLE ; // RETURN
128  }
129  if ( m_algorithms->empty() || m_algorithms->back() != a )
130  {
131  MsgStream log ( msgSvc() , name() ) ;
132  log << MSG::ERROR << "Algorithm stack is invalid" << endmsg ;
133  return StatusCode::FAILURE ;
134  }
135  m_algorithms->pop_back() ; // POP_BACK
136 
137  return StatusCode::SUCCESS ;
138 }
139 // ============================================================================
141 // ============================================================================
143 {
144  return (m_algorithms.get() && ! m_algorithms->empty())
145  ? m_algorithms->back()
146  : nullptr;
147 }
148 // ============================================================================
149 // handle incident @see IIncidentListener
150 // ============================================================================
152  if ( m_algorithms.get() && !m_algorithms->empty() ) {
153  MsgStream log ( msgSvc() , name() ) ;
154  log << MSG::ERROR
155  << "Non-empty stack of algorithms #"
156  << m_algorithms->size() << endmsg ;
157  }
158 }
159 // ============================================================================
160 // ============================================================================
162 // ============================================================================
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:63
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode finalize() override
Definition: Service.cpp:188
void handle(const Incident &) override
handle incident
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:64
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
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:62
std::vector< IAlgorithm * > Algorithms
the actual type of algorithm' stack
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:23
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:141
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: