| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

GiGaCnvBase.h

Go to the documentation of this file.
00001 // $Id: GiGaCnvBase.h,v 1.14 2007/11/08 15:29:04 gcorti Exp $ 
00002 #ifndef GIGA_GIGACNVBASE_H 
00003 #define GIGA_GIGACNVBASE_H  1 
00004 
00005 // Include files
00006 // from STL 
00007 #include <string> 
00008 #include <vector> 
00009 #include <map> 
00010 #include <exception> 
00011 
00012 // from Gaudi 
00013 #include "GaudiKernel/IDataProviderSvc.h" 
00014 #include "GaudiKernel/IToolSvc.h" 
00015 #include "GaudiKernel/Converter.h" 
00016 #include "GaudiKernel/MsgStream.h" 
00017 #include "GaudiKernel/SmartDataPtr.h" 
00018 #include "GaudiKernel/System.h" 
00019 
00020 // from GiGa
00021 #include "GiGaCnv/IGiGaCnvSvc.h" 
00022 #include "GiGaCnv/IGiGaCnvSvcLocation.h" 
00023 #include "GiGaCnv/IGiGaKineCnvSvc.h" 
00024 #include "GiGaCnv/GiGaLeaf.h" 
00025 
00026 // forward declarations
00027 class IDataProviderSvc     ;
00028 class IMessageSvc          ; 
00029 class IChronoStatSvc       ; 
00030 class IToolSvc             ; 
00031 class IParticlePropertySvc ; 
00032 class IGiGaSvc             ;   
00033 class IGiGaSetUpSvc        ;
00034 //
00035 class GaudiException       ; 
00036 //
00037 class IGiGaGeomCnvSvc      ;
00038 class IGiGaHitsCnvSvc      ; 
00039 
00040 
00049 class GiGaCnvBase: public Converter 
00050 {
00051 public:
00052   typedef std::vector<GiGaLeaf> Leaves;
00053   
00054 protected: 
00055   
00061   GiGaCnvBase
00062   ( const long  StorageType , 
00063     const CLID&          ClassType   , 
00064     ISvcLocator*         Locator     );
00065   
00067   virtual ~GiGaCnvBase();
00069 public: 
00070   long repSvcType() const
00071   { return i_repSvcType(); }
00072   
00078   virtual StatusCode initialize () ; 
00079   
00085   virtual StatusCode finalize   () ;
00086   
00087 protected: 
00088 
00092   inline ISvcLocator*          svcLoc    () const 
00093   { return serviceLocator ()                          ; }
00094   
00098   inline IGiGaCnvSvc*          cnvSvc    () const 
00099   { return m_GiGaCnvSvc                               ; } 
00100   
00104   inline IGiGaGeomCnvSvc*      geoSvc    () const 
00105   { return m_GiGaGeomCnvSvc                           ; } 
00106   
00110   inline IGiGaKineCnvSvc*      kineSvc   () const 
00111   { return m_GiGaKineCnvSvc                           ; } 
00112   
00116   inline IGiGaHitsCnvSvc*      hitsSvc   () const 
00117   { return m_GiGaHitsCnvSvc                           ; }
00118   
00122   inline IDataProviderSvc*     evtSvc    () const 
00123   { return m_evtSvc                                   ; }   
00124   
00128   inline IDataProviderSvc*     detSvc    () const 
00129   { return m_detSvc                                   ; }
00130   
00131   
00135   inline IChronoStatSvc*       chronoSvc () const 
00136   { return m_chronoSvc                                ; } 
00137 
00141   inline IToolSvc*             toolSvc   () const 
00142   { return m_toolSvc                                  ; } 
00143   
00147   inline IGiGaSvc*             gigaSvc   () const 
00148   { return 0 != cnvSvc () ? cnvSvc ()->gigaSvc () : 0 ; }
00149 
00153   inline IGiGaSetUpSvc*        setupSvc  () const 
00154   { return 0 != cnvSvc () ? cnvSvc ()->setupSvc() : 0 ; } 
00155   
00159   inline IParticlePropertySvc* ppSvc     () const 
00160   { return 0 != kineSvc() ? kineSvc()->ppSvc   () : 0 ; }
00161 
00162 
00190   template<class TYPE>
00191   TYPE* 
00192   get
00193   ( IDataProviderSvc*  svc        , 
00194     const std::string& location   ,
00195     const TYPE*        /* type */ ) const 
00196   {
00197     // check the environment 
00198     Assert( 0 != svc   , "  get():: IDataProvider* points to NULL!"      );
00199     SmartDataPtr<TYPE> object( svc, location ) ;
00200     Assert( !(!object) ,  " get():: No valid data at '" + location + "'" );
00201     TYPE* aux = object ;
00202     Assert( 0 != aux   ,  " get():: No valid data at '" + location + "'" );
00203     const std::string type( System::typeinfoName( typeid( *aux ) ) );
00204     // debug printout 
00205     // return located valid data 
00206     Print( " The data from address '"     + location + 
00207            "' are retrieved from TS "     ,
00208            StatusCode::SUCCESS ,  MSG::DEBUG ) ;
00209     Print( " [ The actual data type is '" + type     + 
00210            "' ] "                         ,
00211            StatusCode::SUCCESS  , MSG::DEBUG ) ;
00212     return aux ;
00213   };
00214   
00230   template<class TOOL>
00231   TOOL* 
00232   tool
00233   ( const std::string& type           , 
00234     const std::string& name           , 
00235     TOOL*&             Tool           , 
00236     const IInterface*  parent  = 0    , 
00237     bool               create  = true ) const 
00238   {
00239     // for empty names delegate to another method 
00240     if( name.empty() ) { return tool( type , Tool , parent , create ) ; }
00241     Assert( 0 != toolSvc() , "IToolSvc* points toNULL!" );
00242     // get the tool from Tool Service 
00243     StatusCode sc = toolSvc () 
00244       -> retrieveTool ( type , name , Tool, parent , create );
00245     Assert( sc.isSuccess() , 
00246             "Could not retrieve Tool'" + type + "'/'" + name + "'", sc ) ;
00247     Assert( 0 != Tool      , 
00248             "Could not retrieve Tool'" + type + "'/'" + name + "'"     ) ;
00249     // debug printout 
00250     Print( " The Tool of type '" + Tool->type() + 
00251            "'/'"                 + Tool->name() + 
00252            "' is retrieved from IToolSvc " , MSG::DEBUG  , sc ) ;
00253     // return located tool 
00254     return Tool ;
00255   };
00256 
00270   template<class TOOL>
00271   TOOL* 
00272   tool
00273   ( const std::string& type          , 
00274     TOOL*&             Tool          , 
00275     const IInterface*  parent = 0    , 
00276     bool               create = true ) const
00277   {
00278     // check the environment 
00279     Assert( 0 != toolSvc() , "IToolSvc* points toNULL!" );
00280     // "type" or "type/name" ?
00281     std::string::const_iterator it = 
00282       std::find( type.begin() , type.end () , '/' );
00283     // "type" is compound!
00284     if( type.end() != it ) 
00285       {
00286         std::string::size_type pos = it - type.begin()   ;
00287         const std::string ntype( type , 0       , pos               );
00288         const std::string nname( type , pos + 1 , std::string::npos );
00289         return tool( ntype , // new type 
00290                      nname , // new name 
00291                      Tool , parent , create            ) ;
00292       }
00293     // retrieve the tool from Tool Service 
00294     StatusCode sc = toolSvc () 
00295       -> retrieveTool ( type , Tool, parent , create   );
00296     Assert( sc.isSuccess() , "Could not retrieve Tool'" + type + "'" , sc ) ;
00297     Assert( 0 != Tool      , "Could not retrieve Tool'" + type + "'"      ) ;
00298     // debug printout 
00299     Print( " The Tool of type '" + Tool->type() + 
00300            "'/'"                 + Tool->name() + 
00301            "' is retrieved from IToolSvc " , MSG::DEBUG , sc ) ;
00302     // return located tool 
00303     return Tool ;
00304   };
00305 
00311   StatusCode Error     
00312   ( const std::string& Message                       , 
00313     const StatusCode& status   = StatusCode::FAILURE , 
00314     const size_t      mx       = 10                  ) const ;
00315   
00321   StatusCode Warning     
00322   ( const std::string& Message                       , 
00323     const StatusCode&  status  = StatusCode::FAILURE , 
00324     const size_t       mx      = 10                  ) const ;
00325   
00332   StatusCode Print
00333   ( const std::string& Message                       , 
00334     const StatusCode & Status  = StatusCode::SUCCESS ,
00335     const MSG::Level & level   = MSG::INFO           ) const  ;
00336     
00344   StatusCode Exception 
00345   ( const std::string    & msg                       ,   
00346     const GaudiException & exc                       , 
00347     const MSG::Level     & lvl = MSG::FATAL          ,
00348     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00349   
00357   StatusCode Exception 
00358   ( const std::string    & msg                       ,  
00359     const std::exception & exc                       , 
00360     const MSG::Level     & lvl = MSG::FATAL          ,
00361     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00362   
00369   StatusCode Exception 
00370   ( const std::string    & msg                       ,  
00371     const MSG::Level     & lvl = MSG::FATAL          ,
00372     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00373   
00380   inline StatusCode Assert
00381   ( bool  assertion                                  , 
00382     const std::string& msg = "GiGaCnvBase::unknown"  , 
00383     const StatusCode&  sc  = StatusCode::FAILURE     ) const ;
00384   
00391   inline StatusCode Assert
00392   ( bool  assertion                              ,
00393     const char*        msg                       ,
00394     const StatusCode&  sc  = StatusCode::FAILURE ) const ;
00395   
00396 
00400   inline const std::string&  name     () const { return m_ConverterName; } 
00401 
00403   inline void setNameOfGiGaConversionService
00404   ( const std::string& CnvSvc ) 
00405   { m_NameOfGiGaConversionService = CnvSvc ; }                     
00406   
00408   void setConverterName 
00409   ( const std::string& ConverterName ) 
00410   { m_ConverterName  = ConverterName ; } 
00411   
00416   StatusCode declareObject ( const GiGaLeaf&   leaf );
00418 protected: 
00420   std::string           m_NameOfGiGaConversionService ; 
00421   std::string           m_ConverterName               ;
00423   Leaves                m_leaves                      ;
00425 private:
00427   IGiGaCnvSvc*          m_GiGaCnvSvc                  ; 
00428   IGiGaGeomCnvSvc*      m_GiGaGeomCnvSvc              ; 
00429   IGiGaKineCnvSvc*      m_GiGaKineCnvSvc              ; 
00430   IGiGaHitsCnvSvc*      m_GiGaHitsCnvSvc              ; 
00432   IDataProviderSvc*     m_evtSvc                      ; 
00433   IDataProviderSvc*     m_detSvc                      ; 
00434   IChronoStatSvc*       m_chronoSvc                   ; 
00435   IToolSvc*             m_toolSvc                     ; 
00437   CLID                  m_local ;
00439   typedef std::map<std::string,unsigned int> Counter;
00441   mutable Counter m_errors     ;
00443   mutable Counter m_warnings   ; 
00445   mutable Counter m_exceptions ;
00446   
00447   
00448 };
00449 
00450 // ============================================================================
00456 // ============================================================================
00457 inline StatusCode  GiGaCnvBase::Assert
00458 ( bool               assertion , 
00459   const std::string& msg       , 
00460   const StatusCode&  sc        ) const 
00461 {  
00462   StatusCode status = StatusCode::SUCCESS ;
00463   return (assertion) ? status : Exception( msg , MSG::FATAL , sc ) ;
00464 };
00465 // ============================================================================
00466 
00467 // ============================================================================
00473 // ============================================================================
00474 inline StatusCode  GiGaCnvBase::Assert
00475 ( bool               assertion , 
00476   const char*        msg       , 
00477   const StatusCode&  sc        ) const 
00478 { 
00479   StatusCode status = StatusCode::SUCCESS ;
00480   return (assertion) ? status : Exception( msg , MSG::FATAL , sc ) ;
00481 };
00482 // ============================================================================
00483 
00484 // ============================================================================
00485 // End 
00486 // ============================================================================
00487 #endif    //      GIGA_GIGACNVBASE_H 
00488 // ============================================================================
00489 
00490 
00491 
00492 
00493 
00494 
00495 
00496 
00497 
00498 
00499 
00500 
00501 
00502 
00503 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:03:52 2011 for GiGaCnv by doxygen 1.4.7