Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | List of all members
util::TimeFilter Class Reference
Inheritance diagram for util::TimeFilter:
art::EDFilter art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDFilter
 
using WorkerType = WorkerT< EDFilter >
 
template<typename UserConfig >
using Table = ProducerBase::Table< UserConfig >
 

Public Member Functions

 TimeFilter (fhicl::ParameterSet const &p)
 
virtual ~TimeFilter ()
 
virtual void ReadEventFile ()
 
virtual bool beginRun (art::Run &run) override
 
virtual bool beginSubRun (art::SubRun &sr) override
 
virtual bool filter (art::Event &e) override
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Static Public Attributes

static constexpr bool Pass {true}
 
static constexpr bool Fail {false}
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Attributes

std::string fRawDataLabel
 Raw trigger label (to get trigger/event time) More...
 
double fDelta
 Acceptable difference in trigger timestamp from user-provided time. More...
 
std::string fEventFile
 List of run/subrun/evt_times. More...
 
bool fFileHasEvent
 True if file-format contains event number (4 columns instead of 3) More...
 
int fMode
 0=include, 1=exclude list More...
 
bool fSkip
 Parameter to skip full run or subrun. More...
 
std::set< unsigned intfRuns
 
std::set< std::pair< unsigned int, unsigned int > > fSubRuns
 
std::set< std::tuple< unsigned int, unsigned int, double > > fTimes
 

Detailed Description

Select events based on a list of run/subrun and times. Compares trigger time of current event with time in input file. If the times are within Delta of each other, keep (or exclude) the event. File format is expected to be a list of run/subrun/event/event_time:

run subrun event event_time

100442 18 1963 1578454974.061060 100442 28 466 1578457923.335764 100442 33 138 1578459414.524462 with comments marked by a leading '#'. The event column is not used, it's just there so the same file can be used by a different module for the use-case this was originally designed for. (Looking at TB Spill events to determine if FEBs were shutoff for a corresponding Beamline event). If you don't have an event number, set FileHasEvent to false. By default the module looks for these to be in a file called "time-list.txt", although the filename can be reconfigured. The module can be configured to run in one of two modes. The configuration include_runeventfilter sets Mode=0 which means that the events listed in the file are to be included in the output. The configuration exclude_runeventfilter sets Mode=1 which means that the events listed are to be excluded from the output file.

Definition at line 50 of file TimeFilter_module.cc.

Member Typedef Documentation

using art::EDFilter::ModuleType = EDFilter
inherited

Definition at line 37 of file EDFilter.h.

template<typename UserConfig >
using art::EDFilter::Table = ProducerBase::Table<UserConfig>
inherited

Definition at line 46 of file EDFilter.h.

using art::EDFilter::WorkerType = WorkerT<EDFilter>
inherited

Definition at line 38 of file EDFilter.h.

Constructor & Destructor Documentation

util::TimeFilter::TimeFilter ( fhicl::ParameterSet const &  p)
explicit

Definition at line 85 of file TimeFilter_module.cc.

References ReadEventFile().

86  : fRawDataLabel(p.get<std::string>("RawDataLabel")),
87  fDelta(p.get<double>("Delta")),
88  fEventFile(p.get<std::string>("EventFile")),
89  fFileHasEvent(p.get<bool>("FileHasEvent")),
90  fMode(p.get<int>("Mode"))
91  {
92  ReadEventFile();
93  }
const char * p
Definition: xmltok.h:285
virtual void ReadEventFile()
std::string fEventFile
List of run/subrun/evt_times.
int fMode
0=include, 1=exclude list
bool fFileHasEvent
True if file-format contains event number (4 columns instead of 3)
std::string fRawDataLabel
Raw trigger label (to get trigger/event time)
double fDelta
Acceptable difference in trigger timestamp from user-provided time.
enum BeamMode string
util::TimeFilter::~TimeFilter ( )
virtual

Definition at line 132 of file TimeFilter_module.cc.

133  {
134  }

Member Function Documentation

bool util::TimeFilter::beginRun ( art::Run run)
overridevirtual

Reimplemented from art::EDFilter.

Definition at line 137 of file TimeFilter_module.cc.

References fMode, fRuns, fSkip, and art::Run::run().

138  {
139  fSkip = (fMode == 0 && !fRuns.count(run.run()));
140  return fSkip;
141  }
std::set< unsigned int > fRuns
RunNumber_t run() const
Definition: Run.h:47
int fMode
0=include, 1=exclude list
bool fSkip
Parameter to skip full run or subrun.
bool util::TimeFilter::beginSubRun ( art::SubRun sr)
overridevirtual

