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

Last change on this file since 16876 was 16801, checked in by tbretz, 11 years ago
Replaced the new invalid FTM::State::kConfigured with Configured1 and Configured2
File size: 138.8 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::kConfigured1 ||
2587 s.index==FTM::State::kConfigured2;
2588
2589 if (s.index<FTM::State::kDisconnected) // No Dim connection
2590 SetLedColor(fStatusFTMLed, kLedGray, time);
2591 if (s.index==FTM::State::kDisconnected) // Dim connection / FTM disconnected
2592 SetLedColor(fStatusFTMLed, kLedYellow, time);
2593 if (s.index==FTM::State::kConnected ||
2594 s.index==FTM::State::kIdle ||
2595 configuring) // Dim connection / FTM connected
2596 SetLedColor(fStatusFTMLed, kLedGreen, time);
2597 if (s.index==FTM::State::kTriggerOn) // Dim connection / FTM connected
2598 SetLedColor(fStatusFTMLed, kLedGreenCheck, time);
2599 if (s.index==FTM::State::kConnected ||
2600 s.index==FTM::State::kIdle) // Dim connection / FTM connected
2601 enable = true;
2602 if (s.index>=FTM::State::kConfigError1) // Dim connection / FTM connected
2603 SetLedColor(fStatusFTMLed, kLedGreenWarn, time);
2604
2605 fFtmStartRun->setEnabled(!configuring && enable);
2606 fFtmStopRun->setEnabled(!configuring && (enable || s.index==FTM::State::kTriggerOn));
2607
2608 fTriggerWidget->setEnabled(enable);
2609 fFtuGroupEnable->setEnabled(enable);
2610 fRatesControls->setEnabled(enable);
2611 fFtuWidget->setEnabled(s.index>FTM::State::kDisconnected);
2612
2613 if (s.index>=FTM::State::kConnected)
2614 SetFtuStatusLed(time);
2615 else
2616 {
2617 SetLedColor(fStatusFTULed, kLedGray, time);
2618 fStatusFTULabel->setText("Offline");
2619 fStatusFTULabel->setToolTip("FTM is not online.");
2620 }
2621 }
2622
2623 if (server=="FAD_CONTROL")
2624 {
2625 fStatusFADLabel->setText(s.name.c_str());
2626 fStatusFADLabel->setToolTip(s.comment.c_str());
2627
2628 bool enable = false;
2629
2630 if (s.index<FAD::State::kOffline) // No Dim connection
2631 {
2632 SetLedColor(fStatusFADLed, kLedGray, time);
2633
2634 // Timing problem - sometimes they stay gray :(
2635 //for (int i=0; i<40; i++)
2636 // SetLedColor(fFadLED[i], kLedGray, time);
2637
2638 /*
2639 fStatusEventBuilderLabel->setText("Offline");
2640 fStatusEventBuilderLabel->setToolTip("No connection to fadctrl.");
2641 fEvtBldWidget->setEnabled(false);
2642
2643 SetLedColor(fStatusEventBuilderLed, kLedGray, time);
2644 */
2645 }
2646 if (s.index==FAD::State::kOffline) // Dim connection / FTM disconnected
2647 SetLedColor(fStatusFADLed, kLedRed, time);
2648 if (s.index==FAD::State::kDisconnected) // Dim connection / FTM disconnected
2649 SetLedColor(fStatusFADLed, kLedOrange, time);
2650 if (s.index==FAD::State::kConnecting) // Dim connection / FTM disconnected
2651 {
2652 SetLedColor(fStatusFADLed, kLedYellow, time);
2653 // FIXME FIXME FIXME: The LEDs are not displayed when disabled!
2654 enable = true;
2655 }
2656 if (s.index>=FAD::State::kConnected) // Dim connection / FTM connected
2657 {
2658 SetLedColor(fStatusFADLed, kLedGreen, time);
2659 enable = true;
2660 }
2661
2662 fFadWidget->setEnabled(enable);
2663
2664 fFadStart->setEnabled (s.index==FAD::State::kOffline);
2665 fFadStop->setEnabled (s.index >FAD::State::kOffline);
2666 fFadAbort->setEnabled (s.index >FAD::State::kOffline);
2667 fFadSoftReset->setEnabled(s.index >FAD::State::kOffline);
2668 fFadHardReset->setEnabled(s.index >FAD::State::kOffline);
2669 }
2670
2671 if (server=="FSC_CONTROL")
2672 {
2673 fStatusFSCLabel->setText(s.name.c_str());
2674 fStatusFSCLabel->setToolTip(s.comment.c_str());
2675
2676 bool enable = false;
2677
2678 if (s.index<FSC::State::kDisconnected) // No Dim connection
2679 SetLedColor(fStatusFSCLed, kLedGray, time);
2680 if (s.index==FSC::State::kDisconnected) // Dim connection / FTM disconnected
2681 SetLedColor(fStatusFSCLed, kLedRed, time);
2682 if (s.index>=FSC::State::kConnected) // Dim connection / FTM disconnected
2683 {
2684 SetLedColor(fStatusFSCLed, kLedGreen, time);
2685 enable = true;
2686 }
2687
2688 fAuxWidget->setEnabled(enable);
2689 }
2690
2691 if (server=="DRIVE_CONTROL")
2692 {
2693 fStatusDriveLabel->setText(s.name.c_str());
2694 fStatusDriveLabel->setToolTip(s.comment.c_str());
2695
2696 if (s.index<Drive::State::kDisconnected) // No Dim connection
2697 SetLedColor(fStatusDriveLed, kLedGray, time);
2698 if (s.index==Drive::State::kDisconnected) // Dim connection / No connection to cosy
2699 SetLedColor(fStatusDriveLed, kLedRed, time);
2700 if (s.index==Drive::State::kConnected || s.index==Drive::State::kNotReady || s.index==Drive::State::kLocked) // Not Ready
2701 SetLedColor(fStatusDriveLed, kLedGreenBar, time);
2702 if (s.index==Drive::State::kConnected || s.index==Drive::State::kArmed) // Connected / Armed
2703 SetLedColor(fStatusDriveLed, kLedGreen, time);
2704 if (s.index==Drive::State::kMoving) // Moving
2705 SetLedColor(fStatusDriveLed, kLedInProgress, time);
2706 if (s.index==Drive::State::kTracking || s.index==Drive::State::kOnTrack) // Tracking
2707 SetLedColor(fStatusDriveLed, kLedGreenCheck, time);
2708 if (s.index>=0xff) // Error
2709 SetLedColor(fStatusDriveLed, kLedGreenWarn, time);
2710 }
2711
2712 if (server=="BIAS_CONTROL")
2713 {
2714 fStatusBiasLabel->setText(s.name.c_str());
2715 fStatusBiasLabel->setToolTip(s.comment.c_str());
2716
2717 if (s.index<1) // No Dim connection
2718 SetLedColor(fStatusBiasLed, kLedGray, time);
2719 if (s.index==BIAS::State::kDisconnected) // Dim connection / FTM disconnected
2720 SetLedColor(fStatusBiasLed, kLedRed, time);
2721 if (s.index==BIAS::State::kConnecting || s.index==BIAS::State::kInitializing) // Connecting / Initializing
2722 SetLedColor(fStatusBiasLed, kLedOrange, time);
2723 if (s.index==BIAS::State::kVoltageOff) // At reference
2724 SetLedColor(fStatusBiasLed, kLedGreenBar, time);
2725 if (s.index==BIAS::State::kNotReferenced) // At reference
2726 SetLedColor(fStatusBiasLed, kLedGreenWarn, time);
2727 if (s.index==BIAS::State::kRamping) // Ramping
2728 SetLedColor(fStatusBiasLed, kLedInProgress, time);
2729 if (s.index==BIAS::State::kVoltageOn) // At reference
2730 SetLedColor(fStatusBiasLed, kLedGreenCheck, time);
2731 if (s.index==BIAS::State::kOverCurrent) // Over current
2732 SetLedColor(fStatusBiasLed, kLedWarnBorder, time);
2733 if (s.index==BIAS::State::kExpertMode) // ExpertMode
2734 SetLedColor(fStatusBiasLed, kLedWarnTriangleBorder, time);
2735
2736 fBiasWidget->setEnabled(s.index>=BIAS::State::kInitializing);
2737 }
2738
2739 if (server=="FEEDBACK")
2740 {
2741 fStatusFeedbackLabel->setText(s.name.c_str());
2742 fStatusFeedbackLabel->setToolTip(s.comment.c_str());
2743
2744 const bool connected = s.index> Feedback::State::kConnecting;
2745 const bool idle = s.index>=Feedback::State::kTempCtrlIdle && s.index<=Feedback::State::kCurrentCtrlIdle;
2746 const bool running = s.index>=Feedback::State::kTempCtrlRunning && s.index<=Feedback::State::kCurrentCtrlRunning;
2747 const bool calib = s.index==Feedback::State::kCalibrating;
2748
2749 if (s.index<=Feedback::State::kConnecting) // NoDim / Disconnected
2750 SetLedColor(fStatusFeedbackLed, kLedRed, time);
2751 if (s.index<Feedback::State::kDisconnected) // No Dim connection
2752 SetLedColor(fStatusFeedbackLed, kLedGray, time);
2753 if (s.index==Feedback::State::kConnecting) // Connecting
2754 SetLedColor(fStatusFeedbackLed, kLedOrange, time);
2755 if (connected) // Connected
2756 SetLedColor(fStatusFeedbackLed, kLedYellow, time);
2757 if (idle)
2758 SetLedColor(fStatusFeedbackLed, kLedGreen, time);
2759 if (running)
2760 SetLedColor(fStatusFeedbackLed, kLedGreenCheck, time);
2761 if (calib)
2762 SetLedColor(fStatusFeedbackLed, kLedInProgress, time);
2763
2764 fFeedbackWidget->setEnabled(connected);
2765
2766 fFeedbackCalibrate->setEnabled(s.index==Feedback::State::kConnectedFSC || s.index==Feedback::State::kConnected);
2767 fFeedbackTempStart->setEnabled(s.index==Feedback::State::kConnectedFSC || s.index==Feedback::State::kConnected);
2768
2769 fFeedbackStop->setEnabled(s.index>Feedback::State::kConnected);
2770
2771 fFeedbackTempOffset->setEnabled(s.index<=Feedback::State::kConnected);
2772 fFeedbackOutputEnable->setEnabled(s.index<Feedback::State::kTempCtrlRunning);
2773 fFeedbackOutputDisable->setEnabled(running);
2774
2775 const bool enable =
2776 s.index!=Feedback::State::kTempCtrlIdle ||
2777 s.index!=Feedback::State::kCurrentCtrlIdle ||
2778 s.index!=Feedback::State::kTempCtrlRunning ||
2779 s.index!=Feedback::State::kCurrentCtrlRunning;
2780
2781 fFeedbackFrameLeft->setEnabled(enable);
2782 fFeedbackCanvLeft->setEnabled(enable);
2783 }
2784
2785 if (server=="RATE_CONTROL")
2786 {
2787 fStatusRateControlLabel->setText(s.name.c_str());
2788 fStatusRateControlLabel->setToolTip(s.comment.c_str());
2789
2790 if (s.index==RateControl::State::kInProgress)
2791 SetLedColor(fStatusRateControlLed, kLedGreenCheck, time);
2792 if (s.index==RateControl::State::kGlobalThresholdSet)
2793 SetLedColor(fStatusRateControlLed, kLedGreen, time);
2794 if (s.index==RateControl::State::kSettingGlobalThreshold)
2795 SetLedColor(fStatusRateControlLed, kLedInProgress, time);
2796 if (s.index==RateControl::State::kConnected)
2797 SetLedColor(fStatusRateControlLed, kLedGreenBar, time);
2798 if (s.index==RateControl::State::kConnecting)
2799 SetLedColor(fStatusRateControlLed, kLedOrange, time);
2800 if (s.index<RateControl::State::kConnecting)
2801 SetLedColor(fStatusRateControlLed, kLedRed, time);
2802 if (s.index<RateControl::State::kDisconnected)
2803 SetLedColor(fStatusRateControlLed, kLedGray, time);
2804 }
2805
2806 if (server=="DATA_LOGGER")
2807 {
2808 fStatusLoggerLabel->setText(s.name.c_str());
2809 fStatusLoggerLabel->setToolTip(s.comment.c_str());
2810
2811 bool enable = true;
2812
2813 if (s.index<30) // Ready/Waiting
2814 SetLedColor(fStatusLoggerLed, kLedYellow, time);
2815 if (s.index==30) // Ready/Waiting
2816 SetLedColor(fStatusLoggerLed, kLedGreen, time);
2817 if (s.index<-1) // Offline
2818 {
2819 SetLedColor(fStatusLoggerLed, kLedGray, time);
2820 enable = false;
2821 }
2822 if (s.index>=0x100) // Error
2823 SetLedColor(fStatusLoggerLed, kLedRed, time);
2824 if (s.index==40) // Logging
2825 SetLedColor(fStatusLoggerLed, kLedGreen, time);
2826
2827 fLoggerWidget->setEnabled(enable);
2828 fLoggerStart->setEnabled(s.index>-1 && s.index<30);
2829 fLoggerStop->setEnabled(s.index>=30);
2830 }
2831
2832 if (server=="MAGIC_WEATHER")
2833 {
2834 fStatusWeatherLabel->setText(s.name.c_str());
2835
2836 if (s.index==MagicWeather::State::kReceiving)
2837 SetLedColor(fStatusWeatherLed, kLedGreen, time);
2838 if (s.index<MagicWeather::State::kReceiving)
2839 SetLedColor(fStatusWeatherLed, kLedRed, time);
2840 if (s.index<MagicWeather::State::kConnected)
2841 SetLedColor(fStatusWeatherLed, kLedGray, time);
2842 }
2843
2844 if (server=="CHAT")
2845 {
2846 fStatusChatLabel->setText(s.name.c_str());
2847
2848 fChatOnline = s.index==0;
2849
2850 SetLedColor(fStatusChatLed, fChatOnline ? kLedGreen : kLedGray, time);
2851
2852 fChatSend->setEnabled(fChatOnline);
2853 fChatMessage->setEnabled(fChatOnline);
2854 }
2855
2856 if (server=="RATESCAN")
2857 fRateScanControls->setEnabled(s.index>=RateScan::State::kConnected);
2858
2859 if (server=="SCHEDULER")
2860 {
2861 fStatusSchedulerLabel->setText(s.name.c_str());
2862
2863 SetLedColor(fStatusSchedulerLed, s.index>=0 ? kLedGreen : kLedRed, time);
2864 }
2865 }
2866
2867 void on_fTabWidget_currentChanged(int which)
2868 {
2869 if (fTabWidget->tabText(which)=="Chat")
2870 fTabWidget->setTabIcon(which, QIcon());
2871 }
2872
2873 void handleWrite(const Time &time, const string &text, int qos)
2874 {
2875 stringstream out;
2876
2877 if (text.substr(0, 6)=="CHAT: ")
2878 {
2879 if (qos==MessageImp::kDebug)
2880 return;
2881
2882 out << "<font size='-1' color='navy'>[<B>";
2883 out << time.GetAsStr("%H:%M:%S");
2884 out << "</B>]</FONT> " << text.substr(6);
2885 fChatText->append(out.str().c_str());
2886
2887 if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
2888 return;
2889
2890 static int num = 0;
2891 if (num++<2)
2892 return;
2893
2894 for (int i=0; i<fTabWidget->count(); i++)
2895 if (fTabWidget->tabText(i)=="Chat")
2896 {
2897 fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
2898 break;
2899 }
2900
2901 return;
2902 }
2903
2904
2905 out << "<font style='font-family:monospace' color='";
2906
2907 switch (qos)
2908 {
2909 case kMessage: out << "black"; break;
2910 case kInfo: out << "green"; break;
2911 case kWarn: out << "#FF6600"; break;
2912 case kError: out << "maroon"; break;
2913 case kFatal: out << "maroon"; break;
2914 case kDebug: out << "navy"; break;
2915 default: out << "navy"; break;
2916 }
2917 out << "'>";
2918 out << time.GetAsStr("%H:%M:%S.%f").substr(0,12);
2919 out << " - " << text << "</font>";
2920
2921 fLogText->append(out.str().c_str());
2922
2923 if (qos>=kWarn && qos!=kDebug && qos!=kComment)
2924 fTextEdit->append(out.str().c_str());
2925 }
2926
2927 void IndicateStateChange(const Time &time, const string &server)
2928 {
2929 const State s = GetState(server, GetCurrentState(server));
2930
2931 QApplication::postEvent(this,
2932 new FunctionEvent(bind(&FactGui::handleStateChanged, this, time, server, s)));
2933 }
2934
2935 int Write(const Time &time, const string &txt, int qos)
2936 {
2937 QApplication::postEvent(this,
2938 new FunctionEvent(bind(&FactGui::handleWrite, this, time, txt, qos)));
2939
2940 return 0;
2941 }
2942
2943 // ====================== Dim infoHandler================================
2944
2945 void handleDimService(const string &txt)
2946 {
2947 fDimSvcText->append(txt.c_str());
2948 }
2949
2950 void infoHandlerService(DimInfo &info)
2951 {
2952 const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
2953
2954 stringstream dummy;
2955 const Converter conv(dummy, fmt, false);
2956
2957 const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
2958
2959 stringstream out;
2960 out << "<font size'-1' color='navy'>[";
2961 out << tm.GetAsStr("%H:%M:%S.%f").substr(0,12);
2962 out << "]</font> <B>" << info.getName() << "</B> - ";
2963
2964 bool iserr = 2;
2965 if (!conv)
2966 {
2967 out << "Compilation of format string '" << fmt << "' failed!";
2968 }
2969 else
2970 {
2971 try
2972 {
2973 const string dat = info.getSize()==0 ? "&lt;empty&gt;" : conv.GetString(info.getData(), info.getSize());
2974 out << dat;
2975 iserr = info.getSize()==0;
2976 }
2977 catch (const runtime_error &e)
2978 {
2979 out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
2980 }
2981 }
2982
2983 // srand(hash<string>()(string(info.getName())));
2984 // int bg = rand()&0xffffff;
2985
2986 int bg = hash<string>()(string(info.getName()));
2987
2988 // allow only light colors
2989 bg = ~(bg&0x1f1f1f)&0xffffff;
2990
2991 if (iserr==2)
2992 bg = 0xffffff;
2993
2994 stringstream bgcol;
2995 bgcol << hex << setfill('0') << setw(6) << bg;
2996
2997 const string col = iserr==0 ? "black" : (iserr==1 ? "#FF6600" : "black");
2998 const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
2999
3000 QApplication::postEvent(this,
3001 new FunctionEvent(bind(&FactGui::handleDimService, this, str)));
3002 }
3003
3004 void CallInfoHandler(void (FactGui::*handler)(const DimData&), const DimData &d)
3005 {
3006 fInHandler = true;
3007 (this->*handler)(d);
3008 fInHandler = false;
3009 }
3010
3011 /*
3012 void CallInfoHandler(const boost::function<void()> &func)
3013 {
3014 // This ensures that newly received values are not sent back to the emitter
3015 // because changing the value emits the valueChanged signal (or similar)
3016 fInHandler = true;
3017 func();
3018 fInHandler = false;
3019 }*/
3020
3021 void PostInfoHandler(void (FactGui::*handler)(const DimData&))
3022 {
3023 //const boost::function<void()> f = boost::bind(handler, this, DimData(getInfo()));
3024
3025 FunctionEvent *evt = new FunctionEvent(bind(&FactGui::CallInfoHandler, this, handler, DimData(getInfo())));
3026 // FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, f));
3027 // FunctionEvent *evt = new FunctionEvent(boost::bind(handler, this, DimData(getInfo()))));
3028
3029 QApplication::postEvent(this, evt);
3030 }
3031
3032 void infoHandler()
3033 {
3034 // Initialize the time-stamp (what a weird workaround...)
3035 if (getInfo())
3036 getInfo()->getTimestamp();
3037
3038 if (getInfo()==&fDimDNS)
3039 return PostInfoHandler(&FactGui::handleDimDNS);
3040#ifdef DEBUG_DIM
3041 cout << "HandleDimInfo " << getInfo()->getName() << endl;
3042#endif
3043 if (getInfo()==&fDimLoggerStats)
3044 return PostInfoHandler(&FactGui::handleLoggerStats);
3045
3046// if (getInfo()==&fDimFadFiles)
3047// return PostInfoHandler(&FactGui::handleFadFiles);
3048
3049 if (getInfo()==&fDimFadWriteStats)
3050 return PostInfoHandler(&FactGui::handleFadWriteStats);
3051
3052 if (getInfo()==&fDimFadConnections)
3053 return PostInfoHandler(&FactGui::handleFadConnections);
3054
3055 if (getInfo()==&fDimFadFwVersion)
3056 return PostInfoHandler(&FactGui::handleFadFwVersion);
3057
3058 if (getInfo()==&fDimFadRunNumber)
3059 return PostInfoHandler(&FactGui::handleFadRunNumber);
3060
3061 if (getInfo()==&fDimFadDNA)
3062 return PostInfoHandler(&FactGui::handleFadDNA);
3063
3064 if (getInfo()==&fDimFadTemperature)
3065 return PostInfoHandler(&FactGui::handleFadTemperature);
3066
3067 if (getInfo()==&fDimFadRefClock)
3068 return PostInfoHandler(&FactGui::handleFadRefClock);
3069
3070 if (getInfo()==&fDimFadRoi)
3071 return PostInfoHandler(&FactGui::handleFadRoi);
3072
3073 if (getInfo()==&fDimFadDac)
3074 return PostInfoHandler(&FactGui::handleFadDac);
3075
3076 if (getInfo()==&fDimFadDrsCalibration)
3077 return PostInfoHandler(&FactGui::handleFadDrsCalibration);
3078
3079 if (getInfo()==&fDimFadPrescaler)
3080 return PostInfoHandler(&FactGui::handleFadPrescaler);
3081
3082 if (getInfo()==&fDimFadStatus)
3083 return PostInfoHandler(&FactGui::handleFadStatus);
3084
3085 if (getInfo()==&fDimFadStatistics1)
3086 return PostInfoHandler(&FactGui::handleFadStatistics1);
3087
3088 //if (getInfo()==&fDimFadStatistics2)
3089 // return PostInfoHandler(&FactGui::handleFadStatistics2);
3090
3091 if (getInfo()==&fDimFadFileFormat)
3092 return PostInfoHandler(&FactGui::handleFadFileFormat);
3093
3094 if (getInfo()==&fDimFadEvents)
3095 return PostInfoHandler(&FactGui::handleFadEvents);
3096
3097 if (getInfo()==&fDimFadRuns)
3098 return PostInfoHandler(&FactGui::handleFadRuns);
3099
3100 if (getInfo()==&fDimFadStartRun)
3101 return PostInfoHandler(&FactGui::handleFadStartRun);
3102
3103 if (getInfo()==&fDimFadRawData)
3104 return PostInfoHandler(&FactGui::handleFadRawData);
3105
3106 if (getInfo()==&fDimFadEventData)
3107 return PostInfoHandler(&FactGui::handleFadEventData);
3108
3109/*
3110 if (getInfo()==&fDimFadSetup)
3111 return PostInfoHandler(&FactGui::handleFadSetup);
3112*/
3113 if (getInfo()==&fDimLoggerFilenameNight)
3114 return PostInfoHandler(&FactGui::handleLoggerFilenameNight);
3115
3116 if (getInfo()==&fDimLoggerNumSubs)
3117 return PostInfoHandler(&FactGui::handleLoggerNumSubs);
3118
3119 if (getInfo()==&fDimLoggerFilenameRun)
3120 return PostInfoHandler(&FactGui::handleLoggerFilenameRun);
3121
3122 if (getInfo()==&fDimFtmTriggerRates)
3123 return PostInfoHandler(&FactGui::handleFtmTriggerRates);
3124
3125 if (getInfo()==&fDimFtmCounter)
3126 return PostInfoHandler(&FactGui::handleFtmCounter);
3127
3128 if (getInfo()==&fDimFtmDynamicData)
3129 return PostInfoHandler(&FactGui::handleFtmDynamicData);
3130
3131 if (getInfo()==&fDimFtmPassport)
3132 return PostInfoHandler(&FactGui::handleFtmPassport);
3133
3134 if (getInfo()==&fDimFtmFtuList)
3135 return PostInfoHandler(&FactGui::handleFtmFtuList);
3136
3137 if (getInfo()==&fDimFtmStaticData)
3138 return PostInfoHandler(&FactGui::handleFtmStaticData);
3139
3140 if (getInfo()==&fDimFtmError)
3141 return PostInfoHandler(&FactGui::handleFtmError);
3142
3143 if (getInfo()==&fDimFscTemp)
3144 return PostInfoHandler(&FactGui::handleFscTemp);
3145
3146 if (getInfo()==&fDimFscVolt)
3147 return PostInfoHandler(&FactGui::handleFscVolt);
3148
3149 if (getInfo()==&fDimFscCurrent)
3150 return PostInfoHandler(&FactGui::handleFscCurrent);
3151
3152 if (getInfo()==&fDimFscHumidity)
3153 return PostInfoHandler(&FactGui::handleFscHumidity);
3154
3155 if (getInfo()==&fDimBiasNominal)
3156 return PostInfoHandler(&FactGui::handleBiasNominal);
3157
3158 if (getInfo()==&fDimBiasVolt)
3159 return PostInfoHandler(&FactGui::handleBiasVolt);
3160
3161 if (getInfo()==&fDimBiasDac)
3162 return PostInfoHandler(&FactGui::handleBiasDac);
3163
3164 if (getInfo()==&fDimBiasCurrent)
3165 return PostInfoHandler(&FactGui::handleBiasCurrent);
3166
3167 if (getInfo()==&fDimFeedbackReference)
3168 return PostInfoHandler(&FactGui::handleFeedbackReference);
3169
3170 if (getInfo()==&fDimFeedbackDeviation)
3171 return PostInfoHandler(&FactGui::handleFeedbackDeviation);
3172
3173 if (getInfo()==&fDimFeedbackCalibration)
3174 return PostInfoHandler(&FactGui::handleFeedbackCalibration);
3175
3176 if (getInfo()==&fDimRateScan)
3177 return PostInfoHandler(&FactGui::handleRateScan);
3178
3179 if (getInfo()==&fDimMagicWeather)
3180 return PostInfoHandler(&FactGui::handleMagicWeather);
3181
3182// if (getInfo()==&fDimFadFiles)
3183// return PostInfoHandler(&FactGui::handleFadFiles);
3184
3185 for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
3186 if (i->second==getInfo())
3187 {
3188 infoHandlerService(*i->second);
3189 return;
3190 }
3191
3192 //DimNetwork::infoHandler();
3193 }
3194
3195
3196 // ======================================================================
3197
3198 bool event(QEvent *evt)
3199 {
3200 if (dynamic_cast<FunctionEvent*>(evt))
3201 return static_cast<FunctionEvent*>(evt)->Exec();
3202
3203 if (dynamic_cast<CheckBoxEvent*>(evt))
3204 {
3205 const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
3206 const QStandardItem *par = item.parent();
3207 if (par)
3208 {
3209 const QString server = par->text();
3210 const QString service = item.text();
3211
3212 const string s = (server+'/'+service).toStdString();
3213
3214 if (item.checkState()==Qt::Checked)
3215 SubscribeService(s);
3216 else
3217 UnsubscribeService(s);
3218 }
3219 }
3220
3221 return MainWindow::event(evt); // unrecognized
3222 }
3223
3224 void on_fDimCmdSend_clicked()
3225 {
3226 const QString server = fDimCmdServers->currentIndex().data().toString();
3227 const QString command = fDimCmdCommands->currentIndex().data().toString();
3228 const QString arguments = fDimCmdLineEdit->displayText();
3229
3230 // FIXME: Sending a command exactly when the info Handler changes
3231 // the list it might lead to confusion.
3232 try
3233 {
3234 SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
3235 fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
3236 fDimCmdLineEdit->clear();
3237 }
3238 catch (const runtime_error &e)
3239 {
3240 stringstream txt;
3241 txt << e.what();
3242
3243 string buffer;
3244 while (getline(txt, buffer, '\n'))
3245 fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
3246 }
3247 }
3248
3249#ifdef HAVE_ROOT
3250 void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *canv)
3251 {
3252 // kMousePressEvent // TCanvas processed QEvent mousePressEvent
3253 // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
3254 // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
3255 // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
3256 // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
3257 // kEnterEvent // TCanvas processed QEvent enterEvent
3258 // kLeaveEvent // TCanvas processed QEvent leaveEvent
3259
3260 if (dynamic_cast<TCanvas*>(obj))
3261 return;
3262
3263 TQtWidget *tipped = static_cast<TQtWidget*>(sender());
3264
3265 if (evt==11/*kMouseReleaseEvent*/)
3266 return;
3267
3268 if (evt==61/*kMouseDoubleClickEvent*/)
3269 return;
3270
3271 if (obj)
3272 {
3273 // Find the object which will get picked by the GetObjectInfo
3274 // due to buffer overflows in many root-versions
3275 // in TH1 and TProfile we have to work around and implement
3276 // our own GetObjectInfo which make everything a bit more
3277 // complicated.
3278 canv->cd();
3279#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
3280 const char *objectInfo =
3281 obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
3282#else
3283 const char *objectInfo = dynamic_cast<TH1*>(obj) ?
3284 "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
3285#endif
3286
3287 QString tipText;
3288 tipText += obj->GetName();
3289 tipText += " [";
3290 tipText += obj->ClassName();
3291 tipText += "]: ";
3292 tipText += objectInfo;
3293
3294 fStatusBar->showMessage(tipText, 3000);
3295 }
3296
3297 gSystem->DispatchOneEvent(kFALSE);
3298 //gSystem->ProcessEvents();
3299 //QWhatsThis::display(tipText)
3300 }
3301
3302 void slot_RootUpdate()
3303 {
3304 gSystem->DispatchOneEvent(kFALSE);
3305 //gSystem->ProcessEvents();
3306 QTimer::singleShot(10, this, SLOT(slot_RootUpdate()));
3307 }
3308#endif
3309
3310 void ChoosePatchThreshold(Camera &cam, int isw)
3311 {
3312 cam.Reset();
3313
3314 fThresholdIdx->setValue(isw);
3315
3316 const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
3317
3318 fPatchRate->setEnabled(isw>=0);
3319 fThresholdCrate->setEnabled(isw>=0);
3320 fThresholdBoard->setEnabled(isw>=0);
3321 fThresholdPatch->setEnabled(isw>=0);
3322
3323 if (isw<0)
3324 return;
3325
3326 const int patch = ihw%4;
3327 const int board = (ihw/4)%10;
3328 const int crate = (ihw/4)/10;
3329
3330 fInChoosePatchTH = true;
3331
3332 fThresholdCrate->setValue(crate);
3333 fThresholdBoard->setValue(board);
3334 fThresholdPatch->setValue(patch);
3335
3336 fInChoosePatchTH = false;
3337
3338 fThresholdVal->setValue(fFtmStaticData.fThreshold[ihw]);
3339 fPatchRate->setValue(fTriggerRates.fPatchRate[ihw]);
3340 fBoardRate->setValue(fTriggerRates.fBoardRate[ihw/4]);
3341
3342 // Loop over the software idx of all pixels
3343// for (unsigned int i=0; i<1440; i++)
3344// if (fPatchHW[i]==ihw)
3345// cam.SetBold(i);
3346 }
3347
3348 /*
3349 void ChoosePatchBias(Camera &cam, int isw)
3350 {
3351 cam.Reset();
3352
3353 fBiasChannel->setValue(isw);
3354
3355 const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
3356
3357 fBiasCurrent->setEnabled(isw>=0);
3358 fBiasCrate->setEnabled(isw>=0);
3359 fBiasBoard->setEnabled(isw>=0);
3360 fBiasPatch->setEnabled(isw>=0);
3361
3362 if (isw<0)
3363 return;
3364
3365 const int patch = ihw%4;
3366 const int board = (ihw/4)%10;
3367 const int crate = (ihw/4)/10;
3368
3369 fInChoosePatchBias = true;
3370
3371 fBiasCrate->setValue(crate);
3372 fBiasBoard->setValue(board);
3373 fBiasPatch->setValue(patch);
3374
3375 fInChoosePatchBias = false;
3376
3377 if (fVecBias.size()>0)
3378 {
3379 // FIXME: Mapping
3380 fBiasVoltDac->setValue(fVecBias[ihw]);
3381 fBiasVolt->setValue(fVecBias[ihw]*90./4096);
3382 }
3383
3384 fBiasCurrent->setValue(cam.GetData(isw));
3385
3386 // Loop over the software idx of all pixels
3387 for (unsigned int i=0; i<1440; i++)
3388 if (fPatchHW[i]==ihw)
3389 cam.SetBold(i);
3390 }*/
3391
3392 void slot_ChoosePixelThreshold(int isw)
3393 {
3394 fPixelIdx->setValue(isw);
3395
3396 const PixelMapEntry &entry = fPixelMap.index(isw);
3397 fPixelEnable->setChecked(fFtmStaticData.IsEnabled(entry.hw()));
3398 }
3399
3400 void slot_CameraDoubleClick(int isw)
3401 {
3402 fPixelIdx->setValue(isw);
3403
3404 const PixelMapEntry &entry = fPixelMap.index(isw);
3405 Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", uint16_t(entry.hw()));
3406 }
3407
3408 void slot_CameraMouseMove(int isw)
3409 {
3410 const PixelMapEntry &entry = fPixelMap.index(isw);
3411
3412 QString tipText;
3413 tipText += fRatesCanv->GetName();
3414 ostringstream str;
3415 str << setfill('0') <<
3416 " || HW: " << entry.crate() << "|" << entry.board() << "|" << entry.patch() << "|" << entry.pixel() << " (crate|board|patch|pixel)" <<
3417 " || HV: " << entry.hv_board << "|" << setw(2) << entry.hv_channel << " (board|channel)" <<
3418 " || ID: " << isw;
3419
3420
3421 tipText += str.str().c_str();
3422 fStatusBar->showMessage(tipText, 3000);
3423 }
3424
3425 /*
3426 void on_fThresholdIdx_valueChanged(int isw)
3427 {
3428 // fRatesCanv->SetBold(isw);
3429 // fRatesCanv->updateGL();
3430 }*/
3431
3432 /*
3433 void UpdateThresholdIdx()
3434 {
3435 if (fInChoosePatchTH)
3436 return;
3437
3438 const int crate = fThresholdCrate->value();
3439 const int board = fThresholdBoard->value();
3440 const int patch = fThresholdPatch->value();
3441
3442 const int ihw = patch + board*4 + crate*40;
3443
3444 int isw = 0;
3445 for (; isw<160; isw++)
3446 if (ihw==fPatchMapHW[isw])
3447 break;
3448
3449 on_fThresholdIdx_valueChanged(isw);
3450 }*/
3451
3452 void on_fPixelIdx_valueChanged(int isw)
3453 {
3454 int ii = 0;
3455 for (; ii<160; ii++)
3456 if (fPixelMap.index(isw).hw()/9==fPatchMapHW[ii])
3457 break;
3458
3459 fRatesCanv->SetWhite(isw);
3460 ChoosePatchThreshold(*fRatesCanv, ii);
3461
3462 const PixelMapEntry &entry = fPixelMap.index(isw);
3463 fPixelEnable->setChecked(fFtmStaticData.IsEnabled(entry.hw()));
3464 }
3465
3466 // ------------------- Bias display ---------------------
3467
3468 void UpdateBiasValues()
3469 {
3470 const int b = fBiasHvBoard->value();
3471 const int c = fBiasHvChannel->value();
3472
3473 const int ihw = b*32+c;
3474
3475 const double offset = fVecBiasCalibOffset.size()>0 ? fVecBiasCalibOffset[ihw] : 0;
3476
3477
3478 if (fVecBiasDac.size()>0)
3479 {
3480 fBiasVoltCur->setValue(fVecBiasDac[ihw]*90./4096-offset);
3481 fBiasVoltRef->setValue(fVecBiasDac[ihw+416]*90./4096-offset);
3482
3483 SetLedColor(fBiasNominalLed,
3484 fVecBiasDac[ihw]==fVecBiasDac[ihw+416]?kLedGreen:kLedRed, Time());
3485 }
3486
3487 if (fVecBiasCurrent.size()>0)
3488 {
3489 double val = abs(fVecBiasCurrent[ihw]) * 5000./4096;
3490 if (fBiasOffsets.size()>0 && fVecBiasVolt.size()>0)
3491 val -= fVecBiasVolt[ihw]/fBiasOffsets[ihw]*1e6;
3492
3493 fBiasCurrent->setValue(val);
3494 SetLedColor(fBiasOverCurrentLed,
3495 fVecBiasCurrent[ihw]<0?kLedRed:kLedGreen, Time());
3496 }
3497
3498 if (fBiasOffsets.size()>0 && fVecBiasVolt.size()>0)
3499 fBiasOffset->setValue(fVecBiasVolt[ihw]/fBiasOffsets[ihw]*1e6);
3500
3501 fBiasOffset->setEnabled(fBiasOffsets.size()>0 && fVecBiasVolt.size()>0);
3502 }
3503
3504 void UpdateBiasCam(const PixelMapEntry &entry)
3505 {
3506 fInChooseBiasCam = true;
3507
3508 fBiasCamCrate->setValue(entry.crate());
3509 fBiasCamBoard->setValue(entry.board());
3510 fBiasCamPatch->setValue(entry.patch());
3511 fBiasCamPixel->setValue(entry.pixel());
3512
3513 fInChooseBiasCam = false;
3514 }
3515
3516 void BiasHvChannelChanged()
3517 {
3518 if (fInChooseBiasHv)
3519 return;
3520
3521 const int b = fBiasHvBoard->value();
3522 const int ch = fBiasHvChannel->value();
3523
3524 // FIXME: Mark corresponding patch in camera
3525 const PixelMapEntry &entry = fPixelMap.hv(b, ch);
3526 fBiasCamV->SetWhite(entry.index);
3527 fBiasCamA->SetWhite(entry.index);
3528 fBiasCamV->updateCamera();
3529 fBiasCamA->updateCamera();
3530
3531 UpdateBiasCam(entry);
3532 UpdateBiasValues();
3533 }
3534
3535 void UpdateBiasHv(const PixelMapEntry &entry)
3536 {
3537 fInChooseBiasHv = true;
3538
3539 fBiasHvBoard->setValue(entry.hv_board);
3540 fBiasHvChannel->setValue(entry.hv_channel);
3541
3542 fInChooseBiasHv = false;
3543 }
3544
3545 void BiasCamChannelChanged()
3546 {
3547 if (fInChooseBiasCam)
3548 return;
3549
3550 const int crate = fBiasCamCrate->value();
3551 const int board = fBiasCamBoard->value();
3552 const int patch = fBiasCamPatch->value();
3553 const int pixel = fBiasCamPixel->value();
3554
3555 // FIXME: Display corresponding patches
3556 const PixelMapEntry &entry = fPixelMap.cbpx(crate, board, patch, pixel);
3557 fBiasCamV->SetWhite(entry.index);
3558 fBiasCamA->SetWhite(entry.index);
3559 fBiasCamV->updateCamera();
3560 fBiasCamA->updateCamera();
3561
3562 UpdateBiasHv(entry);
3563 UpdateBiasValues();
3564 }
3565
3566 void slot_ChooseBiasChannel(int isw)
3567 {
3568 const PixelMapEntry &entry = fPixelMap.index(isw);
3569
3570 UpdateBiasHv(entry);
3571 UpdateBiasCam(entry);
3572 UpdateBiasValues();
3573 }
3574
3575 void on_fBiasDispRefVolt_stateChanged(int = 0)
3576 {
3577 // FIXME: Display patches for which ref==cur
3578
3579 valarray<double> dat(0., 1440);
3580
3581 int offset = 0;
3582 if (!fBiasDispRefVolt->isChecked())
3583 fBiasCamV->setTitle("Applied BIAS voltage");
3584 else
3585 {
3586 fBiasCamV->setTitle("Reference BIAS voltage");
3587 offset = 416;
3588 }
3589
3590 if (fVecBiasDac.size()>0)
3591 {
3592 for (int i=0; i<1440; i++)
3593 {
3594 const PixelMapEntry &entry = fPixelMap.index(i);
3595 dat[i] = fVecBiasDac[entry.hv()+offset]*90./4096;
3596
3597 if (fVecBiasCalibOffset.size()>0)
3598 dat[i] -= fVecBiasCalibOffset[entry.hv()];
3599
3600 fBiasCamV->highlightPixel(i, fVecBiasDac[entry.hv()]!=fVecBiasDac[entry.hv()+416]);
3601 }
3602
3603 fBiasCamV->SetData(dat);
3604 }
3605
3606 fBiasCamV->updateCamera();
3607 }
3608
3609 // ------------------------------------------------------
3610
3611 void on_fPixelEnable_stateChanged(int b)
3612 {
3613 if (fInHandler)
3614 return;
3615
3616 const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
3617
3618 Dim::SendCommand(b==Qt::Unchecked ?
3619 "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
3620 uint16_t(entry.hw()));
3621 }
3622
3623 void on_fPixelDisableOthers_clicked()
3624 {
3625 const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
3626 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PIXELS_EXCEPT", uint16_t(entry.hw()));
3627 }
3628
3629 void on_fThresholdDisableOthers_clicked()
3630 {
3631 const int16_t isw = fThresholdIdx->value();
3632 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3633 if (ihw<0)
3634 return;
3635
3636 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PATCHES_EXCEPT", ihw);
3637 }
3638
3639 void on_fThresholdEnablePatch_clicked()
3640 {
3641 const int16_t isw = fThresholdIdx->value();
3642 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3643 if (ihw<0)
3644 return;
3645
3646 Dim::SendCommand("FTM_CONTROL/ENABLE_PATCH", ihw);
3647 }
3648
3649 void on_fThresholdDisablePatch_clicked()
3650 {
3651 const int16_t isw = fThresholdIdx->value();
3652 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3653 if (ihw<0)
3654 return;
3655
3656 Dim::SendCommand("FTM_CONTROL/DISABLE_PATCH", ihw);
3657 }
3658
3659 void on_fThresholdVal_valueChanged(int v)
3660 {
3661 fThresholdVolt->setValue(2500./4095*v);
3662
3663 const int32_t isw = fThresholdIdx->value();
3664 const int32_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3665
3666 const int32_t d[2] = { ihw, v };
3667
3668 if (!fInHandler)
3669 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
3670 }
3671
3672 TGraph fGraphFtmTemp[4];
3673 TGraph fGraphFtmRate;
3674 TGraph fGraphPatchRate[160];
3675 TGraph fGraphBoardRate[40];
3676
3677#ifdef HAVE_ROOT
3678 TH1 *DrawTimeFrame(const char *ytitle)
3679 {
3680 const double tm = Time().RootTime();
3681
3682 TH1F *h=new TH1F("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
3683 h->SetDirectory(0);
3684 h->SetBit(kCanDelete);
3685 h->SetStats(kFALSE);
3686// h.SetMinimum(0);
3687// h.SetMaximum(1);
3688 h->SetXTitle("Time");
3689 h->SetYTitle(ytitle);
3690 h->GetXaxis()->CenterTitle();
3691 h->GetYaxis()->CenterTitle();
3692 h->GetXaxis()->SetTimeDisplay(true);
3693 h->GetXaxis()->SetTimeFormat("%Mh%S'%F1995-01-01 00:00:00 GMT");
3694 h->GetXaxis()->SetLabelSize(0.025);
3695 h->GetYaxis()->SetLabelSize(0.025);
3696 h->GetYaxis()->SetTitleOffset(1.2);
3697 // h.GetYaxis()->SetTitleSize(1.2);
3698 return h;
3699 }
3700#endif
3701
3702 pair<string,string> Split(const string &str) const
3703 {
3704 const size_t p = str.find_first_of('|');
3705 if (p==string::npos)
3706 return make_pair(str, "");
3707
3708 return make_pair(str.substr(0, p), str.substr(p+1));
3709 }
3710
3711public:
3712 FactGui(Configuration &conf) :
3713 fFtuStatus(40),
3714 /*fPixelMapHW(1440),*/ fPatchMapHW(160),
3715 fInChoosePatchTH(false),
3716 fInChooseBiasHv(false), fInChooseBiasCam(false),
3717 fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
3718 //-
3719 fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
3720 fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHTLY", (void*)NULL, 0, this),
3721 fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", (void*)NULL, 0, this),
3722 fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", (void*)NULL, 0, this),
3723 //-
3724 fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
3725 fDimFtmTriggerRates ("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this),
3726 fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
3727 fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
3728 fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
3729 fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this),
3730 fDimFtmCounter ("FTM_CONTROL/COUNTER", (void*)NULL, 0, this),
3731 //-
3732 fDimFadWriteStats ("FAD_CONTROL/STATS", (void*)NULL, 0, this),
3733 fDimFadStartRun ("FAD_CONTROL/START_RUN", (void*)NULL, 0, this),
3734 fDimFadRuns ("FAD_CONTROL/RUNS", (void*)NULL, 0, this),
3735 fDimFadEvents ("FAD_CONTROL/EVENTS", (void*)NULL, 0, this),
3736 fDimFadRawData ("FAD_CONTROL/RAW_DATA", (void*)NULL, 0, this),
3737 fDimFadEventData ("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, this),
3738 fDimFadConnections ("FAD_CONTROL/CONNECTIONS", (void*)NULL, 0, this),
3739 fDimFadFwVersion ("FAD_CONTROL/FIRMWARE_VERSION", (void*)NULL, 0, this),
3740 fDimFadRunNumber ("FAD_CONTROL/RUN_NUMBER", (void*)NULL, 0, this),
3741 fDimFadDNA ("FAD_CONTROL/DNA", (void*)NULL, 0, this),
3742 fDimFadTemperature ("FAD_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3743 fDimFadPrescaler ("FAD_CONTROL/PRESCALER", (void*)NULL, 0, this),
3744 fDimFadRefClock ("FAD_CONTROL/REFERENCE_CLOCK", (void*)NULL, 0, this),
3745 fDimFadRoi ("FAD_CONTROL/REGION_OF_INTEREST", (void*)NULL, 0, this),
3746 fDimFadDac ("FAD_CONTROL/DAC", (void*)NULL, 0, this),
3747 fDimFadDrsCalibration ("FAD_CONTROL/DRS_CALIBRATION", (void*)NULL, 0, this),
3748 fDimFadStatus ("FAD_CONTROL/STATUS", (void*)NULL, 0, this),
3749 fDimFadStatistics1 ("FAD_CONTROL/STATISTICS1", (void*)NULL, 0, this),
3750 //fDimFadStatistics2 ("FAD_CONTROL/STATISTICS2", (void*)NULL, 0, this),
3751 fDimFadFileFormat ("FAD_CONTROL/FILE_FORMAT", (void*)NULL, 0, this),
3752 //-
3753 fDimFscTemp ("FSC_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3754 fDimFscVolt ("FSC_CONTROL/VOLTAGE", (void*)NULL, 0, this),
3755 fDimFscCurrent ("FSC_CONTROL/CURRENT", (void*)NULL, 0, this),
3756 fDimFscHumidity ("FSC_CONTROL/HUMIDITY", (void*)NULL, 0, this),
3757 //-
3758 fDimFeedbackDeviation ("FEEDBACK/DEVIATION", (void*)NULL, 0, this),
3759 fDimFeedbackReference ("FEEDBACK/REFERENCE", (void*)NULL, 0, this),
3760 fDimFeedbackCalibration("FEEDBACK/CALIBRATION", (void*)NULL, 0, this),
3761 //-
3762 fDimBiasNominal ("BIAS_CONTROL/NOMINAL", (void*)NULL, 0, this),
3763 fDimBiasVolt ("BIAS_CONTROL/VOLTAGE", (void*)NULL, 0, this),
3764 fDimBiasDac ("BIAS_CONTROL/DAC", (void*)NULL, 0, this),
3765 fDimBiasCurrent ("BIAS_CONTROL/CURRENT", (void*)NULL, 0, this),
3766 //-
3767 fDimRateScan ("RATE_SCAN/DATA", (void*)NULL, 0, this),
3768 //-
3769 fDimMagicWeather ("MAGIC_WEATHER/DATA", (void*)NULL, 0, this),
3770 //-
3771 fDimVersion(0),
3772 fFreeSpaceLogger(UINT64_MAX), fFreeSpaceData(UINT64_MAX),
3773 fEventData(0),
3774 fDrsCalibration(1440*1024*6+160*1024*2),
3775 fTimeStamp0(0)
3776 {
3777 fClockCondFreq->addItem("--- Hz", QVariant(-1));
3778 fClockCondFreq->addItem("800 MHz", QVariant(800));
3779 fClockCondFreq->addItem("1 GHz", QVariant(1000));
3780 fClockCondFreq->addItem("2 GHz", QVariant(2000));
3781 fClockCondFreq->addItem("3 GHz", QVariant(3000));
3782 fClockCondFreq->addItem("4 GHz", QVariant(4000));
3783 fClockCondFreq->addItem("5 GHz", QVariant(5000));
3784
3785 cout << "-- run counter ---" << endl;
3786 fMcpNumEvents->addItem("unlimited", QVariant(0));
3787 const vector<uint32_t> runcount = conf.Vec<uint32_t>("run-count");
3788 for (vector<uint32_t>::const_iterator it=runcount.begin(); it!=runcount.end(); it++)
3789 {
3790 cout << *it << endl;
3791 ostringstream str;
3792 str << *it;
3793 fMcpNumEvents->addItem(str.str().c_str(), QVariant(*it));
3794 }
3795
3796 cout << "-- run times ---" << endl;
3797 fMcpTime->addItem("unlimited", QVariant(0));
3798 const vector<string> runtime = conf.Vec<string>("run-time");
3799 for (vector<string>::const_iterator it=runtime.begin(); it!=runtime.end(); it++)
3800 {
3801 const pair<string,string> p = Split(*it);
3802 cout << *it << "|" << p.second << "|" << p.first << "|" << endl;
3803 fMcpTime->addItem(p.second.c_str(), QVariant(stoi(p.first)));
3804 }
3805
3806 cout << "-- run types ---" << endl;
3807 const vector<string> runtype = conf.Vec<string>("run-type");
3808 for (vector<string>::const_iterator it=runtype.begin(); it!=runtype.end(); it++)
3809 {
3810 const pair<string,string> p = Split(*it);
3811 cout << *it << "|" << p.second << "|" << p.first << "|" << endl;
3812 fMcpRunType->addItem(p.second.c_str(), QVariant(p.first.c_str()));
3813 }
3814
3815 fTriggerWidget->setEnabled(false);
3816 fFtuWidget->setEnabled(false);
3817 fFtuGroupEnable->setEnabled(false);
3818 fRatesControls->setEnabled(false);
3819 fFadWidget->setEnabled(false);
3820 fGroupEthernet->setEnabled(false);
3821 fGroupOutput->setEnabled(false);
3822 fLoggerWidget->setEnabled(false);
3823 fBiasWidget->setEnabled(false);
3824 fAuxWidget->setEnabled(false);
3825
3826 fChatSend->setEnabled(false);
3827 fChatMessage->setEnabled(false);
3828
3829 DimClient::sendCommand("CHAT/MSG", "GUI online.");
3830 // + MessageDimRX
3831
3832 // --------------------------------------------------------------------------
3833
3834 if (!fPixelMap.Read(conf.Get<string>("pixel-map-file")))
3835 {
3836 cerr << "ERROR - Problems reading " << conf.Get<string>("pixel-map-file") << endl;
3837 exit(-1);
3838 }
3839
3840 // --------------------------------------------------------------------------
3841
3842 ifstream fin3("PatchList.txt");
3843
3844 string buf;
3845
3846 int l = 0;
3847 while (getline(fin3, buf, '\n'))
3848 {
3849 buf = Tools::Trim(buf);
3850 if (buf[0]=='#')
3851 continue;
3852
3853 unsigned int softid, hardid;
3854
3855 stringstream str(buf);
3856
3857 str >> softid;
3858 str >> hardid;
3859
3860 if (softid>=fPatchMapHW.size())
3861 continue;
3862
3863 fPatchMapHW[softid] = hardid-1;
3864
3865 l++;
3866 }
3867
3868 if (l!=160)
3869 cerr << "WARNING - Problems reading PatchList.txt" << endl;
3870
3871 // --------------------------------------------------------------------------
3872
3873 fCommentsWidget->setEnabled(false);
3874
3875 static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))");
3876
3877 const string database = conf.Get<string>("CommentDB");
3878
3879 if (!database.empty())
3880 {
3881 boost::smatch what;
3882 if (!boost::regex_match(database, what, expr, boost::match_extra))
3883 throw runtime_error("Couldn't parse '"+database+"'.");
3884
3885 if (what.size()!=10)
3886 throw runtime_error("Error parsing '"+database+"'.");
3887
3888 const string user = what[2];
3889 const string passwd = what[4];
3890 const string server = what[5];
3891 const string db = what[9];
3892 const int port = atoi(string(what[7]).c_str());
3893
3894 QSqlDatabase qdb = QSqlDatabase::addDatabase("QMYSQL");
3895 qdb.setHostName(server.c_str());
3896 qdb.setDatabaseName(db.c_str());
3897 qdb.setUserName(user.c_str());
3898 qdb.setPassword(passwd.c_str());
3899 qdb.setPort(port);
3900 qdb.setConnectOptions("CLIENT_SSL=1;MYSQL_OPT_RECONNECT=1");
3901 if (qdb.open())
3902 {
3903 QSqlTableModel *model = new QSqlTableModel(fTableComments, qdb);
3904 model->setTable("runcomments");
3905 model->setEditStrategy(QSqlTableModel::OnManualSubmit);
3906
3907 const bool ok2 = model->select();
3908
3909 if (ok2)
3910 {
3911 fTableComments->setModel(model);
3912 fTableComments->resizeColumnsToContents();
3913 fTableComments->resizeRowsToContents();
3914
3915 connect(fCommentSubmit, SIGNAL(clicked()), model, SLOT(submitAll()));
3916 connect(fCommentRevert, SIGNAL(clicked()), model, SLOT(revertAll()));
3917 connect(fCommentUpdateLayout, SIGNAL(clicked()), fTableComments, SLOT(resizeColumnsToContents()));
3918 connect(fCommentUpdateLayout, SIGNAL(clicked()), fTableComments, SLOT(resizeRowsToContents()));
3919
3920 fCommentsWidget->setEnabled(true);
3921 }
3922 else
3923 cout << "\n==> ERROR: Select on table failed.\n" << endl;
3924 }
3925 else
3926 cout << "\n==> ERROR: Connection to database failed:\n "
3927 << qdb.lastError().text().toStdString() << endl << endl;
3928 }
3929
3930 // --------------------------------------------------------------------------
3931#ifdef HAVE_ROOT
3932
3933 fGraphFeedbackDev.SetLineColor(kBlue);
3934 fGraphFeedbackDev.SetMarkerColor(kBlue);
3935 fGraphFeedbackDev.SetMarkerStyle(kFullDotMedium);
3936
3937 fGraphFeedbackCmd.SetLineColor(kBlue);
3938 fGraphFeedbackCmd.SetMarkerColor(kBlue);
3939 fGraphFeedbackCmd.SetMarkerStyle(kFullDotMedium);
3940
3941 // Evolution of control deviation
3942 // Evolution of command values (bias voltage change)
3943 fGraphFeedbackDev.SetName("ControlDev");
3944 fGraphFeedbackCmd.SetName("CommandVal");
3945
3946 TCanvas *c = fFeedbackDev->GetCanvas();
3947 c->SetBorderMode(0);
3948 c->SetFrameBorderMode(0);
3949 c->SetFillColor(kWhite);
3950 c->SetRightMargin(0.03);
3951 c->SetTopMargin(0.03);
3952 c->SetGrid();
3953
3954 TH1 *hf = DrawTimeFrame("Control deviation [mV] ");
3955 hf->GetXaxis()->SetLabelSize(0.07);
3956 hf->GetYaxis()->SetLabelSize(0.07);
3957 hf->GetYaxis()->SetTitleSize(0.08);
3958 hf->GetYaxis()->SetTitleOffset(0.55);
3959 hf->GetXaxis()->SetTitle("");
3960 hf->GetYaxis()->SetRangeUser(-99, 99);
3961
3962 c->GetListOfPrimitives()->Add(hf, "");
3963 c->GetListOfPrimitives()->Add(&fGraphFeedbackDev, "LP");
3964
3965 c = fFeedbackCmd->GetCanvas();
3966 c->SetBorderMode(0);
3967 c->SetFrameBorderMode(0);
3968 c->SetFillColor(kWhite);
3969 c->SetRightMargin(0.03);
3970 c->SetTopMargin(0.03);
3971 c->SetGrid();
3972
3973 hf = DrawTimeFrame("Command delta value [mV] ");
3974 hf->GetXaxis()->SetLabelSize(0.07);
3975 hf->GetYaxis()->SetLabelSize(0.07);
3976 hf->GetYaxis()->SetTitleSize(0.08);
3977 hf->GetYaxis()->SetTitleOffset(0.55);
3978 hf->GetXaxis()->SetTitle("");
3979 hf->GetYaxis()->SetRangeUser(-99*10, 99*10);
3980
3981 c->GetListOfPrimitives()->Add(hf, "");
3982 c->GetListOfPrimitives()->Add(&fGraphFeedbackCmd, "LP");
3983
3984 // --------------------------------------------------------------------------
3985
3986 c = fRateScanCanv->GetCanvas();
3987 //c->SetBit(TCanvas::kNoContextMenu);
3988 c->SetBorderMode(0);
3989 c->SetFrameBorderMode(0);
3990 c->SetFillColor(kWhite);
3991 c->SetRightMargin(0.03);
3992 c->SetTopMargin(0.03);
3993 c->SetGrid();
3994
3995 TH1F *h=new TH1F("Frame", "", 1, 0, 1);
3996 h->SetDirectory(0);
3997 h->SetBit(kCanDelete);
3998 h->SetStats(kFALSE);
3999 h->SetXTitle("Threshold [DAC]");
4000 h->SetYTitle("Rate [Hz]");
4001 h->GetXaxis()->CenterTitle();
4002 h->GetYaxis()->CenterTitle();
4003 h->GetXaxis()->SetLabelSize(0.025);
4004 h->GetYaxis()->SetLabelSize(0.025);
4005 h->GetYaxis()->SetTitleOffset(1.2);
4006 c->GetListOfPrimitives()->Add(h, "");
4007
4008 fGraphRateScan[0].SetName("CameraRate");
4009 for (int i=0; i<40; i++)
4010 {
4011 fGraphRateScan[i+1].SetName("BoardRate");
4012 fGraphRateScan[i+1].SetMarkerStyle(kFullDotMedium);
4013 }
4014 for (int i=0; i<160; i++)
4015 {
4016 fGraphRateScan[i+41].SetName("PatchRate");
4017 fGraphRateScan[i+41].SetMarkerStyle(kFullDotMedium);
4018 }
4019
4020 fGraphRateScan[0].SetLineColor(kBlue);
4021 fGraphRateScan[0].SetMarkerColor(kBlue);
4022 fGraphRateScan[0].SetMarkerStyle(kFullDotSmall);
4023 c->GetListOfPrimitives()->Add(&fGraphRateScan[0], "LP");
4024
4025 // --------------------------------------------------------------------------
4026
4027 c = fFtmRateCanv->GetCanvas();
4028 //c->SetBit(TCanvas::kNoContextMenu);
4029 c->SetBorderMode(0);
4030 c->SetFrameBorderMode(0);
4031 c->SetFillColor(kWhite);
4032 c->SetRightMargin(0.03);
4033 c->SetTopMargin(0.03);
4034 c->SetGrid();
4035
4036 hf = DrawTimeFrame("Trigger rate [Hz]");
4037 hf->GetYaxis()->SetRangeUser(0, 1010);
4038
4039 for (int i=0; i<160; i++)
4040 {
4041 fGraphPatchRate[i].SetName("PatchRate");
4042 //fGraphPatchRate[i].SetLineColor(kBlue);
4043 //fGraphPatchRate[i].SetMarkerColor(kBlue);
4044 fGraphPatchRate[i].SetMarkerStyle(kFullDotMedium);
4045 }
4046 for (int i=0; i<40; i++)
4047 {
4048 fGraphBoardRate[i].SetName("BoardRate");
4049 //fGraphBoardRate[i].SetLineColor(kBlue);
4050 //fGraphBoardRate[i].SetMarkerColor(kBlue);
4051 fGraphBoardRate[i].SetMarkerStyle(kFullDotMedium);
4052 }
4053
4054 fGraphFtmRate.SetLineColor(kBlue);
4055 fGraphFtmRate.SetMarkerColor(kBlue);
4056 fGraphFtmRate.SetMarkerStyle(kFullDotSmall);
4057
4058 c->GetListOfPrimitives()->Add(hf, "");
4059 c->GetListOfPrimitives()->Add(&fGraphFtmRate, "LP");
4060
4061 /*
4062 TCanvas *c = fFtmTempCanv->GetCanvas();
4063 c->SetBit(TCanvas::kNoContextMenu);
4064 c->SetBorderMode(0);
4065 c->SetFrameBorderMode(0);
4066 c->SetFillColor(kWhite);
4067 c->SetRightMargin(0.03);
4068 c->SetTopMargin(0.03);
4069 c->cd();
4070 */
4071 //CreateTimeFrame("Temperature / �C");
4072
4073 fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
4074 fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
4075 fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
4076 fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
4077
4078 fGraphFtmTemp[1].SetLineColor(kBlue);
4079 fGraphFtmTemp[2].SetLineColor(kRed);
4080 fGraphFtmTemp[3].SetLineColor(kGreen);
4081
4082 fGraphFtmTemp[1].SetMarkerColor(kBlue);
4083 fGraphFtmTemp[2].SetMarkerColor(kRed);
4084 fGraphFtmTemp[3].SetMarkerColor(kGreen);
4085
4086 //fGraphFtmTemp[0].Draw("LP");
4087 //fGraphFtmTemp[1].Draw("LP");
4088 //fGraphFtmTemp[2].Draw("LP");
4089 //fGraphFtmTemp[3].Draw("LP");
4090
4091 // --------------------------------------------------------------------------
4092
4093 c = fAdcDataCanv->GetCanvas();
4094 //c->SetBit(TCanvas::kNoContextMenu);
4095 c->SetBorderMode(0);
4096 c->SetFrameBorderMode(0);
4097 c->SetFillColor(kWhite);
4098 c->SetRightMargin(0.10);
4099 c->SetGrid();
4100 //c->cd();
4101#endif
4102
4103 // --------------------------------------------------------------------------
4104 fFeedbackDevCam->assignPixelMap(fPixelMap);
4105 fFeedbackDevCam->setAutoscaleLowerLimit((fFeedbackDevMin->minimum()+0.5*fFeedbackDevMin->singleStep()));
4106 fFeedbackDevCam->SetMin(fFeedbackDevMin->value());
4107 fFeedbackDevCam->SetMax(fFeedbackDevMax->value());
4108 fFeedbackDevCam->updateCamera();
4109
4110 fFeedbackCmdCam->assignPixelMap(fPixelMap);
4111 fFeedbackCmdCam->setAutoscaleLowerLimit((fFeedbackCmdMin->minimum()+0.5*fFeedbackCmdMin->singleStep()));
4112 fFeedbackCmdCam->SetMin(fFeedbackCmdMin->value());
4113 fFeedbackCmdCam->SetMax(fFeedbackCmdMax->value());
4114 fFeedbackCmdCam->updateCamera();
4115
4116 // --------------------------------------------------------------------------
4117
4118 fBiasCamV->assignPixelMap(fPixelMap);
4119 fBiasCamV->setAutoscaleLowerLimit((fBiasVoltMin->minimum()+0.5*fBiasVoltMin->singleStep()));
4120 fBiasCamV->SetMin(fBiasVoltMin->value());
4121 fBiasCamV->SetMax(fBiasVoltMax->value());
4122 fBiasCamV->updateCamera();
4123
4124 fBiasCamA->assignPixelMap(fPixelMap);
4125 fBiasCamA->setAutoscaleLowerLimit((fBiasCurrentMin->minimum()+0.5*fBiasCurrentMin->singleStep()));
4126 fBiasCamA->SetMin(fBiasCurrentMin->value());
4127 fBiasCamA->SetMax(fBiasCurrentMax->value());
4128 fBiasCamA->updateCamera();
4129
4130 // --------------------------------------------------------------------------
4131
4132 fRatesCanv->assignPixelMap(fPixelMap);
4133 fRatesCanv->setAutoscaleLowerLimit((fRatesMin->minimum()+0.5*fRatesMin->singleStep())*0.001);
4134 fRatesCanv->SetMin(fRatesMin->value());
4135 fRatesCanv->SetMax(fRatesMax->value());
4136 fRatesCanv->updateCamera();
4137 on_fPixelIdx_valueChanged(0);
4138
4139 // --------------------------------------------------------------------------
4140
4141 fRatesCanv->setTitle("Patch rates");
4142 fRatesCanv->setUnits("Hz");
4143
4144 fBiasCamA->setTitle("BIAS current");
4145 fBiasCamA->setUnits("uA");
4146
4147 fBiasCamV->setTitle("Applied BIAS voltage");
4148 fBiasCamV->setUnits("V");
4149
4150 fEventCanv1->setTitle("Average (all slices)");
4151 fEventCanv2->setTitle("RMS (all slices)");
4152 fEventCanv3->setTitle("Maximum (all slices)");
4153 fEventCanv4->setTitle("Position of maximum (all slices)");
4154
4155 fEventCanv1->setUnits("mV");
4156 fEventCanv2->setUnits("mV");
4157 fEventCanv3->setUnits("mV");
4158 fEventCanv4->setUnits("slice");
4159
4160 // --------------------------------------------------------------------------
4161
4162 fFeedbackDevCam->setTitle("Control deviation (Pulser amplitude voltage)");
4163 fFeedbackCmdCam->setTitle("Applied voltage change (BIAS voltage)");
4164
4165 fFeedbackDevCam->setUnits("mV");
4166 fFeedbackCmdCam->setUnits("mV");
4167
4168 // --------------------------------------------------------------------------
4169
4170 QTimer::singleShot(1000, this, SLOT(slot_RootUpdate()));
4171
4172 //widget->setMouseTracking(true);
4173 //widget->EnableSignalEvents(kMouseMoveEvent);
4174
4175 fFtmRateCanv->setMouseTracking(true);
4176 fFtmRateCanv->EnableSignalEvents(kMouseMoveEvent);
4177
4178 fAdcDataCanv->setMouseTracking(true);
4179 fAdcDataCanv->EnableSignalEvents(kMouseMoveEvent);
4180
4181 fRatesCanv->setMouseTracking(true);
4182 fEventCanv1->setMouseTracking(true);
4183 fEventCanv2->setMouseTracking(true);
4184 fEventCanv3->setMouseTracking(true);
4185 fEventCanv4->setMouseTracking(true);
4186
4187 fBiasCamV->setMouseTracking(true);
4188 fBiasCamA->setMouseTracking(true);
4189
4190 fFeedbackDevCam->setMouseTracking(true);
4191 fFeedbackCmdCam->setMouseTracking(true);
4192
4193 fEventCanv1->ShowPixelCursor(true);
4194 fEventCanv2->ShowPixelCursor(true);
4195 fEventCanv3->ShowPixelCursor(true);
4196 fEventCanv4->ShowPixelCursor(true);
4197
4198 fEventCanv1->ShowPatchCursor(true);
4199 fEventCanv2->ShowPatchCursor(true);
4200 fEventCanv3->ShowPatchCursor(true);
4201 fEventCanv4->ShowPatchCursor(true);
4202
4203 fFeedbackDevCam->ShowPixelCursor(true);
4204 fFeedbackCmdCam->ShowPixelCursor(true);
4205
4206 fFeedbackDevCam->ShowPatchCursor(true);
4207 fFeedbackCmdCam->ShowPatchCursor(true);
4208
4209 connect(fRatesCanv, SIGNAL(signalPixelMoveOver(int)),
4210 this, SLOT(slot_CameraMouseMove(int)));
4211 connect(fEventCanv1, SIGNAL(signalPixelMoveOver(int)),
4212 this, SLOT(slot_CameraMouseMove(int)));
4213 connect(fEventCanv2, SIGNAL(signalPixelMoveOver(int)),
4214 this, SLOT(slot_CameraMouseMove(int)));
4215 connect(fEventCanv3, SIGNAL(signalPixelMoveOver(int)),
4216 this, SLOT(slot_CameraMouseMove(int)));
4217 connect(fEventCanv4, SIGNAL(signalPixelMoveOver(int)),
4218 this, SLOT(slot_CameraMouseMove(int)));
4219
4220 connect(fBiasCamV, SIGNAL(signalPixelMoveOver(int)),
4221 this, SLOT(slot_CameraMouseMove(int)));
4222 connect(fBiasCamA, SIGNAL(signalPixelMoveOver(int)),
4223 this, SLOT(slot_CameraMouseMove(int)));
4224
4225 connect(fFeedbackDevCam, SIGNAL(signalPixelMoveOver(int)),
4226 this, SLOT(slot_CameraMouseMove(int)));
4227 connect(fFeedbackCmdCam, SIGNAL(signalPixelMoveOver(int)),
4228 this, SLOT(slot_CameraMouseMove(int)));
4229
4230 connect(fRatesCanv, SIGNAL(signalPixelDoubleClick(int)),
4231 this, SLOT(slot_CameraDoubleClick(int)));
4232 connect(fRatesCanv, SIGNAL(signalCurrentPixel(int)),
4233 this, SLOT(slot_ChoosePixelThreshold(int)));
4234 connect(fBiasCamV, SIGNAL(signalCurrentPixel(int)),
4235 this, SLOT(slot_ChooseBiasChannel(int)));
4236 connect(fBiasCamA, SIGNAL(signalCurrentPixel(int)),
4237 this, SLOT(slot_ChooseBiasChannel(int)));
4238
4239 connect(fFtmRateCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
4240 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
4241 connect(fAdcDataCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
4242 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
4243 }
4244
4245 ~FactGui()
4246 {
4247 // Unsubscribe all services
4248 for (map<string,DimInfo*>::iterator i=fServices.begin();
4249 i!=fServices.end(); i++)
4250 delete i->second;
4251
4252 // This is allocated as a chuck of chars
4253 delete [] reinterpret_cast<char*>(fEventData);
4254 }
4255};
4256
4257#endif
Note: See TracBrowser for help on using the repository browser.