The Gaudi Framework  v32r2 (46d42edc)
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  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  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  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  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  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  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  TYPE* getDet( const std::string& location ) const {
448  return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( detSvc(), location, false );
449  }
450 
472  template <class TYPE>
474  return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( detSvc(), location, false );
475  }
476 
502  template <class TYPE>
503  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  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  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  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  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  // ==========================================================================
663  StatusCode Error( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const {
664  return GaudiCommon<CounterHolder<AlgTool>>::Error( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
665  }
689  StatusCode Warning( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const {
690  return GaudiCommon<CounterHolder<AlgTool>>::Warning( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
691  }
707  StatusCode Info( const std::string& msg, const StatusCode st = StatusCode::SUCCESS, const size_t mx = 10 ) const {
708  return GaudiCommon<CounterHolder<AlgTool>>::Info( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
709  }
710  // ==========================================================================
711 public:
712  // ==========================================================================
714  static bool enableSummary( bool );
716  static bool summaryEnabled();
717 
718  // ==========================================================================
725  GaudiTool( const std::string& type, const std::string& name, const IInterface* parent );
726 
728  ~GaudiTool() override;
729  // ==========================================================================
730 private:
731  // ==========================================================================
733  GaudiTool() = delete;
734  GaudiTool( const GaudiTool& ) = delete;
735  GaudiTool& operator=( const GaudiTool& ) = delete;
736  // ==========================================================================
737 private:
738  // ==========================================================================
740  bool isPublic() const;
743  const IAlgContextSvc* asvc = this->contextSvc();
744  const IAlgorithm* current = ( asvc ? asvc->currentAlg() : NULL );
745  return ( current ? " [" + current->name() + "]" : "" );
746  }
747  // ==========================================================================
748 private:
749  // ==========================================================================
762  // Pointer to the Algorithm Context Service
764 
765  Gaudi::Property<std::string> m_contextSvcName{this, "ContextService", "AlgContextSvc",
766  "the name of Algorithm Context Service"};
767  // ==========================================================================
768 private:
769  // ==========================================================================
771  bool m_isPublic = false;
772  // ==========================================================================
773 private:
774  // ==========================================================================
777  // ==========================================================================
778 private:
779  // ==========================================================================
781  static bool s_enableSummary;
782  // ==========================================================================
783 };
784 // ============================================================================
785 
786 // ============================================================================
787 // The END
788 // ============================================================================
789 #endif // GAUDIALG_GAUDITOOL_H
const DataObject * put(std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:228
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
Define general base for Gaudi exception.
SmartIF< INTupleSvc > m_ntupleSvc
pointer to the N-Tuple service
Definition: GaudiTool.h:751
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
Implementation of property with value of concrete type.
Definition: Property.h:352
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
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.
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
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:53
SmartIF< IAlgContextSvc > m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:763
STL namespace.
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:571
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.
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
StatusCode finalize() override
standard finalization method
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
SmartIF< IIncidentSvc > m_incSvc
pointer to Incident Service
Definition: GaudiTool.h:759
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:707
STL class.
The IChronoStatSvc is the interface implemented by the ChronoStatService.
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:304
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:689
Gaudi::Utils::GetData< TYPE >::return_type get(const std::string &location, const bool useRootInTES=true) const
Templated access to the data from Gaudi Event Transient Store.
Definition: GaudiTool.h:335
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 get(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiTool.h:265
Definition of the IHistogramSvc interface class.
Definition: IHistogramSvc.h:46
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
T move(T... args)
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
StatusCode initialize() override
standard initialization method
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:781
STL class.
GaudiCommon & operator=(const GaudiCommon &)=delete
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.
SmartIF< IChronoStatSvc > m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:757
SmartIF< IHistogramSvc > m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:761
void put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:192
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
SmartIF< IDataProviderSvc > m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:755
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:602
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:91
An abstract interface for Algorithm Context Service.
TYPE * getDet(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:447
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
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:776
SmartIF< INTupleSvc > m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:753
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
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
#define GAUDI_API
Definition: Kernel.h:71
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
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:742
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
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.