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

Last change on this file since 12474 was 12426, checked in by lyard, 14 years ago
removed cout
File size: 81.5 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 < 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 > 1)
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 buildVerticesList();
526// for (int i=0;i<1440;i++)
527// updateNeighbors(i);
528
529 for (int i=0;i<160;i++)
530 {
531 const float color[3] = { 0.5, 0.5, 0.3 };
532
533 for (int j=0;j<3;j++)
534 patchesColor[i][j] = color[j];
535 }
536
537 //calibrationLoaded = false;
538 //drawCalibrationLoaded = false;
539
540}
541/************************************************************
542 * DESTRUCTOR
543 ************************************************************/
544RawDataViewer::~RawDataViewer()
545{
546 if (inputFile != NULL)
547 {
548 inputFile->close();
549 delete inputFile;
550 }
551 if (eventData != NULL) {
552 delete[] eventData;
553 delete[] rawEventData;
554 delete[] waveLetArray;
555 }
556}
557
558/************************************************************
559 * PAINT GL. main drawing function.
560 ************************************************************/
561void RawDataViewer::paintGL()
562{
563 glFinish();
564 makeCurrent();
565 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
566 glLoadIdentity();
567
568 glTranslatef(0,0,-0.5);
569
570 if (drawBlur)
571 {
572 glShadeModel(GL_SMOOTH);
573 drawCamera(false);
574 }
575 else
576 {
577 glShadeModel(GL_FLAT);
578 drawCamera(true);
579 }
580 glTranslatef(0,0,0.1f);
581 if (drawPatch)
582 drawPatches();
583 glTranslatef(0,0,0.1f);
584 if (!drawBlur && (selectedPixel != -1))
585 {
586 glLineWidth(1.0f);
587 glColor3f(1.0,1.0,1.0);
588 drawHexagon(selectedPixel, false);
589 }
590 glTranslatef(0,0,0.1f);
591 if (drawImpulse)
592 {
593 // glRotatef(cameraRotation, 0,0,1);
594 glLoadIdentity();
595 glLineWidth(2.0);
596 drawPixelCurve();
597 }
598 glTranslatef(0,0,0.1f);
599 DrawScale();
600}
601
602/************************************************************
603 * MOUSE PRESS EVENT. mouse click handler.
604 ************************************************************/
605void RawDataViewer::mousePressEvent(QMouseEvent *cEvent)
606{
607 if (cEvent->pos().x() > width()-(width()/50.f))
608 {
609 toggleInterfaceDisplay();
610 return;
611 }
612 lastPos = cEvent->pos();
613 if (setCorrectSlice(cEvent))
614 return;
615 int face = PixelAtPosition(cEvent->pos());
616 // if (face != -1) {
617 selectedPixel = face;
618 emit signalCurrentPixel(face);
619 // }
620 updateGL();
621}
622
623/************************************************************
624 * SET CORRECT SLICE. if displayed, figures out if the graph was
625 * clicked, and if so, which slice should be displayed
626 ************************************************************/
627bool RawDataViewer::setCorrectSlice(QMouseEvent* cEvent)
628{
629 if (!drawImpulse)
630 return false;
631 float cx = (float)cEvent->x() * pixelSize - shownSizex/2;
632 float cy = ((float)height()-(float)cEvent->y())*pixelSize - shownSizey/2;
633 if (cx < bboxMin[0] ||
634 cx > bboxMax[0] ||
635 cy < bboxMin[1] ||
636 cy > bboxMax[1])
637 return false;
638 whichSlice = (cx - bboxMin[0])*(nRoi+nRoiTM)/(bboxMax[0] - bboxMin[0]);
639 if (whichSlice >= nRoi)
640 whichSlice = nRoi-1;
641 emit signalCurrentSlice(whichSlice);
642 return true;
643}
644
645/************************************************************
646 * MOUSE MOVE EVENT. used to track the dragging of slices display
647 ************************************************************/
648void RawDataViewer::mouseMoveEvent(QMouseEvent *cEvent)
649{
650 if (cEvent->buttons() & Qt::LeftButton) {
651 setCorrectSlice(cEvent);
652 updateGL();
653 } else if (cEvent->buttons() & Qt::RightButton) {
654 updateGL();
655 }
656 lastPos = cEvent->pos();
657}
658
659/************************************************************
660 * MOUSE DOUBLE CLICK EVENT. used to select pixels
661 ************************************************************/
662void RawDataViewer::mouseDoubleClickEvent(QMouseEvent *cEvent)
663{
664 int face = PixelAtPosition(cEvent->pos());
665 if (face != -1) {
666 selectedPixel = face;
667 emit signalCurrentPixel(face);
668 updateGL();
669 }
670}
671
672/************************************************************
673 * OPEN FILE. opens a new fits file
674 ************************************************************/
675void RawDataViewer::openFile(string& file)
676{
677 if (inputFile)
678 {
679 inputFile->close();
680 delete inputFile;
681 }
682 try {
683 inputFile = new fits(file);
684 }
685 catch (std::runtime_error e)
686 {
687 cout << "Something went wrong while loading fits. aborting: " << e.what() << endl;
688 return;
689 }
690 if (!*inputFile)
691 {
692 delete inputFile;
693 inputFile = NULL;
694 return;
695 }
696 vector<string> entriesToCheck;
697 entriesToCheck.push_back("NAXIS2");
698 entriesToCheck.push_back("NROI");
699 entriesToCheck.push_back("REVISION");
700 entriesToCheck.push_back("RUNID");
701 entriesToCheck.push_back("NBOARD");
702 entriesToCheck.push_back("NPIX");
703 entriesToCheck.push_back("NROITM");
704 entriesToCheck.push_back("TIMESYS");
705 entriesToCheck.push_back("DATE");
706 entriesToCheck.push_back("NIGHT");
707 entriesToCheck.push_back("CAMERA");
708 entriesToCheck.push_back("DAQ");
709 entriesToCheck.push_back("TSTART");
710 entriesToCheck.push_back("TSTOP");
711 //entriesToCheck.push_back("ADCRANGE");
712 //entriesToCheck.push_back("NBEVTOK");
713 //entriesToCheck.push_back("NBEVTREJ");
714 //entriesToCheck.push_back("NBEVTBAD");
715
716 for (vector<string>::const_iterator it=entriesToCheck.begin(); it != entriesToCheck.end(); it++)
717 {
718 try {
719 if (!inputFile->HasKey(*it)){
720 cout << *it << " missing. Aborting load..." << endl;
721 return;}
722 }
723 catch (std::runtime_error e)
724 {
725 cout << e.what() << endl;
726 return;
727 }
728 }
729 nRows = inputFile->GetInt("NAXIS2");
730 nRoi = inputFile->GetInt("NROI");
731 runNumber = inputFile->GetInt("RUNID");
732 nTM = inputFile->HasKey("NTMARK") ? inputFile->GetInt("NTMARK") : 0;
733 runType = inputFile->HasKey("RUNTYPE") ? inputFile->GetInt("RUNTYPE") : -1;
734 firstDataTime = inputFile->GetInt("TSTART");
735 lastDataTime = inputFile->GetInt("TSTOP");
736 nRoiTM = inputFile->GetInt("NROITM");
737 revision = inputFile->GetInt("REVISION");
738 builderVersion = inputFile->HasKey("BLDVER") ? inputFile->GetInt("BLDVER") : -1;
739 nBoards = inputFile->GetInt("NBOARD");
740 nPixels = inputFile->GetInt("NPIX");
741 timeSystem = inputFile->GetStr("TIMESYS");
742 creationDate = inputFile->GetStr("DATE");
743 nightInt = inputFile->GetInt("NIGHT");
744 camera = inputFile->GetStr("CAMERA");
745 daq = inputFile->GetStr("DAQ");
746 adcCount = inputFile->HasKey("ADCRANGE") ? inputFile->GetFloat("ADCRANGE") : 2000;
747
748 if (inputFile->HasKey("OFFSET"))
749 offSetRoi = inputFile->GetInt("OFFSET");
750
751 nbOk = 0;//inputFile->GetInt("NBEVTOK");
752 nbRej = 0;//inputFile->GetInt("NBEVTREJ");
753 nbBad = 0;//inputFile->GetInt("NBEVTBAD");
754
755 eventNum = 0;
756
757#ifdef LOAD_RAW
758 nRows = NUM_STORED_EVENTS;
759#endif
760
761 if (eventData != NULL) {
762 delete[] eventData;
763 delete[] rawEventData;
764 delete[] waveLetArray;
765 }
766 eventData = new float[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
767
768 rawEventData = new int16_t[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
769 waveLetArray = new int16_t[1024*1440];
770 try
771 {
772 inputFile->SetPtrAddress("Data", rawEventData);
773 inputFile->SetPtrAddress("EventNum", &eventNum);
774 inputFile->SetPtrAddress("TriggerType", &triggerType);
775 inputFile->SetPtrAddress("SoftTrig", &softTrig);
776 inputFile->SetPtrAddress("BoardTime", boardTime);
777 inputFile->SetPtrAddress("StartCellData", startPix);
778 inputFile->SetPtrAddress("StartCellTimeMarker", startTM);
779 inputFile->SetPtrAddress("TimeMarker", &rawEventData[1440*nRoi]);
780 }
781 catch (const runtime_error &e)
782 {
783 cout << e.what() << endl;
784 cout << "Loading aborted." << endl;
785
786 nRoi = nRows = 0;
787
788 return;
789 }
790
791 try
792 {
793 pcTime[0] = pcTime[1] = 0;
794 inputFile->SetPtrAddress("UnixTimeUTC", pcTime);
795 }
796 catch (const runtime_error&)
797 {
798 try
799 {
800 inputFile->SetPtrAddress("PCTime", pcTime);
801 }
802 catch (const runtime_error&)
803 {
804
805 }
806 }
807
808
809 int backupStep = eventStep;
810 rowNum = -1;
811 eventStep = 1;
812
813 doMyWaveletTestPlease();
814
815
816 plusEvent();
817 eventStep = backupStep;
818 emit newFileLoaded();
819 emit signalCurrentPixel(selectedPixel);
820}
821/*
822bool RawDataViewer::doWaveLetsPlease(int givenSpan, int16_t* orig_in, int16_t* wavelets_in, bool verifyResult)
823{
824 float* interArray = new float[givenSpan];
825 float* resultArray = new float[givenSpan];
826 float* orig = new float[givenSpan];
827 float* wavelets = new float[givenSpan];
828 for (int i=0;i<givenSpan;i++)
829 {
830 if (fabs((float)(orig_in[i])) > 32767.f)
831 cout << "Input overflow: " << orig_in[i] << endl;
832 orig[i] = (float)orig_in[i];
833 }
834 for (int k=0;k<givenSpan;k++)
835 interArray[k] = orig[k];
836 int span = givenSpan/2;
837 while (span > 0)
838 {
839 for (int k=0;k<span;k++)
840 {
841 wavelets[k] = (interArray[2*k] + interArray[2*k + 1])/2.f;
842 wavelets[k + span] = (interArray[2*k + 1] - interArray[2*k])/2.f;
843 }
844 for (int k=0;k<givenSpan;k++)
845 interArray[k] = wavelets[k];
846 span /= 2;
847 }
848 //move float results to int16_t array
849 float intScaling = 15.9f;
850 int max = 0;
851 for (int i=0;i<givenSpan;i++)
852 {
853 float cValue = intScaling*wavelets[i];//
854 if (cValue > 0)
855 cValue += 0.5f;
856 else
857 cValue -= 0.5f;
858 wavelets_in[i] = (int16_t)(cValue);
859 if (fabs(cValue) > 32767.f)
860 {
861 cout << "Overflow ! " << cValue << endl;
862 }
863 if (fabs(cValue) > fabs(max))
864 max = cValue;
865 }
866// cout << "Max wave value: " << max << endl;
867 //result reconstruction and checking
868 if (!verifyResult)
869 return true;
870
871 for (int k=0;k<givenSpan;k++)
872 {
873 resultArray[k] = wavelets_in[k]/intScaling;
874 }
875
876 span = 1;
877 while (span < givenSpan)
878 {
879 for (int k=0;k<givenSpan;k++)
880 interArray[k] = resultArray[k];
881 for (int k=0;k<span;k++)
882 {
883 resultArray[2*k] = (float)(((interArray[k] - interArray[k + span])*(1.f/1.f)) + 0.0f);
884 resultArray[2*k + 1] = (float)(((interArray[k] + interArray[k + span])*(1.f/1.f)) + 0.0f);
885 }
886 span *= 2;
887 }
888
889 for (int k=0;k<givenSpan;k++)
890 {
891 float plus = 0.5f;
892 if (resultArray[k] < 0)
893 plus *= -1.f;
894 if ((int)(resultArray[k]+plus) != (int)(orig_in[k]))
895 {
896 cout << "Nop, sorry: k: " << k << " " << resultArray[k] << " " << (int)(resultArray[k]+plus) << " " << plus << " " << orig[k] << endl;
897 return false;
898 }
899 }
900 return true;
901}
902*/
903bool RawDataViewer::doWaveLetsPlease(int givenSpan, int16_t* orig_in, int16_t* wavelets_in, bool verifyResult)
904{
905 float* interArray = new float[givenSpan];
906 float* resultArray = new float[givenSpan];
907 float* orig = new float[givenSpan];
908 float* wavelets = new float[givenSpan];
909 for (int i=0;i<givenSpan;i++)
910 {
911 if (fabs((float)(orig_in[i])) > 32767.f)
912 cout << "Input overflow: " << orig_in[i] << endl;
913 orig[i] = (float)orig_in[i];
914 }
915 for (int k=0;k<givenSpan;k++)
916 interArray[k] = orig[k];
917 int span = givenSpan/2;
918 while (span > 0)
919 {
920 for (int k=0;k<span;k++)
921 {
922 wavelets[k] = interArray[2*k];// + interArray[2*k + 1])/2.f;
923 wavelets[k + span] = interArray[2*k + 1] - interArray[2*k];//)/2.f;
924 }
925 for (int k=0;k<givenSpan;k++)
926 interArray[k] = wavelets[k];
927 span /= 2;
928 }
929 //move float results to int16_t array
930 float intScaling = 1.f;
931 int max = 0;
932 for (int i=0;i<givenSpan;i++)
933 {
934 float cValue = intScaling*wavelets[i];//
935 if (cValue > 0)
936 cValue += 0.5f;
937 else
938 cValue -= 0.5f;
939 wavelets_in[i] = (int16_t)(cValue);
940 if (fabs(cValue) > 32767.f)
941 {
942 cout << "Overflow ! " << cValue << endl;
943 }
944 if (fabs(cValue) > fabs(max))
945 max = cValue;
946 }
947// cout << "Max wave value: " << max << endl;
948 //result reconstruction and checking
949 if (!verifyResult)
950 return true;
951
952 for (int k=0;k<givenSpan;k++)
953 {
954 resultArray[k] = wavelets_in[k]/intScaling;
955 }
956
957 span = 1;
958 while (span < givenSpan)
959 {
960 for (int k=0;k<givenSpan;k++)
961 interArray[k] = resultArray[k];
962 for (int k=0;k<span;k++)
963 {
964 resultArray[2*k] = (float)(((interArray[k])*(1.f/1.f)) + 0.0f);
965 resultArray[2*k + 1] = (float)(((interArray[k] + interArray[k + span])*(1.f/1.f)) + 0.0f);
966 }
967 span *= 2;
968 }
969
970 for (int k=0;k<givenSpan;k++)
971 {
972 float plus = 0.5f;
973 if (resultArray[k] < 0)
974 plus *= -1.f;
975 if ((int)(resultArray[k]+plus) != (int)(orig_in[k]))
976 {
977 cout << "Nop, sorry: k: " << k << " " << resultArray[k] << " " << (int)(resultArray[k]+plus) << " " << plus << " " << orig[k] << endl;
978 return false;
979 }
980 }
981 delete[] interArray;
982 delete[] resultArray;
983 delete[] orig;
984 delete[] wavelets;
985 return true;
986}
987
988void RawDataViewer::doWaveLetOnCurrentEventPlease()
989{
990 int16_t* origTheWayIWant = new int16_t[1024*1440];
991
992// int numPixels = 1024;
993// int leftOver = 1440-numPixels;
994 for (int k=0;k<1024;k++)
995 for (int j=0;j<1440;j++)
996 {
997 origTheWayIWant[k*1440 + j] = rawEventData[j + k*1440];
998 }
999
1000 int waveSpan = 1024;
1001 int waveToPixelsRatio = 32;
1002 waveSpan = waveSpan*waveToPixelsRatio;
1003 int totalNumSamples = 1024*1440;
1004 int j=0;
1005 for (;j<totalNumSamples;j+= waveSpan)
1006 {
1007 if (j + waveSpan < totalNumSamples)
1008 if (!doWaveLetsPlease(waveSpan, &origTheWayIWant[j], &waveLetArray[j], true))
1009 return;
1010 }
1011
1012 while (j%1440 != 0)
1013 {
1014 int lastRun = 1;
1015 while (lastRun < 1440 - j%1440)
1016 lastRun *= 2;
1017 lastRun /= 2;
1018 if (lastRun > 2)
1019 {
1020 doWaveLetsPlease(lastRun, &origTheWayIWant[j], &waveLetArray[j], true);
1021 }
1022 else
1023 {
1024 for (int l=0;l<lastRun;l++)
1025 waveLetArray[j+l] = origTheWayIWant[j+l];
1026 }
1027 if (!lastRun)
1028 break;
1029 j += lastRun;
1030 }
1031
1032 delete[] origTheWayIWant;
1033
1034}
1035void RawDataViewer::doMyWaveletTestPlease()
1036{
1037// cout << "Size of float: " << sizeof(float) << endl;
1038 return;
1039 ofstream outBin("/scratch/bin/outputBin.bin", ios_base::out | ios_base::binary);
1040 ofstream outWave("/scratch/bin/outputWave.bin", ios_base::out | ios_base::binary);
1041 int16_t* waveLetArray_ = new int16_t[1024*1440];
1042 int16_t* origTheWayIWant = new int16_t[1024*1440];
1043
1044 for (int i=0;i<nRows;i++)
1045 {
1046 cout << '\r' << "Doing row " << i << " of " << nRows;
1047 cout.flush();
1048 inputFile->GetRow(i);
1049 outBin.write((const char*)(rawEventData), 1440*1024*2);
1050
1051// int numPixels = 1024;
1052// int leftOver = 1440-numPixels;
1053 for (int k=0;k<1024;k++)
1054 for (int j=0;j<1440;j++)
1055 {
1056 origTheWayIWant[k*1440 + j] = rawEventData[j + k*1440];
1057 }
1058
1059 int waveSpan = 1024;
1060 int waveToPixelsRatio = 32;
1061 waveSpan = waveSpan*waveToPixelsRatio;
1062 int totalNumSamples = 1024*1440;
1063 int j=0;
1064 for (;j<totalNumSamples;j+= waveSpan)//1440/waveToPixelsRatio;j++)
1065 {
1066 if (j + waveSpan < totalNumSamples)
1067 if (!doWaveLetsPlease(waveSpan, &origTheWayIWant[j], &waveLetArray_[j], true))
1068 return;
1069 }
1070
1071 while (j%1440 != 0)// < totalNumSamples)
1072 {
1073 cout << "Copying the remaining of the data" << endl;
1074 int lastRun = 1;
1075 while (lastRun < 1440 - j%1440)//totalNumSamples-j)
1076 lastRun *= 2;
1077 lastRun /= 2;
1078 if (lastRun > 2)
1079 {
1080// cout << " Doint one last run of " << lastRun << " samples" << endl;
1081 doWaveLetsPlease(lastRun, &origTheWayIWant[j], &waveLetArray_[j], true);
1082 }
1083 else
1084 {
1085// cout << " Filling in " << lastRun << " samples" << endl;
1086 for (int l=0;l<lastRun;l++)
1087 waveLetArray_[j+l] = origTheWayIWant[j+l];
1088 }
1089 if (!lastRun)
1090 break;
1091 j += lastRun;
1092 }
1093 outWave.write((const char*)(waveLetArray_), 1440*1024*2);
1094 }
1095 outWave.close();
1096 outBin.close();
1097 inputFile->GetRow(0);
1098
1099 delete[] waveLetArray_;
1100 delete[] origTheWayIWant;
1101}
1102void RawDataViewer::openCalibFile(string& file)
1103{
1104 //calibrationLoaded = false;
1105
1106 string msg;
1107 try
1108 {
1109 msg = fDrsCalib.ReadFitsImp(file);
1110 if (msg.empty())
1111 {
1112 emit newFileLoaded();
1113 updateGL();
1114 return;
1115 }
1116 }
1117 catch (const runtime_error &e)
1118 {
1119 msg = e.what();
1120 }
1121
1122 cerr << msg << endl;
1123 fDrsCalib.Clear();
1124}
1125
1126/************************************************************
1127 * PLUS EVENT
1128 ************************************************************/
1129void RawDataViewer::plusEvent()
1130{
1131 eventStepping(true);
1132}
1133/************************************************************
1134 * MINUS EVENT
1135 ************************************************************/
1136void RawDataViewer::minusEvent()
1137{
1138 eventStepping(false);
1139}
1140/************************************************************
1141 * SET EVENT STEP
1142 ************************************************************/
1143void RawDataViewer::setEventStep(int step)
1144{
1145 eventStep = step;
1146}
1147/************************************************************
1148 * EVENT STEPPING
1149 ************************************************************/
1150
1151void RawDataViewer::ApplyCalibration()
1152{
1153 for (int i=0;i<1440*nRoi + 160*nRoiTM;i++)//(1440+160)*nRoi;i++)
1154 eventData[i] = (float)rawEventData[i];
1155
1156 if (fIsDrsCalibration)
1157 {
1158 fDrsCalib.Apply(eventData, rawEventData, startPix, nRoi);
1159 DrsCalibrate::RemoveSpikes(eventData, nRoi);
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
2214 for (int i=0;i<GLWindow->nRoi;i++)
2215 {
2216 xval[i] = i;
2217#ifdef LOAD_RAW
2218 yval[i] = eventsData[0][pixel][i];
2219#else
2220 yval[i] = GLWindow->eventData[GLWindow->nRoi*pixel + i];
2221#endif
2222 }
2223int realNumSamples = GLWindow->nRoi;
2224 if (GLWindow->nRoiTM != 0)
2225 {
2226 const PixelMapEntry& mapEntry = GLWindow->fPixelMap.index(softwarePix);
2227 const int pixelIdInPatch = mapEntry.pixel();
2228 const int patchId = mapEntry.patch();
2229 const int boardId = mapEntry.board();
2230 const int crateId = mapEntry.crate();
2231 if (pixelIdInPatch == 8)
2232 {
2233 int TMIndex = 0;
2234 int xIndex = GLWindow->nRoi;
2235 int arrayIndex = GLWindow->nRoi;
2236 if (GLWindow->offSetRoi < 0)
2237 TMIndex -= GLWindow->offSetRoi;
2238 if (GLWindow->offSetRoi > 0)
2239 xIndex += GLWindow->offSetRoi;
2240 for (int i=TMIndex;i<GLWindow->nRoiTM;i++, xIndex++, arrayIndex++)
2241 {
2242 xval[arrayIndex] = xIndex;
2243 yval[arrayIndex] = GLWindow->eventData[GLWindow->nRoi*1440 + GLWindow->nRoiTM*(40*crateId + 4*boardId + patchId) + i];
2244 }
2245 // realNumSamples += GLWindow->nRoiTM - TMIndex;
2246 }
2247 cout << pixelIdInPatch << " " ;
2248 }
2249//cout << realNumSamples << endl;
2250 // GLWindow->computePulsesStatistics();
2251#if QWT_VERSION < 0x060000
2252 pixelValueCurveItem.setData(xval, yval, realNumSamples);
2253//// aMeanCurveItem.setData(xval, GLWindow->aMeas, GLWindow->nRoi);
2254 // meanCurveItem.setData(xval, GLWindow->n1mean, GLWindow->nRoi);
2255 // vCorrCurveItem.setData(xval, GLWindow->vCorr, GLWindow->nRoi-3);
2256#else
2257 pixelValueCurveItem.setSamples(xval, yval, realNumSamples);
2258// aMeanCurveItem.setSamples(xval, GLWindow->aMeas, GLWindow->nRoi);
2259 // meanCurveItem.setSamples(xval, GLWindow->n1mean, GLWindow->nRoi);
2260 // vCorrCurveItem.setSamples(xval, GLWindow->vCorr, GLWindow->nRoi-3);
2261#endif
2262
2263
2264 QStack< QRectF > stack;
2265 stack.push(scaleBoundingRectangle(pixelValueCurveItem.boundingRect(), 1.5f));
2266 curveZoom->setZoomStack(stack);
2267 stack.pop();
2268
2269 displaySliceValue();
2270 on_autoScaleColor_clicked();
2271}
2272
2273void UIConnector::on_HwIDBox_valueChanged(int)
2274{
2275 updating = true;
2276
2277 const int hwID = HwIDBox->value();
2278
2279 const int crateID = hwID/360;
2280 const int boardID = (hwID%360)/36;
2281 const int patchID = (hwID%36 )/9;
2282 const int pixelID = hwID%9;
2283
2284 SwIDBox->setValue(GLWindow->softwareMapping[hwID]);
2285
2286 crateIDBox->setValue(crateID);
2287 boardIDBox->setValue(boardID);
2288 patchIDBox->setValue(patchID);
2289 pixelIDBox->setValue(pixelID);
2290
2291 updating = false;
2292
2293 GLWindow->selectedPixel = GLWindow->softwareMapping[hwID];
2294 GLWindow->updateGL();
2295
2296 pixelChanged(GLWindow->selectedPixel);
2297}
2298
2299void UIConnector::cbpxChanged()
2300{
2301 if (updating)
2302 return;
2303
2304 const int hwid = crateIDBox->value()*360 + boardIDBox->value()*36 + patchIDBox->value()*9 + pixelIDBox->value();
2305 HwIDBox->setValue(hwid);
2306}
2307
2308void UIConnector::on_SwIDBox_valueChanged(int swid)
2309{
2310 if (updating)
2311 return;
2312
2313 HwIDBox->setValue(GLWindow->hardwareMapping[swid]);
2314}
2315
2316void UIConnector::on_autoScaleColor_clicked()
2317{
2318 if (!autoScaleColor->isChecked())
2319 {
2320 GLWindow->ss[0] = 0.496;
2321 GLWindow->ss[1] = 0.507;
2322 GLWindow->ss[2] = 0.518;
2323 GLWindow->ss[3] = 0.529;
2324 GLWindow->ss[4] = 0.540;;
2325 colorRange0->setValue(GLWindow->ss[0]);
2326 colorRange1->setValue(GLWindow->ss[1]);
2327 colorRange2->setValue(GLWindow->ss[2]);
2328 colorRange3->setValue(GLWindow->ss[3]);
2329 colorRange4->setValue(GLWindow->ss[4]);
2330 return;
2331 }
2332 if (!GLWindow->nRoi)
2333 return;
2334
2335 int start = 0;
2336 int end = 1440;
2337
2338 if (!entireCameraScale->isChecked())
2339 {
2340 start = GLWindow->selectedPixel;
2341 end = GLWindow->selectedPixel+1;
2342 if (end == 0)
2343 {
2344 start = 0;
2345 end = 1440;
2346 }
2347 }
2348
2349 int min = 100000; //real min = -2048, int_16 = -32768 to 32767
2350 int max = -100000; //real max = 2047
2351
2352 long average = 0;
2353 long numSamples = 0;
2354 int errorDetected = -1;
2355
2356 for (int i=start;i<end;i++)
2357 {
2358 for (int j=0;j<GLWindow->nRoi;j++)
2359 {
2360 int cValue = GLWindow->eventData[i*GLWindow->nRoi+j];
2361 if (cValue > max && cValue < 32767)
2362 max = cValue;
2363 if (cValue < min && cValue > -32768)
2364 min = cValue;
2365 if (cValue < 32767 && cValue > -32768)
2366 {
2367 average+=cValue;
2368 numSamples++;
2369 }
2370 else
2371 {
2372 errorDetected = i;
2373 }
2374// numSamples++;
2375 }
2376 }
2377 average /= numSamples;
2378 if (errorDetected != -1)
2379 {
2380 cout << "Overflow detected at pixel " << errorDetected << " (at least)" << endl;
2381 }
2382// cout << "min: " << min << " max: " << max << " average: " << average << endl;
2383 double minRange = (double)(min+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2384 double maxRange = (double)(max+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2385 double midRange = (double)(average+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2386 if (GLWindow->logScale)
2387 {
2388 minRange *= 9;
2389 maxRange *= 9;
2390// midRange *= 9;
2391 minRange += 1;
2392 maxRange += 1;
2393// midRange += 1;
2394 minRange = log10(minRange);
2395 maxRange = log10(maxRange);
2396// midRange = (minRange + maxRange)/2.f;
2397 midRange = log10(midRange);
2398 }
2399
2400 GLWindow->ss[0] = minRange;
2401 colorRange0->setValue(GLWindow->ss[0]);
2402 GLWindow->ss[4] = maxRange;
2403 colorRange4->setValue(GLWindow->ss[4]);
2404// GLWindow->ss[2] = midRange;
2405// range2->setValue(GLWindow->ss[2]);
2406// GLWindow->ss[1] = (minRange+midRange)/2;
2407// range1->setValue(GLWindow->ss[1]);
2408// GLWindow->ss[3] = (maxRange+midRange)/2;
2409// range3->setValue(GLWindow->ss[3]);
2410
2411 GLWindow->ss[2] = (maxRange+minRange)/2;
2412 colorRange2->setValue(GLWindow->ss[2]);
2413
2414 GLWindow->ss[1] = minRange+(maxRange-minRange)/4;
2415 colorRange1->setValue(GLWindow->ss[1]);
2416
2417 GLWindow->ss[3] = minRange+3*(maxRange-minRange)/4;
2418 colorRange3->setValue(GLWindow->ss[3]);
2419}
2420
2421void PrintUsage()
2422{
2423 cout << "\n"
2424 "The FACT++ raw data viewer.\n"
2425 "\n"
2426 "Usage: viewer [OPTIONS] [datafile.fits[.gz] [calibration.drs.fits[.gz]]]\n"
2427 " or: viewer [OPTIONS]\n";
2428 cout << endl;
2429
2430}
2431
2432void PrintHelp()
2433{
2434 cout <<
2435 "\n"
2436 << endl;
2437}
2438
2439int UIConnector::SetupConfiguration(Configuration &conf)
2440{
2441 RawDataViewer *canvas = GLWindow;
2442
2443 if (conf.Has("color.range"))
2444 {
2445 vector<double> value = conf.Vec<double>("color.range");
2446 if (value.size() != 5)
2447 {
2448 cout << "Error, colorRange option should have exactly 5 double values" << endl;
2449 return -1;
2450 }
2451 for (int i=0;i<5;i++)
2452 canvas->ss[i] = value[i];
2453 }
2454
2455 if (conf.Has("color.red"))
2456 {
2457 vector<double> value = conf.Vec<double>("color.red");
2458 if (value.size() != 5)
2459 {
2460 cout << "Error, colorRed option should have exactly 5 double values" << endl;
2461 return -1;
2462 }
2463 for (int i=0;i<5;i++)
2464 canvas->rr[i] = value[i];
2465 }
2466
2467 if (conf.Has("color.green"))
2468 {
2469 vector<double> value = conf.Vec<double>("color.green");
2470 if (value.size() != 5)
2471 {
2472 cout << "Error, colorGreen option should have exactly 5 double values" << endl;
2473 return -1;
2474 }
2475 for (int i=0;i<5;i++)
2476 canvas->gg[i] = value[i];
2477 }
2478
2479 if (conf.Has("color.blue"))
2480 {
2481 vector<double> value = conf.Vec<double>("color.blue");
2482 if (value.size() != 5)
2483 {
2484 cout << "Error, colorBlue option should have exactly 5 double values" << endl;
2485 return -1;
2486 }
2487 for (int i=0;i<5;i++)
2488 canvas->bb[i] = value[i];
2489 }
2490
2491 colorRange0->setValue(canvas->ss[0]);
2492 colorRange1->setValue(canvas->ss[1]);
2493 colorRange2->setValue(canvas->ss[2]);
2494 colorRange3->setValue(canvas->ss[3]);
2495 colorRange4->setValue(canvas->ss[4]);
2496 redValue0->setValue(canvas->rr[0]);
2497 redValue1->setValue(canvas->rr[1]);
2498 redValue2->setValue(canvas->rr[2]);
2499 redValue3->setValue(canvas->rr[3]);
2500 redValue4->setValue(canvas->rr[4]);
2501 greenValue0->setValue(canvas->gg[0]);
2502 greenValue1->setValue(canvas->gg[1]);
2503 greenValue2->setValue(canvas->gg[2]);
2504 greenValue3->setValue(canvas->gg[3]);
2505 greenValue4->setValue(canvas->gg[4]);
2506 blueValue0->setValue(canvas->bb[0]);
2507 blueValue1->setValue(canvas->bb[1]);
2508 blueValue2->setValue(canvas->bb[2]);
2509 blueValue3->setValue(canvas->bb[3]);
2510 blueValue4->setValue(canvas->bb[4]);
2511
2512 if (conf.Has("drs"))
2513 {
2514 const QString qstr(conf.Get<string>("drs").c_str());
2515 calibFileSelected(qstr);
2516 }
2517
2518 if (conf.Has("file"))
2519 {
2520 const QString qstr(conf.Get<string>("file").c_str());
2521 fileSelected(qstr);
2522 }
2523
2524
2525 return 0;
2526}
2527
2528void SetupConfiguration(Configuration& conf)
2529{
2530 po::options_description configs("Raw Events Viewer Options");
2531 configs.add_options()
2532 ("color.range", vars<double>(), "Range of the display colours")
2533 ("color.red", vars<double>(), "Range of red values")
2534 ("color.green", vars<double>(), "Range of green values")
2535 ("color.blue", vars<double>(), "Range of blue values")
2536 ("file,f", var<string>(), "File to be loaded")
2537 ("drs,d", var<string>(), "DRS calibration file to be loaded")
2538 ;
2539 conf.AddOptions(configs);
2540
2541 po::positional_options_description p;
2542 p.add("file", 1); // The first positional options
2543 p.add("drs", 2); // The first positional options
2544 conf.SetArgumentPositions(p);
2545
2546}
2547
2548/************************************************************
2549 * MAIN PROGRAM FUNCTION.
2550 ************************************************************/
2551int main(int argc, const char *argv[])
2552{
2553 QApplication app(argc, const_cast<char**>(argv));
2554
2555 if (!QGLFormat::hasOpenGL()) {
2556 std::cerr << "This system has no OpenGL support" << std::endl;
2557 return 1;
2558 }
2559
2560 Configuration conf(argv[0]);
2561 conf.SetPrintUsage(PrintUsage);
2562 SetupConfiguration(conf);
2563 if (!conf.DoParse(argc, argv, PrintHelp))
2564 return 2;
2565
2566 UIConnector myUi;
2567 if (myUi.SetupConfiguration(conf)<0)
2568 return 3;
2569
2570 return app.exec();
2571}
2572
Note: See TracBrowser for help on using the repository browser.