Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
software/JTrigger/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
17#include "JSupport/JSupport.hh"
18
20#include "JROOT/JManager.hh"
21
22#include "JLang/JPredicate.hh"
23#include "JLang/JComparison.hh"
25#include "JTrigger/JChecksum.hh"
26
27#include "Jeep/JParser.hh"
28#include "Jeep/JMessage.hh"
29
30namespace {
31
32 /**
33 * Print DAQ hit.
34 *
35 * \param out output stream
36 * \param hit DAQ hit
37 */
38 inline void print(std::ostream& out, const KM3NETDAQ::JDAQHit& hit)
39 {
40 using namespace std;
41
42 out << "\thit: "
43 << setw(2) << hex << (int) hit.getPMT() << ' '
44 << setw(3) << dec << (int) hit.getPMT() << ' '
45 << setw(8) << hex << hit.getT() << ' '
46 << setw(10) << dec << hit.getT() << ' '
47 << setw(2) << hex << (int) hit.getToT() << ' '
48 << setw(3) << dec << (int) hit.getToT();
49 }
50
51 /**
52 * Print error type.
53 *
54 * \param out output stream
55 * \param type error type
56 */
57 inline void print(std::ostream& out, const int type)
58 {
59 using namespace std;
60 using namespace JPP;
61
62 switch (type) {
63
65 out << "time ";
66 break;
67
69 out << "TDC ";
70 break;
71
73 out << "PMT ";
74 break;
75
77 out << "UDP ";
78 break;
79
81 out << "size ";
82 break;
83
84 default:
85 out << "? ";
86 break;
87 }
88 }
89}
90
91
92/**
93 * \file
94 *
95 * Example program to check KM3NETDAQ::JDAQTimeslice for errors.
96 * \author mdejong
97 */
98int main(int argc, char **argv)
99{
100 using namespace std;
101 using namespace JPP;
102 using namespace KM3NETDAQ;
103
105 JLimit_t & numberOfEvents = inputFile.getLimit();
106 JROOTClassSelector selector;
107 string outputFile;
108 int N;
109 double rate_Hz;
110 int debug;
111
112 try {
113
114 JParser<> zap("Example program to check timeslice data for errors.");
115
116 zap['f'] = make_field(inputFile);
117 zap['n'] = make_field(numberOfEvents) = JLimit::max();
119 zap['o'] = make_field(outputFile) = "checksum.root";
120 zap['N'] = make_field(N, "number of rows to print") = 10;
121 zap['R'] = make_field(rate_Hz, "high-rate veto [Hz]") = 0.0;
122 zap['d'] = make_field(debug) = 3;
123
124 zap(argc, argv);
125 }
126 catch(const exception& error) {
127 FATAL(error.what() << endl);
128 }
129
130
132
133
134 if (rate_Hz > 0.0) {
135 MAXIMAL_FRAME_SIZE = (int) (getFrameTime() * 1.0e-9 * rate_Hz * NUMBER_OF_PMTS + 0.5);
136 }
137
138 map<int, int> errors;
139 map<int, int> misses;
140
142
143 const Long64_t nx = frame_index.second - frame_index.first + 1;
144 const Double_t xmin = (Double_t) frame_index.first - 0.5;
145 const Double_t xmax = (Double_t) frame_index.second + 0.5;
146
147 JManager<int, TH1D> H1(new TH1D("[%]", NULL, nx, xmin, xmax));
148
149 for (counter_type counter = 0; in.hasNext(); ++counter) {
150
151 STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
152
153 const JDAQTimeslice* timeslice = in.next();
154
155 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
156
157 const JChecksum::result_type& result = checksum(*frame);
158
160
161 if (count_if(result.begin(), result.end(), make_predicate(&JChecksum::error::type, type)) != 0) {
162 misses[frame->getModuleID()] += 1;
163 }
164 }
165
166 for (JChecksum::const_iterator error = result.begin(); error != result.end(); ++error) {
167
168 errors[error->type] += 1;
169
170 H1[error->type]->Fill((Double_t) frame->getFrameIndex());
171 }
172
173 if (debug >= debug_t) {
174
175 for (JChecksum::const_iterator error = result.begin(); error != result.end(); ++error) {
176
177 if (error->pos >= 0) {
178
179 const int pmt = (*frame)[error->pos].getPMT();
180
181 cout << "Module "
182 << setw(10) << frame->getModuleID() << '.' << setw(2) << setfill('0') << pmt << setfill(' ') << ' '
183 << setw(8) << frame->getFrameIndex() << ' '
184 << setw(6) << error->pos << '/' << setw(8) << frame->size() << ' '
185 << setw(2) << error->type << ' ';
186
187 if (pmt < NUMBER_OF_PMTS) {
188 cout << setw(1) << frame->testHighRateVeto(pmt)
189 << setw(1) << frame->testFIFOStatus (pmt) << ' ';
190 }
191
192 cout << setw(4) << frame->getUDPNumberOfReceivedPackets() << '/'
193 << setw(4) << frame->getUDPMaximalSequenceNumber();
194
195 cout << " ";
196
197 print(cout, error->type);
198
199 cout << endl << endl;
200
201 deque<JDAQHit> buffer;
202
203 for (int i = error->pos - 1, n = 0; i >= 0 && n <= N; --i) {
204 if ((*frame)[i].getPMT() == (*frame)[error->pos].getPMT()) {
205 buffer.push_front((*frame)[i]);
206 ++n;
207 }
208 }
209
210 for (deque<JDAQHit>::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
211 print(cout, *i); cout << endl;
212 }
213
214 print(cout, (*frame)[error->pos]);
215
216 cout << " <<< " << endl;
217
218 for (int i = error->pos + 1, n = 0; i < frame->size() && n <= N; ++i) {
219 if ((*frame)[i].getPMT() == (*frame)[error->pos].getPMT()) {
220 print(cout, (*frame)[i]); cout << endl;
221 ++n;
222 }
223 }
224
225 } else {
226
227 cout << "Module "
228 << setw(10) << frame->getModuleID() << ' ' << setw(2) << ' ' << ' '
229 << setw(8) << frame->getFrameIndex() << ' '
230 << setw(6) << error->pos << '/' << setw(8) << frame->size() << ' '
231 << setw(2) << error->type << ' ';
232
233 cout << setw(1) << ' '
234 << setw(1) << ' ' << ' ';
235
236 cout << setw(4) << frame->getUDPNumberOfReceivedPackets() << '/'
237 << setw(4) << frame->getUDPMaximalSequenceNumber();
238
239 cout << " ";
240
241 print(cout, error->type);
242
243 cout << endl << endl;
244 }
245 }
246 }
247 }
248 }
249 STATUS(endl);
250
251 for (map<int, int>::const_iterator i = errors.begin(); i != errors.end(); ++i) {
252
253 print(cout, i->first);
254
255 cout << ' ' << setw(8) << i->second << endl;
256 }
257
258 int ns = 0;
259
260 for (map<int, int>::const_iterator i = misses.begin(); i != misses.end(); ++i) {
261
262 cout << "misses " << setw(10) << i->first << ' ' << setw(8) << i->second << endl;
263
264 ns += i->second;
265 }
266 {
267 cout << "misses " << setw(10) << "total" << ' ' << setw(8) << ns << endl;
268 }
269
270 H1.Write(outputFile.c_str());
271}
string outputFile
Dynamic ROOT object management.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Scanning of objects from a single file according a format that follows from the extension of each fil...
Support methods.
ROOT TTree parameter settings of various packages.
Auxiliary class for multiplexing object iterators.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition JManager.hh:47
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition JManager.hh:304
Object reading from a list of files.
JKey_t first
Definition JPair.hh:128
JValue_t second
Definition JPair.hh:129
Hit data structure.
Definition JDAQHit.hh:35
JPMT_t getPMT() const
Get PMT.
Definition JDAQHit.hh:75
JTDC_t getT() const
Get time.
Definition JDAQHit.hh:86
JTOT_t getToT() const
Get time-over-threshold.
Definition JDAQHit.hh:97
std::ostream & print(std::ostream &out, const JTestSummary &summary, T __begin, T __end, const bool useColors=true, const JFormat_t &formatting=JFormat_t(18, 3, std::ios::fixed))
Print test summary.
@ debug_t
debug
Definition JMessage.hh:29
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::set< JROOTClassSelector > getROOTClassSelection(const bool option=false)
Get ROOT class selection.
Long64_t counter_type
Type definition for counter.
JFrameIndexRange getFrameIndexRange(JTreeScannerInterface< T, KM3NETDAQ::JDAQEvaluator > &in)
Get range of frame indices.
return result
Definition JPolint.hh:862
const int n
Definition JPolint.hh:791
static const JChecksum checksum
Function object to perform check-sum of raw data.
Definition JChecksum.hh:200
static int MAXIMAL_FRAME_SIZE
Maximal frame size.
Definition JChecksum.hh:35
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
int main(int argc, char **argv)
Auxiliary class to select ROOT class based on class name.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
Auxiliary data structure for result of checksum.
Definition JChecksum.hh:90
@ ETDC_t
TDC value error.
Definition JChecksum.hh:47
@ SIZE_t
size error
Definition JChecksum.hh:50
@ EUDP_t
UDP packet error.
Definition JChecksum.hh:49
@ EPMT_t
PMT number error.
Definition JChecksum.hh:46
@ TIME_t
Time order error.
Definition JChecksum.hh:48
result_type::const_iterator const_iterator
Definition JChecksum.hh:119