All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 SmartIF<IAuditor> AuditorSvc::newAuditor_( MsgStream& log, const std::string& name ) {
23  // locate the auditor factory, instantiate a new auditor, initialize it
24  StatusCode sc;
25  Gaudi::Utils::TypeNameString item(name) ;
26  SmartIF<IAuditor> aud{ Auditor::Factory::create( item.type(), item.name(), serviceLocator().get() ) };
27  if ( aud ) {
28  if ( m_targetState >= Gaudi::StateMachine::INITIALIZED ) {
29  sc = aud->sysInitialize();
30  if ( sc.isFailure() ) {
31  log << MSG::WARNING << "Failed to initialize Auditor " << name << endmsg;
32  aud.reset();
33  }
34  }
35  } else {
36  log << MSG::WARNING << "Unable to retrieve factory for Auditor " << name << endmsg;
37  }
38  return aud;
39 }
40 
42  // find an auditor by name, return 0 on error
43  const std::string item_name = Gaudi::Utils::TypeNameString(name).name();
45  [&](const IAuditor* i) { return i->name() == item_name; });
46  return SmartIF<IAuditor>{ it != std::end(m_pAudList) ? *it : nullptr };
47 }
48 
50  if ( m_audNameList.size() == m_pAudList.size() )
51  return StatusCode::SUCCESS;
52 
53  StatusCode sc;
54 
55 // if ( sc.isFailure() ) {
56 // error() << "Unable to locate ObjectManager Service" << endmsg;
57 // return sc;
58 // }
59 
60  // create all declared Auditors that do not yet exist
61  for ( auto& it : m_audNameList ) {
62 
63  // this is clumsy, but the PropertyHolder won't tell us when my property changes right
64  // under my nose, so I'll have to figure this out the hard way
65  if ( !findAuditor_( it ) ) { // if auditor does not yet exist
66  auto aud = newAuditor_( msgStream(), it );
67  if ( aud ) {
69  } else {
70  error() << "Error constructing Auditor " << it << endmsg;
72  }
73  }
74  }
75  return sc;
76 }
77 
78 // Inherited Service overrides:
79 //
80  // Initialize the service.
83  if ( sc.isFailure() )
84  return sc;
85 
86  // create auditor objects for all named auditors
87  sc = syncAuditors_();
88 
89  return sc;
90 }
91 
92  // Finalise the service.
94 
95  for (auto& it : m_pAudList ) {
96  if(it->isEnabled()) it->sysFinalize().ignore();
97  }
98  m_pAudList.clear();
99 
100  // Finalize this specific service
101  return Service::finalize();
102 }
103 
104 // --------- "Before" methods ---------
105 void AuditorSvc::before(StandardEventType evt, INamedInterface* obj) {
106  if (!isEnabled()) return;
107  for (auto& it : m_pAudList ) {
108  if(it->isEnabled()) it->before(evt,obj);
109  }
110 }
111 
112 void AuditorSvc::before(StandardEventType evt, const std::string &name) {
113  if (!isEnabled()) return;
114  for (auto& it : m_pAudList ) {
115  if(it->isEnabled()) it->before(evt,name);
116  }
117 }
118 
119 void AuditorSvc::before(CustomEventTypeRef evt, INamedInterface* obj) {
120  if (!isEnabled()) return;
121  for (auto& it : m_pAudList) {
122  if(it->isEnabled()) it->before(evt,obj);
123  }
124 }
125 
126 void AuditorSvc::before(CustomEventTypeRef evt, const std::string &name) {
127  if (!isEnabled()) return;
128  for (auto& it : m_pAudList ) {
129  if(it->isEnabled()) it->before(evt,name);
130  }
131 }
132 
133 // --------- "After" methods ---------
134 void AuditorSvc::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc) {
135  if (!isEnabled()) return;
136  for (auto& it : m_pAudList ) {
137  if(it->isEnabled()) it->after(evt,obj,sc);
138  }
139 }
140 
141 void AuditorSvc::after(StandardEventType evt, const std::string &name, const StatusCode& sc) {
142  if (!isEnabled()) return;
143  for (auto& it : m_pAudList ) {
144  if(it->isEnabled()) it->after(evt,name,sc);
145  }
146 }
147 
148 void AuditorSvc::after(CustomEventTypeRef evt, INamedInterface* obj, const StatusCode& sc) {
149  if (!isEnabled()) return;
150  for (auto& it : m_pAudList ) {
151  if(it->isEnabled()) it->after(evt,obj,sc);
152  }
153 }
154 
155 void AuditorSvc::after(CustomEventTypeRef evt, const std::string &name, const StatusCode& sc) {
156  if (!isEnabled()) return;
157  for (auto& it : m_pAudList) {
158  if(it->isEnabled()) it->after(evt,name,sc);
159  }
160 }
161 
162 // --------- obsolete methods ---------
163 #define OBSOLETION(name) \
164  void AuditorSvc::name(INamedInterface*) { \
165  throw GaudiException("The method IAuditor::" #name " is obsolete do not call it.", \
166  "AuditorSvc::" #name , StatusCode::FAILURE); \
167  }
168 
171 
174 
177  throw GaudiException("The method afterExecute is obsolete do not call it.",
178  "AuditorSvc::afterExecute" , StatusCode::FAILURE);
179 }
180 
183 
186 
189 
190 
191 bool AuditorSvc::isEnabled( ) const {
192  return m_isEnabled;
193 }
194 
196  return Service::sysInitialize();
197 }
199  return Service::sysFinalize();
200 }
201 
202 
204  // by interactively setting properties, auditors might be out of sync
205  if ( !syncAuditors_().isSuccess() ) {
206  // as we didn't manage to sync auditors, the safest bet is to assume the
207  // worse...
208  // So don't let clients play with an AuditorSvc in an inconsistent state
209  return nullptr;
210  }
211 
212  // search available auditors, returns 0 on error
213  return findAuditor_( name );
214 }
void beforeBeginRun(INamedInterface *ini) override
StatusCode initialize() override
Definition: AuditorSvc.cpp:81
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:64
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
Define general base for Gaudi exception.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
StatusCode finalize() override
Definition: Service.cpp:174
Gaudi::Property< bool > m_isEnabled
Definition: AuditorSvc.h:95
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:134
STL namespace.
void afterReinitialize(INamedInterface *ini) override
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:198
void afterExecute(INamedInterface *ini, const StatusCode &) override
Definition: AuditorSvc.cpp:176
T end(T...args)
void beforeEndRun(INamedInterface *ini) override
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
std::vector< SmartIF< IAuditor > > m_pAudList
Definition: AuditorSvc.h:98
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: AuditorSvc.cpp:105
STL class.
void beforeExecute(INamedInterface *ini) override
T push_back(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Helper class to parse a string of format "type/name".
StatusCode sysInitialize() override
Definition: AuditorSvc.cpp:195
void beforeReinitialize(INamedInterface *ini) override
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void beforeInitialize(INamedInterface *ini) override
void afterInitialize(INamedInterface *ini) override
void afterEndRun(INamedInterface *ini) override
StatusCode sysFinalize() override
Finalize Service.
Definition: Service.cpp:144
T move(T...args)
void afterBeginRun(INamedInterface *ini) override
SmartIF< IAuditor > findAuditor_(const std::string &)
Definition: AuditorSvc.cpp:41
IInterface compliant class extending IInterface with the name() method.
T find_if(T...args)
T size(T...args)
void beforeFinalize(INamedInterface *ini) override
StatusCode finalize() override
Definition: AuditorSvc.cpp:93
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:163
T begin(T...args)
const std::string & type() const
MsgStream & msgStream() const
Return an uninitialized MsgStream.
IAuditor * getAuditor(const std::string &name) override
Definition: AuditorSvc.cpp:203
SmartIF< IAuditor > newAuditor_(MsgStream &, const std::string &)
Definition: AuditorSvc.cpp:22
const std::string & name() const
void afterFinalize(INamedInterface *ini) override
void ignore() const
Definition: StatusCode.h:106
StatusCode syncAuditors_()
Definition: AuditorSvc.cpp:49
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Gaudi::Property< std::vector< std::string > > m_audNameList
Definition: AuditorSvc.h:94
virtual const std::string & name() const =0
Retrieve the name of the instance.
evt
Definition: IOTest.py:85
bool isEnabled() const override
Definition: AuditorSvc.cpp:191
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:26