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"
17 // ============================================================================
18 // forward declarations:
19 // ============================================================================
20 class INTupleSvc ; // GaudiKernel
21 // ============================================================================
22 /* @file GaudiAlgorithm.h
23  *
24  * Header file for class GaudiAlgorithm.
25  * The actual code is mainly imported from
26  * - LHCb Calorimeter software and
27  * - LHCb C++ toolkit for smart and friendly physics analysis "LoKi"
28  *
29  * This base class allows "easy"(=="1 line") access to tools
30  * and services. This access is safe in the sense that there
31  * is no need to worry about the reference counts for tools
32  * and services.
33  *
34  * The base class allows "easy" (=="1 line") access to data in
35  * Gaudi Transient Stores. The functionality includes the checking
36  * of the presence of the data at the given location, checking the
37  * validity of the data, retrieval of valid data and "forced" retrieve
38  * of valid data (create if there is no data).
39  *
40  * The base class allows to perform an easy error, warning and exception
41  * treatments, including the accumulated statistics of exceptions, errors
42  * and warnings.
43  *
44  * The base class also includes utilities for general statistical counters.
45  *
46  * It has been reported that usage of this base class results in
47  * significant shrinkage of existing code lines.
48  *
49  * @attention
50  * See also the class GaudiCommon, which implements some of the common
51  * functionality between GaudiTool and GaudiAlgorithm.
52  *
53  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
54  * @author Chris Jones Christopher.Rob.Jones@cern.ch
55  * @date 30/06/2001
56  */
57 // ============================================================================
91 // ============================================================================
92 class GAUDI_API GaudiAlgorithm: public GaudiCommon<Algorithm>
93 {
94 public:
95  // ==========================================================================
101  StatusCode initialize() override;
102  // ==========================================================================
108  StatusCode execute () override;
109  // ==========================================================================
115  StatusCode finalize () override;
116  // ==========================================================================
123  StatusCode sysExecute () override;
124  // ==========================================================================
125 public:
126 
127  // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
128  // and detDvc() ) that are not members of AlgTool.
129  // Also some methods seem which are members of the base class do not seem
130  // to be found unless forwarding methods are put here ??
131 
164  inline void put ( IDataProviderSvc* svc ,
165  DataObject* object ,
166  const std::string& address ,
167  const bool useRootInTES = true ) const
168  {
169  GaudiCommon<Algorithm>::put ( svc , object , address , useRootInTES ) ;
170  }
171 
203  inline void put ( DataObject* object ,
204  const std::string& address ,
205  const bool useRootInTES = true ) const
206  {
207  GaudiCommon<Algorithm>::put ( evtSvc() , object , address , useRootInTES ) ;
208  }
209 
242  template < class TYPE >
245  const std::string& location ,
246  const bool useRootInTES = true ) const
247  {
248  return GaudiCommon<Algorithm>::get<TYPE> ( svc , location , useRootInTES ) ;
249  }
250 
284  template < class TYPE >
287  const std::string& location ,
288  const bool useRootInTES = true ) const
289  {
290  return GaudiCommon<Algorithm>::getIfExists<TYPE> ( svc , location , useRootInTES ) ;
291  }
292 
319  template < class TYPE >
321  get ( const std::string& location,
322  const bool useRootInTES = true ) const
323  {
324  return GaudiCommon<Algorithm>::get<TYPE> ( evtSvc() , location , useRootInTES ) ;
325  }
326 
359  template < class TYPE >
361  getIfExists ( const std::string& location ,
362  const bool useRootInTES = true ) const
363  {
364  return GaudiCommon<Algorithm>::getIfExists<TYPE> ( evtSvc() , location , useRootInTES ) ;
365  }
366 
385  template < class TYPE >
386  inline TYPE* getDet ( IDataProviderSvc* svc ,
387  const std::string& location ) const
388  {
389  return GaudiCommon<Algorithm>::get<TYPE> ( svc , location , false ) ;
390  }
391 
414  template < class TYPE >
417  const std::string& location ) const
418  {
419  return GaudiCommon<Algorithm>::getIfExists<TYPE> ( svc , location , false ) ;
420  }
421 
439  template < class TYPE >
440  inline TYPE* getDet ( const std::string& location ) const
441  {
442  return GaudiCommon<Algorithm>::get<TYPE> ( detSvc() , location , false ) ;
443  }
444 
466  template < class TYPE >
468  getDetIfExists ( const std::string& location ) const
469  {
470  return GaudiCommon<Algorithm>::getIfExists<TYPE> ( detSvc() , location , false ) ;
471  }
472 
499  template < class TYPE >
500  inline bool exist ( IDataProviderSvc* svc ,
501  const std::string& location ,
502  const bool useRootInTES = true ) const
503  {
504  return GaudiCommon<Algorithm>::exist<TYPE> ( svc , location , useRootInTES ) ;
505  }
506 
532  template < class TYPE >
533  inline bool exist ( const std::string& location ,
534  const bool useRootInTES = true ) const
535  {
536  return GaudiCommon<Algorithm>::exist<TYPE> ( evtSvc() , location , useRootInTES ) ;
537  }
538 
555  template < class TYPE >
556  inline bool existDet ( IDataProviderSvc* svc ,
557  const std::string& location ) const
558  {
559  return GaudiCommon<Algorithm>::exist<TYPE> ( svc , location , false ) ;
560  }
561 
577  template < class TYPE >
578  inline bool existDet ( const std::string& location ) const
579  {
580  return GaudiCommon<Algorithm>::exist<TYPE> ( detSvc() , location , false ) ;
581  }
582 
610  template < class TYPE , class TYPE2 >
613  const std::string& location ,
614  const bool useRootInTES = true ) const
615  {
616  return GaudiCommon<Algorithm>::getOrCreate<TYPE,TYPE2> ( svc , location , useRootInTES ) ;
617  }
618 
645  template < class TYPE , class TYPE2 >
647  getOrCreate ( const std::string& location ,
648  const bool useRootInTES = true ) const
649  {
650  return GaudiCommon<Algorithm>::getOrCreate<TYPE,TYPE2> ( evtSvc() , location , useRootInTES ) ;
651  }
652 public:
653  // ==========================================================================
659  GaudiAlgorithm ( const std::string& name ,
660  ISvcLocator* pSvcLocator );
661  // ==========================================================================
663  ~GaudiAlgorithm() override = default;
664  // ==========================================================================
665 public:
666  // ==========================================================================
670  SmartIF<INTupleSvc>& evtColSvc () const;
671  // ==========================================================================
672  // no default/copy constructor, no assignment -- except that ROOT really
673  // wants a default constructor declared. So we define it, and don't implement
674  // it...
675  GaudiAlgorithm ( const GaudiAlgorithm& ) = delete;
676  GaudiAlgorithm& operator = ( const GaudiAlgorithm& ) = delete;
677 private :
678  GaudiAlgorithm() ;
679  // ==========================================================================
680 private:
681  // ==========================================================================
682  // Pointer to the Event Tag Collection Service
684  std::vector<std::string> m_vetoObjs;
687  std::vector<std::string> m_requireObjs;
688  // ==========================================================================
689 };
690 // ============================================================================
691 // The END
692 // ============================================================================
693 #endif // GAUDIALG_GaudiAlgorithm_H
694 // ============================================================================
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.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
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.
#define GAUDI_API
Definition: Kernel.h:107
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.
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.
Gaudi::Utils::GetData< TYPE >::return_type getDetIfExists(const std::string &location) const
Templated access to the detector data from the Gaudi Detector Transient Store.
std::vector< std::string > m_requireObjs
process the event only if one or more of these objects are present in TES
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
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.
GaudiCommon & operator=(const GaudiCommon &)=delete
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:73
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
SmartIF< SERVICE > svc(const std::string &name, const bool create=true) const
A useful method for the easy location of services.