Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CommonTools_UtilAlgos_ObjectSelectorProducer_h
0002 #define CommonTools_UtilAlgos_ObjectSelectorProducer_h
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/ConsumesCollector.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Utilities/interface/InputTag.h"
0008 #include "CommonTools/UtilAlgos/interface/StoreManagerTrait.h"
0009 #include "CommonTools/UtilAlgos/interface/SelectedOutputCollectionTrait.h"
0010 #include "CommonTools/UtilAlgos/interface/NullPostProcessor.h"
0011 #include "CommonTools/UtilAlgos/interface/EventSetupInitTrait.h"
0012 #include <utility>
0013 #include <vector>
0014 #include <memory>
0015 #include <algorithm>
0016 
0017 /**
0018  * This class template is like ObjectSelector, but it is an EDProducer
0019  * instead of EDFilter. Use case is that when the filter decisions are
0020  * ignored (cms.ignore in configuration or EDFilter returns always
0021  * true), EDProducers are better for the unscheduled mode than
0022  * EDFilters.
0023  */
0024 template <typename Selector,
0025           typename OutputCollection,
0026           typename PostProcessor,
0027           typename StoreManager,
0028           typename Base,
0029           typename Init>
0030 class ObjectSelectorProducer : public Base {
0031 public:
0032   /// constructor
0033   explicit ObjectSelectorProducer(const edm::ParameterSet& cfg)
0034       : Base(cfg),
0035         srcToken_(
0036             this->template consumes<typename Selector::collection>(cfg.template getParameter<edm::InputTag>("src"))),
0037         selectorInit_(this->consumesCollector()),
0038         selector_(cfg, this->consumesCollector()),
0039         postProcessor_(cfg, this->consumesCollector()) {
0040     postProcessor_.init(*this);
0041   }
0042   /// destructor
0043   ~ObjectSelectorProducer() override {}
0044 
0045 private:
0046   /// process one event
0047   void produce(edm::Event& evt, const edm::EventSetup& es) override {
0048     selectorInit_.init(selector_, evt, es);
0049     edm::Handle<typename Selector::collection> source;
0050     evt.getByToken(srcToken_, source);
0051     StoreManager manager(source);
0052     selector_.select(source, evt, es);
0053     manager.cloneAndStore(selector_.begin(), selector_.end(), evt);
0054     edm::OrphanHandle<OutputCollection> filtered = manager.put(evt);
0055     postProcessor_.process(filtered, evt);
0056   }
0057   /// source collection label
0058   edm::EDGetTokenT<typename Selector::collection> srcToken_;
0059   /// Object collection selector
0060   Init selectorInit_;
0061   Selector selector_;
0062   /// post processor
0063   PostProcessor postProcessor_;
0064 };
0065 
0066 #endif