File indexing completed on 2024-04-06 12:26:45
0001
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/global/EDFilter.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Utilities/interface/Parse.h"
0007
0008 #include "FWCore/ParameterSet/interface/FileInPath.h"
0009
0010 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0011
0012 #include <fstream>
0013
0014 class MultiEventFilter : public edm::global::EDFilter<> {
0015 class Event {
0016 public:
0017 Event(edm::RunNumber_t r, edm::LuminosityBlockNumber_t l, edm::EventNumber_t e) : run(r), lumi(l), event(e) {}
0018 edm::RunNumber_t run;
0019 edm::LuminosityBlockNumber_t lumi;
0020 edm::EventNumber_t event;
0021 };
0022
0023 public:
0024 explicit MultiEventFilter(const edm::ParameterSet& iConfig);
0025
0026 private:
0027 bool filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0028
0029 std::vector<Event> events_;
0030 const std::vector<std::string> eventList_;
0031
0032 const bool taggingMode_;
0033 };
0034
0035 MultiEventFilter::MultiEventFilter(const edm::ParameterSet& iConfig)
0036 : eventList_(iConfig.getParameter<std::vector<std::string> >("EventList")),
0037 taggingMode_(iConfig.getParameter<bool>("taggingMode")) {
0038 edm::FileInPath fp = iConfig.getParameter<edm::FileInPath>("file");
0039 std::string fFile = fp.fullPath();
0040 std::ifstream inStream(fFile.c_str());
0041
0042 for (unsigned int i = 0; i < eventList_.size(); ++i) {
0043 std::vector<std::string> tokens = edm::tokenize(eventList_[i], ":");
0044 if (tokens.size() != 3) {
0045 throw edm::Exception(edm::errors::Configuration) << "Incorrect event specification";
0046 continue;
0047 }
0048 events_.push_back(Event(atoi(tokens[0].c_str()), atoi(tokens[1].c_str()), atoi(tokens[2].c_str())));
0049 }
0050
0051 std::string line;
0052 while (getline(inStream, line)) {
0053 std::vector<std::string> tokens = edm::tokenize(line, ":");
0054 if (tokens.size() != 3) {
0055 throw edm::Exception(edm::errors::Configuration) << "Incorrect event specification";
0056 continue;
0057 }
0058 events_.push_back(Event(atoi(tokens[0].c_str()), atoi(tokens[1].c_str()), atoi(tokens[2].c_str())));
0059 }
0060
0061 produces<bool>();
0062 }
0063
0064 bool MultiEventFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0065 bool pass = true;
0066
0067 for (unsigned int i = 0; i < events_.size(); ++i) {
0068 if (events_[i].event == iEvent.id().event() && events_[i].run == iEvent.id().run() &&
0069 events_[i].lumi == iEvent.id().luminosityBlock())
0070 pass = false;
0071 }
0072
0073 iEvent.put(std::make_unique<bool>(pass));
0074
0075 return taggingMode_ || pass;
0076 }
0077
0078 #include "FWCore/Framework/interface/MakerMacros.h"
0079
0080 DEFINE_FWK_MODULE(MultiEventFilter);