2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
6 * @file AthContainers/tools/copyThinned.icc
7 * @author scott snyder <snyder@bnl.gov>
9 * @brief Helper to copy an object while applying thinning.
17 * @brief Helper to copy an object while applying thinning.
18 * @param orig The object to copy.
19 * @param dummy Dummy argument for overload resolution.
20 * @param info Thinning information for this object (or nullptr).
22 * This is the generic version of @c copyThinned, which matches types
23 * for which there is not a more specific overload. It simply makes
24 * a copy of @c orig using the copy constructor.
26 template <class CONTAINER>
27 std::unique_ptr<CONTAINER>
28 copyThinned1 (const CONTAINER& orig,
29 const void* /*dummy*/,
30 const SG::ThinningInfo* /*info*/)
32 return std::make_unique<CONTAINER> (orig);
37 * @brief Helper to copy an object while applying thinning.
38 * @param orig The object to copy.
39 * @param dummy Dummy argument for overload resolution.
40 * @param info Thinning information for this object (or nullptr).
42 * This overload handles @c DataVector types. It returns a view container
43 * copy of @c orig, from which any thinned elements are removed.
45 template <class CONTAINER>
46 std::unique_ptr<CONTAINER>
47 copyThinned1 (CONTAINER& orig,
48 DataVector<typename CONTAINER::base_value_type>* /*dummy*/,
49 const SG::ThinningInfo* info)
51 const ThinningDecisionBase* dec = info ? info->m_decision : nullptr;
52 size_t size = orig.size();
53 if (size > 0 && dec) {
54 auto newcont = std::make_unique<CONTAINER>();
55 // Avoid some ambiguities with clear().
56 auto* dv = static_cast<DataVector<typename CONTAINER::base_value_type>*> (newcont.get());
57 dv->clear (SG::VIEW_ELEMENTS);
58 newcont->reserve (size);
60 for (size_t i = 0; i < size; i++) {
61 if (!(dec && dec->thinned (i))) {
62 newcont->push_back (orig[i]);
69 return std::make_unique<CONTAINER> (orig);
74 * @brief Helper to copy an object while applying thinning.
75 * @param orig The object to copy.
76 * @param dummy Dummy argument for overload resolution.
77 * @param info Thinning information for this object (or nullptr).
79 * This overload handles @c DataVector types. It returns a view container
80 * copy of @c orig, from which any thinned elements are removed.
82 template <class CONTAINER>
83 std::unique_ptr<const CONTAINER>
84 copyThinned1 (const CONTAINER& orig,
85 const DataVector<typename CONTAINER::base_value_type>* /*dummy*/,
86 const SG::ThinningInfo* info)
88 const ThinningDecisionBase* dec = info ? info->m_decision : nullptr;
89 size_t size = orig.size();
90 if (size > 0 && dec) {
91 auto newcont = std::make_unique<ConstDataVector<CONTAINER> >();
92 newcont->clear (SG::VIEW_ELEMENTS);
93 newcont->reserve (size);
95 for (size_t i = 0; i < size; i++) {
96 if (!(dec && dec->thinned (i)))
98 newcont->push_back (orig[i]);
102 return std::unique_ptr<const CONTAINER>(newcont.release()->asDataVector());
105 return std::make_unique<CONTAINER> (orig);
110 * @brief Helper to copy an object while applying thinning.
111 * @param orig The object to copy.
112 * @param dummy Dummy argument for overload resolution.
113 * @param info Thinning information for this object (or nullptr).
115 * This overload handles @c IAuxStore types. It returns a new copy
116 * of the store, with any thinned elements removed.
118 template <class CONTAINER>
119 std::unique_ptr<CONTAINER>
120 copyThinned1 (const CONTAINER& orig,
121 const SG::IAuxStore* /*dummy*/,
122 const SG::ThinningInfo* info)
124 // T->P conversion is done from within copyAuxStoreThinned,
125 // so we need to call it regardless of whether or not
126 // thinning is actually done. Variable selection happens there
127 // as well, so need to call it even if the container is empty.
128 // (Actually, in that case, all dynamic variables will be removed,
130 auto newcont = std::make_unique<CONTAINER>();
131 copyAuxStoreThinned (orig, *newcont, info);
137 * @brief Helper to copy an object while applying thinning.
138 * @param orig The object to copy.
139 * @param info Thinning information for this object (or nullptr).
141 * Returns a new copy of @c orig with elements removed according to the
142 * thinning defined in @c svc. Ownership of the new object is passed
143 * back to the caller.
145 * The code here handles @c IAuxStore objects.
146 * (For a @c DataVector object, use @c copyThinnedConst.)
147 * Support for additional object types may be added by adding
148 * overloads for @c copyThinned1.
150 template <class CONTAINER>
151 std::unique_ptr<CONTAINER>
152 copyThinned (CONTAINER& orig,
153 const SG::ThinningInfo* info)
155 return copyThinned1 (orig, &orig, info);
160 * @brief Helper to copy an object while applying thinning, const version.
161 * @param orig The object to copy.
162 * @param info Thinning information for this object (or nullptr).
164 * Returns a new copy of @c orig with elements removed according to the
165 * thinning defined in @c svc. Ownership of the new object is passed
166 * back to the caller.
168 * The code here handles @c DataVector and @c IAuxStore objects.
169 * Support for additional object types may be added by adding
170 * overloads for @c copyThinned1.
172 template <class CONTAINER>
173 std::unique_ptr<const CONTAINER>
174 copyThinnedConst (const CONTAINER& orig,
175 const SG::ThinningInfo* info)
177 return copyThinned1 (orig, &orig, info);