Auditor.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/Kernel.h"
5 
6 #include "GaudiKernel/Auditor.h"
7 
10 
11 // Constructor
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
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 
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 
127 
129 
131 
133 
135 
137 
139 
141 
143 
145 
147 
149 
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 
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 
212  return m_pSvcLocator;
213 }
214 
215 // Use the job options service to set declared properties
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();
222  return StatusCode::SUCCESS;
223 }
224 
225 // IProperty implementation
226 // Delegate to the Property manager
228  return m_PropertyMgr->setProperty(p);
229 }
231  return m_PropertyMgr->setProperty(s);
232 }
234  return m_PropertyMgr->setProperty(n,v);
235 }
237  return m_PropertyMgr->getProperty(p);
238 }
240  return m_PropertyMgr->getProperty(name);
241 }
243  return m_PropertyMgr->getProperty(n,v);
244 }
246  return m_PropertyMgr->getProperties();
247 }
249  return m_PropertyMgr->hasProperty(name);
250 }
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:28
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool m_isEnabled
Auditor is enabled flag.
Definition: Auditor.h:244
virtual StatusCode finalize()
Definition: Auditor.cpp:198
bool hasProperty(const std::string &name) const override
Implementation of IProperty::hasProperty.
Definition: Auditor.cpp:248
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
void beforeInitialize(INamedInterface *) override
Definition: Auditor.cpp:126
StatusCode getProperty(Property *p) const override
Get the value of a property.
Definition: Auditor.cpp:236
StatusCode setProperty(const Property &p) override
set the property form another property
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
StatusCode setProperties()
Set the auditor's properties.
Definition: Auditor.cpp:216
void beforeBeginRun(INamedInterface *) override
Definition: Auditor.cpp:138
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:150
void afterEndRun(INamedInterface *) override
Definition: Auditor.cpp:144
Property manager helper class.
Definition: PropertyMgr.h:37
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:239
STL class.
StatusCode getProperty(Property *p) const override
get the property
void afterBeginRun(INamedInterface *) override
Definition: Auditor.cpp:140
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:245
void beforeExecute(INamedInterface *) override
Definition: Auditor.cpp:134
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:241
Auditor(const std::string &name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:12
T what(T...args)
void afterExecute(INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:136
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:130
const std::vector< Property * > & getProperties() const override
get all properties
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:107
virtual const std::string & tag() const
name tag for the exception, or exception type
const std::vector< Property * > & getProperties() const override
Get all properties.
Definition: Auditor.cpp:245
STL class.
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
Definition: Auditor.cpp:211
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:128
StatusCode setProperty(const Property &p) override
Set a value of a property of an auditor.
Definition: Auditor.cpp:227
IInterface compliant class extending IInterface with the name() method.
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
bool isEnabled() const override
Definition: Auditor.cpp:206
SmartIF< PropertyMgr > m_PropertyMgr
For management of properties.
Definition: Auditor.h:242
const std::string & name() const override
Definition: Auditor.cpp:202
string s
Definition: gaudirun.py:245
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:148
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:146
virtual StatusCode initialize()
Definition: Auditor.cpp:82
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:87
void beforeEndRun(INamedInterface *) override
Definition: Auditor.cpp:142
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int m_outputLevel
Auditor output level.
Definition: Auditor.h:243
void afterReinitialize(INamedInterface *) override
Definition: Auditor.cpp:132
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:246