| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 // ============================================================================
24 DECLARE_COMPONENT(AlgContextSvc)
25 // ============================================================================
26 // standard initialization of the service
27 // ============================================================================
28 StatusCode AlgContextSvc::initialize ()
29 {
30 // Initialize the base class
31 StatusCode sc = Service::initialize () ;
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 // ============================================================================
61 StatusCode AlgContextSvc::finalize ()
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 // ============================================================================
80 StatusCode AlgContextSvc::setCurrentAlg ( IAlgorithm* a )
81 {
82 if ( !a )
83 {
84 warning() << "IAlgorithm* points to NULL" << endmsg ;
85 return StatusCode::RECOVERABLE ;
86 }
87 // check whether thread-local algorithm list already exists
88 // if not, create it
89 if ( ! m_algorithms.get()) {
90 m_algorithms.reset( new IAlgContextSvc::Algorithms() );
91 }
92 m_algorithms->push_back ( a ) ;
93
94 return StatusCode::SUCCESS ;
95 }
96 // ============================================================================
97 // remove the algorithm ("pop_back") @see IAlgContextSvc
98 // ============================================================================
99 StatusCode AlgContextSvc::unSetCurrentAlg ( IAlgorithm* a )
100 {
101 // check whether thread-local algorithm list already exists
102 // if not, create it
103 if ( ! m_algorithms.get()) {
104 m_algorithms.reset( new IAlgContextSvc::Algorithms() );
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 // ============================================================================
124 IAlgorithm* AlgContextSvc::currentAlg () const
125 {
126 return (m_algorithms.get() && ! m_algorithms->empty())
127 ? m_algorithms->back()
128 : nullptr;
129 }
130 // ============================================================================
131 // handle incident @see IIncidentListener
132 // ============================================================================
133 void AlgContextSvc::handle ( const Incident& ) {
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 // ============================================================================
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:174
MsgStream.h
AlgContextSvc::handle
void handle(const Incident &) override
handle incident
Definition: AlgContextSvc.cpp:133
AlgContextSvc::m_inc
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:64
AlgContextSvc::unSetCurrentAlg
StatusCode unSetCurrentAlg(IAlgorithm *a) override
remove the algorithm ("pop_back")
Definition: AlgContextSvc.cpp:99
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
AlgContextSvc
Definition: AlgContextSvc.h:28
AlgContextSvc::m_algorithms
boost::thread_specific_ptr< IAlgContextSvc::Algorithms > m_algorithms
the stack of current algorithms
Definition: AlgContextSvc.h:62
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:120
AlgContextSvc.h
AlgContextSvc::currentAlg
IAlgorithm * currentAlg() const override
accessor to current algorithm:
Definition: AlgContextSvc.cpp:124
IIncidentSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:27
std::vector< IAlgorithm * >
StatusCode::RECOVERABLE
Definition: StatusCode.h:31
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
Service::service
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
AlgContextSvc::finalize
StatusCode finalize() override
standard finalization of the service
Definition: AlgContextSvc.cpp:61
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
AlgContextSvc::setCurrentAlg
StatusCode setCurrentAlg(IAlgorithm *a) override
set the currently executing algorithm ("push_back")
Definition: AlgContextSvc.cpp:80
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244