Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
JCompareSummaryslice.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <map>
6
7#include "TROOT.h"
8#include "TFile.h"
9#include "TH1D.h"
10#include "TH2D.h"
11
13
17#include "JSupport/JSupport.hh"
18
20
21#include "JTools/JRange.hh"
22
23#include "Jeep/JParser.hh"
24#include "Jeep/JMessage.hh"
25
26namespace {
27
29
30 static const double factor = 1.0e-3; // conversion factor [kHz]
31
32 /**
33 * Write DAQ frame status to output stream.
34 *
35 * \param out output stream
36 * \param status DAQ frame status
37 * \return output stream
38 */
39 inline std::ostream& operator<<(std::ostream& out, const KM3NETDAQ::JDAQFrameStatus& status)
40 {
41 using namespace std;
42
43 out << ' ' << setw(8) << setfill('0') << hex << status.getStatus() << dec << setfill(' ');
44 out << '|' << setw(8) << setfill('0') << hex << status.getFIFOStatus() << dec << setfill(' ');
45 out << ' ' << setw(2) << status.getUDPNumberOfReceivedPackets();
46 out << ' ' << setw(2) << status.getUDPMaximalSequenceNumber();
47
48 return out;
49 }
50
51 /**
52 * Auxiliary data structure for printing summary data.
53 */
54 struct printer {
55 /**
56 * Constructor.
57 *
58 * \param frame summary frame
59 * \param pmt PMT
60 */
61 printer(const JDAQSummaryFrame& frame, const int pmt) :
62 frame(frame),
63 pmt (pmt)
64 {}
65
66 /**
67 * Write summary data to output stream.
68 *
69 * \param out output stream
70 * \param object printer
71 * \return output stream
72 */
73 friend inline std::ostream& operator<<(std::ostream& out, const printer& object)
74 {
75 using namespace std;
76
77 return out << SCIENTIFIC(9,3) << object.frame.getRate(object.pmt, factor) << ' '
78 << object.frame.testHighRateVeto(object.pmt)
79 << object.frame.testFIFOStatus (object.pmt) << ' '
80 << setw(3) << object.frame.getUDPMaximalSequenceNumber() << '/'
81 << setw(3) << object.frame.getUDPNumberOfReceivedPackets() << ' '
82 << object.frame.hasUDPTrailer();
83 }
84
85 protected:
86 const JDAQSummaryFrame& frame;
87 const int pmt;
88 };
89}
90
91
92/**
93 * \file
94 * Auxiliary program to compare summary data.
95 *
96 * \author mdejong
97 */
98int main(int argc, char **argv)
99{
100 using namespace std;
101 using namespace JPP;
102 using namespace KM3NETDAQ;
103
104 pair<string, string> inputFile;
105 string outputFile;
106 JLimit_t numberOfEvents;
108 int debug;
109
110 try {
111
112 JParser<> zap("Auxiliary program to compare summary data.");
113
114 zap['f'] = make_field(inputFile, "pair of input files");
115 zap['o'] = make_field(outputFile, "output file") = "summary.root";
116 zap['n'] = make_field(numberOfEvents) = JLimit::max();
117 zap['R'] = make_field(rate_kHz, "accepted range [kHz]") = JRange<double>(-0.1, +0.1);
118 zap['d'] = make_field(debug, "debug") = 0;
119
120 zap(argc, argv);
121 }
122 catch(const exception &error) {
123 FATAL(error.what() << endl);
124 }
125
126 JSummaryFileRouter router(inputFile.second);
127
128 TFile out(outputFile.c_str(), "recreate");
129
130 TH1D h0("h0", NULL, 200, -2.0, +2.0);
132 TH2D h2("h2", NULL, 2, -0.5, +1.5, 2, -0.5, +1.5);
133 TH2D h3("h3", NULL, 2, -0.5, +1.5, 2, -0.5, +1.5);
134 TH2D h4("h4", NULL, 100, 0.0, 100.0, 100, 0.0, 100.0);
135 TH2D h5("h5", NULL, 100, 0.0, 100.0, 100, 0.0, 100.0);
136 TH2D h6("h6", NULL, 2, -0.5, +1.5, 2, -0.5, +1.5);
137
138 TH2D ha("ha", NULL, JDAQRate::getN(), JDAQRate::getData(factor), 200, -10.0, +10.0);
139 TH2D hb("hb", NULL, JDAQRate::getN(), JDAQRate::getData(factor), 513, -256.5, +256.5);
140
141 size_t counts = 0;
142 size_t misses = 0;
143
144 struct {
147 } module;
148
149 struct {
153 } PMT;
154
155
156 for (JSingleFileScanner<JDAQSummaryslice> in(inputFile.first, numberOfEvents); in.hasNext(); ) {
157
158 STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
159
160 const JDAQSummaryslice* const p = in.next();
161
162 router.update(*p);
163
164 counts += 1;
165
166 DEBUG("frame index: " << setw(6) << p->getFrameIndex() << ' ' << p->getTimesliceStart() << " / " << setw(6) << router.getFrameIndex() << ' ' << router.getTimesliceStart() << endl);
167
168 if (p->getFrameIndex() == router.getFrameIndex()) {
169
170 for (JDAQSummaryslice::const_iterator i = p->begin(); i != p->end(); ++i) {
171
172 const JDAQSummaryFrame& f1 = *i;
173
174 module.counts[f1.getModuleID()] += 1;
175
176 if (router.hasSummaryFrame(f1.getModuleID())) {
177
178 const JDAQSummaryFrame& f2 = router.getSummaryFrame(f1.getModuleID());
179
180 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
181
182 const JPMTIdentifier id(f1.getModuleID(), pmt);
183
184 if (debug >= debug_t || !rate_kHz(f2.getRate(pmt, factor) - f1.getRate(pmt, factor))) {
185 cout << "PMT " << id << ' ' << printer(*i,pmt) << " -> " << printer(f2,pmt) << endl;
186 }
187
188 PMT.counts[id] += 1;
189
190 if ((f2.testHighRateVeto(pmt) != f1.testHighRateVeto(pmt)) ||
191 (f2.testFIFOStatus (pmt) != f1.testFIFOStatus (pmt))) {
192 PMT.misses[id] += 1;
193 }
194
195 if (!rate_kHz(f2.getRate(pmt, factor) - f1.getRate(pmt, factor))) {
196 PMT.errors[id] += 1;
197 }
198
199 ha.Fill(f1.getRate(pmt, factor), f1.getRate(pmt, factor) - f2.getRate(pmt, factor));
200 hb.Fill(f1.getRate(pmt, factor), (int) f1.getValue(pmt) - (int) f2.getValue(pmt));
201 h0.Fill(f1.getRate (pmt, factor) - f2.getRate (pmt, factor));
202 h1.Fill(f1.getRate (pmt, factor), f2.getRate (pmt, factor));
203 h2.Fill(f1.testHighRateVeto(pmt), f2.testHighRateVeto(pmt));
204 h3.Fill(f1.testFIFOStatus (pmt), f2.testFIFOStatus (pmt));
205 }
206
209 h6.Fill(f1.hasUDPTrailer(), f2.hasUDPTrailer());
210
211 } else {
212
213 module.misses[f1.getModuleID()] += 1;
214 }
215 }
216 } else {
217
218 misses += 1;
219 }
220 }
221 STATUS(endl);
222
223 cout << "Number of slice misses "<< setw(6) << misses << '/' << setw(6) << counts << endl;
224
225 for (const auto& i : module.misses) {
226 cout << "Number of module misses " << setw(8) << i.first << ' ' << setw(6) << i.second << '/' << setw(6) << module.counts[i.first] << endl;
227 }
228
229 for (const auto& i : PMT.misses) {
230 cout << "Number of PMT misses " << i.first << ' ' << setw(6) << i.second << '/' << setw(6) << PMT.counts[i.first] << endl;
231 }
232
233 for (const auto& i : PMT.errors) {
234 cout << "Number of PMT errors " << i.first << ' ' << setw(6) << i.second << '/' << setw(6) << PMT.counts[i.first] << endl;
235 }
236
237 out.Write();
238 out.Close();
239}
int main(int argc, char **argv)
JDAQPMTIdentifier PMT
Command line options.
string outputFile
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
Auxiliary class to define a range between two values.
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.
Template definition of a multi-dimensional oscillation probability interpolation table.
File router for fast addressing of summary data.
void update(const JDAQHeader &header)
Update router.
bool hasSummaryFrame(const JDAQModuleIdentifier &module) const
Has summary frame.
const JDAQSummaryFrame & getSummaryFrame(const JDAQModuleIdentifier &module) const
Get summary frame.
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
int getFrameIndex() const
Get frame index.
bool testFIFOStatus() const
Test FIFO status.
int getUDPNumberOfReceivedPackets() const
Get number of received UDP packets.
int getFIFOStatus() const
Get FIFO status.
int getStatus() const
Get TDC and White Rabbit status.
bool hasUDPTrailer() const
Get UDP trailer status.
bool testHighRateVeto() const
Test high-rate veto status.
int getUDPMaximalSequenceNumber() const
Get maximal sequence number of UDP packet.
int getModuleID() const
Get module identifier.
static int getN()
Get number of bins.
static const double * getData(const double factor=1.0)
Get abscissa values.
Data storage class for rate measurements of all PMTs in one module.
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
JRate_t getValue(const int tdc) const
Get value.
std::ostream & operator<<(std::ostream &out, const morphology_type &object)
Write morphology to output stream.
@ debug_t
debug
Definition JMessage.hh:29
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition JDAQ.hh:26
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 floating point format specification.
Definition JManip.hh:488