2 * Copyright (C) 2002-2025 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.
26void 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.
43WriteDecorHandleKey<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
61WriteDecorHandleKey<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.
85template <std::derived_from<IProperty> OWNER>
87WriteDecorHandleKey<T>::WriteDecorHandleKey( OWNER* owner,
88 const std::string& name,
89 const std::string& key /*={}*/,
90 const std::string& doc /*=""*/)
91 : Base (owner, name, key, doc),
92 m_contHandleKey (contKeyFromKey (key), StoreID::storeName(StoreID::EVENT_STORE) )
98 * @brief auto-declaring Property Constructor.
99 * @param owner Owning component.
100 * @param name name of the Property
101 * @param contKey WriteHandleKey of the associated container
102 * @param decorKey name The decoration name.
103 * @param doc Documentation string.
105 * Will associate the named Property with this WDHK via declareProperty
106 * The container part of the decoration key will be taken from @c contKey,
107 * while @c decorKey gives the name of the decoration itself.
108 * If @c decorKey is blank, then the overall key will be blank.
111template <std::derived_from<IProperty> OWNER>
113WriteDecorHandleKey<T>::WriteDecorHandleKey( OWNER* owner,
114 const std::string& name,
115 const VarHandleKey& contKey,
116 const std::string& decorKey /*={}*/,
117 const std::string& doc /*=""*/)
118 : Base (owner, name, makeContDecorKey (contKey, decorKey), doc),
119 m_contHandleKey (contKey.key(), StoreID::storeName(StoreID::EVENT_STORE)),
128 * @brief Change the key of the object to which we're referring.
129 * @param sgkey The StoreGate key for the object.
131 * The provided key may actually start with the name of the store,
132 * separated by a "+": "MyStore+Obj". If no "+" is present,
133 * the store is not changed.
136WriteDecorHandleKey<T>&
137WriteDecorHandleKey<T>::operator= (const std::string& sgkey)
139 const std::string key = m_contKey ? makeContDecorKey(*m_contKey, sgkey) : sgkey;
140 m_contHandleKey = contKeyFromKey (key);
141 Base::operator= (key);
147 * @brief Change the key of the object to which we're referring.
148 * @param sgkey The StoreGate key for the object.
150 * The provided key may actually start with the name of the store,
151 * separated by a "+": "MyStore+Obj". If no "+" is present
152 * the store is not changed. A key name that starts with a "+"
153 * is interpreted as a hierarchical key name, not an empty store name.
155 * Returns failure if the key string format is bad.
158StatusCode WriteDecorHandleKey<T>::assign (const std::string& sgkey)
160 const std::string key = m_contKey ? makeContDecorKey(*m_contKey, sgkey) : sgkey;
161 if (m_contHandleKey.assign (contKeyFromKey (key)).isFailure())
162 return StatusCode::FAILURE;
163 return Base::assign (key);
168 * @brief If this object is used as a property, then this should be called
169 * during the initialize phase. It will fail if the requested
170 * StoreGate service cannot be found or if the key is blank.
172 * @param used If false, then this handle is not to be used.
173 * Instead of normal initialization, the key will be cleared.
176StatusCode WriteDecorHandleKey<T>::initialize (bool used /*= true*/)
178 // If a parent container is used, its key may have changed
180 m_contHandleKey = m_contKey->key();
181 const std::string decorKey = decorKeyFromKey(this->key(), this->key());
182 VarHandleKey::operator=(makeContDecorKey (m_contKey->key(), decorKey));
185 detail::registerWriteDecorHandleKey (this->owner(), m_contHandleKey.fullKey());
187 if (m_contHandleKey.initialize (used).isFailure())
188 return StatusCode::FAILURE;
189 return Base::initialize (used);
194 * @brief If this object is used as a property, then this should be called
195 * during the initialize phase. This variant will allow the key
197 * @param Flag to select this variant. Call like
199 * ATH_CHECK( key.initialize (SG::AllowEmpty) );
203StatusCode WriteDecorHandleKey<T>::initialize (AllowEmptyEnum)
205 if (this->key().empty()) {
206 return StatusCode::SUCCESS;
208 return this->initialize (true);
213 * @brief Python representation of Handle.
216std::string WriteDecorHandleKey<T>::pythonRepr() const
218 std::string repr = Base::pythonRepr();
219 // With a parent container our representation becomes the decoration name only.
221 removeContFromDecorKey(*m_contKey, repr);
228 * @brief Return the handle key for the container.
231const ReadHandleKey<T>& WriteDecorHandleKey<T>::contHandleKey() const
233 return m_contHandleKey;
238 * @brief Return the handle key for the container.
241ReadHandleKey<T>& WriteDecorHandleKey<T>::contHandleKey_nc()
243 return m_contHandleKey;
248 * @brief Declare that this item does not participate in scheduling.
250 * If a WriteDataHandleKey is renounced, then we skip creating the
251 * output alias. Further, we skip the check that the element provided
252 * is a member of the declared container. A WriteDataHandle initialized
253 * from a renounced key will effectively behave like a simple Decorator.
257void WriteDecorHandleKey<T>::renounce()
264 * @brief Return the renounced flag.
268bool WriteDecorHandleKey<T>::renounced() const