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

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