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 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  error() << "Could not locate 'IncidentSvc'" << endmsg ;
56  return StatusCode::FAILURE ; // RETURN
57  }
58  m_inc -> addListener ( this , IncidentType::BeginEvent ) ;
59  m_inc -> addListener ( this , IncidentType::EndEvent ) ;
60  }
61  if ( m_algorithms.get() && !m_algorithms->empty() )
62  {
63  warning() << "Non-empty stack of algorithms #"
64  << m_algorithms->size() << endmsg ;
65  }
66  return StatusCode::SUCCESS ;
67 }
68 // ============================================================================
69 // standard finalization of the service @see IService
70 // ============================================================================
72 {
73  if ( m_algorithms.get() && !m_algorithms->empty() )
74  {
75  warning() << "Non-empty stack of algorithms #"
76  << m_algorithms->size() << endmsg ;
77  }
78  // Incident Service
79  if ( m_inc )
80  {
81  m_inc -> removeListener ( this ) ;
82  m_inc.reset();
83  }
84  // finalize the base class
85  return Service::finalize () ;
86 }
87 // ============================================================================
88 // set the currently executing algorithm ("push_back") @see IAlgContextSvc
89 // ============================================================================
91 {
92  if ( !a )
93  {
94  warning() << "IAlgorithm* points to NULL" << endmsg ;
95  return StatusCode::RECOVERABLE ; // RETURN
96  }
97  // check whether thread-local algorithm list already exists
98  // if not, create it
99  if ( ! m_algorithms.get()) {
101  }
102  m_algorithms->push_back ( a ) ;
103 
104  return StatusCode::SUCCESS ; // RETURN
105 }
106 // ============================================================================
107 // remove the algorithm ("pop_back") @see IAlgContextSvc
108 // ============================================================================
110 {
111  // check whether thread-local algorithm list already exists
112  // if not, create it
113  if ( ! m_algorithms.get()) {
115  }
116 
117  if ( !a )
118  {
119  warning() << "IAlgorithm* points to NULL" << endmsg ;
120  return StatusCode::RECOVERABLE ; // RETURN
121  }
122  if ( m_algorithms->empty() || m_algorithms->back() != a )
123  {
124  error() << "Algorithm stack is invalid" << endmsg ;
125  return StatusCode::FAILURE ;
126  }
127  m_algorithms->pop_back() ; // POP_BACK
128 
129  return StatusCode::SUCCESS ;
130 }
131 // ============================================================================
133 // ============================================================================
135 {
136  return (m_algorithms.get() && ! m_algorithms->empty())
137  ? m_algorithms->back()
138  : nullptr;
139 }
140 // ============================================================================
141 // handle incident @see IIncidentListener
142 // ============================================================================
144  if ( m_algorithms.get() && !m_algorithms->empty() ) {
145  error() << "Non-empty stack of algorithms #"
146  << m_algorithms->size() << endmsg ;
147  }
148 }
149 // ============================================================================
150 // ============================================================================
152 // ============================================================================
StatusCode initialize() override
Definition: Service.cpp:68
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:193
void handle(const Incident &) override
handle incident
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:66
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
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:64
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
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:25
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't already exist.
Definition: Service.h:144
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:
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244