Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:16

0001 #ifndef RecoAlgos_SingleElementCollectionSelectorPlusEvent_h
0002 #define RecoAlgos_SingleElementCollectionSelectorPlusEvent_h
0003 /** \class SingleElementCollectionSelectorPlusEvent
0004  *
0005  * selects a subset of a track collection based
0006  * on single element selection done via functor
0007  *
0008  * \author Luca Lista, INFN
0009  *
0010  * \version $Revision: 1.1 $
0011  *
0012  * $Id: SingleElementCollectionSelectorPlusEvent.h,v 1.1 2009/03/03 13:07:28 llista Exp $
0013  *
0014  */
0015 #include "FWCore/Framework/interface/ConsumesCollector.h"
0016 #include "CommonTools/UtilAlgos/interface/SelectionAdderTrait.h"
0017 #include "CommonTools/UtilAlgos/interface/StoreContainerTrait.h"
0018 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
0019 #include "CommonTools/UtilAlgos/interface/SelectedOutputCollectionTrait.h"
0020 
0021 namespace edm {
0022   class Event;
0023   class EventSetup;
0024 }  // namespace edm
0025 
0026 template <typename InputCollection,
0027           typename Selector,
0028           typename OutputCollection = typename helper::SelectedOutputCollectionTrait<InputCollection>::type,
0029           typename StoreContainer = typename helper::StoreContainerTrait<OutputCollection>::type,
0030           typename RefAdder = typename helper::SelectionAdderTrait<InputCollection, StoreContainer>::type>
0031 struct SingleElementCollectionSelectorPlusEvent {
0032   typedef InputCollection collection;
0033   typedef StoreContainer container;
0034   typedef typename container::const_iterator const_iterator;
0035   SingleElementCollectionSelectorPlusEvent(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
0036       : select_(reco::modules::make<Selector>(cfg, iC)) {}
0037   const_iterator begin() const { return selected_.begin(); }
0038   const_iterator end() const { return selected_.end(); }
0039   void select(const edm::Handle<InputCollection> &c, const edm::Event &ev, const edm::EventSetup &) {
0040     selected_.clear();
0041     for (size_t idx = 0; idx < c->size(); ++idx) {
0042       if (select_(edm::Ref<InputCollection>(c, idx), ev))  //(*c)[idx]
0043         addRef_(selected_, c, idx);
0044     }
0045   }
0046 
0047 private:
0048   StoreContainer selected_;
0049   Selector select_;
0050   RefAdder addRef_;
0051 };
0052 
0053 #endif