Reimplemented from art::EDFilter.

Definition at line 144 of file TimeFilter_module.cc.

References fMode, fSkip, fSubRuns, make_pair(), art::SubRun::run(), and art::SubRun::subRun().

145  {
146  fSkip = (fMode == 0 && !fSubRuns.count(std::make_pair(sr.run(), sr.subRun())));
147  return fSkip;
148  }
std::set< std::pair< unsigned int, unsigned int > > fSubRuns
SubRunNumber_t subRun() const
Definition: SubRun.h:44
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
int fMode
0=include, 1=exclude list
bool fSkip
Parameter to skip full run or subrun.
RunNumber_t run() const
Definition: SubRun.h:49
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDFilter::currentContext ( ) const
protectedinherited
bool util::TimeFilter::filter ( art::Event e)
overridevirtual

Implements art::EDFilter.

Definition at line 151 of file TimeFilter_module.cc.

References abs(), novadaq::timeutils::convertNovaTimeToUnixTime(), DEFINE_ART_MODULE(), release_diff::diff, e, allTimeWatchdog::endl, fDelta, fMode, fRawDataLabel, fSkip, fSubRuns, fTimes, rawdata::RawTrigger::fTriggerTimingMarker_TimeStart, art::DataViewImpl::getByLabel(), it, LOG_INFO, make_pair(), art::Event::run(), art::Event::subRun(), and msf_helper::timespec.

152  {
153 
154  // Skipping full run or subrun
155  if (fSkip){
156  return false;
157  }
158 
159  bool inlist = false;
160  // Is this run/subrun pair in the list?
161  inlist = fSubRuns.count(std::make_pair(evt.run(), evt.subRun()));
162 
163  // If we're looking for the events in the list, and this one isn't, then
164  // we can skip this event.
165  if(fMode == 0 && !inlist){
166  return false;
167  }
168  // If we're rejecting events in the list, and this event is in we can
169  // reject it, so long as it's not just the slices we're supposed to be
170  // rejecting.
171  if(fMode == 1 && inlist){
172  return false;
173  }
174 
175  // Now find the trigger time for this event and compare to list.
177  evt.getByLabel(fRawDataLabel, trigs);
178  const rawdata::RawTrigger trig = trigs->at(0);
179 
180  struct timespec unixTime;
182 
183  unsigned long int unixTimeSec = unixTime.tv_sec;
184  unsigned long int unixTimeNanoSec = unixTime.tv_nsec;
185  double evtTime = unixTimeSec + (1e-9)*unixTimeNanoSec;
186 
187  // lower_bound returns value in set just above (or equal to) the key you give it
188  // in this case, returns the first input event time after the current event's trigger time
189  // (so the first event time that could be contained within the current trigger)
190  // Then check the time difference between the trigger time and the time you're trying to match
191  // If the delta is too large, reject the event (or keep if mode is 1)
192  std::set< std::tuple<unsigned int, unsigned int, double> >::iterator it
193  = fTimes.lower_bound(std::make_tuple(evt.run(),evt.subRun(),evtTime));
194  double input_time = std::get<2>(*it);
195  // bound function will only find *next* time in list. Check previous time to see if diff is closer.
196  it--;
197  double input_time_prev = std::get<2>(*it);
198  double diff = evtTime - input_time;
199  double diff2 = evtTime - input_time_prev;
200  if (abs(diff2)<abs(diff)) {
201  input_time = input_time_prev;
202  diff = diff2;
203  }
204 
205  // If we're keeping times in the list, and this event has too large
206  // a time difference, reject it.
207  if (fMode == 0 && abs(diff) > fDelta){
208  return false;
209  }
210  // If we're rejecting times in the list, and this event is within Delta
211  // of a time in the list, reject it.
212  if (fMode == 1 && abs(diff) <= fDelta){
213  return false;
214  }
215 
216  LOG_INFO("TimeFilter")<<"Kept (or rejected if Mode=1) event with trigger time: "<<std::fixed<<evtTime
217  <<". Closest time in list: "<<input_time<<". Diff: "<<diff<<std::endl;
218 
219  return true;
220  }
std::set< std::pair< unsigned int, unsigned int > > fSubRuns
set< int >::iterator it
std::set< std::tuple< unsigned int, unsigned int, double > > fTimes
void abs(TH1 *hist)
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
bool convertNovaTimeToUnixTime(uint64_t const &inputNovaTime, struct timespec &outputUnixTime)
int fMode
0=include, 1=exclude list
int evt
bool fSkip
Parameter to skip full run or subrun.
unsigned long long fTriggerTimingMarker_TimeStart
Definition: RawTrigger.h:38
#define LOG_INFO(stream)
Definition: Messenger.h:144
std::string fRawDataLabel
Raw trigger label (to get trigger/event time)
double fDelta
Acceptable difference in trigger timestamp from user-provided time.
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
template<typename PROD , BranchType B>
ProductID art::EDFilter::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 131 of file EDFilter.h.

