source: trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc@ 12669

Last change on this file since 12669 was 12669, checked in by lyard, 13 years ago
viewer improvements
File size: 82.7 KB
Line 
1/*
2 * QtGl.cpp
3 *
4 * Created on: Jul 19, 2011
5 * Author: lyard
6 */
7//FIXME replace with FACT++ Time class
8#include <boost/date_time/local_time/local_time.hpp>
9
10
11#include "RawEventsViewer.h"
12#include "viewer.h"
13#include <math.h>
14#include <fstream>
15
16#ifdef LOAD_RAW
17int16_t eventsData[NUM_STORED_EVENTS][ACTUAL_NUM_PIXELS][1024];
18#include </home/lyard/Code/display.C>
19#endif
20
21#define VALUES_SPAN 4096
22
23#include <QFileDialog>
24
25#include <qwt_symbol.h>
26
27#include "src/Configuration.h"
28#include "externals/fits.h"
29
30
31using namespace std;
32
33#undef ACTUAL_NUM_PIXELS
34#define ACTUAL_NUM_PIXELS 1440
35
36//bounding box for diplaying the impulse curve
37float bboxMin[2] = {-0.8,-0.9};
38float bboxMax[2] = {0.8,-0.3};
39/************************************************************
40 * CALC BLUR COLOR if in blur display mode, calculate the interpolated
41 * colour for a given vertex
42 ************************************************************/
43void RawDataViewer::calcBlurColor(int pixel, int vertex)
44{
45 GLfloat color[3];
46 int first, second;
47 first = vertex-1;
48 second = vertex;
49 if (first < 0)
50 first = 5;
51 // if (second > 5)
52 // second = 0;
53 first = neighbors[pixel][first];
54 second = neighbors[pixel][second];
55 for (int i=0;i<3;i++)
56 color[i] = pixelsColor[pixel][i];
57 float divide = 1;
58 if (first != -1)
59 {
60 divide++;
61 for (int i=0;i<3;i++)
62 color[i] += pixelsColor[first][i];
63 }
64 if (second != -1)
65 {
66 divide++;
67 for (int i=0;i<3;i++)
68 color[i] += pixelsColor[second][i];
69 }
70 for (int i=0;i<3;i++)
71 color[i] /= divide;
72 glColor3fv(color);
73}
74void RawDataViewer::calcMidBlurColor(int pixel, int vertex)
75{
76 GLfloat color[3];
77 int first, second;
78 first = vertex-1;
79 if (first < 0)
80 first = 5;
81 first = neighbors[pixel][first];
82 for (int i=0;i<3;i++)
83 color[i] = pixelsColor[pixel][i];
84 float divide = 1;
85 if (first != -1)
86 {
87 divide++;
88 for (int i=0;i<3;i++)
89 color[i] += pixelsColor[first][i];
90 }
91 for (int i=0;i<3;i++)
92 color[i] /= divide;
93 glColor3fv(color);
94}
95/************************************************************
96 * DRAW BLURRY HEXAGON. draws a solid hexagon, with interpolated colours
97 ************************************************************/
98void RawDataViewer::drawBlurryHexagon(int index)
99{
100//alternative mesh
101/* GLfloat color1[3];
102 GLfloat color2[3];
103 GLfloat color3[3];
104 for (int i=0;i<3;i++)
105 color1[i] = pixelsColor[index][i];
106 glBegin(GL_TRIANGLES);
107 for (int i=0;i<6;i++)
108 {
109 int first = i;
110 int second = i+1;
111 if (second == 6) second = 0;
112 first = neighbors[index][first];
113 second = neighbors[index][second];
114 if (first == -1 || second == -1) continue;
115 for (int j=0;j<3;j++)
116 {
117 color2[j] = pixelsColor[first][j];
118 color3[j] = pixelsColor[second][j];
119 }
120 glColor3fv(color2);
121 glVertex2fv(pixelsCoords[first]);
122 glColor3fv(color1);
123 glVertex2fv(pixelsCoords[index]);
124 glColor3fv(color3);
125 glVertex2fv(pixelsCoords[second]);
126 }
127 glEnd();
128 return;*/
129//per-pixel mesh
130 GLfloat color[3];
131 for (int i=0;i<3;i++)
132 color[i] = pixelsColor[index][i];
133 glBegin(GL_TRIANGLES);
134 calcBlurColor(index, 0);
135 glVertex2fv(verticesList[verticesIndices[index][0]]);
136 glColor3fv(color);
137 glVertex2fv(pixelsCoords[index]);
138/*
139 calcMidBlurColor(index, 1);
140 glVertex2f((verticesList[verticesIndices[index][0]][0] + verticesList[verticesIndices[index][1]][0])/2.f,
141 (verticesList[verticesIndices[index][0]][1] + verticesList[verticesIndices[index][1]][1])/2.f);
142 glVertex2f((verticesList[verticesIndices[index][0]][0] + verticesList[verticesIndices[index][1]][0])/2.f,
143 (verticesList[verticesIndices[index][0]][1] + verticesList[verticesIndices[index][1]][1])/2.f);
144 glColor3fv(color);
145 glVertex2fv(pixelsCoords[index]);
146*/
147 calcBlurColor(index, 1);
148 glVertex2fv(verticesList[verticesIndices[index][1]]);
149
150 glVertex2fv(verticesList[verticesIndices[index][1]]);
151 glColor3fv(color);
152 glVertex2fv(pixelsCoords[index]);
153/*
154 calcMidBlurColor(index, 2);
155 glVertex2f((verticesList[verticesIndices[index][1]][0] + verticesList[verticesIndices[index][2]][0])/2.f,
156 (verticesList[verticesIndices[index][1]][1] + verticesList[verticesIndices[index][2]][1])/2.f);
157 glVertex2f((verticesList[verticesIndices[index][1]][0] + verticesList[verticesIndices[index][2]][0])/2.f,
158 (verticesList[verticesIndices[index][1]][1] + verticesList[verticesIndices[index][2]][1])/2.f);
159 glColor3fv(color);
160 glVertex2fv(pixelsCoords[index]);
161*/
162 calcBlurColor(index, 2);
163 glVertex2fv(verticesList[verticesIndices[index][2]]);
164
165 glVertex2fv(verticesList[verticesIndices[index][2]]);
166 glColor3fv(color);
167 glVertex2fv(pixelsCoords[index]);
168/*
169 calcMidBlurColor(index, 3);
170 glVertex2f((verticesList[verticesIndices[index][2]][0] + verticesList[verticesIndices[index][3]][0])/2.f,
171 (verticesList[verticesIndices[index][2]][1] + verticesList[verticesIndices[index][3]][1])/2.f);
172 glVertex2f((verticesList[verticesIndices[index][2]][0] + verticesList[verticesIndices[index][3]][0])/2.f,
173 (verticesList[verticesIndices[index][2]][1] + verticesList[verticesIndices[index][3]][1])/2.f);
174 glColor3fv(color);
175 glVertex2fv(pixelsCoords[index]);
176*/
177 calcBlurColor(index, 3);
178 glVertex2fv(verticesList[verticesIndices[index][3]]);
179
180 glVertex2fv(verticesList[verticesIndices[index][3]]);
181 glColor3fv(color);
182 glVertex2fv(pixelsCoords[index]);
183/*
184 calcMidBlurColor(index, 4);
185 glVertex2f((verticesList[verticesIndices[index][3]][0] + verticesList[verticesIndices[index][4]][0])/2.f,
186 (verticesList[verticesIndices[index][3]][1] + verticesList[verticesIndices[index][4]][1])/2.f);
187 glVertex2f((verticesList[verticesIndices[index][3]][0] + verticesList[verticesIndices[index][4]][0])/2.f,
188 (verticesList[verticesIndices[index][3]][1] + verticesList[verticesIndices[index][4]][1])/2.f);
189 glColor3fv(color);
190 glVertex2fv(pixelsCoords[index]);
191*/
192 calcBlurColor(index, 4);
193 glVertex2fv(verticesList[verticesIndices[index][4]]);
194
195 glVertex2fv(verticesList[verticesIndices[index][4]]);
196 glColor3fv(color);
197 glVertex2fv(pixelsCoords[index]);
198/*
199 calcMidBlurColor(index, 5);
200 glVertex2f((verticesList[verticesIndices[index][4]][0] + verticesList[verticesIndices[index][5]][0])/2.f,
201 (verticesList[verticesIndices[index][4]][1] + verticesList[verticesIndices[index][5]][1])/2.f);
202 glVertex2f((verticesList[verticesIndices[index][4]][0] + verticesList[verticesIndices[index][5]][0])/2.f,
203 (verticesList[verticesIndices[index][4]][1] + verticesList[verticesIndices[index][5]][1])/2.f);
204 glColor3fv(color);
205 glVertex2fv(pixelsCoords[index]);
206*/
207 calcBlurColor(index, 5);
208 glVertex2fv(verticesList[verticesIndices[index][5]]);
209
210 glVertex2fv(verticesList[verticesIndices[index][5]]);
211 glColor3fv(color);
212 glVertex2fv(pixelsCoords[index]);
213/*
214 calcMidBlurColor(index, 0);
215 glVertex2f((verticesList[verticesIndices[index][5]][0] + verticesList[verticesIndices[index][0]][0])/2.f,
216 (verticesList[verticesIndices[index][5]][1] + verticesList[verticesIndices[index][0]][1])/2.f);
217 glVertex2f((verticesList[verticesIndices[index][5]][0] + verticesList[verticesIndices[index][0]][0])/2.f,
218 (verticesList[verticesIndices[index][5]][1] + verticesList[verticesIndices[index][0]][1])/2.f);
219 glColor3fv(color);
220 glVertex2fv(pixelsCoords[index]);
221*/
222 calcBlurColor(index, 0);
223 glVertex2fv(verticesList[verticesIndices[index][0]]);
224 glEnd();
225
226 return;
227}
228
229/************************************************************
230 * DRAW CAMERA draws all the camera pixels
231 ************************************************************/
232void RawDataViewer::drawCamera(bool alsoWire)
233{
234 glLoadIdentity();
235 if (!drawImpulse)
236 {
237 glTranslatef(0,-0.44,0);
238 glRotatef(cameraRotation, 0,0,-1);
239 if (cameraRotation == 90)
240 {
241 glTranslatef(-0.45,-0.45,0);
242 // cout << "correction" << endl;
243 }
244 if (cameraRotation == -90)
245 {
246 glTranslatef(0.45,-0.45,0);
247 }
248 glScalef(1.5,1.5,1);
249 }
250 else
251 {
252 glRotatef(cameraRotation, 0,0,-1);
253 if (cameraRotation == 90)
254 {
255 glTranslatef(-0.45/1.5,-0.45/1.5,0);
256 // cout << "correction" << endl;
257 }
258 if (cameraRotation == -90)
259 {
260 glTranslatef(0.45/1.5,-0.45/1.5,0);
261 }
262 }
263 glColor3f(0.5,0.5,0.5);
264 glLineWidth(1.0);
265 float color;
266//cout << "Actual num pixels: " << ACTUAL_NUM_PIXELS << endl;
267 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
268 {
269 if (!nRoi)
270 color = (float)(i)/(float)(ACTUAL_NUM_PIXELS);
271 else
272#ifdef LOAD_RAW
273 color = float(eventsData[eventNum][i][whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
274#else
275 color = float(eventData[nRoi*hardwareMapping[i] + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
276 if (logScale)
277 {
278 color *= 9;
279 color += 1;
280 color = log10(color);
281 }
282#endif
283 if (color < ss[0])
284 {
285 pixelsColor[i][0] = tooLowValueCoulour[0];
286 pixelsColor[i][1] = tooLowValueCoulour[1];
287 pixelsColor[i][2] = tooLowValueCoulour[2];
288 continue;
289 }
290 if (color > ss[4])
291 {
292 pixelsColor[i][0] = tooHighValueCoulour[0];
293 pixelsColor[i][1] = tooHighValueCoulour[1];
294 pixelsColor[i][2] = tooHighValueCoulour[2];
295 continue;
296 }
297 int index = 0;
298 while (ss[index] < color && index < 4)
299 index++;
300 index--;
301 if (index < 0) index = 0;
302 float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
303 if (weight0 > 1.0f) weight0 = 1.0f;
304 if (weight0 < 0.0f) weight0 = 0.0f;
305 float weight1 = 1.0f-weight0;
306 pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
307 pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
308 pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
309 }
310
311 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
312 {
313// if (i == 690 ||
314// i == 70)
315// continue;
316 glColor3fv(pixelsColor[i]);
317 glLoadName(i);
318if (drawBlur)
319 drawBlurryHexagon(i);
320else
321 drawHexagon(i,true);
322
323 }
324 if (!alsoWire)
325 return;
326 glTranslatef(0,0,0.1f);
327 glColor3f(0.0f,0.0f,0.0f);
328 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
329 {
330// if (i == 690 ||
331// i == 70)
332// continue;
333 drawHexagon(i, false);
334 }
335
336}
337
338/************************************************************
339 * TRIM. FIXME this should not be here but taken from an existing class (somewhere)
340 ***********************************************************
341string Trim(const string &str)
342{
343 // Trim Both leading and trailing spaces
344 const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces
345 const size_t end = str.find_last_not_of(' '); // Find the first character position from reverse af
346
347 // if all spaces or empty return an empty string
348 if (string::npos==start || string::npos==end)
349 return string();
350
351 return str.substr(start, end-start+1);
352}*/
353/************************************************************
354 * DRAW PIXEL CURVE. draws the raw impulse curve of the currently selected pixel
355 ************************************************************/
356void RawDataViewer::drawPixelCurve()
357{
358 float xZoom, yZoom;
359 xZoom = yZoom = 1.0f;
360 float xRange = bboxMax[0] - bboxMin[0];
361 float yRange = bboxMax[1] - bboxMin[1];
362
363 glBegin(GL_LINES);
364 glLineWidth(1.0f);
365 glColor3f(0.0,0.0,0.0);
366 glVertex2f(bboxMin[0], bboxMin[1]);
367 glVertex2f(bboxMax[0], bboxMin[1]);
368 glVertex2f(bboxMin[0], bboxMin[1]);
369 glVertex2f(bboxMin[0], bboxMax[1]);
370 glVertex2f(bboxMin[0], (bboxMin[1]+bboxMax[1])/2.0f);
371 glVertex2f(bboxMax[0], (bboxMin[1]+bboxMax[1])/2.0f);
372 glVertex2f(bboxMin[0] + xRange*nRoi/(float)(nRoi+nRoiTM),
373 bboxMin[1]);
374 glVertex2f(bboxMin[0] + xRange*nRoi/(float)(nRoi+nRoiTM),
375 bboxMax[1]);
376 glEnd();
377 glTranslatef(0,0,0.1f);
378 if (!nRoi)
379 return;
380 glBegin(GL_LINES);
381 glColor3f(1.0f,1.0f,0.0f);
382 float divideMe = (float)(VALUES_SPAN-1);
383 float plusMe = VALUES_SPAN/2;
384
385 /*
386 if (drawCalibrationLoaded)
387 plusMe += 0;//VALUES_SPAN/2;
388 if (drawCalibrationLoaded && calibrationLoaded)
389 {
390 divideMe /=2;
391 plusMe = 0 ;///=2;
392 }*/
393
394 const int hw = hardwareMapping[selectedPixel];
395 const PixelMapEntry& mapEntry = fPixelMap.index(selectedPixel);
396 const int pixelIdInPatch = mapEntry.pixel();
397 const int patchId = mapEntry.patch();
398 const int boardId = mapEntry.board();
399 const int crateId = mapEntry.crate();
400
401 if (selectedPixel != -1)
402 {
403 for (int i=0;i<nRoi-1;i++)
404 {
405 float d1 = eventData[nRoi*hw + i]+plusMe;
406 float d2 = eventData[nRoi*hw + i+1]+plusMe;
407 if (!finite(d1)) d1 = 20000;
408 if (!finite(d2)) d2 = 20000;
409 glVertex2f(bboxMin[0] + xRange*i/(float)(nRoi+nRoiTM),
410 bboxMin[1] + yRange*(d1) /divideMe);
411 glVertex2f(bboxMin[0] + xRange*(i+1)/(float)(nRoi+nRoiTM),
412 bboxMin[1] + yRange*(d2) /divideMe);
413 }
414 glEnd();
415
416 glColor3f(0.0f, 1.0f, 1.0f);
417 glBegin(GL_LINES);
418 if (pixelIdInPatch == 8)//this channel has a time marker
419 {
420//link between pixel slices and TM slices. should I draw it ?
421// float d1 = eventData[nRoi*hw + nRoi-1]+plusMe;
422// float d2 = eventData[nRoi*1440 + nRoiTM*(40*crateId + 4*boardId + patchId)] + plusMe;
423// glVertex2f(bboxMin[0] + xRange*(nRoi-1)/(float)(nRoi+nRoiTM),
424// bboxMin[1] + yRange*(d1) /divideMe);
425// glVertex2f(bboxMin[0] + xRange*(nRoi)/(float)(nRoi+nRoiTM),
426// bboxMin[1] + yRange*(d2)/divideMe);
427 for (int i=0;i<nRoiTM-1;i++)
428 {
429 float d1 = eventData[nRoi*1440 + nRoiTM*(40*crateId + 4*boardId + patchId) + i] + plusMe;
430 float d2 = eventData[nRoi*1440 + nRoiTM*(40*crateId + 4*boardId + patchId) + i+1] + plusMe;
431 if (!finite(d1)) d1 = 20000;
432 if (!finite(d2)) d2 = 20000;
433 glVertex2f(bboxMin[0] + xRange*(i+nRoi)/(float)(nRoi+nRoiTM),
434 bboxMin[1] + yRange*(d1)/divideMe);
435 glVertex2f(bboxMin[0] + xRange*(i+1+nRoi)/(float)(nRoi+nRoiTM),
436 bboxMin[1] + yRange*(d2) / divideMe);
437 }
438 }
439
440 }
441 glEnd();
442 glTranslatef(0,0,0.1f);
443 glBegin(GL_LINES);
444 glColor3f(1.0,0.0,0.0);
445 glVertex2f(bboxMin[0] + xRange*whichSlice/(float)(nRoi+nRoiTM),
446 bboxMin[1]);
447 glVertex2f(bboxMin[0] + xRange*whichSlice/(float)(nRoi+nRoiTM),
448 bboxMax[1]);
449
450/* glColor3f(0.f,0.5f,0.f);
451 for (int i=0;i<nRoi-1;i++)
452 {
453 glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
454 bboxMin[1] + yRange*(n1mean[ i]+plusMe) /divideMe);
455 glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
456 bboxMin[1] + yRange*(n1mean[i+1]+plusMe) /divideMe);
457 }
458*/
459 glEnd();
460 // glEnable(GL_MULTISAMPLE);
461 /* setFont(QFont("Times", 12));
462 qglColor(QColor(255,223,127));
463 float xShift = 0.10f;
464 float yShift = 0.01f;
465 renderText(bboxMin[0]-xShift/2.0f, bboxMax[1]+3*yShift, 0, QString("Volts"));
466 if (drawCalibrationLoaded)
467 {
468 renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+2.10"));
469 renderText(bboxMin[0]-xShift, ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+1.05"));//((bboxMin[1]+bboxMax[1])/2.0f)
470 renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("0.00"));
471 }
472 else
473 {
474 renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+1.05"));
475 renderText(bboxMin[0]-xShift, ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+0.00"));//((bboxMin[1]+bboxMax[1])/2.0f)
476 renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("-1.05"));
477 }
478 renderText(bboxMax[0]+xShift/2.0f, bboxMin[1]-4*yShift, 0, QString("Slices"));
479 renderText(bboxMin[0]-yShift/2.0f, bboxMin[1]-4*yShift, 0, QString("0"));
480 ostringstream str;
481 str << nRoi/2;
482 renderText(((bboxMin[0]+bboxMax[0])/2.0f)-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
483 str.str("");
484 str << nRoi;
485 renderText(bboxMax[0]-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
486*/
487}
488/************************************************************
489 * CONSTRUCTOR.
490 ************************************************************/
491RawDataViewer::RawDataViewer(QWidget *cParent) : BasicGlCamera(cParent), RMSvalues(1440)
492{
493 // setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));
494 whichSlice = 0;
495#ifdef LOAD_RAW
496 nRoi = 1024;
497#else
498 nRoi = 0;
499#endif
500 nRoiTM = 0;
501 offSetRoi = 0;
502 eventNum = 0;
503 rowNum = -1;
504 eventStep = 1;
505 selectedPixel = 393;
506 inputFile = NULL;
507 eventData = NULL;
508 drawPatch = false;
509 drawImpulse = true;
510 drawBlur = false;
511 loopCurrentEvent = false;
512 fIsDrsCalibration = false;
513 SetAutoRefresh(true);
514#ifdef LOAD_RAW
515 loadEvents("/scratch/00000043.001_T.bin");
516#endif
517 PixelMap mypMap;
518 if (!mypMap.Read("FACTmap111030.txt"))
519 {
520 cerr << "ERROR - Problems reading FACTmap111030.txt" << endl;
521 exit(-1);
522 }
523
524 assignPixelMap(mypMap);
525
526 for (int i=0;i<160;i++)
527 {
528 const float color[3] = { 0.5, 0.5, 0.3 };
529
530 for (int j=0;j<3;j++)
531 patchesColor[i][j] = color[j];
532 }
533
534 //calibrationLoaded = false;
535 //drawCalibrationLoaded = false;
536
537}
538/************************************************************
539 * DESTRUCTOR
540 ************************************************************/
541RawDataViewer::~RawDataViewer()
542{
543 if (inputFile != NULL)
544 {
545 inputFile->close();
546 delete inputFile;
547 }
548 if (eventData != NULL) {
549 delete[] eventData;
550 delete[] rawEventData;
551 delete[] waveLetArray;
552 }
553}
554
555/************************************************************
556 * PAINT GL. main drawing function.
557 ************************************************************/
558void RawDataViewer::paintGL()
559{
560 //Should not be required, but apparently it helps when piping it through X forwarding
561 glFinish();
562 makeCurrent();
563 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
564 glLoadIdentity();
565
566 glTranslatef(0,0,-0.5);
567
568 if (drawBlur)
569 {
570 glShadeModel(GL_SMOOTH);
571 drawCamera(false);
572 }
573 else
574 {
575 glShadeModel(GL_FLAT);
576 drawCamera(true);
577 }
578 glTranslatef(0,0,0.1f);
579 if (drawPatch)
580 drawPatches();
581 glTranslatef(0,0,0.1f);
582 if (!drawBlur && (selectedPixel != -1))
583 {
584 glLineWidth(1.0f);
585 glColor3f(1.0,1.0,1.0);
586 drawHexagon(selectedPixel, false);
587 }
588 glTranslatef(0,0,0.1f);
589 if (drawImpulse)
590 {
591 // glRotatef(cameraRotation, 0,0,1);
592 glLoadIdentity();
593 glLineWidth(2.0);
594 drawPixelCurve();
595 }
596 glTranslatef(0,0,0.1f);
597 DrawScale();
598}
599
600/************************************************************
601 * MOUSE PRESS EVENT. mouse click handler.
602 ************************************************************/
603void RawDataViewer::mousePressEvent(QMouseEvent *cEvent)
604{
605 if (cEvent->pos().x() > width()-(width()/50.f))
606 {
607 toggleInterfaceDisplay();
608 return;
609 }
610 lastPos = cEvent->pos();
611 if (setCorrectSlice(cEvent))
612 return;
613 int face = PixelAtPosition(cEvent->pos());
614 // if (face != -1) {
615 selectedPixel = face;
616 emit signalCurrentPixel(face);
617 // }
618 updateGL();
619}
620
621/************************************************************
622 * SET CORRECT SLICE. if displayed, figures out if the graph was
623 * clicked, and if so, which slice should be displayed
624 ************************************************************/
625bool RawDataViewer::setCorrectSlice(QMouseEvent* cEvent)
626{
627 if (!drawImpulse)
628 return false;
629 float cx = (float)cEvent->x() * pixelSize - shownSizex/2;
630 float cy = ((float)height()-(float)cEvent->y())*pixelSize - shownSizey/2;
631 if (cx < bboxMin[0] ||
632 cx > bboxMax[0] ||
633 cy < bboxMin[1] ||
634 cy > bboxMax[1])
635 return false;
636 whichSlice = (cx - bboxMin[0])*(nRoi+nRoiTM)/(bboxMax[0] - bboxMin[0]);
637 if (whichSlice >= nRoi)
638 whichSlice = nRoi-1;
639 emit signalCurrentSlice(whichSlice);
640 return true;
641}
642
643/************************************************************
644 * MOUSE MOVE EVENT. used to track the dragging of slices display
645 ************************************************************/
646void RawDataViewer::mouseMoveEvent(QMouseEvent *cEvent)
647{
648 if (cEvent->buttons() & Qt::LeftButton) {
649 setCorrectSlice(cEvent);
650 updateGL();
651 } else if (cEvent->buttons() & Qt::RightButton) {
652 updateGL();
653 }
654 lastPos = cEvent->pos();
655}
656
657/************************************************************
658 * MOUSE DOUBLE CLICK EVENT. used to select pixels
659 ************************************************************/
660void RawDataViewer::mouseDoubleClickEvent(QMouseEvent *cEvent)
661{
662 int face = PixelAtPosition(cEvent->pos());
663 if (face != -1) {
664 selectedPixel = face;
665 emit signalCurrentPixel(face);
666 updateGL();
667 }
668}
669
670/************************************************************
671 * OPEN FILE. opens a new fits file
672 ************************************************************/
673void RawDataViewer::openFile(string& file)
674{
675 if (inputFile)
676 {
677 inputFile->close();
678 delete inputFile;
679 }
680 try {
681 inputFile = new fits(file);
682 }
683 catch (std::runtime_error e)
684 {
685 cout << "Something went wrong while loading fits. aborting: " << e.what() << endl;
686 return;
687 }
688 if (!*inputFile)
689 {
690 delete inputFile;
691 inputFile = NULL;
692 return;
693 }
694 vector<string> entriesToCheck;
695 entriesToCheck.push_back("NAXIS2");
696 entriesToCheck.push_back("NROI");
697 entriesToCheck.push_back("REVISION");
698 entriesToCheck.push_back("RUNID");
699 entriesToCheck.push_back("NBOARD");
700 entriesToCheck.push_back("NPIX");
701 entriesToCheck.push_back("NROITM");
702 entriesToCheck.push_back("TIMESYS");
703 entriesToCheck.push_back("DATE");
704 entriesToCheck.push_back("NIGHT");
705 entriesToCheck.push_back("CAMERA");
706 entriesToCheck.push_back("DAQ");
707 entriesToCheck.push_back("TSTART");
708 entriesToCheck.push_back("TSTOP");
709 //entriesToCheck.push_back("ADCRANGE");
710 //entriesToCheck.push_back("NBEVTOK");
711 //entriesToCheck.push_back("NBEVTREJ");
712 //entriesToCheck.push_back("NBEVTBAD");
713
714 for (vector<string>::const_iterator it=entriesToCheck.begin(); it != entriesToCheck.end(); it++)
715 {
716 try {
717 if (!inputFile->HasKey(*it)){
718 cout << "Warning: header keyword " << *it << " missing." << endl;
719 return;}
720 }
721 catch (std::runtime_error e)
722 {
723 cout << e.what() << endl;
724 return;
725 }
726 }
727 nRows = inputFile->HasKey("NAXIS2") ? inputFile->GetInt("NAXIS2") : 0;
728 nRoi = inputFile->HasKey("NROI") ? inputFile->GetInt("NROI") : 0;
729 runNumber = inputFile->HasKey("RUNID") ? inputFile->GetInt("RUNID") : -1;
730 nTM = inputFile->HasKey("NTMARK") ? inputFile->GetInt("NTMARK") : 0;
731 runType = inputFile->HasKey("RUNTYPE") ? inputFile->GetInt("RUNTYPE") : -1;
732 firstDataTime = inputFile->HasKey("TSTART") ? inputFile->GetInt("TSTART") : -1;
733 lastDataTime = inputFile->HasKey("TSTOP") ? inputFile->GetInt("TSTOP"): -1;
734 nRoiTM = inputFile->HasKey("NROITM") ? inputFile->GetInt("NROITM") : 0;
735 revision = inputFile->HasKey("REVISION") ? inputFile->GetInt("REVISION") : -1;
736 builderVersion = inputFile->HasKey("BLDVER") ? inputFile->GetInt("BLDVER") : -1;
737 nBoards = inputFile->HasKey("NBOARD") ? inputFile->GetInt("NBOARD") : 0;
738 nPixels = inputFile->HasKey("NPIX") ? inputFile->GetInt("NPIX") : 0;
739 timeSystem = inputFile->HasKey("TIMESYS") ? inputFile->GetStr("TIMESYS") : 0;
740 creationDate = inputFile->HasKey("DATE") ? inputFile->GetStr("DATE") : 0;
741 nightInt = inputFile->HasKey("NIGHT") ? inputFile->GetInt("NIGHT") : 0;
742 camera = inputFile->HasKey("CAMERA") ? inputFile->GetStr("CAMERA") : 0;
743 daq = inputFile->HasKey("DAQ") ? inputFile->GetStr("DAQ") : 0;
744 adcCount = inputFile->HasKey("ADCRANGE") ? inputFile->GetFloat("ADCRANGE") : 2000;
745
746 if (inputFile->HasKey("OFFSET"))
747 offSetRoi = inputFile->GetInt("OFFSET");
748
749 nbOk = 0;//inputFile->GetInt("NBEVTOK");
750 nbRej = 0;//inputFile->GetInt("NBEVTREJ");
751 nbBad = 0;//inputFile->GetInt("NBEVTBAD");
752
753 eventNum = 0;
754
755#ifdef LOAD_RAW
756 nRows = NUM_STORED_EVENTS;
757#endif
758
759 if (eventData != NULL) {
760 delete[] eventData;
761 delete[] rawEventData;
762 delete[] waveLetArray;
763 }
764 eventData = new float[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
765
766 rawEventData = new int16_t[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
767 waveLetArray = new int16_t[1024*1440];
768 try
769 {
770 inputFile->SetPtrAddress("Data", rawEventData);
771 inputFile->SetPtrAddress("EventNum", &eventNum);
772 inputFile->SetPtrAddress("TriggerType", &triggerType);
773 inputFile->SetPtrAddress("SoftTrig", &softTrig);
774 inputFile->SetPtrAddress("BoardTime", boardTime);
775 inputFile->SetPtrAddress("StartCellData", startPix);
776 inputFile->SetPtrAddress("StartCellTimeMarker", startTM);
777 inputFile->SetPtrAddress("TimeMarker", &rawEventData[1440*nRoi]);
778 }
779 catch (const runtime_error &e)
780 {
781 cout << e.what() << endl;
782 cout << "Loading aborted." << endl;
783
784 nRoi = nRows = 0;
785
786 return;
787 }
788
789 try
790 {
791 pcTime[0] = pcTime[1] = 0;
792 inputFile->SetPtrAddress("UnixTimeUTC", pcTime);
793 }
794 catch (const runtime_error&)
795 {
796 try
797 {
798 inputFile->SetPtrAddress("PCTime", pcTime);
799 }
800 catch (const runtime_error&)
801 {
802
803 }
804 }
805
806
807 int backupStep = eventStep;
808 rowNum = -1;
809 eventStep = 1;
810
811 doMyWaveletTestPlease();
812
813
814 plusEvent();
815 eventStep = backupStep;
816 emit newFileLoaded();
817 emit signalCurrentPixel(selectedPixel);
818}
819/*
820bool RawDataViewer::doWaveLetsPlease(int givenSpan, int16_t* orig_in, int16_t* wavelets_in, bool verifyResult)
821{
822 float* interArray = new float[givenSpan];
823 float* resultArray = new float[givenSpan];
824 float* orig = new float[givenSpan];
825 float* wavelets = new float[givenSpan];
826 for (int i=0;i<givenSpan;i++)
827 {
828 if (fabs((float)(orig_in[i])) > 32767.f)
829 cout << "Input overflow: " << orig_in[i] << endl;
830 orig[i] = (float)orig_in[i];
831 }
832 for (int k=0;k<givenSpan;k++)
833 interArray[k] = orig[k];
834 int span = givenSpan/2;
835 while (span > 0)
836 {
837 for (int k=0;k<span;k++)
838 {
839 wavelets[k] = (interArray[2*k] + interArray[2*k + 1])/2.f;
840 wavelets[k + span] = (interArray[2*k + 1] - interArray[2*k])/2.f;
841 }
842 for (int k=0;k<givenSpan;k++)
843 interArray[k] = wavelets[k];
844 span /= 2;
845 }
846 //move float results to int16_t array
847 float intScaling = 15.9f;
848 int max = 0;
849 for (int i=0;i<givenSpan;i++)
850 {
851 float cValue = intScaling*wavelets[i];//
852 if (cValue > 0)
853 cValue += 0.5f;
854 else
855 cValue -= 0.5f;
856 wavelets_in[i] = (int16_t)(cValue);
857 if (fabs(cValue) > 32767.f)
858 {
859 cout << "Overflow ! " << cValue << endl;
860 }
861 if (fabs(cValue) > fabs(max))
862 max = cValue;
863 }
864// cout << "Max wave value: " << max << endl;
865 //result reconstruction and checking
866 if (!verifyResult)
867 return true;
868
869 for (int k=0;k<givenSpan;k++)
870 {
871 resultArray[k] = wavelets_in[k]/intScaling;
872 }
873
874 span = 1;
875 while (span < givenSpan)
876 {
877 for (int k=0;k<givenSpan;k++)
878 interArray[k] = resultArray[k];
879 for (int k=0;k<span;k++)
880 {
881 resultArray[2*k] = (float)(((interArray[k] - interArray[k + span])*(1.f/1.f)) + 0.0f);
882 resultArray[2*k + 1] = (float)(((interArray[k] + interArray[k + span])*(1.f/1.f)) + 0.0f);
883 }
884 span *= 2;
885 }
886
887 for (int k=0;k<givenSpan;k++)
888 {
889 float plus = 0.5f;
890 if (resultArray[k] < 0)
891 plus *= -1.f;
892 if ((int)(resultArray[k]+plus) != (int)(orig_in[k]))
893 {
894 cout << "Nop, sorry: k: " << k << " " << resultArray[k] << " " << (int)(resultArray[k]+plus) << " " << plus << " " << orig[k] << endl;
895 return false;
896 }
897 }
898 return true;
899}
900*/
901bool RawDataViewer::doWaveLetsPlease(int givenSpan, int16_t* orig_in, int16_t* wavelets_in, bool verifyResult)
902{
903 float* interArray = new float[givenSpan];
904 float* resultArray = new float[givenSpan];
905 float* orig = new float[givenSpan];
906 float* wavelets = new float[givenSpan];
907 for (int i=0;i<givenSpan;i++)
908 {
909 if (fabs((float)(orig_in[i])) > 32767.f)
910 cout << "Input overflow: " << orig_in[i] << endl;
911 orig[i] = (float)orig_in[i];
912 }
913 for (int k=0;k<givenSpan;k++)
914 interArray[k] = orig[k];
915 int span = givenSpan/2;
916 while (span > 0)
917 {
918 for (int k=0;k<span;k++)
919 {
920 wavelets[k] = interArray[2*k];// + interArray[2*k + 1])/2.f;
921 wavelets[k + span] = interArray[2*k + 1] - interArray[2*k];//)/2.f;
922 }
923 for (int k=0;k<givenSpan;k++)
924 interArray[k] = wavelets[k];
925 span /= 2;
926 }
927 //move float results to int16_t array
928 float intScaling = 1.f;
929 int max = 0;
930 for (int i=0;i<givenSpan;i++)
931 {
932 float cValue = intScaling*wavelets[i];//
933 if (cValue > 0)
934 cValue += 0.5f;
935 else
936 cValue -= 0.5f;
937 wavelets_in[i] = (int16_t)(cValue);
938 if (fabs(cValue) > 32767.f)
939 {
940 cout << "Overflow ! " << cValue << endl;
941 }
942 if (fabs(cValue) > fabs(max))
943 max = cValue;
944 }
945// cout << "Max wave value: " << max << endl;
946 //result reconstruction and checking
947 if (!verifyResult)
948 return true;
949
950 for (int k=0;k<givenSpan;k++)
951 {
952 resultArray[k] = wavelets_in[k]/intScaling;
953 }
954
955 span = 1;
956 while (span < givenSpan)
957 {
958 for (int k=0;k<givenSpan;k++)
959 interArray[k] = resultArray[k];
960 for (int k=0;k<span;k++)
961 {
962 resultArray[2*k] = (float)(((interArray[k])*(1.f/1.f)) + 0.0f);
963 resultArray[2*k + 1] = (float)(((interArray[k] + interArray[k + span])*(1.f/1.f)) + 0.0f);
964 }
965 span *= 2;
966 }
967
968 for (int k=0;k<givenSpan;k++)
969 {
970 float plus = 0.5f;
971 if (resultArray[k] < 0)
972 plus *= -1.f;
973 if ((int)(resultArray[k]+plus) != (int)(orig_in[k]))
974 {
975 cout << "Nop, sorry: k: " << k << " " << resultArray[k] << " " << (int)(resultArray[k]+plus) << " " << plus << " " << orig[k] << endl;
976 return false;
977 }
978 }
979 delete[] interArray;
980 delete[] resultArray;
981 delete[] orig;
982 delete[] wavelets;
983 return true;
984}
985
986void RawDataViewer::doWaveLetOnCurrentEventPlease()
987{
988 int16_t* origTheWayIWant = new int16_t[1024*1440];
989
990// int numPixels = 1024;
991// int leftOver = 1440-numPixels;
992 for (int k=0;k<1024;k++)
993 for (int j=0;j<1440;j++)
994 {
995 origTheWayIWant[k*1440 + j] = rawEventData[j + k*1440];
996 }
997
998 int waveSpan = 1024;
999 int waveToPixelsRatio = 32;
1000 waveSpan = waveSpan*waveToPixelsRatio;
1001 int totalNumSamples = 1024*1440;
1002 int j=0;
1003 for (;j<totalNumSamples;j+= waveSpan)
1004 {
1005 if (j + waveSpan < totalNumSamples)
1006 if (!doWaveLetsPlease(waveSpan, &origTheWayIWant[j], &waveLetArray[j], true))
1007 return;
1008 }
1009
1010 while (j%1440 != 0)
1011 {
1012 int lastRun = 1;
1013 while (lastRun < 1440 - j%1440)
1014 lastRun *= 2;
1015 lastRun /= 2;
1016 if (lastRun > 2)
1017 {
1018 doWaveLetsPlease(lastRun, &origTheWayIWant[j], &waveLetArray[j], true);
1019 }
1020 else
1021 {
1022 for (int l=0;l<lastRun;l++)
1023 waveLetArray[j+l] = origTheWayIWant[j+l];
1024 }
1025 if (!lastRun)
1026 break;
1027 j += lastRun;
1028 }
1029
1030 delete[] origTheWayIWant;
1031
1032}
1033void RawDataViewer::doMyWaveletTestPlease()
1034{
1035// cout << "Size of float: " << sizeof(float) << endl;
1036 return;
1037 ofstream outBin("/scratch/bin/outputBin.bin", ios_base::out | ios_base::binary);
1038 ofstream outWave("/scratch/bin/outputWave.bin", ios_base::out | ios_base::binary);
1039 int16_t* waveLetArray_ = new int16_t[1024*1440];
1040 int16_t* origTheWayIWant = new int16_t[1024*1440];
1041
1042 for (int i=0;i<nRows;i++)
1043 {
1044 cout << '\r' << "Doing row " << i << " of " << nRows;
1045 cout.flush();
1046 inputFile->GetRow(i);
1047 outBin.write((const char*)(rawEventData), 1440*1024*2);
1048
1049// int numPixels = 1024;
1050// int leftOver = 1440-numPixels;
1051 for (int k=0;k<1024;k++)
1052 for (int j=0;j<1440;j++)
1053 {
1054 origTheWayIWant[k*1440 + j] = rawEventData[j + k*1440];
1055 }
1056
1057 int waveSpan = 1024;
1058 int waveToPixelsRatio = 32;
1059 waveSpan = waveSpan*waveToPixelsRatio;
1060 int totalNumSamples = 1024*1440;
1061 int j=0;
1062 for (;j<totalNumSamples;j+= waveSpan)//1440/waveToPixelsRatio;j++)
1063 {
1064 if (j + waveSpan < totalNumSamples)
1065 if (!doWaveLetsPlease(waveSpan, &origTheWayIWant[j], &waveLetArray_[j], true))
1066 return;
1067 }
1068
1069 while (j%1440 != 0)// < totalNumSamples)
1070 {
1071 cout << "Copying the remaining of the data" << endl;
1072 int lastRun = 1;
1073 while (lastRun < 1440 - j%1440)//totalNumSamples-j)
1074 lastRun *= 2;
1075 lastRun /= 2;
1076 if (lastRun > 2)
1077 {
1078// cout << " Doint one last run of " << lastRun << " samples" << endl;
1079 doWaveLetsPlease(lastRun, &origTheWayIWant[j], &waveLetArray_[j], true);
1080 }
1081 else
1082 {
1083// cout << " Filling in " << lastRun << " samples" << endl;
1084 for (int l=0;l<lastRun;l++)
1085 waveLetArray_[j+l] = origTheWayIWant[j+l];
1086 }
1087 if (!lastRun)
1088 break;
1089 j += lastRun;
1090 }
1091 outWave.write((const char*)(waveLetArray_), 1440*1024*2);
1092 }
1093 outWave.close();
1094 outBin.close();
1095 inputFile->GetRow(0);
1096
1097 delete[] waveLetArray_;
1098 delete[] origTheWayIWant;
1099}
1100void RawDataViewer::openCalibFile(string& file)
1101{
1102 //calibrationLoaded = false;
1103
1104 string msg;
1105 try
1106 {
1107 msg = fDrsCalib.ReadFitsImp(file);
1108 if (msg.empty())
1109 {
1110 emit newFileLoaded();
1111 updateGL();
1112 return;
1113 }
1114 }
1115 catch (const runtime_error &e)
1116 {
1117 msg = e.what();
1118 }
1119
1120 cerr << msg << endl;
1121 fDrsCalib.Clear();
1122}
1123
1124/************************************************************
1125 * PLUS EVENT
1126 ************************************************************/
1127void RawDataViewer::plusEvent()
1128{
1129 eventStepping(true);
1130}
1131/************************************************************
1132 * MINUS EVENT
1133 ************************************************************/
1134void RawDataViewer::minusEvent()
1135{
1136 eventStepping(false);
1137}
1138/************************************************************
1139 * SET EVENT STEP
1140 ************************************************************/
1141void RawDataViewer::setEventStep(int step)
1142{
1143 eventStep = step;
1144}
1145/************************************************************
1146 * EVENT STEPPING
1147 ************************************************************/
1148
1149void RawDataViewer::ApplyCalibration()
1150{
1151 for (int i=0;i<1440*nRoi + 160*nRoiTM;i++)//(1440+160)*nRoi;i++)
1152 eventData[i] = (float)rawEventData[i];
1153
1154 if (fIsDrsCalibration)
1155 {
1156 fDrsCalib.Apply(eventData, rawEventData, startPix, nRoi);
1157 DrsCalibrate::RemoveSpikes(eventData, nRoi);
1158 for (int i=0;i<1024;i++)
1159 eventData[i] = eventData[i+1024];
1160 //TODO apply calibration to the Time markers
1161 }
1162
1163 //hide the time markers
1164 int nSlicesToRemove = 60;
1165 float* backupData;
1166 if (nRoiTM == 0) //they are written into the regular channel
1167 {
1168 backupData = new float[nSlicesToRemove*160];
1169 for (int i=0;i<1440;i++)
1170 {
1171 const PixelMapEntry& mapEntry = fPixelMap.index(i);
1172 const int pixelIdInPatch = mapEntry.pixel();
1173 const int patchId = mapEntry.patch();
1174 const int boardId = mapEntry.board();
1175 const int crateId = mapEntry.crate();
1176
1177 const int hw = mapEntry.hw();
1178 if (pixelIdInPatch == 8)
1179 {
1180 // cout << patchId << " ";
1181 for (int j=0;j<nSlicesToRemove;j++)
1182 {
1183 backupData[(40*crateId + 4*boardId + patchId)*nSlicesToRemove+j] = eventData[(hw*nRoi) + (nRoi-nSlicesToRemove) + j];
1184 eventData[(hw*nRoi) + (nRoi-nSlicesToRemove) + j] = eventData[hw*nRoi + (nRoi-nSlicesToRemove) - 1];
1185 }
1186 }
1187 }
1188 }
1189
1190 vector<float> pixelStatsData(1440*4);
1191 DrsCalibrate::GetPixelStats(pixelStatsData.data(), eventData, nRoi);
1192
1193 for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
1194 RMSvalues[it->index] = pixelStatsData[1*1440+it->hw()];
1195
1196 if (nRoiTM == 0)//move back the data back in place
1197 {
1198 for (int i=0;i<1440;i++)
1199 {
1200 const PixelMapEntry& mapEntry = fPixelMap.index(i);
1201 const int pixelIdInPatch = mapEntry.pixel();
1202 const int patchId = mapEntry.patch();
1203 const int boardId = mapEntry.board();
1204 const int crateId = mapEntry.crate();
1205 if (patchId > 160)
1206 cout << "Voila mon probleme: " << patchId << endl;
1207 const int hw = mapEntry.hw();
1208 if (pixelIdInPatch == 8)
1209 {
1210 // cout << "|" << crateId << " " << boardId << " " << patchId << " " << hw << "| ";
1211 for (int j=0;j<nSlicesToRemove;j++)
1212 {
1213 eventData[(hw*nRoi) + (nRoi - nSlicesToRemove) + j] = backupData[(40*crateId + 4*boardId + patchId)*nSlicesToRemove+j];
1214 }
1215 }
1216 }
1217 delete[] backupData;
1218 }
1219 if (isVisible())
1220 updateGL();
1221}
1222
1223void RawDataViewer::eventStepping(bool plus)
1224{
1225 if (plus)
1226 rowNum += eventStep;
1227 else
1228 rowNum -= eventStep;
1229 if (rowNum >= nRows)
1230 rowNum -= nRows;
1231 if (rowNum < 0)
1232 rowNum += nRows;
1233#ifdef LOAD_RAW
1234 eventNum+=eventStep;
1235#else
1236 if (inputFile == NULL)
1237 return;
1238 inputFile->GetRow(rowNum);
1239// cout << "Getting row " << rowNum << endl;
1240#endif
1241
1242 ApplyCalibration();
1243
1244 emit signalCurrentEvent(eventNum);
1245 emit signalCurrentPixel(selectedPixel);
1246}
1247
1248/************************************************************
1249 * NEXT SLICE. deprec ?
1250 ************************************************************/
1251void RawDataViewer::nextSlice()
1252{
1253 whichSlice++;
1254 if (whichSlice >= nRoi)
1255 {
1256 whichSlice = 0;
1257 if (!loopCurrentEvent)
1258 {
1259 int backupStep = eventStep;
1260 eventStep = 1;
1261 eventStepping(true);
1262 eventStep = backupStep;
1263 }
1264 }
1265 emit signalCurrentSlice(whichSlice);
1266 updateGL();
1267}
1268void RawDataViewer::previousSlice()
1269{
1270 whichSlice--;
1271 if (whichSlice < 0)
1272 {
1273 whichSlice = nRoi-1;
1274 if (!loopCurrentEvent)
1275 {
1276 int backupStep = eventStep;
1277 eventStep = 1;
1278 eventStepping(false);
1279 eventStep = backupStep;
1280 }
1281 }
1282 emit signalCurrentSlice(whichSlice);
1283 updateGL();
1284}
1285void RawDataViewer::setCurrentPixel(int pix)
1286{
1287 // if (pix == -1)
1288 // return;
1289 selectedPixel = pix;
1290 if (isVisible())
1291 updateGL();
1292 emit signalCurrentPixel(pix);
1293}
1294void RawDataViewer::computePulsesStatistics()
1295{
1296 if (!inputFile)
1297 {
1298 cout << "A FITS file must be open in order to complete this operation" << endl;
1299 return;
1300 }
1301
1302
1303// for (int i=0;i<nRows;i++)//for all events
1304// {
1305// inputFile->GetRow(rowNum);
1306// for (int i=0;i<(1440+160)*nRoi;i++)
1307// eventData[i] = (float)rawEventData[i];
1308
1309// for (int j=0;j<ACTUAL_NUM_PIXELS;j++)
1310/// {
1311 int j = selectedPixel;
1312 if (j == -1)
1313 return;
1314 for (int i=0;i<nRoi;i++)
1315 {
1316 aMeas[i] = eventData[j*nRoi+i];// * adcCount;
1317
1318 }
1319 for (int i=0;i<nRoi;i++)
1320 {
1321 if (i==0)
1322 n1mean[i] = aMeas[i+1];
1323 else
1324 {
1325 if (i==1023)
1326 n1mean[i] = aMeas[i-1];
1327 else
1328 n1mean[i] = (aMeas[i-1]+aMeas[i+1])/2.f;
1329 }
1330 }
1331 //find spike
1332 for (int i=0;i<nRoi-3;i++)
1333 {
1334 const float fract = 0.8f;
1335 float xx, xp, xpp;
1336 vCorr[i] = 0;//aMeas[i];
1337 xx = aMeas[i] - n1mean[i];
1338 if (xx < -8.f)
1339 {
1340 xp = aMeas[i+1] - n1mean[i+1];
1341 xpp = aMeas[i+2] - n1mean[i+2];
1342 if ((aMeas[i+2] - (aMeas[i] + aMeas[i+3])/2.f) > 10.f)
1343 {
1344 vCorr[i+1] = (aMeas[i] + aMeas[i+3])/2.f;
1345 vCorr[i+2] = (aMeas[i] + aMeas[i+3])/2.f;
1346 i = i+2;
1347 }
1348 else
1349 {
1350 if ((xp > -2.*xx*fract) && (xpp < -10.f))
1351 {
1352 vCorr[i+1] = n1mean[i+1];
1353 n1mean[i+2] = aMeas[i+1] - aMeas[i+3]/2.f;
1354 i++;
1355 }
1356 }
1357 }
1358 }
1359 for (int i=0;i<nRoi;i++)
1360 n1mean[i] = aMeas[i]-n1mean[i];
1361 // }
1362 // }
1363}
1364/************************************************************
1365 * UICONNECTOR CONSTRUCTOR
1366 ************************************************************/
1367UIConnector::UIConnector(QWidget *p)
1368{
1369 setupUi(this);
1370 initHistograms();
1371
1372 currentFile = "none";
1373 currentCalibFile = "none";
1374
1375 updateSpinnerDisplay = true;
1376 updating = false;
1377
1378 timer.setInterval(10.0);
1379 QObject::connect(&timer, SIGNAL(timeout()),
1380 this, SLOT(nextSlicePlease()));
1381
1382 QButtonGroup &scaleGroup = *new QButtonGroup(p);// = new QButtonGroup(canvas);
1383 QButtonGroup &animateGroup = *new QButtonGroup(p);// = new QButtonGroup(canvas);
1384
1385 scaleGroup.addButton(currentPixelScale);
1386 scaleGroup.addButton(entireCameraScale);
1387
1388 animateGroup.addButton(playEventsRadio);
1389 animateGroup.addButton(playSlicesRadio);
1390
1391 entireCameraScale->setChecked(true);
1392
1393 GLWindow_2->enableText(false);
1394 // GLWindow_2->ShowPatchCursor(true);
1395
1396 QObject::connect(GLWindow, SIGNAL(colorPaletteHasChanged()),
1397 this, SLOT(on_autoScaleColor_clicked()));
1398 QObject::connect(GLWindow, SIGNAL(signalCurrentSlice(int)),
1399 this, SLOT(currentSliceHasChanged(int)));
1400 QObject::connect(GLWindow, SIGNAL(signalCurrentEvent(int)),
1401 this, SLOT(currentEventHasChanged(int)));
1402 QObject::connect(GLWindow, SIGNAL(signalCurrentPixel(int)),
1403 this, SLOT(pixelChanged(int)));
1404 QObject::connect(GLWindow, SIGNAL(newFileLoaded()),
1405 this, SLOT(newFileLoaded()));
1406
1407 QObject::connect(GLWindow_2, SIGNAL(signalCurrentPixel(int)),
1408 GLWindow, SLOT(setCurrentPixel(int)));
1409
1410
1411 show();
1412}
1413UIConnector::~UIConnector()
1414{
1415 grid1->detach();
1416 grid2->detach();
1417 grid3->detach();
1418 grid4->detach();
1419 grid5->detach();
1420 boardsTimeHistoItem.detach();
1421 startCellHistoItem.detach();
1422 startTimeMarkHistoItem.detach();
1423 pixelValueCurveItem.detach();
1424 aMeanCurveItem.detach();
1425 vCorrCurveItem.detach();
1426 meanCurveItem.detach();
1427}
1428void UIConnector::slicesPlusPlus()
1429{
1430 GLWindow->nextSlice();
1431}
1432void UIConnector::slicesMinusMinus()
1433{
1434 GLWindow->previousSlice();
1435}
1436void UIConnector::on_calibratedCheckBox_stateChanged(int state)
1437{
1438 GLWindow->fIsDrsCalibration = state;
1439 GLWindow->ApplyCalibration();
1440
1441 on_autoScaleColor_clicked();
1442 pixelChanged(GLWindow->selectedPixel);
1443
1444}
1445/************************************************************
1446 * DRAW PATCHES CHECK CHANGE. checkbox handler
1447 ************************************************************/
1448void UIConnector::on_drawPatchCheckBox_stateChanged(int state)
1449{
1450 GLWindow->drawPatch = state;
1451 GLWindow->updateGL();
1452}
1453/************************************************************
1454 * DRAW IMPULSE CHECK CHANGE. checkbox handler
1455 ************************************************************/
1456void UIConnector::on_drawImpulseCheckBox_stateChanged(int state)
1457{
1458 GLWindow->drawImpulse = state;
1459 GLWindow->updateGL();
1460}
1461/************************************************************
1462 * DRAW BLUR CHECK CHANGE. checkbox handler
1463 ************************************************************/
1464void UIConnector::on_drawBlurCheckBox_stateChanged(int state)
1465{
1466 GLWindow->drawBlur = state;
1467 GLWindow->updateGL();
1468}
1469void UIConnector::on_loopOverCurrentEventBox_stateChanged(int state)
1470{
1471 GLWindow->loopCurrentEvent = state;
1472}
1473
1474/************************************************************
1475 * NEXT SLICE PLEASE
1476 ************************************************************/
1477void UIConnector::nextSlicePlease()
1478{
1479 if (playEventsRadio->isChecked ())
1480 GLWindow->eventStepping(true);
1481 else
1482 GLWindow->nextSlice();
1483}
1484
1485/************************************************************
1486 * SET VIEWER.
1487 ************************************************************/
1488//void UIConnector::setViewer(RawDataViewer* v)
1489//{
1490// viewer = v;
1491//}
1492/************************************************************
1493 * SLICES PER SECOND CHANGED. timing ui handler
1494 ************************************************************/
1495void UIConnector::slicesPerSecondChanged(double value)
1496{
1497 timer.setInterval(1000.0/value);
1498}
1499
1500void UIConnector::on_colorRange0_valueChanged(double value) { GLWindow->ss[0] = (float)value; GLWindow->updateGL(); }
1501void UIConnector::on_colorRange1_valueChanged(double value) { GLWindow->ss[1] = (float)value; GLWindow->updateGL(); }
1502void UIConnector::on_colorRange2_valueChanged(double value) { GLWindow->ss[2] = (float)value; GLWindow->updateGL(); }
1503void UIConnector::on_colorRange3_valueChanged(double value) { GLWindow->ss[3] = (float)value; GLWindow->updateGL(); }
1504void UIConnector::on_colorRange4_valueChanged(double value) { GLWindow->ss[4] = (float)value; GLWindow->updateGL(); }
1505
1506void UIConnector::on_redValue0_valueChanged(double value) { GLWindow->rr[0] = (float)value; GLWindow->updateGL(); }
1507void UIConnector::on_redValue1_valueChanged(double value) { GLWindow->rr[1] = (float)value; GLWindow->updateGL(); }
1508void UIConnector::on_redValue2_valueChanged(double value) { GLWindow->rr[2] = (float)value; GLWindow->updateGL(); }
1509void UIConnector::on_redValue3_valueChanged(double value) { GLWindow->rr[3] = (float)value; GLWindow->updateGL(); }
1510void UIConnector::on_redValue4_valueChanged(double value) { GLWindow->rr[4] = (float)value; GLWindow->updateGL(); }
1511
1512void UIConnector::on_greenValue0_valueChanged(double value) { GLWindow->gg[0] = (float)value; GLWindow->updateGL(); }
1513void UIConnector::on_greenValue1_valueChanged(double value) { GLWindow->gg[1] = (float)value; GLWindow->updateGL(); }
1514void UIConnector::on_greenValue2_valueChanged(double value) { GLWindow->gg[2] = (float)value; GLWindow->updateGL(); }
1515void UIConnector::on_greenValue3_valueChanged(double value) { GLWindow->gg[3] = (float)value; GLWindow->updateGL(); }
1516void UIConnector::on_greenValue4_valueChanged(double value) { GLWindow->gg[4] = (float)value; GLWindow->updateGL(); }
1517
1518void UIConnector::on_blueValue0_valueChanged(double value) { GLWindow->bb[0] = (float)value; GLWindow->updateGL(); }
1519void UIConnector::on_blueValue1_valueChanged(double value) { GLWindow->bb[1] = (float)value; GLWindow->updateGL(); }
1520void UIConnector::on_blueValue2_valueChanged(double value) { GLWindow->bb[2] = (float)value; GLWindow->updateGL(); }
1521void UIConnector::on_blueValue3_valueChanged(double value) { GLWindow->bb[3] = (float)value; GLWindow->updateGL(); }
1522void UIConnector::on_blueValue4_valueChanged(double value) { GLWindow->bb[4] = (float)value; GLWindow->updateGL(); }
1523
1524/************************************************************
1525 * LOAD NEW FILE CLICKED. button handler
1526 ************************************************************/
1527void UIConnector::on_loadNewFileButton_clicked()
1528{
1529 QFileDialog dialog;
1530 dialog.setFileMode(QFileDialog::ExistingFile);
1531 dialog.open(this, SLOT(fileSelected(QString)));
1532 dialog.setVisible(true);
1533 dialog.exec();
1534}
1535void UIConnector::on_loadDRSCalibButton_clicked()
1536{
1537 QFileDialog dialog;
1538 dialog.setFileMode(QFileDialog::ExistingFile);
1539 dialog.open(this, SLOT(calibFileSelected(QString)));
1540 dialog.setVisible(true);
1541 dialog.exec();
1542}
1543/************************************************************
1544 * FILE SELECTED. return of the file open dialog handler
1545 ************************************************************/
1546void UIConnector::fileSelected(QString file)
1547{
1548 currentFile = file.toStdString();
1549 if (currentFile != "")
1550 GLWindow->openFile(currentFile);
1551}
1552void UIConnector::calibFileSelected(QString file)
1553{
1554 currentCalibFile = file.toStdString();
1555 if (currentCalibFile != "")
1556 GLWindow->openCalibFile(currentCalibFile);
1557}
1558/************************************************************
1559 * NEW FILE LOADED. update of the UI after a new file has been loaded
1560 ************************************************************/
1561void UIConnector::newFileLoaded()
1562{
1563 ostringstream str;
1564
1565 //extract the file name only (no path) from the full name
1566 str << "File: ";
1567 if (currentFile.size() > 2)
1568 str << currentFile.substr(currentFile.find_last_of("//")+1, currentFile.size()) << "\n";
1569 else
1570 str << "--\n";
1571 str << "Calibration: ";
1572 if (currentCalibFile.size() > 2)
1573 str << currentCalibFile.substr(currentCalibFile.find_last_of("//")+1, currentCalibFile.size()) << "\n";
1574 else
1575 str << "--\n";
1576// fileLoadedLabel->setText(QString(str.str().c_str()));
1577// str.str("");
1578 str << "Run number: " << GLWindow->runNumber << "\n";
1579// runNumberLabel->setText(QString(str.str().c_str()));
1580// str.str("");
1581 str << "Number of Events: " << GLWindow->nRows << "\n";
1582
1583 displayingEventBox->setMaximum(GLWindow->nRows-1);
1584
1585 str << "Number of Slices: " << GLWindow->nRoi << "\n";// << "/1024";
1586// numberOfSlicesLabel->setText(QString(str.str().c_str()));
1587// str.str("");
1588 str << "Number of Time Marks: " << GLWindow->nTM << "\n";
1589// numberOfTimeMarksLabel->setText(QString(str.str().c_str()));
1590
1591// str.str("");
1592 str << "Run Type: " << GLWindow->runType << "\n";
1593// runTypeLabel->setText(QString(str.str().c_str()));
1594// str.str("");
1595 str << "Time of 1st data: " << GLWindow->firstDataTime << "\n";
1596// firstTimeLabel->setText(QString(str.str().c_str()));
1597// str.str("");
1598 str << "Time of last data: " << GLWindow->lastDataTime << "\n";
1599// lastTimeLabel->setText(QString(str.str().c_str()));
1600// str.str("");
1601 str << "SVN revision: " << GLWindow->revision << '\n';
1602 str << "Number of boards: " << GLWindow->nBoards << '\n';
1603 str << "Number of pixels: " << GLWindow->nPixels << '\n';
1604 str << "Number of Slices TM: " << GLWindow->nRoiTM << '\n';
1605 str << "Time system: " << GLWindow->timeSystem << '\n';
1606 str << "Date: " << GLWindow->creationDate << '\n';
1607 str << "Night: " << GLWindow->nightInt << '\n';
1608 str << "Camera: " << GLWindow->camera << '\n';
1609 str << "DAQ: " << GLWindow->daq << '\n';
1610 str << "ADC Count: " << GLWindow->adcCount << '\n';
1611 str << "NB Evts OK:" << GLWindow->nbOk << '\n';
1612 str << "NB Evts Rejected: " << GLWindow->nbRej << '\n';
1613 str << "NB Evts Bad: " << GLWindow->nbBad << '\n';
1614 extraInfoLabel->setText(QString(str.str().c_str()));
1615
1616 /*
1617 if (GLWindow->calibrationLoaded)
1618 {
1619 drawCalibrationCheckBox->setEnabled(true);
1620 }*/
1621
1622
1623}
1624/************************************************************
1625 * PLAY PAUSE CLICKED. ui handler
1626 ************************************************************/
1627void UIConnector::on_playPauseButton_clicked()
1628{
1629 if (timer.isActive())
1630 timer.stop();
1631 else
1632 timer.start();
1633}
1634
1635void UIConnector::displaySliceValue()
1636{
1637 if (!GLWindow->nRoi)
1638 return;
1639 if (GLWindow->selectedPixel == -1)
1640 {
1641 ostringstream str;
1642 str << " Current Pixel val.: --";
1643 currentPixelValue->setText(QString(str.str().c_str()));
1644 return;
1645 }
1646 const int idx =
1647 GLWindow->nRoi*GLWindow->hardwareMapping[GLWindow->selectedPixel]
1648 + GLWindow->whichSlice;
1649
1650 ostringstream str;
1651 str << "Current Pixel val.: " << GLWindow->eventData[idx];
1652 currentPixelValue->setText(QString(str.str().c_str()));
1653}
1654
1655/************************************************************
1656 * CURRENT SLICE HAS CHANGE. ui handler
1657 ************************************************************/
1658void UIConnector::currentSliceHasChanged(int slice)
1659{
1660 if (!GLWindow->nRoi)
1661 return;
1662
1663 if (updateSpinnerDisplay)
1664 displayingSliceBox->setValue(slice);
1665
1666 displaySliceValue();
1667}
1668
1669/*****
1670 *******************************************************
1671 * CURRENT EVENT HAS CHANGED. ui handler
1672 ************************************************************/
1673
1674double xval[50000];
1675double yval[50000];
1676void UIConnector::on_displayingEventBox_valueChanged(int cEvent)
1677{
1678// cout << "Here " << updateSpinnerDisplay << endl;
1679 if (!updateSpinnerDisplay)
1680 return;
1681 updateSpinnerDisplay = false;
1682// currentEventHasChanged(cEvent);
1683 GLWindow->rowNum = cEvent - GLWindow->eventStep;
1684 GLWindow->eventStepping(true);
1685 updateSpinnerDisplay = true;
1686
1687// GLWindow->updateGL();
1688}
1689void UIConnector::on_slicesPerSecValue_valueChanged(double value)
1690{
1691 timer.setInterval(1000.0/value);
1692}
1693void UIConnector::on_displayingSliceBox_valueChanged(int cSlice)
1694{
1695 updateSpinnerDisplay = false;
1696 currentSliceHasChanged(cSlice);
1697 updateSpinnerDisplay = true;
1698 GLWindow->whichSlice = cSlice;
1699 GLWindow->updateGL();
1700}
1701void UIConnector::currentEventHasChanged(int )
1702{
1703
1704 GLWindow_2->SetData(GLWindow->RMSvalues);
1705 if (GLWindow_2->isVisible())
1706 GLWindow_2->updateGL();
1707 ostringstream str;
1708// str << "Displaying Event " << cEvent;
1709// QString qstr(str.str().c_str());
1710// emit updateCurrentEventDisplay(qstr);
1711 if (updateSpinnerDisplay)
1712 {
1713 updateSpinnerDisplay = false;
1714 displayingEventBox->setValue(GLWindow->rowNum);
1715 updateSpinnerDisplay = true;
1716 }
1717
1718 // GLWindow->doWaveLetOnCurrentEventPlease();
1719
1720 //retrieve the data that we want to display
1721 boost::posix_time::ptime hrTime( boost::gregorian::date(1970, boost::gregorian::Jan, 1),
1722 boost::posix_time::seconds(GLWindow->pcTime[0]) + boost::posix_time::microsec(GLWindow->pcTime[1]));
1723
1724 str.str("");
1725 str << "PC Time: " << boost::posix_time::to_iso_extended_string(hrTime);
1726 PCTimeLabel->setText(QString(str.str().c_str()));
1727
1728 str.str("");
1729 str << "Software Trigger: " << GLWindow->softTrig;
1730 softwareTriggerLabel->setText(QString(str.str().c_str()));
1731
1732 str.str("");
1733 str << "Trigger Type: " << GLWindow->triggerType;
1734 triggerTypeLabel->setText(QString(str.str().c_str()));
1735
1736 displaySliceValue();
1737
1738 if (autoScaleColor->isChecked())
1739 emit GLWindow->colorPaletteHasChanged();//autoScalePressed();
1740
1741 boardsTimeList->clear();
1742 startPixelsList->clear();
1743 startTimeMarksList->clear();
1744 triggerDelayList->clear();
1745 std::map<int, int> boardsHistoMap;
1746 for (int i=0;i <NBOARDS; i++)
1747 {
1748 str.str("");
1749 str << i;
1750 if (i<10) str << " ";
1751 if (i<100) str << " ";
1752 if (i<1000) str << " ";
1753 str << ": " << GLWindow->boardTime[i];
1754 boardsTimeList->addItem(QString(str.str().c_str()));
1755 if (boardsHistoMap.find(GLWindow->boardTime[i]) != boardsHistoMap.end())
1756 boardsHistoMap[GLWindow->boardTime[i]]++;
1757 else
1758 boardsHistoMap[GLWindow->boardTime[i]] = 1;
1759 }
1760 std::map<int, int> pixelHistoMap;
1761 for (int i=0;i <NPIX; i++)
1762 {
1763 str.str("");
1764 str << i;
1765 if (i<10) str << " ";
1766 if (i<100) str << " ";
1767 if (i<1000) str << " ";
1768 str << ": " << GLWindow->startPix[i];
1769 startPixelsList->addItem(QString(str.str().c_str()));
1770 if (pixelHistoMap.find(GLWindow->startPix[i]) != pixelHistoMap.end())
1771 pixelHistoMap[GLWindow->startPix[i]]++;
1772 else
1773 pixelHistoMap[GLWindow->startPix[i]] = 1;
1774 }
1775
1776 std::map<int, int> timeMarksMap;
1777 for (int i=0;i <NTMARK; i++)
1778 {
1779 str.str("");
1780 str << i;
1781 if (i<10) str << " ";
1782 if (i<100) str << " ";
1783 if (i<1000) str << " ";
1784 str << ": " << GLWindow->startTM[i];
1785 startTimeMarksList->addItem(QString(str.str().c_str()));
1786 if (timeMarksMap.find(GLWindow->startTM[i]) != timeMarksMap.end())
1787 timeMarksMap[GLWindow->startTM[i]]++;
1788 else
1789 timeMarksMap[GLWindow->startTM[i]] = 1;
1790 }
1791 std::map<int,int> delayMap;
1792 triggerDelayList->addItem(QString("Patch | Slice:Delay Slice:Delay..."));
1793 for (int i=0;i<NTMARK; i++)
1794 {
1795 str.str("");
1796 str << i << " | ";
1797 for (int j=0;j<GLWindow->nRoi;j++)
1798 {
1799 int value = GLWindow->eventData[1440*GLWindow->nRoi + i*GLWindow->nRoi + j];
1800 if (delayMap.find(value) != delayMap.end())
1801 delayMap[value]++;
1802 else
1803 delayMap[value] = 1;
1804 str << j << ":" << value << " ";
1805 }
1806 triggerDelayList->addItem(QString(str.str().c_str()));
1807 }
1808
1809 std::map<int,int>::iterator it = boardsHistoMap.begin();
1810 int nsamples = 0;
1811 int previousValue = it->first-10;
1812 for (unsigned int i=0;i<boardsHistoMap.size();i++)
1813 {
1814 if (previousValue != it->first-1)
1815 {
1816 xval[nsamples] = previousValue+1;
1817 yval[nsamples] = 0;
1818 nsamples++;
1819 xval[nsamples] = it->first-1;
1820 yval[nsamples] = 0;
1821 nsamples++;
1822 }
1823 xval[nsamples] = it->first;
1824 yval[nsamples] = it->second;
1825 previousValue = it->first;
1826 it++;
1827 nsamples++;
1828 xval[nsamples] = previousValue;
1829 yval[nsamples] = 0;
1830 nsamples++;
1831 if (nsamples > 4090)
1832 {
1833 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1834 break;
1835 }
1836 }
1837 xval[nsamples] = it==boardsHistoMap.begin() ? 0 : (--it)->first+1;
1838 yval[nsamples] = 0;
1839 nsamples++;
1840 // if (nsamples > 5)
1841#if QWT_VERSION < 0x060000
1842 boardsTimeHistoItem.setData(xval, yval, nsamples);
1843#else
1844 boardsTimeHistoItem.setSamples(xval, yval, nsamples);
1845#endif
1846
1847 it = pixelHistoMap.begin();
1848 nsamples = 0;
1849 previousValue = it->first-10;
1850 for (unsigned int i=0;i<pixelHistoMap.size();i++)
1851 {
1852 if (previousValue != it->first-1)
1853 {
1854 xval[nsamples] = previousValue+1;
1855 yval[nsamples] = 0;
1856 nsamples++;
1857 xval[nsamples] = it->first-1;
1858 yval[nsamples] = 0;
1859 nsamples++;
1860 }
1861 xval[nsamples] = it->first;
1862 yval[nsamples] = it->second;
1863 previousValue = it->first;
1864 it++;
1865 nsamples++;
1866 xval[nsamples] = previousValue;
1867 yval[nsamples] = 0;
1868 nsamples++;
1869 if (nsamples > 4090)
1870 {
1871 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1872 break;
1873 }
1874 }
1875 xval[nsamples] = it==pixelHistoMap.begin() ? 0 : (--it)->first+1;
1876 yval[nsamples] = 0;
1877 nsamples++;
1878// if (nsamples > 5)
1879#if QWT_VERSION < 0x060000
1880 startCellHistoItem.setData(xval, yval, nsamples);
1881#else
1882 startCellHistoItem.setSamples(xval, yval, nsamples);
1883#endif
1884
1885 it = timeMarksMap.begin();
1886 nsamples = 0;
1887 previousValue = it->first-10;
1888 for (unsigned int i=0;i<timeMarksMap.size();i++)
1889 {
1890 if (previousValue != it->first-1)
1891 {
1892 xval[nsamples] = previousValue+1;
1893 yval[nsamples] = 0;
1894 nsamples++;
1895 xval[nsamples] = it->first-1;
1896 yval[nsamples] = 0;
1897 nsamples++;
1898 }
1899 xval[nsamples] = it->first;
1900 yval[nsamples] = it->second;
1901 previousValue = it->first;
1902 it++;
1903 nsamples++;
1904 xval[nsamples] = previousValue;
1905 yval[nsamples] = 0;
1906 nsamples++;
1907 if (nsamples > 4090)
1908 {
1909 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1910 break;
1911 }
1912 }
1913 xval[nsamples] = it==timeMarksMap.begin() ? 0 : (--it)->first+1;
1914 yval[nsamples] = 0;
1915 nsamples++;
1916 // if (nsamples > 5)
1917#if QWT_VERSION < 0x060000
1918 startTimeMarkHistoItem.setData(xval, yval, nsamples);
1919#else
1920 startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
1921#endif
1922
1923 it = delayMap.begin();
1924 nsamples = 0;
1925 previousValue = it->first-10;
1926 for (unsigned int i=0;i<delayMap.size();i++)
1927 {
1928 if (previousValue != it->first-1)
1929 {
1930 xval[nsamples] = previousValue+1;
1931 yval[nsamples] = 0;
1932 nsamples++;
1933 xval[nsamples] = it->first-1;
1934 yval[nsamples] = 0;
1935 nsamples++;
1936 }
1937 xval[nsamples] = it->first;
1938 yval[nsamples] = it->second;
1939 previousValue = it->first;
1940 it++;
1941 nsamples++;
1942 xval[nsamples] = previousValue;
1943 yval[nsamples] = 0;
1944 nsamples++;
1945 if (nsamples > 4090)
1946 {
1947 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1948 break;
1949 }
1950 }
1951 xval[nsamples] = it==delayMap.begin() ? 0 : (--it)->first+1;
1952 yval[nsamples] = 0;
1953 nsamples++;
1954 // if (nsamples > 5)
1955#if QWT_VERSION < 0x060000
1956 triggerDelayHistoItem.setData(xval, yval, nsamples);
1957#else
1958 triggerDelayHistoItem.setSamples(xval, yval, nsamples);
1959#endif
1960 //WAVELETS HACK
1961/* std::map<int, int> valuesHistoMap;
1962 std::map<int, int> waveletHistoMap;
1963 for (int i=0;i<1024*1440;i++)
1964 {
1965 if (valuesHistoMap.find(GLWindow->rawEventData[i]) != valuesHistoMap.end())
1966 valuesHistoMap[GLWindow->rawEventData[i]]++;
1967 else
1968 valuesHistoMap[GLWindow->rawEventData[i]] = 1;
1969 if (waveletHistoMap.find(GLWindow->waveLetArray[i]) != waveletHistoMap.end())
1970 waveletHistoMap[GLWindow->waveLetArray[i]]++;
1971 else
1972 waveletHistoMap[GLWindow->waveLetArray[i]] = 1;
1973 }
1974
1975 it = valuesHistoMap.begin();
1976 nsamples = 0;
1977 previousValue = it->first-10;
1978 cout << "Num values Original: " << valuesHistoMap.size() << endl;
1979 for (unsigned int i=0;i<valuesHistoMap.size();i++)
1980 {
1981 if (previousValue != it->first-1)
1982 {
1983 xval[nsamples] = previousValue+1;
1984 yval[nsamples] = 0;
1985 nsamples++;
1986 xval[nsamples] = it->first-1;
1987 yval[nsamples] = 0;
1988 nsamples++;
1989 }
1990 xval[nsamples] = it->first;
1991 yval[nsamples] = it->second;
1992 previousValue = it->first;
1993 it++;
1994 nsamples++;
1995 xval[nsamples] = previousValue;
1996 yval[nsamples] = 0;
1997 nsamples++;
1998 if (nsamples > 50000)
1999 {
2000 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
2001 break;
2002 }
2003 }
2004 xval[nsamples] = it==valuesHistoMap.begin() ? 0 : (--it)->first+1;
2005 yval[nsamples] = 0;
2006 nsamples++;
2007 // if (nsamples > 5)
2008 #if QWT_VERSION < 0x060000
2009 triggerDelayHistoItem.setData(xval, yval, nsamples);
2010 #else
2011 triggerDelayHistoItem.setSamples(xval, yval, nsamples);
2012 #endif
2013
2014 it = waveletHistoMap.begin();
2015 nsamples = 0;
2016 previousValue = it->first-10;
2017 cout << "Num values WaveLets: " << waveletHistoMap.size() << endl;
2018 for (unsigned int i=0;i<waveletHistoMap.size();i++)
2019 {
2020 if (previousValue != it->first-1)
2021 {
2022 xval[nsamples] = previousValue+1;
2023 yval[nsamples] = 0;
2024 nsamples++;
2025 xval[nsamples] = it->first-1;
2026 yval[nsamples] = 0;
2027 nsamples++;
2028 }
2029 xval[nsamples] = it->first;
2030 yval[nsamples] = it->second;
2031 previousValue = it->first;
2032 it++;
2033 nsamples++;
2034 xval[nsamples] = previousValue;
2035 yval[nsamples] = 0;
2036 nsamples++;
2037 if (nsamples > 50000)
2038 {
2039 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
2040 break;
2041 }
2042 }
2043 xval[nsamples] = it==waveletHistoMap.begin() ? 0 : (--it)->first+1;
2044 yval[nsamples] = 0;
2045 nsamples++;
2046 // if (nsamples > 5)
2047 #if QWT_VERSION < 0x060000
2048 startTimeMarkHistoItem.setData(xval, yval, nsamples);
2049 #else
2050 startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
2051 #endif
2052*/
2053//END OF WAVELETS HACK
2054 // startCellHistoZoom->setZoomBase(startCellHistoItem.boundingRect());
2055 QStack< QRectF > stack;
2056// QRectF cRectangle = boardsTimeHistoItem.boundingRect();
2057 stack.push(scaleBoundingRectangle(boardsTimeHistoItem.boundingRect(), 1.05f));//cRectangle);//boardsTimeHistoItem.boundingRect());
2058 boardsTimeHistoZoom->setZoomStack(stack);
2059 stack.pop();
2060 stack.push(scaleBoundingRectangle(startCellHistoItem.boundingRect(), 1.05f));
2061 startCellHistoZoom->setZoomStack(stack);
2062 stack.pop();
2063 stack.push(scaleBoundingRectangle(startTimeMarkHistoItem.boundingRect(), 1.05f));
2064 startTimeMarkHistoZoom->setZoomStack(stack);
2065 stack.pop();
2066 stack.push(scaleBoundingRectangle(triggerDelayHistoItem.boundingRect(), 1.05f));
2067 triggerDelayHistoZoom->setZoomStack(stack);
2068 stack.pop();
2069
2070 pixelChanged(GLWindow->selectedPixel);
2071}
2072//can't use a ref to rectangle, as the type must be converted first
2073QRectF UIConnector::scaleBoundingRectangle(QRectF rectangle, float scale)
2074{
2075 QPointF bottomRight = rectangle.bottomRight();
2076 QPointF topLeft = rectangle.topLeft();
2077 QPointF center = rectangle.center();
2078 return QRectF(topLeft + (topLeft-center)*(scale-1.0f), //top left
2079 bottomRight + (bottomRight-center)*(scale-1.0f)); //bottom right
2080}
2081void UIConnector::initHistograms()
2082{
2083// QwtPlot* boardsTimeHisto;
2084// QwtPlotHistogram boardsTimeHistoItem;
2085 grid1 = new QwtPlotGrid;
2086 grid1->enableX(false);
2087 grid1->enableY(true);
2088 grid1->enableXMin(false);
2089 grid1->enableYMin(false);
2090 grid1->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2091 grid1->attach(boardsTimeHisto);
2092
2093 grid2 = new QwtPlotGrid;
2094 grid2->enableX(false);
2095 grid2->enableY(true);
2096 grid2->enableXMin(false);
2097 grid2->enableYMin(false);
2098 grid2->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2099 grid2->attach(startCellsHisto);
2100
2101 grid3 = new QwtPlotGrid;
2102 grid3->enableX(false);
2103 grid3->enableY(true);
2104 grid3->enableXMin(false);
2105 grid3->enableYMin(false);
2106 grid3->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2107 grid3->attach(startTimeMarkHisto);
2108
2109 grid4 = new QwtPlotGrid;
2110 grid4->enableX(false);
2111 grid4->enableY(true);
2112 grid4->enableXMin(false);
2113 grid4->enableYMin(false);
2114 grid4->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2115 grid4->attach(pixelValueCurve);
2116
2117 grid5 = new QwtPlotGrid;
2118 grid5->enableX(false);
2119 grid5->enableY(true);
2120 grid5->enableXMin(false);
2121 grid5->enableYMin(false);
2122 grid5->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2123 grid5->attach(triggerDelayHisto);
2124
2125 boardsTimeHisto->setAutoReplot(true);
2126 startCellsHisto->setAutoReplot(true);
2127 startTimeMarkHisto->setAutoReplot(true);
2128 pixelValueCurve->setAutoReplot(true);
2129 triggerDelayHisto->setAutoReplot(true);
2130 boardsTimeHisto->setTitle("Boards time values");
2131 startCellsHisto->setTitle("Start Cell values");
2132 startTimeMarkHisto->setTitle("Start Time Marks values");
2133 pixelValueCurve->setTitle("Current pixel values");
2134 triggerDelayHisto->setTitle("Trigger Delays");
2135
2136 // boardsTimeHistoItem.setBrush(QBrush(Qt::red));
2137// startCellHistoItem.setBrush(QBrush(Qt::red));
2138// startTimeMarkHistoItem.setBrush(QBrush(Qt::red));
2139// triggerDelayHistoItem.setBrush(QBrush(Qt::red));
2140// pixelValueCurveItem.setBrush(QBrush(Qt::red));
2141
2142 boardsTimeHistoItem.setPen(QColor(Qt::darkGreen));
2143 boardsTimeHistoItem.setStyle(QwtPlotCurve::Steps);
2144 startCellHistoItem.setPen(QColor(Qt::darkGreen));
2145 startCellHistoItem.setStyle(QwtPlotCurve::Steps);
2146 startTimeMarkHistoItem.setPen(QColor(Qt::darkGreen));
2147 startTimeMarkHistoItem.setStyle(QwtPlotCurve::Steps);
2148 triggerDelayHistoItem.setPen(QColor(Qt::darkGreen));
2149 triggerDelayHistoItem.setStyle(QwtPlotCurve::Steps);
2150
2151 boardsTimeHistoItem.attach(boardsTimeHisto);
2152 startCellHistoItem.attach(startCellsHisto);
2153 startTimeMarkHistoItem.attach(startTimeMarkHisto);
2154 triggerDelayHistoItem.attach(triggerDelayHisto);
2155
2156 //curve
2157// pixelValueCurveItem.setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush, QPen(Qt::black), QSize(5,5)));
2158 pixelValueCurveItem.setPen(QColor(Qt::black));
2159 aMeanCurveItem.setPen(QColor(Qt::darkGreen));
2160 vCorrCurveItem.setPen(QColor(Qt::red));
2161 meanCurveItem.setPen(QColor(Qt::blue));
2162 pixelValueCurveItem.setStyle(QwtPlotCurve::Lines);
2163 aMeanCurveItem.setStyle(QwtPlotCurve::Lines);
2164 vCorrCurveItem.setStyle(QwtPlotCurve::Lines);
2165 meanCurveItem.setStyle(QwtPlotCurve::Lines);
2166
2167// pixelValueCurveItem.setCurveAttribute(QwtPlotCurve::Fitted);
2168 pixelValueCurveItem.attach(pixelValueCurve);
2169// aMeanCurveItem.attach(pixelValueCurve);
2170 // vCorrCurveItem.attach(pixelValueCurve);
2171// meanCurveItem.attach(pixelValueCurve);
2172
2173 //FIXME delete these pointers with the destructor
2174 curveZoom = new QwtPlotZoomer(pixelValueCurve->canvas());
2175 curveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2176 curveZoom->setTrackerPen(QPen(Qt::gray));
2177
2178 boardsTimeHistoZoom = new QwtPlotZoomer(boardsTimeHisto->canvas());
2179 boardsTimeHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2180 boardsTimeHistoZoom->setTrackerPen(QPen(Qt::gray));
2181
2182 startCellHistoZoom = new QwtPlotZoomer(startCellsHisto->canvas());
2183 startCellHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2184 startCellHistoZoom->setTrackerPen(QPen(Qt::gray));
2185
2186 startTimeMarkHistoZoom = new QwtPlotZoomer(startTimeMarkHisto->canvas());
2187 startTimeMarkHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2188 startTimeMarkHistoZoom->setTrackerPen(QPen(Qt::gray));
2189
2190 triggerDelayHistoZoom = new QwtPlotZoomer(triggerDelayHisto->canvas());
2191 triggerDelayHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2192 triggerDelayHistoZoom->setTrackerPen(QPen(Qt::gray));
2193
2194
2195}
2196
2197void UIConnector::pixelChanged(int pixel)
2198{
2199 GLWindow_2->fWhite = pixel;
2200 if (pixel != -1)
2201 GLWindow_2->fWhitePatch = GLWindow_2->pixelsPatch[pixel];
2202 else
2203 GLWindow_2->fWhitePatch = -1;
2204 if (pixel == -1)
2205 return;
2206 int softwarePix = pixel;
2207 pixel = GLWindow->hardwareMapping[pixel];
2208
2209 HwIDBox->setValue(pixel);
2210
2211 if (!GLWindow->nRoi)
2212 return;
2213
2214int currentPixel = pixel;
2215//IN ORDER TO GET THE AVERAGE OF ALL PIXELS DISPLAYED IN THE CURVE OF THE VIEWER
2216//UNCOMMENT THE 9 LINES BELOW, i.e. UNTIL THE END OF AVERAGE DISPLAY COMMENT MARK
2217//int currentPixel = 0;
2218// for (int i=0;i<GLWindow->nRoi;i++)
2219// yval[i] = 0;
2220// for (int j=0;j<1440;j++) {
2221// currentPixel = j;
2222 for (int i=0;i<GLWindow->nRoi;i++)
2223 {
2224 xval[i] = i;
2225 yval[i] = GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
2226// yval[i] += GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
2227 }
2228// }
2229// for (int i=0;i<GLWindow->nRoi;i++)
2230// yval[i] /= 1440;
2231//END OF AVERAGE DISPLAY COMMENTS
2232int realNumSamples = GLWindow->nRoi;
2233 if (GLWindow->nRoiTM != 0)
2234 {
2235 const PixelMapEntry& mapEntry = GLWindow->fPixelMap.index(softwarePix);
2236 const int pixelIdInPatch = mapEntry.pixel();
2237 const int patchId = mapEntry.patch();
2238 const int boardId = mapEntry.board();
2239 const int crateId = mapEntry.crate();
2240 if (pixelIdInPatch == 8)
2241 {
2242 int TMIndex = 0;
2243 int xIndex = GLWindow->nRoi;
2244 int arrayIndex = GLWindow->nRoi;
2245 if (GLWindow->offSetRoi < 0)
2246 TMIndex -= GLWindow->offSetRoi;
2247 if (GLWindow->offSetRoi > 0)
2248 xIndex += GLWindow->offSetRoi;
2249 for (int i=TMIndex;i<GLWindow->nRoiTM;i++, xIndex++, arrayIndex++)
2250 {
2251 xval[arrayIndex] = xIndex;
2252 yval[arrayIndex] = GLWindow->eventData[GLWindow->nRoi*1440 + GLWindow->nRoiTM*(40*crateId + 4*boardId + patchId) + i];
2253 }
2254 realNumSamples += GLWindow->nRoiTM - TMIndex;
2255 }
2256 // cout << pixelIdInPatch << " " ;
2257 }
2258//cout << realNumSamples << endl;
2259 // GLWindow->computePulsesStatistics();
2260#if QWT_VERSION < 0x060000
2261 pixelValueCurveItem.setData(xval, yval, realNumSamples);
2262//// aMeanCurveItem.setData(xval, GLWindow->aMeas, GLWindow->nRoi);
2263 // meanCurveItem.setData(xval, GLWindow->n1mean, GLWindow->nRoi);
2264 // vCorrCurveItem.setData(xval, GLWindow->vCorr, GLWindow->nRoi-3);
2265#else
2266 pixelValueCurveItem.setSamples(xval, yval, realNumSamples);
2267// aMeanCurveItem.setSamples(xval, GLWindow->aMeas, GLWindow->nRoi);
2268 // meanCurveItem.setSamples(xval, GLWindow->n1mean, GLWindow->nRoi);
2269 // vCorrCurveItem.setSamples(xval, GLWindow->vCorr, GLWindow->nRoi-3);
2270#endif
2271
2272
2273 QStack< QRectF > stack;
2274 stack.push(scaleBoundingRectangle(pixelValueCurveItem.boundingRect(), 1.5f));
2275 curveZoom->setZoomStack(stack);
2276 stack.pop();
2277
2278 displaySliceValue();
2279 on_autoScaleColor_clicked();
2280}
2281
2282void UIConnector::on_HwIDBox_valueChanged(int)
2283{
2284 updating = true;
2285
2286 const int hwID = HwIDBox->value();
2287
2288 const int crateID = hwID/360;
2289 const int boardID = (hwID%360)/36;
2290 const int patchID = (hwID%36 )/9;
2291 const int pixelID = hwID%9;
2292
2293 SwIDBox->setValue(GLWindow->softwareMapping[hwID]);
2294
2295 crateIDBox->setValue(crateID);
2296 boardIDBox->setValue(boardID);
2297 patchIDBox->setValue(patchID);
2298 pixelIDBox->setValue(pixelID);
2299
2300 updating = false;
2301
2302 GLWindow->selectedPixel = GLWindow->softwareMapping[hwID];
2303 GLWindow->updateGL();
2304
2305 pixelChanged(GLWindow->selectedPixel);
2306}
2307
2308void UIConnector::cbpxChanged()
2309{
2310 if (updating)
2311 return;
2312
2313 const int hwid = crateIDBox->value()*360 + boardIDBox->value()*36 + patchIDBox->value()*9 + pixelIDBox->value();
2314 HwIDBox->setValue(hwid);
2315}
2316
2317void UIConnector::on_SwIDBox_valueChanged(int swid)
2318{
2319 if (updating)
2320 return;
2321
2322 HwIDBox->setValue(GLWindow->hardwareMapping[swid]);
2323}
2324
2325void UIConnector::on_autoScaleColor_clicked()
2326{
2327 if (!autoScaleColor->isChecked())
2328 {
2329 GLWindow->ss[0] = 0.496;
2330 GLWindow->ss[1] = 0.507;
2331 GLWindow->ss[2] = 0.518;
2332 GLWindow->ss[3] = 0.529;
2333 GLWindow->ss[4] = 0.540;;
2334 colorRange0->setValue(GLWindow->ss[0]);
2335 colorRange1->setValue(GLWindow->ss[1]);
2336 colorRange2->setValue(GLWindow->ss[2]);
2337 colorRange3->setValue(GLWindow->ss[3]);
2338 colorRange4->setValue(GLWindow->ss[4]);
2339 return;
2340 }
2341 if (!GLWindow->nRoi)
2342 return;
2343
2344 int start = 0;
2345 int end = 1440;
2346
2347 if (!entireCameraScale->isChecked())
2348 {
2349 start = GLWindow->selectedPixel;
2350 end = GLWindow->selectedPixel+1;
2351 if (end == 0)
2352 {
2353 start = 0;
2354 end = 1440;
2355 }
2356 }
2357
2358 int min = 100000; //real min = -2048, int_16 = -32768 to 32767
2359 int max = -100000; //real max = 2047
2360
2361 long average = 0;
2362 long numSamples = 0;
2363 int errorDetected = -1;
2364
2365 for (int i=start;i<end;i++)
2366 {
2367 for (int j=10;j<GLWindow->nRoi-50;j++)
2368 {
2369 int cValue = GLWindow->eventData[i*GLWindow->nRoi+j];
2370 if (cValue > max && cValue < 32767)
2371 max = cValue;
2372 if (cValue < min && cValue > -32768)
2373 min = cValue;
2374 if (cValue < 32767 && cValue > -32768)
2375 {
2376 average+=cValue;
2377 numSamples++;
2378 }
2379 else
2380 {
2381 errorDetected = i;
2382 }
2383// numSamples++;
2384 }
2385 }
2386 average /= numSamples;
2387 if (errorDetected != -1)
2388 {
2389 cout << "Overflow detected at pixel " << errorDetected << " (at least)" << endl;
2390 }
2391// cout << "min: " << min << " max: " << max << " average: " << average << endl;
2392 double minRange = (double)(min+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2393 double maxRange = (double)(max+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2394 double midRange = (double)(average+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2395 if (GLWindow->logScale)
2396 {
2397 minRange *= 9;
2398 maxRange *= 9;
2399// midRange *= 9;
2400 minRange += 1;
2401 maxRange += 1;
2402// midRange += 1;
2403 minRange = log10(minRange);
2404 maxRange = log10(maxRange);
2405// midRange = (minRange + maxRange)/2.f;
2406 midRange = log10(midRange);
2407 }
2408
2409 GLWindow->ss[0] = minRange;
2410 colorRange0->setValue(GLWindow->ss[0]);
2411 GLWindow->ss[4] = maxRange;
2412 colorRange4->setValue(GLWindow->ss[4]);
2413// GLWindow->ss[2] = midRange;
2414// range2->setValue(GLWindow->ss[2]);
2415// GLWindow->ss[1] = (minRange+midRange)/2;
2416// range1->setValue(GLWindow->ss[1]);
2417// GLWindow->ss[3] = (maxRange+midRange)/2;
2418// range3->setValue(GLWindow->ss[3]);
2419
2420 GLWindow->ss[2] = (maxRange+minRange)/2;
2421 colorRange2->setValue(GLWindow->ss[2]);
2422
2423 GLWindow->ss[1] = minRange+(maxRange-minRange)/4;
2424 colorRange1->setValue(GLWindow->ss[1]);
2425
2426 GLWindow->ss[3] = minRange+3*(maxRange-minRange)/4;
2427 colorRange3->setValue(GLWindow->ss[3]);
2428}
2429
2430void PrintUsage()
2431{
2432 cout << "\n"
2433 "The FACT++ raw data viewer.\n"
2434 "\n"
2435 "Usage: viewer [OPTIONS] [datafile.fits[.gz] [calibration.drs.fits[.gz]]]\n"
2436 " or: viewer [OPTIONS]\n";
2437 cout << endl;
2438
2439}
2440
2441void PrintHelp()
2442{
2443 cout <<
2444 "\n"
2445 << endl;
2446}
2447
2448int UIConnector::SetupConfiguration(Configuration &conf)
2449{
2450 RawDataViewer *canvas = GLWindow;
2451
2452 if (conf.Has("color.range"))
2453 {
2454 vector<double> value = conf.Vec<double>("color.range");
2455 if (value.size() != 5)
2456 {
2457 cout << "Error, colorRange option should have exactly 5 double values" << endl;
2458 return -1;
2459 }
2460 for (int i=0;i<5;i++)
2461 canvas->ss[i] = value[i];
2462 }
2463
2464 if (conf.Has("color.red"))
2465 {
2466 vector<double> value = conf.Vec<double>("color.red");
2467 if (value.size() != 5)
2468 {
2469 cout << "Error, colorRed option should have exactly 5 double values" << endl;
2470 return -1;
2471 }
2472 for (int i=0;i<5;i++)
2473 canvas->rr[i] = value[i];
2474 }
2475
2476 if (conf.Has("color.green"))
2477 {
2478 vector<double> value = conf.Vec<double>("color.green");
2479 if (value.size() != 5)
2480 {
2481 cout << "Error, colorGreen option should have exactly 5 double values" << endl;
2482 return -1;
2483 }
2484 for (int i=0;i<5;i++)
2485 canvas->gg[i] = value[i];
2486 }
2487
2488 if (conf.Has("color.blue"))
2489 {
2490 vector<double> value = conf.Vec<double>("color.blue");
2491 if (value.size() != 5)
2492 {
2493 cout << "Error, colorBlue option should have exactly 5 double values" << endl;
2494 return -1;
2495 }
2496 for (int i=0;i<5;i++)
2497 canvas->bb[i] = value[i];
2498 }
2499
2500 colorRange0->setValue(canvas->ss[0]);
2501 colorRange1->setValue(canvas->ss[1]);
2502 colorRange2->setValue(canvas->ss[2]);
2503 colorRange3->setValue(canvas->ss[3]);
2504 colorRange4->setValue(canvas->ss[4]);
2505 redValue0->setValue(canvas->rr[0]);
2506 redValue1->setValue(canvas->rr[1]);
2507 redValue2->setValue(canvas->rr[2]);
2508 redValue3->setValue(canvas->rr[3]);
2509 redValue4->setValue(canvas->rr[4]);
2510 greenValue0->setValue(canvas->gg[0]);
2511 greenValue1->setValue(canvas->gg[1]);
2512 greenValue2->setValue(canvas->gg[2]);
2513 greenValue3->setValue(canvas->gg[3]);
2514 greenValue4->setValue(canvas->gg[4]);
2515 blueValue0->setValue(canvas->bb[0]);
2516 blueValue1->setValue(canvas->bb[1]);
2517 blueValue2->setValue(canvas->bb[2]);
2518 blueValue3->setValue(canvas->bb[3]);
2519 blueValue4->setValue(canvas->bb[4]);
2520
2521 if (conf.Has("drs"))
2522 {
2523 const QString qstr(conf.Get<string>("drs").c_str());
2524 calibFileSelected(qstr);
2525 }
2526
2527 if (conf.Has("file"))
2528 {
2529 const QString qstr(conf.Get<string>("file").c_str());
2530 fileSelected(qstr);
2531 }
2532
2533
2534 return 0;
2535}
2536
2537void SetupConfiguration(Configuration& conf)
2538{
2539 po::options_description configs("Raw Events Viewer Options");
2540 configs.add_options()
2541 ("color.range", vars<double>(), "Range of the display colours")
2542 ("color.red", vars<double>(), "Range of red values")
2543 ("color.green", vars<double>(), "Range of green values")
2544 ("color.blue", vars<double>(), "Range of blue values")
2545 ("file,f", var<string>(), "File to be loaded")
2546 ("drs,d", var<string>(), "DRS calibration file to be loaded")
2547 ;
2548 conf.AddOptions(configs);
2549
2550 po::positional_options_description p;
2551 p.add("file", 1); // The first positional options
2552 p.add("drs", 2); // The first positional options
2553 conf.SetArgumentPositions(p);
2554
2555}
2556
2557/************************************************************
2558 * MAIN PROGRAM FUNCTION.
2559 ************************************************************/
2560int main(int argc, const char *argv[])
2561{
2562 QApplication app(argc, const_cast<char**>(argv));
2563
2564 if (!QGLFormat::hasOpenGL()) {
2565 std::cerr << "This system has no OpenGL support" << std::endl;
2566 return 1;
2567 }
2568
2569 Configuration conf(argv[0]);
2570 conf.SetPrintUsage(PrintUsage);
2571 SetupConfiguration(conf);
2572 if (!conf.DoParse(argc, argv, PrintHelp))
2573 return 2;
2574
2575 UIConnector myUi;
2576 if (myUi.SetupConfiguration(conf)<0)
2577 return 3;
2578
2579 return app.exec();
2580}
2581
Note: See TracBrowser for help on using the repository browser.