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"
13 // ============================================================================
20 // ============================================================================
25 // ============================================================================
26 // standard initialization of the service
27 // ============================================================================
28 StatusCode AlgContextSvc::initialize ()
29 {
30  // Initialize the base class
32  if ( sc.isFailure () ) { return sc ; }
33  // Incident Service
34  if ( m_inc )
35  {
36  m_inc -> removeListener ( this ) ;
37  m_inc.reset();
38  }
39  // perform more checks?
40  if ( m_check )
41  {
42  m_inc = Service::service ( "IncidentSvc" , true ) ;
43  if ( !m_inc )
44  {
45  error() << "Could not locate 'IncidentSvc'" << endmsg ;
46  return StatusCode::FAILURE ;
47  }
48  m_inc -> addListener ( this , IncidentType::BeginEvent ) ;
49  m_inc -> addListener ( this , IncidentType::EndEvent ) ;
50  }
51  if ( m_algorithms.get() && !m_algorithms->empty() )
52  {
53  warning() << "Non-empty stack of algorithms #"
54  << m_algorithms->size() << endmsg ;
55  }
56  return StatusCode::SUCCESS ;
57 }
58 // ============================================================================
59 // standard finalization of the service @see IService
60 // ============================================================================
62 {
63  if ( m_algorithms.get() && !m_algorithms->empty() )
64  {
65  warning() << "Non-empty stack of algorithms #"
66  << m_algorithms->size() << endmsg ;
67  }
68  // Incident Service
69  if ( m_inc )
70  {
71  m_inc -> removeListener ( this ) ;
72  m_inc.reset();
73  }
74  // finalize the base class
75  return Service::finalize () ;
76 }
77 // ============================================================================
78 // set the currently executing algorithm ("push_back") @see IAlgContextSvc
79 // ============================================================================
81 {
82  if ( !a )
83  {
84  warning() << "IAlgorithm* points to NULL" << endmsg ;
86  }
87  // check whether thread-local algorithm list already exists
88  // if not, create it
89  if ( ! m_algorithms.get()) {
91  }
92  m_algorithms->push_back ( a ) ;
93 
94  return StatusCode::SUCCESS ;
95 }
96 // ============================================================================
97 // remove the algorithm ("pop_back") @see IAlgContextSvc
98 // ============================================================================
100 {
101  // check whether thread-local algorithm list already exists
102  // if not, create it
103  if ( ! m_algorithms.get()) {
105  }
106 
107  if ( !a )
108  {
109  warning() << "IAlgorithm* points to NULL" << endmsg ;
110  return StatusCode::RECOVERABLE ;
111  }
112  if ( m_algorithms->empty() || m_algorithms->back() != a )
113  {
114  error() << "Algorithm stack is invalid" << endmsg ;
115  return StatusCode::FAILURE ;
116  }
117  m_algorithms->pop_back() ;
118 
119  return StatusCode::SUCCESS ;
120 }
121 // ============================================================================
123 // ============================================================================
125 {
126  return (m_algorithms.get() && ! m_algorithms->empty())
127  ? m_algorithms->back()
128  : nullptr;
129 }
130 // ============================================================================
131 // handle incident @see IIncidentListener
132 // ============================================================================
134  if ( m_algorithms.get() && !m_algorithms->empty() ) {
135  error() << "Non-empty stack of algorithms #"
136  << m_algorithms->size() << endmsg ;
137  }
138 }
139 // ============================================================================
140 // ============================================================================
142 // ============================================================================
StatusCode initialize() override
Definition: Service.cpp:64
StatusCode finalize() override
Definition: Service.cpp:174
void handle(const Incident &) override
handle incident
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:64
StatusCode unSetCurrentAlg(IAlgorithm *a) override
remove the algorithm ("pop_back")
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:62
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
IAlgorithm * currentAlg() const override
accessor to current algorithm:
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:27
Base class for all Incidents (computing events).
Definition: Incident.h:17
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Service.h:85
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")
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244