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

Last change on this file since 11228 was 11226, checked in by tbretz, 14 years ago
broadcast whole events via Dim; made MainWindow and abstract base class and implemented the Adc tab widgets into MainWindow and FactGui
File size: 84.6 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/HeadersFTM.h"
19#include "src/HeadersFAD.h"
20#include "src/DimNetwork.h"
21#include "src/tools.h"
22
23#include "TROOT.h"
24#include "TSystem.h"
25#include "TGraph.h"
26#include "TH1.h"
27#include "TStyle.h"
28#include "TMarker.h"
29#include "TColor.h"
30
31using namespace std;
32
33// #########################################################################
34
35class Camera : public TObject
36{
37 typedef pair<double,double> Position;
38 typedef vector<Position> Positions;
39
40 Positions fGeom;
41
42 void CreatePalette()
43 {
44 /*
45 double ss[5] = {0., 0.10, 0.45, 0.75, 1.00};
46 double rr[5] = {0., 0.35, 0.85, 1.00, 1.00};
47 double gg[5] = {0., 0.10, 0.20, 0.73, 1.00};
48 double bb[5] = {0., 0.03, 0.06, 0.00, 1.00};
49 */
50 double ss[5] = {0.00, 0.25, 0.50, 0.75, 1.00};
51 double rr[5] = {0.15, 0.00, 0.00, 1.00, 0.85};
52 double gg[5] = {0.15, 0.00, 1.00, 0.00, 0.85};
53 double bb[5] = {0.15, 1.00, 0.00, 0.00, 0.85};
54
55 const Int_t nn = 1440;
56
57 Int_t idx = TColor::CreateGradientColorTable(5, ss, rr, gg, bb, nn);
58 for (int i=0; i<nn; i++)
59 fPalette.push_back(idx++);
60 }
61
62 void CreateGeometry()
63 {
64 const double gsSin60 = sqrt(3.)/2;
65
66 const int rings = 23;
67
68 // add the first pixel to the list
69
70 fGeom.push_back(make_pair(0, -0.5));
71
72 for (int ring=1; ring<=rings; ring++)
73 {
74 for (int s=0; s<6; s++)
75 {
76 for (int i=1; i<=ring; i++)
77 {
78 double xx, yy;
79 switch (s)
80 {
81 case 0: // Direction South East
82 xx = (ring+i)*0.5;
83 yy = (-ring+i)*gsSin60;
84 break;
85
86 case 1: // Direction North East
87 xx = ring-i*0.5;
88 yy = i*gsSin60;
89 break;
90
91 case 2: // Direction North
92 xx = ring*0.5-i;
93 yy = ring*gsSin60;
94 break;
95
96 case 3: // Direction North West
97 xx = -(ring+i)*0.5;
98 yy = (ring-i)*gsSin60;
99 break;
100
101 case 4: // Direction South West
102 xx = 0.5*i-ring;
103 yy = -i*gsSin60;
104 break;
105
106 case 5: // Direction South
107 xx = i-ring*0.5;
108 yy = -ring*gsSin60;
109 break;
110 }
111
112 if (xx*xx + yy*yy - xx > 395.75)
113 continue;
114
115 fGeom.push_back(make_pair(yy, xx-0.5));
116 }
117 }
118 }
119 }
120
121 valarray<double> fData;
122 vector<bool> fBold;
123 vector<bool> fEnable;
124
125 int fWhite;
126
127public:
128 Camera() : fData(1440), fBold(1440), fEnable(1440), fWhite(-1)
129 {
130 CreatePalette();
131 CreateGeometry();
132
133 for (int i=0; i<1440; i++)
134 {
135 fData[i] = i;
136 fBold[i]=false;
137 fEnable[i]=true;
138 }
139 }
140
141 void Reset() { fBold.assign(1440, false); }
142
143 void SetBold(int idx) { fBold[idx]=true; }
144 void SetWhite(int idx) { fWhite=idx; }
145 void SetEnable(int idx, bool b) { fEnable[idx]=b; }
146 void Toggle(int idx) { fEnable[idx]=!fEnable[idx]; }
147 double GetData(int idx) const { return fData[idx]; }
148
149 const char *GetName() const { return "Camera"; }
150
151 vector<Int_t> fPalette;
152
153 void Paint(const Position &p)
154 {
155 static const Double_t fgCos60 = 0.5; // TMath::Cos(60/TMath::RadToDeg());
156 static const Double_t fgSin60 = sqrt(3.)/2; // TMath::Sin(60/TMath::RadToDeg());
157
158 static const Double_t fgDy[6] = { fgCos60, 0., -fgCos60, -fgCos60, 0., fgCos60 };
159 static const Double_t fgDx[6] = { fgSin60/3, fgSin60*2/3, fgSin60/3, -fgSin60/3, -fgSin60*2/3, -fgSin60/3 };
160
161 //
162 // calculate the positions of the pixel corners
163 //
164 Double_t x[7], y[7];
165 for (Int_t i=0; i<7; i++)
166 {
167 x[i] = p.first + fgDx[i%6];
168 y[i] = p.second + fgDy[i%6];
169 }
170
171 gPad->PaintFillArea(6, x, y);
172 gPad->PaintPolyLine(7, x, y);
173
174 }
175
176 double align(double min, double val, double max) const
177 {
178 if (val<min)
179 return min;
180 if (val>max)
181 return max;
182 return val;
183 }
184
185 void Paint(Option_t *)
186 {
187 gStyle->SetPalette(fPalette.size(), fPalette.data());
188
189 const double r = double(gPad->GetWw())/gPad->GetWh();
190 const double max = 20.5; // 20.5 rings in x and y
191
192 if (r>1)
193 gPad->Range(-r*max, -max, r*max, max);
194 else
195 gPad->Range(-max, -max/r, max, max/r);
196
197 Double_t x1, x2, y1, y2;
198 gPad->GetRange(x1, x2, y1, y2);
199
200 double dmin = fData[0];
201 double dmax = fData[0];
202
203 for (unsigned int i=0; i<fData.size(); i++)
204 {
205 if (!fEnable[i])
206 continue;
207
208 if (fData[i]>dmax)
209 dmax = fData[i];
210 if (fData[i]<dmin)
211 dmin = fData[i];
212 }
213
214 const double min = dmin;
215 const double scale = dmax==dmin ? 1 : dmax-dmin;
216
217 TAttFill fill(0, 1001);
218 TAttLine line;
219
220 int cnt=0;
221 for (Positions::iterator p=fGeom.begin(); p!=fGeom.end(); p++, cnt++)
222 {
223 if (fBold[cnt])
224 continue;
225
226 const double val = align(dmin, fData[cnt], dmax);
227
228 const int col = (val-min)/scale*(fPalette.size()-1);
229
230 if (fEnable[cnt])
231 fill.SetFillColor(gStyle->GetColorPalette(col));
232 else
233 fill.SetFillColor(kWhite);
234
235 fill.Modify();
236
237 Paint(*p);
238 }
239
240 line.SetLineWidth(2);
241 line.Modify();
242
243 cnt = 0;
244 for (Positions::iterator p=fGeom.begin(); p!=fGeom.end(); p++, cnt++)
245 {
246 if (!fBold[cnt])
247 continue;
248
249 const double val = align(dmin, fData[cnt], dmax);
250
251 const int col = (val-min)/scale*(fPalette.size()-1);
252
253 if (fEnable[cnt])
254 fill.SetFillColor(gStyle->GetColorPalette(col));
255 else
256 fill.SetFillColor(kWhite);
257 fill.Modify();
258
259 Paint(*p);
260 }
261
262 TMarker m(0,0,kStar);
263 m.DrawMarker(0, 0);
264
265 if (fWhite<0)
266 return;
267
268 const Position &p = fGeom[fWhite];
269
270 line.SetLineColor(kWhite);
271 line.Modify();
272
273 const double val = align(dmin, fData[fWhite], dmax);
274
275 const int col = (val-min)/scale*(fPalette.size()-1);
276
277 if (fEnable[fWhite])
278 fill.SetFillColor(gStyle->GetColorPalette(col));
279 else
280 fill.SetFillColor(kWhite);
281 fill.Modify();
282
283 Paint(p);
284 }
285
286 int GetIdx(float px, float py) const
287 {
288 static const double sqrt3 = sqrt(3);
289
290 int idx = 0;
291 for (Positions::const_iterator p=fGeom.begin(); p!=fGeom.end(); p++, idx++)
292 {
293 const Double_t dy = py - p->second;
294 if (fabs(dy)>0.5)
295 continue;
296
297 const Double_t dx = px - p->first;
298
299 if (TMath::Abs(dy + dx*sqrt3) > 1)
300 continue;
301
302 if (TMath::Abs(dy - dx*sqrt3) > 1)
303 continue;
304
305 return idx;
306 }
307 return -1;
308 }
309
310 char *GetObjectInfo(Int_t px, Int_t py) const
311 {
312 static stringstream stream;
313 static string str;
314
315 const float x = gPad->AbsPixeltoX(px);
316 const float y = gPad->AbsPixeltoY(py);
317
318 const int idx = GetIdx(x, y);
319
320 stream.seekp(0);
321 if (idx>=0)
322 {
323 stream << "Pixel=" << idx << " Data=" << fData[idx] << '\0';
324 }
325
326 str = stream.str();
327 return const_cast<char*>(str.c_str());
328 }
329
330 Int_t DistancetoPrimitive(Int_t px, Int_t py)
331 {
332 const float x = gPad->AbsPixeltoX(px);
333 const float y = gPad->AbsPixeltoY(py);
334
335 return GetIdx(x, y)>=0 ? 0 : 99999;
336 }
337
338 void SetData(const valarray<double> &data)
339 {
340 fData = data;
341 }
342};
343
344// #########################################################################
345
346
347class FactGui : public MainWindow, public DimNetwork
348{
349private:
350 class FunctionEvent : public QEvent
351 {
352 public:
353 boost::function<void(const QEvent &)> fFunction;
354
355 FunctionEvent(const boost::function<void(const QEvent &)> &f)
356 : QEvent((QEvent::Type)QEvent::registerEventType()),
357 fFunction(f) { }
358
359 bool Exec() { fFunction(*this); return true; }
360 };
361
362 valarray<int8_t> fFtuStatus;
363
364 vector<int> fPixelMapHW; // Software -> Hardware
365 vector<int> fPatchMapHW; // Software -> Hardware
366 vector<int> fPatchHW; // Maps the software(!) pixel id to the hardware(!) patch id
367
368 bool fInChoosePatch; // FIXME. Find a better solution
369
370 DimStampedInfo fDimDNS;
371
372 DimStampedInfo fDimLoggerStats;
373 DimStampedInfo fDimLoggerFilenameNight;
374 DimStampedInfo fDimLoggerFilenameRun;
375 DimStampedInfo fDimLoggerNumSubs;
376
377 DimStampedInfo fDimFtmPassport;
378 DimStampedInfo fDimFtmTriggerCounter;
379 DimStampedInfo fDimFtmError;
380 DimStampedInfo fDimFtmFtuList;
381 DimStampedInfo fDimFtmStaticData;
382 DimStampedInfo fDimFtmDynamicData;
383 DimStampedInfo fDimFtmCounter;
384
385 DimStampedInfo fDimFadRuns;
386 DimStampedInfo fDimFadEvents;
387 DimStampedInfo fDimFadEventData;
388 DimStampedInfo fDimFadConnections;
389 DimStampedInfo fDimFadFwVersion;
390 DimStampedInfo fDimFadRunNumber;
391 DimStampedInfo fDimFadDNA;
392 DimStampedInfo fDimFadTemperature;
393 DimStampedInfo fDimFadRefClock;
394 DimStampedInfo fDimFadStatus;
395 DimStampedInfo fDimFadStatistics;
396
397 map<string, DimInfo*> fServices;
398
399 // ========================== LED Colors ================================
400
401 enum LedColor_t
402 {
403 kLedRed,
404 kLedGreen,
405 kLedYellow,
406 kLedOrange,
407 kLedGray
408 };
409
410 void SetLedColor(QPushButton *button, LedColor_t col, const Time &t)
411 {
412 switch (col)
413 {
414 case kLedRed:
415 button->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
416 break;
417
418 case kLedGreen:
419 button->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
420 break;
421
422 case kLedYellow:
423 button->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
424 break;
425
426 case kLedOrange:
427 button->setIcon(QIcon(":/Resources/icons/orange circle 1.png"));
428 break;
429
430 case kLedGray:
431 button->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
432 break;
433 }
434
435 //button->setToolTip("Last change: "+QDateTime::currentDateTimeUtc().toString()+" UTC");
436 button->setToolTip(("Last change: "+t.GetAsStr()+" (UTC)").c_str());
437 }
438
439 // ===================== Services and Commands ==========================
440
441 QStandardItem *AddServiceItem(const std::string &server, const std::string &service, bool iscmd)
442 {
443 QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
444 QListView *services = iscmd ? fDimCmdCommands : fDimSvcServices;
445 QListView *description = iscmd ? fDimCmdDescription : fDimSvcDescription;
446
447 QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
448 if (!m)
449 {
450 m = new QStandardItemModel(this);
451 servers->setModel(m);
452 services->setModel(m);
453 description->setModel(m);
454 }
455
456 QList<QStandardItem*> l = m->findItems(server.c_str());
457
458 if (l.size()>1)
459 {
460 cout << "hae" << endl;
461 return 0;
462 }
463
464 QStandardItem *col = l.size()==0 ? NULL : l[0];
465
466 if (!col)
467 {
468 col = new QStandardItem(server.c_str());
469 m->appendRow(col);
470
471 if (!services->rootIndex().isValid())
472 {
473 services->setRootIndex(col->index());
474 servers->setCurrentIndex(col->index());
475 }
476 }
477
478 QStandardItem *item = 0;
479 for (int i=0; i<col->rowCount(); i++)
480 {
481 QStandardItem *coli = col->child(i);
482 if (coli->text().toStdString()==service)
483 return coli;
484 }
485
486 item = new QStandardItem(service.c_str());
487 col->appendRow(item);
488 col->sortChildren(0);
489
490 if (!description->rootIndex().isValid())
491 {
492 description->setRootIndex(item->index());
493 services->setCurrentIndex(item->index());
494 }
495
496 if (!iscmd)
497 item->setCheckable(true);
498
499 return item;
500 }
501
502 void AddDescription(QStandardItem *item, const vector<Description> &vec)
503 {
504 if (!item)
505 return;
506 if (vec.size()==0)
507 return;
508
509 item->setToolTip(vec[0].comment.c_str());
510
511 const string str = Description::GetHtmlDescription(vec);
512
513 QStandardItem *desc = new QStandardItem(str.c_str());
514 desc->setSelectable(false);
515 item->setChild(0, 0, desc);
516 }
517
518 void AddServer(const std::string &s)
519 {
520 DimNetwork::AddServer(s);
521
522 QApplication::postEvent(this,
523 new FunctionEvent(boost::bind(&FactGui::handleAddServer, this, s)));
524 }
525
526 void RemoveServer(const std::string &s)
527 {
528 UnsubscribeServer(s);
529
530 DimNetwork::RemoveServer(s);
531
532 QApplication::postEvent(this,
533 new FunctionEvent(boost::bind(&FactGui::handleRemoveServer, this, s)));
534 }
535
536 void RemoveAllServers()
537 {
538 UnsubscribeAllServers();
539
540 vector<string> v = GetServerList();
541 for (vector<string>::iterator i=v.begin(); i<v.end(); i++)
542 QApplication::postEvent(this,
543 new FunctionEvent(boost::bind(&FactGui::handleStateOffline, this, *i)));
544
545 DimNetwork::RemoveAllServers();
546
547 QApplication::postEvent(this,
548 new FunctionEvent(boost::bind(&FactGui::handleRemoveAllServers, this)));
549 }
550
551 void AddService(const std::string &server, const std::string &service, const std::string &fmt, bool iscmd)
552 {
553 QApplication::postEvent(this,
554 new FunctionEvent(boost::bind(&FactGui::handleAddService, this, server, service, fmt, iscmd)));
555 }
556
557 void RemoveService(const std::string &server, const std::string &service, bool iscmd)
558 {
559 if (fServices.find(server+'/'+service)!=fServices.end())
560 UnsubscribeService(server+'/'+service);
561
562 QApplication::postEvent(this,
563 new FunctionEvent(boost::bind(&FactGui::handleRemoveService, this, server, service, iscmd)));
564 }
565
566 void RemoveAllServices(const std::string &server)
567 {
568 UnsubscribeServer(server);
569
570 QApplication::postEvent(this,
571 new FunctionEvent(boost::bind(&FactGui::handleRemoveAllServices, this, server)));
572 }
573
574 void AddDescription(const std::string &server, const std::string &service, const vector<Description> &vec)
575 {
576 QApplication::postEvent(this,
577 new FunctionEvent(boost::bind(&FactGui::handleAddDescription, this, server, service, vec)));
578 }
579
580 // ======================================================================
581
582 void handleAddServer(const std::string &server)
583 {
584 const State s = GetState(server, GetCurrentState(server));
585 handleStateChanged(Time(), server, s);
586 }
587
588 void handleRemoveServer(const string &server)
589 {
590 handleStateOffline(server);
591 handleRemoveAllServices(server);
592 }
593
594 void handleRemoveAllServers()
595 {
596 QStandardItemModel *m = 0;
597 if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
598 m->removeRows(0, m->rowCount());
599
600 if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
601 m->removeRows(0, m->rowCount());
602 }
603
604 void handleAddService(const std::string &server, const std::string &service, const std::string &/*fmt*/, bool iscmd)
605 {
606 QStandardItem *item = AddServiceItem(server, service, iscmd);
607 const vector<Description> v = GetDescription(server, service);
608 AddDescription(item, v);
609 }
610
611 void handleRemoveService(const std::string &server, const std::string &service, bool iscmd)
612 {
613 QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
614
615 QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
616 if (!m)
617 return;
618
619 QList<QStandardItem*> l = m->findItems(server.c_str());
620 if (l.size()!=1)
621 return;
622
623 for (int i=0; i<l[0]->rowCount(); i++)
624 {
625 QStandardItem *row = l[0]->child(i);
626 if (row->text().toStdString()==service)
627 {
628 l[0]->removeRow(row->index().row());
629 return;
630 }
631 }
632 }
633
634 void handleRemoveAllServices(const std::string &server)
635 {
636 QStandardItemModel *m = 0;
637 if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
638 {
639 QList<QStandardItem*> l = m->findItems(server.c_str());
640 if (l.size()==1)
641 m->removeRow(l[0]->index().row());
642 }
643
644 if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
645 {
646 QList<QStandardItem*> l = m->findItems(server.c_str());
647 if (l.size()==1)
648 m->removeRow(l[0]->index().row());
649 }
650 }
651
652 void handleAddDescription(const std::string &server, const std::string &service, const vector<Description> &vec)
653 {
654 const bool iscmd = IsCommand(server, service)==true;
655
656 QStandardItem *item = AddServiceItem(server, service, iscmd);
657 AddDescription(item, vec);
658 }
659
660 // ======================================================================
661
662 void SubscribeService(const string &service)
663 {
664 if (fServices.find(service)!=fServices.end())
665 {
666 cout << "ERROR - We are already subscribed to " << service << endl;
667 return;
668 }
669
670 fServices[service] = new DimStampedInfo(service.c_str(), (void*)NULL, 0, this);
671 }
672
673 void UnsubscribeService(const string &service)
674 {
675 const map<string,DimInfo*>::iterator i=fServices.find(service);
676
677 if (i==fServices.end())
678 {
679 cout << "ERROR - We are not subscribed to " << service << endl;
680 return;
681 }
682
683 delete i->second;
684
685 fServices.erase(i);
686 }
687
688 void UnsubscribeServer(const string &server)
689 {
690 for (map<string,DimInfo*>::iterator i=fServices.begin();
691 i!=fServices.end(); i++)
692 if (i->first.substr(0, server.length()+1)==server+'/')
693 {
694 delete i->second;
695 fServices.erase(i);
696 }
697 }
698
699 void UnsubscribeAllServers()
700 {
701 for (map<string,DimInfo*>::iterator i=fServices.begin();
702 i!=fServices.end(); i++)
703 delete i->second;
704
705 fServices.clear();
706 }
707
708 // ======================================================================
709
710 struct DimData
711 {
712 const int qos;
713 const string name;
714 const string format;
715 const vector<char> data;
716 const Time time;
717
718 Time extract(DimInfo *inf) const
719 {
720 // Must be called in exactly this order!
721 const int tsec = inf->getTimestamp();
722 const int tms = inf->getTimestampMillisecs();
723
724 return Time(tsec, tms*1000);
725 }
726
727// DimInfo *info; // this is ONLY for a fast check of the type of the DimData!!
728
729 DimData(DimInfo *inf) :
730 qos(inf->getQuality()),
731 name(inf->getName()),
732 format(inf->getFormat()),
733 data(inf->getString(), inf->getString()+inf->getSize()),
734 time(extract(inf))/*,
735 info(inf)*/
736 {
737 }
738
739 template<typename T>
740 T get(uint32_t offset=0) const { return *reinterpret_cast<const T*>(data.data()+offset); }
741
742 template<typename T>
743 const T *ptr(uint32_t offset=0) const { return reinterpret_cast<const T*>(data.data()+offset); }
744
745 template<typename T>
746 const T &ref(uint32_t offset=0) const { return *reinterpret_cast<const T*>(data.data()+offset); }
747
748// vector<char> vec(int b) const { return vector<char>(data.begin()+b, data.end()); }
749// string str(unsigned int b) const { return b>=data.size()?string():string(data.data()+b, data.size()-b); }
750 const char *c_str() const { return (char*)data.data(); }
751/*
752 vector<boost::any> any() const
753 {
754 const Converter conv(format);
755 conv.Print();
756 return conv.GetAny(data.data(), data.size());
757 }*/
758 size_t size() const { return data.size(); }
759 };
760
761 // ======================= DNS ==========================================
762
763 void handleDimDNS(const DimData &d)
764 {
765 const int version = d.size()!=4 ? 0 : d.get<uint32_t>();
766
767 ostringstream str;
768 str << "V" << version/100 << 'r' << version%100;
769
770 SetLedColor(fStatusDNSLed, version==0 ? kLedRed : kLedGreen, Time());
771
772 fStatusDNSLabel->setText(version==0?"Offline":str.str().c_str());
773 fStatusDNSLabel->setToolTip(version==0?"No connection to DIM DNS.":"Connection to DIM DNS established.");
774 }
775
776
777 // ======================= Logger =======================================
778
779 void handleLoggerStats(const DimData &d)
780 {
781 const bool connected = d.size()!=0;
782
783 fLoggerET->setEnabled(connected);
784 fLoggerRate->setEnabled(connected);
785 fLoggerWritten->setEnabled(connected);
786 fLoggerFreeSpace->setEnabled(connected);
787 fLoggerSpaceLeft->setEnabled(connected);
788
789 if (!connected)
790 return;
791
792 const uint64_t *vals = d.ptr<uint64_t>();
793
794 const size_t written = vals[0];
795 const size_t space = vals[1];
796 const size_t rate = vals[2];
797
798 fLoggerFreeSpace->setSuffix(" MB");
799 fLoggerFreeSpace->setDecimals(0);
800 fLoggerFreeSpace->setValue(space*1e-6);
801
802 if (space> 1000000) // > 1GB
803 {
804 fLoggerFreeSpace->setSuffix(" GB");
805 fLoggerFreeSpace->setDecimals(2);
806 fLoggerFreeSpace->setValue(space*1e-9);
807 }
808 if (space>= 3000000) // >= 3GB
809 {
810 fLoggerFreeSpace->setSuffix(" GB");
811 fLoggerFreeSpace->setDecimals(1);
812 fLoggerFreeSpace->setValue(space*1e-9);
813 }
814 if (space>=100000000) // >= 100GB
815 {
816 fLoggerFreeSpace->setSuffix(" GB");
817 fLoggerFreeSpace->setDecimals(0);
818 fLoggerFreeSpace->setValue(space*1e-9);
819 }
820
821 fLoggerET->setTime(QTime().addSecs(rate>0?space/rate:0));
822 fLoggerRate->setValue(rate*1e-3); // kB/s
823 fLoggerWritten->setValue(written*1e-6);
824
825 fLoggerRate->setSuffix(" kB/s");
826 fLoggerRate->setDecimals(2);
827 fLoggerRate->setValue(rate*1e-3);
828 if (rate> 2000) // > 2kB/s
829 {
830 fLoggerRate->setSuffix(" kB/s");
831 fLoggerRate->setDecimals(1);
832 fLoggerRate->setValue(rate*1e-3);
833 }
834 if (rate>=100000) // >100kB/s
835 {
836 fLoggerRate->setSuffix(" kB/s");
837 fLoggerRate->setDecimals(0);
838 fLoggerRate->setValue(rate*1e-3);
839 }
840 if (rate>=1000000) // >100kB/s
841 {
842 fLoggerRate->setSuffix(" MB/s");
843 fLoggerRate->setDecimals(2);
844 fLoggerRate->setValue(rate*1e-6);
845 }
846 if (rate>=10000000) // >1MB/s
847 {
848 fLoggerRate->setSuffix(" MB/s");
849 fLoggerRate->setDecimals(1);
850 fLoggerRate->setValue(rate*1e-6);
851 }
852 if (rate>=100000000) // >10MB/s
853 {
854 fLoggerRate->setSuffix(" MB/s");
855 fLoggerRate->setDecimals(0);
856 fLoggerRate->setValue(rate*1e-6);
857 }
858
859 if (space/1000000>static_cast<size_t>(fLoggerSpaceLeft->maximum()))
860 fLoggerSpaceLeft->setValue(fLoggerSpaceLeft->maximum()); // GB
861 else
862 fLoggerSpaceLeft->setValue(space/1000000); // MB
863 }
864
865 void handleLoggerFilenameNight(const DimData &d)
866 {
867 const bool connected = d.size()!=0;
868
869 fLoggerFilenameNight->setEnabled(connected);
870 if (!connected)
871 return;
872
873 fLoggerFilenameNight->setText(d.c_str()+4);
874
875 const uint32_t files = d.get<uint32_t>();
876
877 SetLedColor(fLoggerLedLog, files&1 ? kLedGreen : kLedGray, d.time);
878 SetLedColor(fLoggerLedRep, files&2 ? kLedGreen : kLedGray, d.time);
879 SetLedColor(fLoggerLedFits, files&4 ? kLedGreen : kLedGray, d.time);
880 }
881
882 void handleLoggerFilenameRun(const DimData &d)
883 {
884 const bool connected = d.size()!=0;
885
886 fLoggerFilenameRun->setEnabled(connected);
887 if (!connected)
888 return;
889
890 fLoggerFilenameRun->setText(d.c_str()+4);
891
892 const uint32_t files = d.get<uint32_t>();
893
894 SetLedColor(fLoggerLedLog, files&1 ? kLedGreen : kLedGray, d.time);
895 SetLedColor(fLoggerLedRep, files&2 ? kLedGreen : kLedGray, d.time);
896 SetLedColor(fLoggerLedFits, files&4 ? kLedGreen : kLedGray, d.time);
897 }
898
899 void handleLoggerNumSubs(const DimData &d)
900 {
901 const bool connected = d.size()!=0;
902
903 fLoggerSubscriptions->setEnabled(connected);
904 fLoggerOpenFiles->setEnabled(connected);
905 if (!connected)
906 return;
907
908 const uint32_t *vals = d.ptr<uint32_t>();
909
910 fLoggerSubscriptions->setValue(vals[0]);
911 fLoggerOpenFiles->setValue(vals[1]);
912 }
913
914
915 // ===================== All ============================================
916
917 bool CheckSize(const DimData &d, size_t sz) const
918 {
919 if (d.size()==0)
920 return false;
921
922 if (d.size()!=sz)
923 {
924 cout << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected=" << sz << endl;
925 return false;
926 }
927
928 return true;
929 }
930
931 // ===================== FAD ============================================
932
933 void handleFadRuns(const DimData &d)
934 {
935 if (!CheckSize(d, 20))
936 return;
937
938 const uint32_t *ptr = d.ptr<uint32_t>();
939
940 fEvtBldOpenFiles->setValue(ptr[0]);
941 fEvtBldOpenStreams->setValue(ptr[0]);
942 fEvtBldRunNumberMin->setValue(ptr[1]);
943 fEvtBldRunNumberMax->setValue(ptr[2]);
944 fEvtBldLastOpened->setValue(ptr[3]);
945 fEvtBldLastClosed->setValue(ptr[4]);
946 }
947
948 void handleFadEvents(const DimData &d)
949 {
950 if (!CheckSize(d, 16))
951 return;
952
953 const uint32_t *ptr = d.ptr<uint32_t>();
954
955 fEvtsSuccessCurRun->setValue(ptr[0]);
956 fEvtsSuccessTotal->setValue(ptr[1]);
957 fEvtBldEventId->setValue(ptr[2]);
958 fEvtBldTriggerId->setValue(ptr[3]);
959 }
960
961 void handleFadTemperature(const DimData &d)
962 {
963 if (d.size()==0)
964 {
965 fFadTempMin->setEnabled(false);
966 fFadTempMax->setEnabled(false);
967 return;
968 }
969
970 if (!CheckSize(d, 82*sizeof(float)))
971 return;
972
973 const float *ptr = d.ptr<float>();
974
975 fFadTempMin->setEnabled(true);
976 fFadTempMax->setEnabled(true);
977
978 fFadTempMin->setValue(ptr[0]);
979 fFadTempMax->setValue(ptr[40]);
980
981 handleFadToolTip(d.time, fFadTempMin, ptr+1);
982 handleFadToolTip(d.time, fFadTempMax, ptr+41);
983 }
984
985 void handleFadRefClock(const DimData &d)
986 {
987 if (d.size()==0)
988 {
989 fFadRefClockMin->setEnabled(false);
990 fFadRefClockMax->setEnabled(false);
991 SetLedColor(fFadLedRefClock, kLedGray, d.time);
992 return;
993 }
994
995 if (!CheckSize(d, 42*sizeof(uint32_t)))
996 return;
997
998 const uint32_t *ptr = d.ptr<uint32_t>();
999
1000 fFadRefClockMin->setEnabled(true);
1001 fFadRefClockMax->setEnabled(true);
1002
1003 fFadRefClockMin->setValue(ptr[0]*2.048);
1004 fFadRefClockMax->setValue(ptr[1]*2.048);
1005
1006 const int64_t diff = int64_t(ptr[1]) - int64_t(ptr[0]);
1007
1008 SetLedColor(fFadLedRefClock, abs(diff)>3?kLedRed:kLedGreen, d.time);
1009
1010 handleFadToolTip(d.time, fFadLedRefClock, ptr+2);
1011 }
1012
1013 struct DimEventData
1014 {
1015 uint16_t Roi ; // #slices per pixel (same for all pixels and tmarks)
1016 uint32_t EventNum ; // EventNumber as from FTM
1017 uint16_t TriggerType ; // Trigger Type from FTM
1018
1019 uint32_t PCTime ; // when did event start to arrive at PC
1020 uint32_t BoardTime; //
1021
1022 int16_t StartPix; // First Channel per Pixel (Pixels sorted according Software ID) ; -1 if not filled
1023 int16_t StartTM; // First Channel for TimeMark (sorted Hardware ID) ; -1 if not filled
1024
1025 int16_t Adc_Data[]; // final length defined by malloc ....
1026
1027 } __attribute__((__packed__));;
1028
1029 DimEventData *fEventData;
1030
1031 void DisplayEventData()
1032 {
1033#ifdef HAVE_ROOT
1034 TCanvas *c = fAdcDataCanv->GetCanvas();
1035
1036 TH1 *h = dynamic_cast<TH1*>(c->FindObject("EventData"));
1037 if (h && h->GetNbinsX()!=fEventData->Roi)
1038 {
1039 delete h;
1040 h = 0;
1041 }
1042
1043 if (!h)
1044 {
1045 c->cd();
1046
1047 TH1D hist("EventData", "", fEventData->Roi, -0.5, fEventData->Roi-0.5);
1048 hist.SetStats(kFALSE);
1049 //hist->SetBit(TH1::kNoTitle);
1050 hist.SetMarkerStyle(kFullDotMedium);
1051 hist.SetMarkerColor(kBlue);
1052 hist.SetYTitle("Voltage [mV]");
1053 hist.GetXaxis()->CenterTitle();
1054 hist.GetYaxis()->CenterTitle();
1055 hist.SetMinimum(-1026);
1056 hist.SetMaximum(1025);
1057 h = hist.DrawCopy("PL");
1058 h->SetDirectory(0);
1059 }
1060
1061 ostringstream str;
1062 str << "Event ID = " << fEventData->EventNum << " Trigger type = " << fEventData->TriggerType << " PC Time=" << fEventData->PCTime << " Board time = " << fEventData->BoardTime;
1063 h->SetTitle(str.str().c_str());
1064 str.str("");
1065 str << "ADC Pipeline (start=" << fEventData->StartPix << ")";
1066 h->SetXTitle(str.str().c_str());
1067
1068 //str.str("");
1069 //str << "Crate=" << crate << " Board=" << board << " Channel=" << channel << " [" << d.time() << "]" << endl;
1070 //hist->SetTitle(str.str().c_str());
1071
1072 const uint32_t p = fAdcChannel->value()+fAdcBoard->value()*36+fAdcCrate->value()*360;
1073
1074 for (int i=0; i<fEventData->Roi; i++)
1075 h->SetBinContent(i+1, fEventData->Adc_Data[p*fEventData->Roi+i]*0.5);
1076
1077 if (fAdcAutoScale->isChecked())
1078 {
1079 h->SetMinimum(-1111);
1080 h->SetMaximum(-1111);
1081 }
1082
1083 if (!fAdcAutoScale->isChecked())
1084 {
1085 if (h->GetMinimum()==-1111)
1086 h->SetMinimum(-1026);
1087 if (h->GetMaximum()==-1111)
1088 h->SetMaximum(1025);
1089 }
1090
1091 c->Modified();
1092 c->Update();
1093#endif
1094 }
1095
1096 void handleFadEventData(const DimData &d)
1097 {
1098 if (d.size()==0)
1099 return;
1100
1101 if (fAdcStop->isChecked())
1102 return;
1103
1104 const DimEventData &dat = d.ref<DimEventData>();
1105
1106 if (d.size()<sizeof(DimEventData))
1107 {
1108 cout << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected=" << sizeof(DimEventData) << endl;
1109 return;
1110 }
1111
1112 if (d.size()!=sizeof(DimEventData)+dat.Roi*2*1440)
1113 {
1114 cout << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected=" << dat.Roi*2+sizeof(DimEventData) << endl;
1115 return;
1116 }
1117
1118 delete fEventData;
1119 fEventData = reinterpret_cast<DimEventData*>(new char[d.size()]);
1120 memcpy(fEventData, d.ptr<void>(), d.size());
1121
1122 DisplayEventData();
1123 }
1124
1125// vector<uint8_t> fFadConnections;
1126
1127 void handleFadConnections(const DimData &d)
1128 {
1129 if (!CheckSize(d, 41))
1130 return;
1131
1132 const uint8_t *ptr = d.ptr<uint8_t>();
1133
1134 for (int i=0; i<40; i++)
1135 {
1136 const uint8_t stat1 = ptr[i]&3;
1137 const uint8_t stat2 = ptr[i]>>3;
1138
1139 if (stat1==0 && stat2==0)
1140 {
1141 SetLedColor(fFadLED[i], kLedGray, d.time);
1142 continue;
1143 }
1144 if (stat1==2 && stat2==8)
1145 {
1146 SetLedColor(fFadLED[i], kLedGreen, d.time);
1147 continue;
1148 }
1149
1150 if (stat1==1 && stat2==1)
1151 SetLedColor(fFadLED[i], kLedRed, d.time);
1152 else
1153 SetLedColor(fFadLED[i], kLedOrange, d.time);
1154 }
1155
1156
1157 const bool runs = ptr[40]!=0;
1158
1159 fStatusEventBuilderLabel->setText(runs?"Running":"Not running");
1160 fStatusEventBuilderLabel->setToolTip(runs?"Event builder thread running.":"Event builder thread stopped.");
1161 fEvtBldWidget->setEnabled(runs);
1162
1163 SetLedColor(fStatusEventBuilderLed, runs?kLedGreen:kLedRed, d.time);
1164
1165// fFadConnections.assign(ptr, ptr+40);
1166 }
1167
1168 template<typename T>
1169 void handleFadToolTip(const Time &time, QWidget *w, T *ptr)
1170 {
1171 ostringstream tip;
1172 tip << "<table border='1'><tr><th colspan='11'>" << time.GetAsStr() << " (UTC)</th></tr><tr><th></th>";
1173 for (int b=0; b<10; b++)
1174 tip << "<th>" << b << "</th>";
1175 tip << "</tr>";
1176
1177 for (int c=0; c<4; c++)
1178 {
1179 tip << "<tr><th>" << c << "</th>";
1180 for (int b=0; b<10; b++)
1181 tip << "<td>" << ptr[c*10+b] << "</td>";
1182 tip << "</tr>";
1183 }
1184 tip << "</table>";
1185
1186 w->setToolTip(tip.str().c_str());
1187 }
1188
1189 template<typename T, class S>
1190 void handleFadMinMax(const DimData &d, QPushButton *led, S *wmin, S *wmax=0)
1191 {
1192 if (!CheckSize(d, 42*sizeof(T)))
1193 return;
1194
1195 const T *ptr = d.ptr<T>();
1196 const T min = ptr[40];
1197 const T max = ptr[41];
1198
1199 if (max<min)
1200 SetLedColor(led, kLedGray, d.time);
1201 else
1202 SetLedColor(led, min==max?kLedGreen: kLedOrange, d.time);
1203
1204 if (!wmax && max!=min)
1205 wmin->setValue(0);
1206 else
1207 wmin->setValue(min);
1208
1209 if (wmax)
1210 wmax->setValue(max);
1211
1212 handleFadToolTip(d.time, led, ptr);
1213 }
1214
1215 void handleFadFwVersion(const DimData &d)
1216 {
1217 handleFadMinMax<float, QDoubleSpinBox>(d, fFadLedFwVersion, fFadFwVersion);
1218 }
1219
1220 void handleFadRunNumber(const DimData &d)
1221 {
1222 handleFadMinMax<uint32_t, QSpinBox>(d, fFadLedRunNumber, fFadRunNumber);
1223 }
1224
1225 void handleFadDNA(const DimData &d)
1226 {
1227 if (!CheckSize(d, 40*sizeof(uint64_t)))
1228 return;
1229
1230 const uint64_t *ptr = d.ptr<uint64_t>();
1231
1232 ostringstream tip;
1233 tip << "<table width='100%'>";
1234 tip << "<tr><th>Crate</th><td></td><th>Board</th><td></td><th>DNA</th></tr>";
1235
1236 for (int i=0; i<40; i++)
1237 {
1238 tip << dec;
1239 tip << "<tr>";
1240 tip << "<td align='center'>" << i/10 << "</td><td>:</td>";
1241 tip << "<td align='center'>" << i%10 << "</td><td>:</td>";
1242 tip << hex;
1243 tip << "<td>0x" << setfill('0') << setw(16) << ptr[i] << "</td>";
1244 tip << "</tr>";
1245 }
1246 tip << "</table>";
1247
1248 fFadDNA->setText(tip.str().c_str());
1249 }
1250
1251 void SetFadLed(QPushButton *led, const DimData &d, uint16_t bitmask, bool invert=false)
1252 {
1253 if (d.size()==0)
1254 {
1255 SetLedColor(led, kLedGray, d.time);
1256 return;
1257 }
1258
1259 const bool quality = d.ptr<uint16_t>()[0]&bitmask;
1260 const bool value = d.ptr<uint16_t>()[1]&bitmask;
1261 const uint16_t *ptr = d.ptr<uint16_t>()+2;
1262
1263 SetLedColor(led, quality?kLedOrange:(value^invert?kLedGreen:kLedRed), d.time);
1264
1265 ostringstream tip;
1266 tip << "<table border='1'><tr><th colspan='11'>" << d.time.GetAsStr() << " (UTC)</th></tr><tr><th></th>";
1267 for (int b=0; b<10; b++)
1268 tip << "<th>" << b << "</th>";
1269 tip << "</tr>";
1270
1271 /*
1272 tip << "<tr>" << hex;
1273 tip << "<th>" << d.ptr<uint16_t>()[0] << " " << (d.ptr<uint16_t>()[0]&bitmask) << "</th>";
1274 tip << "<th>" << d.ptr<uint16_t>()[1] << " " << (d.ptr<uint16_t>()[1]&bitmask) << "</th>";
1275 tip << "</tr>";
1276 */
1277
1278 for (int c=0; c<4; c++)
1279 {
1280 tip << "<tr><th>" << dec << c << "</th>" << hex;
1281 for (int b=0; b<10; b++)
1282 {
1283 tip << "<td>"
1284 << (ptr[c*10+b]&bitmask)
1285 << "</td>";
1286 }
1287 tip << "</tr>";
1288 }
1289 tip << "</table>";
1290
1291 led->setToolTip(tip.str().c_str());
1292 }
1293
1294 void handleFadStatus(const DimData &d)
1295 {
1296 if (d.size()!=0 && !CheckSize(d, 42*sizeof(uint16_t)))
1297 return;
1298
1299 SetFadLed(fFadLedDrsEnabled, d, FAD::EventHeader::kDenable);
1300 SetFadLed(fFadLedDrsWrite, d, FAD::EventHeader::kDwrite);
1301 SetFadLed(fFadLedDcmLocked, d, FAD::EventHeader::kDcmLocked);
1302 SetFadLed(fFadLedDcmReady, d, FAD::EventHeader::kDcmReady);
1303 SetFadLed(fFadLedSpiSclk, d, FAD::EventHeader::kSpiSclk);
1304 SetFadLed(fFadLedRefClockTooLow, d, FAD::EventHeader::kRefClkTooLow, true);
1305 SetFadLed(fFadLedBusy, d, FAD::EventHeader::kBusy);
1306 SetFadLed(fFadLedTriggerLine, d, FAD::EventHeader::kTriggerLine);
1307 SetFadLed(fFadLedContTrigger, d, FAD::EventHeader::kContTrigger);
1308 SetFadLed(fFadLedSocket, d, FAD::EventHeader::kSock17);
1309 SetFadLed(fFadLedPllLock, d, 0xf000);
1310 }
1311
1312 void handleFadStatistics(const DimData &d)
1313 {
1314 if (!CheckSize(d, 8*sizeof(int64_t)))
1315 return;
1316
1317 const int64_t *stat = d.ptr<int64_t>();
1318
1319 fFadBufferMax->setValue(stat[0]/1000000);
1320 fFadBuffer->setMaximum(stat[0]);
1321 fFadBuffer->setValue(stat[5]);
1322
1323 fFadEvtWait->setValue(stat[1]);
1324 fFadEvtSkip->setValue(stat[2]);
1325 fFadEvtDel->setValue(stat[3]);
1326 fFadEvtTot->setValue(stat[4]);
1327 fFadEthernetRateTot->setValue(stat[6]/1024.);
1328 fFadEthernetRateAvg->setValue(stat[6]/1024./stat[7]);
1329 fFadEvtConn->setValue(stat[7]);
1330 }
1331
1332
1333 // ===================== FTM ============================================
1334
1335 double fTimeStamp1;
1336
1337 void handleFtmTriggerCounter(const DimData &d)
1338 {
1339 if (!CheckSize(d, sizeof(FTM::DimTriggerCounter)))
1340 return;
1341
1342 const FTM::DimTriggerCounter &sdata = d.ref<FTM::DimTriggerCounter>();
1343
1344 fFtmTime->setText(QString::number(sdata.fTimeStamp/1000000., 'f', 6)+ " s");
1345 fTriggerCounter->setText(QString::number(sdata.fTriggerCounter));
1346
1347 if (sdata.fTimeStamp>0)
1348 fTriggerCounterRate->setValue(1000000.*sdata.fTriggerCounter/sdata.fTimeStamp);
1349 else
1350 fTriggerCounterRate->setValue(0);
1351
1352
1353 // ----------------------------------------------
1354#ifdef HAVE_ROOT
1355
1356 if (fTriggerCounter0<0)
1357 {
1358 fTriggerCounter0 = sdata.fTriggerCounter;
1359 fTimeStamp1 = sdata.fTimeStamp;
1360 return;
1361 }
1362
1363 TCanvas *c = fFtmRateCanv->GetCanvas();
1364
1365 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1366
1367 const double rate = sdata.fTriggerCounter-fTriggerCounter0;
1368 const double tdiff = sdata.fTimeStamp -fTimeStamp1;
1369
1370 fTriggerCounter0 = sdata.fTriggerCounter;
1371 fTimeStamp1 = sdata.fTimeStamp;
1372
1373 if (rate<0 && tdiff<=0)
1374 {
1375 fGraphFtmRate.Set(0);
1376
1377 const double tm = Time().RootTime();
1378
1379 h->SetBins(1, tm, tm+60);
1380 h->GetXaxis()->SetTimeFormat("%M'%S\"");
1381 h->GetXaxis()->SetTitle("Time");
1382
1383 c->Modified();
1384 c->Update();
1385 return;
1386 }
1387
1388 if (rate<0)
1389 return;
1390
1391// const double avgrate = sdata.fTimeStamp>0 ? double(sdata.fTriggerCounter)/sdata.fTimeStamp*1000000 : 1;
1392
1393 const double t1 = h->GetXaxis()->GetXmax();
1394 const double t0 = h->GetXaxis()->GetXmin();
1395
1396 h->SetBins(h->GetNbinsX()+1, t0, t0+sdata.fTimeStamp/1000000.+1);
1397 fGraphFtmRate.SetPoint(fGraphFtmRate.GetN(),
1398 t0+sdata.fTimeStamp/1000000., 1000000*rate/tdiff);
1399
1400 if (t1-t0>60)
1401 {
1402 h->GetXaxis()->SetTimeFormat("%Hh%M'");
1403 h->GetXaxis()->SetTitle("Time");
1404 }
1405
1406 h->SetMinimum(0);
1407// h->SetMaximum(2*avgrate);
1408
1409 c->Modified();
1410 c->Update();
1411#endif
1412 // ----------------------------------------------
1413 }
1414
1415 void handleFtmCounter(const DimData &d)
1416 {
1417 if (!CheckSize(d, sizeof(uint32_t)*6))
1418 return;
1419
1420 const uint32_t *sdata = d.ptr<uint32_t>();
1421
1422 fFtmCounterH->setValue(sdata[0]);
1423 fFtmCounterS->setValue(sdata[1]);
1424 fFtmCounterD->setValue(sdata[2]);
1425 fFtmCounterF->setValue(sdata[3]);
1426 fFtmCounterE->setValue(sdata[4]);
1427 fFtmCounterR->setValue(sdata[5]);
1428 }
1429
1430 int64_t fTriggerCounter0;
1431 int64_t fTimeStamp0;
1432
1433 void handleFtmDynamicData(const DimData &d)
1434 {
1435 if (!CheckSize(d, sizeof(FTM::DimDynamicData)))
1436 return;
1437
1438 const FTM::DimDynamicData &sdata = d.ref<FTM::DimDynamicData>();
1439
1440 fOnTime->setText(QString::number(sdata.fOnTimeCounter/1000000., 'f', 6)+" s");
1441
1442 if (sdata.fTimeStamp>0)
1443 fOnTimeRel->setValue(100.*sdata.fOnTimeCounter/sdata.fTimeStamp);
1444 else
1445 fOnTimeRel->setValue(0);
1446
1447 fFtmTemp0->setValue(sdata.fTempSensor[0]*0.1);
1448 fFtmTemp1->setValue(sdata.fTempSensor[1]*0.1);
1449 fFtmTemp2->setValue(sdata.fTempSensor[2]*0.1);
1450 fFtmTemp3->setValue(sdata.fTempSensor[3]*0.1);
1451
1452
1453#ifdef HAVE_ROOT
1454
1455 // ----------------------------------------------
1456
1457 if (fTimeStamp0<0)
1458 {
1459 fTimeStamp0 = sdata.fTimeStamp;
1460 return;
1461 }
1462
1463 TCanvas *c = fFtmRateCanv->GetCanvas();
1464
1465 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1466
1467 const double tdiff = sdata.fTimeStamp-fTimeStamp0;
1468 fTimeStamp0 = sdata.fTimeStamp;
1469
1470 if (tdiff<0)
1471 {
1472 for (int i=0; i<160; i++)
1473 fGraphPatchRate[i].Set(0);
1474 for (int i=0; i<40; i++)
1475 fGraphBoardRate[i].Set(0);
1476
1477 return;
1478 }
1479
1480 //const double t1 = h->GetXaxis()->GetXmax();
1481 const double t0 = h->GetXaxis()->GetXmin();
1482
1483 for (int i=0; i<160; i++)
1484 fGraphPatchRate[i].SetPoint(fGraphPatchRate[i].GetN(),
1485 t0+sdata.fTimeStamp/1000000., float(sdata.fRatePatch[i])*2/fFtmStaticData.fPrescaling[i]);
1486 for (int i=0; i<40; i++)
1487 fGraphBoardRate[i].SetPoint(fGraphBoardRate[i].GetN(),
1488 t0+sdata.fTimeStamp/1000000., float(sdata.fRateBoard[i])*2/fFtmStaticData.fPrescaling[i]);
1489
1490 c->Modified();
1491 c->Update();
1492
1493 //fGraphFtmRate.ComputeRange(x[0], x[1], x[2], x[3]);
1494
1495 // ----------------------------------------------
1496
1497 if (fThresholdIdx->value()>=0)
1498 {
1499 const int isw = fThresholdIdx->value();
1500 const int ihw = fPatchMapHW[isw];
1501 fPatchRate->setValue(sdata.fRatePatch[ihw]);
1502 }
1503
1504 valarray<double> dat(0., 1440);
1505
1506 // fPatch converts from software id to software patch id
1507 for (int i=0; i<1440; i++)
1508 {
1509 const int ihw = fPatchHW[i];
1510// const int isw = fPatch[i];
1511// const int ihw = fPatchMapHW[isw];
1512 dat[i] = sdata.fRatePatch[ihw];
1513 }
1514
1515 c = fRatesCanv->GetCanvas();
1516 Camera *cam = (Camera*)c->FindObject("Camera");
1517
1518 cam->SetData(dat);
1519
1520 c->Modified();
1521 c->Update();
1522
1523 // ----------------------------------------------
1524#endif
1525 }
1526
1527 void DisplayRates()
1528 {
1529#ifdef HAVE_ROOT
1530 TCanvas *c = fFtmRateCanv->GetCanvas();
1531
1532 while (c->FindObject("PatchRate"))
1533 c->GetListOfPrimitives()->Remove(c->FindObject("PatchRate"));
1534
1535 while (c->FindObject("BoardRate"))
1536 c->GetListOfPrimitives()->Remove(c->FindObject("BoardRate"));
1537
1538 c->cd();
1539
1540 if (fRatePatch1->value()>=0)
1541 {
1542 fGraphPatchRate[fRatePatch1->value()].SetLineColor(kRed);
1543 fGraphPatchRate[fRatePatch1->value()].SetMarkerColor(kRed);
1544 fGraphPatchRate[fRatePatch1->value()].Draw("PL");
1545 }
1546 if (fRatePatch2->value()>=0)
1547 {
1548 fGraphPatchRate[fRatePatch2->value()].SetLineColor(kGreen);
1549 fGraphPatchRate[fRatePatch2->value()].SetMarkerColor(kGreen);
1550 fGraphPatchRate[fRatePatch2->value()].Draw("PL");
1551 }
1552 if (fRateBoard1->value()>=0)
1553 {
1554 fGraphBoardRate[fRateBoard1->value()].SetLineColor(kMagenta);
1555 fGraphBoardRate[fRateBoard1->value()].SetMarkerColor(kMagenta);
1556 fGraphBoardRate[fRateBoard1->value()].Draw("PL");
1557 }
1558 if (fRateBoard2->value()>=0)
1559 {
1560 fGraphBoardRate[fRateBoard2->value()].SetLineColor(kCyan);
1561 fGraphBoardRate[fRateBoard2->value()].SetMarkerColor(kCyan);
1562 fGraphBoardRate[fRateBoard2->value()].Draw("PL");
1563 }
1564#endif
1565 }
1566
1567 void on_fRatePatch1_valueChanged(int)
1568 {
1569 DisplayRates();
1570 }
1571
1572 void on_fRatePatch2_valueChanged(int)
1573 {
1574 DisplayRates();
1575 }
1576
1577 void on_fRateBoard1_valueChanged(int)
1578 {
1579 DisplayRates();
1580 }
1581
1582 void on_fRateBoard2_valueChanged(int)
1583 {
1584 DisplayRates();
1585 }
1586
1587 FTM::DimStaticData fFtmStaticData;
1588
1589 void SetFtuLed(int idx, int counter, const Time &t)
1590 {
1591 if (counter==0 || counter>3)
1592 counter = 3;
1593
1594 if (counter<0)
1595 counter = 0;
1596
1597 const LedColor_t col[4] = { kLedGray, kLedGreen, kLedOrange, kLedRed };
1598
1599 SetLedColor(fFtuLED[idx], col[counter], t);
1600
1601 fFtuStatus[idx] = counter;
1602 }
1603
1604 void SetFtuStatusLed(const Time &t)
1605 {
1606 const int max = fFtuStatus.max();
1607
1608 switch (max)
1609 {
1610 case 0:
1611 SetLedColor(fStatusFTULed, kLedGray, t);
1612 fStatusFTULabel->setText("All disabled");
1613 fStatusFTULabel->setToolTip("All FTUs are disabled");
1614 break;
1615
1616 case 1:
1617 SetLedColor(fStatusFTULed, kLedGreen, t);
1618 fStatusFTULabel->setToolTip("Communication with FTU is smooth.");
1619 fStatusFTULabel->setText("ok");
1620 break;
1621
1622 case 2:
1623 SetLedColor(fStatusFTULed, kLedOrange, t);
1624 fStatusFTULabel->setText("Warning");
1625 fStatusFTULabel->setToolTip("At least one FTU didn't answer immediately");
1626 break;
1627
1628 case 3:
1629 SetLedColor(fStatusFTULed, kLedRed, t);
1630 fStatusFTULabel->setToolTip("At least one FTU didn't answer!");
1631 fStatusFTULabel->setText("ERROR");
1632 break;
1633 }
1634
1635 const int cnt = count(&fFtuStatus[0], &fFtuStatus[40], 0);
1636 fFtuAllOn->setEnabled(cnt!=0);
1637 fFtuAllOff->setEnabled(cnt!=40);
1638 }
1639
1640 void handleFtmStaticData(const DimData &d)
1641 {
1642 if (!CheckSize(d, sizeof(FTM::DimStaticData)))
1643 return;
1644
1645 const FTM::DimStaticData &sdata = d.ref<FTM::DimStaticData>();
1646
1647 fTriggerInterval->setValue(sdata.fTriggerInterval);
1648 fPhysicsCoincidence->setValue(sdata.fMultiplicityPhysics);
1649 fCalibCoincidence->setValue(sdata.fMultiplicityCalib);
1650 fPhysicsWindow->setValue(sdata.fWindowPhysics);
1651 fCalibWindow->setValue(sdata.fWindowCalib);
1652
1653 fTriggerDelay->setValue(sdata.fDelayTrigger);
1654 fTimeMarkerDelay->setValue(sdata.fDelayTimeMarker);
1655 fDeadTime->setValue(sdata.fDeadTime);
1656
1657 fClockCondR0->setValue(sdata.fClockConditioner[0]);
1658 fClockCondR1->setValue(sdata.fClockConditioner[1]);
1659 fClockCondR8->setValue(sdata.fClockConditioner[2]);
1660 fClockCondR9->setValue(sdata.fClockConditioner[3]);
1661 fClockCondR11->setValue(sdata.fClockConditioner[4]);
1662 fClockCondR13->setValue(sdata.fClockConditioner[5]);
1663 fClockCondR14->setValue(sdata.fClockConditioner[6]);
1664 fClockCondR15->setValue(sdata.fClockConditioner[7]);
1665
1666 const uint32_t R0 = sdata.fClockConditioner[0];
1667 const uint32_t R14 = sdata.fClockConditioner[6];
1668 const uint32_t R15 = sdata.fClockConditioner[7];
1669
1670 const uint32_t Ndiv = (R15&0x1ffff00)<<2;
1671 const uint32_t Rdiv = (R14&0x007ff00)>>8;
1672 const uint32_t Cdiv = (R0 &0x000ff00)>>8;
1673
1674 double freq = 40.*Ndiv/(Rdiv*Cdiv);
1675
1676 fClockCondFreqRes->setValue(freq);
1677
1678 //fClockCondFreq->setEditText("");
1679 fClockCondFreq->setCurrentIndex(0);
1680
1681 fTriggerSeqPed->setValue(sdata.fTriggerSeqPed);
1682 fTriggerSeqLPint->setValue(sdata.fTriggerSeqLPint);
1683 fTriggerSeqLPext->setValue(sdata.fTriggerSeqLPext);
1684
1685 fEnableTrigger->setChecked(sdata.HasTrigger());
1686 fEnableVeto->setChecked(sdata.HasVeto());
1687 fEnableExt1->setChecked(sdata.HasExt1());
1688 fEnableExt2->setChecked(sdata.HasExt2());
1689 fEnableClockCond->setChecked(sdata.HasClockConditioner());
1690
1691 for (int i=0; i<40; i++)
1692 {
1693 if (!sdata.IsActive(i))
1694 SetFtuLed(i, -1, d.time);
1695 else
1696 {
1697 if (fFtuStatus[i]==0)
1698 SetFtuLed(i, 1, d.time);
1699 }
1700 fFtuLED[i]->setChecked(false);
1701 }
1702 SetFtuStatusLed(d.time);
1703
1704#ifdef HAVE_ROOT
1705 Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
1706 for (int isw=0; isw<1440; isw++)
1707 {
1708 const int ihw = fPixelMapHW[isw];
1709 cam->SetEnable(isw, sdata.IsEnabled(ihw));
1710 }
1711
1712 fRatesCanv->GetCanvas()->Modified();
1713 fRatesCanv->GetCanvas()->Update();
1714#endif
1715
1716 {
1717 const int isw = fPixelIdx->value();
1718 const int ihw = fPixelMapHW[isw];
1719 const bool on = sdata.IsEnabled(ihw);
1720 fPixelEnable->setChecked(on);
1721 }
1722
1723 if (fThresholdIdx->value()>=0)
1724 {
1725 const int isw = fThresholdIdx->value();
1726 const int ihw = fPatchMapHW[isw];
1727 fThresholdVal->setValue(sdata.fThreshold[ihw]);
1728 }
1729
1730 fPrescalingVal->setValue(sdata.fPrescaling[0]);
1731
1732 fFtmStaticData = sdata;
1733 }
1734
1735 void handleFtmPassport(const DimData &d)
1736 {
1737 if (!CheckSize(d, sizeof(FTM::DimPassport)))
1738 return;
1739
1740 const FTM::DimPassport &sdata = d.ref<FTM::DimPassport>();
1741
1742 stringstream str1, str2;
1743 str1 << hex << "0x" << setfill('0') << setw(16) << sdata.fBoardId;
1744 str2 << sdata.fFirmwareId;
1745
1746 fFtmBoardId->setText(str1.str().c_str());
1747 fFtmFirmwareId->setText(str2.str().c_str());
1748 }
1749
1750 void handleFtmFtuList(const DimData &d)
1751 {
1752 if (!CheckSize(d, sizeof(FTM::DimFtuList)))
1753 return;
1754
1755 fFtuPing->setChecked(false);
1756
1757 const FTM::DimFtuList &sdata = d.ref<FTM::DimFtuList>();
1758
1759 stringstream str;
1760 str << "<table width='100%'>" << setfill('0');
1761 str << "<tr><th>Num</th><th></th><th>Addr</th><th></th><th>DNA</th></tr>";
1762 for (int i=0; i<40; i++)
1763 {
1764 str << "<tr>";
1765 str << "<td align='center'>" << dec << i << hex << "</td>";
1766 str << "<td align='center'>:</td>";
1767 str << "<td align='center'>0x" << setw(2) << (int)sdata.fAddr[i] << "</td>";
1768 str << "<td align='center'>:</td>";
1769 str << "<td align='center'>0x" << setw(16) << sdata.fDNA[i] << "</td>";
1770 str << "</tr>";
1771 }
1772 str << "</table>";
1773
1774 fFtuDNA->setText(str.str().c_str());
1775
1776 fFtuAnswersTotal->setValue(sdata.fNumBoards);
1777 fFtuAnswersCrate0->setValue(sdata.fNumBoardsCrate[0]);
1778 fFtuAnswersCrate1->setValue(sdata.fNumBoardsCrate[1]);
1779 fFtuAnswersCrate2->setValue(sdata.fNumBoardsCrate[2]);
1780 fFtuAnswersCrate3->setValue(sdata.fNumBoardsCrate[3]);
1781
1782 for (int i=0; i<40; i++)
1783 SetFtuLed(i, sdata.IsActive(i) ? sdata.fPing[i] : -1, d.time);
1784
1785 SetFtuStatusLed(d.time);
1786 }
1787
1788 void handleFtmError(const DimData &d)
1789 {
1790 if (!CheckSize(d, sizeof(FTM::DimError)))
1791 return;
1792
1793 const FTM::DimError &sdata = d.ref<FTM::DimError>();
1794
1795 SetFtuLed(sdata.fError.fDestAddress , sdata.fError.fNumCalls, d.time);
1796 SetFtuStatusLed(d.time);
1797
1798 // FIXME: Write to special window!
1799 //Out() << "Error:" << endl;
1800 //Out() << sdata.fError << endl;
1801 }
1802
1803 // ====================== MessageImp ====================================
1804
1805 bool fChatOnline;
1806
1807 void handleStateChanged(const Time &time, const std::string &server,
1808 const State &s)
1809 {
1810 // FIXME: Prefix tooltip with time
1811 if (server=="FTM_CONTROL")
1812 {
1813 // FIXME: Enable FTU page!!!
1814 fStatusFTMLabel->setText(s.name.c_str());
1815 fStatusFTMLabel->setToolTip(s.comment.c_str());
1816
1817 bool enable = false;
1818
1819 if (s.index<FTM::kDisconnected) // No Dim connection
1820 SetLedColor(fStatusFTMLed, kLedGray, time);
1821 if (s.index==FTM::kDisconnected) // Dim connection / FTM disconnected
1822 SetLedColor(fStatusFTMLed, kLedYellow, time);
1823 if (s.index==FTM::kConnected || s.index==FTM::kIdle || s.index==FTM::kTakingData) // Dim connection / FTM connected
1824 SetLedColor(fStatusFTMLed, kLedGreen, time);
1825
1826 if (s.index==FTM::kConnected || s.index==FTM::kIdle) // Dim connection / FTM connected
1827 enable = true;
1828
1829 fTriggerWidget->setEnabled(enable);
1830 fFtuWidget->setEnabled(enable);
1831 fRatesWidget->setEnabled(enable);
1832
1833 if (!enable)
1834 {
1835 SetLedColor(fStatusFTULed, kLedGray, time);
1836 fStatusFTULabel->setText("Offline");
1837 fStatusFTULabel->setToolTip("FTM is not online.");
1838 }
1839 }
1840
1841 if (server=="FAD_CONTROL")
1842 {
1843 fStatusFADLabel->setText(s.name.c_str());
1844 fStatusFADLabel->setToolTip(s.comment.c_str());
1845
1846 bool enable = false;
1847
1848 if (s.index<FAD::kOffline) // No Dim connection
1849 {
1850 SetLedColor(fStatusFADLed, kLedGray, time);
1851
1852 fStatusEventBuilderLabel->setText("Offline");
1853 fStatusEventBuilderLabel->setToolTip("No connection to fadctrl.");
1854 fEvtBldWidget->setEnabled(false);
1855
1856 SetLedColor(fStatusEventBuilderLed, kLedGray, time);
1857 }
1858 if (s.index==FAD::kOffline) // Dim connection / FTM disconnected
1859 SetLedColor(fStatusFADLed, kLedRed, time);
1860 if (s.index==FAD::kDisconnected) // Dim connection / FTM disconnected
1861 SetLedColor(fStatusFADLed, kLedOrange, time);
1862 if (s.index==FAD::kConnecting) // Dim connection / FTM disconnected
1863 {
1864 SetLedColor(fStatusFADLed, kLedYellow, time);
1865 // FIXME FIXME FIXME: The LEDs are not displayed when disabled!
1866 enable = true;
1867 }
1868 if (s.index>=FAD::kConnected) // Dim connection / FTM connected
1869 {
1870 SetLedColor(fStatusFADLed, kLedGreen, time);
1871 enable = true;
1872 }
1873
1874 fFadWidget->setEnabled(enable);
1875 }
1876
1877 if (server=="FSC_CONTROL")
1878 {
1879 fStatusFSCLabel->setText(s.name.c_str());
1880 fStatusFSCLabel->setToolTip(s.comment.c_str());
1881
1882 bool enable = false;
1883
1884 if (s.index<1) // No Dim connection
1885 SetLedColor(fStatusFSCLed, kLedGray, time);
1886 if (s.index==1) // Dim connection / FTM disconnected
1887 SetLedColor(fStatusFSCLed, kLedRed, time);
1888 if (s.index>=2) // Dim connection / FTM disconnected
1889 {
1890 SetLedColor(fStatusFSCLed, kLedGreen, time);
1891 enable = true;
1892 }
1893
1894 //fFscWidget->setEnabled(enable);
1895 }
1896
1897 if (server=="DATA_LOGGER")
1898 {
1899 fStatusLoggerLabel->setText(s.name.c_str());
1900 fStatusLoggerLabel->setToolTip(s.comment.c_str());
1901
1902 bool enable = true;
1903
1904 if (s.index<=30) // Ready/Waiting
1905 SetLedColor(fStatusLoggerLed, kLedYellow, time);
1906 if (s.index<-1) // Offline
1907 {
1908 SetLedColor(fStatusLoggerLed, kLedGray, time);
1909 enable = false;
1910 }
1911 if (s.index>=0x100) // Error
1912 SetLedColor(fStatusLoggerLed, kLedRed, time);
1913 if (s.index==40) // Logging
1914 SetLedColor(fStatusLoggerLed, kLedGreen, time);
1915
1916 fLoggerWidget->setEnabled(enable);
1917 }
1918
1919 if (server=="CHAT")
1920 {
1921 fStatusChatLabel->setText(s.name.c_str());
1922
1923 fChatOnline = s.index==0;
1924
1925 SetLedColor(fStatusChatLed, fChatOnline ? kLedGreen : kLedGray, time);
1926
1927 fChatSend->setEnabled(fChatOnline);
1928 fChatMessage->setEnabled(fChatOnline);
1929 }
1930
1931 if (server=="SCHEDULER")
1932 {
1933 fStatusSchedulerLabel->setText(s.name.c_str());
1934
1935 SetLedColor(fStatusSchedulerLed, s.index>=0 ? kLedGreen : kLedRed, time);
1936 }
1937 }
1938
1939 void handleStateOffline(const string &server)
1940 {
1941 handleStateChanged(Time(), server, State(-2, "Offline", "No connection via DIM."));
1942 }
1943
1944 void on_fTabWidget_currentChanged(int which)
1945 {
1946 if (fTabWidget->tabText(which)=="Chat")
1947 fTabWidget->setTabIcon(which, QIcon());
1948 }
1949
1950 void handleWrite(const Time &time, const string &text, int qos)
1951 {
1952 stringstream out;
1953
1954 if (text.substr(0, 6)=="CHAT: ")
1955 {
1956 if (qos==MessageImp::kDebug)
1957 return;
1958
1959 out << "<font size='-1' color='navy'>[<B>";
1960 out << Time::fmt("%H:%M:%S") << time << "</B>]</FONT> ";
1961 out << text.substr(6);
1962 fChatText->append(out.str().c_str());
1963
1964 if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
1965 return;
1966
1967 static int num = 0;
1968 if (num++<2)
1969 return;
1970
1971 for (int i=0; i<fTabWidget->count(); i++)
1972 if (fTabWidget->tabText(i)=="Chat")
1973 {
1974 fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
1975 break;
1976 }
1977
1978 return;
1979 }
1980
1981
1982 out << "<font style='font-family:monospace' color='";
1983
1984 switch (qos)
1985 {
1986 case kMessage: out << "black"; break;
1987 case kInfo: out << "green"; break;
1988 case kWarn: out << "#FF6600"; break;
1989 case kError: out << "maroon"; break;
1990 case kFatal: out << "maroon"; break;
1991 case kDebug: out << "navy"; break;
1992 default: out << "navy"; break;
1993 }
1994 out << "'>" << time.GetAsStr() << " - " << text << "</font>";
1995
1996 fLogText->append(out.str().c_str());
1997
1998 if (qos>=kWarn)
1999 fTextEdit->append(out.str().c_str());
2000 }
2001
2002 void IndicateStateChange(const Time &time, const std::string &server)
2003 {
2004 const State s = GetState(server, GetCurrentState(server));
2005
2006 QApplication::postEvent(this,
2007 new FunctionEvent(boost::bind(&FactGui::handleStateChanged, this, time, server, s)));
2008 }
2009
2010 int Write(const Time &time, const string &txt, int qos)
2011 {
2012 QApplication::postEvent(this,
2013 new FunctionEvent(boost::bind(&FactGui::handleWrite, this, time, txt, qos)));
2014
2015 return 0;
2016 }
2017
2018 // ====================== Dim infoHandler================================
2019
2020 void handleDimService(const string &txt)
2021 {
2022 fDimSvcText->append(txt.c_str());
2023 }
2024
2025 void infoHandlerService(DimInfo &info)
2026 {
2027 const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
2028
2029 stringstream dummy;
2030 const Converter conv(dummy, fmt, false);
2031
2032 const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
2033
2034 stringstream out;
2035 out << "<font size'-1' color='navy'>[" << Time::fmt("%H:%M:%S.%f") << tm << "]</font> <B>" << info.getName() << "</B> - ";
2036
2037 bool iserr = true;
2038 if (!conv)
2039 {
2040 out << "Compilation of format string '" << fmt << "' failed!";
2041 }
2042 else
2043 {
2044 try
2045 {
2046 const string dat = conv.GetString(info.getData(), info.getSize());
2047 out << dat;
2048 iserr = false;
2049 }
2050 catch (const runtime_error &e)
2051 {
2052 out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
2053 }
2054 }
2055
2056 // srand(hash<string>()(string(info.getName())));
2057 // int bg = rand()&0xffffff;
2058
2059 int bg = hash<string>()(string(info.getName()));
2060
2061 // allow only light colors
2062 bg = ~(bg&0x1f1f1f)&0xffffff;
2063
2064 if (iserr)
2065 bg = 0xffffff;
2066
2067 stringstream bgcol;
2068 bgcol << hex << setfill('0') << setw(6) << bg;
2069
2070 const string col = iserr ? "red" : "black";
2071 const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
2072
2073 QApplication::postEvent(this,
2074 new FunctionEvent(boost::bind(&FactGui::handleDimService, this, str)));
2075 }
2076
2077 void CallInfoHandler(void (FactGui::*handler)(const DimData&), const DimData &d)
2078 {
2079 fInHandler = true;
2080 (this->*handler)(d);
2081 fInHandler = false;
2082 }
2083
2084 /*
2085 void CallInfoHandler(const boost::function<void()> &func)
2086 {
2087 // This ensures that newly received values are not sent back to the emitter
2088 // because changing the value emits the valueChanged signal (or similar)
2089 fInHandler = true;
2090 func();
2091 fInHandler = false;
2092 }*/
2093
2094 void PostInfoHandler(void (FactGui::*handler)(const DimData&))
2095 {
2096 //const boost::function<void()> f = boost::bind(handler, this, DimData(getInfo()));
2097
2098 FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, handler, DimData(getInfo())));
2099 // FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, f));
2100 // FunctionEvent *evt = new FunctionEvent(boost::bind(handler, this, DimData(getInfo()))));
2101
2102 QApplication::postEvent(this, evt);
2103 }
2104
2105 void infoHandler()
2106 {
2107 // Initialize the time-stamp (what a weird workaround...)
2108 if (getInfo())
2109 getInfo()->getTimestamp();
2110
2111 if (getInfo()==&fDimDNS)
2112 return PostInfoHandler(&FactGui::handleDimDNS);
2113#ifdef DEBUG_DIM
2114 cout << "HandleDimInfo " << getInfo()->getName() << endl;
2115#endif
2116 if (getInfo()==&fDimLoggerStats)
2117 return PostInfoHandler(&FactGui::handleLoggerStats);
2118
2119// if (getInfo()==&fDimFadFiles)
2120// return PostInfoHandler(&FactGui::handleFadFiles);
2121
2122 if (getInfo()==&fDimFadConnections)
2123 return PostInfoHandler(&FactGui::handleFadConnections);
2124
2125 if (getInfo()==&fDimFadFwVersion)
2126 return PostInfoHandler(&FactGui::handleFadFwVersion);
2127
2128 if (getInfo()==&fDimFadRunNumber)
2129 return PostInfoHandler(&FactGui::handleFadRunNumber);
2130
2131 if (getInfo()==&fDimFadDNA)
2132 return PostInfoHandler(&FactGui::handleFadDNA);
2133
2134 if (getInfo()==&fDimFadTemperature)
2135 return PostInfoHandler(&FactGui::handleFadTemperature);
2136
2137 if (getInfo()==&fDimFadRefClock)
2138 return PostInfoHandler(&FactGui::handleFadRefClock);
2139
2140 if (getInfo()==&fDimFadStatus)
2141 return PostInfoHandler(&FactGui::handleFadStatus);
2142
2143 if (getInfo()==&fDimFadStatistics)
2144 return PostInfoHandler(&FactGui::handleFadStatistics);
2145
2146 if (getInfo()==&fDimFadEvents)
2147 return PostInfoHandler(&FactGui::handleFadEvents);
2148
2149 if (getInfo()==&fDimFadRuns)
2150 return PostInfoHandler(&FactGui::handleFadRuns);
2151
2152 if (getInfo()==&fDimFadEventData)
2153 return PostInfoHandler(&FactGui::handleFadEventData);
2154
2155/*
2156 if (getInfo()==&fDimFadSetup)
2157 return PostInfoHandler(&FactGui::handleFadSetup);
2158*/
2159 if (getInfo()==&fDimLoggerFilenameNight)
2160 return PostInfoHandler(&FactGui::handleLoggerFilenameNight);
2161
2162 if (getInfo()==&fDimLoggerNumSubs)
2163 return PostInfoHandler(&FactGui::handleLoggerNumSubs);
2164
2165 if (getInfo()==&fDimLoggerFilenameRun)
2166 return PostInfoHandler(&FactGui::handleLoggerFilenameRun);
2167
2168 if (getInfo()==&fDimFtmTriggerCounter)
2169 return PostInfoHandler(&FactGui::handleFtmTriggerCounter);
2170
2171 if (getInfo()==&fDimFtmCounter)
2172 return PostInfoHandler(&FactGui::handleFtmCounter);
2173
2174 if (getInfo()==&fDimFtmDynamicData)
2175 return PostInfoHandler(&FactGui::handleFtmDynamicData);
2176
2177 if (getInfo()==&fDimFtmPassport)
2178 return PostInfoHandler(&FactGui::handleFtmPassport);
2179
2180 if (getInfo()==&fDimFtmFtuList)
2181 return PostInfoHandler(&FactGui::handleFtmFtuList);
2182
2183 if (getInfo()==&fDimFtmStaticData)
2184 return PostInfoHandler(&FactGui::handleFtmStaticData);
2185
2186 if (getInfo()==&fDimFtmError)
2187 return PostInfoHandler(&FactGui::handleFtmError);
2188
2189// if (getInfo()==&fDimFadFiles)
2190// return PostInfoHandler(&FactGui::handleFadFiles);
2191
2192 for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
2193 if (i->second==getInfo())
2194 {
2195 infoHandlerService(*i->second);
2196 return;
2197 }
2198
2199 DimNetwork::infoHandler();
2200 }
2201
2202
2203 // ======================================================================
2204
2205 bool event(QEvent *evt)
2206 {
2207 if (dynamic_cast<FunctionEvent*>(evt))
2208 return static_cast<FunctionEvent*>(evt)->Exec();
2209
2210 if (dynamic_cast<CheckBoxEvent*>(evt))
2211 {
2212 const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
2213 const QStandardItem *par = item.parent();
2214 if (par)
2215 {
2216 const QString server = par->text();
2217 const QString service = item.text();
2218
2219 const string s = (server+'/'+service).toStdString();
2220
2221 if (item.checkState()==Qt::Checked)
2222 SubscribeService(s);
2223 else
2224 UnsubscribeService(s);
2225 }
2226 }
2227
2228 return MainWindow::event(evt); // unrecognized
2229 }
2230
2231 void on_fDimCmdSend_clicked()
2232 {
2233 const QString server = fDimCmdServers->currentIndex().data().toString();
2234 const QString command = fDimCmdCommands->currentIndex().data().toString();
2235 const QString arguments = fDimCmdLineEdit->displayText();
2236
2237 // FIXME: Sending a command exactly when the info Handler changes
2238 // the list it might lead to confusion.
2239 try
2240 {
2241 SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
2242 fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
2243 fDimCmdLineEdit->clear();
2244 }
2245 catch (const runtime_error &e)
2246 {
2247 stringstream txt;
2248 txt << e.what();
2249
2250 string buffer;
2251 while (getline(txt, buffer, '\n'))
2252 fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
2253 }
2254 }
2255
2256#ifdef HAVE_ROOT
2257 void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *canv)
2258 {
2259 // kMousePressEvent // TCanvas processed QEvent mousePressEvent
2260 // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
2261 // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
2262 // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
2263 // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
2264 // kEnterEvent // TCanvas processed QEvent enterEvent
2265 // kLeaveEvent // TCanvas processed QEvent leaveEvent
2266 if (dynamic_cast<TCanvas*>(obj))
2267 return;
2268
2269 TQtWidget *tipped = static_cast<TQtWidget*>(sender());
2270
2271 if (evt==11/*kMouseReleaseEvent*/)
2272 {
2273 if (dynamic_cast<Camera*>(obj))
2274 {
2275 const float xx = canv->AbsPixeltoX(tipped->GetEventX());
2276 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
2277
2278 Camera *cam = static_cast<Camera*>(obj);
2279 const int isw = cam->GetIdx(xx, yy);
2280
2281 fPixelIdx->setValue(isw);
2282 ChoosePixel(*cam, isw);
2283 }
2284 return;
2285 }
2286
2287 if (evt==61/*kMouseDoubleClickEvent*/)
2288 {
2289 if (dynamic_cast<Camera*>(obj))
2290 {
2291 const float xx = canv->AbsPixeltoX(tipped->GetEventX());
2292 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
2293
2294 Camera *cam = static_cast<Camera*>(obj);
2295 const int isw = cam->GetIdx(xx, yy);
2296
2297 ChoosePixel(*cam, isw);
2298
2299 fPixelIdx->setValue(isw);
2300
2301 const uint16_t ihw = fPixelMapHW[isw];
2302
2303 Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", ihw);
2304 }
2305
2306 if (dynamic_cast<TAxis*>(obj))
2307 static_cast<TAxis*>(obj)->UnZoom();
2308
2309 return;
2310 }
2311
2312 // Find the object which will get picked by the GetObjectInfo
2313 // due to buffer overflows in many root-versions
2314 // in TH1 and TProfile we have to work around and implement
2315 // our own GetObjectInfo which make everything a bit more
2316 // complicated.
2317 canv->cd();
2318#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
2319 const char *objectInfo =
2320 obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
2321#else
2322 const char *objectInfo = dynamic_cast<TH1*>(obj) ?
2323 "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
2324#endif
2325
2326 QString tipText;
2327 tipText += obj->GetName();
2328 tipText += " [";
2329 tipText += obj->ClassName();
2330 tipText += "]: ";
2331 tipText += objectInfo;
2332
2333 if (dynamic_cast<Camera*>(obj))
2334 {
2335 const float xx = canv->AbsPixeltoX(tipped->GetEventX());
2336 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
2337
2338 Camera *cam = static_cast<Camera*>(obj);
2339
2340 const int isw = cam->GetIdx(xx, yy);
2341 const int ihw = fPixelMapHW[isw];
2342
2343 const int idx = fPatchHW[isw];
2344
2345 int ii = 0;
2346 for (; ii<160; ii++)
2347 if (idx==fPatchMapHW[ii])
2348 break;
2349
2350
2351 const int patch = ihw%4;
2352 const int board = (ihw/4)%10;
2353 const int crate = (ihw/4)/10;
2354
2355 ostringstream str;
2356 str << " (hw=" << ihw << ") Patch=" << ii << " (hw=" << fPatchMapHW[idx] << "; Crate=" << crate << " Board=" << board << " Patch=" << patch << ")";
2357
2358 tipText += str.str().c_str();
2359 }
2360
2361
2362 fStatusBar->showMessage(tipText, 3000);
2363
2364 gSystem->ProcessEvents();
2365 //QWhatsThis::display(tipText)
2366 }
2367
2368 void slot_RootUpdate()
2369 {
2370 gSystem->ProcessEvents();
2371 QTimer::singleShot(0, this, SLOT(slot_RootUpdate()));
2372 }
2373
2374 void ChoosePatch(Camera &cam, int isw)
2375 {
2376 cam.Reset();
2377
2378 fThresholdIdx->setValue(isw);
2379
2380 const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
2381
2382 fPatchRate->setEnabled(isw>=0);
2383 fThresholdCrate->setEnabled(isw>=0);
2384 fThresholdBoard->setEnabled(isw>=0);
2385 fThresholdPatch->setEnabled(isw>=0);
2386
2387 if (isw<0)
2388 return;
2389
2390 const int patch = ihw%4;
2391 const int board = (ihw/4)%10;
2392 const int crate = (ihw/4)/10;
2393
2394 fInChoosePatch = true;
2395
2396 fThresholdCrate->setValue(crate);
2397 fThresholdBoard->setValue(board);
2398 fThresholdPatch->setValue(patch);
2399
2400 fInChoosePatch = false;
2401
2402 fThresholdVal->setValue(fFtmStaticData.fThreshold[ihw]);
2403 fPatchRate->setValue(cam.GetData(isw));
2404
2405 // Loop over the software idx of all pixels
2406 for (unsigned int i=0; i<1440; i++)
2407 if (fPatchHW[i]==ihw)
2408 cam.SetBold(i);
2409 }
2410
2411 void ChoosePixel(Camera &cam, int isw)
2412 {
2413 const int ihw = fPixelMapHW[isw];
2414
2415 int ii = 0;
2416 for (; ii<160; ii++)
2417 if (fPatchHW[isw]==fPatchMapHW[ii])
2418 break;
2419
2420 cam.SetWhite(isw);
2421 ChoosePatch(cam, ii);
2422
2423 const bool on = fFtmStaticData.IsEnabled(ihw);
2424 fPixelEnable->setChecked(on);
2425 }
2426
2427 void UpdatePatch(int isw)
2428 {
2429 Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
2430 ChoosePatch(*cam, isw);
2431 }
2432
2433 void on_fThresholdIdx_valueChanged(int isw)
2434 {
2435 UpdatePatch(isw);
2436
2437 fRatesCanv->GetCanvas()->Modified();
2438 fRatesCanv->GetCanvas()->Update();
2439 }
2440
2441 void UpdateThresholdIdx()
2442 {
2443 if (fInChoosePatch)
2444 return;
2445
2446 const int crate = fThresholdCrate->value();
2447 const int board = fThresholdBoard->value();
2448 const int patch = fThresholdPatch->value();
2449
2450 const int ihw = patch + board*4 + crate*40;
2451
2452 int isw = 0;
2453 for (; isw<160; isw++)
2454 if (ihw==fPatchMapHW[isw])
2455 break;
2456
2457 UpdatePatch(isw);
2458 }
2459
2460 void on_fThresholdPatch_valueChanged(int)
2461 {
2462 UpdateThresholdIdx();
2463 }
2464 void on_fThresholdBoard_valueChanged(int)
2465 {
2466 UpdateThresholdIdx();
2467 }
2468 void on_fThresholdCrate_valueChanged(int)
2469 {
2470 UpdateThresholdIdx();
2471 }
2472
2473 void on_fPixelIdx_valueChanged(int isw)
2474 {
2475 Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
2476 ChoosePixel(*cam, isw);
2477
2478 fRatesCanv->GetCanvas()->Modified();
2479 fRatesCanv->GetCanvas()->Update();
2480 }
2481#endif
2482
2483 void on_fPixelEnable_stateChanged(int b)
2484 {
2485 if (fInHandler)
2486 return;
2487
2488 const uint16_t isw = fPixelIdx->value();
2489 const uint16_t ihw = fPixelMapHW[isw];
2490
2491 Dim::SendCommand(b==Qt::Unchecked ?
2492 "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
2493 ihw);
2494 }
2495
2496 void on_fPixelDisableOthers_clicked()
2497 {
2498 const uint16_t isw = fPixelIdx->value();
2499 const uint16_t ihw = fPixelMapHW[isw];
2500
2501 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PIXELS_EXCEPT", ihw);
2502 }
2503
2504 void on_fThresholdDisableOthers_clicked()
2505 {
2506 const uint16_t isw = fThresholdIdx->value();
2507 const uint16_t ihw = fPatchMapHW[isw];
2508
2509 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PATCHES_EXCEPT", ihw);
2510 }
2511
2512 void on_fThresholdVal_valueChanged(int v)
2513 {
2514 fThresholdVolt->setValue(2500./4095*v);
2515
2516 const int32_t isw = fThresholdIdx->value();
2517 const int32_t ihw = fPatchMapHW[isw];
2518
2519 const int32_t d[2] = { ihw, v };
2520
2521 if (!fInHandler)
2522 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
2523 }
2524
2525 TGraph fGraphFtmTemp[4];
2526 TGraph fGraphFtmRate;
2527 TGraph fGraphPatchRate[160];
2528 TGraph fGraphBoardRate[40];
2529
2530#ifdef HAVE_ROOT
2531 void DrawTimeFrame(const char *ytitle)
2532 {
2533 const double tm = Time().RootTime();
2534
2535 TH1F h("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
2536 h.SetDirectory(0);
2537// h.SetBit(TH1::kCanRebin);
2538 h.SetStats(kFALSE);
2539// h.SetMinimum(0);
2540// h.SetMaximum(1);
2541 h.SetXTitle("Time");
2542 h.SetYTitle(ytitle);
2543 h.GetXaxis()->CenterTitle();
2544 h.GetYaxis()->CenterTitle();
2545 h.GetXaxis()->SetTimeDisplay(true);
2546 h.GetXaxis()->SetTimeFormat("%Mh%S'");
2547 h.GetXaxis()->SetLabelSize(0.025);
2548 h.GetYaxis()->SetLabelSize(0.025);
2549 h.GetYaxis()->SetTitleOffset(1.2);
2550// h.GetYaxis()->SetTitleSize(1.2);
2551 h.DrawCopy()->SetDirectory(0);
2552 }
2553#endif
2554
2555public:
2556 FactGui() :
2557 fFtuStatus(40),
2558 fPixelMapHW(1440), fPatchMapHW(160), fPatchHW(1440),
2559 fInChoosePatch(false),
2560 fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
2561 //-
2562 fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
2563 fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHTLY", (void*)NULL, 0, this),
2564 fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", (void*)NULL, 0, this),
2565 fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", (void*)NULL, 0, this),
2566 //-
2567 fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
2568 fDimFtmTriggerCounter ("FTM_CONTROL/TRIGGER_COUNTER", (void*)NULL, 0, this),
2569 fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
2570 fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
2571 fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
2572 fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this),
2573 fDimFtmCounter ("FTM_CONTROL/COUNTER", (void*)NULL, 0, this),
2574 //-
2575 fDimFadRuns ("FAD_CONTROL/RUNS", (void*)NULL, 0, this),
2576 fDimFadEvents ("FAD_CONTROL/EVENTS", (void*)NULL, 0, this),
2577 fDimFadEventData ("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, this),
2578 fDimFadConnections ("FAD_CONTROL/CONNECTIONS", (void*)NULL, 0, this),
2579 fDimFadFwVersion ("FAD_CONTROL/FIRMWARE_VERSION", (void*)NULL, 0, this),
2580 fDimFadRunNumber ("FAD_CONTROL/RUN_NUMBER", (void*)NULL, 0, this),
2581 fDimFadDNA ("FAD_CONTROL/DNA", (void*)NULL, 0, this),
2582 fDimFadTemperature ("FAD_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
2583 fDimFadRefClock ("FAD_CONTROL/REFERENCE_CLOCK", (void*)NULL, 0, this),
2584 fDimFadStatus ("FAD_CONTROL/STATUS", (void*)NULL, 0, this),
2585 fDimFadStatistics ("FAD_CONTROL/STATISTICS", (void*)NULL, 0, this),
2586 //-
2587 fEventData(0)
2588 {
2589 fClockCondFreq->addItem("--- Hz", QVariant(-1));
2590 fClockCondFreq->addItem("800 MHz", QVariant(800));
2591 fClockCondFreq->addItem("1 GHz", QVariant(1000));
2592 fClockCondFreq->addItem("2 GHz", QVariant(2000));
2593 fClockCondFreq->addItem("3 GHz", QVariant(3000));
2594 fClockCondFreq->addItem("4 GHz", QVariant(4000));
2595 fClockCondFreq->addItem("5 GHz", QVariant(5000));
2596
2597 fTriggerWidget->setEnabled(false);
2598 fFtuWidget->setEnabled(false);
2599 fRatesWidget->setEnabled(false);
2600// fFadWidget->setEnabled(false);
2601 fLoggerWidget->setEnabled(false);
2602
2603 fChatSend->setEnabled(false);
2604 fChatMessage->setEnabled(false);
2605
2606 DimClient::sendCommand("CHAT/MSG", "GUI online.");
2607 // + MessageDimRX
2608
2609 // --------------------------------------------------------------------------
2610
2611 ifstream fin1("Trigger-Patches.txt");
2612
2613 int l = 0;
2614
2615 string buf;
2616 while (getline(fin1, buf, '\n'))
2617 {
2618 buf = Tools::Trim(buf);
2619 if (buf[0]=='#')
2620 continue;
2621
2622 stringstream str(buf);
2623 for (int i=0; i<9; i++)
2624 {
2625 unsigned int n;
2626 str >> n;
2627
2628 if (n>=fPatchHW.size())
2629 continue;
2630
2631 fPatchHW[n] = l;
2632 }
2633 l++;
2634 }
2635
2636 if (l!=160)
2637 cerr << "WARNING - Problems reading Trigger-Patches.txt" << endl;
2638
2639 // --------------------------------------------------------------------------
2640
2641 ifstream fin2("MasterList-v3.txt");
2642
2643 l = 0;
2644
2645 while (getline(fin2, buf, '\n'))
2646 {
2647 buf = Tools::Trim(buf);
2648 if (buf[0]=='#')
2649 continue;
2650
2651 unsigned int softid, hardid, dummy;
2652
2653 stringstream str(buf);
2654
2655 str >> softid;
2656 str >> dummy;
2657 str >> hardid;
2658
2659 if (softid>=fPixelMapHW.size())
2660 continue;
2661
2662 fPixelMapHW[softid] = hardid;
2663
2664 l++;
2665 }
2666
2667 if (l!=1440)
2668 cerr << "WARNING - Problems reading MasterList-v3.txt" << endl;
2669
2670 // --------------------------------------------------------------------------
2671
2672 ifstream fin3("PatchList.txt");
2673
2674 l = 0;
2675
2676 while (getline(fin3, buf, '\n'))
2677 {
2678 buf = Tools::Trim(buf);
2679 if (buf[0]=='#')
2680 continue;
2681
2682 unsigned int softid, hardid;
2683
2684 stringstream str(buf);
2685
2686 str >> softid;
2687 str >> hardid;
2688
2689 if (softid>=fPatchMapHW.size())
2690 continue;
2691
2692 fPatchMapHW[softid] = hardid-1;
2693
2694 l++;
2695 }
2696
2697 if (l!=160)
2698 cerr << "WARNING - Problems reading PatchList.txt" << endl;
2699
2700 // --------------------------------------------------------------------------
2701#ifdef HAVE_ROOT
2702
2703 fGraphFtmRate.SetLineColor(kBlue);
2704 fGraphFtmRate.SetMarkerColor(kBlue);
2705 fGraphFtmRate.SetMarkerStyle(kFullDotMedium);
2706
2707 for (int i=0; i<160; i++)
2708 {
2709 fGraphPatchRate[i].SetName("PatchRate");
2710 //fGraphPatchRate[i].SetLineColor(kBlue);
2711 //fGraphPatchRate[i].SetMarkerColor(kBlue);
2712 fGraphPatchRate[i].SetMarkerStyle(kFullDotMedium);
2713 }
2714 for (int i=0; i<40; i++)
2715 {
2716 fGraphBoardRate[i].SetName("BoardRate");
2717 //fGraphBoardRate[i].SetLineColor(kBlue);
2718 //fGraphBoardRate[i].SetMarkerColor(kBlue);
2719 fGraphBoardRate[i].SetMarkerStyle(kFullDotMedium);
2720 }
2721 /*
2722 TCanvas *c = fFtmTempCanv->GetCanvas();
2723 c->SetBit(TCanvas::kNoContextMenu);
2724 c->SetBorderMode(0);
2725 c->SetFrameBorderMode(0);
2726 c->SetFillColor(kWhite);
2727 c->SetRightMargin(0.03);
2728 c->SetTopMargin(0.03);
2729 c->cd();
2730 */
2731 //CreateTimeFrame("Temperature / °C");
2732
2733 fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
2734 fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
2735 fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
2736 fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
2737
2738 fGraphFtmTemp[1].SetLineColor(kBlue);
2739 fGraphFtmTemp[2].SetLineColor(kRed);
2740 fGraphFtmTemp[3].SetLineColor(kGreen);
2741
2742 fGraphFtmTemp[1].SetMarkerColor(kBlue);
2743 fGraphFtmTemp[2].SetMarkerColor(kRed);
2744 fGraphFtmTemp[3].SetMarkerColor(kGreen);
2745
2746 //fGraphFtmTemp[0].Draw("LP");
2747 //fGraphFtmTemp[1].Draw("LP");
2748 //fGraphFtmTemp[2].Draw("LP");
2749 //fGraphFtmTemp[3].Draw("LP");
2750
2751 // --------------------------------------------------------------------------
2752
2753 TCanvas *c = fFtmRateCanv->GetCanvas();
2754 //c->SetBit(TCanvas::kNoContextMenu);
2755 c->SetBorderMode(0);
2756 c->SetFrameBorderMode(0);
2757 c->SetFillColor(kWhite);
2758 c->SetRightMargin(0.03);
2759 c->SetTopMargin(0.03);
2760 c->SetGrid();
2761 c->cd();
2762
2763 DrawTimeFrame("Trigger rate [Hz]");
2764
2765 fTriggerCounter0 = -1;
2766
2767 fGraphFtmRate.SetMarkerStyle(kFullDotSmall);
2768 fGraphFtmRate.Draw("LP");
2769
2770 // --------------------------------------------------------------------------
2771
2772 c = fRatesCanv->GetCanvas();
2773 //c->SetBit(TCanvas::kNoContextMenu);
2774 c->SetBorderMode(0);
2775 c->SetFrameBorderMode(0);
2776 c->SetFillColor(kWhite);
2777 c->cd();
2778
2779 Camera *cam = new Camera;
2780 cam->SetBit(kCanDelete);
2781 cam->Draw();
2782
2783 ChoosePixel(*cam, 0);
2784
2785 // --------------------------------------------------------------------------
2786
2787 c = fAdcDataCanv->GetCanvas();
2788 //c->SetBit(TCanvas::kNoContextMenu);
2789 c->SetBorderMode(0);
2790 c->SetFrameBorderMode(0);
2791 c->SetFillColor(kWhite);
2792 c->SetGrid();
2793 c->cd();
2794
2795 // Create histogram?
2796
2797 // --------------------------------------------------------------------------
2798
2799// QTimer::singleShot(0, this, SLOT(slot_RootUpdate()));
2800
2801 //widget->setMouseTracking(true);
2802 //widget->EnableSignalEvents(kMouseMoveEvent);
2803
2804 fFtmRateCanv->setMouseTracking(true);
2805 fFtmRateCanv->EnableSignalEvents(kMouseMoveEvent);
2806
2807 fAdcDataCanv->setMouseTracking(true);
2808 fAdcDataCanv->EnableSignalEvents(kMouseMoveEvent);
2809
2810 fRatesCanv->setMouseTracking(true);
2811 fRatesCanv->EnableSignalEvents(kMouseMoveEvent|kMouseReleaseEvent|kMouseDoubleClickEvent);
2812
2813 connect(fRatesCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
2814 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
2815 connect(fFtmRateCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
2816 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
2817 connect(fAdcDataCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
2818 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
2819#endif
2820 }
2821
2822 ~FactGui()
2823 {
2824 UnsubscribeAllServers();
2825 }
2826};
2827
2828#endif
Note: See TracBrowser for help on using the repository browser.