| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 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   TYPE* 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;
    00318   inline IDataProviderSvc * fastContainersSvc() const;
    00319 public:
    00343   StatusCode Error
    00344   ( const std::string& msg ,
    00345     const StatusCode   st  = StatusCode::FAILURE ,
    00346     const size_t       mx  = 10                  ) const ;
    00370   StatusCode Warning
    00371   ( const std::string& msg ,
    00372     const StatusCode   st  = StatusCode::FAILURE ,
    00373     const size_t       mx  = 10                  ) const ;
    00389   StatusCode Info
    00390   ( const std::string& msg ,
    00391     const StatusCode   st  = StatusCode::SUCCESS ,
    00392     const size_t       mx  = 10                  ) const ;
    00404   StatusCode Print
    00405   ( const std::string& msg ,
    00406     const StatusCode   st  = StatusCode::SUCCESS ,
    00407     const MSG::Level   lev = MSG::INFO           ) const ;
    00416   inline void Assert
    00417   ( const bool         ok                            ,
    00418     const std::string& message = ""                  ,
    00419     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00428   inline void Assert
    00429   ( const bool         ok                            ,
    00430     const char*        message                       ,
    00431     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00440   void Exception
    00441   ( const std::string    & msg                        ,
    00442     const GaudiException & exc                        ,
    00443     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00453   void Exception
    00454   ( const std::string    & msg                        ,
    00455     const std::exception & exc                        ,
    00456     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00465   void Exception
    00466   ( const std::string& msg = "no message"        ,
    00467     const StatusCode   sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00468 public: // predefined streams
    00479   inline MsgStream& msgStream ( const MSG::Level level ) const ;
    00481   inline MsgStream&  always () const { return msgStream ( MSG::ALWAYS ) ; }
    00483   inline MsgStream&   fatal () const { return msgStream ( MSG::FATAL ) ; }
    00485   inline MsgStream&     err () const { return msgStream ( MSG::ERROR ) ; }
    00487   inline MsgStream&   error () const { return msgStream ( MSG::ERROR ) ; }
    00489   inline MsgStream& warning () const { return msgStream ( MSG::WARNING ) ; }
    00491   inline MsgStream&    info () const { return msgStream ( MSG::INFO ) ; }
    00493   inline MsgStream&   debug () const { return msgStream ( MSG::DEBUG ) ; }
    00495   inline MsgStream& verbose () const { return msgStream ( MSG::VERBOSE ) ; }
    00497   inline MsgStream&     msg () const { return msgStream ( MSG::INFO ) ; }
    00498 public:
    00499   // ==========================================================================
    00501   inline const Statistics& counters() const { return m_counters ; }
    00520   inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; }
    00521   // ==========================================================================
    00522 public:
    00526   inline MSG::Level msgLevel() const { return m_msgLevel ; }
    00533   inline bool msgLevel( const MSG::Level level ) const { return msgLevel() <= level ; }
    00538   void resetMsgStream() const;
    00540   inline bool typePrint     () const { return m_typePrint    ; }
    00542   inline bool propsPrint    () const { return m_propsPrint   ; }
    00544   inline bool statPrint     () const { return m_statPrint    ; }
    00546   inline bool errorsPrint   () const { return m_errorsPrint  ; }
    00547   // ==========================================================================
    00548 private:
    00549   // ==========================================================================
    00555   void msgLevelHandler ( Property& theProp );
    00556   // ==========================================================================
    00557 public:
    00562   long printStat   ( const MSG::Level level = MSG::ALWAYS ) const ;
    00567   long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ;
    00572   long printProps ( const MSG::Level level = MSG::ALWAYS ) const ;
    00588   template <class CallerClass>
    00589   inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = NULL) {
    00590     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00591   }
    00622   template <class CallerClass, class CondType>
    00623   inline void registerCondition(const std::string &condition, CondType *&condPtrDest,
    00624                                 StatusCode (CallerClass::*mf)() = NULL) {
    00625     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest);
    00626   }
    00628   template <class CallerClass>
    00629   inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00630     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf);
    00631   }
    00647   template <class CallerClass,class TargetClass>
    00648   inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00649     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00650   }
    00662   inline StatusCode runUpdate() { return updMgrSvc()->update(this); }
    00666   template <class T>
    00667   TransientFastContainer<T> * getFastContainer
    00668   ( const std::string &location,
    00669     typename TransientFastContainer<T>::size_type initial=0);
    00670 public:
    00672   GaudiCommon ( const std::string & name,
    00673                 ISvcLocator * pSvcLocator );
    00675   GaudiCommon ( const std::string& type   ,
    00676                 const std::string& name   ,
    00677                 const IInterface*  parent );
    00678 public:
    00682   virtual StatusCode initialize()
    00683 #ifdef __ICC
    00684    { return i_gcInitialize(); }
    00685   StatusCode i_gcInitialize()
    00686 #endif
    00687   ;
    00691   virtual StatusCode finalize()
    00692 #ifdef __ICC
    00693    { return i_gcFinalize(); }
    00694   StatusCode i_gcFinalize()
    00695 #endif
    00696   ;
    00697 protected:
    00699   virtual ~GaudiCommon() {resetMsgStream();}
    00700 private :
    00701   // default constructor is disabled
    00702   GaudiCommon() ;
    00703   // copy    constructor is disabled
    00704   GaudiCommon           ( const GaudiCommon& ) ;
    00705   // assignment operator is disabled
    00706   GaudiCommon& operator=( const GaudiCommon& ) ;
    00707 protected:
    00709   StatusCode releaseTool ( const IAlgTool*   tool ) const ;
    00711   StatusCode releaseSvc  ( const IInterface* svc  ) const ;
    00712 public:
    00732   StatusCode release ( const IInterface* interface ) const ;
    00733   // ==========================================================================
    00734 public:
    00735   // ==========================================================================
    00737   const AlgTools& tools    () const { return m_tools    ; }    // get all tools
    00739   const Services& services () const { return m_services ; } // get all services
    00740   // ==========================================================================
    00741 private:
    00742   // ==========================================================================
    00744   void printErrorHandler ( Property& /* theProp */ ) ;     //      "ErrorPrint"
    00746   void printPropsHandler ( Property& /* theProp */ ) ;     // "PropertiesPrint"
    00748   void printStatHandler  ( Property& /* theProp */ ) ;     //       "StatPrint"
    00749   // ==========================================================================
    00750 public:
    00751   // ==========================================================================
    00753   inline const std::string & context() const { return m_context; }
    00757   inline const std::string & rootInTES() const { return m_rootInTES; }
    00759   inline double globalTimeOffset() const { return m_globalTimeOffset; }
    00760 private:
    00762   void addToToolList    ( IAlgTool * tool ) const;
    00764   void addToServiceList ( const SmartIF<IService>& svc ) const;
    00766   void initGaudiCommonConstructor( const IInterface * parent = 0 );
    00768   const std::string fullTESLocation( const std::string & location,
    00769                                      const bool useRootInTES ) const;
    00770 private:
    00772   MSG::Level  m_msgLevel    ;
    00773 private:
    00775   mutable MsgStream* m_msgStream   ;
    00777   mutable AlgTools   m_tools       ;
    00779   mutable Services   m_services    ;
    00780   // ==========================================================================
    00782   mutable Counter    m_errors      ;
    00784   mutable Counter    m_warnings    ;
    00786   mutable Counter    m_infos       ;
    00788   mutable Counter    m_exceptions  ;
    00790   mutable Statistics m_counters    ;
    00791   // ==========================================================================
    00793   mutable IUpdateManagerSvc* m_updMgrSvc;
    00795   mutable IDataProviderSvc* m_fastContainersSvc;
    00796   // ==========================================================================
    00798   bool        m_typePrint     ;
    00800   bool        m_propsPrint    ;
    00802   bool        m_statPrint     ;
    00804   bool        m_errorsPrint   ;
    00805   // ==========================================================================
    00807   std::string m_context;
    00809   std::string m_rootInTES;
    00813   std::string m_rootOnTES;
    00815   double m_globalTimeOffset;
    00816   // ==========================================================================
    00817   // the header row
    00818   std::string    m_header  ;
    00819   // format for regular statistical printout rows
    00820   std::string    m_format1 ;
    00821   // format for "efficiency" statistical printout rows
    00822   std::string    m_format2 ;
    00823   // flag to use the special "efficiency" format
    00824   bool           m_useEffFormat ;
    00825 } ;
    00826 // ============================================================================
    00827 #include "GaudiAlg/GaudiCommonImp.h"
    00828 // ============================================================================
    00829
    00830 // ============================================================================
    00831 // The END
    00832 // ============================================================================
    00833 #endif // GAUDIALG_GAUDICOMMON_H
    00834 // ============================================================================