| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

Auditor.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/IJobOptionsSvc.h"
2 #include "GaudiKernel/IMessageSvc.h"
3 #include "GaudiKernel/ISvcLocator.h"
4 #include "GaudiKernel/Kernel.h"
5
6 #include "GaudiKernel/Auditor.h"
7
8 #include "GaudiKernel/GaudiException.h"
9 #include "GaudiKernel/MsgStream.h"
10
11 // Constructor
12 Auditor::Auditor( const std::string& name, ISvcLocator* pSvcLocator )
13 : m_name( name ), m_pSvcLocator( pSvcLocator ), m_isInitialized( false ), m_isFinalized( false )
14 {
15 m_outputLevel.declareUpdateHandler(
16 [this]( Gaudi::Details::PropertyBase& ) { this->updateMsgStreamOutputLevel( this->m_outputLevel ); } );
17 }
18
19 // IAuditor implementation
20 StatusCode Auditor::sysInitialize()
21 {
22 StatusCode sc;
23
24 // Bypass the initialization if the auditor is disabled or
25 // has already been initialized.
26 if ( isEnabled() && !m_isInitialized ) {
27
28 // Setup the default service ... this should be upgraded so as to be configurable.
29 if ( !m_pSvcLocator ) return StatusCode::FAILURE;
30
31 // Set the Auditor's properties
32 sc = setProperties();
33 if ( !sc.isSuccess() ) return StatusCode::FAILURE;
34
35 {
36 try {
37 // Invoke the initialize() method of the derived class
38 sc = initialize();
39 if ( !sc.isSuccess() ) return StatusCode::FAILURE;
40 m_isInitialized = true;
41
42 return sc;
43 } catch ( const GaudiException& Exception )
44 {
46 MsgStream log( msgSvc(), name() + ".sysInitialize()" );
47 log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
49 MsgStream logEx( msgSvc(), Exception.tag() );
50 logEx << MSG::ERROR << Exception << endmsg;
51 } catch ( const std::exception& Exception )
52 {
54 MsgStream log( msgSvc(), name() + ".sysInitialize()" );
55 log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
57 MsgStream logEx( msgSvc(), name() + "*std::exception*" );
58 logEx << MSG::ERROR << Exception.what() << endmsg;
59 } catch ( ... ) {
61 MsgStream log( msgSvc(), name() + ".sysInitialize()" );
62 log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
63 }
64 }
65 }
67 return StatusCode::FAILURE;
68 }
69
70 StatusCode Auditor::initialize() { return StatusCode::SUCCESS; }
71
72 // Implemented for backward compatibility
73 void Auditor::before( StandardEventType evt, INamedInterface* obj )
74 {
75 switch ( evt ) {
76 case Initialize:
77 beforeInitialize( obj );
78 break;
79 case ReInitialize:
80 beforeReinitialize( obj );
81 break;
82 case Execute:
83 beforeExecute( obj );
84 break;
85 case BeginRun:
86 beforeBeginRun( obj );
87 break;
88 case EndRun:
89 beforeEndRun( obj );
90 break;
91 case Finalize:
92 beforeFinalize( obj );
93 break;
94 case Start:
95 break;
96 case Stop:
97 break;
98 case ReStart:
99 break;
100 default:
101 break; // do nothing
102 }
103 }
104 void Auditor::before( StandardEventType, const std::string& ) {}
105
106 void Auditor::before( CustomEventTypeRef, INamedInterface* ) {}
107 void Auditor::before( CustomEventTypeRef, const std::string& ) {}
108
109 // Implemented for backward compatibility
110 void Auditor::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc )
111 {
112 switch ( evt ) {
113 case Initialize:
114 afterInitialize( obj );
115 break;
116 case ReInitialize:
117 afterReinitialize( obj );
118 break;
119 case Execute:
120 afterExecute( obj, sc );
121 break;
122 case BeginRun:
123 afterBeginRun( obj );
124 break;
125 case EndRun:
126 afterEndRun( obj );
127 break;
128 case Finalize:
129 afterFinalize( obj );
130 break;
131 case Start:
132 break;
133 case Stop:
134 break;
135 case ReStart:
136 break;
137 default:
138 break; // do nothing
139 }
140 }
141 void Auditor::after( StandardEventType, const std::string&, const StatusCode& ) {}
142
143 void Auditor::after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) {}
144 void Auditor::after( CustomEventTypeRef, const std::string&, const StatusCode& ) {}
145
146 void Auditor::beforeInitialize( INamedInterface* ) {}
147 void Auditor::afterInitialize( INamedInterface* ) {}
148 void Auditor::beforeReinitialize( INamedInterface* ) {}
149 void Auditor::afterReinitialize( INamedInterface* ) {}
150 void Auditor::beforeExecute( INamedInterface* ) {}
151 void Auditor::afterExecute( INamedInterface*, const StatusCode& ) {}
152 void Auditor::beforeBeginRun( INamedInterface* ) {}
153 void Auditor::afterBeginRun( INamedInterface* ) {}
154 void Auditor::beforeEndRun( INamedInterface* ) {}
155 void Auditor::afterEndRun( INamedInterface* ) {}
156 void Auditor::beforeFinalize( INamedInterface* ) {}
157 void Auditor::afterFinalize( INamedInterface* ) {}
158
159 StatusCode Auditor::sysFinalize()
160 {
161 StatusCode sc = StatusCode::SUCCESS;
162 try {
163 //
164 // Invoke the finalize() method of the derived class if
165 // it has been initialized.
166 if ( m_isInitialized && !m_isFinalized ) {
167 m_isFinalized = true;
168 sc = finalize();
169 if ( !sc.isSuccess() ) return StatusCode::FAILURE;
170 }
171 return sc;
172 //
173 } catch ( const GaudiException& Exception )
174 {
176 MsgStream log( msgSvc(), name() + ".sysFinalize()" );
177 log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
180 MsgStream logEx( msgSvc(), Exception.tag() );
181 logEx << MSG::ERROR << Exception << endmsg;
182 } catch ( const std::exception& Exception )
183 {
185 MsgStream log( msgSvc(), name() + ".sysFinalize()" );
186 log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
188 MsgStream logEx( msgSvc(), name() + "*std::exception*" );
189 logEx << MSG::ERROR << Exception.what() << endmsg;
190 } catch ( ... )
191 {
193 MsgStream log( msgSvc(), name() + ".sysFinalize()" );
194 log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
195 }
197 return StatusCode::FAILURE;
198 }
199
200 StatusCode Auditor::finalize() { return StatusCode::SUCCESS; }
201
202 const std::string& Auditor::name() const { return m_name; }
203
204 bool Auditor::isEnabled() const { return m_isEnabled; }
205
206 SmartIF<ISvcLocator>& Auditor::serviceLocator() const { return m_pSvcLocator; }
207
208 // Use the job options service to set declared properties
209 StatusCode Auditor::setProperties()
210 {
211 if ( !m_pSvcLocator ) return StatusCode::FAILURE;
212 auto jos = service<IJobOptionsSvc>( "JobOptionsSvc" );
213 if ( !jos ) return StatusCode::FAILURE;
214
215 // this initializes the messaging, in case property update handlers need to print
216 // and update the property value bypassing the update handler
217 m_outputLevel.value() = setUpMessaging();
218
219 return jos->setMyProperties( name(), this );
220 }
Auditor::sysInitialize
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:20
Auditor::isEnabled
bool isEnabled() const override
Definition: Auditor.cpp:204
StatusCode::SUCCESS
Definition: StatusCode.h:29
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
SmartIF< ISvcLocator >
Auditor::finalize
virtual StatusCode finalize()
Definition: Auditor.cpp:200
Kernel.h
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
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:146
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
MsgStream.h
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
Auditor::setProperties
StatusCode setProperties()
Set the auditor&#39;s properties.
Definition: Auditor.cpp:209
Auditor::beforeBeginRun
void beforeBeginRun(INamedInterface *) override
Definition: Auditor.cpp:152
Auditor::sysFinalize
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:159
Auditor::afterEndRun
void afterEndRun(INamedInterface *) override
Definition: Auditor.cpp:155
Auditor::m_name
std::string m_name
Auditor&#39;s name for identification.
Definition: Auditor.h:135
std::string
STL class.
Auditor::m_isEnabled
Gaudi::Property< bool > m_isEnabled
Definition: Auditor.h:140
MSG::FATAL
Definition: IMessageSvc.h:16
Auditor::afterBeginRun
void afterBeginRun(INamedInterface *) override
Definition: Auditor.cpp:153
Auditor::m_isInitialized
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:142
Auditor::beforeExecute
void beforeExecute(INamedInterface *) override
Definition: Auditor.cpp:150
Auditor::m_pSvcLocator
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:137
Auditor::Auditor
Auditor(const std::string &name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:12
std::exception::what
T what(T...args)
Auditor::afterExecute
void afterExecute(INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:151
CommonMessaging< implements< IAuditor, IProperty > >::updateMsgStreamOutputLevel
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
Definition: CommonMessaging.h:188
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Auditor::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Auditor.cpp:206
GaudiException.h
Auditor::beforeReinitialize
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:148
Auditor::after
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:110
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:109
IMessageSvc.h
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
CommonMessagingBase::msgSvc
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:75
std::exception
STL class.
Auditor::afterInitialize
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:147
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
MSG::ERROR
Definition: IMessageSvc.h:16
Auditor::afterFinalize
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:157
Auditor::beforeFinalize
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:156
Auditor::initialize
virtual StatusCode initialize()
Definition: Auditor.cpp:70
StatusCode::FAILURE
Definition: StatusCode.h:29
Auditor.h
CommonMessaging< implements< IAuditor, IProperty > >::setUpMessaging
MSG::Level setUpMessaging()
Set up local caches.
Definition: CommonMessaging.h:166
ISvcLocator.h
Auditor::before
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:73
Auditor::m_outputLevel
Gaudi::Property< int > m_outputLevel
Definition: Auditor.h:139
Auditor::beforeEndRun
void beforeEndRun(INamedInterface *) override
Definition: Auditor.cpp:154
Auditor::name
const std::string & name() const override
Definition: Auditor.cpp:202
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
IOTest.evt
evt
Definition: IOTest.py:96
Auditor::afterReinitialize
void afterReinitialize(INamedInterface *) override
Definition: Auditor.cpp:149
Gaudi.Configuration.log
log
Definition: Configuration.py:13
IJobOptionsSvc.h
Auditor::m_isFinalized
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:143