Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:39

0001 #ifndef HLTrigger_HLTCountNumberOfObject_H
0002 /**\class HLTCountNumberOfObject
0003  * Description:
0004  * templated EDFilter to count the number of object in a given collection, using View
0005  * \author Jean-Roch Vlimant
0006 */
0007 
0008 // system include files
0009 #include <memory>
0010 
0011 // user include files
0012 #include "FWCore/Framework/interface/Frameworkfwd.h"
0013 
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 
0019 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
0020 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0021 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0022 
0023 template <class OColl>
0024 class HLTCountNumberOfObject : public HLTFilter {
0025 public:
0026   explicit HLTCountNumberOfObject(const edm::ParameterSet& iConfig)
0027       : HLTFilter(iConfig),
0028         src_(iConfig.getParameter<edm::InputTag>("src")),
0029         minN_(iConfig.getParameter<int>("MinN")),
0030         maxN_(iConfig.getParameter<int>("MaxN")) {
0031     srcToken_ = consumes<OColl>(src_);
0032   }
0033 
0034   ~HLTCountNumberOfObject() override {}
0035 
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0037     edm::ParameterSetDescription desc;
0038     makeHLTFilterDescription(desc);
0039     desc.add<edm::InputTag>("src", edm::InputTag(""));
0040     desc.add<int>("MinN", 0);
0041     desc.add<int>("MaxN", 99999);
0042     descriptions.add(defaultModuleLabel<HLTCountNumberOfObject<OColl>>(), desc);
0043   }
0044 
0045 private:
0046   bool hltFilter(edm::Event& iEvent,
0047                  const edm::EventSetup&,
0048                  trigger::TriggerFilterObjectWithRefs& filterproduct) const override {
0049     edm::Handle<OColl> oHandle;
0050     iEvent.getByToken(srcToken_, oHandle);
0051     int s = oHandle->size();
0052     bool answer = true;
0053     if (minN_ != -1)
0054       answer = answer && (s >= minN_);
0055     if (maxN_ != -1)
0056       answer = answer && (s <= maxN_);
0057     LogDebug("HLTCountNumberOfObject") << module(iEvent) << " sees: " << s
0058                                        << " objects. Filtere answer is: " << (answer ? "true" : "false");
0059 
0060     return answer;
0061   }
0062 
0063   edm::InputTag src_;
0064   edm::EDGetTokenT<OColl> srcToken_;
0065   int minN_, maxN_;
0066 };
0067 
0068 #endif