| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 "GaudiKernel/MsgStream.h"
3 #include "GaudiKernel/ISvcLocator.h"
4 #include "GaudiKernel/IAuditor.h"
5 #include "GaudiKernel/INamedInterface.h"
6 #include "GaudiKernel/Auditor.h"
7 #include "GaudiKernel/TypeNameString.h"
8 #include "GaudiKernel/GaudiException.h"
9 #include "AuditorSvc.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 // 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() ) };
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
41 SmartIF<IAuditor> AuditorSvc::findAuditor_( const std::string& name ) {
42 // find an auditor by name, return 0 on error
43 const std::string item_name = Gaudi::Utils::TypeNameString(name).name();
44 auto it = std::find_if( std::begin(m_pAudList), std::end(m_pAudList),
45 [&](const IAuditor* i) { return i->name() == item_name; });
46 return SmartIF<IAuditor>{ it != std::end(m_pAudList) ? *it : nullptr };
47 }
48
49 StatusCode AuditorSvc::syncAuditors_() {
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 PropertyHolder 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 ) {
68 m_pAudList.push_back( std::move(aud) );
69 } else {
70 error() << "Error constructing Auditor " << it << endmsg;
71 sc = StatusCode::FAILURE;
72 }
73 }
74 }
75 return sc;
76 }
77
78 // Inherited Service overrides:
79 //
80 // Initialize the service.
81 StatusCode AuditorSvc::initialize() {
82 StatusCode sc = Service::initialize();
83 if ( sc.isFailure() )
84 return sc;
85
86 // create auditor objects for all named auditors
87 sc = syncAuditors_();
88
89 return sc;
90 }
91
92 // Finalise the service.
93 StatusCode AuditorSvc::finalize() {
94
95 for (auto& it : m_pAudList ) {
96 if(it->isEnabled()) it->sysFinalize().ignore();
97 }
98 m_pAudList.clear();
99
100 // Finalize this specific service
101 return Service::finalize();
102 }
103
104 // --------- "Before" methods ---------
105 void AuditorSvc::before(StandardEventType evt, INamedInterface* obj) {
106 if (!isEnabled()) return;
107 for (auto& it : m_pAudList ) {
108 if(it->isEnabled()) it->before(evt,obj);
109 }
110 }
111
112 void AuditorSvc::before(StandardEventType evt, const std::string &name) {
113 if (!isEnabled()) return;
114 for (auto& it : m_pAudList ) {
115 if(it->isEnabled()) it->before(evt,name);
116 }
117 }
118
119 void AuditorSvc::before(CustomEventTypeRef evt, INamedInterface* obj) {
120 if (!isEnabled()) return;
121 for (auto& it : m_pAudList) {
122 if(it->isEnabled()) it->before(evt,obj);
123 }
124 }
125
126 void AuditorSvc::before(CustomEventTypeRef evt, const std::string &name) {
127 if (!isEnabled()) return;
128 for (auto& it : m_pAudList ) {
129 if(it->isEnabled()) it->before(evt,name);
130 }
131 }
132
133 // --------- "After" methods ---------
134 void AuditorSvc::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc) {
135 if (!isEnabled()) return;
136 for (auto& it : m_pAudList ) {
137 if(it->isEnabled()) it->after(evt,obj,sc);
138 }
139 }
140
141 void AuditorSvc::after(StandardEventType evt, const std::string &name, const StatusCode& sc) {
142 if (!isEnabled()) return;
143 for (auto& it : m_pAudList ) {
144 if(it->isEnabled()) it->after(evt,name,sc);
145 }
146 }
147
148 void AuditorSvc::after(CustomEventTypeRef evt, INamedInterface* obj, const StatusCode& sc) {
149 if (!isEnabled()) return;
150 for (auto& it : m_pAudList ) {
151 if(it->isEnabled()) it->after(evt,obj,sc);
152 }
153 }
154
155 void AuditorSvc::after(CustomEventTypeRef evt, const std::string &name, const StatusCode& sc) {
156 if (!isEnabled()) return;
157 for (auto& it : m_pAudList) {
158 if(it->isEnabled()) it->after(evt,name,sc);
159 }
160 }
161
162 // --------- obsolete methods ---------
163 #define OBSOLETION(name) \
164 void AuditorSvc::name(INamedInterface*) { \
165 throw GaudiException("The method IAuditor::" #name " is obsolete do not call it.", \
166 "AuditorSvc::" #name , StatusCode::FAILURE); \
167 }
168
169 OBSOLETION(beforeInitialize)
170 OBSOLETION(afterInitialize)
171
172 OBSOLETION(beforeReinitialize)
173 OBSOLETION(afterReinitialize)
174
175 OBSOLETION(beforeExecute)
176 void AuditorSvc::afterExecute(INamedInterface*,const StatusCode&) {
177 throw GaudiException("The method afterExecute is obsolete do not call it.",
178 "AuditorSvc::afterExecute" , StatusCode::FAILURE);
179 }
180
181 OBSOLETION(beforeBeginRun)
182 OBSOLETION(afterBeginRun)
183
184 OBSOLETION(beforeEndRun)
185 OBSOLETION(afterEndRun)
186
187 OBSOLETION(beforeFinalize)
188 OBSOLETION(afterFinalize)
189
190
191 bool AuditorSvc::isEnabled( ) const {
192 return m_isEnabled;
193 }
194
195 StatusCode AuditorSvc::sysInitialize(){
196 return Service::sysInitialize();
197 }
198 StatusCode AuditorSvc::sysFinalize(){
199 return Service::sysFinalize();
200 }
201
202
203 IAuditor* AuditorSvc::getAuditor( const std::string& name ) {
204 // by interactively setting properties, auditors might be out of sync
205 if ( !syncAuditors_().isSuccess() ) {
206 // as we didn't manage to sync auditors, the safest bet is to assume the
207 // worse...
208 // So don't let clients play with an AuditorSvc in an inconsistent state
209 return nullptr;
210 }
211
212 // search available auditors, returns 0 on error
213 return findAuditor_( name );
214 }
AuditorSvc::beforeBeginRun
void beforeBeginRun(INamedInterface *ini) override
AuditorSvc::initialize
StatusCode initialize() override
Definition: AuditorSvc.cpp:81
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:15
StatusCode::SUCCESS
Definition: StatusCode.h:30
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::FAILURE
Definition: StatusCode.h:29
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:174
MsgStream.h
IAuditor.h
AuditorSvc::m_isEnabled
Gaudi::Property< bool > m_isEnabled
Definition: AuditorSvc.h:95
AuditorSvc::after
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:134
AuditorSvc.h
std
STL namespace.
AuditorSvc::afterReinitialize
void afterReinitialize(INamedInterface *ini) override
AuditorSvc::sysFinalize
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:198
AuditorSvc::afterExecute
void afterExecute(INamedInterface *ini, const StatusCode &) override
Definition: AuditorSvc.cpp:176
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:84
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:36
AuditorSvc::before
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: AuditorSvc.cpp:105
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:117
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:195
AuditorSvc::beforeReinitialize
void beforeReinitialize(INamedInterface *ini) override
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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:41
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:93
OBSOLETION
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:163
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:88
AuditorSvc::getAuditor
IAuditor * getAuditor(const std::string &name) override
Definition: AuditorSvc.cpp:203
TypeNameString.h
AuditorSvc::newAuditor_
SmartIF< IAuditor > newAuditor_(MsgStream &, const std::string &)
Definition: AuditorSvc.cpp:22
MSG::WARNING
Definition: IMessageSvc.h:20
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:106
AuditorSvc::syncAuditors_
StatusCode syncAuditors_()
Definition: AuditorSvc.cpp:49
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:244
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:85
AuditorSvc::isEnabled
bool isEnabled() const override
Definition: AuditorSvc.cpp:191
Gaudi.Configuration.log
log
Definition: Configuration.py:13
Service::sysInitialize
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:26