| The Gaudi Framework v27r1

- 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 Constructor
27 // ============================================================================
28 AlgContextSvc::AlgContextSvc
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 // ============================================================================
38 StatusCode AlgContextSvc::initialize ()
39 {
40 // Initialize the base class
41 StatusCode sc = Service::initialize () ;
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 // ============================================================================
71 StatusCode AlgContextSvc::finalize ()
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 // ============================================================================
90 StatusCode AlgContextSvc::setCurrentAlg ( IAlgorithm* a )
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()) {
100 m_algorithms.reset( new IAlgContextSvc::Algorithms() );
101 }
102 m_algorithms->push_back ( a ) ;
103
104 return StatusCode::SUCCESS ; // RETURN
105 }
106 // ============================================================================
107 // remove the algorithm ("pop_back") @see IAlgContextSvc
108 // ============================================================================
109 StatusCode AlgContextSvc::unSetCurrentAlg ( IAlgorithm* a )
110 {
111 // check whether thread-local algorithm list already exists
112 // if not, create it
113 if ( ! m_algorithms.get()) {
114 m_algorithms.reset( new IAlgContextSvc::Algorithms() );
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 // ============================================================================
134 IAlgorithm* AlgContextSvc::currentAlg () const
135 {
136 return (m_algorithms.get() && ! m_algorithms->empty())
137 ? m_algorithms->back()
138 : nullptr;
139 }
140 // ============================================================================
141 // handle incident @see IIncidentListener
142 // ============================================================================
143 void AlgContextSvc::handle ( const Incident& ) {
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 // ============================================================================
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:193
MsgStream.h
AlgContextSvc::handle
void handle(const Incident &) override
handle incident
Definition: AlgContextSvc.cpp:143
AlgContextSvc::m_inc
SmartIF< IIncidentSvc > m_inc
pointer to Incident Service
Definition: AlgContextSvc.h:66
std
STL namespace.
AlgContextSvc::unSetCurrentAlg
StatusCode unSetCurrentAlg(IAlgorithm *a) override
remove the algorithm ("pop_back")
Definition: AlgContextSvc.cpp:109
merge_files.sc
int sc
Definition: merge_files.py:167
StatusCode::RECOVERABLE
Definition: StatusCode.h:31
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
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:64
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
AlgContextSvc.h
AlgContextSvc::m_check
bool m_check
Definition: AlgContextSvc.h:68
StatusCode::FAILURE
Definition: StatusCode.h:29
IIncidentSvc.h
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:25
std::vector< IAlgorithm * >
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
CommonMessaging
Definition: CommonMessaging.h:58
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't already exist.
Definition: Service.h:144
AlgContextSvc::initialize
StatusCode initialize() override
standard initialization of the service
Definition: AlgContextSvc.cpp:38
AlgContextSvc::finalize
StatusCode finalize() override
standard finalization of the service
Definition: AlgContextSvc.cpp:71
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:90
AlgContextSvc::currentAlg
IAlgorithm * currentAlg() const override
accessor to current algorithm:
Definition: AlgContextSvc.cpp:134
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244