ProtoDUNETriggerFilter_module.cc
Go to the documentation of this file.
1 // A very simple module to filter out the events with beam triggers
2 // leigh.howard.whitehead@cern.ch
3 
4 #include <iostream>
5 #include <utility>
6 #include <set>
7 
11 
14 
15 namespace filt{
16 
18  public:
19  explicit ProtoDUNETriggerFilter(fhicl::ParameterSet const & pset);
21  virtual bool filter(art::Event& e);
22 
23  private:
24 
25  unsigned int fLogLevel;
26  std::vector<unsigned int> fTimingFlagSelectList;
27  std::vector<unsigned int> fTimingFlagDeselectList;
32 
33  };
34 
35  ProtoDUNETriggerFilter::ProtoDUNETriggerFilter::ProtoDUNETriggerFilter(fhicl::ParameterSet const & pset)
36 : EDFilter(pset) {
37  using std::cout;
38  using std::endl;
39  const std::string myname = "ProtoDUNETriggerFilter::ctor: ";
40  fLogLevel = pset.get<unsigned int>("LogLevel");
41  std::vector<unsigned int> defaulttriglist;
42  defaulttriglist.push_back(0xc);
43  fTimingFlagSelectList = pset.get<std::vector<unsigned int> >("TimingFlagSelectList",defaulttriglist);
44  std::vector<unsigned int> emptylist;
45  fTimingFlagDeselectList = pset.get<std::vector<unsigned int> >("TimingFlagDeselectList",emptylist);
46 
47  fTimingLabel = pset.get<std::string>("TimingLabel","timingrawdecoder");
48  fTimingInstance = pset.get<std::string>("TimingInstance","daq");
49  fTriggerLabel = pset.get<std::string>("TriggerLabel","ctbrawdecoder");
50  fTriggerInstance = pset.get<std::string>("TriggerInstance","daq");
51  if ( fLogLevel >= 1 ) {
52  cout << myname << " LogLevel: " << fLogLevel << endl;
53  cout << myname << " TimingFlagSelectList: [";
54  bool first = true;
55  for ( unsigned int flg : fTimingFlagSelectList ) {
56  if ( first ) first = false;
57  else cout << ", ";
58  cout << flg;
59  }
60  cout << "]" << endl;
61  cout << myname << " TimingFlagDeselectList: [";
62  first = true;
63  for ( unsigned int flg : fTimingFlagDeselectList ) {
64  if ( first ) first = false;
65  else cout << ", ";
66  cout << flg;
67  }
68  cout << "]" << endl;
69  cout << myname << " TimingLabel: " << fTimingLabel << endl;
70  cout << myname << " TimingInstance: " << fTimingInstance << endl;
71  cout << myname << " TriggerLabel: " << fTriggerLabel << endl;
72  cout << myname << " TriggerInstance: " << fTriggerInstance << endl;
73  }
74  }
75 
77  using std::cout;
78  using std::endl;
79  const std::string myname = "ProtoDUNETriggerFilter::filter: ";
80 
81  bool keep = true;
82 
83  bool checkTriggerFlag = fTimingFlagSelectList.size() || fTimingFlagDeselectList.size();
84 
85  std::string stinfo = "Trigger check disabled.";
86  if ( keep && checkTriggerFlag ) {
87  // Fetch the trigger and timing clock.
89  auto htims = evt.getHandle<std::vector<raw::RDTimeStamp>>(itag1);
90  //art::InputTag itag2(fTriggerLabel, fTriggerInstance);
91  //auto hctb = evt.getHandle<std::vector<raw::ctb::pdspctb> >(itag2);
92 
93  if ( ! htims.isValid() ) {
94  std::cout << myname << "WARNING: Timing clocks product not found." << std::endl;
95  if ( fLogLevel >=2 ) stinfo = "Timing clocks product not found.";
96  } else if ( htims->size() != 1 ) {
97  std::cout << myname << "WARNING: Unexpected timing clocks size: " << htims->size() << std::endl;
98  if ( fLogLevel >=2 ) stinfo = "Unexpected timing clocks size.";
99  for ( unsigned int itim=0; itim<htims->size() && itim<50; ++itim ) {
100  std::cout << myname << " " << htims->at(itim).GetTimeStamp() << std::endl;
101  }
102  } else {
103  const raw::RDTimeStamp& tim = htims->at(0);
104 
105  // See https://twiki.cern.ch/twiki/bin/view/CENF/TimingSystemAdvancedOp#Reference_info
106  unsigned int trigFlag = tim.GetFlags();
107  if ( fLogLevel >=2 ) stinfo = "Trigger flag: " + std::to_string(trigFlag);
108 
109  // If TimingFlagSelectList has entries, the trigger flag must be there.
110  if ( fTimingFlagSelectList.size() ) {
111  keep = false;
112  for ( unsigned int flg : fTimingFlagSelectList ) {
113  if ( keep ) break;
114  if ( flg == trigFlag) keep = true;
115  }
116  }
117 
118  // The trigger flag must not be in TimingFlagDeselectList.
119  for ( unsigned int flg : fTimingFlagDeselectList ) {
120  if ( ! keep ) break;
121  if ( flg == trigFlag ) keep = false;
122  }
123 
124  }
125  }
126 
127  if ( fLogLevel >=2 ) std::cout << myname << (keep ? "Keep" : "Reject") << "ing event " << evt.event()
128  << ". " << stinfo << endl;
129  return keep;
130 
131  }
132 
134 
135 }
EventNumber_t event() const
Definition: DataViewImpl.cc:85
uint16_t GetFlags() const
Definition: RDTimeStamp.h:46
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
std::vector< unsigned int > fTimingFlagSelectList
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
ProtoDUNETriggerFilter(fhicl::ParameterSet const &pset)
std::vector< unsigned int > fTimingFlagDeselectList
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
TCEvent evt
Definition: DataStructs.cxx:7
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
QTextStream & endl(QTextStream &s)