Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "GaudiKernel/IChronoStatSvc.h"
00008 #include "GaudiKernel/IIncidentSvc.h"
00009 #include "GaudiKernel/IDataProviderSvc.h"
00010 #include "GaudiKernel/IHistogramSvc.h"
00011 #include "GaudiKernel/INTupleSvc.h"
00012 #include "GaudiKernel/IAlgContextSvc.h"
00013 #include "GaudiKernel/Bootstrap.h"
00014
00015
00016
00017 #include "GaudiAlg/GaudiTool.h"
00018 #include "GaudiAlg/GaudiAlgorithm.h"
00019
00027
00028
00029
00030 #include "GaudiCommon.icpp"
00031
00032 template class GaudiCommon<AlgTool>;
00033
00040
00041 namespace GaudiToolServices
00042 {
00044 const std::string s_EventDataSvc = "EventDataSvc" ;
00046 const std::string s_DetectorDataSvc = "DetectorDataSvc" ;
00048 const std::string s_ChronoStatSvc = "ChronoStatSvc" ;
00050 const std::string s_IncidentSvc = "IncidentSvc" ;
00052 const std::string s_HistoSvc = "HistogramDataSvc" ;
00053 }
00054
00055 namespace GaudiToolLocal
00056 {
00057
00061 class Counter
00062 {
00063 public:
00064
00065
00066 Counter ( const std::string& msg = " Misbalance ")
00067 : m_map ()
00068 , m_message ( msg )
00069 {};
00070
00071 ~Counter() { report() ; m_map.clear() ;}
00072
00073 public:
00074
00076 long increment ( const std::string& object ) { return ++m_map[object] ; }
00078 long decrement ( const std::string& object ) { return --m_map[object] ; }
00080 long counts ( const std::string& object ) { return m_map[object] ; }
00082 void report() const
00083 {
00085 if ( !GaudiTool::summaryEnabled() ) { return ; }
00086
00087 for ( Map::const_iterator entry = m_map.begin() ;
00088 m_map.end() != entry ; ++entry )
00089 {
00090 if( 0 == entry->second ) { continue ; }
00091 std::cout << "GaudiTool WARNING " << m_message
00092 << "'" << entry->first << "' Counts = " << entry->second
00093 << std::endl ;
00094 }
00095 }
00096
00097 private:
00098
00099 typedef std::map<std::string,long> Map;
00100 Map m_map ;
00101 std::string m_message ;
00102
00103 };
00104
00110 static Counter s_InstanceCounter ( " Create/Destroy (mis)balance " ) ;
00111
00117 static Counter s_FinalizeCounter ( " Initialize/Finalize (mis)balance " ) ;
00118
00119 }
00120
00122
00123 bool GaudiTool::s_enableSummary = true ;
00124
00125
00126
00127 bool GaudiTool::enableSummary ( bool value )
00128 {
00129 s_enableSummary = value ;
00130 return summaryEnabled () ;
00131 }
00132
00133
00134
00135 bool GaudiTool::summaryEnabled ()
00136 { return s_enableSummary ; }
00137
00138
00139
00140 GaudiTool::GaudiTool ( const std::string& this_type ,
00141 const std::string& this_name ,
00142 const IInterface* parent )
00143 : GaudiCommon<AlgTool> ( this_type , this_name , parent )
00144
00145 , m_ntupleSvc ( 0 )
00146 , m_evtColSvc ( 0 )
00147 , m_evtSvc ( 0 )
00148 , m_detSvc ( 0 )
00149 , m_chronoSvc ( 0 )
00150 , m_incSvc ( 0 )
00151 , m_histoSvc ( 0 )
00152 , m_contextSvc ( 0 )
00153 , m_contextSvcName ( "AlgContextSvc" )
00154
00155 , m_local ( this_type + "/" + this_name )
00156 {
00157 declareProperty
00158 ( "ContextService" ,
00159 m_contextSvcName ,
00160 "The name of Algorithm Context Service" ) ;
00161
00162 GaudiToolLocal::s_InstanceCounter.increment ( m_local ) ;
00163 }
00164
00165
00166
00167 GaudiTool::~GaudiTool()
00168 {
00169 GaudiToolLocal::s_InstanceCounter.decrement ( m_local ) ;
00170 }
00171
00172
00173
00174 StatusCode GaudiTool::initialize ()
00175 {
00176
00177 const StatusCode sc = GaudiCommon<AlgTool>::initialize() ;
00178 if ( sc.isFailure() ) { return sc; }
00179
00180
00181 GaudiToolLocal::s_FinalizeCounter.increment( m_local ) ;
00182
00183
00184 return sc;
00185 }
00186
00187
00188
00189 StatusCode GaudiTool::finalize ()
00190 {
00191 if ( msgLevel(MSG::DEBUG) )
00192 debug() << " ==> Finalize the base class GaudiTool " << endmsg;
00193
00194
00195 m_evtSvc = 0 ;
00196 m_detSvc = 0 ;
00197 m_chronoSvc = 0 ;
00198 m_incSvc = 0 ;
00199 m_histoSvc = 0 ;
00200
00201
00202 const StatusCode sc = GaudiCommon<AlgTool>::finalize() ;
00203 if ( sc.isFailure() ) { return sc; }
00204
00205
00206 GaudiToolLocal::s_FinalizeCounter.decrement( m_local ) ;
00207
00208
00209 return sc;
00210 }
00211
00212
00213
00214 IDataProviderSvc* GaudiTool::detSvc () const
00215 {
00216 if ( 0 == m_detSvc )
00217 {
00218 m_detSvc =
00219 svc<IDataProviderSvc>( GaudiToolServices::s_DetectorDataSvc , true ) ;
00220 }
00221 return m_detSvc ;
00222 }
00223
00224
00225
00226 INTupleSvc* GaudiTool::ntupleSvc () const
00227 {
00228 if ( 0 == m_ntupleSvc )
00229 {
00230 m_ntupleSvc = svc<INTupleSvc>( "NTupleSvc" , true ) ;
00231 }
00232 return m_ntupleSvc ;
00233 }
00234
00235
00236
00237 INTupleSvc* GaudiTool::evtColSvc () const
00238 {
00239 if ( 0 == m_evtColSvc )
00240 {
00241 m_evtColSvc = svc< INTupleSvc > ( "EvtTupleSvc" , true ) ;
00242 }
00243 return m_evtColSvc ;
00244 }
00245
00246
00247
00248 IDataProviderSvc* GaudiTool::evtSvc () const
00249 {
00250 if ( 0 == m_evtSvc )
00251 {
00252 m_evtSvc =
00253 svc<IDataProviderSvc>( GaudiToolServices::s_EventDataSvc , true ) ;
00254 }
00255 return m_evtSvc ;
00256 }
00257
00258
00259
00260 IIncidentSvc* GaudiTool::incSvc () const
00261 {
00262 if ( 0 == m_incSvc )
00263 {
00264 m_incSvc =
00265 svc<IIncidentSvc> ( GaudiToolServices::s_IncidentSvc , true ) ;
00266 }
00267 return m_incSvc ;
00268 }
00269
00270
00271
00272 IChronoStatSvc* GaudiTool::chronoSvc () const
00273 {
00274 if ( 0 == m_chronoSvc )
00275 {
00276 m_chronoSvc =
00277 svc<IChronoStatSvc> ( GaudiToolServices::s_ChronoStatSvc , true ) ;
00278 }
00279 return m_chronoSvc ;
00280 }
00281
00282
00283
00284 IHistogramSvc* GaudiTool::histoSvc () const
00285 {
00286 if ( 0 == m_histoSvc )
00287 {
00288 m_histoSvc = svc<IHistogramSvc> ( GaudiToolServices::s_HistoSvc, true ) ;
00289 }
00290 return m_histoSvc;
00291 }
00292
00293
00294
00295 IAlgContextSvc* GaudiTool::contextSvc () const
00296 {
00297 if ( 0 == m_contextSvc )
00298 {
00299 m_contextSvc = svc<IAlgContextSvc> ( m_contextSvcName , true ) ;
00300 }
00301 return m_contextSvc;
00302 }
00303
00304
00305