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 { class exception ; }
27 // ============================================================================
63 // ============================================================================
97 // ============================================================================
98 class GAUDI_API GaudiTool: public GaudiCommon<AlgTool>
99 {
100  public:
101  // ==========================================================================
107  StatusCode initialize () override;
113  StatusCode finalize () override;
114  // ==========================================================================
115  public: // accessors
116  // ==========================================================================
120  INTupleSvc* ntupleSvc () const;
124  INTupleSvc* evtColSvc () const;
128  IDataProviderSvc* detSvc () const ;
129 
133  IIncidentSvc* incSvc () const ;
137  IChronoStatSvc* chronoSvc () const ;
141  IHistogramSvc* histoSvc () const ;
145  IAlgContextSvc* contextSvc () const ;
146  // ==========================================================================
147  public:
148  // ==========================================================================
149  // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
150  // and detDvc() ) that are not members of AlgTool.
151  // Also some methods seem which are members of the base class do not seem
152  // to be found unless forwarding methods are put here ??
153  // ==========================================================================
154 
185  inline DataObject* put ( IDataProviderSvc* svc ,
186  DataObject* object ,
187  const std::string& address ,
188  const bool useRootInTES = true ) const
189  {
190  return GaudiCommon<AlgTool>::put ( svc , object , address , useRootInTES ) ;
191  }
192 
221  inline DataObject* put ( DataObject* object ,
222  const std::string& address ,
223  const bool useRootInTES = true ) const
224  {
225  return GaudiCommon<AlgTool>::put ( evtSvc() , object , address , useRootInTES ) ;
226  }
227 
259  template < class TYPE >
262  const std::string& location ,
263  const bool useRootInTES = true ) const
264  {
265  return GaudiCommon<AlgTool>::get<TYPE> ( svc , location , useRootInTES ) ;
266  }
267 
301  template < class TYPE >
304  const std::string& location ,
305  const bool useRootInTES = true ) const
306  {
307  return GaudiCommon<AlgTool>::getIfExists<TYPE> ( svc , location , useRootInTES ) ;
308  }
309 
335  template < class TYPE >
337  get ( const std::string& location ,
338  const bool useRootInTES = true ) const
339  {
340  return GaudiCommon<AlgTool>::get<TYPE> ( evtSvc() , location , useRootInTES ) ;
341  }
342 
375  template < class TYPE >
377  getIfExists ( const std::string& location ,
378  const bool useRootInTES = true ) const
379  {
380  return GaudiCommon<AlgTool>::getIfExists<TYPE> ( evtSvc() , location , useRootInTES ) ;
381  }
382 
401  template < class TYPE >
402  inline TYPE* getDet ( IDataProviderSvc* svc ,
403  const std::string& location ) const
404  {
405  return GaudiCommon<AlgTool>::get<TYPE> ( svc , location , false ) ;
406  }
407 
430  template < class TYPE >
433  const std::string& location ) const
434  {
435  return GaudiCommon<AlgTool>::getIfExists<TYPE> ( svc , location , false ) ;
436  }
437 
455  template < class TYPE >
456  inline TYPE* getDet ( const std::string& location ) const
457  {
458  return GaudiCommon<AlgTool>::get<TYPE> ( detSvc() , location , false ) ;
459  }
460 
482  template < class TYPE >
484  getDetIfExists ( const std::string& location ) const
485  {
486  return GaudiCommon<AlgTool>::getIfExists<TYPE> ( detSvc() , location , false ) ;
487  }
488 
514  template < class TYPE >
515  inline bool exist ( IDataProviderSvc* svc ,
516  const std::string& location ,
517  const bool useRootInTES = true ) const
518  {
519  return GaudiCommon<AlgTool>::exist<TYPE> ( svc , location , useRootInTES ) ;
520  }
521 
544  template < class TYPE >
545  inline bool exist ( const std::string& location ,
546  const bool useRootInTES = true ) const
547  {
548  return GaudiCommon<AlgTool>::exist<TYPE> ( evtSvc() , location , useRootInTES ) ;
549  }
550 
567  template < class TYPE >
568  inline bool existDet ( IDataProviderSvc* svc ,
569  const std::string& location ) const
570  {
571  return GaudiCommon<AlgTool>::exist<TYPE> ( svc , location , false ) ;
572  }
573 
589  template < class TYPE >
590  inline bool existDet ( const std::string& location ) const
591  {
592  return GaudiCommon<AlgTool>::exist<TYPE> ( detSvc() , location , false ) ;
593  }
594 
621  template < class TYPE , class TYPE2 >
624  const std::string& location ,
625  const bool useRootInTES = true ) const
626  {
627  return GaudiCommon<AlgTool>::getOrCreate<TYPE,TYPE2> ( svc , location , useRootInTES ) ;
628  }
629 
655  template < class TYPE , class TYPE2 >
657  getOrCreate ( const std::string& location ,
658  const bool useRootInTES = true ) const
659  {
660  return GaudiCommon<AlgTool>::getOrCreate<TYPE,TYPE2> ( evtSvc() , location , useRootInTES ) ;
661  }
662  // ==========================================================================
663  public:
664  // ==========================================================================
688  inline StatusCode Error
689  ( const std::string& msg ,
690  const StatusCode st = StatusCode::FAILURE ,
691  const size_t mx = 10 ) const
692  {
693  return GaudiCommon<AlgTool>::Error( m_isPublic ?
694  msg + getCurrentAlgName() : msg,
695  st, mx );
696  }
720  inline StatusCode Warning
721  ( const std::string& msg ,
722  const StatusCode st = StatusCode::FAILURE ,
723  const size_t mx = 10 ) const
724  {
725  return GaudiCommon<AlgTool>::Warning( m_isPublic ?
726  msg + getCurrentAlgName() : msg,
727  st, mx );
728  }
744  inline StatusCode Info
745  ( const std::string& msg ,
746  const StatusCode st = StatusCode::SUCCESS ,
747  const size_t mx = 10 ) const
748  {
749  return GaudiCommon<AlgTool>::Info( m_isPublic ?
750  msg + getCurrentAlgName() : msg,
751  st, mx );
752  }
753  // ==========================================================================
754  public:
755  // ==========================================================================
757  static bool enableSummary ( bool ) ; // enable/disable summary
759  static bool summaryEnabled ( ) ; // is summary enabled?
760  // ==========================================================================
761  protected:
762  // ==========================================================================
769  GaudiTool ( const std::string& type ,
770  const std::string& name ,
771  const IInterface* parent );
772 
774  ~GaudiTool() override;
775  // ==========================================================================
776  private:
777  // ==========================================================================
779  GaudiTool() = delete;
780  GaudiTool ( const GaudiTool& ) = delete;
781  GaudiTool& operator = ( const GaudiTool& ) = delete;
782  // ==========================================================================
783  private:
784  // ==========================================================================
786  bool isPublic() const;
789  {
790  const IAlgContextSvc * asvc = this->contextSvc();
791  const IAlgorithm * current = ( asvc ? asvc->currentAlg() : NULL );
792  return ( current ? " [" + current->name() + "]" : "" );
793  }
794  // ==========================================================================
795  private:
796  // ==========================================================================
798  mutable INTupleSvc* m_ntupleSvc = nullptr;
800  mutable INTupleSvc* m_evtColSvc = nullptr;
802  mutable IDataProviderSvc* m_detSvc = nullptr;
804  mutable IChronoStatSvc* m_chronoSvc = nullptr;
806  mutable IIncidentSvc* m_incSvc = nullptr;
808  mutable IHistogramSvc * m_histoSvc = nullptr;
809  // Pointer to the Algorithm Context Service
810  mutable IAlgContextSvc* m_contextSvc = nullptr;
811  // The name of the Algorithm Context Service
812  std::string m_contextSvcName = "AlgContextSvc";
813  // ==========================================================================
814  private:
815  // ==========================================================================
817  bool m_isPublic = false;
818  // ==========================================================================
819  private:
820  // ==========================================================================
823  // ==========================================================================
824  private:
825  // ==========================================================================
827  static bool s_enableSummary ; // enable printout of summary?
828  // ==========================================================================
829 
830  public:
832  template <class T>
833  Property* declareProperty
834  ( const std::string& name,
835  DataObjectHandle<T>& hndl,
836  const std::string& doc = "none" ) const
837  {
838 
839  if ( hndl.mode() & Gaudi::DataHandle::Reader ) {
840  (const_cast<GaudiTool*>(this))->AlgTool::declareInput(&hndl);
841  }
842 
843  if ( hndl.mode() & Gaudi::DataHandle::Writer ) {
844  (const_cast<GaudiTool*>(this))->AlgTool::declareOutput(&hndl);
845  }
846 
847  if (hndl.owner() == 0) {
848  hndl.setOwner((const_cast<GaudiTool*>(this)));
849  }
850 
851  return m_propertyMgr->declareProperty(name, hndl, doc);
852  }
853 
854 
855 };
856 // ============================================================================
857 
858 // ============================================================================
859 // The END
860 // ============================================================================
861 #endif // GAUDIALG_GAUDITOOL_H
862 // ============================================================================
Define general base for Gaudi exception.
virtual void setOwner(IDataHandleHolder *o)
Definition: DataHandle.h:44
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:432
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.
virtual Mode mode() const
Definition: DataHandle.h:47
Helper structure for implementation of "get"-functions for GaudiCommon
Definition: GaudiCommon.h:36
STL namespace.
StatusCode finalize() override
standard finalization method
TYPE * getDet(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:456
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:788
Data provider interface definition.
STL class.
The IChronoStatSvc is the interface implemented by the ChronoStatService.
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
Definition: AlgTool.h:24
bool existDet(IDataProviderSvc *svc, const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:568
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:377
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:515
string type
Definition: gaudirun.py:151
TYPE * getDet(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:402
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: AlgTool.h:249
Definition of the basic interface.
Definition: IInterface.h:234
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:185
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:657
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:623
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:590
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:25
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:303
StatusCode initialize() override
standard initialization method
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:484
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:827
GaudiCommon & operator=(const GaudiCommon &)=delete
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:221
The useful base class for tools.
Definition: GaudiTool.h:98
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:73
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:822
#define GAUDI_API
Definition: Kernel.h:107
virtual IAlgorithm * currentAlg() const =0
accessor to current algorithm:
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
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:545
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:45
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:21
SmartIF< SERVICE > svc(const std::string &name, const bool create=true) const
A useful method for the easy location of services.