ATLAS Offline Software
Loading...
Searching...
No Matches
MetaContDataBucket.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4/**
5 * @file AthenaKernel/MetaContDataBucket.icc
6 * @author scott snyder <snyder@bnl.gov>
7 * @date Jan, 2018
8 * @brief Allow converting MetaCont<T> to T.
9 */
10
11
12namespace SG {
13
14
15/**
16 * @brief Return the contents of the @c DataBucket,
17 * converted to type given by @a clid. Note that only
18 * derived->base conversions are allowed here.
19 * @param clid The class ID to which to convert.
20 * @param irt To be called if we make a new instance.
21 * @param isConst True if the object being converted is regarded as const.
22 */
23template <class T>
24void* MetaContDataBucket<T>::cast (CLID clid,
25 IRegisterTransient* irt /*= 0*/,
26 bool isConst /*= true*/)
27{
28 // First try normal conversion.
29 if (void* ret = DataBucket<T>::cast (clid, irt, isConst)) {
30 return ret;
31 }
32
33 // Otherwise, try to retrieve the payload and cast it as requested.
34 typename T::Payload_t* payload = nullptr;
35 if (this->ptr()->find (getSID(), payload)) {
36 return SG::BaseInfo<typename T::Payload_t>::cast (payload, clid);
37 }
38 return nullptr;
39}
40
41
42/**
43 * @brief Return the contents of the @c DataBucket,
44 * converted to type given by @a std::type_info. Note that only
45 * derived->base conversions are allowed here.
46 * @param clid The @a std::type_info of the type to which to convert.
47 * @param irt To be called if we make a new instance.
48 * @param isConst True if the object being converted is regarded as const.
49 */
50template <class T>
51void* MetaContDataBucket<T>::cast (const std::type_info& tinfo,
52 IRegisterTransient* irt /*= 0*/,
53 bool isConst /*= true*/)
54{
55 if (void* ret = DataBucket<T>::cast (tinfo, irt, isConst)) {
56 return ret;
57 }
58 // Otherwise, try to retrieve the payload and cast it as requested.
59 typename T::Payload_t* payload = nullptr;
60 if (this->ptr()->find (getSID(), payload)) {
61 return SG::BaseInfo<typename T::Payload_t>::cast (payload, tinfo);
62 }
63 return nullptr;
64}
65
66
67/**
68 * @brief Return the contents of the @c DataBucket,
69 * converted to type given by @a clid. Note that only
70 * derived->base conversions are allowed here.
71 * @param clid The class ID to which to convert.
72 * @param tinfo The @a std::type_info of the type to which to convert.
73 * @param irt To be called if we make a new instance.
74 * @param isConst True if the object being converted is regarded as const.
75 *
76 * This allows the callee to choose whether to use clid or tinfo.
77 * Here we use clid.
78 */
79template <class T>
80inline
81void* MetaContDataBucket<T>::cast (CLID clid,
82 const std::type_info& /*tinfo*/,
83 SG::IRegisterTransient* irt /*= 0*/,
84 bool isConst /*= true*/)
85{
86 return MetaContDataBucket::cast (clid, irt, isConst);
87}
88
89
90/**
91 * @brief Return the metadata source id for the current event store.
92 * Returns an empty string if there's no source ID set.
93 */
94template <class T>
95const SourceID MetaContDataBucket<T>::getSID() const
96{
97 return Atlas::sourceIDFromEventContext();
98}
99
100
101} // namespace SG