CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CommonTools/UtilAlgos/interface/SingleElementCollectionRefSelector.h

Go to the documentation of this file.
00001 #ifndef RecoAlgos_SingleElementCollectionRefSelector_h
00002 #define RecoAlgos_SingleElementCollectionRefSelector_h
00003 
00015 #include "CommonTools/UtilAlgos/interface/SelectionAdderTrait.h"
00016 #include "CommonTools/UtilAlgos/interface/StoreContainerTrait.h"
00017 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
00018 #include "DataFormats/Common/interface/View.h"
00019 namespace reco {
00020   namespace modules {
00021     template<typename S> struct SingleElementCollectionRefSelectorEventSetupInit;
00022   }
00023 }
00024 template<typename InputType, typename Selector, 
00025          typename OutputCollection = typename ::helper::SelectedOutputCollectionTrait<edm::View<InputType> >::type, 
00026          typename StoreContainer = typename ::helper::StoreContainerTrait<OutputCollection>::type,
00027          typename RefAdder = typename ::helper::SelectionAdderTrait<edm::View<InputType>, StoreContainer>::type>
00028 struct SingleElementCollectionRefSelector {
00029   typedef edm::View<InputType> InputCollection;
00030   typedef InputCollection collection;
00031   typedef StoreContainer container;
00032   typedef Selector selector;
00033   typedef typename container::const_iterator const_iterator;
00034   SingleElementCollectionRefSelector(const edm::ParameterSet & cfg) : 
00035     select_(reco::modules::make<Selector>(cfg)) { }
00036   const_iterator begin() const { return selected_.begin(); }
00037   const_iterator end() const { return selected_.end(); }
00038   void select(const edm::Handle<InputCollection> & c, const edm::Event &, const edm::EventSetup&) {
00039     selected_.clear();    
00040     for(size_t idx = 0; idx < c->size(); ++ idx) {
00041       if(select_(c->refAt(idx))) addRef_(selected_, c, idx);
00042     }
00043   }
00044 private:
00045   container selected_;
00046   selector select_;
00047   RefAdder addRef_;
00048   friend class reco::modules::SingleElementCollectionRefSelectorEventSetupInit<SingleElementCollectionRefSelector>;
00049 };
00050 
00051 #include "CommonTools/UtilAlgos/interface/EventSetupInitTrait.h"
00052 
00053 namespace reco {
00054   namespace modules {
00055     template<typename S>
00056     struct SingleElementCollectionRefSelectorEventSetupInit {
00057       static void init(S & s, const edm::Event & ev, const edm::EventSetup& es) { 
00058         typedef typename EventSetupInit<typename S::selector>::type ESI;
00059         ESI::init(s.select_, ev, es);
00060       }
00061     };
00062 
00063     template<typename I, typename S, typename O, typename C, typename R>
00064     struct EventSetupInit<SingleElementCollectionRefSelector<I, S, O, C, R> > {
00065       typedef SingleElementCollectionRefSelectorEventSetupInit<SingleElementCollectionRefSelector<I, S, O, C, R> > type;
00066     };
00067   }
00068 }
00069 
00070 #endif