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

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