Back to home page

Project CMSSW displayed by LXR

 
 

    


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 //FIXME remove New when ready
0009 namespace edmNew {
0010 
0011   // adapt the RecHit accessors to DSTV
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   // invoke f for each object in the range of DataSets selected by sel
0018   // to ease use, f is passed by reference
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   }  // namespace dstvdetails
0037 
0038   // to write an easy iterator on objects in a range of DataSets selected by sel
0039   // is left as exercise to the reader
0040   // here we provide this not optimal solution...
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 }  // namespace edmNew
0051 
0052 #endif  //  DataFormats_Common_DetSetAlgorithm_h