00001
00002
00003 #ifndef GAUDIALG_GAUDICOMMON_H
00004 #define GAUDIALG_GAUDICOMMON_H 1
00005
00006
00007
00008
00009
00010 #include <string>
00011 #include <vector>
00012 #include <map>
00013 #include <algorithm>
00014
00015
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
00033
00034 class Algorithm ;
00035 class AlgTool ;
00036 namespace Gaudi { namespace Utils { template <class TYPE> struct GetData ; } }
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00057
00058 template < class PBASE >
00059 class GAUDI_API GaudiCommon: public PBASE
00060 {
00061 protected:
00071 static const bool IgnoreRootInTES = false;
00083 static const bool UseRootInTES = true;
00084
00085 protected:
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
00098 ICounterSummarySvc* m_counterSummarySvc;
00100 std::vector<std::string> m_counterList;
00101
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 ;
00146 template < class TYPE >
00147 typename Gaudi::Utils::GetData<TYPE>::return_type
00148 getIfExists ( IDataProviderSvc* svc ,
00149 const std::string& location ,
00150 const bool useRootInTES = true ) const ;
00177 template < class TYPE >
00178 bool exist ( IDataProviderSvc* svc ,
00179 const std::string& location ,
00180 const bool useRootInTES = true ) const ;
00208 template < class TYPE , class TYPE2 >
00209 typename Gaudi::Utils::GetData<TYPE>::return_type
00210 getOrCreate ( IDataProviderSvc* svc ,
00211 const std::string& location ,
00212 const bool useRootInTES = true ) const ;
00238 DataObject* put ( IDataProviderSvc* svc ,
00239 DataObject* object ,
00240 const std::string& location ,
00241 const bool useRootInTES = true ) const ;
00267 template < class TOOL >
00268 TOOL* tool ( const std::string& type ,
00269 const std::string& name ,
00270 const IInterface* parent = 0 ,
00271 bool create = true ) const ;
00294 template < class TOOL >
00295 TOOL* tool ( const std::string& type ,
00296 const IInterface* parent = 0 ,
00297 bool create = true ) const ;
00320 template < class SERVICE >
00321 SmartIF<SERVICE> svc ( const std::string& name ,
00322 const bool create = true ) const ;
00324 inline IUpdateManagerSvc * updMgrSvc() const;
00325 public:
00349 StatusCode Error
00350 ( const std::string& msg ,
00351 const StatusCode st = StatusCode::FAILURE ,
00352 const size_t mx = 10 ) const ;
00376 StatusCode Warning
00377 ( const std::string& msg ,
00378 const StatusCode st = StatusCode::FAILURE ,
00379 const size_t mx = 10 ) const ;
00395 StatusCode Info
00396 ( const std::string& msg ,
00397 const StatusCode st = StatusCode::SUCCESS ,
00398 const size_t mx = 10 ) const ;
00410 StatusCode Print
00411 ( const std::string& msg ,
00412 const StatusCode st = StatusCode::SUCCESS ,
00413 const MSG::Level lev = MSG::INFO ) const ;
00422 inline void Assert
00423 ( const bool ok ,
00424 const std::string& message = "" ,
00425 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const;
00434 inline void Assert
00435 ( const bool ok ,
00436 const char* message ,
00437 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const;
00446 void Exception
00447 ( const std::string & msg ,
00448 const GaudiException & exc ,
00449 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
00459 void Exception
00460 ( const std::string & msg ,
00461 const std::exception & exc ,
00462 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
00471 void Exception
00472 ( const std::string& msg = "no message" ,
00473 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
00474 public:
00485 inline MsgStream& msgStream ( const MSG::Level level ) const ;
00487 inline MsgStream& always () const { return msgStream ( MSG::ALWAYS ) ; }
00489 inline MsgStream& fatal () const { return msgStream ( MSG::FATAL ) ; }
00491 inline MsgStream& err () const { return msgStream ( MSG::ERROR ) ; }
00493 inline MsgStream& error () const { return msgStream ( MSG::ERROR ) ; }
00495 inline MsgStream& warning () const { return msgStream ( MSG::WARNING ) ; }
00497 inline MsgStream& info () const { return msgStream ( MSG::INFO ) ; }
00499 inline MsgStream& debug () const { return msgStream ( MSG::DEBUG ) ; }
00501 inline MsgStream& verbose () const { return msgStream ( MSG::VERBOSE ) ; }
00503 inline MsgStream& msg () const { return msgStream ( MSG::INFO ) ; }
00504 public:
00505
00507 inline const Statistics& counters() const { return m_counters ; }
00526 inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; }
00527
00528 public:
00532 inline MSG::Level msgLevel() const { return m_msgLevel ; }
00539 inline bool msgLevel( const MSG::Level level ) const { return msgLevel() <= level ; }
00544 void resetMsgStream() const;
00546 inline bool typePrint () const { return m_typePrint ; }
00548 inline bool propsPrint () const { return m_propsPrint ; }
00550 inline bool statPrint () const { return m_statPrint ; }
00552 inline bool errorsPrint () const { return m_errorsPrint ; }
00553
00554 private:
00555
00561 void msgLevelHandler ( Property& theProp );
00562
00563 public:
00568 long printStat ( const MSG::Level level = MSG::ALWAYS ) const ;
00573 long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ;
00578 long printProps ( const MSG::Level level = MSG::ALWAYS ) const ;
00594 template <class CallerClass>
00595 inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = NULL) {
00596 updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
00597 }
00628 template <class CallerClass, class CondType>
00629 inline void registerCondition(const std::string &condition, CondType *&condPtrDest,
00630 StatusCode (CallerClass::*mf)() = NULL) {
00631 updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest);
00632 }
00634 template <class CallerClass>
00635 inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) {
00636 updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf);
00637 }
00653 template <class CallerClass,class TargetClass>
00654 inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) {
00655 updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
00656 }
00668 inline StatusCode runUpdate() { return updMgrSvc()->update(this); }
00669 public:
00671 GaudiCommon ( const std::string & name,
00672 ISvcLocator * pSvcLocator );
00674 GaudiCommon ( const std::string& type ,
00675 const std::string& name ,
00676 const IInterface* parent );
00677 public:
00681 virtual StatusCode initialize()
00682 #ifdef __ICC
00683 { return i_gcInitialize(); }
00684 StatusCode i_gcInitialize()
00685 #endif
00686 ;
00690 virtual StatusCode finalize()
00691 #ifdef __ICC
00692 { return i_gcFinalize(); }
00693 StatusCode i_gcFinalize()
00694 #endif
00695 ;
00696 protected:
00698 virtual ~GaudiCommon() {resetMsgStream();}
00699 private :
00700
00701 GaudiCommon() ;
00702
00703 GaudiCommon ( const GaudiCommon& ) ;
00704
00705 GaudiCommon& operator=( const GaudiCommon& ) ;
00706 protected:
00708 StatusCode releaseTool ( const IAlgTool* tool ) const ;
00710 StatusCode releaseSvc ( const IInterface* svc ) const ;
00711 public:
00731 StatusCode release ( const IInterface* interface ) const ;
00733 virtual inline unsigned long release() { return PBASE::release(); }
00734
00735 public:
00736
00738 const AlgTools& tools () const { return m_tools ; }
00740 const Services& services () const { return m_services ; }
00741
00742 private:
00743
00745 void printErrorHandler ( Property& ) ;
00747 void printPropsHandler ( Property& ) ;
00749 void printStatHandler ( Property& ) ;
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
00762 public:
00763
00765 const std::string fullTESLocation
00766 ( const std::string & location ,
00767 const bool useRootInTES ) const ;
00768
00769 private:
00770
00772 void addToToolList ( IAlgTool * tool ) const;
00774 void addToServiceList ( const SmartIF<IService>& svc ) const;
00776 void initGaudiCommonConstructor( const IInterface * parent = 0 );
00777
00778 private:
00780 MSG::Level m_msgLevel ;
00781 private:
00783 mutable MsgStream* m_msgStream ;
00785 mutable AlgTools m_tools ;
00787 mutable Services m_services ;
00788
00790 mutable Counter m_errors ;
00792 mutable Counter m_warnings ;
00794 mutable Counter m_infos ;
00796 mutable Counter m_exceptions ;
00798 mutable Statistics m_counters ;
00799
00801 mutable IUpdateManagerSvc* m_updMgrSvc;
00802
00804 bool m_typePrint ;
00806 bool m_propsPrint ;
00808 bool m_statPrint ;
00810 bool m_errorsPrint ;
00811
00813 std::string m_context;
00815 std::string m_rootInTES;
00819 std::string m_rootOnTES;
00821 double m_globalTimeOffset;
00822
00823
00824 std::string m_header ;
00825
00826 std::string m_format1 ;
00827
00828 std::string m_format2 ;
00829
00830 bool m_useEffFormat ;
00831 } ;
00832
00833 #include "GaudiAlg/GaudiCommonImp.h"
00834
00835
00836
00837
00838
00839 #endif // GAUDIALG_GAUDICOMMON_H
00840