GaudiAlgorithm.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_GaudiAlgorithm_H
2 #define GAUDIALG_GaudiAlgorithm_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 #include <vector>
7 #include <string>
8 // ============================================================================
9 // GaudiKernel
10 // ============================================================================
11 #include "GaudiKernel/Algorithm.h"
12 // ============================================================================
13 // GaudiAlg
14 // ============================================================================
15 #include "GaudiAlg/GaudiAlg.h"
16 #include "GaudiAlg/GaudiCommon.h"
18 // ============================================================================
19 // forward declarations:
20 // ============================================================================
21 class INTupleSvc ; // GaudiKernel
22 // ============================================================================
23 /* @file GaudiAlgorithm.h
24  *
25  * Header file for class GaudiAlgorithm.
26  * The actual code is mainly imported from
27  * - LHCb Calorimeter software and
28  * - LHCb C++ toolkit for smart and friendly physics analysis "LoKi"
29  *
30  * This base class allows "easy"(=="1 line") access to tools
31  * and services. This access is safe in the sense that there
32  * is no need to worry about the reference counts for tools
33  * and services.
34  *
35  * The base class allows "easy" (=="1 line") access to data in
36  * Gaudi Transient Stores. The functionality includes the checking
37  * of the presence of the data at the given location, checking the
38  * validity of the data, retrieval of valid data and "forced" retrieve
39  * of valid data (create if there is no data).
40  *
41  * The base class allows to perform an easy error, warning and exception
42  * treatments, including the accumulated statistics of exceptions, errors
43  * and warnings.
44  *
45  * The base class also includes utilities for general statistical counters.
46  *
47  * It has been reported that usage of this base class results in
48  * significant shrinkage of existing code lines.
49  *
50  * @attention
51  * See also the class GaudiCommon, which implements some of the common
52  * functionality between GaudiTool and GaudiAlgorithm.
53  *
54  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
55  * @author Chris Jones Christopher.Rob.Jones@cern.ch
56  * @date 30/06/2001
57  */
58 // ============================================================================
92 // ============================================================================
93 class GAUDI_API GaudiAlgorithm: public GaudiCommon<Algorithm>
94 {
95 public:
96  // ==========================================================================
102  StatusCode initialize() override;
103  // ==========================================================================
109  StatusCode execute () override;
110  // ==========================================================================
116  StatusCode finalize () override;
117  // ==========================================================================
124  StatusCode sysExecute () override;
125  // ==========================================================================
126 public:
127 
128  // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
129  // and detDvc() ) that are not members of AlgTool.
130  // Also some methods seem which are members of the base class do not seem
131  // to be found unless forwarding methods are put here ??
132 
165  inline void put ( IDataProviderSvc* svc ,
166  DataObject* object ,
167  const std::string& address ,
168  const bool useRootInTES = true ) const
169  {
170  GaudiCommon<Algorithm>::put ( svc , object , address , useRootInTES ) ;
171  }
172 
204  inline void put ( DataObject* object ,
205  const std::string& address ,
206  const bool useRootInTES = true ) const
207  {
208  GaudiCommon<Algorithm>::put ( evtSvc() , object , address , useRootInTES ) ;
209  }
210 
243  template < class TYPE >
246  const std::string& location ,
247  const bool useRootInTES = true ) const
248  {
249  return GaudiCommon<Algorithm>::get<TYPE> ( svc , location , useRootInTES ) ;
250  }
251 
285  template < class TYPE >
288  const std::string& location ,
289  const bool useRootInTES = true ) const
290  {
291  return GaudiCommon<Algorithm>::getIfExists<TYPE> ( svc , location , useRootInTES ) ;
292  }
293 
320  template < class TYPE >
322  get ( const std::string& location,
323  const bool useRootInTES = true ) const
324  {
325  return GaudiCommon<Algorithm>::get<TYPE> ( evtSvc() , location , useRootInTES ) ;
326  }
327 
360  template < class TYPE >
362  getIfExists ( const std::string& location ,
363  const bool useRootInTES = true ) const
364  {
365  return GaudiCommon<Algorithm>::getIfExists<TYPE> ( evtSvc() , location , useRootInTES ) ;
366  }
367 
386  template < class TYPE >
387  inline TYPE* getDet ( IDataProviderSvc* svc ,
388  const std::string& location ) const
389  {
390  return GaudiCommon<Algorithm>::get<TYPE> ( svc , location , false ) ;
391  }
392 
415  template < class TYPE >
418  const std::string& location ) const
419  {
420  return GaudiCommon<Algorithm>::getIfExists<TYPE> ( svc , location , false ) ;
421  }
422 
440  template < class TYPE >
441  inline TYPE* getDet ( const std::string& location ) const
442  {
443  return GaudiCommon<Algorithm>::get<TYPE> ( detSvc() , location , false ) ;
444  }
445 
467  template < class TYPE >
469  getDetIfExists ( const std::string& location ) const
470  {
471  return GaudiCommon<Algorithm>::getIfExists<TYPE> ( detSvc() , location , false ) ;
472  }
473 
500  template < class TYPE >
501  inline bool exist ( IDataProviderSvc* svc ,
502  const std::string& location ,
503  const bool useRootInTES = true ) const
504  {
505  return GaudiCommon<Algorithm>::exist<TYPE> ( svc , location , useRootInTES ) ;
506  }
507 
533  template < class TYPE >
534  inline bool exist ( const std::string& location ,
535  const bool useRootInTES = true ) const
536  {
537  return GaudiCommon<Algorithm>::exist<TYPE> ( evtSvc() , location , useRootInTES ) ;
538  }
539 
556  template < class TYPE >
557  inline bool existDet ( IDataProviderSvc* svc ,
558  const std::string& location ) const
559  {
560  return GaudiCommon<Algorithm>::exist<TYPE> ( svc , location , false ) ;
561  }
562 
578  template < class TYPE >
579  inline bool existDet ( const std::string& location ) const
580  {
581  return GaudiCommon<Algorithm>::exist<TYPE> ( detSvc() , location , false ) ;
582  }
583 
611  template < class TYPE , class TYPE2 >
614  const std::string& location ,
615  const bool useRootInTES = true ) const
616  {
617  return GaudiCommon<Algorithm>::getOrCreate<TYPE,TYPE2> ( svc , location , useRootInTES ) ;
618  }
619 
646  template < class TYPE , class TYPE2 >
648  getOrCreate ( const std::string& location ,
649  const bool useRootInTES = true ) const
650  {
651  return GaudiCommon<Algorithm>::getOrCreate<TYPE,TYPE2> ( evtSvc() , location , useRootInTES ) ;
652  }
653 public:
654  // ==========================================================================
660  GaudiAlgorithm ( const std::string& name ,
661  ISvcLocator* pSvcLocator );
662  // ==========================================================================
664  ~GaudiAlgorithm() override = default;
665  // ==========================================================================
666 public:
667  // ==========================================================================
671  SmartIF<INTupleSvc>& evtColSvc () const;
672  // ==========================================================================
673  // no default/copy constructor, no assignment -- except that ROOT really
674  // wants a default constructor declared. So we define it, and don't implement
675  // it...
676  GaudiAlgorithm ( const GaudiAlgorithm& ) = delete;
677  GaudiAlgorithm& operator = ( const GaudiAlgorithm& ) = delete;
678 private :
679  GaudiAlgorithm() ;
680  // ==========================================================================
681 private:
682  // ==========================================================================
683  // Pointer to the Event Tag Collection Service
685  std::vector<std::string> m_vetoObjs;
689  // ==========================================================================
690 
691  public:
693  template <class T>
694  Property* declareProperty
695  ( const std::string& name,
696  DataObjectHandle<T>& hndl,
697  const std::string& doc = "none" ) const
698  {
699 
700  if ( hndl.mode() & Gaudi::DataHandle::Reader ) {
701  (const_cast<GaudiAlgorithm*>(this))->Algorithm::declareInput(&hndl);
702  }
703 
704  if ( hndl.mode() & Gaudi::DataHandle::Writer ) {
705  (const_cast<GaudiAlgorithm*>(this))->Algorithm::declareOutput(&hndl);
706  }
707 
708  if (hndl.owner() == 0) {
709  hndl.setOwner((const_cast<GaudiAlgorithm*>(this)));
710  }
711 
712  return m_propertyMgr->declareProperty(name, hndl, doc);
713  }
714 
715 };
716 // ============================================================================
717 // The END
718 // ============================================================================
719 #endif // GAUDIALG_GaudiAlgorithm_H
720 // ============================================================================
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.
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.
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
virtual void setOwner(IDataHandleHolder *o)
Definition: DataHandle.h:44
DataObject * put(IDataProviderSvc *svc, DataObject *object, const std::string &location, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
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.
virtual Mode mode() const
Definition: DataHandle.h:47
TYPE * getDet(IDataProviderSvc *svc, const std::string &location) const
Templated access to the detector data from the Gaudi Detector 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.
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Algorithm.h:426
TYPE * getDet(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
Helper structure for implementation of "get"-functions for GaudiCommon
Definition: GaudiCommon.h:36
StatusCode finalize() override
standard finalization method
Data provider interface definition.
bool existDet(const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
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.
bool existDet(IDataProviderSvc *svc, const std::string &location) const
Check the existence of detector objects in the Gaudi Transient Detector Store.
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.
STL class.
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
Definition: AlgTool.h:24
Gaudi::Utils::GetData< TYPE >::return_type getDetIfExists(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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.
The useful base class for data processing algorithms.
void put(DataObject *object, const std::string &address, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
StatusCode initialize() override
standard initialization method
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.
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
GaudiCommon & operator=(const GaudiCommon &)=delete
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:73
std::vector< std::string > m_requireObjs
process the event only if one or more of these objects are present in TES
#define GAUDI_API
Definition: Kernel.h:107
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:45
SmartIF< SERVICE > svc(const std::string &name, const bool create=true) const
A useful method for the easy location of services.