| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

# 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/TransientFastContainer.h"
    00031 #include "GaudiKernel/HashMap.h"
    00032 // ============================================================================
    00033 // forward declarations
    00034 // ============================================================================
    00035 class Algorithm ; // GaudiKernel
    00036 class AlgTool   ; // GaudiKernel
    00037 namespace Gaudi { namespace Utils { template <class TYPE> struct GetData ; } }
    00038 // ============================================================================
    00039 /*  @file GaudiCommon.h
    00040  *
    00041  *  Header file for class : GaudiCommon
    00042  *
    00043  *  @author Chris Jones   Christopher.Rob.Jones@cern.ch
    00044  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
    00045  *  @author Rob Lambert Rob.Lambert@cern.ch
    00046  *  @date   2009-08-04
    00047  */
    00048 // ============================================================================
    00058 // ============================================================================
    00059 template < class PBASE >
    00060 class GAUDI_API GaudiCommon: public PBASE
    00061 {
    00062 protected: // definitions
    00072   static const bool IgnoreRootInTES = false;
    00084   static const bool UseRootInTES = true;
    00085   // ==========================================================================
    00086 protected: // few actual data types
    00087   // ==========================================================================
    00089   typedef std::map<std::string,StatEntity>   Statistics ;
    00091   typedef std::map<std::string,unsigned int> Counter      ;
    00093   typedef std::vector<IAlgTool*>             AlgTools     ;
    00095   typedef GaudiUtils::HashMap<std::string, SmartIF<IService> > Services;
    00096   // ==========================================================================
    00097   //protected members such that they can be used in the derived classes
    00099   ICounterSummarySvc* m_counterSummarySvc;
    00101   std::vector<std::string> m_counterList;
    00102   //list of stat entities to write. Set by property StatEntityList. This can be a regular expression.
    00103   std::vector<std::string> m_statEntityList;
    00104 public:
    00105   // ==========================================================================
    00139   template < class TYPE >
    00140   typename Gaudi::Utils::GetData<TYPE>::return_type
    00141   get ( IDataProviderSvc*  svc         ,
    00142         const std::string& location    ,
    00143         const bool useRootInTES = true ) const ;
    00170   template < class TYPE >
    00171   bool  exist    ( IDataProviderSvc*  svc      ,
    00172                    const std::string& location ,
    00173                    const bool useRootInTES = true ) const ;
    00201   template < class TYPE , class TYPE2 >
    00202   typename Gaudi::Utils::GetData<TYPE>::return_type
    00203   getOrCreate ( IDataProviderSvc*  svc                 ,
    00204                 const std::string& location            ,
    00205                 const bool         useRootInTES = true ) const  ;
    00231   DataObject* put ( IDataProviderSvc*  svc ,
    00232              DataObject*        object   ,
    00233              const std::string& location  ,
    00234              const bool useRootInTES = true ) const ;
    00260   template < class TOOL >
    00261   TOOL* tool ( const std::string& type           ,
    00262                const std::string& name           ,
    00263                const IInterface*  parent  = 0    ,
    00264                bool               create  = true ) const ;
    00287   template < class TOOL >
    00288   TOOL* tool ( const std::string& type          ,
    00289                const IInterface*  parent = 0    ,
    00290                bool               create = true ) const ;
    00313   template < class SERVICE >
    00314   SmartIF<SERVICE> svc ( const std::string& name           ,
    00315                          const bool         create = true ) const ;
    00317   inline IUpdateManagerSvc * updMgrSvc() const;
    00319   inline IDataProviderSvc * fastContainersSvc() const;
    00320 public:
    00344   StatusCode Error
    00345   ( const std::string& msg ,
    00346     const StatusCode   st  = StatusCode::FAILURE ,
    00347     const size_t       mx  = 10                  ) const ;
    00371   StatusCode Warning
    00372   ( const std::string& msg ,
    00373     const StatusCode   st  = StatusCode::FAILURE ,
    00374     const size_t       mx  = 10                  ) const ;
    00390   StatusCode Info
    00391   ( const std::string& msg ,
    00392     const StatusCode   st  = StatusCode::SUCCESS ,
    00393     const size_t       mx  = 10                  ) const ;
    00405   StatusCode Print
    00406   ( const std::string& msg ,
    00407     const StatusCode   st  = StatusCode::SUCCESS ,
    00408     const MSG::Level   lev = MSG::INFO           ) const ;
    00417   inline void Assert
    00418   ( const bool         ok                            ,
    00419     const std::string& message = ""                  ,
    00420     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00429   inline void Assert
    00430   ( const bool         ok                            ,
    00431     const char*        message                       ,
    00432     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00441   void Exception
    00442   ( const std::string    & msg                        ,
    00443     const GaudiException & exc                        ,
    00444     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00454   void Exception
    00455   ( const std::string    & msg                        ,
    00456     const std::exception & exc                        ,
    00457     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00466   void Exception
    00467   ( const std::string& msg = "no message"        ,
    00468     const StatusCode   sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00469 public: // predefined streams
    00480   inline MsgStream& msgStream ( const MSG::Level level ) const ;
    00482   inline MsgStream&  always () const { return msgStream ( MSG::ALWAYS ) ; }
    00484   inline MsgStream&   fatal () const { return msgStream ( MSG::FATAL ) ; }
    00486   inline MsgStream&     err () const { return msgStream ( MSG::ERROR ) ; }
    00488   inline MsgStream&   error () const { return msgStream ( MSG::ERROR ) ; }
    00490   inline MsgStream& warning () const { return msgStream ( MSG::WARNING ) ; }
    00492   inline MsgStream&    info () const { return msgStream ( MSG::INFO ) ; }
    00494   inline MsgStream&   debug () const { return msgStream ( MSG::DEBUG ) ; }
    00496   inline MsgStream& verbose () const { return msgStream ( MSG::VERBOSE ) ; }
    00498   inline MsgStream&     msg () const { return msgStream ( MSG::INFO ) ; }
    00499 public:
    00500   // ==========================================================================
    00502   inline const Statistics& counters() const { return m_counters ; }
    00521   inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; }
    00522   // ==========================================================================
    00523 public:
    00527   inline MSG::Level msgLevel() const { return m_msgLevel ; }
    00534   inline bool msgLevel( const MSG::Level level ) const { return msgLevel() <= level ; }
    00539   void resetMsgStream() const;
    00541   inline bool typePrint     () const { return m_typePrint    ; }
    00543   inline bool propsPrint    () const { return m_propsPrint   ; }
    00545   inline bool statPrint     () const { return m_statPrint    ; }
    00547   inline bool errorsPrint   () const { return m_errorsPrint  ; }
    00548   // ==========================================================================
    00549 private:
    00550   // ==========================================================================
    00556   void msgLevelHandler ( Property& theProp );
    00557   // ==========================================================================
    00558 public:
    00563   long printStat   ( const MSG::Level level = MSG::ALWAYS ) const ;
    00568   long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ;
    00573   long printProps ( const MSG::Level level = MSG::ALWAYS ) const ;
    00589   template <class CallerClass>
    00590   inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = NULL) {
    00591     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00592   }
    00623   template <class CallerClass, class CondType>
    00624   inline void registerCondition(const std::string &condition, CondType *&condPtrDest,
    00625                                 StatusCode (CallerClass::*mf)() = NULL) {
    00626     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest);
    00627   }
    00629   template <class CallerClass>
    00630   inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00631     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf);
    00632   }
    00648   template <class CallerClass,class TargetClass>
    00649   inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00650     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00651   }
    00663   inline StatusCode runUpdate() { return updMgrSvc()->update(this); }
    00667   template <class T>
    00668   TransientFastContainer<T> * getFastContainer
    00669   ( const std::string &location,
    00670     typename TransientFastContainer<T>::size_type initial=0);
    00671 public:
    00673   GaudiCommon ( const std::string & name,
    00674                 ISvcLocator * pSvcLocator );
    00676   GaudiCommon ( const std::string& type   ,
    00677                 const std::string& name   ,
    00678                 const IInterface*  parent );
    00679 public:
    00683   virtual StatusCode initialize()
    00684 #ifdef __ICC
    00685    { return i_gcInitialize(); }
    00686   StatusCode i_gcInitialize()
    00687 #endif
    00688   ;
    00692   virtual StatusCode finalize()
    00693 #ifdef __ICC
    00694    { return i_gcFinalize(); }
    00695   StatusCode i_gcFinalize()
    00696 #endif
    00697   ;
    00698 protected:
    00700   virtual ~GaudiCommon() {resetMsgStream();}
    00701 private :
    00702   // default constructor is disabled
    00703   GaudiCommon() ;
    00704   // copy    constructor is disabled
    00705   GaudiCommon           ( const GaudiCommon& ) ;
    00706   // assignment operator is disabled
    00707   GaudiCommon& operator=( const GaudiCommon& ) ;
    00708 protected:
    00710   StatusCode releaseTool ( const IAlgTool*   tool ) const ;
    00712   StatusCode releaseSvc  ( const IInterface* svc  ) const ;
    00713 public:
    00733   StatusCode release ( const IInterface* interface ) const ;
    00734   // ==========================================================================
    00735 public:
    00736   // ==========================================================================
    00738   const AlgTools& tools    () const { return m_tools    ; }    // get all tools
    00740   const Services& services () const { return m_services ; } // get all services
    00741   // ==========================================================================
    00742 private:
    00743   // ==========================================================================
    00745   void printErrorHandler ( Property& /* theProp */ ) ;     //      "ErrorPrint"
    00747   void printPropsHandler ( Property& /* theProp */ ) ;     // "PropertiesPrint"
    00749   void printStatHandler  ( Property& /* theProp */ ) ;     //       "StatPrint"
    00750   // ==========================================================================
    00751 public:
    00752   // ==========================================================================
    00754   inline const std::string & context() const { return m_context; }
    00758   inline const std::string & rootInTES() const { return m_rootInTES; }
    00760   inline double globalTimeOffset() const { return m_globalTimeOffset; }
    00761 private:
    00763   void addToToolList    ( IAlgTool * tool ) const;
    00765   void addToServiceList ( const SmartIF<IService>& svc ) const;
    00767   void initGaudiCommonConstructor( const IInterface * parent = 0 );
    00769   const std::string fullTESLocation( const std::string & location,
    00770                                      const bool useRootInTES ) const;
    00771 private:
    00773   MSG::Level  m_msgLevel    ;
    00774 private:
    00776   mutable MsgStream* m_msgStream   ;
    00778   mutable AlgTools   m_tools       ;
    00780   mutable Services   m_services    ;
    00781   // ==========================================================================
    00783   mutable Counter    m_errors      ;
    00785   mutable Counter    m_warnings    ;
    00787   mutable Counter    m_infos       ;
    00789   mutable Counter    m_exceptions  ;
    00791   mutable Statistics m_counters    ;
    00792   // ==========================================================================
    00794   mutable IUpdateManagerSvc* m_updMgrSvc;
    00796   mutable IDataProviderSvc* m_fastContainersSvc;
    00797   // ==========================================================================
    00799   bool        m_typePrint     ;
    00801   bool        m_propsPrint    ;
    00803   bool        m_statPrint     ;
    00805   bool        m_errorsPrint   ;
    00806   // ==========================================================================
    00808   std::string m_context;
    00810   std::string m_rootInTES;
    00814   std::string m_rootOnTES;
    00816   double m_globalTimeOffset;
    00817   // ==========================================================================
    00818   // the header row
    00819   std::string    m_header  ;
    00820   // format for regular statistical printout rows
    00821   std::string    m_format1 ;
    00822   // format for "efficiency" statistical printout rows
    00823   std::string    m_format2 ;
    00824   // flag to use the special "efficiency" format
    00825   bool           m_useEffFormat ;
    00826 } ;
    00827 // ============================================================================
    00828 #include "GaudiAlg/GaudiCommonImp.h"
    00829 // ============================================================================
    00830
    00831 // ============================================================================
    00832 // The END
    00833 // ============================================================================
    00834 #endif // GAUDIALG_GAUDICOMMON_H
    00835 // ============================================================================