CMS 3D CMS Logo

MultiEventFilter.cc
Go to the documentation of this file.
1 
7 
9 
11 
12 #include <fstream>
13 
15 
16  class Event {
17  public:
22  };
23 
24  public:
25 
26  explicit MultiEventFilter(const edm::ParameterSet & iConfig);
27  ~MultiEventFilter() override {}
28 
29  private:
30 
31  bool filter(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
32 
33  std::vector<Event> events_;
34  const std::vector<std::string> eventList_;
35 
36  const bool taggingMode_;
37 
38 };
39 
40 
42  : eventList_ (iConfig.getParameter<std::vector<std::string> >("EventList") )
43  , taggingMode_ (iConfig.getParameter<bool>("taggingMode") )
44 {
45  edm::FileInPath fp = iConfig.getParameter<edm::FileInPath>("file");
46  std::string fFile = fp.fullPath();
47  std::ifstream inStream(fFile.c_str());
48 
49  for (unsigned int i = 0; i < eventList_.size(); ++i) {
50  std::vector<std::string> tokens = edm::tokenize(eventList_[i], ":");
51  if(tokens.size() != 3) {
52  throw edm::Exception(edm::errors::Configuration) << "Incorrect event specification";
53  continue;
54  }
55  events_.push_back(Event(atoi(tokens[0].c_str()), atoi(tokens[1].c_str()), atoi(tokens[2].c_str())));
56  }
57 
59  while( getline(inStream, line) ){
60  std::vector<std::string> tokens = edm::tokenize(line, ":");
61  if(tokens.size() != 3) {
62  throw edm::Exception(edm::errors::Configuration) << "Incorrect event specification";
63  continue;
64  }
65  events_.push_back(Event(atoi(tokens[0].c_str()), atoi(tokens[1].c_str()), atoi(tokens[2].c_str())));
66  }
67 
68  produces<bool>();
69 }
70 
71 
73 
74  bool pass = true;
75 
76  for (unsigned int i = 0; i < events_.size(); ++i) {
77  if (events_[i].event == iEvent.id().event() &&
78  events_[i].run == iEvent.id().run() &&
79  events_[i].lumi == iEvent.id().luminosityBlock()) pass = false;
80  }
81 
82  iEvent.put(std::make_unique<bool>(pass));
83 
84  return taggingMode_ || pass;
85 
86 }
87 
88 
90 
RunNumber_t run() const
Definition: EventID.h:39
edm::LuminosityBlockNumber_t lumi
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool filter(edm::Event &iEvent, const edm::EventSetup &iSetup) override
unsigned long long EventNumber_t
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
unsigned int LuminosityBlockNumber_t
const bool taggingMode_
std::vector< Event > events_
const std::vector< std::string > eventList_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MultiEventFilter(const edm::ParameterSet &iConfig)
Event(edm::RunNumber_t r, edm::LuminosityBlockNumber_t l, edm::EventNumber_t e)
edm::EventID id() const
Definition: EventBase.h:59
std::string fullPath() const
Definition: FileInPath.cc:163
unsigned int RunNumber_t
~MultiEventFilter() override
Definition: event.py:1
edm::EventNumber_t event
std::vector< std::string > tokenize(std::string const &input, std::string const &separator)
breaks the input string into tokens, delimited by the separator