ATLAS Offline Software
AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandleKey.icc
Go to the documentation of this file.
1 // $Id$
2 /*
3  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
4  */
5 /**
6  * @file StoreGate/WriteDecorHandleKey.h
7  * @author Nils Krumnack <Nils.Erik.Krumnack@cern.h>
8  * @author scott snyder <snyder@bnl.gov> (for original version)
9  * @brief Property holding a SG store/key/clid/attr name from which a
10  * WriteDecorHandle is made.
11  */
12 
13 
14 #include "AsgDataHandles/DecorKeyHelpers.h"
15 // #include "GaudiKernel/IDataHandleHolder.h"
16 
17 
18 namespace SG {
19 
20 
21 // namespace detail {
22 
23 
24 // /**
25 // * @brief Optionally register read dependency of a @c WriteDecorHandleKey.
26 // */
27 // void registerWriteDecorHandleKey (IDataHandleHolder* owner,
28 // const DataObjID& contHandleKey);
29 
30 
31 // } // namespace detail
32 
33 
34 /**
35  * @brief Constructor.
36  * @param key The StoreGate key for the object.
37  * @param storeName Name to use for the store, if it's not encoded in sgkey.
38  *
39  * The provided key may actually start with the name of the store,
40  * separated by a "+": "MyStore+Obj". If no "+" is present
41  * the store named by @c storeName is used.
42  */
43 template <class T>
44 WriteDecorHandleKey<T>::WriteDecorHandleKey (const std::string& key /*= ""*/) :
45  // const std::string& storeName /*= "StoreGateSvc"*/) :
46  Base (key/*, storeName*/),
47  m_contHandleKey (contKeyFromKey (key)/*, storeName*/)
48 {
49 }
50 
51 
52 /**
53  * @brief auto-declaring Property Constructor.
54  * @param owner Owning component.
55  * @param name name of the Property
56  * @param key default StoreGate key for the object.
57  * @param doc Documentation string.
58  *
59  * will associate the named Property with this key via declareProperty
60  *
61  * The provided key may actually start with the name of the store,
62  * separated by a "+": "MyStore+Obj". If no "+" is present
63  * the store named by @c storeName is used.
64  */
65 template <class T>
66 template <class OWNER, class K>
67 inline
68 WriteDecorHandleKey<T>::WriteDecorHandleKey( OWNER* owner,
69  const std::string& name,
70  const K& key /*={}*/,
71  const std::string& doc /*=""*/)
72  : Base (key),
73  m_contHandleKey (contKeyFromKey (key)/*, StoreID::storeName(StoreID::EVENT_STORE) */)
74 {
75  owner->declareProperty(name, *this, doc);
76 }
77 
78 
79 /**
80  * @brief Change the key of the object to which we're referring.
81  * @param sgkey The StoreGate key for the object.
82  *
83  * The provided key may actually start with the name of the store,
84  * separated by a "+": "MyStore+Obj". If no "+" is present,
85  * the store is not changed.
86  */
87 template <class T>
88 WriteDecorHandleKey<T>&
89 WriteDecorHandleKey<T>::operator= (const std::string& sgkey)
90 {
91  m_contHandleKey = contKeyFromKey (sgkey);
92  Base::operator= (sgkey);
93  return *this;
94 }
95 
96 
97 /**
98  * @brief Change the key of the object to which we're referring.
99  * @param sgkey The StoreGate key for the object.
100  *
101  * The provided key may actually start with the name of the store,
102  * separated by a "+": "MyStore+Obj". If no "+" is present
103  * the store is not changed. A key name that starts with a "+"
104  * is interpreted as a hierarchical key name, not an empty store name.
105  *
106  * Returns failure the key string format is bad.
107  */
108 template <class T>
109 StatusCode WriteDecorHandleKey<T>::assign (const std::string& sgkey)
110 {
111  if (m_contHandleKey.assign (contKeyFromKey (sgkey)).isFailure())
112  return StatusCode::FAILURE;
113  return Base::assign (sgkey);
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 WriteDecorHandleKey<T>::initialize (bool used /*= true*/)
127 {
128  // detail::registerWriteDecorHandleKey (this->owner(), m_contHandleKey.fullKey());
129  if (m_contHandleKey.initialize (used).isFailure())
130  return StatusCode::FAILURE;
131  return Base::initialize (used);
132 }
133 
134 
135 /**
136  * @brief Return the handle key for the container.
137  */
138 template <class T>
139 const ReadHandleKey<T>& WriteDecorHandleKey<T>::contHandleKey() const
140 {
141  return m_contHandleKey;
142 }
143 
144 
145 // /**
146 // * @brief Return the handle key for the container.
147 // */
148 // template <class T>
149 // ReadHandleKey<T>& WriteDecorHandleKey<T>::contHandleKey_nc()
150 // {
151 // return m_contHandleKey;
152 // }
153 
154 
155 } // namespace SG
156