All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiCommon.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_GAUDICOMMON_H
2 #define GAUDIALG_GAUDICOMMON_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // from STL
7 // ============================================================================
8 #include <string>
9 #include <vector>
10 #include <map>
11 #include <algorithm>
12 // ============================================================================
13 // GaudiKernel
14 // ============================================================================
15 #include "GaudiKernel/StatusCode.h"
17 #include "GaudiKernel/IToolSvc.h"
18 #include "GaudiKernel/IAlgTool.h"
21 #include "GaudiKernel/IAlgorithm.h"
23 #include "GaudiKernel/System.h"
26 #include "GaudiKernel/StatEntity.h"
29 #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 
39  constexpr const struct svc_eq_t {
40  bool operator()(const std::string& n, const SmartIF<IService>& s) const { return n == s->name(); };
41  bool operator()(const SmartIF<IService>& s, const std::string& n) const { return s->name() == n; };
42  bool operator()(const SmartIF<IService>& s, const SmartIF<IService>& n) const { return s->name() == n->name(); };
43  } svc_eq { };
44  constexpr const struct svc_lt_t {
45  bool operator()(const std::string& n, const SmartIF<IService>& s) const { return n < s->name(); };
46  bool operator()(const SmartIF<IService>& s, const std::string& n) const { return s->name() < n; };
47  bool operator()(const SmartIF<IService>& s, const SmartIF<IService>& n) const { return s->name() < n->name(); };
48  } svc_lt { };
49 
50 }
51 // ============================================================================
52 /* @file GaudiCommon.h
53  *
54  * Header file for class : GaudiCommon
55  *
56  * @author Chris Jones Christopher.Rob.Jones@cern.ch
57  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
58  * @author Rob Lambert Rob.Lambert@cern.ch
59  * @date 2009-08-04
60  */
61 // ============================================================================
71 // ============================================================================
72 template < class PBASE >
73 class GAUDI_API GaudiCommon: public PBASE
74 {
75 protected: // definitions
76  using base_class = PBASE;
77 
87  static const bool IgnoreRootInTES = false;
99  static const bool UseRootInTES = true;
100  // ==========================================================================
101 protected: // few actual data types
102  // ==========================================================================
111 
112  // ==========================================================================
113  //protected members such that they can be used in the derived classes
118  //list of stat entities to write. Set by property StatEntityList. This can be a regular expression.
120 public:
121  // ==========================================================================
155  template < class TYPE >
157  get ( IDataProviderSvc* svc ,
158  const std::string& location ,
159  const bool useRootInTES = true ) const ;
163  template < class TYPE >
165  getIfExists ( IDataProviderSvc* svc ,
166  const std::string& location ,
167  const bool useRootInTES = true ) const ;
194  template < class TYPE >
195  bool exist ( IDataProviderSvc* svc ,
196  const std::string& location ,
197  const bool useRootInTES = true ) const ;
225  template < class TYPE , class TYPE2 >
227  getOrCreate ( IDataProviderSvc* svc ,
228  const std::string& location ,
229  const bool useRootInTES = true ) const ;
255  DataObject* put ( IDataProviderSvc* svc ,
256  DataObject* object ,
257  const std::string& location ,
258  const bool useRootInTES = true ) const ;
284  template < class TOOL >
285  TOOL* tool ( const std::string& type ,
286  const std::string& name ,
287  const IInterface* parent = 0 ,
288  bool create = true ) const ;
311  template < class TOOL >
312  TOOL* tool ( const std::string& type ,
313  const IInterface* parent = 0 ,
314  bool create = true ) const ;
337  template < class SERVICE >
338  SmartIF<SERVICE> svc ( const std::string& name ,
339  const bool create = true ) const ;
341  inline IUpdateManagerSvc * updMgrSvc() const;
342 public:
366  StatusCode Error
367  ( const std::string& msg ,
368  const StatusCode st = StatusCode::FAILURE ,
369  const size_t mx = 10 ) const ;
393  StatusCode Warning
394  ( const std::string& msg ,
395  const StatusCode st = StatusCode::FAILURE ,
396  const size_t mx = 10 ) const ;
412  StatusCode Info
413  ( const std::string& msg ,
414  const StatusCode st = StatusCode::SUCCESS ,
415  const size_t mx = 10 ) const ;
427  StatusCode Print
428  ( const std::string& msg ,
429  const StatusCode st = StatusCode::SUCCESS ,
430  const MSG::Level lev = MSG::INFO ) const ;
439  inline void Assert
440  ( const bool ok ,
441  const std::string& message = "" ,
442  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const;
451  inline void Assert
452  ( const bool ok ,
453  const char* message ,
454  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const;
463  void Exception
464  ( const std::string & msg ,
465  const GaudiException & exc ,
466  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
476  void Exception
477  ( const std::string & msg ,
478  const std::exception & exc ,
479  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
488  void Exception
489  ( const std::string& msg = "no message" ,
490  const StatusCode sc = StatusCode(StatusCode::FAILURE, true) ) const ;
491 public:
492  // ==========================================================================
494  inline const Statistics& counters() const { return m_counters ; }
513  inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag] ; }
514  // ==========================================================================
515 public:
517  inline bool typePrint () const { return m_typePrint ; }
519  inline bool propsPrint () const { return m_propsPrint ; }
521  inline bool statPrint () const { return m_statPrint ; }
523  inline bool errorsPrint () const { return m_errorsPrint ; }
524  // ==========================================================================
525 public:
530  long printStat ( const MSG::Level level = MSG::ALWAYS ) const ;
535  long printErrors ( const MSG::Level level = MSG::ALWAYS ) const ;
540  long printProps ( const MSG::Level level = MSG::ALWAYS ) const ;
556  template <class CallerClass>
557  inline void registerCondition(const std::string &condition, StatusCode (CallerClass::*mf)() = nullptr) {
558  updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
559  }
590  template <class CallerClass, class CondType>
591  inline void registerCondition(const std::string &condition, CondType *&condPtrDest,
592  StatusCode (CallerClass::*mf)() = NULL) {
593  updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf,condPtrDest);
594  }
596  template <class CallerClass>
597  inline void registerCondition(char *condition, StatusCode (CallerClass::*mf)() = NULL) {
598  updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),std::string(condition),mf);
599  }
615  template <class CallerClass,class TargetClass>
616  inline void registerCondition(TargetClass *condition, StatusCode (CallerClass::*mf)() = NULL) {
617  updMgrSvc()->registerCondition(dynamic_cast<CallerClass*>(this),condition,mf);
618  }
630  inline StatusCode runUpdate() { return updMgrSvc()->update(this); }
631 public:
633  GaudiCommon ( const std::string& name,
634  ISvcLocator * pSvcLocator );
636  GaudiCommon ( const std::string& type ,
637  const std::string& name ,
638  const IInterface* parent );
639 public:
643  StatusCode initialize() override
644 #ifdef __ICC
645  { return i_gcInitialize(); }
646  StatusCode i_gcInitialize()
647 #endif
648  ;
652  StatusCode finalize() override
653 #ifdef __ICC
654  { return i_gcFinalize(); }
655  StatusCode i_gcFinalize()
656 #endif
657  ;
658 protected:
660  ~GaudiCommon() override = default;
661 private :
662  GaudiCommon() = delete;
663  GaudiCommon ( const GaudiCommon& ) = delete;
664  GaudiCommon& operator=( const GaudiCommon& ) = delete;
665 protected:
667  StatusCode releaseTool ( const IAlgTool* tool ) const ;
669  StatusCode releaseSvc ( const IInterface* svc ) const ;
670 public:
690  StatusCode release ( const IInterface* interface ) const ;
691 
693  using PBASE::release;
694  // ==========================================================================
695 public:
696  // ==========================================================================
698  const Services& services () const { return m_services ; } // get all services
699  // ==========================================================================
700 private:
701  // ==========================================================================
703  void printErrorHandler ( Property& /* theProp */ ) ; // "ErrorPrint"
705  void printPropsHandler ( Property& /* theProp */ ) ; // "PropertiesPrint"
707  void printStatHandler ( Property& /* theProp */ ) ; // "StatPrint"
708  // ==========================================================================
709 public:
710  // ==========================================================================
712  inline const std::string & context() const { return m_context; }
716  inline const std::string & rootInTES() const { return m_rootInTES; }
717  // ==========================================================================
718 public:
719  // ==========================================================================
721  const std::string fullTESLocation
722  ( const std::string & location ,
723  const bool useRootInTES ) const ;
724  // ==========================================================================
725 private:
726  // ==========================================================================
728  void addToServiceList ( SmartIF<IService> svc ) const;
730  void initGaudiCommonConstructor( const IInterface * parent = 0 );
731  // ==========================================================================
732 private:
734  mutable AlgTools m_managedTools;
736  mutable Services m_services ;
737  // ==========================================================================
739  mutable Counter m_errors ;
741  mutable Counter m_warnings ;
743  mutable Counter m_infos ;
745  mutable Counter m_exceptions ;
747  mutable Statistics m_counters ;
748  // ==========================================================================
750  mutable IUpdateManagerSvc* m_updMgrSvc = nullptr;
751  // ==========================================================================
753  bool m_typePrint = true ;
755  bool m_propsPrint = false ;
757  bool m_statPrint = true ;
759  bool m_errorsPrint = true ;
760  // ==========================================================================
765  // ==========================================================================
766  // the header row
768  // format for regular statistical printout rows
770  // format for "efficiency" statistical printout rows
772  // flag to use the special "efficiency" format
774 } ;
775 // ============================================================================
776 #include "GaudiAlg/GaudiCommonImp.h"
777 // ============================================================================
778 
779 // ============================================================================
780 // The END
781 // ============================================================================
782 #endif // GAUDIALG_GAUDICOMMON_H
783 // ============================================================================
The implementation of inline/templated methods for class GaudiCommon.
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:46
Counter m_warnings
counter of warnings
Definition: GaudiCommon.h:741
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:45
Define general base for Gaudi exception.
def initialize()
Definition: AnalysisTest.py:12
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Counter m_exceptions
Counter of exceptions.
Definition: GaudiCommon.h:745
std::map< std::string, unsigned int > Counter
the actual type error/warning counter
Definition: GaudiCommon.h:106
const std::string & rootInTES() const
Returns the "rootInTES" string.
Definition: GaudiCommon.h:716
std::vector< IAlgTool * > AlgTools
storage for active tools
Definition: GaudiCommon.h:108
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
void registerCondition(TargetClass *condition, StatusCode(CallerClass::*mf)()=NULL)
register the current instance to the UpdateManagerSvc as a consumer for a condition.
Definition: GaudiCommon.h:616
Services m_services
List of active services.
Definition: GaudiCommon.h:736
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:47
Statistics m_counters
General counters.
Definition: GaudiCommon.h:747
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:712
const Statistics & counters() const
accessor to all counters
Definition: GaudiCommon.h:494
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:40
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:597
Data provider interface definition.
void registerCondition(const std::string &condition, StatusCode(CallerClass::*mf)()=nullptr)
register the current instance to the UpdateManagerSvc as a consumer for a condition.
Definition: GaudiCommon.h:557
const Services & services() const
get the list of aquired services
Definition: GaudiCommon.h:698
STL class.
bool statPrint() const
Print statistical counters at finalization ?
Definition: GaudiCommon.h:521
bool m_useEffFormat
flag to use the special "efficiency" format
Definition: GaudiCommon.h:773
StatEntity & counter(const std::string &tag) const
accessor to certain counter by name
Definition: GaudiCommon.h:513
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
std::map< std::string, StatEntity > Statistics
the actual type of general counters
Definition: GaudiCommon.h:104
Counter m_errors
Counter of errors.
Definition: GaudiCommon.h:739
string type
Definition: gaudirun.py:151
std::string m_format1
format for regular statistical printout rows
Definition: GaudiCommon.h:769
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::string m_rootInTES
The rootInTES string.
Definition: GaudiCommon.h:764
bool propsPrint() const
Print properties at initialization ?
Definition: GaudiCommon.h:519
Definition of the basic interface.
Definition: IInterface.h:234
Counter m_infos
counter of infos
Definition: GaudiCommon.h:743
bool errorsPrint() const
Print error counters at finalization ?
Definition: GaudiCommon.h:523
std::vector< SmartIF< IService > > Services
storage for active services
Definition: GaudiCommon.h:110
SmartIF< ICounterSummarySvc > m_counterSummarySvc
a pointer to the CounterSummarySvc
Definition: GaudiCommon.h:115
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:630
STL class.
std::string m_header
the header row
Definition: GaudiCommon.h:767
bool typePrint() const
Insert the actual C++ type of the algorithm/tool in the messages ?
Definition: GaudiCommon.h:517
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:42
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::string m_format2
format for "efficiency" statistical printout rows
Definition: GaudiCommon.h:771
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:591
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:45
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
string s
Definition: gaudirun.py:245
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:73
AlgTools m_managedTools
List of active tools.
Definition: GaudiCommon.h:734
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:41
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:64
std::string m_context
The context string.
Definition: GaudiCommon.h:762
#define GAUDI_API
Definition: Kernel.h:107
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Helper functions to set/get the application return code.
Definition: __init__.py:1