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