2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 * @file StoreGate/ReadDecorHandleKey.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Property holding a SG store/key/clid/attr name from which a
9 * ReadDecorHandle is made.
13 #include "StoreGate/DecorKeyHelpers.h"
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.
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.
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 m_contHandleKey (contKeyFromKey (key), storeName)
39 * @brief Constructor with associated container.
40 * @param contKey ReadHandleKey of the associated container
41 * @param decorKey The decoration name.
42 * @param storeName Name to use for the store.
44 * The decoration @decorKey will be read from the container referenced
49 ReadDecorHandleKey<T>::ReadDecorHandleKey (const VarHandleKey& contKey,
50 const std::string& decorKey /*= /""*/,
51 const std::string& storeName /*= StoreID::storeName(StoreID::EVENT_STORE*/)
52 : Base (ClassID_traits<topbase_t>::ID(), makeContDecorKey (contKey, decorKey), storeName),
53 m_contHandleKey (contKey.key(), storeName),
60 * @brief auto-declaring Property Constructor.
61 * @param owner Owning component.
62 * @param name name of the Property
63 * @param key default StoreGate key for the object.
64 * @param doc Documentation string.
66 * will associate the named Property with this RHK via declareProperty
68 * The provided key may actually start with the name of the store,
69 * separated by a "+": "MyStore+Obj". If no "+" is present
70 * the store named by @c storeName is used.
73 template <class OWNER,
74 typename /*= typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type*/>
76 ReadDecorHandleKey<T>::ReadDecorHandleKey( OWNER* owner,
77 const std::string& name,
78 const std::string& key /*={}*/,
79 const std::string& doc /*=""*/)
80 : Base (ClassID_traits<topbase_t>::ID(), owner, name, key, doc),
81 m_contHandleKey (contKeyFromKey (key), StoreID::storeName(StoreID::EVENT_STORE) )
87 * @brief auto-declaring Property Constructor.
88 * @param owner Owning component.
89 * @param name name of the Property
90 * @param key default StoreGate key for the object.
91 * @param doc Documentation string.
93 * will associate the named Property with this RHK via declareProperty
95 * The provided key may actually start with the name of the store,
96 * separated by a "+": "MyStore+Obj". If no "+" is present
97 * the store named by @c storeName is used.
100 template <class OWNER,
101 typename /*= typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type*/>
103 ReadDecorHandleKey<T>::ReadDecorHandleKey( OWNER* owner,
104 const std::string& name,
105 const VarHandleKey& contKey,
106 const std::string& decorKey /*= {}*/,
107 const std::string& doc /*= ""*/)
108 : Base (ClassID_traits<topbase_t>::ID(), owner, name, makeContDecorKey (contKey, decorKey), doc),
109 m_contHandleKey (contKey.key(), StoreID::storeName(StoreID::EVENT_STORE) ),
116 * @brief Change the key of the object to which we're referring.
117 * @param sgkey The StoreGate key for the object.
119 * The provided key may actually start with the name of the store,
120 * separated by a "+": "MyStore+Obj". If no "+" is present,
121 * the store is not changed.
124 ReadDecorHandleKey<T>&
125 ReadDecorHandleKey<T>::operator= (const std::string& sgkey)
127 const std::string key = m_contKey ? makeContDecorKey(*m_contKey, sgkey) : sgkey;
128 m_contHandleKey = contKeyFromKey (key);
129 Base::operator= (key);
135 * @brief Change the key of the object to which we're referring.
136 * @param sgkey The StoreGate key for the object.
138 * The provided key may actually start with the name of the store,
139 * separated by a "+": "MyStore+Obj". If no "+" is present
140 * the store is not changed. A key name that starts with a "+"
141 * is interpreted as a hierarchical key name, not an empty store name.
143 * Returns failure the key string format is bad.
146 StatusCode ReadDecorHandleKey<T>::assign (const std::string& sgkey)
148 const std::string key = m_contKey ? makeContDecorKey(*m_contKey, sgkey) : sgkey;
149 if (m_contHandleKey.assign (contKeyFromKey (key)).isFailure())
150 return StatusCode::FAILURE;
151 return Base::assign (key);
156 * @brief Return the class ID for the referenced object.
158 * Overridden here to return the CLID for @c T instead of @c topbase_t.
162 CLID ReadDecorHandleKey<T>::clid() const
164 return ClassID_traits<T>::ID();
169 * @brief If this object is used as a property, then this should be called
170 * during the initialize phase. It will fail if the requested
171 * StoreGate service cannot be found or if the key is blank.
173 * @param used If false, then this handle is not to be used.
174 * Instead of normal initialization, the key will be cleared.
177 StatusCode ReadDecorHandleKey<T>::initialize (bool used /*= true*/)
179 // If a parent container is used, its key may have changed
181 m_contHandleKey = m_contKey->key();
182 std::string decorKey=decorKeyFromKey(this->key());
183 VarHandleKey::operator=(makeContDecorKey (m_contKey->key(), decorKey));
186 if (m_contHandleKey.initialize (used).isFailure())
187 return StatusCode::FAILURE;
188 return Base::initialize (used);
193 * @brief Python representation of Handle.
196 std::string ReadDecorHandleKey<T>::pythonRepr() const
198 std::string repr = Base::pythonRepr();
199 // With a parent container our representation becomes the decoration name only.
201 removeContFromDecorKey(*m_contKey, repr);
208 * @brief Return the handle key for the container.
211 const ReadHandleKey<T>& ReadDecorHandleKey<T>::contHandleKey() const
213 return m_contHandleKey;