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;
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 PropertyMgr 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 // Standard Constructor.
79 // Input: name String with service name
80 // Input: svc Pointer to service locator interface
82 : base_class(name, svc) {
83  declareProperty("Auditors", m_audNameList );
84  declareProperty("Enable", m_isEnabled = true);
85 }
86 
87 // Inherited Service overrides:
88 //
89  // Initialize the service.
92  if ( sc.isFailure() )
93  return sc;
94 
95  // create auditor objects for all named auditors
96  sc = syncAuditors_();
97 
98  return sc;
99 }
100 
101  // Finalise the service.
103 
104  for (auto& it : m_pAudList ) {
105  if(it->isEnabled()) it->sysFinalize().ignore();
106  }
107  m_pAudList.clear();
108 
109  // Finalize this specific service
110  return Service::finalize();
111 }
112 
113 // --------- "Before" methods ---------
114 void AuditorSvc::before(StandardEventType evt, INamedInterface* obj) {
115  if (!isEnabled()) return;
116  for (auto& it : m_pAudList ) {
117  if(it->isEnabled()) it->before(evt,obj);
118  }
119 }
120 
121 void AuditorSvc::before(StandardEventType evt, const std::string &name) {
122  if (!isEnabled()) return;
123  for (auto& it : m_pAudList ) {
124  if(it->isEnabled()) it->before(evt,name);
125  }
126 }
127 
128 void AuditorSvc::before(CustomEventTypeRef evt, INamedInterface* obj) {
129  if (!isEnabled()) return;
130  for (auto& it : m_pAudList) {
131  if(it->isEnabled()) it->before(evt,obj);
132  }
133 }
134 
135 void AuditorSvc::before(CustomEventTypeRef evt, const std::string &name) {
136  if (!isEnabled()) return;
137  for (auto& it : m_pAudList ) {
138  if(it->isEnabled()) it->before(evt,name);
139  }
140 }
141 
142 // --------- "After" methods ---------
143 void AuditorSvc::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc) {
144  if (!isEnabled()) return;
145  for (auto& it : m_pAudList ) {
146  if(it->isEnabled()) it->after(evt,obj,sc);
147  }
148 }
149 
150 void AuditorSvc::after(StandardEventType evt, const std::string &name, const StatusCode& sc) {
151  if (!isEnabled()) return;
152  for (auto& it : m_pAudList ) {
153  if(it->isEnabled()) it->after(evt,name,sc);
154  }
155 }
156 
157 void AuditorSvc::after(CustomEventTypeRef evt, INamedInterface* obj, const StatusCode& sc) {
158  if (!isEnabled()) return;
159  for (auto& it : m_pAudList ) {
160  if(it->isEnabled()) it->after(evt,obj,sc);
161  }
162 }
163 
164 void AuditorSvc::after(CustomEventTypeRef evt, const std::string &name, const StatusCode& sc) {
165  if (!isEnabled()) return;
166  for (auto& it : m_pAudList) {
167  if(it->isEnabled()) it->after(evt,name,sc);
168  }
169 }
170 
171 // --------- obsolete methods ---------
172 #define OBSOLETION(name) \
173  void AuditorSvc::name(INamedInterface*) { \
174  throw GaudiException("The method IAuditor::" #name " is obsolete do not call it.", \
175  "AuditorSvc::" #name , StatusCode::FAILURE); \
176  }
177 
178 OBSOLETION(beforeInitialize)
179 OBSOLETION(afterInitialize)
180 
181 OBSOLETION(beforeReinitialize)
182 OBSOLETION(afterReinitialize)
183 
184 OBSOLETION(beforeExecute)
185 void AuditorSvc::afterExecute(INamedInterface*,const StatusCode&) {
186  throw GaudiException("The method afterExecute is obsolete do not call it.",
187  "AuditorSvc::afterExecute" , StatusCode::FAILURE);
188 }
189 
190 OBSOLETION(beforeBeginRun)
191 OBSOLETION(afterBeginRun)
192 
193 OBSOLETION(beforeEndRun)
194 OBSOLETION(afterEndRun)
195 
196 OBSOLETION(beforeFinalize)
197 OBSOLETION(afterFinalize)
198 
199 
200 bool AuditorSvc::isEnabled( ) const {
201  return m_isEnabled;
202 }
203 
205  return Service::sysInitialize();
206 }
208  return Service::sysFinalize();
209 }
210 
211 
213  // by interactively setting properties, auditors might be out of sync
214  if ( !syncAuditors_().isSuccess() ) {
215  // as we didn't manage to sync auditors, the safest bet is to assume the
216  // worse...
217  // So don't let clients play with an AuditorSvc in an inconsistent state
218  return nullptr;
219  }
220 
221  // search available auditors, returns 0 on error
222  return findAuditor_( name );
223 }
StatusCode initialize() override
Definition: AuditorSvc.cpp:90
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:68
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
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:25
StatusCode finalize() override
Definition: Service.cpp:193
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:143
STL namespace.
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:207
AuditorSvc(const std::string &name, ISvcLocator *svc)
Definition: AuditorSvc.cpp:81
T end(T...args)
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
std::vector< SmartIF< IAuditor > > m_pAudList
Definition: AuditorSvc.h:103
#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:114
bool isEnabled() const override
Definition: AuditorSvc.cpp:200
virtual const std::string & name() const =0
Retrieve the name of the instance.
STL class.
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".
Definition: TypeNameString.h:9
StatusCode sysInitialize() override
Definition: AuditorSvc.cpp:204
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode sysFinalize() override
Finalize Service.
Definition: Service.cpp:158
T move(T...args)
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)
StatusCode finalize() override
Definition: AuditorSvc.cpp:102
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:172
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:212
tuple item
print s1,s2
Definition: ana.py:146
SmartIF< IAuditor > newAuditor_(MsgStream &, const std::string &)
Definition: AuditorSvc.cpp:22
std::vector< std::string > m_audNameList
Definition: AuditorSvc.h:100
bool m_isEnabled
Definition: AuditorSvc.h:106
const std::string & name() const
void ignore() const
Definition: StatusCode.h:108
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
StatusCode syncAuditors_()
Definition: AuditorSvc.cpp:49
list i
Definition: ana.py:128
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
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:26