Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 #include "GaudiKernel/DataObject.h"
11 // ============================================================================
12 // GaudiAlg
13 // ============================================================================
14 #include "GaudiAlg/GaudiAlg.h"
15 #include "GaudiAlg/GaudiCommon.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  inline 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  inline 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  inline 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  inline 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>
266  const bool useRootInTES = true ) const {
267  return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( svc, location, useRootInTES );
268  }
269 
303  template <class TYPE>
305  getIfExists( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const {
306  return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( svc, location, useRootInTES );
307  }
308 
334  template <class TYPE>
336  const bool useRootInTES = true ) const {
337  return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( evtSvc(), location, useRootInTES );
338  }
339 
372  template <class TYPE>
374  const bool useRootInTES = true ) const {
375  return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( evtSvc(), location, useRootInTES );
376  }
377 
396  template <class TYPE>
397  inline 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>
425  const std::string& location ) const {
426  return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( svc, location, false );
427  }
428 
446  template <class TYPE>
447  inline TYPE* getDet( const std::string& location ) const {
448  return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( detSvc(), location, false );
449  }
450 
472  template <class TYPE>
473  inline 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  inline 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  inline 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  inline 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  inline 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>
603  getOrCreate( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const {
604  return GaudiCommon<CounterHolder<AlgTool>>::getOrCreate<TYPE, TYPE2>( svc, location, useRootInTES );
605  }
606 
632  template <class TYPE, class TYPE2>
634  const bool useRootInTES = true ) const {
635  return GaudiCommon<CounterHolder<AlgTool>>::getOrCreate<TYPE, TYPE2>( evtSvc(), location, useRootInTES );
636  }
637  // ==========================================================================
638 public:
639  // ==========================================================================
664  const size_t mx = 10 ) const {
665  return GaudiCommon<CounterHolder<AlgTool>>::Error( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
666  }
691  const size_t mx = 10 ) const {
692  return GaudiCommon<CounterHolder<AlgTool>>::Warning( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
693  }
710  const size_t mx = 10 ) const {
711  return GaudiCommon<CounterHolder<AlgTool>>::Info( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
712  }
713  // ==========================================================================
714 public:
715  // ==========================================================================
717  static bool enableSummary( bool );
719  static bool summaryEnabled();
720 
721  // ==========================================================================
728  GaudiTool( const std::string& type, const std::string& name, const IInterface* parent );
729 
731  ~GaudiTool() override;
732  // ==========================================================================
733 private:
734  // ==========================================================================
736  GaudiTool() = delete;
737  GaudiTool( const GaudiTool& ) = delete;
738  GaudiTool& operator=( const GaudiTool& ) = delete;
739  // ==========================================================================
740 private:
741  // ==========================================================================
743  bool isPublic() const;
746  const IAlgContextSvc* asvc = this->contextSvc();
747  const IAlgorithm* current = ( asvc ? asvc->currentAlg() : NULL );
748  return ( current ? " [" + current->name() + "]" : "" );
749  }
750  // ==========================================================================
751 private:
752  // ==========================================================================
765  // Pointer to the Algorithm Context Service
767 
768  Gaudi::Property<std::string> m_contextSvcName{this, "ContextService", "AlgContextSvc",
769  "the name of Algorithm Context Service"};
770  // ==========================================================================
771 private:
772  // ==========================================================================
774  bool m_isPublic = false;
775  // ==========================================================================
776 private:
777  // ==========================================================================
780  // ==========================================================================
781 private:
782  // ==========================================================================
784  static bool s_enableSummary;
785  // ==========================================================================
786 };
787 // ============================================================================
788 
789 // ============================================================================
790 // The END
791 // ============================================================================
792 #endif // GAUDIALG_GAUDITOOL_H
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:690
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:754
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
Implementation of property with value of concrete type.
Definition: Property.h:352
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:54
SmartIF< IAlgContextSvc > m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:766
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:762
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:745
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:709
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:551
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
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
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
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Definition of the basic interface.
Definition: IInterface.h:244
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
Definition of the IHistogramSvc interface class.
Definition: IHistogramSvc.h:46
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:603
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:571
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:188
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
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
const DataObject * put(std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:228
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:784
STL class.
SmartIF< IChronoStatSvc > m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:760
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< IHistogramSvc > m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:764
SmartIF< IDataProviderSvc > m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:758
constexpr static const auto FAILURE
Definition: StatusCode.h:86
The useful base class for tools.
Definition: GaudiTool.h:101
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:92
An abstract interface for Algorithm Context Service.
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:779
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
SmartIF< INTupleSvc > m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:756
#define GAUDI_API
Definition: Kernel.h:71
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:530
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:192