References art::EDFilter::moduleDescription_.

Referenced by novaddt::HoughTrackMaker::create_associations().

132  {
133  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
134  instanceName);
135  }
ModuleDescription moduleDescription_
Definition: EDFilter.h:124
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void util::TimeFilter::ReadEventFile ( )
virtual

Definition at line 96 of file TimeFilter_module.cc.

References om::cerr, clear, allTimeWatchdog::endl, fEventFile, fFileHasEvent, fRuns, fSubRuns, fTimes, make_pair(), updateRunHistoryTables::run, string, and getGoodRuns4SAM::subrun.

Referenced by TimeFilter().

97  {
98 
99  fRuns. clear();
100  fSubRuns. clear();
101  fTimes. clear();
102  std::ifstream ifs;
103  ifs.open(fEventFile.c_str());
104  if (ifs.is_open()) {
105  while (ifs.good()) {
106  std::string buff;
107  std::getline(ifs, buff);
108  if (buff[0]=='#') continue;
109 
110  int run, subrun, event;
111  double time;
112 
113  if (fFileHasEvent)
114  sscanf(buff.c_str(), "%d %d %d %lf", &run, &subrun, &event, &time);
115  else
116  sscanf(buff.c_str(), "%d %d %lf", &run, &subrun, &time);
117 
118  fRuns.insert(run);
119  fSubRuns.insert(std::make_pair(run, subrun));
120  fTimes.insert(std::make_tuple(run, subrun, time));
121  } // close while loop
122  ifs.close();
123  } // close input file
124  else {
125  std::cerr << __FILE__ << ":" << __LINE__
126  << " Failed to open file " << fEventFile << " for read"
127  << std::endl;
128  }
129  }
std::set< std::pair< unsigned int, unsigned int > > fSubRuns
vector< vector< double > > clear
std::set< std::tuple< unsigned int, unsigned int, double > > fTimes
std::set< unsigned int > fRuns
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
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
std::string fEventFile
List of run/subrun/evt_times.
bool fFileHasEvent
True if file-format contains event number (4 columns instead of 3)
enum BeamMode string
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

constexpr bool art::EDFilter::Fail {false}
staticinherited

Definition at line 33 of file EDFilter.h.

Referenced by evgen::GENIEFilter::filter().

double util::TimeFilter::fDelta
private

Acceptable difference in trigger timestamp from user-provided time.

Definition at line 65 of file TimeFilter_module.cc.

Referenced by filter().

std::string util::TimeFilter::fEventFile
private

List of run/subrun/evt_times.

Definition at line 66 of file TimeFilter_module.cc.

Referenced by ReadEventFile().

bool util::TimeFilter::fFileHasEvent
private

True if file-format contains event number (4 columns instead of 3)

Definition at line 67 of file TimeFilter_module.cc.

Referenced by ReadEventFile().

int util::TimeFilter::fMode
private

0=include, 1=exclude list

Definition at line 68 of file TimeFilter_module.cc.

Referenced by beginRun(), beginSubRun(), and filter().

std::string util::TimeFilter::fRawDataLabel
private

Raw trigger label (to get trigger/event time)

Definition at line 64 of file TimeFilter_module.cc.

Referenced by filter().

std::set<unsigned int> util::TimeFilter::fRuns
private

Definition at line 72 of file TimeFilter_module.cc.

Referenced by beginRun(), and ReadEventFile().

bool util::TimeFilter::fSkip
private

Parameter to skip full run or subrun.

Definition at line 70 of file TimeFilter_module.cc.

Referenced by beginRun(), beginSubRun(), and filter().

std::set< std::pair<unsigned int, unsigned int> > util::TimeFilter::fSubRuns
private

Definition at line 73 of file TimeFilter_module.cc.

Referenced by beginSubRun(), filter(), and ReadEventFile().

std::set< std::tuple<unsigned int, unsigned int, double> > util::TimeFilter::fTimes
private

Definition at line 75 of file TimeFilter_module.cc.

Referenced by filter(), and ReadEventFile().

constexpr bool art::EDFilter::Pass {true}
staticinherited

Definition at line 32 of file EDFilter.h.

Referenced by evgen::GENIEFilter::filter().


The documentation for this class was generated from the following file: