1 #ifndef GAUDIHIVE_DATAOBJECTHANDLE_H 2 #define GAUDIHIVE_DATAOBJECTHANDLE_H 12 #include <type_traits> 21 template <
typename Range,
typename StorageType>
24 auto c =
static_cast<const StorageType*
>( obj );
29 auto last =
end( *
c );
31 auto _first =
reinterpret_cast<typename Range::const_iterator*
>( &first );
32 auto _last =
reinterpret_cast<typename Range::const_iterator*
>( &last );
33 return Range( *_first, *_last );
36 template <
typename ValueType,
typename Range = Gaudi::Range_<
typename ValueType::ConstVector>>
39 using Selection =
typename ValueType::Selection;
40 auto sel =
dynamic_cast<const Selection*
>( obj );
41 if (
sel )
return &make_range<Range, typename ValueType::Selection>;
42 auto con =
dynamic_cast<std::add_const_t<typename ValueType::Container>*
>( obj );
43 if ( con )
return &make_range<Range, typename ValueType::Container>;
50 using Type = std::add_const_t<T>;
51 assert( dataObj !=
nullptr );
52 auto obj =
dynamic_cast<Type*
>( dataObj );
53 bool ok = ( obj != nullptr );
58 " and is different from the one of the object in the store.",
61 assert( obj == static_cast<Type*>( dataObj ) );
101 T*
get()
const {
return get( true ); }
112 bool exist()
const {
return get( false ) !=
nullptr; }
128 T*
get(
bool mustExist )
const;
129 mutable bool m_goodType =
false;
141 template <
typename T>
144 auto dataObj = fetch();
147 throw GaudiException(
"Cannot retrieve " + objKey() +
" from transient store.",
152 if (
UNLIKELY( !m_goodType ) ) m_goodType = details::verifyType<T>( dataObj );
153 return static_cast<T*
>( dataObj );
157 template <
typename T>
169 template <
typename T>
172 T* obj =
get( false );
173 return obj ? obj :
put( std::make_unique<T>() );
179 template <
typename T>
183 using ValueType = std::remove_cv_t<std::remove_pointer_t<typename T::value_type>>;
197 template <
typename ValueType>
200 auto dataObj = fetch();
202 throw GaudiException(
"Cannot retrieve " + objKey() +
" from transient store.",
206 m_converter = details::select_range_converter<ValueType>( dataObj );
207 if ( !m_converter ) {
208 throw GaudiException(
"The type requested for " + objKey() +
" cannot be obtained from object in event store",
212 return ( *m_converter )( dataObj );
217 template <
typename T>
226 const T*
get()
const {
return &
_get()->getData(); }
231 const T*
put( T&&
object );
236 boost::optional<std::size_t>
size()
const {
return _get()->size(); }
240 mutable bool m_goodType =
false;
245 template <
typename T>
250 throw GaudiException(
"Cannot retrieve " + objKey() +
" from transient store.",
253 if (
UNLIKELY( !m_goodType ) ) m_goodType = details::verifyType<AnyDataWrapper<T>>( obj );
259 template <
typename T>
263 auto objectp = std::make_unique<AnyDataWrapper<T>>(
std::move( obj ) );
264 StatusCode rc = m_EDS->registerObject( objKey(), objectp.get() );
265 if ( rc.isFailure() ) {
268 return &objectp.release()->getData();
273 template <
typename T>
290 template <typename OWNER, typename K, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
297 template <
typename... Args>
299 : DataObjectReadHandle( args, std::index_sequence_for<Args...>{} )
304 template <
typename T>
321 template <typename OWNER, typename K, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
328 template <
typename... Args>
330 : DataObjectWriteHandle( args, std::index_sequence_for<Args...>{} )
constexpr static const auto FAILURE
Define general base for Gaudi exception.
Gaudi::Range_< typename ValueType::ConstVector > Range
DataObjectReadHandle(const DataObjID &k, IDataHandleHolder *owner)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
auto end(reverse_wrapper< T > &w)
bool verifyType(const DataObject *dataObj)
bool exist() const
Check the existence of the object in the transient store.
IRegistry * registry() const
Get pointer to Registry.
T * get() const
Retrieve object from transient data store.
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
Range make_range(const DataObject *obj)
typename Payload_helper< T >::type Payload_t
This class is used for returning status codes from appropriate routines.
This file has been imported from LoKi project "C++ ToolKit for Smart and Friendly Physics Analysis" ...
DataObjectReadHandle(const std::tuple< Args... > &args, std::index_sequence< Is... >)
std::conditional_t< std::is_base_of< DataObject, T >::value, T, AnyDataWrapper< T >> type
T * put(std::unique_ptr< T > object)
Register object in transient store.
T(*)(const DataObject *) Converter_t
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
auto begin(reverse_wrapper< T > &w)
Useful class for representation of "sequence" of the objects through the range of valid iterators...
Converter_t< Range > select_range_converter(const DataObject *obj)
boost::optional< std::size_t > size() const
Size of boxed item, if boxed item has a 'size' method.
T * getIfExists() const
Bypass check of existence of object in transient store Only uses main location of the...
DataObjectWriteHandle(const DataObjID &k, IDataHandleHolder *owner)
A DataObject is the base class of any identifiable object on any data store.
Type
the list of available types for ntuples
std::remove_cv_t< std::remove_pointer_t< typename T::value_type >> ValueType
Helper functions to set/get the application return code.
T * getOrCreate()
Get object from store or create a new one if it doesn't exist.
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
DataObjectWriteHandle(const std::tuple< Args... > &args, std::index_sequence< Is... >)