LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
EventFilter_module.cc
Go to the documentation of this file.
1 //
3 // EventFilter class
4 //
6 #include <fstream>
7 
12 #include "fhiclcpp/ParameterSet.h"
14 
16 namespace filter {
17 
18  class EventFilter : public art::EDFilter {
19 
20  public:
21  explicit EventFilter(fhicl::ParameterSet const&);
22 
23  bool filter(art::Event& evt) override;
24 
25  std::vector<unsigned int> SetOfBadEvents() const { return fBadEvents; }
26  std::vector<unsigned int> SetOfBadRuns() const { return fBadRuns; }
27 
28  private:
29  std::vector<unsigned int> fBadEvents;
30  std::vector<unsigned int> fBadRuns;
31 
32  std::vector<unsigned int> fSelEvents;
33  std::vector<unsigned int> fSelRuns;
34  std::vector<unsigned int> fSelSubRuns;
35  std::string fEventList;
36  int fSelection; //0: reject events based on input
37  //>0: accept events based on txt file
38  //<0: reject events based on txt file
39 
40  }; //class EventFilter
41 }
42 
44 
46 {
47  fBadEvents = pset.get<std::vector<unsigned int>>("BadEvents");
48  fBadRuns = pset.get<std::vector<unsigned int>>("BadRuns");
49 
50  fSelection = pset.get<int>("Selection");
51  fEventList = pset.get<std::string>("EventList");
52  fSelEvents.clear();
53  fSelRuns.clear();
54  std::ifstream in;
55  in.open(fEventList.c_str());
56  char line[1024];
57  while (1) {
58  in.getline(line, 1024);
59  if (!in.good()) break;
60  unsigned int n0, n1, n2;
61  sscanf(line, "%u %u %u", &n0, &n1, &n2);
62  fSelRuns.push_back(n0);
63  fSelSubRuns.push_back(n1);
64  fSelEvents.push_back(n2);
65  }
66  in.close();
67 }
68 
70 {
71  unsigned int evtNo = (unsigned int)evt.id().event();
72  unsigned int runNo = (unsigned int)evt.run();
73  unsigned int subrunNo = (unsigned int)evt.subRun();
74  if (fSelection == 0) {
75  std::vector<unsigned int> sobe = SetOfBadEvents();
76  std::vector<unsigned int> sobr = SetOfBadRuns();
77  if (sobe.size() != sobr.size()) {
78  throw cet::exception("EventFilter.cxx: ")
79  << " BadEvent and BadRun list must be same length. Line " << __LINE__ << ", " << __FILE__
80  << "\n";
81  }
82 
83  for (unsigned int ii = 0; ii < sobe.size(); ++ii) {
84  if (sobe.at(ii) == evtNo && sobr.at(ii) == runNo) {
85  mf::LogInfo("EventFilter: ")
86  << "\t\n Skipping run/event " << runNo << "/" << evtNo << " by request.\n";
87  return false;
88  }
89  }
90  return true;
91  }
92  else {
93  for (unsigned int ii = 0; ii < fSelRuns.size(); ii++) {
94  if (fSelRuns[ii] == runNo && fSelSubRuns[ii] == subrunNo && fSelEvents[ii] == evtNo) {
95  //std::cout<<"true"<<std::endl;
96  if (fSelection > 0) { return true; }
97  else {
98  return false;
99  }
100  }
101  }
102  if (fSelection > 0) { return false; }
103  else {
104  return true;
105  }
106  }
107 }
108 
109 namespace filter {
110 
112 
113 } //namespace filt
std::vector< unsigned int > SetOfBadRuns() const
std::vector< unsigned int > fSelRuns
list of selected runs
SubRunNumber_t subRun() const
Definition: Event.cc:35
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< unsigned int > fSelEvents
list of selected events
std::vector< unsigned int > fBadRuns
list of bad runs
Framework includes.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
bool filter(art::Event &evt) override
EventFilter(fhicl::ParameterSet const &)
std::vector< unsigned int > SetOfBadEvents() const
std::vector< unsigned int > fBadEvents
list of bad events
ifstream in
Definition: comparison.C:7
std::vector< unsigned int > fSelSubRuns
list of selected runs
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.cc:6
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:8
RunNumber_t run() const
Definition: Event.cc:29
EventID id() const
Definition: Event.cc:23
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33