Jpp
JRemovePMT.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <set>
6 
7 #include "JDAQ/JDAQ.hh"
9 #include "JDAQ/JDAQTimeslice.hh"
10 #include "JDAQ/JDAQSummaryslice.hh"
11 #include "JDAQ/JDAQEvent.hh"
13 
16 #include "JSupport/JSupport.hh"
17 
18 #include "JLang/JTypeSelector.hh"
21 
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 namespace {
26 
28 
29  /**
30  * Remove PMT(s) from data.
31  *
32  * \param data data (I/O)
33  * \param PMT PMT(s) to be removed
34  */
35  template<class T>
36  inline void remove(std::vector<T>& data, const std::set<JDAQPMTIdentifier>& PMT)
37  {
38  using namespace std;
39 
40  vector<T> buffer;
41 
42  for (typename vector<T>::const_iterator hit = data.begin(); hit != data.end(); ++hit) {
43  if (PMT.find(JDAQPMTIdentifier(hit->getModuleID(), hit->getPMT())) == PMT.end() &&
44  PMT.find(JDAQPMTIdentifier(-1, hit->getPMT())) == PMT.end()) {
45  buffer.push_back(*hit);
46  }
47  }
48 
49  data.swap(buffer);
50  }
51 }
52 
53 
54 /**
55  * \file
56  *
57  * Example program to remove PMT(s) from data (and set corresponding rate to 0).
58  * \author mdejong
59  */
60 int main(int argc, char **argv)
61 {
62  using namespace std;
63  using namespace JPP;
64  using namespace KM3NETDAQ;
65 
66  JMultipleFileScanner<JDAQTimesliceTypes_t> inputFile;
67  JLimit_t& numberOfEvents = inputFile.getLimit();
68  JFileRecorder<JTriggerTypes_t> outputFile;
70  int debug;
71 
72  try {
73 
74  JParser<> zap("Example program to remove PMT(s) from data (and set corresponding rate to 0).");
75 
76  zap['f'] = make_field(inputFile);
77  zap['o'] = make_field(outputFile) = "abc.root";
78  zap['n'] = make_field(numberOfEvents) = JLimit::max();
79  zap['P'] = make_field(PMT) = JPARSER::initialised();
80  zap['d'] = make_field(debug) = 1;
81 
82  zap(argc, argv);
83  }
84  catch(const exception& error) {
85  FATAL(error.what() << endl);
86  }
87 
88 
89  cout.tie(&cerr);
90 
91  outputFile.open();
92 
93  {
94  JObjectMultiplexer<JDAQTimesliceTypes_t, JDAQTimeslice> in(inputFile);
95 
96  // put base class JDAQTimeslice at end of type list
97 
99 
100  JObjectDemultiplexer<JDAQTimeslice, daq_timeslicetypes_t> out(outputFile);
101 
102  for (counter_type counter = 0; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
103 
104  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
105 
106  JDAQTimeslice* timeslice = in.next();
107 
108  for (JDAQTimeslice::iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
109 
110  bool rm = false;
111 
112  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
113 
114  if (PMT.find(JDAQPMTIdentifier(frame->getModuleID(), pmt)) != PMT.end() ||
115  PMT.find(JDAQPMTIdentifier(-1, pmt)) != PMT.end()) {
116  rm = true;
117  }
118  }
119 
120  if (rm) {
121 
123 
124  for (JDAQSuperFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit) {
125  buffer[hit->getPMT()].push_back(*hit);
126  }
127 
128  vector<JDAQHit> data;
129 
130  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
131 
132  if (PMT.find(JDAQPMTIdentifier(frame->getModuleID(), pmt)) == PMT.end() &&
133  PMT.find(JDAQPMTIdentifier(-1, pmt)) == PMT.end()) {
134  copy(buffer[pmt].begin(), buffer[pmt].end(), back_inserter(data));
135  }
136  }
137 
138  sort(data.begin(), data.end());
139 
140  frame->clear();
141  frame->add(data.size(), data.data());
142  }
143  }
144 
145  out.put(*timeslice);
146  }
147  STATUS(endl);
148  }
149  {
150  JMultipleFileScanner<JDAQEvent> in(inputFile);
151 
152  while (in.hasNext()) {
153 
154  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
155 
156  JDAQEvent* event = in.next();
157 
158  remove(event->getHits<JDAQTriggeredHit>(), PMT);
159  remove(event->getHits<JDAQSnapshotHit> (), PMT);
160 
161  outputFile.put(*event);
162  }
163  STATUS(endl);
164  }
165  {
166  JMultipleFileScanner<JDAQSummaryslice> in(inputFile);
167 
168  while (in.hasNext()) {
169 
170  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
171 
172  JDAQSummaryslice* summaryslice = in.next();
173 
174  for (JDAQSummaryslice::iterator frame = summaryslice->begin(); frame != summaryslice->end(); ++frame) {
175 
176  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
177 
178  if (PMT.find(JDAQPMTIdentifier(frame->getModuleID(), pmt)) != PMT.end() ||
179  PMT.find(JDAQPMTIdentifier(-1, pmt)) != PMT.end()) {
180  (*frame)[pmt].setValue(0.0);
181  }
182  }
183  }
184 
185  outputFile.put(*summaryslice);
186  }
187  STATUS(endl);
188  }
189 
190  JMultipleFileScanner<JTriggerParameters> io(inputFile);
191 
192  io >> outputFile;
193 
194  outputFile.close();
195 }
JDAQ.hh
JTypeSelector.hh
KM3NETDAQ::JDAQEvent
DAQ Event.
Definition: JDAQEvent.hh:34
JTriggerParameters.hh
JFileRecorder.hh
JMessage.hh
main
int main(int argc, char **argv)
Definition: JRemovePMT.cc:60
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
JLANG::JAppend
Append to type list.
Definition: JTypeList.hh:61
std::vector< T >
JSUPPORT::JLimit_t
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:215
KM3NETDAQ::NUMBER_OF_PMTS
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
KM3NETDAQ::JDAQTimeslice
Data time slice.
Definition: JDAQTimeslice.hh:36
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JDAQTimeslice.hh
PMT
JDAQPMTIdentifier PMT
Command line options.
Definition: JDAQTimesliceSelector.cc:35
JAANET::copy
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:152
std::set
Definition: JSTDTypes.hh:13
JDAQSummaryslice.hh
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
KM3NETDAQ::JDAQTriggeredHit
DAQ triggered hit.
Definition: JDAQTriggeredHit.hh:25
KM3NETDAQ::JDAQSuperFrame::const_iterator
JDAQFrame::const_iterator const_iterator
Definition: JDAQSuperFrame.hh:34
debug
int debug
debug level
Definition: JSirene.cc:59
KM3NETDAQ::JDAQTriggerCounter::next
JTriggerCounter_t next()
Increment trigger counter.
Definition: JDAQTriggerCounter.hh:120
JSUPPORT::JLimit::getLimit
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
KM3NETDAQ::JDAQSummaryslice
Data summary slice.
Definition: JDAQSummaryslice.hh:31
JObjectMultiplexer.hh
KM3NETDAQ::JDAQKeyHit
DAQ key hit.
Definition: JDAQKeyHit.hh:24
JMultipleFileScanner.hh
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
KM3NETDAQ::JDAQPMTIdentifier
PMT identifier.
Definition: JDAQPMTIdentifier.hh:25
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JDAQEvent.hh
JDAQPMTIdentifier.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JROOT::counter_type
Long64_t counter_type
Type definition for counter.
Definition: JCounter.hh:24
JObjectDemultiplexer.hh