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

In This Package:

GetData.h

Go to the documentation of this file.
00001 // $Id: GetData.h,v 1.1 2008/10/10 08:06:33 marcocle Exp $
00002 // ============================================================================
00003 #ifndef GAUDIUTILS_GETDATA_H 
00004 #define GAUDIUTILS_GETDATA_H 1
00005 // ============================================================================
00006 // Include files
00007 // ============================================================================
00008 // GaudiKernel
00009 // ============================================================================
00010 #include "GaudiKernel/IDataProviderSvc.h"
00011 #include "GaudiKernel/SmartDataPtr.h"
00012 // ============================================================================
00013 // GaudiUtils
00014 // ============================================================================
00015 #include "GaudiUtils/Range.h"
00016 #include "GaudiUtils/NamedRange.h"
00017 // ============================================================================
00018 // Forward declaration 
00019 // ============================================================================
00020 template <class BASE> class GaudiCommon ; // GaudiAlg
00021 // ============================================================================
00022 namespace Gaudi
00023 {
00024   namespace Utils 
00025   {
00026     // ========================================================================
00033     template <class TYPE> 
00034     struct _GetType        
00035     { typedef TYPE* return_type ; };
00036     // ========================================================================
00038     template <class TYPE> 
00039     struct _GetType<TYPE*> 
00040     { typedef TYPE* return_type ; };
00041     // ========================================================================
00043     template <class TYPE> 
00044     struct _GetType<TYPE&> 
00045     { typedef TYPE* return_type ; };
00046     // ========================================================================
00048     template <class CONTAINER>
00049     struct _GetType<Gaudi::Range_<CONTAINER> >
00050     { typedef Gaudi::Range_<CONTAINER>      return_type ; };
00051     // ========================================================================
00053     template <class CONTAINER>
00054     struct _GetType<Gaudi::NamedRange_<CONTAINER> >
00055     { typedef Gaudi::NamedRange_<CONTAINER> return_type ; };
00056     // ========================================================================
00065     template <class TYPE>
00066     struct GetData 
00067     {
00068     public:
00069       // ======================================================================
00070       typedef TYPE                                   Type        ;
00072       typedef typename _GetType<Type>::return_type   return_type ;
00073       // ======================================================================
00074     public:
00075       // ======================================================================
00082       template <class COMMON>
00083       inline return_type operator() 
00084         ( const COMMON&            common    , 
00085           IDataProviderSvc*        service   ,
00086           const std::string&       location  ) const 
00087       {
00089         SmartDataPtr<TYPE> obj ( service , location ) ;
00090         return_type aux = obj ;
00092         common.Assert ( !(!aux) , "get():: No valid data at '" + location + "'"  ) ;
00094         if ( common.msgLevel ( MSG::DEBUG ) )
00095         { common.debug() << "The object of type '"
00096                          << System::typeinfoName(typeid(aux))
00097                          << "' has been retrieved from TS at address '"
00098                          << location << "'" << endreq ; }
00099         // return located *VALID* data
00100         return aux ;
00101         // ====================================================================== 
00102       }
00103     };
00104     // ========================================================================
00106     template <class TYPE>
00107     struct GetData<Gaudi::Range_<std::vector<const TYPE*> > >
00108     {
00109     public:
00110       // ======================================================================  
00112       typedef Gaudi::Range_<std::vector<const TYPE*> >   Type        ;
00113       typedef typename _GetType<Type>::return_type       return_type ;
00114       // ======================================================================  
00115     public:
00116       // ======================================================================  
00123       template <class COMMON>
00124       inline return_type operator() 
00125         ( const COMMON&            common    , 
00126           IDataProviderSvc*        service   ,
00127           const std::string&       location  ) const 
00128       {
00129         { // try to get the selection from TES 
00130           SmartDataPtr<typename TYPE::Selection> obj ( service , location ) ;
00131           typename TYPE::Selection* aux = obj ;
00132           if ( 0 != aux ) 
00133           {
00134             if ( common.msgLevel ( MSG::DEBUG ) )
00135             { common.debug() << "The object of type '"
00136                              << System::typeinfoName(typeid(*aux))
00137                              << "' has been retrieved from TS at address '"
00138                              << location << "'" << endreq ; }
00139             return make_range ( aux->begin() , aux->end() ) ;
00140           }
00141         }
00142         { // get from TES the container 
00143           SmartDataPtr<typename TYPE::Container> obj ( service , location ) ;
00144           typename TYPE::Container* aux = obj ;
00145           if ( 0 != aux ) 
00146           {
00147             if ( common.msgLevel ( MSG::DEBUG ) )
00148             { common.debug() << "The object of type '"
00149                              << System::typeinfoName(typeid(*aux))
00150                              << "' has been retrieved from TS at address '"
00151                              << location << "'" << endreq ; }
00152             return make_range ( aux->begin() , aux->end() ) ;
00153           }    
00154         }
00155         // no valid data 
00156         common.Assert ( false , "get():: No valid data at '" + location + "'"  ) ;
00157         // the fictive return 
00158         return return_type () ;
00159       }
00160       // ====================================================================== 
00161     private:
00162       // ====================================================================== 
00163       template <class ITERATOR>
00164       return_type make_range 
00165       ( ITERATOR first , 
00166         ITERATOR last  ) const 
00167       {
00168         ITERATOR _begin = first ;
00169         ITERATOR _end   = last  ;         
00170         return return_type 
00171           ( *reinterpret_cast<typename return_type::const_iterator*> ( &_begin ) ,
00172             *reinterpret_cast<typename return_type::const_iterator*> ( &_end   ) ) ;   
00173       }
00174       // ====================================================================== 
00175     } ;
00176     // ========================================================================
00178     template <class TYPE>
00179     struct GetData<Gaudi::NamedRange_<std::vector<const TYPE*> > > 
00180     {
00181     public:
00182       // ======================================================================
00184       typedef Gaudi::NamedRange_<std::vector<const TYPE*> > Type        ;
00185       typedef typename _GetType<Type>::return_type          return_type ;
00186       // ======================================================================
00187     public:
00188       // ======================================================================
00195       template <class COMMON>
00196       inline return_type operator() 
00197         ( const COMMON&            common    , 
00198           IDataProviderSvc*        service   ,
00199           const std::string&       location  ) const 
00200       {
00201         { // try to get the selection from TES 
00202           SmartDataPtr<typename TYPE::Selection> obj ( service , location ) ;
00203           typename TYPE::Selection* aux = obj ;
00204           if ( 0 != obj ) 
00205           {
00206             if ( common.msgLevel ( MSG::DEBUG ) )
00207             { common.debug() << "The object of type '"
00208                              << System::typeinfoName(typeid(*aux))
00209                              << "' has been retrieved from TS at address '"
00210                              << location << "'" << endreq ; }
00211             return make_range ( aux -> begin() , aux -> end() , location ) ;
00212           }
00213         }
00214         { // get from TES the container 
00215           SmartDataPtr<typename TYPE::Container> obj ( service , location ) ;
00216           typename TYPE::Container* aux = obj ;
00217           if ( 0 != obj ) 
00218           {
00219             if ( common.msgLevel ( MSG::DEBUG ) )
00220             { common.debug() << "The object of type '"
00221                              << System::typeinfoName(typeid(*aux))
00222                              << "' has been retrieved from TS at address '"
00223                              << location << "'" << endreq ; }
00224             return make_range ( aux -> begin() , aux -> end() , location ) ;
00225           }    
00226         }
00227         // no valid data 
00228         common.Assert ( false , "get():: No valid data at '" + location + "'"  ) ;
00229         // the fictive return 
00230         return return_type () ;
00231       }
00232       // ====================================================================== 
00233     private:
00234       // ====================================================================== 
00235       template <class ITERATOR>
00236       return_type make_range 
00237       ( ITERATOR           first    , 
00238         ITERATOR           last     , 
00239         const std::string& location ) const 
00240       {
00241         ITERATOR _begin = first ;
00242         ITERATOR _end   = last  ;         
00243         return return_type 
00244           ( *reinterpret_cast<typename return_type::const_iterator*> ( &_begin ) ,
00245             *reinterpret_cast<typename return_type::const_iterator*> ( &_end   ) , 
00246             location ) ;
00247       }
00248       // ====================================================================== 
00249     } ;
00250     // ========================================================================
00252     template <class TYPE>
00253     struct GetData<TYPE*> : public GetData<TYPE> {} ;
00254     // ========================================================================
00256     template <class TYPE>
00257     struct GetData<TYPE&> : public GetData<TYPE> {} ;
00258     // ========================================================================
00259   } // end of namespace Gaudi::Utils 
00260   // ==========================================================================
00261 } // end of namespace Gaudi 
00262 // ============================================================================
00263 // The END 
00264 // ============================================================================
00265 #endif // GAUDIUTILS_GETDATA_H
00266 // ============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:58:14 2011 for GaudiAlg by doxygen 1.4.7