Gaudi Framework, version v23r6
Home
Generated: Wed Jan 30 2013
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
GaudiAlg
src
lib
GaudiTool.cpp
Go to the documentation of this file.
1
// $Id: GaudiTool.cpp,v 1.10 2007/09/25 16:12:41 marcocle Exp $
2
// ============================================================================
3
// Include files
4
// ============================================================================
5
// GaudiKernel
6
// ============================================================================
7
#include "
GaudiKernel/IChronoStatSvc.h
"
8
#include "
GaudiKernel/IIncidentSvc.h
"
9
#include "
GaudiKernel/IDataProviderSvc.h
"
10
#include "
GaudiKernel/IHistogramSvc.h
"
11
#include "
GaudiKernel/INTupleSvc.h
"
12
#include "
GaudiKernel/IAlgContextSvc.h
"
13
#include "
GaudiKernel/Bootstrap.h
"
14
// ============================================================================
15
// GaudiAlg
16
// ============================================================================
17
#include "
GaudiAlg/GaudiTool.h
"
18
#include "
GaudiAlg/GaudiAlgorithm.h
"
19
// ============================================================================
27
// ============================================================================
28
// templated methods
29
// ============================================================================
30
#include "
GaudiCommon.icpp
"
31
// ============================================================================
32
template
class
GaudiCommon<AlgTool>
;
33
// ============================================================================
40
// ============================================================================
41
namespace
GaudiToolServices
42
{
44
const
std::string
s_EventDataSvc
=
"EventDataSvc"
;
46
const
std::string
s_DetectorDataSvc
=
"DetectorDataSvc"
;
48
const
std::string
s_ChronoStatSvc
=
"ChronoStatSvc"
;
50
const
std::string
s_IncidentSvc
=
"IncidentSvc"
;
52
const
std::string
s_HistoSvc
=
"HistogramDataSvc"
;
53
}
54
// ============================================================================
55
namespace
GaudiToolLocal
56
{
57
// ==========================================================================
61
class
Counter
62
{
63
public
:
64
// ========================================================================
65
// constructor
66
Counter
(
const
std::string
&
msg
=
" Misbalance "
)
67
: m_map ()
68
, m_message (
msg
)
69
{};
70
// destructor
71
~Counter
() { report() ; m_map.clear() ;}
72
// ========================================================================
73
public
:
74
// ========================================================================
76
long
increment
(
const
std::string
&
object
) {
return
++m_map[object] ; }
78
long
decrement
(
const
std::string
&
object
) {
return
--m_map[object] ; }
80
long
counts
(
const
std::string
&
object
) {
return
m_map[object] ; }
82
void
report()
const
83
{
85
if
( !
GaudiTool::summaryEnabled
() ) { return ; }
// RETURN
86
//
87
for
(
Map::const_iterator
entry = m_map.begin() ;
88
m_map.end() != entry ; ++entry )
89
{
90
if
( 0 == entry->second ) { continue ; }
91
std::cout
<<
"GaudiTool WARNING "
<< m_message
92
<<
"'"
<< entry->first <<
"' Counts = "
<< entry->second
93
<<
std::endl
;
94
}
95
}
96
// ========================================================================
97
private
:
98
// ========================================================================
99
typedef
std::map<std::string,long>
Map
;
100
Map
m_map
;
101
std::string
m_message
;
102
// ========================================================================
103
};
104
// ==========================================================================
110
static
Counter
s_InstanceCounter
(
" Create/Destroy (mis)balance "
) ;
111
// ==========================================================================
117
static
Counter
s_FinalizeCounter
(
" Initialize/Finalize (mis)balance "
) ;
118
// ==========================================================================
119
}
120
// ============================================================================
122
// ============================================================================
123
bool
GaudiTool::s_enableSummary
= true ;
// summary is enabled
124
// ============================================================================
125
// enable/disable summary
126
// ============================================================================
127
bool
GaudiTool::enableSummary
(
bool
value )
// enable/disable summary
128
{
129
s_enableSummary
= value ;
130
return
summaryEnabled
() ;
131
}
132
// ============================================================================
133
// is summary enabled?
134
// ============================================================================
135
bool
GaudiTool::summaryEnabled
()
// is summary enabled?
136
{
return
s_enableSummary
; }
137
// ============================================================================
138
// Standard constructor
139
// ============================================================================
140
GaudiTool::GaudiTool
(
const
std::string
& this_type ,
141
const
std::string
& this_name ,
142
const
IInterface
* parent )
143
:
GaudiCommon
<
AlgTool
> ( this_type , this_name , parent )
144
// services
145
, m_ntupleSvc ( 0 )
146
, m_evtColSvc ( 0 )
147
, m_evtSvc ( 0 )
148
, m_detSvc ( 0 )
149
, m_chronoSvc ( 0 )
150
, m_incSvc ( 0 )
151
, m_histoSvc ( 0 )
152
, m_contextSvc ( 0 )
// pointer to Algorithm Context Service
153
, m_contextSvcName (
"AlgContextSvc"
)
// Algorithm Context Service name
154
//
155
, m_local ( this_type +
"/"
+ this_name )
156
{
157
declareProperty
158
(
"ContextService"
,
159
m_contextSvcName
,
160
"The name of Algorithm Context Service"
) ;
161
// make instance counts
162
GaudiToolLocal::s_InstanceCounter
.increment (
m_local
) ;
163
}
164
// ============================================================================
165
// destructor
166
// ============================================================================
167
GaudiTool::~GaudiTool
()
168
{
169
GaudiToolLocal::s_InstanceCounter
.decrement (
m_local
) ;
170
}
171
// ============================================================================
172
// standard initialization method
173
// ============================================================================
174
StatusCode
GaudiTool::initialize
()
175
{
176
// initialize the base class
177
const
StatusCode
sc
=
GaudiCommon<AlgTool>::initialize
() ;
178
if
( sc.
isFailure
() ) {
return
sc
; }
179
180
// increment the counter
181
GaudiToolLocal::s_FinalizeCounter
.increment(
m_local
) ;
182
183
// return
184
return
sc
;
185
}
186
// ============================================================================
187
// standard finalization method
188
// ============================================================================
189
StatusCode
GaudiTool::finalize
()
190
{
191
if
(
msgLevel
(
MSG::DEBUG
) )
192
debug
() <<
" ==> Finalize the base class GaudiTool "
<<
endmsg
;
193
194
// clear "explicit services"
195
m_evtSvc
= 0 ;
196
m_detSvc
= 0 ;
197
m_chronoSvc
= 0 ;
198
m_incSvc
= 0 ;
199
m_histoSvc
= 0 ;
200
201
// finalize the base class
202
const
StatusCode
sc
=
GaudiCommon<AlgTool>::finalize
() ;
203
if
( sc.
isFailure
() ) {
return
sc
; }
204
205
// Decrement the counter
206
GaudiToolLocal::s_FinalizeCounter
.decrement(
m_local
) ;
207
208
// return
209
return
sc
;
210
}
211
// ============================================================================
212
// accessor to detector service
213
// ============================================================================
214
IDataProviderSvc
*
GaudiTool::detSvc
()
const
215
{
216
if
( 0 ==
m_detSvc
)
217
{
218
m_detSvc
=
219
svc<IDataProviderSvc>(
GaudiToolServices::s_DetectorDataSvc
, true ) ;
220
}
221
return
m_detSvc
;
222
}
223
// ============================================================================
224
// The standard N-Tuple
225
// ============================================================================
226
INTupleSvc
*
GaudiTool::ntupleSvc
()
const
227
{
228
if
( 0 ==
m_ntupleSvc
)
229
{
230
m_ntupleSvc
= svc<INTupleSvc>(
"NTupleSvc"
, true ) ;
231
}
232
return
m_ntupleSvc
;
233
}
234
// ============================================================================
235
// The standard event collection service
236
// ============================================================================
237
INTupleSvc
*
GaudiTool::evtColSvc
()
const
238
{
239
if
( 0 ==
m_evtColSvc
)
240
{
241
m_evtColSvc
= svc< INTupleSvc > (
"EvtTupleSvc"
, true ) ;
242
}
243
return
m_evtColSvc
;
244
}
245
// ============================================================================
246
// accessor to event service service
247
// ============================================================================
248
IDataProviderSvc
*
GaudiTool::evtSvc
()
const
249
{
250
if
( 0 ==
m_evtSvc
)
251
{
252
m_evtSvc
=
253
svc<IDataProviderSvc>(
GaudiToolServices::s_EventDataSvc
, true ) ;
254
}
255
return
m_evtSvc
;
256
}
257
// ============================================================================
258
// accessor to Incident Service
259
// ============================================================================
260
IIncidentSvc
*
GaudiTool::incSvc
()
const
261
{
262
if
( 0 ==
m_incSvc
)
263
{
264
m_incSvc
=
265
svc<IIncidentSvc> (
GaudiToolServices::s_IncidentSvc
, true ) ;
266
}
267
return
m_incSvc
;
268
}
269
// ============================================================================
270
// accessor to Chrono & Stat Service
271
// ============================================================================
272
IChronoStatSvc
*
GaudiTool::chronoSvc
()
const
273
{
274
if
( 0 ==
m_chronoSvc
)
275
{
276
m_chronoSvc
=
277
svc<IChronoStatSvc> (
GaudiToolServices::s_ChronoStatSvc
, true ) ;
278
}
279
return
m_chronoSvc
;
280
}
281
// ============================================================================
282
// accessor to histogram Service
283
// ============================================================================
284
IHistogramSvc
*
GaudiTool::histoSvc
()
const
285
{
286
if
( 0 ==
m_histoSvc
)
287
{
288
m_histoSvc
= svc<IHistogramSvc> (
GaudiToolServices::s_HistoSvc
, true ) ;
289
}
290
return
m_histoSvc
;
291
}
292
// ============================================================================
293
// accessor to Algorithm Context Service
294
// ============================================================================
295
IAlgContextSvc
*
GaudiTool::contextSvc
()
const
296
{
297
if
( 0 ==
m_contextSvc
)
298
{
299
m_contextSvc
= svc<IAlgContextSvc> (
m_contextSvcName
, true ) ;
300
}
301
return
m_contextSvc
;
302
}
303
// ============================================================================
304
// The END
305
// ============================================================================
Generated at Wed Jan 30 2013 17:13:37 for Gaudi Framework, version v23r6 by
Doxygen
version 1.8.2 written by
Dimitri van Heesch
, © 1997-2004