ATLAS Offline Software
Loading...
Searching...
No Matches
StoreGate/StoreGate/ReadHandleKey.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4/**
5 * @file StoreGate/ReadHandleKey.icc
6 * @author scott snyder <snyder@bnl.gov>
7 * @date Feb, 2016
8 * @brief Property holding a SG store/key/clid from which a ReadHandle is made.
9 */
10
11
12namespace SG {
13
14
15/**
16 * @brief Constructor.
17 * @param key The StoreGate key for the object.
18 * @param storeName Name to use for the store, if it's not encoded in sgkey.
19 *
20 * The provided key may actually start with the name of the store,
21 * separated by a "+": "MyStore+Obj". If no "+" is present
22 * the store named by @c storeName is used.
23 */
24template <class T>
25ReadHandleKey<T>::ReadHandleKey (const std::string& key /*= ""*/,
26 const std::string& storeName /*= "StoreGateSvc"*/)
27 : VarHandleKey (ClassID_traits<T>::ID(), key,
28 Gaudi::DataHandle::Reader,
29 storeName)
30{
31}
32
33
34/**
35 * @brief Change the key of the object to which we're referring.
36 * @param sgkey The StoreGate key for the object.
37 *
38 * The provided key may actually start with the name of the store,
39 * separated by a "+": "MyStore+Obj". If no "+" is present,
40 * the store is not changed.
41 */
42template <class T>
43ReadHandleKey<T>& ReadHandleKey<T>::operator= (const std::string& sgkey)
44{
45 VarHandleKey::operator= (sgkey);
46 return *this;
47}
48
49
50/**
51 * @brief Auto-declaring Property constructor.
52 * @param owner Owning component.
53 * @param name Name of the Property.
54 * @param key Default StoreGate key for the object.
55 * @param doc Documentation string.
56 *
57 * Will associate the named Property with this RHK via declareProperty.
58 *
59 * The provided key may actually start with the name of the store,
60 * separated by a "+": "MyStore+Obj". If no "+" is present
61 * the store named by @c storeName is used.
62 */
63template <class T>
64template <std::derived_from<IProperty> OWNER>
65inline
66ReadHandleKey<T>::ReadHandleKey( OWNER* owner,
67 const std::string& name,
68 const std::string& key /* ={}*/,
69 const std::string& doc /*= ""*/)
70 : ReadHandleKey<T>( key )
71{
72 auto p = owner->declareProperty(name, *this, doc);
73 p->template setOwnerType<OWNER>();
74}
75
76
77/**
78 * @brief Constructor with explicit CLID.
79 * @param clid The CLID for the referenced object.
80 * @param key The StoreGate key for the object.
81 * @param storeName Name to use for the store, if it's not encoded in sgkey.
82 *
83 * This is meant to be used by @c ReadDecorHandleKey, to allow fixing the
84 * CLID to a base class to avoid scheduler issues.
85 */
86template <class T>
87inline
88ReadHandleKey<T>::ReadHandleKey (CLID clid,
89 const std::string& key,
90 const std::string& storeName)
91 : VarHandleKey (clid, key, Gaudi::DataHandle::Reader, storeName)
92{
93}
94
95
96/**
97 * @brief Auto-declaring constructor with explicit CLID.
98 * @param clid The CLID for the referenced object.
99 * @param owner Owning component.
100 * @param name name of the Property
101 * @param key The StoreGate key for the object.
102 * @param doc Documentation string.
103 *
104 * This is meant to be used by @c ReadDecorHandleKey, to allow fixing the
105 * CLID to a base class to avoid scheduler issues.
106 */
107template <class T>
108template <std::derived_from<IProperty> OWNER>
109inline
110ReadHandleKey<T>::ReadHandleKey( CLID clid,
111 OWNER* owner,
112 const std::string& name,
113 const std::string& key,
114 const std::string& doc)
115 : ReadHandleKey<T>( clid, key, StoreID::storeName(StoreID::EVENT_STORE) )
116{
117 auto p = owner->declareProperty(name, *this, doc);
118 p->template setOwnerType<OWNER>();
119}
120
121
122/**
123 * @brief Constructor.
124 * @param key The StoreGate key for the object.
125 * @param storeName Name to use for the store, if it's not encoded in sgkey.
126 *
127 * The provided key may actually start with the name of the store,
128 * separated by a "+": "MyStore+Obj". If no "+" is present
129 * the store named by @c storeName is used.
130 */
131template <class T>
132InitializedReadHandleKey<T>::InitializedReadHandleKey (const std::string& key /*= ""*/,
133 const std::string& storeName /*= StoreID::storeName(StoreID::EVENT_STORE)*/)
134 : ReadHandleKey<T> (key, storeName)
135{
136 if (this->initialize().isFailure()) {
137 throw SG::ExcBadInitializedReadHandleKey();
138 }
139}
140
141
142} // namespace SG