Jpp  16.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JChecksum.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <limits>
5 #include <deque>
6 #include <map>
7 
8 #include "TROOT.h"
9 #include "TFile.h"
10 #include "TH1D.h"
11 
13 
14 #include "JDAQ/JDAQTimesliceIO.hh"
17 #include "JSupport/JSupport.hh"
18 
20 #include "JROOT/JManager.hh"
21 
23 #include "JTrigger/JChecksum.hh"
24 
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 namespace {
29 
30  /**
31  * Print DAQ hit.
32  *
33  * \param out output stream
34  * \param hit DAQ hit
35  */
36  void print(std::ostream& out, const KM3NETDAQ::JDAQHit& hit)
37  {
38  using namespace std;
39 
40  out << "\thit: "
41  << setw(3) << (int) hit.getPMT() << ' '
42  << setw(8) << hex << hit.getT() << ' '
43  << setw(10) << dec << hit.getT() << ' '
44  << setw(3) << (int) hit.getToT();
45  }
46 
47  /**
48  * Print error type.
49  *
50  * \param out output stream
51  * \param type error type
52  */
53  void print(std::ostream& out, const int type)
54  {
55  using namespace std;
56  using namespace JPP;
57 
58  switch (type) {
59 
60  case JChecksum::TIME_t:
61  out << "time ";
62  break;
63 
64  case JChecksum::ETDC_t:
65  out << "TDC ";
66  break;
67 
68  case JChecksum::EPMT_t:
69  out << "PMT ";
70  break;
71 
72  case JChecksum::EUDP_t:
73  out << "UDP ";
74  break;
75 
76  case JChecksum::SIZE_t:
77  out << "size ";
78  break;
79 
80  default:
81  out << "? ";
82  break;
83  }
84  }
85 }
86 
87 
88 /**
89  * \file
90  *
91  * Example program to histogram KM3NETDAQ::JDAQTimeslice.
92  * \author mdejong
93  */
94 int main(int argc, char **argv)
95 {
96  using namespace std;
97  using namespace JPP;
98  using namespace KM3NETDAQ;
99 
101  JLimit_t & numberOfEvents = inputFile.getLimit();
102  JROOTClassSelector selector;
103  string outputFile;
104  int N;
105  double rate_Hz;
106  int debug;
107 
108  try {
109 
110  JParser<> zap("Example program to histogram timeslice data.");
111 
112  zap['f'] = make_field(inputFile);
113  zap['n'] = make_field(numberOfEvents) = JLimit::max();
114  zap['C'] = make_field(selector) = getROOTClassSelection<JDAQTimesliceTypes_t>();
115  zap['o'] = make_field(outputFile) = "checksum.root";
116  zap['N'] = make_field(N, "number of rows to print") = 10;
117  zap['R'] = make_field(rate_Hz, "high-rate veto [Hz]") = 0.0;
118  zap['d'] = make_field(debug) = 3;
119 
120  zap(argc, argv);
121  }
122  catch(const exception& error) {
123  FATAL(error.what() << endl);
124  }
125 
126  cout.tie(&cerr);
127 
129 
130 
131  if (rate_Hz > 0.0) {
132  MAXIMAL_FRAME_SIZE = (int) (getFrameTime() * 1.0e-9 * rate_Hz * NUMBER_OF_PMTS + 0.5);
133  }
134 
135  map<int, int> errors;
136 
137  JFrameIndexRange frame_index = getFrameIndexRange<JDAQSummaryslice>(inputFile);
138 
139  const Long64_t nx = frame_index.second - frame_index.first + 1;
140  const Double_t xmin = (Double_t) frame_index.first - 0.5;
141  const Double_t xmax = (Double_t) frame_index.second + 0.5;
142 
143  JManager<int, TH1D> H1(new TH1D("[%]", NULL, nx, xmin, xmax));
144 
145  for (counter_type counter = 0; in.hasNext(); ++counter) {
146 
147  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
148 
149  const JDAQTimeslice* timeslice = in.next();
150 
151  for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
152 
153  const JChecksum::result_type result = checksum.get(*frame);
154 
155  for (JChecksum::const_iterator error = result.begin(); error != result.end(); ++error) {
156 
157  errors[error->type] += 1;
158 
159  H1[error->type]->Fill((Double_t) frame->getFrameIndex());
160  }
161 
162  if (debug >= debug_t) {
163 
164  for (JChecksum::const_iterator error = result.begin(); error != result.end(); ++error) {
165 
166  if (error->pos >= 0) {
167 
168  const int pmt = (*frame)[error->pos].getPMT();
169 
170  cout << "Module "
171  << setw(10) << frame->getModuleID() << '.' << setw(2) << setfill('0') << pmt << setfill(' ') << ' '
172  << setw(8) << frame->getFrameIndex() << ' '
173  << setw(6) << error->pos << '/' << setw(8) << frame->size() << ' '
174  << setw(2) << error->type << ' ';
175 
176  if (pmt < NUMBER_OF_PMTS) {
177  cout << setw(1) << frame->testHighRateVeto(pmt)
178  << setw(1) << frame->testFIFOStatus (pmt) << ' ';
179  }
180 
181  cout << setw(4) << frame->getUDPNumberOfReceivedPackets() << '/'
182  << setw(4) << frame->getUDPMaximalSequenceNumber();
183 
184  cout << " ";
185 
186  print(cout, error->type);
187 
188  cout << endl << endl;
189 
190  deque<JDAQHit> buffer;
191 
192  for (int i = error->pos - 1, n = 0; i >= 0 && n <= N; --i) {
193  if ((*frame)[i].getPMT() == (*frame)[error->pos].getPMT()) {
194  buffer.push_front((*frame)[i]);
195  ++n;
196  }
197  }
198 
199  for (deque<JDAQHit>::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
200  print(cout, *i); cout << endl;
201  }
202 
203  print(cout, (*frame)[error->pos]);
204 
205  cout << " <<< " << endl;
206 
207  for (int i = error->pos + 1, n = 0; i < frame->size() && n <= N; ++i) {
208  if ((*frame)[i].getPMT() == (*frame)[error->pos].getPMT()) {
209  print(cout, (*frame)[i]); cout << endl;
210  ++n;
211  }
212  }
213 
214  } else {
215 
216  cout << "Module "
217  << setw(10) << frame->getModuleID() << ' ' << setw(2) << ' ' << ' '
218  << setw(8) << frame->getFrameIndex() << ' '
219  << setw(6) << error->pos << '/' << setw(8) << frame->size() << ' '
220  << setw(2) << error->type << ' ';
221 
222  cout << setw(1) << ' '
223  << setw(1) << ' ' << ' ';
224 
225  cout << setw(4) << frame->getUDPNumberOfReceivedPackets() << '/'
226  << setw(4) << frame->getUDPMaximalSequenceNumber();
227 
228  cout << " ";
229 
230  print(cout, error->type);
231 
232  cout << endl << endl;
233  }
234  }
235  }
236  }
237  }
238  STATUS(endl);
239 
240  for (map<int, int>::const_iterator i = errors.begin(); i != errors.end(); ++i) {
241 
242  print(cout, i->first);
243 
244  cout << ' ' << setw(8) << i->second << endl;
245  }
246 
247  H1.Write(outputFile.c_str());
248 }
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary class to select ROOT class based on class name.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Long64_t counter_type
Type definition for counter.
result_type::const_iterator const_iterator
Definition: JChecksum.hh:83
Dynamic ROOT object management.
Auxiliary class for multiplexing object iterators.
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
string outputFile
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
static const JChecksum checksum
Function object to perform check-sum of raw data.
Definition: JChecksum.hh:176
static int MAXIMAL_FRAME_SIZE
Maximal frame size.
Definition: JChecksum.hh:32
JValue_t second
Definition: JPair.hh:129
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:97
Scanning of objects from a single file according a format that follows from the extension of each fil...
const int n
Definition: JPolint.hh:676
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Hit data structure.
Definition: JDAQHit.hh:34
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
return result
Definition: JPolint.hh:743
Support methods.
Data time slice.
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
virtual const pointer_type & next() override
Get next element.
int debug
debug level
Definition: JSirene.cc:63
virtual bool hasNext() override
Check availability of next element.
print
Definition: JConvertDusj.sh:44
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
Object reading from a list of files.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42
const result_type & get(const JDAQSuperFrame &frame) const
Check sum.
Definition: JChecksum.hh:108