1 #ifndef art_Persistency_Common_CollectionUtilities_h 2 #define art_Persistency_Common_CollectionUtilities_h 74 #include "cetlib/map_vector.h" 77 #include <type_traits> 83 class EDProductGetter;
86 template <
typename CONTAINER>
90 template <
typename COLLECTION>
95 template <
typename COLLECTION,
typename OFFSETS>
101 template <
typename T>
106 template <
typename T,
typename OFFSETS>
118 template <
typename T>
122 template <
typename iterator>
130 template <
typename T>
139 template <
typename iterator>
152 getter = (*beg).productGetter();
155 if ((*i) !=
nullptr &&
156 !((*i)->productGetter() && (*i)->productGetter() == getter &&
157 (*i)->id().isValid() && (*i)->id() == id)) {
166 template <
typename C>
175 template <
typename P>
184 template <
typename CONTAINER>
189 out.insert(in.begin(), in.end());
193 template <
typename T>
195 using mv_t = cet::map_vector<T>;
202 for (
auto& pr : in) {
203 pr.first = cet::map_vector_key{pr.first.asInt() +
d};
210 out.append(in.begin(), in.end());
215 template <
typename T,
typename InIter =
typename T::const_iterator>
217 decltype(std::declval<T>().insert(std::declval<InIter>(),
218 std::declval<InIter>()));
220 template <
typename T,
typename =
void>
223 template <
typename T>
228 template <
typename T,
232 decltype(std::declval<T>().insert(std::declval<OutIter>(),
233 std::declval<InIter>(),
234 std::declval<InIter>()));
236 template <
typename T,
typename OutIter,
typename =
void>
239 template <
typename T,
typename OutIter>
242 std::void_t<three_arg_insert_t<T, OutIter>>>
245 template <
typename T>
252 template <
typename CONTAINER>
259 static_assert(detail::has_three_arg_insert<CONTAINER>);
260 out.insert(out.end(), in.begin(), in.end());
265 template <
typename COLLECTION>
270 typename COLLECTION::size_type total_size = 0;
271 for (
auto collptr : in) {
272 if (collptr !=
nullptr) {
273 total_size += collptr->size();
276 out.reserve(total_size);
277 for (
auto collptr : in) {
278 if (collptr !=
nullptr) {
285 template <
typename COLLECTION,
typename OFFSETS>
292 offsets.reserve(in.size());
293 typename COLLECTION::size_type current_offset{};
294 for (
auto collptr : in) {
295 if (collptr ==
nullptr)
299 offsets.push_back(current_offset);
300 current_offset += delta;
302 flattenCollections<COLLECTION>(
in, out);
306 template <
typename T>
315 <<
"Attempt to flatten incompatible PtrVectors " 316 <<
"referring to different ProductIDs.\n";
318 flattenCollections<PtrVector<T>>(
in, out);
322 template <
typename T,
typename OFFSETS>
332 <<
"Attempt to flatten incompatible PtrVectors " 333 <<
"referring to different ProductIDs.\n";
335 flattenCollections<PtrVector<T>>(
in, out, offsets);
static size_t offset(cet::map_vector< P > const &mv)
void concatContainers(CONTAINER &out, CONTAINER const &in)
decltype(std::declval< T >().insert(std::declval< OutIter >(), std::declval< InIter >(), std::declval< InIter >())) three_arg_insert_t
static size_t offset(C const &c)
decltype(std::declval< T >().insert(std::declval< InIter >(), std::declval< InIter >())) two_arg_insert_t
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void flattenCollections(std::vector< COLLECTION const * > const &in, COLLECTION &out)
bool verifyPtrCollection(std::vector< art::PtrVector< T > const * > const &in)
static void concatenate(mv_t &out, mv_t in)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
static void concatenate(CONTAINER &out, CONTAINER const &in)
cet::map_vector< T > mv_t
constexpr bool has_three_arg_insert