ATLAS Offline Software
Loading...
Searching...
No Matches
ThinningHandleKey.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
15namespace 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 */
27template <class T>
28ThinningHandleKey<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 */
49template <class T>
50template <std::derived_from<IProperty> OWNER>
51ThinningHandleKey<T>::ThinningHandleKey( OWNER* owner,
52 const std::string& name,
53 const std::string& key,
54 const std::string& doc)
55 : Base (owner, name, key, doc)
56{
57 this->setOwner (owner);
58}
59
60
61/**
62 * @brief Assignment.
63 * @param other Key to assign.
64 */
65template <class T>
66ThinningHandleKey<T>& ThinningHandleKey<T>::operator= (const ThinningHandleKey& other)
67{
68 // Don't copy m_decisionKey.
69 Base::operator= (other);
70 return *this;
71}
72
73
74/**
75 * @brief Change the key of the object to which we're referring.
76 * @param sgkey The StoreGate key for the object.
77 *
78 * The provided key may actually start with the name of the store,
79 * separated by a "+": "MyStore+Obj". If no "+" is present,
80 * the store is not changed.
81 */
82template <class T>
83ThinningHandleKey<T>& ThinningHandleKey<T>::operator= (const std::string& sgkey)
84{
85 // Don't copy m_decisionKey.
86 Base::operator= (sgkey);
87 return *this;
88}
89
90
91/**
92 * @brief Should be called during the initialize phase. It will fail
93 * if the requested StoreGate service cannot be found or if the key is blank.
94 * @param stream The name of the stream for which thinning is being applied.
95 * @param qualifier Qualifier to add on to the key for the decision object.
96 * If there are multiple algorithms thinning the same object,
97 * this can be used to keep them from interfering with
98 * each other. (The thinning decisions will be merged with AND
99 * at the end.)
100 * @param used If false, then this handle is not to be used.
101 * Instead of normal initialization, the key will be cleared.
102 */
103template <class T>
104StatusCode ThinningHandleKey<T>::initialize (const std::string& stream,
105 const std::string& qualifier,
106 bool used /*= true*/)
107{
108 if (used) {
109 std::string dkey = this->fullKey().key() + "_THINNED_" + stream;
110 if (!qualifier.empty()) {
111 // Make sure that the qualifier doesn't contain any periods.
112 std::string qual = qualifier;
113 std::replace (qual.begin(), qual.end(), '.', '_');
114 dkey += "." + qual;
115 }
116 m_decisionKey = dkey;
117 if (this->owner()) {
118 this->owner()->addDependency (m_decisionKey.fullKey(), Gaudi::DataHandle::Writer);
119 }
120 if (m_decisionKey.initialize (used).isFailure())
121 return StatusCode::FAILURE;
122 }
123 return Base::initialize (used);
124}
125
126
127/**
128 * @brief Should be called during the initialize phase. It will fail
129 * if the requested StoreGate service cannot be found or if the key is blank.
130 * @param stream The name of the stream for which thinning is being applied.
131 * @param qualifier Qualifier to add on to the key for the decision object.
132 * If there are multiple algorithms thinning the same object,
133 * this can be used to keep them from interfering with
134 * each other. (The thinning decisions will be merged with AND
135 * at the end.)
136 * @param used If false, then this handle is not to be used.
137 * Instead of normal initialization, the key will be cleared.
138 */
139template <class T>
140StatusCode ThinningHandleKey<T>::initialize (const std::string& stream,
141 const char* qualifier,
142 bool used /*= true*/)
143{
144 return initialize (stream, std::string(qualifier), used);
145}
146
147
148/**
149 * @brief Should be called during the initialize phase. It will fail
150 * if the requested StoreGate service cannot be found or if the key is blank.
151 * @param stream The name of the stream for which thinning is being applied.
152 * @param used If false, then this handle is not to be used.
153 * Instead of normal initialization, the key will be cleared.
154 */
155template <class T>
156StatusCode ThinningHandleKey<T>::initialize (const std::string& stream,
157 bool used /*= true*/)
158{
159 // Use the owner name as the default qualifier.
160 // It's possible that the owner name contains periods, which we don't
161 // want here; these will be removed in the delegated @c initialize().
162 std::string oname;
163 if (this->owner()) {
164 oname = this->owner()->name();
165 }
166 return initialize (stream, oname, used);
167}
168
169
170/**
171 * @brief Return the write key for the thinning decision.
172 */
173template <class T>
174inline
175const WriteHandleKey<ThinningDecision>&
176ThinningHandleKey<T>::decisionHandleKey() const
177{
178 return m_decisionKey;
179}
180
181
182} // namespace SG