Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
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
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  // 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() ).release()};
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() ) return StatusCode::SUCCESS;
51 
52  StatusCode sc;
53 
54  // if ( sc.isFailure() ) {
55  // error() << "Unable to locate ObjectManager Service" << endmsg;
56  // return sc;
57  // }
58 
59  // create all declared Auditors that do not yet exist
60  for ( auto& it : m_audNameList ) {
61 
62  // this is clumsy, but the PropertyHolder won't tell us when my property changes right
63  // under my nose, so I'll have to figure this out the hard way
64  if ( !findAuditor_( it ) ) { // if auditor does not yet exist
65  auto aud = newAuditor_( msgStream(), it );
66  if ( aud ) {
67  m_pAudList.push_back( std::move( aud ) );
68  } else {
69  error() << "Error constructing Auditor " << it << endmsg;
71  }
72  }
73  }
74  return sc;
75 }
76 
77 // Inherited Service overrides:
78 //
79 // Initialize the service.
82  if ( sc.isFailure() ) return sc;
83 
84  // create auditor objects for all named auditors
85  sc = syncAuditors_();
86 
87  return sc;
88 }
89 
90 // Finalise the service.
92 
93  for ( auto& it : m_pAudList ) {
94  if ( it->isEnabled() ) it->sysFinalize().ignore();
95  }
96  m_pAudList.clear();
97 
98  // Finalize this specific service
99  return Service::finalize();
100 }
101 
102 // --------- "Before" methods ---------
103 void AuditorSvc::before( StandardEventType evt, INamedInterface* obj ) {
104  if ( !isEnabled() ) return;
105  for ( auto& it : m_pAudList ) {
106  if ( it->isEnabled() ) it->before( evt, obj );
107  }
108 }
109 
110 void AuditorSvc::before( StandardEventType evt, const std::string& name ) {
111  if ( !isEnabled() ) return;
112  for ( auto& it : m_pAudList ) {
113  if ( it->isEnabled() ) it->before( evt, name );
114  }
115 }
116 
117 void AuditorSvc::before( CustomEventTypeRef evt, INamedInterface* obj ) {
118  if ( !isEnabled() ) return;
119  for ( auto& it : m_pAudList ) {
120  if ( it->isEnabled() ) it->before( evt, obj );
121  }
122 }
123 
124 void AuditorSvc::before( CustomEventTypeRef evt, const std::string& name ) {
125  if ( !isEnabled() ) return;
126  for ( auto& it : m_pAudList ) {
127  if ( it->isEnabled() ) it->before( evt, name );
128  }
129 }
130 
131 // --------- "After" methods ---------
132 void AuditorSvc::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc ) {
133  if ( !isEnabled() ) return;
134  for ( auto& it : m_pAudList ) {
135  if ( it->isEnabled() ) it->after( evt, obj, sc );
136  }
137 }
138 
139 void AuditorSvc::after( StandardEventType evt, const std::string& name, const StatusCode& sc ) {
140  if ( !isEnabled() ) return;
141  for ( auto& it : m_pAudList ) {
142  if ( it->isEnabled() ) it->after( evt, name, sc );
143  }
144 }
145 
146 void AuditorSvc::after( CustomEventTypeRef evt, INamedInterface* obj, const StatusCode& sc ) {
147  if ( !isEnabled() ) return;
148  for ( auto& it : m_pAudList ) {
149  if ( it->isEnabled() ) it->after( evt, obj, sc );
150  }
151 }
152 
153 void AuditorSvc::after( CustomEventTypeRef evt, const std::string& name, const StatusCode& sc ) {
154  if ( !isEnabled() ) return;
155  for ( auto& it : m_pAudList ) {
156  if ( it->isEnabled() ) it->after( evt, name, sc );
157  }
158 }
159 
160 // --------- obsolete methods ---------
161 #define OBSOLETION( name ) \
162  void AuditorSvc::name( INamedInterface* ) { \
163  throw GaudiException( "The method IAuditor::" #name " is obsolete do not call it.", "AuditorSvc::" #name, \
164  StatusCode::FAILURE ); \
165  }
166 
169 
172 
175  throw GaudiException( "The method afterExecute is obsolete do not call it.", "AuditorSvc::afterExecute",
177 }
178 
181 
184 
187 
188 bool AuditorSvc::isEnabled() const { return m_isEnabled; }
189 
192 
194  // by interactively setting properties, auditors might be out of sync
195  if ( !syncAuditors_().isSuccess() ) {
196  // as we didn't manage to sync auditors, the safest bet is to assume the
197  // worse...
198  // So don't let clients play with an AuditorSvc in an inconsistent state
199  return nullptr;
200  }
201 
202  // search available auditors, returns 0 on error
203  return findAuditor_( name );
204 }
void beforeBeginRun(INamedInterface *ini) override
StatusCode initialize() override
Definition: AuditorSvc.cpp:80
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:60
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:274
StatusCode finalize() override
Definition: Service.cpp:164
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:161
Gaudi::Property< bool > m_isEnabled
Definition: AuditorSvc.h:91
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:132
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL namespace.
void afterReinitialize(INamedInterface *ini) override
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:191
void afterExecute(INamedInterface *ini, const StatusCode &) override
Definition: AuditorSvc.cpp:174
T end(T...args)
void beforeEndRun(INamedInterface *ini) override
bool isFailure() const
Definition: StatusCode.h:130
std::vector< SmartIF< IAuditor > > m_pAudList
Definition: AuditorSvc.h:94
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: AuditorSvc.cpp:103
STL class.
#define DECLARE_COMPONENT(type)
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:190
void beforeReinitialize(INamedInterface *ini) override
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
void beforeInitialize(INamedInterface *ini) override
void afterInitialize(INamedInterface *ini) override
void afterEndRun(INamedInterface *ini) override
StatusCode sysFinalize() override
Finalize Service.
Definition: Service.cpp:135
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:91
T begin(T...args)
const std::string & type() const
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
MsgStream & msgStream() const
Return an uninitialized MsgStream.
IAuditor * getAuditor(const std::string &name) override
Definition: AuditorSvc.cpp:193
constexpr static const auto FAILURE
Definition: StatusCode.h:86
SmartIF< IAuditor > newAuditor_(MsgStream &, const std::string &)
Definition: AuditorSvc.cpp:22
const std::string & name() const
void afterFinalize(INamedInterface *ini) override
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:192
Gaudi::Property< std::vector< std::string > > m_audNameList
Definition: AuditorSvc.h:90
virtual const std::string & name() const =0
Retrieve the name of the instance.
evt
Definition: IOTest.py:94
bool isEnabled() const override
Definition: AuditorSvc.cpp:188
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:24