| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

AuditorSvc.cpp
Go to the documentation of this file.
1 // Include Files
2 #include "AuditorSvc.h"
3 #include "GaudiKernel/Auditor.h"
4 #include "GaudiKernel/GaudiException.h"
5 #include "GaudiKernel/IAuditor.h"
6 #include "GaudiKernel/INamedInterface.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/MsgStream.h"
9 #include "GaudiKernel/TypeNameString.h"
10
11 // Instantiation of a static factory class used by clients to create
12 // instances of this service
13 DECLARE_COMPONENT( AuditorSvc )
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
42 SmartIF<IAuditor> AuditorSvc::findAuditor_( const std::string& name )
43 {
44 // find an auditor by name, return 0 on error
45 const std::string item_name = Gaudi::Utils::TypeNameString( name ).name();
46 auto it = std::find_if( std::begin( m_pAudList ), std::end( m_pAudList ),
47 [&]( const IAuditor* i ) { return i->name() == item_name; } );
48 return SmartIF<IAuditor>{it != std::end( m_pAudList ) ? *it : nullptr};
49 }
50
51 StatusCode AuditorSvc::syncAuditors_()
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;
73 sc = StatusCode::FAILURE;
74 }
75 }
76 }
77 return sc;
78 }
79
80 // Inherited Service overrides:
81 //
82 // Initialize the service.
83 StatusCode AuditorSvc::initialize()
84 {
85 StatusCode sc = Service::initialize();
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.
95 StatusCode AuditorSvc::finalize()
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
181 OBSOLETION( beforeInitialize )
182 OBSOLETION( afterInitialize )
183
184 OBSOLETION( beforeReinitialize )
185 OBSOLETION( afterReinitialize )
186
187 OBSOLETION( beforeExecute )
188 void AuditorSvc::afterExecute( INamedInterface*, const StatusCode& )
189 {
190 throw GaudiException( "The method afterExecute is obsolete do not call it.", "AuditorSvc::afterExecute",
191 StatusCode::FAILURE );
192 }
193
194 OBSOLETION( beforeBeginRun )
195 OBSOLETION( afterBeginRun )
196
197 OBSOLETION( beforeEndRun )
198 OBSOLETION( afterEndRun )
199
200 OBSOLETION( beforeFinalize )
201 OBSOLETION( afterFinalize )
202
203 bool AuditorSvc::isEnabled() const { return m_isEnabled; }
204
205 StatusCode AuditorSvc::sysInitialize() { return Service::sysInitialize(); }
206 StatusCode AuditorSvc::sysFinalize() { return Service::sysFinalize(); }
207
208 IAuditor* AuditorSvc::getAuditor( const std::string& name )
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 }
AuditorSvc::beforeBeginRun
void beforeBeginRun(INamedInterface *ini) override
AuditorSvc::initialize
StatusCode initialize() override
Definition: AuditorSvc.cpp:83
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:17
StatusCode::SUCCESS
Definition: StatusCode.h:31
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::FAILURE
Definition: StatusCode.h:31
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:174
MsgStream.h
IAuditor.h
OBSOLETION
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:174
AuditorSvc::m_isEnabled
Gaudi::Property< bool > m_isEnabled
Definition: AuditorSvc.h:95
AuditorSvc::after
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:141
AuditorSvc.h
std
STL namespace.
AuditorSvc::afterReinitialize
void afterReinitialize(INamedInterface *ini) override
AuditorSvc::sysFinalize
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:206
AuditorSvc::afterExecute
void afterExecute(INamedInterface *ini, const StatusCode &) override
Definition: AuditorSvc.cpp:188
std::end
T end(T...args)
AuditorSvc::beforeEndRun
void beforeEndRun(INamedInterface *ini) override
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
AuditorSvc
Definition: AuditorSvc.h:18
AuditorSvc::m_pAudList
std::vector< SmartIF< IAuditor > > m_pAudList
Definition: AuditorSvc.h:98
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
AuditorSvc::before
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: AuditorSvc.cpp:108
std::string
STL class.
AuditorSvc::beforeExecute
void beforeExecute(INamedInterface *ini) override
std::vector::push_back
T push_back(T...args)
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
INamedInterface.h
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:12
AuditorSvc::sysInitialize
StatusCode sysInitialize() override
Definition: AuditorSvc.cpp:205
AuditorSvc::beforeReinitialize
void beforeReinitialize(INamedInterface *ini) override
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
GaudiException.h
AuditorSvc::beforeInitialize
void beforeInitialize(INamedInterface *ini) override
AuditorSvc::afterInitialize
void afterInitialize(INamedInterface *ini) override
AuditorSvc::afterEndRun
void afterEndRun(INamedInterface *ini) override
Service::sysFinalize
StatusCode sysFinalize() override
Finalize Service.
Definition: Service.cpp:144
std::move
T move(T...args)
AuditorSvc::afterBeginRun
void afterBeginRun(INamedInterface *ini) override
AuditorSvc::findAuditor_
SmartIF< IAuditor > findAuditor_(const std::string &)
Definition: AuditorSvc.cpp:42
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
std::find_if
T find_if(T...args)
std::vector::size
T size(T...args)
AuditorSvc::beforeFinalize
void beforeFinalize(INamedInterface *ini) override
AuditorSvc::finalize
StatusCode finalize() override
Definition: AuditorSvc.cpp:95
std::begin
T begin(T...args)
Gaudi::Utils::TypeNameString::type
const std::string & type() const
Definition: TypeNameString.h:39
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition: CommonMessaging.h:78
AuditorSvc::getAuditor
IAuditor * getAuditor(const std::string &name) override
Definition: AuditorSvc.cpp:208
TypeNameString.h
AuditorSvc::newAuditor_
SmartIF< IAuditor > newAuditor_(MsgStream &, const std::string &)
Definition: AuditorSvc.cpp:22
MSG::WARNING
Definition: IMessageSvc.h:16
Gaudi::Utils::TypeNameString::name
const std::string & name() const
Definition: TypeNameString.h:40
AuditorSvc::afterFinalize
void afterFinalize(INamedInterface *ini) override
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:109
AuditorSvc::syncAuditors_
StatusCode syncAuditors_()
Definition: AuditorSvc.cpp:51
IAuditor
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
Auditor.h
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
AuditorSvc::m_audNameList
Gaudi::Property< std::vector< std::string > > m_audNameList
Definition: AuditorSvc.h:94
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
IOTest.evt
evt
Definition: IOTest.py:96
AuditorSvc::isEnabled
bool isEnabled() const override
Definition: AuditorSvc.cpp:203
Gaudi.Configuration.log
log
Definition: Configuration.py:13
Service::sysInitialize
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:26