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 <algorithm>
9 #include <map>
10 #include <string>
11 #include <vector>
12 // ============================================================================
13 // GaudiKernel
14 // ============================================================================
17 #include "GaudiKernel/HashMap.h"
19 #include "GaudiKernel/IAlgTool.h"
20 #include "GaudiKernel/IAlgorithm.h"
25 #include "GaudiKernel/IToolSvc.h"
28 #include "GaudiKernel/StatEntity.h"
29 #include "GaudiKernel/StatusCode.h"
30 #include "GaudiKernel/System.h"
31 // ============================================================================
32 // forward declarations
33 // ============================================================================
34 class Algorithm; // GaudiKernel
35 class AlgTool; // GaudiKernel
36 namespace Gaudi
37 {
38  namespace Utils
39  {
40  template <class TYPE>
41  struct GetData;
42  }
43 }
44 
46 {
47  constexpr const struct svc_eq_t {
48  bool operator()( const std::string& n, const SmartIF<IService>& s ) const { return n == s->name(); };
49  bool operator()( const SmartIF<IService>& s, const std::string& n ) const { return s->name() == n; };
50  bool operator()( const SmartIF<IService>& s, const SmartIF<IService>& n ) const { return s->name() == n->name(); };
51  } svc_eq{};
52  constexpr const struct svc_lt_t {
53  bool operator()( const std::string& n, const SmartIF<IService>& s ) const { return n < s->name(); };
54  bool operator()( const SmartIF<IService>& s, const std::string& n ) const { return s->name() < n; };
55  bool operator()( const SmartIF<IService>& s, const SmartIF<IService>& n ) const { return s->name() < n->name(); };
56  } svc_lt{};
57 }
58 // ============================================================================
59 /* @file GaudiCommon.h
60  *
61  * Header file for class : GaudiCommon
62  *
63  * @author Chris Jones Christopher.Rob.Jones@cern.ch
64  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
65  * @author Rob Lambert Rob.Lambert@cern.ch
66  * @date 2009-08-04
67  */
68 // ============================================================================
78 // ============================================================================
79 template <class PBASE>
80 class GAUDI_API GaudiCommon : public PBASE
81 {
82 protected: // definitions
83  using base_class = PBASE;
84 
94  static const bool IgnoreRootInTES = false;
106  static const bool UseRootInTES = true;
107  // ==========================================================================
108 protected: // few actual data types
109  // ==========================================================================
118 
119  // ==========================================================================
120  // protected members such that they can be used in the derived classes
123 
124 public:
125  // ==========================================================================
159  template <class TYPE>
161  const bool useRootInTES = true ) const;
165  template <class TYPE>
166  typename Gaudi::Utils::GetData<TYPE>::return_type getIfExists( IDataProviderSvc* svc, const std::string& location,
167  const bool useRootInTES = true ) const;
194  template <class TYPE>
195  bool exist( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const;
223  template <class TYPE, class TYPE2>
224  typename Gaudi::Utils::GetData<TYPE>::return_type getOrCreate( IDataProviderSvc* svc, const std::string& location,
225  const bool useRootInTES = true ) const;
251  DataObject* put( IDataProviderSvc* svc, DataObject* object, const std::string& location,
252  const bool useRootInTES = true ) const;
278  template <class TOOL>
279  TOOL* tool( const std::string& type, const std::string& name, const IInterface* parent = 0,
280  bool create = true ) const;
303  template <class TOOL>
304  TOOL* tool( const std::string& type, const IInterface* parent = 0, bool create = true ) const;
327  template <class SERVICE>
328  SmartIF<SERVICE> svc( const std::string& name, const bool create = true ) const;
330  inline IUpdateManagerSvc* updMgrSvc() const;
331 
332 public:
356  StatusCode Error( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const;
380  StatusCode Warning( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const;
396  StatusCode Info( const std::string& msg, const StatusCode st = StatusCode::SUCCESS, const size_t mx = 10 ) const;
408  StatusCode Print( const std::string& msg, const StatusCode st = StatusCode::SUCCESS,
409  const MSG::Level lev = MSG::INFO ) const;
418  inline void Assert( const bool ok, const std::string& message = "",
419  const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
428  inline void Assert( const bool ok, const char* message,
429  const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
438  void Exception( const std::string& msg, const GaudiException& exc,
439  const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
449  void Exception( const std::string& msg, const std::exception& exc,
450  const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
459  void Exception( const std::string& msg = "no message",
460  const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
461 
462 public:
463  // ==========================================================================
465  inline const Statistics& counters() const { return m_counters; }
484  inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag]; }
485  // ==========================================================================
486 public:
488  inline bool typePrint() const { return m_typePrint; }
490  inline bool propsPrint() const { return m_propsPrint; }
492  inline bool statPrint() const { return m_statPrint; }
494  inline bool errorsPrint() const { return m_errorsPrint; }
495  // ==========================================================================
496 public:
501  long printStat( const MSG::Level level = MSG::ALWAYS ) const;
506  long printErrors( const MSG::Level level = MSG::ALWAYS ) const;
511  long printProps( const MSG::Level level = MSG::ALWAYS ) const;
527  template <class CallerClass>
528  inline void registerCondition( const std::string& condition, StatusCode ( CallerClass::*mf )() = nullptr )
529  {
530  updMgrSvc()->registerCondition( dynamic_cast<CallerClass*>( this ), condition, mf );
531  }
562  template <class CallerClass, class CondType>
563  inline void registerCondition( const std::string& condition, CondType*& condPtrDest,
564  StatusCode ( CallerClass::*mf )() = NULL )
565  {
566  updMgrSvc()->registerCondition( dynamic_cast<CallerClass*>( this ), condition, mf, condPtrDest );
567  }
569  template <class CallerClass>
570  inline void registerCondition( char* condition, StatusCode ( CallerClass::*mf )() = NULL )
571  {
572  updMgrSvc()->registerCondition( dynamic_cast<CallerClass*>( this ), std::string( condition ), mf );
573  }
589  template <class CallerClass, class TargetClass>
590  inline void registerCondition( TargetClass* condition, StatusCode ( CallerClass::*mf )() = NULL )
591  {
592  updMgrSvc()->registerCondition( dynamic_cast<CallerClass*>( this ), condition, mf );
593  }
605  inline StatusCode runUpdate() { return updMgrSvc()->update( this ); }
606 public:
608  GaudiCommon( const std::string& name, ISvcLocator* pSvcLocator );
610  GaudiCommon( const std::string& type, const std::string& name, const IInterface* parent );
611 
612 public:
616  StatusCode initialize() override
617 #ifdef __ICC
618  {
619  return i_gcInitialize();
620  }
621  StatusCode i_gcInitialize()
622 #endif
623  ;
627  StatusCode finalize() override
628 #ifdef __ICC
629  {
630  return i_gcFinalize();
631  }
632  StatusCode i_gcFinalize()
633 #endif
634  ;
635 protected:
637  ~GaudiCommon() override = default;
638 
639 private:
640  GaudiCommon() = delete;
641  GaudiCommon( const GaudiCommon& ) = delete;
642  GaudiCommon& operator=( const GaudiCommon& ) = delete;
643 
644 protected:
646  StatusCode releaseTool( const IAlgTool* tool ) const;
648  StatusCode releaseSvc( const IInterface* svc ) const;
649 
650 public:
670  StatusCode release( const IInterface* interface ) const;
671 
673  using PBASE::release;
674  // ==========================================================================
675 public:
676  // ==========================================================================
678  const Services& services() const { return m_services; } // get all services
679  // ==========================================================================
680 private:
681  // ==========================================================================
683  void printErrorHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "ErrorPrint"
685  void printPropsHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "PropertiesPrint"
687  void printStatHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "StatPrint"
688  // ==========================================================================
689 public:
690  // ==========================================================================
692  inline const std::string& context() const { return m_context; }
696  inline const std::string& rootInTES() const { return m_rootInTES; }
697  // ==========================================================================
698 public:
699  // ==========================================================================
701  const std::string fullTESLocation( const std::string& location, const bool useRootInTES ) const;
702  // ==========================================================================
703 private:
704  // ==========================================================================
706  void addToServiceList( SmartIF<IService> svc ) const;
708  void initGaudiCommonConstructor( const IInterface* parent = 0 );
709  // ==========================================================================
710 private:
712  mutable AlgTools m_managedTools;
714  mutable Services m_services;
715  // ==========================================================================
717  mutable Counter m_errors;
719  mutable Counter m_warnings;
721  mutable Counter m_infos;
723  mutable Counter m_exceptions;
725  mutable Statistics m_counters;
726  // ==========================================================================
728  mutable IUpdateManagerSvc* m_updMgrSvc = nullptr;
729  // ==========================================================================
730  // Properties
731  Gaudi::Property<bool> m_errorsPrint{this, "ErrorsPrint", true, "print the statistics of errors/warnings/exceptions"};
732  Gaudi::Property<bool> m_propsPrint{this, "PropertiesPrint", false, "print the properties of the component"};
733  Gaudi::Property<bool> m_statPrint{this, "StatPrint", true, "print the table of counters"};
734  Gaudi::Property<bool> m_typePrint{this, "TypePrint", true, "add the actual C++ component type into the messages"};
735 
736  Gaudi::Property<std::string> m_context{this, "Context", {}, "note: overridden by parent settings"};
737  Gaudi::Property<std::string> m_rootInTES{this, "RootInTES", {}, "note: overridden by parent settings"};
738 
739  Gaudi::Property<std::string> m_header{this, "StatTableHeader",
740  " | Counter | # | "
741  " sum | mean/eff^* | rms/err^* | min | max |",
742  "the header row for the output Stat-table"};
744  this, "RegularRowFormat", " | %|-48.48s|%|50t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |",
745  "the format for regular row in the output Stat-table"};
747  this, "EfficiencyRowFormat",
748  " |*%|-48.48s|%|50t||%|10d| |%|11.5g| |(%|#9.6g| +- %|-#9.6g|)%%| ------- | ------- |",
749  "The format for \"efficiency\" row in the output Stat-table"};
750  Gaudi::Property<bool> m_useEffFormat{this, "UseEfficiencyRowFormat", true,
751  "use the special format for printout of efficiency counters"};
752 
754  this, "CounterList", {".*"}, "RegEx list, of simple integer counters for CounterSummary"};
756  this, "StatEntityList", {}, "RegEx list, of StatEntity counters for CounterSummary"};
757 };
758 // ============================================================================
759 #include "GaudiAlg/GaudiCommonImp.h"
760 // ============================================================================
761 
762 // ============================================================================
763 // The END
764 // ============================================================================
765 #endif // GAUDIALG_GAUDICOMMON_H
766 // ============================================================================
The implementation of inline/templated methods for class GaudiCommon.
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:54
std::map< std::string, StatEntity > Statistics
the actual type of general counters
Definition: GaudiCommon.h:111
Counter m_warnings
counter of warnings
Definition: GaudiCommon.h:719
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:53
Define general base for Gaudi exception.
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:723
Implementation of property with value of concrete type.
Definition: Property.h:313
const std::string & rootInTES() const
Returns the "rootInTES" string.
Definition: GaudiCommon.h:696
std::vector< IAlgTool * > AlgTools
storage for active tools
Definition: GaudiCommon.h:115
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:590
std::map< std::string, unsigned int > Counter
the actual type error/warning counter
Definition: GaudiCommon.h:113
Services m_services
List of active services.
Definition: GaudiCommon.h:714
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:55
Statistics m_counters
General counters.
Definition: GaudiCommon.h:725
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:41
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:692
const Statistics & counters() const
accessor to all counters
Definition: GaudiCommon.h:465
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:48
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:570
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:528
const Services & services() const
get the list of aquired services
Definition: GaudiCommon.h:678
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
bool statPrint() const
Print statistical counters at finalization ?
Definition: GaudiCommon.h:492
StatEntity & counter(const std::string &tag) const
accessor to certain counter by name
Definition: GaudiCommon.h:484
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
Counter m_errors
Counter of errors.
Definition: GaudiCommon.h:717
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
bool propsPrint() const
Print properties at initialization ?
Definition: GaudiCommon.h:490
Definition of the basic interface.
Definition: IInterface.h:234
Counter m_infos
counter of infos
Definition: GaudiCommon.h:721
bool errorsPrint() const
Print error counters at finalization ?
Definition: GaudiCommon.h:494
std::vector< SmartIF< IService > > Services
storage for active services
Definition: GaudiCommon.h:117
SmartIF< ICounterSummarySvc > m_counterSummarySvc
a pointer to the CounterSummarySvc
Definition: GaudiCommon.h:122
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
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:605
STL class.
bool typePrint() const
Insert the actual C++ type of the algorithm/tool in the messages ?
Definition: GaudiCommon.h:488
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:50
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
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:563
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:46
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:80
AlgTools m_managedTools
List of active tools.
Definition: GaudiCommon.h:712
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:49
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:64
#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