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

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