ATLAS Offline Software
StoreGate/StoreGate/ReadHandleKey.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 
12 namespace 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  */
24 template <class T>
25 ReadHandleKey<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  */
42 template <class T>
43 ReadHandleKey<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  */
63 template <class T>
64 template <class OWNER,
65  typename /*= typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type*/>
66 inline
67 ReadHandleKey<T>::ReadHandleKey( OWNER* owner,
68  const std::string& name,
69  const std::string& key /* ={}*/,
70  const std::string& doc /*= ""*/)
71  : ReadHandleKey<T>( key )
72 {
73  auto p = owner->declareProperty(name, *this, doc);
74  p->template setOwnerType<OWNER>();
75 }
76 
77 
78 /**
79  * @brief Constructor with explicit CLID.
80  * @param clid The CLID for the referenced object.
81  * @param key The StoreGate key for the object.
82  * @param storeName Name to use for the store, if it's not encoded in sgkey.
83  *
84  * This is meant to be used by @c ReadDecorHandleKey, to allow fixing the
85  * CLID to a base class to avoid scheduler issues.
86  */
87 template <class T>
88 inline
89 ReadHandleKey<T>::ReadHandleKey (CLID clid,
90  const std::string& key,
91  const std::string& storeName)
92  : VarHandleKey (clid, key, Gaudi::DataHandle::Reader, storeName)
93 {
94 }
95 
96 
97 /**
98  * @brief Auto-declaring constructor with explicit CLID.
99  * @param clid The CLID for the referenced object.
100  * @param owner Owning component.
101  * @param name name of the Property
102  * @param key The StoreGate key for the object.
103  * @param doc Documentation string.
104  *
105  * This is meant to be used by @c ReadDecorHandleKey, to allow fixing the
106  * CLID to a base class to avoid scheduler issues.
107  */
108 template <class T>
109 template <class OWNER,
110  typename /*= typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type*/>
111 inline
112 ReadHandleKey<T>::ReadHandleKey( CLID clid,
113  OWNER* owner,
114  const std::string& name,
115  const std::string& key,
116  const std::string& doc)
117  : ReadHandleKey<T>( clid, key, StoreID::storeName(StoreID::EVENT_STORE) )
118 {
119  auto p = owner->declareProperty(name, *this, doc);
120  p->template setOwnerType<OWNER>();
121 }
122 
123 
124 /**
125  * @brief Constructor.
126  * @param key The StoreGate key for the object.
127  * @param storeName Name to use for the store, if it's not encoded in sgkey.
128  *
129  * The provided key may actually start with the name of the store,
130  * separated by a "+": "MyStore+Obj". If no "+" is present
131  * the store named by @c storeName is used.
132  */
133 template <class T>
134 InitializedReadHandleKey<T>::InitializedReadHandleKey (const std::string& key /*= ""*/,
135  const std::string& storeName /*= StoreID::storeName(StoreID::EVENT_STORE)*/)
136  : ReadHandleKey<T> (key, storeName)
137 {
138  if (this->initialize().isFailure()) {
139  throw SG::ExcBadInitializedReadHandleKey();
140  }
141 }
142 
143 
144 } // namespace SG