![]() |
|
|
Generated: 24 Nov 2008 |
00001 // $Id: GaudiTool.cpp,v 1.10 2007/09/25 16:12:41 marcocle Exp $ 00002 // ============================================================================ 00003 // Include files 00004 // ============================================================================ 00005 // GaudiKernel 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 // GaudiAlg 00016 // ============================================================================ 00017 #include "GaudiAlg/GaudiTool.h" 00018 #include "GaudiAlg/GaudiAlgorithm.h" 00019 // ============================================================================ 00027 // ============================================================================ 00028 // templated methods 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 // constructor 00065 Counter ( const std::string& msg = " Misbalance ") 00066 : m_map () 00067 , m_message ( msg ) 00068 {}; 00069 // destructor 00070 ~Counter() { report() ; m_map.clear() ;} 00071 // make the increment 00072 long increment ( const std::string& object ) { return ++m_map[object] ; } 00073 // make the decrement 00074 long decrement ( const std::string& object ) { return --m_map[object] ; } 00075 // current count 00076 long counts ( const std::string& object ) { return m_map[object] ; } 00077 // make a report 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 // Standard constructor 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 // services 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 ) // pointer to Algorithm Context Service 00127 , m_contextSvcName ( "AlgContextSvc" ) // Algorithm Context Service name 00128 // 00129 , m_local ( this_type + "/" + this_name ) 00130 { 00131 declareProperty 00132 ( "ContextService" , 00133 m_contextSvcName , 00134 "The name of Algorithm Context Service" ) ; 00135 // make instance counts 00136 GaudiToolLocal::s_InstanceCounter.increment ( m_local ) ; 00137 } 00138 // ============================================================================ 00139 // destructor 00140 // ============================================================================ 00141 GaudiTool::~GaudiTool() 00142 { 00143 GaudiToolLocal::s_InstanceCounter.decrement ( m_local ) ; 00144 } 00145 // ============================================================================ 00146 // standard initialization method 00147 // ============================================================================ 00148 StatusCode GaudiTool::initialize () 00149 { 00150 // initialize the base class 00151 const StatusCode sc = GaudiCommon<AlgTool>::initialize() ; 00152 if ( sc.isFailure() ) { return sc; } 00153 00154 // increment the counter 00155 GaudiToolLocal::s_FinalizeCounter.increment( m_local ) ; 00156 00157 // return 00158 return sc; 00159 } 00160 // ============================================================================ 00161 // standard finalization method 00162 // ============================================================================ 00163 StatusCode GaudiTool::finalize () 00164 { 00165 if ( msgLevel(MSG::DEBUG) ) 00166 debug() << " ==> Finalize the base class GaudiTool " << endreq; 00167 00168 // clear "explicit services" 00169 m_evtSvc = 0 ; 00170 m_detSvc = 0 ; 00171 m_chronoSvc = 0 ; 00172 m_incSvc = 0 ; 00173 m_histoSvc = 0 ; 00174 00175 // finalize the base class 00176 const StatusCode sc = GaudiCommon<AlgTool>::finalize() ; 00177 if ( sc.isFailure() ) { return sc; } 00178 00179 // Decrement the counter 00180 GaudiToolLocal::s_FinalizeCounter.decrement( m_local ) ; 00181 00182 // return 00183 return sc; 00184 } 00185 // ============================================================================ 00186 // accessor to detector service 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 // The standard N-Tuple 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 // The standard event collection service 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 // accessor to event service service 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 // accessor to Incident Service 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 // accessor to Chrono & Stat Service 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 // accessor to histogram Service 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 // accessor to Algorithm Context Service 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 // The END 00279 // ============================================================================