File indexing completed on 2024-04-06 12:03:50
0001 #ifndef DataFormats_Common_DetSetAlgorithm_h
0002 #define DataFormats_Common_DetSetAlgorithm_h
0003
0004 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0005 #include <algorithm>
0006 #include <functional>
0007
0008
0009 namespace edmNew {
0010
0011
0012 template <typename DSTV, typename A, typename B>
0013 typename DSTV::Range detsetRangeFromPair(DSTV const &v, std::pair<A, B> const &p) {
0014 return v.equal_range(p.first, p.second);
0015 }
0016
0017
0018
0019 template <typename DSTV, typename A, typename B, typename F>
0020 void foreachDetSetObject(DSTV const &v, std::pair<A, B> const &sel, F &f) {
0021 typedef typename DSTV::data_type data_type;
0022 typename DSTV::Range range = detsetRangeFromPair(v, sel);
0023 for (typename DSTV::const_iterator id = range.first; id != range.second; id++)
0024 std::for_each((*id).begin(), (*id).end(), std::function<void(const data_type &)>(std::ref(f)));
0025 }
0026
0027 namespace dstvdetails {
0028
0029 struct Pointer {
0030 template <typename H>
0031 H const *operator()(H const &h) const {
0032 return &h;
0033 }
0034 };
0035
0036 }
0037
0038
0039
0040
0041 template <typename DSTV, typename A, typename B, typename T>
0042 void copyDetSetRange(DSTV const &dstv, std::vector<T const *> &v, std::pair<A, B> const &sel) {
0043 typename DSTV::Range range = dstv.equal_range(sel.first, sel.second);
0044 for (typename DSTV::const_iterator id = range.first; id != range.second; id++) {
0045 size_t cs = v.size();
0046 v.resize(cs + (*id).size());
0047 std::transform((*id).begin(), (*id).end(), v.begin() + cs, dstvdetails::Pointer());
0048 }
0049 }
0050 }
0051
0052 #endif