2 * Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration.
5 * @file StoreGate/WriteDecorHandleKey.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Property holding a SG store/key/clid/attr name from which a
9 * WriteDecorHandle is made.
13 #include "StoreGate/DecorKeyHelpers.h"
14 #include "GaudiKernel/IDataHandleHolder.h"
24 * @brief Optionally register read dependency of a @c WriteDecorHandleKey.
26 void registerWriteDecorHandleKey (IDataHandleHolder* owner,
27 const DataObjID& contHandleKey);
35 * @param key The StoreGate key for the object.
36 * @param storeName Name to use for the store, if it's not encoded in sgkey.
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 named by @c storeName is used.
43 WriteDecorHandleKey<T>::WriteDecorHandleKey (const std::string& key /*= ""*/,
44 const std::string& storeName /*= "StoreGateSvc"*/) :
45 Base (key, storeName),
46 m_contHandleKey (contKeyFromKey (key), storeName)
52 * @brief Constructor with associated container.
53 * @param contKey WriteHandleKey of the associated container
54 * @param decorKey The decoration name.
55 * @param storeName Name to use for the store.
57 * The decoration @decorKey will be applied on the container referenced
61 WriteDecorHandleKey<T>::WriteDecorHandleKey (const VarHandleKey& contKey,
62 const std::string& decorKey /*= ""*/,
63 const std::string& storeName /*= "StoreGateSvc"*/) :
64 Base (makeContDecorKey (contKey, decorKey), storeName),
65 m_contHandleKey (contKey.key(), storeName),
72 * @brief auto-declaring Property Constructor.
73 * @param owner Owning component.
74 * @param name name of the Property
75 * @param key default StoreGate key for the object.
76 * @param doc Documentation string.
78 * will associate the named Property with this key via declareProperty
80 * The provided key may actually start with the name of the store,
81 * separated by a "+": "MyStore+Obj". If no "+" is present
82 * the store named by @c storeName is used.
85 template <class OWNER,
86 typename /*= typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type*/>
88 WriteDecorHandleKey<T>::WriteDecorHandleKey( OWNER* owner,
89 const std::string& name,
90 const std::string& key /*={}*/,
91 const std::string& doc /*=""*/)
92 : Base (owner, name, key, doc),
93 m_contHandleKey (contKeyFromKey (key), StoreID::storeName(StoreID::EVENT_STORE) )
99 * @brief auto-declaring Property Constructor.
100 * @param owner Owning component.
101 * @param name name of the Property
102 * @param contKey WriteHandleKey of the associated container
103 * @param decorKey name The decoration name.
104 * @param doc Documentation string.
106 * will associate the named Property with this WDHK via declareProperty
109 template <class OWNER,
110 typename /*= typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type*/>
112 WriteDecorHandleKey<T>::WriteDecorHandleKey( OWNER* owner,
113 const std::string& name,
114 const VarHandleKey& contKey,
115 const std::string& decorKey /*={}*/,
116 const std::string& doc /*=""*/)
117 : Base (owner, name, makeContDecorKey (contKey, decorKey), doc),
118 m_contHandleKey (contKey.key(), StoreID::storeName(StoreID::EVENT_STORE)),
127 * @brief Change the key of the object to which we're referring.
128 * @param sgkey The StoreGate key for the object.
130 * The provided key may actually start with the name of the store,
131 * separated by a "+": "MyStore+Obj". If no "+" is present,
132 * the store is not changed.
135 WriteDecorHandleKey<T>&
136 WriteDecorHandleKey<T>::operator= (const std::string& sgkey)
138 const std::string key = m_contKey ? makeContDecorKey(*m_contKey, sgkey) : sgkey;
139 m_contHandleKey = contKeyFromKey (key);
140 Base::operator= (key);
146 * @brief Change the key of the object to which we're referring.
147 * @param sgkey The StoreGate key for the object.
149 * The provided key may actually start with the name of the store,
150 * separated by a "+": "MyStore+Obj". If no "+" is present
151 * the store is not changed. A key name that starts with a "+"
152 * is interpreted as a hierarchical key name, not an empty store name.
154 * Returns failure the key string format is bad.
157 StatusCode WriteDecorHandleKey<T>::assign (const std::string& sgkey)
159 const std::string key = m_contKey ? makeContDecorKey(*m_contKey, sgkey) : sgkey;
160 if (m_contHandleKey.assign (contKeyFromKey (key)).isFailure())
161 return StatusCode::FAILURE;
162 return Base::assign (key);
167 * @brief If this object is used as a property, then this should be called
168 * during the initialize phase. It will fail if the requested
169 * StoreGate service cannot be found or if the key is blank.
171 * @param used If false, then this handle is not to be used.
172 * Instead of normal initialization, the key will be cleared.
175 StatusCode WriteDecorHandleKey<T>::initialize (bool used /*= true*/)
177 // If a parent container is used, its key may have changed
179 m_contHandleKey = m_contKey->key();
180 std::string decorKey=decorKeyFromKey(this->key());
181 VarHandleKey::operator=(makeContDecorKey (m_contKey->key(), decorKey));
183 detail::registerWriteDecorHandleKey (this->owner(), m_contHandleKey.fullKey());
184 if (m_contHandleKey.initialize (used).isFailure())
185 return StatusCode::FAILURE;
186 return Base::initialize (used);
191 * @brief Python representation of Handle.
194 std::string WriteDecorHandleKey<T>::pythonRepr() const
196 std::string repr = Base::pythonRepr();
197 // With a parent container our representation becomes the decoration name only.
199 removeContFromDecorKey(*m_contKey, repr);
206 * @brief Return the handle key for the container.
209 const ReadHandleKey<T>& WriteDecorHandleKey<T>::contHandleKey() const
211 return m_contHandleKey;
216 * @brief Return the handle key for the container.
219 ReadHandleKey<T>& WriteDecorHandleKey<T>::contHandleKey_nc()
221 return m_contHandleKey;
226 * @brief Declare that this item does not participate in scheduling.
228 * If a WriteDataHandleKey is renounced, then we skip creating the
229 * output alias. Further, we skip the check that the element provided
230 * is a member of the declared container. A WriteDataHandle initialized
231 * from a renounced key will effectively behave like a simple Decorator.
235 void WriteDecorHandleKey<T>::renounce()
242 * @brief Return the renounced flag.
246 bool WriteDecorHandleKey<T>::renounced() const