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

Last change on this file since 12412 was 12395, checked in by lyard, 14 years ago
added separate TM display, and remove TMs from RMS calculation
File size: 80.2 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 eventNum = 0;
501 rowNum = -1;
502 eventStep = 1;
503 selectedPixel = 393;
504 inputFile = NULL;
505 eventData = NULL;
506 drawPatch = false;
507 drawImpulse = true;
508 drawBlur = false;
509 loopCurrentEvent = false;
510 fIsDrsCalibration = false;
511 SetAutoRefresh(true);
512#ifdef LOAD_RAW
513 loadEvents("/scratch/00000043.001_T.bin");
514#endif
515 PixelMap mypMap;
516 if (!mypMap.Read("FACTmap111030.txt"))
517 {
518 cerr << "ERROR - Problems reading FACTmap111030.txt" << endl;
519 exit(-1);
520 }
521
522 assignPixelMap(mypMap);
523 buildVerticesList();
524// for (int i=0;i<1440;i++)
525// updateNeighbors(i);
526
527 for (int i=0;i<160;i++)
528 {
529 const float color[3] = { 0.5, 0.5, 0.3 };
530
531 for (int j=0;j<3;j++)
532 patchesColor[i][j] = color[j];
533 }
534
535 //calibrationLoaded = false;
536 //drawCalibrationLoaded = false;
537
538}
539/************************************************************
540 * DESTRUCTOR
541 ************************************************************/
542RawDataViewer::~RawDataViewer()
543{
544 if (inputFile != NULL)
545 {
546 inputFile->close();
547 delete inputFile;
548 }
549 if (eventData != NULL) {
550 delete[] eventData;
551 delete[] rawEventData;
552 delete[] waveLetArray;
553 }
554}
555
556/************************************************************
557 * PAINT GL. main drawing function.
558 ************************************************************/
559void RawDataViewer::paintGL()
560{
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 << *it << " missing. Aborting load..." << endl;
719 return;}
720 }
721 catch (std::runtime_error e)
722 {
723 cout << e.what() << endl;
724 return;
725 }
726 }
727 nRows = inputFile->GetInt("NAXIS2");
728 nRoi = inputFile->GetInt("NROI");
729 runNumber = inputFile->GetInt("RUNID");
730 nTM = inputFile->HasKey("NTMARK") ? inputFile->GetInt("NTMARK") : 0;
731 runType = inputFile->HasKey("RUNTYPE") ? inputFile->GetInt("RUNTYPE") : -1;
732 firstDataTime = inputFile->GetInt("TSTART");
733 lastDataTime = inputFile->GetInt("TSTOP");
734 nRoiTM = inputFile->GetInt("NROITM");
735 revision = inputFile->GetInt("REVISION");
736 builderVersion = inputFile->HasKey("BLDVER") ? inputFile->GetInt("BLDVER") : -1;
737 nBoards = inputFile->GetInt("NBOARD");
738 nPixels = inputFile->GetInt("NPIX");
739 timeSystem = inputFile->GetStr("TIMESYS");
740 creationDate = inputFile->GetStr("DATE");
741 nightInt = inputFile->GetInt("NIGHT");
742 camera = inputFile->GetStr("CAMERA");
743 daq = inputFile->GetStr("DAQ");
744 adcCount = inputFile->HasKey("ADCRANGE") ? inputFile->GetFloat("ADCRANGE") : 2000;
745 nbOk = 0;//inputFile->GetInt("NBEVTOK");
746 nbRej = 0;//inputFile->GetInt("NBEVTREJ");
747 nbBad = 0;//inputFile->GetInt("NBEVTBAD");
748
749 eventNum = 0;
750
751#ifdef LOAD_RAW
752 nRows = NUM_STORED_EVENTS;
753#endif
754
755 if (eventData != NULL) {
756 delete[] eventData;
757 delete[] rawEventData;
758 delete[] waveLetArray;
759 }
760 eventData = new float[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
761
762 rawEventData = new int16_t[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
763 waveLetArray = new int16_t[1024*1440];
764 try
765 {
766 inputFile->SetPtrAddress("Data", rawEventData);
767 inputFile->SetPtrAddress("EventNum", &eventNum);
768 inputFile->SetPtrAddress("TriggerType", &triggerType);
769 inputFile->SetPtrAddress("SoftTrig", &softTrig);
770 inputFile->SetPtrAddress("BoardTime", boardTime);
771 inputFile->SetPtrAddress("StartCellData", startPix);
772 inputFile->SetPtrAddress("StartCellTimeMarker", startTM);
773 inputFile->SetPtrAddress("TimeMarker", &rawEventData[1440*nRoi]);
774 }
775 catch (const runtime_error &e)
776 {
777 cout << e.what() << endl;
778 cout << "Loading aborted." << endl;
779
780 nRoi = nRows = 0;
781
782 return;
783 }
784
785 try
786 {
787 pcTime[0] = pcTime[1] = 0;
788 inputFile->SetPtrAddress("UnixTimeUTC", pcTime);
789 }
790 catch (const runtime_error&)
791 {
792 try
793 {
794 inputFile->SetPtrAddress("PCTime", pcTime);
795 }
796 catch (const runtime_error&)
797 {
798
799 }
800 }
801
802
803 int backupStep = eventStep;
804 rowNum = -1;
805 eventStep = 1;
806
807 doMyWaveletTestPlease();
808
809
810 plusEvent();
811 eventStep = backupStep;
812 emit newFileLoaded();
813 emit signalCurrentPixel(selectedPixel);
814}
815/*
816bool RawDataViewer::doWaveLetsPlease(int givenSpan, int16_t* orig_in, int16_t* wavelets_in, bool verifyResult)
817{
818 float* interArray = new float[givenSpan];
819 float* resultArray = new float[givenSpan];
820 float* orig = new float[givenSpan];
821 float* wavelets = new float[givenSpan];
822 for (int i=0;i<givenSpan;i++)
823 {
824 if (fabs((float)(orig_in[i])) > 32767.f)
825 cout << "Input overflow: " << orig_in[i] << endl;
826 orig[i] = (float)orig_in[i];
827 }
828 for (int k=0;k<givenSpan;k++)
829 interArray[k] = orig[k];
830 int span = givenSpan/2;
831 while (span > 0)
832 {
833 for (int k=0;k<span;k++)
834 {
835 wavelets[k] = (interArray[2*k] + interArray[2*k + 1])/2.f;
836 wavelets[k + span] = (interArray[2*k + 1] - interArray[2*k])/2.f;
837 }
838 for (int k=0;k<givenSpan;k++)
839 interArray[k] = wavelets[k];
840 span /= 2;
841 }
842 //move float results to int16_t array
843 float intScaling = 15.9f;
844 int max = 0;
845 for (int i=0;i<givenSpan;i++)
846 {
847 float cValue = intScaling*wavelets[i];//
848 if (cValue > 0)
849 cValue += 0.5f;
850 else
851 cValue -= 0.5f;
852 wavelets_in[i] = (int16_t)(cValue);
853 if (fabs(cValue) > 32767.f)
854 {
855 cout << "Overflow ! " << cValue << endl;
856 }
857 if (fabs(cValue) > fabs(max))
858 max = cValue;
859 }
860// cout << "Max wave value: " << max << endl;
861 //result reconstruction and checking
862 if (!verifyResult)
863 return true;
864
865 for (int k=0;k<givenSpan;k++)
866 {
867 resultArray[k] = wavelets_in[k]/intScaling;
868 }
869
870 span = 1;
871 while (span < givenSpan)
872 {
873 for (int k=0;k<givenSpan;k++)
874 interArray[k] = resultArray[k];
875 for (int k=0;k<span;k++)
876 {
877 resultArray[2*k] = (float)(((interArray[k] - interArray[k + span])*(1.f/1.f)) + 0.0f);
878 resultArray[2*k + 1] = (float)(((interArray[k] + interArray[k + span])*(1.f/1.f)) + 0.0f);
879 }
880 span *= 2;
881 }
882
883 for (int k=0;k<givenSpan;k++)
884 {
885 float plus = 0.5f;
886 if (resultArray[k] < 0)
887 plus *= -1.f;
888 if ((int)(resultArray[k]+plus) != (int)(orig_in[k]))
889 {
890 cout << "Nop, sorry: k: " << k << " " << resultArray[k] << " " << (int)(resultArray[k]+plus) << " " << plus << " " << orig[k] << endl;
891 return false;
892 }
893 }
894 return true;
895}
896*/
897bool RawDataViewer::doWaveLetsPlease(int givenSpan, int16_t* orig_in, int16_t* wavelets_in, bool verifyResult)
898{
899 float* interArray = new float[givenSpan];
900 float* resultArray = new float[givenSpan];
901 float* orig = new float[givenSpan];
902 float* wavelets = new float[givenSpan];
903 for (int i=0;i<givenSpan;i++)
904 {
905 if (fabs((float)(orig_in[i])) > 32767.f)
906 cout << "Input overflow: " << orig_in[i] << endl;
907 orig[i] = (float)orig_in[i];
908 }
909 for (int k=0;k<givenSpan;k++)
910 interArray[k] = orig[k];
911 int span = givenSpan/2;
912 while (span > 0)
913 {
914 for (int k=0;k<span;k++)
915 {
916 wavelets[k] = interArray[2*k];// + interArray[2*k + 1])/2.f;
917 wavelets[k + span] = interArray[2*k + 1] - interArray[2*k];//)/2.f;
918 }
919 for (int k=0;k<givenSpan;k++)
920 interArray[k] = wavelets[k];
921 span /= 2;
922 }
923 //move float results to int16_t array
924 float intScaling = 1.f;
925 int max = 0;
926 for (int i=0;i<givenSpan;i++)
927 {
928 float cValue = intScaling*wavelets[i];//
929 if (cValue > 0)
930 cValue += 0.5f;
931 else
932 cValue -= 0.5f;
933 wavelets_in[i] = (int16_t)(cValue);
934 if (fabs(cValue) > 32767.f)
935 {
936 cout << "Overflow ! " << cValue << endl;
937 }
938 if (fabs(cValue) > fabs(max))
939 max = cValue;
940 }
941// cout << "Max wave value: " << max << endl;
942 //result reconstruction and checking
943 if (!verifyResult)
944 return true;
945
946 for (int k=0;k<givenSpan;k++)
947 {
948 resultArray[k] = wavelets_in[k]/intScaling;
949 }
950
951 span = 1;
952 while (span < givenSpan)
953 {
954 for (int k=0;k<givenSpan;k++)
955 interArray[k] = resultArray[k];
956 for (int k=0;k<span;k++)
957 {
958 resultArray[2*k] = (float)(((interArray[k])*(1.f/1.f)) + 0.0f);
959 resultArray[2*k + 1] = (float)(((interArray[k] + interArray[k + span])*(1.f/1.f)) + 0.0f);
960 }
961 span *= 2;
962 }
963
964 for (int k=0;k<givenSpan;k++)
965 {
966 float plus = 0.5f;
967 if (resultArray[k] < 0)
968 plus *= -1.f;
969 if ((int)(resultArray[k]+plus) != (int)(orig_in[k]))
970 {
971 cout << "Nop, sorry: k: " << k << " " << resultArray[k] << " " << (int)(resultArray[k]+plus) << " " << plus << " " << orig[k] << endl;
972 return false;
973 }
974 }
975 delete[] interArray;
976 delete[] resultArray;
977 delete[] orig;
978 delete[] wavelets;
979 return true;
980}
981
982void RawDataViewer::doWaveLetOnCurrentEventPlease()
983{
984 int16_t* origTheWayIWant = new int16_t[1024*1440];
985
986// int numPixels = 1024;
987// int leftOver = 1440-numPixels;
988 for (int k=0;k<1024;k++)
989 for (int j=0;j<1440;j++)
990 {
991 origTheWayIWant[k*1440 + j] = rawEventData[j + k*1440];
992 }
993
994 int waveSpan = 1024;
995 int waveToPixelsRatio = 32;
996 waveSpan = waveSpan*waveToPixelsRatio;
997 int totalNumSamples = 1024*1440;
998 int j=0;
999 for (;j<totalNumSamples;j+= waveSpan)
1000 {
1001 if (j + waveSpan < totalNumSamples)
1002 if (!doWaveLetsPlease(waveSpan, &origTheWayIWant[j], &waveLetArray[j], true))
1003 return;
1004 }
1005
1006 while (j%1440 != 0)
1007 {
1008 int lastRun = 1;
1009 while (lastRun < 1440 - j%1440)
1010 lastRun *= 2;
1011 lastRun /= 2;
1012 if (lastRun > 2)
1013 {
1014 doWaveLetsPlease(lastRun, &origTheWayIWant[j], &waveLetArray[j], true);
1015 }
1016 else
1017 {
1018 for (int l=0;l<lastRun;l++)
1019 waveLetArray[j+l] = origTheWayIWant[j+l];
1020 }
1021 if (!lastRun)
1022 break;
1023 j += lastRun;
1024 }
1025
1026 delete[] origTheWayIWant;
1027
1028}
1029void RawDataViewer::doMyWaveletTestPlease()
1030{
1031// cout << "Size of float: " << sizeof(float) << endl;
1032 return;
1033 ofstream outBin("/scratch/bin/outputBin.bin", ios_base::out | ios_base::binary);
1034 ofstream outWave("/scratch/bin/outputWave.bin", ios_base::out | ios_base::binary);
1035 int16_t* waveLetArray_ = new int16_t[1024*1440];
1036 int16_t* origTheWayIWant = new int16_t[1024*1440];
1037
1038 for (int i=0;i<nRows;i++)
1039 {
1040 cout << '\r' << "Doing row " << i << " of " << nRows;
1041 cout.flush();
1042 inputFile->GetRow(i);
1043 outBin.write((const char*)(rawEventData), 1440*1024*2);
1044
1045// int numPixels = 1024;
1046// int leftOver = 1440-numPixels;
1047 for (int k=0;k<1024;k++)
1048 for (int j=0;j<1440;j++)
1049 {
1050 origTheWayIWant[k*1440 + j] = rawEventData[j + k*1440];
1051 }
1052
1053 int waveSpan = 1024;
1054 int waveToPixelsRatio = 32;
1055 waveSpan = waveSpan*waveToPixelsRatio;
1056 int totalNumSamples = 1024*1440;
1057 int j=0;
1058 for (;j<totalNumSamples;j+= waveSpan)//1440/waveToPixelsRatio;j++)
1059 {
1060 if (j + waveSpan < totalNumSamples)
1061 if (!doWaveLetsPlease(waveSpan, &origTheWayIWant[j], &waveLetArray_[j], true))
1062 return;
1063 }
1064
1065 while (j%1440 != 0)// < totalNumSamples)
1066 {
1067 cout << "Copying the remaining of the data" << endl;
1068 int lastRun = 1;
1069 while (lastRun < 1440 - j%1440)//totalNumSamples-j)
1070 lastRun *= 2;
1071 lastRun /= 2;
1072 if (lastRun > 2)
1073 {
1074// cout << " Doint one last run of " << lastRun << " samples" << endl;
1075 doWaveLetsPlease(lastRun, &origTheWayIWant[j], &waveLetArray_[j], true);
1076 }
1077 else
1078 {
1079// cout << " Filling in " << lastRun << " samples" << endl;
1080 for (int l=0;l<lastRun;l++)
1081 waveLetArray_[j+l] = origTheWayIWant[j+l];
1082 }
1083 if (!lastRun)
1084 break;
1085 j += lastRun;
1086 }
1087 outWave.write((const char*)(waveLetArray_), 1440*1024*2);
1088 }
1089 outWave.close();
1090 outBin.close();
1091 inputFile->GetRow(0);
1092
1093 delete[] waveLetArray_;
1094 delete[] origTheWayIWant;
1095}
1096void RawDataViewer::openCalibFile(string& file)
1097{
1098 //calibrationLoaded = false;
1099
1100 string msg;
1101 try
1102 {
1103 msg = fDrsCalib.ReadFitsImp(file);
1104 if (msg.empty())
1105 {
1106 emit newFileLoaded();
1107 updateGL();
1108 return;
1109 }
1110 }
1111 catch (const runtime_error &e)
1112 {
1113 msg = e.what();
1114 }
1115
1116 cerr << msg << endl;
1117 fDrsCalib.Clear();
1118}
1119
1120/************************************************************
1121 * PLUS EVENT
1122 ************************************************************/
1123void RawDataViewer::plusEvent()
1124{
1125 eventStepping(true);
1126}
1127/************************************************************
1128 * MINUS EVENT
1129 ************************************************************/
1130void RawDataViewer::minusEvent()
1131{
1132 eventStepping(false);
1133}
1134/************************************************************
1135 * SET EVENT STEP
1136 ************************************************************/
1137void RawDataViewer::setEventStep(int step)
1138{
1139 eventStep = step;
1140}
1141/************************************************************
1142 * EVENT STEPPING
1143 ************************************************************/
1144
1145void RawDataViewer::ApplyCalibration()
1146{
1147 for (int i=0;i<1440*nRoi + 160*nRoiTM;i++)//(1440+160)*nRoi;i++)
1148 eventData[i] = (float)rawEventData[i];
1149
1150 if (fIsDrsCalibration)
1151 {
1152 fDrsCalib.Apply(eventData, rawEventData, startPix, nRoi);
1153 DrsCalibrate::RemoveSpikes(eventData, nRoi);
1154 //TODO apply calibration to the Time markers
1155 }
1156
1157 //hide the time markers
1158 int nSlicesToRemove = 60;
1159 float* backupData;
1160 if (nRoiTM == 0) //they are written into the regular channel
1161 {
1162 backupData = new float[nSlicesToRemove*160];
1163 for (int i=0;i<1440;i++)
1164 {
1165 const PixelMapEntry& mapEntry = fPixelMap.index(i);
1166 const int pixelIdInPatch = mapEntry.pixel();
1167 const int patchId = mapEntry.patch();
1168 const int boardId = mapEntry.board();
1169 const int crateId = mapEntry.crate();
1170
1171 const int hw = mapEntry.hw();
1172 if (pixelIdInPatch == 8)
1173 {
1174 // cout << patchId << " ";
1175 for (int j=0;j<nSlicesToRemove;j++)
1176 {
1177 backupData[(40*crateId + 4*boardId + patchId)*nSlicesToRemove+j] = eventData[(hw*nRoi) + (nRoi-nSlicesToRemove) + j];
1178 eventData[(hw*nRoi) + (nRoi-nSlicesToRemove) + j] = eventData[hw*nRoi + (nRoi-nSlicesToRemove) - 1];
1179 }
1180 }
1181 }
1182 }
1183
1184 vector<float> pixelStatsData(1440*4);
1185 DrsCalibrate::GetPixelStats(pixelStatsData.data(), eventData, nRoi);
1186
1187 for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
1188 RMSvalues[it->index] = pixelStatsData[1*1440+it->hw()];
1189
1190 if (nRoiTM == 0)//move back the data back in place
1191 {
1192 for (int i=0;i<1440;i++)
1193 {
1194 const PixelMapEntry& mapEntry = fPixelMap.index(i);
1195 const int pixelIdInPatch = mapEntry.pixel();
1196 const int patchId = mapEntry.patch();
1197 const int boardId = mapEntry.board();
1198 const int crateId = mapEntry.crate();
1199 if (patchId > 160)
1200 cout << "Voila mon probleme: " << patchId << endl;
1201 const int hw = mapEntry.hw();
1202 if (pixelIdInPatch == 8)
1203 {
1204 // cout << "|" << crateId << " " << boardId << " " << patchId << " " << hw << "| ";
1205 for (int j=0;j<nSlicesToRemove;j++)
1206 {
1207 eventData[(hw*nRoi) + (nRoi - nSlicesToRemove) + j] = backupData[(40*crateId + 4*boardId + patchId)*nSlicesToRemove+j];
1208 }
1209 }
1210 }
1211 delete[] backupData;
1212 }
1213 if (isVisible())
1214 updateGL();
1215}
1216
1217void RawDataViewer::eventStepping(bool plus)
1218{
1219 if (plus)
1220 rowNum += eventStep;
1221 else
1222 rowNum -= eventStep;
1223 if (rowNum >= nRows)
1224 rowNum -= nRows;
1225 if (rowNum < 0)
1226 rowNum += nRows;
1227#ifdef LOAD_RAW
1228 eventNum+=eventStep;
1229#else
1230 if (inputFile == NULL)
1231 return;
1232 inputFile->GetRow(rowNum);
1233// cout << "Getting row " << rowNum << endl;
1234#endif
1235
1236 ApplyCalibration();
1237
1238 emit signalCurrentEvent(eventNum);
1239 emit signalCurrentPixel(selectedPixel);
1240}
1241
1242/************************************************************
1243 * NEXT SLICE. deprec ?
1244 ************************************************************/
1245void RawDataViewer::nextSlice()
1246{
1247 whichSlice++;
1248 if (whichSlice >= nRoi)
1249 {
1250 whichSlice = 0;
1251 if (!loopCurrentEvent)
1252 {
1253 int backupStep = eventStep;
1254 eventStep = 1;
1255 eventStepping(true);
1256 eventStep = backupStep;
1257 }
1258 }
1259 emit signalCurrentSlice(whichSlice);
1260 updateGL();
1261}
1262void RawDataViewer::previousSlice()
1263{
1264 whichSlice--;
1265 if (whichSlice < 0)
1266 {
1267 whichSlice = nRoi-1;
1268 if (!loopCurrentEvent)
1269 {
1270 int backupStep = eventStep;
1271 eventStep = 1;
1272 eventStepping(false);
1273 eventStep = backupStep;
1274 }
1275 }
1276 emit signalCurrentSlice(whichSlice);
1277 updateGL();
1278}
1279void RawDataViewer::setCurrentPixel(int pix)
1280{
1281 // if (pix == -1)
1282 // return;
1283 selectedPixel = pix;
1284 if (isVisible())
1285 updateGL();
1286 emit signalCurrentPixel(pix);
1287}
1288void RawDataViewer::computePulsesStatistics()
1289{
1290 if (!inputFile)
1291 {
1292 cout << "A FITS file must be open in order to complete this operation" << endl;
1293 return;
1294 }
1295
1296
1297// for (int i=0;i<nRows;i++)//for all events
1298// {
1299// inputFile->GetRow(rowNum);
1300// for (int i=0;i<(1440+160)*nRoi;i++)
1301// eventData[i] = (float)rawEventData[i];
1302
1303// for (int j=0;j<ACTUAL_NUM_PIXELS;j++)
1304/// {
1305 int j = selectedPixel;
1306 if (j == -1)
1307 return;
1308 for (int i=0;i<nRoi;i++)
1309 {
1310 aMeas[i] = eventData[j*nRoi+i];// * adcCount;
1311
1312 }
1313 for (int i=0;i<nRoi;i++)
1314 {
1315 if (i==0)
1316 n1mean[i] = aMeas[i+1];
1317 else
1318 {
1319 if (i==1023)
1320 n1mean[i] = aMeas[i-1];
1321 else
1322 n1mean[i] = (aMeas[i-1]+aMeas[i+1])/2.f;
1323 }
1324 }
1325 //find spike
1326 for (int i=0;i<nRoi-3;i++)
1327 {
1328 const float fract = 0.8f;
1329 float xx, xp, xpp;
1330 vCorr[i] = 0;//aMeas[i];
1331 xx = aMeas[i] - n1mean[i];
1332 if (xx < -8.f)
1333 {
1334 xp = aMeas[i+1] - n1mean[i+1];
1335 xpp = aMeas[i+2] - n1mean[i+2];
1336 if ((aMeas[i+2] - (aMeas[i] + aMeas[i+3])/2.f) > 10.f)
1337 {
1338 vCorr[i+1] = (aMeas[i] + aMeas[i+3])/2.f;
1339 vCorr[i+2] = (aMeas[i] + aMeas[i+3])/2.f;
1340 i = i+2;
1341 }
1342 else
1343 {
1344 if ((xp > -2.*xx*fract) && (xpp < -10.f))
1345 {
1346 vCorr[i+1] = n1mean[i+1];
1347 n1mean[i+2] = aMeas[i+1] - aMeas[i+3]/2.f;
1348 i++;
1349 }
1350 }
1351 }
1352 }
1353 for (int i=0;i<nRoi;i++)
1354 n1mean[i] = aMeas[i]-n1mean[i];
1355 // }
1356 // }
1357}
1358/************************************************************
1359 * UICONNECTOR CONSTRUCTOR
1360 ************************************************************/
1361UIConnector::UIConnector(QWidget *p)
1362{
1363 setupUi(this);
1364 initHistograms();
1365
1366 currentFile = "none";
1367 currentCalibFile = "none";
1368
1369 updateSpinnerDisplay = true;
1370 updating = false;
1371
1372 timer.setInterval(10.0);
1373 QObject::connect(&timer, SIGNAL(timeout()),
1374 this, SLOT(nextSlicePlease()));
1375
1376 QButtonGroup &scaleGroup = *new QButtonGroup(p);// = new QButtonGroup(canvas);
1377 QButtonGroup &animateGroup = *new QButtonGroup(p);// = new QButtonGroup(canvas);
1378
1379 scaleGroup.addButton(currentPixelScale);
1380 scaleGroup.addButton(entireCameraScale);
1381
1382 animateGroup.addButton(playEventsRadio);
1383 animateGroup.addButton(playSlicesRadio);
1384
1385 entireCameraScale->setChecked(true);
1386
1387 GLWindow_2->enableText(false);
1388 // GLWindow_2->ShowPatchCursor(true);
1389
1390 QObject::connect(GLWindow, SIGNAL(colorPaletteHasChanged()),
1391 this, SLOT(on_autoScaleColor_clicked()));
1392 QObject::connect(GLWindow, SIGNAL(signalCurrentSlice(int)),
1393 this, SLOT(currentSliceHasChanged(int)));
1394 QObject::connect(GLWindow, SIGNAL(signalCurrentEvent(int)),
1395 this, SLOT(currentEventHasChanged(int)));
1396 QObject::connect(GLWindow, SIGNAL(signalCurrentPixel(int)),
1397 this, SLOT(pixelChanged(int)));
1398 QObject::connect(GLWindow, SIGNAL(newFileLoaded()),
1399 this, SLOT(newFileLoaded()));
1400
1401 QObject::connect(GLWindow_2, SIGNAL(signalCurrentPixel(int)),
1402 GLWindow, SLOT(setCurrentPixel(int)));
1403
1404
1405 show();
1406}
1407UIConnector::~UIConnector()
1408{
1409 grid1->detach();
1410 grid2->detach();
1411 grid3->detach();
1412 grid4->detach();
1413 grid5->detach();
1414 boardsTimeHistoItem.detach();
1415 startCellHistoItem.detach();
1416 startTimeMarkHistoItem.detach();
1417 pixelValueCurveItem.detach();
1418 aMeanCurveItem.detach();
1419 vCorrCurveItem.detach();
1420 meanCurveItem.detach();
1421}
1422void UIConnector::slicesPlusPlus()
1423{
1424 GLWindow->nextSlice();
1425}
1426void UIConnector::slicesMinusMinus()
1427{
1428 GLWindow->previousSlice();
1429}
1430void UIConnector::on_calibratedCheckBox_stateChanged(int state)
1431{
1432 GLWindow->fIsDrsCalibration = state;
1433 GLWindow->ApplyCalibration();
1434
1435 on_autoScaleColor_clicked();
1436 pixelChanged(GLWindow->selectedPixel);
1437
1438}
1439/************************************************************
1440 * DRAW PATCHES CHECK CHANGE. checkbox handler
1441 ************************************************************/
1442void UIConnector::on_drawPatchCheckBox_stateChanged(int state)
1443{
1444 GLWindow->drawPatch = state;
1445 GLWindow->updateGL();
1446}
1447/************************************************************
1448 * DRAW IMPULSE CHECK CHANGE. checkbox handler
1449 ************************************************************/
1450void UIConnector::on_drawImpulseCheckBox_stateChanged(int state)
1451{
1452 GLWindow->drawImpulse = state;
1453 GLWindow->updateGL();
1454}
1455/************************************************************
1456 * DRAW BLUR CHECK CHANGE. checkbox handler
1457 ************************************************************/
1458void UIConnector::on_drawBlurCheckBox_stateChanged(int state)
1459{
1460 GLWindow->drawBlur = state;
1461 GLWindow->updateGL();
1462}
1463void UIConnector::on_loopOverCurrentEventBox_stateChanged(int state)
1464{
1465 GLWindow->loopCurrentEvent = state;
1466}
1467
1468/************************************************************
1469 * NEXT SLICE PLEASE
1470 ************************************************************/
1471void UIConnector::nextSlicePlease()
1472{
1473 if (playEventsRadio->isChecked ())
1474 GLWindow->eventStepping(true);
1475 else
1476 GLWindow->nextSlice();
1477}
1478
1479/************************************************************
1480 * SET VIEWER.
1481 ************************************************************/
1482//void UIConnector::setViewer(RawDataViewer* v)
1483//{
1484// viewer = v;
1485//}
1486/************************************************************
1487 * SLICES PER SECOND CHANGED. timing ui handler
1488 ************************************************************/
1489void UIConnector::slicesPerSecondChanged(double value)
1490{
1491 timer.setInterval(1000.0/value);
1492}
1493
1494void UIConnector::on_colorRange0_valueChanged(double value) { GLWindow->ss[0] = (float)value; GLWindow->updateGL(); }
1495void UIConnector::on_colorRange1_valueChanged(double value) { GLWindow->ss[1] = (float)value; GLWindow->updateGL(); }
1496void UIConnector::on_colorRange2_valueChanged(double value) { GLWindow->ss[2] = (float)value; GLWindow->updateGL(); }
1497void UIConnector::on_colorRange3_valueChanged(double value) { GLWindow->ss[3] = (float)value; GLWindow->updateGL(); }
1498void UIConnector::on_colorRange4_valueChanged(double value) { GLWindow->ss[4] = (float)value; GLWindow->updateGL(); }
1499
1500void UIConnector::on_redValue0_valueChanged(double value) { GLWindow->rr[0] = (float)value; GLWindow->updateGL(); }
1501void UIConnector::on_redValue1_valueChanged(double value) { GLWindow->rr[1] = (float)value; GLWindow->updateGL(); }
1502void UIConnector::on_redValue2_valueChanged(double value) { GLWindow->rr[2] = (float)value; GLWindow->updateGL(); }
1503void UIConnector::on_redValue3_valueChanged(double value) { GLWindow->rr[3] = (float)value; GLWindow->updateGL(); }
1504void UIConnector::on_redValue4_valueChanged(double value) { GLWindow->rr[4] = (float)value; GLWindow->updateGL(); }
1505
1506void UIConnector::on_greenValue0_valueChanged(double value) { GLWindow->gg[0] = (float)value; GLWindow->updateGL(); }
1507void UIConnector::on_greenValue1_valueChanged(double value) { GLWindow->gg[1] = (float)value; GLWindow->updateGL(); }
1508void UIConnector::on_greenValue2_valueChanged(double value) { GLWindow->gg[2] = (float)value; GLWindow->updateGL(); }
1509void UIConnector::on_greenValue3_valueChanged(double value) { GLWindow->gg[3] = (float)value; GLWindow->updateGL(); }
1510void UIConnector::on_greenValue4_valueChanged(double value) { GLWindow->gg[4] = (float)value; GLWindow->updateGL(); }
1511
1512void UIConnector::on_blueValue0_valueChanged(double value) { GLWindow->bb[0] = (float)value; GLWindow->updateGL(); }
1513void UIConnector::on_blueValue1_valueChanged(double value) { GLWindow->bb[1] = (float)value; GLWindow->updateGL(); }
1514void UIConnector::on_blueValue2_valueChanged(double value) { GLWindow->bb[2] = (float)value; GLWindow->updateGL(); }
1515void UIConnector::on_blueValue3_valueChanged(double value) { GLWindow->bb[3] = (float)value; GLWindow->updateGL(); }
1516void UIConnector::on_blueValue4_valueChanged(double value) { GLWindow->bb[4] = (float)value; GLWindow->updateGL(); }
1517
1518/************************************************************
1519 * LOAD NEW FILE CLICKED. button handler
1520 ************************************************************/
1521void UIConnector::on_loadNewFileButton_clicked()
1522{
1523 QFileDialog dialog;
1524 dialog.setFileMode(QFileDialog::ExistingFile);
1525 dialog.open(this, SLOT(fileSelected(QString)));
1526 dialog.setVisible(true);
1527 dialog.exec();
1528}
1529void UIConnector::on_loadDRSCalibButton_clicked()
1530{
1531 QFileDialog dialog;
1532 dialog.setFileMode(QFileDialog::ExistingFile);
1533 dialog.open(this, SLOT(calibFileSelected(QString)));
1534 dialog.setVisible(true);
1535 dialog.exec();
1536}
1537/************************************************************
1538 * FILE SELECTED. return of the file open dialog handler
1539 ************************************************************/
1540void UIConnector::fileSelected(QString file)
1541{
1542 currentFile = file.toStdString();
1543 if (currentFile != "")
1544 GLWindow->openFile(currentFile);
1545}
1546void UIConnector::calibFileSelected(QString file)
1547{
1548 currentCalibFile = file.toStdString();
1549 if (currentCalibFile != "")
1550 GLWindow->openCalibFile(currentCalibFile);
1551}
1552/************************************************************
1553 * NEW FILE LOADED. update of the UI after a new file has been loaded
1554 ************************************************************/
1555void UIConnector::newFileLoaded()
1556{
1557 ostringstream str;
1558
1559 //extract the file name only (no path) from the full name
1560 str << "File: " << currentFile.substr(currentFile.find_last_of("//")+1, currentFile.size()) << "\n";
1561 str << "Calibration: " << currentCalibFile.substr(currentCalibFile.find_last_of("//")+1, currentCalibFile.size()) << "\n";
1562// fileLoadedLabel->setText(QString(str.str().c_str()));
1563// str.str("");
1564 str << "Run number: " << GLWindow->runNumber << "\n";
1565// runNumberLabel->setText(QString(str.str().c_str()));
1566// str.str("");
1567 str << "Number of Events: " << GLWindow->nRows << "\n";
1568
1569 displayingEventBox->setMaximum(GLWindow->nRows-1);
1570
1571 str << "Number of Slices: " << GLWindow->nRoi << "\n";// << "/1024";
1572// numberOfSlicesLabel->setText(QString(str.str().c_str()));
1573// str.str("");
1574 str << "Number of Time Marks: " << GLWindow->nTM << "\n";
1575// numberOfTimeMarksLabel->setText(QString(str.str().c_str()));
1576
1577// str.str("");
1578 str << "Run Type: " << GLWindow->runType << "\n";
1579// runTypeLabel->setText(QString(str.str().c_str()));
1580// str.str("");
1581 str << "Time of 1st data: " << GLWindow->firstDataTime << "\n";
1582// firstTimeLabel->setText(QString(str.str().c_str()));
1583// str.str("");
1584 str << "Time of last data: " << GLWindow->lastDataTime << "\n";
1585// lastTimeLabel->setText(QString(str.str().c_str()));
1586// str.str("");
1587 str << "SVN revision: " << GLWindow->revision << '\n';
1588 str << "Number of boards: " << GLWindow->nBoards << '\n';
1589 str << "Number of pixels: " << GLWindow->nPixels << '\n';
1590 str << "Number of Slices TM: " << GLWindow->nRoiTM << '\n';
1591 str << "Time system: " << GLWindow->timeSystem << '\n';
1592 str << "Date: " << GLWindow->creationDate << '\n';
1593 str << "Night: " << GLWindow->nightInt << '\n';
1594 str << "Camera: " << GLWindow->camera << '\n';
1595 str << "DAQ: " << GLWindow->daq << '\n';
1596 str << "ADC Count: " << GLWindow->adcCount << '\n';
1597 str << "NB Evts OK:" << GLWindow->nbOk << '\n';
1598 str << "NB Evts Rejected: " << GLWindow->nbRej << '\n';
1599 str << "NB Evts Bad: " << GLWindow->nbBad << '\n';
1600 extraInfoLabel->setText(QString(str.str().c_str()));
1601
1602 /*
1603 if (GLWindow->calibrationLoaded)
1604 {
1605 drawCalibrationCheckBox->setEnabled(true);
1606 }*/
1607
1608
1609}
1610/************************************************************
1611 * PLAY PAUSE CLICKED. ui handler
1612 ************************************************************/
1613void UIConnector::on_playPauseButton_clicked()
1614{
1615 if (timer.isActive())
1616 timer.stop();
1617 else
1618 timer.start();
1619}
1620
1621void UIConnector::displaySliceValue()
1622{
1623 if (!GLWindow->nRoi)
1624 return;
1625 if (GLWindow->selectedPixel == -1)
1626 {
1627 ostringstream str;
1628 str << " Current Pixel val.: --";
1629 currentPixelValue->setText(QString(str.str().c_str()));
1630 return;
1631 }
1632 const int idx =
1633 GLWindow->nRoi*GLWindow->hardwareMapping[GLWindow->selectedPixel]
1634 + GLWindow->whichSlice;
1635
1636 ostringstream str;
1637 str << "Current Pixel val.: " << GLWindow->eventData[idx];
1638 currentPixelValue->setText(QString(str.str().c_str()));
1639}
1640
1641/************************************************************
1642 * CURRENT SLICE HAS CHANGE. ui handler
1643 ************************************************************/
1644void UIConnector::currentSliceHasChanged(int slice)
1645{
1646 if (!GLWindow->nRoi)
1647 return;
1648
1649 if (updateSpinnerDisplay)
1650 displayingSliceBox->setValue(slice);
1651
1652 displaySliceValue();
1653}
1654
1655/*****
1656 *******************************************************
1657 * CURRENT EVENT HAS CHANGED. ui handler
1658 ************************************************************/
1659
1660double xval[50000];
1661double yval[50000];
1662void UIConnector::on_displayingEventBox_valueChanged(int cEvent)
1663{
1664// cout << "Here " << updateSpinnerDisplay << endl;
1665 if (!updateSpinnerDisplay)
1666 return;
1667 updateSpinnerDisplay = false;
1668// currentEventHasChanged(cEvent);
1669 GLWindow->rowNum = cEvent - GLWindow->eventStep;
1670 GLWindow->eventStepping(true);
1671 updateSpinnerDisplay = true;
1672
1673// GLWindow->updateGL();
1674}
1675void UIConnector::on_slicesPerSecValue_valueChanged(double value)
1676{
1677 timer.setInterval(1000.0/value);
1678}
1679void UIConnector::on_displayingSliceBox_valueChanged(int cSlice)
1680{
1681 updateSpinnerDisplay = false;
1682 currentSliceHasChanged(cSlice);
1683 updateSpinnerDisplay = true;
1684 GLWindow->whichSlice = cSlice;
1685 GLWindow->updateGL();
1686}
1687void UIConnector::currentEventHasChanged(int )
1688{
1689
1690 GLWindow_2->SetData(GLWindow->RMSvalues);
1691 if (GLWindow_2->isVisible())
1692 GLWindow_2->updateGL();
1693 ostringstream str;
1694// str << "Displaying Event " << cEvent;
1695// QString qstr(str.str().c_str());
1696// emit updateCurrentEventDisplay(qstr);
1697 if (updateSpinnerDisplay)
1698 {
1699 updateSpinnerDisplay = false;
1700 displayingEventBox->setValue(GLWindow->rowNum);
1701 updateSpinnerDisplay = true;
1702 }
1703
1704 // GLWindow->doWaveLetOnCurrentEventPlease();
1705
1706 //retrieve the data that we want to display
1707 boost::posix_time::ptime hrTime( boost::gregorian::date(1970, boost::gregorian::Jan, 1),
1708 boost::posix_time::seconds(GLWindow->pcTime[0]) + boost::posix_time::microsec(GLWindow->pcTime[1]));
1709
1710 str.str("");
1711 str << "PC Time: " << boost::posix_time::to_iso_extended_string(hrTime);
1712 PCTimeLabel->setText(QString(str.str().c_str()));
1713
1714 str.str("");
1715 str << "Software Trigger: " << GLWindow->softTrig;
1716 softwareTriggerLabel->setText(QString(str.str().c_str()));
1717
1718 str.str("");
1719 str << "Trigger Type: " << GLWindow->triggerType;
1720 triggerTypeLabel->setText(QString(str.str().c_str()));
1721
1722 displaySliceValue();
1723
1724 if (autoScaleColor->isChecked())
1725 emit GLWindow->colorPaletteHasChanged();//autoScalePressed();
1726
1727 boardsTimeList->clear();
1728 startPixelsList->clear();
1729 startTimeMarksList->clear();
1730 triggerDelayList->clear();
1731 std::map<int, int> boardsHistoMap;
1732 for (int i=0;i <NBOARDS; i++)
1733 {
1734 str.str("");
1735 str << i;
1736 if (i<10) str << " ";
1737 if (i<100) str << " ";
1738 if (i<1000) str << " ";
1739 str << ": " << GLWindow->boardTime[i];
1740 boardsTimeList->addItem(QString(str.str().c_str()));
1741 if (boardsHistoMap.find(GLWindow->boardTime[i]) != boardsHistoMap.end())
1742 boardsHistoMap[GLWindow->boardTime[i]]++;
1743 else
1744 boardsHistoMap[GLWindow->boardTime[i]] = 1;
1745 }
1746 std::map<int, int> pixelHistoMap;
1747 for (int i=0;i <NPIX; i++)
1748 {
1749 str.str("");
1750 str << i;
1751 if (i<10) str << " ";
1752 if (i<100) str << " ";
1753 if (i<1000) str << " ";
1754 str << ": " << GLWindow->startPix[i];
1755 startPixelsList->addItem(QString(str.str().c_str()));
1756 if (pixelHistoMap.find(GLWindow->startPix[i]) != pixelHistoMap.end())
1757 pixelHistoMap[GLWindow->startPix[i]]++;
1758 else
1759 pixelHistoMap[GLWindow->startPix[i]] = 1;
1760 }
1761
1762 std::map<int, int> timeMarksMap;
1763 for (int i=0;i <NTMARK; i++)
1764 {
1765 str.str("");
1766 str << i;
1767 if (i<10) str << " ";
1768 if (i<100) str << " ";
1769 if (i<1000) str << " ";
1770 str << ": " << GLWindow->startTM[i];
1771 startTimeMarksList->addItem(QString(str.str().c_str()));
1772 if (timeMarksMap.find(GLWindow->startTM[i]) != timeMarksMap.end())
1773 timeMarksMap[GLWindow->startTM[i]]++;
1774 else
1775 timeMarksMap[GLWindow->startTM[i]] = 1;
1776 }
1777 std::map<int,int> delayMap;
1778 triggerDelayList->addItem(QString("Patch | Slice:Delay Slice:Delay..."));
1779 for (int i=0;i<NTMARK; i++)
1780 {
1781 str.str("");
1782 str << i << " | ";
1783 for (int j=0;j<GLWindow->nRoi;j++)
1784 {
1785 int value = GLWindow->eventData[1440*GLWindow->nRoi + i*GLWindow->nRoi + j];
1786 if (delayMap.find(value) != delayMap.end())
1787 delayMap[value]++;
1788 else
1789 delayMap[value] = 1;
1790 str << j << ":" << value << " ";
1791 }
1792 triggerDelayList->addItem(QString(str.str().c_str()));
1793 }
1794
1795 std::map<int,int>::iterator it = boardsHistoMap.begin();
1796 int nsamples = 0;
1797 int previousValue = it->first-10;
1798 for (unsigned int i=0;i<boardsHistoMap.size();i++)
1799 {
1800 if (previousValue != it->first-1)
1801 {
1802 xval[nsamples] = previousValue+1;
1803 yval[nsamples] = 0;
1804 nsamples++;
1805 xval[nsamples] = it->first-1;
1806 yval[nsamples] = 0;
1807 nsamples++;
1808 }
1809 xval[nsamples] = it->first;
1810 yval[nsamples] = it->second;
1811 previousValue = it->first;
1812 it++;
1813 nsamples++;
1814 xval[nsamples] = previousValue;
1815 yval[nsamples] = 0;
1816 nsamples++;
1817 if (nsamples > 4090)
1818 {
1819 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1820 break;
1821 }
1822 }
1823 xval[nsamples] = it==boardsHistoMap.begin() ? 0 : (--it)->first+1;
1824 yval[nsamples] = 0;
1825 nsamples++;
1826 // if (nsamples > 5)
1827#if QWT_VERSION < 0x060000
1828 boardsTimeHistoItem.setData(xval, yval, nsamples);
1829#else
1830 boardsTimeHistoItem.setSamples(xval, yval, nsamples);
1831#endif
1832
1833 it = pixelHistoMap.begin();
1834 nsamples = 0;
1835 previousValue = it->first-10;
1836 for (unsigned int i=0;i<pixelHistoMap.size();i++)
1837 {
1838 if (previousValue != it->first-1)
1839 {
1840 xval[nsamples] = previousValue+1;
1841 yval[nsamples] = 0;
1842 nsamples++;
1843 xval[nsamples] = it->first-1;
1844 yval[nsamples] = 0;
1845 nsamples++;
1846 }
1847 xval[nsamples] = it->first;
1848 yval[nsamples] = it->second;
1849 previousValue = it->first;
1850 it++;
1851 nsamples++;
1852 xval[nsamples] = previousValue;
1853 yval[nsamples] = 0;
1854 nsamples++;
1855 if (nsamples > 4090)
1856 {
1857 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1858 break;
1859 }
1860 }
1861 xval[nsamples] = it==pixelHistoMap.begin() ? 0 : (--it)->first+1;
1862 yval[nsamples] = 0;
1863 nsamples++;
1864// if (nsamples > 5)
1865#if QWT_VERSION < 0x060000
1866 startCellHistoItem.setData(xval, yval, nsamples);
1867#else
1868 startCellHistoItem.setSamples(xval, yval, nsamples);
1869#endif
1870
1871 it = timeMarksMap.begin();
1872 nsamples = 0;
1873 previousValue = it->first-10;
1874 for (unsigned int i=0;i<timeMarksMap.size();i++)
1875 {
1876 if (previousValue != it->first-1)
1877 {
1878 xval[nsamples] = previousValue+1;
1879 yval[nsamples] = 0;
1880 nsamples++;
1881 xval[nsamples] = it->first-1;
1882 yval[nsamples] = 0;
1883 nsamples++;
1884 }
1885 xval[nsamples] = it->first;
1886 yval[nsamples] = it->second;
1887 previousValue = it->first;
1888 it++;
1889 nsamples++;
1890 xval[nsamples] = previousValue;
1891 yval[nsamples] = 0;
1892 nsamples++;
1893 if (nsamples > 4090)
1894 {
1895 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1896 break;
1897 }
1898 }
1899 xval[nsamples] = it==timeMarksMap.begin() ? 0 : (--it)->first+1;
1900 yval[nsamples] = 0;
1901 nsamples++;
1902 // if (nsamples > 5)
1903#if QWT_VERSION < 0x060000
1904 startTimeMarkHistoItem.setData(xval, yval, nsamples);
1905#else
1906 startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
1907#endif
1908
1909 it = delayMap.begin();
1910 nsamples = 0;
1911 previousValue = it->first-10;
1912 for (unsigned int i=0;i<delayMap.size();i++)
1913 {
1914 if (previousValue != it->first-1)
1915 {
1916 xval[nsamples] = previousValue+1;
1917 yval[nsamples] = 0;
1918 nsamples++;
1919 xval[nsamples] = it->first-1;
1920 yval[nsamples] = 0;
1921 nsamples++;
1922 }
1923 xval[nsamples] = it->first;
1924 yval[nsamples] = it->second;
1925 previousValue = it->first;
1926 it++;
1927 nsamples++;
1928 xval[nsamples] = previousValue;
1929 yval[nsamples] = 0;
1930 nsamples++;
1931 if (nsamples > 4090)
1932 {
1933 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1934 break;
1935 }
1936 }
1937 xval[nsamples] = it==delayMap.begin() ? 0 : (--it)->first+1;
1938 yval[nsamples] = 0;
1939 nsamples++;
1940 // if (nsamples > 5)
1941#if QWT_VERSION < 0x060000
1942 triggerDelayHistoItem.setData(xval, yval, nsamples);
1943#else
1944 triggerDelayHistoItem.setSamples(xval, yval, nsamples);
1945#endif
1946 //WAVELETS HACK
1947/* std::map<int, int> valuesHistoMap;
1948 std::map<int, int> waveletHistoMap;
1949 for (int i=0;i<1024*1440;i++)
1950 {
1951 if (valuesHistoMap.find(GLWindow->rawEventData[i]) != valuesHistoMap.end())
1952 valuesHistoMap[GLWindow->rawEventData[i]]++;
1953 else
1954 valuesHistoMap[GLWindow->rawEventData[i]] = 1;
1955 if (waveletHistoMap.find(GLWindow->waveLetArray[i]) != waveletHistoMap.end())
1956 waveletHistoMap[GLWindow->waveLetArray[i]]++;
1957 else
1958 waveletHistoMap[GLWindow->waveLetArray[i]] = 1;
1959 }
1960
1961 it = valuesHistoMap.begin();
1962 nsamples = 0;
1963 previousValue = it->first-10;
1964 cout << "Num values Original: " << valuesHistoMap.size() << endl;
1965 for (unsigned int i=0;i<valuesHistoMap.size();i++)
1966 {
1967 if (previousValue != it->first-1)
1968 {
1969 xval[nsamples] = previousValue+1;
1970 yval[nsamples] = 0;
1971 nsamples++;
1972 xval[nsamples] = it->first-1;
1973 yval[nsamples] = 0;
1974 nsamples++;
1975 }
1976 xval[nsamples] = it->first;
1977 yval[nsamples] = it->second;
1978 previousValue = it->first;
1979 it++;
1980 nsamples++;
1981 xval[nsamples] = previousValue;
1982 yval[nsamples] = 0;
1983 nsamples++;
1984 if (nsamples > 50000)
1985 {
1986 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1987 break;
1988 }
1989 }
1990 xval[nsamples] = it==valuesHistoMap.begin() ? 0 : (--it)->first+1;
1991 yval[nsamples] = 0;
1992 nsamples++;
1993 // if (nsamples > 5)
1994 #if QWT_VERSION < 0x060000
1995 triggerDelayHistoItem.setData(xval, yval, nsamples);
1996 #else
1997 triggerDelayHistoItem.setSamples(xval, yval, nsamples);
1998 #endif
1999
2000 it = waveletHistoMap.begin();
2001 nsamples = 0;
2002 previousValue = it->first-10;
2003 cout << "Num values WaveLets: " << waveletHistoMap.size() << endl;
2004 for (unsigned int i=0;i<waveletHistoMap.size();i++)
2005 {
2006 if (previousValue != it->first-1)
2007 {
2008 xval[nsamples] = previousValue+1;
2009 yval[nsamples] = 0;
2010 nsamples++;
2011 xval[nsamples] = it->first-1;
2012 yval[nsamples] = 0;
2013 nsamples++;
2014 }
2015 xval[nsamples] = it->first;
2016 yval[nsamples] = it->second;
2017 previousValue = it->first;
2018 it++;
2019 nsamples++;
2020 xval[nsamples] = previousValue;
2021 yval[nsamples] = 0;
2022 nsamples++;
2023 if (nsamples > 50000)
2024 {
2025 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
2026 break;
2027 }
2028 }
2029 xval[nsamples] = it==waveletHistoMap.begin() ? 0 : (--it)->first+1;
2030 yval[nsamples] = 0;
2031 nsamples++;
2032 // if (nsamples > 5)
2033 #if QWT_VERSION < 0x060000
2034 startTimeMarkHistoItem.setData(xval, yval, nsamples);
2035 #else
2036 startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
2037 #endif
2038*/
2039//END OF WAVELETS HACK
2040 // startCellHistoZoom->setZoomBase(startCellHistoItem.boundingRect());
2041 QStack< QRectF > stack;
2042// QRectF cRectangle = boardsTimeHistoItem.boundingRect();
2043 stack.push(scaleBoundingRectangle(boardsTimeHistoItem.boundingRect(), 1.05f));//cRectangle);//boardsTimeHistoItem.boundingRect());
2044 boardsTimeHistoZoom->setZoomStack(stack);
2045 stack.pop();
2046 stack.push(scaleBoundingRectangle(startCellHistoItem.boundingRect(), 1.05f));
2047 startCellHistoZoom->setZoomStack(stack);
2048 stack.pop();
2049 stack.push(scaleBoundingRectangle(startTimeMarkHistoItem.boundingRect(), 1.05f));
2050 startTimeMarkHistoZoom->setZoomStack(stack);
2051 stack.pop();
2052 stack.push(scaleBoundingRectangle(triggerDelayHistoItem.boundingRect(), 1.05f));
2053 triggerDelayHistoZoom->setZoomStack(stack);
2054 stack.pop();
2055
2056 pixelChanged(GLWindow->selectedPixel);
2057}
2058//can't use a ref to rectangle, as the type must be converted first
2059QRectF UIConnector::scaleBoundingRectangle(QRectF rectangle, float scale)
2060{
2061 QPointF bottomRight = rectangle.bottomRight();
2062 QPointF topLeft = rectangle.topLeft();
2063 QPointF center = rectangle.center();
2064 return QRectF(topLeft + (topLeft-center)*(scale-1.0f), //top left
2065 bottomRight + (bottomRight-center)*(scale-1.0f)); //bottom right
2066}
2067void UIConnector::initHistograms()
2068{
2069// QwtPlot* boardsTimeHisto;
2070// QwtPlotHistogram boardsTimeHistoItem;
2071 grid1 = new QwtPlotGrid;
2072 grid1->enableX(false);
2073 grid1->enableY(true);
2074 grid1->enableXMin(false);
2075 grid1->enableYMin(false);
2076 grid1->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2077 grid1->attach(boardsTimeHisto);
2078
2079 grid2 = new QwtPlotGrid;
2080 grid2->enableX(false);
2081 grid2->enableY(true);
2082 grid2->enableXMin(false);
2083 grid2->enableYMin(false);
2084 grid2->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2085 grid2->attach(startCellsHisto);
2086
2087 grid3 = new QwtPlotGrid;
2088 grid3->enableX(false);
2089 grid3->enableY(true);
2090 grid3->enableXMin(false);
2091 grid3->enableYMin(false);
2092 grid3->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2093 grid3->attach(startTimeMarkHisto);
2094
2095 grid4 = new QwtPlotGrid;
2096 grid4->enableX(false);
2097 grid4->enableY(true);
2098 grid4->enableXMin(false);
2099 grid4->enableYMin(false);
2100 grid4->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2101 grid4->attach(pixelValueCurve);
2102
2103 grid5 = new QwtPlotGrid;
2104 grid5->enableX(false);
2105 grid5->enableY(true);
2106 grid5->enableXMin(false);
2107 grid5->enableYMin(false);
2108 grid5->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
2109 grid5->attach(triggerDelayHisto);
2110
2111 boardsTimeHisto->setAutoReplot(true);
2112 startCellsHisto->setAutoReplot(true);
2113 startTimeMarkHisto->setAutoReplot(true);
2114 pixelValueCurve->setAutoReplot(true);
2115 triggerDelayHisto->setAutoReplot(true);
2116 boardsTimeHisto->setTitle("Boards time values");
2117 startCellsHisto->setTitle("Start Cell values");
2118 startTimeMarkHisto->setTitle("Start Time Marks values");
2119 pixelValueCurve->setTitle("Current pixel values");
2120 triggerDelayHisto->setTitle("Trigger Delays");
2121
2122 // boardsTimeHistoItem.setBrush(QBrush(Qt::red));
2123// startCellHistoItem.setBrush(QBrush(Qt::red));
2124// startTimeMarkHistoItem.setBrush(QBrush(Qt::red));
2125// triggerDelayHistoItem.setBrush(QBrush(Qt::red));
2126// pixelValueCurveItem.setBrush(QBrush(Qt::red));
2127
2128 boardsTimeHistoItem.setPen(QColor(Qt::darkGreen));
2129 boardsTimeHistoItem.setStyle(QwtPlotCurve::Steps);
2130 startCellHistoItem.setPen(QColor(Qt::darkGreen));
2131 startCellHistoItem.setStyle(QwtPlotCurve::Steps);
2132 startTimeMarkHistoItem.setPen(QColor(Qt::darkGreen));
2133 startTimeMarkHistoItem.setStyle(QwtPlotCurve::Steps);
2134 triggerDelayHistoItem.setPen(QColor(Qt::darkGreen));
2135 triggerDelayHistoItem.setStyle(QwtPlotCurve::Steps);
2136
2137 boardsTimeHistoItem.attach(boardsTimeHisto);
2138 startCellHistoItem.attach(startCellsHisto);
2139 startTimeMarkHistoItem.attach(startTimeMarkHisto);
2140 triggerDelayHistoItem.attach(triggerDelayHisto);
2141
2142 //curve
2143// pixelValueCurveItem.setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush, QPen(Qt::black), QSize(5,5)));
2144 pixelValueCurveItem.setPen(QColor(Qt::black));
2145 aMeanCurveItem.setPen(QColor(Qt::darkGreen));
2146 vCorrCurveItem.setPen(QColor(Qt::red));
2147 meanCurveItem.setPen(QColor(Qt::blue));
2148 pixelValueCurveItem.setStyle(QwtPlotCurve::Lines);
2149 aMeanCurveItem.setStyle(QwtPlotCurve::Lines);
2150 vCorrCurveItem.setStyle(QwtPlotCurve::Lines);
2151 meanCurveItem.setStyle(QwtPlotCurve::Lines);
2152
2153// pixelValueCurveItem.setCurveAttribute(QwtPlotCurve::Fitted);
2154 pixelValueCurveItem.attach(pixelValueCurve);
2155// aMeanCurveItem.attach(pixelValueCurve);
2156 // vCorrCurveItem.attach(pixelValueCurve);
2157// meanCurveItem.attach(pixelValueCurve);
2158
2159 //FIXME delete these pointers with the destructor
2160 curveZoom = new QwtPlotZoomer(pixelValueCurve->canvas());
2161 curveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2162 curveZoom->setTrackerPen(QPen(Qt::gray));
2163
2164 boardsTimeHistoZoom = new QwtPlotZoomer(boardsTimeHisto->canvas());
2165 boardsTimeHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2166 boardsTimeHistoZoom->setTrackerPen(QPen(Qt::gray));
2167
2168 startCellHistoZoom = new QwtPlotZoomer(startCellsHisto->canvas());
2169 startCellHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2170 startCellHistoZoom->setTrackerPen(QPen(Qt::gray));
2171
2172 startTimeMarkHistoZoom = new QwtPlotZoomer(startTimeMarkHisto->canvas());
2173 startTimeMarkHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2174 startTimeMarkHistoZoom->setTrackerPen(QPen(Qt::gray));
2175
2176 triggerDelayHistoZoom = new QwtPlotZoomer(triggerDelayHisto->canvas());
2177 triggerDelayHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
2178 triggerDelayHistoZoom->setTrackerPen(QPen(Qt::gray));
2179
2180
2181}
2182
2183void UIConnector::pixelChanged(int pixel)
2184{
2185 GLWindow_2->fWhite = pixel;
2186 if (pixel != -1)
2187 GLWindow_2->fWhitePatch = GLWindow_2->pixelsPatch[pixel];
2188 else
2189 GLWindow_2->fWhitePatch = -1;
2190 if (pixel == -1)
2191 return;
2192
2193 pixel = GLWindow->hardwareMapping[pixel];
2194
2195 HwIDBox->setValue(pixel);
2196
2197 if (!GLWindow->nRoi)
2198 return;
2199
2200 for (int i=0;i<GLWindow->nRoi;i++)
2201 {
2202 xval[i] = i;
2203#ifdef LOAD_RAW
2204 yval[i] = eventsData[0][pixel][i];
2205#else
2206 yval[i] = GLWindow->eventData[GLWindow->nRoi*pixel + i];
2207#endif
2208 }
2209
2210 // GLWindow->computePulsesStatistics();
2211#if QWT_VERSION < 0x060000
2212 pixelValueCurveItem.setData(xval, yval, GLWindow->nRoi);
2213//// aMeanCurveItem.setData(xval, GLWindow->aMeas, GLWindow->nRoi);
2214 // meanCurveItem.setData(xval, GLWindow->n1mean, GLWindow->nRoi);
2215 // vCorrCurveItem.setData(xval, GLWindow->vCorr, GLWindow->nRoi-3);
2216#else
2217 pixelValueCurveItem.setSamples(xval, yval, GLWindow->nRoi);
2218// aMeanCurveItem.setSamples(xval, GLWindow->aMeas, GLWindow->nRoi);
2219 // meanCurveItem.setSamples(xval, GLWindow->n1mean, GLWindow->nRoi);
2220 // vCorrCurveItem.setSamples(xval, GLWindow->vCorr, GLWindow->nRoi-3);
2221#endif
2222
2223
2224 QStack< QRectF > stack;
2225 stack.push(scaleBoundingRectangle(pixelValueCurveItem.boundingRect(), 1.5f));
2226 curveZoom->setZoomStack(stack);
2227 stack.pop();
2228
2229 displaySliceValue();
2230 on_autoScaleColor_clicked();
2231}
2232
2233void UIConnector::on_HwIDBox_valueChanged(int)
2234{
2235 updating = true;
2236
2237 const int hwID = HwIDBox->value();
2238
2239 const int crateID = hwID/360;
2240 const int boardID = (hwID%360)/36;
2241 const int patchID = (hwID%36 )/9;
2242 const int pixelID = hwID%9;
2243
2244 SwIDBox->setValue(GLWindow->softwareMapping[hwID]);
2245
2246 crateIDBox->setValue(crateID);
2247 boardIDBox->setValue(boardID);
2248 patchIDBox->setValue(patchID);
2249 pixelIDBox->setValue(pixelID);
2250
2251 updating = false;
2252
2253 GLWindow->selectedPixel = GLWindow->softwareMapping[hwID];
2254 GLWindow->updateGL();
2255
2256 pixelChanged(GLWindow->selectedPixel);
2257}
2258
2259void UIConnector::cbpxChanged()
2260{
2261 if (updating)
2262 return;
2263
2264 const int hwid = crateIDBox->value()*360 + boardIDBox->value()*36 + patchIDBox->value()*9 + pixelIDBox->value();
2265 HwIDBox->setValue(hwid);
2266}
2267
2268void UIConnector::on_SwIDBox_valueChanged(int swid)
2269{
2270 if (updating)
2271 return;
2272
2273 HwIDBox->setValue(GLWindow->hardwareMapping[swid]);
2274}
2275
2276void UIConnector::on_autoScaleColor_clicked()
2277{
2278 if (!autoScaleColor->isChecked())
2279 {
2280 GLWindow->ss[0] = 0.496;
2281 GLWindow->ss[1] = 0.507;
2282 GLWindow->ss[2] = 0.518;
2283 GLWindow->ss[3] = 0.529;
2284 GLWindow->ss[4] = 0.540;;
2285 colorRange0->setValue(GLWindow->ss[0]);
2286 colorRange1->setValue(GLWindow->ss[1]);
2287 colorRange2->setValue(GLWindow->ss[2]);
2288 colorRange3->setValue(GLWindow->ss[3]);
2289 colorRange4->setValue(GLWindow->ss[4]);
2290 return;
2291 }
2292 if (!GLWindow->nRoi)
2293 return;
2294
2295 int start = 0;
2296 int end = 1440;
2297
2298 if (!entireCameraScale->isChecked())
2299 {
2300 start = GLWindow->selectedPixel;
2301 end = GLWindow->selectedPixel+1;
2302 if (end == 0)
2303 {
2304 start = 0;
2305 end = 1440;
2306 }
2307 }
2308
2309 int min = 100000; //real min = -2048, int_16 = -32768 to 32767
2310 int max = -100000; //real max = 2047
2311
2312 long average = 0;
2313 long numSamples = 0;
2314 int errorDetected = -1;
2315
2316 for (int i=start;i<end;i++)
2317 {
2318 for (int j=0;j<GLWindow->nRoi;j++)
2319 {
2320 int cValue = GLWindow->eventData[i*GLWindow->nRoi+j];
2321 if (cValue > max && cValue < 32767)
2322 max = cValue;
2323 if (cValue < min && cValue > -32768)
2324 min = cValue;
2325 if (cValue < 32767 && cValue > -32768)
2326 {
2327 average+=cValue;
2328 numSamples++;
2329 }
2330 else
2331 {
2332 errorDetected = i;
2333 }
2334// numSamples++;
2335 }
2336 }
2337 average /= numSamples;
2338 if (errorDetected != -1)
2339 {
2340 cout << "Overflow detected at pixel " << errorDetected << " (at least)" << endl;
2341 }
2342// cout << "min: " << min << " max: " << max << " average: " << average << endl;
2343 double minRange = (double)(min+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2344 double maxRange = (double)(max+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2345 double midRange = (double)(average+(VALUES_SPAN/2))/(double)VALUES_SPAN;
2346 if (GLWindow->logScale)
2347 {
2348 minRange *= 9;
2349 maxRange *= 9;
2350// midRange *= 9;
2351 minRange += 1;
2352 maxRange += 1;
2353// midRange += 1;
2354 minRange = log10(minRange);
2355 maxRange = log10(maxRange);
2356// midRange = (minRange + maxRange)/2.f;
2357 midRange = log10(midRange);
2358 }
2359
2360 GLWindow->ss[0] = minRange;
2361 colorRange0->setValue(GLWindow->ss[0]);
2362 GLWindow->ss[4] = maxRange;
2363 colorRange4->setValue(GLWindow->ss[4]);
2364// GLWindow->ss[2] = midRange;
2365// range2->setValue(GLWindow->ss[2]);
2366// GLWindow->ss[1] = (minRange+midRange)/2;
2367// range1->setValue(GLWindow->ss[1]);
2368// GLWindow->ss[3] = (maxRange+midRange)/2;
2369// range3->setValue(GLWindow->ss[3]);
2370
2371 GLWindow->ss[2] = (maxRange+minRange)/2;
2372 colorRange2->setValue(GLWindow->ss[2]);
2373
2374 GLWindow->ss[1] = minRange+(maxRange-minRange)/4;
2375 colorRange1->setValue(GLWindow->ss[1]);
2376
2377 GLWindow->ss[3] = minRange+3*(maxRange-minRange)/4;
2378 colorRange3->setValue(GLWindow->ss[3]);
2379}
2380
2381void PrintUsage()
2382{
2383 cout << "\n"
2384 "The FACT++ raw data viewer.\n"
2385 "\n"
2386 "Usage: viewer [OPTIONS] [datafile.fits[.gz] [calibration.drs.fits[.gz]]]\n"
2387 " or: viewer [OPTIONS]\n";
2388 cout << endl;
2389
2390}
2391
2392void PrintHelp()
2393{
2394 cout <<
2395 "\n"
2396 << endl;
2397}
2398
2399int UIConnector::SetupConfiguration(Configuration &conf)
2400{
2401 RawDataViewer *canvas = GLWindow;
2402
2403 if (conf.Has("color.range"))
2404 {
2405 vector<double> value = conf.Vec<double>("color.range");
2406 if (value.size() != 5)
2407 {
2408 cout << "Error, colorRange option should have exactly 5 double values" << endl;
2409 return -1;
2410 }
2411 for (int i=0;i<5;i++)
2412 canvas->ss[i] = value[i];
2413 }
2414
2415 if (conf.Has("color.red"))
2416 {
2417 vector<double> value = conf.Vec<double>("color.red");
2418 if (value.size() != 5)
2419 {
2420 cout << "Error, colorRed option should have exactly 5 double values" << endl;
2421 return -1;
2422 }
2423 for (int i=0;i<5;i++)
2424 canvas->rr[i] = value[i];
2425 }
2426
2427 if (conf.Has("color.green"))
2428 {
2429 vector<double> value = conf.Vec<double>("color.green");
2430 if (value.size() != 5)
2431 {
2432 cout << "Error, colorGreen option should have exactly 5 double values" << endl;
2433 return -1;
2434 }
2435 for (int i=0;i<5;i++)
2436 canvas->gg[i] = value[i];
2437 }
2438
2439 if (conf.Has("color.blue"))
2440 {
2441 vector<double> value = conf.Vec<double>("color.blue");
2442 if (value.size() != 5)
2443 {
2444 cout << "Error, colorBlue option should have exactly 5 double values" << endl;
2445 return -1;
2446 }
2447 for (int i=0;i<5;i++)
2448 canvas->bb[i] = value[i];
2449 }
2450
2451 colorRange0->setValue(canvas->ss[0]);
2452 colorRange1->setValue(canvas->ss[1]);
2453 colorRange2->setValue(canvas->ss[2]);
2454 colorRange3->setValue(canvas->ss[3]);
2455 colorRange4->setValue(canvas->ss[4]);
2456 redValue0->setValue(canvas->rr[0]);
2457 redValue1->setValue(canvas->rr[1]);
2458 redValue2->setValue(canvas->rr[2]);
2459 redValue3->setValue(canvas->rr[3]);
2460 redValue4->setValue(canvas->rr[4]);
2461 greenValue0->setValue(canvas->gg[0]);
2462 greenValue1->setValue(canvas->gg[1]);
2463 greenValue2->setValue(canvas->gg[2]);
2464 greenValue3->setValue(canvas->gg[3]);
2465 greenValue4->setValue(canvas->gg[4]);
2466 blueValue0->setValue(canvas->bb[0]);
2467 blueValue1->setValue(canvas->bb[1]);
2468 blueValue2->setValue(canvas->bb[2]);
2469 blueValue3->setValue(canvas->bb[3]);
2470 blueValue4->setValue(canvas->bb[4]);
2471
2472 if (conf.Has("drs"))
2473 {
2474 const QString qstr(conf.Get<string>("drs").c_str());
2475 calibFileSelected(qstr);
2476 }
2477
2478 if (conf.Has("file"))
2479 {
2480 const QString qstr(conf.Get<string>("file").c_str());
2481 fileSelected(qstr);
2482 }
2483
2484
2485 return 0;
2486}
2487
2488void SetupConfiguration(Configuration& conf)
2489{
2490 po::options_description configs("Raw Events Viewer Options");
2491 configs.add_options()
2492 ("color.range", vars<double>(), "Range of the display colours")
2493 ("color.red", vars<double>(), "Range of red values")
2494 ("color.green", vars<double>(), "Range of green values")
2495 ("color.blue", vars<double>(), "Range of blue values")
2496 ("file,f", var<string>(), "File to be loaded")
2497 ("drs,d", var<string>(), "DRS calibration file to be loaded")
2498 ;
2499 conf.AddOptions(configs);
2500
2501 po::positional_options_description p;
2502 p.add("file", 1); // The first positional options
2503 p.add("drs", 2); // The first positional options
2504 conf.SetArgumentPositions(p);
2505
2506}
2507
2508/************************************************************
2509 * MAIN PROGRAM FUNCTION.
2510 ************************************************************/
2511int main(int argc, const char *argv[])
2512{
2513 QApplication app(argc, const_cast<char**>(argv));
2514
2515 if (!QGLFormat::hasOpenGL()) {
2516 std::cerr << "This system has no OpenGL support" << std::endl;
2517 return 1;
2518 }
2519
2520 Configuration conf(argv[0]);
2521 conf.SetPrintUsage(PrintUsage);
2522 SetupConfiguration(conf);
2523 if (!conf.DoParse(argc, argv, PrintHelp))
2524 return 2;
2525
2526 UIConnector myUi;
2527 if (myUi.SetupConfiguration(conf)<0)
2528 return 3;
2529
2530 return app.exec();
2531}
2532
Note: See TracBrowser for help on using the repository browser.