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

Last change on this file since 11734 was 11723, checked in by tbretz, 14 years ago
Fixed a bug when iterators point to empty lists.
File size: 73.5 KB
Line 
1/*
2 * QtGl.cpp
3 *
4 * Created on: Jul 19, 2011
5 * Author: lyard
6 */
7
8#include "RawEventsViewer.h"
9#include "viewer.h"
10#include <math.h>
11#include <fstream>
12
13#ifdef LOAD_RAW
14int16_t eventsData[NUM_STORED_EVENTS][ACTUAL_NUM_PIXELS][1024];
15#include </home/lyard/Code/display.C>
16#endif
17
18#define VALUES_SPAN 4096
19
20#include <QtGui/QFileDialog>
21
22#include <qwt_plot_grid.h>
23#include <qwt_symbol.h>
24
25#include "src/Configuration.h"
26
27//Coordinates of an hexagon of radius 1 and center 0
28GLfloat hexcoords[6][2] = {{-0.577367206, 1},
29 { 0.577367206, 1},
30 { 1.154734411, 0},
31 { 0.577367206, -1},
32 {-0.577367206, -1},
33 {-1.154734411, 0}};
34
35//bounding box for diplaying the impulse curve
36float bboxMin[2] = {-0.8,-0.9};
37float bboxMax[2] = {0.8,-0.3};
38/************************************************************
39 * UPDATE NEIGHBORS recalculate the neighbors of the current pixels.
40 * Only takes the previous pixels into account (and updates them, too)
41 ************************************************************/
42void RawDataViewer::updateNeighbors(int currentPixel)
43{
44 float squaredDistance = 0;
45 for (int i=0;i<currentPixel;i++)
46 {
47 squaredDistance = (pixelsCoords[i][0] - pixelsCoords[currentPixel][0])*
48 (pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) +
49 (pixelsCoords[i][1] - pixelsCoords[currentPixel][1])*
50 (pixelsCoords[i][1] - pixelsCoords[currentPixel][1]);
51 if (squaredDistance < 4*hexRadius*hexRadius*(1.0f+hexTolerance))//neighbor !
52 {//ok, but which one ?
53 if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
54 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//top
55 neighbors[i][0] = currentPixel;
56 neighbors[currentPixel][3] = i;
57 continue;}
58 if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
59 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//bottom
60 neighbors[i][3] = currentPixel;
61 neighbors[currentPixel][0] = i;
62 continue;}
63 if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] &&
64 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top right
65 neighbors[i][4] = currentPixel;
66 neighbors[currentPixel][1] = i;
67 continue;}
68 if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] &&
69 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom right
70 neighbors[i][5] = currentPixel;
71 neighbors[currentPixel][2] = i;
72 continue;}
73 if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] &&
74 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top left
75 neighbors[i][2] = currentPixel;
76 neighbors[currentPixel][5] = i;
77 continue;}
78 if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] &&
79 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom left
80 neighbors[i][1] = currentPixel;
81 neighbors[currentPixel][4] = i;
82 continue;}
83 }
84 }
85}
86/************************************************************
87 * SKIP PIXELS skips a given number of pixels.
88 * Only update the pixel coordinates. i.e. update neighbors must
89 * called again afterwards.
90 ************************************************************/
91void RawDataViewer::skipPixels(int start, int howMany)
92{
93 for (int i=start;i<MAX_NUM_PIXELS-howMany;i++)
94 {
95 pixelsCoords[i][0] = pixelsCoords[i+howMany][0];
96 pixelsCoords[i][1] = pixelsCoords[i+howMany][1];
97 }
98}
99/************************************************************
100 * CALCULATE PIXELS COORDS as the name suggests
101 ************************************************************/
102void RawDataViewer::calculatePixelsCoords()
103{
104 pixelsCoords[0][0] = 0;
105 pixelsCoords[0][1] = 0.3;
106 pixelsCoords[0][2] = 0;
107 pixelsCoords[1][0] = 0;
108 pixelsCoords[1][1] = 0.3+2*hexRadius;
109 pixelsCoords[1][2] = 0;
110 neighbors[0][0] = 1;
111 neighbors[1][3] = 0;
112 //from which side of the previous hexagon are we coming from ?
113 int fromSide = 3;
114 //to which side are we heading to ?
115 int toSide = 0;
116 for (int i=2;i<MAX_NUM_PIXELS;i++)
117 {
118 toSide = fromSide-1;
119 if (toSide < 0)
120 toSide =5;
121 while (neighbors[i-1][toSide] >= 0)
122 {
123 toSide--;
124 if (toSide < 0)
125 toSide = 5;
126 }
127 fromSide = toSide + 3;
128 if (fromSide > 5)
129 fromSide -= 6;
130 //ok. now we now in which direction we're heading
131 pixelsCoords[i][0] = pixelsCoords[i-1][0];
132 pixelsCoords[i][1] = pixelsCoords[i-1][1];
133 pixelsCoords[i][2] = pixelsCoords[i-1][2];
134 switch (toSide)
135 {
136 case 0:
137 pixelsCoords[i][1] += 2*hexRadius;
138 break;
139 case 1:
140 pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0);
141 pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0);
142 break;
143 case 2:
144 pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0);
145 pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0);
146 break;
147 case 3:
148 pixelsCoords[i][1] -= 2*hexRadius;
149 break;
150 case 4:
151 pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0);
152 pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0);
153 break;
154 case 5:
155 pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0);
156 pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0);
157 break;
158 };
159
160 updateNeighbors(i);
161 }
162 //Ok. So now we've circled around all the way to MAX_NUM_PIXELS
163 //do the required shifts so that it matches the fact camera up to ACTUAL_NUM_PIXELS pixels
164 skipPixels(1200, 1);
165 skipPixels(1218, 3);
166 skipPixels(1236, 1);
167 skipPixels(1256, 1);
168 skipPixels(1274, 3);
169 skipPixels(1292, 3);
170 skipPixels(1309, 6);
171 skipPixels(1323, 7);
172 skipPixels(1337, 6);
173 skipPixels(1354, 6);
174 skipPixels(1368, 7);
175 skipPixels(1382, 9);
176 skipPixels(1394, 12);
177 skipPixels(1402, 15);
178 skipPixels(1410, 12);
179 skipPixels(1422, 12);
180 skipPixels(1430, 15);
181}
182/************************************************************
183 * BUILD VERTICES LIST. from the coordinates of the camera pixels,
184 * calculate the list and coordinates of the vertices required to draw the
185 * entire camera.
186 ************************************************************/
187void RawDataViewer::buildVerticesList()
188{
189 numVertices = 0;
190 GLfloat cVertex[2];
191 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
192 {
193 for (int j=0;j<6;j++)
194 {
195 for (int k=0;k<2;k++)
196 cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
197 bool found = false;
198 for (int k=0;k<numVertices;k++)
199 {
200 if ((cVertex[0] - verticesList[k][0])*
201 (cVertex[0] - verticesList[k][0]) +
202 (cVertex[1] - verticesList[k][1])*
203 (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
204 {
205 found = true;
206 break;
207 }
208 }
209 if (!found)
210 {
211 for (int k=0;k<2;k++)
212 verticesList[numVertices][k] = cVertex[k];
213 numVertices++;
214 }
215 }
216 }
217 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
218 {
219 for (int j=0;j<6;j++)
220 {
221 for (int k=0;k<2;k++)
222 cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
223 for (int k=0;k<numVertices;k++)
224 {
225 if ((cVertex[0] - verticesList[k][0])*
226 (cVertex[0] - verticesList[k][0]) +
227 (cVertex[1] - verticesList[k][1])*
228 (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
229 {
230 verticesIndices[i][j] = k;
231 break;
232 }
233 }
234 }
235 }
236}
237/************************************************************
238 * BUILD PATCHES INDICES. from the list of patches, crawls through
239 * the list of camera pixels and build the list of edges that should be kept
240 * in order to display the patches' contours.
241 ************************************************************/
242void RawDataViewer::buildPatchesIndices()
243{
244 vector<edge>::iterator it;
245 bool erased = false;
246 for (int i=0;i<NTMARK;i++)//for all patches
247 {
248 patchesIndices[i].clear();
249 for (int j=0;j<9;j++)//for all cells of the current patch
250 {
251 if (patches[i][j] == 690 ||
252 patches[i][j] == 70)
253 continue;
254 for (int k=0;k<6;k++)//for all sides of the current cell
255 {
256 int first = k-1;
257 int second = k;
258 if (first < 0)
259 first = 5;
260 erased = false;
261 for (it=(patchesIndices[i]).begin(); it != (patchesIndices[i]).end(); it++)//check if this side is here already or not
262 {
263 if (((*it).first == verticesIndices[patches[i][j]][first] &&
264 (*it).second == verticesIndices[patches[i][j]][second]) ||
265 ((*it).first == verticesIndices[patches[i][j]][second] &&
266 (*it).second == verticesIndices[patches[i][j]][first]))
267 {
268 patchesIndices[i].erase(it);
269 erased = true;
270 break;
271 }
272 }
273 if (!erased)
274 {
275 edge temp;
276 temp.first = verticesIndices[patches[i][j]][first];
277 temp.second = verticesIndices[patches[i][j]][second];
278 patchesIndices[i].push_back(temp);
279 }
280 }
281 }
282 }
283}
284/************************************************************
285 * CALC BLUR COLOR if in blur display mode, calculate the interpolated
286 * colour for a given vertex
287 ************************************************************/
288void RawDataViewer::calcBlurColor(int pixel, int vertex)
289{
290 GLfloat color[3];
291 int first, second;
292 first = vertex-1;
293 second = vertex;
294 if (first < 0)
295 first = 5;
296 first = neighbors[pixel][first];
297 second = neighbors[pixel][second];
298 for (int i=0;i<3;i++)
299 color[i] = pixelsColor[pixel][i];
300 float divide = 1;
301 if (first != -1)
302 {
303 divide++;
304 for (int i=0;i<3;i++)
305 color[i] += pixelsColor[first][i];
306 }
307 if (second != -1)
308 {
309 divide++;
310 for (int i=0;i<3;i++)
311 color[i] += pixelsColor[second][i];
312 }
313 for (int i=0;i<3;i++)
314 color[i] /= divide;
315 glColor3fv(color);
316}
317/************************************************************
318 * DRAW BLURRY HEXAGON. draws a solid hexagon, with interpolated colours
319 ************************************************************/
320void RawDataViewer::drawBlurryHexagon(int index)
321{
322 GLfloat color[3];
323 for (int i=0;i<3;i++)
324 color[i] = pixelsColor[index][i];
325 glBegin(GL_TRIANGLES);
326 calcBlurColor(index, 0);
327 glVertex2fv(verticesList[verticesIndices[index][0]]);
328 glColor3fv(color);
329 glVertex2fv(pixelsCoords[index]);
330 calcBlurColor(index, 1);
331 glVertex2fv(verticesList[verticesIndices[index][1]]);
332
333 glVertex2fv(verticesList[verticesIndices[index][1]]);
334 glColor3fv(color);
335 glVertex2fv(pixelsCoords[index]);
336 calcBlurColor(index, 2);
337 glVertex2fv(verticesList[verticesIndices[index][2]]);
338
339 glVertex2fv(verticesList[verticesIndices[index][2]]);
340 glColor3fv(color);
341 glVertex2fv(pixelsCoords[index]);
342 calcBlurColor(index, 3);
343 glVertex2fv(verticesList[verticesIndices[index][3]]);
344
345 glVertex2fv(verticesList[verticesIndices[index][3]]);
346 glColor3fv(color);
347 glVertex2fv(pixelsCoords[index]);
348 calcBlurColor(index, 4);
349 glVertex2fv(verticesList[verticesIndices[index][4]]);
350
351 glVertex2fv(verticesList[verticesIndices[index][4]]);
352 glColor3fv(color);
353 glVertex2fv(pixelsCoords[index]);
354 calcBlurColor(index, 5);
355 glVertex2fv(verticesList[verticesIndices[index][5]]);
356
357 glVertex2fv(verticesList[verticesIndices[index][5]]);
358 glColor3fv(color);
359 glVertex2fv(pixelsCoords[index]);
360 calcBlurColor(index, 0);
361 glVertex2fv(verticesList[verticesIndices[index][0]]);
362 glEnd();
363
364 return;
365}
366/************************************************************
367 * DRAW HEXAGON. draws a single hexagon.
368 ************************************************************/
369void RawDataViewer::drawHexagon(int index, bool solid)
370{
371 if (solid)
372 glBegin(GL_POLYGON);
373 else
374 glBegin(GL_LINE_LOOP);
375
376 glVertex2fv(verticesList[verticesIndices[index][0]]);
377 glVertex2fv(verticesList[verticesIndices[index][1]]);
378 glVertex2fv(verticesList[verticesIndices[index][2]]);
379 glVertex2fv(verticesList[verticesIndices[index][3]]);
380 glVertex2fv(verticesList[verticesIndices[index][4]]);
381 glVertex2fv(verticesList[verticesIndices[index][5]]);
382 if (solid)
383 glVertex2fv(verticesList[verticesIndices[index][0]]);
384
385 glEnd();
386
387 return;
388}
389
390
391float ss[5] = {0.00, 0.25, 0.5, 0.75, 1.00};
392float rr[5] = {0.15, 0.00, 0.00, 1.00, 0.85};
393float gg[5] = {0.15, 0.00, 1.00, 0.00, 0.85};
394float bb[5] = {0.15, 1.00, 0.00, 0.00, 0.85};
395/*
396float ss[5] = {0., 0.47, 0.475, 0.48, 1.00};
397float rr[5] = {0., 0.35, 0.85, 1.00, 1.00};
398float gg[5] = {0., 0.10, 0.20, 0.73, 1.00};
399float bb[5] = {0., 0.03, 0.06, 0.00, 1.00};
400*/
401/************************************************************
402 * DRAW PATCHES. draws the clustering patches
403 ************************************************************/
404void RawDataViewer::drawPatches()
405{
406 glLineWidth(2.0f);
407 float backupRadius = hexRadius;
408 hexRadius *= 0.95;
409 glBegin(GL_LINES);
410 for (int i=0;i<NTMARK;i++)
411 {
412 glColor3fv(patchesColor[i]);
413 for (unsigned int j=0;j<patchesIndices[i].size();j++)
414 {
415 glVertex2fv(verticesList[patchesIndices[i][j].first]);
416 glVertex2fv(verticesList[patchesIndices[i][j].second]);
417 }
418 }
419 glEnd();
420 hexRadius = backupRadius;
421}
422/************************************************************
423 * DRAW CAMERA draws all the camera pixels
424 ************************************************************/
425void RawDataViewer::drawCamera(bool alsoWire)
426{
427 glColor3f(0.5,0.5,0.5);
428 glLineWidth(1.0);
429 float color;
430
431 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
432 {
433 if (!nRoi)
434 color = (float)(i)/(float)(ACTUAL_NUM_PIXELS);
435 else
436#ifdef LOAD_RAW
437 color = float(eventsData[eventNum][i][whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
438#else
439 color = float(eventData[nRoi*i + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
440#endif
441 int index = 0;
442 while (ss[index] < color)
443 index++;
444 index--;
445 float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
446 float weight1 = 1.0f-weight0;
447 pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
448 pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
449 pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
450 }
451
452 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
453 {
454 if (i == 690 ||
455 i == 70)
456 continue;
457 glColor3fv(pixelsColor[i]);
458 glLoadName(i);
459if (drawBlur)
460 drawBlurryHexagon(i);
461else
462 drawHexagon(i,true);
463
464 }
465 if (!alsoWire)
466 return;
467 glColor3f(0.0f,0.0f,0.0f);
468 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
469 {
470 if (i == 690 ||
471 i == 70)
472 continue;
473 drawHexagon(i, false);
474 }
475
476}
477
478/************************************************************
479 * TRIM. FIXME this should not be here but taken from an existing class (somewhere)
480 ************************************************************/
481string Trim(const string &str)
482{
483 // Trim Both leading and trailing spaces
484 const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces
485 const size_t end = str.find_last_not_of(' '); // Find the first character position from reverse af
486
487 // if all spaces or empty return an empty string
488 if (string::npos==start || string::npos==end)
489 return string();
490
491 return str.substr(start, end-start+1);
492}
493/************************************************************
494 * DRAW PIXEL CURVE. draws the raw impulse curve of the currently selected pixel
495 ************************************************************/
496void RawDataViewer::drawPixelCurve()
497{
498 if (!nRoi)
499 return;
500
501 float xZoom, yZoom;
502 xZoom = yZoom = 1.0f;
503
504 glBegin(GL_LINES);
505 glLineWidth(1.0f);
506 glColor3f(0.5,0.5,0.5);
507 glVertex2f(bboxMin[0], bboxMin[1]);
508 glVertex2f(bboxMax[0], bboxMin[1]);
509 glVertex2f(bboxMin[0], bboxMin[1]);
510 glVertex2f(bboxMin[0], bboxMax[1]);
511 glVertex2f(bboxMin[0], (bboxMin[1]+bboxMax[1])/2.0f);
512 glVertex2f(bboxMax[0], (bboxMin[1]+bboxMax[1])/2.0f);
513 float xRange = bboxMax[0] - bboxMin[0];
514 float yRange = bboxMax[1] - bboxMin[1];
515 glColor3f(1.0,1.0,1.0);
516 for (int i=0;i<nRoi-1;i++)
517 {
518#ifdef LOAD_RAW
519 glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
520 bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i]+(VALUES_SPAN/2)) /(float)(VALUES_SPAN-1));
521 glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
522 bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i+1]+(VALUES_SPAN/2)) /(float)(VALUES_SPAN-1));
523#else
524 glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
525 bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i]+(VALUES_SPAN/2)) /(float)(VALUES_SPAN-1));
526 glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
527 bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i+1]+(VALUES_SPAN/2)) /(float)(VALUES_SPAN-1));
528#endif
529 }
530 glColor3f(1.0,0.0,0.0);
531 glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi,
532 bboxMin[1]);
533 glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi,
534 bboxMax[1]);
535 glEnd();
536 glEnable(GL_MULTISAMPLE);
537 setFont(QFont("Times", 12));
538 qglColor(QColor(255,223,127));
539 float xShift = 0.10f;
540 float yShift = 0.01f;
541 renderText(bboxMin[0]-xShift/2.0f, bboxMax[1]+3*yShift, 0, QString("Volts"));
542 renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+1.05"));
543 renderText(bboxMin[0]-xShift, ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+0.00"));//((bboxMin[1]+bboxMax[1])/2.0f)
544 renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("-1.05"));
545
546 renderText(bboxMax[0]+xShift/2.0f, bboxMin[1]-4*yShift, 0, QString("Slices"));
547 renderText(bboxMin[0]-yShift/2.0f, bboxMin[1]-4*yShift, 0, QString("0"));
548 ostringstream str;
549 str << nRoi/2;
550 renderText(((bboxMin[0]+bboxMax[0])/2.0f)-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
551 str.str("");
552 str << nRoi;
553 renderText(bboxMax[0]-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
554
555}
556/************************************************************
557 * CONSTRUCTOR.
558 ************************************************************/
559RawDataViewer::RawDataViewer(QWidget *cParent) : QGLWidget(cParent)
560{
561 setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));
562 hexRadius = 0.015f;
563 hexTolerance = hexRadius/100.0f;
564 viewSize = 1.0f;
565 whichSlice = 0;
566#ifdef LOAD_RAW
567 nRoi = 1024;
568#else
569 nRoi = 0;
570#endif
571 eventNum = 0;
572 rowNum = -1;
573 eventStep = 1;
574 selectedPixel = 393;
575 inputFile = NULL;
576 eventData = NULL;
577 drawPatch = true;
578 drawImpulse = false;
579 drawBlur = false;
580 loopCurrentEvent = false;
581#ifdef LOAD_RAW
582 loadEvents("/scratch/00000043.001_T.bin");
583#endif
584 calculatePixelsCoords();
585
586 ifstream fin2("MasterList-v3.txt");
587 if (!fin2.is_open())
588 {
589 cout << "Error: file \"MasterList-v3\" missing. aborting." << endl;
590 exit(-1);
591 }
592 int l = 0;
593 string buf;
594 while (getline(fin2, buf, '\n'))
595 {
596 buf = Trim(buf);
597 if (buf[0]=='#')
598 continue;
599
600 unsigned int softid, hardid, dummy;
601
602 stringstream str(buf);
603
604 str >> softid;
605 str >> dummy;
606 str >> hardid;
607
608 if (softid>=1440)
609 continue;
610
611 hardwareMapping[softid] = hardid;
612 softwareMapping[hardid] = softid;
613
614 l++;
615 }
616 GLfloat tempPixelsCoords[MAX_NUM_PIXELS][3];
617 for (int i=0;i<1440;i++)
618 for (int j=0;j<3;j++)
619 tempPixelsCoords[hardwareMapping[i]][j] = pixelsCoords[i][j];
620 for (int i=0;i<1440;i++)
621 for (int j=0;j<3;j++)
622 pixelsCoords[i][j] = tempPixelsCoords[i][j];
623 buildVerticesList();
624 ifstream fin1("Trigger-Patches.txt");
625 if (!fin1.is_open())
626 {
627 cout << "Error: file \"Trigger-Patches.txt\" missing. Aborting." << endl;
628 exit(-1);
629 }
630 l=0;
631 while (getline(fin1, buf, '\n'))
632 {
633 buf = Trim(buf);
634 if (buf[0]=='#')
635 continue;
636
637 stringstream str(buf);
638 for (int i=0; i<9; i++)
639 {
640 unsigned int n;
641 str >> n;
642
643 if (n>=1440)
644 continue;
645
646 patches[l][i] = hardwareMapping[n];
647 }
648 l++;
649 }
650 buildPatchesIndices();
651 float color[3];
652 for (int i=0;i<160;i++)
653 {
654 color[0] = 0.5; color[1] = 0.5; color[2] = 0.3;
655 for (int j=0;j<3;j++)
656 patchesColor[i][j] = color[j];
657 }
658
659 for (int i=0;i<1440;i++)
660 updateNeighbors(i);
661}
662/************************************************************
663 * DESTRUCTOR
664 ************************************************************/
665RawDataViewer::~RawDataViewer()
666{
667 if (inputFile != NULL)
668 {
669 inputFile->close();
670 delete inputFile;
671 }
672 if (eventData != NULL)
673 delete[] eventData;
674}
675/************************************************************
676 * INITIALIZE GL. does not do much.
677 ************************************************************/
678void RawDataViewer::initializeGL()
679{
680 qglClearColor(QColor(25,25,38));
681 glShadeModel(GL_FLAT);
682 glDisable(GL_DEPTH_TEST);
683 glDisable(GL_CULL_FACE);
684// glEnable(GL_LINE_SMOOTH);
685// glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
686}
687
688/************************************************************
689 * RESIZE GL. reshapes the ortho projection to match the current window size
690 ************************************************************/
691void RawDataViewer::resizeGL(int cWidth, int cHeight)
692{
693 glViewport(0, 0, cWidth, cHeight);
694 glMatrixMode(GL_PROJECTION);
695 glLoadIdentity();
696 GLfloat windowRatio = (float)cWidth/(float)cHeight;
697 if (windowRatio < 1)
698 {
699 windowRatio = 1.0f/windowRatio;
700 gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
701 pixelSize = 2*viewSize/(float)cWidth;
702 shownSizex = 2*viewSize;
703 shownSizey = 2*viewSize*windowRatio;
704 }
705 else
706 {
707 gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
708 pixelSize = 2*viewSize/(float)cHeight;
709 shownSizex = 2*viewSize*windowRatio;
710 shownSizey = 2*viewSize;
711 }
712 glMatrixMode(GL_MODELVIEW);
713}
714
715/************************************************************
716 * PAINT GL. main drawing function.
717 ************************************************************/
718void RawDataViewer::paintGL()
719{
720 glClear(GL_COLOR_BUFFER_BIT);
721 glLoadIdentity();
722
723 if (!drawImpulse)
724 {
725 glTranslatef(0,-0.44,0);
726 glScalef(1.5,1.5,1);
727 }
728 if (drawBlur)
729 {
730 glShadeModel(GL_SMOOTH);
731 drawCamera(false);
732 }
733 else
734 {
735 glShadeModel(GL_FLAT);
736 drawCamera(true);
737 }
738 if (drawImpulse)
739 {
740 glLineWidth(2.0);
741 drawPixelCurve();
742 }
743 if (drawPatch)
744 drawPatches();
745
746 if (!drawBlur)
747 {
748 glLineWidth(1.0f);
749 glColor3f(1.0,1.0,1.0);
750 drawHexagon(selectedPixel, false);
751 }
752}
753
754/************************************************************
755 * MOUSE PRESS EVENT. mouse click handler.
756 ************************************************************/
757void RawDataViewer::mousePressEvent(QMouseEvent *cEvent)
758{
759 lastPos = cEvent->pos();
760 setCorrectSlice(cEvent);
761 updateGL();
762}
763
764/************************************************************
765 * SET CORRECT SLICE. if displayed, figures out if the graph was
766 * clicked, and if so, which slice should be displayed
767 ************************************************************/
768void RawDataViewer::setCorrectSlice(QMouseEvent* cEvent)
769{
770 if (!drawImpulse)
771 return;
772 float cx = (float)cEvent->x() * pixelSize - shownSizex/2;
773 float cy = ((float)height()-(float)cEvent->y())*pixelSize - shownSizey/2;
774 if (cx < bboxMin[0] ||
775 cx > bboxMax[0] ||
776 cy < bboxMin[1] ||
777 cy > bboxMax[1])
778 return;
779 whichSlice = (cx - bboxMin[0])*1024/(bboxMax[0] - bboxMin[0]);
780 emit signalCurrentSlice(whichSlice);
781}
782
783/************************************************************
784 * MOUSE MOVE EVENT. used to track the dragging of slices display
785 ************************************************************/
786void RawDataViewer::mouseMoveEvent(QMouseEvent *cEvent)
787{
788 if (cEvent->buttons() & Qt::LeftButton) {
789 setCorrectSlice(cEvent);
790 updateGL();
791 } else if (cEvent->buttons() & Qt::RightButton) {
792 updateGL();
793 }
794 lastPos = cEvent->pos();
795}
796
797/************************************************************
798 * MOUSE DOUBLE CLICK EVENT. used to select pixels
799 ************************************************************/
800void RawDataViewer::mouseDoubleClickEvent(QMouseEvent *cEvent)
801{
802 int face = PixelAtPosition(cEvent->pos());
803 if (face != -1) {
804 selectedPixel = face;
805 emit signalCurrentPixel(face);
806 updateGL();
807 }
808}
809
810/************************************************************
811 * PIXEL AT POSITION. figures out which camera pixel was clicked.
812 ************************************************************/
813int RawDataViewer::PixelAtPosition(const QPoint &cPos)
814{
815 const int MaxSize = 512;
816 GLuint buffer[MaxSize];
817 GLint viewport[4];
818
819 makeCurrent();
820
821 glGetIntegerv(GL_VIEWPORT, viewport);
822 glSelectBuffer(MaxSize, buffer);
823 glRenderMode(GL_SELECT);
824
825 glInitNames();
826 glPushName(0);
827
828 glMatrixMode(GL_PROJECTION);
829 glPushMatrix();
830 glLoadIdentity();
831 GLfloat windowRatio = GLfloat(width()) / GLfloat(height());
832 gluPickMatrix(GLdouble(cPos.x()), GLdouble(viewport[3] - cPos.y()),
833 1.0, 1.0, viewport);
834
835 if (windowRatio < 1)
836 {
837 windowRatio = 1.0f/windowRatio;
838 gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
839 }
840 else
841 {
842 gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
843 }
844
845 glMatrixMode(GL_MODELVIEW);
846 drawCamera(false);
847 glMatrixMode(GL_PROJECTION);
848 glPopMatrix();
849
850 //for some reason that I cannot understand, the push/pop matrix doesn't do the trick here... bizarre
851 //ok, so re-do the resizeGL thing.
852 resizeGL(width(), height());
853
854 if (!glRenderMode(GL_RENDER))
855 return -1;
856
857 return buffer[3];
858}
859/************************************************************
860 * OPEN FILE. opens a new fits file
861 ************************************************************/
862void RawDataViewer::openFile(string& file)
863{
864 if (inputFile)
865 {
866 inputFile->close();
867 delete inputFile;
868 }
869 inputFile = new fits(file);
870 if (!*inputFile)
871 {
872 delete inputFile;
873 inputFile = NULL;
874 return;
875 }
876 vector<string> entriesToCheck;
877 entriesToCheck.push_back("NAXIS2");
878 entriesToCheck.push_back("NROI");
879 entriesToCheck.push_back("NTMARK");
880 entriesToCheck.push_back("RUNTYPE");
881 entriesToCheck.push_back("REVISION");
882 entriesToCheck.push_back("BLDVER");
883 entriesToCheck.push_back("RUNID");
884 entriesToCheck.push_back("NBOARD");
885 entriesToCheck.push_back("NPIX");
886 entriesToCheck.push_back("NROITM");
887 entriesToCheck.push_back("TIMESYS");
888 entriesToCheck.push_back("DATE");
889 entriesToCheck.push_back("NIGHT");
890 entriesToCheck.push_back("CAMERA");
891 entriesToCheck.push_back("DAQ");
892 entriesToCheck.push_back("ADCCOUNT");
893 entriesToCheck.push_back("TSTART");
894 entriesToCheck.push_back("TSTOP");
895 entriesToCheck.push_back("NBEVTOK");
896 entriesToCheck.push_back("NBEVTREJ");
897 entriesToCheck.push_back("NBEVTBAD");
898
899 for (vector<string>::const_iterator it=entriesToCheck.begin(); it != entriesToCheck.end(); it++)
900 {
901 if (!inputFile->HasKey(*it)){
902 cout << *it << " missing. Aborting load..." << endl;
903 return;}
904 }
905 nRows = inputFile->GetInt("NAXIS2");
906 nRoi = inputFile->GetInt("NROI");
907 runNumber = inputFile->GetInt("RUNID");
908 nTM = inputFile->GetInt("NTMARK");
909 runType = inputFile->GetInt("RUNTYPE");
910 firstDataTime = inputFile->GetInt("TSTART");
911 lastDataTime = inputFile->GetInt("TSTOP");
912 nRoiTM = inputFile->GetInt("NROITM");
913 revision = inputFile->GetInt("REVISION");
914 builderVersion = inputFile->GetInt("BLDVER");
915 nBoards = inputFile->GetInt("NBOARD");
916 nPixels = inputFile->GetInt("NPIX");
917 timeSystem = inputFile->GetStr("TIMESYS");
918 creationDate = inputFile->GetStr("DATE");
919 nightInt = inputFile->GetInt("NIGHT");
920 camera = inputFile->GetStr("CAMERA");
921 daq = inputFile->GetStr("DAQ");
922 adcCount = inputFile->GetFloat("ADCCOUNT");
923 nbOk = inputFile->GetInt("NBEVTOK");
924 nbRej = inputFile->GetInt("NBEVTREJ");
925 nbBad = inputFile->GetInt("NBEVTBAD");
926
927 eventNum = 0;
928
929#ifdef LOAD_RAW
930 nRows = NUM_STORED_EVENTS;
931#endif
932
933 if (eventData != NULL)
934 delete[] eventData;
935 eventData = new int16_t[(1440+160)*nRoi];
936 if (!inputFile->SetPtrAddress("Data", eventData)){
937 cout << "Missing column " << "Data" << " Aborting load..." << endl;
938 nRoi = nRows = 0;}
939 if (!inputFile->SetPtrAddress("EventNum", &eventNum)){
940 cout << "Missing column " << "EventNum" << " Aborting load..." << endl;
941 nRoi = nRows = 0;}
942 if (!inputFile->SetPtrAddress("TriggerType", &triggerType)){
943 cout << "Missing column " << "TriggerType" << " Aborting load..." << endl;
944 nRoi = nRows = 0;}
945 if (!inputFile->SetPtrAddress("SoftTrig", &softTrig)){
946 cout << "Missing column " << "SoftTrig" << " Aborting load..." << endl;
947 nRoi = nRows = 0;}
948 if (!inputFile->SetPtrAddress("PCTime", &pcTime)){
949 cout << "Missing column " << "PCTime" << " Aborting load..." << endl;
950 nRoi = nRows = 0;}
951 if (!inputFile->SetPtrAddress("BoardTime", boardTime)){
952 cout << "Missing column " << "BoardTime" << " Aborting load..." << endl;
953 nRoi = nRows = 0;}
954 if (!inputFile->SetPtrAddress("StartCellData", startPix)){
955 cout << "Missing column " << "StartCellData" << " Aborting load..." << endl;
956 nRoi = nRows = 0;}
957 if (!inputFile->SetPtrAddress("StartCellTimeMarker", startTM)){
958 cout << "Missing column " << "StartCellTimeMarker" << " Aborting load..." << endl;
959 nRoi = nRows = 0;}
960 int backupStep = eventStep;
961 rowNum = -1;
962 eventStep = 1;
963 plusEvent();
964 eventStep = backupStep;
965 emit newFileLoaded();
966 emit signalCurrentPixel(selectedPixel);
967}
968
969/************************************************************
970 * PLUS EVENT
971 ************************************************************/
972void RawDataViewer::plusEvent()
973{
974 eventStepping(true);
975}
976/************************************************************
977 * MINUS EVENT
978 ************************************************************/
979void RawDataViewer::minusEvent()
980{
981 eventStepping(false);
982}
983/************************************************************
984 * SET EVENT STEP
985 ************************************************************/
986void RawDataViewer::setEventStep(int step)
987{
988 eventStep = step;
989}
990/************************************************************
991 * EVENT STEPPING
992 ************************************************************/
993void RawDataViewer::eventStepping(bool plus)
994{
995 if (plus)
996 rowNum += eventStep;
997 else
998 rowNum -= eventStep;
999 if (rowNum >= nRows)
1000 rowNum -= nRows;
1001 if (rowNum < 0)
1002 rowNum += nRows;
1003#ifdef LOAD_RAW
1004 eventNum+=eventStep;
1005#else
1006 if (inputFile == NULL)
1007 return;
1008 inputFile->GetRow(rowNum);
1009#endif
1010
1011 updateGL();
1012 emit signalCurrentEvent(eventNum);
1013 emit signalCurrentPixel(selectedPixel);
1014
1015}
1016/************************************************************
1017 * NEXT SLICE. deprec ?
1018 ************************************************************/
1019void RawDataViewer::nextSlice()
1020{
1021 whichSlice++;
1022 if (whichSlice >= nRoi)
1023 {
1024 if (!loopCurrentEvent)
1025 {
1026 int backupStep = eventStep;
1027 eventStep = 1;
1028 eventStepping(true);
1029 eventStep = backupStep;
1030 }
1031 whichSlice=0;
1032 }
1033 emit signalCurrentSlice(whichSlice);
1034 updateGL();
1035}
1036void RawDataViewer::previousSlice()
1037{
1038 whichSlice--;
1039 if (whichSlice < 0)
1040 {
1041 if (!loopCurrentEvent)
1042 {
1043 int backupStep = eventStep;
1044 eventStep = 1;
1045 eventStepping(false);
1046 eventStep = backupStep;
1047 }
1048 whichSlice = nRoi-1;
1049 }
1050 emit signalCurrentSlice(whichSlice);
1051 updateGL();
1052}
1053/************************************************************
1054 * UICONNECTOR CONSTRUCTOR
1055 ************************************************************/
1056UIConnector::UIConnector(QWidget*)
1057{
1058 timer.setInterval(10.0);
1059 QObject::connect(&timer, SIGNAL(timeout()),
1060 this, SLOT(nextSlicePlease()));
1061 hwID = 393;
1062 swID = 0;
1063 crateID = 9;
1064 boardID = 8;
1065 patchID = 1;
1066 rescaleWholeCamera = true;
1067}
1068void UIConnector::slicesPlusPlus()
1069{
1070 viewer->nextSlice();
1071}
1072void UIConnector::slicesMinusMinus()
1073{
1074 viewer->previousSlice();
1075}
1076/************************************************************
1077 * DRAW PATCHES CHECK CHANGE. checkbox handler
1078 ************************************************************/
1079void UIConnector::drawPatchesCheckChange(int state)
1080{
1081 if (state)
1082 viewer->drawPatch = true;
1083 else
1084 viewer->drawPatch = false;
1085 viewer->updateGL();
1086}
1087/************************************************************
1088 * DRAW IMPULSE CHECK CHANGE. checkbox handler
1089 ************************************************************/
1090void UIConnector::drawImpulseCheckChange(int state)
1091{
1092 if (state)
1093 viewer->drawImpulse = true;
1094 else
1095 viewer->drawImpulse = false;
1096 viewer->updateGL();
1097}
1098/************************************************************
1099 * DRAW BLUR CHECK CHANGE. checkbox handler
1100 ************************************************************/
1101void UIConnector::drawBlurCheckChange(int state)
1102{
1103 if (state)
1104 viewer->drawBlur = true;
1105 else
1106 viewer->drawBlur = false;
1107 viewer->updateGL();
1108}
1109void UIConnector::loopEventCheckChange(int state)
1110{
1111 if (state)
1112 viewer->loopCurrentEvent = true;
1113 else
1114 viewer->loopCurrentEvent = false;
1115}
1116/************************************************************
1117 * NEXT SLICE PLEASE
1118 ************************************************************/
1119void UIConnector::nextSlicePlease()
1120{
1121 viewer->nextSlice();
1122}
1123/************************************************************
1124 * SET VIEWER.
1125 ************************************************************/
1126void UIConnector::setViewer(RawDataViewer* v)
1127{
1128 viewer = v;
1129}
1130/************************************************************
1131 * SLICES PER SECOND CHANGED. timing ui handler
1132 ************************************************************/
1133void UIConnector::slicesPerSecondChanged(double value)
1134{
1135 timer.setInterval(1000.0/value);
1136}
1137/************************************************************
1138 * RANGE CHANGED . colors tweaking handler
1139 ************************************************************/
1140void UIConnector::rangeChanged0(double value)
1141{
1142 ss[0] = (float)value;
1143 viewer->updateGL();
1144}
1145/************************************************************
1146 * RANGE CHANGED . colors tweaking handler
1147 ************************************************************/
1148void UIConnector::rangeChanged1(double value)
1149{
1150 ss[1] = (float)value;
1151 viewer->updateGL();
1152}
1153/************************************************************
1154 * RANGE CHANGED . colors tweaking handler
1155 ************************************************************/
1156void UIConnector::rangeChanged2(double value)
1157{
1158 ss[2] = (float)value;
1159 viewer->updateGL();
1160}
1161/************************************************************
1162 * RANGE CHANGED . colors tweaking handler
1163 ************************************************************/
1164void UIConnector::rangeChanged3(double value)
1165{
1166 ss[3] = (float)value;
1167 viewer->updateGL();
1168}
1169/************************************************************
1170 * RANGE CHANGED . colors tweaking handler
1171 ************************************************************/
1172void UIConnector::rangeChanged4(double value)
1173{
1174 ss[4] = (float)value;
1175 viewer->updateGL();
1176}
1177/************************************************************
1178 * RANGE CHANGED . colors tweaking handler
1179 ************************************************************/
1180void UIConnector::redChanged0(double value)
1181{
1182 rr[0] = (float)value;
1183 viewer->updateGL();
1184}
1185/************************************************************
1186 * RED CHANGED . colors tweaking handler
1187 ************************************************************/
1188void UIConnector::redChanged1(double value)
1189{
1190 rr[1] = (float)value;
1191 viewer->updateGL();
1192}
1193/************************************************************
1194 * RED CHANGED . colors tweaking handler
1195 ************************************************************/
1196void UIConnector::redChanged2(double value)
1197{
1198 rr[2] = (float)value;
1199 viewer->updateGL();
1200}
1201/************************************************************
1202 * RED CHANGED . colors tweaking handler
1203 ************************************************************/
1204void UIConnector::redChanged3(double value)
1205{
1206 rr[3] = (float)value;
1207 viewer->updateGL();
1208}
1209/************************************************************
1210 * RED CHANGED . colors tweaking handler
1211 ************************************************************/
1212void UIConnector::redChanged4(double value)
1213{
1214 rr[4] = (float)value;
1215 viewer->updateGL();
1216}
1217/************************************************************
1218 * GREEN CHANGED . colors tweaking handler
1219 ************************************************************/
1220void UIConnector::greenChanged0(double value)
1221{
1222 gg[0] = (float)value;
1223 viewer->updateGL();
1224}
1225/************************************************************
1226 * GREEN CHANGED . colors tweaking handler
1227 ************************************************************/
1228void UIConnector::greenChanged1(double value)
1229{
1230 gg[1] = (float)value;
1231 viewer->updateGL();
1232}
1233/************************************************************
1234 * GREEN CHANGED . colors tweaking handler
1235 ************************************************************/
1236void UIConnector::greenChanged2(double value)
1237{
1238 gg[2] = (float)value;
1239 viewer->updateGL();
1240}
1241/************************************************************
1242 * GREEN CHANGED . colors tweaking handler
1243 ************************************************************/
1244void UIConnector::greenChanged3(double value)
1245{
1246 gg[3] = (float)value;
1247 viewer->updateGL();
1248}
1249/************************************************************
1250 * GREEN CHANGED . colors tweaking handler
1251 ************************************************************/
1252void UIConnector::greenChanged4(double value)
1253{
1254 gg[4] = (float)value;
1255 viewer->updateGL();
1256}
1257/************************************************************
1258 * BLUE CHANGED . colors tweaking handler
1259 ************************************************************/
1260void UIConnector::blueChanged0(double value)
1261{
1262 bb[0] = (float)value;
1263 viewer->updateGL();
1264}
1265/************************************************************
1266 * BLUE CHANGED . colors tweaking handler
1267 ************************************************************/
1268void UIConnector::blueChanged1(double value)
1269{
1270 bb[1] = (float)value;
1271 viewer->updateGL();
1272}
1273/************************************************************
1274 * BLUE CHANGED . colors tweaking handler
1275 ************************************************************/
1276void UIConnector::blueChanged2(double value)
1277{
1278 bb[2] = (float)value;
1279 viewer->updateGL();
1280}
1281/************************************************************
1282 * BLUE CHANGED . colors tweaking handler
1283 ************************************************************/
1284void UIConnector::blueChanged3(double value)
1285{
1286 bb[3] = (float)value;
1287 viewer->updateGL();
1288}
1289/************************************************************
1290 * BLUE CHANGED . colors tweaking handler
1291 ************************************************************/
1292void UIConnector::blueChanged4(double value)
1293{
1294 bb[4] = (float)value;
1295 viewer->updateGL();
1296}
1297/************************************************************
1298 * LOAD NEW FILE CLICKED. button handler
1299 ************************************************************/
1300void UIConnector::loadNewFileClicked()
1301{
1302 QFileDialog dialog;
1303 dialog.setFileMode(QFileDialog::ExistingFile);
1304 dialog.open(this, SLOT(fileSelected(QString)));
1305 dialog.setVisible(true);
1306 dialog.exec();
1307}
1308/************************************************************
1309 * FILE SELECTED. return of the file open dialog handler
1310 ************************************************************/
1311void UIConnector::fileSelected(QString file)
1312{
1313 currentFile = file.toStdString();
1314 if (currentFile != "")
1315 viewer->openFile(currentFile);
1316}
1317/************************************************************
1318 * NEW FILE LOADED. update of the UI after a new file has been loaded
1319 ************************************************************/
1320void UIConnector::newFileLoaded()
1321{
1322 ostringstream str;
1323 str << "File loaded: " << currentFile << "\n";
1324// fileLoadedLabel->setText(QString(str.str().c_str()));
1325// str.str("");
1326 str << "Run number: " << viewer->runNumber << "\n";
1327// runNumberLabel->setText(QString(str.str().c_str()));
1328// str.str("");
1329 str << "Number of Events: " << viewer->nRows << "\n";
1330 str << "Number of Slices: " << viewer->nRoi << "\n";// << "/1024";
1331// numberOfSlicesLabel->setText(QString(str.str().c_str()));
1332// str.str("");
1333 str << "Number of Time Marks: " << viewer->nTM << "\n";
1334// numberOfTimeMarksLabel->setText(QString(str.str().c_str()));
1335
1336// str.str("");
1337 str << "Run Type: " << viewer->runType << "\n";
1338// runTypeLabel->setText(QString(str.str().c_str()));
1339// str.str("");
1340 str << "Time of 1st data: " << viewer->firstDataTime << "\n";
1341// firstTimeLabel->setText(QString(str.str().c_str()));
1342// str.str("");
1343 str << "Time of last data: " << viewer->lastDataTime << "\n";
1344// lastTimeLabel->setText(QString(str.str().c_str()));
1345// str.str("");
1346 str << "SVN revision: " << viewer->revision << '\n';
1347 str << "Number of boards: " << viewer->nBoards << '\n';
1348 str << "Number of pixels: " << viewer->nPixels << '\n';
1349 str << "Number of Slices TM: " << viewer->nRoiTM << '\n';
1350 str << "Time system: " << viewer->timeSystem << '\n';
1351 str << "Date: " << viewer->creationDate << '\n';
1352 str << "Night: " << viewer->nightInt << '\n';
1353 str << "Camera: " << viewer->camera << '\n';
1354 str << "DAQ: " << viewer->daq << '\n';
1355 str << "ADC Count: " << viewer->adcCount << '\n';
1356 str << "NB Evts OK:" << viewer->nbOk << '\n';
1357 str << "NB Evts Rejected: " << viewer->nbRej << '\n';
1358 str << "NB Evts Bad: " << viewer->nbBad << '\n';
1359 extraInfoLabel->setText(QString(str.str().c_str()));
1360
1361
1362}
1363/************************************************************
1364 * PLAY PAUSE CLICKED. ui handler
1365 ************************************************************/
1366void UIConnector::playPauseClicked()
1367{
1368 if (timer.isActive())
1369 timer.stop();
1370 else
1371 timer.start();
1372}
1373/************************************************************
1374 * CURRENT SLICE HAS CHANGE. ui handler
1375 ************************************************************/
1376void UIConnector::currentSliceHasChanged(int slice)
1377{
1378 ostringstream str;
1379 str << "Displaying Slice " << slice;
1380 QString qstr(str.str().c_str());
1381 emit updateCurrentSliceDisplay(qstr);
1382
1383 str.str("");
1384 str << "Current Pixel val.: " << viewer->eventData[viewer->nRoi*viewer->selectedPixel + viewer->whichSlice];
1385 qstr = qstr.fromStdString(str.str());
1386 emit updateCurrentPixelSliceValue(qstr);
1387
1388}
1389/************************************************************
1390 * CURRENT EVENT HAS CHANGED. ui handler
1391 ************************************************************/
1392double xval[4096];
1393double yval[4096];
1394
1395void UIConnector::currentEventHasChanged(int cEvent)
1396{
1397 ostringstream str;
1398 str << "Displaying Event " << cEvent;
1399 QString qstr(str.str().c_str());
1400 emit updateCurrentEventDisplay(qstr);
1401 //retrieve the data that we want to display
1402 str.str("");
1403 str << "PC Time: " << viewer->pcTime;
1404 qstr = qstr.fromStdString(str.str());
1405 emit updateCurrentPCTime(qstr);
1406
1407 str.str("");
1408 str << "Software Trigger: " << viewer->softTrig;
1409 qstr = qstr.fromStdString(str.str());
1410 emit updateCurrentSoftTrigger(qstr);
1411
1412 str.str("");
1413 str << "Trigger Type: " << viewer->triggerType;
1414 qstr = qstr.fromStdString(str.str());
1415 emit updateCurrentTriggerType(qstr);
1416
1417 str.str("");
1418 str << "Current Pixel val.: " << viewer->eventData[viewer->nRoi*viewer->selectedPixel + viewer->whichSlice];
1419 qstr = qstr.fromStdString(str.str());
1420 emit updateCurrentPixelSliceValue(qstr);
1421
1422 boardsTimeList->clear();
1423 startPixelsList->clear();
1424 startTimeMarksList->clear();
1425 triggerDelayList->clear();
1426 std::map<int, int> boardsHistoMap;
1427 for (int i=0;i <NBOARDS; i++)
1428 {
1429 str.str("");
1430 str << i;
1431 if (i<10) str << " ";
1432 if (i<100) str << " ";
1433 if (i<1000) str << " ";
1434 str << ": " << viewer->boardTime[i];
1435 boardsTimeList->addItem(QString(str.str().c_str()));
1436 if (boardsHistoMap.find(viewer->boardTime[i]) != boardsHistoMap.end())
1437 boardsHistoMap[viewer->boardTime[i]]++;
1438 else
1439 boardsHistoMap[viewer->boardTime[i]] = 1;
1440 }
1441 std::map<int, int> pixelHistoMap;
1442 for (int i=0;i <NPIX; i++)
1443 {
1444 str.str("");
1445 str << i;
1446 if (i<10) str << " ";
1447 if (i<100) str << " ";
1448 if (i<1000) str << " ";
1449 str << ": " << viewer->startPix[i];
1450 startPixelsList->addItem(QString(str.str().c_str()));
1451 if (pixelHistoMap.find(viewer->startPix[i]) != pixelHistoMap.end())
1452 pixelHistoMap[viewer->startPix[i]]++;
1453 else
1454 pixelHistoMap[viewer->startPix[i]] = 1;
1455 }
1456 std::map<int, int> timeMarksMap;
1457 for (int i=0;i <NTMARK; i++)
1458 {
1459 str.str("");
1460 str << i;
1461 if (i<10) str << " ";
1462 if (i<100) str << " ";
1463 if (i<1000) str << " ";
1464 str << ": " << viewer->startTM[i];
1465 startTimeMarksList->addItem(QString(str.str().c_str()));
1466 if (timeMarksMap.find(viewer->startTM[i]) != timeMarksMap.end())
1467 timeMarksMap[viewer->startTM[i]]++;
1468 else
1469 timeMarksMap[viewer->startTM[i]] = 1;
1470 }
1471 std::map<int,int> delayMap;
1472 triggerDelayList->addItem(QString("Patch | Slice:Delay Slice:Delay..."));
1473 for (int i=0;i<NTMARK; i++)
1474 {
1475 str.str("");
1476 str << i << " | ";
1477 for (int j=0;j<viewer->nRoi;j++)
1478 {
1479 int value = viewer->eventData[1440*viewer->nRoi + i*viewer->nRoi + j];
1480 if (delayMap.find(value) != delayMap.end())
1481 delayMap[value]++;
1482 else
1483 delayMap[value] = 1;
1484 str << j << ":" << value << " ";
1485 }
1486 triggerDelayList->addItem(QString(str.str().c_str()));
1487 }
1488
1489 std::map<int,int>::iterator it = boardsHistoMap.begin();
1490 int nsamples = 0;
1491 int previousValue = it->first-10;
1492 for (unsigned int i=0;i<boardsHistoMap.size();i++)
1493 {
1494 if (previousValue != it->first-1)
1495 {
1496 xval[nsamples] = previousValue+1;
1497 yval[nsamples] = 0;
1498 nsamples++;
1499 xval[nsamples] = it->first-1;
1500 yval[nsamples] = 0;
1501 nsamples++;
1502 }
1503 xval[nsamples] = it->first;
1504 yval[nsamples] = it->second;
1505 previousValue = it->first;
1506 it++;
1507 nsamples++;
1508 xval[nsamples] = previousValue;
1509 yval[nsamples] = 0;
1510 nsamples++;
1511 if (nsamples > 4090)
1512 {
1513 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1514 break;
1515 }
1516 }
1517 xval[nsamples] = it==boardsHistoMap.begin() ? 0 : (--it)->first+1;
1518 yval[nsamples] = 0;
1519 nsamples++;
1520 // if (nsamples > 5)
1521#if QWT_VERSION < 0x060000
1522 boardsTimeHistoItem.setData(xval, yval, nsamples);
1523#else
1524 boardsTimeHistoItem.setSamples(xval, yval, nsamples);
1525#endif
1526
1527 it = pixelHistoMap.begin();
1528 nsamples = 0;
1529 previousValue = it->first-10;
1530 for (unsigned int i=0;i<pixelHistoMap.size();i++)
1531 {
1532 if (previousValue != it->first-1)
1533 {
1534 xval[nsamples] = previousValue+1;
1535 yval[nsamples] = 0;
1536 nsamples++;
1537 xval[nsamples] = it->first-1;
1538 yval[nsamples] = 0;
1539 nsamples++;
1540 }
1541 xval[nsamples] = it->first;
1542 yval[nsamples] = it->second;
1543 previousValue = it->first;
1544 it++;
1545 nsamples++;
1546 xval[nsamples] = previousValue;
1547 yval[nsamples] = 0;
1548 nsamples++;
1549 if (nsamples > 4090)
1550 {
1551 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1552 break;
1553 }
1554 }
1555 xval[nsamples] = it==pixelHistoMap.begin() ? 0 : (--it)->first+1;
1556 yval[nsamples] = 0;
1557 nsamples++;
1558// if (nsamples > 5)
1559#if QWT_VERSION < 0x060000
1560 startCellHistoItem.setData(xval, yval, nsamples);
1561#else
1562 startCellHistoItem.setSamples(xval, yval, nsamples);
1563#endif
1564
1565 it = timeMarksMap.begin();
1566 nsamples = 0;
1567 previousValue = it->first-10;
1568 for (unsigned int i=0;i<timeMarksMap.size();i++)
1569 {
1570 if (previousValue != it->first-1)
1571 {
1572 xval[nsamples] = previousValue+1;
1573 yval[nsamples] = 0;
1574 nsamples++;
1575 xval[nsamples] = it->first-1;
1576 yval[nsamples] = 0;
1577 nsamples++;
1578 }
1579 xval[nsamples] = it->first;
1580 yval[nsamples] = it->second;
1581 previousValue = it->first;
1582 it++;
1583 nsamples++;
1584 xval[nsamples] = previousValue;
1585 yval[nsamples] = 0;
1586 nsamples++;
1587 if (nsamples > 4090)
1588 {
1589 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1590 break;
1591 }
1592 }
1593 xval[nsamples] = it==timeMarksMap.begin() ? 0 : (--it)->first+1;
1594 yval[nsamples] = 0;
1595 nsamples++;
1596 // if (nsamples > 5)
1597#if QWT_VERSION < 0x060000
1598 startTimeMarkHistoItem.setData(xval, yval, nsamples);
1599#else
1600 startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
1601#endif
1602
1603 it = delayMap.begin();
1604 nsamples = 0;
1605 previousValue = it->first-10;
1606 for (unsigned int i=0;i<delayMap.size();i++)
1607 {
1608 if (previousValue != it->first-1)
1609 {
1610 xval[nsamples] = previousValue+1;
1611 yval[nsamples] = 0;
1612 nsamples++;
1613 xval[nsamples] = it->first-1;
1614 yval[nsamples] = 0;
1615 nsamples++;
1616 }
1617 xval[nsamples] = it->first;
1618 yval[nsamples] = it->second;
1619 previousValue = it->first;
1620 it++;
1621 nsamples++;
1622 xval[nsamples] = previousValue;
1623 yval[nsamples] = 0;
1624 nsamples++;
1625 if (nsamples > 4090)
1626 {
1627 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1628 break;
1629 }
1630 }
1631 xval[nsamples] = it==delayMap.begin() ? 0 : (--it)->first+1;
1632 yval[nsamples] = 0;
1633 nsamples++;
1634 // if (nsamples > 5)
1635#if QWT_VERSION < 0x060000
1636 triggerDelayHistoItem.setData(xval, yval, nsamples);
1637#else
1638 triggerDelayHistoItem.setSamples(xval, yval, nsamples);
1639#endif
1640
1641// startCellHistoZoom->setZoomBase(startCellHistoItem.boundingRect());
1642 QStack< QRectF > stack;
1643 stack.push(boardsTimeHistoItem.boundingRect());
1644 boardsTimeHistoZoom->setZoomStack(stack);
1645 stack.pop();
1646 stack.push(startCellHistoItem.boundingRect());
1647 startCellHistoZoom->setZoomStack(stack);
1648 stack.pop();
1649 stack.push(startTimeMarkHistoItem.boundingRect());
1650 startTimeMarkHistoZoom->setZoomStack(stack);
1651 stack.pop();
1652 stack.push(triggerDelayHistoItem.boundingRect());
1653 triggerDelayHistoZoom->setZoomStack(stack);
1654 stack.pop();
1655 pixelChanged(viewer->selectedPixel);
1656
1657
1658
1659}
1660
1661void UIConnector::initHistograms()
1662{
1663// QwtPlot* boardsTimeHisto;
1664// QwtPlotHistogram boardsTimeHistoItem;
1665 QwtPlotGrid* grid = new QwtPlotGrid;
1666 grid->enableX(false);
1667 grid->enableY(true);
1668 grid->enableXMin(false);
1669 grid->enableYMin(false);
1670 grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1671 grid->attach(boardsTimeHisto);
1672
1673 grid = new QwtPlotGrid;
1674 grid->enableX(false);
1675 grid->enableY(true);
1676 grid->enableXMin(false);
1677 grid->enableYMin(false);
1678 grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1679 grid->attach(startCellHisto);
1680
1681 grid = new QwtPlotGrid;
1682 grid->enableX(false);
1683 grid->enableY(true);
1684 grid->enableXMin(false);
1685 grid->enableYMin(false);
1686 grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1687 grid->attach(startTimeMarkHisto);
1688
1689 grid = new QwtPlotGrid;
1690 grid->enableX(false);
1691 grid->enableY(true);
1692 grid->enableXMin(false);
1693 grid->enableYMin(false);
1694 grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1695 grid->attach(pixelValueCurve);
1696
1697 grid = new QwtPlotGrid;
1698 grid->enableX(false);
1699 grid->enableY(true);
1700 grid->enableXMin(false);
1701 grid->enableYMin(false);
1702 grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1703 grid->attach(triggerDelayHisto);
1704
1705
1706 boardsTimeHisto->setAutoReplot(true);
1707 startCellHisto->setAutoReplot(true);
1708 startTimeMarkHisto->setAutoReplot(true);
1709 pixelValueCurve->setAutoReplot(true);
1710 triggerDelayHisto->setAutoReplot(true);
1711 boardsTimeHisto->setTitle("Boards time values");
1712 startCellHisto->setTitle("Start Cell values");
1713 startTimeMarkHisto->setTitle("Start Time Marks values");
1714 pixelValueCurve->setTitle("Current pixel values");
1715 triggerDelayHisto->setTitle("Trigger Delays");
1716
1717 // boardsTimeHistoItem.setBrush(QBrush(Qt::red));
1718// startCellHistoItem.setBrush(QBrush(Qt::red));
1719// startTimeMarkHistoItem.setBrush(QBrush(Qt::red));
1720// triggerDelayHistoItem.setBrush(QBrush(Qt::red));
1721// pixelValueCurveItem.setBrush(QBrush(Qt::red));
1722
1723 boardsTimeHistoItem.setPen(QColor(Qt::darkGreen));
1724 boardsTimeHistoItem.setStyle(QwtPlotCurve::Steps);
1725 startCellHistoItem.setPen(QColor(Qt::darkGreen));
1726 startCellHistoItem.setStyle(QwtPlotCurve::Steps);
1727 startTimeMarkHistoItem.setPen(QColor(Qt::darkGreen));
1728 startTimeMarkHistoItem.setStyle(QwtPlotCurve::Steps);
1729 triggerDelayHistoItem.setPen(QColor(Qt::darkGreen));
1730 triggerDelayHistoItem.setStyle(QwtPlotCurve::Steps);
1731
1732 boardsTimeHistoItem.attach(boardsTimeHisto);
1733 startCellHistoItem.attach(startCellHisto);
1734 startTimeMarkHistoItem.attach(startTimeMarkHisto);
1735 triggerDelayHistoItem.attach(triggerDelayHisto);
1736
1737 //curve
1738// pixelValueCurveItem.setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush, QPen(Qt::black), QSize(5,5)));
1739 pixelValueCurveItem.setPen(QColor(Qt::darkGreen));
1740 pixelValueCurveItem.setStyle(QwtPlotCurve::Lines);
1741// pixelValueCurveItem.setCurveAttribute(QwtPlotCurve::Fitted);
1742 pixelValueCurveItem.attach(pixelValueCurve);
1743
1744 //FIXME delete these pointers with the destructor
1745 curveZoom = new QwtPlotZoomer(pixelValueCurve->canvas());
1746 curveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1747 curveZoom->setTrackerPen(QPen(Qt::gray));
1748 boardsTimeHistoZoom = new QwtPlotZoomer(boardsTimeHisto->canvas());
1749 boardsTimeHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1750 boardsTimeHistoZoom->setTrackerPen(QPen(Qt::gray));
1751 startCellHistoZoom = new QwtPlotZoomer(startCellHisto->canvas());
1752 startCellHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1753 startCellHistoZoom->setTrackerPen(QPen(Qt::gray));
1754 startTimeMarkHistoZoom = new QwtPlotZoomer(startTimeMarkHisto->canvas());
1755 startTimeMarkHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1756 startTimeMarkHistoZoom->setTrackerPen(QPen(Qt::gray));
1757 triggerDelayHistoZoom = new QwtPlotZoomer(triggerDelayHisto->canvas());
1758 triggerDelayHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1759 triggerDelayHistoZoom->setTrackerPen(QPen(Qt::gray));
1760
1761
1762}
1763void UIConnector::pixelChanged(int pixel)
1764{
1765 if (!viewer->nRoi)
1766 return;
1767
1768 for (int i=0;i<viewer->nRoi;i++)
1769 {
1770 xval[i] = i;
1771#ifdef LOAD_RAW
1772 yval[i] = eventsData[0][pixel][i];
1773#else
1774 yval[i] = viewer->eventData[viewer->nRoi*pixel + i];
1775#endif
1776 }
1777#if QWT_VERSION < 0x060000
1778 pixelValueCurveItem.setRawData(xval, yval, viewer->nRoi);
1779#else
1780 pixelValueCurveItem.setRawSamples(xval, yval, viewer->nRoi);
1781#endif
1782
1783 QStack< QRectF > stack;
1784 stack.push(pixelValueCurveItem.boundingRect());
1785 curveZoom->setZoomStack(stack);
1786 stack.pop();
1787
1788 hwID = pixel;
1789 swID = viewer->softwareMapping[pixel];
1790 crateID = (pixel/4)/10;
1791 boardID = (pixel/4)%10;
1792 patchID = pixel%4;
1793 HwIDBox->setValue(hwID);
1794 SwIDBox->setValue(swID);
1795 crateIDBox->setValue(crateID);
1796 boardIDBox->setValue(boardID);
1797 patchIDBox->setValue(patchID);
1798
1799 ostringstream str;
1800 QString qstr;
1801 str.str("");
1802 str << "Current Pixel val.: " << viewer->eventData[viewer->nRoi*viewer->selectedPixel + viewer->whichSlice];
1803 qstr = qstr.fromStdString(str.str());
1804 emit updateCurrentPixelSliceValue(qstr);
1805
1806// cout << "Pixel: " << viewer->softwareMapping[pixel] << " Hardware ID: " << pixel << " Patch: " << pixel%4;
1807// cout << " Board: " << (pixel/4)%10 << " Crate: " << (pixel/4)/10 << endl;
1808
1809 // curveZoom->setZoomBase();
1810// cout << "pixel changed ! " << pixel << endl;
1811}
1812
1813void UIConnector::hwIDChanged(int hwid)
1814{
1815 hwID = hwid;
1816 swID = viewer->softwareMapping[hwid];
1817 crateID = (hwid/4)/10;
1818 boardID = (hwid/4)%10;
1819 patchID = hwid%4;
1820 HwIDBox->setValue(hwID);
1821 SwIDBox->setValue(swID);
1822 crateIDBox->setValue(crateID);
1823 boardIDBox->setValue(boardID);
1824 patchIDBox->setValue(patchID);
1825
1826 viewer->selectedPixel = hwid;
1827 pixelChanged(hwid);
1828 viewer->updateGL();
1829
1830}
1831void UIConnector::swIDChanged(int swid)
1832{
1833 swID = swid;
1834 hwID = viewer->hardwareMapping[swid];
1835 crateID = (hwID/4)/10;
1836 boardID = (hwID/4)%10;
1837 patchID = hwID%4;
1838 HwIDBox->setValue(hwID);
1839 SwIDBox->setValue(swID);
1840 crateIDBox->setValue(crateID);
1841 boardIDBox->setValue(boardID);
1842 patchIDBox->setValue(patchID);
1843
1844 viewer->selectedPixel = hwID;
1845 pixelChanged(hwID);
1846 viewer->updateGL();
1847}
1848void UIConnector::crateIDChanged(int cid)
1849{
1850 crateID = cid;
1851 hwID = 40*crateID + 4*boardID + patchID;
1852 swID = viewer->softwareMapping[hwID];
1853 HwIDBox->setValue(hwID);
1854 SwIDBox->setValue(swID);
1855 viewer->selectedPixel = hwID;
1856 pixelChanged(hwID);
1857 viewer->updateGL();
1858}
1859void UIConnector::boardIDChanged(int bid)
1860{
1861 boardID = bid;
1862 hwID = 40*crateID + 4*boardID + patchID;
1863 swID = viewer->softwareMapping[hwID];
1864 HwIDBox->setValue(hwID);
1865 SwIDBox->setValue(swID);
1866 viewer->selectedPixel = hwID;
1867 pixelChanged(hwID);
1868 viewer->updateGL();
1869}
1870void UIConnector::patchIDChanged(int pid)
1871{
1872 patchID = pid;
1873 hwID = 40*crateID + 4*boardID + patchID;
1874 swID = viewer->softwareMapping[hwID];
1875 HwIDBox->setValue(hwID);
1876 SwIDBox->setValue(swID);
1877 viewer->selectedPixel = hwID;
1878 pixelChanged(hwID);
1879 viewer->updateGL();
1880}
1881void UIConnector::autoScalePressed()
1882{
1883 if (!viewer->nRoi)
1884 return;
1885 int start, end;
1886 if (rescaleWholeCamera)
1887 {
1888 start = 0;
1889 end = 1440;
1890 }
1891 else
1892 {
1893 start = viewer->selectedPixel;
1894 end = viewer->selectedPixel+1;
1895 }
1896
1897 int min = 10000; //real min = -2048
1898 int max = -10000; //real max = 2047
1899 long average = 0;
1900 int numSamples = 0;
1901 for (int i=start;i<end;i++)
1902 {
1903 for (int j=0;j<viewer->nRoi;j++)
1904 {
1905 int cValue = viewer->eventData[i*viewer->nRoi+j];
1906 if (cValue > max)
1907 max = cValue;
1908 if (cValue < min)
1909 min = cValue;
1910 average+=cValue;
1911 numSamples++;
1912 }
1913 }
1914 average /= numSamples;
1915
1916 double minRange = (double)(min+(VALUES_SPAN/2))/(double)VALUES_SPAN;
1917 double maxRange = (double)(max+(VALUES_SPAN/2))/(double)VALUES_SPAN;
1918 double midRange = (double)(average+(VALUES_SPAN/2))/(double)VALUES_SPAN;
1919 ss[0] = minRange;
1920 range0->setValue(ss[0]);
1921 ss[4] = maxRange;
1922 range4->setValue(ss[4]);
1923 ss[2] = midRange;
1924 range2->setValue(ss[2]);
1925 ss[1] = (minRange+midRange)/2;
1926 range1->setValue(ss[1]);
1927 ss[3] = (maxRange+midRange)/2;
1928 range3->setValue(ss[3]);
1929
1930
1931}
1932void UIConnector::entireCameraChanged(bool state)
1933{
1934 if (state)
1935 {
1936 rescaleWholeCamera = true;
1937 currentPixelScale->setChecked(false);
1938 }
1939 else
1940 {
1941 rescaleWholeCamera = false;
1942 currentPixelScale->setChecked(true);
1943 }
1944}
1945void UIConnector::currentPixelChanged(bool state)
1946{
1947
1948 if (state)
1949 {
1950 rescaleWholeCamera = false;
1951 entireCameraScale->setChecked(false);
1952 }
1953 else
1954 {
1955 rescaleWholeCamera = true;
1956 entireCameraScale->setChecked(true);
1957 }
1958}
1959void PrintHelp()
1960{
1961 cout <<
1962 "\n"
1963 << endl;
1964}
1965void SetupConfiguration(Configuration& conf)
1966{
1967 po::options_description configs("Raw Events Viewer Options");
1968 configs.add_options()
1969 ("color.range", vars<double>(), "Range of the display colours")
1970 ("color.red", vars<double>(), "Range of red values")
1971 ("color.rreen", vars<double>(), "Range of green values")
1972 ("color.blue", vars<double>(), "Range of blue values")
1973 ("file,f", var<string>(), "File to be loaded at startup")
1974 ;
1975 conf.AddOptions(configs);
1976
1977 po::positional_options_description p;
1978 p.add("file", 1); // The first positional options
1979 conf.SetArgumentPositions(p);
1980
1981}
1982/************************************************************
1983 * MAIN PROGRAM FUNCTION.
1984 ************************************************************/
1985int main(int argc, char *argv[])
1986{
1987 Configuration conf(argv[0]);
1988 conf.SetPrintUsage(PrintHelp);
1989 SetupConfiguration(conf);
1990 if (!conf.DoParse(argc, const_cast<const char**>(argv), PrintHelp))
1991 return -1;
1992
1993 if (conf.Has("color.range"))
1994 {
1995 vector<double> value = conf.Vec<double>("color.range");
1996 if (value.size() != 5)
1997 {
1998 cout << "Error, colorRange option should have exactly 5 double values" << endl;
1999 return -1;
2000 }
2001 for (int i=0;i<5;i++)
2002 ss[i] = value[i];
2003 }
2004
2005 if (conf.Has("color.red"))
2006 {
2007 vector<double> value = conf.Vec<double>("color.red");
2008 if (value.size() != 5)
2009 {
2010 cout << "Error, colorRed option should have exactly 5 double values" << endl;
2011 return -1;
2012 }
2013 for (int i=0;i<5;i++)
2014 rr[i] = value[i];
2015 }
2016
2017 if (conf.Has("color.green"))
2018 {
2019 vector<double> value = conf.Vec<double>("color.green");
2020 if (value.size() != 5)
2021 {
2022 cout << "Error, colorGreen option should have exactly 5 double values" << endl;
2023 return -1;
2024 }
2025 for (int i=0;i<5;i++)
2026 gg[i] = value[i];
2027 }
2028
2029 if (conf.Has("color.blue"))
2030 {
2031 vector<double> value = conf.Vec<double>("color.blue");
2032 if (value.size() != 5)
2033 {
2034 cout << "Error, colorBlue option should have exactly 5 double values" << endl;
2035 return -1;
2036 }
2037 for (int i=0;i<5;i++)
2038 bb[i] = value[i];
2039 }
2040
2041 QApplication app(argc, argv);
2042
2043 if (!QGLFormat::hasOpenGL()) {
2044 std::cerr << "This system has no OpenGL support" << std::endl;
2045 return 1;
2046 }
2047
2048 QMainWindow mainWindow;
2049
2050 Ui_MainWindow myUi;
2051 myUi.setupUi(&mainWindow);
2052
2053 RawDataViewer *canvas = myUi.GLWindow;
2054
2055 QObject::connect(myUi.eventsMinusButton, SIGNAL(clicked()),
2056 canvas, SLOT(minusEvent()));
2057 QObject::connect(myUi.eventsPlusButton, SIGNAL(clicked()),
2058 canvas, SLOT(plusEvent()));
2059 QObject::connect(myUi.eventsStepBox, SIGNAL(valueChanged(int)),
2060 canvas, SLOT(setEventStep(int)));
2061 myUi.colorRange0->setValue(ss[0]);
2062 myUi.colorRange1->setValue(ss[1]);
2063 myUi.colorRange2->setValue(ss[2]);
2064 myUi.colorRange3->setValue(ss[3]);
2065 myUi.colorRange4->setValue(ss[4]);
2066 myUi.redValue0->setValue(rr[0]);
2067 myUi.redValue1->setValue(rr[1]);
2068 myUi.redValue2->setValue(rr[2]);
2069 myUi.redValue3->setValue(rr[3]);
2070 myUi.redValue4->setValue(rr[4]);
2071 myUi.greenValue0->setValue(gg[0]);
2072 myUi.greenValue1->setValue(gg[1]);
2073 myUi.greenValue2->setValue(gg[2]);
2074 myUi.greenValue3->setValue(gg[3]);
2075 myUi.greenValue4->setValue(gg[4]);
2076 myUi.blueValue0->setValue(bb[0]);
2077 myUi.blueValue1->setValue(bb[1]);
2078 myUi.blueValue2->setValue(bb[2]);
2079 myUi.blueValue3->setValue(bb[3]);
2080 myUi.blueValue4->setValue(bb[4]);
2081
2082 UIConnector connector;
2083 connector.setViewer(canvas);
2084 connector.boardsTimeList = myUi.boardsTimeList;
2085 connector.boardsTimeHisto = myUi.boardsTimeHisto;
2086 connector.startPixelsList = myUi.startPixelsList;
2087 connector.startCellHisto = myUi.startCellsHisto;
2088 connector.startTimeMarkHisto = myUi.startTimeMarkHisto;
2089 connector.pixelValueCurve = myUi.pixelValueCurve;
2090 connector.triggerDelayHisto = myUi.triggerDelayHisto;
2091 connector.triggerDelayList = myUi.triggerDelayList;
2092
2093 connector.startTimeMarksList = myUi.startTimeMarksList;
2094// connector.fileLoadedLabel = myUi.fileLoadedLabel;
2095// connector.runNumberLabel = myUi.runNumberLabel;
2096// connector.numberOfSlicesLabel = myUi.numberOfSlicesLabel;
2097// connector.numberOfTimeMarksLabel = myUi.numberOfTimeMarksLabel;
2098// connector.runTypeLabel = myUi.runTypeLabel;
2099// connector.firstTimeLabel = myUi.timeOfFirstDataLabel;
2100// connector.lastTimeLabel = myUi.timeOfLastDataLabel;
2101 connector.currentPixelValue = myUi.currentPixelValue;
2102
2103 connector.currentPixelScale = myUi.currentPixelScale;
2104 connector.entireCameraScale = myUi.entireCameraScale;
2105
2106 connector.extraInfoLabel = myUi.extraInfoLabel;
2107
2108 connector.HwIDBox = myUi.HwIDBox;
2109 connector.SwIDBox = myUi.SwIDBox;
2110 connector.crateIDBox = myUi.crateIDBox;
2111 connector.boardIDBox = myUi.boardIDBox;
2112 connector.patchIDBox = myUi.patchIDBox;
2113
2114 connector.range0 = myUi.colorRange0;
2115 connector.range1 = myUi.colorRange1;
2116 connector.range2 = myUi.colorRange2;
2117 connector.range3 = myUi.colorRange3;
2118 connector.range4 = myUi.colorRange4;
2119
2120 connector.initHistograms();
2121
2122 QObject::connect(myUi.slicesPlusPlusButton, SIGNAL(clicked()),
2123 &connector, SLOT(slicesPlusPlus()));
2124 QObject::connect(myUi.slicesMinusMinusButton, SIGNAL(clicked()),
2125 &connector, SLOT(slicesMinusMinus()));
2126 QObject::connect(myUi.autoScaleColor, SIGNAL(clicked()),
2127 &connector, SLOT(autoScalePressed()));
2128 QObject::connect(myUi.currentPixelScale, SIGNAL(toggled(bool)),
2129 &connector, SLOT(currentPixelChanged(bool)));
2130 QObject::connect(myUi.entireCameraScale, SIGNAL(toggled(bool)),
2131 &connector, SLOT(entireCameraChanged(bool)));
2132
2133 QObject::connect(myUi.HwIDBox, SIGNAL(valueChanged(int)),
2134 &connector, SLOT(hwIDChanged(int)));
2135 QObject::connect(myUi.SwIDBox, SIGNAL(valueChanged(int)),
2136 &connector, SLOT(swIDChanged(int)));
2137 QObject::connect(myUi.crateIDBox, SIGNAL(valueChanged(int)),
2138 &connector, SLOT(crateIDChanged(int)));
2139 QObject::connect(myUi.boardIDBox, SIGNAL(valueChanged(int)),
2140 &connector, SLOT(boardIDChanged(int)));
2141 QObject::connect(myUi.patchIDBox, SIGNAL(valueChanged(int)),
2142 &connector, SLOT(patchIDChanged(int)));
2143
2144 // connector.pixelChanged(0);
2145 QObject::connect(canvas, SIGNAL(signalCurrentPixel(int)),
2146 &connector, SLOT(pixelChanged(int)));
2147 QObject::connect(myUi.drawPatchCheckBox, SIGNAL(stateChanged(int)),
2148 &connector, SLOT(drawPatchesCheckChange(int)));
2149 QObject::connect(myUi.drawImpulseCheckBox, SIGNAL(stateChanged(int)),
2150 &connector, SLOT(drawImpulseCheckChange(int)));
2151 QObject::connect(myUi.drawBlurCheckBox, SIGNAL(stateChanged(int)),
2152 &connector, SLOT(drawBlurCheckChange(int)));
2153 QObject::connect(myUi.loopOverCurrentEventBox, SIGNAL(stateChanged(int)),
2154 &connector, SLOT(loopEventCheckChange(int)));
2155 QObject::connect(canvas, SIGNAL(newFileLoaded()),
2156 &connector, SLOT(newFileLoaded()));
2157
2158 QObject::connect(myUi.loadNewFileButton, SIGNAL(clicked()),
2159 &connector, SLOT(loadNewFileClicked()));
2160
2161 QObject::connect(myUi.colorRange0, SIGNAL(valueChanged(double)),
2162 &connector, SLOT(rangeChanged0(double)));
2163
2164 QObject::connect(myUi.colorRange1, SIGNAL(valueChanged(double)),
2165 &connector, SLOT(rangeChanged1(double)));
2166
2167 QObject::connect(myUi.colorRange2, SIGNAL(valueChanged(double)),
2168 &connector, SLOT(rangeChanged2(double)));
2169
2170 QObject::connect(myUi.colorRange3, SIGNAL(valueChanged(double)),
2171 &connector, SLOT(rangeChanged3(double)));
2172
2173 QObject::connect(myUi.colorRange4, SIGNAL(valueChanged(double)),
2174 &connector, SLOT(rangeChanged4(double)));
2175
2176 QObject::connect(myUi.redValue0, SIGNAL(valueChanged(double)),
2177 &connector, SLOT(redChanged0(double)));
2178
2179 QObject::connect(myUi.redValue1, SIGNAL(valueChanged(double)),
2180 &connector, SLOT(redChanged1(double)));
2181
2182 QObject::connect(myUi.redValue2, SIGNAL(valueChanged(double)),
2183 &connector, SLOT(redChanged2(double)));
2184
2185 QObject::connect(myUi.redValue3, SIGNAL(valueChanged(double)),
2186 &connector, SLOT(redChanged3(double)));
2187
2188 QObject::connect(myUi.redValue4, SIGNAL(valueChanged(double)),
2189 &connector, SLOT(redChanged4(double)));
2190
2191 QObject::connect(myUi.greenValue0, SIGNAL(valueChanged(double)),
2192 &connector, SLOT(greenChanged0(double)));
2193
2194 QObject::connect(myUi.greenValue1, SIGNAL(valueChanged(double)),
2195 &connector, SLOT(greenChanged1(double)));
2196
2197 QObject::connect(myUi.greenValue2, SIGNAL(valueChanged(double)),
2198 &connector, SLOT(greenChanged2(double)));
2199
2200 QObject::connect(myUi.greenValue3, SIGNAL(valueChanged(double)),
2201 &connector, SLOT(greenChanged3(double)));
2202
2203 QObject::connect(myUi.greenValue4, SIGNAL(valueChanged(double)),
2204 &connector, SLOT(greenChanged4(double)));
2205
2206 QObject::connect(myUi.blueValue0, SIGNAL(valueChanged(double)),
2207 &connector, SLOT(blueChanged0(double)));
2208
2209 QObject::connect(myUi.blueValue1, SIGNAL(valueChanged(double)),
2210 &connector, SLOT(blueChanged1(double)));
2211
2212 QObject::connect(myUi.blueValue2, SIGNAL(valueChanged(double)),
2213 &connector, SLOT(blueChanged2(double)));
2214
2215 QObject::connect(myUi.blueValue3, SIGNAL(valueChanged(double)),
2216 &connector, SLOT(blueChanged3(double)));
2217
2218 QObject::connect(myUi.blueValue4, SIGNAL(valueChanged(double)),
2219 &connector, SLOT(blueChanged4(double)));
2220
2221 QObject::connect(myUi.slicesPerSecValue, SIGNAL(valueChanged(double)),
2222 &connector, SLOT(slicesPerSecondChanged(double)));
2223 QObject::connect(myUi.playPauseButton, SIGNAL(clicked()),
2224 &connector, SLOT(playPauseClicked()));
2225
2226 QObject::connect(canvas, SIGNAL(signalCurrentSlice(int)),
2227 &connector, SLOT(currentSliceHasChanged(int)));
2228 QObject::connect(canvas, SIGNAL(signalCurrentEvent(int)),
2229 &connector, SLOT(currentEventHasChanged(int)));
2230
2231 QObject::connect(&connector, SIGNAL(updateCurrentSliceDisplay(QString)),
2232 myUi.displayingSliceLabel, SLOT(setText(const QString)));
2233 QObject::connect(&connector, SIGNAL(updateCurrentEventDisplay(QString)),
2234 myUi.displayingEventLabel, SLOT(setText(const QString)));
2235 QObject::connect(&connector, SIGNAL(updateCurrentPCTime(QString)),
2236 myUi.PCTimeLabel, SLOT(setText(const QString)));
2237 QObject::connect(&connector, SIGNAL(updateCurrentSoftTrigger(QString)),
2238 myUi.softwareTriggerLabel, SLOT(setText(const QString)));
2239 QObject::connect(&connector, SIGNAL(updateCurrentTriggerType(QString)),
2240 myUi.triggerTypeLabel, SLOT(setText(const QString)));
2241 QObject::connect(&connector, SIGNAL(updateCurrentPixelSliceValue(const QString)),
2242 myUi.currentPixelValue, SLOT(setText(const QString)));
2243
2244 if (conf.Has("file"))
2245 {
2246 string str = conf.Get<string>("file");
2247 QString qstr(str.c_str());
2248 connector.fileSelected(qstr);
2249 }
2250
2251 mainWindow.show();
2252
2253 return app.exec();
2254}
Note: See TracBrowser for help on using the repository browser.