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

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