| The Gaudi Framework v29r1 (5cd95fa2)

- 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 // 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
45 namespace GaudiCommon_details
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 // ==========================================================================
111 typedef std::map<std::string, StatEntity> Statistics;
113 typedef std::map<std::string, unsigned int> Counter;
115 typedef std::vector<IAlgTool*> AlgTools;
117 typedef std::vector<SmartIF<IService>> Services;
118
119 // ==========================================================================
120 // protected members such that they can be used in the derived classes
122 SmartIF<ICounterSummarySvc> m_counterSummarySvc;
123
124 public:
125 // ==========================================================================
159 template <class TYPE>
160 typename Gaudi::Utils::GetData<TYPE>::return_type get( IDataProviderSvc* svc, const std::string& location,
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"};
755 Gaudi::Property<std::string> m_format1{
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"};
758 Gaudi::Property<std::string> m_format2{
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
765 Gaudi::Property<std::vector<std::string>> m_counterList{
766 this, "CounterList", {".*"}, "RegEx list, of simple integer counters for CounterSummary"};
767 Gaudi::Property<std::vector<std::string>> m_statEntityList{
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 // ============================================================================
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:54
System.h
GaudiCommon_details
Definition: GaudiCommon.h:45
GaudiCommon::Statistics
std::map< std::string, StatEntity > Statistics
the actual type of general counters
Definition: GaudiCommon.h:111
GaudiCommon::m_warnings
Counter m_warnings
counter of warnings
Definition: GaudiCommon.h:731
StatusCode::SUCCESS
Definition: StatusCode.h:31
SmartIF< IService >
GaudiCommon_details::svc_lt_t::operator()
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:53
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:735
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::FAILURE
Definition: StatusCode.h:31
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:708
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:611
GaudiCommon::AlgTools
std::vector< IAlgTool * > AlgTools
storage for active tools
Definition: GaudiCommon.h:115
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:590
GaudiCommon::Counter
std::map< std::string, unsigned int > Counter
the actual type error/warning counter
Definition: GaudiCommon.h:113
GaudiCommon::m_services
Services m_services
List of active services.
Definition: GaudiCommon.h:726
GaudiCommon_details::svc_lt_t::operator()
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:55
GaudiPython.HistoUtils.location
location
Definition: HistoUtils.py:899
IUpdateManagerSvc.h
GaudiCommon::m_counters
Statistics m_counters
General counters.
Definition: GaudiCommon.h:737
Gaudi::Utils::GetData
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:41
ICounterSummarySvc.h
GaudiCommon::context
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:704
GaudiCommon::counters
const Statistics & counters() const
accessor to all counters
Definition: GaudiCommon.h:465
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:48
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:570
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
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:528
IToolSvc.h
std::map< std::string, StatEntity >
GaudiCommon::services
const Services & services() const
get the list of aquired services
Definition: GaudiCommon.h:690
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:492
GaudiCommon::counter
StatEntity & counter(const std::string &tag) const
accessor to certain counter by name
Definition: GaudiCommon.h:484
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:729
SmartDataPtr.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
GaudiCommon::propsPrint
bool propsPrint() const
Print properties at initialization ?
Definition: GaudiCommon.h:490
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:733
IAlgTool.h
GaudiCommon::errorsPrint
bool errorsPrint() const
Print error counters at finalization ?
Definition: GaudiCommon.h:494
GaudiCommon::Services
std::vector< SmartIF< IService > > Services
storage for active services
Definition: GaudiCommon.h:117
GaudiCommon::m_counterSummarySvc
SmartIF< ICounterSummarySvc > m_counterSummarySvc
a pointer to the CounterSummarySvc
Definition: GaudiCommon.h:122
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:605
std::exception
STL class.
GaudiCommon::typePrint
bool typePrint() const
Insert the actual C++ type of the algorithm/tool in the messages ?
Definition: GaudiCommon.h:488
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:50
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:563
GaudiCommon_details::svc_lt_t
Definition: GaudiCommon.h:52
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:80
gaudirun.level
level
Definition: gaudirun.py:271
GaudiCommon::m_managedTools
AlgTools m_managedTools
List of active tools.
Definition: GaudiCommon.h:724
IChronoStatSvc.h
GaudiCommon_details::svc_eq_t
Definition: GaudiCommon.h:47
StatusCode.h
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:49
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:618
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:29
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:116
DataObjectHandle.h