1 #ifndef GAUDIUTILS_GETDATA_H
2 #define GAUDIUTILS_GETDATA_H 1
8 #include "GaudiKernel/IDataProviderSvc.h"
9 #include "GaudiKernel/SmartDataPtr.h"
10 #include "GaudiKernel/IRegistry.h"
14 #include "GaudiKernel/Range.h"
15 #include "GaudiKernel/NamedRange.h"
38 struct _GetType<TYPE*>
39 {
typedef TYPE* return_type ; };
43 struct _GetType<TYPE&>
44 {
typedef TYPE* return_type ; };
47 template <
class CONTAINER>
48 struct _GetType<
Gaudi::Range_<CONTAINER> >
52 template <
class CONTAINER>
53 struct _GetType<
Gaudi::NamedRange_<CONTAINER> >
62 const std::string& location ) {
66 dynamic_cast<typename _GetType<TYPE>::return_type
>(obj) :
85 typedef typename _GetType<Type>::return_type
return_type ;
96 template <
class COMMON>
97 inline return_type operator()
98 (
const COMMON& common ,
100 const std::string& location ,
101 const bool checkData =
true)
const
104 return_type obj = getFromTS<Type>(service, location);
106 common.Assert(obj,
"get():: No valid data at '" + location +
"'");
110 common.debug() <<
"The object of type '"
113 << (obj ?
"has been" :
"could not be")
114 <<
" retrieved from TS at address '"
115 << location <<
"'" <<
endmsg ;
124 template <
class TYPE>
125 struct GetData<
Gaudi::Range_<std::vector<const TYPE*> > >
131 typedef typename _GetType<Type>::return_type
return_type ;
142 template <
class COMMON>
143 inline return_type operator()
144 (
const COMMON& common ,
146 const std::string& location ,
147 const bool checkData =
true)
const
151 DataObject*
object =
this -> getData ( service , location ) ;
155 typedef typename TYPE::Selection Selection_;
156 const Selection_*
sel =
dynamic_cast<Selection_*
> ( object ) ;
160 { common.debug() <<
"The object of type '"
162 <<
"' has been retrieved from TS at address '"
163 << location <<
"'" <<
endmsg ; }
164 return make_range ( sel ) ;
167 typedef typename TYPE::Container Container_ ;
168 const Container_* cnt =
dynamic_cast<Container_*
> ( object ) ;
172 { common.debug() <<
"The object of type '"
174 <<
"' has been retrieved from TS at address '"
175 << location <<
"'" <<
endmsg ; }
176 return make_range ( cnt ) ;
180 common.Assert (
false ,
"get():: No valid data at '" + location +
"'" ) ;
184 common.Assert (
false ,
"get():: No data at '" + location +
"'" ) ;
192 return_type make_range (
const typename TYPE::Container* cnt )
const
195 return_type make_range (
const typename TYPE::Selection* cnt )
const
204 const std::string& location )
const
209 service ,
nullptr , location ) ;
210 return getter.accessData () ;
215 template <
class ITERATOR>
216 return_type make_range
218 ITERATOR last )
const
220 auto _begin =
reinterpret_cast<typename return_type::const_iterator*
>(&first);
221 auto _end =
reinterpret_cast<typename return_type::const_iterator*
>(&last);
228 template <
class TYPE>
229 struct GetData<
Gaudi::NamedRange_<std::vector<const TYPE*> > >
235 typedef typename _GetType<Type>::return_type
return_type ;
246 template <
class COMMON>
247 inline return_type operator()
248 (
const COMMON& common ,
250 const std::string& location ,
251 const bool checkData =
true)
const
253 return return_type ( m_range( common , service , location, checkData ) , location ) ;
259 return_type make_range (
const typename TYPE::Container* cnt )
const
262 static const std::string s_empty =
"" ;
265 ( m_range.make_range ( cnt ) , reg ? reg->
identifier() : s_empty ) ;
268 return_type make_range (
const typename TYPE::Selection* cnt )
const
271 static const std::string s_empty =
"" ;
274 ( m_range.make_range ( cnt ) , reg ? reg->
identifier() : s_empty ) ;
283 const std::string& location )
const
284 {
return m_range.getData ( service , location ) ; }
289 GetData<Gaudi::Range_<std::vector<const TYPE*> > > m_range ;
294 template <
class TYPE>
295 struct GetData<const TYPE> :
public GetData<TYPE> {} ;
298 template <
class TYPE>
299 struct GetData<TYPE*> :
public GetData<TYPE> {} ;
302 template <
class TYPE>
303 struct GetData<TYPE&> :
public GetData<TYPE> {} ;
313 template <
class TYPE>
324 inline bool operator()
326 const std::string& location )
const
329 return getFromTS<TYPE>(service, location);
335 template <
class TYPE>
336 struct CheckData<
Gaudi::Range_<std::vector<const TYPE*> > >
346 inline bool operator()
348 const std::string& location )
const
350 DataObject*
object = this->getData( service , location ) ;
351 if ( !
object ) {
return false ; }
353 dynamic_cast<typename TYPE::Selection*
> ( object ) ||
354 dynamic_cast<typename TYPE::Container*> (
object ) ;
365 const std::string& location )
const
370 service ,
nullptr , location ) ;
371 return getter.accessData () ;
377 template <
class TYPE>
378 struct CheckData<
Gaudi::NamedRange_<std::vector<const TYPE*> > >
379 :
public CheckData<Gaudi::Range_<std::vector<const TYPE*> > > {} ;
382 template <
class TYPE>
383 struct CheckData<TYPE*> :
public CheckData<TYPE> {} ;
386 template <
class TYPE>
387 struct CheckData<TYPE&> :
public CheckData<TYPE> {} ;
390 template <
class TYPE>
391 struct CheckData<const TYPE> :
public CheckData<TYPE> {} ;
401 template <
class TYPE,
class TYPE2>
402 struct GetOrCreateData
407 typedef GetData<TYPE>
Getter ;
423 template <
class COMMON>
424 inline return_type operator()
425 (
const COMMON& common ,
427 const std::string& location ,
428 const std::string& location2 )
const
433 TYPE2* o =
new TYPE2() ;
434 common.put ( service , o , location2 ) ;
436 { common.debug() <<
"The object of type '"
438 <<
"' has been created from TS at address '"
439 << location2 <<
"'" <<
endmsg ; }
442 return_type ret = obj ;
444 common.Assert ( !(!ret) ,
"get():: No valid data at '" + location +
"'" ) ;
446 { common.debug() <<
"The object of type '"
448 <<
"' has been retrieved from TS at address '"
449 << location <<
"'" <<
endmsg ; }
456 template <
class TYPE,
class TYPE2>
457 struct GetOrCreateData<
Gaudi::Range_<std::vector<const TYPE*> >,TYPE2>
463 typedef GetData<Range>
Getter ;
465 typedef CheckData<Range> Checker ;
481 template <
class COMMON>
482 inline return_type operator()
483 (
const COMMON& common ,
485 const std::string& location ,
486 const std::string& location2 )
const
488 DataObject* obj = m_getter.getData ( service , location ) ;
491 common.put ( service ,
new TYPE2() , location2 ) ;
493 { common.debug() <<
"The object of type '"
495 <<
"' has been created from TS at address '"
496 << location2 <<
"'" <<
endmsg ; }
498 return m_getter ( common , service , location ) ;
509 template <
class TYPE,
class TYPE2>
510 struct GetOrCreateData<
Gaudi::NamedRange_<std::vector<const TYPE*> >,TYPE2>
516 typedef GetOrCreateData<Range_,TYPE2>
Helper ;
518 typedef GetData<Range>
Getter ;
534 template <
class COMMON>
535 inline return_type operator()
536 (
const COMMON& common ,
538 const std::string& location ,
539 const std::string& location2 )
const
544 location2 ) , location ) ;
554 template <
class TYPE,
class TYPE2>
555 struct GetOrCreateData<TYPE,TYPE2*>
556 :
public GetOrCreateData<TYPE,TYPE2> {} ;
557 template <
class TYPE,
class TYPE2>
558 struct GetOrCreateData<TYPE*,TYPE2>
559 :
public GetOrCreateData<TYPE,TYPE2> {} ;
560 template <
class TYPE,
class TYPE2>
561 struct GetOrCreateData<TYPE*,TYPE2*>
562 :
public GetOrCreateData<TYPE,TYPE2> {} ;
564 template <
class TYPE,
class TYPE2>
565 struct GetOrCreateData< TYPE,const TYPE2>
566 :
public GetOrCreateData<TYPE,TYPE2> {} ;
567 template <
class TYPE,
class TYPE2>
568 struct GetOrCreateData<const TYPE, TYPE2>
569 :
public GetOrCreateData<TYPE,TYPE2> {} ;
570 template <
class TYPE,
class TYPE2>
571 struct GetOrCreateData<const TYPE,const TYPE2>
572 :
public GetOrCreateData<TYPE,TYPE2> {} ;
574 template <
class TYPE,
class TYPE2>
575 struct GetOrCreateData<TYPE,TYPE2&>
576 :
public GetOrCreateData<TYPE,TYPE2> {} ;
577 template <
class TYPE,
class TYPE2>
578 struct GetOrCreateData<TYPE&,TYPE2>
579 :
public GetOrCreateData<TYPE,TYPE2> {} ;
580 template <
class TYPE,
class TYPE2>
581 struct GetOrCreateData<TYPE&,TYPE2&>
582 :
public GetOrCreateData<TYPE,TYPE2> {} ;
590 #endif // GAUDIUTILS_GETDATA_H
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
auto begin(reverse_wrapper< T > &w)
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.
auto end(reverse_wrapper< T > &w)
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.