|
19 | 19 | #include <cassert> |
20 | 20 | #include <stdexcept> |
21 | 21 | #include <gsl/gsl> // for guideline support library; array_view |
| 22 | +#include <type_traits> |
22 | 23 |
|
23 | 24 | namespace o2 |
24 | 25 | { |
@@ -115,6 +116,28 @@ class MCTruthContainer |
115 | 116 | mTruthArray.emplace_back(element); |
116 | 117 | } |
117 | 118 |
|
| 119 | + // convenience interface to add multiple labels at once |
| 120 | + // can use elements of any assignable type or sub-type |
| 121 | + template <typename CompatibleLabel> |
| 122 | + void addElements(uint dataindex, gsl::span<CompatibleLabel> elements) |
| 123 | + { |
| 124 | + static_assert(std::is_same<TruthElement, CompatibleLabel>::value || |
| 125 | + std::is_assignable<TruthElement, CompatibleLabel>::value || |
| 126 | + std::is_base_of<TruthElement, CompatibleLabel>::value, |
| 127 | + "Need to add compatible labels"); |
| 128 | + for (auto& e : elements) { |
| 129 | + addElement(dataindex, e); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + template <typename CompatibleLabel> |
| 134 | + void addElements(uint dataindex, const std::vector<CompatibleLabel>& v) |
| 135 | + { |
| 136 | + using B = typename std::remove_const<CompatibleLabel>::type; |
| 137 | + auto s = gsl::span<CompatibleLabel>(const_cast<B*>(&v[0]), v.size()); |
| 138 | + addElements(dataindex, s); |
| 139 | + } |
| 140 | + |
118 | 141 | // Add element at last position or for a previous index |
119 | 142 | // (at random access position). |
120 | 143 | // This might be a slow process since data has to be moved internally |
|
0 commit comments