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/DataObject.h"
10 // ============================================================================
11 // GaudiAlg
12 // ============================================================================
13 #include "GaudiAlg/GaudiAlg.h"
14 #include "GaudiAlg/GaudiCommon.h"
15 // ============================================================================
16 // forward declarations
17 // ============================================================================
18 class IDataProviderSvc ;
19 class IChronoStatSvc ;
20 class IIncidentSvc ;
21 class IHistogramSvc ;
22 class GaudiException ;
23 class INTupleSvc ;
24 class IAlgContextSvc ;
25 namespace std { class exception ; }
26 // ============================================================================
62 // ============================================================================
96 // ============================================================================
97 class GAUDI_API GaudiTool: public GaudiCommon<AlgTool>
98 {
99  public:
100  // ==========================================================================
106  StatusCode initialize () override;
112  StatusCode finalize () override;
113  // ==========================================================================
114  public: // accessors
115  // ==========================================================================
119  INTupleSvc* ntupleSvc () const;
123  INTupleSvc* evtColSvc () const;
127  IDataProviderSvc* detSvc () const ;
131  IDataProviderSvc* evtSvc () const ;
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 detDvc() ) 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  inline DataObject* put ( IDataProviderSvc* svc ,
188  DataObject* object ,
189  const std::string& address ,
190  const bool useRootInTES = true ) const
191  {
192  return GaudiCommon<AlgTool>::put ( svc , object , address , useRootInTES ) ;
193  }
194 
223  inline DataObject* put ( DataObject* object ,
224  const std::string& address ,
225  const bool useRootInTES = true ) const
226  {
227  return GaudiCommon<AlgTool>::put ( evtSvc() , object , address , useRootInTES ) ;
228  }
229 
261  template < class TYPE >
264  const std::string& location ,
265  const bool useRootInTES = true ) const
266  {
267  return GaudiCommon<AlgTool>::get<TYPE> ( svc , location , useRootInTES ) ;
268  }
269 
303  template < class TYPE >
306  const std::string& location ,
307  const bool useRootInTES = true ) const
308  {
309  return GaudiCommon<AlgTool>::getIfExists<TYPE> ( svc , location , useRootInTES ) ;
310  }
311 
337  template < class TYPE >
339  get ( const std::string& location ,
340  const bool useRootInTES = true ) const
341  {
342  return GaudiCommon<AlgTool>::get<TYPE> ( evtSvc() , location , useRootInTES ) ;
343  }
344 
377  template < class TYPE >
379  getIfExists ( const std::string& location ,
380  const bool useRootInTES = true ) const
381  {
382  return GaudiCommon<AlgTool>::getIfExists<TYPE> ( evtSvc() , location , useRootInTES ) ;
383  }
384 
403  template < class TYPE >
404  inline TYPE* getDet ( IDataProviderSvc* svc ,
405  const std::string& location ) const
406  {
407  return GaudiCommon<AlgTool>::get<TYPE> ( svc , location , false ) ;
408  }
409 
432  template < class TYPE >
435  const std::string& location ) const
436  {
437  return GaudiCommon<AlgTool>::getIfExists<TYPE> ( svc , location , false ) ;
438  }
439 
457  template < class TYPE >
458  inline TYPE* getDet ( const std::string& location ) const
459  {
460  return GaudiCommon<AlgTool>::get<TYPE> ( detSvc() , location , false ) ;
461  }
462 
484  template < class TYPE >
486  getDetIfExists ( const std::string& location ) const
487  {
488  return GaudiCommon<AlgTool>::getIfExists<TYPE> ( detSvc() , location , false ) ;
489  }
490 
516  template < class TYPE >
517  inline bool exist ( IDataProviderSvc* svc ,
518  const std::string& location ,
519  const bool useRootInTES = true ) const
520  {
521  return GaudiCommon<AlgTool>::exist<TYPE> ( svc , location , useRootInTES ) ;
522  }
523 
546  template < class TYPE >
547  inline bool exist ( const std::string& location ,
548  const bool useRootInTES = true ) const
549  {
550  return GaudiCommon<AlgTool>::exist<TYPE> ( evtSvc() , location , useRootInTES ) ;
551  }
552 
569  template < class TYPE >
570  inline bool existDet ( IDataProviderSvc* svc ,
571  const std::string& location ) const
572  {
573  return GaudiCommon<AlgTool>::exist<TYPE> ( svc , location , false ) ;
574  }
575 
591  template < class TYPE >
592  inline bool existDet ( const std::string& location ) const
593  {
594  return GaudiCommon<AlgTool>::exist<TYPE> ( detSvc() , location , false ) ;
595  }
596 
623  template < class TYPE , class TYPE2 >
626  const std::string& location ,
627  const bool useRootInTES = true ) const
628  {
629  return GaudiCommon<AlgTool>::getOrCreate<TYPE,TYPE2> ( svc , location , useRootInTES ) ;
630  }
631 
657  template < class TYPE , class TYPE2 >
659  getOrCreate ( const std::string& location ,
660  const bool useRootInTES = true ) const
661  {
662  return GaudiCommon<AlgTool>::getOrCreate<TYPE,TYPE2> ( evtSvc() , location , useRootInTES ) ;
663  }
664  // ==========================================================================
665  public:
666  // ==========================================================================
690  inline StatusCode Error
691  ( const std::string& msg ,
692  const StatusCode st = StatusCode::FAILURE ,
693  const size_t mx = 10 ) const
694  {
695  return GaudiCommon<AlgTool>::Error( m_isPublic ?
696  msg + getCurrentAlgName() : msg,
697  st, mx );
698  }
722  inline StatusCode Warning
723  ( const std::string& msg ,
724  const StatusCode st = StatusCode::FAILURE ,
725  const size_t mx = 10 ) const
726  {
727  return GaudiCommon<AlgTool>::Warning( m_isPublic ?
728  msg + getCurrentAlgName() : msg,
729  st, mx );
730  }
746  inline StatusCode Info
747  ( const std::string& msg ,
748  const StatusCode st = StatusCode::SUCCESS ,
749  const size_t mx = 10 ) const
750  {
751  return GaudiCommon<AlgTool>::Info( m_isPublic ?
752  msg + getCurrentAlgName() : msg,
753  st, mx );
754  }
755  // ==========================================================================
756  public:
757  // ==========================================================================
759  static bool enableSummary ( bool ) ; // enable/disable summary
761  static bool summaryEnabled ( ) ; // is summary enabled?
762  // ==========================================================================
763  protected:
764  // ==========================================================================
771  GaudiTool ( const std::string& type ,
772  const std::string& name ,
773  const IInterface* parent );
774 
776  ~GaudiTool() override;
777  // ==========================================================================
778  private:
779  // ==========================================================================
781  GaudiTool() = delete;
782  GaudiTool ( const GaudiTool& ) = delete;
783  GaudiTool& operator = ( const GaudiTool& ) = delete;
784  // ==========================================================================
785  private:
786  // ==========================================================================
788  bool isPublic() const;
790  inline std::string getCurrentAlgName() const
791  {
792  const IAlgContextSvc * asvc = this->contextSvc();
793  const IAlgorithm * current = ( asvc ? asvc->currentAlg() : NULL );
794  return ( current ? " [" + current->name() + "]" : "" );
795  }
796  // ==========================================================================
797  private:
798  // ==========================================================================
800  mutable INTupleSvc* m_ntupleSvc = nullptr;
802  mutable INTupleSvc* m_evtColSvc = nullptr;
804  mutable IDataProviderSvc* m_evtSvc = nullptr;
806  mutable IDataProviderSvc* m_detSvc = nullptr;
808  mutable IChronoStatSvc* m_chronoSvc = nullptr;
810  mutable IIncidentSvc* m_incSvc = nullptr;
812  mutable IHistogramSvc * m_histoSvc = nullptr;
813  // Pointer to the Algorithm Context Service
814  mutable IAlgContextSvc* m_contextSvc = nullptr;
815  // The name of the Algorithm Context Service
816  std::string m_contextSvcName = "AlgContextSvc";
817  // ==========================================================================
818  private:
819  // ==========================================================================
821  bool m_isPublic = false;
822  // ==========================================================================
823  private:
824  // ==========================================================================
826  const std::string m_local ;
827  // ==========================================================================
828  private:
829  // ==========================================================================
831  static bool s_enableSummary ; // enable printout of summary?
832  // ==========================================================================
833 };
834 // ============================================================================
835 
836 // ============================================================================
837 // The END
838 // ============================================================================
839 #endif // GAUDIALG_GAUDITOOL_H
840 // ============================================================================
Define general base for Gaudi exception.
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:434
#define GAUDI_API
Definition: Kernel.h:107
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
Definition: GaudiCommon.h:36
STL namespace.
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:831
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:458
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:790
Data provider interface definition.
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:570
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:379
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:517
TYPE * getDet(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:404
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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:187
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:659
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:625
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:592
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:19
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:305
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:486
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:223
The useful base class for tools.
Definition: GaudiTool.h:97
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:826
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:547
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.
string type
Definition: gaudirun.py:151