EventFilterNoSlice_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 /// \brief Filter events based on their run/event numbers
3 /// \author messier@indiana.edu
4 /// \date
5 ///////////////////////////////////////////////////////////////////////////
6 #include <cstdlib>
7 #include <iostream>
8 #include <fstream>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13 
19 
20 namespace util {
21  /// Select events based on a list of run and event numbers
22  ///
23  /// File format is expected to be a list of run/subrun/event triplets:
24  ///
25  /// # run subrun event
26  /// 10796 4 102012
27  /// 10796 2 121093
28  /// 10796 11 133092
29  ///
30  /// with comments marked by a leading '#'. By default the module
31  /// looks for these to be in a file called "event-list.txt",
32  /// although the filename can be reconfigured. The module can be
33  /// configured to run in one of two modes. The configuration
34  /// include_runeventfilter sets Mode=0 which means that the events
35  /// listed in the file are to be included in the output. The
36  /// configuration exclude_runeventfilter sets Mode=1 which means
37  /// that the events listed are to be excluded from the output
38  /// file. See RunEventFilter.fcl.
39  ///
41  {
42  public:
43  explicit EventFilterNoSlice(fhicl::ParameterSet const& p);
44  virtual ~EventFilterNoSlice();
45 
46  virtual void reconfigure(fhicl::ParameterSet const& p);
47 
48  virtual bool beginRun(art::Run& run) override;
49  virtual bool beginSubRun(art::SubRun& sr) override;
50  virtual bool filter(art::Event& e) override;
51 
52 
53  private:
54  std::string fEventFile; ///< List of event numbers
55  int fMode; ///< 0=include, 1=exclude list
56 
57  std::set<unsigned int> fRuns;
58  std::set< std::pair<unsigned int, unsigned int> > fSubRuns;
59  std::set< std::tuple<unsigned int, unsigned int,
60  unsigned int> > fEvents;
61 
62  };
63 }
64 
65 
66 ////////////////////////////////////////////////////////////////////////
67 namespace util
68 {
69  //......................................................................
71  : fMode(0)
72  {
73  this->reconfigure(p);
74  }
75 
76  //......................................................................
78  {
79  fEventFile = p.get<std::string>("EventFile");
80  fMode = p.get<int>("Mode");
81 
82  //
83  // Reconfigure the run and event list given the new file name.
84  //
85  fRuns. clear();
86  fSubRuns. clear();
87  fEvents. clear();
88  std::ifstream ifs;
89  ifs.open(fEventFile.c_str());
90  if (ifs.is_open()) {
91  while (ifs.good()) {
92  std::string buff;
93  std::getline(ifs, buff);
94  if (buff[0]=='#') continue;
95 
96  int run, subrun, event;
97 
98  sscanf(buff.c_str(), "%d %d %d", &run, &subrun, &event);
99 
100  fRuns.insert(run);
101  fSubRuns.insert(std::make_pair(run, subrun));
102  fEvents.insert(std::make_tuple(run, subrun, event));
103  } // close while loop
104  ifs.close();
105  } // close input file
106  else {
107  std::cerr << __FILE__ << ":" << __LINE__
108  << " Failed to open file " << fEventFile << " for read"
109  << std::endl;
110  }
111  }
112 
113  //......................................................................
115  {
116  }
117 
118  //......................................................................
120  {
121  return true;
122  }
123 
124  //......................................................................
126  {
127  return true;
128  }
129 
130  //......................................................................
132  {
133 
134 
135  bool inlist = false;
136  // Is this event in the list?
137  inlist = fEvents.count(std::make_tuple(evt.run(),
138  evt.subRun(),
139  evt.event()));
140 
141  // If we're looking for the events in the list, and this one isn't, then
142  // we can skip this event.
143  if(fMode == 0 && !inlist){
144  //evt.put(std::move(filtcol));
145  return false;
146  }
147  // If we're rejecting events in the list, and this event is in we can
148  // reject it, so long as it's not just the slices we're supposed to be
149  // rejecting.
150  if(fMode == 1 && inlist){
151  //evt.put(std::move(filtcol));
152  return false;
153  }
154 
155  return true;
156  }
157 
158 } // end namespace util
159 
160 
161 ////////////////////////////////////////////////////////////////////////
162 namespace util
163 {
165 }
166 ////////////////////////////////////////////////////////////////////////
SubRunNumber_t subRun() const
Definition: Event.h:72
Filter events based on their run/event numbers.
virtual bool beginRun(art::Run &run) override
const char * p
Definition: xmltok.h:285
vector< vector< double > > clear
OStream cerr
Definition: OStream.cxx:7
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
DEFINE_ART_MODULE(TestTMapFile)
Definition: Run.h:31
int fMode
0=include, 1=exclude list
EventFilterNoSlice(fhicl::ParameterSet const &p)
T get(std::string const &key) const
Definition: ParameterSet.h:231
virtual bool filter(art::Event &e) override
int evt
std::set< std::tuple< unsigned int, unsigned int, unsigned int > > fEvents
caf::StandardRecord * sr
std::set< std::pair< unsigned int, unsigned int > > fSubRuns
EventNumber_t event() const
Definition: Event.h:67
Definition: run.py:1
virtual void reconfigure(fhicl::ParameterSet const &p)
std::string fEventFile
List of event numbers.
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.h:77
std::set< unsigned int > fRuns
virtual bool beginSubRun(art::SubRun &sr) override
enum BeamMode string