The Gaudi Framework  v36r1 (3e2fb5a8)
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"
19 #include "GaudiKernel/DataObject.h"
20 // ============================================================================
21 // GaudiAlg
22 // ============================================================================
23 #include "GaudiAlg/GaudiAlg.h"
24 #include "GaudiAlg/GaudiCommon.h"
26 // ============================================================================
27 // forward declarations
28 // ============================================================================
29 class IDataProviderSvc;
30 class IChronoStatSvc;
31 class IIncidentSvc;
32 class IHistogramSvc;
33 class GaudiException;
34 class INTupleSvc;
35 class IAlgContextSvc;
36 namespace std {
37  class exception;
38 }
39 // ============================================================================
75 // ============================================================================
109 // ============================================================================
110 class GAUDI_API GaudiTool : public GaudiCommon<AlgTool> {
111 public:
112  // ==========================================================================
118  StatusCode initialize() override;
124  StatusCode finalize() override;
125  // ==========================================================================
126 public: // accessors
127  // ==========================================================================
131  INTupleSvc* ntupleSvc() const;
135  INTupleSvc* evtColSvc() const;
139  IDataProviderSvc* detSvc() const;
140 
144  IIncidentSvc* incSvc() const;
148  IChronoStatSvc* chronoSvc() const;
152  IHistogramSvc* histoSvc() const;
156  IAlgContextSvc* contextSvc() const;
157  // ==========================================================================
158 public:
159  // ==========================================================================
160  // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
161  // and detSvc() ) that are not members of AlgTool.
162  // Also some methods seem which are members of the base class do not seem
163  // to be found unless forwarding methods are put here ??
164  // ==========================================================================
165 
196  // [[deprecated( "please pass a std::unique_ptr as 2nd argument" )]]
197  void put( IDataProviderSvc* svc, DataObject* object, const std::string& address,
198  const bool useRootInTES = true ) const {
199  put( svc, std::unique_ptr<DataObject>( object ), address, useRootInTES );
200  }
201  void put( IDataProviderSvc* svc, std::unique_ptr<DataObject> object, const std::string& address,
202  const bool useRootInTES = true ) const {
203  GaudiCommon<AlgTool>::put( svc, std::move( object ), address, useRootInTES );
204  }
205 
234  const DataObject* put( DataObject* object, const std::string& address, const bool useRootInTES = true ) const {
235  return put( std::unique_ptr<DataObject>( object ), address, useRootInTES );
236  }
237  const DataObject* put( std::unique_ptr<DataObject> object, const std::string& address,
238  const bool useRootInTES = true ) const {
239  return GaudiCommon<AlgTool>::put( evtSvc(), std::move( object ), address, useRootInTES );
240  }
241 
273  template <class TYPE>
275  const bool useRootInTES = true ) const {
276  return GaudiCommon<AlgTool>::get<TYPE>( svc, location, useRootInTES );
277  }
278 
312  template <class TYPE>
314  const bool useRootInTES = true ) const {
315  return GaudiCommon<AlgTool>::getIfExists<TYPE>( svc, location, useRootInTES );
316  }
317 
343  template <class TYPE>
345  const bool useRootInTES = true ) const {
346  return GaudiCommon<AlgTool>::get<TYPE>( evtSvc(), location, useRootInTES );
347  }
348 
381  template <class TYPE>
383  const bool useRootInTES = true ) const {
384  return GaudiCommon<AlgTool>::getIfExists<TYPE>( evtSvc(), location, useRootInTES );
385  }
386 
405  template <class TYPE>
406  TYPE* getDet( IDataProviderSvc* svc, const std::string& location ) const {
407  return GaudiCommon<AlgTool>::get<TYPE>( svc, location, false );
408  }
409 
432  template <class TYPE>
434  const std::string& location ) const {
436  }
437 
455  template <class TYPE>
456  TYPE* getDet( const std::string& location ) const {
457  return GaudiCommon<AlgTool>::get<TYPE>( detSvc(), location, false );
458  }
459 
481  template <class TYPE>
483  return GaudiCommon<AlgTool>::getIfExists<TYPE>( detSvc(), location, false );
484  }
485 
511  template <class TYPE>
512  bool exist( IDataProviderSvc* svc, const std::string& location, const bool useRootInTES = true ) const {
513  return GaudiCommon<AlgTool>::exist<TYPE>( svc, location, useRootInTES );
514  }
515 
538  template <class TYPE>
539  bool exist( const std::string& location, const bool useRootInTES = true ) const {
540  return GaudiCommon<AlgTool>::exist<TYPE>( evtSvc(), location, useRootInTES );
541  }
542 
559  template <class TYPE>
560  bool existDet( IDataProviderSvc* svc, const std::string& location ) const {
561  return GaudiCommon<AlgTool>::exist<TYPE>( svc, location, false );
562  }
563 
579  template <class TYPE>
580  bool existDet( const std::string& location ) const {
581  return GaudiCommon<AlgTool>::exist<TYPE>( detSvc(), location, false );
582  }
583 
610  template <class TYPE, class TYPE2>
612  const bool useRootInTES = true ) const {
613  return GaudiCommon<AlgTool>::getOrCreate<TYPE, TYPE2>( svc, location, useRootInTES );
614  }
615 
641  template <class TYPE, class TYPE2>
643  const bool useRootInTES = true ) const {
644  return GaudiCommon<AlgTool>::getOrCreate<TYPE, TYPE2>( evtSvc(), location, useRootInTES );
645  }
646  // ==========================================================================
647 public:
648  // ==========================================================================
672  StatusCode Error( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const {
673  return GaudiCommon<AlgTool>::Error( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
674  }
698  StatusCode Warning( const std::string& msg, const StatusCode st = StatusCode::FAILURE, const size_t mx = 10 ) const {
699  return GaudiCommon<AlgTool>::Warning( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
700  }
716  StatusCode Info( const std::string& msg, const StatusCode st = StatusCode::SUCCESS, const size_t mx = 10 ) const {
717  return GaudiCommon<AlgTool>::Info( m_isPublic ? msg + getCurrentAlgName() : msg, st, mx );
718  }
719  // ==========================================================================
720 public:
721  // ==========================================================================
723  static bool enableSummary( bool );
725  static bool summaryEnabled();
726 
727  // ==========================================================================
735 
737  ~GaudiTool() override;
738  // ==========================================================================
739 private:
740  // ==========================================================================
742  GaudiTool( const GaudiTool& ) = delete;
743  GaudiTool& operator=( const GaudiTool& ) = delete;
744  // ==========================================================================
745 private:
746  // ==========================================================================
748  bool isPublic() const;
751  const IAlgContextSvc* asvc = this->contextSvc();
752  const IAlgorithm* current = ( asvc ? asvc->currentAlg() : NULL );
753  return ( current ? " [" + current->name() + "]" : "" );
754  }
755  // ==========================================================================
756 private:
757  // ==========================================================================
770  // Pointer to the Algorithm Context Service
772 
773  Gaudi::Property<std::string> m_contextSvcName{this, "ContextService", "AlgContextSvc",
774  "the name of Algorithm Context Service"};
775  // ==========================================================================
776 private:
777  // ==========================================================================
779  bool m_isPublic = false;
780  // ==========================================================================
781 private:
782  // ==========================================================================
785  // ==========================================================================
786 private:
787  // ==========================================================================
789  static bool s_enableSummary;
790  // ==========================================================================
791 };
792 // ============================================================================
793 
794 // ============================================================================
795 // The END
796 // ============================================================================
797 #endif // GAUDIALG_GAUDITOOL_H
GaudiCommon.h
GaudiTool::m_histoSvc
SmartIF< IHistogramSvc > m_histoSvc
pointer for histogram service
Definition: GaudiTool.h:769
GaudiAlg.h
GaudiTool::m_evtColSvc
SmartIF< INTupleSvc > m_evtColSvc
pointer to the event tag collection service
Definition: GaudiTool.h:761
GaudiTool::exist
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:539
GaudiTool::existDet
bool existDet(IDataProviderSvc *svc, const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:560
GaudiTool::m_detSvc
SmartIF< IDataProviderSvc > m_detSvc
pointer to Detector Data Service
Definition: GaudiTool.h:763
GaudiTool::getOrCreate
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:611
GaudiPython.HistoUtils.location
location
Definition: HistoUtils.py:947
std::string
STL class.
IHistogramSvc
Definition: IHistogramSvc.h:56
GaudiTool::operator=
GaudiTool & operator=(const GaudiTool &)=delete
GaudiTool::existDet
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
Definition: GaudiTool.h:580
GaudiTool::put
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:234
std::move
T move(T... args)
IAlgContextSvc::currentAlg
virtual IAlgorithm * currentAlg() const =0
accessor to current algorithm:
GaudiTool::m_local
const std::string m_local
full tool name "type/name"
Definition: GaudiTool.h:784
GaudiTool::exist
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:512
GaudiTool::put
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:197
GaudiTool::GaudiTool
GaudiTool(const GaudiTool &)=delete
no copy constructor, no assignment
GaudiException
Definition: GaudiException.h:31
GaudiTool::Warning
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:698
GaudiTool::getCurrentAlgName
std::string getCurrentAlgName() const
Returns the current active algorithm name via the context service.
Definition: GaudiTool.h:750
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:18
GaudiTool::Error
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:672
GaudiTool::getIfExists
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:313
GaudiTool::get
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:274
GaudiTool::getDetIfExists
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:433
GaudiTool::getIfExists
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:382
TimingHistograms.name
name
Definition: TimingHistograms.py:23
StatusCode
Definition: StatusCode.h:65
IAlgorithm
Definition: IAlgorithm.h:38
GaudiTool::m_chronoSvc
SmartIF< IChronoStatSvc > m_chronoSvc
pointer to Chrono & Stat Service
Definition: GaudiTool.h:765
IChronoStatSvc
Definition: IChronoStatSvc.h:43
GaudiTool::Info
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:716
GaudiTool::s_enableSummary
static bool s_enableSummary
enable printout of summary?
Definition: GaudiTool.h:789
GaudiTool::m_incSvc
SmartIF< IIncidentSvc > m_incSvc
pointer to Incident Service
Definition: GaudiTool.h:767
SmartIF< INTupleSvc >
GaudiCommon::Warning
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.
Definition: GaudiCommon.icpp:275
GaudiCommon::put
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.
Definition: GaudiCommon.icpp:424
GaudiCommon::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiCommon.icpp:76
GaudiTool::getDet
TYPE * getDet(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Definition: GaudiTool.h:456
gaudirun.type
type
Definition: gaudirun.py:154
GaudiCommon::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiCommon.icpp:112
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DataObject.h
std
STL namespace.
GaudiTool::get
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:344
GaudiTool::put
const DataObject * put(std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:237
IInterface
Definition: IInterface.h:237
Gaudi::Utils::GetData::return_type
_GetType< Type >::return_type return_type
the actual return type
Definition: GetData.h:120
IAlgContextSvc
Definition: IAlgContextSvc.h:33
DataObject
Definition: DataObject.h:40
AlgTool.h
GaudiTool::m_ntupleSvc
SmartIF< INTupleSvc > m_ntupleSvc
pointer to the N-Tuple service
Definition: GaudiTool.h:759
IDataProviderSvc
Definition: IDataProviderSvc.h:53
INTupleSvc
Definition: INTupleSvc.h:46
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
GaudiCommon::Info
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.
Definition: GaudiCommon.icpp:294
IIncidentSvc
Definition: IIncidentSvc.h:33
GaudiTool::put
void put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
Definition: GaudiTool.h:201
std::unique_ptr
STL class.
GaudiTool
Definition: GaudiTool.h:110
DataObjectHandle.h
GaudiTool::getDetIfExists
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:482
GaudiTool::getOrCreate
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:642
GaudiCommon::Error
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.
Definition: GaudiCommon.icpp:256
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::Property< std::string >
GaudiTool::getDet
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
GaudiTool::m_contextSvc
SmartIF< IAlgContextSvc > m_contextSvc
Algorithm Context Service.
Definition: GaudiTool.h:771
GaudiCommon
Definition: GaudiCommon.h:95