The Gaudi Framework  v29r0 (ff2e7097)
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 
607 public:
610  template <typename U = PBASE, class = typename std::enable_if<std::is_base_of<Algorithm, PBASE>::value, U>::type>
611  GaudiCommon( const std::string& name, ISvcLocator* pSvcLocator ) : base_class( name, pSvcLocator )
612  {
613  initGaudiCommonConstructor();
614  }
617  template <typename U = PBASE, class = typename std::enable_if<std::is_base_of<AlgTool, PBASE>::value, U>::type>
618  GaudiCommon( const std::string& type, const std::string& name, const IInterface* ancestor )
619  : base_class( type, name, ancestor )
620  {
621  initGaudiCommonConstructor( this->parent() );
622  }
623 
624 public:
628  StatusCode initialize() override
629 #ifdef __ICC
630  {
631  return i_gcInitialize();
632  }
633  StatusCode i_gcInitialize()
634 #endif
635  ;
639  StatusCode finalize() override
640 #ifdef __ICC
641  {
642  return i_gcFinalize();
643  }
644  StatusCode i_gcFinalize()
645 #endif
646  ;
647 protected:
649  ~GaudiCommon() override = default;
650 
651 private:
652  GaudiCommon() = delete;
653  GaudiCommon( const GaudiCommon& ) = delete;
654  GaudiCommon& operator=( const GaudiCommon& ) = delete;
655 
656 protected:
658  StatusCode releaseTool( const IAlgTool* tool ) const;
660  StatusCode releaseSvc( const IInterface* svc ) const;
661 
662 public:
682  StatusCode release( const IInterface* interface ) const;
683 
685  using PBASE::release;
686  // ==========================================================================
687 public:
688  // ==========================================================================
690  const Services& services() const { return m_services; } // get all services
691  // ==========================================================================
692 private:
693  // ==========================================================================
695  void printErrorHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "ErrorPrint"
697  void printPropsHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "PropertiesPrint"
699  void printStatHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "StatPrint"
700  // ==========================================================================
701 public:
702  // ==========================================================================
704  inline const std::string& context() const { return m_context; }
708  inline const std::string& rootInTES() const { return m_rootInTES; }
709  // ==========================================================================
710 public:
711  // ==========================================================================
713  const std::string fullTESLocation( const std::string& location, const bool useRootInTES ) const;
714  // ==========================================================================
715 private:
716  // ==========================================================================
718  void addToServiceList( SmartIF<IService> svc ) const;
720  void initGaudiCommonConstructor( const IInterface* parent = nullptr );
721  // ==========================================================================
722 private:
724  mutable AlgTools m_managedTools;
726  mutable Services m_services;
727  // ==========================================================================
729  mutable Counter m_errors;
731  mutable Counter m_warnings;
733  mutable Counter m_infos;
735  mutable Counter m_exceptions;
737  mutable Statistics m_counters;
738  // ==========================================================================
740  mutable IUpdateManagerSvc* m_updMgrSvc = nullptr;
741  // ==========================================================================
742  // Properties
743  Gaudi::Property<bool> m_errorsPrint{this, "ErrorsPrint", true, "print the statistics of errors/warnings/exceptions"};
744  Gaudi::Property<bool> m_propsPrint{this, "PropertiesPrint", false, "print the properties of the component"};
745  Gaudi::Property<bool> m_statPrint{this, "StatPrint", true, "print the table of counters"};
746  Gaudi::Property<bool> m_typePrint{this, "TypePrint", true, "add the actual C++ component type into the messages"};
747 
748  Gaudi::Property<std::string> m_context{this, "Context", {}, "note: overridden by parent settings"};
749  Gaudi::Property<std::string> m_rootInTES{this, "RootInTES", {}, "note: overridden by parent settings"};
750 
751  Gaudi::Property<std::string> m_header{this, "StatTableHeader",
752  " | Counter | # | "
753  " sum | mean/eff^* | rms/err^* | min | max |",
754  "the header row for the output Stat-table"};
756  this, "RegularRowFormat", " | %|-48.48s|%|50t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |",
757  "the format for regular row in the output Stat-table"};
759  this, "EfficiencyRowFormat",
760  " |*%|-48.48s|%|50t||%|10d| |%|11.5g| |(%|#9.6g| +- %|-#9.6g|)%%| ------- | ------- |",
761  "The format for \"efficiency\" row in the output Stat-table"};
762  Gaudi::Property<bool> m_useEffFormat{this, "UseEfficiencyRowFormat", true,
763  "use the special format for printout of efficiency counters"};
764 
766  this, "CounterList", {".*"}, "RegEx list, of simple integer counters for CounterSummary"};
768  this, "StatEntityList", {}, "RegEx list, of StatEntity counters for CounterSummary"};
769 };
770 // ============================================================================
771 #include "GaudiAlg/GaudiCommonImp.h"
772 // ============================================================================
773 
774 // ============================================================================
775 // The END
776 // ============================================================================
777 #endif // GAUDIALG_GAUDICOMMON_H
778 // ============================================================================
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:731
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:735
Implementation of property with value of concrete type.
Definition: Property.h:319
const std::string & rootInTES() const
Returns the "rootInTES" string.
Definition: GaudiCommon.h:708
GaudiCommon(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor - the SFINAE constraint below ensures that this is constructor is only defined ...
Definition: GaudiCommon.h:611
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:726
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:55
Statistics m_counters
General counters.
Definition: GaudiCommon.h:737
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:704
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:690
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:729
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
bool propsPrint() const
Print properties at initialization ?
Definition: GaudiCommon.h:490
Definition of the basic interface.
Definition: IInterface.h:277
Counter m_infos
counter of infos
Definition: GaudiCommon.h:733
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:48
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
string s
Definition: gaudirun.py:253
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:80
AlgTools m_managedTools
List of active tools.
Definition: GaudiCommon.h:724
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:49
GaudiCommon(const std::string &type, const std::string &name, const IInterface *ancestor)
Tool constructor - SFINAE-ed to insure this constructor is only defined if PBASE derives from AlgTool...
Definition: GaudiCommon.h:618
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:65
#define GAUDI_API
Definition: Kernel.h:110
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
Helper functions to set/get the application return code.
Definition: __init__.py:1
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)