| The Gaudi Framework v27r1

- 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 PropertyMgr 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 // Standard Constructor.
79 // Input: name String with service name
80 // Input: svc Pointer to service locator interface
81 AuditorSvc::AuditorSvc( const std::string& name, ISvcLocator* svc )
82 : base_class(name, svc) {
83 declareProperty("Auditors", m_audNameList );
84 declareProperty("Enable", m_isEnabled = true);
85 }
86
87 // Inherited Service overrides:
88 //
89 // Initialize the service.
90 StatusCode AuditorSvc::initialize() {
91 StatusCode sc = Service::initialize();
92 if ( sc.isFailure() )
93 return sc;
94
95 // create auditor objects for all named auditors
96 sc = syncAuditors_();
97
98 return sc;
99 }
100
101 // Finalise the service.
102 StatusCode AuditorSvc::finalize() {
103
104 for (auto& it : m_pAudList ) {
105 if(it->isEnabled()) it->sysFinalize().ignore();
106 }
107 m_pAudList.clear();
108
109 // Finalize this specific service
110 return Service::finalize();
111 }
112
113 // --------- "Before" methods ---------
114 void AuditorSvc::before(StandardEventType evt, INamedInterface* obj) {
115 if (!isEnabled()) return;
116 for (auto& it : m_pAudList ) {
117 if(it->isEnabled()) it->before(evt,obj);
118 }
119 }
120
121 void AuditorSvc::before(StandardEventType evt, const std::string &name) {
122 if (!isEnabled()) return;
123 for (auto& it : m_pAudList ) {
124 if(it->isEnabled()) it->before(evt,name);
125 }
126 }
127
128 void AuditorSvc::before(CustomEventTypeRef evt, INamedInterface* obj) {
129 if (!isEnabled()) return;
130 for (auto& it : m_pAudList) {
131 if(it->isEnabled()) it->before(evt,obj);
132 }
133 }
134
135 void AuditorSvc::before(CustomEventTypeRef evt, const std::string &name) {
136 if (!isEnabled()) return;
137 for (auto& it : m_pAudList ) {
138 if(it->isEnabled()) it->before(evt,name);
139 }
140 }
141
142 // --------- "After" methods ---------
143 void AuditorSvc::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc) {
144 if (!isEnabled()) return;
145 for (auto& it : m_pAudList ) {
146 if(it->isEnabled()) it->after(evt,obj,sc);
147 }
148 }
149
150 void AuditorSvc::after(StandardEventType evt, const std::string &name, const StatusCode& sc) {
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 if (!isEnabled()) return;
159 for (auto& it : m_pAudList ) {
160 if(it->isEnabled()) it->after(evt,obj,sc);
161 }
162 }
163
164 void AuditorSvc::after(CustomEventTypeRef evt, const std::string &name, const StatusCode& sc) {
165 if (!isEnabled()) return;
166 for (auto& it : m_pAudList) {
167 if(it->isEnabled()) it->after(evt,name,sc);
168 }
169 }
170
171 // --------- obsolete methods ---------
172 #define OBSOLETION(name) \
173 void AuditorSvc::name(INamedInterface*) { \
174 throw GaudiException("The method IAuditor::" #name " is obsolete do not call it.", \
175 "AuditorSvc::" #name , StatusCode::FAILURE); \
176 }
177
178 OBSOLETION(beforeInitialize)
179 OBSOLETION(afterInitialize)
180
181 OBSOLETION(beforeReinitialize)
182 OBSOLETION(afterReinitialize)
183
184 OBSOLETION(beforeExecute)
185 void AuditorSvc::afterExecute(INamedInterface*,const StatusCode&) {
186 throw GaudiException("The method afterExecute is obsolete do not call it.",
187 "AuditorSvc::afterExecute" , StatusCode::FAILURE);
188 }
189
190 OBSOLETION(beforeBeginRun)
191 OBSOLETION(afterBeginRun)
192
193 OBSOLETION(beforeEndRun)
194 OBSOLETION(afterEndRun)
195
196 OBSOLETION(beforeFinalize)
197 OBSOLETION(afterFinalize)
198
199
200 bool AuditorSvc::isEnabled( ) const {
201 return m_isEnabled;
202 }
203
204 StatusCode AuditorSvc::sysInitialize(){
205 return Service::sysInitialize();
206 }
207 StatusCode AuditorSvc::sysFinalize(){
208 return Service::sysFinalize();
209 }
210
211
212 IAuditor* AuditorSvc::getAuditor( const std::string& name ) {
213 // by interactively setting properties, auditors might be out of sync
214 if ( !syncAuditors_().isSuccess() ) {
215 // as we didn't manage to sync auditors, the safest bet is to assume the
216 // worse...
217 // So don't let clients play with an AuditorSvc in an inconsistent state
218 return nullptr;
219 }
220
221 // search available auditors, returns 0 on error
222 return findAuditor_( name );
223 }
AuditorSvc::initialize
StatusCode initialize() override
Definition: AuditorSvc.cpp:90
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
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
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:193
MsgStream.h
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
IAuditor.h
AuditorSvc::after
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:143
AuditorSvc.h
std
STL namespace.
AuditorSvc::sysFinalize
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:207
AuditorSvc::AuditorSvc
AuditorSvc(const std::string &name, ISvcLocator *svc)
Definition: AuditorSvc.cpp:81
std::end
T end(T...args)
merge_files.sc
int sc
Definition: merge_files.py:167
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:103
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:114
AuditorSvc::isEnabled
bool isEnabled() const override
Definition: AuditorSvc.cpp:200
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
std::string
STL class.
std::vector::push_back
T push_back(T...args)
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
INamedInterface.h
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
StatusCode::FAILURE
Definition: StatusCode.h:29
AuditorSvc::sysInitialize
StatusCode sysInitialize() override
Definition: AuditorSvc.cpp:204
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiException.h
read_lhcb_event_file.evt
tuple evt
Definition: read_lhcb_event_file.py:14
Service::sysFinalize
StatusCode sysFinalize() override
Finalize Service.
Definition: Service.cpp:158
std::move
T move(T...args)
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::finalize
StatusCode finalize() override
Definition: AuditorSvc.cpp:102
OBSOLETION
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:172
std::begin
T begin(T...args)
Gaudi::Utils::TypeNameString::type
const std::string & type() const
Definition: TypeNameString.h:22
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition: CommonMessaging.h:89
AuditorSvc::getAuditor
IAuditor * getAuditor(const std::string &name) override
Definition: AuditorSvc.cpp:212
TypeNameString.h
ana.item
tuple item
print s1,s2
Definition: ana.py:146
CommonMessaging
Definition: CommonMessaging.h:58
AuditorSvc::newAuditor_
SmartIF< IAuditor > newAuditor_(MsgStream &, const std::string &)
Definition: AuditorSvc.cpp:22
AuditorSvc::m_audNameList
std::vector< std::string > m_audNameList
Definition: AuditorSvc.h:100
MSG::WARNING
Definition: IMessageSvc.h:20
AuditorSvc::m_isEnabled
bool m_isEnabled
Definition: AuditorSvc.h:106
Gaudi::Utils::TypeNameString::name
const std::string & name() const
Definition: TypeNameString.h:23
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
AuditorSvc::syncAuditors_
StatusCode syncAuditors_()
Definition: AuditorSvc.cpp:49
ana.i
list i
Definition: ana.py:128
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
Service::sysInitialize
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:26