The Gaudi Framework  v30r3 (a5ef0a68)
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  // [[deprecated( "please pass a std::unique_ptr as 2nd argument" )]]
189  inline void put( IDataProviderSvc* svc, DataObject* object, const std::string& address,
190  const bool useRootInTES = true ) const
191  {
192  put( svc, std::unique_ptr<DataObject>( object ), address, useRootInTES );
193  }
194  inline void put( IDataProviderSvc* svc, std::unique_ptr<DataObject> object, const std::string& address,
195  const bool useRootInTES = true ) const
196  {
197  GaudiCommon<AlgTool>::put( svc, std::move( object ), address, useRootInTES );
198  }
199 
228  inline const DataObject* put( DataObject* object, const std::string& address, const bool useRootInTES = true ) const
229  {
230  return put( std::unique_ptr<DataObject>( object ), address, useRootInTES );
231  }
232  inline const DataObject* put( std::unique_ptr<DataObject> object, const std::string& address,
233  const bool useRootInTES = true ) const
234  {
235  return GaudiCommon<AlgTool>::put( evtSvc(), std::move( object ), address, useRootInTES );
236  }
237 
269  template <class TYPE>
271  const bool useRootInTES = true ) const
272  {
273  return GaudiCommon<AlgTool>::get<TYPE>( svc, location, useRootInTES );
274  }
275 
309  template <class TYPE>
311  getIfExists( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const
312  {
313  return GaudiCommon<AlgTool>::getIfExists<TYPE>( svc, location, useRootInTES );
314  }
315 
341  template <class TYPE>
343  const bool useRootInTES = true ) const
344  {
345  return GaudiCommon<AlgTool>::get<TYPE>( evtSvc(), location, useRootInTES );
346  }
347 
380  template <class TYPE>
382  const bool useRootInTES = true ) const
383  {
384  return GaudiCommon<AlgTool>::getIfExists<TYPE>( evtSvc(), location, useRootInTES );
385  }
386 
405  template <class TYPE>
406  inline TYPE* getDet( IDataProviderSvc* svc, const std::string& location ) const
407  {
408  return GaudiCommon<AlgTool>::get<TYPE>( svc, location, false );
409  }
410 
433  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>
485  inline typename Gaudi::Utils::GetData<TYPE>::return_type getDetIfExists( const std::string& location ) const
486  {
487  return GaudiCommon<AlgTool>::getIfExists<TYPE>( detSvc(), location, false );
488  }
489 
515  template <class TYPE>
516  inline bool exist( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const
517  {
518  return GaudiCommon<AlgTool>::exist<TYPE>( svc, location, useRootInTES );
519  }
520 
543  template <class TYPE>
544  inline bool exist( const std::string& location, const bool useRootInTES = true ) const
545  {
546  return GaudiCommon<AlgTool>::exist<TYPE>( evtSvc(), location, useRootInTES );
547  }
548 
565  template <class TYPE>
566  inline bool existDet( IDataProviderSvc* svc, const std::string& location ) const
567  {
568  return GaudiCommon<AlgTool>::exist<TYPE>( svc, location, false );
569  }
570 
586  template <class TYPE>
587  inline bool existDet( const std::string& location ) const
588  {
589  return GaudiCommon<AlgTool>::exist<TYPE>( detSvc(), location, false );
590  }
591 
618  template <class TYPE, class TYPE2>
620  getOrCreate( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const
621  {
622  return GaudiCommon<AlgTool>::getOrCreate<TYPE, TYPE2>( svc, location, useRootInTES );
623  }
624 
650  template <class TYPE, class TYPE2>
652  const bool useRootInTES = true ) const
653  {
654  return GaudiCommon<AlgTool>::getOrCreate<TYPE, TYPE2>( evtSvc(), location, useRootInTES );
655  }
656  // ==========================================================================
657 public:
658  // ==========================================================================
683  const size_t mx = 10 ) const
684  {
685  return GaudiCommon<AlgTool>::Error( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
686  }
711  const size_t mx = 10 ) const
712  {
713  return GaudiCommon<AlgTool>::Warning( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
714  }
731  const size_t mx = 10 ) const
732  {
733  return GaudiCommon<AlgTool>::Info( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
734  }
735  // ==========================================================================
736 public:
737  // ==========================================================================
739  static bool enableSummary( bool );
741  static bool summaryEnabled();
742 
743  // ==========================================================================
750  GaudiTool( const std::string& type, const std::string& name, const IInterface* parent );
751 
753  ~GaudiTool() override;
754  // ==========================================================================
755 private:
756  // ==========================================================================
758  GaudiTool() = delete;
759  GaudiTool( const GaudiTool& ) = delete;
760  GaudiTool& operator=( const GaudiTool& ) = delete;
761  // ==========================================================================
762 private:
763  // ==========================================================================
765  bool isPublic() const;
768  {
769  const IAlgContextSvc* asvc = this->contextSvc();
770  const IAlgorithm* current = ( asvc ? asvc->currentAlg() : NULL );
771  return ( current ? " [" + current->name() + "]" : "" );
772  }
773  // ==========================================================================
774 private:
775  // ==========================================================================
788  // Pointer to the Algorithm Context Service
790 
791  Gaudi::Property<std::string> m_contextSvcName{this, "ContextService", "AlgContextSvc",
792  "the name of Algorithm Context Service"};
793  // ==========================================================================
794 private:
795  // ==========================================================================
797  bool m_isPublic = false;
798  // ==========================================================================
799 private:
800  // ==========================================================================
803  // ==========================================================================
804 private:
805  // ==========================================================================
807  static bool s_enableSummary;
808  // ==========================================================================
809 };
810 // ============================================================================
811 
812 // ============================================================================
813 // The END
814 // ============================================================================
815 #endif // GAUDIALG_GAUDITOOL_H
816 // ============================================================================
constexpr static const auto FAILURE
Definition: StatusCode.h:88
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:710
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:777
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
Implementation of property with value of concrete type.
Definition: Property.h:381
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.
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:54
SmartIF< IAlgContextSvc > m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:789
STL namespace.
TYPE * getDet(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:458
SmartIF< IIncidentSvc > m_incSvc
pointer to Incident Service
Definition: GaudiTool.h:785
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:767
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:730
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:566
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:381
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:516
TYPE * getDet(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:406
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
Definition of the basic interface.
Definition: IInterface.h:277
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.
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.
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:651
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:620
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:587
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
T move(T...args)
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:189
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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:311
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:485
const DataObject * put(std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:232
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:807
STL class.
SmartIF< IChronoStatSvc > m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:783
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:682
SmartIF< IHistogramSvc > m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:787
SmartIF< IDataProviderSvc > m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:781
The useful base class for tools.
Definition: GaudiTool.h:101
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:93
An abstract interface for Algorithm Context Service.
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.
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:802
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:228
SmartIF< INTupleSvc > m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:779
#define GAUDI_API
Definition: Kernel.h:104
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:544
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)
void put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:194