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

In This Package:

GiGaCnvSvcBase.h

Go to the documentation of this file.
00001 // $Id: GiGaCnvSvcBase.h,v 1.15 2008/05/30 13:13:17 gcorti Exp $ 
00002 #ifndef      GIGA_GIGACNVSVCBASE_H 
00003 #define      GIGA_GIGACNVSVCBASE_H  1 
00004 
00005 // Include files
00006 // from STL 
00007 #include <string> 
00008 #include <vector> 
00009 #include <exception> 
00010 #include <map> 
00011 // from Gaudi - base class and interafces 
00012 #include "GaudiKernel/IIncidentListener.h" 
00013 #include "GaudiKernel/IDataProviderSvc.h" 
00014 #include "GaudiKernel/IToolSvc.h" 
00015 #include "GaudiKernel/System.h"
00016 #include "GaudiKernel/SmartDataPtr.h"
00017 #include "GaudiKernel/ConversionSvc.h"
00018 // from GiGa 
00019 #include "GiGaCnv/IGiGaCnvSvc.h" 
00020 #include "GiGaCnv/GiGaLeaf.h" 
00021 #include "GiGa/IGiGaSvc.h"
00022 #include "GiGa/IGiGaSetUpSvc.h"
00023 #include "GaudiKernel/GaudiException.h"
00024 
00025 // Forward declarations
00026 class IDataProviderSvc     ; 
00027 class IParticlePropertySvc ; 
00028 class IMagneticFieldSvc    ; 
00029 class IChronoStatSvc       ; 
00030 class IToolSvc             ; 
00031 class IIncidentSvc         ; 
00032 class ISvcLocator          ;
00033 //class GaudiException       ;
00034 
00035 
00045 class GiGaCnvSvcBase: virtual public  IGiGaCnvSvc       ,
00046                       virtual public  IIncidentListener ,       
00047                       public          ConversionSvc
00048 {
00049 public:
00050 
00051   typedef std::vector<GiGaLeaf> Leaves;
00052 
00053 protected:
00054   
00060   GiGaCnvSvcBase( const std::string&   ServiceName       , 
00061                   ISvcLocator*         ServiceLocator    ,
00062                   const unsigned int   StorageType       ) ;
00063 
00065   virtual ~GiGaCnvSvcBase();
00066 
00067 public: 
00068 
00072   virtual StatusCode initialize     (); 
00073 
00077   virtual StatusCode finalize       ();
00079   virtual StatusCode queryInterface ( const InterfaceID& , void**  );
00081   virtual StatusCode declareObject  ( const GiGaLeaf& Leaf );
00083   virtual void       handle         ( const Incident&      );
00086   virtual IGiGaSvc* gigaSvc   ()  const {
00087     if( m_gigaSvc == 0 ) {
00088       StatusCode status = serviceLocator()->service( m_gigaName, m_gigaSvc, 
00089                                                      true );
00090       if( status.isFailure() ) { 
00091         //FIXME Throw exception
00092         Error("Initialize::Could not locate IGiGaSvc=" + m_gigaName, status );
00093       }       
00094       if( 0 == gigaSvc() ) {
00095         Error("Initialize::Could not locate IGiGaSvc=" + m_gigaName );
00096       }
00097       Print( " Located GiGa Service="+m_gigaName, MSG::VERBOSE ); 
00098     } 
00099     return m_gigaSvc; 
00100   }  
00101   
00103   virtual IGiGaSetUpSvc*    setupSvc  ()  const {
00104     
00105     if( m_setupSvc == 0 ) {
00106       StatusCode status = serviceLocator()->service( m_setupName, m_setupSvc, 
00107                                                      true );
00108       if( status.isFailure() ){ 
00109         Error("Initialize::Could not locate IGiGaSetUpSvc=" + 
00110               m_setupName, status );
00111       }      
00112       if( 0 == setupSvc() ) { 
00113         Error("Initialize::Could not locate IGiGaSetUpSvc=" + 
00114               m_setupName );
00115       }
00116       Print( " Located GiGa SetUp Service="+m_setupName, MSG::VERBOSE ); 
00117     } 
00118     return m_setupSvc;
00119   } 
00120   
00124   virtual StatusCode registerGiGaLeaves() ;
00125   
00140   virtual StatusCode createAddress
00141   ( long                  svc_type ,
00142     const CLID&           clid     ,
00143     const std::string*    par      , 
00144     const unsigned long*  ip       ,
00145     IOpaqueAddress*&      address  ) ;
00146   
00147 protected:
00150   inline IDataProviderSvc* dpSvc     ()  const { return m_dpSvc       ; }  
00152   inline IDataProviderSvc* evtSvc    ()  const { return m_evtSvc      ; }  
00154   inline IDataProviderSvc* detSvc    ()  const { return m_detSvc      ; }  
00156   inline IChronoStatSvc*   chronoSvc ()  const { return m_chronoSvc   ; } 
00158   inline IToolSvc*         toolSvc   ()  const { return m_toolSvc     ; } 
00160   inline IIncidentSvc*     incSvc    ()  const { return m_incSvc      ; } 
00162   inline ISvcLocator*      svcLoc    ()  const { return serviceLocator() ; } 
00164   StatusCode    setNameOfDataProviderSvc( const std::string& Name ) 
00165   { m_dpName = Name ; return StatusCode::SUCCESS ; } 
00167 //   StatusCode locateOwnCnvs();
00168 
00196   template<class TYPE>
00197   TYPE* 
00198   get
00199   ( IDataProviderSvc*  svc        , 
00200     const std::string& location   ,
00201     const TYPE*        /* type */ ) const 
00202   {
00203     // check the environment 
00204     Assert( 0 != svc   , "  get():: IDataProvider* points to NULL!"      );
00205     SmartDataPtr<TYPE> object( svc, location ) ;
00206     Assert( !(!object) ,  " get():: No valid data at '" + location + "'" );
00207     TYPE* aux = object ;
00208     Assert( 0 != aux   ,  " get():: No valid data at '" + location + "'" );
00209     const std::string type( System::typeinfoName( typeid( *aux ) ) );
00210     // debug printout 
00211     // return located valid data 
00212     Print( " The data from address '"     + location + 
00213            "' are retrieved from TS "     , 
00214            MSG::DEBUG     ,     StatusCode::SUCCESS  ) ;
00215     Print( " [ The actual data type is '" + type     + 
00216            "' ] "                         ,
00217            MSG::VERBOSE   ,     StatusCode::SUCCESS  ) ;
00218     return aux ;
00219   };
00220 
00236   template<class TOOL>
00237   TOOL* 
00238   tool
00239   ( const std::string& type           , 
00240     const std::string& name           , 
00241     TOOL*&             Tool           , 
00242     const IInterface*  parent  = 0    , 
00243     bool               create  = true ) const 
00244   {
00245     // for empty names delegate to another method 
00246     if( name.empty() ) { return tool( type , Tool , parent , create ) ; }
00247     Assert( 0 != toolSvc() , "IToolSvc* points toNULL!" );
00248     // get the tool from Tool Service 
00249     StatusCode sc = toolSvc () 
00250       -> retrieveTool ( type , name , Tool, parent , create );
00251     Assert( sc.isSuccess() , 
00252             "Could not retrieve Tool'" + type + "'/'" + name + "'", sc ) ;
00253     Assert( 0 != Tool      , 
00254             "Could not retrieve Tool'" + type + "'/'" + name + "'"     ) ;
00255     // debug printout 
00256     Print( " The Tool of type '" + Tool->type() + 
00257            "'/'"                 + Tool->name() + 
00258            "' is retrieved from IToolSvc " , MSG::DEBUG  , sc ) ;
00259     // return located tool 
00260     return Tool ;
00261   };
00262 
00276   template<class TOOL>
00277   TOOL* 
00278   tool
00279   ( const std::string& type          , 
00280     TOOL*&             Tool          , 
00281     const IInterface*  parent = 0    , 
00282     bool               create = true ) const
00283   {
00284     // check the environment 
00285     Assert( 0 != toolSvc() , "IToolSvc* points toNULL!" );
00286     // "type" or "type/name" ?
00287     std::string::const_iterator it = 
00288       std::find( type.begin() , type.end () , '/' );
00289     // "type" is compound!
00290     if( type.end() != it ) 
00291       {
00292         std::string::size_type pos = it - type.begin()   ;
00293         const std::string ntype( type , 0       , pos               );
00294         const std::string nname( type , pos + 1 , std::string::npos );
00295         return tool( ntype , // new type 
00296                      nname , // new name 
00297                      Tool , parent , create            ) ;
00298       }
00299     // retrieve the tool from Tool Service 
00300     StatusCode sc = toolSvc () 
00301       -> retrieveTool ( type , Tool, parent , create   );
00302     Assert( sc.isSuccess() , "Could not retrieve Tool'" + type + "'" , sc ) ;
00303     Assert( 0 != Tool      , "Could not retrieve Tool'" + type + "'"      ) ;
00304     // debug printout 
00305     Print( " The Tool of type '" + Tool->type() + 
00306            "'/'"                 + Tool->name() + 
00307            "' is retrieved from IToolSvc " , MSG::DEBUG , sc ) ;
00308     // return located tool 
00309     return Tool ;
00310   };
00311   
00317   StatusCode Error     
00318   ( const std::string    & msg                       ,  
00319     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00320 
00326   StatusCode Warning   
00327   ( const std::string    & msg                       ,  
00328     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00329   
00336   StatusCode Print     
00337   ( const std::string    & msg                       ,  
00338     const MSG::Level     & lvl = MSG::INFO           ,
00339     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00340   
00347   inline StatusCode Assert
00348   ( bool  assertion                                    , 
00349     const std::string& msg = "GiGaCnvSvcBase::unknown" , 
00350     const StatusCode&  sc  = StatusCode::FAILURE       ) const ;
00351   
00358   inline StatusCode Assert
00359   ( bool  assertion                              ,
00360     const char*        msg                       ,
00361     const StatusCode&  sc  = StatusCode::FAILURE ) const ;
00362   
00370   StatusCode Exception 
00371   ( const std::string    & msg                        ,  
00372     const GaudiException & exc                        , 
00373     const MSG::Level     & lvl = MSG::FATAL           ,
00374     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00375 
00383   StatusCode Exception 
00384   ( const std::string    & msg                        ,  
00385     const std::exception & exc                        , 
00386     const MSG::Level     & lvl = MSG::FATAL           ,
00387     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00388   
00395   StatusCode Exception 
00396   ( const std::string    & msg                        ,  
00397     const MSG::Level     & lvl = MSG::FATAL           ,
00398     const StatusCode     & sc  = StatusCode::FAILURE ) const ;
00400 private: 
00402   GiGaCnvSvcBase() ; 
00403   GiGaCnvSvcBase           ( const GiGaCnvSvcBase& ) ; //< no copy
00404   GiGaCnvSvcBase& operator=( const GiGaCnvSvcBase& ) ; //< no assignment 
00406 protected:
00408   Leaves                               m_leaves     ; 
00410 private: 
00412   std::string                          m_dpName     ; 
00413   IDataProviderSvc*                    m_dpSvc      ; 
00415   std::string                          m_evtName    ; 
00416   IDataProviderSvc*                    m_evtSvc     ; 
00418   std::string                          m_detName    ; 
00419   IDataProviderSvc*                    m_detSvc     ; 
00421   std::string                          m_gigaName   ; 
00422   mutable IGiGaSvc*                    m_gigaSvc    ; 
00424   std::string                          m_setupName  ; 
00425   mutable IGiGaSetUpSvc*               m_setupSvc   ; 
00427   std::string                          m_chronoName ; 
00428   IChronoStatSvc*                      m_chronoSvc  ;
00430   std::string                          m_toolName   ; 
00431   IToolSvc*                            m_toolSvc    ;
00433   std::string                          m_inName     ; 
00434   IIncidentSvc*                        m_incSvc     ;
00436   typedef std::map<std::string,unsigned int> Counter;
00438   mutable Counter m_errors     ;
00440   mutable Counter m_warnings   ; 
00442   mutable Counter m_exceptions ;
00443 };        
00444 
00445 // ============================================================================
00451 // ============================================================================
00452 inline StatusCode  GiGaCnvSvcBase::Assert
00453 ( bool               assertion , 
00454   const std::string& msg       , 
00455   const StatusCode&  sc        ) const 
00456 {  
00457   StatusCode status = StatusCode::SUCCESS ;
00458   return (assertion) ? status : Exception( msg , MSG::FATAL , sc ) ;
00459 };
00460 // ============================================================================
00461 
00462 // ============================================================================
00468 // ============================================================================
00469 inline StatusCode  GiGaCnvSvcBase::Assert
00470 ( bool               assertion , 
00471   const char*        msg       , 
00472   const StatusCode&  sc        ) const 
00473 { 
00474   StatusCode status = StatusCode::SUCCESS ;
00475   return (assertion) ? status : Exception( msg , MSG::FATAL , sc ) ;
00476 };
00477 // ============================================================================
00478 
00479 // ============================================================================
00480 // The END 
00481 // ============================================================================
00482 #endif  
00483 // ============================================================================
00484 
00485 
00486 
00487 
00488 
00489 
00490 
00491 
00492 
00493 
00494 
00495 
00496 
00497 
00498 
00499 
| 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