LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
EventTimeFilter_module.cc
Go to the documentation of this file.
1 //
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 //
14 
15 // C++
16 #include <iostream>
17 
18 // ROOT
19 #include "RtypesCore.h"
20 #include "TMath.h"
21 #include "TTimeStamp.h"
22 
27 #include "fhiclcpp/ParameterSet.h"
28 
30 namespace filter {
31 
32  class EventTimeFilter : public art::EDFilter {
33 
34  public:
35  explicit EventTimeFilter(fhicl::ParameterSet const&);
36 
37  bool filter(art::Event& evt);
38 
39  private:
40  UInt_t fDateRangeLow;
41  UInt_t fTimeRangeLow;
44 
45  }; //class EventTimeFilter
46 
47 }
48 
50 {
51  fDateRangeLow = pset.get<UInt_t>("DateRangeLow", 0); // YYYYMMDD
52  fTimeRangeLow = pset.get<UInt_t>("TimeRangeLow", 0); // HHMMSS
53  fDateRangeHigh = pset.get<UInt_t>("DateRangeHigh", 0); // YYYYMMDD
54  fTimeRangeHigh = pset.get<UInt_t>("TimeRangeHigh", 0); // HHMMSS
55 }
56 
58 {
59 
60  // Check that input date is in correct format
61  if (fDateRangeHigh > 99999999 || fDateRangeLow > 99999999) {
62  std::cout << "Warning: please provide date in format YYYYMMDD, event time "
63  << "filter returning false." << std::endl;
64  return false;
65  }
66  if (fDateRangeHigh > 0 && fDateRangeHigh < 10000000) {
67  std::cout << "Warning: please provide date in format YYYYMMDD, event time "
68  << "filter returning false." << std::endl;
69  return false;
70  }
71  if (fDateRangeLow > 0 && fDateRangeLow < 10000000) {
72  std::cout << "Warning: please provide date in format YYYYMMDD, event time "
73  << "filter returning false." << std::endl;
74  return false;
75  }
76 
77  // Check that input times are in correct format
78  if (fTimeRangeHigh > 999999 || fTimeRangeLow > 999999) {
79  std::cout << "Warning: please provide time in format HHMMSS, event time "
80  << "filter returning false." << std::endl;
81  return false;
82  }
83  if (fTimeRangeHigh > 0 && fTimeRangeHigh < 100000) {
84  std::cout << "Warning: please provide time in format HHMMSS, event time "
85  << "filter returning false." << std::endl;
86  return false;
87  }
88  if (fTimeRangeLow > 0 && fTimeRangeLow < 100000) {
89  std::cout << "Warning: please provide time in format HHMMSS, event time "
90  << "filter returning false." << std::endl;
91  return false;
92  }
93 
94  // Event time
95  art::Timestamp evtTime = evt.time();
96  TTimeStamp* evtTTS;
97  if (evtTime.timeHigh() == 0) { evtTTS = new TTimeStamp(evtTime.timeLow()); }
98  else {
99  evtTTS = new TTimeStamp(evtTime.timeHigh(), evtTime.timeLow());
100  }
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) { ttsLow = new TTimeStamp(fDateRangeLow, fTimeRangeLow, 0u); }
108  else {
109  ttsLow = new TTimeStamp(fDateRangeLow, 0u, 0u);
110  std::cout << "Warning: No start time given for event time filter, "
111  << "assuming 00:00:00" << std::endl;
112  }
113  }
114 
115  // Requested time range higher end
116  TTimeStamp* ttsHigh(nullptr);
117  if (fDateRangeHigh != 0) {
118  if (fTimeRangeHigh != 0) { ttsHigh = new TTimeStamp(fDateRangeHigh, fTimeRangeHigh, 0u); }
119  else {
120  std::cout << "Warning: No end time given for event time filter, assuming "
121  << "23:59:59" << std::endl;
122  ttsHigh = new TTimeStamp(fDateRangeHigh, 235959u, 0u);
123  }
124  }
125 
126  // Filter decision
127  if (ttsLow == nullptr && ttsHigh == nullptr) {
128  std::cout << "Warning: No date range requested for event time filter, "
129  << "returning false." << std::endl;
130  return false;
131  }
132  else if (ttsLow == nullptr) {
133  std::cout << "Warning: No lower limit requested for event time filter, "
134  << "taking all events before " << ttsHigh->AsString() << std::endl;
135  if (evtTTS->GetSec() < ttsHigh->GetSec()) { return true; }
136  else {
137  return false;
138  }
139  }
140  else if (ttsHigh == nullptr) {
141  std::cout << "Warning: No lower limit requested for event time filter, "
142  << "taking all events after " << ttsLow->AsString() << std::endl;
143  if (evtTTS->GetSec() > ttsLow->GetSec()) { return true; }
144  else {
145  return false;
146  }
147  }
148  else {
149  if (evtTTS->GetSec() > ttsLow->GetSec() && evtTTS->GetSec() < ttsHigh->GetSec()) {
150  return true;
151  }
152  else {
153  return false;
154  }
155  }
156 }
157 
158 namespace filter {
160 }
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
Framework includes.
bool filter(art::Event &evt)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
EventTimeFilter(fhicl::ParameterSet const &)
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.cc:6
Timestamp time() const
Definition: Event.cc:47
TCEvent evt
Definition: DataStructs.cxx:8