source: trunk/FACT++/gui/FactGui.h@ 16778

Last change on this file since 16778 was 16697, checked in by tbretz, 11 years ago
Fixed the missing ')'
File size: 138.7 KB
Line 
1#ifndef FACT_FactGui
2#define FACT_FactGui
3
4#include "MainWindow.h"
5
6#include <iomanip>
7#include <valarray>
8
9#include <boost/regex.hpp>
10
11#include <QTimer>
12#include <QtSql/QSqlError>
13#include <QtSql/QSqlTableModel>
14#include <QStandardItemModel>
15
16#include "CheckBoxDelegate.h"
17
18#include "src/Dim.h"
19#include "src/Converter.h"
20#include "src/Configuration.h"
21#include "src/DimNetwork.h"
22#include "src/tools.h"
23#include "src/DimData.h"
24#include "externals/PixelMap.h"
25
26#ifdef HAVE_ROOT
27#include "TROOT.h"
28#include "TSystem.h"
29#include "TGraph.h"
30#include "TGraphErrors.h"
31#include "TH2.h"
32#include "TBox.h"
33#include "TStyle.h"
34#include "TMarker.h"
35#include "TColor.h"
36#endif
37
38#include "QCameraWidget.h"
39
40#include "src/FAD.h"
41#include "src/HeadersMCP.h"
42#include "src/HeadersFTM.h"
43#include "src/HeadersFAD.h"
44#include "src/HeadersFSC.h"
45#include "src/HeadersBIAS.h"
46#include "src/HeadersDrive.h"
47#include "src/HeadersFeedback.h"
48#include "src/HeadersRateScan.h"
49#include "src/HeadersRateControl.h"
50#include "src/HeadersMagicWeather.h"
51
52using namespace std;
53
54// #########################################################################
55
56class FactGui : public MainWindow, public DimNetwork, public DimInfoHandler
57{
58private:
59 class FunctionEvent : public QEvent
60 {
61 public:
62 function<void(const QEvent &)> fFunction;
63
64 FunctionEvent(const function<void(const QEvent &)> &f)
65 : QEvent((QEvent::Type)QEvent::registerEventType()),
66 fFunction(f) { }
67
68 bool Exec() { fFunction(*this); return true; }
69 };
70
71 valarray<int8_t> fFtuStatus;
72
73 PixelMap fPixelMap;
74
75 //vector<int> fPixelMapHW; // Software -> Hardware
76 vector<int> fPatchMapHW; // Software -> Hardware
77
78 bool fInChoosePatchTH; // FIXME. Find a better solution
79 bool fInChooseBiasHv; // FIXME. Find a better solution
80 bool fInChooseBiasCam; // FIXME. Find a better solution
81
82 DimStampedInfo fDimDNS;
83
84 DimStampedInfo fDimLoggerStats;
85 DimStampedInfo fDimLoggerFilenameNight;
86 DimStampedInfo fDimLoggerFilenameRun;
87 DimStampedInfo fDimLoggerNumSubs;
88
89 DimStampedInfo fDimFtmPassport;
90 DimStampedInfo fDimFtmTriggerRates;
91 DimStampedInfo fDimFtmError;
92 DimStampedInfo fDimFtmFtuList;
93 DimStampedInfo fDimFtmStaticData;
94 DimStampedInfo fDimFtmDynamicData;
95 DimStampedInfo fDimFtmCounter;
96
97 DimStampedInfo fDimFadWriteStats;
98 DimStampedInfo fDimFadStartRun;
99 DimStampedInfo fDimFadRuns;
100 DimStampedInfo fDimFadEvents;
101 DimStampedInfo fDimFadRawData;
102 DimStampedInfo fDimFadEventData;
103 DimStampedInfo fDimFadConnections;
104 DimStampedInfo fDimFadFwVersion;
105 DimStampedInfo fDimFadRunNumber;
106 DimStampedInfo fDimFadDNA;
107 DimStampedInfo fDimFadTemperature;
108 DimStampedInfo fDimFadPrescaler;
109 DimStampedInfo fDimFadRefClock;
110 DimStampedInfo fDimFadRoi;
111 DimStampedInfo fDimFadDac;
112 DimStampedInfo fDimFadDrsCalibration;
113 DimStampedInfo fDimFadStatus;
114 DimStampedInfo fDimFadStatistics1;
115 //DimStampedInfo fDimFadStatistics2;
116 DimStampedInfo fDimFadFileFormat;
117
118 DimStampedInfo fDimFscTemp;
119 DimStampedInfo fDimFscVolt;
120 DimStampedInfo fDimFscCurrent;
121 DimStampedInfo fDimFscHumidity;
122
123 DimStampedInfo fDimFeedbackDeviation;
124 DimStampedInfo fDimFeedbackReference;
125 DimStampedInfo fDimFeedbackCalibration;
126
127 DimStampedInfo fDimBiasNominal;
128 DimStampedInfo fDimBiasVolt;
129 DimStampedInfo fDimBiasDac;
130 DimStampedInfo fDimBiasCurrent;
131
132 DimStampedInfo fDimRateScan;
133
134 DimStampedInfo fDimMagicWeather;
135
136 map<string, DimInfo*> fServices;
137
138 // ========================== LED Colors ================================
139
140 enum LedColor_t
141 {
142 kLedRed,
143 kLedGreen,
144 kLedGreenWarn,
145 kLedGreenCheck,
146 kLedGreenBar,
147 kLedYellow,
148 kLedOrange,
149 kLedGray,
150 kLedWarnBorder,
151 kLedWarn,
152 kLedWarnTriangleBorder,
153 kLedWarnTriangle,
154 kLedInProgress,
155 };
156
157 void SetLedColor(QPushButton *button, LedColor_t col, const Time &t)
158 {
159 switch (col)
160 {
161 case kLedRed:
162 button->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
163 break;
164
165 case kLedGreen:
166 button->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
167 break;
168
169 case kLedGreenBar:
170 button->setIcon(QIcon(":/Resources/icons/green bar.png"));
171 break;
172
173 case kLedGreenWarn:
174 button->setIcon(QIcon(":/Resources/icons/green warn.png"));
175 break;
176
177 case kLedGreenCheck:
178 button->setIcon(QIcon(":/Resources/icons/green check.png"));
179 break;
180
181 case kLedYellow:
182 button->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
183 break;
184
185 case kLedOrange:
186 button->setIcon(QIcon(":/Resources/icons/orange circle 1.png"));
187 break;
188
189 case kLedGray:
190 button->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
191 break;
192
193 case kLedWarnBorder:
194 button->setIcon(QIcon(":/Resources/icons/warning 1.png"));
195 break;
196
197 case kLedWarn:
198 button->setIcon(QIcon(":/Resources/icons/warning 2.png"));
199 break;
200
201 case kLedWarnTriangle:
202 button->setIcon(QIcon(":/Resources/icons/warning 3.png"));
203 break;
204
205 case kLedWarnTriangleBorder:
206 button->setIcon(QIcon(":/Resources/icons/warning 4.png"));
207 break;
208
209 case kLedInProgress:
210 button->setIcon(QIcon(":/Resources/icons/in progress.png"));
211 break;
212
213 }
214
215 //button->setToolTip("Last change: "+QDateTime::currentDateTimeUtc().toString()+" UTC");
216 button->setToolTip(("Last change: "+t.GetAsStr()+" (UTC)").c_str());
217 }
218
219 // ===================== Services and Commands ==========================
220
221 QStandardItem *AddServiceItem(const string &server, const string &service, bool iscmd)
222 {
223 QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
224 QListView *services = iscmd ? fDimCmdCommands : fDimSvcServices;
225 QListView *description = iscmd ? fDimCmdDescription : fDimSvcDescription;
226
227 QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
228 if (!m)
229 {
230 m = new QStandardItemModel(this);
231 servers->setModel(m);
232 services->setModel(m);
233 description->setModel(m);
234 }
235
236 QList<QStandardItem*> l = m->findItems(server.c_str());
237
238 if (l.size()>1)
239 {
240 cout << "hae" << endl;
241 return 0;
242 }
243
244 QStandardItem *col = l.size()==0 ? NULL : l[0];
245
246 if (!col)
247 {
248 col = new QStandardItem(server.c_str());
249 m->appendRow(col);
250
251 if (!services->rootIndex().isValid())
252 {
253 services->setRootIndex(col->index());
254 servers->setCurrentIndex(col->index());
255 }
256 }
257
258 QStandardItem *item = 0;
259 for (int i=0; i<col->rowCount(); i++)
260 {
261 QStandardItem *coli = col->child(i);
262 if (coli->text().toStdString()==service)
263 return coli;
264 }
265
266 item = new QStandardItem(service.c_str());
267 col->appendRow(item);
268 col->sortChildren(0);
269
270 if (!description->rootIndex().isValid())
271 {
272 description->setRootIndex(item->index());
273 services->setCurrentIndex(item->index());
274 }
275
276 if (!iscmd)
277 item->setCheckable(true);
278
279 return item;
280 }
281
282 void AddDescription(QStandardItem *item, const vector<Description> &vec)
283 {
284 if (!item)
285 return;
286 if (vec.size()==0)
287 return;
288
289 item->setToolTip(vec[0].comment.c_str());
290
291 const string str = Description::GetHtmlDescription(vec);
292
293 QStandardItem *desc = new QStandardItem(str.c_str());
294 desc->setSelectable(false);
295 item->setChild(0, 0, desc);
296 }
297
298 void AddServer(const string &s)
299 {
300 DimNetwork::AddServer(s);
301
302 const State state = GetState(s, GetCurrentState(s));
303
304 QApplication::postEvent(this,
305 new FunctionEvent(bind(&FactGui::handleAddServer, this, s, state)));
306 }
307
308 void AddService(const string &server, const string &service, const string &fmt, bool iscmd)
309 {
310 const vector<Description> v = GetDescription(server, service);
311
312 QApplication::postEvent(this,
313 new FunctionEvent(bind(&FactGui::handleAddService, this, server, service, fmt, iscmd, v)));
314 }
315
316 void RemoveService(string server, string service, bool iscmd)
317 {
318 UnsubscribeService(server+'/'+service, true);
319
320 QApplication::postEvent(this,
321 new FunctionEvent(bind(&FactGui::handleRemoveService, this, server, service, iscmd)));
322 }
323
324 void RemoveAllServices(const string &server)
325 {
326 UnsubscribeAllServices(server);
327
328 QApplication::postEvent(this,
329 new FunctionEvent(bind(&FactGui::handleRemoveAllServices, this, server)));
330 }
331
332 void AddDescription(const string &server, const string &service, const vector<Description> &vec)
333 {
334 const bool iscmd = IsCommand(server, service)==true;
335
336 QApplication::postEvent(this,
337 new FunctionEvent(bind(&FactGui::handleAddDescription, this, server, service, vec, iscmd)));
338 }
339
340 // ======================================================================
341
342 void handleAddServer(const string &server, const State &state)
343 {
344 handleStateChanged(Time(), server, state);
345 }
346
347 void handleAddService(const string &server, const string &service, const string &/*fmt*/, bool iscmd, const vector<Description> &vec)
348 {
349 QStandardItem *item = AddServiceItem(server, service, iscmd);
350 AddDescription(item, vec);
351 }
352
353 void handleRemoveService(const string &server, const string &service, bool iscmd)
354 {
355 QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
356
357 QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
358 if (!m)
359 return;
360
361 QList<QStandardItem*> l = m->findItems(server.c_str());
362 if (l.size()!=1)
363 return;
364
365 for (int i=0; i<l[0]->rowCount(); i++)
366 {
367 QStandardItem *row = l[0]->child(i);
368 if (row->text().toStdString()==service)
369 {
370 l[0]->removeRow(row->index().row());
371 return;
372 }
373 }
374 }
375
376 void handleRemoveAllServices(const string &server)
377 {
378 handleStateChanged(Time(), server, State(-2, "Offline", "No connection via DIM."));
379
380 QStandardItemModel *m = 0;
381 if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
382 {
383 QList<QStandardItem*> l = m->findItems(server.c_str());
384 if (l.size()==1)
385 m->removeRow(l[0]->index().row());
386 }
387
388 if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
389 {
390 QList<QStandardItem*> l = m->findItems(server.c_str());
391 if (l.size()==1)
392 m->removeRow(l[0]->index().row());
393 }
394 }
395
396 void handleAddDescription(const string &server, const string &service, const vector<Description> &vec, bool iscmd)
397 {
398 QStandardItem *item = AddServiceItem(server, service, iscmd);
399 AddDescription(item, vec);
400 }
401
402 // ======================================================================
403
404 void SubscribeService(const string &service)
405 {
406 if (fServices.find(service)!=fServices.end())
407 {
408 cerr << "ERROR - We are already subscribed to " << service << endl;
409 return;
410 }
411
412 fServices[service] = new DimStampedInfo(service.c_str(), (void*)NULL, 0, this);
413 }
414
415 void UnsubscribeService(const string &service, bool allow_unsubscribed=false)
416 {
417 const map<string,DimInfo*>::iterator i=fServices.find(service);
418
419 if (i==fServices.end())
420 {
421 if (!allow_unsubscribed)
422 cerr << "ERROR - We are not subscribed to " << service << endl;
423 return;
424 }
425
426 delete i->second;
427
428 fServices.erase(i);
429 }
430
431 void UnsubscribeAllServices(const string &server)
432 {
433 for (map<string,DimInfo*>::iterator i=fServices.begin();
434 i!=fServices.end(); i++)
435 if (i->first.substr(0, server.length()+1)==server+'/')
436 {
437 delete i->second;
438 fServices.erase(i);
439 }
440 }
441
442 // ======================= DNS ==========================================
443
444 uint32_t fDimVersion;
445
446 void UpdateGlobalStatus()
447 {
448 ostringstream dns;
449 dns << (fDimVersion==0?"No connection":"Connection");
450 dns << " to DIM DNS (" << getenv("DIM_DNS_NODE") << ")";
451 dns << (fDimVersion==0?".":" established");
452
453 ostringstream str;
454 str << "V" << fDimVersion/100 << 'r' << fDimVersion%100;
455
456 LedColor_t led = kLedGreen;
457 if (fDimVersion>0)
458 {
459 dns << fixed << setprecision(1) << right;
460 if (fFreeSpaceLogger!=UINT64_MAX)
461 dns << "<pre> * Data logger: " << setw(7) << fFreeSpaceLogger*1e-7 << " GB</pre>";
462 if (fFreeSpaceData!=UINT64_MAX)
463 dns << "<pre> * Event Builder: " << setw(7) << fFreeSpaceData*1e-7 << " GB</pre>";
464
465 if (fFreeSpaceLogger<500000000 || fFreeSpaceData<500000000)
466 led = kLedGreenWarn;
467 if (fFreeSpaceLogger<200000000 || fFreeSpaceData<200000000)
468 led = kLedWarnTriangleBorder;
469
470 if (led!=kLedGreen)
471 str << " (Disk space!)";
472 }
473
474 fStatusDNSLabel->setToolTip(dns.str().c_str());
475
476 SetLedColor(fStatusDNSLed, fDimVersion==0 ? kLedRed : led, Time());
477
478 fStatusDNSLabel->setText(fDimVersion==0?"Offline":str.str().c_str());
479 }
480
481 void handleDimDNS(const DimData &d)
482 {
483 fDimVersion = d.size()!=4 ? 0 : d.get<uint32_t>();
484
485 UpdateGlobalStatus();
486
487 fShutdown->setEnabled(fDimVersion!=0);
488 fShutdownAll->setEnabled(fDimVersion!=0);
489 }
490
491
492 // ======================= Logger =======================================
493
494 uint64_t fFreeSpaceLogger;
495
496 void handleLoggerStats(const DimData &d)
497 {
498 const bool connected = d.size()!=0;
499
500 fLoggerET->setEnabled(connected);
501 fLoggerRate->setEnabled(connected);
502 fLoggerWritten->setEnabled(connected);
503 fLoggerFreeSpace->setEnabled(connected);
504 fLoggerSpaceLeft->setEnabled(connected);
505
506 fFreeSpaceLogger = UINT64_MAX;
507 UpdateGlobalStatus();
508
509 if (!connected)
510 return;
511
512 const uint64_t *vals = d.ptr<uint64_t>();
513
514 const size_t space = vals[0];
515 const size_t written = vals[1];
516 const size_t rate = float(vals[2])/vals[3];
517
518 fFreeSpaceLogger = space;
519 UpdateGlobalStatus();
520
521 fLoggerFreeSpace->setSuffix(" MB");
522 fLoggerFreeSpace->setDecimals(0);
523 fLoggerFreeSpace->setValue(space*1e-6);
524
525 if (space> 1000000) // > 1GB
526 {
527 fLoggerFreeSpace->setSuffix(" GB");
528 fLoggerFreeSpace->setDecimals(2);
529 fLoggerFreeSpace->setValue(space*1e-9);
530 }
531 if (space>= 3000000) // >= 3GB
532 {
533 fLoggerFreeSpace->setSuffix(" GB");
534 fLoggerFreeSpace->setDecimals(1);
535 fLoggerFreeSpace->setValue(space*1e-9);
536 }
537 if (space>=100000000) // >= 100GB
538 {
539 fLoggerFreeSpace->setSuffix(" GB");
540 fLoggerFreeSpace->setDecimals(0);
541 fLoggerFreeSpace->setValue(space*1e-9);
542 }
543
544 fLoggerET->setTime(QTime().addSecs(rate>0?space/rate:0));
545 fLoggerRate->setValue(rate*1e-3); // kB/s
546 fLoggerWritten->setValue(written*1e-6);
547
548 fLoggerRate->setSuffix(" kB/s");
549 fLoggerRate->setDecimals(2);
550 fLoggerRate->setValue(rate);
551 if (rate> 2) // > 2kB/s
552 {
553 fLoggerRate->setSuffix(" kB/s");
554 fLoggerRate->setDecimals(1);
555 fLoggerRate->setValue(rate);
556 }
557 if (rate>=100) // >100kB/s
558 {
559 fLoggerRate->setSuffix(" kB/s");
560 fLoggerRate->setDecimals(0);
561 fLoggerRate->setValue(rate);
562 }
563 if (rate>=1000) // >100kB/s
564 {
565 fLoggerRate->setSuffix(" MB/s");
566 fLoggerRate->setDecimals(2);
567 fLoggerRate->setValue(rate*1e-3);
568 }
569 if (rate>=10000) // >1MB/s
570 {
571 fLoggerRate->setSuffix(" MB/s");
572 fLoggerRate->setDecimals(1);
573 fLoggerRate->setValue(rate*1e-3);
574 }
575 if (rate>=100000) // >10MB/s
576 {
577 fLoggerRate->setSuffix(" MB/s");
578 fLoggerRate->setDecimals(0);
579 fLoggerRate->setValue(rate*1e-3);
580 }
581
582 if (space/1000000>static_cast<size_t>(fLoggerSpaceLeft->maximum()))
583 fLoggerSpaceLeft->setValue(fLoggerSpaceLeft->maximum()); // GB
584 else
585 fLoggerSpaceLeft->setValue(space/1000000); // MB
586 }
587
588 void handleLoggerFilenameNight(const DimData &d)
589 {
590 const bool connected = d.size()!=0;
591
592 fLoggerFilenameNight->setEnabled(connected);
593 if (!connected)
594 return;
595
596 fLoggerFilenameNight->setText(d.c_str()+4);
597
598 const uint32_t files = d.get<uint32_t>();
599
600 SetLedColor(fLoggerLedLog, files&1 ? kLedGreen : kLedGray, d.time);
601 SetLedColor(fLoggerLedRep, files&2 ? kLedGreen : kLedGray, d.time);
602 SetLedColor(fLoggerLedFits, files&4 ? kLedGreen : kLedGray, d.time);
603 }
604
605 void handleLoggerFilenameRun(const DimData &d)
606 {
607 const bool connected = d.size()!=0;
608
609 fLoggerFilenameRun->setEnabled(connected);
610 if (!connected)
611 return;
612
613 fLoggerFilenameRun->setText(d.c_str()+4);
614
615 const uint32_t files = d.get<uint32_t>();
616
617 SetLedColor(fLoggerLedLog, files&1 ? kLedGreen : kLedGray, d.time);
618 SetLedColor(fLoggerLedRep, files&2 ? kLedGreen : kLedGray, d.time);
619 SetLedColor(fLoggerLedFits, files&4 ? kLedGreen : kLedGray, d.time);
620 }
621
622 void handleLoggerNumSubs(const DimData &d)
623 {
624 const bool connected = d.size()!=0;
625
626 fLoggerSubscriptions->setEnabled(connected);
627 fLoggerOpenFiles->setEnabled(connected);
628 if (!connected)
629 return;
630
631 const uint32_t *vals = d.ptr<uint32_t>();
632
633 fLoggerSubscriptions->setValue(vals[0]);
634 fLoggerOpenFiles->setValue(vals[1]);
635 }
636
637
638 // ===================== All ============================================
639
640 bool CheckSize(const DimData &d, size_t sz, bool print=true) const
641 {
642 if (d.size()==0)
643 return false;
644
645 if (d.size()!=sz)
646 {
647 if (print)
648 cerr << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected=" << sz << endl;
649 return false;
650 }
651
652 return true;
653 }
654
655 // ===================== FAD ============================================
656
657 uint64_t fFreeSpaceData;
658
659 void handleFadWriteStats(const DimData &d)
660 {
661 const bool connected = d.size()!=0;
662
663 fEvtBuilderET->setEnabled(connected);
664 fEvtBuilderRate->setEnabled(connected);
665 fEvtBuilderWritten->setEnabled(connected);
666 fEvtBuilderFreeSpace->setEnabled(connected);
667 fEvtBuilderSpaceLeft->setEnabled(connected);
668
669 fFreeSpaceData = UINT64_MAX;
670 UpdateGlobalStatus();
671
672 if (!connected)
673 return;
674
675 const uint64_t *vals = d.ptr<uint64_t>();
676
677 const size_t space = vals[0];
678 const size_t written = vals[1];
679 const size_t rate = float(vals[2])/vals[3];
680
681 fFreeSpaceData = space;
682 UpdateGlobalStatus();
683
684 fEvtBuilderFreeSpace->setSuffix(" MB");
685 fEvtBuilderFreeSpace->setDecimals(0);
686 fEvtBuilderFreeSpace->setValue(space*1e-6);
687
688 if (space> 1000000) // > 1GB
689 {
690 fEvtBuilderFreeSpace->setSuffix(" GB");
691 fEvtBuilderFreeSpace->setDecimals(2);
692 fEvtBuilderFreeSpace->setValue(space*1e-9);
693 }
694 if (space>= 3000000) // >= 3GB
695 {
696 fEvtBuilderFreeSpace->setSuffix(" GB");
697 fEvtBuilderFreeSpace->setDecimals(1);
698 fEvtBuilderFreeSpace->setValue(space*1e-9);
699 }
700 if (space>=100000000) // >= 100GB
701 {
702 fEvtBuilderFreeSpace->setSuffix(" GB");
703 fEvtBuilderFreeSpace->setDecimals(0);
704 fEvtBuilderFreeSpace->setValue(space*1e-9);
705 }
706
707 fEvtBuilderET->setTime(QTime().addSecs(rate>0?space/rate:0));
708 fEvtBuilderRate->setValue(rate*1e-3); // kB/s
709 fEvtBuilderWritten->setValue(written*1e-6);
710
711 fEvtBuilderRate->setSuffix(" kB/s");
712 fEvtBuilderRate->setDecimals(2);
713 fEvtBuilderRate->setValue(rate);
714 if (rate> 2) // > 2kB/s
715 {
716 fEvtBuilderRate->setSuffix(" kB/s");
717 fEvtBuilderRate->setDecimals(1);
718 fEvtBuilderRate->setValue(rate);
719 }
720 if (rate>=100) // >100kB/s
721 {
722 fEvtBuilderRate->setSuffix(" kB/s");
723 fEvtBuilderRate->setDecimals(0);
724 fEvtBuilderRate->setValue(rate);
725 }
726 if (rate>=1000) // >100kB/s
727 {
728 fEvtBuilderRate->setSuffix(" MB/s");
729 fEvtBuilderRate->setDecimals(2);
730 fEvtBuilderRate->setValue(rate*1e-3);
731 }
732 if (rate>=10000) // >1MB/s
733 {
734 fEvtBuilderRate->setSuffix(" MB/s");
735 fEvtBuilderRate->setDecimals(1);
736 fEvtBuilderRate->setValue(rate*1e-3);
737 }
738 if (rate>=100000) // >10MB/s
739 {
740 fEvtBuilderRate->setSuffix(" MB/s");
741 fEvtBuilderRate->setDecimals(0);
742 fEvtBuilderRate->setValue(rate*1e-3);
743 }
744
745 if (space/1000000>static_cast<size_t>(fEvtBuilderSpaceLeft->maximum()))
746 fEvtBuilderSpaceLeft->setValue(fEvtBuilderSpaceLeft->maximum()); // GB
747 else
748 fEvtBuilderSpaceLeft->setValue(space/1000000); // MB
749 }
750
751 void handleFadRuns(const DimData &d)
752 {
753 if (d.size()==0)
754 return;
755
756 if (d.size()<8)
757 {
758 cerr << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected>=8" << endl;
759 return;
760 }
761
762 const uint32_t *ptr = d.ptr<uint32_t>();
763
764 fEvtBldLastOpened->setValue(ptr[0]);
765 fEvtBldLastClosed->setValue(ptr[1]);
766
767 if (d.size()>=8)
768 fEvtBldFilename->setText(d.ptr<char>(8));
769
770 fEvtBldLastOpened->setEnabled(d.qos);
771 fEvtBldLastClosed->setEnabled(d.qos);
772 fEvtBldFilename->setEnabled(d.qos);
773 }
774
775 void handleFadStartRun(const DimData &d)
776 {
777 if (!CheckSize(d, 16))
778 return;
779
780 const int64_t *runs = d.ptr<int64_t>();
781
782 fFadRunNoCur->setValue(runs[0]);
783 fFadRunNoNext->setValue(runs[1]);
784 fFadRunNoCur->setEnabled(runs[0]>=0);
785 //fMcpStopRun->setEnabled(runs[0]>=0);
786
787 }
788
789 void handleFadEvents(const DimData &d)
790 {
791 if (!CheckSize(d, 16))
792 return;
793
794 const uint32_t *ptr = d.ptr<uint32_t>();
795
796 fEvtsSuccessCurRun->setValue(ptr[0]);
797 fEvtsSuccessTotal->setValue(ptr[1]);
798 fEvtBldEventId->setValue(ptr[2]);
799 fFadEvtCounter->setValue(ptr[2]);
800 fEvtBldTriggerId->setValue(ptr[3]);
801 }
802
803 void handleFadTemperature(const DimData &d)
804 {
805 if (d.size()==0)
806 {
807 fFadTempMin->setEnabled(false);
808 fFadTempMax->setEnabled(false);
809 SetLedColor(fFadLedTemp, kLedGray, d.time);
810 return;
811 }
812
813 if (!CheckSize(d, sizeof(uint16_t)+160*sizeof(float)))
814 return;
815
816 const float *ptr = d.ptr<float>(2);
817
818 fFadTempMin->setEnabled(true);
819 fFadTempMax->setEnabled(true);
820
821 float min = FLT_MAX;
822 float max = -FLT_MAX;
823
824 vector<float> mn(40, FLT_MAX);
825 vector<float> mx(40, -FLT_MAX);
826 for (int i=0; i<160; i++)
827 {
828 if (!finite(ptr[i]))
829 continue;
830
831 if (ptr[i]<min)
832 min = ptr[i];
833 if (ptr[i]>max)
834 max = ptr[i];
835
836 if (ptr[i]<mn[i/4])
837 mn[i/4] = ptr[i];
838 if (ptr[i]>mx[i/4])
839 mx[i/4] = ptr[i];
840 }
841
842 fFadTempMin->setValue(min);
843 fFadTempMax->setValue(max);
844
845 handleFadToolTip(d.time, fFadTempMin, mn.data());
846 handleFadToolTip(d.time, fFadTempMax, mx.data());
847 }
848
849 void handleFadRefClock(const DimData &d)
850 {
851 if (d.size()==0)
852 {
853 fFadRefClockMin->setEnabled(false);
854 fFadRefClockMax->setEnabled(false);
855 SetLedColor(fFadLedRefClock, kLedGray, d.time);
856 return;
857 }
858
859 if (!CheckSize(d, sizeof(uint16_t)+40*sizeof(float)))
860 return;
861
862 const float *ptr = d.ptr<float>(2);
863
864 fFadRefClockMin->setEnabled(true);
865 fFadRefClockMax->setEnabled(true);
866
867 float min = FLT_MAX;
868 float max = -FLT_MAX;
869 for (int i=0; i<40; i++)
870 {
871 if (!finite(ptr[i]))
872 continue;
873
874 if (ptr[i]<min)
875 min = ptr[i];
876 if (ptr[i]>max)
877 max = ptr[i];
878 }
879
880 fFadRefClockMin->setValue(min);
881 fFadRefClockMax->setValue(max);
882
883 const int64_t diff = int64_t(max) - int64_t(min);
884
885 SetLedColor(fFadLedRefClock, abs(diff)>3?kLedRed:kLedGreen, d.time);
886
887 handleFadToolTip(d.time, fFadLedRefClock, ptr);
888 }
889
890 void handleFadRoi(const DimData &d)
891 {
892 if (d.size()==0)
893 {
894 fFadRoi->setEnabled(false);
895 fFadRoiCh9->setEnabled(false);
896 //SetLedColor(fFadLedRoi, kLedGray, d.time);
897 return;
898 }
899
900 if (!CheckSize(d, 2*sizeof(uint16_t)))
901 return;
902
903 const uint16_t *ptr = d.ptr<uint16_t>();
904
905 fFadRoi->setEnabled(true);
906 fFadRoiCh9->setEnabled(true);
907
908 fFadRoi->setValue(ptr[0]);
909 fFadRoiCh9->setValue(ptr[1]);
910
911 //SetLedColor(fFadLedRoi, kLedGray, d.time);
912 }
913
914 void handleDac(QPushButton *led, QSpinBox *box, const DimData &d, int idx)
915 {
916 if (d.size()==0)
917 {
918 box->setEnabled(false);
919 SetLedColor(led, kLedGray, d.time);
920 return;
921 }
922
923 const uint16_t *ptr = d.ptr<uint16_t>()+idx*42;
924
925 box->setEnabled(true);
926 box->setValue(ptr[40]==ptr[41]?ptr[40]:0);
927
928 SetLedColor(led, ptr[40]==ptr[41]?kLedGreen:kLedOrange, d.time);
929 handleFadToolTip(d.time, led, ptr);
930 }
931
932 void handleFadDac(const DimData &d)
933 {
934 if (!CheckSize(d, 8*42*sizeof(uint16_t)) && !d.size()==0)
935 return;
936
937 handleDac(fFadLedDac0, fFadDac0, d, 0);
938 handleDac(fFadLedDac1, fFadDac1, d, 1);
939 handleDac(fFadLedDac2, fFadDac2, d, 2);
940 handleDac(fFadLedDac3, fFadDac3, d, 3);
941 handleDac(fFadLedDac4, fFadDac4, d, 4);
942 handleDac(fFadLedDac5, fFadDac5, d, 5);
943 handleDac(fFadLedDac6, fFadDac6, d, 6);
944 handleDac(fFadLedDac7, fFadDac7, d, 7);
945 }
946
947 EVENT *fEventData;
948
949 void DrawHorizontal(TH1 *hf, double xmax, TH1 &h, double scale)
950 {
951 for (Int_t i=1;i<=h.GetNbinsX();i++)
952 {
953 if (h.GetBinContent(i)<0.5 || h.GetBinContent(i)>h.GetEntries()-0.5)
954 continue;
955
956 TBox * box=new TBox(xmax, h.GetBinLowEdge(i),
957 xmax+h.GetBinContent(i)*scale,
958 h.GetBinLowEdge(i+1));
959
960 box->SetFillStyle(0);
961 box->SetLineColor(h.GetLineColor());
962 box->SetLineStyle(kSolid);
963 box->SetBit(kCannotPick|kNoContextMenu);
964 //box->Draw();
965
966 hf->GetListOfFunctions()->Add(box);
967 }
968 }
969
970 void DisplayEventData()
971 {
972 if (!fEventData)
973 return;
974
975#ifdef HAVE_ROOT
976 TCanvas *c = fAdcDataCanv->GetCanvas();
977
978 TH1 *hf = dynamic_cast<TH1*>(c->FindObject("Frame"));
979 TH1 *h = dynamic_cast<TH1*>(c->FindObject("EventData"));
980 TH1 *d0 = dynamic_cast<TH1*>(c->FindObject("DrsCalib0"));
981 TH1 *d1 = dynamic_cast<TH1*>(c->FindObject("DrsCalib1"));
982 TH1 *d2 = dynamic_cast<TH1*>(c->FindObject("DrsCalib2"));
983
984 const int roi = fAdcPhysical->isChecked() ? 1024 : (fEventData->Roi>0 ? fEventData->Roi : 1);
985
986 if ((hf && hf->GetNbinsX()!=roi) ||
987 (dynamic_cast<TH2*>(h) && !fAdcPersistent->isChecked()) ||
988 (!dynamic_cast<TH2*>(h) && fAdcPersistent->isChecked()))
989 {
990 delete hf;
991 delete h;
992 delete d0;
993 delete d1;
994 delete d2;
995 d0 = 0;
996 d1 = 0;
997 d2 = 0;
998 hf = 0;
999 }
1000
1001 if (!hf)
1002 {
1003 hf = new TH1F("Frame", "", roi, -0.5, roi-0.5);
1004 hf->SetDirectory(0);
1005 hf->SetBit(kCanDelete);
1006 hf->SetStats(kFALSE);
1007 hf->SetYTitle("Voltage [mV]");
1008 hf->GetXaxis()->CenterTitle();
1009 hf->GetYaxis()->CenterTitle();
1010 hf->SetMinimum(-1250);
1011 hf->SetMaximum(2150);
1012
1013 if (!fAdcPersistent->isChecked())
1014 h = new TH1F("EventData", "", roi, -0.5, roi-0.5);
1015 else
1016 {
1017 h = new TH2F("EventData", "", roi, -0.5, roi-0.5, 6751, -2350.5*2000/4096, 4400.5*2000/4096);
1018 h->SetContour(50);
1019 gStyle->SetPalette(1, 0);
1020 }
1021
1022 h->SetDirectory(0);
1023 h->SetBit(kCanDelete);
1024 h->SetMarkerStyle(kFullDotMedium);
1025 h->SetMarkerColor(kBlue);
1026
1027 c->GetListOfPrimitives()->Add(hf, "");
1028
1029 if (dynamic_cast<TH2*>(h))
1030 c->GetListOfPrimitives()->Add(h, "col same");
1031 }
1032
1033 if (d0 && !(fDrsCalibBaselineOn->isChecked() && fDrsCalibBaseline->value()>0))
1034 {
1035 delete d0;
1036 d0 = 0;
1037 }
1038 if (d1 && !(fDrsCalibGainOn->isChecked() && fDrsCalibGain->value()>0))
1039 {
1040 delete d1;
1041 d1 = 0;
1042 }
1043 if (d2 && !(fDrsCalibTrgOffsetOn->isChecked() && fDrsCalibTrgOffset->value()>0))
1044 {
1045 delete d2;
1046 d2 = 0;
1047 }
1048
1049 if (!d0 && fDrsCalibBaselineOn->isChecked() && fDrsCalibBaseline->value()>0)
1050 {
1051 d0 = new TH1F("DrsCalib0", "", roi, -0.5, roi-0.5);
1052 d0->SetDirectory(0);
1053 d0->SetBit(kCanDelete);
1054 d0->SetMarkerStyle(kFullDotSmall);
1055 d0->SetMarkerColor(kRed);
1056 d0->SetLineColor(kRed);
1057 c->GetListOfPrimitives()->Add(d0, "PEX0same");
1058 }
1059
1060 if (!d1 && fDrsCalibGainOn->isChecked() && fDrsCalibGain->value()>0)
1061 {
1062 d1 = new TH1F("DrsCalib1", "", roi, -0.5, roi-0.5);
1063 d1->SetDirectory(0);
1064 d1->SetBit(kCanDelete);
1065 d1->SetMarkerStyle(kFullDotSmall);
1066 d1->SetMarkerColor(kMagenta);
1067 d1->SetLineColor(kMagenta);
1068 c->GetListOfPrimitives()->Add(d1, "PEX0same");
1069 }
1070
1071 if (!d2 && fDrsCalibTrgOffsetOn->isChecked() && fDrsCalibTrgOffset->value()>0)
1072 {
1073 d2 = new TH1F("DrsCalib2", "", roi, -0.5, roi-0.5);
1074 d2->SetDirectory(0);
1075 d2->SetBit(kCanDelete);
1076 d2->SetMarkerStyle(kFullDotSmall);
1077 d2->SetMarkerColor(kGreen);
1078 d2->SetLineColor(kGreen);
1079 c->GetListOfPrimitives()->Add(d2, "PEX0same");
1080 }
1081
1082 if (!dynamic_cast<TH2*>(h) && !c->GetListOfPrimitives()->FindObject(h))
1083 c->GetListOfPrimitives()->Add(h, "PLsame");
1084
1085 // -----------------------------------------------------------
1086
1087 const uint32_t p =
1088 fAdcChannel->value() +
1089 fAdcChip->value() * 9+
1090 fAdcBoard->value() * 36+
1091 fAdcCrate->value() *360;
1092
1093 ostringstream str;
1094 str << "CBPX = " << fAdcCrate->value() << '|' << fAdcBoard->value() << '|' << fAdcChip->value() << '|' << fAdcChannel->value() << " (" << p << ")";
1095 str << " EventNum = " << fEventData->EventNum;
1096 str << " TriggerNum = " << fEventData->TriggerNum;
1097 str << " TriggerType = " << fEventData->TriggerType;
1098 str << " BoardTime = " << fEventData->BoardTime[fAdcBoard->value()+fAdcCrate->value()*10];
1099 str << " (" << Time(fEventData->PCTime, fEventData->PCUsec) << ")";
1100 hf->SetTitle(str.str().c_str());
1101 str.str("");
1102 str << "ADC Pipeline (start cell: " << fEventData->StartPix[p] << ")";
1103 hf->SetXTitle(str.str().c_str());
1104
1105 // -----------------------------------------------------------
1106
1107 const int16_t start = fEventData->StartPix[p];
1108
1109 fDrsCalibBaseline->setEnabled(fDrsCalibBaseline->value()>0);
1110 fDrsCalibGain->setEnabled(fDrsCalibGain->value()>0);
1111 fDrsCalibTrgOffset->setEnabled(fDrsCalibTrgOffset->value()>0);
1112 fDrsCalibROI->setEnabled(fDrsCalibROI->value()>0);
1113
1114 fDrsCalibBaseline2->setEnabled(fDrsCalibBaseline->value()>0);
1115 fDrsCalibGain2->setEnabled(fDrsCalibGain->value()>0);
1116 fDrsCalibTrgOffset2->setEnabled(fDrsCalibTrgOffset->value()>0);
1117 fDrsCalibROI2->setEnabled(fDrsCalibROI->value()>0);
1118
1119 SetLedColor(fFadLedDrsBaseline, fDrsCalibBaseline->value()>0 ?kLedGreen:kLedGray, Time());
1120 SetLedColor(fFadLedDrsGain, fDrsCalibGain->value()>0 ?kLedGreen:kLedGray, Time());
1121 SetLedColor(fFadLedDrsTrgOff, fDrsCalibTrgOffset->value()>0?kLedGreen:kLedGray, Time());
1122
1123 if (d0)//fDrsCalibBaseline->value()==0 || start<0)
1124 d0->Reset();
1125 if (d1)//fDrsCalibGain->value()==0 || start<0)
1126 d1->Reset();
1127 if (d2)//fDrsCalibTrgOffset->value()==0 || start<0)
1128 d2->Reset();
1129
1130 if (!dynamic_cast<TH2*>(h))
1131 h->Reset();
1132 if (d0)
1133 d0->SetEntries(0);
1134 if (d1)
1135 d1->SetEntries(0);
1136 if (d2)
1137 d2->SetEntries(0);
1138
1139 for (int i=0; i<fEventData->Roi; i++)
1140 {
1141 // FIXME: physcial: i -> (i+start)%1024
1142 // FIXME: logical: i -> i
1143
1144 const int ii = fAdcPhysical->isChecked() ? (i+start)%1024 : i;
1145
1146 //if (dynamic_cast<TH2*>(h))
1147 h->Fill(ii, reinterpret_cast<float*>(fEventData->Adc_Data)[p*fEventData->Roi+i]);
1148 //else
1149 // h->SetBinContent(i+1, reinterpret_cast<float*>(fEventData->Adc_Data)[p*fEventData->Roi+i]);
1150 if (start<0)
1151 continue;
1152
1153 if (d0)
1154 {
1155 d0->SetBinContent(ii+1, fDrsCalibration[1440*1024*0 + p*1024+(start+i)%1024]);
1156 d0->SetBinError(ii+1, fDrsCalibration[1440*1024*1 + p*1024+(start+i)%1024]);
1157
1158 }
1159 if (d1)
1160 {
1161 d1->SetBinContent(ii+1, fDrsCalibration[1440*1024*2 + p*1024+(start+i)%1024]);
1162 d1->SetBinError(ii+1, fDrsCalibration[1440*1024*3 + p*1024+(start+i)%1024]);
1163 }
1164 if (d2)
1165 {
1166 d2->SetBinContent(ii+1, fDrsCalibration[1440*1024*4 + p*1024 + i]);
1167 d2->SetBinError(ii+1, fDrsCalibration[1440*1024*5 + p*1024 + i]);
1168 }
1169 }
1170
1171 // -----------------------------------------------------------
1172 if (fAdcDynamicScale->isEnabled() && fAdcDynamicScale->isChecked())
1173 {
1174 h->SetMinimum();
1175 h->SetMaximum();
1176
1177 hf->SetMinimum(h->GetMinimum());
1178 hf->SetMaximum(h->GetMaximum());
1179 }
1180 if (fAdcManualScale->isEnabled() && fAdcManualScale->isChecked())
1181 {
1182 if (h->GetMinimumStored()==-1111)
1183 {
1184 h->SetMinimum(-1150);//-1026);
1185 hf->SetMinimum(-1150);//-1026);
1186 }
1187 if (h->GetMaximumStored()==-1111)
1188 {
1189 h->SetMaximum(2150);//1025);
1190 hf->SetMaximum(2150);//1025);
1191 }
1192 }
1193
1194 if (fAdcAutoScale->isEnabled() && fAdcAutoScale->isChecked())
1195 {
1196 h->SetMinimum();
1197 h->SetMaximum();
1198
1199 if (h->GetMinimum()<hf->GetMinimum())
1200 hf->SetMinimum(h->GetMinimum());
1201 if (h->GetMaximum()>hf->GetMaximum())
1202 hf->SetMaximum(h->GetMaximum());
1203 }
1204
1205 if (dynamic_cast<TH2*>(h))
1206 {
1207 h->SetMinimum();
1208 h->SetMaximum();
1209 }
1210
1211 // -----------------------------------------------------------
1212
1213 const int imin = ceil(hf->GetMinimum());
1214 const int imax = floor(hf->GetMaximum());
1215
1216 TH1S hd("", "", imax-imin+1, imin-0.5, imax+0.5);
1217 hd.SetDirectory(0);
1218 TH1S h0("", "", imax-imin+1, imin-0.5, imax+0.5);
1219 h0.SetDirectory(0);
1220 TH1S h1("", "", imax-imin+1, imin-0.5, imax+0.5);
1221 h1.SetDirectory(0);
1222 TH1S h2("", "", imax-imin+1, imin-0.5, imax+0.5);
1223 h2.SetDirectory(0);
1224 hd.SetLineColor(h->GetLineColor());
1225 if (d0)
1226 h0.SetLineColor(d0->GetLineColor());
1227 if (d1)
1228 h1.SetLineColor(d1->GetLineColor());
1229 if (d2)
1230 h2.SetLineColor(d2->GetLineColor());
1231
1232 for (int i=0; i<fEventData->Roi; i++)
1233 {
1234 if (!dynamic_cast<TH2*>(h))
1235 hd.Fill(h->GetBinContent(i+1));
1236 if (d0)
1237 h0.Fill(d0->GetBinContent(i+1));
1238 if (d1)
1239 h1.Fill(d1->GetBinContent(i+1));
1240 if (d2)
1241 h2.Fill(d2->GetBinContent(i+1));
1242 }
1243
1244 double mm = hd.GetMaximum(hd.GetEntries());
1245 if (h0.GetMaximum(h0.GetEntries())>mm)
1246 mm = h0.GetMaximum();
1247 if (h1.GetMaximum(h1.GetEntries())>mm)
1248 mm = h1.GetMaximum();
1249 if (h2.GetMaximum(h2.GetEntries())>mm)
1250 mm = h2.GetMaximum();
1251
1252 TIter Next(hf->GetListOfFunctions());
1253 TObject *obj = 0;
1254 while ((obj=Next()))
1255 if (dynamic_cast<TBox*>(obj))
1256 delete hf->GetListOfFunctions()->Remove(obj);
1257
1258 const double l = h->GetBinLowEdge(h->GetXaxis()->GetLast()+1);
1259 const double m = c->GetX2();
1260
1261 const double scale = 0.9*(m-l)/mm;
1262
1263 DrawHorizontal(hf, l, h2, scale);
1264 DrawHorizontal(hf, l, h1, scale);
1265 DrawHorizontal(hf, l, h0, scale);
1266 DrawHorizontal(hf, l, hd, scale);
1267
1268 // -----------------------------------------------------------
1269
1270 c->Modified();
1271 c->Update();
1272#endif
1273 }
1274
1275 void handleFadRawData(const DimData &d)
1276 {
1277 if (d.size()==0)
1278 return;
1279
1280 if (fAdcStop->isChecked())
1281 return;
1282
1283 const EVENT &dat = d.ref<EVENT>();
1284
1285 if (d.size()<sizeof(EVENT))
1286 {
1287 cerr << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected>=" << sizeof(EVENT) << endl;
1288 return;
1289 }
1290
1291 if (d.size()!=sizeof(EVENT)+dat.Roi*4*1440+dat.Roi*4*160)
1292 {
1293 cerr << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected=" << dat.Roi*4*1440+sizeof(EVENT) << " [roi=" << dat.Roi << "]" << endl;
1294 return;
1295 }
1296
1297 delete [] reinterpret_cast<char*>(fEventData);
1298 fEventData = reinterpret_cast<EVENT*>(new char[d.size()]);
1299 memcpy(fEventData, d.ptr<void>(), d.size());
1300
1301 DisplayEventData();
1302 }
1303
1304 void handleFadEventData(const DimData &d)
1305 {
1306 if (!CheckSize(d, 4*1440*sizeof(float)))
1307 return;
1308
1309 if (fEventsStop->isChecked())
1310 return;
1311
1312 const float *ptr = d.ptr<float>();
1313
1314 valarray<double> arr1(1440);
1315 valarray<double> arr2(1440);
1316 valarray<double> arr3(1440);
1317 valarray<double> arr4(1440);
1318
1319 for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
1320 {
1321 arr1[it->index] = ptr[0*1440+it->hw()];
1322 arr2[it->index] = ptr[1*1440+it->hw()];
1323 arr3[it->index] = ptr[2*1440+it->hw()];
1324 arr4[it->index] = ptr[3*1440+it->hw()];
1325 }
1326
1327 fEventCanv1->SetData(arr1);
1328 fEventCanv2->SetData(arr2);
1329 fEventCanv3->SetData(arr3);
1330 fEventCanv4->SetData(arr4);
1331
1332 fEventCanv1->updateCamera();
1333 fEventCanv2->updateCamera();
1334 fEventCanv3->updateCamera();
1335 fEventCanv4->updateCamera();
1336 }
1337
1338 vector<float> fDrsCalibration;
1339
1340 void handleFadDrsCalibration(const DimData &d)
1341 {
1342 const size_t sz = 1024*1440*6+1024*160*2;
1343
1344 if (d.size()==0)
1345 {
1346 fDrsCalibBaseline->setValue(-1);
1347 fDrsCalibGain->setValue(-1);
1348 fDrsCalibTrgOffset->setValue(-1);
1349 fDrsCalibROI->setValue(-1);
1350
1351 fDrsCalibBaseline2->setValue(-1);
1352 fDrsCalibGain2->setValue(-1);
1353 fDrsCalibTrgOffset2->setValue(-1);
1354 fDrsCalibROI2->setValue(-1);
1355
1356 fDrsCalibration.assign(sz, 0);
1357 DisplayEventData();
1358 return;
1359 }
1360
1361 if (!CheckSize(d, sz*sizeof(float)+4*sizeof(uint32_t)))
1362 // Do WHAT?
1363 return;
1364
1365 const uint32_t *run = d.ptr<uint32_t>();
1366
1367 fDrsCalibROI->setValue(run[0]);
1368 fDrsCalibBaseline->setValue(run[1]);
1369 fDrsCalibGain->setValue(run[2]);
1370 fDrsCalibTrgOffset->setValue(run[3]);
1371
1372 fDrsCalibROI2->setValue(run[0]);
1373 fDrsCalibBaseline2->setValue(run[1]);
1374 fDrsCalibGain2->setValue(run[2]);
1375 fDrsCalibTrgOffset2->setValue(run[3]);
1376
1377 const float *dat = d.ptr<float>(sizeof(uint32_t)*4);
1378 fDrsCalibration.assign(dat, dat+sz);
1379
1380 DisplayEventData();
1381 }
1382
1383// vector<uint8_t> fFadConnections;
1384
1385 void handleFadConnections(const DimData &d)
1386 {
1387 if (!CheckSize(d, 41))
1388 {
1389 fStatusEventBuilderLabel->setText("Offline");
1390 fStatusEventBuilderLabel->setToolTip("FADs or fadctrl seems to be offline.");
1391 fGroupEthernet->setEnabled(false);
1392 fGroupOutput->setEnabled(false);
1393
1394 SetLedColor(fStatusEventBuilderLed, kLedGray, d.time);
1395 return;
1396 }
1397
1398 const uint8_t *ptr = d.ptr<uint8_t>();
1399
1400 for (int i=0; i<40; i++)
1401 {
1402 const uint8_t stat1 = ptr[i]&3;
1403 const uint8_t stat2 = ptr[i]>>3;
1404
1405 if (stat1==0 && stat2==0)
1406 {
1407 SetLedColor(fFadLED[i], kLedGray, d.time);
1408 continue;
1409 }
1410 if (stat1>=2 && stat2==8)
1411 {
1412 SetLedColor(fFadLED[i], stat1==2?kLedGreen:kLedGreenCheck, d.time);
1413 continue;
1414 }
1415
1416 if (stat1==1 && stat2==1)
1417 SetLedColor(fFadLED[i], kLedRed, d.time);
1418 else
1419 SetLedColor(fFadLED[i], kLedOrange, d.time);
1420 }
1421
1422
1423 const bool runs = ptr[40]!=0;
1424
1425 fStatusEventBuilderLabel->setText(runs?"Running":"Not running");
1426 fStatusEventBuilderLabel->setToolTip(runs?"Event builder thread running.":"Event builder thread stopped.");
1427
1428 fGroupEthernet->setEnabled(runs);
1429 fGroupOutput->setEnabled(runs);
1430
1431 SetLedColor(fStatusEventBuilderLed, runs?kLedGreen:kLedRed, d.time);
1432
1433// fFadConnections.assign(ptr, ptr+40);
1434 }
1435
1436 template<typename T>
1437 void handleFadToolTip(const Time &time, QWidget *w, T *ptr)
1438 {
1439 ostringstream tip;
1440 tip << "<table border='1'><tr><th colspan='11'>" << time.GetAsStr() << " (UTC)</th></tr><tr><th></th>";
1441 for (int b=0; b<10; b++)
1442 tip << "<th>" << b << "</th>";
1443 tip << "</tr>";
1444
1445 for (int c=0; c<4; c++)
1446 {
1447 tip << "<tr><th>" << c << "</th>";
1448 for (int b=0; b<10; b++)
1449 tip << "<td>" << ptr[c*10+b] << "</td>";
1450 tip << "</tr>";
1451 }
1452 tip << "</table>";
1453
1454 w->setToolTip(tip.str().c_str());
1455 }
1456
1457 template<typename T, class S>
1458 void handleFadMinMax(const DimData &d, QPushButton *led, S *wmin, S *wmax=0)
1459 {
1460 if (!CheckSize(d, 42*sizeof(T)))
1461 return;
1462
1463 const T *ptr = d.ptr<T>();
1464 const T min = ptr[40];
1465 const T max = ptr[41];
1466
1467 if (max==0 && min>max)
1468 SetLedColor(led, kLedGray, d.time);
1469 else
1470 SetLedColor(led, min==max?kLedGreen: kLedOrange, d.time);
1471
1472 if (!wmax && max!=min)
1473 wmin->setValue(0);
1474 else
1475 wmin->setValue(min);
1476
1477 if (wmax)
1478 wmax->setValue(max);
1479
1480 handleFadToolTip(d.time, led, ptr);
1481 }
1482
1483 void handleFadFwVersion(const DimData &d)
1484 {
1485 handleFadMinMax<float, QDoubleSpinBox>(d, fFadLedFwVersion, fFadFwVersion);
1486 }
1487
1488 void handleFadRunNumber(const DimData &d)
1489 {
1490 handleFadMinMax<uint32_t, QSpinBox>(d, fFadLedRunNumber, fFadRunNumber);
1491 }
1492
1493 void handleFadPrescaler(const DimData &d)
1494 {
1495 handleFadMinMax<uint16_t, QSpinBox>(d, fFadLedPrescaler, fFadPrescaler);
1496 }
1497
1498 void handleFadDNA(const DimData &d)
1499 {
1500 if (!CheckSize(d, 40*sizeof(uint64_t)))
1501 return;
1502
1503 const uint64_t *ptr = d.ptr<uint64_t>();
1504
1505 ostringstream tip;
1506 tip << "<table width='100%'>";
1507 tip << "<tr><th>Crate</th><td></td><th>Board</th><td></td><th>DNA</th></tr>";
1508
1509 for (int i=0; i<40; i++)
1510 {
1511 tip << dec;
1512 tip << "<tr>";
1513 tip << "<td align='center'>" << i/10 << "</td><td>:</td>";
1514 tip << "<td align='center'>" << i%10 << "</td><td>:</td>";
1515 tip << hex;
1516 tip << "<td>0x" << setfill('0') << setw(16) << ptr[i] << "</td>";
1517 tip << "</tr>";
1518 }
1519 tip << "</table>";
1520
1521 fFadDNA->setText(tip.str().c_str());
1522 }
1523
1524 void SetFadLed(QPushButton *led, const DimData &d, uint16_t bitmask, bool invert=false)
1525 {
1526 if (d.size()==0)
1527 {
1528 SetLedColor(led, kLedGray, d.time);
1529 return;
1530 }
1531
1532 const bool quality = d.ptr<uint16_t>()[0]&bitmask;
1533 const bool value = d.ptr<uint16_t>()[1]&bitmask;
1534 const uint16_t *ptr = d.ptr<uint16_t>()+2;
1535
1536 SetLedColor(led, quality?kLedOrange:(value^invert?kLedGreen:kLedGreenBar), d.time);
1537
1538 ostringstream tip;
1539 tip << "<table border='1'><tr><th colspan='11'>" << d.time.GetAsStr() << " (UTC)</th></tr><tr><th></th>";
1540 for (int b=0; b<10; b++)
1541 tip << "<th>" << b << "</th>";
1542 tip << "</tr>";
1543
1544 /*
1545 tip << "<tr>" << hex;
1546 tip << "<th>" << d.ptr<uint16_t>()[0] << " " << (d.ptr<uint16_t>()[0]&bitmask) << "</th>";
1547 tip << "<th>" << d.ptr<uint16_t>()[1] << " " << (d.ptr<uint16_t>()[1]&bitmask) << "</th>";
1548 tip << "</tr>";
1549 */
1550
1551 for (int c=0; c<4; c++)
1552 {
1553 tip << "<tr><th>" << dec << c << "</th>" << hex;
1554 for (int b=0; b<10; b++)
1555 {
1556 tip << "<td>"
1557 << (ptr[c*10+b]&bitmask)
1558 << "</td>";
1559 }
1560 tip << "</tr>";
1561 }
1562 tip << "</table>";
1563
1564 led->setToolTip(tip.str().c_str());
1565 }
1566
1567 void handleFadStatus(const DimData &d)
1568 {
1569 if (d.size()!=0 && !CheckSize(d, 42*sizeof(uint16_t)))
1570 return;
1571
1572 SetFadLed(fFadLedDrsEnabled, d, FAD::EventHeader::kDenable);
1573 SetFadLed(fFadLedDrsWrite, d, FAD::EventHeader::kDwrite);
1574 SetFadLed(fFadLedDcmLocked, d, FAD::EventHeader::kDcmLocked);
1575 SetFadLed(fFadLedDcmReady, d, FAD::EventHeader::kDcmReady);
1576 SetFadLed(fFadLedSpiSclk, d, FAD::EventHeader::kSpiSclk);
1577 SetFadLed(fFadLedRefClockTooLow, d, FAD::EventHeader::kRefClkTooLow, true);
1578 SetFadLed(fFadLedBusyOn, d, FAD::EventHeader::kBusyOn);
1579 SetFadLed(fFadLedBusyOff, d, FAD::EventHeader::kBusyOff);
1580 SetFadLed(fFadLedTriggerLine, d, FAD::EventHeader::kTriggerLine);
1581 SetFadLed(fFadLedContTrigger, d, FAD::EventHeader::kContTrigger);
1582 SetFadLed(fFadLedSocket, d, FAD::EventHeader::kSock17);
1583 SetFadLed(fFadLedPllLock, d, 0xf000);
1584 }
1585
1586 void handleFadStatistics1(const DimData &d)
1587 {
1588 if (!CheckSize(d, sizeof(GUI_STAT)))
1589 return;
1590
1591 const GUI_STAT &stat = d.ref<GUI_STAT>();
1592
1593 fFadBufferMax->setValue(stat.totMem/1000000); // Memory::allocated
1594 fFadBuffer->setMaximum(stat.maxMem/100); // g_maxMem
1595 fFadBuffer->setValue(stat.usdMem/100); // Memory::inuse
1596
1597 uint32_t sum = 0;
1598 int cnt = 0;
1599
1600 for (int i=0; i<40; i++)
1601 {
1602 if (stat.numConn[i]==1)
1603 {
1604 sum += stat.rateBytes[i];
1605 cnt++;
1606 }
1607 }
1608
1609 fFadEvtConn->setValue(cnt);
1610
1611 fFadEvtBufNew->setValue(stat.bufNew); // Incomplete in buffer (evtCtrl)
1612 fFadEvtBufEvt->setValue(stat.bufTot); // Complete events in buffer (max_inuse)
1613
1614 fFadEvtCheck->setValue(stat.bufEvt); // Complete in buffer
1615 fFadEvtWrite->setValue(stat.bufWrite);
1616 fFadEvtProc->setValue(stat.bufProc);
1617
1618 if (stat.deltaT==0)
1619 return;
1620
1621 //fFadEthernetRateMin->setValue(min/stat.deltaT);
1622 //fFadEthernetRateMax->setValue(max/stat.deltaT);
1623 fFadEthernetRateTot->setValue(sum/stat.deltaT);
1624 fFadEthernetRateAvg->setValue(cnt==0 ? 0 : sum/cnt/stat.deltaT);
1625
1626 fFadTransmission->setValue(1000*stat.rateNew/stat.deltaT);
1627 fFadWriteRate->setValue(1000*stat.rateWrite/stat.deltaT);
1628 }
1629
1630 /*
1631 void handleFadStatistics2(const DimData &d)
1632 {
1633 if (!CheckSize(d, sizeof(EVT_STAT)))
1634 return;
1635
1636 //const EVT_STAT &stat = d.ref<EVT_STAT>();
1637 }*/
1638
1639 void handleFadFileFormat(const DimData &d)
1640 {
1641 if (!CheckSize(d, sizeof(uint16_t)))
1642 return;
1643
1644 const uint16_t &fmt = d.get<uint16_t>();
1645
1646 SetLedColor(fFadLedFileFormatNone, fmt==FAD::kNone ?kLedGreen:kLedGray, d.time);
1647 SetLedColor(fFadLedFileFormatDebug, fmt==FAD::kDebug?kLedGreen:kLedGray, d.time);
1648 SetLedColor(fFadLedFileFormatRaw, fmt==FAD::kRaw ?kLedGreen:kLedGray, d.time);
1649 SetLedColor(fFadLedFileFormatFits, fmt==FAD::kFits ?kLedGreen:kLedGray, d.time);
1650 SetLedColor(fFadLedFileFormatCalib, fmt==FAD::kCalib?kLedGreen:kLedGray, d.time);
1651 }
1652
1653 // ===================== FTM ============================================
1654
1655 FTM::DimTriggerRates fTriggerRates;
1656
1657 void UpdateTriggerRate(const FTM::DimTriggerRates &sdata)
1658 {
1659#ifdef HAVE_ROOT
1660 TCanvas *c = fFtmRateCanv->GetCanvas();
1661
1662 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1663
1664 if (sdata.fTimeStamp<=fTriggerRates.fTimeStamp)
1665 {
1666 fGraphFtmRate.Set(0);
1667
1668 const double tm = Time().RootTime();
1669
1670 h->SetBins(1, tm, tm+60);
1671 h->GetXaxis()->SetTimeFormat("%M'%S\"%F1995-01-01 00:00:00 GMT");
1672 h->GetXaxis()->SetTitle("Time");
1673
1674 c->Modified();
1675 c->Update();
1676 return;
1677 }
1678
1679 const double t1 = h->GetXaxis()->GetXmax();
1680 const double t0 = h->GetXaxis()->GetXmin();
1681
1682 const double now = t0+sdata.fTimeStamp/1000000.;
1683
1684 h->SetBins(h->GetNbinsX()+1, t0, now+1);
1685 fGraphFtmRate.SetPoint(fGraphFtmRate.GetN(), now, sdata.fTriggerRate);
1686
1687 if (t1-t0>300)
1688 {
1689 h->GetXaxis()->SetTimeFormat("%Hh%M'%F1995-01-01 00:00:00 GMT");
1690 h->GetXaxis()->SetTitle("Time");
1691 }
1692
1693 h->SetMinimum(0);
1694
1695 c->Modified();
1696 c->Update();
1697#endif
1698 }
1699
1700 void UpdateRatesCam(const FTM::DimTriggerRates &sdata)
1701 {
1702 if (fThresholdIdx->value()>=0)
1703 {
1704 const int isw = fThresholdIdx->value();
1705 const int ihw = fPatchMapHW[isw];
1706 fPatchRate->setValue(sdata.fPatchRate[ihw]);
1707 fBoardRate->setValue(sdata.fBoardRate[ihw/4]);
1708 }
1709
1710 const bool b = fBoardRatesEnabled->isChecked();
1711
1712 valarray<double> dat(0., 1440);
1713
1714 // fPatch converts from software id to software patch id
1715 for (int i=0; i<1440; i++)
1716 {
1717 const int ihw = fPixelMap.index(i).hw()/9;
1718 dat[i] = b ? sdata.fBoardRate[ihw/4] : sdata.fPatchRate[ihw];
1719 }
1720
1721 fRatesCanv->SetData(dat);
1722 fRatesCanv->updateCamera();
1723 }
1724
1725 int64_t fTimeStamp0;
1726
1727 void on_fBoardRatesEnabled_toggled(bool)
1728 {
1729 UpdateRatesCam(fTriggerRates);
1730 }
1731
1732 void UpdateRatesGraphs(const FTM::DimTriggerRates &sdata)
1733 {
1734#ifdef HAVE_ROOT
1735 if (fTimeStamp0<0)
1736 {
1737 fTimeStamp0 = sdata.fTimeStamp;
1738 return;
1739 }
1740
1741 TCanvas *c = fFtmRateCanv->GetCanvas();
1742
1743 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1744
1745 const double tdiff = sdata.fTimeStamp-fTimeStamp0;
1746 fTimeStamp0 = sdata.fTimeStamp;
1747
1748 if (tdiff<0)
1749 {
1750 for (int i=0; i<160; i++)
1751 fGraphPatchRate[i].Set(0);
1752 for (int i=0; i<40; i++)
1753 fGraphBoardRate[i].Set(0);
1754
1755 return;
1756 }
1757
1758 //const double t1 = h->GetXaxis()->GetXmax();
1759 const double t0 = h->GetXaxis()->GetXmin();
1760
1761 for (int i=0; i<160; i++)
1762 if (fFtuStatus[i/4]>0)
1763 fGraphPatchRate[i].SetPoint(fGraphPatchRate[i].GetN(),
1764 t0+sdata.fTimeStamp/1000000., sdata.fPatchRate[i]);
1765 for (int i=0; i<40; i++)
1766 if (fFtuStatus[i]>0)
1767 fGraphBoardRate[i].SetPoint(fGraphBoardRate[i].GetN(),
1768 t0+sdata.fTimeStamp/1000000., sdata.fBoardRate[i]);
1769
1770 c->Modified();
1771 c->Update();
1772#endif
1773 }
1774
1775 void handleFtmTriggerRates(const DimData &d)
1776 {
1777 if (!CheckSize(d, sizeof(FTM::DimTriggerRates)))
1778 return;
1779
1780 const FTM::DimTriggerRates &sdata = d.ref<FTM::DimTriggerRates>();
1781
1782 fFtmTime->setText(QString::number(sdata.fTimeStamp/1000000., 'f', 6)+ " s");
1783 fTriggerCounter->setText(QString::number(sdata.fTriggerCounter));
1784
1785 if (sdata.fTimeStamp>0)
1786 fTriggerCounterRate->setValue(1000000.*sdata.fTriggerCounter/sdata.fTimeStamp);
1787 else
1788 fTriggerCounterRate->setValue(0);
1789
1790 // ----------------------------------------------
1791
1792 fOnTime->setText(QString::number(sdata.fOnTimeCounter/1000000., 'f', 6)+" s");
1793
1794 if (sdata.fTimeStamp>0)
1795 fOnTimeRel->setValue(100.*sdata.fOnTimeCounter/sdata.fTimeStamp);
1796 else
1797 fOnTimeRel->setValue(0);
1798
1799 // ----------------------------------------------
1800
1801 UpdateTriggerRate(sdata);
1802 UpdateRatesGraphs(sdata);
1803 UpdateRatesCam(sdata);
1804
1805 fTriggerRates = sdata;
1806 }
1807
1808 void handleFtmCounter(const DimData &d)
1809 {
1810 if (!CheckSize(d, sizeof(uint32_t)*6))
1811 return;
1812
1813 const uint32_t *sdata = d.ptr<uint32_t>();
1814
1815 fFtmCounterH->setValue(sdata[0]);
1816 fFtmCounterS->setValue(sdata[1]);
1817 fFtmCounterD->setValue(sdata[2]);
1818 fFtmCounterF->setValue(sdata[3]);
1819 fFtmCounterE->setValue(sdata[4]);
1820 fFtmCounterR->setValue(sdata[5]);
1821 }
1822
1823 void handleFtmDynamicData(const DimData &d)
1824 {
1825 if (!CheckSize(d, sizeof(FTM::DimDynamicData)))
1826 return;
1827
1828 const FTM::DimDynamicData &sdata = d.ref<FTM::DimDynamicData>();
1829
1830 fFtmTemp0->setValue(sdata.fTempSensor[0]*0.1);
1831 fFtmTemp1->setValue(sdata.fTempSensor[1]*0.1);
1832 fFtmTemp2->setValue(sdata.fTempSensor[2]*0.1);
1833 fFtmTemp3->setValue(sdata.fTempSensor[3]*0.1);
1834
1835 SetLedColor(fClockCondLed, sdata.fState&FTM::kFtmLocked ? kLedGreen : kLedRed, d.time);
1836 }
1837
1838 void DisplayRates()
1839 {
1840#ifdef HAVE_ROOT
1841 TCanvas *c = fFtmRateCanv->GetCanvas();
1842
1843 TList * l = c->GetListOfPrimitives();
1844
1845
1846 while (c->FindObject("PatchRate"))
1847 l->Remove(c->FindObject("PatchRate"));
1848
1849 while (c->FindObject("BoardRate"))
1850 l->Remove(c->FindObject("BoardRate"));
1851
1852 if (fRatePatch1->value()>=0)
1853 {
1854 fGraphPatchRate[fRatePatch1->value()].SetLineColor(kRed);
1855 fGraphPatchRate[fRatePatch1->value()].SetMarkerColor(kRed);
1856 l->Add(&fGraphPatchRate[fRatePatch1->value()], "PL");
1857 }
1858 if (fRatePatch2->value()>=0)
1859 {
1860 fGraphPatchRate[fRatePatch2->value()].SetLineColor(kGreen);
1861 fGraphPatchRate[fRatePatch2->value()].SetMarkerColor(kGreen);
1862 l->Add(&fGraphPatchRate[fRatePatch2->value()], "PL");
1863 }
1864 if (fRateBoard1->value()>=0)
1865 {
1866 fGraphBoardRate[fRateBoard1->value()].SetLineColor(kMagenta);
1867 fGraphBoardRate[fRateBoard1->value()].SetMarkerColor(kMagenta);
1868 l->Add(&fGraphBoardRate[fRateBoard1->value()], "PL");
1869 }
1870 if (fRateBoard2->value()>=0)
1871 {
1872 fGraphBoardRate[fRateBoard2->value()].SetLineColor(kCyan);
1873 fGraphBoardRate[fRateBoard2->value()].SetMarkerColor(kCyan);
1874 l->Add(&fGraphBoardRate[fRateBoard2->value()], "PL");
1875 }
1876
1877 c->Modified();
1878 c->Update();
1879#endif
1880 }
1881
1882 FTM::DimStaticData fFtmStaticData;
1883
1884 void SetFtuLed(int idx, int counter, const Time &t)
1885 {
1886 if (counter==0 || counter>3)
1887 counter = 3;
1888
1889 if (counter<0)
1890 counter = 0;
1891
1892 const LedColor_t col[4] = { kLedGray, kLedGreen, kLedOrange, kLedRed };
1893
1894 SetLedColor(fFtuLED[idx], col[counter], t);
1895
1896 fFtuStatus[idx] = counter;
1897 }
1898
1899 void SetFtuStatusLed(const Time &t)
1900 {
1901 const int max = fFtuStatus.max();
1902
1903 switch (max)
1904 {
1905 case 0:
1906 SetLedColor(fStatusFTULed, kLedGray, t);
1907 fStatusFTULabel->setText("All disabled");
1908 fStatusFTULabel->setToolTip("All FTUs are disabled");
1909 break;
1910
1911 case 1:
1912 SetLedColor(fStatusFTULed, kLedGreen, t);
1913 fStatusFTULabel->setToolTip("Communication with FTU is smooth.");
1914 fStatusFTULabel->setText("ok");
1915 break;
1916
1917 case 2:
1918 SetLedColor(fStatusFTULed, kLedOrange, t);
1919 fStatusFTULabel->setText("Warning");
1920 fStatusFTULabel->setToolTip("At least one FTU didn't answer immediately");
1921 break;
1922
1923 case 3:
1924 SetLedColor(fStatusFTULed, kLedRed, t);
1925 fStatusFTULabel->setToolTip("At least one FTU didn't answer!");
1926 fStatusFTULabel->setText("ERROR");
1927 break;
1928 }
1929
1930 const int cnt = count(&fFtuStatus[0], &fFtuStatus[40], 0);
1931 fFtuAllOn->setEnabled(cnt!=0);
1932 fFtuAllOff->setEnabled(cnt!=40);
1933 }
1934
1935 void handleFtmStaticData(const DimData &d)
1936 {
1937 if (!CheckSize(d, sizeof(FTM::DimStaticData)))
1938 return;
1939
1940 const FTM::DimStaticData &sdata = d.ref<FTM::DimStaticData>();
1941
1942 fTriggerInterval->setValue(sdata.fTriggerInterval);
1943 fPhysicsCoincidence->setValue(sdata.fMultiplicityPhysics);
1944 fCalibCoincidence->setValue(sdata.fMultiplicityCalib);
1945 fPhysicsWindow->setValue(sdata.fWindowPhysics);
1946 fCalibWindow->setValue(sdata.fWindowCalib);
1947
1948 fTriggerDelay->setValue(sdata.fDelayTrigger);
1949 fTimeMarkerDelay->setValue(sdata.fDelayTimeMarker);
1950 fDeadTime->setValue(sdata.fDeadTime);
1951
1952 fClockCondR0->setValue(sdata.fClockConditioner[0]);
1953 fClockCondR1->setValue(sdata.fClockConditioner[1]);
1954 fClockCondR8->setValue(sdata.fClockConditioner[2]);
1955 fClockCondR9->setValue(sdata.fClockConditioner[3]);
1956 fClockCondR11->setValue(sdata.fClockConditioner[4]);
1957 fClockCondR13->setValue(sdata.fClockConditioner[5]);
1958 fClockCondR14->setValue(sdata.fClockConditioner[6]);
1959 fClockCondR15->setValue(sdata.fClockConditioner[7]);
1960
1961 const uint32_t R0 = sdata.fClockConditioner[0];
1962 const uint32_t R14 = sdata.fClockConditioner[6];
1963 const uint32_t R15 = sdata.fClockConditioner[7];
1964
1965 const uint32_t Ndiv = (R15&0x1ffff00)<<2;
1966 const uint32_t Rdiv = (R14&0x007ff00)>>8;
1967 const uint32_t Cdiv = (R0 &0x000ff00)>>8;
1968
1969 double freq = 40.*Ndiv/(Rdiv*Cdiv);
1970
1971 fClockCondFreqRes->setValue(freq);
1972
1973 //fClockCondFreq->setEditText("");
1974 fClockCondFreq->setCurrentIndex(0);
1975
1976 fTriggerSeqPed->setValue(sdata.fTriggerSeqPed);
1977 fTriggerSeqLPint->setValue(sdata.fTriggerSeqLPint);
1978 fTriggerSeqLPext->setValue(sdata.fTriggerSeqLPext);
1979
1980 fLpIntIntensity->setValue(sdata.fIntensityLPint);
1981 fLpExtIntensity->setValue(sdata.fIntensityLPext);
1982
1983 fLpIntGroup1->setChecked(sdata.HasLPintG1());
1984 fLpIntGroup2->setChecked(sdata.HasLPintG2());
1985 fLpExtGroup1->setChecked(sdata.HasLPextG1());
1986 fLpExtGroup2->setChecked(sdata.HasLPextG2());
1987
1988 fEnableTrigger->setChecked(sdata.HasTrigger());
1989 fEnableVeto->setChecked(sdata.HasVeto());
1990 fEnableExt1->setChecked(sdata.HasExt1());
1991 fEnableExt2->setChecked(sdata.HasExt2());
1992 fEnableClockCond->setChecked(sdata.HasClockConditioner());
1993
1994 uint16_t multiplicity = sdata.fMultiplicity[0];
1995
1996 for (int i=0; i<40; i++)
1997 {
1998 if (!sdata.IsActive(i))
1999 SetFtuLed(i, -1, d.time);
2000 else
2001 {
2002 if (fFtuStatus[i]==0)
2003 SetFtuLed(i, 1, d.time);
2004 }
2005 fFtuLED[i]->setChecked(false);
2006
2007 if (sdata.fMultiplicity[i]!=multiplicity)
2008 multiplicity = -1;
2009
2010 }
2011 SetFtuStatusLed(d.time);
2012
2013 fNoutof4Val->setValue(multiplicity);
2014
2015 for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
2016 fRatesCanv->SetEnable(it->index, sdata.IsEnabled(it->hw()));
2017
2018 const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
2019 fPixelEnable->setChecked(sdata.IsEnabled(entry.hw()));
2020
2021 if (fThresholdIdx->value()>=0)
2022 {
2023 const int isw = fThresholdIdx->value();
2024 const int ihw = fPatchMapHW[isw];
2025 fThresholdVal->setValue(sdata.fThreshold[ihw]);
2026 }
2027
2028 fPrescalingVal->setValue(sdata.fPrescaling[0]);
2029
2030 fFtmStaticData = sdata;
2031 }
2032
2033 void handleFtmPassport(const DimData &d)
2034 {
2035 if (!CheckSize(d, sizeof(FTM::DimPassport)))
2036 return;
2037
2038 const FTM::DimPassport &sdata = d.ref<FTM::DimPassport>();
2039
2040 stringstream str1, str2;
2041 str1 << hex << "0x" << setfill('0') << setw(16) << sdata.fBoardId;
2042 str2 << sdata.fFirmwareId;
2043
2044 fFtmBoardId->setText(str1.str().c_str());
2045 fFtmFirmwareId->setText(str2.str().c_str());
2046 }
2047
2048 void handleFtmFtuList(const DimData &d)
2049 {
2050 if (!CheckSize(d, sizeof(FTM::DimFtuList)))
2051 return;
2052
2053 fFtuPing->setChecked(false);
2054
2055 const FTM::DimFtuList &sdata = d.ref<FTM::DimFtuList>();
2056
2057 stringstream str;
2058 str << "<table width='100%'>" << setfill('0');
2059 str << "<tr><th>Num</th><th></th><th>Addr</th><th></th><th>DNA</th></tr>";
2060 for (int i=0; i<40; i++)
2061 {
2062 str << "<tr>";
2063 str << "<td align='center'>" << dec << i << hex << "</td>";
2064 str << "<td align='center'>:</td>";
2065 str << "<td align='center'>0x" << setw(2) << (int)sdata.fAddr[i] << "</td>";
2066 str << "<td align='center'>:</td>";
2067 str << "<td align='center'>0x" << setw(16) << sdata.fDNA[i] << "</td>";
2068 str << "</tr>";
2069 }
2070 str << "</table>";
2071
2072 fFtuDNA->setText(str.str().c_str());
2073
2074 fFtuAnswersTotal->setValue(sdata.fNumBoards);
2075 fFtuAnswersCrate0->setValue(sdata.fNumBoardsCrate[0]);
2076 fFtuAnswersCrate1->setValue(sdata.fNumBoardsCrate[1]);
2077 fFtuAnswersCrate2->setValue(sdata.fNumBoardsCrate[2]);
2078 fFtuAnswersCrate3->setValue(sdata.fNumBoardsCrate[3]);
2079
2080 for (int i=0; i<40; i++)
2081 SetFtuLed(i, sdata.IsActive(i) ? sdata.fPing[i] : -1, d.time);
2082
2083 SetFtuStatusLed(d.time);
2084 }
2085
2086 void handleFtmError(const DimData &d)
2087 {
2088 if (!CheckSize(d, sizeof(FTM::DimError)))
2089 return;
2090
2091 const FTM::DimError &sdata = d.ref<FTM::DimError>();
2092
2093 SetFtuLed(sdata.fError.fDestAddress, sdata.fError.fNumCalls, d.time);
2094 SetFtuStatusLed(d.time);
2095
2096 // FIXME: Write to special window!
2097 //Out() << "Error:" << endl;
2098 //Out() << sdata.fError << endl;
2099 }
2100
2101 // ========================== FSC =======================================
2102
2103 void SetFscValue(QDoubleSpinBox *box, const DimData &d, int idx, bool enable)
2104 {
2105 //box->setEnabled(enable);
2106 if (!enable)
2107 {
2108 box->setToolTip(d.time.GetAsStr().c_str());
2109 return;
2110 }
2111
2112 ostringstream str;
2113 str << d.time << " -- " << d.get<float>() << "s";
2114
2115 box->setToolTip(str.str().c_str());
2116 box->setValue(d.get<float>(idx*4+4));
2117 }
2118
2119
2120 void handleFscTemp(const DimData &d)
2121 {
2122 const bool enable = d.size()>0 && CheckSize(d, 60*sizeof(float));
2123 if (!enable)
2124 return;
2125
2126 QDoubleSpinBox *boxes[] = {
2127 fTempCam00, fTempCam01,
2128 fTempCam10, fTempCam11, fTempCam12, fTempCam13, fTempCam14,
2129 fTempCam20, fTempCam21, fTempCam22, fTempCam23, fTempCam24, fTempCam25,
2130 fTempCam30, fTempCam31, fTempCam32, fTempCam33, fTempCam34,
2131 fTempCam40, fTempCam41, fTempCam42, fTempCam43, fTempCam44, fTempCam45,
2132 fTempCam50, fTempCam51, fTempCam52, fTempCam53, fTempCam54,
2133 fTempCam60, fTempCam61,
2134 // 0:b/f 1:b/f 2:b/f 3:b/f
2135 fTempCrate0back, fTempCrate0front,
2136 fTempCrate1back, fTempCrate1front,
2137 fTempCrate2back, fTempCrate2front,
2138 fTempCrate3back, fTempCrate3front,
2139 // 0:b/f 1:b/f 2:b/f 3:b/f
2140 fTempPS0back, fTempPS0front,
2141 fTempPS1back, fTempPS1front,
2142 fTempPS2back, fTempPS2front,
2143 fTempPS3back, fTempPS3front,
2144 // AUX PS: FTM t/b; FSC t/b
2145 fTempAuxFTMtop, fTempAuxFTMbottom,
2146 fTempAuxFSCtop, fTempAuxFSCbottom,
2147 // Backpanel: FTM t/b; FSC t/b
2148 fTempBackpanelFTMtop, fTempBackpanelFTMbottom,
2149 fTempBackpanelFSCtop, fTempBackpanelFSCbottom,
2150 // top front/back; bottom front/back
2151 fTempSwitchboxTopFront, fTempSwitchboxTopBack,
2152 fTempSwitchboxBottomFront, fTempSwitchboxBottomBack,
2153 };
2154
2155 for (int i=0; i<59; i++)
2156 SetFscValue(boxes[i], d, i, enable);
2157
2158 if (!enable)
2159 return;
2160
2161 const float *ptr = d.ptr<float>();
2162
2163 double avg = 0;
2164 int num = 0;
2165 for (int i=1; i<32; i++)
2166 if (ptr[i]!=0)
2167 {
2168 avg += ptr[i];
2169 num ++;
2170 }
2171
2172 fTempCamAvg->setValue(num?avg/num:0);
2173 }
2174
2175 void handleFscVolt(const DimData &d)
2176 {
2177 const bool enable = d.size()>0 && CheckSize(d, 31*sizeof(float));
2178 if (!enable)
2179 return;
2180
2181 QDoubleSpinBox *boxes[] = {
2182 fVoltFad00, fVoltFad10, fVoltFad20, fVoltFad30,
2183 fVoltFad01, fVoltFad11, fVoltFad21, fVoltFad31,
2184 fVoltFad02, fVoltFad12, fVoltFad22, fVoltFad32,
2185 fVoltFPA00, fVoltFPA10, fVoltFPA20, fVoltFPA30,
2186 fVoltFPA01, fVoltFPA11, fVoltFPA21, fVoltFPA31,
2187 fVoltFPA02, fVoltFPA12, fVoltFPA22, fVoltFPA32,
2188 fVoltETH0, fVoltETH1,
2189 fVoltFTM0, fVoltFTM1,
2190 fVoltFFC, fVoltFLP,
2191 };
2192
2193 for (int i=0; i<30; i++)
2194 SetFscValue(boxes[i], d, i, enable);
2195 }
2196
2197 void handleFscCurrent(const DimData &d)
2198 {
2199 const bool enable = d.size()>0 && CheckSize(d, 31*sizeof(float));
2200 if (!enable)
2201 return;
2202
2203 QDoubleSpinBox *boxes[] = {
2204 fAmpFad00, fAmpFad10, fAmpFad20, fAmpFad30,
2205 fAmpFad01, fAmpFad11, fAmpFad21, fAmpFad31,
2206 fAmpFad02, fAmpFad12, fAmpFad22, fAmpFad32,
2207 fAmpFPA00, fAmpFPA10, fAmpFPA20, fAmpFPA30,
2208 fAmpFPA01, fAmpFPA11, fAmpFPA21, fAmpFPA31,
2209 fAmpFPA02, fAmpFPA12, fAmpFPA22, fAmpFPA32,
2210 fAmpETH0, fAmpETH1,
2211 fAmpFTM0, fAmpFTM1,
2212 fAmpFFC, fAmpFLP,
2213 };
2214
2215 for (int i=0; i<30; i++)
2216 SetFscValue(boxes[i], d, i, enable);
2217 }
2218
2219 void handleFscHumidity(const DimData &d)
2220 {
2221 const bool enable = d.size()>0 && CheckSize(d, 5*sizeof(float));
2222
2223 SetFscValue(fHumidity1, d, 0, enable);
2224 SetFscValue(fHumidity2, d, 1, enable);
2225 SetFscValue(fHumidity3, d, 2, enable);
2226 SetFscValue(fHumidity4, d, 3, enable);
2227 }
2228
2229 // ========================== Feedback ==================================
2230
2231#ifdef HAVE_ROOT
2232 TGraphErrors fGraphFeedbackDev;
2233 TGraphErrors fGraphFeedbackCmd;
2234
2235 void UpdateFeedback(TQtWidget &rwidget, const Time &time, TGraphErrors &graph, double avg, double rms)
2236 {
2237 TCanvas *c = rwidget.GetCanvas();
2238
2239 TH1 *h = (TH1*)c->FindObject("TimeFrame");
2240
2241 while (graph.GetN()>500)
2242 graph.RemovePoint(0);
2243
2244 const double now = time.RootTime();
2245
2246 while (graph.GetN()>0 && now-graph.GetX()[0]>3600)
2247 graph.RemovePoint(0);
2248
2249 const int n = graph.GetN();
2250
2251 const double xmin = n>0 ? graph.GetX()[0] : now;
2252
2253 h->SetBins(n+1, xmin-1, now+1);
2254 graph.SetPoint(n, now, avg);
2255 graph.SetPointError(n, 0, rms);
2256
2257 h->GetXaxis()->SetTimeFormat(now-xmin>300 ? "%Hh%M'%F1995-01-01 00:00:00 GMT" : "%M'%S\"%F1995-01-01 00:00:00 GMT");
2258
2259 c->Modified();
2260 c->Update();
2261 }
2262#endif
2263
2264 void handleFeedbackDeviation(const DimData &d)
2265 {
2266 if (!CheckSize(d, (2*416+2)*sizeof(float)))
2267 return;
2268
2269 if (d.qos==0)
2270 return;
2271
2272 const float *ptr = d.ptr<float>();
2273
2274 valarray<float> dev(1440);
2275 valarray<float> cmd(1440);
2276
2277 double avgdev = 0;
2278 double avgcmd = 0;
2279
2280 double rmsdev = 0;
2281 double rmscmd = 0;
2282
2283 for (int i=0; i<1440; i++)
2284 {
2285 const PixelMapEntry &entry = fPixelMap.index(i);
2286
2287 dev[i] = /*1000*/ptr[entry.hv()];
2288 cmd[i] = 1000*ptr[entry.hv()+416];
2289
2290 avgdev += dev[i];
2291 avgcmd += cmd[i];
2292
2293 rmsdev += dev[i]*dev[i];
2294 rmscmd += cmd[i]*cmd[i];
2295 }
2296
2297 avgdev /= 1440;
2298 avgcmd /= 1440;
2299
2300 rmsdev = sqrt(rmsdev/1440 - avgdev*avgdev);
2301 rmscmd = sqrt(rmscmd/1440 - avgcmd*avgcmd);
2302
2303 fFeedbackDevCam->SetData(dev);
2304 fFeedbackCmdCam->SetData(cmd);
2305
2306 fFeedbackDevCam->updateCamera();
2307 fFeedbackCmdCam->updateCamera();
2308
2309#ifdef HAVE_ROOT
2310 UpdateFeedback(*fFeedbackDev, d.time, fGraphFeedbackDev, avgdev, rmsdev);
2311 UpdateFeedback(*fFeedbackCmd, d.time, fGraphFeedbackCmd, avgcmd, rmscmd);
2312#endif
2313 }
2314
2315 void handleFeedbackReference(const DimData &d)
2316 {
2317 if (!CheckSize(d, 416*sizeof(float)))
2318 return;
2319
2320 const float *ptr = d.ptr<float>();
2321
2322// fFeedbackRefCam->SetData(valarray<float>(ptr, 416));
2323// fFeedbackRefCam->updateCamera();
2324 }
2325
2326 vector<float> fBiasOffsets;
2327
2328 void handleFeedbackCalibration(const DimData &d)
2329 {
2330 if (!CheckSize(d, 3*416*sizeof(float)))
2331 return;
2332
2333 const float *ptr = d.ptr<float>();
2334 fBiasOffsets.assign(ptr+2*416, ptr+3*416);
2335 }
2336
2337 // ======================= Rate Scan ====================================
2338
2339 TGraph fGraphRateScan[201];
2340
2341 void UpdateRateScan(uint32_t th, const float *rates)
2342 {
2343#ifdef HAVE_ROOT
2344 TCanvas *c = fRateScanCanv->GetCanvas();
2345
2346 TH1 *h = (TH1*)c->FindObject("Frame");
2347
2348 if (fGraphRateScan[0].GetN()==0 || th<fGraphRateScan[0].GetX()[fGraphRateScan[0].GetN()-1])
2349 {
2350 h->SetBins(1, th<10 ? 0 : th-10, th+10);
2351 h->SetMinimum(1);
2352 h->SetMaximum(rates[0]*2);
2353
2354 for (int i=0; i<201; i++)
2355 {
2356 fGraphRateScan[i].Set(0);
2357 fGraphRateScan[i].SetPoint(fGraphRateScan[i].GetN(), th, rates[i]);
2358 }
2359
2360 c->SetGrid();
2361 c->SetLogy();
2362
2363 c->Modified();
2364 c->Update();
2365 return;
2366 }
2367
2368 const double dac = h->GetXaxis()->GetXmin();
2369 h->SetBins(h->GetNbinsX()+1, dac, th+10);
2370
2371 for (int i=0; i<201; i++)
2372 fGraphRateScan[i].SetPoint(fGraphRateScan[i].GetN(), th, rates[i]);
2373
2374 c->Modified();
2375 c->Update();
2376#endif
2377 }
2378
2379 void DisplayRateScan()
2380 {
2381#ifdef HAVE_ROOT
2382 TCanvas *c = fRateScanCanv->GetCanvas();
2383
2384 TList *l = c->GetListOfPrimitives();
2385
2386 while (c->FindObject("PatchRate"))
2387 l->Remove(c->FindObject("PatchRate"));
2388
2389 while (c->FindObject("BoardRate"))
2390 l->Remove(c->FindObject("BoardRate"));
2391
2392 if (fRateScanPatch1->value()>=0)
2393 {
2394 fGraphRateScan[fRateScanPatch1->value()+41].SetLineColor(kRed);
2395 fGraphRateScan[fRateScanPatch1->value()+41].SetMarkerColor(kRed);
2396 l->Add(&fGraphRateScan[fRateScanPatch1->value()+41], "PL");
2397 }
2398 if (fRateScanPatch2->value()>=0)
2399 {
2400 fGraphRateScan[fRateScanPatch2->value()+41].SetLineColor(kGreen);
2401 fGraphRateScan[fRateScanPatch2->value()+41].SetMarkerColor(kGreen);
2402 l->Add(&fGraphRateScan[fRateScanPatch2->value()+41], "PL");
2403 }
2404 if (fRateScanBoard1->value()>=0)
2405 {
2406 fGraphRateScan[fRateScanBoard1->value()+1].SetLineColor(kMagenta);
2407 fGraphRateScan[fRateScanBoard1->value()+1].SetMarkerColor(kMagenta);
2408 l->Add(&fGraphRateScan[fRateScanBoard1->value()+1], "PL");
2409 }
2410 if (fRateScanBoard2->value()>=0)
2411 {
2412 fGraphRateScan[fRateScanBoard2->value()+1].SetLineColor(kCyan);
2413 fGraphRateScan[fRateScanBoard2->value()+1].SetMarkerColor(kCyan);
2414 l->Add(&fGraphRateScan[fRateScanBoard2->value()+1], "PL");
2415 }
2416
2417 c->Modified();
2418 c->Update();
2419#endif
2420 }
2421
2422 void handleRateScan(const DimData &d)
2423 {
2424 if (!CheckSize(d, 206*sizeof(float)))
2425 return;
2426
2427 UpdateRateScan(d.get<uint32_t>(8), d.ptr<float>(20));
2428 }
2429
2430 // ===================== MAGIC Weather ==================================
2431
2432 void handleMagicWeather(const DimData &d)
2433 {
2434 if (!CheckSize(d, 7*sizeof(float)+sizeof(uint16_t)))
2435 return;
2436
2437 const float *ptr = d.ptr<float>(2);
2438
2439 fMagicTemp->setValue(ptr[0]);
2440 fMagicDew->setValue(ptr[1]);
2441 fMagicHum->setValue(ptr[2]);
2442 fMagicPressure->setValue(ptr[3]);
2443 fMagicWind->setValue(ptr[4]);
2444 fMagicGusts->setValue(ptr[5]);
2445
2446 static const char *dir[] =
2447 {
2448 "N", "NNE", "NE", "ENE",
2449 "E", "ESE", "SE", "SSE",
2450 "S", "SSW", "SW", "WSW",
2451 "W", "WNW", "NW", "NNW"
2452 };
2453
2454 const uint16_t i = uint16_t(floor(fmod(ptr[6]+11.25, 360)/22.5));
2455 fMagicWindDir->setText(dir[i%16]);
2456 }
2457
2458 // ========================== FSC =======================================
2459
2460 vector<float> fVecBiasVolt;
2461 vector<int16_t> fVecBiasDac;
2462 vector<int16_t> fVecBiasCurrent;
2463 vector<float> fVecBiasCalibOffset;
2464
2465 void handleBiasNominal(const DimData &d)
2466 {
2467 if (!CheckSize(d, 3*416*sizeof(float)))
2468 return;
2469
2470 const float *ptr = d.ptr<float>();
2471
2472 fVecBiasCalibOffset.assign(ptr+2*416, ptr+3*416);
2473
2474 on_fBiasDispRefVolt_stateChanged();
2475 UpdateBiasValues();
2476 }
2477
2478 void handleBiasVolt(const DimData &d)
2479 {
2480 if (!CheckSize(d, 416*sizeof(float)))
2481 return;
2482
2483 const float *ptr = d.ptr<float>();
2484 fVecBiasVolt.assign(ptr, ptr+416);
2485 }
2486
2487 void handleBiasDac(const DimData &d)
2488 {
2489 if (!CheckSize(d, 2*416*sizeof(int16_t)))
2490 return;
2491
2492 const int16_t *ptr = d.ptr<int16_t>();
2493 fVecBiasDac.assign(ptr, ptr+2*416);
2494
2495 on_fBiasDispRefVolt_stateChanged();
2496 UpdateBiasValues();
2497 }
2498
2499 void handleBiasCurrent(const DimData &d)
2500 {
2501 if (!CheckSize(d, 416*sizeof(int16_t)))
2502 return;
2503
2504 const int16_t *ptr = d.ptr<int16_t>();
2505
2506 fVecBiasCurrent.assign(ptr, ptr+416);
2507
2508 valarray<double> dat(0., 1440);
2509
2510 // fPatch converts from software id to software patch id
2511 for (int i=0; i<1440; i++)
2512 {
2513 const PixelMapEntry &entry = fPixelMap.index(i);
2514
2515 // FIXME: Display Overcurrent
2516 /*
2517 dat[i] = fVecBiasVolt[entry.hv()]*90./4096;
2518 double amp = abs(ptr[entry.hv()]);
2519 if (fBiasOffsets.size()>0)
2520 amp -= fBiasOffsets[entry.hv()];
2521 amp *= 5000./4096;
2522 amp *= 5200 *1e-6;
2523 dat[i] -= amp;
2524 */
2525
2526 dat[i] = abs(ptr[entry.hv()]) * 5000./4096;
2527
2528 if (fBiasOffsets.size()>0 && fVecBiasVolt.size()>0)
2529 dat[i] -= fVecBiasVolt[entry.hv()]/fBiasOffsets[entry.hv()]*1e6;
2530
2531 dat[i] *= 4.5 / (entry.group() ? 5 : 4);
2532
2533 fBiasCamA->SetEnable(i, uint16_t(ptr[entry.hv()])!=0x8000);
2534 fBiasCamA->highlightPixel(i, ptr[entry.hv()]<0);
2535 }
2536
2537 fBiasCamA->SetData(dat);
2538 fBiasCamA->updateCamera();
2539
2540 UpdateBiasValues();
2541 }
2542
2543 // ====================== MessageImp ====================================
2544
2545 bool fChatOnline;
2546
2547 void handleStateChanged(const Time &time, const string &server,
2548 const State &s)
2549 {
2550 // FIXME: Prefix tooltip with time
2551 if (server=="MCP")
2552 {
2553 // FIXME: Enable FTU page!!!
2554 fStatusMCPLabel->setText(s.name.c_str());
2555 fStatusMCPLabel->setToolTip(s.comment.c_str());
2556
2557 if (s.index<MCP::State::kDisconnected) // No Dim connection
2558 SetLedColor(fStatusMCPLed, kLedGray, time);
2559 if (s.index==MCP::State::kDisconnected) // Disconnected
2560 SetLedColor(fStatusMCPLed, kLedRed, time);
2561 if (s.index==MCP::State::kConnecting) // Connecting
2562 SetLedColor(fStatusMCPLed, kLedOrange, time);
2563 if (s.index==MCP::State::kConnected) // Connected
2564 SetLedColor(fStatusMCPLed, kLedYellow, time);
2565 if (s.index==MCP::State::kIdle || s.index>=MCP::State::kConfigured) // Idle, TriggerOn, TakingData
2566 SetLedColor(fStatusMCPLed, kLedGreen, time);
2567
2568 if (s.index>MCP::State::kIdle && s.index<MCP::State::kConfigured)
2569 SetLedColor(fStatusMCPLed, kLedGreenBar, time);
2570
2571 fMcpStartRun->setEnabled(s.index>=MCP::State::kIdle);
2572 fMcpStopRun->setEnabled(s.index>=MCP::State::kIdle);
2573 fMcpReset->setEnabled(s.index>=MCP::State::kIdle && MCP::State::kConfigured);
2574 }
2575
2576 if (server=="FTM_CONTROL")
2577 {
2578 // FIXME: Enable FTU page!!!
2579 fStatusFTMLabel->setText(s.name.c_str());
2580 fStatusFTMLabel->setToolTip(s.comment.c_str());
2581
2582 bool enable = false;
2583 const bool configuring =
2584 s.index==FTM::State::kConfiguring1 ||
2585 s.index==FTM::State::kConfiguring2 ||
2586 s.index==FTM::State::kConfigured;
2587
2588 if (s.index<FTM::State::kDisconnected) // No Dim connection
2589 SetLedColor(fStatusFTMLed, kLedGray, time);
2590 if (s.index==FTM::State::kDisconnected) // Dim connection / FTM disconnected
2591 SetLedColor(fStatusFTMLed, kLedYellow, time);
2592 if (s.index==FTM::State::kConnected ||
2593 s.index==FTM::State::kIdle ||
2594 configuring) // Dim connection / FTM connected
2595 SetLedColor(fStatusFTMLed, kLedGreen, time);
2596 if (s.index==FTM::State::kTriggerOn) // Dim connection / FTM connected
2597 SetLedColor(fStatusFTMLed, kLedGreenCheck, time);
2598 if (s.index==FTM::State::kConnected ||
2599 s.index==FTM::State::kIdle) // Dim connection / FTM connected
2600 enable = true;
2601 if (s.index>=FTM::State::kConfigError1) // Dim connection / FTM connected
2602 SetLedColor(fStatusFTMLed, kLedGreenWarn, time);
2603
2604 fFtmStartRun->setEnabled(!configuring && enable);
2605 fFtmStopRun->setEnabled(!configuring && (enable || s.index==FTM::State::kTriggerOn));
2606
2607 fTriggerWidget->setEnabled(enable);
2608 fFtuGroupEnable->setEnabled(enable);
2609 fRatesControls->setEnabled(enable);
2610 fFtuWidget->setEnabled(s.index>FTM::State::kDisconnected);
2611
2612 if (s.index>=FTM::State::kConnected)
2613 SetFtuStatusLed(time);
2614 else
2615 {
2616 SetLedColor(fStatusFTULed, kLedGray, time);
2617 fStatusFTULabel->setText("Offline");
2618 fStatusFTULabel->setToolTip("FTM is not online.");
2619 }
2620 }
2621
2622 if (server=="FAD_CONTROL")
2623 {
2624 fStatusFADLabel->setText(s.name.c_str());
2625 fStatusFADLabel->setToolTip(s.comment.c_str());
2626
2627 bool enable = false;
2628
2629 if (s.index<FAD::State::kOffline) // No Dim connection
2630 {
2631 SetLedColor(fStatusFADLed, kLedGray, time);
2632
2633 // Timing problem - sometimes they stay gray :(
2634 //for (int i=0; i<40; i++)
2635 // SetLedColor(fFadLED[i], kLedGray, time);
2636
2637 /*
2638 fStatusEventBuilderLabel->setText("Offline");
2639 fStatusEventBuilderLabel->setToolTip("No connection to fadctrl.");
2640 fEvtBldWidget->setEnabled(false);
2641
2642 SetLedColor(fStatusEventBuilderLed, kLedGray, time);
2643 */
2644 }
2645 if (s.index==FAD::State::kOffline) // Dim connection / FTM disconnected
2646 SetLedColor(fStatusFADLed, kLedRed, time);
2647 if (s.index==FAD::State::kDisconnected) // Dim connection / FTM disconnected
2648 SetLedColor(fStatusFADLed, kLedOrange, time);
2649 if (s.index==FAD::State::kConnecting) // Dim connection / FTM disconnected
2650 {
2651 SetLedColor(fStatusFADLed, kLedYellow, time);
2652 // FIXME FIXME FIXME: The LEDs are not displayed when disabled!
2653 enable = true;
2654 }
2655 if (s.index>=FAD::State::kConnected) // Dim connection / FTM connected
2656 {
2657 SetLedColor(fStatusFADLed, kLedGreen, time);
2658 enable = true;
2659 }
2660
2661 fFadWidget->setEnabled(enable);
2662
2663 fFadStart->setEnabled (s.index==FAD::State::kOffline);
2664 fFadStop->setEnabled (s.index >FAD::State::kOffline);
2665 fFadAbort->setEnabled (s.index >FAD::State::kOffline);
2666 fFadSoftReset->setEnabled(s.index >FAD::State::kOffline);
2667 fFadHardReset->setEnabled(s.index >FAD::State::kOffline);
2668 }
2669
2670 if (server=="FSC_CONTROL")
2671 {
2672 fStatusFSCLabel->setText(s.name.c_str());
2673 fStatusFSCLabel->setToolTip(s.comment.c_str());
2674
2675 bool enable = false;
2676
2677 if (s.index<FSC::State::kDisconnected) // No Dim connection
2678 SetLedColor(fStatusFSCLed, kLedGray, time);
2679 if (s.index==FSC::State::kDisconnected) // Dim connection / FTM disconnected
2680 SetLedColor(fStatusFSCLed, kLedRed, time);
2681 if (s.index>=FSC::State::kConnected) // Dim connection / FTM disconnected
2682 {
2683 SetLedColor(fStatusFSCLed, kLedGreen, time);
2684 enable = true;
2685 }
2686
2687 fAuxWidget->setEnabled(enable);
2688 }
2689
2690 if (server=="DRIVE_CONTROL")
2691 {
2692 fStatusDriveLabel->setText(s.name.c_str());
2693 fStatusDriveLabel->setToolTip(s.comment.c_str());
2694
2695 if (s.index<Drive::State::kDisconnected) // No Dim connection
2696 SetLedColor(fStatusDriveLed, kLedGray, time);
2697 if (s.index==Drive::State::kDisconnected) // Dim connection / No connection to cosy
2698 SetLedColor(fStatusDriveLed, kLedRed, time);
2699 if (s.index==Drive::State::kConnected || s.index==Drive::State::kNotReady || s.index==Drive::State::kLocked) // Not Ready
2700 SetLedColor(fStatusDriveLed, kLedGreenBar, time);
2701 if (s.index==Drive::State::kConnected || s.index==Drive::State::kArmed) // Connected / Armed
2702 SetLedColor(fStatusDriveLed, kLedGreen, time);
2703 if (s.index==Drive::State::kMoving) // Moving
2704 SetLedColor(fStatusDriveLed, kLedInProgress, time);
2705 if (s.index==Drive::State::kTracking || s.index==Drive::State::kOnTrack) // Tracking
2706 SetLedColor(fStatusDriveLed, kLedGreenCheck, time);
2707 if (s.index>=0xff) // Error
2708 SetLedColor(fStatusDriveLed, kLedGreenWarn, time);
2709 }
2710
2711 if (server=="BIAS_CONTROL")
2712 {
2713 fStatusBiasLabel->setText(s.name.c_str());
2714 fStatusBiasLabel->setToolTip(s.comment.c_str());
2715
2716 if (s.index<1) // No Dim connection
2717 SetLedColor(fStatusBiasLed, kLedGray, time);
2718 if (s.index==BIAS::State::kDisconnected) // Dim connection / FTM disconnected
2719 SetLedColor(fStatusBiasLed, kLedRed, time);
2720 if (s.index==BIAS::State::kConnecting || s.index==BIAS::State::kInitializing) // Connecting / Initializing
2721 SetLedColor(fStatusBiasLed, kLedOrange, time);
2722 if (s.index==BIAS::State::kVoltageOff) // At reference
2723 SetLedColor(fStatusBiasLed, kLedGreenBar, time);
2724 if (s.index==BIAS::State::kNotReferenced) // At reference
2725 SetLedColor(fStatusBiasLed, kLedGreenWarn, time);
2726 if (s.index==BIAS::State::kRamping) // Ramping
2727 SetLedColor(fStatusBiasLed, kLedInProgress, time);
2728 if (s.index==BIAS::State::kVoltageOn) // At reference
2729 SetLedColor(fStatusBiasLed, kLedGreenCheck, time);
2730 if (s.index==BIAS::State::kOverCurrent) // Over current
2731 SetLedColor(fStatusBiasLed, kLedWarnBorder, time);
2732 if (s.index==BIAS::State::kExpertMode) // ExpertMode
2733 SetLedColor(fStatusBiasLed, kLedWarnTriangleBorder, time);
2734
2735 fBiasWidget->setEnabled(s.index>=BIAS::State::kInitializing);
2736 }
2737
2738 if (server=="FEEDBACK")
2739 {
2740 fStatusFeedbackLabel->setText(s.name.c_str());
2741 fStatusFeedbackLabel->setToolTip(s.comment.c_str());
2742
2743 const bool connected = s.index> Feedback::State::kConnecting;
2744 const bool idle = s.index>=Feedback::State::kTempCtrlIdle && s.index<=Feedback::State::kCurrentCtrlIdle;
2745 const bool running = s.index>=Feedback::State::kTempCtrlRunning && s.index<=Feedback::State::kCurrentCtrlRunning;
2746 const bool calib = s.index==Feedback::State::kCalibrating;
2747
2748 if (s.index<=Feedback::State::kConnecting) // NoDim / Disconnected
2749 SetLedColor(fStatusFeedbackLed, kLedRed, time);
2750 if (s.index<Feedback::State::kDisconnected) // No Dim connection
2751 SetLedColor(fStatusFeedbackLed, kLedGray, time);
2752 if (s.index==Feedback::State::kConnecting) // Connecting
2753 SetLedColor(fStatusFeedbackLed, kLedOrange, time);
2754 if (connected) // Connected
2755 SetLedColor(fStatusFeedbackLed, kLedYellow, time);
2756 if (idle)
2757 SetLedColor(fStatusFeedbackLed, kLedGreen, time);
2758 if (running)
2759 SetLedColor(fStatusFeedbackLed, kLedGreenCheck, time);
2760 if (calib)
2761 SetLedColor(fStatusFeedbackLed, kLedInProgress, time);
2762
2763 fFeedbackWidget->setEnabled(connected);
2764
2765 fFeedbackCalibrate->setEnabled(s.index==Feedback::State::kConnectedFSC || s.index==Feedback::State::kConnected);
2766 fFeedbackTempStart->setEnabled(s.index==Feedback::State::kConnectedFSC || s.index==Feedback::State::kConnected);
2767
2768 fFeedbackStop->setEnabled(s.index>Feedback::State::kConnected);
2769
2770 fFeedbackTempOffset->setEnabled(s.index<=Feedback::State::kConnected);
2771 fFeedbackOutputEnable->setEnabled(s.index<Feedback::State::kTempCtrlRunning);
2772 fFeedbackOutputDisable->setEnabled(running);
2773
2774 const bool enable =
2775 s.index!=Feedback::State::kTempCtrlIdle ||
2776 s.index!=Feedback::State::kCurrentCtrlIdle ||
2777 s.index!=Feedback::State::kTempCtrlRunning ||
2778 s.index!=Feedback::State::kCurrentCtrlRunning;
2779
2780 fFeedbackFrameLeft->setEnabled(enable);
2781 fFeedbackCanvLeft->setEnabled(enable);
2782 }
2783
2784 if (server=="RATE_CONTROL")
2785 {
2786 fStatusRateControlLabel->setText(s.name.c_str());
2787 fStatusRateControlLabel->setToolTip(s.comment.c_str());
2788
2789 if (s.index==RateControl::State::kInProgress)
2790 SetLedColor(fStatusRateControlLed, kLedGreenCheck, time);
2791 if (s.index==RateControl::State::kGlobalThresholdSet)
2792 SetLedColor(fStatusRateControlLed, kLedGreen, time);
2793 if (s.index==RateControl::State::kSettingGlobalThreshold)
2794 SetLedColor(fStatusRateControlLed, kLedInProgress, time);
2795 if (s.index==RateControl::State::kConnected)
2796 SetLedColor(fStatusRateControlLed, kLedGreenBar, time);
2797 if (s.index==RateControl::State::kConnecting)
2798 SetLedColor(fStatusRateControlLed, kLedOrange, time);
2799 if (s.index<RateControl::State::kConnecting)
2800 SetLedColor(fStatusRateControlLed, kLedRed, time);
2801 if (s.index<RateControl::State::kDisconnected)
2802 SetLedColor(fStatusRateControlLed, kLedGray, time);
2803 }
2804
2805 if (server=="DATA_LOGGER")
2806 {
2807 fStatusLoggerLabel->setText(s.name.c_str());
2808 fStatusLoggerLabel->setToolTip(s.comment.c_str());
2809
2810 bool enable = true;
2811
2812 if (s.index<30) // Ready/Waiting
2813 SetLedColor(fStatusLoggerLed, kLedYellow, time);
2814 if (s.index==30) // Ready/Waiting
2815 SetLedColor(fStatusLoggerLed, kLedGreen, time);
2816 if (s.index<-1) // Offline
2817 {
2818 SetLedColor(fStatusLoggerLed, kLedGray, time);
2819 enable = false;
2820 }
2821 if (s.index>=0x100) // Error
2822 SetLedColor(fStatusLoggerLed, kLedRed, time);
2823 if (s.index==40) // Logging
2824 SetLedColor(fStatusLoggerLed, kLedGreen, time);
2825
2826 fLoggerWidget->setEnabled(enable);
2827 fLoggerStart->setEnabled(s.index>-1 && s.index<30);
2828 fLoggerStop->setEnabled(s.index>=30);
2829 }
2830
2831 if (server=="MAGIC_WEATHER")
2832 {
2833 fStatusWeatherLabel->setText(s.name.c_str());
2834
2835 if (s.index==MagicWeather::State::kReceiving)
2836 SetLedColor(fStatusWeatherLed, kLedGreen, time);
2837 if (s.index<MagicWeather::State::kReceiving)
2838 SetLedColor(fStatusWeatherLed, kLedRed, time);
2839 if (s.index<MagicWeather::State::kConnected)
2840 SetLedColor(fStatusWeatherLed, kLedGray, time);
2841 }
2842
2843 if (server=="CHAT")
2844 {
2845 fStatusChatLabel->setText(s.name.c_str());
2846
2847 fChatOnline = s.index==0;
2848
2849 SetLedColor(fStatusChatLed, fChatOnline ? kLedGreen : kLedGray, time);
2850
2851 fChatSend->setEnabled(fChatOnline);
2852 fChatMessage->setEnabled(fChatOnline);
2853 }
2854
2855 if (server=="RATESCAN")
2856 fRateScanControls->setEnabled(s.index>=RateScan::State::kConnected);
2857
2858 if (server=="SCHEDULER")
2859 {
2860 fStatusSchedulerLabel->setText(s.name.c_str());
2861
2862 SetLedColor(fStatusSchedulerLed, s.index>=0 ? kLedGreen : kLedRed, time);
2863 }
2864 }
2865
2866 void on_fTabWidget_currentChanged(int which)
2867 {
2868 if (fTabWidget->tabText(which)=="Chat")
2869 fTabWidget->setTabIcon(which, QIcon());
2870 }
2871
2872 void handleWrite(const Time &time, const string &text, int qos)
2873 {
2874 stringstream out;
2875
2876 if (text.substr(0, 6)=="CHAT: ")
2877 {
2878 if (qos==MessageImp::kDebug)
2879 return;
2880
2881 out << "<font size='-1' color='navy'>[<B>";
2882 out << time.GetAsStr("%H:%M:%S");
2883 out << "</B>]</FONT> " << text.substr(6);
2884 fChatText->append(out.str().c_str());
2885
2886 if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
2887 return;
2888
2889 static int num = 0;
2890 if (num++<2)
2891 return;
2892
2893 for (int i=0; i<fTabWidget->count(); i++)
2894 if (fTabWidget->tabText(i)=="Chat")
2895 {
2896 fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
2897 break;
2898 }
2899
2900 return;
2901 }
2902
2903
2904 out << "<font style='font-family:monospace' color='";
2905
2906 switch (qos)
2907 {
2908 case kMessage: out << "black"; break;
2909 case kInfo: out << "green"; break;
2910 case kWarn: out << "#FF6600"; break;
2911 case kError: out << "maroon"; break;
2912 case kFatal: out << "maroon"; break;
2913 case kDebug: out << "navy"; break;
2914 default: out << "navy"; break;
2915 }
2916 out << "'>";
2917 out << time.GetAsStr("%H:%M:%S.%f").substr(0,12);
2918 out << " - " << text << "</font>";
2919
2920 fLogText->append(out.str().c_str());
2921
2922 if (qos>=kWarn && qos!=kDebug && qos!=kComment)
2923 fTextEdit->append(out.str().c_str());
2924 }
2925
2926 void IndicateStateChange(const Time &time, const string &server)
2927 {
2928 const State s = GetState(server, GetCurrentState(server));
2929
2930 QApplication::postEvent(this,
2931 new FunctionEvent(bind(&FactGui::handleStateChanged, this, time, server, s)));
2932 }
2933
2934 int Write(const Time &time, const string &txt, int qos)
2935 {
2936 QApplication::postEvent(this,
2937 new FunctionEvent(bind(&FactGui::handleWrite, this, time, txt, qos)));
2938
2939 return 0;
2940 }
2941
2942 // ====================== Dim infoHandler================================
2943
2944 void handleDimService(const string &txt)
2945 {
2946 fDimSvcText->append(txt.c_str());
2947 }
2948
2949 void infoHandlerService(DimInfo &info)
2950 {
2951 const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
2952
2953 stringstream dummy;
2954 const Converter conv(dummy, fmt, false);
2955
2956 const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
2957
2958 stringstream out;
2959 out << "<font size'-1' color='navy'>[";
2960 out << tm.GetAsStr("%H:%M:%S.%f").substr(0,12);
2961 out << "]</font> <B>" << info.getName() << "</B> - ";
2962
2963 bool iserr = 2;
2964 if (!conv)
2965 {
2966 out << "Compilation of format string '" << fmt << "' failed!";
2967 }
2968 else
2969 {
2970 try
2971 {
2972 const string dat = info.getSize()==0 ? "&lt;empty&gt;" : conv.GetString(info.getData(), info.getSize());
2973 out << dat;
2974 iserr = info.getSize()==0;
2975 }
2976 catch (const runtime_error &e)
2977 {
2978 out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
2979 }
2980 }
2981
2982 // srand(hash<string>()(string(info.getName())));
2983 // int bg = rand()&0xffffff;
2984
2985 int bg = hash<string>()(string(info.getName()));
2986
2987 // allow only light colors
2988 bg = ~(bg&0x1f1f1f)&0xffffff;
2989
2990 if (iserr==2)
2991 bg = 0xffffff;
2992
2993 stringstream bgcol;
2994 bgcol << hex << setfill('0') << setw(6) << bg;
2995
2996 const string col = iserr==0 ? "black" : (iserr==1 ? "#FF6600" : "black");
2997 const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
2998
2999 QApplication::postEvent(this,
3000 new FunctionEvent(bind(&FactGui::handleDimService, this, str)));
3001 }
3002
3003 void CallInfoHandler(void (FactGui::*handler)(const DimData&), const DimData &d)
3004 {
3005 fInHandler = true;
3006 (this->*handler)(d);
3007 fInHandler = false;
3008 }
3009
3010 /*
3011 void CallInfoHandler(const boost::function<void()> &func)
3012 {
3013 // This ensures that newly received values are not sent back to the emitter
3014 // because changing the value emits the valueChanged signal (or similar)
3015 fInHandler = true;
3016 func();
3017 fInHandler = false;
3018 }*/
3019
3020 void PostInfoHandler(void (FactGui::*handler)(const DimData&))
3021 {
3022 //const boost::function<void()> f = boost::bind(handler, this, DimData(getInfo()));
3023
3024 FunctionEvent *evt = new FunctionEvent(bind(&FactGui::CallInfoHandler, this, handler, DimData(getInfo())));
3025 // FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, f));
3026 // FunctionEvent *evt = new FunctionEvent(boost::bind(handler, this, DimData(getInfo()))));
3027
3028 QApplication::postEvent(this, evt);
3029 }
3030
3031 void infoHandler()
3032 {
3033 // Initialize the time-stamp (what a weird workaround...)
3034 if (getInfo())
3035 getInfo()->getTimestamp();
3036
3037 if (getInfo()==&fDimDNS)
3038 return PostInfoHandler(&FactGui::handleDimDNS);
3039#ifdef DEBUG_DIM
3040 cout << "HandleDimInfo " << getInfo()->getName() << endl;
3041#endif
3042 if (getInfo()==&fDimLoggerStats)
3043 return PostInfoHandler(&FactGui::handleLoggerStats);
3044
3045// if (getInfo()==&fDimFadFiles)
3046// return PostInfoHandler(&FactGui::handleFadFiles);
3047
3048 if (getInfo()==&fDimFadWriteStats)
3049 return PostInfoHandler(&FactGui::handleFadWriteStats);
3050
3051 if (getInfo()==&fDimFadConnections)
3052 return PostInfoHandler(&FactGui::handleFadConnections);
3053
3054 if (getInfo()==&fDimFadFwVersion)
3055 return PostInfoHandler(&FactGui::handleFadFwVersion);
3056
3057 if (getInfo()==&fDimFadRunNumber)
3058 return PostInfoHandler(&FactGui::handleFadRunNumber);
3059
3060 if (getInfo()==&fDimFadDNA)
3061 return PostInfoHandler(&FactGui::handleFadDNA);
3062
3063 if (getInfo()==&fDimFadTemperature)
3064 return PostInfoHandler(&FactGui::handleFadTemperature);
3065
3066 if (getInfo()==&fDimFadRefClock)
3067 return PostInfoHandler(&FactGui::handleFadRefClock);
3068
3069 if (getInfo()==&fDimFadRoi)
3070 return PostInfoHandler(&FactGui::handleFadRoi);
3071
3072 if (getInfo()==&fDimFadDac)
3073 return PostInfoHandler(&FactGui::handleFadDac);
3074
3075 if (getInfo()==&fDimFadDrsCalibration)
3076 return PostInfoHandler(&FactGui::handleFadDrsCalibration);
3077
3078 if (getInfo()==&fDimFadPrescaler)
3079 return PostInfoHandler(&FactGui::handleFadPrescaler);
3080
3081 if (getInfo()==&fDimFadStatus)
3082 return PostInfoHandler(&FactGui::handleFadStatus);
3083
3084 if (getInfo()==&fDimFadStatistics1)
3085 return PostInfoHandler(&FactGui::handleFadStatistics1);
3086
3087 //if (getInfo()==&fDimFadStatistics2)
3088 // return PostInfoHandler(&FactGui::handleFadStatistics2);
3089
3090 if (getInfo()==&fDimFadFileFormat)
3091 return PostInfoHandler(&FactGui::handleFadFileFormat);
3092
3093 if (getInfo()==&fDimFadEvents)
3094 return PostInfoHandler(&FactGui::handleFadEvents);
3095
3096 if (getInfo()==&fDimFadRuns)
3097 return PostInfoHandler(&FactGui::handleFadRuns);
3098
3099 if (getInfo()==&fDimFadStartRun)
3100 return PostInfoHandler(&FactGui::handleFadStartRun);
3101
3102 if (getInfo()==&fDimFadRawData)
3103 return PostInfoHandler(&FactGui::handleFadRawData);
3104
3105 if (getInfo()==&fDimFadEventData)
3106 return PostInfoHandler(&FactGui::handleFadEventData);
3107
3108/*
3109 if (getInfo()==&fDimFadSetup)
3110 return PostInfoHandler(&FactGui::handleFadSetup);
3111*/
3112 if (getInfo()==&fDimLoggerFilenameNight)
3113 return PostInfoHandler(&FactGui::handleLoggerFilenameNight);
3114
3115 if (getInfo()==&fDimLoggerNumSubs)
3116 return PostInfoHandler(&FactGui::handleLoggerNumSubs);
3117
3118 if (getInfo()==&fDimLoggerFilenameRun)
3119 return PostInfoHandler(&FactGui::handleLoggerFilenameRun);
3120
3121 if (getInfo()==&fDimFtmTriggerRates)
3122 return PostInfoHandler(&FactGui::handleFtmTriggerRates);
3123
3124 if (getInfo()==&fDimFtmCounter)
3125 return PostInfoHandler(&FactGui::handleFtmCounter);
3126
3127 if (getInfo()==&fDimFtmDynamicData)
3128 return PostInfoHandler(&FactGui::handleFtmDynamicData);
3129
3130 if (getInfo()==&fDimFtmPassport)
3131 return PostInfoHandler(&FactGui::handleFtmPassport);
3132
3133 if (getInfo()==&fDimFtmFtuList)
3134 return PostInfoHandler(&FactGui::handleFtmFtuList);
3135
3136 if (getInfo()==&fDimFtmStaticData)
3137 return PostInfoHandler(&FactGui::handleFtmStaticData);
3138
3139 if (getInfo()==&fDimFtmError)
3140 return PostInfoHandler(&FactGui::handleFtmError);
3141
3142 if (getInfo()==&fDimFscTemp)
3143 return PostInfoHandler(&FactGui::handleFscTemp);
3144
3145 if (getInfo()==&fDimFscVolt)
3146 return PostInfoHandler(&FactGui::handleFscVolt);
3147
3148 if (getInfo()==&fDimFscCurrent)
3149 return PostInfoHandler(&FactGui::handleFscCurrent);
3150
3151 if (getInfo()==&fDimFscHumidity)
3152 return PostInfoHandler(&FactGui::handleFscHumidity);
3153
3154 if (getInfo()==&fDimBiasNominal)
3155 return PostInfoHandler(&FactGui::handleBiasNominal);
3156
3157 if (getInfo()==&fDimBiasVolt)
3158 return PostInfoHandler(&FactGui::handleBiasVolt);
3159
3160 if (getInfo()==&fDimBiasDac)
3161 return PostInfoHandler(&FactGui::handleBiasDac);
3162
3163 if (getInfo()==&fDimBiasCurrent)
3164 return PostInfoHandler(&FactGui::handleBiasCurrent);
3165
3166 if (getInfo()==&fDimFeedbackReference)
3167 return PostInfoHandler(&FactGui::handleFeedbackReference);
3168
3169 if (getInfo()==&fDimFeedbackDeviation)
3170 return PostInfoHandler(&FactGui::handleFeedbackDeviation);
3171
3172 if (getInfo()==&fDimFeedbackCalibration)
3173 return PostInfoHandler(&FactGui::handleFeedbackCalibration);
3174
3175 if (getInfo()==&fDimRateScan)
3176 return PostInfoHandler(&FactGui::handleRateScan);
3177
3178 if (getInfo()==&fDimMagicWeather)
3179 return PostInfoHandler(&FactGui::handleMagicWeather);
3180
3181// if (getInfo()==&fDimFadFiles)
3182// return PostInfoHandler(&FactGui::handleFadFiles);
3183
3184 for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
3185 if (i->second==getInfo())
3186 {
3187 infoHandlerService(*i->second);
3188 return;
3189 }
3190
3191 //DimNetwork::infoHandler();
3192 }
3193
3194
3195 // ======================================================================
3196
3197 bool event(QEvent *evt)
3198 {
3199 if (dynamic_cast<FunctionEvent*>(evt))
3200 return static_cast<FunctionEvent*>(evt)->Exec();
3201
3202 if (dynamic_cast<CheckBoxEvent*>(evt))
3203 {
3204 const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
3205 const QStandardItem *par = item.parent();
3206 if (par)
3207 {
3208 const QString server = par->text();
3209 const QString service = item.text();
3210
3211 const string s = (server+'/'+service).toStdString();
3212
3213 if (item.checkState()==Qt::Checked)
3214 SubscribeService(s);
3215 else
3216 UnsubscribeService(s);
3217 }
3218 }
3219
3220 return MainWindow::event(evt); // unrecognized
3221 }
3222
3223 void on_fDimCmdSend_clicked()
3224 {
3225 const QString server = fDimCmdServers->currentIndex().data().toString();
3226 const QString command = fDimCmdCommands->currentIndex().data().toString();
3227 const QString arguments = fDimCmdLineEdit->displayText();
3228
3229 // FIXME: Sending a command exactly when the info Handler changes
3230 // the list it might lead to confusion.
3231 try
3232 {
3233 SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
3234 fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
3235 fDimCmdLineEdit->clear();
3236 }
3237 catch (const runtime_error &e)
3238 {
3239 stringstream txt;
3240 txt << e.what();
3241
3242 string buffer;
3243 while (getline(txt, buffer, '\n'))
3244 fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
3245 }
3246 }
3247
3248#ifdef HAVE_ROOT
3249 void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *canv)
3250 {
3251 // kMousePressEvent // TCanvas processed QEvent mousePressEvent
3252 // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
3253 // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
3254 // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
3255 // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
3256 // kEnterEvent // TCanvas processed QEvent enterEvent
3257 // kLeaveEvent // TCanvas processed QEvent leaveEvent
3258
3259 if (dynamic_cast<TCanvas*>(obj))
3260 return;
3261
3262 TQtWidget *tipped = static_cast<TQtWidget*>(sender());
3263
3264 if (evt==11/*kMouseReleaseEvent*/)
3265 return;
3266
3267 if (evt==61/*kMouseDoubleClickEvent*/)
3268 return;
3269
3270 if (obj)
3271 {
3272 // Find the object which will get picked by the GetObjectInfo
3273 // due to buffer overflows in many root-versions
3274 // in TH1 and TProfile we have to work around and implement
3275 // our own GetObjectInfo which make everything a bit more
3276 // complicated.
3277 canv->cd();
3278#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
3279 const char *objectInfo =
3280 obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
3281#else
3282 const char *objectInfo = dynamic_cast<TH1*>(obj) ?
3283 "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
3284#endif
3285
3286 QString tipText;
3287 tipText += obj->GetName();
3288 tipText += " [";
3289 tipText += obj->ClassName();
3290 tipText += "]: ";
3291 tipText += objectInfo;
3292
3293 fStatusBar->showMessage(tipText, 3000);
3294 }
3295
3296 gSystem->DispatchOneEvent(kFALSE);
3297 //gSystem->ProcessEvents();
3298 //QWhatsThis::display(tipText)
3299 }
3300
3301 void slot_RootUpdate()
3302 {
3303 gSystem->DispatchOneEvent(kFALSE);
3304 //gSystem->ProcessEvents();
3305 QTimer::singleShot(10, this, SLOT(slot_RootUpdate()));
3306 }
3307#endif
3308
3309 void ChoosePatchThreshold(Camera &cam, int isw)
3310 {
3311 cam.Reset();
3312
3313 fThresholdIdx->setValue(isw);
3314
3315 const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
3316
3317 fPatchRate->setEnabled(isw>=0);
3318 fThresholdCrate->setEnabled(isw>=0);
3319 fThresholdBoard->setEnabled(isw>=0);
3320 fThresholdPatch->setEnabled(isw>=0);
3321
3322 if (isw<0)
3323 return;
3324
3325 const int patch = ihw%4;
3326 const int board = (ihw/4)%10;
3327 const int crate = (ihw/4)/10;
3328
3329 fInChoosePatchTH = true;
3330
3331 fThresholdCrate->setValue(crate);
3332 fThresholdBoard->setValue(board);
3333 fThresholdPatch->setValue(patch);
3334
3335 fInChoosePatchTH = false;
3336
3337 fThresholdVal->setValue(fFtmStaticData.fThreshold[ihw]);
3338 fPatchRate->setValue(fTriggerRates.fPatchRate[ihw]);
3339 fBoardRate->setValue(fTriggerRates.fBoardRate[ihw/4]);
3340
3341 // Loop over the software idx of all pixels
3342// for (unsigned int i=0; i<1440; i++)
3343// if (fPatchHW[i]==ihw)
3344// cam.SetBold(i);
3345 }
3346
3347 /*
3348 void ChoosePatchBias(Camera &cam, int isw)
3349 {
3350 cam.Reset();
3351
3352 fBiasChannel->setValue(isw);
3353
3354 const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
3355
3356 fBiasCurrent->setEnabled(isw>=0);
3357 fBiasCrate->setEnabled(isw>=0);
3358 fBiasBoard->setEnabled(isw>=0);
3359 fBiasPatch->setEnabled(isw>=0);
3360
3361 if (isw<0)
3362 return;
3363
3364 const int patch = ihw%4;
3365 const int board = (ihw/4)%10;
3366 const int crate = (ihw/4)/10;
3367
3368 fInChoosePatchBias = true;
3369
3370 fBiasCrate->setValue(crate);
3371 fBiasBoard->setValue(board);
3372 fBiasPatch->setValue(patch);
3373
3374 fInChoosePatchBias = false;
3375
3376 if (fVecBias.size()>0)
3377 {
3378 // FIXME: Mapping
3379 fBiasVoltDac->setValue(fVecBias[ihw]);
3380 fBiasVolt->setValue(fVecBias[ihw]*90./4096);
3381 }
3382
3383 fBiasCurrent->setValue(cam.GetData(isw));
3384
3385 // Loop over the software idx of all pixels
3386 for (unsigned int i=0; i<1440; i++)
3387 if (fPatchHW[i]==ihw)
3388 cam.SetBold(i);
3389 }*/
3390
3391 void slot_ChoosePixelThreshold(int isw)
3392 {
3393 fPixelIdx->setValue(isw);
3394
3395 const PixelMapEntry &entry = fPixelMap.index(isw);
3396 fPixelEnable->setChecked(fFtmStaticData.IsEnabled(entry.hw()));
3397 }
3398
3399 void slot_CameraDoubleClick(int isw)
3400 {
3401 fPixelIdx->setValue(isw);
3402
3403 const PixelMapEntry &entry = fPixelMap.index(isw);
3404 Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", uint16_t(entry.hw()));
3405 }
3406
3407 void slot_CameraMouseMove(int isw)
3408 {
3409 const PixelMapEntry &entry = fPixelMap.index(isw);
3410
3411 QString tipText;
3412 tipText += fRatesCanv->GetName();
3413 ostringstream str;
3414 str << setfill('0') <<
3415 " || HW: " << entry.crate() << "|" << entry.board() << "|" << entry.patch() << "|" << entry.pixel() << " (crate|board|patch|pixel)" <<
3416 " || HV: " << entry.hv_board << "|" << setw(2) << entry.hv_channel << " (board|channel)" <<
3417 " || ID: " << isw;
3418
3419
3420 tipText += str.str().c_str();
3421 fStatusBar->showMessage(tipText, 3000);
3422 }
3423
3424 /*
3425 void on_fThresholdIdx_valueChanged(int isw)
3426 {
3427 // fRatesCanv->SetBold(isw);
3428 // fRatesCanv->updateGL();
3429 }*/
3430
3431 /*
3432 void UpdateThresholdIdx()
3433 {
3434 if (fInChoosePatchTH)
3435 return;
3436
3437 const int crate = fThresholdCrate->value();
3438 const int board = fThresholdBoard->value();
3439 const int patch = fThresholdPatch->value();
3440
3441 const int ihw = patch + board*4 + crate*40;
3442
3443 int isw = 0;
3444 for (; isw<160; isw++)
3445 if (ihw==fPatchMapHW[isw])
3446 break;
3447
3448 on_fThresholdIdx_valueChanged(isw);
3449 }*/
3450
3451 void on_fPixelIdx_valueChanged(int isw)
3452 {
3453 int ii = 0;
3454 for (; ii<160; ii++)
3455 if (fPixelMap.index(isw).hw()/9==fPatchMapHW[ii])
3456 break;
3457
3458 fRatesCanv->SetWhite(isw);
3459 ChoosePatchThreshold(*fRatesCanv, ii);
3460
3461 const PixelMapEntry &entry = fPixelMap.index(isw);
3462 fPixelEnable->setChecked(fFtmStaticData.IsEnabled(entry.hw()));
3463 }
3464
3465 // ------------------- Bias display ---------------------
3466
3467 void UpdateBiasValues()
3468 {
3469 const int b = fBiasHvBoard->value();
3470 const int c = fBiasHvChannel->value();
3471
3472 const int ihw = b*32+c;
3473
3474 const double offset = fVecBiasCalibOffset.size()>0 ? fVecBiasCalibOffset[ihw] : 0;
3475
3476
3477 if (fVecBiasDac.size()>0)
3478 {
3479 fBiasVoltCur->setValue(fVecBiasDac[ihw]*90./4096-offset);
3480 fBiasVoltRef->setValue(fVecBiasDac[ihw+416]*90./4096-offset);
3481
3482 SetLedColor(fBiasNominalLed,
3483 fVecBiasDac[ihw]==fVecBiasDac[ihw+416]?kLedGreen:kLedRed, Time());
3484 }
3485
3486 if (fVecBiasCurrent.size()>0)
3487 {
3488 double val = abs(fVecBiasCurrent[ihw]) * 5000./4096;
3489 if (fBiasOffsets.size()>0 && fVecBiasVolt.size()>0)
3490 val -= fVecBiasVolt[ihw]/fBiasOffsets[ihw]*1e6;
3491
3492 fBiasCurrent->setValue(val);
3493 SetLedColor(fBiasOverCurrentLed,
3494 fVecBiasCurrent[ihw]<0?kLedRed:kLedGreen, Time());
3495 }
3496
3497 if (fBiasOffsets.size()>0 && fVecBiasVolt.size()>0)
3498 fBiasOffset->setValue(fVecBiasVolt[ihw]/fBiasOffsets[ihw]*1e6);
3499
3500 fBiasOffset->setEnabled(fBiasOffsets.size()>0 && fVecBiasVolt.size()>0);
3501 }
3502
3503 void UpdateBiasCam(const PixelMapEntry &entry)
3504 {
3505 fInChooseBiasCam = true;
3506
3507 fBiasCamCrate->setValue(entry.crate());
3508 fBiasCamBoard->setValue(entry.board());
3509 fBiasCamPatch->setValue(entry.patch());
3510 fBiasCamPixel->setValue(entry.pixel());
3511
3512 fInChooseBiasCam = false;
3513 }
3514
3515 void BiasHvChannelChanged()
3516 {
3517 if (fInChooseBiasHv)
3518 return;
3519
3520 const int b = fBiasHvBoard->value();
3521 const int ch = fBiasHvChannel->value();
3522
3523 // FIXME: Mark corresponding patch in camera
3524 const PixelMapEntry &entry = fPixelMap.hv(b, ch);
3525 fBiasCamV->SetWhite(entry.index);
3526 fBiasCamA->SetWhite(entry.index);
3527 fBiasCamV->updateCamera();
3528 fBiasCamA->updateCamera();
3529
3530 UpdateBiasCam(entry);
3531 UpdateBiasValues();
3532 }
3533
3534 void UpdateBiasHv(const PixelMapEntry &entry)
3535 {
3536 fInChooseBiasHv = true;
3537
3538 fBiasHvBoard->setValue(entry.hv_board);
3539 fBiasHvChannel->setValue(entry.hv_channel);
3540
3541 fInChooseBiasHv = false;
3542 }
3543
3544 void BiasCamChannelChanged()
3545 {
3546 if (fInChooseBiasCam)
3547 return;
3548
3549 const int crate = fBiasCamCrate->value();
3550 const int board = fBiasCamBoard->value();
3551 const int patch = fBiasCamPatch->value();
3552 const int pixel = fBiasCamPixel->value();
3553
3554 // FIXME: Display corresponding patches
3555 const PixelMapEntry &entry = fPixelMap.cbpx(crate, board, patch, pixel);
3556 fBiasCamV->SetWhite(entry.index);
3557 fBiasCamA->SetWhite(entry.index);
3558 fBiasCamV->updateCamera();
3559 fBiasCamA->updateCamera();
3560
3561 UpdateBiasHv(entry);
3562 UpdateBiasValues();
3563 }
3564
3565 void slot_ChooseBiasChannel(int isw)
3566 {
3567 const PixelMapEntry &entry = fPixelMap.index(isw);
3568
3569 UpdateBiasHv(entry);
3570 UpdateBiasCam(entry);
3571 UpdateBiasValues();
3572 }
3573
3574 void on_fBiasDispRefVolt_stateChanged(int = 0)
3575 {
3576 // FIXME: Display patches for which ref==cur
3577
3578 valarray<double> dat(0., 1440);
3579
3580 int offset = 0;
3581 if (!fBiasDispRefVolt->isChecked())
3582 fBiasCamV->setTitle("Applied BIAS voltage");
3583 else
3584 {
3585 fBiasCamV->setTitle("Reference BIAS voltage");
3586 offset = 416;
3587 }
3588
3589 if (fVecBiasDac.size()>0)
3590 {
3591 for (int i=0; i<1440; i++)
3592 {
3593 const PixelMapEntry &entry = fPixelMap.index(i);
3594 dat[i] = fVecBiasDac[entry.hv()+offset]*90./4096;
3595
3596 if (fVecBiasCalibOffset.size()>0)
3597 dat[i] -= fVecBiasCalibOffset[entry.hv()];
3598
3599 fBiasCamV->highlightPixel(i, fVecBiasDac[entry.hv()]!=fVecBiasDac[entry.hv()+416]);
3600 }
3601
3602 fBiasCamV->SetData(dat);
3603 }
3604
3605 fBiasCamV->updateCamera();
3606 }
3607
3608 // ------------------------------------------------------
3609
3610 void on_fPixelEnable_stateChanged(int b)
3611 {
3612 if (fInHandler)
3613 return;
3614
3615 const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
3616
3617 Dim::SendCommand(b==Qt::Unchecked ?
3618 "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
3619 uint16_t(entry.hw()));
3620 }
3621
3622 void on_fPixelDisableOthers_clicked()
3623 {
3624 const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
3625 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PIXELS_EXCEPT", uint16_t(entry.hw()));
3626 }
3627
3628 void on_fThresholdDisableOthers_clicked()
3629 {
3630 const int16_t isw = fThresholdIdx->value();
3631 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3632 if (ihw<0)
3633 return;
3634
3635 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PATCHES_EXCEPT", ihw);
3636 }
3637
3638 void on_fThresholdEnablePatch_clicked()
3639 {
3640 const int16_t isw = fThresholdIdx->value();
3641 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3642 if (ihw<0)
3643 return;
3644
3645 Dim::SendCommand("FTM_CONTROL/ENABLE_PATCH", ihw);
3646 }
3647
3648 void on_fThresholdDisablePatch_clicked()
3649 {
3650 const int16_t isw = fThresholdIdx->value();
3651 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3652 if (ihw<0)
3653 return;
3654
3655 Dim::SendCommand("FTM_CONTROL/DISABLE_PATCH", ihw);
3656 }
3657
3658 void on_fThresholdVal_valueChanged(int v)
3659 {
3660 fThresholdVolt->setValue(2500./4095*v);
3661
3662 const int32_t isw = fThresholdIdx->value();
3663 const int32_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3664
3665 const int32_t d[2] = { ihw, v };
3666
3667 if (!fInHandler)
3668 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
3669 }
3670
3671 TGraph fGraphFtmTemp[4];
3672 TGraph fGraphFtmRate;
3673 TGraph fGraphPatchRate[160];
3674 TGraph fGraphBoardRate[40];
3675
3676#ifdef HAVE_ROOT
3677 TH1 *DrawTimeFrame(const char *ytitle)
3678 {
3679 const double tm = Time().RootTime();
3680
3681 TH1F *h=new TH1F("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
3682 h->SetDirectory(0);
3683 h->SetBit(kCanDelete);
3684 h->SetStats(kFALSE);
3685// h.SetMinimum(0);
3686// h.SetMaximum(1);
3687 h->SetXTitle("Time");
3688 h->SetYTitle(ytitle);
3689 h->GetXaxis()->CenterTitle();
3690 h->GetYaxis()->CenterTitle();
3691 h->GetXaxis()->SetTimeDisplay(true);
3692 h->GetXaxis()->SetTimeFormat("%Mh%S'%F1995-01-01 00:00:00 GMT");
3693 h->GetXaxis()->SetLabelSize(0.025);
3694 h->GetYaxis()->SetLabelSize(0.025);
3695 h->GetYaxis()->SetTitleOffset(1.2);
3696 // h.GetYaxis()->SetTitleSize(1.2);
3697 return h;
3698 }
3699#endif
3700
3701 pair<string,string> Split(const string &str) const
3702 {
3703 const size_t p = str.find_first_of('|');
3704 if (p==string::npos)
3705 return make_pair(str, "");
3706
3707 return make_pair(str.substr(0, p), str.substr(p+1));
3708 }
3709
3710public:
3711 FactGui(Configuration &conf) :
3712 fFtuStatus(40),
3713 /*fPixelMapHW(1440),*/ fPatchMapHW(160),
3714 fInChoosePatchTH(false),
3715 fInChooseBiasHv(false), fInChooseBiasCam(false),
3716 fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
3717 //-
3718 fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
3719 fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHTLY", (void*)NULL, 0, this),
3720 fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", (void*)NULL, 0, this),
3721 fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", (void*)NULL, 0, this),
3722 //-
3723 fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
3724 fDimFtmTriggerRates ("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this),
3725 fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
3726 fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
3727 fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
3728 fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this),
3729 fDimFtmCounter ("FTM_CONTROL/COUNTER", (void*)NULL, 0, this),
3730 //-
3731 fDimFadWriteStats ("FAD_CONTROL/STATS", (void*)NULL, 0, this),
3732 fDimFadStartRun ("FAD_CONTROL/START_RUN", (void*)NULL, 0, this),
3733 fDimFadRuns ("FAD_CONTROL/RUNS", (void*)NULL, 0, this),
3734 fDimFadEvents ("FAD_CONTROL/EVENTS", (void*)NULL, 0, this),
3735 fDimFadRawData ("FAD_CONTROL/RAW_DATA", (void*)NULL, 0, this),
3736 fDimFadEventData ("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, this),
3737 fDimFadConnections ("FAD_CONTROL/CONNECTIONS", (void*)NULL, 0, this),
3738 fDimFadFwVersion ("FAD_CONTROL/FIRMWARE_VERSION", (void*)NULL, 0, this),
3739 fDimFadRunNumber ("FAD_CONTROL/RUN_NUMBER", (void*)NULL, 0, this),
3740 fDimFadDNA ("FAD_CONTROL/DNA", (void*)NULL, 0, this),
3741 fDimFadTemperature ("FAD_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3742 fDimFadPrescaler ("FAD_CONTROL/PRESCALER", (void*)NULL, 0, this),
3743 fDimFadRefClock ("FAD_CONTROL/REFERENCE_CLOCK", (void*)NULL, 0, this),
3744 fDimFadRoi ("FAD_CONTROL/REGION_OF_INTEREST", (void*)NULL, 0, this),
3745 fDimFadDac ("FAD_CONTROL/DAC", (void*)NULL, 0, this),
3746 fDimFadDrsCalibration ("FAD_CONTROL/DRS_CALIBRATION", (void*)NULL, 0, this),
3747 fDimFadStatus ("FAD_CONTROL/STATUS", (void*)NULL, 0, this),
3748 fDimFadStatistics1 ("FAD_CONTROL/STATISTICS1", (void*)NULL, 0, this),
3749 //fDimFadStatistics2 ("FAD_CONTROL/STATISTICS2", (void*)NULL, 0, this),
3750 fDimFadFileFormat ("FAD_CONTROL/FILE_FORMAT", (void*)NULL, 0, this),
3751 //-
3752 fDimFscTemp ("FSC_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3753 fDimFscVolt ("FSC_CONTROL/VOLTAGE", (void*)NULL, 0, this),
3754 fDimFscCurrent ("FSC_CONTROL/CURRENT", (void*)NULL, 0, this),
3755 fDimFscHumidity ("FSC_CONTROL/HUMIDITY", (void*)NULL, 0, this),
3756 //-
3757 fDimFeedbackDeviation ("FEEDBACK/DEVIATION", (void*)NULL, 0, this),
3758 fDimFeedbackReference ("FEEDBACK/REFERENCE", (void*)NULL, 0, this),
3759 fDimFeedbackCalibration("FEEDBACK/CALIBRATION", (void*)NULL, 0, this),
3760 //-
3761 fDimBiasNominal ("BIAS_CONTROL/NOMINAL", (void*)NULL, 0, this),
3762 fDimBiasVolt ("BIAS_CONTROL/VOLTAGE", (void*)NULL, 0, this),
3763 fDimBiasDac ("BIAS_CONTROL/DAC", (void*)NULL, 0, this),
3764 fDimBiasCurrent ("BIAS_CONTROL/CURRENT", (void*)NULL, 0, this),
3765 //-
3766 fDimRateScan ("RATE_SCAN/DATA", (void*)NULL, 0, this),
3767 //-
3768 fDimMagicWeather ("MAGIC_WEATHER/DATA", (void*)NULL, 0, this),
3769 //-
3770 fDimVersion(0),
3771 fFreeSpaceLogger(UINT64_MAX), fFreeSpaceData(UINT64_MAX),
3772 fEventData(0),
3773 fDrsCalibration(1440*1024*6+160*1024*2),
3774 fTimeStamp0(0)
3775 {
3776 fClockCondFreq->addItem("--- Hz", QVariant(-1));
3777 fClockCondFreq->addItem("800 MHz", QVariant(800));
3778 fClockCondFreq->addItem("1 GHz", QVariant(1000));
3779 fClockCondFreq->addItem("2 GHz", QVariant(2000));
3780 fClockCondFreq->addItem("3 GHz", QVariant(3000));
3781 fClockCondFreq->addItem("4 GHz", QVariant(4000));
3782 fClockCondFreq->addItem("5 GHz", QVariant(5000));
3783
3784 cout << "-- run counter ---" << endl;
3785 fMcpNumEvents->addItem("unlimited", QVariant(0));
3786 const vector<uint32_t> runcount = conf.Vec<uint32_t>("run-count");
3787 for (vector<uint32_t>::const_iterator it=runcount.begin(); it!=runcount.end(); it++)
3788 {
3789 cout << *it << endl;
3790 ostringstream str;
3791 str << *it;
3792 fMcpNumEvents->addItem(str.str().c_str(), QVariant(*it));
3793 }
3794
3795 cout << "-- run times ---" << endl;
3796 fMcpTime->addItem("unlimited", QVariant(0));
3797 const vector<string> runtime = conf.Vec<string>("run-time");
3798 for (vector<string>::const_iterator it=runtime.begin(); it!=runtime.end(); it++)
3799 {
3800 const pair<string,string> p = Split(*it);
3801 cout << *it << "|" << p.second << "|" << p.first << "|" << endl;
3802 fMcpTime->addItem(p.second.c_str(), QVariant(stoi(p.first)));
3803 }
3804
3805 cout << "-- run types ---" << endl;
3806 const vector<string> runtype = conf.Vec<string>("run-type");
3807 for (vector<string>::const_iterator it=runtype.begin(); it!=runtype.end(); it++)
3808 {
3809 const pair<string,string> p = Split(*it);
3810 cout << *it << "|" << p.second << "|" << p.first << "|" << endl;
3811 fMcpRunType->addItem(p.second.c_str(), QVariant(p.first.c_str()));
3812 }
3813
3814 fTriggerWidget->setEnabled(false);
3815 fFtuWidget->setEnabled(false);
3816 fFtuGroupEnable->setEnabled(false);
3817 fRatesControls->setEnabled(false);
3818 fFadWidget->setEnabled(false);
3819 fGroupEthernet->setEnabled(false);
3820 fGroupOutput->setEnabled(false);
3821 fLoggerWidget->setEnabled(false);
3822 fBiasWidget->setEnabled(false);
3823 fAuxWidget->setEnabled(false);
3824
3825 fChatSend->setEnabled(false);
3826 fChatMessage->setEnabled(false);
3827
3828 DimClient::sendCommand("CHAT/MSG", "GUI online.");
3829 // + MessageDimRX
3830
3831 // --------------------------------------------------------------------------
3832
3833 if (!fPixelMap.Read(conf.Get<string>("pixel-map-file")))
3834 {
3835 cerr << "ERROR - Problems reading " << conf.Get<string>("pixel-map-file") << endl;
3836 exit(-1);
3837 }
3838
3839 // --------------------------------------------------------------------------
3840
3841 ifstream fin3("PatchList.txt");
3842
3843 string buf;
3844
3845 int l = 0;
3846 while (getline(fin3, buf, '\n'))
3847 {
3848 buf = Tools::Trim(buf);
3849 if (buf[0]=='#')
3850 continue;
3851
3852 unsigned int softid, hardid;
3853
3854 stringstream str(buf);
3855
3856 str >> softid;
3857 str >> hardid;
3858
3859 if (softid>=fPatchMapHW.size())
3860 continue;
3861
3862 fPatchMapHW[softid] = hardid-1;
3863
3864 l++;
3865 }
3866
3867 if (l!=160)
3868 cerr << "WARNING - Problems reading PatchList.txt" << endl;
3869
3870 // --------------------------------------------------------------------------
3871
3872 fCommentsWidget->setEnabled(false);
3873
3874 static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))");
3875
3876 const string database = conf.Get<string>("CommentDB");
3877
3878 if (!database.empty())
3879 {
3880 boost::smatch what;
3881 if (!boost::regex_match(database, what, expr, boost::match_extra))
3882 throw runtime_error("Couldn't parse '"+database+"'.");
3883
3884 if (what.size()!=10)
3885 throw runtime_error("Error parsing '"+database+"'.");
3886
3887 const string user = what[2];
3888 const string passwd = what[4];
3889 const string server = what[5];
3890 const string db = what[9];
3891 const int port = atoi(string(what[7]).c_str());
3892
3893 QSqlDatabase qdb = QSqlDatabase::addDatabase("QMYSQL");
3894 qdb.setHostName(server.c_str());
3895 qdb.setDatabaseName(db.c_str());
3896 qdb.setUserName(user.c_str());
3897 qdb.setPassword(passwd.c_str());
3898 qdb.setPort(port);
3899 qdb.setConnectOptions("CLIENT_SSL=1;MYSQL_OPT_RECONNECT=1");
3900 if (qdb.open())
3901 {
3902 QSqlTableModel *model = new QSqlTableModel(fTableComments, qdb);
3903 model->setTable("runcomments");
3904 model->setEditStrategy(QSqlTableModel::OnManualSubmit);
3905
3906 const bool ok2 = model->select();
3907
3908 if (ok2)
3909 {
3910 fTableComments->setModel(model);
3911 fTableComments->resizeColumnsToContents();
3912 fTableComments->resizeRowsToContents();
3913
3914 connect(fCommentSubmit, SIGNAL(clicked()), model, SLOT(submitAll()));
3915 connect(fCommentRevert, SIGNAL(clicked()), model, SLOT(revertAll()));
3916 connect(fCommentUpdateLayout, SIGNAL(clicked()), fTableComments, SLOT(resizeColumnsToContents()));
3917 connect(fCommentUpdateLayout, SIGNAL(clicked()), fTableComments, SLOT(resizeRowsToContents()));
3918
3919 fCommentsWidget->setEnabled(true);
3920 }
3921 else
3922 cout << "\n==> ERROR: Select on table failed.\n" << endl;
3923 }
3924 else
3925 cout << "\n==> ERROR: Connection to database failed:\n "
3926 << qdb.lastError().text().toStdString() << endl << endl;
3927 }
3928
3929 // --------------------------------------------------------------------------
3930#ifdef HAVE_ROOT
3931
3932 fGraphFeedbackDev.SetLineColor(kBlue);
3933 fGraphFeedbackDev.SetMarkerColor(kBlue);
3934 fGraphFeedbackDev.SetMarkerStyle(kFullDotMedium);
3935
3936 fGraphFeedbackCmd.SetLineColor(kBlue);
3937 fGraphFeedbackCmd.SetMarkerColor(kBlue);
3938 fGraphFeedbackCmd.SetMarkerStyle(kFullDotMedium);
3939
3940 // Evolution of control deviation
3941 // Evolution of command values (bias voltage change)
3942 fGraphFeedbackDev.SetName("ControlDev");
3943 fGraphFeedbackCmd.SetName("CommandVal");
3944
3945 TCanvas *c = fFeedbackDev->GetCanvas();
3946 c->SetBorderMode(0);
3947 c->SetFrameBorderMode(0);
3948 c->SetFillColor(kWhite);
3949 c->SetRightMargin(0.03);
3950 c->SetTopMargin(0.03);
3951 c->SetGrid();
3952
3953 TH1 *hf = DrawTimeFrame("Control deviation [mV] ");
3954 hf->GetXaxis()->SetLabelSize(0.07);
3955 hf->GetYaxis()->SetLabelSize(0.07);
3956 hf->GetYaxis()->SetTitleSize(0.08);
3957 hf->GetYaxis()->SetTitleOffset(0.55);
3958 hf->GetXaxis()->SetTitle("");
3959 hf->GetYaxis()->SetRangeUser(-99, 99);
3960
3961 c->GetListOfPrimitives()->Add(hf, "");
3962 c->GetListOfPrimitives()->Add(&fGraphFeedbackDev, "LP");
3963
3964 c = fFeedbackCmd->GetCanvas();
3965 c->SetBorderMode(0);
3966 c->SetFrameBorderMode(0);
3967 c->SetFillColor(kWhite);
3968 c->SetRightMargin(0.03);
3969 c->SetTopMargin(0.03);
3970 c->SetGrid();
3971
3972 hf = DrawTimeFrame("Command delta value [mV] ");
3973 hf->GetXaxis()->SetLabelSize(0.07);
3974 hf->GetYaxis()->SetLabelSize(0.07);
3975 hf->GetYaxis()->SetTitleSize(0.08);
3976 hf->GetYaxis()->SetTitleOffset(0.55);
3977 hf->GetXaxis()->SetTitle("");
3978 hf->GetYaxis()->SetRangeUser(-99*10, 99*10);
3979
3980 c->GetListOfPrimitives()->Add(hf, "");
3981 c->GetListOfPrimitives()->Add(&fGraphFeedbackCmd, "LP");
3982
3983 // --------------------------------------------------------------------------
3984
3985 c = fRateScanCanv->GetCanvas();
3986 //c->SetBit(TCanvas::kNoContextMenu);
3987 c->SetBorderMode(0);
3988 c->SetFrameBorderMode(0);
3989 c->SetFillColor(kWhite);
3990 c->SetRightMargin(0.03);
3991 c->SetTopMargin(0.03);
3992 c->SetGrid();
3993
3994 TH1F *h=new TH1F("Frame", "", 1, 0, 1);
3995 h->SetDirectory(0);
3996 h->SetBit(kCanDelete);
3997 h->SetStats(kFALSE);
3998 h->SetXTitle("Threshold [DAC]");
3999 h->SetYTitle("Rate [Hz]");
4000 h->GetXaxis()->CenterTitle();
4001 h->GetYaxis()->CenterTitle();
4002 h->GetXaxis()->SetLabelSize(0.025);
4003 h->GetYaxis()->SetLabelSize(0.025);
4004 h->GetYaxis()->SetTitleOffset(1.2);
4005 c->GetListOfPrimitives()->Add(h, "");
4006
4007 fGraphRateScan[0].SetName("CameraRate");
4008 for (int i=0; i<40; i++)
4009 {
4010 fGraphRateScan[i+1].SetName("BoardRate");
4011 fGraphRateScan[i+1].SetMarkerStyle(kFullDotMedium);
4012 }
4013 for (int i=0; i<160; i++)
4014 {
4015 fGraphRateScan[i+41].SetName("PatchRate");
4016 fGraphRateScan[i+41].SetMarkerStyle(kFullDotMedium);
4017 }
4018
4019 fGraphRateScan[0].SetLineColor(kBlue);
4020 fGraphRateScan[0].SetMarkerColor(kBlue);
4021 fGraphRateScan[0].SetMarkerStyle(kFullDotSmall);
4022 c->GetListOfPrimitives()->Add(&fGraphRateScan[0], "LP");
4023
4024 // --------------------------------------------------------------------------
4025
4026 c = fFtmRateCanv->GetCanvas();
4027 //c->SetBit(TCanvas::kNoContextMenu);
4028 c->SetBorderMode(0);
4029 c->SetFrameBorderMode(0);
4030 c->SetFillColor(kWhite);
4031 c->SetRightMargin(0.03);
4032 c->SetTopMargin(0.03);
4033 c->SetGrid();
4034
4035 hf = DrawTimeFrame("Trigger rate [Hz]");
4036 hf->GetYaxis()->SetRangeUser(0, 1010);
4037
4038 for (int i=0; i<160; i++)
4039 {
4040 fGraphPatchRate[i].SetName("PatchRate");
4041 //fGraphPatchRate[i].SetLineColor(kBlue);
4042 //fGraphPatchRate[i].SetMarkerColor(kBlue);
4043 fGraphPatchRate[i].SetMarkerStyle(kFullDotMedium);
4044 }
4045 for (int i=0; i<40; i++)
4046 {
4047 fGraphBoardRate[i].SetName("BoardRate");
4048 //fGraphBoardRate[i].SetLineColor(kBlue);
4049 //fGraphBoardRate[i].SetMarkerColor(kBlue);
4050 fGraphBoardRate[i].SetMarkerStyle(kFullDotMedium);
4051 }
4052
4053 fGraphFtmRate.SetLineColor(kBlue);
4054 fGraphFtmRate.SetMarkerColor(kBlue);
4055 fGraphFtmRate.SetMarkerStyle(kFullDotSmall);
4056
4057 c->GetListOfPrimitives()->Add(hf, "");
4058 c->GetListOfPrimitives()->Add(&fGraphFtmRate, "LP");
4059
4060 /*
4061 TCanvas *c = fFtmTempCanv->GetCanvas();
4062 c->SetBit(TCanvas::kNoContextMenu);
4063 c->SetBorderMode(0);
4064 c->SetFrameBorderMode(0);
4065 c->SetFillColor(kWhite);
4066 c->SetRightMargin(0.03);
4067 c->SetTopMargin(0.03);
4068 c->cd();
4069 */
4070 //CreateTimeFrame("Temperature / �C");
4071
4072 fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
4073 fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
4074 fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
4075 fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
4076
4077 fGraphFtmTemp[1].SetLineColor(kBlue);
4078 fGraphFtmTemp[2].SetLineColor(kRed);
4079 fGraphFtmTemp[3].SetLineColor(kGreen);
4080
4081 fGraphFtmTemp[1].SetMarkerColor(kBlue);
4082 fGraphFtmTemp[2].SetMarkerColor(kRed);
4083 fGraphFtmTemp[3].SetMarkerColor(kGreen);
4084
4085 //fGraphFtmTemp[0].Draw("LP");
4086 //fGraphFtmTemp[1].Draw("LP");
4087 //fGraphFtmTemp[2].Draw("LP");
4088 //fGraphFtmTemp[3].Draw("LP");
4089
4090 // --------------------------------------------------------------------------
4091
4092 c = fAdcDataCanv->GetCanvas();
4093 //c->SetBit(TCanvas::kNoContextMenu);
4094 c->SetBorderMode(0);
4095 c->SetFrameBorderMode(0);
4096 c->SetFillColor(kWhite);
4097 c->SetRightMargin(0.10);
4098 c->SetGrid();
4099 //c->cd();
4100#endif
4101
4102 // --------------------------------------------------------------------------
4103 fFeedbackDevCam->assignPixelMap(fPixelMap);
4104 fFeedbackDevCam->setAutoscaleLowerLimit((fFeedbackDevMin->minimum()+0.5*fFeedbackDevMin->singleStep()));
4105 fFeedbackDevCam->SetMin(fFeedbackDevMin->value());
4106 fFeedbackDevCam->SetMax(fFeedbackDevMax->value());
4107 fFeedbackDevCam->updateCamera();
4108
4109 fFeedbackCmdCam->assignPixelMap(fPixelMap);
4110 fFeedbackCmdCam->setAutoscaleLowerLimit((fFeedbackCmdMin->minimum()+0.5*fFeedbackCmdMin->singleStep()));
4111 fFeedbackCmdCam->SetMin(fFeedbackCmdMin->value());
4112 fFeedbackCmdCam->SetMax(fFeedbackCmdMax->value());
4113 fFeedbackCmdCam->updateCamera();
4114
4115 // --------------------------------------------------------------------------
4116
4117 fBiasCamV->assignPixelMap(fPixelMap);
4118 fBiasCamV->setAutoscaleLowerLimit((fBiasVoltMin->minimum()+0.5*fBiasVoltMin->singleStep()));
4119 fBiasCamV->SetMin(fBiasVoltMin->value());
4120 fBiasCamV->SetMax(fBiasVoltMax->value());
4121 fBiasCamV->updateCamera();
4122
4123 fBiasCamA->assignPixelMap(fPixelMap);
4124 fBiasCamA->setAutoscaleLowerLimit((fBiasCurrentMin->minimum()+0.5*fBiasCurrentMin->singleStep()));
4125 fBiasCamA->SetMin(fBiasCurrentMin->value());
4126 fBiasCamA->SetMax(fBiasCurrentMax->value());
4127 fBiasCamA->updateCamera();
4128
4129 // --------------------------------------------------------------------------
4130
4131 fRatesCanv->assignPixelMap(fPixelMap);
4132 fRatesCanv->setAutoscaleLowerLimit((fRatesMin->minimum()+0.5*fRatesMin->singleStep())*0.001);
4133 fRatesCanv->SetMin(fRatesMin->value());
4134 fRatesCanv->SetMax(fRatesMax->value());
4135 fRatesCanv->updateCamera();
4136 on_fPixelIdx_valueChanged(0);
4137
4138 // --------------------------------------------------------------------------
4139
4140 fRatesCanv->setTitle("Patch rates");
4141 fRatesCanv->setUnits("Hz");
4142
4143 fBiasCamA->setTitle("BIAS current");
4144 fBiasCamA->setUnits("uA");
4145
4146 fBiasCamV->setTitle("Applied BIAS voltage");
4147 fBiasCamV->setUnits("V");
4148
4149 fEventCanv1->setTitle("Average (all slices)");
4150 fEventCanv2->setTitle("RMS (all slices)");
4151 fEventCanv3->setTitle("Maximum (all slices)");
4152 fEventCanv4->setTitle("Position of maximum (all slices)");
4153
4154 fEventCanv1->setUnits("mV");
4155 fEventCanv2->setUnits("mV");
4156 fEventCanv3->setUnits("mV");
4157 fEventCanv4->setUnits("slice");
4158
4159 // --------------------------------------------------------------------------
4160
4161 fFeedbackDevCam->setTitle("Control deviation (Pulser amplitude voltage)");
4162 fFeedbackCmdCam->setTitle("Applied voltage change (BIAS voltage)");
4163
4164 fFeedbackDevCam->setUnits("mV");
4165 fFeedbackCmdCam->setUnits("mV");
4166
4167 // --------------------------------------------------------------------------
4168
4169 QTimer::singleShot(1000, this, SLOT(slot_RootUpdate()));
4170
4171 //widget->setMouseTracking(true);
4172 //widget->EnableSignalEvents(kMouseMoveEvent);
4173
4174 fFtmRateCanv->setMouseTracking(true);
4175 fFtmRateCanv->EnableSignalEvents(kMouseMoveEvent);
4176
4177 fAdcDataCanv->setMouseTracking(true);
4178 fAdcDataCanv->EnableSignalEvents(kMouseMoveEvent);
4179
4180 fRatesCanv->setMouseTracking(true);
4181 fEventCanv1->setMouseTracking(true);
4182 fEventCanv2->setMouseTracking(true);
4183 fEventCanv3->setMouseTracking(true);
4184 fEventCanv4->setMouseTracking(true);
4185
4186 fBiasCamV->setMouseTracking(true);
4187 fBiasCamA->setMouseTracking(true);
4188
4189 fFeedbackDevCam->setMouseTracking(true);
4190 fFeedbackCmdCam->setMouseTracking(true);
4191
4192 fEventCanv1->ShowPixelCursor(true);
4193 fEventCanv2->ShowPixelCursor(true);
4194 fEventCanv3->ShowPixelCursor(true);
4195 fEventCanv4->ShowPixelCursor(true);
4196
4197 fEventCanv1->ShowPatchCursor(true);
4198 fEventCanv2->ShowPatchCursor(true);
4199 fEventCanv3->ShowPatchCursor(true);
4200 fEventCanv4->ShowPatchCursor(true);
4201
4202 fFeedbackDevCam->ShowPixelCursor(true);
4203 fFeedbackCmdCam->ShowPixelCursor(true);
4204
4205 fFeedbackDevCam->ShowPatchCursor(true);
4206 fFeedbackCmdCam->ShowPatchCursor(true);
4207
4208 connect(fRatesCanv, SIGNAL(signalPixelMoveOver(int)),
4209 this, SLOT(slot_CameraMouseMove(int)));
4210 connect(fEventCanv1, SIGNAL(signalPixelMoveOver(int)),
4211 this, SLOT(slot_CameraMouseMove(int)));
4212 connect(fEventCanv2, SIGNAL(signalPixelMoveOver(int)),
4213 this, SLOT(slot_CameraMouseMove(int)));
4214 connect(fEventCanv3, SIGNAL(signalPixelMoveOver(int)),
4215 this, SLOT(slot_CameraMouseMove(int)));
4216 connect(fEventCanv4, SIGNAL(signalPixelMoveOver(int)),
4217 this, SLOT(slot_CameraMouseMove(int)));
4218
4219 connect(fBiasCamV, SIGNAL(signalPixelMoveOver(int)),
4220 this, SLOT(slot_CameraMouseMove(int)));
4221 connect(fBiasCamA, SIGNAL(signalPixelMoveOver(int)),
4222 this, SLOT(slot_CameraMouseMove(int)));
4223
4224 connect(fFeedbackDevCam, SIGNAL(signalPixelMoveOver(int)),
4225 this, SLOT(slot_CameraMouseMove(int)));
4226 connect(fFeedbackCmdCam, SIGNAL(signalPixelMoveOver(int)),
4227 this, SLOT(slot_CameraMouseMove(int)));
4228
4229 connect(fRatesCanv, SIGNAL(signalPixelDoubleClick(int)),
4230 this, SLOT(slot_CameraDoubleClick(int)));
4231 connect(fRatesCanv, SIGNAL(signalCurrentPixel(int)),
4232 this, SLOT(slot_ChoosePixelThreshold(int)));
4233 connect(fBiasCamV, SIGNAL(signalCurrentPixel(int)),
4234 this, SLOT(slot_ChooseBiasChannel(int)));
4235 connect(fBiasCamA, SIGNAL(signalCurrentPixel(int)),
4236 this, SLOT(slot_ChooseBiasChannel(int)));
4237
4238 connect(fFtmRateCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
4239 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
4240 connect(fAdcDataCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
4241 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
4242 }
4243
4244 ~FactGui()
4245 {
4246 // Unsubscribe all services
4247 for (map<string,DimInfo*>::iterator i=fServices.begin();
4248 i!=fServices.end(); i++)
4249 delete i->second;
4250
4251 // This is allocated as a chuck of chars
4252 delete [] reinterpret_cast<char*>(fEventData);
4253 }
4254};
4255
4256#endif
Note: See TracBrowser for help on using the repository browser.