00001 #ifndef DataFormats_Common_DetSetAlgorithm_h
00002 #define DataFormats_Common_DetSetAlgorithm_h
00003
00004 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00005 #include <boost/ref.hpp>
00006 #include <boost/bind.hpp>
00007 #include <boost/function.hpp>
00008 #include <algorithm>
00009
00010
00011 namespace edmNew {
00012
00013
00014 template <typename DSTV, typename A, typename B>
00015 typename DSTV::Range detsetRangeFromPair(DSTV const & v, std::pair<A,B> const & p) {
00016 return v.equal_range(p.first,p.second);
00017 }
00018
00019
00020
00021
00022 template <typename DSTV, typename A, typename B, typename F>
00023 void foreachDetSetObject(DSTV const & v, std::pair<A,B> const & sel, F & f) {
00024 typedef typename DSTV::data_type data_type;
00025 typename DSTV::Range range = detsetRangeFromPair(v,sel);
00026 for(typename DSTV::const_iterator id=range.first; id!=range.second; id++)
00027 std::for_each((*id).begin(), (*id).end(),
00028 boost::function<void(const data_type &)>(boost::ref(f)));
00029 }
00030
00031 namespace dstvdetails {
00032
00033 struct Pointer {
00034 template<typename H>
00035 H const * operator()(H const& h) const { return &h;}
00036 };
00037
00038 }
00039
00040
00041
00042
00043 template <typename DSTV, typename A, typename B, typename T>
00044 void copyDetSetRange(DSTV const & dstv,
00045 std::vector<T const *> & v,
00046 std::pair<A,B> const & sel) {
00047 typename DSTV::Range range = dstv.equal_range(sel.first,sel.second);
00048 for(typename DSTV::const_iterator id=range.first; id!=range.second; id++){
00049 size_t cs = v.size();
00050 v.resize(cs+(*id).size());
00051 std::transform((*id).begin(), (*id).end(),v.begin()+cs,dstvdetails::Pointer());
00052 }
00053 }
00054 }
00055
00056
00057 #endif // DataFormats_Common_DetSetAlgorithm_h