GetData.h
Go to the documentation of this file.00001
00002
00003 #ifndef GAUDIUTILS_GETDATA_H
00004 #define GAUDIUTILS_GETDATA_H 1
00005
00006
00007
00008
00009
00010 #include "GaudiKernel/IDataProviderSvc.h"
00011 #include "GaudiKernel/SmartDataPtr.h"
00012
00013
00014
00015 #include "GaudiKernel/Range.h"
00016 #include "GaudiKernel/NamedRange.h"
00017
00018
00019
00020 template <class BASE> class GaudiCommon ;
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 << "'" << endmsg ; }
00099
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 {
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 << "'" << endmsg ; }
00139 return make_range ( aux->begin() , aux->end() ) ;
00140 }
00141 }
00142 {
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 << "'" << endmsg ; }
00152 return make_range ( aux->begin() , aux->end() ) ;
00153 }
00154 }
00155
00156 common.Assert ( false , "get():: No valid data at '" + location + "'" ) ;
00157
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 typename return_type::const_iterator* _begin = reinterpret_cast<typename return_type::const_iterator*>(&first);
00169 typename return_type::const_iterator* _end = reinterpret_cast<typename return_type::const_iterator*>(&last);
00170 return return_type(*_begin, *_end);
00171 }
00172
00173 } ;
00174
00176 template <class TYPE>
00177 struct GetData<Gaudi::NamedRange_<std::vector<const TYPE*> > >
00178 {
00179 public:
00180
00182 typedef Gaudi::NamedRange_<std::vector<const TYPE*> > Type ;
00183 typedef typename _GetType<Type>::return_type return_type ;
00184
00185 public:
00186
00193 template <class COMMON>
00194 inline return_type operator()
00195 ( const COMMON& common ,
00196 IDataProviderSvc* service ,
00197 const std::string& location ) const
00198 {
00199 {
00200 SmartDataPtr<typename TYPE::Selection> obj ( service , location ) ;
00201 typename TYPE::Selection* aux = obj ;
00202 if ( 0 != obj )
00203 {
00204 if ( common.msgLevel ( MSG::DEBUG ) )
00205 { common.debug() << "The object of type '"
00206 << System::typeinfoName(typeid(*aux))
00207 << "' has been retrieved from TS at address '"
00208 << location << "'" << endmsg ; }
00209 return make_range ( aux -> begin() , aux -> end() , location ) ;
00210 }
00211 }
00212 {
00213 SmartDataPtr<typename TYPE::Container> obj ( service , location ) ;
00214 typename TYPE::Container* aux = obj ;
00215 if ( 0 != obj )
00216 {
00217 if ( common.msgLevel ( MSG::DEBUG ) )
00218 { common.debug() << "The object of type '"
00219 << System::typeinfoName(typeid(*aux))
00220 << "' has been retrieved from TS at address '"
00221 << location << "'" << endmsg ; }
00222 return make_range ( aux -> begin() , aux -> end() , location ) ;
00223 }
00224 }
00225
00226 common.Assert ( false , "get():: No valid data at '" + location + "'" ) ;
00227
00228 return return_type () ;
00229 }
00230
00231 private:
00232
00233 template <class ITERATOR>
00234 return_type make_range
00235 ( ITERATOR first ,
00236 ITERATOR last ,
00237 const std::string& location ) const
00238 {
00239 typename return_type::const_iterator* _begin = reinterpret_cast<typename return_type::const_iterator*>(&first);
00240 typename return_type::const_iterator* _end = reinterpret_cast<typename return_type::const_iterator*>(&last);
00241 return return_type(*_begin, *_end, location);
00242 }
00243
00244 } ;
00245
00247 template <class TYPE>
00248 struct GetData<TYPE*> : public GetData<TYPE> {} ;
00249
00251 template <class TYPE>
00252 struct GetData<TYPE&> : public GetData<TYPE> {} ;
00253
00254 }
00255
00256 }
00257
00258
00259
00260 #endif // GAUDIUTILS_GETDATA_H
00261