| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AuditorSvc.cpp
Go to the documentation of this file.
1 // Include Files
2 #include "GaudiKernel/MsgStream.h"
3 #include "GaudiKernel/ISvcLocator.h"
4 #include "GaudiKernel/IAuditor.h"
5 #include "GaudiKernel/INamedInterface.h"
6 #include "GaudiKernel/Auditor.h"
7 #include "GaudiKernel/TypeNameString.h"
8 #include "GaudiKernel/GaudiException.h"
9 #include "AuditorSvc.h"
10
11 // Instantiation of a static factory class used by clients to create
12 // instances of this service
13 DECLARE_COMPONENT(AuditorSvc)
14
15 //
16 // ClassName: AuditorSvc
17 //
18 // Description: This service manages Auditors.
19 //------------------------------------------------------------------
20
21 //- private helpers ---
22 IAuditor* AuditorSvc::newAuditor_( MsgStream& log, const std::string& name ) {
23 // locate the auditor factory, instantiate a new auditor, initialize it
24 IAuditor* aud = 0;
25 StatusCode sc;
26 Gaudi::Utils::TypeNameString item(name) ;
27 aud = Auditor::Factory::create( item.type(), item.name(), serviceLocator().get() );
28 if ( aud ) {
29 aud->addRef();
30 if ( m_targetState >= Gaudi::StateMachine::INITIALIZED ) {
31 sc = aud->sysInitialize();
32 if ( sc.isFailure() ) {
33 log << MSG::WARNING << "Failed to initialize Auditor " << name << endmsg;
34 aud->release();
35 aud = 0;
36 }
37 }
38 }
39 else {
40 log << MSG::WARNING << "Unable to retrieve factory for Auditor " << name << endmsg;
41 }
42
43 return aud;
44 }
45
46 IAuditor* AuditorSvc::findAuditor_( const std::string& name ) {
47 // find an auditor by name, return 0 on error
48 IAuditor* aud = 0;
49 const std::string item_name = Gaudi::Utils::TypeNameString(name).name();
50 for ( ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); ++it ) {
51 if ( (*it)->name() == item_name ) {
52 (*it)->addRef();
53 aud = *it;
54 break;
55 }
56 }
57
58 return aud;
59 }
60
61 StatusCode AuditorSvc::syncAuditors_() {
62 if ( m_audNameList.size() == m_pAudList.size() )
63 return StatusCode::SUCCESS;
64
65 MsgStream log( msgSvc(), name() );
66 StatusCode sc;
67
68 // if ( sc.isFailure() ) {
69 // log << MSG::ERROR << "Unable to locate ObjectManager Service" << endmsg;
70 // return sc;
71 // }
72
73 // create all declared Auditors that do not yet exist
74 for ( VectorName::iterator it = m_audNameList.begin(); it != m_audNameList.end(); it++ ) {
75
76 // this is clumsy, but the PropertyMgr won't tell us when my property changes right
77 // under my nose, so I'll have to figure this out the hard way
78 if ( !findAuditor_( *it ) ) { // if auditor does not yet exist
79 IAuditor* aud = newAuditor_( log, *it );
80
81 if ( aud != 0 ) {
82 m_pAudList.push_back( aud );
83 }
84 else {
85 log << MSG::ERROR << "Error constructing Auditor " << *it << endmsg;
86 sc = StatusCode::FAILURE;
87 }
88 }
89 }
90 return sc;
91 }
92
93 // Standard Constructor.
94 // Input: name String with service name
95 // Input: svc Pointer to service locator interface
96 AuditorSvc::AuditorSvc( const std::string& name, ISvcLocator* svc )
97 : base_class(name, svc) {
98 declareProperty("Auditors", m_audNameList );
99 declareProperty("Enable", m_isEnabled = true);
100 m_pAudList.clear();
101 }
102
103 // Destructor.
104 AuditorSvc::~AuditorSvc() {
105 }
106
107 // Inherited Service overrides:
108 //
109 // Initialize the service.
110 StatusCode AuditorSvc::initialize() {
111 StatusCode sc = Service::initialize();
112 if ( sc.isFailure() )
113 return sc;
114
115 // create auditor objects for all named auditors
116 sc = syncAuditors_();
117
118 return sc;
119 }
120
121 // Finalise the service.
122 StatusCode AuditorSvc::finalize() {
123
124 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
125 if((*it)->isEnabled()) {
126 (*it)->sysFinalize().ignore();
127 }
128 (*it)->release();
129 }
130 m_pAudList.clear();
131
132 // Finalize this specific service
133 return Service::finalize();
134 }
135
136 // --------- "Before" methods ---------
137 void AuditorSvc::before(StandardEventType evt, INamedInterface* obj) {
138 if (!isEnabled()) return;
139 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
140 if((*it)->isEnabled()) {
141 (*it)->before(evt,obj);
142 }
143 }
144 }
145
146 void AuditorSvc::before(StandardEventType evt, const std::string &name) {
147 if (!isEnabled()) return;
148 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
149 if((*it)->isEnabled()) {
150 (*it)->before(evt,name);
151 }
152 }
153 }
154
155 void AuditorSvc::before(CustomEventTypeRef evt, INamedInterface* obj) {
156 if (!isEnabled()) return;
157 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
158 if((*it)->isEnabled()) {
159 (*it)->before(evt,obj);
160 }
161 }
162 }
163
164 void AuditorSvc::before(CustomEventTypeRef evt, const std::string &name) {
165 if (!isEnabled()) return;
166 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
167 if((*it)->isEnabled()) {
168 (*it)->before(evt,name);
169 }
170 }
171 }
172
173 // --------- "After" methods ---------
174 void AuditorSvc::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc) {
175 if (!isEnabled()) return;
176 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
177 if((*it)->isEnabled()) {
178 (*it)->after(evt,obj,sc);
179 }
180 }
181 }
182
183 void AuditorSvc::after(StandardEventType evt, const std::string &name, const StatusCode& sc) {
184 if (!isEnabled()) return;
185 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
186 if((*it)->isEnabled()) {
187 (*it)->after(evt,name,sc);
188 }
189 }
190 }
191
192 void AuditorSvc::after(CustomEventTypeRef evt, INamedInterface* obj, const StatusCode& sc) {
193 if (!isEnabled()) return;
194 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
195 if((*it)->isEnabled()) {
196 (*it)->after(evt,obj,sc);
197 }
198 }
199 }
200
201 void AuditorSvc::after(CustomEventTypeRef evt, const std::string &name, const StatusCode& sc) {
202 if (!isEnabled()) return;
203 for (ListAudits::iterator it = m_pAudList.begin() ; it != m_pAudList.end(); it++) {
204 if((*it)->isEnabled()) {
205 (*it)->after(evt,name,sc);
206 }
207 }
208 }
209
210 // --------- obsolete methods ---------
211 #define OBSOLETION(name) \
212 void AuditorSvc::name(INamedInterface*) { \
213 throw GaudiException("The method IAuditor::" #name " is obsolete do not call it.", \
214 "AuditorSvc::" #name , StatusCode::FAILURE); \
215 }
216
217 OBSOLETION(beforeInitialize)
218 OBSOLETION(afterInitialize)
219
220 OBSOLETION(beforeReinitialize)
221 OBSOLETION(afterReinitialize)
222
223 OBSOLETION(beforeExecute)
224 void AuditorSvc::afterExecute(INamedInterface*,const StatusCode&) {
225 throw GaudiException("The method afterExecute is obsolete do not call it.",
226 "AuditorSvc::afterExecute" , StatusCode::FAILURE);
227 }
228
229 OBSOLETION(beforeBeginRun)
230 OBSOLETION(afterBeginRun)
231
232 OBSOLETION(beforeEndRun)
233 OBSOLETION(afterEndRun)
234
235 OBSOLETION(beforeFinalize)
236 OBSOLETION(afterFinalize)
237
238
239 bool AuditorSvc::isEnabled( ) const {
240 return m_isEnabled;
241 }
242
243 StatusCode AuditorSvc::sysInitialize(){
244 return Service::sysInitialize();
245 }
246 StatusCode AuditorSvc::sysFinalize(){
247 return Service::sysFinalize();
248 }
249
250
251 IAuditor* AuditorSvc::getAuditor( const std::string& name ) {
252 // by interactively setting properties, auditors might be out of sync
253 if ( !syncAuditors_().isSuccess() ) {
254 // as we didn't manage to sync auditors, the safest bet is to assume the
255 // worse...
256 // So don't let clients play with an AuditorSvc in an inconsistent state
257 return 0;
258 }
259
260 // search available auditors, returns 0 on error
261 return findAuditor_( name );
262 }