|
22 | 22 |
|
23 | 23 | namespace o2::framework |
24 | 24 | { |
25 | | - |
26 | 25 | template <typename G, typename... A> |
27 | 26 | struct GroupSlicer { |
28 | 27 | using grouping_t = std::decay_t<G>; |
@@ -151,83 +150,108 @@ struct GroupSlicer { |
151 | 150 | return std::make_tuple(prepareArgument<A>()...); |
152 | 151 | } |
153 | 152 |
|
154 | | - template <typename A1> |
| 153 | + template <soa::is_smallgroups A1> |
| 154 | + requires (o2::soa::relatedByIndex<std::decay_t<G>, std::decay_t<A1>>() && soa::is_filtered_table<std::decay_t<A1>>) |
155 | 155 | auto prepareArgument() |
156 | 156 | { |
157 | 157 | constexpr auto index = framework::has_type_at_v<A1>(associated_pack_t{}); |
158 | 158 | auto& originalTable = std::get<A1>(*mAt); |
159 | | - |
160 | | - if constexpr (o2::soa::relatedByIndex<std::decay_t<G>, std::decay_t<A1>>()) { |
161 | | - uint64_t pos; |
162 | | - if constexpr (soa::is_filtered_table<std::decay_t<G>>) { |
163 | | - pos = groupSelection[position]; |
164 | | - } else { |
165 | | - pos = position; |
| 159 | + uint64_t pos; |
| 160 | + if constexpr (soa::is_filtered_table<std::decay_t<G>>) { |
| 161 | + pos = groupSelection[position]; |
| 162 | + } else { |
| 163 | + pos = position; |
| 164 | + } |
| 165 | + // generic split |
| 166 | + auto selection = sliceInfosUnsorted[index].getSliceFor(pos); |
| 167 | + // intersect selections |
| 168 | + o2::soa::SelectionVector s; |
| 169 | + if (selections[index]->empty()) { |
| 170 | + if (!selection.empty()) { |
| 171 | + std::copy(selection.begin(), selection.end(), std::back_inserter(s)); |
166 | 172 | } |
167 | | - |
168 | | - if constexpr (!o2::soa::is_smallgroups<std::decay_t<A1>>) { |
169 | | - // optimized split |
170 | | - if (originalTable.size() == 0) { |
171 | | - return originalTable; |
| 173 | + } else { |
| 174 | + if (!selection.empty()) { |
| 175 | + if constexpr (std::decay_t<A1>::applyFilters) { |
| 176 | + std::set_intersection(selection.begin(), selection.end(), selections[index]->begin(), selections[index]->end(), std::back_inserter(s)); |
| 177 | + } else { |
| 178 | + std::copy(selection.begin(), selection.end(), std::back_inserter(s)); |
172 | 179 | } |
173 | | - auto oc = sliceInfos[index].getSliceFor(pos); |
174 | | - uint64_t offset = oc.first; |
175 | | - auto count = oc.second; |
176 | | - if constexpr (soa::is_filtered_table<std::decay_t<A1>>) { |
177 | | - auto groupedElementsTable = originalTable.asArrowTable()->Slice(offset, count); |
178 | | - if (count == 0) { |
179 | | - return std::decay_t<A1>{{groupedElementsTable}, soa::SelectionVector{}}; |
180 | | - } |
| 180 | + } |
| 181 | + } |
| 182 | + std::decay_t<A1> typedTable{{originalTable.asArrowTable()}, std::move(s)}; |
| 183 | + typedTable.bindInternalIndicesTo(&originalTable); |
| 184 | + return typedTable; |
| 185 | + } |
| 186 | + |
| 187 | + template <soa::is_filtered_table A1> |
| 188 | + requires (o2::soa::relatedByIndex<std::decay_t<G>, std::decay_t<A1>>() && !soa::is_smallgroups<A1>) |
| 189 | + auto prepareArgument() |
| 190 | + { |
| 191 | + constexpr auto index = framework::has_type_at_v<A1>(associated_pack_t{}); |
| 192 | + auto& originalTable = std::get<A1>(*mAt); |
| 193 | + uint64_t pos; |
| 194 | + if constexpr (soa::is_filtered_table<std::decay_t<G>>) { |
| 195 | + pos = groupSelection[position]; |
| 196 | + } else { |
| 197 | + pos = position; |
| 198 | + } |
| 199 | + // optimized split |
| 200 | + if (originalTable.size() == 0) { |
| 201 | + return originalTable; |
| 202 | + } |
| 203 | + auto oc = sliceInfos[index].getSliceFor(pos); |
| 204 | + uint64_t offset = oc.first; |
| 205 | + auto count = oc.second; |
| 206 | + auto groupedElementsTable = originalTable.asArrowTable()->Slice(offset, count); |
| 207 | + if (count == 0) { |
| 208 | + return std::decay_t<A1>{{groupedElementsTable}, soa::SelectionVector{}}; |
| 209 | + } |
181 | 210 |
|
182 | | - // for each grouping element we need to slice the selection vector |
183 | | - auto start_iterator = std::lower_bound(starts[index], selections[index]->end(), offset); |
184 | | - auto stop_iterator = std::lower_bound(start_iterator, selections[index]->end(), offset + count); |
185 | | - starts[index] = stop_iterator; |
186 | | - soa::SelectionVector slicedSelection{start_iterator, stop_iterator}; |
187 | | - std::transform(slicedSelection.begin(), slicedSelection.end(), slicedSelection.begin(), |
188 | | - [&offset](int64_t idx) { |
189 | | - return idx - static_cast<int64_t>(offset); |
190 | | - }); |
| 211 | + // for each grouping element we need to slice the selection vector |
| 212 | + auto start_iterator = std::lower_bound(starts[index], selections[index]->end(), offset); |
| 213 | + auto stop_iterator = std::lower_bound(start_iterator, selections[index]->end(), offset + count); |
| 214 | + starts[index] = stop_iterator; |
| 215 | + soa::SelectionVector slicedSelection{start_iterator, stop_iterator}; |
| 216 | + std::transform(slicedSelection.begin(), slicedSelection.end(), slicedSelection.begin(), |
| 217 | + [&offset](int64_t idx) { |
| 218 | + return idx - static_cast<int64_t>(offset); |
| 219 | + }); |
191 | 220 |
|
192 | | - std::decay_t<A1> typedTable{{groupedElementsTable}, std::move(slicedSelection), offset}; |
193 | | - typedTable.bindInternalIndicesTo(&originalTable); |
194 | | - return typedTable; |
| 221 | + std::decay_t<A1> typedTable{{groupedElementsTable}, std::move(slicedSelection), offset}; |
| 222 | + typedTable.bindInternalIndicesTo(&originalTable); |
| 223 | + return typedTable; |
| 224 | + } |
195 | 225 |
|
196 | | - } else { |
197 | | - auto groupedElementsTable = originalTable.rawSlice(offset, offset + count - 1); |
198 | | - groupedElementsTable.bindInternalIndicesTo(&originalTable); |
199 | | - return groupedElementsTable; |
200 | | - } |
201 | | - } else { |
202 | | - // generic split |
203 | | - if constexpr (soa::is_filtered_table<std::decay_t<A1>>) { |
204 | | - auto selection = sliceInfosUnsorted[index].getSliceFor(pos); |
205 | | - // intersect selections |
206 | | - o2::soa::SelectionVector s; |
207 | | - if (selections[index]->empty()) { |
208 | | - if (!selection.empty()) { |
209 | | - std::copy(selection.begin(), selection.end(), std::back_inserter(s)); |
210 | | - } |
211 | | - } else { |
212 | | - if (!selection.empty()) { |
213 | | - if constexpr (std::decay_t<A1>::applyFilters) { |
214 | | - std::set_intersection(selection.begin(), selection.end(), selections[index]->begin(), selections[index]->end(), std::back_inserter(s)); |
215 | | - } else { |
216 | | - std::copy(selection.begin(), selection.end(), std::back_inserter(s)); |
217 | | - } |
218 | | - } |
219 | | - } |
220 | | - std::decay_t<A1> typedTable{{originalTable.asArrowTable()}, std::move(s)}; |
221 | | - typedTable.bindInternalIndicesTo(&originalTable); |
222 | | - return typedTable; |
223 | | - } else { |
224 | | - throw runtime_error("Unsorted grouped table needs to be used with soa::SmallGroups<>"); |
225 | | - } |
226 | | - } |
| 226 | + template <soa::is_table A1> |
| 227 | + requires (o2::soa::relatedByIndex<std::decay_t<G>, std::decay_t<A1>>() && !soa::is_smallgroups<A1> && !soa::is_filtered_table<A1>) |
| 228 | + auto prepareArgument() |
| 229 | + { |
| 230 | + constexpr auto index = framework::has_type_at_v<A1>(associated_pack_t{}); |
| 231 | + auto& originalTable = std::get<A1>(*mAt); |
| 232 | + uint64_t pos; |
| 233 | + if constexpr (soa::is_filtered_table<std::decay_t<G>>) { |
| 234 | + pos = groupSelection[position]; |
227 | 235 | } else { |
228 | | - static_assert(!o2::soa::is_smallgroups<std::decay_t<A1>>, "SmallGroups used with a table that is not related by index to the gouping table"); |
| 236 | + pos = position; |
| 237 | + } |
| 238 | + // optimized split |
| 239 | + if (originalTable.size() == 0) { |
229 | 240 | return originalTable; |
230 | 241 | } |
| 242 | + auto oc = sliceInfos[index].getSliceFor(pos); |
| 243 | + uint64_t offset = oc.first; |
| 244 | + auto count = oc.second; |
| 245 | + auto groupedElementsTable = originalTable.rawSlice(offset, offset + count - 1); |
| 246 | + groupedElementsTable.bindInternalIndicesTo(&originalTable); |
| 247 | + return groupedElementsTable; |
| 248 | + } |
| 249 | + |
| 250 | + template <soa::is_table A1> |
| 251 | + requires (!o2::soa::relatedByIndex<std::decay_t<G>, std::decay_t<A1>>() && !soa::is_smallgroups<A1>) |
| 252 | + auto prepareArgument() |
| 253 | + { |
| 254 | + return std::get<A1>(*mAt); |
231 | 255 | } |
232 | 256 |
|
233 | 257 | std::string mIndexColumnName; |
|
0 commit comments