| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# GaudiAlgorithm.h

Go to the documentation of this file.

    00001 // $Id: GaudiAlgorithm.h,v 1.19 2008/11/04 22:49:25 marcocle Exp $
    00002 // ============================================================================
    00003 #ifndef GAUDIALG_GaudiAlgorithm_H
    00004 #define GAUDIALG_GaudiAlgorithm_H 1
    00005 // ============================================================================
    00006 // Include files
    00007 // ============================================================================
    00008 #include <vector>
    00009 #include <string>
    00010 // ============================================================================
    00011 // GaudiKernel
    00012 // ============================================================================
    00013 #include "GaudiKernel/Algorithm.h"
    00014 // ============================================================================
    00015 // GaudiAlg
    00016 // ============================================================================
    00017 #include "GaudiAlg/GaudiAlg.h"
    00018 #include "GaudiAlg/GaudiCommon.h"
    00019 // ============================================================================
    00020 // forward declarations:
    00021 // ============================================================================
    00022 class                   INTupleSvc     ; // GaudiKernel
    00023 class                   IAlgContextSvc ; // GaudiKernel
    00024 template<class T> class  AlgFactory    ; // GaudiKernel
    00025 // ============================================================================
    00026 /* @file GaudiAlgorithm.h
    00027  *
    00028  * Header file for class GaudiAlgorithm.
    00029  * The actual code is mainly imported from
    00030  *   - LHCb Calorimeter software and
    00031  *   - LHCb C++ toolkit for smart and friendly physics analysis "LoKi"
    00032  *
    00033  *  This base class allows "easy"(=="1 line") access to tools
    00034  *  and services. This access is safe in the sense that there
    00035  *  is no need to worry about the reference counts for tools
    00036  *  and services.
    00037  *
    00038  *  The base class allows "easy" (=="1 line") access to data in
    00039  *  Gaudi Transient Stores. The functionality includes the checking
    00040  *  of the presence of the data at the given location, checking the
    00041  *  validity of the data, retrieval of valid data and "forced" retrive
    00042  *  of valid data (create if there is no data).
    00043  *
    00044  *  The base class allows to perform an easy error, warning and exception
    00045  *  treatments, including the accumulated statistics of exceptions, errors
    00046  *  and warnings.
    00047  *
    00048  *  The base class also includes utilities for general statistical counters.
    00049  *
    00050  *  It has been reported that usage of this base class results in
    00051  *  significant shrinkage of existing code lines.
    00052  *
    00053  *  @attention
    00054  *  See also the class GaudiCommon, which implements some of the common
    00055  *  functionality between GaudiTool and GaudiAlgorithm.
    00056  *
    00057  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
    00058  *  @author Chris Jones   Christopher.Rob.Jones@cern.ch
    00059  *  @date 30/06/2001
    00060  */
    00061 // ============================================================================
    00095 // ============================================================================
    00096 class GaudiAlgorithm : public GaudiCommon<Algorithm>
    00097 {
    00098   // friend factory for instantiation
    00099   friend class AlgFactory<GaudiAlgorithm>;
    00100 public:
    00101   // ==========================================================================
    00107   virtual StatusCode initialize();
    00108   // ==========================================================================
    00114   virtual StatusCode execute   ();
    00115   // ==========================================================================
    00121   virtual StatusCode finalize  ();
    00122   // ==========================================================================
    00129   virtual StatusCode sysExecute () ;
    00130   // ==========================================================================
    00131 public:
    00132
    00133   // following methods cannot go in GaudiCommon since they use methods ( evtSvc()
    00134   // and detDvc() ) that are not members of AlgTool.
    00135   // Also some methods seem which are members of the base class do not seem
    00136   // to be found unless forwarding methods are put here ??
    00137
    00170   inline void put ( IDataProviderSvc*  svc     ,
    00171                     DataObject*        object  ,
    00172                     const std::string& address ,
    00173                     const bool useRootInTES = true ) const
    00174   {
    00175     GaudiCommon<Algorithm>::put ( svc , object , address , useRootInTES ) ;
    00176   }
    00177
    00209   inline void put ( DataObject*        object   ,
    00210                     const std::string& address  ,
    00211                     const bool useRootInTES = true ) const
    00212   {
    00213     GaudiCommon<Algorithm>::put ( evtSvc() , object , address , useRootInTES ) ;
    00214   }
    00215
    00248   template < class TYPE  >
    00249   inline typename Gaudi::Utils::GetData<TYPE>::return_type
    00250   get  ( IDataProviderSvc*  svc       ,
    00251          const std::string& location  ,
    00252          const bool useRootInTES = true ) const
    00253   {
    00254     return GaudiCommon<Algorithm>::get<TYPE> ( svc , location , useRootInTES ) ;
    00255   }
    00256
    00283   template < class TYPE  >
    00284   inline typename Gaudi::Utils::GetData<TYPE>::return_type
    00285   get  ( const std::string& location,
    00286          const bool useRootInTES = true ) const
    00287   {
    00288     return GaudiCommon<Algorithm>::get<TYPE> ( evtSvc() , location , useRootInTES ) ;
    00289   }
    00290
    00309   template < class TYPE  >
    00310   inline TYPE* getDet ( IDataProviderSvc*  svc        ,
    00311                         const std::string& location   ) const
    00312   {
    00313     return GaudiCommon<Algorithm>::get<TYPE> ( svc , location , false ) ;
    00314   }
    00315
    00333   template < class TYPE  >
    00334   inline TYPE* getDet ( const std::string& location   ) const
    00335   {
    00336     return GaudiCommon<Algorithm>::get<TYPE> ( detSvc() , location , false ) ;
    00337   }
    00338
    00365   template < class TYPE  >
    00366   inline bool  exist    ( IDataProviderSvc*  svc      ,
    00367                           const std::string& location ,
    00368                           const bool useRootInTES = true ) const
    00369   {
    00370     return GaudiCommon<Algorithm>::exist<TYPE> ( svc , location , useRootInTES ) ;
    00371   }
    00372
    00398   template < class TYPE  >
    00399   inline bool  exist    ( const std::string& location ,
    00400                           const bool useRootInTES = true ) const
    00401   {
    00402     return GaudiCommon<Algorithm>::exist<TYPE> ( evtSvc() , location , useRootInTES ) ;
    00403   }
    00404
    00421   template < class TYPE  >
    00422   inline bool  existDet    ( IDataProviderSvc*  svc      ,
    00423                              const std::string& location ) const
    00424   {
    00425     return GaudiCommon<Algorithm>::exist<TYPE> ( svc , location , false ) ;
    00426   }
    00427
    00443   template < class TYPE  >
    00444   inline bool  existDet    ( const std::string& location ) const
    00445   {
    00446     return GaudiCommon<Algorithm>::exist<TYPE> ( detSvc() , location , false ) ;
    00447   }
    00448
    00476   template < class TYPE , class TYPE2 >
    00477   inline TYPE* getOrCreate ( IDataProviderSvc*  svc      ,
    00478                              const std::string& location ,
    00479                              const bool useRootInTES = true ) const
    00480   {
    00481     return GaudiCommon<Algorithm>::getOrCreate<TYPE,TYPE2> ( svc , location , useRootInTES ) ;
    00482   }
    00483
    00510   template < class TYPE , class TYPE2 >
    00511   inline TYPE* getOrCreate ( const std::string& location ,
    00512                              const bool useRootInTES = true ) const
    00513   {
    00514     return GaudiCommon<Algorithm>::getOrCreate<TYPE,TYPE2> ( evtSvc() , location , useRootInTES ) ;
    00515   }
    00516 public:
    00517   // ==========================================================================
    00523   GaudiAlgorithm ( const std::string& name        ,
    00524                    ISvcLocator*       pSvcLocator );
    00525   // ==========================================================================
    00527   virtual ~GaudiAlgorithm();
    00528   // ==========================================================================
    00529 public:
    00530   // ==========================================================================
    00532   inline bool registerContext() const { return m_registerContext ; }
    00533   // ==========================================================================
    00534 public:
    00535   // ==========================================================================
    00539   INTupleSvc*     evtColSvc  () const;
    00540   // ==========================================================================
    00544   IAlgContextSvc* contextSvc () const;
    00545   // ==========================================================================
    00546 private:
    00547   // ==========================================================================
    00548   // no public default constructor
    00549   GaudiAlgorithm();
    00550   // ==========================================================================
    00551   // no public copy constructor
    00552   GaudiAlgorithm             ( const GaudiAlgorithm& );
    00553   // ==========================================================================
    00554   // no public assignment operator
    00555   GaudiAlgorithm& operator = ( const GaudiAlgorithm& );
    00556   // ==========================================================================
    00557 private:
    00558   // ==========================================================================
    00559   // Pointer to the Event Tag Collection Service
    00560   mutable INTupleSvc*     m_evtColSvc      ;
    00561   // Pointer to the Algorithm Context Service
    00562   mutable IAlgContextSvc* m_contextSvc     ;
    00563   // The name of the Algorithm Context Service
    00564   std::string             m_contextSvcName ;
    00565   // enforce the algorithm registration for Algorithm Context Service
    00566   bool    m_registerContext ;
    00567
    00568   std::vector<std::string> m_vetoObjs;
    00570   std::vector<std::string> m_requireObjs;
    00571
    00572   // ==========================================================================
    00573 };
    00574 // ============================================================================
    00575 // The END
    00576 // ============================================================================
    00577 #endif // GAUDIALG_GaudiAlgorithm_H
    00578 // ============================================================================
    00579
    00580