The Gaudi Framework  v32r2 (46d42edc)
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;
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 
167 OBSOLETION( beforeInitialize )
168 OBSOLETION( afterInitialize )
169 
170 OBSOLETION( beforeReinitialize )
171 OBSOLETION( afterReinitialize )
172 
173 OBSOLETION( beforeExecute )
174 void AuditorSvc::afterExecute( INamedInterface*, const StatusCode& ) {
175  throw GaudiException( "The method afterExecute is obsolete do not call it.", "AuditorSvc::afterExecute",
177 }
178 
179 OBSOLETION( beforeBeginRun )
180 OBSOLETION( afterBeginRun )
181 
182 OBSOLETION( beforeEndRun )
183 OBSOLETION( afterEndRun )
184 
185 OBSOLETION( beforeFinalize )
186 OBSOLETION( afterFinalize )
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 }
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.
StatusCode finalize() override
Definition: Service.cpp:164
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:132
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL namespace.
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:191
const std::string & type() const
T end(T... args)
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
bool isEnabled() const override
Definition: AuditorSvc.cpp:188
virtual const std::string & name() const =0
Retrieve the name of the instance.
STL class.
#define DECLARE_COMPONENT(type)
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
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
const std::string & name() const
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
T clear(T... args)
MsgStream & msgStream() const
Return an uninitialized MsgStream.
StatusCode sysFinalize() override
Finalize Service.
Definition: Service.cpp:135
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)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
StatusCode finalize() override
Definition: AuditorSvc.cpp:91
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:161
T begin(T... args)
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
bool isFailure() const
Definition: StatusCode.h:130
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
evt
Definition: IOTest.py:95
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:24