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 >
140  get ( IDataProviderSvc* svc ,
141  const std::string& location ,
142  const bool useRootInTES = true ) const ;
146  template < class 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 >
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 // ============================================================================
MsgStream & warning() const
shortcut for the method msgStream ( MSG::WARNING )
Definition: GaudiCommon.h:495
The implementation of inline/templated methods for class GaudiCommon.
Counter m_warnings
counter of warnings
Definition: GaudiCommon.h:792
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
AlgTools m_tools
List of active tools.
Definition: GaudiCommon.h:785
double m_globalTimeOffset
The globalTimeOffset value.
Definition: GaudiCommon.h:821
Define general base for Gaudi exception.
MsgStream & info() const
shortcut for the method msgStream ( MSG::INFO )
Definition: GaudiCommon.h:497
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
Counter m_exceptions
Counter of exceptions.
Definition: GaudiCommon.h:796
std::map< std::string, unsigned int > Counter
the actual type error/warning counter
Definition: GaudiCommon.h:90
MsgStream & err() const
shortcut for the method msgStream ( MSG::ERROR )
Definition: GaudiCommon.h:491
const std::string & rootInTES() const
Returns the "rootInTES" string.
Definition: GaudiCommon.h:758
std::string m_rootOnTES
The rootOnTES string.
Definition: GaudiCommon.h:819
std::vector< IAlgTool * > AlgTools
storage for active tools
Definition: GaudiCommon.h:92
void registerCondition(TargetClass *condition, StatusCode(CallerClass::*mf)()=NULL)
register the current instance to the UpdateManagerSvc as a consumer for a condition.
Definition: GaudiCommon.h:654
Services m_services
List of active services.
Definition: GaudiCommon.h:787
Statistics m_counters
General counters.
Definition: GaudiCommon.h:798
Helper structure for implementation of "get"-functions for GaudiCommon
Definition: GaudiCommon.h:36
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:754
const Statistics & counters() const
accessor to all counters
Definition: GaudiCommon.h:507
bool m_typePrint
insert the actual C++ type of the algorithm in the messages?
Definition: GaudiCommon.h:804
void registerCondition(char *condition, StatusCode(CallerClass::*mf)()=NULL)
just to avoid conflicts with the version using a pointer to a template class.
Definition: GaudiCommon.h:635
Data provider interface definition.
ICounterSummarySvc * m_counterSummarySvc
a pointer to the CounterSummarySvc
Definition: GaudiCommon.h:98
const Services & services() const
get the list of aquired services
Definition: GaudiCommon.h:740
MsgStream & error() const
shortcut for the method msgStream ( MSG::ERROR )
Definition: GaudiCommon.h:493
MSG::Level msgLevel() const
The current message service output level.
Definition: GaudiCommon.h:532
virtual ~GaudiCommon()
Destructor.
Definition: GaudiCommon.h:698
bool statPrint() const
Print statistical counters at finalization ?
Definition: GaudiCommon.h:550
bool m_useEffFormat
flag to use the special "efficiency" format
Definition: GaudiCommon.h:830
StatEntity & counter(const std::string &tag) const
accessor to certain counter by name
Definition: GaudiCommon.h:526
std::map< std::string, StatEntity > Statistics
the actual type of general counters
Definition: GaudiCommon.h:88
Counter m_errors
Counter of errors.
Definition: GaudiCommon.h:790
string type
Definition: gaudirun.py:126
const AlgTools & tools() const
get the list of aquired tools
Definition: GaudiCommon.h:738
virtual unsigned long release()
Un-hide IInterface::release (ICC warning #1125)
Definition: GaudiCommon.h:733
std::string m_format1
format for regular statistical printout rows
Definition: GaudiCommon.h:826
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::string m_rootInTES
The rootInTES string.
Definition: GaudiCommon.h:815
MsgStream & verbose() const
shortcut for the method msgStream ( MSG::VERBOSE )
Definition: GaudiCommon.h:501
bool propsPrint() const
Print properties at initialization ?
Definition: GaudiCommon.h:548
Definition of the basic interface.
Definition: IInterface.h:160
void registerCondition(const std::string &condition, StatusCode(CallerClass::*mf)()=NULL)
register the current instance to the UpdateManagerSvc as a consumer for a condition.
Definition: GaudiCommon.h:595
Counter m_infos
counter of infos
Definition: GaudiCommon.h:794
MsgStream & msg() const
shortcut for the method msgStream ( MSG::INFO )
Definition: GaudiCommon.h:503
bool errorsPrint() const
Print error counters at finalization ?
Definition: GaudiCommon.h:552
MsgStream & debug() const
shortcut for the method msgStream ( MSG::DEBUG )
Definition: GaudiCommon.h:499
Interface class to the Update Manager service.
StatusCode runUpdate()
asks the UpdateManagerSvc to perform an update of the instance (if needed) without waiting the next B...
Definition: GaudiCommon.h:668
std::vector< std::string > m_statEntityList
Definition: GaudiCommon.h:102
MSG::Level m_msgLevel
The message level.
Definition: GaudiCommon.h:780
std::string m_header
the header row
Definition: GaudiCommon.h:824
MsgStream & always() const
shortcut for the method msgStream ( MSG::ALWAYS )
Definition: GaudiCommon.h:487
bool typePrint() const
Insert the actual C++ type of the algorithm/tool in the messages ?
Definition: GaudiCommon.h:546
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:61
bool m_statPrint
print counters at finalization ?
Definition: GaudiCommon.h:808
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
std::string m_format2
format for "efficiency" statistical printout rows
Definition: GaudiCommon.h:828
MsgStream * m_msgStream
The predefined message stream.
Definition: GaudiCommon.h:783
IUpdateManagerSvc * m_updMgrSvc
Pointer to the Update Manager Service instance.
Definition: GaudiCommon.h:801
void registerCondition(const std::string &condition, CondType *&condPtrDest, StatusCode(CallerClass::*mf)()=NULL)
register the current instance to the UpdateManagerSvc as a consumer for a condition.
Definition: GaudiCommon.h:629
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:34
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
Common class providing an architecture-independent hash map.
Definition: HashMap.h:108
std::vector< std::string > m_counterList
list of counters to declare. Set by property CounterList. This can be a regular expression.
Definition: GaudiCommon.h:100
bool m_errorsPrint
print warning and error counters at finalization ?
Definition: GaudiCommon.h:810
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:59
MsgStream & fatal() const
shortcut for the method msgStream ( MSG::FATAL )
Definition: GaudiCommon.h:489
double globalTimeOffset() const
Returns the "globalTimeOffset" double.
Definition: GaudiCommon.h:760
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:68
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
std::string m_context
The context string.
Definition: GaudiCommon.h:813
bool msgLevel(const MSG::Level level) const
Test the output level.
Definition: GaudiCommon.h:539
#define GAUDI_API
Definition: Kernel.h:108
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
GaudiUtils::HashMap< std::string, SmartIF< IService > > Services
storage for active services
Definition: GaudiCommon.h:94
Simple service interface to collect counters to persist in a summary file.
bool m_propsPrint
print properties at initialization?
Definition: GaudiCommon.h:806