3 #ifndef GAUDIUTILS_GETDATA_H
4 #define GAUDIUTILS_GETDATA_H 1
10 #include "GaudiKernel/IDataProviderSvc.h"
11 #include "GaudiKernel/SmartDataPtr.h"
12 #include "GaudiKernel/IRegistry.h"
16 #include "GaudiKernel/Range.h"
17 #include "GaudiKernel/NamedRange.h"
40 struct _GetType<TYPE*>
41 {
typedef TYPE* return_type ; };
45 struct _GetType<TYPE&>
46 {
typedef TYPE* return_type ; };
49 template <
class CONTAINER>
50 struct _GetType<
Gaudi::Range_<CONTAINER> >
54 template <
class CONTAINER>
55 struct _GetType<
Gaudi::NamedRange_<CONTAINER> >
64 const std::string& location ) {
68 dynamic_cast<typename _GetType<TYPE>::return_type
>(obj) :
87 typedef typename _GetType<Type>::return_type
return_type ;
98 template <
class COMMON>
99 inline return_type operator()
100 (
const COMMON& common ,
102 const std::string& location ,
103 const bool checkData =
true)
const
106 return_type obj = getFromTS<Type>(service, location);
108 common.Assert(obj,
"get():: No valid data at '" + location +
"'");
112 common.debug() <<
"The object of type '"
115 << (obj ?
"has been" :
"could not be")
116 <<
" retrieved from TS at address '"
117 << location <<
"'" <<
endmsg ;
126 template <
class TYPE>
127 struct GetData<
Gaudi::Range_<std::vector<const TYPE*> > >
133 typedef typename _GetType<Type>::return_type
return_type ;
144 template <
class COMMON>
145 inline return_type operator()
146 (
const COMMON& common ,
148 const std::string& location ,
149 const bool checkData =
true)
const
153 DataObject*
object =
this -> getData ( service , location ) ;
157 typedef typename TYPE::Selection Selection_;
158 const Selection_*
sel =
dynamic_cast<Selection_*
> ( object ) ;
162 { common.debug() <<
"The object of type '"
164 <<
"' has been retrieved from TS at address '"
165 << location <<
"'" <<
endmsg ; }
166 return make_range ( sel ) ;
169 typedef typename TYPE::Container Container_ ;
170 const Container_* cnt =
dynamic_cast<Container_*
> ( object ) ;
174 { common.debug() <<
"The object of type '"
176 <<
"' has been retrieved from TS at address '"
177 << location <<
"'" <<
endmsg ; }
178 return make_range ( cnt ) ;
182 common.Assert (
false ,
"get():: No valid data at '" + location +
"'" ) ;
186 common.Assert (
false ,
"get():: No data at '" + location +
"'" ) ;
194 return_type make_range (
const typename TYPE::Container* cnt )
const
195 {
return 0 == cnt ?
return_type() : make_range ( cnt->begin() , cnt->
end() ) ; }
197 return_type make_range (
const typename TYPE::Selection* cnt )
const
198 {
return 0 == cnt ?
return_type() : return_type ( cnt->begin() , cnt->
end() ) ; }
206 const std::string& location )
const
211 service , 0 , location ) ;
212 return getter.accessData () ;
217 template <
class ITERATOR>
218 return_type make_range
220 ITERATOR last )
const
222 typename return_type::const_iterator* _begin =
reinterpret_cast<typename return_type::const_iterator*
>(&first);
223 typename return_type::const_iterator* _end =
reinterpret_cast<typename return_type::const_iterator*
>(&last);
230 template <
class TYPE>
231 struct GetData<
Gaudi::NamedRange_<std::vector<const TYPE*> > >
237 typedef typename _GetType<Type>::return_type
return_type ;
248 template <
class COMMON>
249 inline return_type operator()
250 (
const COMMON& common ,
252 const std::string& location ,
253 const bool checkData =
true)
const
255 return return_type ( m_range( common , service , location, checkData ) , location ) ;
261 return_type make_range (
const typename TYPE::Container* cnt )
const
264 static const std::string s_empty =
"" ;
267 ( m_range.make_range ( cnt ) , 0 != reg ? reg->
identifier() : s_empty ) ;
270 return_type make_range (
const typename TYPE::Selection* cnt )
const
273 static const std::string s_empty =
"" ;
276 ( m_range.make_range ( cnt ) , 0 != reg ? reg->
identifier() : s_empty ) ;
285 const std::string& location )
const
286 {
return m_range.getData ( service , location ) ; }
291 GetData<Gaudi::Range_<std::vector<const TYPE*> > > m_range ;
296 template <
class TYPE>
297 struct GetData<const TYPE> :
public GetData<TYPE> {} ;
300 template <
class TYPE>
301 struct GetData<TYPE*> :
public GetData<TYPE> {} ;
304 template <
class TYPE>
305 struct GetData<TYPE&> :
public GetData<TYPE> {} ;
315 template <
class TYPE>
326 inline bool operator()
328 const std::string& location )
const
331 return getFromTS<TYPE>(service, location);
337 template <
class TYPE>
338 struct CheckData<
Gaudi::Range_<std::vector<const TYPE*> > >
348 inline bool operator()
350 const std::string& location )
const
352 DataObject*
object = this->getData( service , location ) ;
353 if ( 0 ==
object ) {
return false ; }
355 0 !=
dynamic_cast<typename TYPE::Selection*
> ( object ) ||
356 0 != dynamic_cast<typename TYPE::Container*> (
object ) ;
367 const std::string& location )
const
372 service , 0 , location ) ;
373 return getter.accessData () ;
379 template <
class TYPE>
380 struct CheckData<
Gaudi::NamedRange_<std::vector<const TYPE*> > >
381 :
public CheckData<Gaudi::Range_<std::vector<const TYPE*> > > {} ;
384 template <
class TYPE>
385 struct CheckData<TYPE*> :
public CheckData<TYPE> {} ;
388 template <
class TYPE>
389 struct CheckData<TYPE&> :
public CheckData<TYPE> {} ;
392 template <
class TYPE>
393 struct CheckData<const TYPE> :
public CheckData<TYPE> {} ;
403 template <
class TYPE,
class TYPE2>
404 struct GetOrCreateData
409 typedef GetData<TYPE>
Getter ;
425 template <
class COMMON>
426 inline return_type operator()
427 (
const COMMON& common ,
429 const std::string& location ,
430 const std::string& location2 )
const
435 TYPE2* o =
new TYPE2() ;
436 common.put ( service , o , location2 ) ;
438 { common.debug() <<
"The object of type '"
440 <<
"' has been created from TS at address '"
441 << location2 <<
"'" <<
endmsg ; }
445 return_type ret = obj ;
447 common.Assert ( !(!ret) ,
"get():: No valid data at '" + location +
"'" ) ;
449 { common.debug() <<
"The object of type '"
451 <<
"' has been retrieved from TS at address '"
452 << location <<
"'" <<
endmsg ; }
459 template <
class TYPE,
class TYPE2>
460 struct GetOrCreateData<
Gaudi::Range_<std::vector<const TYPE*> >,TYPE2>
466 typedef GetData<Range>
Getter ;
468 typedef CheckData<Range> Checker ;
484 template <
class COMMON>
485 inline return_type operator()
486 (
const COMMON& common ,
488 const std::string& location ,
489 const std::string& location2 )
const
491 DataObject* obj = m_getter.getData ( service , location ) ;
494 TYPE2* o =
new TYPE2() ;
495 common.put ( service , o , location2 ) ;
497 { common.debug() <<
"The object of type '"
499 <<
"' has been created from TS at address '"
500 << location2 <<
"'" <<
endmsg ; }
502 return m_getter ( common , service , location ) ;
513 template <
class TYPE,
class TYPE2>
514 struct GetOrCreateData<
Gaudi::NamedRange_<std::vector<const TYPE*> >,TYPE2>
520 typedef GetOrCreateData<Range_,TYPE2>
Helper ;
522 typedef GetData<Range>
Getter ;
538 template <
class COMMON>
539 inline return_type operator()
540 (
const COMMON& common ,
542 const std::string& location ,
543 const std::string& location2 )
const
548 location2 ) , location ) ;
558 template <
class TYPE,
class TYPE2>
559 struct GetOrCreateData<TYPE,TYPE2*>
560 :
public GetOrCreateData<TYPE,TYPE2> {} ;
561 template <
class TYPE,
class TYPE2>
562 struct GetOrCreateData<TYPE*,TYPE2>
563 :
public GetOrCreateData<TYPE,TYPE2> {} ;
564 template <
class TYPE,
class TYPE2>
565 struct GetOrCreateData<TYPE*,TYPE2*>
566 :
public GetOrCreateData<TYPE,TYPE2> {} ;
568 template <
class TYPE,
class TYPE2>
569 struct GetOrCreateData< TYPE,const TYPE2>
570 :
public GetOrCreateData<TYPE,TYPE2> {} ;
571 template <
class TYPE,
class TYPE2>
572 struct GetOrCreateData<const TYPE, TYPE2>
573 :
public GetOrCreateData<TYPE,TYPE2> {} ;
574 template <
class TYPE,
class TYPE2>
575 struct GetOrCreateData<const TYPE,const TYPE2>
576 :
public GetOrCreateData<TYPE,TYPE2> {} ;
578 template <
class TYPE,
class TYPE2>
579 struct GetOrCreateData<TYPE,TYPE2&>
580 :
public GetOrCreateData<TYPE,TYPE2> {} ;
581 template <
class TYPE,
class TYPE2>
582 struct GetOrCreateData<TYPE&,TYPE2>
583 :
public GetOrCreateData<TYPE,TYPE2> {} ;
584 template <
class TYPE,
class TYPE2>
585 struct GetOrCreateData<TYPE&,TYPE2&>
586 :
public GetOrCreateData<TYPE,TYPE2> {} ;
594 #endif // GAUDIUTILS_GETDATA_H
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
bool isSuccess() const
Test for a status code of SUCCESS.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Data provider interface definition.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
_GetType< Type >::return_type return_type
the actual return type
_GetType< TYPE >::return_type getFromTS(IDataProviderSvc *service, const std::string &location)
Helper function to provide the minimal lookup and cast functionality of SmartDataPtr used in the help...
Getter::return_type return_type
the actual return type
A small class used to access easily (and efficiently) data items residing in data stores...
static AccessFunction access()
Useful class for representation of "sequence" of the objects through the range of valid iterators...
A small class used to access easily (and efficiently) data items residing in data stores...
Implements the common functionality between GaudiTools and GaudiAlgorithms.
virtual const id_type & identifier() const =0
Full identifier (or key)
A DataObject is the base class of any identifiable object on any data store.
Type
the list of available types for ntuples
Helper functions to set/get the application return code.
GetData< TYPE > Getter
the actual data getter
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.