All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 // ============================================================================
11 #include "GaudiKernel/INTupleSvc.h"
13 #include "GaudiKernel/Bootstrap.h"
14 // ============================================================================
15 // GaudiAlg
16 // ============================================================================
17 #include "GaudiAlg/GaudiTool.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 {
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 {
158  ( "ContextService" ,
160  "The name of Algorithm Context Service" ) ;
161  // make instance counts
162  GaudiToolLocal::s_InstanceCounter.increment ( m_local ) ;
163 }
164 // ============================================================================
165 // destructor
166 // ============================================================================
168 {
169  GaudiToolLocal::s_InstanceCounter.decrement ( m_local ) ;
170 }
171 // ============================================================================
172 // standard initialization method
173 // ============================================================================
175 {
176  // initialize the base class
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 // ============================================================================
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
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 // ============================================================================
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 // ============================================================================
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 // ============================================================================
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 // ============================================================================
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 // ============================================================================
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 // ============================================================================
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 // ============================================================================
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 // ============================================================================
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 // ============================================================================
IChronoStatSvc * chronoSvc() const
accessor to Chrono & Stat Service
Definition: GaudiTool.cpp:272
IIncidentSvc * incSvc() const
accessor to Incident Service
Definition: GaudiTool.cpp:260
IAlgContextSvc * contextSvc() const
acessor to the Algorithm Context Service
Definition: GaudiTool.cpp:295
std::string m_contextSvcName
Algorithm Context Service.
Definition: GaudiTool.h:718
Header file for class GaudiAlgorithm.
long counts(const std::string &object)
current count
Definition: GaudiTool.cpp:80
IChronoStatSvc * m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:710
void report() const
make a report
Definition: GaudiTool.cpp:82
IHistogramSvc * histoSvc() const
acessor to the histogram service
Definition: GaudiTool.cpp:284
virtual StatusCode finalize()
standard finalization method
const std::string s_ChronoStatSvc
the default name for Chrono & Stat Service
Definition: GaudiTool.cpp:48
IDataProviderSvc * m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:708
GaudiTool()
no public default constructor
static bool enableSummary(bool)
enable/disable summary
Definition: GaudiTool.cpp:127
Data provider interface definition.
IDataProviderSvc * evtSvc() const
accessor to event service service
Definition: GaudiTool.cpp:248
INTupleSvc * ntupleSvc() const
Access the standard N-Tuple.
Definition: GaudiTool.cpp:226
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
MSG::Level msgLevel() const
The current message service output level.
Definition: GaudiCommon.h:532
const std::string s_IncidentSvc
the default name for Incident Service
Definition: GaudiTool.cpp:50
virtual StatusCode initialize()
standard initialization method
Definition: GaudiTool.cpp:174
The IChronoStatSvc is the interface implemented by the ChronoStatService.
INTupleSvc * evtColSvc() const
Access the standard event collection service.
Definition: GaudiTool.cpp:237
IAlgContextSvc * m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:716
IDataProviderSvc * m_evtSvc
pointer to Event Data Service
Definition: GaudiTool.h:706
const std::string s_HistoSvc
the default name for Histogram Service
Definition: GaudiTool.cpp:52
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: AlgTool.h:234
Definition of the basic interface.
Definition: IInterface.h:160
Definition of the IHistogramSvc interface class.
Definition: IHistogramSvc.h:47
MsgStream & debug() const
shortcut for the method msgStream ( MSG::DEBUG )
Definition: GaudiCommon.h:499
IHistogramSvc * m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:714
long increment(const std::string &object)
make the increment
Definition: GaudiTool.cpp:76
virtual ~GaudiTool()
destructor, virtual and protected
Definition: GaudiTool.cpp:167
const std::string s_DetectorDataSvc
the default name for Detector Data Service
Definition: GaudiTool.cpp:46
std::map< std::string, long > Map
Definition: GaudiTool.cpp:99
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:728
IIncidentSvc * m_incSvc
pointer to Incident Service
Definition: GaudiTool.h:712
INTupleSvc * m_ntupleSvc
pointer to the N-Tuple service
Definition: GaudiTool.h:702
simple local counter
Definition: GaudiTool.cpp:61
INTupleSvc * m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:704
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:34
Counter(const std::string &msg=" Misbalance ")
Definition: GaudiTool.cpp:66
const std::string s_EventDataSvc
the default name for Event Data Service
Definition: GaudiTool.cpp:44
An abstract interface for Algorithm Context Service.
virtual StatusCode initialize()
standard initialization method
virtual StatusCode finalize()
standard finalization method
Definition: GaudiTool.cpp:189
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:723
long decrement(const std::string &object)
make the decrement
Definition: GaudiTool.cpp:78
static bool summaryEnabled()
is summary enabled?
Definition: GaudiTool.cpp:135
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:22
IDataProviderSvc * detSvc() const
accessor to detector service
Definition: GaudiTool.cpp:214