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 Counter ( const std::string& msg = " Misbalance ")
00066 : m_map ()
00067 , m_message ( msg )
00068 {};
00069
00070 ~Counter() { report() ; m_map.clear() ;}
00071
00072 long increment ( const std::string& object ) { return ++m_map[object] ; }
00073
00074 long decrement ( const std::string& object ) { return --m_map[object] ; }
00075
00076 long counts ( const std::string& object ) { return m_map[object] ; }
00077
00078 void report() const
00079 {
00080 for ( Map::const_iterator entry = m_map.begin() ;
00081 m_map.end() != entry ; ++entry )
00082 {
00083 if( 0 == entry->second ) { continue ; }
00084 std::cout << "GaudiTool WARNING " << m_message
00085 << "'" << entry->first << "' Counts = " << entry->second
00086 << std::endl ;
00087 }
00088 };
00089
00090 private:
00091 typedef std::map<std::string,long> Map;
00092 Map m_map ;
00093 std::string m_message ;
00094 };
00095
00101 static Counter s_InstanceCounter ( " Create/Destroy (mis)balance " ) ;
00102
00108 static Counter s_FinalizeCounter ( " Initialize/Finalize (mis)balance " ) ;
00109
00110 }
00111
00112
00113
00114 GaudiTool::GaudiTool ( const std::string& this_type ,
00115 const std::string& this_name ,
00116 const IInterface* parent )
00117 : GaudiCommon<AlgTool> ( this_type , this_name , parent )
00118
00119 , m_ntupleSvc ( 0 )
00120 , m_evtColSvc ( 0 )
00121 , m_evtSvc ( 0 )
00122 , m_detSvc ( 0 )
00123 , m_chronoSvc ( 0 )
00124 , m_incSvc ( 0 )
00125 , m_histoSvc ( 0 )
00126 , m_contextSvc ( 0 )
00127 , m_contextSvcName ( "AlgContextSvc" )
00128
00129 , m_local ( this_type + "/" + this_name )
00130 {
00131 declareProperty
00132 ( "ContextService" ,
00133 m_contextSvcName ,
00134 "The name of Algorithm Context Service" ) ;
00135
00136 GaudiToolLocal::s_InstanceCounter.increment ( m_local ) ;
00137 }
00138
00139
00140
00141 GaudiTool::~GaudiTool()
00142 {
00143 GaudiToolLocal::s_InstanceCounter.decrement ( m_local ) ;
00144 }
00145
00146
00147
00148 StatusCode GaudiTool::initialize ()
00149 {
00150
00151 const StatusCode sc = GaudiCommon<AlgTool>::initialize() ;
00152 if ( sc.isFailure() ) { return sc; }
00153
00154
00155 GaudiToolLocal::s_FinalizeCounter.increment( m_local ) ;
00156
00157
00158 return sc;
00159 }
00160
00161
00162
00163 StatusCode GaudiTool::finalize ()
00164 {
00165 if ( msgLevel(MSG::DEBUG) )
00166 debug() << " ==> Finalize the base class GaudiTool " << endreq;
00167
00168
00169 m_evtSvc = 0 ;
00170 m_detSvc = 0 ;
00171 m_chronoSvc = 0 ;
00172 m_incSvc = 0 ;
00173 m_histoSvc = 0 ;
00174
00175
00176 const StatusCode sc = GaudiCommon<AlgTool>::finalize() ;
00177 if ( sc.isFailure() ) { return sc; }
00178
00179
00180 GaudiToolLocal::s_FinalizeCounter.decrement( m_local ) ;
00181
00182
00183 return sc;
00184 }
00185
00186
00187
00188 IDataProviderSvc* GaudiTool::detSvc () const
00189 {
00190 if ( 0 == m_detSvc )
00191 {
00192 m_detSvc =
00193 svc<IDataProviderSvc>( GaudiToolServices::s_DetectorDataSvc , true ) ;
00194 }
00195 return m_detSvc ;
00196 }
00197
00198
00199
00200 INTupleSvc* GaudiTool::ntupleSvc () const
00201 {
00202 if ( 0 == m_ntupleSvc )
00203 {
00204 m_ntupleSvc = svc<INTupleSvc>( "NTupleSvc" , true ) ;
00205 }
00206 return m_ntupleSvc ;
00207 }
00208
00209
00210
00211 INTupleSvc* GaudiTool::evtColSvc () const
00212 {
00213 if ( 0 == m_evtColSvc )
00214 {
00215 m_evtColSvc = svc< INTupleSvc > ( "EvtTupleSvc" , true ) ;
00216 }
00217 return m_evtColSvc ;
00218 }
00219
00220
00221
00222 IDataProviderSvc* GaudiTool::evtSvc () const
00223 {
00224 if ( 0 == m_evtSvc )
00225 {
00226 m_evtSvc =
00227 svc<IDataProviderSvc>( GaudiToolServices::s_EventDataSvc , true ) ;
00228 }
00229 return m_evtSvc ;
00230 }
00231
00232
00233
00234 IIncidentSvc* GaudiTool::incSvc () const
00235 {
00236 if ( 0 == m_incSvc )
00237 {
00238 m_incSvc =
00239 svc<IIncidentSvc> ( GaudiToolServices::s_IncidentSvc , true ) ;
00240 }
00241 return m_incSvc ;
00242 }
00243
00244
00245
00246 IChronoStatSvc* GaudiTool::chronoSvc () const
00247 {
00248 if ( 0 == m_chronoSvc )
00249 {
00250 m_chronoSvc =
00251 svc<IChronoStatSvc> ( GaudiToolServices::s_ChronoStatSvc , true ) ;
00252 }
00253 return m_chronoSvc ;
00254 }
00255
00256
00257
00258 IHistogramSvc* GaudiTool::histoSvc () const
00259 {
00260 if ( 0 == m_histoSvc )
00261 {
00262 m_histoSvc = svc<IHistogramSvc> ( GaudiToolServices::s_HistoSvc, true ) ;
00263 }
00264 return m_histoSvc;
00265 }
00266
00267
00268
00269 IAlgContextSvc* GaudiTool::contextSvc () const
00270 {
00271 if ( 0 == m_contextSvc )
00272 {
00273 m_contextSvc = svc<IAlgContextSvc> ( m_contextSvcName , true ) ;
00274 }
00275 return m_contextSvc;
00276 }
00277
00278
00279