| The Gaudi Framework v32r1 (f65d50dc)

GaudiTool.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_GAUDITOOL_H
2 #define GAUDIALG_GAUDITOOL_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // GaudiKernel
7 // ============================================================================
8 #include "GaudiKernel/AlgTool.h"
9 #include "GaudiKernel/CounterHolder.h"
10 #include "GaudiKernel/DataObject.h"
11 // ============================================================================
12 // GaudiAlg
13 // ============================================================================
14 #include "GaudiAlg/GaudiAlg.h"
15 #include "GaudiAlg/GaudiCommon.h"
16 #include "GaudiKernel/DataObjectHandle.h"
17 // ============================================================================
18 // forward declarations
19 // ============================================================================
20 class IDataProviderSvc;
21 class IChronoStatSvc;
22 class IIncidentSvc;
23 class IHistogramSvc;
24 class GaudiException;
25 class INTupleSvc;
26 class IAlgContextSvc;
27 namespace std {
28 class exception;
29 }
30 // ============================================================================
66 // ============================================================================
100 // ============================================================================
101 class GAUDI_API GaudiTool : public GaudiCommon<CounterHolder<AlgTool>> {
102 public:
103 // ==========================================================================
109 StatusCode initialize() override;
115 StatusCode finalize() override;
116 // ==========================================================================
117 public: // accessors
118 // ==========================================================================
122 INTupleSvc* ntupleSvc() const;
126 INTupleSvc* evtColSvc() const;
130 IDataProviderSvc* detSvc() const;
131
135 IIncidentSvc* incSvc() const;
139 IChronoStatSvc* chronoSvc() const;
143 IHistogramSvc* histoSvc() const;
147 IAlgContextSvc* contextSvc() const;
148 // ==========================================================================
149 public:
150 // ==========================================================================
151 // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
152 // and detSvc() ) that are not members of AlgTool.
153 // Also some methods seem which are members of the base class do not seem
154 // to be found unless forwarding methods are put here ??
155 // ==========================================================================
156
187 // [[deprecated( "please pass a std::unique_ptr as 2nd argument" )]]
188 void put( IDataProviderSvc* svc, DataObject* object, const std::string& address,
189 const bool useRootInTES = true ) const {
190 put( svc, std::unique_ptr<DataObject>( object ), address, useRootInTES );
191 }
192 void put( IDataProviderSvc* svc, std::unique_ptr<DataObject> object, const std::string& address,
193 const bool useRootInTES = true ) const {
194 GaudiCommon<CounterHolder<AlgTool>>::put( svc, std::move( object ), address, useRootInTES );
195 }
196
225 const DataObject* put( DataObject* object, const std::string& address, const bool useRootInTES = true ) const {
226 return put( std::unique_ptr<DataObject>( object ), address, useRootInTES );
227 }
228 const DataObject* put( std::unique_ptr<DataObject> object, const std::string& address,
229 const bool useRootInTES = true ) const {
230 return GaudiCommon<CounterHolder<AlgTool>>::put( evtSvc(), std::move( object ), address, useRootInTES );
231 }
232
264 template <class TYPE>
265 typename Gaudi::Utils::GetData<TYPE>::return_type get( IDataProviderSvc* svc, const std::string& location,
266 const bool useRootInTES = true ) const {
267 return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( svc, location, useRootInTES );
268 }
269
303 template <class TYPE>
304 typename Gaudi::Utils::GetData<TYPE>::return_type getIfExists( IDataProviderSvc* svc, const std::string& location,
305 const bool useRootInTES = true ) const {
306 return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( svc, location, useRootInTES );
307 }
308
334 template <class TYPE>
335 typename Gaudi::Utils::GetData<TYPE>::return_type get( const std::string& location,
336 const bool useRootInTES = true ) const {
337 return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( evtSvc(), location, useRootInTES );
338 }
339
372 template <class TYPE>
373 typename Gaudi::Utils::GetData<TYPE>::return_type getIfExists( const std::string& location,
374 const bool useRootInTES = true ) const {
375 return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( evtSvc(), location, useRootInTES );
376 }
377
396 template <class TYPE>
397 TYPE* getDet( IDataProviderSvc* svc, const std::string& location ) const {
398 return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( svc, location, false );
399 }
400
423 template <class TYPE>
424 typename Gaudi::Utils::GetData<TYPE>::return_type getDetIfExists( IDataProviderSvc* svc,
425 const std::string& location ) const {
426 return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( svc, location, false );
427 }
428
446 template <class TYPE>
447 TYPE* getDet( const std::string& location ) const {
448 return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( detSvc(), location, false );
449 }
450
472 template <class TYPE>
473 typename Gaudi::Utils::GetData<TYPE>::return_type getDetIfExists( const std::string& location ) const {
474 return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( detSvc(), location, false );
475 }
476
502 template <class TYPE>
503 bool exist( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const {
504 return GaudiCommon<CounterHolder<AlgTool>>::exist<TYPE>( svc, location, useRootInTES );
505 }
506
529 template <class TYPE>
530 bool exist( const std::string& location, const bool useRootInTES = true ) const {
531 return GaudiCommon<CounterHolder<AlgTool>>::exist<TYPE>( evtSvc(), location, useRootInTES );
532 }
533
550 template <class TYPE>
551 bool existDet( IDataProviderSvc* svc, const std::string& location ) const {
552 return GaudiCommon<CounterHolder<AlgTool>>::exist<TYPE>( svc, location, false );
553 }
554
570 template <class TYPE>
571 bool existDet( const std::string& location ) const {
572 return GaudiCommon<CounterHolder<AlgTool>>::exist<TYPE>( detSvc(), location, false );
573 }
574
601 template <class TYPE, class TYPE2>
602 typename Gaudi::Utils::GetData<TYPE>::return_type getOrCreate( IDataProviderSvc* svc, const std::string& location,
603 const bool useRootInTES = true ) const {
604 return GaudiCommon<CounterHolder<AlgTool>>::getOrCreate<TYPE, TYPE2>( svc, location, useRootInTES );
605 }
606
632 template <class TYPE, class TYPE2>
633 typename Gaudi::Utils::GetData<TYPE>::return_type getOrCreate( const std::string& location,
634 const bool useRootInTES = true ) const {
635 return GaudiCommon<CounterHolder<AlgTool>>::getOrCreate<TYPE, TYPE2>( evtSvc(), location, useRootInTES );
636 }
637 // ==========================================================================
638 public:
639 // ==========================================================================
663 StatusCode Error( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const {
664 return GaudiCommon<CounterHolder<AlgTool>>::Error( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
665 }
689 StatusCode Warning( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const {
690 return GaudiCommon<CounterHolder<AlgTool>>::Warning( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
691 }
707 StatusCode Info( const std::string& msg, const StatusCode st = StatusCode::SUCCESS, const size_t mx = 10 ) const {
708 return GaudiCommon<CounterHolder<AlgTool>>::Info( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
709 }
710 // ==========================================================================
711 public:
712 // ==========================================================================
714 static bool enableSummary( bool );
716 static bool summaryEnabled();
717
718 // ==========================================================================
725 GaudiTool( const std::string& type, const std::string& name, const IInterface* parent );
726
728 ~GaudiTool() override;
729 // ==========================================================================
730 private:
731 // ==========================================================================
733 GaudiTool() = delete;
734 GaudiTool( const GaudiTool& ) = delete;
735 GaudiTool& operator=( const GaudiTool& ) = delete;
736 // ==========================================================================
737 private:
738 // ==========================================================================
740 bool isPublic() const;
742 std::string getCurrentAlgName() const {
743 const IAlgContextSvc* asvc = this->contextSvc();
744 const IAlgorithm* current = ( asvc ? asvc->currentAlg() : NULL );
745 return ( current ? " [" + current->name() + "]" : "" );
746 }
747 // ==========================================================================
748 private:
749 // ==========================================================================
751 mutable SmartIF<INTupleSvc> m_ntupleSvc;
753 mutable SmartIF<INTupleSvc> m_evtColSvc;
755 mutable SmartIF<IDataProviderSvc> m_detSvc;
757 mutable SmartIF<IChronoStatSvc> m_chronoSvc;
759 mutable SmartIF<IIncidentSvc> m_incSvc;
761 mutable SmartIF<IHistogramSvc> m_histoSvc;
762 // Pointer to the Algorithm Context Service
763 mutable SmartIF<IAlgContextSvc> m_contextSvc;
764
765 Gaudi::Property<std::string> m_contextSvcName{this, "ContextService", "AlgContextSvc",
766 "the name of Algorithm Context Service"};
767 // ==========================================================================
768 private:
769 // ==========================================================================
771 bool m_isPublic = false;
772 // ==========================================================================
773 private:
774 // ==========================================================================
776 const std::string m_local;
777 // ==========================================================================
778 private:
779 // ==========================================================================
781 static bool s_enableSummary;
782 // ==========================================================================
783 };
784 // ============================================================================
785
786 // ============================================================================
787 // The END
788 // ============================================================================
789 #endif // GAUDIALG_GAUDITOOL_H
GaudiTool::put
const DataObject * put(std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:228
GaudiTool::Error
StatusCode Error(const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the error message and return with the given StatusCode.
Definition: GaudiTool.h:663
SmartIF< INTupleSvc >
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
GaudiTool::m_ntupleSvc
SmartIF< INTupleSvc > m_ntupleSvc
pointer to the N-Tuple service
Definition: GaudiTool.h:751
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
GaudiTool::getDet
TYPE * getDet(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:397
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
AlgTool.h
GaudiTool::getOrCreate
Gaudi::Utils::GetData< TYPE >::return_type getOrCreate(const std::string &location, const bool useRootInTES=true) const
Get the existing data object from Gaudi Event Transient store.
Definition: GaudiTool.h:633
GaudiPython.HistoUtils.location
location
Definition: HistoUtils.py:936
GaudiCommon::Error
WARN_UNUSED StatusCode Error(const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the error message and return with the given StatusCode.
Definition: GaudiCommon.icpp:286
GaudiTool::getDetIfExists
Gaudi::Utils::GetData< TYPE >::return_type getDetIfExists(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:424
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Gaudi::Utils::GetData
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:53
GaudiTool::m_contextSvc
SmartIF< IAlgContextSvc > m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:763
std
STL namespace.
GaudiTool::existDet
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:571
GaudiCommon::put
DataObject * put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, const std::string &location, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
Definition: GaudiCommon.icpp:486
GaudiTool::exist
bool exist(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Check the existence of a data object or container in the Gaudi Transient Event Store.
Definition: GaudiTool.h:503
GaudiCommon::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiCommon.icpp:131
GaudiTool::put
void put(IDataProviderSvc *svc, DataObject *object, const std::string &address, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
Definition: GaudiTool.h:188
GaudiTool::m_incSvc
SmartIF< IIncidentSvc > m_incSvc
pointer to Incident Service
Definition: GaudiTool.h:759
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:43
GaudiTool::Info
StatusCode Info(const std::string &msg, const StatusCode st=StatusCode::SUCCESS, const size_t mx=10) const
Print the info message and return with the given StatusCode.
Definition: GaudiTool.h:707
GaudiCommon.h
std::string
STL class.
CounterHolder.h
INTupleSvc
Definition: INTupleSvc.h:36
IChronoStatSvc
The IChronoStatSvc is the interface implemented by the ChronoStatService.
Definition: IChronoStatSvc.h:33
GaudiTool::getIfExists
Gaudi::Utils::GetData< TYPE >::return_type getIfExists(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiTool.h:304
GaudiTool::Warning
StatusCode Warning(const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the warning message and return with the given StatusCode.
Definition: GaudiTool.h:689
GaudiTool::get
Gaudi::Utils::GetData< TYPE >::return_type get(const std::string &location, const bool useRootInTES=true) const
Templated access to the data from Gaudi Event Transient Store.
Definition: GaudiTool.h:335
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IInterface
Definition of the basic interface.
Definition: IInterface.h:244
gaudirun.type
type
Definition: gaudirun.py:142
GaudiTool::get
Gaudi::Utils::GetData< TYPE >::return_type get(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiTool.h:265
IHistogramSvc
Definition of the IHistogramSvc interface class.
Definition: IHistogramSvc.h:46
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
std::move
T move(T... args)
GaudiTool::getIfExists
Gaudi::Utils::GetData< TYPE >::return_type getIfExists(const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiTool.h:373
GaudiAlg.h
GaudiCommon::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiCommon.icpp:95
GaudiTool::s_enableSummary
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:781
std::unique_ptr
STL class.
GaudiCommon::operator=
GaudiCommon & operator=(const GaudiCommon &)=delete
GaudiCommon::Info
WARN_UNUSED StatusCode Info(const std::string &msg, const StatusCode st=StatusCode::SUCCESS, const size_t mx=10) const
Print the info message and return with the given StatusCode.
Definition: GaudiCommon.icpp:324
GaudiTool::m_chronoSvc
SmartIF< IChronoStatSvc > m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:757
GaudiTool::m_histoSvc
SmartIF< IHistogramSvc > m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:761
GaudiTool::put
void put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:192
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
GaudiTool::getDetIfExists
Gaudi::Utils::GetData< TYPE >::return_type getDetIfExists(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:473
GaudiTool::m_detSvc
SmartIF< IDataProviderSvc > m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:755
GaudiTool::getOrCreate
Gaudi::Utils::GetData< TYPE >::return_type getOrCreate(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Get the existing data object from Gaudi Event Transient store.
Definition: GaudiTool.h:602
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
GaudiTool
The useful base class for tools.
Definition: GaudiTool.h:101
GaudiCommon
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:91
IAlgContextSvc
An abstract interface for Algorithm Context Service.
Definition: IAlgContextSvc.h:23
GaudiTool::getDet
TYPE * getDet(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:447
GaudiTool::put
const DataObject * put(DataObject *object, const std::string &address, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
Definition: GaudiTool.h:225
GaudiTool::m_local
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:776
GaudiTool::m_evtColSvc
SmartIF< INTupleSvc > m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:753
GaudiTool::existDet
bool existDet(IDataProviderSvc *svc, const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:551
GaudiTool::exist
bool exist(const std::string &location, const bool useRootInTES=true) const
Check the existence of a data object or container in the Gaudi Transient Event Store.
Definition: GaudiTool.h:530
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
IAlgContextSvc::currentAlg
virtual IAlgorithm * currentAlg() const =0
accessor to current algorithm:
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
GaudiTool::getCurrentAlgName
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:742
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
DataObject.h
GaudiCommon::Warning
WARN_UNUSED StatusCode Warning(const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the warning message and return with the given StatusCode.
Definition: GaudiCommon.icpp:305
DataObjectHandle.h