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

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