| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# 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 ;
    00418   inline StatusCode Assert
    00419   ( const bool         ok                            ,
    00420     const std::string& message = ""                  ,
    00421     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00432   inline StatusCode Assert
    00433   ( const bool         ok                            ,
    00434     const char*        message                       ,
    00435     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00446   StatusCode Exception
    00447   ( const std::string    & msg                        ,
    00448     const GaudiException & exc                        ,
    00449     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00460   StatusCode Exception
    00461   ( const std::string    & msg                        ,
    00462     const std::exception & exc                        ,
    00463     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00473   StatusCode Exception
    00474   ( const std::string& msg = "no message"        ,
    00475     const StatusCode   sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00476 public: // predefined streams
    00487   inline MsgStream& msgStream ( const MSG::Level level ) const ;
    00489   inline MsgStream&  always () const { return msgStream ( MSG::ALWAYS ) ; }
    00491   inline MsgStream&   fatal () const { return msgStream ( MSG::FATAL ) ; }
    00493   inline MsgStream&     err () const { return msgStream ( MSG::ERROR ) ; }
    00495   inline MsgStream&   error () const { return msgStream ( MSG::ERROR ) ; }
    00497   inline MsgStream& warning () const { return msgStream ( MSG::WARNING ) ; }
    00499   inline MsgStream&    info () const { return msgStream ( MSG::INFO ) ; }
    00501   inline MsgStream&   debug () const { return msgStream ( MSG::DEBUG ) ; }
    00503   inline MsgStream& verbose () const { return msgStream ( MSG::VERBOSE ) ; }
    00505   inline MsgStream&     msg () const { return msgStream ( MSG::INFO ) ; }
    00506 public:
    00507   // ==========================================================================
    00509   inline const Statistics& counters() const { return m_counters ; }
    00528   inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; }
    00529   // ==========================================================================
    00530 public:
    00534   inline MSG::Level msgLevel() const { return m_msgLevel ; }
    00541   inline bool msgLevel( const MSG::Level level ) const { return msgLevel() <= level ; }
    00546   void resetMsgStream() const;
    00548   inline bool typePrint     () const { return m_typePrint    ; }
    00550   inline bool propsPrint    () const { return m_propsPrint   ; }
    00552   inline bool statPrint     () const { return m_statPrint    ; }
    00554   inline bool errorsPrint   () const { return m_errorsPrint  ; }
    00555   // ==========================================================================
    00556 private:
    00557   // ==========================================================================
    00563   void msgLevelHandler ( Property& theProp );
    00564   // ==========================================================================
    00565 public:
    00570   long printStat   ( const MSG::Level level = MSG::ALWAYS ) const ;
    00575   long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ;
    00580   long printProps ( const MSG::Level level = MSG::ALWAYS ) const ;
    00596   template <class CallerClass>
    00597   inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = NULL) {
    00598     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00599   }
    00630   template <class CallerClass, class CondType>
    00631   inline void registerCondition(const std::string &condition, CondType *&condPtrDest,
    00632                                 StatusCode (CallerClass::*mf)() = NULL) {
    00633     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest);
    00634   }
    00636   template <class CallerClass>
    00637   inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00638     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf);
    00639   }
    00655   template <class CallerClass,class TargetClass>
    00656   inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00657     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00658   }
    00670   inline StatusCode runUpdate() { return updMgrSvc()->update(this); }
    00674   template <class T>
    00675   TransientFastContainer<T> * getFastContainer
    00676   ( const std::string &location,
    00677     typename TransientFastContainer<T>::size_type initial=0);
    00678 public:
    00680   GaudiCommon ( const std::string & name,
    00681                 ISvcLocator * pSvcLocator );
    00683   GaudiCommon ( const std::string& type   ,
    00684                 const std::string& name   ,
    00685                 const IInterface*  parent );
    00686 public:
    00690   virtual StatusCode initialize ();
    00694   virtual StatusCode finalize   ();
    00695 protected:
    00697   virtual ~GaudiCommon( );
    00698 private :
    00699   // default constructor is disabled
    00700   GaudiCommon() ;
    00701   // copy    constructor is disabled
    00702   GaudiCommon           ( const GaudiCommon& ) ;
    00703   // assignment operator is disabled
    00704   GaudiCommon& operator=( const GaudiCommon& ) ;
    00705 protected:
    00707   StatusCode releaseTool ( const IAlgTool*   tool ) const ;
    00709   StatusCode releaseSvc  ( const IInterface* svc  ) const ;
    00710 public:
    00730   StatusCode release ( const IInterface* interface ) const ;
    00731   // ==========================================================================
    00732 public:
    00733   // ==========================================================================
    00735   const AlgTools& tools    () const { return m_tools    ; }    // get all tools
    00737   const Services& services () const { return m_services ; } // get all services
    00738   // ==========================================================================
    00739 private:
    00740   // ==========================================================================
    00742   void printErrorHandler ( Property& /* theProp */ ) ;     //      "ErrorPrint"
    00744   void printPropsHandler ( Property& /* theProp */ ) ;     // "PropertiesPrint"
    00746   void printStatHandler  ( Property& /* theProp */ ) ;     //       "StatPrint"
    00747   // ==========================================================================
    00748 public:
    00749   // ==========================================================================
    00751   inline const std::string & context() const { return m_context; }
    00755   inline const std::string & rootInTES() const { return m_rootInTES; }
    00757   inline double globalTimeOffset() const { return m_globalTimeOffset; }
    00758 private:
    00760   void addToToolList    ( IAlgTool * tool ) const;
    00762   void addToServiceList ( const SmartIF<IService>& svc ) const;
    00764   void initGaudiCommonConstructor( const IInterface * parent = 0 );
    00766   const std::string fullTESLocation( const std::string & location,
    00767                                      const bool useRootInTES ) const;
    00768 private:
    00770   MSG::Level  m_msgLevel    ;
    00771 private:
    00773   mutable MsgStream* m_msgStream   ;
    00775   mutable AlgTools   m_tools       ;
    00777   mutable Services   m_services    ;
    00778   // ==========================================================================
    00780   mutable Counter    m_errors      ;
    00782   mutable Counter    m_warnings    ;
    00784   mutable Counter    m_infos       ;
    00786   mutable Counter    m_exceptions  ;
    00788   mutable Statistics m_counters    ;
    00789   // ==========================================================================
    00791   mutable IUpdateManagerSvc* m_updMgrSvc;
    00793   mutable IDataProviderSvc* m_fastContainersSvc;
    00794   // ==========================================================================
    00796   bool        m_typePrint     ;
    00798   bool        m_propsPrint    ;
    00800   bool        m_statPrint     ;
    00802   bool        m_errorsPrint   ;
    00803   // ==========================================================================
    00805   std::string m_context;
    00807   std::string m_rootInTES;
    00811   std::string m_rootOnTES;
    00813   double m_globalTimeOffset;
    00814   // ==========================================================================
    00815   // the header row
    00816   std::string    m_header  ;
    00817   // format for regular statistical printout rows
    00818   std::string    m_format1 ;
    00819   // format for "efficiency" statistical printout rows
    00820   std::string    m_format2 ;
    00821   // flag to use the special "efficiency" format
    00822   bool           m_useEffFormat ;
    00823 } ;
    00824 // ============================================================================
    00825 #include "GaudiAlg/GaudiCommonImp.h"
    00826 // ============================================================================
    00827
    00828 // ============================================================================
    00829 // The END
    00830 // ============================================================================
    00831 #endif // GAUDIALG_GAUDICOMMON_H
    00832 // ============================================================================