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

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