ATLAS Offline Software
AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandleKey.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /**
6  * @file AsgDataHandles/ReadDecorHandleKey.icc
7  * @author Nils Krumnack <Nils.Erik.Krumnack@cern.h>
8  * @author scott snyder <snyder@bnl.gov> (for original)
9  * @brief Property holding a SG store/key/clid/attr name from which a
10  * ReadDecorHandle is made.
11  */
12 
13 #include <AsgDataHandles/DecorKeyHelpers.h>
14 
15 
16 namespace SG {
17 
18 
19 /**
20  * @brief Constructor.
21  * @param key The StoreGate key for the object.
22  * @param storeName Name to use for the store, if it's not encoded in sgkey.
23  *
24  * The provided key may actually start with the name of the store,
25  * separated by a "+": "MyStore+Obj". If no "+" is present
26  * the store named by @c storeName is used.
27  */
28 template <class T>
29 inline
30 ReadDecorHandleKey<T>::ReadDecorHandleKey (const std::string& key /*= ""*/)
31  // const std::string& storeName /*= StoreID::storeName(StoreID::EVENT_STORE)*/)
32  // : Base (ClassID_traits<topbase_t>::ID(), key, storeName),
33  : Base (key),
34  m_contHandleKey (contKeyFromKey (key)/*, storeName*/)
35 {
36 }
37 
38 
39 /**
40  * @brief auto-declaring Property Constructor.
41  * @param owner Owning component.
42  * @param name name of the Property
43  * @param key default StoreGate key for the object.
44  * @param doc Documentation string.
45  *
46  * will associate the named Property with this RHK via declareProperty
47  *
48  * The provided key may actually start with the name of the store,
49  * separated by a "+": "MyStore+Obj". If no "+" is present
50  * the store named by @c storeName is used.
51  */
52 template <class T>
53 template <class OWNER, class K>
54 inline
55 ReadDecorHandleKey<T>::ReadDecorHandleKey( OWNER* owner,
56  const std::string& name,
57  const K& key /*={}*/,
58  const std::string& doc /*=""*/)
59  : Base (key),
60  m_contHandleKey (contKeyFromKey (key)/*, StoreID::storeName(StoreID::EVENT_STORE) */)
61 {
62  owner->declareProperty(name, *this, doc);
63 }
64 
65 
66 /**
67  * @brief Change the key of the object to which we're referring.
68  * @param sgkey The StoreGate key for the object.
69  *
70  * The provided key may actually start with the name of the store,
71  * separated by a "+": "MyStore+Obj". If no "+" is present,
72  * the store is not changed.
73  */
74 template <class T>
75 ReadDecorHandleKey<T>&
76 ReadDecorHandleKey<T>::operator= (const std::string& sgkey)
77 {
78  m_contHandleKey = contKeyFromKey (sgkey);
79  Base::operator= (sgkey);
80  return *this;
81 }
82 
83 
84 /**
85  * @brief Change the key of the object to which we're referring.
86  * @param sgkey The StoreGate key for the object.
87  *
88  * The provided key may actually start with the name of the store,
89  * separated by a "+": "MyStore+Obj". If no "+" is present
90  * the store is not changed. A key name that starts with a "+"
91  * is interpreted as a hierarchical key name, not an empty store name.
92  *
93  * Returns failure the key string format is bad.
94  */
95 template <class T>
96 StatusCode ReadDecorHandleKey<T>::assign (const std::string& sgkey)
97 {
98  if (m_contHandleKey.assign (contKeyFromKey (sgkey)).isFailure())
99  return StatusCode::FAILURE;
100  return Base::assign (sgkey);
101 }
102 
103 
104 // /**
105 // * @brief Return the class ID for the referenced object.
106 // *
107 // * Overridden here to return the CLID for @c T instead of @c topbase_t.
108 // */
109 // template <class T>
110 // inline
111 // CLID ReadDecorHandleKey<T>::clid() const
112 // {
113 // return ClassID_traits<T>::ID();
114 // }
115 
116 
117 /**
118  * @brief If this object is used as a property, then this should be called
119  * during the initialize phase. It will fail if the requested
120  * StoreGate service cannot be found or if the key is blank.
121  *
122  * @param used If false, then this handle is not to be used.
123  * Instead of normal initialization, the key will be cleared.
124  */
125 template <class T>
126 StatusCode ReadDecorHandleKey<T>::initialize (bool used /*= true*/)
127 {
128  if (m_contHandleKey.initialize (used).isFailure())
129  return StatusCode::FAILURE;
130  return Base::initialize (used);
131 }
132 
133 
134 /**
135  * @brief Return the handle key for the container.
136  */
137 template <class T>
138 const ReadHandleKey<T>& ReadDecorHandleKey<T>::contHandleKey() const
139 {
140  return m_contHandleKey;
141 }
142 
143 
144 } // namespace SG