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

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