The Gaudi Framework  v29r0 (ff2e7097)
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"
10 // ============================================================================
11 // GaudiAlg
12 // ============================================================================
13 #include "GaudiAlg/GaudiAlg.h"
14 #include "GaudiAlg/GaudiCommon.h"
16 // ============================================================================
17 // forward declarations
18 // ============================================================================
19 class IDataProviderSvc;
20 class IChronoStatSvc;
21 class IIncidentSvc;
22 class IHistogramSvc;
23 class GaudiException;
24 class INTupleSvc;
25 class IAlgContextSvc;
26 namespace std
27 {
28  class exception;
29 }
30 // ============================================================================
66 // ============================================================================
100 // ============================================================================
101 class GAUDI_API GaudiTool : public GaudiCommon<AlgTool>
102 {
103 public:
104  // ==========================================================================
110  StatusCode initialize() override;
116  StatusCode finalize() override;
117  // ==========================================================================
118 public: // accessors
119  // ==========================================================================
123  INTupleSvc* ntupleSvc() const;
127  INTupleSvc* evtColSvc() const;
131  IDataProviderSvc* detSvc() const;
132 
136  IIncidentSvc* incSvc() const;
140  IChronoStatSvc* chronoSvc() const;
144  IHistogramSvc* histoSvc() const;
148  IAlgContextSvc* contextSvc() const;
149  // ==========================================================================
150 public:
151  // ==========================================================================
152  // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
153  // and detSvc() ) that are not members of AlgTool.
154  // Also some methods seem which are members of the base class do not seem
155  // to be found unless forwarding methods are put here ??
156  // ==========================================================================
157 
188  inline DataObject* put( IDataProviderSvc* svc, DataObject* object, const std::string& address,
189  const bool useRootInTES = true ) const
190  {
191  return GaudiCommon<AlgTool>::put( svc, object, address, useRootInTES );
192  }
193 
222  inline DataObject* put( DataObject* object, const std::string& address, const bool useRootInTES = true ) const
223  {
224  return GaudiCommon<AlgTool>::put( evtSvc(), object, address, useRootInTES );
225  }
226 
258  template <class TYPE>
260  const bool useRootInTES = true ) const
261  {
262  return GaudiCommon<AlgTool>::get<TYPE>( svc, location, useRootInTES );
263  }
264 
298  template <class TYPE>
300  getIfExists( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const
301  {
302  return GaudiCommon<AlgTool>::getIfExists<TYPE>( svc, location, useRootInTES );
303  }
304 
330  template <class TYPE>
332  const bool useRootInTES = true ) const
333  {
334  return GaudiCommon<AlgTool>::get<TYPE>( evtSvc(), location, useRootInTES );
335  }
336 
369  template <class TYPE>
371  const bool useRootInTES = true ) const
372  {
373  return GaudiCommon<AlgTool>::getIfExists<TYPE>( evtSvc(), location, useRootInTES );
374  }
375 
394  template <class TYPE>
395  inline TYPE* getDet( IDataProviderSvc* svc, const std::string& location ) const
396  {
397  return GaudiCommon<AlgTool>::get<TYPE>( svc, location, false );
398  }
399 
422  template <class TYPE>
424  const std::string& location ) const
425  {
426  return GaudiCommon<AlgTool>::getIfExists<TYPE>( svc, location, false );
427  }
428 
446  template <class TYPE>
447  inline TYPE* getDet( const std::string& location ) const
448  {
449  return GaudiCommon<AlgTool>::get<TYPE>( detSvc(), location, false );
450  }
451 
473  template <class TYPE>
474  inline typename Gaudi::Utils::GetData<TYPE>::return_type getDetIfExists( const std::string& location ) const
475  {
476  return GaudiCommon<AlgTool>::getIfExists<TYPE>( detSvc(), location, false );
477  }
478 
504  template <class TYPE>
505  inline bool exist( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const
506  {
507  return GaudiCommon<AlgTool>::exist<TYPE>( svc, location, useRootInTES );
508  }
509 
532  template <class TYPE>
533  inline bool exist( const std::string& location, const bool useRootInTES = true ) const
534  {
535  return GaudiCommon<AlgTool>::exist<TYPE>( evtSvc(), location, useRootInTES );
536  }
537 
554  template <class TYPE>
555  inline bool existDet( IDataProviderSvc* svc, const std::string& location ) const
556  {
557  return GaudiCommon<AlgTool>::exist<TYPE>( svc, location, false );
558  }
559 
575  template <class TYPE>
576  inline bool existDet( const std::string& location ) const
577  {
578  return GaudiCommon<AlgTool>::exist<TYPE>( detSvc(), location, false );
579  }
580 
607  template <class TYPE, class TYPE2>
609  getOrCreate( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const
610  {
611  return GaudiCommon<AlgTool>::getOrCreate<TYPE, TYPE2>( svc, location, useRootInTES );
612  }
613 
639  template <class TYPE, class TYPE2>
641  const bool useRootInTES = true ) const
642  {
643  return GaudiCommon<AlgTool>::getOrCreate<TYPE, TYPE2>( evtSvc(), location, useRootInTES );
644  }
645  // ==========================================================================
646 public:
647  // ==========================================================================
672  const size_t mx = 10 ) const
673  {
674  return GaudiCommon<AlgTool>::Error( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
675  }
700  const size_t mx = 10 ) const
701  {
702  return GaudiCommon<AlgTool>::Warning( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
703  }
720  const size_t mx = 10 ) const
721  {
722  return GaudiCommon<AlgTool>::Info( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
723  }
724  // ==========================================================================
725 public:
726  // ==========================================================================
728  static bool enableSummary( bool );
730  static bool summaryEnabled();
731 
732  // ==========================================================================
739  GaudiTool( const std::string& type, const std::string& name, const IInterface* parent );
740 
742  ~GaudiTool() override;
743  // ==========================================================================
744 private:
745  // ==========================================================================
747  GaudiTool() = delete;
748  GaudiTool( const GaudiTool& ) = delete;
749  GaudiTool& operator=( const GaudiTool& ) = delete;
750  // ==========================================================================
751 private:
752  // ==========================================================================
754  bool isPublic() const;
757  {
758  const IAlgContextSvc* asvc = this->contextSvc();
759  const IAlgorithm* current = ( asvc ? asvc->currentAlg() : NULL );
760  return ( current ? " [" + current->name() + "]" : "" );
761  }
762  // ==========================================================================
763 private:
764  // ==========================================================================
777  // Pointer to the Algorithm Context Service
779 
780  Gaudi::Property<std::string> m_contextSvcName{this, "ContextService", "AlgContextSvc",
781  "the name of Algorithm Context Service"};
782  // ==========================================================================
783 private:
784  // ==========================================================================
786  bool m_isPublic = false;
787  // ==========================================================================
788 private:
789  // ==========================================================================
792  // ==========================================================================
793 private:
794  // ==========================================================================
796  static bool s_enableSummary;
797  // ==========================================================================
798 };
799 // ============================================================================
800 
801 // ============================================================================
802 // The END
803 // ============================================================================
804 #endif // GAUDIALG_GAUDITOOL_H
805 // ============================================================================
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:699
virtual IAlgorithm * currentAlg() const =0
accessor to current algorithm:
Define general base for Gaudi exception.
SmartIF< INTupleSvc > m_ntupleSvc
pointer to the N-Tuple service
Definition: GaudiTool.h:766
DataObject * put(IDataProviderSvc *svc, DataObject *object, const std::string &location, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
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:423
Implementation of property with value of concrete type.
Definition: Property.h:319
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.
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:41
SmartIF< IAlgContextSvc > m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:778
STL namespace.
TYPE * getDet(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:447
SmartIF< IIncidentSvc > m_incSvc
pointer to Incident Service
Definition: GaudiTool.h:774
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:756
Data provider interface definition.
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:719
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
The IChronoStatSvc is the interface implemented by the ChronoStatService.
bool existDet(IDataProviderSvc *svc, const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:555
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:370
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:505
TYPE * getDet(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:395
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
Definition of the basic interface.
Definition: IInterface.h:277
DataObject * 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
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.
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:640
Definition of the IHistogramSvc interface class.
Definition: IHistogramSvc.h:47
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:609
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:576
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
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:300
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:474
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:796
SmartIF< IChronoStatSvc > m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:772
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:671
SmartIF< IHistogramSvc > m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:776
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:222
SmartIF< IDataProviderSvc > m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:770
The useful base class for tools.
Definition: GaudiTool.h:101
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:80
An abstract interface for Algorithm Context Service.
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.
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:791
SmartIF< INTupleSvc > m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:768
#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
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:533
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23