All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventTimeFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // EventTimeFilter class
4 //
5 // author: Aidan Reynolds
6 // email: aidan.reynolds@physics.ox.ac.uk
7 //
8 // - A filter to select events between given start and end dates and times.
9 // - Dates should be passed in the form YYYYMMDD
10 // - Times should be passes in the form HHMMSS
11 // - All dates and times should be in UTC
12 //
13 ////////////////////////////////////////////////////////////////////////
14 
15 // C++
16 #include <iostream>
17 
18 // ROOT
19 #include "RtypesCore.h"
20 #include "TMath.h"
21 #include "TTimeStamp.h"
22 
23 /// Framework
24 #include "art/Framework/Core/ModuleMacros.h"
25 #include "art/Framework/Core/EDFilter.h"
26 #include "art/Framework/Principal/Event.h"
27 #include "fhiclcpp/ParameterSet.h"
28 
29 ///filters for events, etc
30 namespace filter {
31 
32  class EventTimeFilter : public art::EDFilter {
33 
34  public:
35 
36  explicit EventTimeFilter(fhicl::ParameterSet const& );
37 
38  bool filter(art::Event& evt);
39 
40  private:
41 
42  UInt_t fDateRangeLow;
43  UInt_t fTimeRangeLow;
46 
47  }; //class EventTimeFilter
48 
49 }
50 
51 filter::EventTimeFilter::EventTimeFilter(fhicl::ParameterSet const& pset)
52  : EDFilter{pset}
53 {
54  fDateRangeLow = pset.get<UInt_t>("DateRangeLow", 0); // YYYYMMDD
55  fTimeRangeLow = pset.get<UInt_t>("TimeRangeLow", 0); // HHMMSS
56  fDateRangeHigh = pset.get<UInt_t>("DateRangeHigh", 0); // YYYYMMDD
57  fTimeRangeHigh = pset.get<UInt_t>("TimeRangeHigh", 0); // HHMMSS
58 }
59 
61 
62  // Check that input date is in correct format
63  if (fDateRangeHigh > 99999999 || fDateRangeLow > 99999999) {
64  std::cout << "Warning: please provide date in format YYYYMMDD, event time "
65  << "filter returning false." << std::endl;
66  return false;
67  }
68  if (fDateRangeHigh > 0 && fDateRangeHigh < 10000000) {
69  std::cout << "Warning: please provide date in format YYYYMMDD, event time "
70  << "filter returning false." << std::endl;
71  return false;
72  }
73  if (fDateRangeLow > 0 && fDateRangeLow < 10000000) {
74  std::cout << "Warning: please provide date in format YYYYMMDD, event time "
75  << "filter returning false." << std::endl;
76  return false;
77  }
78 
79  // Check that input times are in correct format
80  if (fTimeRangeHigh > 999999 || fTimeRangeLow > 999999) {
81  std::cout << "Warning: please provide time in format HHMMSS, event time "
82  << "filter returning false." << std::endl;
83  return false;
84  }
85  if (fTimeRangeHigh > 0 && fTimeRangeHigh < 100000) {
86  std::cout << "Warning: please provide time in format HHMMSS, event time "
87  << "filter returning false." << std::endl;
88  return false;
89  }
90  if (fTimeRangeLow > 0 && fTimeRangeLow < 100000) {
91  std::cout << "Warning: please provide time in format HHMMSS, event time "
92  << "filter returning false." << std::endl;
93  return false;
94  }
95 
96  // Event time
97  art::Timestamp evtTime = evt.time();
98  TTimeStamp * evtTTS;
99  if (evtTime.timeHigh() == 0) { evtTTS = new TTimeStamp(evtTime.timeLow()); }
100  else { evtTTS = new TTimeStamp(evtTime.timeHigh(), evtTime.timeLow()); }
101 
102  std::cout << "Event time: " << evtTTS -> AsString() << std::endl;
103 
104  // Requested time range lower end
105  TTimeStamp * ttsLow(nullptr);
106  if (fDateRangeLow != 0) {
107  if (fTimeRangeLow != 0) {
108  ttsLow = new TTimeStamp(fDateRangeLow, fTimeRangeLow, 0u);
109  }
110  else {
111  ttsLow = new TTimeStamp(fDateRangeLow, 0u, 0u);
112  std::cout << "Warning: No start time given for event time filter, "
113  << "assuming 00:00:00" << std::endl;
114  }
115  }
116 
117  // Requested time range higher end
118  TTimeStamp * ttsHigh(nullptr);
119  if (fDateRangeHigh != 0) {
120  if (fTimeRangeHigh != 0) {
121  ttsHigh = new TTimeStamp(fDateRangeHigh, fTimeRangeHigh, 0u);
122  }
123  else {
124  std::cout << "Warning: No end time given for event time filter, assuming "
125  << "23:59:59" << std::endl;
126  ttsHigh = new TTimeStamp(fDateRangeHigh, 235959u, 0u);
127  }
128  }
129 
130  // Filter decision
131  if (ttsLow == nullptr && ttsHigh == nullptr) {
132  std::cout << "Warning: No date range requested for event time filter, "
133  << "returning false." << std::endl;
134  return false;
135  }
136  else if (ttsLow == nullptr) {
137  std::cout << "Warning: No lower limit requested for event time filter, "
138  << "taking all events before " << ttsHigh -> AsString()
139  << std::endl;
140  if (evtTTS -> GetSec() < ttsHigh -> GetSec()) { return true; }
141  else { return false;}
142  }
143  else if (ttsHigh == nullptr) {
144  std::cout << "Warning: No lower limit requested for event time filter, "
145  << "taking all events after " << ttsLow -> AsString()
146  << std::endl;
147  if (evtTTS -> GetSec() > ttsLow -> GetSec()) { return true; }
148  else { return false;}
149  }
150  else {
151  if (evtTTS -> GetSec() > ttsLow -> GetSec() &&
152  evtTTS -> GetSec() < ttsHigh -> GetSec()) { return true; }
153  else { return false; }
154  }
155 
156 }
157 
158 namespace filter { DEFINE_ART_MODULE(EventTimeFilter) }
bool filter(art::Event &evt)
EventTimeFilter(fhicl::ParameterSet const &)
physics filters filter
TCEvent evt
Definition: DataStructs.cxx:8
BEGIN_PROLOG could also be cout