| # Gaudi Framework, version v23r0 |

Home |  | Generated: Mon Jan 30 2012

# GaudiCommon.h

Go to the documentation of this file.

    00001 // $Id: GaudiCommon.h,v 1.18 2008/10/27 19:22:20 marcocle Exp $
    00002 // ============================================================================
    00003 #ifndef GAUDIALG_GAUDICOMMON_H
    00004 #define GAUDIALG_GAUDICOMMON_H 1
    00005 // ============================================================================
    00006 // Include files
    00007 // ============================================================================
    00008 // from STL
    00009 // ============================================================================
    00010 #include <string>
    00011 #include <vector>
    00012 #include <map>
    00013 #include <algorithm>
    00014 // ============================================================================
    00015 // GaudiKernel
    00016 // ============================================================================
    00017 #include "GaudiKernel/StatusCode.h"
    00018 #include "GaudiKernel/IMessageSvc.h"
    00019 #include "GaudiKernel/IToolSvc.h"
    00020 #include "GaudiKernel/IAlgTool.h"
    00021 #include "GaudiKernel/IAlgContextSvc.h"
    00022 #include "GaudiKernel/IDataProviderSvc.h"
    00023 #include "GaudiKernel/SmartDataPtr.h"
    00024 #include "GaudiKernel/System.h"
    00025 #include "GaudiKernel/GaudiException.h"
    00026 #include "GaudiKernel/IChronoStatSvc.h"
    00027 #include "GaudiKernel/StatEntity.h"
    00028 #include "GaudiKernel/ICounterSummarySvc.h"
    00029 #include "GaudiKernel/IUpdateManagerSvc.h"
    00030 #include "GaudiKernel/HashMap.h"
    00031 // ============================================================================
    00032 // forward declarations
    00033 // ============================================================================
    00034 class Algorithm ; // GaudiKernel
    00035 class AlgTool   ; // GaudiKernel
    00036 namespace Gaudi { namespace Utils { template <class TYPE> struct GetData ; } }
    00037 // ============================================================================
    00038 /*  @file GaudiCommon.h
    00039  *
    00040  *  Header file for class : GaudiCommon
    00041  *
    00042  *  @author Chris Jones   Christopher.Rob.Jones@cern.ch
    00043  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
    00044  *  @author Rob Lambert Rob.Lambert@cern.ch
    00045  *  @date   2009-08-04
    00046  */
    00047 // ============================================================================
    00057 // ============================================================================
    00058 template < class PBASE >
    00059 class GAUDI_API GaudiCommon: public PBASE
    00060 {
    00061 protected: // definitions
    00071   static const bool IgnoreRootInTES = false;
    00083   static const bool UseRootInTES = true;
    00084   // ==========================================================================
    00085 protected: // few actual data types
    00086   // ==========================================================================
    00088   typedef std::map<std::string,StatEntity>   Statistics ;
    00090   typedef std::map<std::string,unsigned int> Counter      ;
    00092   typedef std::vector<IAlgTool*>             AlgTools     ;
    00094   typedef GaudiUtils::HashMap<std::string, SmartIF<IService> > Services;
    00095   // ==========================================================================
    00096   //protected members such that they can be used in the derived classes
    00098   ICounterSummarySvc* m_counterSummarySvc;
    00100   std::vector<std::string> m_counterList;
    00101   //list of stat entities to write. Set by property StatEntityList. This can be a regular expression.
    00102   std::vector<std::string> m_statEntityList;
    00103 public:
    00104   // ==========================================================================
    00138   template < class TYPE >
    00139   typename Gaudi::Utils::GetData<TYPE>::return_type
    00140   get ( IDataProviderSvc*  svc         ,
    00141         const std::string& location    ,
    00142         const bool useRootInTES = true ) const ;
    00169   template < class TYPE >
    00170   bool  exist    ( IDataProviderSvc*  svc      ,
    00171                    const std::string& location ,
    00172                    const bool useRootInTES = true ) const ;
    00200   template < class TYPE , class TYPE2 >
    00201   typename Gaudi::Utils::GetData<TYPE>::return_type
    00202   getOrCreate ( IDataProviderSvc*  svc                 ,
    00203                 const std::string& location            ,
    00204                 const bool         useRootInTES = true ) const  ;
    00230   DataObject* put ( IDataProviderSvc*  svc ,
    00231              DataObject*        object   ,
    00232              const std::string& location  ,
    00233              const bool useRootInTES = true ) const ;
    00259   template < class TOOL >
    00260   TOOL* tool ( const std::string& type           ,
    00261                const std::string& name           ,
    00262                const IInterface*  parent  = 0    ,
    00263                bool               create  = true ) const ;
    00286   template < class TOOL >
    00287   TOOL* tool ( const std::string& type          ,
    00288                const IInterface*  parent = 0    ,
    00289                bool               create = true ) const ;
    00312   template < class SERVICE >
    00313   SmartIF<SERVICE> svc ( const std::string& name           ,
    00314                          const bool         create = true ) const ;
    00316   inline IUpdateManagerSvc * updMgrSvc() const;
    00317 public:
    00341   StatusCode Error
    00342   ( const std::string& msg ,
    00343     const StatusCode   st  = StatusCode::FAILURE ,
    00344     const size_t       mx  = 10                  ) const ;
    00368   StatusCode Warning
    00369   ( const std::string& msg ,
    00370     const StatusCode   st  = StatusCode::FAILURE ,
    00371     const size_t       mx  = 10                  ) const ;
    00387   StatusCode Info
    00388   ( const std::string& msg ,
    00389     const StatusCode   st  = StatusCode::SUCCESS ,
    00390     const size_t       mx  = 10                  ) const ;
    00402   StatusCode Print
    00403   ( const std::string& msg ,
    00404     const StatusCode   st  = StatusCode::SUCCESS ,
    00405     const MSG::Level   lev = MSG::INFO           ) const ;
    00414   inline void Assert
    00415   ( const bool         ok                            ,
    00416     const std::string& message = ""                  ,
    00417     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00426   inline void Assert
    00427   ( const bool         ok                            ,
    00428     const char*        message                       ,
    00429     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00438   void Exception
    00439   ( const std::string    & msg                        ,
    00440     const GaudiException & exc                        ,
    00441     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00451   void Exception
    00452   ( const std::string    & msg                        ,
    00453     const std::exception & exc                        ,
    00454     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00463   void Exception
    00464   ( const std::string& msg = "no message"        ,
    00465     const StatusCode   sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00466 public: // predefined streams
    00477   inline MsgStream& msgStream ( const MSG::Level level ) const ;
    00479   inline MsgStream&  always () const { return msgStream ( MSG::ALWAYS ) ; }
    00481   inline MsgStream&   fatal () const { return msgStream ( MSG::FATAL ) ; }
    00483   inline MsgStream&     err () const { return msgStream ( MSG::ERROR ) ; }
    00485   inline MsgStream&   error () const { return msgStream ( MSG::ERROR ) ; }
    00487   inline MsgStream& warning () const { return msgStream ( MSG::WARNING ) ; }
    00489   inline MsgStream&    info () const { return msgStream ( MSG::INFO ) ; }
    00491   inline MsgStream&   debug () const { return msgStream ( MSG::DEBUG ) ; }
    00493   inline MsgStream& verbose () const { return msgStream ( MSG::VERBOSE ) ; }
    00495   inline MsgStream&     msg () const { return msgStream ( MSG::INFO ) ; }
    00496 public:
    00497   // ==========================================================================
    00499   inline const Statistics& counters() const { return m_counters ; }
    00518   inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; }
    00519   // ==========================================================================
    00520 public:
    00524   inline MSG::Level msgLevel() const { return m_msgLevel ; }
    00531   inline bool msgLevel( const MSG::Level level ) const { return msgLevel() <= level ; }
    00536   void resetMsgStream() const;
    00538   inline bool typePrint     () const { return m_typePrint    ; }
    00540   inline bool propsPrint    () const { return m_propsPrint   ; }
    00542   inline bool statPrint     () const { return m_statPrint    ; }
    00544   inline bool errorsPrint   () const { return m_errorsPrint  ; }
    00545   // ==========================================================================
    00546 private:
    00547   // ==========================================================================
    00553   void msgLevelHandler ( Property& theProp );
    00554   // ==========================================================================
    00555 public:
    00560   long printStat   ( const MSG::Level level = MSG::ALWAYS ) const ;
    00565   long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ;
    00570   long printProps ( const MSG::Level level = MSG::ALWAYS ) const ;
    00586   template <class CallerClass>
    00587   inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = NULL) {
    00588     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00589   }
    00620   template <class CallerClass, class CondType>
    00621   inline void registerCondition(const std::string &condition, CondType *&condPtrDest,
    00622                                 StatusCode (CallerClass::*mf)() = NULL) {
    00623     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest);
    00624   }
    00626   template <class CallerClass>
    00627   inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00628     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf);
    00629   }
    00645   template <class CallerClass,class TargetClass>
    00646   inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00647     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00648   }
    00660   inline StatusCode runUpdate() { return updMgrSvc()->update(this); }
    00661 public:
    00663   GaudiCommon ( const std::string & name,
    00664                 ISvcLocator * pSvcLocator );
    00666   GaudiCommon ( const std::string& type   ,
    00667                 const std::string& name   ,
    00668                 const IInterface*  parent );
    00669 public:
    00673   virtual StatusCode initialize()
    00674 #ifdef __ICC
    00675    { return i_gcInitialize(); }
    00676   StatusCode i_gcInitialize()
    00677 #endif
    00678   ;
    00682   virtual StatusCode finalize()
    00683 #ifdef __ICC
    00684    { return i_gcFinalize(); }
    00685   StatusCode i_gcFinalize()
    00686 #endif
    00687   ;
    00688 protected:
    00690   virtual ~GaudiCommon() {resetMsgStream();}
    00691 private :
    00692   // default constructor is disabled
    00693   GaudiCommon() ;
    00694   // copy    constructor is disabled
    00695   GaudiCommon           ( const GaudiCommon& ) ;
    00696   // assignment operator is disabled
    00697   GaudiCommon& operator=( const GaudiCommon& ) ;
    00698 protected:
    00700   StatusCode releaseTool ( const IAlgTool*   tool ) const ;
    00702   StatusCode releaseSvc  ( const IInterface* svc  ) const ;
    00703 public:
    00723   StatusCode release ( const IInterface* interface ) const ;
    00725   virtual inline unsigned long release() { return PBASE::release(); }
    00726   // ==========================================================================
    00727 public:
    00728   // ==========================================================================
    00730   const AlgTools& tools    () const { return m_tools    ; }    // get all tools
    00732   const Services& services () const { return m_services ; } // get all services
    00733   // ==========================================================================
    00734 private:
    00735   // ==========================================================================
    00737   void printErrorHandler ( Property& /* theProp */ ) ;     //      "ErrorPrint"
    00739   void printPropsHandler ( Property& /* theProp */ ) ;     // "PropertiesPrint"
    00741   void printStatHandler  ( Property& /* theProp */ ) ;     //       "StatPrint"
    00742   // ==========================================================================
    00743 public:
    00744   // ==========================================================================
    00746   inline const std::string & context() const { return m_context; }
    00750   inline const std::string & rootInTES() const { return m_rootInTES; }
    00752   inline double globalTimeOffset() const { return m_globalTimeOffset; }
    00753 private:
    00755   void addToToolList    ( IAlgTool * tool ) const;
    00757   void addToServiceList ( const SmartIF<IService>& svc ) const;
    00759   void initGaudiCommonConstructor( const IInterface * parent = 0 );
    00761   const std::string fullTESLocation( const std::string & location,
    00762                                      const bool useRootInTES ) const;
    00763 private:
    00765   MSG::Level  m_msgLevel    ;
    00766 private:
    00768   mutable MsgStream* m_msgStream   ;
    00770   mutable AlgTools   m_tools       ;
    00772   mutable Services   m_services    ;
    00773   // ==========================================================================
    00775   mutable Counter    m_errors      ;
    00777   mutable Counter    m_warnings    ;
    00779   mutable Counter    m_infos       ;
    00781   mutable Counter    m_exceptions  ;
    00783   mutable Statistics m_counters    ;
    00784   // ==========================================================================
    00786   mutable IUpdateManagerSvc* m_updMgrSvc;
    00787   // ==========================================================================
    00789   bool        m_typePrint     ;
    00791   bool        m_propsPrint    ;
    00793   bool        m_statPrint     ;
    00795   bool        m_errorsPrint   ;
    00796   // ==========================================================================
    00798   std::string m_context;
    00800   std::string m_rootInTES;
    00804   std::string m_rootOnTES;
    00806   double m_globalTimeOffset;
    00807   // ==========================================================================
    00808   // the header row
    00809   std::string    m_header  ;
    00810   // format for regular statistical printout rows
    00811   std::string    m_format1 ;
    00812   // format for "efficiency" statistical printout rows
    00813   std::string    m_format2 ;
    00814   // flag to use the special "efficiency" format
    00815   bool           m_useEffFormat ;
    00816 } ;
    00817 // ============================================================================
    00818 #include "GaudiAlg/GaudiCommonImp.h"
    00819 // ============================================================================
    00820
    00821 // ============================================================================
    00822 // The END
    00823 // ============================================================================
    00824 #endif // GAUDIALG_GAUDICOMMON_H
    00825 // ============================================================================

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines