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

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