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

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