Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-25 02:13:22

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/Framework/interface/Run.h"
0005 #include "FWCore/Framework/interface/stream/EDFilter.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0009 
0010 //
0011 // class declaration
0012 //
0013 
0014 class LSNumberFilter : public edm::stream::EDFilter<> {
0015 public:
0016   explicit LSNumberFilter(const edm::ParameterSet&);
0017   ~LSNumberFilter() override = default;
0018 
0019   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020 
0021 private:
0022   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0023   bool filter(edm::Event&, const edm::EventSetup&) override;
0024   bool is_HLT_vetoed_;
0025   const unsigned int minLS_;
0026   const std::vector<std::string> veto_HLT_Menu_;
0027   HLTConfigProvider hltConfig_;
0028 };
0029 
0030 void LSNumberFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0031   edm::ParameterSetDescription desc;
0032   desc.setComment("Filters the first minLS lumisections and reject the run according to the HLT menu name");
0033   desc.addUntracked<unsigned int>("minLS", 21)->setComment("first LS to accept");
0034   desc.addUntracked<std::vector<std::string>>("veto_HLT_Menu", {})->setComment("list of HLT menus to reject");
0035   descriptions.addWithDefaultLabel(desc);
0036 }
0037 
0038 LSNumberFilter::LSNumberFilter(const edm::ParameterSet& iConfig)
0039     : minLS_(iConfig.getUntrackedParameter<unsigned>("minLS", 21)),
0040       veto_HLT_Menu_(iConfig.getUntrackedParameter<std::vector<std::string>>("veto_HLT_Menu")) {}
0041 
0042 //
0043 // member functions
0044 //
0045 
0046 // ------------ method called on each new Event  ------------
0047 bool LSNumberFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0048   if ((iEvent.luminosityBlock() < minLS_) || is_HLT_vetoed_) {
0049     return false;
0050   }
0051 
0052   return true;
0053 }
0054 
0055 void LSNumberFilter::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0056   bool changed{false};
0057   hltConfig_.init(iRun, iSetup, "HLT", changed);
0058   is_HLT_vetoed_ = false;
0059   for (const auto& veto : veto_HLT_Menu_) {
0060     std::size_t found = hltConfig_.tableName().find(veto);
0061     if (found != std::string::npos) {
0062       is_HLT_vetoed_ = true;
0063       edm::LogWarning("LSNumberFilter") << "Detected " << veto
0064                                         << " in HLT Config tableName(): " << hltConfig_.tableName()
0065                                         << "; Events of this run will be ignored" << std::endl;
0066       break;
0067     }
0068   }
0069 }
0070 //define this as a plug-in
0071 DEFINE_FWK_MODULE(LSNumberFilter);