| The Gaudi Framework v32r1 (f65d50dc)

AuditorSvc.cpp
Go to the documentation of this file.
1 // Include Files
2 #include "AuditorSvc.h"
3 #include "GaudiKernel/Auditor.h"
4 #include "GaudiKernel/GaudiException.h"
5 #include "GaudiKernel/IAuditor.h"
6 #include "GaudiKernel/INamedInterface.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/MsgStream.h"
9 #include "GaudiKernel/TypeNameString.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() ).release()};
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() ) return StatusCode::SUCCESS;
51
52 StatusCode sc;
53
54 // if ( sc.isFailure() ) {
55 // error() << "Unable to locate ObjectManager Service" << endmsg;
56 // return sc;
57 // }
58
59 // create all declared Auditors that do not yet exist
60 for ( auto& it : m_audNameList ) {
61
62 // this is clumsy, but the PropertyHolder won't tell us when my property changes right
63 // under my nose, so I'll have to figure this out the hard way
64 if ( !findAuditor_( it ) ) { // if auditor does not yet exist
65 auto aud = newAuditor_( msgStream(), it );
66 if ( aud ) {
67 m_pAudList.push_back( std::move( aud ) );
68 } else {
69 error() << "Error constructing Auditor " << it << endmsg;
70 sc = StatusCode::FAILURE;
71 }
72 }
73 }
74 return sc;
75 }
76
77 // Inherited Service overrides:
78 //
79 // Initialize the service.
80 StatusCode AuditorSvc::initialize() {
81 StatusCode sc = Service::initialize();
82 if ( sc.isFailure() ) return sc;
83
84 // create auditor objects for all named auditors
85 sc = syncAuditors_();
86
87 return sc;
88 }
89
90 // Finalise the service.
91 StatusCode AuditorSvc::finalize() {
92
93 for ( auto& it : m_pAudList ) {
94 if ( it->isEnabled() ) it->sysFinalize().ignore();
95 }
96 m_pAudList.clear();
97
98 // Finalize this specific service
99 return Service::finalize();
100 }
101
102 // --------- "Before" methods ---------
103 void AuditorSvc::before( StandardEventType evt, INamedInterface* obj ) {
104 if ( !isEnabled() ) return;
105 for ( auto& it : m_pAudList ) {
106 if ( it->isEnabled() ) it->before( evt, obj );
107 }
108 }
109
110 void AuditorSvc::before( StandardEventType evt, const std::string& name ) {
111 if ( !isEnabled() ) return;
112 for ( auto& it : m_pAudList ) {
113 if ( it->isEnabled() ) it->before( evt, name );
114 }
115 }
116
117 void AuditorSvc::before( CustomEventTypeRef evt, INamedInterface* obj ) {
118 if ( !isEnabled() ) return;
119 for ( auto& it : m_pAudList ) {
120 if ( it->isEnabled() ) it->before( evt, obj );
121 }
122 }
123
124 void AuditorSvc::before( CustomEventTypeRef evt, const std::string& name ) {
125 if ( !isEnabled() ) return;
126 for ( auto& it : m_pAudList ) {
127 if ( it->isEnabled() ) it->before( evt, name );
128 }
129 }
130
131 // --------- "After" methods ---------
132 void AuditorSvc::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc ) {
133 if ( !isEnabled() ) return;
134 for ( auto& it : m_pAudList ) {
135 if ( it->isEnabled() ) it->after( evt, obj, sc );
136 }
137 }
138
139 void AuditorSvc::after( StandardEventType evt, const std::string& name, const StatusCode& sc ) {
140 if ( !isEnabled() ) return;
141 for ( auto& it : m_pAudList ) {
142 if ( it->isEnabled() ) it->after( evt, name, sc );
143 }
144 }
145
146 void AuditorSvc::after( CustomEventTypeRef evt, INamedInterface* obj, const StatusCode& sc ) {
147 if ( !isEnabled() ) return;
148 for ( auto& it : m_pAudList ) {
149 if ( it->isEnabled() ) it->after( evt, obj, sc );
150 }
151 }
152
153 void AuditorSvc::after( CustomEventTypeRef evt, const std::string& name, const StatusCode& sc ) {
154 if ( !isEnabled() ) return;
155 for ( auto& it : m_pAudList ) {
156 if ( it->isEnabled() ) it->after( evt, name, sc );
157 }
158 }
159
160 // --------- obsolete methods ---------
161 #define OBSOLETION( name ) \
162 void AuditorSvc::name( INamedInterface* ) { \
163 throw GaudiException( "The method IAuditor::" #name " is obsolete do not call it.", "AuditorSvc::" #name, \
164 StatusCode::FAILURE ); \
165 }
166
167 OBSOLETION( beforeInitialize )
168 OBSOLETION( afterInitialize )
169
170 OBSOLETION( beforeReinitialize )
171 OBSOLETION( afterReinitialize )
172
173 OBSOLETION( beforeExecute )
174 void AuditorSvc::afterExecute( INamedInterface*, const StatusCode& ) {
175 throw GaudiException( "The method afterExecute is obsolete do not call it.", "AuditorSvc::afterExecute",
176 StatusCode::FAILURE );
177 }
178
179 OBSOLETION( beforeBeginRun )
180 OBSOLETION( afterBeginRun )
181
182 OBSOLETION( beforeEndRun )
183 OBSOLETION( afterEndRun )
184
185 OBSOLETION( beforeFinalize )
186 OBSOLETION( afterFinalize )
187
188 bool AuditorSvc::isEnabled() const { return m_isEnabled; }
189
190 StatusCode AuditorSvc::sysInitialize() { return Service::sysInitialize(); }
191 StatusCode AuditorSvc::sysFinalize() { return Service::sysFinalize(); }
192
193 IAuditor* AuditorSvc::getAuditor( const std::string& name ) {
194 // by interactively setting properties, auditors might be out of sync
195 if ( !syncAuditors_().isSuccess() ) {
196 // as we didn't manage to sync auditors, the safest bet is to assume the
197 // worse...
198 // So don't let clients play with an AuditorSvc in an inconsistent state
199 return nullptr;
200 }
201
202 // search available auditors, returns 0 on error
203 return findAuditor_( name );
204 }
AuditorSvc::initialize
StatusCode initialize() override
Definition: AuditorSvc.cpp:80
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:60
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:164
MsgStream.h
IAuditor.h
AuditorSvc::after
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: AuditorSvc.cpp:132
AuditorSvc.h
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std
STL namespace.
AuditorSvc::sysFinalize
StatusCode sysFinalize() override
Definition: AuditorSvc.cpp:191
Gaudi::Utils::TypeNameString::type
const std::string & type() const
Definition: TypeNameString.h:36
std::end
T end(T... args)
AuditorSvc
Definition: AuditorSvc.h:18
AuditorSvc::m_pAudList
std::vector< SmartIF< IAuditor > > m_pAudList
Definition: AuditorSvc.h:94
AuditorSvc::before
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: AuditorSvc.cpp:103
AuditorSvc::isEnabled
bool isEnabled() const override
Definition: AuditorSvc.cpp:188
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
std::string
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
std::vector::push_back
T push_back(T... args)
INamedInterface.h
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:10
AuditorSvc::sysInitialize
StatusCode sysInitialize() override
Definition: AuditorSvc.cpp:190
Gaudi::Utils::TypeNameString::name
const std::string & name() const
Definition: TypeNameString.h:37
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
GaudiException.h
std::vector::clear
T clear(T... args)
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition: CommonMessaging.h:71
Service::sysFinalize
StatusCode sysFinalize() override
Finalize Service.
Definition: Service.cpp:135
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)
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
AuditorSvc::finalize
StatusCode finalize() override
Definition: AuditorSvc.cpp:91
OBSOLETION
#define OBSOLETION(name)
Definition: AuditorSvc.cpp:161
std::begin
T begin(T... args)
AuditorSvc::getAuditor
IAuditor * getAuditor(const std::string &name) override
Definition: AuditorSvc.cpp:193
TypeNameString.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
AuditorSvc::newAuditor_
SmartIF< IAuditor > newAuditor_(MsgStream &, const std::string &)
Definition: AuditorSvc.cpp:22
MSG::WARNING
Definition: IMessageSvc.h:15
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
AuditorSvc::syncAuditors_
StatusCode syncAuditors_()
Definition: AuditorSvc.cpp:49
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:192
AuditorSvc::m_audNameList
Gaudi::Property< std::vector< std::string > > m_audNameList
Definition: AuditorSvc.h:90
IOTest.evt
evt
Definition: IOTest.py:94
Gaudi.Configuration.log
log
Definition: Configuration.py:13
Service::sysInitialize
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:24