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
4 #include "GaudiKernel/IAuditor.h"
6 #include "GaudiKernel/Auditor.h"
9 #include "AuditorSvc.h"
10 
11 // Instantiation of a static factory class used by clients to create
12 // instances of this service
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;
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 
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;
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.
105 }
106 
107 // Inherited Service overrides:
108 //
109  // Initialize the service.
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.
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 ---------
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 
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 ---------
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 
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 
244  return Service::sysInitialize();
245 }
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 }
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: AuditorSvc.cpp:110
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
StandardEventType
Defines the standard (= used by the framework) auditable event types.
Definition: IAuditor.h:24
virtual void before(StandardEventType, INamedInterface *)
The following methods are meant to be implemented by the child class...
Definition: AuditorSvc.cpp:137
virtual IAuditor * getAuditor(const std::string &name)
management functionality: retrieve an Auditor
Definition: AuditorSvc.cpp:251
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
const CustomEventType & CustomEventTypeRef
Used in function calls for optimization purposes.
Definition: IAuditor.h:41
virtual ~AuditorSvc()
Definition: AuditorSvc.cpp:104
virtual bool isEnabled() const
Tell if the auditor is enabled or not.
Definition: AuditorSvc.cpp:239
AuditorSvc(const std::string &name, ISvcLocator *svc)
Definition: AuditorSvc.cpp:96
virtual StatusCode sysFinalize()
Finalize Service.
Definition: Service.cpp:164
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:72
VectorName m_audNameList
Definition: AuditorSvc.h:104
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
virtual void after(StandardEventType, INamedInterface *, const StatusCode &)
Audit the end of a standard "event".
Definition: AuditorSvc.cpp:174
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
IAuditor * newAuditor_(MsgStream &, const std::string &)
Definition: AuditorSvc.cpp:22
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
IAuditor * findAuditor_(const std::string &)
Definition: AuditorSvc.cpp:46
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: AuditorSvc.cpp:122
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
virtual StatusCode sysInitialize()
Initialize Service.
Definition: Service.cpp:37
virtual StatusCode sysInitialize()
Initialize Service.
Definition: AuditorSvc.cpp:243
IInterface compliant class extending IInterface with the name() method.
virtual unsigned long release()=0
Release Interface instance.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:74
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:211
const std::string & type() const
tuple item
print s1,s2
Definition: ana.py:146
Templated class to add the standard messaging functionalities.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
bool m_isEnabled
Definition: AuditorSvc.h:110
const std::string & name() const
void ignore() const
Definition: StatusCode.h:94
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:211
StatusCode syncAuditors_()
Definition: AuditorSvc.cpp:61
ListAudits m_pAudList
Definition: AuditorSvc.h:107
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:199
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode sysFinalize()
Finalize Service.
Definition: AuditorSvc.cpp:246
virtual StatusCode sysInitialize()=0
Used by AuditorSvc.