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

Last change on this file since 14782 was 14620, checked in by tbretz, 12 years ago
Adapted Led colors to som new states; do not diplay comments in the warning section
File size: 139.9 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/PixelMap.h"
24#include "src/DimData.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 /*
1563 //info about status of the main threads
1564 int32_t readStat ; //read thread
1565 int32_t procStat ; //processing thread(s)
1566 int32_t writStat ; //write thread
1567 */
1568
1569 fFadBufferMax->setValue(stat.totMem/1000000);
1570 fFadBuffer->setMaximum(stat.totMem/100);
1571 fFadBuffer->setValue((stat.maxMem>stat.totMem?stat.totMem:stat.maxMem)/100); // Max mem used in last second
1572
1573 uint32_t sum = 0;
1574 //int32_t min = 0x7fffff;
1575 //int32_t max = 0;
1576
1577 int cnt = 0;
1578 int err = 0;
1579
1580 for (int i=0; i<40; i++)
1581 {
1582 if (stat.numConn[i]!=1)
1583 continue;
1584
1585 cnt++;
1586
1587 sum += stat.rateBytes[i];
1588 err += stat.errConn[i];
1589
1590 //if (stat.rateBytes[i]<min)
1591 // min = stat.rateBytes[i];
1592 //if (stat.rateBytes[i]>max)
1593 // max = stat.rateBytes[i];
1594 }
1595
1596 fFadEvtConn->setValue(cnt);
1597 fFadEvtConnErr->setValue(err);
1598
1599 fFadEvtBufNew->setValue(stat.bufNew); // Incomplete in buffer
1600 fFadEvtBufEvt->setValue(stat.bufEvt); // Complete in buffer
1601 fFadEvtBufMax->setValue(stat.maxEvt); // Complete in buffer
1602 fFadEvtWrite->setValue(stat.evtWrite-stat.evtSkip-stat.evtErr);
1603 fFadEvtSkip->setValue(stat.evtSkip);
1604 fFadEvtErr->setValue(stat.evtErr);
1605
1606 if (stat.deltaT==0)
1607 return;
1608
1609 //fFadEthernetRateMin->setValue(min/stat.deltaT);
1610 //fFadEthernetRateMax->setValue(max/stat.deltaT);
1611 fFadEthernetRateTot->setValue(sum/stat.deltaT);
1612 fFadEthernetRateAvg->setValue(cnt==0 ? 0 : sum/cnt/stat.deltaT);
1613
1614 fFadTransmission->setValue(1000*stat.rateNew/stat.deltaT);
1615 fFadWriteRate->setValue(1000*stat.rateWrite/stat.deltaT);
1616 }
1617
1618 void handleFadStatistics2(const DimData &d)
1619 {
1620 if (!CheckSize(d, sizeof(EVT_STAT)))
1621 return;
1622
1623 //const EVT_STAT &stat = d.ref<EVT_STAT>();
1624
1625 /*
1626 //some info about what happened since start of program (or last 'reset')
1627 uint32_t reset ; //#if increased, reset all counters
1628 uint32_t numRead[MAX_SOCK] ; //how often succesfull read from N sockets per loop
1629
1630 uint64_t gotByte[NBOARDS] ; //#Bytes read per Board
1631 uint32_t gotErr[NBOARDS] ; //#Communication Errors per Board
1632
1633 uint32_t evtGet; //#new Start of Events read
1634 uint32_t evtTot; //#complete Events read
1635
1636 uint32_t evtErr; //#Events with Errors
1637 uint32_t evtSkp; //#Events incomplete (timeout)
1638
1639
1640 uint32_t procTot; //#Events processed
1641 uint32_t procErr; //#Events showed problem in processing
1642 uint32_t procTrg; //#Events accepted by SW trigger
1643 uint32_t procSkp; //#Events rejected by SW trigger
1644
1645 uint32_t feedTot; //#Events used for feedBack system
1646 uint32_t feedErr; //#Events rejected by feedBack
1647
1648 uint32_t wrtTot; //#Events written to disk
1649 uint32_t wrtErr; //#Events with write-error
1650
1651 uint32_t runOpen; //#Runs opened
1652 uint32_t runClose; //#Runs closed
1653 uint32_t runErr; //#Runs with open/close errors
1654
1655
1656 //info about current connection status
1657 uint8_t numConn[NBOARDS] ; //#Sockets succesfully open per board
1658 */
1659 }
1660
1661 void handleFadFileFormat(const DimData &d)
1662 {
1663 if (!CheckSize(d, sizeof(uint16_t)))
1664 return;
1665
1666 const uint16_t &fmt = d.get<uint16_t>();
1667
1668 SetLedColor(fFadLedFileFormatNone, fmt==FAD::kNone ?kLedGreen:kLedGray, d.time);
1669 SetLedColor(fFadLedFileFormatDebug, fmt==FAD::kDebug?kLedGreen:kLedGray, d.time);
1670 SetLedColor(fFadLedFileFormatRaw, fmt==FAD::kRaw ?kLedGreen:kLedGray, d.time);
1671 SetLedColor(fFadLedFileFormatFits, fmt==FAD::kFits ?kLedGreen:kLedGray, d.time);
1672 SetLedColor(fFadLedFileFormatCalib, fmt==FAD::kCalib?kLedGreen:kLedGray, d.time);
1673 }
1674
1675 // ===================== FTM ============================================
1676
1677 FTM::DimTriggerRates fTriggerRates;
1678
1679 void UpdateTriggerRate(const FTM::DimTriggerRates &sdata)
1680 {
1681#ifdef HAVE_ROOT
1682 TCanvas *c = fFtmRateCanv->GetCanvas();
1683
1684 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1685
1686 if (sdata.fTriggerRate<0)
1687 {
1688 fGraphFtmRate.Set(0);
1689
1690 const double tm = Time().RootTime();
1691
1692 h->SetBins(1, tm, tm+60);
1693 h->GetXaxis()->SetTimeFormat("%M'%S\"");
1694 h->GetXaxis()->SetTitle("Time");
1695
1696 c->Modified();
1697 c->Update();
1698 return;
1699 }
1700
1701 const double t1 = h->GetXaxis()->GetXmax();
1702 const double t0 = h->GetXaxis()->GetXmin();
1703
1704 const double now = t0+sdata.fTimeStamp/1000000.;
1705
1706 h->SetBins(h->GetNbinsX()+1, t0, now+1);
1707 fGraphFtmRate.SetPoint(fGraphFtmRate.GetN(), now, sdata.fTriggerRate);
1708
1709 if (t1-t0>300)
1710 {
1711 h->GetXaxis()->SetTimeFormat("%Hh%M'");
1712 h->GetXaxis()->SetTitle("Time");
1713 }
1714
1715 h->SetMinimum(0);
1716
1717 c->Modified();
1718 c->Update();
1719#endif
1720 }
1721
1722 void UpdateRatesCam(const FTM::DimTriggerRates &sdata)
1723 {
1724 if (fThresholdIdx->value()>=0)
1725 {
1726 const int isw = fThresholdIdx->value();
1727 const int ihw = fPatchMapHW[isw];
1728 fPatchRate->setValue(sdata.fPatchRate[ihw]);
1729 fBoardRate->setValue(sdata.fBoardRate[ihw/4]);
1730 }
1731
1732 const bool b = fBoardRatesEnabled->isChecked();
1733
1734 valarray<double> dat(0., 1440);
1735
1736 // fPatch converts from software id to software patch id
1737 for (int i=0; i<1440; i++)
1738 {
1739 const int ihw = fPixelMap.index(i).hw()/9;
1740 dat[i] = b ? sdata.fBoardRate[ihw/4] : sdata.fPatchRate[ihw];
1741 }
1742
1743 fRatesCanv->SetData(dat);
1744 fRatesCanv->updateCamera();
1745 }
1746
1747 int64_t fTimeStamp0;
1748
1749 void on_fBoardRatesEnabled_toggled(bool)
1750 {
1751 UpdateRatesCam(fTriggerRates);
1752 }
1753
1754 void UpdateRatesGraphs(const FTM::DimTriggerRates &sdata)
1755 {
1756#ifdef HAVE_ROOT
1757 if (fTimeStamp0<0)
1758 {
1759 fTimeStamp0 = sdata.fTimeStamp;
1760 return;
1761 }
1762
1763 TCanvas *c = fFtmRateCanv->GetCanvas();
1764
1765 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1766
1767 const double tdiff = sdata.fTimeStamp-fTimeStamp0;
1768 fTimeStamp0 = sdata.fTimeStamp;
1769
1770 if (tdiff<0)
1771 {
1772 for (int i=0; i<160; i++)
1773 fGraphPatchRate[i].Set(0);
1774 for (int i=0; i<40; i++)
1775 fGraphBoardRate[i].Set(0);
1776
1777 return;
1778 }
1779
1780 //const double t1 = h->GetXaxis()->GetXmax();
1781 const double t0 = h->GetXaxis()->GetXmin();
1782
1783 for (int i=0; i<160; i++)
1784 if (fFtuStatus[i/4]>0)
1785 fGraphPatchRate[i].SetPoint(fGraphPatchRate[i].GetN(),
1786 t0+sdata.fTimeStamp/1000000., sdata.fPatchRate[i]);
1787 for (int i=0; i<40; i++)
1788 if (fFtuStatus[i]>0)
1789 fGraphBoardRate[i].SetPoint(fGraphBoardRate[i].GetN(),
1790 t0+sdata.fTimeStamp/1000000., sdata.fBoardRate[i]);
1791
1792 c->Modified();
1793 c->Update();
1794#endif
1795 }
1796
1797 void handleFtmTriggerRates(const DimData &d)
1798 {
1799 if (!CheckSize(d, sizeof(FTM::DimTriggerRates)))
1800 return;
1801
1802 const FTM::DimTriggerRates &sdata = d.ref<FTM::DimTriggerRates>();
1803
1804 fFtmTime->setText(QString::number(sdata.fTimeStamp/1000000., 'f', 6)+ " s");
1805 fTriggerCounter->setText(QString::number(sdata.fTriggerCounter));
1806
1807 if (sdata.fTimeStamp>0)
1808 fTriggerCounterRate->setValue(1000000.*sdata.fTriggerCounter/sdata.fTimeStamp);
1809 else
1810 fTriggerCounterRate->setValue(0);
1811
1812 // ----------------------------------------------
1813
1814 fOnTime->setText(QString::number(sdata.fOnTimeCounter/1000000., 'f', 6)+" s");
1815
1816 if (sdata.fTimeStamp>0)
1817 fOnTimeRel->setValue(100.*sdata.fOnTimeCounter/sdata.fTimeStamp);
1818 else
1819 fOnTimeRel->setValue(0);
1820
1821 // ----------------------------------------------
1822
1823 UpdateTriggerRate(sdata);
1824 UpdateRatesGraphs(sdata);
1825 UpdateRatesCam(sdata);
1826
1827 fTriggerRates = sdata;
1828 }
1829
1830 void handleFtmCounter(const DimData &d)
1831 {
1832 if (!CheckSize(d, sizeof(uint32_t)*6))
1833 return;
1834
1835 const uint32_t *sdata = d.ptr<uint32_t>();
1836
1837 fFtmCounterH->setValue(sdata[0]);
1838 fFtmCounterS->setValue(sdata[1]);
1839 fFtmCounterD->setValue(sdata[2]);
1840 fFtmCounterF->setValue(sdata[3]);
1841 fFtmCounterE->setValue(sdata[4]);
1842 fFtmCounterR->setValue(sdata[5]);
1843 }
1844
1845 void handleFtmDynamicData(const DimData &d)
1846 {
1847 if (!CheckSize(d, sizeof(FTM::DimDynamicData)))
1848 return;
1849
1850 const FTM::DimDynamicData &sdata = d.ref<FTM::DimDynamicData>();
1851
1852 fFtmTemp0->setValue(sdata.fTempSensor[0]*0.1);
1853 fFtmTemp1->setValue(sdata.fTempSensor[1]*0.1);
1854 fFtmTemp2->setValue(sdata.fTempSensor[2]*0.1);
1855 fFtmTemp3->setValue(sdata.fTempSensor[3]*0.1);
1856
1857 SetLedColor(fClockCondLed, sdata.fState&FTM::kFtmLocked ? kLedGreen : kLedRed, d.time);
1858 }
1859
1860 void DisplayRates()
1861 {
1862#ifdef HAVE_ROOT
1863 TCanvas *c = fFtmRateCanv->GetCanvas();
1864
1865 TList * l = c->GetListOfPrimitives();
1866
1867
1868 while (c->FindObject("PatchRate"))
1869 l->Remove(c->FindObject("PatchRate"));
1870
1871 while (c->FindObject("BoardRate"))
1872 l->Remove(c->FindObject("BoardRate"));
1873
1874 if (fRatePatch1->value()>=0)
1875 {
1876 fGraphPatchRate[fRatePatch1->value()].SetLineColor(kRed);
1877 fGraphPatchRate[fRatePatch1->value()].SetMarkerColor(kRed);
1878 l->Add(&fGraphPatchRate[fRatePatch1->value()], "PL");
1879 }
1880 if (fRatePatch2->value()>=0)
1881 {
1882 fGraphPatchRate[fRatePatch2->value()].SetLineColor(kGreen);
1883 fGraphPatchRate[fRatePatch2->value()].SetMarkerColor(kGreen);
1884 l->Add(&fGraphPatchRate[fRatePatch2->value()], "PL");
1885 }
1886 if (fRateBoard1->value()>=0)
1887 {
1888 fGraphBoardRate[fRateBoard1->value()].SetLineColor(kMagenta);
1889 fGraphBoardRate[fRateBoard1->value()].SetMarkerColor(kMagenta);
1890 l->Add(&fGraphBoardRate[fRateBoard1->value()], "PL");
1891 }
1892 if (fRateBoard2->value()>=0)
1893 {
1894 fGraphBoardRate[fRateBoard2->value()].SetLineColor(kCyan);
1895 fGraphBoardRate[fRateBoard2->value()].SetMarkerColor(kCyan);
1896 l->Add(&fGraphBoardRate[fRateBoard2->value()], "PL");
1897 }
1898
1899 c->Modified();
1900 c->Update();
1901#endif
1902 }
1903
1904 FTM::DimStaticData fFtmStaticData;
1905
1906 void SetFtuLed(int idx, int counter, const Time &t)
1907 {
1908 if (counter==0 || counter>3)
1909 counter = 3;
1910
1911 if (counter<0)
1912 counter = 0;
1913
1914 const LedColor_t col[4] = { kLedGray, kLedGreen, kLedOrange, kLedRed };
1915
1916 SetLedColor(fFtuLED[idx], col[counter], t);
1917
1918 fFtuStatus[idx] = counter;
1919 }
1920
1921 void SetFtuStatusLed(const Time &t)
1922 {
1923 const int max = fFtuStatus.max();
1924
1925 switch (max)
1926 {
1927 case 0:
1928 SetLedColor(fStatusFTULed, kLedGray, t);
1929 fStatusFTULabel->setText("All disabled");
1930 fStatusFTULabel->setToolTip("All FTUs are disabled");
1931 break;
1932
1933 case 1:
1934 SetLedColor(fStatusFTULed, kLedGreen, t);
1935 fStatusFTULabel->setToolTip("Communication with FTU is smooth.");
1936 fStatusFTULabel->setText("ok");
1937 break;
1938
1939 case 2:
1940 SetLedColor(fStatusFTULed, kLedOrange, t);
1941 fStatusFTULabel->setText("Warning");
1942 fStatusFTULabel->setToolTip("At least one FTU didn't answer immediately");
1943 break;
1944
1945 case 3:
1946 SetLedColor(fStatusFTULed, kLedRed, t);
1947 fStatusFTULabel->setToolTip("At least one FTU didn't answer!");
1948 fStatusFTULabel->setText("ERROR");
1949 break;
1950 }
1951
1952 const int cnt = count(&fFtuStatus[0], &fFtuStatus[40], 0);
1953 fFtuAllOn->setEnabled(cnt!=0);
1954 fFtuAllOff->setEnabled(cnt!=40);
1955 }
1956
1957 void handleFtmStaticData(const DimData &d)
1958 {
1959 if (!CheckSize(d, sizeof(FTM::DimStaticData)))
1960 return;
1961
1962 const FTM::DimStaticData &sdata = d.ref<FTM::DimStaticData>();
1963
1964 fTriggerInterval->setValue(sdata.fTriggerInterval);
1965 fPhysicsCoincidence->setValue(sdata.fMultiplicityPhysics);
1966 fCalibCoincidence->setValue(sdata.fMultiplicityCalib);
1967 fPhysicsWindow->setValue(sdata.fWindowPhysics);
1968 fCalibWindow->setValue(sdata.fWindowCalib);
1969
1970 fTriggerDelay->setValue(sdata.fDelayTrigger);
1971 fTimeMarkerDelay->setValue(sdata.fDelayTimeMarker);
1972 fDeadTime->setValue(sdata.fDeadTime);
1973
1974 fClockCondR0->setValue(sdata.fClockConditioner[0]);
1975 fClockCondR1->setValue(sdata.fClockConditioner[1]);
1976 fClockCondR8->setValue(sdata.fClockConditioner[2]);
1977 fClockCondR9->setValue(sdata.fClockConditioner[3]);
1978 fClockCondR11->setValue(sdata.fClockConditioner[4]);
1979 fClockCondR13->setValue(sdata.fClockConditioner[5]);
1980 fClockCondR14->setValue(sdata.fClockConditioner[6]);
1981 fClockCondR15->setValue(sdata.fClockConditioner[7]);
1982
1983 const uint32_t R0 = sdata.fClockConditioner[0];
1984 const uint32_t R14 = sdata.fClockConditioner[6];
1985 const uint32_t R15 = sdata.fClockConditioner[7];
1986
1987 const uint32_t Ndiv = (R15&0x1ffff00)<<2;
1988 const uint32_t Rdiv = (R14&0x007ff00)>>8;
1989 const uint32_t Cdiv = (R0 &0x000ff00)>>8;
1990
1991 double freq = 40.*Ndiv/(Rdiv*Cdiv);
1992
1993 fClockCondFreqRes->setValue(freq);
1994
1995 //fClockCondFreq->setEditText("");
1996 fClockCondFreq->setCurrentIndex(0);
1997
1998 fTriggerSeqPed->setValue(sdata.fTriggerSeqPed);
1999 fTriggerSeqLPint->setValue(sdata.fTriggerSeqLPint);
2000 fTriggerSeqLPext->setValue(sdata.fTriggerSeqLPext);
2001
2002 fLpIntIntensity->setValue(sdata.fIntensityLPint);
2003 fLpExtIntensity->setValue(sdata.fIntensityLPext);
2004
2005 fLpIntGroup1->setChecked(sdata.HasLPintG1());
2006 fLpIntGroup2->setChecked(sdata.HasLPintG2());
2007 fLpExtGroup1->setChecked(sdata.HasLPextG1());
2008 fLpExtGroup2->setChecked(sdata.HasLPextG2());
2009
2010 fEnableTrigger->setChecked(sdata.HasTrigger());
2011 fEnableVeto->setChecked(sdata.HasVeto());
2012 fEnableExt1->setChecked(sdata.HasExt1());
2013 fEnableExt2->setChecked(sdata.HasExt2());
2014 fEnableClockCond->setChecked(sdata.HasClockConditioner());
2015
2016 uint16_t multiplicity = sdata.fMultiplicity[0];
2017
2018 for (int i=0; i<40; i++)
2019 {
2020 if (!sdata.IsActive(i))
2021 SetFtuLed(i, -1, d.time);
2022 else
2023 {
2024 if (fFtuStatus[i]==0)
2025 SetFtuLed(i, 1, d.time);
2026 }
2027 fFtuLED[i]->setChecked(false);
2028
2029 if (sdata.fMultiplicity[i]!=multiplicity)
2030 multiplicity = -1;
2031
2032 }
2033 SetFtuStatusLed(d.time);
2034
2035 fNoutof4Val->setValue(multiplicity);
2036
2037 for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
2038 fRatesCanv->SetEnable(it->index, sdata.IsEnabled(it->hw()));
2039
2040 const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
2041 fPixelEnable->setChecked(sdata.IsEnabled(entry.hw()));
2042
2043 if (fThresholdIdx->value()>=0)
2044 {
2045 const int isw = fThresholdIdx->value();
2046 const int ihw = fPatchMapHW[isw];
2047 fThresholdVal->setValue(sdata.fThreshold[ihw]);
2048 }
2049
2050 fPrescalingVal->setValue(sdata.fPrescaling[0]);
2051
2052 fFtmStaticData = sdata;
2053 }
2054
2055 void handleFtmPassport(const DimData &d)
2056 {
2057 if (!CheckSize(d, sizeof(FTM::DimPassport)))
2058 return;
2059
2060 const FTM::DimPassport &sdata = d.ref<FTM::DimPassport>();
2061
2062 stringstream str1, str2;
2063 str1 << hex << "0x" << setfill('0') << setw(16) << sdata.fBoardId;
2064 str2 << sdata.fFirmwareId;
2065
2066 fFtmBoardId->setText(str1.str().c_str());
2067 fFtmFirmwareId->setText(str2.str().c_str());
2068 }
2069
2070 void handleFtmFtuList(const DimData &d)
2071 {
2072 if (!CheckSize(d, sizeof(FTM::DimFtuList)))
2073 return;
2074
2075 fFtuPing->setChecked(false);
2076
2077 const FTM::DimFtuList &sdata = d.ref<FTM::DimFtuList>();
2078
2079 stringstream str;
2080 str << "<table width='100%'>" << setfill('0');
2081 str << "<tr><th>Num</th><th></th><th>Addr</th><th></th><th>DNA</th></tr>";
2082 for (int i=0; i<40; i++)
2083 {
2084 str << "<tr>";
2085 str << "<td align='center'>" << dec << i << hex << "</td>";
2086 str << "<td align='center'>:</td>";
2087 str << "<td align='center'>0x" << setw(2) << (int)sdata.fAddr[i] << "</td>";
2088 str << "<td align='center'>:</td>";
2089 str << "<td align='center'>0x" << setw(16) << sdata.fDNA[i] << "</td>";
2090 str << "</tr>";
2091 }
2092 str << "</table>";
2093
2094 fFtuDNA->setText(str.str().c_str());
2095
2096 fFtuAnswersTotal->setValue(sdata.fNumBoards);
2097 fFtuAnswersCrate0->setValue(sdata.fNumBoardsCrate[0]);
2098 fFtuAnswersCrate1->setValue(sdata.fNumBoardsCrate[1]);
2099 fFtuAnswersCrate2->setValue(sdata.fNumBoardsCrate[2]);
2100 fFtuAnswersCrate3->setValue(sdata.fNumBoardsCrate[3]);
2101
2102 for (int i=0; i<40; i++)
2103 SetFtuLed(i, sdata.IsActive(i) ? sdata.fPing[i] : -1, d.time);
2104
2105 SetFtuStatusLed(d.time);
2106 }
2107
2108 void handleFtmError(const DimData &d)
2109 {
2110 if (!CheckSize(d, sizeof(FTM::DimError)))
2111 return;
2112
2113 const FTM::DimError &sdata = d.ref<FTM::DimError>();
2114
2115 SetFtuLed(sdata.fError.fDestAddress, sdata.fError.fNumCalls, d.time);
2116 SetFtuStatusLed(d.time);
2117
2118 // FIXME: Write to special window!
2119 //Out() << "Error:" << endl;
2120 //Out() << sdata.fError << endl;
2121 }
2122
2123 // ========================== FSC =======================================
2124
2125 void SetFscValue(QDoubleSpinBox *box, const DimData &d, int idx, bool enable)
2126 {
2127 //box->setEnabled(enable);
2128 if (!enable)
2129 {
2130 box->setToolTip(d.time.GetAsStr().c_str());
2131 return;
2132 }
2133
2134 ostringstream str;
2135 str << d.time << " -- " << d.get<float>() << "s";
2136
2137 box->setToolTip(str.str().c_str());
2138 box->setValue(d.get<float>(idx*4+4));
2139 }
2140
2141
2142 void handleFscTemp(const DimData &d)
2143 {
2144 const bool enable = d.size()>0 && CheckSize(d, 60*sizeof(float));
2145 if (!enable)
2146 return;
2147
2148 QDoubleSpinBox *boxes[] = {
2149 fTempCam00, fTempCam01,
2150 fTempCam10, fTempCam11, fTempCam12, fTempCam13, fTempCam14,
2151 fTempCam20, fTempCam21, fTempCam22, fTempCam23, fTempCam24, fTempCam25,
2152 fTempCam30, fTempCam31, fTempCam32, fTempCam33, fTempCam34,
2153 fTempCam40, fTempCam41, fTempCam42, fTempCam43, fTempCam44, fTempCam45,
2154 fTempCam50, fTempCam51, fTempCam52, fTempCam53, fTempCam54,
2155 fTempCam60, fTempCam61,
2156 // 0:b/f 1:b/f 2:b/f 3:b/f
2157 fTempCrate0back, fTempCrate0front,
2158 fTempCrate1back, fTempCrate1front,
2159 fTempCrate2back, fTempCrate2front,
2160 fTempCrate3back, fTempCrate3front,
2161 // 0:b/f 1:b/f 2:b/f 3:b/f
2162 fTempPS0back, fTempPS0front,
2163 fTempPS1back, fTempPS1front,
2164 fTempPS2back, fTempPS2front,
2165 fTempPS3back, fTempPS3front,
2166 // AUX PS: FTM t/b; FSC t/b
2167 fTempAuxFTMtop, fTempAuxFTMbottom,
2168 fTempAuxFSCtop, fTempAuxFSCbottom,
2169 // Backpanel: FTM t/b; FSC t/b
2170 fTempBackpanelFTMtop, fTempBackpanelFTMbottom,
2171 fTempBackpanelFSCtop, fTempBackpanelFSCbottom,
2172 // top front/back; bottom front/back
2173 fTempSwitchboxTopFront, fTempSwitchboxTopBack,
2174 fTempSwitchboxBottomFront, fTempSwitchboxBottomBack,
2175 };
2176
2177 for (int i=0; i<59; i++)
2178 SetFscValue(boxes[i], d, i, enable);
2179
2180 if (!enable)
2181 return;
2182
2183 const float *ptr = d.ptr<float>();
2184
2185 double avg = 0;
2186 int num = 0;
2187 for (int i=1; i<32; i++)
2188 if (ptr[i]!=0)
2189 {
2190 avg += ptr[i];
2191 num ++;
2192 }
2193
2194 fTempCamAvg->setValue(num?avg/num:0);
2195 }
2196
2197 void handleFscVolt(const DimData &d)
2198 {
2199 const bool enable = d.size()>0 && CheckSize(d, 31*sizeof(float));
2200 if (!enable)
2201 return;
2202
2203 QDoubleSpinBox *boxes[] = {
2204 fVoltFad00, fVoltFad10, fVoltFad20, fVoltFad30,
2205 fVoltFad01, fVoltFad11, fVoltFad21, fVoltFad31,
2206 fVoltFad02, fVoltFad12, fVoltFad22, fVoltFad32,
2207 fVoltFPA00, fVoltFPA10, fVoltFPA20, fVoltFPA30,
2208 fVoltFPA01, fVoltFPA11, fVoltFPA21, fVoltFPA31,
2209 fVoltFPA02, fVoltFPA12, fVoltFPA22, fVoltFPA32,
2210 fVoltETH0, fVoltETH1,
2211 fVoltFTM0, fVoltFTM1,
2212 fVoltFFC, fVoltFLP,
2213 };
2214
2215 for (int i=0; i<30; i++)
2216 SetFscValue(boxes[i], d, i, enable);
2217 }
2218
2219 void handleFscCurrent(const DimData &d)
2220 {
2221 const bool enable = d.size()>0 && CheckSize(d, 31*sizeof(float));
2222 if (!enable)
2223 return;
2224
2225 QDoubleSpinBox *boxes[] = {
2226 fAmpFad00, fAmpFad10, fAmpFad20, fAmpFad30,
2227 fAmpFad01, fAmpFad11, fAmpFad21, fAmpFad31,
2228 fAmpFad02, fAmpFad12, fAmpFad22, fAmpFad32,
2229 fAmpFPA00, fAmpFPA10, fAmpFPA20, fAmpFPA30,
2230 fAmpFPA01, fAmpFPA11, fAmpFPA21, fAmpFPA31,
2231 fAmpFPA02, fAmpFPA12, fAmpFPA22, fAmpFPA32,
2232 fAmpETH0, fAmpETH1,
2233 fAmpFTM0, fAmpFTM1,
2234 fAmpFFC, fAmpFLP,
2235 };
2236
2237 for (int i=0; i<30; i++)
2238 SetFscValue(boxes[i], d, i, enable);
2239 }
2240
2241 void handleFscHumidity(const DimData &d)
2242 {
2243 const bool enable = d.size()>0 && CheckSize(d, 5*sizeof(float));
2244
2245 SetFscValue(fHumidity1, d, 0, enable);
2246 SetFscValue(fHumidity2, d, 1, enable);
2247 SetFscValue(fHumidity3, d, 2, enable);
2248 SetFscValue(fHumidity4, d, 3, enable);
2249 }
2250
2251 // ========================== Feedback ==================================
2252
2253#ifdef HAVE_ROOT
2254 TGraphErrors fGraphFeedbackDev;
2255 TGraphErrors fGraphFeedbackCmd;
2256
2257 void UpdateFeedback(TQtWidget &rwidget, const Time &time, TGraphErrors &graph, double avg, double rms)
2258 {
2259 TCanvas *c = rwidget.GetCanvas();
2260
2261 TH1 *h = (TH1*)c->FindObject("TimeFrame");
2262
2263 while (graph.GetN()>500)
2264 graph.RemovePoint(0);
2265
2266 const double now = time.RootTime();
2267
2268 while (graph.GetN()>0 && now-graph.GetX()[0]>3600)
2269 graph.RemovePoint(0);
2270
2271 const int n = graph.GetN();
2272
2273 const double xmin = n>0 ? graph.GetX()[0] : now;
2274
2275 h->SetBins(n+1, xmin-1, now+1);
2276 graph.SetPoint(n, now, avg);
2277 graph.SetPointError(n, 0, rms);
2278
2279 h->GetXaxis()->SetTimeFormat(now-xmin>300 ? "%Hh%M'" : "%M'%S\"");
2280
2281 c->Modified();
2282 c->Update();
2283 }
2284#endif
2285
2286 void handleFeedbackDeviation(const DimData &d)
2287 {
2288 if (!CheckSize(d, (2*416+2)*sizeof(float)))
2289 return;
2290
2291 if (d.qos==0)
2292 return;
2293
2294 const float *ptr = d.ptr<float>();
2295
2296 valarray<float> dev(1440);
2297 valarray<float> cmd(1440);
2298
2299 double avgdev = 0;
2300 double avgcmd = 0;
2301
2302 double rmsdev = 0;
2303 double rmscmd = 0;
2304
2305 for (int i=0; i<1440; i++)
2306 {
2307 const PixelMapEntry &entry = fPixelMap.index(i);
2308
2309 dev[i] = /*1000*/ptr[entry.hv()];
2310 cmd[i] = 1000*ptr[entry.hv()+416];
2311
2312 avgdev += dev[i];
2313 avgcmd += cmd[i];
2314
2315 rmsdev += dev[i]*dev[i];
2316 rmscmd += cmd[i]*cmd[i];
2317 }
2318
2319 avgdev /= 1440;
2320 avgcmd /= 1440;
2321
2322 rmsdev = sqrt(rmsdev/1440 - avgdev*avgdev);
2323 rmscmd = sqrt(rmscmd/1440 - avgcmd*avgcmd);
2324
2325 fFeedbackDevCam->SetData(dev);
2326 fFeedbackCmdCam->SetData(cmd);
2327
2328 fFeedbackDevCam->updateCamera();
2329 fFeedbackCmdCam->updateCamera();
2330
2331#ifdef HAVE_ROOT
2332 UpdateFeedback(*fFeedbackDev, d.time, fGraphFeedbackDev, avgdev, rmsdev);
2333 UpdateFeedback(*fFeedbackCmd, d.time, fGraphFeedbackCmd, avgcmd, rmscmd);
2334#endif
2335 }
2336
2337 void handleFeedbackReference(const DimData &d)
2338 {
2339 if (!CheckSize(d, 416*sizeof(float)))
2340 return;
2341
2342 const float *ptr = d.ptr<float>();
2343
2344// fFeedbackRefCam->SetData(valarray<float>(ptr, 416));
2345// fFeedbackRefCam->updateCamera();
2346 }
2347
2348 vector<float> fBiasOffsets;
2349
2350 void handleFeedbackCalibration(const DimData &d)
2351 {
2352 if (!CheckSize(d, 3*416*sizeof(float)))
2353 return;
2354
2355 const float *ptr = d.ptr<float>();
2356 fBiasOffsets.assign(ptr+2*416, ptr+3*416);
2357 }
2358
2359 // ======================= Rate Scan ====================================
2360
2361 TGraph fGraphRateScan[201];
2362
2363 void UpdateRateScan(uint32_t th, const float *rates)
2364 {
2365#ifdef HAVE_ROOT
2366 TCanvas *c = fRateScanCanv->GetCanvas();
2367
2368 TH1 *h = (TH1*)c->FindObject("Frame");
2369
2370 if (fGraphRateScan[0].GetN()==0 || th<fGraphRateScan[0].GetX()[fGraphRateScan[0].GetN()-1])
2371 {
2372 h->SetBins(1, th<10 ? 0 : th-10, th+10);
2373 h->SetMinimum(1);
2374 h->SetMaximum(rates[0]*2);
2375
2376 for (int i=0; i<201; i++)
2377 {
2378 fGraphRateScan[i].Set(0);
2379 fGraphRateScan[i].SetPoint(fGraphRateScan[i].GetN(), th, rates[i]);
2380 }
2381
2382 c->SetGrid();
2383 c->SetLogy();
2384
2385 c->Modified();
2386 c->Update();
2387 return;
2388 }
2389
2390 const double dac = h->GetXaxis()->GetXmin();
2391 h->SetBins(h->GetNbinsX()+1, dac, th+10);
2392
2393 for (int i=0; i<201; i++)
2394 fGraphRateScan[i].SetPoint(fGraphRateScan[i].GetN(), th, rates[i]);
2395
2396 c->Modified();
2397 c->Update();
2398#endif
2399 }
2400
2401 void DisplayRateScan()
2402 {
2403#ifdef HAVE_ROOT
2404 TCanvas *c = fRateScanCanv->GetCanvas();
2405
2406 TList *l = c->GetListOfPrimitives();
2407
2408 while (c->FindObject("PatchRate"))
2409 l->Remove(c->FindObject("PatchRate"));
2410
2411 while (c->FindObject("BoardRate"))
2412 l->Remove(c->FindObject("BoardRate"));
2413
2414 if (fRateScanPatch1->value()>=0)
2415 {
2416 fGraphRateScan[fRateScanPatch1->value()+41].SetLineColor(kRed);
2417 fGraphRateScan[fRateScanPatch1->value()+41].SetMarkerColor(kRed);
2418 l->Add(&fGraphRateScan[fRateScanPatch1->value()+41], "PL");
2419 }
2420 if (fRateScanPatch2->value()>=0)
2421 {
2422 fGraphRateScan[fRateScanPatch2->value()+41].SetLineColor(kGreen);
2423 fGraphRateScan[fRateScanPatch2->value()+41].SetMarkerColor(kGreen);
2424 l->Add(&fGraphRateScan[fRateScanPatch2->value()+41], "PL");
2425 }
2426 if (fRateScanBoard1->value()>=0)
2427 {
2428 fGraphRateScan[fRateScanBoard1->value()+1].SetLineColor(kMagenta);
2429 fGraphRateScan[fRateScanBoard1->value()+1].SetMarkerColor(kMagenta);
2430 l->Add(&fGraphRateScan[fRateScanBoard1->value()+1], "PL");
2431 }
2432 if (fRateScanBoard2->value()>=0)
2433 {
2434 fGraphRateScan[fRateScanBoard2->value()+1].SetLineColor(kCyan);
2435 fGraphRateScan[fRateScanBoard2->value()+1].SetMarkerColor(kCyan);
2436 l->Add(&fGraphRateScan[fRateScanBoard2->value()+1], "PL");
2437 }
2438
2439 c->Modified();
2440 c->Update();
2441#endif
2442 }
2443
2444 void handleRateScan(const DimData &d)
2445 {
2446 if (!CheckSize(d, 206*sizeof(float)))
2447 return;
2448
2449 UpdateRateScan(d.get<uint32_t>(8), d.ptr<float>(20));
2450 }
2451
2452 // ===================== MAGIC Weather ==================================
2453
2454 void handleMagicWeather(const DimData &d)
2455 {
2456 if (!CheckSize(d, 7*sizeof(float)+sizeof(uint16_t)))
2457 return;
2458
2459 const float *ptr = d.ptr<float>(2);
2460
2461 fMagicTemp->setValue(ptr[0]);
2462 fMagicDew->setValue(ptr[1]);
2463 fMagicHum->setValue(ptr[2]);
2464 fMagicPressure->setValue(ptr[3]);
2465 fMagicWind->setValue(ptr[4]);
2466 fMagicGusts->setValue(ptr[5]);
2467
2468 static const char *dir[] =
2469 {
2470 "N", "NNE", "NE", "ENE",
2471 "E", "ESE", "SE", "SSE",
2472 "S", "SSW", "SW", "WSW",
2473 "W", "WNW", "NW", "NNW"
2474 };
2475
2476 const uint16_t i = uint16_t(floor(fmod(ptr[6]+11.25, 360)/22.5));
2477 fMagicWindDir->setText(dir[i%16]);
2478 }
2479
2480 // ========================== FSC =======================================
2481
2482 vector<float> fVecBiasVolt;
2483 vector<int16_t> fVecBiasDac;
2484 vector<int16_t> fVecBiasCurrent;
2485 vector<float> fVecBiasCalibOffset;
2486
2487 void handleBiasNominal(const DimData &d)
2488 {
2489 if (!CheckSize(d, 3*416*sizeof(float)))
2490 return;
2491
2492 const float *ptr = d.ptr<float>();
2493
2494 fVecBiasCalibOffset.assign(ptr+2*416, ptr+3*416);
2495
2496 on_fBiasDispRefVolt_stateChanged();
2497 UpdateBiasValues();
2498 }
2499
2500 void handleBiasVolt(const DimData &d)
2501 {
2502 if (!CheckSize(d, 416*sizeof(float)))
2503 return;
2504
2505 const float *ptr = d.ptr<float>();
2506 fVecBiasVolt.assign(ptr, ptr+416);
2507 }
2508
2509 void handleBiasDac(const DimData &d)
2510 {
2511 if (!CheckSize(d, 2*416*sizeof(int16_t)))
2512 return;
2513
2514 const int16_t *ptr = d.ptr<int16_t>();
2515 fVecBiasDac.assign(ptr, ptr+2*416);
2516
2517 on_fBiasDispRefVolt_stateChanged();
2518 UpdateBiasValues();
2519 }
2520
2521 void handleBiasCurrent(const DimData &d)
2522 {
2523 if (!CheckSize(d, 416*sizeof(int16_t)))
2524 return;
2525
2526 const int16_t *ptr = d.ptr<int16_t>();
2527
2528 fVecBiasCurrent.assign(ptr, ptr+416);
2529
2530 valarray<double> dat(0., 1440);
2531
2532 // fPatch converts from software id to software patch id
2533 for (int i=0; i<1440; i++)
2534 {
2535 const PixelMapEntry &entry = fPixelMap.index(i);
2536
2537 // FIXME: Display Overcurrent
2538 /*
2539 dat[i] = fVecBiasVolt[entry.hv()]*90./4096;
2540 double amp = abs(ptr[entry.hv()]);
2541 if (fBiasOffsets.size()>0)
2542 amp -= fBiasOffsets[entry.hv()];
2543 amp *= 5000./4096;
2544 amp *= 5200 *1e-6;
2545 dat[i] -= amp;
2546 */
2547
2548 dat[i] = abs(ptr[entry.hv()]) * 5000./4096;
2549
2550 if (fBiasOffsets.size()>0 && fVecBiasVolt.size()>0)
2551 dat[i] -= fVecBiasVolt[entry.hv()]/fBiasOffsets[entry.hv()]*1e6;
2552
2553 dat[i] *= 4.5 / (entry.group() ? 5 : 4);
2554
2555 fBiasCamA->SetEnable(i, uint16_t(ptr[entry.hv()])!=0x8000);
2556 fBiasCamA->highlightPixel(i, ptr[entry.hv()]<0);
2557 }
2558
2559 fBiasCamA->SetData(dat);
2560 fBiasCamA->updateCamera();
2561
2562 UpdateBiasValues();
2563 }
2564
2565 // ====================== MessageImp ====================================
2566
2567 bool fChatOnline;
2568
2569 void handleStateChanged(const Time &time, const string &server,
2570 const State &s)
2571 {
2572 // FIXME: Prefix tooltip with time
2573 if (server=="MCP")
2574 {
2575 // FIXME: Enable FTU page!!!
2576 fStatusMCPLabel->setText(s.name.c_str());
2577 fStatusMCPLabel->setToolTip(s.comment.c_str());
2578
2579 if (s.index<MCP::State::kDisconnected) // No Dim connection
2580 SetLedColor(fStatusMCPLed, kLedGray, time);
2581 if (s.index==MCP::State::kDisconnected) // Disconnected
2582 SetLedColor(fStatusMCPLed, kLedRed, time);
2583 if (s.index==MCP::State::kConnecting) // Connecting
2584 SetLedColor(fStatusMCPLed, kLedOrange, time);
2585 if (s.index==MCP::State::kConnected) // Connected
2586 SetLedColor(fStatusMCPLed, kLedYellow, time);
2587 if (s.index==MCP::State::kIdle || s.index>=MCP::State::kConfigured) // Idle, TriggerOn, TakingData
2588 SetLedColor(fStatusMCPLed, kLedGreen, time);
2589
2590 if (s.index>MCP::State::kIdle && s.index<MCP::State::kConfigured)
2591 SetLedColor(fStatusMCPLed, kLedGreenBar, time);
2592
2593 fMcpStartRun->setEnabled(s.index>=MCP::State::kIdle);
2594 fMcpStopRun->setEnabled(s.index>=MCP::State::kIdle);
2595 fMcpReset->setEnabled(s.index>=MCP::State::kIdle && MCP::State::kConfigured);
2596 }
2597
2598 if (server=="FTM_CONTROL")
2599 {
2600 // FIXME: Enable FTU page!!!
2601 fStatusFTMLabel->setText(s.name.c_str());
2602 fStatusFTMLabel->setToolTip(s.comment.c_str());
2603
2604 bool enable = false;
2605 const bool configuring =
2606 s.index==FTM::State::kConfiguring1 ||
2607 s.index==FTM::State::kConfiguring2 ||
2608 s.index==FTM::State::kConfigured;
2609
2610 if (s.index<FTM::State::kDisconnected) // No Dim connection
2611 SetLedColor(fStatusFTMLed, kLedGray, time);
2612 if (s.index==FTM::State::kDisconnected) // Dim connection / FTM disconnected
2613 SetLedColor(fStatusFTMLed, kLedYellow, time);
2614 if (s.index==FTM::State::kConnected ||
2615 s.index==FTM::State::kIdle ||
2616 configuring) // Dim connection / FTM connected
2617 SetLedColor(fStatusFTMLed, kLedGreen, time);
2618 if (s.index==FTM::State::kTriggerOn) // Dim connection / FTM connected
2619 SetLedColor(fStatusFTMLed, kLedGreenCheck, time);
2620 if (s.index==FTM::State::kConnected ||
2621 s.index==FTM::State::kIdle) // Dim connection / FTM connected
2622 enable = true;
2623 if (s.index>=FTM::State::kConfigError1) // Dim connection / FTM connected
2624 SetLedColor(fStatusFTMLed, kLedGreenWarn, time);
2625
2626 fFtmStartRun->setEnabled(!configuring && enable);
2627 fFtmStopRun->setEnabled(!configuring && (enable || s.index==FTM::State::kTriggerOn));
2628
2629 fTriggerWidget->setEnabled(enable);
2630 fFtuGroupEnable->setEnabled(enable);
2631 fRatesControls->setEnabled(enable);
2632 fFtuWidget->setEnabled(s.index>FTM::State::kDisconnected);
2633
2634 if (s.index>=FTM::State::kConnected)
2635 SetFtuStatusLed(time);
2636 else
2637 {
2638 SetLedColor(fStatusFTULed, kLedGray, time);
2639 fStatusFTULabel->setText("Offline");
2640 fStatusFTULabel->setToolTip("FTM is not online.");
2641 }
2642 }
2643
2644 if (server=="FAD_CONTROL")
2645 {
2646 fStatusFADLabel->setText(s.name.c_str());
2647 fStatusFADLabel->setToolTip(s.comment.c_str());
2648
2649 bool enable = false;
2650
2651 if (s.index<FAD::State::kOffline) // No Dim connection
2652 {
2653 SetLedColor(fStatusFADLed, kLedGray, time);
2654
2655 // Timing problem - sometimes they stay gray :(
2656 //for (int i=0; i<40; i++)
2657 // SetLedColor(fFadLED[i], kLedGray, time);
2658
2659 /*
2660 fStatusEventBuilderLabel->setText("Offline");
2661 fStatusEventBuilderLabel->setToolTip("No connection to fadctrl.");
2662 fEvtBldWidget->setEnabled(false);
2663
2664 SetLedColor(fStatusEventBuilderLed, kLedGray, time);
2665 */
2666 }
2667 if (s.index==FAD::State::kOffline) // Dim connection / FTM disconnected
2668 SetLedColor(fStatusFADLed, kLedRed, time);
2669 if (s.index==FAD::State::kDisconnected) // Dim connection / FTM disconnected
2670 SetLedColor(fStatusFADLed, kLedOrange, time);
2671 if (s.index==FAD::State::kConnecting) // Dim connection / FTM disconnected
2672 {
2673 SetLedColor(fStatusFADLed, kLedYellow, time);
2674 // FIXME FIXME FIXME: The LEDs are not displayed when disabled!
2675 enable = true;
2676 }
2677 if (s.index>=FAD::State::kConnected) // Dim connection / FTM connected
2678 {
2679 SetLedColor(fStatusFADLed, kLedGreen, time);
2680 enable = true;
2681 }
2682
2683 fFadWidget->setEnabled(enable);
2684
2685 fFadStart->setEnabled (s.index==FAD::State::kOffline);
2686 fFadStop->setEnabled (s.index >FAD::State::kOffline);
2687 fFadAbort->setEnabled (s.index >FAD::State::kOffline);
2688 fFadSoftReset->setEnabled(s.index >FAD::State::kOffline);
2689 fFadHardReset->setEnabled(s.index >FAD::State::kOffline);
2690 }
2691
2692 if (server=="FSC_CONTROL")
2693 {
2694 fStatusFSCLabel->setText(s.name.c_str());
2695 fStatusFSCLabel->setToolTip(s.comment.c_str());
2696
2697 bool enable = false;
2698
2699 if (s.index<FSC::State::kDisconnected) // No Dim connection
2700 SetLedColor(fStatusFSCLed, kLedGray, time);
2701 if (s.index==FSC::State::kDisconnected) // Dim connection / FTM disconnected
2702 SetLedColor(fStatusFSCLed, kLedRed, time);
2703 if (s.index>=FSC::State::kConnected) // Dim connection / FTM disconnected
2704 {
2705 SetLedColor(fStatusFSCLed, kLedGreen, time);
2706 enable = true;
2707 }
2708
2709 fAuxWidget->setEnabled(enable);
2710 }
2711
2712 if (server=="DRIVE_CONTROL")
2713 {
2714 fStatusDriveLabel->setText(s.name.c_str());
2715 fStatusDriveLabel->setToolTip(s.comment.c_str());
2716
2717 if (s.index<Drive::State::kDisconnected) // No Dim connection
2718 SetLedColor(fStatusDriveLed, kLedGray, time);
2719 if (s.index==Drive::State::kDisconnected) // Dim connection / No connection to cosy
2720 SetLedColor(fStatusDriveLed, kLedRed, time);
2721 if (s.index==Drive::State::kConnected || s.index==Drive::State::kNotReady || s.index==Drive::State::kLocked) // Not Ready
2722 SetLedColor(fStatusDriveLed, kLedGreenBar, time);
2723 if (s.index==Drive::State::kConnected || s.index==Drive::State::kArmed) // Connected / Armed
2724 SetLedColor(fStatusDriveLed, kLedGreen, time);
2725 if (s.index==Drive::State::kMoving) // Moving
2726 SetLedColor(fStatusDriveLed, kLedInProgress, time);
2727 if (s.index==Drive::State::kTracking || s.index==Drive::State::kOnTrack) // Tracking
2728 SetLedColor(fStatusDriveLed, kLedGreenCheck, time);
2729 if (s.index>=0xff) // Error
2730 SetLedColor(fStatusDriveLed, kLedGreenWarn, time);
2731 }
2732
2733 if (server=="BIAS_CONTROL")
2734 {
2735 fStatusBiasLabel->setText(s.name.c_str());
2736 fStatusBiasLabel->setToolTip(s.comment.c_str());
2737
2738 if (s.index<1) // No Dim connection
2739 SetLedColor(fStatusBiasLed, kLedGray, time);
2740 if (s.index==BIAS::State::kDisconnected) // Dim connection / FTM disconnected
2741 SetLedColor(fStatusBiasLed, kLedRed, time);
2742 if (s.index==BIAS::State::kConnecting || s.index==BIAS::State::kInitializing) // Connecting / Initializing
2743 SetLedColor(fStatusBiasLed, kLedOrange, time);
2744 if (s.index==BIAS::State::kVoltageOff) // At reference
2745 SetLedColor(fStatusBiasLed, kLedGreenBar, time);
2746 if (s.index==BIAS::State::kNotReferenced) // At reference
2747 SetLedColor(fStatusBiasLed, kLedGreenWarn, time);
2748 if (s.index==BIAS::State::kRamping) // Ramping
2749 SetLedColor(fStatusBiasLed, kLedInProgress, time);
2750 if (s.index==BIAS::State::kVoltageOn) // At reference
2751 SetLedColor(fStatusBiasLed, kLedGreenCheck, time);
2752 if (s.index==BIAS::State::kOverCurrent) // Over current
2753 SetLedColor(fStatusBiasLed, kLedWarnBorder, time);
2754 if (s.index==BIAS::State::kExpertMode) // ExpertMode
2755 SetLedColor(fStatusBiasLed, kLedWarnTriangleBorder, time);
2756
2757 fBiasWidget->setEnabled(s.index>=BIAS::State::kInitializing);
2758 }
2759
2760 if (server=="FEEDBACK")
2761 {
2762 fStatusFeedbackLabel->setText(s.name.c_str());
2763 fStatusFeedbackLabel->setToolTip(s.comment.c_str());
2764
2765 const bool connected = s.index> Feedback::State::kConnecting;
2766 const bool idle = s.index>=Feedback::State::kTempCtrlIdle && s.index<=Feedback::State::kCurrentCtrlIdle;
2767 const bool running = s.index>=Feedback::State::kTempCtrlRunning && s.index<=Feedback::State::kCurrentCtrlRunning;
2768 const bool calib = s.index==Feedback::State::kCalibrating;
2769
2770 if (s.index<=Feedback::State::kConnecting) // NoDim / Disconnected
2771 SetLedColor(fStatusFeedbackLed, kLedRed, time);
2772 if (s.index<Feedback::State::kDisconnected) // No Dim connection
2773 SetLedColor(fStatusFeedbackLed, kLedGray, time);
2774 if (s.index==Feedback::State::kConnecting) // Connecting
2775 SetLedColor(fStatusFeedbackLed, kLedOrange, time);
2776 if (connected) // Connected
2777 SetLedColor(fStatusFeedbackLed, kLedYellow, time);
2778 if (idle)
2779 SetLedColor(fStatusFeedbackLed, kLedGreen, time);
2780 if (running)
2781 SetLedColor(fStatusFeedbackLed, kLedGreenCheck, time);
2782 if (calib)
2783 SetLedColor(fStatusFeedbackLed, kLedInProgress, time);
2784
2785 fFeedbackWidget->setEnabled(connected);
2786
2787 fFeedbackCalibrate->setEnabled(s.index==Feedback::State::kConnectedFSC || s.index==Feedback::State::kConnected);
2788 fFeedbackTempStart->setEnabled(s.index==Feedback::State::kConnectedFSC || s.index==Feedback::State::kConnected);
2789
2790 fFeedbackStop->setEnabled(s.index>Feedback::State::kConnected);
2791
2792 fFeedbackTempOffset->setEnabled(s.index<=Feedback::State::kConnected);
2793 fFeedbackOutputEnable->setEnabled(s.index<Feedback::State::kTempCtrlRunning);
2794 fFeedbackOutputDisable->setEnabled(running);
2795
2796 const bool enable =
2797 s.index!=Feedback::State::kTempCtrlIdle ||
2798 s.index!=Feedback::State::kCurrentCtrlIdle ||
2799 s.index!=Feedback::State::kTempCtrlRunning ||
2800 s.index!=Feedback::State::kCurrentCtrlRunning;
2801
2802 fFeedbackFrameLeft->setEnabled(enable);
2803 fFeedbackCanvLeft->setEnabled(enable);
2804 }
2805
2806 if (server=="RATE_CONTROL")
2807 {
2808 fStatusRateControlLabel->setText(s.name.c_str());
2809 fStatusRateControlLabel->setToolTip(s.comment.c_str());
2810
2811 if (s.index==RateControl::State::kInProgress)
2812 SetLedColor(fStatusRateControlLed, kLedGreenCheck, time);
2813 if (s.index==RateControl::State::kGlobalThresholdSet)
2814 SetLedColor(fStatusRateControlLed, kLedGreen, time);
2815 if (s.index==RateControl::State::kSettingGlobalThreshold)
2816 SetLedColor(fStatusRateControlLed, kLedInProgress, time);
2817 if (s.index==RateControl::State::kConnected)
2818 SetLedColor(fStatusRateControlLed, kLedGreenBar, time);
2819 if (s.index==RateControl::State::kConnecting)
2820 SetLedColor(fStatusRateControlLed, kLedOrange, time);
2821 if (s.index<RateControl::State::kConnecting)
2822 SetLedColor(fStatusRateControlLed, kLedRed, time);
2823 if (s.index<RateControl::State::kDisconnected)
2824 SetLedColor(fStatusRateControlLed, kLedGray, time);
2825 }
2826
2827 if (server=="DATA_LOGGER")
2828 {
2829 fStatusLoggerLabel->setText(s.name.c_str());
2830 fStatusLoggerLabel->setToolTip(s.comment.c_str());
2831
2832 bool enable = true;
2833
2834 if (s.index<30) // Ready/Waiting
2835 SetLedColor(fStatusLoggerLed, kLedYellow, time);
2836 if (s.index==30) // Ready/Waiting
2837 SetLedColor(fStatusLoggerLed, kLedGreen, time);
2838 if (s.index<-1) // Offline
2839 {
2840 SetLedColor(fStatusLoggerLed, kLedGray, time);
2841 enable = false;
2842 }
2843 if (s.index>=0x100) // Error
2844 SetLedColor(fStatusLoggerLed, kLedRed, time);
2845 if (s.index==40) // Logging
2846 SetLedColor(fStatusLoggerLed, kLedGreen, time);
2847
2848 fLoggerWidget->setEnabled(enable);
2849 fLoggerStart->setEnabled(s.index>-1 && s.index<30);
2850 fLoggerStop->setEnabled(s.index>=30);
2851 }
2852
2853 if (server=="MAGIC_WEATHER")
2854 {
2855 fStatusWeatherLabel->setText(s.name.c_str());
2856
2857 if (s.index==MagicWeather::State::kReceiving)
2858 SetLedColor(fStatusWeatherLed, kLedGreen, time);
2859 if (s.index<MagicWeather::State::kReceiving)
2860 SetLedColor(fStatusWeatherLed, kLedRed, time);
2861 if (s.index<MagicWeather::State::kConnected)
2862 SetLedColor(fStatusWeatherLed, kLedGray, time);
2863 }
2864
2865 if (server=="CHAT")
2866 {
2867 fStatusChatLabel->setText(s.name.c_str());
2868
2869 fChatOnline = s.index==0;
2870
2871 SetLedColor(fStatusChatLed, fChatOnline ? kLedGreen : kLedGray, time);
2872
2873 fChatSend->setEnabled(fChatOnline);
2874 fChatMessage->setEnabled(fChatOnline);
2875 }
2876
2877 if (server=="RATESCAN")
2878 fRateScanControls->setEnabled(s.index>=RateScan::State::kConnected);
2879
2880 if (server=="SCHEDULER")
2881 {
2882 fStatusSchedulerLabel->setText(s.name.c_str());
2883
2884 SetLedColor(fStatusSchedulerLed, s.index>=0 ? kLedGreen : kLedRed, time);
2885 }
2886 }
2887
2888 void on_fTabWidget_currentChanged(int which)
2889 {
2890 if (fTabWidget->tabText(which)=="Chat")
2891 fTabWidget->setTabIcon(which, QIcon());
2892 }
2893
2894 void handleWrite(const Time &time, const string &text, int qos)
2895 {
2896 stringstream out;
2897
2898 if (text.substr(0, 6)=="CHAT: ")
2899 {
2900 if (qos==MessageImp::kDebug)
2901 return;
2902
2903 out << "<font size='-1' color='navy'>[<B>";
2904 out << time.GetAsStr("%H:%M:%S");
2905 out << "</B>]</FONT> " << text.substr(6);
2906 fChatText->append(out.str().c_str());
2907
2908 if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
2909 return;
2910
2911 static int num = 0;
2912 if (num++<2)
2913 return;
2914
2915 for (int i=0; i<fTabWidget->count(); i++)
2916 if (fTabWidget->tabText(i)=="Chat")
2917 {
2918 fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
2919 break;
2920 }
2921
2922 return;
2923 }
2924
2925
2926 out << "<font style='font-family:monospace' color='";
2927
2928 switch (qos)
2929 {
2930 case kMessage: out << "black"; break;
2931 case kInfo: out << "green"; break;
2932 case kWarn: out << "#FF6600"; break;
2933 case kError: out << "maroon"; break;
2934 case kFatal: out << "maroon"; break;
2935 case kDebug: out << "navy"; break;
2936 default: out << "navy"; break;
2937 }
2938 out << "'>";
2939 out << time.GetAsStr("%H:%M:%S.%f").substr(0,12);
2940 out << " - " << text << "</font>";
2941
2942 fLogText->append(out.str().c_str());
2943
2944 if (qos>=kWarn && qos!=kDebug && qos!=kComment)
2945 fTextEdit->append(out.str().c_str());
2946 }
2947
2948 void IndicateStateChange(const Time &time, const string &server)
2949 {
2950 const State s = GetState(server, GetCurrentState(server));
2951
2952 QApplication::postEvent(this,
2953 new FunctionEvent(bind(&FactGui::handleStateChanged, this, time, server, s)));
2954 }
2955
2956 int Write(const Time &time, const string &txt, int qos)
2957 {
2958 QApplication::postEvent(this,
2959 new FunctionEvent(bind(&FactGui::handleWrite, this, time, txt, qos)));
2960
2961 return 0;
2962 }
2963
2964 // ====================== Dim infoHandler================================
2965
2966 void handleDimService(const string &txt)
2967 {
2968 fDimSvcText->append(txt.c_str());
2969 }
2970
2971 void infoHandlerService(DimInfo &info)
2972 {
2973 const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
2974
2975 stringstream dummy;
2976 const Converter conv(dummy, fmt, false);
2977
2978 const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
2979
2980 stringstream out;
2981 out << "<font size'-1' color='navy'>[";
2982 out << tm.GetAsStr("%H:%M:%S.%f").substr(0,12);
2983 out << "]</font> <B>" << info.getName() << "</B> - ";
2984
2985 bool iserr = 2;
2986 if (!conv)
2987 {
2988 out << "Compilation of format string '" << fmt << "' failed!";
2989 }
2990 else
2991 {
2992 try
2993 {
2994 const string dat = info.getSize()==0 ? "&lt;empty&gt;" : conv.GetString(info.getData(), info.getSize());
2995 out << dat;
2996 iserr = info.getSize()==0;
2997 }
2998 catch (const runtime_error &e)
2999 {
3000 out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
3001 }
3002 }
3003
3004 // srand(hash<string>()(string(info.getName())));
3005 // int bg = rand()&0xffffff;
3006
3007 int bg = hash<string>()(string(info.getName()));
3008
3009 // allow only light colors
3010 bg = ~(bg&0x1f1f1f)&0xffffff;
3011
3012 if (iserr==2)
3013 bg = 0xffffff;
3014
3015 stringstream bgcol;
3016 bgcol << hex << setfill('0') << setw(6) << bg;
3017
3018 const string col = iserr==0 ? "black" : (iserr==1 ? "#FF6600" : "black");
3019 const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
3020
3021 QApplication::postEvent(this,
3022 new FunctionEvent(bind(&FactGui::handleDimService, this, str)));
3023 }
3024
3025 void CallInfoHandler(void (FactGui::*handler)(const DimData&), const DimData &d)
3026 {
3027 fInHandler = true;
3028 (this->*handler)(d);
3029 fInHandler = false;
3030 }
3031
3032 /*
3033 void CallInfoHandler(const boost::function<void()> &func)
3034 {
3035 // This ensures that newly received values are not sent back to the emitter
3036 // because changing the value emits the valueChanged signal (or similar)
3037 fInHandler = true;
3038 func();
3039 fInHandler = false;
3040 }*/
3041
3042 void PostInfoHandler(void (FactGui::*handler)(const DimData&))
3043 {
3044 //const boost::function<void()> f = boost::bind(handler, this, DimData(getInfo()));
3045
3046 FunctionEvent *evt = new FunctionEvent(bind(&FactGui::CallInfoHandler, this, handler, DimData(getInfo())));
3047 // FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, f));
3048 // FunctionEvent *evt = new FunctionEvent(boost::bind(handler, this, DimData(getInfo()))));
3049
3050 QApplication::postEvent(this, evt);
3051 }
3052
3053 void infoHandler()
3054 {
3055 // Initialize the time-stamp (what a weird workaround...)
3056 if (getInfo())
3057 getInfo()->getTimestamp();
3058
3059 if (getInfo()==&fDimDNS)
3060 return PostInfoHandler(&FactGui::handleDimDNS);
3061#ifdef DEBUG_DIM
3062 cout << "HandleDimInfo " << getInfo()->getName() << endl;
3063#endif
3064 if (getInfo()==&fDimLoggerStats)
3065 return PostInfoHandler(&FactGui::handleLoggerStats);
3066
3067// if (getInfo()==&fDimFadFiles)
3068// return PostInfoHandler(&FactGui::handleFadFiles);
3069
3070 if (getInfo()==&fDimFadWriteStats)
3071 return PostInfoHandler(&FactGui::handleFadWriteStats);
3072
3073 if (getInfo()==&fDimFadConnections)
3074 return PostInfoHandler(&FactGui::handleFadConnections);
3075
3076 if (getInfo()==&fDimFadFwVersion)
3077 return PostInfoHandler(&FactGui::handleFadFwVersion);
3078
3079 if (getInfo()==&fDimFadRunNumber)
3080 return PostInfoHandler(&FactGui::handleFadRunNumber);
3081
3082 if (getInfo()==&fDimFadDNA)
3083 return PostInfoHandler(&FactGui::handleFadDNA);
3084
3085 if (getInfo()==&fDimFadTemperature)
3086 return PostInfoHandler(&FactGui::handleFadTemperature);
3087
3088 if (getInfo()==&fDimFadRefClock)
3089 return PostInfoHandler(&FactGui::handleFadRefClock);
3090
3091 if (getInfo()==&fDimFadRoi)
3092 return PostInfoHandler(&FactGui::handleFadRoi);
3093
3094 if (getInfo()==&fDimFadDac)
3095 return PostInfoHandler(&FactGui::handleFadDac);
3096
3097 if (getInfo()==&fDimFadDrsCalibration)
3098 return PostInfoHandler(&FactGui::handleFadDrsCalibration);
3099
3100 if (getInfo()==&fDimFadPrescaler)
3101 return PostInfoHandler(&FactGui::handleFadPrescaler);
3102
3103 if (getInfo()==&fDimFadStatus)
3104 return PostInfoHandler(&FactGui::handleFadStatus);
3105
3106 if (getInfo()==&fDimFadStatistics1)
3107 return PostInfoHandler(&FactGui::handleFadStatistics1);
3108
3109 if (getInfo()==&fDimFadStatistics2)
3110 return PostInfoHandler(&FactGui::handleFadStatistics2);
3111
3112 if (getInfo()==&fDimFadFileFormat)
3113 return PostInfoHandler(&FactGui::handleFadFileFormat);
3114
3115 if (getInfo()==&fDimFadEvents)
3116 return PostInfoHandler(&FactGui::handleFadEvents);
3117
3118 if (getInfo()==&fDimFadRuns)
3119 return PostInfoHandler(&FactGui::handleFadRuns);
3120
3121 if (getInfo()==&fDimFadStartRun)
3122 return PostInfoHandler(&FactGui::handleFadStartRun);
3123
3124 if (getInfo()==&fDimFadRawData)
3125 return PostInfoHandler(&FactGui::handleFadRawData);
3126
3127 if (getInfo()==&fDimFadEventData)
3128 return PostInfoHandler(&FactGui::handleFadEventData);
3129
3130/*
3131 if (getInfo()==&fDimFadSetup)
3132 return PostInfoHandler(&FactGui::handleFadSetup);
3133*/
3134 if (getInfo()==&fDimLoggerFilenameNight)
3135 return PostInfoHandler(&FactGui::handleLoggerFilenameNight);
3136
3137 if (getInfo()==&fDimLoggerNumSubs)
3138 return PostInfoHandler(&FactGui::handleLoggerNumSubs);
3139
3140 if (getInfo()==&fDimLoggerFilenameRun)
3141 return PostInfoHandler(&FactGui::handleLoggerFilenameRun);
3142
3143 if (getInfo()==&fDimFtmTriggerRates)
3144 return PostInfoHandler(&FactGui::handleFtmTriggerRates);
3145
3146 if (getInfo()==&fDimFtmCounter)
3147 return PostInfoHandler(&FactGui::handleFtmCounter);
3148
3149 if (getInfo()==&fDimFtmDynamicData)
3150 return PostInfoHandler(&FactGui::handleFtmDynamicData);
3151
3152 if (getInfo()==&fDimFtmPassport)
3153 return PostInfoHandler(&FactGui::handleFtmPassport);
3154
3155 if (getInfo()==&fDimFtmFtuList)
3156 return PostInfoHandler(&FactGui::handleFtmFtuList);
3157
3158 if (getInfo()==&fDimFtmStaticData)
3159 return PostInfoHandler(&FactGui::handleFtmStaticData);
3160
3161 if (getInfo()==&fDimFtmError)
3162 return PostInfoHandler(&FactGui::handleFtmError);
3163
3164 if (getInfo()==&fDimFscTemp)
3165 return PostInfoHandler(&FactGui::handleFscTemp);
3166
3167 if (getInfo()==&fDimFscVolt)
3168 return PostInfoHandler(&FactGui::handleFscVolt);
3169
3170 if (getInfo()==&fDimFscCurrent)
3171 return PostInfoHandler(&FactGui::handleFscCurrent);
3172
3173 if (getInfo()==&fDimFscHumidity)
3174 return PostInfoHandler(&FactGui::handleFscHumidity);
3175
3176 if (getInfo()==&fDimBiasNominal)
3177 return PostInfoHandler(&FactGui::handleBiasNominal);
3178
3179 if (getInfo()==&fDimBiasVolt)
3180 return PostInfoHandler(&FactGui::handleBiasVolt);
3181
3182 if (getInfo()==&fDimBiasDac)
3183 return PostInfoHandler(&FactGui::handleBiasDac);
3184
3185 if (getInfo()==&fDimBiasCurrent)
3186 return PostInfoHandler(&FactGui::handleBiasCurrent);
3187
3188 if (getInfo()==&fDimFeedbackReference)
3189 return PostInfoHandler(&FactGui::handleFeedbackReference);
3190
3191 if (getInfo()==&fDimFeedbackDeviation)
3192 return PostInfoHandler(&FactGui::handleFeedbackDeviation);
3193
3194 if (getInfo()==&fDimFeedbackCalibration)
3195 return PostInfoHandler(&FactGui::handleFeedbackCalibration);
3196
3197 if (getInfo()==&fDimRateScan)
3198 return PostInfoHandler(&FactGui::handleRateScan);
3199
3200 if (getInfo()==&fDimMagicWeather)
3201 return PostInfoHandler(&FactGui::handleMagicWeather);
3202
3203// if (getInfo()==&fDimFadFiles)
3204// return PostInfoHandler(&FactGui::handleFadFiles);
3205
3206 for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
3207 if (i->second==getInfo())
3208 {
3209 infoHandlerService(*i->second);
3210 return;
3211 }
3212
3213 //DimNetwork::infoHandler();
3214 }
3215
3216
3217 // ======================================================================
3218
3219 bool event(QEvent *evt)
3220 {
3221 if (dynamic_cast<FunctionEvent*>(evt))
3222 return static_cast<FunctionEvent*>(evt)->Exec();
3223
3224 if (dynamic_cast<CheckBoxEvent*>(evt))
3225 {
3226 const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
3227 const QStandardItem *par = item.parent();
3228 if (par)
3229 {
3230 const QString server = par->text();
3231 const QString service = item.text();
3232
3233 const string s = (server+'/'+service).toStdString();
3234
3235 if (item.checkState()==Qt::Checked)
3236 SubscribeService(s);
3237 else
3238 UnsubscribeService(s);
3239 }
3240 }
3241
3242 return MainWindow::event(evt); // unrecognized
3243 }
3244
3245 void on_fDimCmdSend_clicked()
3246 {
3247 const QString server = fDimCmdServers->currentIndex().data().toString();
3248 const QString command = fDimCmdCommands->currentIndex().data().toString();
3249 const QString arguments = fDimCmdLineEdit->displayText();
3250
3251 // FIXME: Sending a command exactly when the info Handler changes
3252 // the list it might lead to confusion.
3253 try
3254 {
3255 SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
3256 fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
3257 fDimCmdLineEdit->clear();
3258 }
3259 catch (const runtime_error &e)
3260 {
3261 stringstream txt;
3262 txt << e.what();
3263
3264 string buffer;
3265 while (getline(txt, buffer, '\n'))
3266 fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
3267 }
3268 }
3269
3270#ifdef HAVE_ROOT
3271 void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *canv)
3272 {
3273 // kMousePressEvent // TCanvas processed QEvent mousePressEvent
3274 // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
3275 // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
3276 // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
3277 // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
3278 // kEnterEvent // TCanvas processed QEvent enterEvent
3279 // kLeaveEvent // TCanvas processed QEvent leaveEvent
3280
3281 if (dynamic_cast<TCanvas*>(obj))
3282 return;
3283
3284 TQtWidget *tipped = static_cast<TQtWidget*>(sender());
3285
3286 if (evt==11/*kMouseReleaseEvent*/)
3287 return;
3288
3289 if (evt==61/*kMouseDoubleClickEvent*/)
3290 return;
3291
3292 if (obj)
3293 {
3294 // Find the object which will get picked by the GetObjectInfo
3295 // due to buffer overflows in many root-versions
3296 // in TH1 and TProfile we have to work around and implement
3297 // our own GetObjectInfo which make everything a bit more
3298 // complicated.
3299 canv->cd();
3300#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
3301 const char *objectInfo =
3302 obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
3303#else
3304 const char *objectInfo = dynamic_cast<TH1*>(obj) ?
3305 "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
3306#endif
3307
3308 QString tipText;
3309 tipText += obj->GetName();
3310 tipText += " [";
3311 tipText += obj->ClassName();
3312 tipText += "]: ";
3313 tipText += objectInfo;
3314
3315 fStatusBar->showMessage(tipText, 3000);
3316 }
3317
3318 gSystem->DispatchOneEvent(kFALSE);
3319 //gSystem->ProcessEvents();
3320 //QWhatsThis::display(tipText)
3321 }
3322
3323 void slot_RootUpdate()
3324 {
3325 gSystem->DispatchOneEvent(kFALSE);
3326 //gSystem->ProcessEvents();
3327 QTimer::singleShot(10, this, SLOT(slot_RootUpdate()));
3328 }
3329#endif
3330
3331 void ChoosePatchThreshold(Camera &cam, int isw)
3332 {
3333 cam.Reset();
3334
3335 fThresholdIdx->setValue(isw);
3336
3337 const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
3338
3339 fPatchRate->setEnabled(isw>=0);
3340 fThresholdCrate->setEnabled(isw>=0);
3341 fThresholdBoard->setEnabled(isw>=0);
3342 fThresholdPatch->setEnabled(isw>=0);
3343
3344 if (isw<0)
3345 return;
3346
3347 const int patch = ihw%4;
3348 const int board = (ihw/4)%10;
3349 const int crate = (ihw/4)/10;
3350
3351 fInChoosePatchTH = true;
3352
3353 fThresholdCrate->setValue(crate);
3354 fThresholdBoard->setValue(board);
3355 fThresholdPatch->setValue(patch);
3356
3357 fInChoosePatchTH = false;
3358
3359 fThresholdVal->setValue(fFtmStaticData.fThreshold[ihw]);
3360 fPatchRate->setValue(fTriggerRates.fPatchRate[ihw]);
3361 fBoardRate->setValue(fTriggerRates.fBoardRate[ihw/4]);
3362
3363 // Loop over the software idx of all pixels
3364// for (unsigned int i=0; i<1440; i++)
3365// if (fPatchHW[i]==ihw)
3366// cam.SetBold(i);
3367 }
3368
3369 /*
3370 void ChoosePatchBias(Camera &cam, int isw)
3371 {
3372 cam.Reset();
3373
3374 fBiasChannel->setValue(isw);
3375
3376 const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
3377
3378 fBiasCurrent->setEnabled(isw>=0);
3379 fBiasCrate->setEnabled(isw>=0);
3380 fBiasBoard->setEnabled(isw>=0);
3381 fBiasPatch->setEnabled(isw>=0);
3382
3383 if (isw<0)
3384 return;
3385
3386 const int patch = ihw%4;
3387 const int board = (ihw/4)%10;
3388 const int crate = (ihw/4)/10;
3389
3390 fInChoosePatchBias = true;
3391
3392 fBiasCrate->setValue(crate);
3393 fBiasBoard->setValue(board);
3394 fBiasPatch->setValue(patch);
3395
3396 fInChoosePatchBias = false;
3397
3398 if (fVecBias.size()>0)
3399 {
3400 // FIXME: Mapping
3401 fBiasVoltDac->setValue(fVecBias[ihw]);
3402 fBiasVolt->setValue(fVecBias[ihw]*90./4096);
3403 }
3404
3405 fBiasCurrent->setValue(cam.GetData(isw));
3406
3407 // Loop over the software idx of all pixels
3408 for (unsigned int i=0; i<1440; i++)
3409 if (fPatchHW[i]==ihw)
3410 cam.SetBold(i);
3411 }*/
3412
3413 void slot_ChoosePixelThreshold(int isw)
3414 {
3415 fPixelIdx->setValue(isw);
3416
3417 const PixelMapEntry &entry = fPixelMap.index(isw);
3418 fPixelEnable->setChecked(fFtmStaticData.IsEnabled(entry.hw()));
3419 }
3420
3421 void slot_CameraDoubleClick(int isw)
3422 {
3423 fPixelIdx->setValue(isw);
3424
3425 const PixelMapEntry &entry = fPixelMap.index(isw);
3426 Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", uint16_t(entry.hw()));
3427 }
3428
3429 void slot_CameraMouseMove(int isw)
3430 {
3431 const PixelMapEntry &entry = fPixelMap.index(isw);
3432
3433 QString tipText;
3434 tipText += fRatesCanv->GetName();
3435 ostringstream str;
3436 str << setfill('0') <<
3437 " || HW: " << entry.crate() << "|" << entry.board() << "|" << entry.patch() << "|" << entry.pixel() << " (crate|board|patch|pixel)" <<
3438 " || HV: " << entry.hv_board << "|" << setw(2) << entry.hv_channel << " (board|channel)" <<
3439 " || ID: " << isw;
3440
3441
3442 tipText += str.str().c_str();
3443 fStatusBar->showMessage(tipText, 3000);
3444 }
3445
3446 /*
3447 void on_fThresholdIdx_valueChanged(int isw)
3448 {
3449 // fRatesCanv->SetBold(isw);
3450 // fRatesCanv->updateGL();
3451 }*/
3452
3453 /*
3454 void UpdateThresholdIdx()
3455 {
3456 if (fInChoosePatchTH)
3457 return;
3458
3459 const int crate = fThresholdCrate->value();
3460 const int board = fThresholdBoard->value();
3461 const int patch = fThresholdPatch->value();
3462
3463 const int ihw = patch + board*4 + crate*40;
3464
3465 int isw = 0;
3466 for (; isw<160; isw++)
3467 if (ihw==fPatchMapHW[isw])
3468 break;
3469
3470 on_fThresholdIdx_valueChanged(isw);
3471 }*/
3472
3473 void on_fPixelIdx_valueChanged(int isw)
3474 {
3475 int ii = 0;
3476 for (; ii<160; ii++)
3477 if (fPixelMap.index(isw).hw()/9==fPatchMapHW[ii])
3478 break;
3479
3480 fRatesCanv->SetWhite(isw);
3481 ChoosePatchThreshold(*fRatesCanv, ii);
3482
3483 const PixelMapEntry &entry = fPixelMap.index(isw);
3484 fPixelEnable->setChecked(fFtmStaticData.IsEnabled(entry.hw()));
3485 }
3486
3487 // ------------------- Bias display ---------------------
3488
3489 void UpdateBiasValues()
3490 {
3491 const int b = fBiasHvBoard->value();
3492 const int c = fBiasHvChannel->value();
3493
3494 const int ihw = b*32+c;
3495
3496 const double offset = fVecBiasCalibOffset.size()>0 ? fVecBiasCalibOffset[ihw] : 0;
3497
3498
3499 if (fVecBiasDac.size()>0)
3500 {
3501 fBiasVoltCur->setValue(fVecBiasDac[ihw]*90./4096-offset);
3502 fBiasVoltRef->setValue(fVecBiasDac[ihw+416]*90./4096-offset);
3503
3504 SetLedColor(fBiasNominalLed,
3505 fVecBiasDac[ihw]==fVecBiasDac[ihw+416]?kLedGreen:kLedRed, Time());
3506 }
3507
3508 if (fVecBiasCurrent.size()>0)
3509 {
3510 double val = abs(fVecBiasCurrent[ihw]) * 5000./4096;
3511 if (fBiasOffsets.size()>0 && fVecBiasVolt.size()>0)
3512 val -= fVecBiasVolt[ihw]/fBiasOffsets[ihw]*1e6;
3513
3514 fBiasCurrent->setValue(val);
3515 SetLedColor(fBiasOverCurrentLed,
3516 fVecBiasCurrent[ihw]<0?kLedRed:kLedGreen, Time());
3517 }
3518
3519 if (fBiasOffsets.size()>0 && fVecBiasVolt.size()>0)
3520 fBiasOffset->setValue(fVecBiasVolt[ihw]/fBiasOffsets[ihw]*1e6);
3521
3522 fBiasOffset->setEnabled(fBiasOffsets.size()>0 && fVecBiasVolt.size()>0);
3523 }
3524
3525 void UpdateBiasCam(const PixelMapEntry &entry)
3526 {
3527 fInChooseBiasCam = true;
3528
3529 fBiasCamCrate->setValue(entry.crate());
3530 fBiasCamBoard->setValue(entry.board());
3531 fBiasCamPatch->setValue(entry.patch());
3532 fBiasCamPixel->setValue(entry.pixel());
3533
3534 fInChooseBiasCam = false;
3535 }
3536
3537 void BiasHvChannelChanged()
3538 {
3539 if (fInChooseBiasHv)
3540 return;
3541
3542 const int b = fBiasHvBoard->value();
3543 const int ch = fBiasHvChannel->value();
3544
3545 // FIXME: Mark corresponding patch in camera
3546 const PixelMapEntry &entry = fPixelMap.hv(b, ch);
3547 fBiasCamV->SetWhite(entry.index);
3548 fBiasCamA->SetWhite(entry.index);
3549 fBiasCamV->updateCamera();
3550 fBiasCamA->updateCamera();
3551
3552 UpdateBiasCam(entry);
3553 UpdateBiasValues();
3554 }
3555
3556 void UpdateBiasHv(const PixelMapEntry &entry)
3557 {
3558 fInChooseBiasHv = true;
3559
3560 fBiasHvBoard->setValue(entry.hv_board);
3561 fBiasHvChannel->setValue(entry.hv_channel);
3562
3563 fInChooseBiasHv = false;
3564 }
3565
3566 void BiasCamChannelChanged()
3567 {
3568 if (fInChooseBiasCam)
3569 return;
3570
3571 const int crate = fBiasCamCrate->value();
3572 const int board = fBiasCamBoard->value();
3573 const int patch = fBiasCamPatch->value();
3574 const int pixel = fBiasCamPixel->value();
3575
3576 // FIXME: Display corresponding patches
3577 const PixelMapEntry &entry = fPixelMap.cbpx(crate, board, patch, pixel);
3578 fBiasCamV->SetWhite(entry.index);
3579 fBiasCamA->SetWhite(entry.index);
3580 fBiasCamV->updateCamera();
3581 fBiasCamA->updateCamera();
3582
3583 UpdateBiasHv(entry);
3584 UpdateBiasValues();
3585 }
3586
3587 void slot_ChooseBiasChannel(int isw)
3588 {
3589 const PixelMapEntry &entry = fPixelMap.index(isw);
3590
3591 UpdateBiasHv(entry);
3592 UpdateBiasCam(entry);
3593 UpdateBiasValues();
3594 }
3595
3596 void on_fBiasDispRefVolt_stateChanged(int = 0)
3597 {
3598 // FIXME: Display patches for which ref==cur
3599
3600 valarray<double> dat(0., 1440);
3601
3602 int offset = 0;
3603 if (!fBiasDispRefVolt->isChecked())
3604 fBiasCamV->setTitle("Applied BIAS voltage");
3605 else
3606 {
3607 fBiasCamV->setTitle("Reference BIAS voltage");
3608 offset = 416;
3609 }
3610
3611 if (fVecBiasDac.size()>0)
3612 {
3613 for (int i=0; i<1440; i++)
3614 {
3615 const PixelMapEntry &entry = fPixelMap.index(i);
3616 dat[i] = fVecBiasDac[entry.hv()+offset]*90./4096;
3617
3618 if (fVecBiasCalibOffset.size()>0)
3619 dat[i] -= fVecBiasCalibOffset[entry.hv()];
3620
3621 fBiasCamV->highlightPixel(i, fVecBiasDac[entry.hv()]!=fVecBiasDac[entry.hv()+416]);
3622 }
3623
3624 fBiasCamV->SetData(dat);
3625 }
3626
3627 fBiasCamV->updateCamera();
3628 }
3629
3630 // ------------------------------------------------------
3631
3632 void on_fPixelEnable_stateChanged(int b)
3633 {
3634 if (fInHandler)
3635 return;
3636
3637 const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
3638
3639 Dim::SendCommand(b==Qt::Unchecked ?
3640 "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
3641 uint16_t(entry.hw()));
3642 }
3643
3644 void on_fPixelDisableOthers_clicked()
3645 {
3646 const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
3647 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PIXELS_EXCEPT", uint16_t(entry.hw()));
3648 }
3649
3650 void on_fThresholdDisableOthers_clicked()
3651 {
3652 const int16_t isw = fThresholdIdx->value();
3653 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3654 if (ihw<0)
3655 return;
3656
3657 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PATCHES_EXCEPT", ihw);
3658 }
3659
3660 void on_fThresholdEnablePatch_clicked()
3661 {
3662 const int16_t isw = fThresholdIdx->value();
3663 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3664 if (ihw<0)
3665 return;
3666
3667 Dim::SendCommand("FTM_CONTROL/ENABLE_PATCH", ihw);
3668 }
3669
3670 void on_fThresholdDisablePatch_clicked()
3671 {
3672 const int16_t isw = fThresholdIdx->value();
3673 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3674 if (ihw<0)
3675 return;
3676
3677 Dim::SendCommand("FTM_CONTROL/DISABLE_PATCH", ihw);
3678 }
3679
3680 void on_fThresholdVal_valueChanged(int v)
3681 {
3682 fThresholdVolt->setValue(2500./4095*v);
3683
3684 const int32_t isw = fThresholdIdx->value();
3685 const int32_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3686
3687 const int32_t d[2] = { ihw, v };
3688
3689 if (!fInHandler)
3690 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
3691 }
3692
3693 TGraph fGraphFtmTemp[4];
3694 TGraph fGraphFtmRate;
3695 TGraph fGraphPatchRate[160];
3696 TGraph fGraphBoardRate[40];
3697
3698#ifdef HAVE_ROOT
3699 TH1 *DrawTimeFrame(const char *ytitle)
3700 {
3701 const double tm = Time().RootTime();
3702
3703 TH1F *h=new TH1F("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
3704 h->SetDirectory(0);
3705 h->SetBit(kCanDelete);
3706 h->SetStats(kFALSE);
3707// h.SetMinimum(0);
3708// h.SetMaximum(1);
3709 h->SetXTitle("Time");
3710 h->SetYTitle(ytitle);
3711 h->GetXaxis()->CenterTitle();
3712 h->GetYaxis()->CenterTitle();
3713 h->GetXaxis()->SetTimeDisplay(true);
3714 h->GetXaxis()->SetTimeFormat("%Mh%S'");
3715 h->GetXaxis()->SetLabelSize(0.025);
3716 h->GetYaxis()->SetLabelSize(0.025);
3717 h->GetYaxis()->SetTitleOffset(1.2);
3718 // h.GetYaxis()->SetTitleSize(1.2);
3719 return h;
3720 }
3721#endif
3722
3723 pair<string,string> Split(const string &str) const
3724 {
3725 const size_t p = str.find_first_of('|');
3726 if (p==string::npos)
3727 return make_pair(str, "");
3728
3729 return make_pair(str.substr(0, p), str.substr(p+1));
3730 }
3731
3732public:
3733 FactGui(Configuration &conf) :
3734 fFtuStatus(40),
3735 /*fPixelMapHW(1440),*/ fPatchMapHW(160),
3736 fInChoosePatchTH(false),
3737 fInChooseBiasHv(false), fInChooseBiasCam(false),
3738 fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
3739 //-
3740 fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
3741 fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHTLY", (void*)NULL, 0, this),
3742 fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", (void*)NULL, 0, this),
3743 fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", (void*)NULL, 0, this),
3744 //-
3745 fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
3746 fDimFtmTriggerRates ("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this),
3747 fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
3748 fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
3749 fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
3750 fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this),
3751 fDimFtmCounter ("FTM_CONTROL/COUNTER", (void*)NULL, 0, this),
3752 //-
3753 fDimFadWriteStats ("FAD_CONTROL/STATS", (void*)NULL, 0, this),
3754 fDimFadStartRun ("FAD_CONTROL/START_RUN", (void*)NULL, 0, this),
3755 fDimFadRuns ("FAD_CONTROL/RUNS", (void*)NULL, 0, this),
3756 fDimFadEvents ("FAD_CONTROL/EVENTS", (void*)NULL, 0, this),
3757 fDimFadRawData ("FAD_CONTROL/RAW_DATA", (void*)NULL, 0, this),
3758 fDimFadEventData ("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, this),
3759 fDimFadConnections ("FAD_CONTROL/CONNECTIONS", (void*)NULL, 0, this),
3760 fDimFadFwVersion ("FAD_CONTROL/FIRMWARE_VERSION", (void*)NULL, 0, this),
3761 fDimFadRunNumber ("FAD_CONTROL/RUN_NUMBER", (void*)NULL, 0, this),
3762 fDimFadDNA ("FAD_CONTROL/DNA", (void*)NULL, 0, this),
3763 fDimFadTemperature ("FAD_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3764 fDimFadPrescaler ("FAD_CONTROL/PRESCALER", (void*)NULL, 0, this),
3765 fDimFadRefClock ("FAD_CONTROL/REFERENCE_CLOCK", (void*)NULL, 0, this),
3766 fDimFadRoi ("FAD_CONTROL/REGION_OF_INTEREST", (void*)NULL, 0, this),
3767 fDimFadDac ("FAD_CONTROL/DAC", (void*)NULL, 0, this),
3768 fDimFadDrsCalibration ("FAD_CONTROL/DRS_CALIBRATION", (void*)NULL, 0, this),
3769 fDimFadStatus ("FAD_CONTROL/STATUS", (void*)NULL, 0, this),
3770 fDimFadStatistics1 ("FAD_CONTROL/STATISTICS1", (void*)NULL, 0, this),
3771 fDimFadStatistics2 ("FAD_CONTROL/STATISTICS2", (void*)NULL, 0, this),
3772 fDimFadFileFormat ("FAD_CONTROL/FILE_FORMAT", (void*)NULL, 0, this),
3773 //-
3774 fDimFscTemp ("FSC_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3775 fDimFscVolt ("FSC_CONTROL/VOLTAGE", (void*)NULL, 0, this),
3776 fDimFscCurrent ("FSC_CONTROL/CURRENT", (void*)NULL, 0, this),
3777 fDimFscHumidity ("FSC_CONTROL/HUMIDITY", (void*)NULL, 0, this),
3778 //-
3779 fDimFeedbackDeviation ("FEEDBACK/DEVIATION", (void*)NULL, 0, this),
3780 fDimFeedbackReference ("FEEDBACK/REFERENCE", (void*)NULL, 0, this),
3781 fDimFeedbackCalibration("FEEDBACK/CALIBRATION", (void*)NULL, 0, this),
3782 //-
3783 fDimBiasNominal ("BIAS_CONTROL/NOMINAL", (void*)NULL, 0, this),
3784 fDimBiasVolt ("BIAS_CONTROL/VOLTAGE", (void*)NULL, 0, this),
3785 fDimBiasDac ("BIAS_CONTROL/DAC", (void*)NULL, 0, this),
3786 fDimBiasCurrent ("BIAS_CONTROL/CURRENT", (void*)NULL, 0, this),
3787 //-
3788 fDimRateScan ("RATE_SCAN/DATA", (void*)NULL, 0, this),
3789 //-
3790 fDimMagicWeather ("MAGIC_WEATHER/DATA", (void*)NULL, 0, this),
3791 //-
3792 fDimVersion(0),
3793 fFreeSpaceLogger(UINT64_MAX), fFreeSpaceData(UINT64_MAX),
3794 fEventData(0),
3795 fDrsCalibration(1440*1024*6+160*1024*2),
3796 fTimeStamp0(0)
3797 {
3798 fClockCondFreq->addItem("--- Hz", QVariant(-1));
3799 fClockCondFreq->addItem("800 MHz", QVariant(800));
3800 fClockCondFreq->addItem("1 GHz", QVariant(1000));
3801 fClockCondFreq->addItem("2 GHz", QVariant(2000));
3802 fClockCondFreq->addItem("3 GHz", QVariant(3000));
3803 fClockCondFreq->addItem("4 GHz", QVariant(4000));
3804 fClockCondFreq->addItem("5 GHz", QVariant(5000));
3805
3806 cout << "-- run counter ---" << endl;
3807 fMcpNumEvents->addItem("unlimited", QVariant(0));
3808 const vector<uint32_t> runcount = conf.Vec<uint32_t>("run-count");
3809 for (vector<uint32_t>::const_iterator it=runcount.begin(); it!=runcount.end(); it++)
3810 {
3811 cout << *it << endl;
3812 ostringstream str;
3813 str << *it;
3814 fMcpNumEvents->addItem(str.str().c_str(), QVariant(*it));
3815 }
3816
3817 cout << "-- run times ---" << endl;
3818 fMcpTime->addItem("unlimited", QVariant(0));
3819 const vector<string> runtime = conf.Vec<string>("run-time");
3820 for (vector<string>::const_iterator it=runtime.begin(); it!=runtime.end(); it++)
3821 {
3822 const pair<string,string> p = Split(*it);
3823 cout << *it << "|" << p.second << "|" << p.first << "|" << endl;
3824 fMcpTime->addItem(p.second.c_str(), QVariant(stoi(p.first)));
3825 }
3826
3827 cout << "-- run types ---" << endl;
3828 const vector<string> runtype = conf.Vec<string>("run-type");
3829 for (vector<string>::const_iterator it=runtype.begin(); it!=runtype.end(); it++)
3830 {
3831 const pair<string,string> p = Split(*it);
3832 cout << *it << "|" << p.second << "|" << p.first << "|" << endl;
3833 fMcpRunType->addItem(p.second.c_str(), QVariant(p.first.c_str()));
3834 }
3835
3836 fTriggerWidget->setEnabled(false);
3837 fFtuWidget->setEnabled(false);
3838 fFtuGroupEnable->setEnabled(false);
3839 fRatesControls->setEnabled(false);
3840 fFadWidget->setEnabled(false);
3841 fGroupEthernet->setEnabled(false);
3842 fGroupOutput->setEnabled(false);
3843 fLoggerWidget->setEnabled(false);
3844 fBiasWidget->setEnabled(false);
3845 fAuxWidget->setEnabled(false);
3846
3847 fChatSend->setEnabled(false);
3848 fChatMessage->setEnabled(false);
3849
3850 DimClient::sendCommand("CHAT/MSG", "GUI online.");
3851 // + MessageDimRX
3852
3853 // --------------------------------------------------------------------------
3854
3855 if (!fPixelMap.Read(conf.Get<string>("pixel-map-file")))
3856 {
3857 cerr << "ERROR - Problems reading " << conf.Get<string>("pixel-map-file") << endl;
3858 exit(-1);
3859 }
3860
3861 // --------------------------------------------------------------------------
3862
3863 ifstream fin3("PatchList.txt");
3864
3865 string buf;
3866
3867 int l = 0;
3868 while (getline(fin3, buf, '\n'))
3869 {
3870 buf = Tools::Trim(buf);
3871 if (buf[0]=='#')
3872 continue;
3873
3874 unsigned int softid, hardid;
3875
3876 stringstream str(buf);
3877
3878 str >> softid;
3879 str >> hardid;
3880
3881 if (softid>=fPatchMapHW.size())
3882 continue;
3883
3884 fPatchMapHW[softid] = hardid-1;
3885
3886 l++;
3887 }
3888
3889 if (l!=160)
3890 cerr << "WARNING - Problems reading PatchList.txt" << endl;
3891
3892 // --------------------------------------------------------------------------
3893
3894 fCommentsWidget->setEnabled(false);
3895
3896 static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))");
3897
3898 const string database = conf.Get<string>("CommentDB");
3899
3900 if (!database.empty())
3901 {
3902 boost::smatch what;
3903 if (!boost::regex_match(database, what, expr, boost::match_extra))
3904 throw runtime_error("Couldn't parse '"+database+"'.");
3905
3906 if (what.size()!=10)
3907 throw runtime_error("Error parsing '"+database+"'.");
3908
3909 const string user = what[2];
3910 const string passwd = what[4];
3911 const string server = what[5];
3912 const string db = what[9];
3913 const int port = atoi(string(what[7]).c_str());
3914
3915 QSqlDatabase qdb = QSqlDatabase::addDatabase("QMYSQL");
3916 qdb.setHostName(server.c_str());
3917 qdb.setDatabaseName(db.c_str());
3918 qdb.setUserName(user.c_str());
3919 qdb.setPassword(passwd.c_str());
3920 qdb.setPort(port);
3921 qdb.setConnectOptions("CLIENT_SSL=1;MYSQL_OPT_RECONNECT=1");
3922 if (qdb.open())
3923 {
3924 QSqlTableModel *model = new QSqlTableModel(fTableComments, qdb);
3925 model->setTable("runcomments");
3926 model->setEditStrategy(QSqlTableModel::OnManualSubmit);
3927
3928 const bool ok2 = model->select();
3929
3930 if (ok2)
3931 {
3932 fTableComments->setModel(model);
3933 fTableComments->resizeColumnsToContents();
3934 fTableComments->resizeRowsToContents();
3935
3936 connect(fCommentSubmit, SIGNAL(clicked()), model, SLOT(submitAll()));
3937 connect(fCommentRevert, SIGNAL(clicked()), model, SLOT(revertAll()));
3938 connect(fCommentUpdateLayout, SIGNAL(clicked()), fTableComments, SLOT(resizeColumnsToContents()));
3939 connect(fCommentUpdateLayout, SIGNAL(clicked()), fTableComments, SLOT(resizeRowsToContents()));
3940
3941 fCommentsWidget->setEnabled(true);
3942 }
3943 else
3944 cout << "\n==> ERROR: Select on table failed.\n" << endl;
3945 }
3946 else
3947 cout << "\n==> ERROR: Connection to database failed:\n "
3948 << qdb.lastError().text().toStdString() << endl << endl;
3949 }
3950
3951 // --------------------------------------------------------------------------
3952#ifdef HAVE_ROOT
3953
3954 fGraphFeedbackDev.SetLineColor(kBlue);
3955 fGraphFeedbackDev.SetMarkerColor(kBlue);
3956 fGraphFeedbackDev.SetMarkerStyle(kFullDotMedium);
3957
3958 fGraphFeedbackCmd.SetLineColor(kBlue);
3959 fGraphFeedbackCmd.SetMarkerColor(kBlue);
3960 fGraphFeedbackCmd.SetMarkerStyle(kFullDotMedium);
3961
3962 // Evolution of control deviation
3963 // Evolution of command values (bias voltage change)
3964 fGraphFeedbackDev.SetName("ControlDev");
3965 fGraphFeedbackCmd.SetName("CommandVal");
3966
3967 TCanvas *c = fFeedbackDev->GetCanvas();
3968 c->SetBorderMode(0);
3969 c->SetFrameBorderMode(0);
3970 c->SetFillColor(kWhite);
3971 c->SetRightMargin(0.03);
3972 c->SetTopMargin(0.03);
3973 c->SetGrid();
3974
3975 TH1 *hf = DrawTimeFrame("Control deviation [mV] ");
3976 hf->GetXaxis()->SetLabelSize(0.07);
3977 hf->GetYaxis()->SetLabelSize(0.07);
3978 hf->GetYaxis()->SetTitleSize(0.08);
3979 hf->GetYaxis()->SetTitleOffset(0.55);
3980 hf->GetXaxis()->SetTitle("");
3981 hf->GetYaxis()->SetRangeUser(-99, 99);
3982
3983 c->GetListOfPrimitives()->Add(hf, "");
3984 c->GetListOfPrimitives()->Add(&fGraphFeedbackDev, "LP");
3985
3986 c = fFeedbackCmd->GetCanvas();
3987 c->SetBorderMode(0);
3988 c->SetFrameBorderMode(0);
3989 c->SetFillColor(kWhite);
3990 c->SetRightMargin(0.03);
3991 c->SetTopMargin(0.03);
3992 c->SetGrid();
3993
3994 hf = DrawTimeFrame("Command delta value [mV] ");
3995 hf->GetXaxis()->SetLabelSize(0.07);
3996 hf->GetYaxis()->SetLabelSize(0.07);
3997 hf->GetYaxis()->SetTitleSize(0.08);
3998 hf->GetYaxis()->SetTitleOffset(0.55);
3999 hf->GetXaxis()->SetTitle("");
4000 hf->GetYaxis()->SetRangeUser(-99*10, 99*10);
4001
4002 c->GetListOfPrimitives()->Add(hf, "");
4003 c->GetListOfPrimitives()->Add(&fGraphFeedbackCmd, "LP");
4004
4005 // --------------------------------------------------------------------------
4006
4007 c = fRateScanCanv->GetCanvas();
4008 //c->SetBit(TCanvas::kNoContextMenu);
4009 c->SetBorderMode(0);
4010 c->SetFrameBorderMode(0);
4011 c->SetFillColor(kWhite);
4012 c->SetRightMargin(0.03);
4013 c->SetTopMargin(0.03);
4014 c->SetGrid();
4015
4016 TH1F *h=new TH1F("Frame", "", 1, 0, 1);
4017 h->SetDirectory(0);
4018 h->SetBit(kCanDelete);
4019 h->SetStats(kFALSE);
4020 h->SetXTitle("Threshold [DAC]");
4021 h->SetYTitle("Rate [Hz]");
4022 h->GetXaxis()->CenterTitle();
4023 h->GetYaxis()->CenterTitle();
4024 h->GetXaxis()->SetLabelSize(0.025);
4025 h->GetYaxis()->SetLabelSize(0.025);
4026 h->GetYaxis()->SetTitleOffset(1.2);
4027 c->GetListOfPrimitives()->Add(h, "");
4028
4029 fGraphRateScan[0].SetName("CameraRate");
4030 for (int i=0; i<40; i++)
4031 {
4032 fGraphRateScan[i+1].SetName("BoardRate");
4033 fGraphRateScan[i+1].SetMarkerStyle(kFullDotMedium);
4034 }
4035 for (int i=0; i<160; i++)
4036 {
4037 fGraphRateScan[i+41].SetName("PatchRate");
4038 fGraphRateScan[i+41].SetMarkerStyle(kFullDotMedium);
4039 }
4040
4041 fGraphRateScan[0].SetLineColor(kBlue);
4042 fGraphRateScan[0].SetMarkerColor(kBlue);
4043 fGraphRateScan[0].SetMarkerStyle(kFullDotSmall);
4044 c->GetListOfPrimitives()->Add(&fGraphRateScan[0], "LP");
4045
4046 // --------------------------------------------------------------------------
4047
4048 c = fFtmRateCanv->GetCanvas();
4049 //c->SetBit(TCanvas::kNoContextMenu);
4050 c->SetBorderMode(0);
4051 c->SetFrameBorderMode(0);
4052 c->SetFillColor(kWhite);
4053 c->SetRightMargin(0.03);
4054 c->SetTopMargin(0.03);
4055 c->SetGrid();
4056
4057 hf = DrawTimeFrame("Trigger rate [Hz]");
4058 hf->GetYaxis()->SetRangeUser(0, 1010);
4059
4060 for (int i=0; i<160; i++)
4061 {
4062 fGraphPatchRate[i].SetName("PatchRate");
4063 //fGraphPatchRate[i].SetLineColor(kBlue);
4064 //fGraphPatchRate[i].SetMarkerColor(kBlue);
4065 fGraphPatchRate[i].SetMarkerStyle(kFullDotMedium);
4066 }
4067 for (int i=0; i<40; i++)
4068 {
4069 fGraphBoardRate[i].SetName("BoardRate");
4070 //fGraphBoardRate[i].SetLineColor(kBlue);
4071 //fGraphBoardRate[i].SetMarkerColor(kBlue);
4072 fGraphBoardRate[i].SetMarkerStyle(kFullDotMedium);
4073 }
4074
4075 fGraphFtmRate.SetLineColor(kBlue);
4076 fGraphFtmRate.SetMarkerColor(kBlue);
4077 fGraphFtmRate.SetMarkerStyle(kFullDotSmall);
4078
4079 c->GetListOfPrimitives()->Add(hf, "");
4080 c->GetListOfPrimitives()->Add(&fGraphFtmRate, "LP");
4081
4082 /*
4083 TCanvas *c = fFtmTempCanv->GetCanvas();
4084 c->SetBit(TCanvas::kNoContextMenu);
4085 c->SetBorderMode(0);
4086 c->SetFrameBorderMode(0);
4087 c->SetFillColor(kWhite);
4088 c->SetRightMargin(0.03);
4089 c->SetTopMargin(0.03);
4090 c->cd();
4091 */
4092 //CreateTimeFrame("Temperature / �C");
4093
4094 fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
4095 fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
4096 fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
4097 fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
4098
4099 fGraphFtmTemp[1].SetLineColor(kBlue);
4100 fGraphFtmTemp[2].SetLineColor(kRed);
4101 fGraphFtmTemp[3].SetLineColor(kGreen);
4102
4103 fGraphFtmTemp[1].SetMarkerColor(kBlue);
4104 fGraphFtmTemp[2].SetMarkerColor(kRed);
4105 fGraphFtmTemp[3].SetMarkerColor(kGreen);
4106
4107 //fGraphFtmTemp[0].Draw("LP");
4108 //fGraphFtmTemp[1].Draw("LP");
4109 //fGraphFtmTemp[2].Draw("LP");
4110 //fGraphFtmTemp[3].Draw("LP");
4111
4112 // --------------------------------------------------------------------------
4113
4114 c = fAdcDataCanv->GetCanvas();
4115 //c->SetBit(TCanvas::kNoContextMenu);
4116 c->SetBorderMode(0);
4117 c->SetFrameBorderMode(0);
4118 c->SetFillColor(kWhite);
4119 c->SetRightMargin(0.10);
4120 c->SetGrid();
4121 //c->cd();
4122#endif
4123
4124 // --------------------------------------------------------------------------
4125 fFeedbackDevCam->assignPixelMap(fPixelMap);
4126 fFeedbackDevCam->setAutoscaleLowerLimit((fFeedbackDevMin->minimum()+0.5*fFeedbackDevMin->singleStep()));
4127 fFeedbackDevCam->SetMin(fFeedbackDevMin->value());
4128 fFeedbackDevCam->SetMax(fFeedbackDevMax->value());
4129 fFeedbackDevCam->updateCamera();
4130
4131 fFeedbackCmdCam->assignPixelMap(fPixelMap);
4132 fFeedbackCmdCam->setAutoscaleLowerLimit((fFeedbackCmdMin->minimum()+0.5*fFeedbackCmdMin->singleStep()));
4133 fFeedbackCmdCam->SetMin(fFeedbackCmdMin->value());
4134 fFeedbackCmdCam->SetMax(fFeedbackCmdMax->value());
4135 fFeedbackCmdCam->updateCamera();
4136
4137 // --------------------------------------------------------------------------
4138
4139 fBiasCamV->assignPixelMap(fPixelMap);
4140 fBiasCamV->setAutoscaleLowerLimit((fBiasVoltMin->minimum()+0.5*fBiasVoltMin->singleStep()));
4141 fBiasCamV->SetMin(fBiasVoltMin->value());
4142 fBiasCamV->SetMax(fBiasVoltMax->value());
4143 fBiasCamV->updateCamera();
4144
4145 fBiasCamA->assignPixelMap(fPixelMap);
4146 fBiasCamA->setAutoscaleLowerLimit((fBiasCurrentMin->minimum()+0.5*fBiasCurrentMin->singleStep()));
4147 fBiasCamA->SetMin(fBiasCurrentMin->value());
4148 fBiasCamA->SetMax(fBiasCurrentMax->value());
4149 fBiasCamA->updateCamera();
4150
4151 // --------------------------------------------------------------------------
4152
4153 fRatesCanv->assignPixelMap(fPixelMap);
4154 fRatesCanv->setAutoscaleLowerLimit((fRatesMin->minimum()+0.5*fRatesMin->singleStep())*0.001);
4155 fRatesCanv->SetMin(fRatesMin->value());
4156 fRatesCanv->SetMax(fRatesMax->value());
4157 fRatesCanv->updateCamera();
4158 on_fPixelIdx_valueChanged(0);
4159
4160 // --------------------------------------------------------------------------
4161
4162 fRatesCanv->setTitle("Patch rates");
4163 fRatesCanv->setUnits("Hz");
4164
4165 fBiasCamA->setTitle("BIAS current");
4166 fBiasCamA->setUnits("uA");
4167
4168 fBiasCamV->setTitle("Applied BIAS voltage");
4169 fBiasCamV->setUnits("V");
4170
4171 fEventCanv1->setTitle("Average (all slices)");
4172 fEventCanv2->setTitle("RMS (all slices)");
4173 fEventCanv3->setTitle("Maximum (all slices)");
4174 fEventCanv4->setTitle("Position of maximum (all slices)");
4175
4176 fEventCanv1->setUnits("mV");
4177 fEventCanv2->setUnits("mV");
4178 fEventCanv3->setUnits("mV");
4179 fEventCanv4->setUnits("slice");
4180
4181 // --------------------------------------------------------------------------
4182
4183 fFeedbackDevCam->setTitle("Control deviation (Pulser amplitude voltage)");
4184 fFeedbackCmdCam->setTitle("Applied voltage change (BIAS voltage)");
4185
4186 fFeedbackDevCam->setUnits("mV");
4187 fFeedbackCmdCam->setUnits("mV");
4188
4189 // --------------------------------------------------------------------------
4190
4191 QTimer::singleShot(1000, this, SLOT(slot_RootUpdate()));
4192
4193 //widget->setMouseTracking(true);
4194 //widget->EnableSignalEvents(kMouseMoveEvent);
4195
4196 fFtmRateCanv->setMouseTracking(true);
4197 fFtmRateCanv->EnableSignalEvents(kMouseMoveEvent);
4198
4199 fAdcDataCanv->setMouseTracking(true);
4200 fAdcDataCanv->EnableSignalEvents(kMouseMoveEvent);
4201
4202 fRatesCanv->setMouseTracking(true);
4203 fEventCanv1->setMouseTracking(true);
4204 fEventCanv2->setMouseTracking(true);
4205 fEventCanv3->setMouseTracking(true);
4206 fEventCanv4->setMouseTracking(true);
4207
4208 fBiasCamV->setMouseTracking(true);
4209 fBiasCamA->setMouseTracking(true);
4210
4211 fFeedbackDevCam->setMouseTracking(true);
4212 fFeedbackCmdCam->setMouseTracking(true);
4213
4214 fEventCanv1->ShowPixelCursor(true);
4215 fEventCanv2->ShowPixelCursor(true);
4216 fEventCanv3->ShowPixelCursor(true);
4217 fEventCanv4->ShowPixelCursor(true);
4218
4219 fEventCanv1->ShowPatchCursor(true);
4220 fEventCanv2->ShowPatchCursor(true);
4221 fEventCanv3->ShowPatchCursor(true);
4222 fEventCanv4->ShowPatchCursor(true);
4223
4224 fFeedbackDevCam->ShowPixelCursor(true);
4225 fFeedbackCmdCam->ShowPixelCursor(true);
4226
4227 fFeedbackDevCam->ShowPatchCursor(true);
4228 fFeedbackCmdCam->ShowPatchCursor(true);
4229
4230 connect(fRatesCanv, SIGNAL(signalPixelMoveOver(int)),
4231 this, SLOT(slot_CameraMouseMove(int)));
4232 connect(fEventCanv1, SIGNAL(signalPixelMoveOver(int)),
4233 this, SLOT(slot_CameraMouseMove(int)));
4234 connect(fEventCanv2, SIGNAL(signalPixelMoveOver(int)),
4235 this, SLOT(slot_CameraMouseMove(int)));
4236 connect(fEventCanv3, SIGNAL(signalPixelMoveOver(int)),
4237 this, SLOT(slot_CameraMouseMove(int)));
4238 connect(fEventCanv4, SIGNAL(signalPixelMoveOver(int)),
4239 this, SLOT(slot_CameraMouseMove(int)));
4240
4241 connect(fBiasCamV, SIGNAL(signalPixelMoveOver(int)),
4242 this, SLOT(slot_CameraMouseMove(int)));
4243 connect(fBiasCamA, SIGNAL(signalPixelMoveOver(int)),
4244 this, SLOT(slot_CameraMouseMove(int)));
4245
4246 connect(fFeedbackDevCam, SIGNAL(signalPixelMoveOver(int)),
4247 this, SLOT(slot_CameraMouseMove(int)));
4248 connect(fFeedbackCmdCam, SIGNAL(signalPixelMoveOver(int)),
4249 this, SLOT(slot_CameraMouseMove(int)));
4250
4251 connect(fRatesCanv, SIGNAL(signalPixelDoubleClick(int)),
4252 this, SLOT(slot_CameraDoubleClick(int)));
4253 connect(fRatesCanv, SIGNAL(signalCurrentPixel(int)),
4254 this, SLOT(slot_ChoosePixelThreshold(int)));
4255 connect(fBiasCamV, SIGNAL(signalCurrentPixel(int)),
4256 this, SLOT(slot_ChooseBiasChannel(int)));
4257 connect(fBiasCamA, SIGNAL(signalCurrentPixel(int)),
4258 this, SLOT(slot_ChooseBiasChannel(int)));
4259
4260 connect(fFtmRateCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
4261 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
4262 connect(fAdcDataCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
4263 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
4264 }
4265
4266 ~FactGui()
4267 {
4268 // Unsubscribe all services
4269 for (map<string,DimInfo*>::iterator i=fServices.begin();
4270 i!=fServices.end(); i++)
4271 delete i->second;
4272
4273 // This is allocated as a chuck of chars
4274 delete [] reinterpret_cast<char*>(fEventData);
4275 }
4276};
4277
4278#endif
Note: See TracBrowser for help on using the repository browser.