ATLAS Offline Software
ThinningHandleKey.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 /**
5  * @file StoreGate/ThinningHandleKey.icc
6  * @author scott snyder <snyder@bnl.gov>
7  * @date Sep, 2019
8  * @brief HandleKey object for adding thinning to an object.
9  */
10 
11 
12 #include <algorithm>
13 
14 
15 namespace SG {
16 
17 
18 /**
19  * @brief Constructor.
20  * @param key The StoreGate key for the object.
21  * @param storeName Name to use for the store, if it's not encoded in sgkey.
22  *
23  * The provided key may actually start with the name of the store,
24  * separated by a "+": "MyStore+Obj". If no "+" is present
25  * the store named by @c storeName is used.
26  */
27 template <class T>
28 ThinningHandleKey<T>::ThinningHandleKey
29  (const std::string& key /*= ""*/,
30  const std::string& storeName /*= StoreID::storeName(StoreID::EVENT_STORE)*/)
31  : Base (key, storeName)
32 {
33 }
34 
35 
36 /**
37  * @brief Auto-declaring Property constructor.
38  * @param owner Owning component.
39  * @param name Name of the Property.
40  * @param key Default StoreGate key for the object.
41  * @param doc Documentation string.
42  *
43  * Will associate the named Property with this key via declareProperty.
44  *
45  * The provided key may actually start with the name of the store,
46  * separated by a "+": "MyStore+Obj". If no "+" is present
47  * the store named by @c storeName is used.
48  */
49 template <class T>
50 template <class OWNER,
51  typename /*= typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type*/>
52 ThinningHandleKey<T>::ThinningHandleKey( OWNER* owner,
53  const std::string& name,
54  const std::string& key,
55  const std::string& doc)
56  : Base (owner, name, key, doc)
57 {
58  this->setOwner (owner);
59 }
60 
61 
62 /**
63  * @brief Assignment.
64  * @param other Key to assign.
65  */
66 template <class T>
67 ThinningHandleKey<T>& ThinningHandleKey<T>::operator= (const ThinningHandleKey& other)
68 {
69  // Don't copy m_decisionKey.
70  Base::operator= (other);
71  return *this;
72 }
73 
74 
75 /**
76  * @brief Change the key of the object to which we're referring.
77  * @param sgkey The StoreGate key for the object.
78  *
79  * The provided key may actually start with the name of the store,
80  * separated by a "+": "MyStore+Obj". If no "+" is present,
81  * the store is not changed.
82  */
83 template <class T>
84 ThinningHandleKey<T>& ThinningHandleKey<T>::operator= (const std::string& sgkey)
85 {
86  // Don't copy m_decisionKey.
87  Base::operator= (sgkey);
88  return *this;
89 }
90 
91 
92 /**
93  * @brief Should be called during the initialize phase. It will fail
94  * if the requested StoreGate service cannot be found or if the key is blank.
95  * @param stream The name of the stream for which thinning is being applied.
96  * @param qualifier Qualifier to add on to the key for the decision object.
97  * If there are multiple algorithms thinning the same object,
98  * this can be used to keep them from interfering with
99  * each other. (The thinning decisions will be merged with AND
100  * at the end.)
101  * @param used If false, then this handle is not to be used.
102  * Instead of normal initialization, the key will be cleared.
103  */
104 template <class T>
105 StatusCode ThinningHandleKey<T>::initialize (const std::string& stream,
106  const std::string& qualifier,
107  bool used /*= true*/)
108 {
109  if (used) {
110  std::string dkey = this->fullKey().key() + "_THINNED_" + stream;
111  if (!qualifier.empty()) {
112  // Make sure that the qualifier doesn't contain any periods.
113  std::string qual = qualifier;
114  std::replace (qual.begin(), qual.end(), '.', '_');
115  dkey += "." + qual;
116  }
117  m_decisionKey = dkey;
118  if (this->owner()) {
119  this->owner()->addDependency (m_decisionKey.fullKey(), Gaudi::DataHandle::Writer);
120  }
121  if (m_decisionKey.initialize (used).isFailure())
122  return StatusCode::FAILURE;
123  }
124  return Base::initialize (used);
125 }
126 
127 
128 /**
129  * @brief Should be called during the initialize phase. It will fail
130  * if the requested StoreGate service cannot be found or if the key is blank.
131  * @param stream The name of the stream for which thinning is being applied.
132  * @param qualifier Qualifier to add on to the key for the decision object.
133  * If there are multiple algorithms thinning the same object,
134  * this can be used to keep them from interfering with
135  * each other. (The thinning decisions will be merged with AND
136  * at the end.)
137  * @param used If false, then this handle is not to be used.
138  * Instead of normal initialization, the key will be cleared.
139  */
140 template <class T>
141 StatusCode ThinningHandleKey<T>::initialize (const std::string& stream,
142  const char* qualifier,
143  bool used /*= true*/)
144 {
145  return initialize (stream, std::string(qualifier), used);
146 }
147 
148 
149 /**
150  * @brief Should be called during the initialize phase. It will fail
151  * if the requested StoreGate service cannot be found or if the key is blank.
152  * @param stream The name of the stream for which thinning is being applied.
153  * @param used If false, then this handle is not to be used.
154  * Instead of normal initialization, the key will be cleared.
155  */
156 template <class T>
157 StatusCode ThinningHandleKey<T>::initialize (const std::string& stream,
158  bool used /*= true*/)
159 {
160  // Use the owner name as the default qualifier.
161  // It's possible that the owner name contains periods, which we don't
162  // want here; these will be removed in the delegated @c initialize().
163  std::string oname;
164  if (this->owner()) {
165  oname = this->owner()->name();
166  }
167  return initialize (stream, oname, used);
168 }
169 
170 
171 /**
172  * @brief Return the write key for the thinning decision.
173  */
174 template <class T>
175 inline
176 const WriteHandleKey<ThinningDecision>&
177 ThinningHandleKey<T>::decisionHandleKey() const
178 {
179  return m_decisionKey;
180 }
181 
182 
183 } // namespace SG