| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 // ============================================================================
15 #include "GaudiKernel/DataObjectHandle.h"
16 #include "GaudiKernel/GaudiException.h"
17 #include "GaudiKernel/HashMap.h"
18 #include "GaudiKernel/IAlgContextSvc.h"
19 #include "GaudiKernel/IAlgTool.h"
20 #include "GaudiKernel/IAlgorithm.h"
21 #include "GaudiKernel/IChronoStatSvc.h"
22 #include "GaudiKernel/ICounterSummarySvc.h"
23 #include "GaudiKernel/IDataProviderSvc.h"
24 #include "GaudiKernel/IMessageSvc.h"
25 #include "GaudiKernel/IToolSvc.h"
26 #include "GaudiKernel/IUpdateManagerSvc.h"
27 #include "GaudiKernel/SmartDataPtr.h"
28 #include "GaudiKernel/StatEntity.h"
29 #include "GaudiKernel/StatusCode.h"
30 #include "GaudiKernel/System.h"
31
32 #ifdef __CLING__
33 #define WARN_UNUSED
34 #elif __cplusplus > 201402L
35 #define WARN_UNUSED [[nodiscard]]
36 #else
37 #define WARN_UNUSED [[gnu::warn_unused_result]]
38 #endif
39
40 // ============================================================================
41 // forward declarations
42 // ============================================================================
43 class Algorithm; // GaudiKernel
44 class AlgTool; // GaudiKernel
45 namespace Gaudi
46 {
47 namespace Utils
48 {
49 template <class TYPE>
50 struct GetData;
51 }
52 }
53
54 namespace GaudiCommon_details
55 {
56 constexpr const struct svc_eq_t {
57 bool operator()( const std::string& n, const SmartIF<IService>& s ) const { return n == s->name(); };
58 bool operator()( const SmartIF<IService>& s, const std::string& n ) const { return s->name() == n; };
59 bool operator()( const SmartIF<IService>& s, const SmartIF<IService>& n ) const { return s->name() == n->name(); };
60 } svc_eq{};
61 constexpr const struct svc_lt_t {
62 bool operator()( const std::string& n, const SmartIF<IService>& s ) const { return n < s->name(); };
63 bool operator()( const SmartIF<IService>& s, const std::string& n ) const { return s->name() < n; };
64 bool operator()( const SmartIF<IService>& s, const SmartIF<IService>& n ) const { return s->name() < n->name(); };
65 } svc_lt{};
66 }
67 // ============================================================================
68 /* @file GaudiCommon.h
69 *
70 * Header file for class : GaudiCommon
71 *
72 * @author Chris Jones Christopher.Rob.Jones@cern.ch
73 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
74 * @author Rob Lambert Rob.Lambert@cern.ch
75 * @date 2009-08-04
76 */
77 // ============================================================================
87 // ============================================================================
88 template <class PBASE>
89 class GAUDI_API GaudiCommon : public PBASE
90 {
91 protected: // definitions
92 using base_class = PBASE;
93
103 static const bool IgnoreRootInTES = false;
115 static const bool UseRootInTES = true;
116 // ==========================================================================
117 protected: // few actual data types
118 // ==========================================================================
120 typedef std::map<std::string, StatEntity> Statistics;
122 typedef std::map<std::string, unsigned int> Counter;
124 typedef std::vector<IAlgTool*> AlgTools;
126 typedef std::vector<SmartIF<IService>> Services;
127
128 // ==========================================================================
129 // protected members such that they can be used in the derived classes
131 SmartIF<ICounterSummarySvc> m_counterSummarySvc;
132
133 public:
134 // ==========================================================================
168 template <class TYPE>
169 typename Gaudi::Utils::GetData<TYPE>::return_type get( IDataProviderSvc* svc, const std::string& location,
170 const bool useRootInTES = true ) const;
174 template <class TYPE>
175 typename Gaudi::Utils::GetData<TYPE>::return_type getIfExists( IDataProviderSvc* svc, const std::string& location,
176 const bool useRootInTES = true ) const;
203 template <class TYPE>
204 bool exist( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const;
232 template <class TYPE, class TYPE2>
233 typename Gaudi::Utils::GetData<TYPE>::return_type getOrCreate( IDataProviderSvc* svc, const std::string& location,
234 const bool useRootInTES = true ) const;
260 DataObject* put( IDataProviderSvc* svc, DataObject* object, const std::string& location,
261 const bool useRootInTES = true ) const;
287 template <class TOOL>
288 TOOL* tool( const std::string& type, const std::string& name, const IInterface* parent = 0,
289 bool create = true ) const;
312 template <class TOOL>
313 TOOL* tool( const std::string& type, const IInterface* parent = 0, bool create = true ) const;
336 template <class SERVICE>
337 SmartIF<SERVICE> svc( const std::string& name, const bool create = true ) const;
339 inline IUpdateManagerSvc* updMgrSvc() const;
340
341 public:
365 WARN_UNUSED
366 StatusCode Error( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const;
390 WARN_UNUSED
391 StatusCode Warning( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const;
407 WARN_UNUSED
408 StatusCode Info( const std::string& msg, const StatusCode st = StatusCode::SUCCESS, const size_t mx = 10 ) const;
420 WARN_UNUSED
421 StatusCode Print( const std::string& msg, const StatusCode st = StatusCode::SUCCESS,
422 const MSG::Level lev = MSG::INFO ) const;
431 inline void Assert( const bool ok, const std::string& message = "",
432 const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
441 inline void Assert( const bool ok, const char* message,
442 const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
451 void Exception( const std::string& msg, const GaudiException& exc,
452 const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
462 void Exception( const std::string& msg, const std::exception& exc,
463 const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
472 void Exception( const std::string& msg = "no message",
473 const StatusCode sc = StatusCode( StatusCode::FAILURE, true ) ) const;
474
475 public:
476 // ==========================================================================
478 inline const Statistics& counters() const { return m_counters; }
497 inline StatEntity& counter( const std::string& tag ) const { return m_counters[tag]; }
498 // ==========================================================================
499 public:
501 inline bool typePrint() const { return m_typePrint; }
503 inline bool propsPrint() const { return m_propsPrint; }
505 inline bool statPrint() const { return m_statPrint; }
507 inline bool errorsPrint() const { return m_errorsPrint; }
508 // ==========================================================================
509 public:
514 long printStat( const MSG::Level level = MSG::ALWAYS ) const;
519 long printErrors( const MSG::Level level = MSG::ALWAYS ) const;
524 long printProps( const MSG::Level level = MSG::ALWAYS ) const;
540 template <class CallerClass>
541 inline void registerCondition( const std::string& condition, StatusCode ( CallerClass::*mf )() = nullptr )
542 {
543 updMgrSvc()->registerCondition( dynamic_cast<CallerClass*>( this ), condition, mf );
544 }
575 template <class CallerClass, class CondType>
576 inline void registerCondition( const std::string& condition, CondType*& condPtrDest,
577 StatusCode ( CallerClass::*mf )() = NULL )
578 {
579 updMgrSvc()->registerCondition( dynamic_cast<CallerClass*>( this ), condition, mf, condPtrDest );
580 }
582 template <class CallerClass>
583 inline void registerCondition( char* condition, StatusCode ( CallerClass::*mf )() = NULL )
584 {
585 updMgrSvc()->registerCondition( dynamic_cast<CallerClass*>( this ), std::string( condition ), mf );
586 }
602 template <class CallerClass, class TargetClass>
603 inline void registerCondition( TargetClass* condition, StatusCode ( CallerClass::*mf )() = NULL )
604 {
605 updMgrSvc()->registerCondition( dynamic_cast<CallerClass*>( this ), condition, mf );
606 }
618 inline StatusCode runUpdate() { return updMgrSvc()->update( this ); }
619
620 public:
623 template <typename U = PBASE, typename = std::enable_if_t<std::is_base_of<Algorithm, PBASE>::value, U>>
624 GaudiCommon( const std::string& name, ISvcLocator* pSvcLocator ) : base_class( name, pSvcLocator )
625 {
626 initGaudiCommonConstructor();
627 }
630 template <typename U = PBASE, typename = std::enable_if_t<std::is_base_of<AlgTool, PBASE>::value, U>>
631 GaudiCommon( const std::string& type, const std::string& name, const IInterface* ancestor )
632 : base_class( type, name, ancestor )
633 {
634 initGaudiCommonConstructor( this->parent() );
635 }
636
637 public:
641 StatusCode initialize() override
642 #ifdef __ICC
643 {
644 return i_gcInitialize();
645 }
646 StatusCode i_gcInitialize()
647 #endif
648 ;
652 StatusCode finalize() override
653 #ifdef __ICC
654 {
655 return i_gcFinalize();
656 }
657 StatusCode i_gcFinalize()
658 #endif
659 ;
660 protected:
662 ~GaudiCommon() override = default;
663
664 private:
665 GaudiCommon() = delete;
666 GaudiCommon( const GaudiCommon& ) = delete;
667 GaudiCommon& operator=( const GaudiCommon& ) = delete;
668
669 protected:
671 StatusCode releaseTool( const IAlgTool* tool ) const;
673 StatusCode releaseSvc( const IInterface* svc ) const;
674
675 public:
695 StatusCode release( const IInterface* interface ) const;
696
698 using PBASE::release;
699 // ==========================================================================
700 public:
701 // ==========================================================================
703 const Services& services() const { return m_services; } // get all services
704 // ==========================================================================
705 private:
706 // ==========================================================================
708 void printErrorHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "ErrorPrint"
710 void printPropsHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "PropertiesPrint"
712 void printStatHandler( Gaudi::Details::PropertyBase& /* theProp */ ); // "StatPrint"
713 // ==========================================================================
714 public:
715 // ==========================================================================
717 inline const std::string& context() const { return m_context; }
721 inline const std::string& rootInTES() const { return m_rootInTES; }
722 // ==========================================================================
723 public:
724 // ==========================================================================
726 const std::string fullTESLocation( const std::string& location, const bool useRootInTES ) const;
727 // ==========================================================================
728 private:
729 // ==========================================================================
731 void addToServiceList( SmartIF<IService> svc ) const;
733 void initGaudiCommonConstructor( const IInterface* parent = nullptr );
734 // ==========================================================================
735 private:
737 mutable AlgTools m_managedTools;
739 mutable Services m_services;
740 // ==========================================================================
742 mutable Counter m_errors;
744 mutable Counter m_warnings;
746 mutable Counter m_infos;
748 mutable Counter m_exceptions;
750 mutable Statistics m_counters;
751 // ==========================================================================
753 mutable IUpdateManagerSvc* m_updMgrSvc = nullptr;
754 // ==========================================================================
755 // Properties
756 Gaudi::Property<bool> m_errorsPrint{this, "ErrorsPrint", true, "print the statistics of errors/warnings/exceptions"};
757 Gaudi::Property<bool> m_propsPrint{this, "PropertiesPrint", false, "print the properties of the component"};
758 Gaudi::Property<bool> m_statPrint{this, "StatPrint", true, "print the table of counters"};
759 Gaudi::Property<bool> m_typePrint{this, "TypePrint", true, "add the actual C++ component type into the messages"};
760
761 Gaudi::Property<std::string> m_context{this, "Context", {}, "note: overridden by parent settings"};
762 Gaudi::Property<std::string> m_rootInTES{this, "RootInTES", {}, "note: overridden by parent settings"};
763
764 Gaudi::Property<std::string> m_header{this, "StatTableHeader",
765 " | Counter | # | "
766 " sum | mean/eff^* | rms/err^* | min | max |",
767 "the header row for the output Stat-table"};
768 Gaudi::Property<std::string> m_format1{
769 this, "RegularRowFormat", " | %|-48.48s|%|50t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |",
770 "the format for regular row in the output Stat-table"};
771 Gaudi::Property<std::string> m_format2{
772 this, "EfficiencyRowFormat",
773 " |*%|-48.48s|%|50t||%|10d| |%|11.5g| |(%|#9.6g| +- %|-#9.6g|)%%| ------- | ------- |",
774 "The format for \"efficiency\" row in the output Stat-table"};
775 Gaudi::Property<bool> m_useEffFormat{this, "UseEfficiencyRowFormat", true,
776 "use the special format for printout of efficiency counters"};
777
778 Gaudi::Property<std::vector<std::string>> m_counterList{
779 this, "CounterList", {".*"}, "RegEx list, of simple integer counters for CounterSummary"};
780 Gaudi::Property<std::vector<std::string>> m_statEntityList{
781 this, "StatEntityList", {}, "RegEx list, of StatEntity counters for CounterSummary"};
782 };
783 // ============================================================================
784 #include "GaudiAlg/GaudiCommonImp.h"
785 // ============================================================================
786
787 // ============================================================================
788 // The END
789 // ============================================================================
790 #endif // GAUDIALG_GAUDICOMMON_H
791 // ============================================================================
GaudiCommonImp.h
The implementation of inline/templated methods for class GaudiCommon.
GaudiCommon_details::svc_lt_t::operator()
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:63
System.h
GaudiCommon_details
Definition: GaudiCommon.h:54
GaudiCommon::Statistics
std::map< std::string, StatEntity > Statistics
the actual type of general counters
Definition: GaudiCommon.h:120
GaudiCommon::m_warnings
Counter m_warnings
counter of warnings
Definition: GaudiCommon.h:744
StatusCode::SUCCESS
Definition: StatusCode.h:29
SmartIF< IService >
GaudiCommon_details::svc_lt_t::operator()
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:62
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
GaudiCommon::m_exceptions
Counter m_exceptions
Counter of exceptions.
Definition: GaudiCommon.h:748
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:319
GaudiCommon::rootInTES
const std::string & rootInTES() const
Returns the "rootInTES" string.
Definition: GaudiCommon.h:721
GaudiCommon::GaudiCommon
GaudiCommon(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor - the SFINAE constraint below ensures that this is constructor is only defined ...
Definition: GaudiCommon.h:624
GaudiCommon::AlgTools
std::vector< IAlgTool * > AlgTools
storage for active tools
Definition: GaudiCommon.h:124
GaudiCommon_details::svc_eq
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
IAlgorithm.h
GaudiCommon::registerCondition
void registerCondition(TargetClass *condition, StatusCode(CallerClass::*mf)()=NULL)
register the current instance to the UpdateManagerSvc as a consumer for a condition.
Definition: GaudiCommon.h:603
GaudiCommon::Counter
std::map< std::string, unsigned int > Counter
the actual type error/warning counter
Definition: GaudiCommon.h:122
GaudiCommon::m_services
Services m_services
List of active services.
Definition: GaudiCommon.h:739
GaudiCommon_details::svc_lt_t::operator()
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:64
GaudiPython.HistoUtils.location
location
Definition: HistoUtils.py:899
IUpdateManagerSvc.h
GaudiCommon::m_counters
Statistics m_counters
General counters.
Definition: GaudiCommon.h:750
Gaudi::Utils::GetData
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:50
ICounterSummarySvc.h
GaudiCommon::context
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:717
GaudiCommon::counters
const Statistics & counters() const
accessor to all counters
Definition: GaudiCommon.h:478
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:57
GaudiCommon::registerCondition
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:583
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:46
HashMap.h
GaudiCommon::registerCondition
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:541
IToolSvc.h
std::map< std::string, StatEntity >
GaudiCommon::services
const Services & services() const
get the list of aquired services
Definition: GaudiCommon.h:703
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:228
MSG::Level
Level
Definition: IMessageSvc.h:16
GaudiCommon::statPrint
bool statPrint() const
Print statistical counters at finalization ?
Definition: GaudiCommon.h:505
GaudiCommon::counter
StatEntity & counter(const std::string &tag) const
accessor to certain counter by name
Definition: GaudiCommon.h:497
IDataProviderSvc.h
GaudiCommon_details::svc_lt
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
GaudiCommon::m_errors
Counter m_errors
Counter of errors.
Definition: GaudiCommon.h:742
SmartDataPtr.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiCommon::propsPrint
bool propsPrint() const
Print properties at initialization ?
Definition: GaudiCommon.h:503
GaudiException.h
IInterface
Definition of the basic interface.
Definition: IInterface.h:277
gaudirun.type
type
Definition: gaudirun.py:133
GaudiCommon::m_infos
Counter m_infos
counter of infos
Definition: GaudiCommon.h:746
IAlgTool.h
GaudiCommon::errorsPrint
bool errorsPrint() const
Print error counters at finalization ?
Definition: GaudiCommon.h:507
GaudiCommon::Services
std::vector< SmartIF< IService > > Services
storage for active services
Definition: GaudiCommon.h:126
GaudiCommon::m_counterSummarySvc
SmartIF< ICounterSummarySvc > m_counterSummarySvc
a pointer to the CounterSummarySvc
Definition: GaudiCommon.h:131
IMessageSvc.h
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
IUpdateManagerSvc
Interface class to the Update Manager service.
Definition: IUpdateManagerSvc.h:144
GaudiCommon::runUpdate
StatusCode runUpdate()
asks the UpdateManagerSvc to perform an update of the instance (if needed) without waiting the next B...
Definition: GaudiCommon.h:618
std::exception
STL class.
WARN_UNUSED
#define WARN_UNUSED
Definition: GaudiCommon.h:37
GaudiCommon::typePrint
bool typePrint() const
Insert the actual C++ type of the algorithm/tool in the messages ?
Definition: GaudiCommon.h:501
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:59
IAlgContextSvc.h
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
std::vector< IAlgTool * >
GaudiCommon::registerCondition
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:576
GaudiCommon_details::svc_lt_t
Definition: GaudiCommon.h:61
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:48
StatEntity.h
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
gaudirun.s
string s
Definition: gaudirun.py:253
GaudiCommon
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:89
gaudirun.level
level
Definition: gaudirun.py:271
GaudiCommon::m_managedTools
AlgTools m_managedTools
List of active tools.
Definition: GaudiCommon.h:737
IChronoStatSvc.h
GaudiCommon_details::svc_eq_t
Definition: GaudiCommon.h:56
StatusCode.h
StatusCode::FAILURE
Definition: StatusCode.h:29
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:58
GaudiCommon::GaudiCommon
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:631
StatEntity
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:65
MSG::INFO
Definition: IMessageSvc.h:16
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
MSG::ALWAYS
Definition: IMessageSvc.h:16
Gaudi::Functional::details::put
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Definition: FunctionalDetails.h:115
DataObjectHandle.h