| The Gaudi Framework v32r1 (f65d50dc)

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