The Gaudi Framework  v33r1 (b1225454)
GaudiTool.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIALG_GAUDITOOL_H
12 #define GAUDIALG_GAUDITOOL_H 1
13 // ============================================================================
14 // Include files
15 // ============================================================================
16 // GaudiKernel
17 // ============================================================================
18 #include "GaudiKernel/AlgTool.h"
20 #include "GaudiKernel/DataObject.h"
21 // ============================================================================
22 // GaudiAlg
23 // ============================================================================
24 #include "GaudiAlg/GaudiAlg.h"
25 #include "GaudiAlg/GaudiCommon.h"
27 // ============================================================================
28 // forward declarations
29 // ============================================================================
30 class IDataProviderSvc;
31 class IChronoStatSvc;
32 class IIncidentSvc;
33 class IHistogramSvc;
34 class GaudiException;
35 class INTupleSvc;
36 class IAlgContextSvc;
37 namespace std {
38  class exception;
39 }
40 // ============================================================================
76 // ============================================================================
110 // ============================================================================
111 class GAUDI_API GaudiTool : public GaudiCommon<CounterHolder<AlgTool>> {
112 public:
113  // ==========================================================================
119  StatusCode initialize() override;
125  StatusCode finalize() override;
126  // ==========================================================================
127 public: // accessors
128  // ==========================================================================
132  INTupleSvc* ntupleSvc() const;
136  INTupleSvc* evtColSvc() const;
140  IDataProviderSvc* detSvc() const;
141 
145  IIncidentSvc* incSvc() const;
149  IChronoStatSvc* chronoSvc() const;
153  IHistogramSvc* histoSvc() const;
157  IAlgContextSvc* contextSvc() const;
158  // ==========================================================================
159 public:
160  // ==========================================================================
161  // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
162  // and detSvc() ) that are not members of AlgTool.
163  // Also some methods seem which are members of the base class do not seem
164  // to be found unless forwarding methods are put here ??
165  // ==========================================================================
166 
197  // [[deprecated( "please pass a std::unique_ptr as 2nd argument" )]]
198  void put( IDataProviderSvc* svc, DataObject* object, const std::string& address,
199  const bool useRootInTES = true ) const {
200  put( svc, std::unique_ptr<DataObject>( object ), address, useRootInTES );
201  }
202  void put( IDataProviderSvc* svc, std::unique_ptr<DataObject> object, const std::string& address,
203  const bool useRootInTES = true ) const {
204  GaudiCommon<CounterHolder<AlgTool>>::put( svc, std::move( object ), address, useRootInTES );
205  }
206 
235  const DataObject* put( DataObject* object, const std::string& address, const bool useRootInTES = true ) const {
236  return put( std::unique_ptr<DataObject>( object ), address, useRootInTES );
237  }
238  const DataObject* put( std::unique_ptr<DataObject> object, const std::string& address,
239  const bool useRootInTES = true ) const {
240  return GaudiCommon<CounterHolder<AlgTool>>::put( evtSvc(), std::move( object ), address, useRootInTES );
241  }
242 
274  template <class TYPE>
276  const bool useRootInTES = true ) const {
277  return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( svc, location, useRootInTES );
278  }
279 
313  template <class TYPE>
315  const bool useRootInTES = true ) const {
316  return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( svc, location, useRootInTES );
317  }
318 
344  template <class TYPE>
346  const bool useRootInTES = true ) const {
347  return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( evtSvc(), location, useRootInTES );
348  }
349 
382  template <class TYPE>
384  const bool useRootInTES = true ) const {
385  return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( evtSvc(), location, useRootInTES );
386  }
387 
406  template <class TYPE>
407  TYPE* getDet( IDataProviderSvc* svc, const std::string& location ) const {
408  return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( svc, location, false );
409  }
410 
433  template <class TYPE>
435  const std::string& location ) const {
436  return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( svc, location, false );
437  }
438 
456  template <class TYPE>
457  TYPE* getDet( const std::string& location ) const {
458  return GaudiCommon<CounterHolder<AlgTool>>::get<TYPE>( detSvc(), location, false );
459  }
460 
482  template <class TYPE>
484  return GaudiCommon<CounterHolder<AlgTool>>::getIfExists<TYPE>( detSvc(), location, false );
485  }
486 
512  template <class TYPE>
513  bool exist( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const {
514  return GaudiCommon<CounterHolder<AlgTool>>::exist<TYPE>( svc, location, useRootInTES );
515  }
516 
539  template <class TYPE>
540  bool exist( const std::string& location, const bool useRootInTES = true ) const {
541  return GaudiCommon<CounterHolder<AlgTool>>::exist<TYPE>( evtSvc(), location, useRootInTES );
542  }
543 
560  template <class TYPE>
561  bool existDet( IDataProviderSvc* svc, const std::string& location ) const {
562  return GaudiCommon<CounterHolder<AlgTool>>::exist<TYPE>( svc, location, false );
563  }
564 
580  template <class TYPE>
581  bool existDet( const std::string& location ) const {
582  return GaudiCommon<CounterHolder<AlgTool>>::exist<TYPE>( detSvc(), location, false );
583  }
584 
611  template <class TYPE, class TYPE2>
613  const bool useRootInTES = true ) const {
614  return GaudiCommon<CounterHolder<AlgTool>>::getOrCreate<TYPE, TYPE2>( svc, location, useRootInTES );
615  }
616 
642  template <class TYPE, class TYPE2>
644  const bool useRootInTES = true ) const {
645  return GaudiCommon<CounterHolder<AlgTool>>::getOrCreate<TYPE, TYPE2>( evtSvc(), location, useRootInTES );
646  }
647  // ==========================================================================
648 public:
649  // ==========================================================================
673  StatusCode Error( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const {
674  return GaudiCommon<CounterHolder<AlgTool>>::Error( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
675  }
699  StatusCode Warning( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const {
700  return GaudiCommon<CounterHolder<AlgTool>>::Warning( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
701  }
717  StatusCode Info( const std::string& msg, const StatusCode st = StatusCode::SUCCESS, const size_t mx = 10 ) const {
718  return GaudiCommon<CounterHolder<AlgTool>>::Info( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
719  }
720  // ==========================================================================
721 public:
722  // ==========================================================================
724  static bool enableSummary( bool );
726  static bool summaryEnabled();
727 
728  // ==========================================================================
736 
738  ~GaudiTool() override;
739  // ==========================================================================
740 private:
741  // ==========================================================================
743  GaudiTool( const GaudiTool& ) = delete;
744  GaudiTool& operator=( const GaudiTool& ) = delete;
745  // ==========================================================================
746 private:
747  // ==========================================================================
749  bool isPublic() const;
752  const IAlgContextSvc* asvc = this->contextSvc();
753  const IAlgorithm* current = ( asvc ? asvc->currentAlg() : NULL );
754  return ( current ? " [" + current->name() + "]" : "" );
755  }
756  // ==========================================================================
757 private:
758  // ==========================================================================
771  // Pointer to the Algorithm Context Service
773 
774  Gaudi::Property<std::string> m_contextSvcName{this, "ContextService", "AlgContextSvc",
775  "the name of Algorithm Context Service"};
776  // ==========================================================================
777 private:
778  // ==========================================================================
780  bool m_isPublic = false;
781  // ==========================================================================
782 private:
783  // ==========================================================================
786  // ==========================================================================
787 private:
788  // ==========================================================================
790  static bool s_enableSummary;
791  // ==========================================================================
792 };
793 // ============================================================================
794 
795 // ============================================================================
796 // The END
797 // ============================================================================
798 #endif // GAUDIALG_GAUDITOOL_H
const DataObject * put(std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:238
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:673
Define general base for Gaudi exception.
SmartIF< INTupleSvc > m_ntupleSvc
pointer to the N-Tuple service
Definition: GaudiTool.h:760
TYPE * getDet(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:407
Implementation of property with value of concrete type.
Definition: Property.h:370
StatusCode Error(std::string_view 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 getOrCreate(const std::string &location, const bool useRootInTES=true) const
Get the existing data object from Gaudi Event Transient store.
Definition: GaudiTool.h:643
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
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Helper structure for implementation of "get"-functions for GaudiCommon<BASE>
Definition: GaudiCommon.h:57
SmartIF< IAlgContextSvc > m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:772
STL namespace.
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:581
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:513
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:198
SmartIF< IIncidentSvc > m_incSvc
pointer to Incident Service
Definition: GaudiTool.h:768
StatusCode Info(std::string_view msg, const StatusCode st=StatusCode::SUCCESS, const size_t mx=10) const
Print the info message and return with the given StatusCode.
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:717
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:314
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:699
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:345
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
StatusCode Warning(std::string_view 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 get(IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Templated access to the data in Gaudi Transient Store.
Definition: GaudiTool.h:275
Definition of the IHistogramSvc interface class.
Definition: IHistogramSvc.h:56
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:38
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:383
StatusCode initialize() override
standard initialization method
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:790
STL class.
GaudiCommon & operator=(const GaudiCommon &)=delete
SmartIF< IChronoStatSvc > m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:766
SmartIF< IHistogramSvc > m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:770
void put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:202
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:483
SmartIF< IDataProviderSvc > m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:764
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:612
constexpr static const auto FAILURE
Definition: StatusCode.h:101
const Gaudi::Algorithm & parent
The useful base class for tools.
Definition: GaudiTool.h:111
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:95
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:457
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:235
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:785
SmartIF< INTupleSvc > m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:762
bool existDet(IDataProviderSvc *svc, const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:561
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:540
#define GAUDI_API
Definition: Kernel.h:81
DataObject * put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, std::string_view location, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
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:40
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:751
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:33