The Gaudi Framework  v29r0 (ff2e7097)
AuditorSvc.cpp
Go to the documentation of this file.
1 // Include Files
2 #include "AuditorSvc.h"
3 #include "GaudiKernel/Auditor.h"
5 #include "GaudiKernel/IAuditor.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 {
24  // locate the auditor factory, instantiate a new auditor, initialize it
25  StatusCode sc;
26  Gaudi::Utils::TypeNameString item( name );
27  SmartIF<IAuditor> aud{Auditor::Factory::create( item.type(), item.name(), serviceLocator().get() )};
28  if ( aud ) {
29  if ( m_targetState >= Gaudi::StateMachine::INITIALIZED ) {
30  sc = aud->sysInitialize();
31  if ( sc.isFailure() ) {
32  log << MSG::WARNING << "Failed to initialize Auditor " << name << endmsg;
33  aud.reset();
34  }
35  }
36  } else {
37  log << MSG::WARNING << "Unable to retrieve factory for Auditor " << name << endmsg;
38  }
39  return aud;
40 }
41 
43 {
44  // find an auditor by name, return 0 on error
45  const std::string item_name = Gaudi::Utils::TypeNameString( name ).name();
47  [&]( const IAuditor* i ) { return i->name() == item_name; } );
48  return SmartIF<IAuditor>{it != std::end( m_pAudList ) ? *it : nullptr};
49 }
50 
52 {
53  if ( m_audNameList.size() == m_pAudList.size() ) return StatusCode::SUCCESS;
54 
55  StatusCode sc;
56 
57  // if ( sc.isFailure() ) {
58  // error() << "Unable to locate ObjectManager Service" << endmsg;
59  // return sc;
60  // }
61 
62  // create all declared Auditors that do not yet exist
63  for ( auto& it : m_audNameList ) {
64 
65  // this is clumsy, but the PropertyHolder won't tell us when my property changes right
66  // under my nose, so I'll have to figure this out the hard way
67  if ( !findAuditor_( it ) ) { // if auditor does not yet exist
68  auto aud = newAuditor_( msgStream(), it );
69  if ( aud ) {
70  m_pAudList.push_back( std::move( aud ) );
71  } else {
72  error() << "Error constructing Auditor " << it << endmsg;
74  }
75  }
76  }
77  return sc;
78 }
79 
80 // Inherited Service overrides:
81 //
82 // Initialize the service.
84 {
86  if ( sc.isFailure() ) return sc;
87 
88  // create auditor objects for all named auditors
89  sc = syncAuditors_();
90 
91  return sc;
92 }
93 
94 // Finalise the service.
96 {
97 
98  for ( auto& it : m_pAudList ) {
99  if ( it->isEnabled() ) it->sysFinalize().ignore();
100  }
101  m_pAudList.clear();
102 
103  // Finalize this specific service
104  return Service::finalize();
105 }
106 
107 // --------- "Before" methods ---------
108 void AuditorSvc::before( StandardEventType evt, INamedInterface* obj )
109 {
110  if ( !isEnabled() ) return;
111  for ( auto& it : m_pAudList ) {
112  if ( it->isEnabled() ) it->before( evt, obj );
113  }
114 }
115 
116 void AuditorSvc::before( StandardEventType evt, const std::string& name )
117 {
118  if ( !isEnabled() ) return;
119  for ( auto& it : m_pAudList ) {
120  if ( it->isEnabled() ) it->before( evt, name );
121  }
122 }
123 
124 void AuditorSvc::before( CustomEventTypeRef evt, INamedInterface* obj )
125 {
126  if ( !isEnabled() ) return;
127  for ( auto& it : m_pAudList ) {
128  if ( it->isEnabled() ) it->before( evt, obj );
129  }
130 }
131 
132 void AuditorSvc::before( CustomEventTypeRef evt, const std::string& name )
133 {
134  if ( !isEnabled() ) return;
135  for ( auto& it : m_pAudList ) {
136  if ( it->isEnabled() ) it->before( evt, name );
137  }
138 }
139 
140 // --------- "After" methods ---------
141 void AuditorSvc::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc )
142 {
143  if ( !isEnabled() ) return;
144  for ( auto& it : m_pAudList ) {
145  if ( it->isEnabled() ) it->after( evt, obj, sc );
146  }
147 }
148 
149 void AuditorSvc::after( StandardEventType evt, const std::string& name, const StatusCode& sc )
150 {
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 {
159  if ( !isEnabled() ) return;
160  for ( auto& it : m_pAudList ) {
161  if ( it->isEnabled() ) it->after( evt, obj, sc );
162  }
163 }
164 
165 void AuditorSvc::after( CustomEventTypeRef evt, const std::string& name, const StatusCode& sc )
166 {
167  if ( !isEnabled() ) return;
168  for ( auto& it : m_pAudList ) {
169  if ( it->isEnabled() ) it->after( evt, name, sc );
170  }
171 }
172 
173 // --------- obsolete methods ---------
174 #define OBSOLETION( name ) \
175  void AuditorSvc::name( INamedInterface* ) \
176  { \
177  throw GaudiException( "The method IAuditor::" #name " is obsolete do not call it.", "AuditorSvc::" #name, \
178  StatusCode::FAILURE ); \
179  }
180 
183 
186 
189 {
190  throw GaudiException( "The method afterExecute is obsolete do not call it.", "AuditorSvc::afterExecute",
192 }
193 
196 
199 
202 
203 bool AuditorSvc::isEnabled() const { return m_isEnabled; }
204 
207 
209 {
210  // by interactively setting properties, auditors might be out of sync
211  if ( !syncAuditors_().isSuccess() ) {
212  // as we didn't manage to sync auditors, the safest bet is to assume the
213  // worse...
214  // So don't let clients play with an AuditorSvc in an inconsistent state
215  return nullptr;
216  }
217 
218  // search available auditors, returns 0 on error
219  return findAuditor_( name );
220 }
void beforeBeginRun(INamedInterface *ini) override
StatusCode initialize() override
Definition: AuditorSvc.cpp:83
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:15
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
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:174
Gaudi::Property< bool > m_isEnabled
Definition: AuditorSvc.h:95
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:141
STL namespace.
void afterReinitialize(INamedInterface *ini) override
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:206
void afterExecute(INamedInterface *ini, const StatusCode &) override
Definition: AuditorSvc.cpp:188
T end(T...args)
void beforeEndRun(INamedInterface *ini) override
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
std::vector< SmartIF< IAuditor > > m_pAudList
Definition: AuditorSvc.h:98
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: AuditorSvc.cpp:108
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:205
void beforeReinitialize(INamedInterface *ini) override
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
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:42
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:95
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:208
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:109
StatusCode syncAuditors_()
Definition: AuditorSvc.cpp:51
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:209
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:96
bool isEnabled() const override
Definition: AuditorSvc.cpp:203
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:26