1 #ifndef GAUDIHIVE_DATAOBJECTHANDLE_H 2 #define GAUDIHIVE_DATAOBJECTHANDLE_H 12 #include <type_traits> 20 template <
typename Range,
typename StorageType>
22 auto c = static_cast<const StorageType*>( obj );
27 auto last =
end( *
c );
29 auto _first = reinterpret_cast<typename Range::const_iterator*>( &first );
30 auto _last = reinterpret_cast<typename Range::const_iterator*>( &last );
31 return Range( *_first, *_last );
34 template <
typename ValueType,
typename Range = Gaudi::Range_<
typename ValueType::ConstVector>>
36 using Selection =
typename ValueType::Selection;
37 auto sel = dynamic_cast<const Selection*>( obj );
38 if (
sel )
return &make_range<Range, typename ValueType::Selection>;
39 auto con =
dynamic_cast<std::add_const_t<typename ValueType::Container>*
>( obj );
40 if ( con )
return &make_range<Range, typename ValueType::Container>;
46 using Type = std::add_const_t<T>;
47 assert( dataObj !=
nullptr );
48 auto obj = dynamic_cast<Type*>( dataObj );
49 bool ok = ( obj != nullptr );
54 " and is different from the one of the object in the store which is " +
58 assert( obj == static_cast<Type*>( dataObj ) );
97 T*
get()
const {
return get(
true ); }
108 bool exist()
const {
return get(
false ) !=
nullptr; }
124 T*
get(
bool mustExist )
const;
137 template <
typename T>
139 auto dataObj = fetch();
142 throw GaudiException(
"Cannot retrieve " + objKey() +
" from transient store.",
147 if (
UNLIKELY( !m_goodType ) ) m_goodType = ::details::verifyType<T>( dataObj );
148 return static_cast<T*>( dataObj );
152 template <
typename T>
156 if ( !
rc.isSuccess() ) {
163 template <
typename T>
165 T* obj =
get(
false );
166 return obj ? obj :
put( std::make_unique<T>() );
172 template <
typename T>
175 using ValueType = std::remove_cv_t<std::remove_pointer_t<typename T::value_type>>;
186 mutable ::details::Converter_t<Range> m_converter =
nullptr;
189 template <
typename ValueType>
191 auto dataObj = fetch();
193 throw GaudiException(
"Cannot retrieve " + objKey() +
" from transient store.",
197 m_converter = ::details::select_range_converter<ValueType>( dataObj );
198 if ( !m_converter ) {
200 ")" +
" cannot be obtained from object in event store" +
" (" +
205 return ( *m_converter )( dataObj );
210 template <
typename T>
218 T*
get()
const {
return &
_get(
true )->getData(); }
220 auto data =
_get(
false );
222 return &data->getData();
231 const T*
put( T&&
object )
const;
236 std::optional<std::size_t>
size()
const {
return _get()->size(); }
245 template <
typename T>
250 throw GaudiException(
"Cannot retrieve " + objKey() +
" from transient store.",
257 if (
UNLIKELY( !m_goodType ) ) m_goodType = ::details::verifyType<AnyDataWrapper<T>>( obj );
263 template <
typename T>
266 auto objectp = std::make_unique<AnyDataWrapper<T>>(
std::move( obj ) );
267 StatusCode rc = m_EDS->registerObject( objKey(), objectp.get() );
268 if (
rc.isFailure() ) {
271 return &objectp.release()->getData();
276 template <
typename T>
288 template <
typename OWNER,
typename K,
typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
293 template <
typename... Args>
298 template <
typename T>
310 template <
typename OWNER,
typename K,
typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
315 template <
typename... Args>
DataObjectWriteHandle(OWNER *owner, std::string propertyName, const K &key={}, std::string doc="")
Autodeclaring constructor with property name, mode, key and documentation.
bool exist() const
Check the existence of the object in the transient store.
Define general base for Gaudi exception.
IRegistry * registry() const
Get pointer to Registry.
Gaudi::Range_< typename ValueType::ConstVector > Range
T * get() const
Retrieve object from transient data store.
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)
virtual IDataHandleHolder * owner() const
DataObjectReadHandle(OWNER *owner, std::string propertyName, const K &key={}, std::string doc="")
Autodeclaring constructor with property name, mode, key and documentation.
T * put(std::unique_ptr< T > object) const
Register object in transient store.
bool verifyType(const DataObject *dataObj)
T * getIfExists() const
Bypass check of existence of object in transient store Only uses main location of the.
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
std::optional< std::size_t > size() const
Size of boxed item, if boxed item has a 'size' method.
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... >)
T * getOrCreate() const
Get object from store or create a new one if it doesn't exist.
T * get() const
Retrieve object from transient data store.
std::conditional_t< std::is_base_of_v< DataObject, T >, T, AnyDataWrapper< T > > type
T(*)(const DataObject *) Converter_t
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
Out1 * put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
auto begin(reverse_wrapper< T > &w)
Useful class for representation of "sequence" of the objects through the range of valid iterators.
constexpr static const auto FAILURE
Converter_t< Range > select_range_converter(const DataObject *obj)
DataObjectWriteHandle(const DataObjID &k, IDataHandleHolder *owner)
DataObjectWriteHandle(const std::tuple< Args... > &args)
std::remove_cv_t< std::remove_pointer_t< typename T::value_type > > ValueType
A DataObject is the base class of any identifiable object on any data store.
Type
the list of available types for ntuples
DataObjectReadHandle(const std::tuple< Args... > &args)
Header file for std:chrono::duration-based Counters.
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
DataObjectWriteHandle(const std::tuple< Args... > &args, std::index_sequence< Is... >)