source: fact/tools/Edd_LP/Edd.cc@ 16466

Last change on this file since 16466 was 12941, checked in by ogrimm, 13 years ago
Less digits deplayed in widgets
File size: 32.8 KB
Line 
1/* ============================================================
2
3Edd - Evidence Data Display
4
5Qt-based graphical user interface for the Evidence contron system
6
7EddLineDisplay changes its background colour in case it display
8a DIM status service
9
10Note: Currently no limit to number of points in plot, can result in out of memory condition.
11
12============================================================ */
13
14#include "Edd.h"
15
16QString DRSBoard = "FADctrl";
17std::string PixelMapText;
18
19extern class EddDim *Handler;
20
21////////////////////////
22// Event oscilloscope //
23////////////////////////
24
25// Constructor
26EventScope::EventScope(class TP_DAQ *Page, QWidget *P): EddBasePlot(P), PixelMap(PixelMapText, false) {
27
28 // Initalise
29 LastPath = ".";
30 Name = DRSBoard+"/EventData";
31 DAQPage = Page;
32 Active = false;
33
34 // Open temporary files
35 Tmpfile = tmpfile();
36 if(Tmpfile==NULL || !File.open()) {
37 QMessageBox::warning(this, "Edd Message", "Could not open temporary file.", QMessageBox::Ok);
38 return;
39 }
40
41 // Open file with RawDataCTX
42 RD = new RawDataCTX(true);
43 ErrCode = CTX_NOTOPEN;
44
45 // Context menu
46 PhysPipeAction = new QAction("Physical pipeline", this);
47 PhysPipeAction->setCheckable(true);
48 connect(PhysPipeAction, SIGNAL(triggered()), SLOT(PlotTraces()));
49 Menu->insertAction(StripAction, PhysPipeAction);
50
51 PersistanceAction = new QAction("Persistance", this);
52 PersistanceAction->setCheckable(true);
53 Menu->insertAction(StripAction, PersistanceAction);
54 Menu->removeAction(StripAction);
55
56 // Initial trace
57 AddTrace(0,0,0);
58
59 // Update interval
60 Timer->setInterval(100);
61}
62
63// Destructor (items with parent widget are automatically deleted)
64EventScope::~EventScope() {
65
66 SetActive(false);
67
68 for (int i=0; i<List.size(); i++) {
69 DeleteCurve(List[i].Curve);
70 delete List[i].Trigger;
71 }
72
73 delete RD;
74 if (Tmpfile != NULL) fclose(Tmpfile);
75}
76
77// Add trace
78void EventScope::AddTrace(int Board, int Chip, int Channel) {
79
80 struct ItemDetails N;
81
82 N.Curve = NewCurve(QString::number(Board)+","+QString::number(Chip)+","+ QString::number(Channel)+ " (" + ToPixel(0, Board, Chip, Channel) + ")");
83 N.Board = Board;
84 N.Chip = Chip;
85 N.Channel = Channel;
86 N.Trigger = new QwtPlotMarker();
87 N.Trigger->setSymbol(QwtSymbol(QwtSymbol::Diamond, QBrush(N.Curve->pen().color()), N.Curve->pen(), QSize(10,10)));
88 N.Trigger->attach(this);
89
90 if (List.isEmpty()) {
91 QPen Pen = N.Curve->pen();
92 Pen.setWidth(2);
93 N.Curve->setPen(Pen);
94 }
95 List.append(N);
96
97 PlotTraces();
98}
99
100// Update last trace (to reflect current setting of spin boxes in DAQ page)
101void EventScope::UpdateFirst(int Board, int Chip, int Channel) {
102
103 if (List.isEmpty()) return;
104
105 // Clear in case persistance was activated
106 ClearCurve(0);
107
108 List.first().Curve->setTitle(QString::number(Board)+","+QString::number(Chip)+","+ QString::number(Channel) + " (" + ToPixel(0, Board, Chip, Channel) + ")");
109 List.first().Board = Board;
110 List.first().Chip = Chip;
111 List.first().Channel = Channel;
112
113 PlotTraces();
114}
115
116// Update event buffer
117void EventScope::Update(const QString &, int Time, const QByteArray &Data, const QString &Format, const QString &, int) {
118
119 // Check if service available
120 if (!SetStatus(this, Name, Time, Format)) return;
121 if (Data.size() < (int) sizeof(RunHeader)) return;
122
123 // Ignore further data while processing this one
124 Handler->Ignore(Name, true);
125
126 // Clear temporary file and write event data to this file
127 File.resize(0);
128 if (File.write(Data) == -1) {
129 QMessageBox::warning(this, "Edd Message","Could not write data to temporary file.",QMessageBox::Ok);
130 return;
131 }
132 File.flush();
133
134 // Open temporary raw data file
135 OpenRawFile(File.fileName());
136
137 // Process all pending events, then allow data again
138 QApplication::processEvents();
139 Handler->Ignore(Name, false);
140}
141
142
143// New event number selected in raw data browser
144void EventScope::OpenRawFile(QString Filename) {
145
146 // Request filename to open if none given
147 if (Filename.isEmpty()) {
148 Filename = QFileDialog::getOpenFileName(this, "Open raw file", LastPath, "Raw data files (*.raw);; All files (*)");
149 if (Filename == NULL) return;
150 }
151
152 DAQPage->FilenameBox->setText(Filename);
153 LastPath = QFileInfo(Filename).absolutePath();
154
155 // Prepare temporary file for run header
156 if (ftruncate(fileno(Tmpfile), 0) == -1) printf("Error with ftruncate() in EventScope::OpenRawFile() (%s)\n", strerror(errno));
157 rewind(Tmpfile);
158
159 // Write run header to temporary file
160 switch (ErrCode = RD->OpenDataFile(Filename.toAscii().data(), Tmpfile)) {
161 case CTX_FOPEN: QMessageBox::warning(this, "Edd Message","Could not open file.",QMessageBox::Ok);
162 return;
163 case CTX_RHEADER: QMessageBox::warning(this, "Edd Message","Could not read run header.",QMessageBox::Ok);
164 return;
165 case CTX_BSTRUCT: QMessageBox::warning(this, "Edd Message","Could not read board structures.",QMessageBox::Ok);
166 return;
167 default: break;
168 }
169 RunHeader *R = RD->RHeader;
170
171 // Magic number warnings not for online display
172 if (Filename != File.fileName()) {
173 if (R->MagicNum == MAGICNUM_OPEN) {
174 QMessageBox::warning(this, "Edd Message","Magic number in run header indicates that the file has not been closed properly.",QMessageBox::Ok);
175 }
176 if (R->MagicNum == MAGICNUM_ERROR) {
177 QMessageBox::warning(this, "Edd Message","Magic number in run header indicates that an error occurred while writing the file.",QMessageBox::Ok);
178 }
179 }
180
181 // Print run header to display
182 rewind(Tmpfile);
183 QTextStream in(Tmpfile);
184 QString text = in.readAll();
185 DAQPage->RunHeaderDisplay->setPlainText(text);
186
187 // Read and display first event (must be before setting spin boxes)
188 NewEventNum(DAQPage->Event->value());
189
190 // Update spin box ranges on DAQ page
191 DAQPage->Event->setRange(0, R->Events-1);
192 DAQPage->Event->setEnabled(true);
193 DAQPage->Channel->setRange(0, R->NChannels-1);
194 DAQPage->Chip->setRange(0, R->NChips-1);
195 DAQPage->Board->setRange(0, R->NBoards-1);
196}
197
198// New event number selected in raw data browser
199void EventScope::NewEventNum(int Event) {
200
201 // Prepare temporary file for event header
202 if (ftruncate(fileno(Tmpfile), 0) == -1) printf("Error with ftruncate() in EventScope::NewEventNum() (%s)\n", strerror(errno));
203 rewind(Tmpfile);
204
205 // Read event
206 if (RD->ReadEvent(Event, Tmpfile) != CTX_OK) {
207 QMessageBox::warning(this, "Edd Message","Could not read event.",QMessageBox::Ok);
208 DAQPage->EventHeaderDisplay->clear();
209 return;
210 }
211
212 // Plot traces for event
213 PlotTraces();
214}
215
216// Update curves
217void EventScope::PlotTraces() {
218
219 double x,y;
220 unsigned int Cell, Trig;
221 static int Last = 0;
222
223 // Only process if valid data in RawDataCTX class
224 if (ErrCode != CTX_OK) return;
225
226 // Print event header and trigger cell information from event data
227 rewind(Tmpfile);
228 QTextStream in(Tmpfile);
229 QString text = in.readAll();
230
231 text.append("\nTrigger cells: ");
232 for (unsigned int i=0; i<RD->RHeader->NBoards*RD->RHeader->NChips; i++) {
233 QString a;
234 text.append(a.sprintf("%d ", *((int *)RD->Data + i)));
235 }
236 DAQPage->EventHeaderDisplay->setPlainText(text);
237
238 // Set x axis title
239 if (PhysPipeAction->isChecked()) setAxisTitle(QwtPlot::xBottom, "Time from start of pipeline (ns)");
240 else setAxisTitle(QwtPlot::xBottom, "Time from trigger minus one revolution (ns)");
241
242 // Loop through event data to update event scope
243 RunHeader *R = RD->RHeader;
244 for (int i=0; i<List.size(); i++) {
245
246 if (PersistanceAction->isChecked()) List[i].Curve->setStyle(QwtPlotCurve::Dots);
247 else {
248 ClearCurve(i);
249 List[i].Curve->setStyle(QwtPlotCurve::Lines);
250 }
251
252 // Check if current event contains requested trace
253 if (List[i].Board>=R->NBoards || List[i].Chip>=R->NChips || List[i].Channel>=R->NChannels) continue;
254
255 // Set trigger marker visibility
256 List[i].Trigger->setVisible(PhysPipeAction->isChecked());
257
258 // Determine trigger cell
259 Trig = *((int *) RD->Data + List[i].Board*R->NChips + List[i].Chip);
260
261 // Calulate point of curve
262 for (unsigned int j=0; j<R->Samples; j++) {
263
264 if (PhysPipeAction->isChecked()) Cell = (j - Trig) % 1024;
265 else Cell = j;
266
267 x = j / RD->BStruct[List[i].Board].NomFreq;
268 y = *((short *) (RD->Data + R->NBoards*R->NChips*sizeof(int)) +
269 List[i].Board*R->NChips*R->NChannels*R->Samples + List[i].Chip*R->NChannels*R->Samples +
270 List[i].Channel*R->Samples + Cell) * RD->BStruct[List[i].Board].ScaleFactor;
271
272 AddPoint(i, x, y);
273
274 // Set trigger point indicator
275 if (Trig == j) List[i].Trigger->setValue(x, y);
276 }
277 }
278
279 // Limit update rate in persistance mode
280 if (!PersistanceAction->isChecked() || time(NULL) > Last) {
281 UpdatePlot();
282 Last = time(NULL);
283 }
284
285 // Loop through event data for pixel display
286 QVector<double> Pixel(R->NBoards*R->NChips*R->NChannels);
287 int Count = 0;
288
289 for (unsigned int Board=0; Board<R->NBoards; Board++) {
290 for (unsigned int Chip=0; Chip<R->NChips; Chip++) {
291 for (unsigned int Channel=0; Channel<R->NChannels; Channel++) {
292 Pixel[Count] = DBL_MIN;
293
294 for (unsigned int i=0; i<R->Samples; i++) {
295 y = *((short *) (RD->Data + R->NBoards*R->NChips*sizeof(int)) +
296 Board*R->NChips*R->NChannels*R->Samples + Chip*R->NChannels*R->Samples +
297 Channel*R->Samples + i) * RD->BStruct[Board].ScaleFactor;
298
299 if (y > Pixel[Count]) Pixel[Count] = y;
300 }
301 Count++;
302 }}}
303
304 emit(PixelData(Pixel));
305}
306
307// Set display active (if inactive, disconnect from server)
308void EventScope::SetActive(bool State) {
309
310 if (State && !Active) Handler->Subscribe(DRSBoard+"/EventData", this, -1);
311 if (!State && Active) Handler->Unsubscribe(DRSBoard+"/EventData", this);
312
313 Active = State;
314}
315
316// Translate FPA ID to Pixel ID (use '-' instead of PM_ERROR_CODE)
317QString EventScope::ToPixel(unsigned int Crate, unsigned int Board, unsigned int Patch, unsigned int Pixel) {
318
319 if (FPA_to_Pixel(Crate, Board, Patch, Pixel) == PM_ERROR_CODE) return "-";
320 else return QString::number(FPA_to_Pixel(Crate, Board, Patch, Pixel));
321}
322
323//------------------------------------------------------------------
324//**************************** Tab pages ***************************
325//------------------------------------------------------------------
326
327//
328// Environment page (For M0, server was called ARDUINO)
329//
330TP_Environment::TP_Environment() {
331
332 QGridLayout *Layout = new QGridLayout(this);
333 setAttribute(Qt::WA_DeleteOnClose);
334
335 // Status display
336 EddLineDisplay *Line = new EddLineDisplay("FSC_CONTROL/MESSAGE");
337 Line->setMaximumWidth(800);
338 Layout->addWidget(Line, 0, 0, 1, 10);
339
340 // Temperatures
341 EddPlot *Plot = new EddPlot();
342 Plot->setMinimumWidth(400);
343
344 for (int i=0; i<58; i++) {
345 Line = new EddLineDisplay("FSC_CONTROL/TEMPERATURE", i+1);
346 Line->setMaximumWidth(50);
347 Layout->addWidget(Line, i/10+1, i%10);
348 Plot->AddService("FSC_CONTROL/TEMPERATURE", i+1);
349 }
350 Layout->addWidget(Plot, 0, 10, 20, 10);
351
352 // Humidities
353 for (int i=0; i<4; i++) {
354 Line = new EddLineDisplay("FSC_CONTROL/HUMIDITY", i+1);
355 Line->setMaximumWidth(50);
356 Layout->addWidget(Line, i/10+7, i%10);
357 }
358
359 // Voltages and currents
360 for (int i=0; i<30; i++) {
361 Line = new EddLineDisplay("FSC_CONTROL/VOLTAGE", i+1);
362 Line->setMaximumWidth(60);
363 Layout->addWidget(Line, i/10+8, i%10);
364
365 Line = new EddLineDisplay("FSC_CONTROL/CURRENT", i+1);
366 Line->setMaximumWidth(60);
367 Layout->addWidget(Line, i/10+11, i%10);
368 }
369
370 // Night sky monitor
371 Line = new EddLineDisplay("SQM/Message");
372 Line->setMaximumWidth(300);
373 Layout->addWidget(Line, 22, 0, 1, 4);
374
375 Line = new EddLineDisplay("SQM/NSB");
376 Layout->addWidget(Line, 22, 5, 1, 2);
377}
378
379//
380// Bias page
381//
382TP_Bias::TP_Bias() {
383
384 QGridLayout *Layout = new QGridLayout(this);
385 setAttribute(Qt::WA_DeleteOnClose);
386 EddLineDisplay *Line;
387
388 Line = new EddLineDisplay("BIAS_CONTROL/MESSAGE");
389 Line->setMaximumWidth(400);
390 Layout->addWidget(Line, 0, 0, 1, 11);
391
392 EddPlot *Plot = new EddPlot();
393 for (int i=0; i<320; i++) Plot->AddService("BIAS_CONTROL/VOLTAGE", i);
394 Layout->addWidget(Plot, 1, 0, 30, 12);
395
396 // Current page
397 EddWindow *Button = new EddWindow("Currents", "Edd - Bias currents");
398 Layout->addWidget(Button, 0, 11);
399
400 Plot = new EddPlot();
401 for (int i=0; i<320; i++) Plot->AddService("BIAS_CONTROL/CURRENT", i);
402 Button->Layout()->addWidget(Plot, 0, 4, 30, 12);
403}
404
405//
406// Feedback page
407//
408TP_Feedback::TP_Feedback() {
409
410 setAttribute(Qt::WA_DeleteOnClose);
411 QGridLayout *Layout = new QGridLayout(this);
412 EddLineDisplay *Line;
413
414 EddPlot *Plot = new EddPlot();
415 for (int i=0; i<36; i++) {
416 Line = new EddLineDisplay("Feedback/Average", i);
417 Line->setMaximumWidth(60);
418 Layout->addWidget(Line, i%9+2, 0+i/9, 1, 1);
419 Plot->AddService("Feedback/Average", i);
420 }
421 Layout->addWidget(Plot, 0, 4, 12, 10);
422
423 Line = new EddLineDisplay("Feedback/Message");
424 Line->setMaximumWidth(200);
425 Layout->addWidget(Line, 0, 0, 1, 2);
426
427 Line = new EddLineDisplay("Feedback/State");
428 Line->setMaximumWidth(150);
429 Layout->addWidget(Line, 1, 0, 1, 2);
430 Line = new EddLineDisplay("Feedback/Count");
431 Line->setMaximumWidth(60);
432 Layout->addWidget(Line, 1, 2);
433
434 // Details page
435 EddWindow *Button = new EddWindow("Details", "Edd - Feedback Details");
436 Layout->addWidget(Button, 12, 0, 1, 1);
437
438 Plot = new EddPlot();
439
440 for (int i=0; i<36; i++) {
441 Line = new EddLineDisplay("Feedback/Sigma", i);
442 Line->setMaximumWidth(60);
443 Button->Layout()->addWidget(Line, i%9, 0+i/9, 1, 1);
444 Plot->AddService("Feedback/Sigma", i);
445
446 Line = new EddLineDisplay("Feedback/Target", i);
447 Line->setMaximumWidth(60);
448 Button->Layout()->addWidget(Line, i%9+10, 0+i/9, 1, 1);
449
450 Line = new EddLineDisplay("Feedback/Response", i);
451 Line->setMaximumWidth(60);
452 Button->Layout()->addWidget(Line, i%9+20, 0+i/9, 1, 1);
453 }
454 Button->Layout()->addWidget(Plot, 0, 4, 30, 12);
455}
456
457
458//
459// FADctrl page
460//
461TP_FADctrl::TP_FADctrl() {
462
463 QString Board;
464
465 QScrollArea *scrollArea = new QScrollArea;
466 scrollArea->setBackgroundRole(QPalette::Dark);
467 scrollArea->setWidget(this);
468 setMinimumSize(QSize(0,0));
469
470 QGridLayout *Layout = new QGridLayout(this);
471 setAttribute(Qt::WA_DeleteOnClose);
472 EddLineDisplay *Line;
473
474 Line = new EddLineDisplay("FAD_CONTROL/MESSAGE");
475 Line->setMaximumWidth(500);
476 Layout->addWidget(Line, 0, 0, 1, 10);
477
478 EddPlot *Plot = new EddPlot();
479 Layout->addWidget(Plot, 1, 0, 6, 10);
480 for (int i=0; i<82; i++) Plot->AddService("FAD_CONTROL/TEMPERATURE", i);
481
482 // Details page
483 EddWindow *Button[2];
484 Button[0] = new EddWindow("Boards 0-19", "Edd - FADctrl - Board 0 to 19");
485 Button[1] = new EddWindow("Boards 20-39", "Edd - FADctrl - Board 20 to 39");
486 Layout->addWidget(Button[0], 7, 0, 1, 1);
487 Layout->addWidget(Button[1], 7, 1, 1, 1);
488
489 for (int i=0; i<40; i++) {
490 Board = Board.sprintf("FADctrl/Board%.2d/", i);
491 Line = new EddLineDisplay(Board+"Server");
492 Line->setMinimumWidth(90);
493 Button[i/20]->Layout()->addWidget(Line, i+7, 0, 1, 1);
494
495 Line = new EddLineDisplay(Board+"BoardID");
496 Line->setMaximumWidth(30);
497 Button[i/20]->Layout()->addWidget(Line, i+7, 1, 1, 1);
498
499 Line = new EddLineDisplay(Board+"Frequency");
500 Line->setMaximumWidth(40);
501 Button[i/20]->Layout()->addWidget(Line, i+7, 2, 1, 1);
502
503 for (int j=0; j<4; j++) {
504 Line = new EddLineDisplay(Board+"Lock", j);
505 Line->setMaximumWidth(20);
506 Button[i/20]->Layout()->addWidget(Line, i+7, 3+j, 1, 1);
507 }
508
509 for (int j=0; j<4; j++) {
510 Line = new EddLineDisplay(Board+"Temperature", j);
511 Line->setMinimumWidth(40);
512 Button[i/20]->Layout()->addWidget(Line, i+7, 7+j, 1, 1);
513 }
514
515 Line = new EddLineDisplay(Board+"TriggerNum");
516 Line->setMinimumWidth(40);
517 Button[i/20]->Layout()->addWidget(Line, i+7, 11, 1, 1);
518
519 Line = new EddLineDisplay(Board+"RateHz");
520 Line->setMinimumWidth(50);
521 Button[i/20]->Layout()->addWidget(Line, i+7, 19, 1, 1);
522
523 Line = new EddLineDisplay(Board+"Status");
524 Line->setMaximumWidth(150);
525 Button[i/20]->Layout()->addWidget(Line, i+7, 20, 1, 1);
526 }
527}
528
529//
530// Event scope page
531//
532TP_DAQ::TP_DAQ(bool IsBrowser) {
533
534 EddLineDisplay *Line;
535
536 setAttribute(Qt::WA_DeleteOnClose);
537 QGridLayout *Layout = new QGridLayout(this);
538
539 // Event scope
540 Scope = new EventScope(this);
541 Scope->setMinimumWidth(700);
542
543 Scope->SetActive(!IsBrowser);
544
545 // FilenameBox must exist also for online browser (but not added to layout)
546 FilenameBox = new QLineEdit();
547
548 if (!IsBrowser) {
549 // Message service
550 Line = new EddLineDisplay(DRSBoard+"/Message");
551 Line->setMinimumWidth(500);
552 Layout->addWidget(Line, 0, 1, 1, 6);
553
554 // Run-related information
555 Line = new EddLineDisplay(DRSBoard+"/EventNumber");
556 Line->setMaximumWidth(100);
557 Layout->addWidget(Line, 0, 8, 1, 1);
558 Line = new EddLineDisplay(DRSBoard+"/FileSizeMB");
559 Line->setMaximumWidth(100);
560 Layout->addWidget(Line, 0, 9, 1, 1);
561 }
562 else {
563 // Filename box
564 Layout->addWidget(FilenameBox, 0, 1, 1, 6);
565 connect(FilenameBox, SIGNAL(returnPressed()), SLOT(OpenDataFile()));
566 FilenameBox->setToolTip("Raw data file name");
567
568 // Browse botton
569 QToolButton *LoadButton = new QToolButton();
570 LoadButton->setToolButtonStyle (Qt::ToolButtonTextOnly);
571 LoadButton->setText("...");
572 Layout->addWidget(LoadButton, 0, 7, 1, 1);
573 connect(LoadButton, SIGNAL(clicked()), Scope, SLOT(OpenRawFile()));
574 LoadButton->setToolTip("Open file dialog to select raw data file");
575 }
576
577 // Text boxes for run and event header
578 RunHeaderDisplay = new QPlainTextEdit();
579 EventHeaderDisplay = new QPlainTextEdit();
580 RunHeaderDisplay->setReadOnly(true);
581 EventHeaderDisplay->setReadOnly(true);
582
583 // Tab widget
584 QTabWidget *TabWidget = new QTabWidget();
585 TabWidget->addTab(Scope, "&Signals");
586 TabWidget->addTab(RunHeaderDisplay, "&Run Header");
587 TabWidget->addTab(EventHeaderDisplay, "&Event Header");
588 Layout->addWidget(TabWidget, 1, 1, 7, 12);
589
590 // Channel number
591 Channel = new QSpinBox;
592 connect(Channel, SIGNAL(valueChanged(int)), SLOT(UpdateScope(int)));
593 Channel->setToolTip("Channel number");
594
595 // Chip number
596 Chip = new QSpinBox;
597 connect(Chip, SIGNAL(valueChanged(int)), SLOT(UpdateScope(int)));
598 Chip->setToolTip("Chip number");
599
600 // Board number
601 Board = new QSpinBox;
602 connect(Board, SIGNAL(valueChanged(int)), SLOT(UpdateScope(int)));
603 Board->setToolTip("Board number");
604
605 // Pixel ID
606 PixelID = new QSpinBox;
607 PixelID->setMaximumWidth(60);
608 PixelID->setRange(-1, 9999);
609 PixelID->setSpecialValueText("n/a");
610 connect(PixelID, SIGNAL(valueChanged(int)), SLOT(TranslatePixelID(int)));
611 PixelID->setToolTip("Pixel identification");
612
613 // Add trace permanently
614 QPushButton *Button = new QPushButton("Keep trace");
615 Button->setToolTip("Keep trace in display");
616 Button->setMaximumWidth(80);
617 connect(Button, SIGNAL(clicked()), SLOT(KeepCurrent()));
618
619 // Layout of pixel addressing widgets
620 QFormLayout *FormLayout = new QFormLayout();
621 FormLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
622 FormLayout->addRow("Board", Board);
623 FormLayout->addRow("Chip", Chip);
624 FormLayout->addRow("Channel", Channel);
625 FormLayout->addRow("Pixel ID", PixelID);
626 FormLayout->addRow("", Button);
627 Layout->addLayout(FormLayout, 0, 0, 4, 1);
628
629 // Spin box for event number
630 Event = new QSpinBox;
631 Event->setToolTip("Event number");
632 Event->setEnabled (false);
633
634 // Stop/start button
635 StartStopButton = new QPushButton("Stop");
636 StartStopButton->setToolTip("Start/stop display");
637 StartStopButton->setMaximumWidth(80);
638 StartStopButton->setCheckable(true);
639 QPalette Palette = StartStopButton->palette();
640 Palette.setColor(QPalette::ButtonText, Qt::blue);
641 Palette.setColor(QPalette::Button, Qt::green);
642 StartStopButton->setPalette(Palette);
643 StartStopButton->setFont(QFont("Times", 10, QFont::Bold));
644
645 if (IsBrowser) {
646 FormLayout = new QFormLayout();
647 FormLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
648 FormLayout->addRow("Event Num", Event);
649 Layout->addLayout(FormLayout, 6, 0);
650 connect(Event, SIGNAL(valueChanged(int)), Scope, SLOT(NewEventNum(int)));
651 }
652 else {
653 Layout->addWidget(StartStopButton, 6, 0);
654 connect(StartStopButton, SIGNAL(toggled(bool)), SLOT(StartStop(bool)));
655 }
656
657 // Event display page
658 EddWindow *New = new EddWindow("Pixel display", "Edd - Event display");
659 New->setFont(QFont("Times", 10, QFont::Bold));
660 New->setMaximumWidth(80);
661 New->setToolTip("Show event display window");
662 New->Window()->resize(550,550);
663
664 Layout->addWidget(New, 7, 0);
665
666 Pixel = new QPushButton *[MAXPIXEL];
667 int Count = 0;
668 double x,y;
669
670 for (int ix=-22; ix<=22; ix++) for (int iy=-19; iy<=20; iy++) {
671 if (Count == MAXPIXEL) break;
672
673 x = ix*0.866;
674 y = iy - (ix%2==0 ? 0.5:0);
675 if ((pow(x,2)+pow(y,2) >= 395) && !(abs(ix)==22 && iy==7)) continue;
676
677 //Pixel[Count] = new QPushButton(Display);
678 Pixel[Count] = new QPushButton(New->Window());
679 Pixel[Count]->setAutoFillBackground(true);
680 Pixel[Count]->setGeometry((int) (x*12.5 + 250), (int) (y*12.5 + 250), 10, 10);
681 Pixel[Count]->show();
682 Count++;
683 }
684
685 // Connect slots for updating displays
686 if (!IsBrowser) StartStop(false);
687 connect(Scope, SIGNAL(PixelData(QVector<double>)), SLOT(SetPixelData(QVector<double>)));
688
689 // Call to get initial pixel ID correct
690 UpdateScope(0);
691}
692
693TP_DAQ::~TP_DAQ() {
694
695 delete[] Pixel;
696}
697
698// Translate pixel ID to board, chip, channel
699void TP_DAQ::TranslatePixelID(int ID) {
700
701 // setValue() below will call UpdateScope() through signal, therefore need to store numbers here
702 unsigned int BoardNo = Scope->Pixel_to_FPAboard(ID);
703 unsigned int PatchNo = Scope->Pixel_to_FPApatch(ID);
704 unsigned int PixelNo = Scope->Pixel_to_FPApixel(ID);
705
706 if (BoardNo == Scope->PM_ERROR_CODE) PixelID->setValue(-1);
707 else {
708 Board->setValue(BoardNo);
709 Chip->setValue(PatchNo);
710 Channel->setValue(PixelNo);
711 }
712}
713
714// Keep current trace
715void TP_DAQ::KeepCurrent() {
716
717 Scope->AddTrace(Board->value(), Chip->value(), Channel->value());
718}
719
720// Start/stop event acquisition
721void TP_DAQ::StartStop(bool State) {
722
723 Scope->SetActive(!State);
724 StartStopButton->setText(State ? "Start" : "Stop");
725}
726
727// Open raw data file
728void TP_DAQ::OpenDataFile() {
729
730 Scope->OpenRawFile(FilenameBox->text());
731}
732
733// Update event scope
734void TP_DAQ::UpdateScope(int) {
735
736 // Update pixel ID
737 PixelID->setValue(Scope->FPA_to_Pixel(0, Board->value(), Chip->value(), Channel->value()));
738 if (PixelID->value() == (int) Scope->PM_ERROR_CODE) PixelID->setValue(-1);
739
740 // Update first trace
741 Scope->UpdateFirst(Board->value(), Chip->value(), Channel->value());
742}
743
744// Show/hide pixel display
745void TP_DAQ::ShowPixelDisplay() {
746
747 Display->show();
748 Display->raise();
749}
750
751void TP_DAQ::SetPixelData(QVector<double> Data) {
752
753 QwtLinearColorMap Map;
754
755 for (int i=0; i<Data.size(); i++) {
756 Pixel[i]->setPalette(QPalette(Map.color(QwtDoubleInterval(300, 400), Data[i])));
757 }
758}
759
760
761//
762// Evidence page
763//
764TP_Evidence::TP_Evidence() {
765
766 setAttribute(Qt::WA_DeleteOnClose);
767 QGridLayout *Layout = new QGridLayout(this);
768 EddLineDisplay *Line;
769 EddText *Text;
770
771 Line = new EddLineDisplay("Alarm/Message");
772 Line->setMaximumWidth(200);
773 Layout->addWidget(Line, 0, 0, 1, 2);
774
775 QPushButton *Button = new QPushButton();
776 Button->setText("ON/OFF");
777 Button->setCheckable(true);
778 connect(Button, SIGNAL(toggled(bool)), SLOT(ToggleAlarm(bool)));
779 Layout->addWidget(Button, 0, 3, 1, 1);
780
781 Line = new EddLineDisplay("Alarm/MasterAlarm");
782 Layout->addWidget(Line, 0, 1, 1, 1);
783
784 Text = new EddText("Alarm/Summary", true);
785 Text->Accumulate = false;
786 Text->setMaximumWidth(200);
787 Text->setMaximumHeight(150);
788 Layout->addWidget(Text, 1, 0, 1, 2);
789
790 Line = new EddLineDisplay("DColl/Message");
791 Line->setMaximumWidth(200);
792 Layout->addWidget(Line, 3, 0, 1, 2);
793
794 Line = new EddLineDisplay("DColl/DataSizeMB");
795 Layout->addWidget(Line, 4, 0, 1, 1);
796
797 Line = new EddLineDisplay("DColl/LogSizeMB");
798 Layout->addWidget(Line, 4, 1, 1, 1);
799
800 Line = new EddLineDisplay("DColl/CurrentFile");
801 Line->setMaximumWidth(400);
802 Layout->addWidget(Line, 5, 0, 1, 3);
803
804 Line = new EddLineDisplay("Config/Message");
805 Line->setMaximumWidth(200);
806 Layout->addWidget(Line, 6, 0, 1, 2);
807
808 Line = new EddLineDisplay("Config/ModifyTime");
809 Line->setMaximumWidth(200);
810 Line->ShowAsTime = true;
811 Layout->addWidget(Line, 7, 0, 1, 1);
812
813 Button = new QPushButton();
814 Button->setText("eLogBook");
815 connect(Button, SIGNAL(released()), SLOT(StartELog()));
816 Layout->addWidget(Button, 6, 1, 1, 1);
817
818 Button = new QPushButton();
819 Button->setText("DIM browser");
820 connect(Button, SIGNAL(released()), SLOT(StartDIMBrowser()));
821 Layout->addWidget(Button, 7, 1, 1, 1);
822
823 Line = new EddLineDisplay("Edd/Rate_kBSec");
824 Layout->addWidget(Line, 8, 0, 1, 1);
825}
826
827// Toggle state of Alarm server
828void TP_Evidence::ToggleAlarm(bool State) {
829
830 if (State) DimClient::sendCommandNB((char *) "Alarm/Switch", (char *) "off");
831 else DimClient::sendCommandNB((char *) "Alarm/Switch", (char *) "on");
832}
833
834// Start DIM Browser
835void TP_Evidence::StartDIMBrowser() {
836
837 QProcess::startDetached("did", QStringList(), QString(getenv("DIMDIR"))+"/linux/");
838}
839
840// Start eLogBook
841void TP_Evidence::StartELog() {
842
843 QProcess::startDetached("firefox http://fact.ethz.ch/FACTelog/index.jsp");
844}
845
846
847//--------------------------------------------------------------------
848//*************************** Main GUI *******************************
849//--------------------------------------------------------------------
850//
851// All widgets have ultimately Central as parent.
852//
853GUI::GUI() {
854
855 Handler = new EddDim;
856
857 // Arrangement in tabs
858 TabWidget = new QTabWidget(this);
859 TabWidget->setTabsClosable(true);
860 connect(TabWidget, SIGNAL(tabCloseRequested(int)), SLOT(DetachTab(int)));
861 TabWidget->addTab(new TP_DAQ(false), "Event scope");
862 printf("...event scope\n");
863 TabWidget->addTab(new TP_FADctrl, "FAD");
864 printf("...FADctrl\n");
865 TabWidget->addTab(new TP_Bias, "Bias");
866 printf("...bias\n");
867 TabWidget->addTab(new TP_Feedback, "Feedback");
868 printf("...feedback\n");
869 TabWidget->addTab(new TP_Environment, "FSC/SQM");
870 printf("...FSC\n");
871 TabWidget->addTab(new TP_Evidence, "Evidence");
872
873 // Set features of main window
874 setStatusBar(new QStatusBar(this));
875 setWindowTitle("Edd - Evidence Data Display - Node: " + QString(DimServer::getDnsNode()) + ":" + QString::number(DimServer::getDnsPort()));
876 setCentralWidget(TabWidget);
877
878 // Menu bar
879 QMenu* Menu = menuBar()->addMenu("&Menu");
880 Menu->addAction("Open history plot", this, SLOT(MenuNewHistory()));
881 Menu->addAction("Send command", this, SLOT(MenuCommand()));
882 Menu->addAction("Raw data browser", this, SLOT(MenuRawDataBrowser()));
883 Menu->addSeparator();
884 Menu->addAction("About", this, SLOT(MenuAbout()));
885 Menu->addSeparator();
886 QAction* QuitAction = Menu->addAction("Quit", qApp, SLOT(quit()));
887 QuitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
888
889 // Size and show main window
890 QSize Size = TabWidget->sizeHint()*1.1;
891 Size = Size.boundedTo(QApplication::desktop()->screenGeometry(this).size()*0.6);
892 //setMaximumSize(QApplication::desktop()->screenGeometry(this).size()*0.9);
893 TabWidget->resize(Size);
894 TabWidget->setMaximumSize(QApplication::desktop()->screenGeometry(this).size()*0.9);
895 show();
896
897 // Set timer to regularly check the master alarm
898 QTimer *Timer = new QTimer(this);
899 connect(Timer, SIGNAL(timeout()), this, SLOT(CheckAlarm()));
900 if (QString(DimServer::getDnsNode()).contains("ethz.ch")) Timer->start(5000);
901}
902
903
904void GUI::MenuAbout() {
905 QString Rev(SVN_REVISION);
906 Rev.remove(0,1).chop(2);
907
908 QMessageBox::about(this, "About Edd","Evidence Data Display\n\n"
909 "Written by Oliver Grimm, IPP, ETH Zurich\n"
910 "This version compiled "__DATE__" ("+Rev+")\n\n"
911 "Graphical user interface implemented with Qt and Qwt.\n"
912 "Evidence control system based on DIM (http://dim.web.cern.ch).\n\n"
913 "Comments to oliver.grimm@phys.ethz.ch.");
914}
915
916// Open new history plot
917void GUI::MenuNewHistory() {
918
919 QStringList List, Index;
920 char *Name, *Format;
921 int Type;
922 bool OK;
923
924 // Find all DIM services and sort
925 getServices("*");
926 while ((Type = getNextService(Name, Format)) != 0) {
927 if (Type==DimSERVICE) List.append(Name);
928 }
929 List.sort();
930
931 // Open dialog and open history window
932 QString Result = QInputDialog::getItem(this, "Edd Request",
933 "Enter or choose DIM service name (add index or index range a-b separated by colon)", List, 0, true, &OK);
934
935 // Check if cancelled or empty data
936 List = Result.trimmed().split(":", QString::SkipEmptyParts);
937 if (!OK || List.isEmpty()) return;
938
939 // Check if index was given
940 if (List.size() == 1) {
941 OpenHistory(List[0].toAscii().data(), -1);
942 return;
943 }
944
945 // Single index or index range?
946 Index = List[1].trimmed().split("-", QString::SkipEmptyParts);
947 if (Index.isEmpty()) {
948 QMessageBox::warning(NULL, "Edd Message", QString("Incorrect index range given") ,QMessageBox::Ok);
949 return;
950 }
951
952 if (Index.size() == 1) OpenHistory(List[0].toAscii().data(), atoi(Index[0].toAscii().data()));
953 else OpenHistory(List[0].toAscii().data(), atoi(Index[0].toAscii().data()), atoi(Index[1].toAscii().data()));
954}
955
956// Send command selected from list
957void GUI::MenuCommand() {
958
959 QStringList List;
960 char *Name, *Format;
961 int Type;
962 bool OK;
963
964 // Find all DIM commands and sort
965 getServices("*");
966 while ((Type = getNextService(Name, Format)) != 0) {
967 if (Type==DimCOMMAND) List.append(Name);
968 }
969 List.sort();
970
971 // Open dialog and open window for entering command
972 QString Result = QInputDialog::getItem(this, "Edd Request",
973 "Enter or choose DIM command name", List, 0, true, &OK);
974 if (OK && !Result.isEmpty()) {
975 Result = Result.trimmed();
976
977 QMainWindow *M = new QMainWindow;
978 M->setCentralWidget(new QWidget(M));
979 M->setStatusBar(new QStatusBar(M));
980 M->setAttribute(Qt::WA_DeleteOnClose);
981 QWidget *W = new EddCommand(Result.toAscii().data());
982 QFormLayout *FormLayout = new QFormLayout(M->centralWidget());
983 FormLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
984 FormLayout->addRow("Enter argument for " + Result, W);
985 M->show();
986 }
987}
988
989// Raw data browser
990void GUI::MenuRawDataBrowser() {
991
992 DetachTab(0, true);
993}
994
995// Open tab as separate window
996void GUI::DetachTab(int Tab, bool IsDAQBrowser) {
997
998 QWidget *W = NULL;
999 QMainWindow *M = new QMainWindow;
1000
1001 M->setCentralWidget(new QWidget(M));
1002 M->setStatusBar(new QStatusBar(M));
1003
1004 switch(Tab) {
1005 case 0: W = new TP_DAQ(IsDAQBrowser); break;
1006 case 1: W = new TP_FADctrl; break;
1007 case 2: W = new TP_Bias; break;
1008 case 3: W = new TP_Feedback; break;
1009 case 4: W = new TP_Environment; break;
1010 case 5: W = new TP_Evidence; break;
1011 default: break;
1012 }
1013
1014 if (W == NULL) {
1015 delete M->centralWidget();
1016 delete M;
1017 return;
1018 }
1019
1020 W->setParent(M);
1021 W->resize(size());
1022 M->resize(size());
1023 if (!IsDAQBrowser) M->setWindowTitle("Edd - " + TabWidget->tabText(Tab));
1024 else M->setWindowTitle("Edd - Raw Data Browser");
1025 M->show();
1026
1027 return;
1028}
1029
1030// Check alarm level and if Alarm server is alive
1031void GUI::CheckAlarm() {
1032
1033 static int WarnedLevel = 0;
1034 static bool AlarmServerWarned = false;
1035
1036 // === Check service Alarm/MasterAlarm ===
1037 DimCurrentInfo MasterAlarm("Alarm/MasterAlarm", -1);
1038
1039 if (MasterAlarm.getInt() > WarnedLevel) {
1040 QSound::play(QApplication::applicationDirPath() + "/Error.wav");
1041
1042 // Construct warning message box
1043 QMessageBox Box;
1044 Box.setWindowTitle("Edd Alarm");
1045 Box.setText("Service 'Alarm/MasterAlarm' is at " + QString::number(MasterAlarm.getInt()));
1046 Box.setInformativeText("Warn again for the same alarm level?");
1047 Box.setIcon(QMessageBox::Warning);
1048 Box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
1049 Box.setDefaultButton(QMessageBox::No);
1050
1051 // Check if user wants to reset warned level
1052 if (Box.exec() == QMessageBox::Yes) WarnedLevel = 0;
1053 else WarnedLevel = MasterAlarm.getInt();
1054 }
1055
1056 // If MasterAlam decreased, lower also warned level
1057 if (MasterAlarm.getInt() < WarnedLevel && MasterAlarm.getInt() >=0 ) WarnedLevel = MasterAlarm.getInt();
1058
1059 // === Check Alarm server ===
1060 DimCurrentInfo ServerList("DIS_DNS/SERVER_LIST", NO_LINK);
1061 std::string Result = EvidenceServer::ToString((char *) "C", ServerList.getData(), ServerList.getSize());
1062
1063 // Warn if SERVER_LIST does not contain alarm server
1064 if (Result.find("Alarm@") == std::string::npos && !AlarmServerWarned) {
1065 QMessageBox Box;
1066 Box.setWindowTitle("Edd Alarm");
1067 Box.setText("Alarm server is unavailable or in error");
1068 Box.setIcon(QMessageBox::Critical);
1069 Box.setStandardButtons(QMessageBox::Ok);
1070 Box.setDefaultButton(QMessageBox::Ok);
1071 Box.exec();
1072
1073 AlarmServerWarned = true;
1074 }
1075
1076 if (Result.find("Alarm@") != std::string::npos) AlarmServerWarned = false;
1077}
1078
1079// Quit application when clicking close button on window
1080void GUI::closeEvent(QCloseEvent *) {
1081
1082 qApp->quit();
1083}
1084
1085
1086//
1087//**************************** Main program ***************************
1088//
1089int main(int argc, char *argv[]) {
1090
1091 if (argc>1 && strcmp(argv[1],"drsdaq")==0) DRSBoard = "drsdaq";
1092
1093 // EvidenceServer::ToString() works for structures only without padding
1094 dic_disable_padding();
1095 dis_disable_padding();
1096
1097 // Make RPC to get pixelmap
1098 DimRpcInfo RPC((char *) "ConfigRequest", (char *) "");
1099 RPC.setData((char *) "Misc PixelMap");
1100 PixelMapText = std::string(RPC.getString(), RPC.getSize());
1101
1102 printf("Bulding GUI, requesting quick-look histories...\n");
1103 QApplication app(argc, argv);
1104 GUI MainWindow;
1105
1106 return app.exec();
1107}
Note: See TracBrowser for help on using the repository browser.