2 * Copyright (C) 2002-2024 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
107 * The container part of the decoration key will be taken from @c contKey,
108 * while @c decorKey gives the name of the decoration itself.
109 * If @c decorKey is blank, then the overall key will be blank.
112 template <class OWNER,
113 typename /*= typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type*/>
115 WriteDecorHandleKey<T>::WriteDecorHandleKey( OWNER* owner,
116 const std::string& name,
117 const VarHandleKey& contKey,
118 const std::string& decorKey /*={}*/,
119 const std::string& doc /*=""*/)
120 : Base (owner, name, makeContDecorKey (contKey, decorKey), doc),
121 m_contHandleKey (contKey.key(), StoreID::storeName(StoreID::EVENT_STORE)),
130 * @brief Change the key of the object to which we're referring.
131 * @param sgkey The StoreGate key for the object.
133 * The provided key may actually start with the name of the store,
134 * separated by a "+": "MyStore+Obj". If no "+" is present,
135 * the store is not changed.
138 WriteDecorHandleKey<T>&
139 WriteDecorHandleKey<T>::operator= (const std::string& sgkey)
141 const std::string key = m_contKey ? makeContDecorKey(*m_contKey, sgkey) : sgkey;
142 m_contHandleKey = contKeyFromKey (key);
143 Base::operator= (key);
149 * @brief Change the key of the object to which we're referring.
150 * @param sgkey The StoreGate key for the object.
152 * The provided key may actually start with the name of the store,
153 * separated by a "+": "MyStore+Obj". If no "+" is present
154 * the store is not changed. A key name that starts with a "+"
155 * is interpreted as a hierarchical key name, not an empty store name.
157 * Returns failure the key string format is bad.
160 StatusCode WriteDecorHandleKey<T>::assign (const std::string& sgkey)
162 const std::string key = m_contKey ? makeContDecorKey(*m_contKey, sgkey) : sgkey;
163 if (m_contHandleKey.assign (contKeyFromKey (key)).isFailure())
164 return StatusCode::FAILURE;
165 return Base::assign (key);
170 * @brief If this object is used as a property, then this should be called
171 * during the initialize phase. It will fail if the requested
172 * StoreGate service cannot be found or if the key is blank.
174 * @param used If false, then this handle is not to be used.
175 * Instead of normal initialization, the key will be cleared.
178 StatusCode WriteDecorHandleKey<T>::initialize (bool used /*= true*/)
180 // If a parent container is used, its key may have changed
182 m_contHandleKey = m_contKey->key();
183 std::string decorKey=decorKeyFromKey(this->key());
184 VarHandleKey::operator=(makeContDecorKey (m_contKey->key(), decorKey));
187 detail::registerWriteDecorHandleKey (this->owner(), m_contHandleKey.fullKey());
189 if (m_contHandleKey.initialize (used).isFailure())
190 return StatusCode::FAILURE;
191 return Base::initialize (used);
196 * @brief If this object is used as a property, then this should be called
197 * during the initialize phase. This variant will allow the key
199 * @param Flag to select this variant. Call like
201 * ATH_CHECK( key.initialize (SG::AllowEmpty) );
205 StatusCode WriteDecorHandleKey<T>::initialize (AllowEmptyEnum)
207 if (this->key().empty()) {
208 return StatusCode::SUCCESS;
210 return this->initialize (true);
215 * @brief Python representation of Handle.
218 std::string WriteDecorHandleKey<T>::pythonRepr() const
220 std::string repr = Base::pythonRepr();
221 // With a parent container our representation becomes the decoration name only.
223 removeContFromDecorKey(*m_contKey, repr);
230 * @brief Return the handle key for the container.
233 const ReadHandleKey<T>& WriteDecorHandleKey<T>::contHandleKey() const
235 return m_contHandleKey;
240 * @brief Return the handle key for the container.
243 ReadHandleKey<T>& WriteDecorHandleKey<T>::contHandleKey_nc()
245 return m_contHandleKey;
250 * @brief Declare that this item does not participate in scheduling.
252 * If a WriteDataHandleKey is renounced, then we skip creating the
253 * output alias. Further, we skip the check that the element provided
254 * is a member of the declared container. A WriteDataHandle initialized
255 * from a renounced key will effectively behave like a simple Decorator.
259 void WriteDecorHandleKey<T>::renounce()
266 * @brief Return the renounced flag.
270 bool WriteDecorHandleKey<T>::renounced() const