| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- File List
- File Members

# GaudiCommon.h

Go to the documentation of this file.

    00001 // $Id: GaudiCommon.h,v 1.15 2008/01/17 20:58:46 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/IUpdateManagerSvc.h"
    00029 #include "GaudiKernel/TransientFastContainer.h"
    00030 // ============================================================================
    00031 // forward declarations
    00032 // ============================================================================
    00033 class Algorithm ; // GaudiKernel
    00034 class AlgTool   ; // GaudiKernel
    00035 // ============================================================================
    00036 /*  @file GaudiCommon.h
    00037  *
    00038  *  Header file for class : GaudiCommon
    00039  *
    00040  *  @author Chris Jones   Christopher.Rob.Jones@cern.ch
    00041  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
    00042  *  @date   2005-08-08
    00043  */
    00044 // ============================================================================
    00053 // ============================================================================
    00054 template < class PBASE >
    00055 class GaudiCommon : public PBASE
    00056 {
    00057 protected: // definitions
    00067   static const bool IgnoreRootInTES = false;
    00079   static const bool UseRootInTES = true;
    00080 protected: // few actual data types
    00082   typedef std::map<std::string,StatEntity>   Statistics ;
    00084   typedef std::map<std::string,unsigned int> Counter      ;
    00086   typedef std::vector<IAlgTool*>             AlgTools     ;
    00088   typedef std::pair<IInterface*,std::string> ServiceEntry ;
    00090   typedef std::vector<ServiceEntry>          Services     ;
    00091 public:
    00125   template < class TYPE >
    00126   TYPE* get ( IDataProviderSvc*  svc        ,
    00127               const std::string& location   ,
    00128               const bool useRootInTES = true ) const ;
    00155   template < class TYPE >
    00156   bool  exist    ( IDataProviderSvc*  svc      ,
    00157                    const std::string& location ,
    00158                    const bool useRootInTES = true ) const ;
    00186   template < class TYPE , class TYPE2 >
    00187   TYPE* getOrCreate ( IDataProviderSvc* svc ,
    00188                       const std::string& location ,
    00189                       const bool useRootInTES = true ) const  ;
    00215   void put ( IDataProviderSvc*  svc ,
    00216              DataObject*        object   ,
    00217              const std::string& location  ,
    00218              const bool useRootInTES = true ) const ;
    00244   template < class TOOL >
    00245   TOOL* tool ( const std::string& type           ,
    00246                const std::string& name           ,
    00247                const IInterface*  parent  = 0    ,
    00248                bool               create  = true ) const ;
    00271   template < class TOOL >
    00272   TOOL* tool ( const std::string& type          ,
    00273                const IInterface*  parent = 0    ,
    00274                bool               create = true ) const ;
    00297   template < class SERVICE >
    00298   SERVICE* svc ( const std::string& name           ,
    00299                  const bool         create = false ) const ;
    00301   inline IUpdateManagerSvc * updMgrSvc() const;
    00303   inline IDataProviderSvc * fastContainersSvc() const;
    00304 public:
    00328   StatusCode Error
    00329   ( const std::string& msg ,
    00330     const StatusCode   st  = StatusCode::FAILURE ,
    00331     const size_t       mx  = 10                  ) const ;
    00355   StatusCode Warning
    00356   ( const std::string& msg ,
    00357     const StatusCode   st  = StatusCode::FAILURE ,
    00358     const size_t       mx  = 10                  ) const ;
    00370   StatusCode Print
    00371   ( const std::string& msg ,
    00372     const StatusCode   st  = StatusCode::SUCCESS ,
    00373     const MSG::Level   lev = MSG::INFO           ) const ;
    00384   inline StatusCode Assert
    00385   ( const bool         ok                            ,
    00386     const std::string& message = ""                  ,
    00387     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00398   inline StatusCode Assert
    00399   ( const bool         ok                            ,
    00400     const char*        message                       ,
    00401     const StatusCode   sc      = StatusCode(StatusCode::FAILURE, true) ) const;
    00412   StatusCode Exception
    00413   ( const std::string    & msg                        ,
    00414     const GaudiException & exc                        ,
    00415     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00426   StatusCode Exception
    00427   ( const std::string    & msg                        ,
    00428     const std::exception & exc                        ,
    00429     const StatusCode       sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00439   StatusCode Exception
    00440   ( const std::string& msg = "no message"        ,
    00441     const StatusCode   sc  = StatusCode(StatusCode::FAILURE, true) ) const ;
    00442 public: // predefined streams
    00453   inline MsgStream& msgStream ( const MSG::Level level ) const ;
    00455   inline MsgStream&  always () const { return msgStream ( MSG::  ALWAYS ) ; }
    00457   inline MsgStream&   fatal () const { return msgStream ( MSG::   FATAL ) ; }
    00459   inline MsgStream&     err () const { return msgStream ( MSG::   ERROR ) ; }
    00461   inline MsgStream&   error () const { return msgStream ( MSG::   ERROR ) ; }
    00463   inline MsgStream& warning () const { return msgStream ( MSG:: WARNING ) ; }
    00465   inline MsgStream&    info () const { return msgStream ( MSG::    INFO ) ; }
    00467   inline MsgStream&   debug () const { return msgStream ( MSG::   DEBUG ) ; }
    00469   inline MsgStream& verbose () const { return msgStream ( MSG:: VERBOSE ) ; }
    00471   inline MsgStream&     msg () const { return msgStream ( MSG::    INFO ) ; }
    00472 public:
    00474   inline const Statistics& counters() const { return m_counters ; }
    00493   inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; }
    00494 public:
    00498   inline MSG::Level msgLevel() const { return m_msgLevel ; }
    00505   inline bool msgLevel( const MSG::Level level ) const { return msgLevel() <= level ; }
    00510   void resetMsgStream() const;
    00512   inline bool typePrint     () const { return m_typePrint    ; }
    00514   inline bool propsPrint    () const { return m_propsPrint   ; }
    00516   inline bool statPrint     () const { return m_statPrint    ; }
    00518   inline bool errorsPrint   () const { return m_errorsPrint  ; }
    00519 private:
    00525   void msgLevelHandler ( Property& theProp );
    00526 public:
    00531   long printStat   ( const MSG::Level level = MSG::ALWAYS ) const ;
    00536   long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ;
    00541   long printProps ( const MSG::Level level = MSG::ALWAYS ) const ;
    00557   template <class CallerClass>
    00558   inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = NULL) {
    00559     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00560   }
    00591   template <class CallerClass, class CondType>
    00592   inline void registerCondition(const std::string &condition, CondType *&condPtrDest,
    00593                                 StatusCode (CallerClass::*mf)() = NULL) {
    00594     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest);
    00595   }
    00597   template <class CallerClass>
    00598   inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00599     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf);
    00600   }
    00616   template <class CallerClass,class TargetClass>
    00617   inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) {
    00618     updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
    00619   }
    00631   inline StatusCode runUpdate() { return updMgrSvc()->update(this); }
    00635   template <class T>
    00636   TransientFastContainer<T> * getFastContainer
    00637   ( const std::string &location,
    00638     typename TransientFastContainer<T>::size_type initial=0);
    00639 public:
    00641   GaudiCommon ( const std::string & name,
    00642                 ISvcLocator * pSvcLocator );
    00644   GaudiCommon ( const std::string& type   ,
    00645                 const std::string& name   ,
    00646                 const IInterface*  parent );
    00647 public:
    00651   virtual StatusCode initialize ();
    00655   virtual StatusCode finalize   ();
    00656 protected:
    00658   virtual ~GaudiCommon( );
    00659 private :
    00660   // default constructor is disabled
    00661   GaudiCommon() ;
    00662   // copy    constructor is disabled
    00663   GaudiCommon           ( const GaudiCommon& ) ;
    00664   // assignement operator is disabled
    00665   GaudiCommon& operator=( const GaudiCommon& ) ;
    00666 protected:
    00668   StatusCode releaseTool ( const IAlgTool*   tool ) const ;
    00670   StatusCode releaseSvc  ( const IInterface* svc  ) const ;
    00671 public:
    00691   StatusCode release ( const IInterface* interface ) const ;
    00692 public:
    00694   inline const std::string & context() const { return m_context; }
    00698   inline const std::string & rootInTES() const { return m_rootInTES; }
    00700   inline const double globalTimeOffset() const { return m_globalTimeOffset; }
    00701 private:
    00703   void addToToolList    ( IAlgTool * tool ) const;
    00705   void addToServiceList ( IInterface * svc,
    00706                           const std::string & name ) const;
    00708   void initGaudiCommonConstructor( const IInterface * parent = 0 );
    00710   const std::string fullTESLocation( const std::string & location,
    00711                                      const bool useRootInTES ) const;
    00712 private:
    00714   MSG::Level         m_msgLevel    ;
    00715 private:
    00717   mutable MsgStream* m_msgStream   ;
    00719   mutable AlgTools   m_tools       ;
    00721   mutable Services   m_services    ;
    00722   // ==========================================================================
    00724   mutable Counter    m_errors      ;
    00726   mutable Counter    m_warnings    ;
    00728   mutable Counter    m_exceptions  ;
    00730   mutable Statistics m_counters    ;
    00731   // ==========================================================================
    00733   mutable IUpdateManagerSvc* m_updMgrSvc;
    00735   mutable IDataProviderSvc* m_fastContainersSvc;
    00736   // ==========================================================================
    00738   bool        m_typePrint     ;
    00740   bool        m_propsPrint    ;
    00742   bool        m_statPrint     ;
    00744   bool        m_errorsPrint   ;
    00745   // ==========================================================================
    00747   std::string m_context;
    00749   std::string m_rootInTES;
    00753   std::string m_rootOnTES;
    00755   double m_globalTimeOffset;
    00756   // ==========================================================================
    00757   // the header row
    00758   std::string    m_header  ;
    00759   // format for regular statistical printout rows
    00760   std::string    m_format1 ;
    00761   // format for "efficiency" statistical printout rows
    00762   std::string    m_format2 ;
    00763   // flag to use the special "efficiency" format
    00764   bool           m_useEffFormat ;
    00765 } ;
    00766 // ============================================================================
    00767 #include "GaudiAlg/GaudiCommonImp.h"
    00768 // ============================================================================
    00769
    00770 // ============================================================================
    00771 // The END
    00772 // ============================================================================
    00773 #endif // GAUDIALG_GAUDICOMMON_H
    00774 // ============================================================================