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

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