| The Gaudi Framework v27r1

- 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 <string>
9 #include <vector>
10 #include <map>
11 #include <algorithm>
12 // ============================================================================
13 // GaudiKernel
14 // ============================================================================
15 #include "GaudiKernel/StatusCode.h"
16 #include "GaudiKernel/IMessageSvc.h"
17 #include "GaudiKernel/IToolSvc.h"
18 #include "GaudiKernel/IAlgTool.h"
19 #include "GaudiKernel/IAlgContextSvc.h"
20 #include "GaudiKernel/IDataProviderSvc.h"
21 #include "GaudiKernel/IAlgorithm.h"
22 #include "GaudiKernel/SmartDataPtr.h"
23 #include "GaudiKernel/System.h"
24 #include "GaudiKernel/GaudiException.h"
25 #include "GaudiKernel/IChronoStatSvc.h"
26 #include "GaudiKernel/StatEntity.h"
27 #include "GaudiKernel/ICounterSummarySvc.h"
28 #include "GaudiKernel/IUpdateManagerSvc.h"
29 #include "GaudiKernel/HashMap.h"
30 #include "GaudiKernel/DataObjectHandle.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
38 namespace GaudiCommon_details {
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 // ==========================================================================
104 typedef std::map<std::string,StatEntity> Statistics ;
106 typedef std::map<std::string,unsigned int> Counter ;
108 typedef std::vector<IAlgTool*> AlgTools ;
110 typedef std::vector<SmartIF<IService>> Services;
111
112 // ==========================================================================
113 //protected members such that they can be used in the derived classes
115 SmartIF<ICounterSummarySvc> m_counterSummarySvc ;
117 std::vector<std::string> m_counterList = std::vector<std::string>(1,".*");
118 //list of stat entities to write. Set by property StatEntityList. This can be a regular expression.
119 std::vector<std::string> m_statEntityList = std::vector<std::string>(0);
120 public:
121 // ==========================================================================
155 template < class TYPE >
156 typename Gaudi::Utils::GetData<TYPE>::return_type
157 get ( IDataProviderSvc* svc ,
158 const std::string& location ,
159 const bool useRootInTES = true ) const ;
163 template < class TYPE >
164 typename Gaudi::Utils::GetData<TYPE>::return_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 >
226 typename Gaudi::Utils::GetData<TYPE>::return_type
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 // ==========================================================================
762 std::string m_context;
764 std::string m_rootInTES;
765 // ==========================================================================
766 // the header row
767 std::string m_header ;
768 // format for regular statistical printout rows
769 std::string m_format1 ;
770 // format for "efficiency" statistical printout rows
771 std::string m_format2 ;
772 // flag to use the special "efficiency" format
773 bool m_useEffFormat ;
774 } ;
775 // ============================================================================
776 #include "GaudiAlg/GaudiCommonImp.h"
777 // ============================================================================
778
779 // ============================================================================
780 // The END
781 // ============================================================================
782 #endif // GAUDIALG_GAUDICOMMON_H
783 // ============================================================================
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:46
System.h
GaudiCommon_details
Definition: GaudiCommon.h:38
GaudiCommon::m_warnings
Counter m_warnings
counter of warnings
Definition: GaudiCommon.h:741
SmartIF< IService >
GaudiCommon_details::svc_lt_t::operator()
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:45
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
AnalysisTest.initialize
def initialize()
Definition: AnalysisTest.py:12
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:745
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
GaudiCommon::Counter
std::map< std::string, unsigned int > Counter
the actual type error/warning counter
Definition: GaudiCommon.h:106
GaudiCommon::rootInTES
const std::string & rootInTES() const
Returns the "rootInTES" string.
Definition: GaudiCommon.h:716
GaudiMP.FdsRegistry.msg
tuple msg
Definition: FdsRegistry.py:8
GaudiCommon::AlgTools
std::vector< IAlgTool * > AlgTools
storage for active tools
Definition: GaudiCommon.h:108
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:616
GaudiCommon::m_services
Services m_services
List of active services.
Definition: GaudiCommon.h:736
GaudiCommon_details::svc_lt_t::operator()
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:47
IUpdateManagerSvc.h
GaudiCommon::m_counters
Statistics m_counters
General counters.
Definition: GaudiCommon.h:747
Gaudi::Utils::GetData
Helper structure for implementation of "get"-functions for GaudiCommon
Definition: GaudiCommon.h:36
ICounterSummarySvc.h
GaudiCommon::context
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:712
GaudiCommon::counters
const Statistics & counters() const
accessor to all counters
Definition: GaudiCommon.h:494
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const std::string &n, const SmartIF< IService > &s) const
Definition: GaudiCommon.h:40
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:597
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
HashMap.h
merge_files.sc
int sc
Definition: merge_files.py:167
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:557
IToolSvc.h
std::map< std::string, StatEntity >
GaudiCommon::services
const Services & services() const
get the list of aquired services
Definition: GaudiCommon.h:698
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
std::string
STL class.
MSG::Level
Level
Definition: IMessageSvc.h:15
GaudiCommon::statPrint
bool statPrint() const
Print statistical counters at finalization ?
Definition: GaudiCommon.h:521
GaudiCommon::m_useEffFormat
bool m_useEffFormat
flag to use the special "efficiency" format
Definition: GaudiCommon.h:773
GaudiCommon::counter
StatEntity & counter(const std::string &tag) const
accessor to certain counter by name
Definition: GaudiCommon.h:513
IDataProviderSvc.h
GaudiCommon_details::svc_lt
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
GaudiCommon::Statistics
std::map< std::string, StatEntity > Statistics
the actual type of general counters
Definition: GaudiCommon.h:104
GaudiCommon::m_errors
Counter m_errors
Counter of errors.
Definition: GaudiCommon.h:739
SmartDataPtr.h
gaudirun.type
string type
Definition: gaudirun.py:151
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
GaudiCommon::m_format1
std::string m_format1
format for regular statistical printout rows
Definition: GaudiCommon.h:769
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiCommon::m_rootInTES
std::string m_rootInTES
The rootInTES string.
Definition: GaudiCommon.h:764
GaudiCommon::propsPrint
bool propsPrint() const
Print properties at initialization ?
Definition: GaudiCommon.h:519
GaudiException.h
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
GaudiCommon::m_infos
Counter m_infos
counter of infos
Definition: GaudiCommon.h:743
IAlgTool.h
GaudiCommon::errorsPrint
bool errorsPrint() const
Print error counters at finalization ?
Definition: GaudiCommon.h:523
GaudiCommon::Services
std::vector< SmartIF< IService > > Services
storage for active services
Definition: GaudiCommon.h:110
GaudiCommon::m_counterSummarySvc
SmartIF< ICounterSummarySvc > m_counterSummarySvc
a pointer to the CounterSummarySvc
Definition: GaudiCommon.h:115
IMessageSvc.h
IUpdateManagerSvc
Interface class to the Update Manager service.
Definition: IUpdateManagerSvc.h:143
GaudiCommon::runUpdate
StatusCode runUpdate()
asks the UpdateManagerSvc to perform an update of the instance (if needed) without waiting the next B...
Definition: GaudiCommon.h:630
std::exception
STL class.
GaudiCommon::m_header
std::string m_header
the header row
Definition: GaudiCommon.h:767
GaudiCommon::typePrint
bool typePrint() const
Insert the actual C++ type of the algorithm/tool in the messages ?
Definition: GaudiCommon.h:517
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const SmartIF< IService > &s, const SmartIF< IService > &n) const
Definition: GaudiCommon.h:42
IAlgContextSvc.h
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
GaudiCommon::m_format2
std::string m_format2
format for "efficiency" statistical printout rows
Definition: GaudiCommon.h:771
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:591
GaudiCommon_details::svc_lt_t
Definition: GaudiCommon.h:44
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:45
StatEntity.h
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
gaudirun.s
string s
Definition: gaudirun.py:245
GaudiCommon
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:73
gaudirun.level
level
Definition: gaudirun.py:261
GaudiCommon::m_managedTools
AlgTools m_managedTools
List of active tools.
Definition: GaudiCommon.h:734
IChronoStatSvc.h
GaudiCommon_details::svc_eq_t
Definition: GaudiCommon.h:39
StatusCode.h
GaudiCommon_details::svc_eq_t::operator()
bool operator()(const SmartIF< IService > &s, const std::string &n) const
Definition: GaudiCommon.h:41
StatEntity
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:64
GaudiCommon::m_context
std::string m_context
The context string.
Definition: GaudiCommon.h:762
MSG::INFO
Definition: IMessageSvc.h:19
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
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:23
DataObjectHandle.h