Jpp 19.3.0-rc.3
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
23#include "JTrigger/JChecksum.hh"
24
25#include "Jeep/JParser.hh"
26#include "Jeep/JMessage.hh"
27
28namespace {
29
30 /**
31 * Print DAQ hit.
32 *
33 * \param out output stream
34 * \param hit DAQ hit
35 */
36 inline 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 inline void print(std::ostream& out, const int type)
54 {
55 using namespace std;
56 using namespace JPP;
57
58 switch (type) {
59
61 out << "time ";
62 break;
63
65 out << "TDC ";
66 break;
67
69 out << "PMT ";
70 break;
71
73 out << "UDP ";
74 break;
75
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 check KM3NETDAQ::JDAQTimeslice for errors.
92 * \author mdejong
93 */
94int 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 check timeslice data for errors.");
111
112 zap['f'] = make_field(inputFile);
113 zap['n'] = make_field(numberOfEvents) = JLimit::max();
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
128
129
130 if (rate_Hz > 0.0) {
131 MAXIMAL_FRAME_SIZE = (int) (getFrameTime() * 1.0e-9 * rate_Hz * NUMBER_OF_PMTS + 0.5);
132 }
133
134 map<int, int> errors;
135
137
138 const Long64_t nx = frame_index.second - frame_index.first + 1;
139 const Double_t xmin = (Double_t) frame_index.first - 0.5;
140 const Double_t xmax = (Double_t) frame_index.second + 0.5;
141
142 JManager<int, TH1D> H1(new TH1D("[%]", NULL, nx, xmin, xmax));
143
144 for (counter_type counter = 0; in.hasNext(); ++counter) {
145
146 STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
147
148 const JDAQTimeslice* timeslice = in.next();
149
150 for (JDAQTimeslice::const_iterator frame = timeslice->begin(); frame != timeslice->end(); ++frame) {
151
152 const JChecksum::result_type& result = checksum(*frame);
153
154 for (JChecksum::const_iterator error = result.begin(); error != result.end(); ++error) {
155
156 errors[error->type] += 1;
157
158 H1[error->type]->Fill((Double_t) frame->getFrameIndex());
159 }
160
161 if (debug >= debug_t) {
162
163 for (JChecksum::const_iterator error = result.begin(); error != result.end(); ++error) {
164
165 if (error->pos >= 0) {
166
167 const int pmt = (*frame)[error->pos].getPMT();
168
169 cout << "Module "
170 << setw(10) << frame->getModuleID() << '.' << setw(2) << setfill('0') << pmt << setfill(' ') << ' '
171 << setw(8) << frame->getFrameIndex() << ' '
172 << setw(6) << error->pos << '/' << setw(8) << frame->size() << ' '
173 << setw(2) << error->type << ' ';
174
175 if (pmt < NUMBER_OF_PMTS) {
176 cout << setw(1) << frame->testHighRateVeto(pmt)
177 << setw(1) << frame->testFIFOStatus (pmt) << ' ';
178 }
179
180 cout << setw(4) << frame->getUDPNumberOfReceivedPackets() << '/'
181 << setw(4) << frame->getUDPMaximalSequenceNumber();
182
183 cout << " ";
184
185 print(cout, error->type);
186
187 cout << endl << endl;
188
189 deque<JDAQHit> buffer;
190
191 for (int i = error->pos - 1, n = 0; i >= 0 && n <= N; --i) {
192 if ((*frame)[i].getPMT() == (*frame)[error->pos].getPMT()) {
193 buffer.push_front((*frame)[i]);
194 ++n;
195 }
196 }
197
198 for (deque<JDAQHit>::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
199 print(cout, *i); cout << endl;
200 }
201
202 print(cout, (*frame)[error->pos]);
203
204 cout << " <<< " << endl;
205
206 for (int i = error->pos + 1, n = 0; i < frame->size() && n <= N; ++i) {
207 if ((*frame)[i].getPMT() == (*frame)[error->pos].getPMT()) {
208 print(cout, (*frame)[i]); cout << endl;
209 ++n;
210 }
211 }
212
213 } else {
214
215 cout << "Module "
216 << setw(10) << frame->getModuleID() << ' ' << setw(2) << ' ' << ' '
217 << setw(8) << frame->getFrameIndex() << ' '
218 << setw(6) << error->pos << '/' << setw(8) << frame->size() << ' '
219 << setw(2) << error->type << ' ';
220
221 cout << setw(1) << ' '
222 << setw(1) << ' ' << ' ';
223
224 cout << setw(4) << frame->getUDPNumberOfReceivedPackets() << '/'
225 << setw(4) << frame->getUDPMaximalSequenceNumber();
226
227 cout << " ";
228
229 print(cout, error->type);
230
231 cout << endl << endl;
232 }
233 }
234 }
235 }
236 }
237 STATUS(endl);
238
239 for (map<int, int>::const_iterator i = errors.begin(); i != errors.end(); ++i) {
240
241 print(cout, i->first);
242
243 cout << ' ' << setw(8) << i->second << endl;
244 }
245
246 H1.Write(outputFile.c_str());
247}
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, const char delimiter=' ', const bool useColors=true)
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