Gaudi Framework, version v23r9

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

Generated at Thu Jul 18 2013 12:18:01 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004