| The Gaudi Framework v27r1

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

- File List
- File Members

Auditor.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/Kernel.h"
2 #include "GaudiKernel/ISvcLocator.h"
3 #include "GaudiKernel/IMessageSvc.h"
4 #include "GaudiKernel/IJobOptionsSvc.h"
5
6 #include "GaudiKernel/Auditor.h"
7
8 #include "GaudiKernel/MsgStream.h"
9 #include "GaudiKernel/GaudiException.h"
10
11 // Constructor
12 Auditor::Auditor( const std::string& name, ISvcLocator *pSvcLocator )
13 : m_name(name),
14 m_pSvcLocator(pSvcLocator),
15 m_PropertyMgr{ new PropertyMgr() },
16 m_isEnabled(true),
17 m_isInitialized(false),
18 m_isFinalized(false)
19 {
20
21 // Declare common Auditor properties with their defaults
22 declareProperty( "OutputLevel", m_outputLevel = MSG::NIL)->declareUpdateHandler([this](Property&) { this->updateMsgStreamOutputLevel(this->m_outputLevel); } );
23 declareProperty( "Enable", m_isEnabled = true);
24 }
25
26
27 // IAuditor implementation
28 StatusCode Auditor::sysInitialize() {
29 StatusCode sc;
30
31 // Bypass the initialization if the auditor is disabled or
32 // has already been initialized.
33 if ( isEnabled( ) && ! m_isInitialized ) {
34
35 // Setup the default service ... this should be upgraded so as to be configurable.
36 if( !m_pSvcLocator )
37 return StatusCode::FAILURE;
38
39 // Set the Auditor's properties
40 sc = setProperties();
41 if( !sc.isSuccess() ) return StatusCode::FAILURE;
42
43 {
44 try{
45 // Invoke the initialize() method of the derived class
46 sc = initialize();
47 if( !sc.isSuccess() ) return StatusCode::FAILURE;
48 m_isInitialized = true;
49
50 return sc;
51 }
52 catch ( const GaudiException& Exception )
53 {
55 MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
56 log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
58 MsgStream logEx ( msgSvc() , Exception.tag() );
59 logEx << MSG::ERROR << Exception << endmsg;
60 }
61 catch( const std::exception& Exception )
62 {
64 MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
65 log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
67 MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
68 logEx << MSG::ERROR << Exception.what() << endmsg;
69 }
70 catch(...)
71 {
73 MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
74 log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
75 }
76 }
77 }
79 return StatusCode::FAILURE;
80 }
81
82 StatusCode Auditor::initialize() {
83 return StatusCode::SUCCESS;
84 }
85
86 // Implemented for backward compatibility
87 void Auditor::before(StandardEventType evt, INamedInterface* obj){
88 switch (evt) {
89 case Initialize: beforeInitialize(obj); break;
90 case ReInitialize: beforeReinitialize(obj); break;
91 case Execute: beforeExecute(obj); break;
92 case BeginRun: beforeBeginRun(obj); break;
93 case EndRun: beforeEndRun(obj); break;
94 case Finalize: beforeFinalize(obj); break;
95 case Start: break;
96 case Stop: break;
97 case ReStart: break;
98 default: break ;// do nothing
99 }
100 }
101 void Auditor::before(StandardEventType, const std::string&) {}
102
103 void Auditor::before(CustomEventTypeRef, INamedInterface*){}
104 void Auditor::before(CustomEventTypeRef, const std::string&){}
105
106 // Implemented for backward compatibility
107 void Auditor::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc){
108 switch (evt) {
109 case Initialize: afterInitialize(obj); break;
110 case ReInitialize: afterReinitialize(obj); break;
111 case Execute: afterExecute(obj, sc); break;
112 case BeginRun: afterBeginRun(obj); break;
113 case EndRun: afterEndRun(obj); break;
114 case Finalize: afterFinalize(obj); break;
115 case Start: break;
116 case Stop: break;
117 case ReStart: break;
118 default: break ;// do nothing
119 }
120 }
121 void Auditor::after(StandardEventType, const std::string&, const StatusCode&) {}
122
123 void Auditor::after(CustomEventTypeRef, INamedInterface*, const StatusCode&){}
124 void Auditor::after(CustomEventTypeRef, const std::string&, const StatusCode&){}
125
126 void Auditor::beforeInitialize(INamedInterface* ) {}
127
128 void Auditor::afterInitialize(INamedInterface* ) {}
129
130 void Auditor::beforeReinitialize(INamedInterface* ) {}
131
132 void Auditor::afterReinitialize(INamedInterface* ) {}
133
134 void Auditor::beforeExecute(INamedInterface* ) {}
135
136 void Auditor::afterExecute(INamedInterface*, const StatusCode& ) {}
137
138 void Auditor::beforeBeginRun(INamedInterface* ) {}
139
140 void Auditor::afterBeginRun(INamedInterface* ) {}
141
142 void Auditor::beforeEndRun(INamedInterface* ) {}
143
144 void Auditor::afterEndRun(INamedInterface* ) {}
145
146 void Auditor::beforeFinalize(INamedInterface* ) {}
147
148 void Auditor::afterFinalize(INamedInterface* ) {}
149
150 StatusCode Auditor::sysFinalize() {
151 StatusCode sc = StatusCode::SUCCESS;
152 try{
153 //
154 // Invoke the finalize() method of the derived class if
155 // it has been initialized.
156 if ( m_isInitialized && ! m_isFinalized ) {
157 m_isFinalized = true;
158 sc = finalize();
159 if( !sc.isSuccess() ) return StatusCode::FAILURE;
160 }
161 return sc;
162 //
163 }
164 catch( const GaudiException& Exception )
165 {
167 MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
168 log << MSG::FATAL
169 << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
172 MsgStream logEx ( msgSvc() , Exception.tag() );
173 logEx << MSG::ERROR
174 << Exception << endmsg;
175 }
176 catch( const std::exception& Exception )
177 {
179 MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
180 log << MSG::FATAL
181 << " Standard std::exception is caught " << endmsg;
183 MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
184 logEx << MSG::ERROR
185 << Exception.what() << endmsg;
186 }
187 catch( ... )
188 {
190 MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
191 log << MSG::FATAL
192 << " UNKNOWN Exception is caught " << endmsg;
193 }
195 return StatusCode::FAILURE ;
196 }
197
198 StatusCode Auditor::finalize() {
199 return StatusCode::SUCCESS;
200 }
201
202 const std::string& Auditor::name() const {
203 return m_name;
204 }
205
206 bool Auditor::isEnabled( ) const {
207 return m_isEnabled;
208 }
209
210
211 SmartIF<ISvcLocator>& Auditor::serviceLocator() const {
212 return m_pSvcLocator;
213 }
214
215 // Use the job options service to set declared properties
216 StatusCode Auditor::setProperties() {
217 if( !m_pSvcLocator ) return StatusCode::FAILURE;
218 auto jos = service<IJobOptionsSvc>("JobOptionsSvc");
219 if( !jos ) return StatusCode::FAILURE;
220 jos->setMyProperties( name(), this ).ignore();
221 updateMsgStreamOutputLevel( m_outputLevel );
222 return StatusCode::SUCCESS;
223 }
224
225 // IProperty implementation
226 // Delegate to the Property manager
227 StatusCode Auditor::setProperty(const Property& p) {
228 return m_PropertyMgr->setProperty(p);
229 }
230 StatusCode Auditor::setProperty(const std::string& s) {
231 return m_PropertyMgr->setProperty(s);
232 }
233 StatusCode Auditor::setProperty(const std::string& n, const std::string& v) {
234 return m_PropertyMgr->setProperty(n,v);
235 }
236 StatusCode Auditor::getProperty(Property* p) const {
237 return m_PropertyMgr->getProperty(p);
238 }
239 const Property& Auditor::getProperty( const std::string& name) const{
240 return m_PropertyMgr->getProperty(name);
241 }
242 StatusCode Auditor::getProperty(const std::string& n, std::string& v ) const {
243 return m_PropertyMgr->getProperty(n,v);
244 }
245 const std::vector<Property*>& Auditor::getProperties( ) const {
246 return m_PropertyMgr->getProperties();
247 }
248 bool Auditor::hasProperty(const std::string& name) const {
249 return m_PropertyMgr->hasProperty(name);
250 }
Auditor::sysInitialize
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:28
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Auditor::m_isEnabled
bool m_isEnabled
Auditor is enabled flag.
Definition: Auditor.h:244
SmartIF< ISvcLocator >
Auditor::finalize
virtual StatusCode finalize()
Definition: Auditor.cpp:198
Kernel.h
Auditor::hasProperty
bool hasProperty(const std::string &name) const override
Implementation of IProperty::hasProperty.
Definition: Auditor.cpp:248
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
Auditor::beforeInitialize
void beforeInitialize(INamedInterface *) override
Definition: Auditor.cpp:126
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
MsgStream.h
Auditor::getProperty
StatusCode getProperty(Property *p) const override
Get the value of a property.
Definition: Auditor.cpp:236
PropertyMgr::setProperty
StatusCode setProperty(const Property &p) override
set the property form another property
Definition: PropertyMgr.cpp:105
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
Auditor::setProperties
StatusCode setProperties()
Set the auditor's properties.
Definition: Auditor.cpp:216
Auditor::beforeBeginRun
void beforeBeginRun(INamedInterface *) override
Definition: Auditor.cpp:138
Auditor::sysFinalize
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:150
Auditor::afterEndRun
void afterEndRun(INamedInterface *) override
Definition: Auditor.cpp:144
merge_files.sc
int sc
Definition: merge_files.py:167
PropertyMgr
Property manager helper class.
Definition: PropertyMgr.h:37
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
Auditor::m_name
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:239
std::string
STL class.
PropertyMgr::getProperty
StatusCode getProperty(Property *p) const override
get the property
Definition: PropertyMgr.cpp:144
MSG::FATAL
Definition: IMessageSvc.h:22
Auditor::afterBeginRun
void afterBeginRun(INamedInterface *) override
Definition: Auditor.cpp:140
Auditor::m_isInitialized
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:245
Auditor::beforeExecute
void beforeExecute(INamedInterface *) override
Definition: Auditor.cpp:134
Auditor::m_pSvcLocator
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:241
Auditor::Auditor
Auditor(const std::string &name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:12
StatusCode::FAILURE
Definition: StatusCode.h:29
std::exception::what
T what(T...args)
StatusCode::SUCCESS
Definition: StatusCode.h:30
Auditor::afterExecute
void afterExecute(INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:136
CommonMessaging< implements< IAuditor, IProperty > >::updateMsgStreamOutputLevel
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
Definition: CommonMessaging.h:187
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
Auditor::beforeReinitialize
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:130
PropertyMgr::getProperties
const std::vector< Property * > & getProperties() const override
get all properties
Definition: PropertyMgr.cpp:186
Auditor::after
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:107
MSG::NIL
Definition: IMessageSvc.h:16
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:119
IMessageSvc.h
Auditor::getProperties
const std::vector< Property * > & getProperties() const override
Get all properties.
Definition: Auditor.cpp:245
std::exception
STL class.
Auditor::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
Definition: Auditor.cpp:211
Auditor::afterInitialize
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:128
Auditor::setProperty
StatusCode setProperty(const Property &p) override
Set a value of a property of an auditor.
Definition: Auditor.cpp:227
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector< Property * >
Auditor::isEnabled
bool isEnabled() const override
Definition: Auditor.cpp:206
Auditor::m_PropertyMgr
SmartIF< PropertyMgr > m_PropertyMgr
For management of properties.
Definition: Auditor.h:242
Auditor::name
const std::string & name() const override
Definition: Auditor.cpp:202
gaudirun.s
string s
Definition: gaudirun.py:245
PropertyMgr::hasProperty
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
Definition: PropertyMgr.cpp:201
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:73
MSG::ERROR
Definition: IMessageSvc.h:21
Auditor::afterFinalize
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:148
Auditor::beforeFinalize
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:146
Auditor::initialize
virtual StatusCode initialize()
Definition: Auditor.cpp:82
Auditor.h
ISvcLocator.h
Auditor::before
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:87
Auditor::beforeEndRun
void beforeEndRun(INamedInterface *) override
Definition: Auditor.cpp:142
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Auditor::m_outputLevel
int m_outputLevel
Auditor output level.
Definition: Auditor.h:243
Auditor::afterReinitialize
void afterReinitialize(INamedInterface *) override
Definition: Auditor.cpp:132
IJobOptionsSvc.h
Auditor::m_isFinalized
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:246