Gaudi Framework, version v23r3

Home   Generated: Thu Jun 28 2012

GaudiTool.cpp

Go to the documentation of this file.
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     // ========================================================================
00065     // constructor
00066     Counter ( const std::string& msg = " Misbalance ")
00067       : m_map     ()
00068       , m_message ( msg )
00069     {};
00070     // destructor
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 ; } // 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 ;                  // summary is enabled
00124 // ============================================================================
00125 // enable/disable summary
00126 // ============================================================================
00127 bool GaudiTool::enableSummary  ( bool value )         // enable/disable summary
00128 {
00129   s_enableSummary = value ;
00130   return summaryEnabled () ;
00131 }
00132 // ============================================================================
00133 // is summary enabled?
00134 // ============================================================================
00135 bool GaudiTool::summaryEnabled ()                     // is summary enabled?
00136 { return s_enableSummary ; }
00137 // ============================================================================
00138 // Standard constructor
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   //  services
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 ) // pointer to Algorithm Context Service
00153   , m_contextSvcName ( "AlgContextSvc" ) // Algorithm Context Service name
00154   //
00155   , m_local       ( this_type + "/" + this_name )
00156 {
00157   declareProperty
00158     ( "ContextService" ,
00159       m_contextSvcName ,
00160       "The name of Algorithm Context Service" ) ;
00161   // make instance counts
00162   GaudiToolLocal::s_InstanceCounter.increment ( m_local ) ;
00163 }
00164 // ============================================================================
00165 // destructor
00166 // ============================================================================
00167 GaudiTool::~GaudiTool()
00168 {
00169   GaudiToolLocal::s_InstanceCounter.decrement ( m_local ) ;
00170 }
00171 // ============================================================================
00172 // standard initialization method
00173 // ============================================================================
00174 StatusCode    GaudiTool::initialize ()
00175 {
00176   // initialize the base class
00177   const StatusCode sc = GaudiCommon<AlgTool>::initialize() ;
00178   if ( sc.isFailure() ) { return sc; }
00179 
00180   // increment the counter
00181   GaudiToolLocal::s_FinalizeCounter.increment( m_local ) ;
00182 
00183   // return
00184   return sc;
00185 }
00186 // ============================================================================
00187 // standard finalization method
00188 // ============================================================================
00189 StatusCode    GaudiTool::finalize   ()
00190 {
00191   if ( msgLevel(MSG::DEBUG) )
00192     debug() << " ==> Finalize the base class GaudiTool " << endmsg;
00193 
00194   // clear "explicit services"
00195     m_evtSvc    = 0 ;
00196     m_detSvc    = 0 ;
00197     m_chronoSvc = 0 ;
00198     m_incSvc    = 0 ;
00199     m_histoSvc  = 0 ;
00200 
00201   // finalize the base class
00202   const StatusCode sc = GaudiCommon<AlgTool>::finalize() ;
00203   if ( sc.isFailure() ) { return sc; }
00204 
00205   // Decrement the counter
00206   GaudiToolLocal::s_FinalizeCounter.decrement( m_local ) ;
00207 
00208   // return
00209   return sc;
00210 }
00211 // ============================================================================
00212 // accessor to detector service
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 // The standard N-Tuple
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 // The standard event collection service
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 // accessor to event service  service
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 // accessor to Incident Service
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 // accessor to Chrono & Stat Service
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 // accessor to histogram Service
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 // accessor to Algorithm Context Service
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 // The END
00305 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 12:29:52 for Gaudi Framework, version v23r3 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004