Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiCommon.h
Go to the documentation of this file.
1 // $Id: GaudiCommon.h,v 1.18 2008/10/27 19:22:20 marcocle Exp $
2 // ============================================================================
3 #ifndef GAUDIALG_GAUDICOMMON_H
4 #define GAUDIALG_GAUDICOMMON_H 1
5 // ============================================================================
6 // Include files
7 // ============================================================================
8 // from STL
9 // ============================================================================
10 #include <string>
11 #include <vector>
12 #include <map>
13 #include <algorithm>
14 // ============================================================================
15 // GaudiKernel
16 // ============================================================================
17 #include "GaudiKernel/StatusCode.h"
19 #include "GaudiKernel/IToolSvc.h"
20 #include "GaudiKernel/IAlgTool.h"
24 #include "GaudiKernel/System.h"
27 #include "GaudiKernel/StatEntity.h"
30 #include "GaudiKernel/HashMap.h"
31 // ============================================================================
32 // forward declarations
33 // ============================================================================
34 class Algorithm ; // GaudiKernel
35 class AlgTool ; // GaudiKernel
36 namespace Gaudi { namespace Utils { template <class TYPE> struct GetData ; } }
37 // ============================================================================
38 /* @file GaudiCommon.h
39  *
40  * Header file for class : GaudiCommon
41  *
42  * @author Chris Jones Christopher.Rob.Jones@cern.ch
43  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
44  * @author Rob Lambert Rob.Lambert@cern.ch
45  * @date 2009-08-04
46  */
47 // ============================================================================
57 // ============================================================================
58 template < class PBASE >
59 class GAUDI_API GaudiCommon: public PBASE
60 {
61 protected: // definitions
71  static const bool IgnoreRootInTES = false;
83  static const bool UseRootInTES = true;
84  // ==========================================================================
85 protected: // few actual data types
86  // ==========================================================================
88  typedef std::map<std::string,StatEntity> Statistics ;
90  typedef std::map<std::string,unsigned int> Counter ;
92  typedef std::vector<IAlgTool*> AlgTools ;
95  // ==========================================================================
96  //protected members such that they can be used in the derived classes
100  std::vector<std::string> m_counterList;
101  //list of stat entities to write. Set by property StatEntityList. This can be a regular expression.
102  std::vector<std::string> m_statEntityList;
103 public:
104  // ==========================================================================
138  template < class TYPE >
139  typename Gaudi::Utils::GetData<TYPE>::return_type
140  get ( IDataProviderSvc* svc ,
141  const std::string& location ,
142  const bool useRootInTES = true ) const ;
146  template < class TYPE >
147  typename Gaudi::Utils::GetData<TYPE>::return_type
148  getIfExists ( IDataProviderSvc* svc ,
149  const std::string& location ,
150  const bool useRootInTES = true ) const ;
177  template < class TYPE >
178  bool exist ( IDataProviderSvc* svc ,
179  const std::string& location ,
180  const bool useRootInTES = true ) const ;
208  template < class TYPE , class TYPE2 >
209  typename Gaudi::Utils::GetData<TYPE>::return_type
210  getOrCreate ( IDataProviderSvc* svc ,
211  const std::string& location ,
212  const bool useRootInTES = true ) const ;
238  DataObject* put ( IDataProviderSvc* svc ,
239  DataObject* object ,
240  const std::string& location ,
241  const bool useRootInTES = true ) const ;
267  template < class TOOL >
268  TOOL* tool ( const std::string& type ,
269  const std::string& name ,
270  const IInterface* parent = 0 ,
271  bool create = true ) const ;
294  template < class TOOL >
295  TOOL* tool ( const std::string& type ,
296  const IInterface* parent = 0 ,
297  bool create = true ) const ;
320  template < class SERVICE >
321  SmartIF<SERVICE> svc ( const std::string& name ,
322  const bool create = true ) const ;
324  inline IUpdateManagerSvc * updMgrSvc() const;
325 public:
349  StatusCode Error
350  ( const std::string& msg ,
351  const StatusCode st = StatusCode::FAILURE ,
352  const size_t mx = 10 ) const ;
376  StatusCode Warning
377  ( const std::string& msg ,
378  const StatusCode st = StatusCode::FAILURE ,
379  const size_t mx = 10 ) const ;
395  StatusCode Info
396  ( const std::string& msg ,
397  const StatusCode st = StatusCode::SUCCESS ,
398  const size_t mx = 10 ) const ;
410  StatusCode Print
411  ( const std::string& msg ,
412  const StatusCode st = StatusCode::SUCCESS ,
413  const MSG::Level lev = MSG::INFO ) const ;
422  inline void Assert
423  ( const bool ok ,
424  const std::string& message = "" ,
425  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const;
434  inline void Assert
435  ( const bool ok ,
436  const char* message ,
437  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const;
446  void Exception
447  ( const std::string & msg ,
448  const GaudiException & exc ,
449  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
459  void Exception
460  ( const std::string & msg ,
461  const std::exception & exc ,
462  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
471  void Exception
472  ( const std::string& msg = "no message" ,
473  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
474 public: // predefined streams
485  inline MsgStream& msgStream ( const MSG::Level level ) const ;
487  inline MsgStream& always () const { return msgStream ( MSG::ALWAYS ) ; }
489  inline MsgStream& fatal () const { return msgStream ( MSG::FATAL ) ; }
491  inline MsgStream& err () const { return msgStream ( MSG::ERROR ) ; }
493  inline MsgStream& error () const { return msgStream ( MSG::ERROR ) ; }
495  inline MsgStream& warning () const { return msgStream ( MSG::WARNING ) ; }
497  inline MsgStream& info () const { return msgStream ( MSG::INFO ) ; }
499  inline MsgStream& debug () const { return msgStream ( MSG::DEBUG ) ; }
501  inline MsgStream& verbose () const { return msgStream ( MSG::VERBOSE ) ; }
503  inline MsgStream& msg () const { return msgStream ( MSG::INFO ) ; }
504 public:
505  // ==========================================================================
507  inline const Statistics& counters() const { return m_counters ; }
526  inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; }
527  // ==========================================================================
528 public:
532  inline MSG::Level msgLevel() const { return m_msgLevel ; }
539  inline bool msgLevel( const MSG::Level level ) const { return msgLevel() <= level ; }
544  void resetMsgStream() const;
546  inline bool typePrint () const { return m_typePrint ; }
548  inline bool propsPrint () const { return m_propsPrint ; }
550  inline bool statPrint () const { return m_statPrint ; }
552  inline bool errorsPrint () const { return m_errorsPrint ; }
553  // ==========================================================================
554 private:
555  // ==========================================================================
561  void msgLevelHandler ( Property& theProp );
562  // ==========================================================================
563 public:
568  long printStat ( const MSG::Level level = MSG::ALWAYS ) const ;
573  long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ;
578  long printProps ( const MSG::Level level = MSG::ALWAYS ) const ;
594  template <class CallerClass>
595  inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = NULL) {
596  updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
597  }
628  template <class CallerClass, class CondType>
629  inline void registerCondition(const std::string &condition, CondType *&condPtrDest,
630  StatusCode (CallerClass::*mf)() = NULL) {
631  updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest);
632  }
634  template <class CallerClass>
635  inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) {
636  updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf);
637  }
653  template <class CallerClass,class TargetClass>
654  inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) {
655  updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
656  }
668  inline StatusCode runUpdate() { return updMgrSvc()->update(this); }
669 public:
671  GaudiCommon ( const std::string & name,
672  ISvcLocator * pSvcLocator );
674  GaudiCommon ( const std::string& type ,
675  const std::string& name ,
676  const IInterface* parent );
677 public:
681  virtual StatusCode initialize()
682 #ifdef __ICC
683  { return i_gcInitialize(); }
684  StatusCode i_gcInitialize()
685 #endif
686  ;
690  virtual StatusCode finalize()
691 #ifdef __ICC
692  { return i_gcFinalize(); }
693  StatusCode i_gcFinalize()
694 #endif
695  ;
696 protected:
698  virtual ~GaudiCommon() {resetMsgStream();}
699 private :
700  // default constructor is disabled
701  GaudiCommon() ;
702  // copy constructor is disabled
703  GaudiCommon ( const GaudiCommon& ) ;
704  // assignment operator is disabled
705  GaudiCommon& operator=( const GaudiCommon& ) ;
706 protected:
708  StatusCode releaseTool ( const IAlgTool* tool ) const ;
710  StatusCode releaseSvc ( const IInterface* svc ) const ;
711 public:
731  StatusCode release ( const IInterface* interface ) const ;
733  virtual inline unsigned long release() { return PBASE::release(); }
734  // ==========================================================================
735 public:
736  // ==========================================================================
738  const AlgTools& tools () const { return m_tools ; } // get all tools
740  const Services& services () const { return m_services ; } // get all services
741  // ==========================================================================
742 private:
743  // ==========================================================================
745  void printErrorHandler ( Property& /* theProp */ ) ; // "ErrorPrint"
747  void printPropsHandler ( Property& /* theProp */ ) ; // "PropertiesPrint"
749  void printStatHandler ( Property& /* theProp */ ) ; // "StatPrint"
750  // ==========================================================================
751 public:
752  // ==========================================================================
754  inline const std::string & context() const { return m_context; }
758  inline const std::string & rootInTES() const { return m_rootInTES; }
760  inline double globalTimeOffset() const { return m_globalTimeOffset; }
761  // ==========================================================================
762 public:
763  // ==========================================================================
765  const std::string fullTESLocation
766  ( const std::string & location ,
767  const bool useRootInTES ) const ;
768  // ==========================================================================
769 private:
770  // ==========================================================================
772  void addToToolList ( IAlgTool * tool ) const;
774  void addToServiceList ( const SmartIF<IService>& svc ) const;
776  void initGaudiCommonConstructor( const IInterface * parent = 0 );
777  // ==========================================================================
778 private:
781 private:
785  mutable AlgTools m_tools ;
788  // ==========================================================================
790  mutable Counter m_errors ;
792  mutable Counter m_warnings ;
794  mutable Counter m_infos ;
799  // ==========================================================================
802  // ==========================================================================
804  bool m_typePrint ;
808  bool m_statPrint ;
811  // ==========================================================================
813  std::string m_context;
815  std::string m_rootInTES;
819  std::string m_rootOnTES;
822  // ==========================================================================
823  // the header row
824  std::string m_header ;
825  // format for regular statistical printout rows
826  std::string m_format1 ;
827  // format for "efficiency" statistical printout rows
828  std::string m_format2 ;
829  // flag to use the special "efficiency" format
831 } ;
832 // ============================================================================
833 #include "GaudiAlg/GaudiCommonImp.h"
834 // ============================================================================
835 
836 // ============================================================================
837 // The END
838 // ============================================================================
839 #endif // GAUDIALG_GAUDICOMMON_H
840 // ============================================================================

Generated at Wed Jun 4 2014 14:48:55 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004