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

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