![]() |
|
|
Generated: 24 Nov 2008 |
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/IUpdateManagerSvc.h" 00029 #include "GaudiKernel/TransientFastContainer.h" 00030 // ============================================================================ 00031 // forward declarations 00032 // ============================================================================ 00033 class Algorithm ; // GaudiKernel 00034 class AlgTool ; // GaudiKernel 00035 namespace Gaudi { namespace Utils { template <class TYPE> struct GetData ; } } 00036 // ============================================================================ 00037 /* @file GaudiCommon.h 00038 * 00039 * Header file for class : GaudiCommon 00040 * 00041 * @author Chris Jones Christopher.Rob.Jones@cern.ch 00042 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 00043 * @date 2005-08-08 00044 */ 00045 // ============================================================================ 00054 // ============================================================================ 00055 template < class PBASE > 00056 class GaudiCommon : public PBASE 00057 { 00058 protected: // definitions 00068 static const bool IgnoreRootInTES = false; 00080 static const bool UseRootInTES = true; 00081 protected: // few actual data types 00083 typedef std::map<std::string,StatEntity> Statistics ; 00085 typedef std::map<std::string,unsigned int> Counter ; 00087 typedef std::vector<IAlgTool*> AlgTools ; 00089 typedef std::pair<IInterface*,std::string> ServiceEntry ; 00091 typedef std::vector<ServiceEntry> Services ; 00092 public: 00126 template < class TYPE > 00127 typename Gaudi::Utils::GetData<TYPE>::return_type 00128 get ( IDataProviderSvc* svc , 00129 const std::string& location , 00130 const bool useRootInTES = true ) const ; 00157 template < class TYPE > 00158 bool exist ( IDataProviderSvc* svc , 00159 const std::string& location , 00160 const bool useRootInTES = true ) const ; 00188 template < class TYPE , class TYPE2 > 00189 TYPE* getOrCreate ( IDataProviderSvc* svc , 00190 const std::string& location , 00191 const bool useRootInTES = true ) const ; 00217 DataObject* put ( IDataProviderSvc* svc , 00218 DataObject* object , 00219 const std::string& location , 00220 const bool useRootInTES = true ) const ; 00246 template < class TOOL > 00247 TOOL* tool ( const std::string& type , 00248 const std::string& name , 00249 const IInterface* parent = 0 , 00250 bool create = true ) const ; 00273 template < class TOOL > 00274 TOOL* tool ( const std::string& type , 00275 const IInterface* parent = 0 , 00276 bool create = true ) const ; 00299 template < class SERVICE > 00300 SERVICE* svc ( const std::string& name , 00301 const bool create = false ) const ; 00303 inline IUpdateManagerSvc * updMgrSvc() const; 00305 inline IDataProviderSvc * fastContainersSvc() const; 00306 public: 00330 StatusCode Error 00331 ( const std::string& msg , 00332 const StatusCode st = StatusCode::FAILURE , 00333 const size_t mx = 10 ) const ; 00357 StatusCode Warning 00358 ( const std::string& msg , 00359 const StatusCode st = StatusCode::FAILURE , 00360 const size_t mx = 10 ) const ; 00372 StatusCode Print 00373 ( const std::string& msg , 00374 const StatusCode st = StatusCode::SUCCESS , 00375 const MSG::Level lev = MSG::INFO ) const ; 00386 inline StatusCode Assert 00387 ( const bool ok , 00388 const std::string& message = "" , 00389 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const; 00400 inline StatusCode Assert 00401 ( const bool ok , 00402 const char* message , 00403 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const; 00414 StatusCode Exception 00415 ( const std::string & msg , 00416 const GaudiException & exc , 00417 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ; 00428 StatusCode Exception 00429 ( const std::string & msg , 00430 const std::exception & exc , 00431 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ; 00441 StatusCode Exception 00442 ( const std::string& msg = "no message" , 00443 const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ; 00444 public: // predefined streams 00455 inline MsgStream& msgStream ( const MSG::Level level ) const ; 00457 inline MsgStream& always () const { return msgStream ( MSG:: ALWAYS ) ; } 00459 inline MsgStream& fatal () const { return msgStream ( MSG:: FATAL ) ; } 00461 inline MsgStream& err () const { return msgStream ( MSG:: ERROR ) ; } 00463 inline MsgStream& error () const { return msgStream ( MSG:: ERROR ) ; } 00465 inline MsgStream& warning () const { return msgStream ( MSG:: WARNING ) ; } 00467 inline MsgStream& info () const { return msgStream ( MSG:: INFO ) ; } 00469 inline MsgStream& debug () const { return msgStream ( MSG:: DEBUG ) ; } 00471 inline MsgStream& verbose () const { return msgStream ( MSG:: VERBOSE ) ; } 00473 inline MsgStream& msg () const { return msgStream ( MSG:: INFO ) ; } 00474 public: 00476 inline const Statistics& counters() const { return m_counters ; } 00495 inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; } 00496 public: 00500 inline MSG::Level msgLevel() const { return m_msgLevel ; } 00507 inline bool msgLevel( const MSG::Level level ) const { return msgLevel() <= level ; } 00512 void resetMsgStream() const; 00514 inline bool typePrint () const { return m_typePrint ; } 00516 inline bool propsPrint () const { return m_propsPrint ; } 00518 inline bool statPrint () const { return m_statPrint ; } 00520 inline bool errorsPrint () const { return m_errorsPrint ; } 00521 private: 00527 void msgLevelHandler ( Property& theProp ); 00528 public: 00533 long printStat ( const MSG::Level level = MSG::ALWAYS ) const ; 00538 long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ; 00543 long printProps ( const MSG::Level level = MSG::ALWAYS ) const ; 00559 template <class CallerClass> 00560 inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = NULL) { 00561 updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf); 00562 } 00593 template <class CallerClass, class CondType> 00594 inline void registerCondition(const std::string &condition, CondType *&condPtrDest, 00595 StatusCode (CallerClass::*mf)() = NULL) { 00596 updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest); 00597 } 00599 template <class CallerClass> 00600 inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) { 00601 updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf); 00602 } 00618 template <class CallerClass,class TargetClass> 00619 inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) { 00620 updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf); 00621 } 00633 inline StatusCode runUpdate() { return updMgrSvc()->update(this); } 00637 template <class T> 00638 TransientFastContainer<T> * getFastContainer 00639 ( const std::string &location, 00640 typename TransientFastContainer<T>::size_type initial=0); 00641 public: 00643 GaudiCommon ( const std::string & name, 00644 ISvcLocator * pSvcLocator ); 00646 GaudiCommon ( const std::string& type , 00647 const std::string& name , 00648 const IInterface* parent ); 00649 public: 00653 virtual StatusCode initialize (); 00657 virtual StatusCode finalize (); 00658 protected: 00660 virtual ~GaudiCommon( ); 00661 private : 00662 // default constructor is disabled 00663 GaudiCommon() ; 00664 // copy constructor is disabled 00665 GaudiCommon ( const GaudiCommon& ) ; 00666 // assignement operator is disabled 00667 GaudiCommon& operator=( const GaudiCommon& ) ; 00668 protected: 00670 StatusCode releaseTool ( const IAlgTool* tool ) const ; 00672 StatusCode releaseSvc ( const IInterface* svc ) const ; 00673 public: 00693 StatusCode release ( const IInterface* interface ) const ; 00694 public: 00696 inline const std::string & context() const { return m_context; } 00700 inline const std::string & rootInTES() const { return m_rootInTES; } 00702 inline double globalTimeOffset() const { return m_globalTimeOffset; } 00703 private: 00705 void addToToolList ( IAlgTool * tool ) const; 00707 void addToServiceList ( IInterface * svc, 00708 const std::string & name ) const; 00710 void initGaudiCommonConstructor( const IInterface * parent = 0 ); 00712 const std::string fullTESLocation( const std::string & location, 00713 const bool useRootInTES ) const; 00714 private: 00716 MSG::Level m_msgLevel ; 00717 private: 00719 mutable MsgStream* m_msgStream ; 00721 mutable AlgTools m_tools ; 00723 mutable Services m_services ; 00724 // ========================================================================== 00726 mutable Counter m_errors ; 00728 mutable Counter m_warnings ; 00730 mutable Counter m_exceptions ; 00732 mutable Statistics m_counters ; 00733 // ========================================================================== 00735 mutable IUpdateManagerSvc* m_updMgrSvc; 00737 mutable IDataProviderSvc* m_fastContainersSvc; 00738 // ========================================================================== 00740 bool m_typePrint ; 00742 bool m_propsPrint ; 00744 bool m_statPrint ; 00746 bool m_errorsPrint ; 00747 // ========================================================================== 00749 std::string m_context; 00751 std::string m_rootInTES; 00755 std::string m_rootOnTES; 00757 double m_globalTimeOffset; 00758 // ========================================================================== 00759 // the header row 00760 std::string m_header ; 00761 // format for regular statistical printout rows 00762 std::string m_format1 ; 00763 // format for "efficiency" statistical printout rows 00764 std::string m_format2 ; 00765 // flag to use the special "efficiency" format 00766 bool m_useEffFormat ; 00767 } ; 00768 // ============================================================================ 00769 #include "GaudiAlg/GaudiCommonImp.h" 00770 // ============================================================================ 00771 00772 // ============================================================================ 00773 // The END 00774 // ============================================================================ 00775 #endif // GAUDIALG_GAUDICOMMON_H 00776 // ============================================================================