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

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