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

Last change on this file since 10953 was 10953, checked in by tbretz, 10 years ago
Added the possibility to disable all patches/pixels except one.
File size: 66.2 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., 0.25, 0.50, 0.75, 1.00};
51 double rr[5] = {0., 0.00, 0.00, 1.00, 1.00};
52 double gg[5] = {0., 0.00, 1.00, 0.00, 1.00};
53 double bb[5] = {0., 1.00, 0.00, 0.00, 1.00};
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 void Paint(Option_t *)
177 {
178 gStyle->SetPalette(fPalette.size(), fPalette.data());
179
180
181 const double r = double(gPad->GetWw())/gPad->GetWh();
182 const double max = 20.5; // 20.5 rings in x and y
183
184 if (r>1)
185 gPad->Range(-r*max, -max, r*max, max);
186 else
187 gPad->Range(-max, -max/r, max, max/r);
188
189
190 const double min = fData.min();
191 const double scale = fData.max()==fData.min() ? 1 : fData.max()-fData.min();
192
193 TAttFill fill(0, 1001);
194 TAttLine line;
195
196 int cnt=0;
197 for (Positions::iterator p=fGeom.begin(); p!=fGeom.end(); p++, cnt++)
198 {
199 if (fBold[cnt])
200 continue;
201
202 const int col = (fData[cnt]-min)/scale*(fPalette.size()-1);
203
204 if (fEnable[cnt])
205 fill.SetFillColor(gStyle->GetColorPalette(col));
206 else
207 fill.SetFillColor(kWhite);
208
209 fill.Modify();
210
211 Paint(*p);
212 }
213
214 line.SetLineWidth(2);
215 line.Modify();
216
217 cnt = 0;
218 for (Positions::iterator p=fGeom.begin(); p!=fGeom.end(); p++, cnt++)
219 {
220 if (!fBold[cnt])
221 continue;
222
223 const int col = (fData[cnt]-min)/scale*(fPalette.size()-1);
224
225 if (fEnable[cnt])
226 fill.SetFillColor(gStyle->GetColorPalette(col));
227 else
228 fill.SetFillColor(kWhite);
229 fill.Modify();
230
231 Paint(*p);
232 }
233
234 TMarker m(0,0,kStar);
235 m.DrawMarker(0, 0);
236
237 if (fWhite<0)
238 return;
239
240 const Position &p = fGeom[fWhite];
241
242 line.SetLineColor(kWhite);
243 line.Modify();
244
245 const int col = (fData[fWhite]-min)/scale*(fPalette.size()-1);
246
247 if (fEnable[fWhite])
248 fill.SetFillColor(gStyle->GetColorPalette(col));
249 else
250 fill.SetFillColor(kWhite);
251 fill.Modify();
252
253 Paint(p);
254 }
255
256 int GetIdx(float px, float py) const
257 {
258 static const double sqrt3 = sqrt(3);
259
260 int idx = 0;
261 for (Positions::const_iterator p=fGeom.begin(); p!=fGeom.end(); p++, idx++)
262 {
263 const Double_t dy = py - p->second;
264 if (fabs(dy)>0.5)
265 continue;
266
267 const Double_t dx = px - p->first;
268
269 if (TMath::Abs(dy + dx*sqrt3) > 1)
270 continue;
271
272 if (TMath::Abs(dy - dx*sqrt3) > 1)
273 continue;
274
275 return idx;
276 }
277 return -1;
278 }
279
280 char* GetObjectInfo(Int_t px, Int_t py) const
281 {
282 static stringstream stream;
283 static string str;
284
285 const float x = gPad->PadtoX(gPad->AbsPixeltoX(px));
286 const float y = gPad->PadtoY(gPad->AbsPixeltoY(py));
287
288 const int idx = GetIdx(x, y);
289
290 stream.seekp(0);
291 if (idx>=0)
292 stream << "Pixel=" << idx << "(" <</* fMapHW[idx] <<*/ ") Data=" << fData[idx] << '\0';
293
294 str = stream.str();
295 return const_cast<char*>(str.c_str());
296 }
297
298 Int_t DistancetoPrimitive(Int_t px, Int_t py)
299 {
300 const float x = gPad->PadtoX(gPad->AbsPixeltoX(px));
301 const float y = gPad->PadtoY(gPad->AbsPixeltoY(py));
302
303 return GetIdx(x, y)>=0 ? 0 : 99999;
304 }
305
306 void SetData(const valarray<double> &data)
307 {
308 fData = data;
309 }
310};
311
312// #########################################################################
313
314
315class FactGui : public MainWindow, public DimNetwork
316{
317private:
318 class FunctionEvent : public QEvent
319 {
320 public:
321 boost::function<void(const QEvent &)> fFunction;
322
323 FunctionEvent(const boost::function<void(const QEvent &)> &f)
324 : QEvent((QEvent::Type)QEvent::registerEventType()),
325 fFunction(f) { }
326
327 bool Exec() { fFunction(*this); return true; }
328 };
329
330 valarray<int8_t> fFtuStatus;
331
332// vector<int> fMapHW; // Software -> Hardware
333// map<int,int> fMapSW; // Hardware -> Software
334
335 DimStampedInfo fDimDNS;
336
337 DimStampedInfo fDimLoggerStats;
338 DimStampedInfo fDimLoggerFilenameNight;
339 DimStampedInfo fDimLoggerFilenameRun;
340 DimStampedInfo fDimLoggerNumSubs;
341
342 DimStampedInfo fDimFtmPassport;
343 DimStampedInfo fDimFtmTriggerCounter;
344 DimStampedInfo fDimFtmError;
345 DimStampedInfo fDimFtmFtuList;
346 DimStampedInfo fDimFtmStaticData;
347 DimStampedInfo fDimFtmDynamicData;
348 DimStampedInfo fDimFtmCounter;
349
350 DimStampedInfo fDimFadFiles;
351 DimStampedInfo fDimFadRuns;
352 DimStampedInfo fDimFadEvents;
353 DimStampedInfo fDimFadCurrentEvent;
354 DimStampedInfo fDimFadConnections;
355
356 map<string, DimInfo*> fServices;
357
358 // ========================== LED Colors ================================
359
360 enum LedColor_t
361 {
362 kLedRed,
363 kLedGreen,
364 kLedYellow,
365 kLedOrange,
366 kLedGray
367 };
368
369 void SetLedColor(QPushButton *button, LedColor_t col, const Time &t)
370 {
371 switch (col)
372 {
373 case kLedRed:
374 button->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
375 break;
376
377 case kLedGreen:
378 button->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
379 break;
380
381 case kLedYellow:
382 button->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
383 break;
384
385 case kLedOrange:
386 button->setIcon(QIcon(":/Resources/icons/orange circle 1.png"));
387 break;
388
389 case kLedGray:
390 button->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
391 break;
392 }
393
394 //button->setToolTip("Last change: "+QDateTime::currentDateTimeUtc().toString()+" UTC");
395 button->setToolTip(("Last change: "+t.GetAsStr()+" UTC").c_str());
396 }
397
398 // ===================== Services and Commands ==========================
399
400 QStandardItem *AddServiceItem(const std::string &server, const std::string &service, bool iscmd)
401 {
402 QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
403 QListView *services = iscmd ? fDimCmdCommands : fDimSvcServices;
404 QListView *description = iscmd ? fDimCmdDescription : fDimSvcDescription;
405
406 QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
407 if (!m)
408 {
409 m = new QStandardItemModel(this);
410 servers->setModel(m);
411 services->setModel(m);
412 description->setModel(m);
413 }
414
415 QList<QStandardItem*> l = m->findItems(server.c_str());
416
417 if (l.size()>1)
418 {
419 cout << "hae" << endl;
420 return 0;
421 }
422
423 QStandardItem *col = l.size()==0 ? NULL : l[0];
424
425 if (!col)
426 {
427 col = new QStandardItem(server.c_str());
428 m->appendRow(col);
429
430 if (!services->rootIndex().isValid())
431 {
432 services->setRootIndex(col->index());
433 servers->setCurrentIndex(col->index());
434 }
435 }
436
437 QStandardItem *item = 0;
438 for (int i=0; i<col->rowCount(); i++)
439 {
440 QStandardItem *coli = col->child(i);
441 if (coli->text().toStdString()==service)
442 return coli;
443 }
444
445 item = new QStandardItem(service.c_str());
446 col->appendRow(item);
447 col->sortChildren(0);
448
449 if (!description->rootIndex().isValid())
450 {
451 description->setRootIndex(item->index());
452 services->setCurrentIndex(item->index());
453 }
454
455 if (!iscmd)
456 item->setCheckable(true);
457
458 return item;
459 }
460
461 void AddDescription(QStandardItem *item, const vector<Description> &vec)
462 {
463 if (!item)
464 return;
465 if (vec.size()==0)
466 return;
467
468 item->setToolTip(vec[0].comment.c_str());
469
470 const string str = Description::GetHtmlDescription(vec);
471
472 QStandardItem *desc = new QStandardItem(str.c_str());
473 desc->setSelectable(false);
474 item->setChild(0, 0, desc);
475 }
476
477 void AddServer(const std::string &s)
478 {
479 DimNetwork::AddServer(s);
480
481 QApplication::postEvent(this,
482 new FunctionEvent(boost::bind(&FactGui::handleAddServer, this, s)));
483 }
484
485 void RemoveServer(const std::string &s)
486 {
487 UnsubscribeServer(s);
488
489 DimNetwork::RemoveServer(s);
490
491 QApplication::postEvent(this,
492 new FunctionEvent(boost::bind(&FactGui::handleRemoveServer, this, s)));
493 }
494
495 void RemoveAllServers()
496 {
497 UnsubscribeAllServers();
498
499 vector<string> v = GetServerList();
500 for (vector<string>::iterator i=v.begin(); i<v.end(); i++)
501 QApplication::postEvent(this,
502 new FunctionEvent(boost::bind(&FactGui::handleStateOffline, this, *i)));
503
504 DimNetwork::RemoveAllServers();
505
506 QApplication::postEvent(this,
507 new FunctionEvent(boost::bind(&FactGui::handleRemoveAllServers, this)));
508 }
509
510 void AddService(const std::string &server, const std::string &service, const std::string &fmt, bool iscmd)
511 {
512 QApplication::postEvent(this,
513 new FunctionEvent(boost::bind(&FactGui::handleAddService, this, server, service, fmt, iscmd)));
514 }
515
516 void RemoveService(const std::string &server, const std::string &service, bool iscmd)
517 {
518 if (fServices.find(server+'/'+service)!=fServices.end())
519 UnsubscribeService(server+'/'+service);
520
521 QApplication::postEvent(this,
522 new FunctionEvent(boost::bind(&FactGui::handleRemoveService, this, server, service, iscmd)));
523 }
524
525 void RemoveAllServices(const std::string &server)
526 {
527 UnsubscribeServer(server);
528
529 QApplication::postEvent(this,
530 new FunctionEvent(boost::bind(&FactGui::handleRemoveAllServices, this, server)));
531 }
532
533 void AddDescription(const std::string &server, const std::string &service, const vector<Description> &vec)
534 {
535 QApplication::postEvent(this,
536 new FunctionEvent(boost::bind(&FactGui::handleAddDescription, this, server, service, vec)));
537 }
538
539 // ======================================================================
540
541 void handleAddServer(const std::string &server)
542 {
543 const State s = GetState(server, GetCurrentState(server));
544 handleStateChanged(Time(), server, s);
545 }
546
547 void handleRemoveServer(const string &server)
548 {
549 handleStateOffline(server);
550 handleRemoveAllServices(server);
551 }
552
553 void handleRemoveAllServers()
554 {
555 QStandardItemModel *m = 0;
556 if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
557 m->removeRows(0, m->rowCount());
558
559 if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
560 m->removeRows(0, m->rowCount());
561 }
562
563 void handleAddService(const std::string &server, const std::string &service, const std::string &/*fmt*/, bool iscmd)
564 {
565 QStandardItem *item = AddServiceItem(server, service, iscmd);
566 const vector<Description> v = GetDescription(server, service);
567 AddDescription(item, v);
568 }
569
570 void handleRemoveService(const std::string &server, const std::string &service, bool iscmd)
571 {
572 QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
573
574 QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
575 if (!m)
576 return;
577
578 QList<QStandardItem*> l = m->findItems(server.c_str());
579 if (l.size()!=1)
580 return;
581
582 for (int i=0; i<l[0]->rowCount(); i++)
583 {
584 QStandardItem *row = l[0]->child(i);
585 if (row->text().toStdString()==service)
586 {
587 l[0]->removeRow(row->index().row());
588 return;
589 }
590 }
591 }
592
593 void handleRemoveAllServices(const std::string &server)
594 {
595 QStandardItemModel *m = 0;
596 if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
597 {
598 QList<QStandardItem*> l = m->findItems(server.c_str());
599 if (l.size()==1)
600 m->removeRow(l[0]->index().row());
601 }
602
603 if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
604 {
605 QList<QStandardItem*> l = m->findItems(server.c_str());
606 if (l.size()==1)
607 m->removeRow(l[0]->index().row());
608 }
609 }
610
611 void handleAddDescription(const std::string &server, const std::string &service, const vector<Description> &vec)
612 {
613 const bool iscmd = IsCommand(server, service)==true;
614
615 QStandardItem *item = AddServiceItem(server, service, iscmd);
616 AddDescription(item, vec);
617 }
618
619 // ======================================================================
620
621 void SubscribeService(const string &service)
622 {
623 if (fServices.find(service)!=fServices.end())
624 {
625 cout << "ERROR - We are already subscribed to " << service << endl;
626 return;
627 }
628
629 fServices[service] = new DimStampedInfo(service.c_str(), (void*)NULL, 0, this);
630 }
631
632 void UnsubscribeService(const string &service)
633 {
634 const map<string,DimInfo*>::iterator i=fServices.find(service);
635
636 if (i==fServices.end())
637 {
638 cout << "ERROR - We are not subscribed to " << service << endl;
639 return;
640 }
641
642 delete i->second;
643
644 fServices.erase(i);
645 }
646
647 void UnsubscribeServer(const string &server)
648 {
649 for (map<string,DimInfo*>::iterator i=fServices.begin();
650 i!=fServices.end(); i++)
651 if (i->first.substr(0, server.length()+1)==server+'/')
652 {
653 delete i->second;
654 fServices.erase(i);
655 }
656 }
657
658 void UnsubscribeAllServers()
659 {
660 for (map<string,DimInfo*>::iterator i=fServices.begin();
661 i!=fServices.end(); i++)
662 delete i->second;
663
664 fServices.clear();
665 }
666
667 // ======================================================================
668
669 struct DimData
670 {
671 Time time;
672 int qos;
673 string name;
674 string format;
675 vector<char> data;
676
677 DimInfo *info; // this is ONLY for a fast check of the type of the DimData!!
678
679 DimData(DimInfo *inf) :
680 qos(inf->getQuality()),
681 name(inf->getName()),
682 format(inf->getFormat()),
683 data(inf->getString(), inf->getString()+inf->getSize()),
684 info(inf)
685 {
686 // Must be called in exactly this order!
687 const int tsec = inf->getTimestamp();
688 const int tms = inf->getTimestampMillisecs();
689
690 time = Time(tsec, tms*1000);
691 }
692
693 template<typename T>
694 T get(uint32_t offset=0) const { return *reinterpret_cast<const T*>(data.data()+offset); }
695
696 template<typename T>
697 const T *ptr(uint32_t offset=0) const { return reinterpret_cast<const T*>(data.data()+offset); }
698
699 template<typename T>
700 const T &ref(uint32_t offset=0) const { return *reinterpret_cast<const T*>(data.data()+offset); }
701
702 vector<char> vec(int b) const { return vector<char>(data.begin()+b, data.end()); }
703 string str(unsigned int b) const { return b>=data.size()?string():string(data.data()+b, data.size()-b); }
704 const char *c_str() const { return (char*)data.data(); }
705
706 vector<boost::any> any() const
707 {
708 const Converter conv(format);
709 conv.Print();
710 return conv.GetAny(data.data(), data.size());
711 }
712 int size() const { return data.size(); }
713 };
714
715 // ======================= DNS ==========================================
716
717 void handleDimDNS(const DimData &d)
718 {
719 const int version = d.get<unsigned int>();
720
721 ostringstream str;
722 str << "V" << version/100 << 'r' << version%100;
723
724 SetLedColor(fStatusDNSLed, version==0 ? kLedRed : kLedGreen, Time());
725
726 fStatusDNSLabel->setText(version==0?"Offline":str.str().c_str());
727 fStatusDNSLabel->setToolTip(version==0?"No connection to DIM DNS.":"Connection to DIM DNS established.");
728 }
729
730
731 // ======================= Logger =======================================
732
733 void handleLoggerStats(const DimData &d)
734 {
735 const bool connected = d.size()!=0;
736
737 fLoggerET->setEnabled(connected);
738 fLoggerRate->setEnabled(connected);
739 fLoggerWritten->setEnabled(connected);
740 fLoggerFreeSpace->setEnabled(connected);
741 fLoggerSpaceLeft->setEnabled(connected);
742
743 if (!connected)
744 return;
745
746 const uint64_t *vals = d.ptr<uint64_t>();
747
748 const size_t written = vals[0];
749 const size_t space = vals[1];
750 const size_t rate = vals[2];
751
752 fLoggerFreeSpace->setSuffix(" MB");
753 fLoggerFreeSpace->setDecimals(0);
754 fLoggerFreeSpace->setValue(space*1e-6);
755
756 if (space> 1000000) // > 1GB
757 {
758 fLoggerFreeSpace->setSuffix(" GB");
759 fLoggerFreeSpace->setDecimals(2);
760 fLoggerFreeSpace->setValue(space*1e-9);
761 }
762 if (space>= 3000000) // >= 3GB
763 {
764 fLoggerFreeSpace->setSuffix(" GB");
765 fLoggerFreeSpace->setDecimals(1);
766 fLoggerFreeSpace->setValue(space*1e-9);
767 }
768 if (space>=100000000) // >= 100GB
769 {
770 fLoggerFreeSpace->setSuffix(" GB");
771 fLoggerFreeSpace->setDecimals(0);
772 fLoggerFreeSpace->setValue(space*1e-9);
773 }
774
775 fLoggerET->setTime(QTime().addSecs(rate>0?space/rate:0));
776 fLoggerRate->setValue(rate*1e-3); // kB/s
777 fLoggerWritten->setValue(written*1e-6);
778
779 fLoggerRate->setSuffix(" kB/s");
780 fLoggerRate->setDecimals(2);
781 fLoggerRate->setValue(rate*1e-3);
782 if (rate> 2000) // > 2kB/s
783 {
784 fLoggerRate->setSuffix(" kB/s");
785 fLoggerRate->setDecimals(1);
786 fLoggerRate->setValue(rate*1e-3);
787 }
788 if (rate>=100000) // >100kB/s
789 {
790 fLoggerRate->setSuffix(" kB/s");
791 fLoggerRate->setDecimals(0);
792 fLoggerRate->setValue(rate*1e-3);
793 }
794 if (rate>=1000000) // >100kB/s
795 {
796 fLoggerRate->setSuffix(" MB/s");
797 fLoggerRate->setDecimals(2);
798 fLoggerRate->setValue(rate*1e-6);
799 }
800 if (rate>=10000000) // >1MB/s
801 {
802 fLoggerRate->setSuffix(" MB/s");
803 fLoggerRate->setDecimals(1);
804 fLoggerRate->setValue(rate*1e-6);
805 }
806 if (rate>=100000000) // >10MB/s
807 {
808 fLoggerRate->setSuffix(" MB/s");
809 fLoggerRate->setDecimals(0);
810 fLoggerRate->setValue(rate*1e-6);
811 }
812
813 if (space/1000000>static_cast<size_t>(fLoggerSpaceLeft->maximum()))
814 fLoggerSpaceLeft->setValue(fLoggerSpaceLeft->maximum()); // GB
815 else
816 fLoggerSpaceLeft->setValue(space/1000000); // MB
817 }
818
819 void handleLoggerFilenameNight(const DimData &d)
820 {
821 const bool connected = d.size()!=0;
822
823 fLoggerFilenameNight->setEnabled(connected);
824 if (!connected)
825 return;
826
827 fLoggerFilenameNight->setText(d.c_str()+4);
828
829 const uint32_t files = d.get<uint32_t>();
830
831 SetLedColor(fLoggerLedLog, files&1 ? kLedGreen : kLedGray, d.time);
832 SetLedColor(fLoggerLedRep, files&2 ? kLedGreen : kLedGray, d.time);
833 SetLedColor(fLoggerLedFits, files&4 ? kLedGreen : kLedGray, d.time);
834 }
835
836 void handleLoggerFilenameRun(const DimData &d)
837 {
838 const bool connected = d.size()!=0;
839
840 fLoggerFilenameRun->setEnabled(connected);
841 if (!connected)
842 return;
843
844 fLoggerFilenameRun->setText(d.c_str()+4);
845
846 const uint32_t files = d.get<uint32_t>();
847
848 SetLedColor(fLoggerLedLog, files&1 ? kLedGreen : kLedGray, d.time);
849 SetLedColor(fLoggerLedRep, files&2 ? kLedGreen : kLedGray, d.time);
850 SetLedColor(fLoggerLedFits, files&4 ? kLedGreen : kLedGray, d.time);
851 }
852
853 void handleLoggerNumSubs(const DimData &d)
854 {
855 const bool connected = d.size()!=0;
856
857 fLoggerSubscriptions->setEnabled(connected);
858 fLoggerOpenFiles->setEnabled(connected);
859 if (!connected)
860 return;
861
862 const uint32_t *vals = d.ptr<uint32_t>();
863
864 fLoggerSubscriptions->setValue(vals[0]);
865 fLoggerOpenFiles->setValue(vals[1]);
866 }
867
868 // ===================== FAD ============================================
869
870 void handleFadFiles(const DimData &d)
871 {
872 if (d.size()==0)
873 return;
874
875 if (d.size()!=8)
876 {
877 cout << "Size mismatch: " << d.size() << " " << 8 << endl;
878 return;
879 }
880
881 fEvtBuilderOpenFiles->setValue(d.get<uint64_t>());
882 }
883
884 void handleFadRuns(const DimData &d)
885 {
886 if (d.size()==0)
887 return;
888
889 if (d.size()!=4)
890 {
891 cout << "Size mismatch: " << d.size() << " " << 8 << endl;
892 return;
893 }
894
895 fEvtsRunMax->setValue(d.get<uint32_t>());
896 }
897
898 void handleFadEvents(const DimData &d)
899 {
900 if (d.size()==0)
901 return;
902
903 if (d.size()!=8)
904 {
905 cout << "Size mismatch: " << d.size() << " " << 8 << endl;
906 return;
907 }
908
909 const uint32_t *ptr = d.ptr<uint32_t>();
910
911 fEvtsSuccessCurRun->setValue(ptr[0]);
912 fEvtsSuccessTotal->setValue(ptr[1]);
913 }
914
915 void handleFadCurrentEvent(const DimData &d)
916 {
917 if (d.size()==0)
918 return;
919
920 if (d.size()!=4)
921 {
922 cout << "Size mismatch: " << d.size() << " " << 4 << endl;
923 return;
924 }
925
926 fEvtsTriggerId->setValue(d.get<uint32_t>());
927 }
928
929 void handleFadConnections(const DimData &d)
930 {
931 if (d.size()==0)
932 return;
933
934 if (d.size()!=40)
935 {
936 cout << "Size mismatch: " << d.size() << " " << 40 << endl;
937 return;
938 }
939
940 const uint8_t *ptr = d.ptr<uint8_t>();
941
942 for (int i=0; i<40; i++)
943 {
944 switch (ptr[i])
945 {
946 case 0: SetLedColor(fFadLED[i], kLedGray, d.time); break;
947 case 9: SetLedColor(fFadLED[i], kLedGreen, d.time); break;
948 default: SetLedColor(fFadLED[i], kLedOrange, d.time);
949 }
950 }
951 }
952
953 // ===================== FTM ============================================
954
955 double fTimeStamp1;
956
957 void handleFtmTriggerCounter(const DimData &d)
958 {
959 if (d.size()==0)
960 return;
961
962 if (d.size()!=sizeof(FTM::DimTriggerCounter))
963 {
964 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimTriggerCounter) << endl;
965 return;
966 }
967
968 const FTM::DimTriggerCounter &sdata = d.ref<FTM::DimTriggerCounter>();
969
970 fFtmTime->setText(QString::number(sdata.fTimeStamp/1000000., 'f', 6)+ " s");
971 fTriggerCounter->setText(QString::number(sdata.fTriggerCounter));
972
973 if (sdata.fTimeStamp>0)
974 fTriggerCounterRate->setValue(1000000.*sdata.fTriggerCounter/sdata.fTimeStamp);
975 else
976 fTriggerCounterRate->setValue(0);
977
978
979 // ----------------------------------------------
980#ifdef HAVE_ROOT
981
982 if (fTriggerCounter0<0)
983 {
984 fTriggerCounter0 = sdata.fTriggerCounter;
985 fTimeStamp1 = sdata.fTimeStamp;
986 return;
987 }
988
989 TCanvas *c = fFtmRateCanv->GetCanvas();
990
991 TH1 *h = (TH1*)c->FindObject("TimeFrame");
992
993 const double rate = sdata.fTriggerCounter-fTriggerCounter0;
994 const double tdiff = sdata.fTimeStamp -fTimeStamp1;
995
996 fTriggerCounter0 = sdata.fTriggerCounter;
997 fTimeStamp1 = sdata.fTimeStamp;
998
999 if (rate<0 && tdiff<=0)
1000 {
1001 fGraphFtmRate.Set(0);
1002
1003 const double tm = Time().RootTime();
1004
1005 h->SetBins(1, tm, tm+60);
1006 h->GetXaxis()->SetTimeFormat("%M'%S\"");
1007 h->GetXaxis()->SetTitle("Time");
1008
1009 c->Modified();
1010 c->Update();
1011 return;
1012 }
1013
1014 if (rate<0)
1015 return;
1016
1017 const double avgrate = sdata.fTimeStamp>0 ? double(sdata.fTriggerCounter)/sdata.fTimeStamp*1000000 : 1;
1018
1019 const double t1 = h->GetXaxis()->GetXmax();
1020 const double t0 = h->GetXaxis()->GetXmin();
1021
1022 h->SetBins(h->GetNbinsX()+1, t0, t0+sdata.fTimeStamp/1000000.+1);
1023 fGraphFtmRate.SetPoint(fGraphFtmRate.GetN(),
1024 t0+sdata.fTimeStamp/1000000., 1000000*rate/tdiff);
1025
1026 if (t1-t0>60)
1027 {
1028 h->GetXaxis()->SetTimeFormat("%Hh%M'");
1029 h->GetXaxis()->SetTitle("Time");
1030 }
1031
1032 h->SetMinimum(0);
1033 h->SetMaximum(2*avgrate);
1034
1035 c->Modified();
1036 c->Update();
1037#endif
1038 // ----------------------------------------------
1039 }
1040
1041 void handleFtmCounter(const DimData &d)
1042 {
1043 if (d.size()==0)
1044 return;
1045
1046 if (d.size()!=sizeof(uint32_t)*6)
1047 {
1048 cout << "Size mismatch: " << d.size() << " " << sizeof(uint32_t)*6 << endl;
1049 return;
1050 }
1051
1052 const uint32_t *sdata = d.ptr<uint32_t>();
1053
1054 fFtmCounterH->setValue(sdata[0]);
1055 fFtmCounterS->setValue(sdata[1]);
1056 fFtmCounterD->setValue(sdata[2]);
1057 fFtmCounterF->setValue(sdata[3]);
1058 fFtmCounterE->setValue(sdata[4]);
1059 fFtmCounterR->setValue(sdata[5]);
1060 }
1061
1062 int64_t fTriggerCounter0;
1063 int64_t fTimeStamp0;
1064
1065 void handleFtmDynamicData(const DimData &d)
1066 {
1067 if (d.size()==0)
1068 return;
1069
1070 if (d.size()!=sizeof(FTM::DimDynamicData))
1071 {
1072 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimDynamicData) << endl;
1073 return;
1074 }
1075
1076 const FTM::DimDynamicData &sdata = d.ref<FTM::DimDynamicData>();
1077
1078 fOnTime->setText(QString::number(sdata.fOnTimeCounter/1000000., 'f', 6)+" s");
1079
1080 if (sdata.fTimeStamp>0)
1081 fOnTimeRel->setValue(100.*sdata.fOnTimeCounter/sdata.fTimeStamp);
1082 else
1083 fOnTimeRel->setValue(0);
1084
1085 fFtmTemp0->setValue(sdata.fTempSensor[0]*0.1);
1086 fFtmTemp1->setValue(sdata.fTempSensor[1]*0.1);
1087 fFtmTemp2->setValue(sdata.fTempSensor[2]*0.1);
1088 fFtmTemp3->setValue(sdata.fTempSensor[3]*0.1);
1089
1090
1091#ifdef HAVE_ROOT
1092
1093 // ----------------------------------------------
1094/*
1095 TCanvas *c = fFtmTempCanv->GetCanvas();
1096
1097// static int cntr = 0;
1098// double_t tm = cntr++;//Time().RootTime();
1099
1100 double tm = d.time.RootTime();
1101
1102 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1103 h->FindBin(tm);
1104
1105 fGraphFtmTemp[0].SetPoint(fGraphFtmTemp[0].GetN(), tm, sdata.fTempSensor[0]*0.1);
1106 fGraphFtmTemp[1].SetPoint(fGraphFtmTemp[1].GetN(), tm, sdata.fTempSensor[1]*0.1);
1107 fGraphFtmTemp[2].SetPoint(fGraphFtmTemp[2].GetN(), tm, sdata.fTempSensor[2]*0.1);
1108 fGraphFtmTemp[3].SetPoint(fGraphFtmTemp[3].GetN(), tm, sdata.fTempSensor[3]*0.1);
1109
1110 c->Modified();
1111 c->Update();
1112*/
1113 // ----------------------------------------------
1114
1115 if (fTimeStamp0<0)
1116 {
1117 fTimeStamp0 = sdata.fTimeStamp;
1118 return;
1119 }
1120
1121 TCanvas *c = fFtmRateCanv->GetCanvas();
1122
1123 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1124
1125 const double tdiff = sdata.fTimeStamp-fTimeStamp0;
1126 fTimeStamp0 = sdata.fTimeStamp;
1127
1128 if (tdiff<0)
1129 {
1130 for (int i=0; i<160; i++)
1131 fGraphPatchRate[i].Set(0);
1132 for (int i=0; i<40; i++)
1133 fGraphBoardRate[i].Set(0);
1134
1135 return;
1136 }
1137
1138 //const double t1 = h->GetXaxis()->GetXmax();
1139 const double t0 = h->GetXaxis()->GetXmin();
1140
1141 for (int i=0; i<160; i++)
1142 fGraphPatchRate[i].SetPoint(fGraphPatchRate[i].GetN(),
1143 t0+sdata.fTimeStamp, float(sdata.fRatePatch[i])/fFtmStaticData.fPrescaling[i]/1000);
1144 for (int i=0; i<40; i++)
1145 fGraphBoardRate[i].SetPoint(fGraphBoardRate[i].GetN(),
1146 t0+sdata.fTimeStamp, float(sdata.fRateBoard[i])/fFtmStaticData.fPrescaling[i]/1000);
1147
1148 c->Modified();
1149 c->Update();
1150
1151 // ----------------------------------------------
1152
1153 if (fThresholdIdx->value()>=0)
1154 fPatchRate->setValue(sdata.fRatePatch[fThresholdIdx->value()]);
1155
1156 valarray<double> dat(0., 1440);
1157
1158 for (int i=0; i<1440; i++)
1159 dat[i] = sdata.fRatePatch[fPatch[i]];
1160
1161 c = fRatesCanv->GetCanvas();
1162 Camera *cam = (Camera*)c->FindObject("Camera");
1163
1164 cam->SetData(dat);
1165
1166 c->Modified();
1167 c->Update();
1168#endif
1169 }
1170
1171 void DisplayRates()
1172 {
1173#ifdef HAVE_ROOT
1174 TCanvas *c = fFtmRateCanv->GetCanvas();
1175
1176 while (c->FindObject("PatchRate"))
1177 c->GetListOfPrimitives()->Remove(c->FindObject("PatchRate"));
1178
1179 while (c->FindObject("BoardRate"))
1180 c->GetListOfPrimitives()->Remove(c->FindObject("BoardRate"));
1181
1182 if (fRatePatch1->value()>=0)
1183 fGraphPatchRate[fRatePatch1->value()].Draw("PL");
1184 if (fRatePatch2->value()>=0)
1185 fGraphPatchRate[fRatePatch2->value()].Draw("PL");
1186 if (fRateBoard1->value()>=0)
1187 fGraphBoardRate[fRateBoard1->value()].Draw("PL");
1188 if (fRateBoard2->value()>=0)
1189 fGraphBoardRate[fRateBoard2->value()].Draw("PL");
1190#endif
1191 }
1192
1193 void on_fRatePatch1_valueChanged(int)
1194 {
1195 DisplayRates();
1196 }
1197
1198 void on_fRatePatch2_valueChanged(int)
1199 {
1200 DisplayRates();
1201 }
1202
1203 void on_fRateBoard1_valueChanged(int)
1204 {
1205 DisplayRates();
1206 }
1207
1208 void on_fRateBoard2_valueChanged(int)
1209 {
1210 DisplayRates();
1211 }
1212
1213 FTM::DimStaticData fFtmStaticData;
1214
1215 void SetFtuLed(int idx, int counter, const Time &t)
1216 {
1217 if (counter==0 || counter>3)
1218 counter = 3;
1219
1220 if (counter<0)
1221 counter = 0;
1222
1223 const LedColor_t col[4] = { kLedGray, kLedGreen, kLedOrange, kLedRed };
1224
1225 SetLedColor(fFtuLED[idx], col[counter], t);
1226
1227 fFtuStatus[idx] = counter;
1228 }
1229
1230 void SetFtuStatusLed(const Time &t)
1231 {
1232 const int max = fFtuStatus.max();
1233
1234 switch (max)
1235 {
1236 case 0:
1237 SetLedColor(fStatusFTULed, kLedGray, t);
1238 fStatusFTULabel->setText("All disabled");
1239 fStatusFTULabel->setToolTip("All FTUs are disabled");
1240 break;
1241
1242 case 1:
1243 SetLedColor(fStatusFTULed, kLedGreen, t);
1244 fStatusFTULabel->setToolTip("Communication with FTU is smooth.");
1245 fStatusFTULabel->setText("ok");
1246 break;
1247
1248 case 2:
1249 SetLedColor(fStatusFTULed, kLedOrange, t);
1250 fStatusFTULabel->setText("Warning");
1251 fStatusFTULabel->setToolTip("At least one FTU didn't answer immediately");
1252 break;
1253
1254 case 3:
1255 SetLedColor(fStatusFTULed, kLedRed, t);
1256 fStatusFTULabel->setToolTip("At least one FTU didn't answer!");
1257 fStatusFTULabel->setText("ERROR");
1258 break;
1259 }
1260
1261 const int cnt = count(&fFtuStatus[0], &fFtuStatus[40], 0);
1262 fFtuAllOn->setEnabled(cnt!=0);
1263 fFtuAllOff->setEnabled(cnt!=40);
1264 }
1265
1266 void handleFtmStaticData(const DimData &d)
1267 {
1268 if (d.size()==0)
1269 return;
1270
1271 if (d.size()!=sizeof(FTM::DimStaticData))
1272 {
1273 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimStaticData) << endl;
1274 return;
1275 }
1276
1277 const FTM::DimStaticData &sdata = d.ref<FTM::DimStaticData>();
1278
1279 fTriggerInterval->setValue(sdata.fTriggerInterval);
1280 fPhysicsCoincidence->setValue(sdata.fMultiplicityPhysics);
1281 fCalibCoincidence->setValue(sdata.fMultiplicityCalib);
1282 fPhysicsWindow->setValue(sdata.fWindowPhysics);
1283 fCalibWindow->setValue(sdata.fWindowCalib);
1284
1285 fTriggerDelay->setValue(sdata.fDelayTrigger);
1286 fTimeMarkerDelay->setValue(sdata.fDelayTimeMarker);
1287 fDeadTime->setValue(sdata.fDeadTime);
1288
1289 fClockCondR0->setValue(sdata.fClockConditioner[0]);
1290 fClockCondR1->setValue(sdata.fClockConditioner[1]);
1291 fClockCondR8->setValue(sdata.fClockConditioner[2]);
1292 fClockCondR9->setValue(sdata.fClockConditioner[3]);
1293 fClockCondR11->setValue(sdata.fClockConditioner[4]);
1294 fClockCondR13->setValue(sdata.fClockConditioner[5]);
1295 fClockCondR14->setValue(sdata.fClockConditioner[6]);
1296 fClockCondR15->setValue(sdata.fClockConditioner[7]);
1297
1298 fTriggerSeqPed->setValue(sdata.fTriggerSeqPed);
1299 fTriggerSeqLPint->setValue(sdata.fTriggerSeqLPint);
1300 fTriggerSeqLPext->setValue(sdata.fTriggerSeqLPext);
1301
1302 fEnableTrigger->setChecked(sdata.HasTrigger());
1303 fEnableVeto->setChecked(sdata.HasVeto());
1304 fEnableExt1->setChecked(sdata.HasExt1());
1305 fEnableExt2->setChecked(sdata.HasExt2());
1306 fEnableClockCond->setChecked(sdata.HasClockConditioner());
1307
1308 for (int i=0; i<40; i++)
1309 {
1310 if (!sdata.IsActive(i))
1311 SetFtuLed(i, -1, d.time);
1312 else
1313 {
1314 if (fFtuStatus[i]==0)
1315 SetFtuLed(i, 1, d.time);
1316 }
1317 fFtuLED[i]->setChecked(false);
1318 }
1319 SetFtuStatusLed(d.time);
1320
1321#ifdef HAVE_ROOT
1322 Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
1323 for (int i=0; i<1440; i++)
1324 cam->SetEnable(i, sdata.IsEnabled(i));
1325
1326 fRatesCanv->GetCanvas()->Modified();
1327 fRatesCanv->GetCanvas()->Update();
1328#endif
1329
1330 fPixelEnable->setChecked(sdata.IsEnabled(fPixelIdx->value()));
1331
1332
1333
1334 const int patch1 = fThresholdIdx->value();
1335 if (patch1>=0)
1336 fThresholdVal->setValue(sdata.fThreshold[patch1]);
1337
1338 fPrescalingVal->setValue(sdata.fPrescaling[0]);
1339
1340 fFtmStaticData = sdata;
1341 }
1342
1343 void handleFtmPassport(const DimData &d)
1344 {
1345 if (d.size()==0)
1346 return;
1347
1348 if (d.size()!=sizeof(FTM::DimPassport))
1349 {
1350 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimPassport) << endl;
1351 return;
1352 }
1353
1354 const FTM::DimPassport &sdata = d.ref<FTM::DimPassport>();
1355
1356 stringstream str1, str2;
1357 str1 << hex << "0x" << setfill('0') << setw(16) << sdata.fBoardId;
1358 str2 << sdata.fFirmwareId;
1359
1360 fFtmBoardId->setText(str1.str().c_str());
1361 fFtmFirmwareId->setText(str2.str().c_str());
1362 }
1363
1364 void handleFtmFtuList(const DimData &d)
1365 {
1366 if (d.size()==0)
1367 return;
1368
1369 if (d.size()!=sizeof(FTM::DimFtuList))
1370 {
1371 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimFtuList) << endl;
1372 return;
1373 }
1374
1375 fFtuPing->setChecked(false);
1376
1377 const FTM::DimFtuList &sdata = d.ref<FTM::DimFtuList>();
1378
1379 stringstream str;
1380 str << "<table width='100%'>" << setfill('0');
1381 str << "<tr><th>Num</th><th></th><th>Addr</th><th></th><th>DNA</th></tr>";
1382 for (int i=0; i<40; i++)
1383 {
1384 str << "<tr>";
1385 str << "<td align='center'>" << dec << i << hex << "</td>";
1386 str << "<td align='center'>:</td>";
1387 str << "<td align='center'>0x" << setw(2) << (int)sdata.fAddr[i] << "</td>";
1388 str << "<td align='center'>:</td>";
1389 str << "<td align='center'>0x" << setw(16) << sdata.fDNA[i] << "</td>";
1390 str << "</tr>";
1391 }
1392 str << "</table>";
1393
1394 fFtuDNA->setText(str.str().c_str());
1395
1396 fFtuAnswersTotal->setValue(sdata.fNumBoards);
1397 fFtuAnswersCrate0->setValue(sdata.fNumBoardsCrate[0]);
1398 fFtuAnswersCrate1->setValue(sdata.fNumBoardsCrate[1]);
1399 fFtuAnswersCrate2->setValue(sdata.fNumBoardsCrate[2]);
1400 fFtuAnswersCrate3->setValue(sdata.fNumBoardsCrate[3]);
1401
1402 for (int i=0; i<40; i++)
1403 SetFtuLed(i, sdata.IsActive(i) ? sdata.fPing[i] : -1, d.time);
1404
1405 SetFtuStatusLed(d.time);
1406 }
1407
1408 void handleFtmError(const DimData &d)
1409 {
1410 if (d.size()==0)
1411 return;
1412
1413 const FTM::DimError &sdata = d.ref<FTM::DimError>();
1414
1415 SetFtuLed(sdata.fError.fDestAddress , sdata.fError.fNumCalls, d.time);
1416 SetFtuStatusLed(d.time);
1417
1418 // FIXME: Write to special window!
1419 //Out() << "Error:" << endl;
1420 //Out() << sdata.fError << endl;
1421 }
1422
1423 // ====================== MessageImp ====================================
1424
1425 bool fChatOnline;
1426
1427 void handleStateChanged(const Time &time, const std::string &server,
1428 const State &s)
1429 {
1430 // FIXME: Prefix tooltip with time
1431 if (server=="FTM_CONTROL")
1432 {
1433 fStatusFTMLabel->setText(s.name.c_str());
1434 fStatusFTMLabel->setToolTip(s.comment.c_str());
1435
1436 bool enable = false;
1437
1438 if (s.index<FTM::kDisconnected) // No Dim connection
1439 SetLedColor(fStatusFTMLed, kLedGray, time);
1440 if (s.index==FTM::kDisconnected) // Dim connection / FTM disconnected
1441 SetLedColor(fStatusFTMLed, kLedYellow, time);
1442 if (s.index==FTM::kConnected || s.index==FTM::kIdle || s.index==FTM::kTakingData) // Dim connection / FTM connected
1443 SetLedColor(fStatusFTMLed, kLedGreen, time);
1444
1445 if (s.index==FTM::kConnected || s.index==FTM::kIdle) // Dim connection / FTM connected
1446 enable = true;
1447
1448 fTriggerWidget->setEnabled(enable);
1449 fFtuWidget->setEnabled(enable);
1450 fRatesWidget->setEnabled(enable);
1451
1452 if (!enable)
1453 {
1454 SetLedColor(fStatusFTULed, kLedGray, time);
1455 fStatusFTULabel->setText("Offline");
1456 fStatusFTULabel->setToolTip("FTM is not online.");
1457 }
1458 }
1459
1460 if (server=="FAD_CONTROL")
1461 {
1462 fStatusFADLabel->setText(s.name.c_str());
1463 fStatusFADLabel->setToolTip(s.comment.c_str());
1464
1465 bool enable = false;
1466
1467 if (s.index<FAD::kDisconnected) // No Dim connection
1468 SetLedColor(fStatusFADLed, kLedGray, time);
1469 if (s.index==FAD::kOffline) // Dim connection / FTM disconnected
1470 SetLedColor(fStatusFADLed, kLedRed, time);
1471 if (s.index==FAD::kDisconnected) // Dim connection / FTM disconnected
1472 SetLedColor(fStatusFADLed, kLedOrange, time);
1473 if (s.index==FAD::kConnecting) // Dim connection / FTM disconnected
1474 SetLedColor(fStatusFADLed, kLedYellow, time);
1475 if (s.index>=FAD::kConnected) // Dim connection / FTM connected
1476 {
1477 SetLedColor(fStatusFADLed, kLedGreen, time);
1478 enable = true;
1479 }
1480
1481 fFadWidget->setEnabled(enable);
1482 }
1483
1484 if (server=="DATA_LOGGER")
1485 {
1486 fStatusLoggerLabel->setText(s.name.c_str());
1487 fStatusLoggerLabel->setToolTip(s.comment.c_str());
1488
1489 bool enable = true;
1490
1491 if (s.index<=30) // Ready/Waiting
1492 SetLedColor(fStatusLoggerLed, kLedYellow, time);
1493 if (s.index<-1) // Offline
1494 {
1495 SetLedColor(fStatusLoggerLed, kLedGray, time);
1496 enable = false;
1497 }
1498 if (s.index>=0x100) // Error
1499 SetLedColor(fStatusLoggerLed, kLedRed, time);
1500 if (s.index==40) // Logging
1501 SetLedColor(fStatusLoggerLed, kLedGreen, time);
1502
1503 fLoggerWidget->setEnabled(enable);
1504 }
1505
1506 if (server=="CHAT")
1507 {
1508 fStatusChatLabel->setText(s.name.c_str());
1509
1510 fChatOnline = s.index==0;
1511
1512 SetLedColor(fStatusChatLed, fChatOnline ? kLedGreen : kLedRed, time);
1513
1514 fChatSend->setEnabled(fChatOnline);
1515 fChatMessage->setEnabled(fChatOnline);
1516 }
1517
1518 if (server=="SCHEDULER")
1519 {
1520 fStatusSchedulerLabel->setText(s.name.c_str());
1521
1522 SetLedColor(fStatusSchedulerLed, s.index>=0 ? kLedGreen : kLedRed, time);
1523 }
1524 }
1525
1526 void handleStateOffline(const string &server)
1527 {
1528 handleStateChanged(Time(), server, State(-2, "Offline", "No connection via DIM."));
1529 }
1530
1531 void on_fTabWidget_currentChanged(int which)
1532 {
1533 if (fTabWidget->tabText(which)=="Chat")
1534 fTabWidget->setTabIcon(which, QIcon());
1535 }
1536
1537 void handleWrite(const Time &time, const string &text, int qos)
1538 {
1539 stringstream out;
1540
1541 if (text.substr(0, 6)=="CHAT: ")
1542 {
1543 out << "<font size='-1' color='navy'>[<B>";
1544 out << Time::fmt("%H:%M:%S") << time << "</B>]</FONT> ";
1545 out << text.substr(6);
1546 fChatText->append(out.str().c_str());
1547
1548 if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
1549 return;
1550
1551 static int num = 0;
1552 if (num++<2)
1553 return;
1554
1555 for (int i=0; i<fTabWidget->count(); i++)
1556 if (fTabWidget->tabText(i)=="Chat")
1557 {
1558 fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
1559 break;
1560 }
1561
1562 return;
1563 }
1564
1565
1566 out << "<font style='font-family:monospace' color='";
1567
1568 switch (qos)
1569 {
1570 case kMessage: out << "black"; break;
1571 case kInfo: out << "green"; break;
1572 case kWarn: out << "#FF6600"; break;
1573 case kError: out << "maroon"; break;
1574 case kFatal: out << "maroon"; break;
1575 case kDebug: out << "navy"; break;
1576 default: out << "navy"; break;
1577 }
1578 out << "'>" << time.GetAsStr() << " - " << text << "</font>";
1579
1580 fLogText->append(out.str().c_str());
1581
1582 if (qos>=kWarn)
1583 fTextEdit->append(out.str().c_str());
1584 }
1585
1586 void IndicateStateChange(const Time &time, const std::string &server)
1587 {
1588 const State s = GetState(server, GetCurrentState(server));
1589
1590 QApplication::postEvent(this,
1591 new FunctionEvent(boost::bind(&FactGui::handleStateChanged, this, time, server, s)));
1592 }
1593
1594 int Write(const Time &time, const string &txt, int qos)
1595 {
1596 QApplication::postEvent(this,
1597 new FunctionEvent(boost::bind(&FactGui::handleWrite, this, time, txt, qos)));
1598
1599 return 0;
1600 }
1601
1602 // ====================== Dim infoHandler================================
1603
1604 void handleDimService(const string &txt)
1605 {
1606 fDimSvcText->append(txt.c_str());
1607 }
1608
1609 void infoHandlerService(DimInfo &info)
1610 {
1611 const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
1612
1613 stringstream dummy;
1614 const Converter conv(dummy, fmt, false);
1615
1616 const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
1617
1618 stringstream out;
1619 out << "<font size'-1' color='navy'>[" << Time::fmt("%H:%M:%S.%f") << tm << "]</font> <B>" << info.getName() << "</B> - ";
1620
1621 bool iserr = true;
1622 if (!conv)
1623 {
1624 out << "Compilation of format string '" << fmt << "' failed!";
1625 }
1626 else
1627 {
1628 try
1629 {
1630 const string dat = conv.GetString(info.getData(), info.getSize());
1631 out << dat;
1632 iserr = false;
1633 }
1634 catch (const runtime_error &e)
1635 {
1636 out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
1637 }
1638 }
1639
1640 // srand(hash<string>()(string(info.getName())));
1641 // int bg = rand()&0xffffff;
1642
1643 int bg = hash<string>()(string(info.getName()));
1644
1645 // allow only light colors
1646 bg = ~(bg&0x1f1f1f)&0xffffff;
1647
1648 if (iserr)
1649 bg = 0xffffff;
1650
1651 stringstream bgcol;
1652 bgcol << hex << setfill('0') << setw(6) << bg;
1653
1654 const string col = iserr ? "red" : "black";
1655 const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
1656
1657 QApplication::postEvent(this,
1658 new FunctionEvent(boost::bind(&FactGui::handleDimService, this, str)));
1659 }
1660
1661 void CallInfoHandler(void (FactGui::*handler)(const DimData&), const DimData &d)
1662 {
1663 fInHandler = true;
1664 (this->*handler)(d);
1665 fInHandler = false;
1666 }
1667
1668 /*
1669 void CallInfoHandler(const boost::function<void()> &func)
1670 {
1671 // This ensures that newly received values are not sent back to the emitter
1672 // because changing the value emits the valueChanged signal (or similar)
1673 fInHandler = true;
1674 func();
1675 fInHandler = false;
1676 }*/
1677
1678 void PostInfoHandler(void (FactGui::*handler)(const DimData&))
1679 {
1680 //const boost::function<void()> f = boost::bind(handler, this, DimData(getInfo()));
1681
1682 FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, handler, DimData(getInfo())));
1683 // FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, f));
1684 // FunctionEvent *evt = new FunctionEvent(boost::bind(handler, this, DimData(getInfo()))));
1685
1686 QApplication::postEvent(this, evt);
1687 }
1688
1689 void infoHandler()
1690 {
1691 // Initialize the time-stamp (what a weird workaround...)
1692 if (getInfo())
1693 getInfo()->getTimestamp();
1694
1695 if (getInfo()==&fDimDNS)
1696 return PostInfoHandler(&FactGui::handleDimDNS);
1697#ifdef DEBUG_DIM
1698 cout << "HandleDimInfo " << getInfo()->getName() << endl;
1699#endif
1700 if (getInfo()==&fDimLoggerStats)
1701 return PostInfoHandler(&FactGui::handleLoggerStats);
1702
1703 if (getInfo()==&fDimFadFiles)
1704 return PostInfoHandler(&FactGui::handleFadFiles);
1705
1706 if (getInfo()==&fDimFadConnections)
1707 return PostInfoHandler(&FactGui::handleFadConnections);
1708
1709 if (getInfo()==&fDimFadEvents)
1710 return PostInfoHandler(&FactGui::handleFadEvents);
1711
1712 if (getInfo()==&fDimFadRuns)
1713 return PostInfoHandler(&FactGui::handleFadRuns);
1714
1715 if (getInfo()==&fDimFadCurrentEvent)
1716 return PostInfoHandler(&FactGui::handleFadCurrentEvent);
1717
1718/*
1719 if (getInfo()==&fDimFadSetup)
1720 return PostInfoHandler(&FactGui::handleFadSetup);
1721*/
1722 if (getInfo()==&fDimLoggerFilenameNight)
1723 return PostInfoHandler(&FactGui::handleLoggerFilenameNight);
1724
1725 if (getInfo()==&fDimLoggerNumSubs)
1726 return PostInfoHandler(&FactGui::handleLoggerNumSubs);
1727
1728 if (getInfo()==&fDimLoggerFilenameRun)
1729 return PostInfoHandler(&FactGui::handleLoggerFilenameRun);
1730
1731 if (getInfo()==&fDimFtmTriggerCounter)
1732 return PostInfoHandler(&FactGui::handleFtmTriggerCounter);
1733
1734 if (getInfo()==&fDimFtmCounter)
1735 return PostInfoHandler(&FactGui::handleFtmCounter);
1736
1737 if (getInfo()==&fDimFtmDynamicData)
1738 return PostInfoHandler(&FactGui::handleFtmDynamicData);
1739
1740 if (getInfo()==&fDimFtmPassport)
1741 return PostInfoHandler(&FactGui::handleFtmPassport);
1742
1743 if (getInfo()==&fDimFtmFtuList)
1744 return PostInfoHandler(&FactGui::handleFtmFtuList);
1745
1746 if (getInfo()==&fDimFtmStaticData)
1747 return PostInfoHandler(&FactGui::handleFtmStaticData);
1748
1749 if (getInfo()==&fDimFtmError)
1750 return PostInfoHandler(&FactGui::handleFtmError);
1751
1752 for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
1753 if (i->second==getInfo())
1754 {
1755 infoHandlerService(*i->second);
1756 return;
1757 }
1758
1759 DimNetwork::infoHandler();
1760 }
1761
1762
1763 // ======================================================================
1764
1765 bool event(QEvent *evt)
1766 {
1767 if (dynamic_cast<FunctionEvent*>(evt))
1768 return static_cast<FunctionEvent*>(evt)->Exec();
1769
1770 if (dynamic_cast<CheckBoxEvent*>(evt))
1771 {
1772 const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
1773 const QStandardItem *par = item.parent();
1774 if (par)
1775 {
1776 const QString server = par->text();
1777 const QString service = item.text();
1778
1779 const string s = (server+'/'+service).toStdString();
1780
1781 if (item.checkState()==Qt::Checked)
1782 SubscribeService(s);
1783 else
1784 UnsubscribeService(s);
1785 }
1786 }
1787
1788 return MainWindow::event(evt); // unrecognized
1789 }
1790
1791 void on_fDimCmdSend_clicked()
1792 {
1793 const QString server = fDimCmdServers->currentIndex().data().toString();
1794 const QString command = fDimCmdCommands->currentIndex().data().toString();
1795 const QString arguments = fDimCmdLineEdit->displayText();
1796
1797 // FIXME: Sending a command exactly when the info Handler changes
1798 // the list it might lead to confusion.
1799 try
1800 {
1801 SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
1802 fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
1803 fDimCmdLineEdit->clear();
1804 }
1805 catch (const runtime_error &e)
1806 {
1807 stringstream txt;
1808 txt << e.what();
1809
1810 string buffer;
1811 while (getline(txt, buffer, '\n'))
1812 fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
1813 }
1814 }
1815
1816#ifdef HAVE_ROOT
1817 void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *)
1818 {
1819 // kMousePressEvent // TCanvas processed QEvent mousePressEvent
1820 // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
1821 // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
1822 // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
1823 // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
1824 // kEnterEvent // TCanvas processed QEvent enterEvent
1825 // kLeaveEvent // TCanvas processed QEvent leaveEvent
1826 if (dynamic_cast<TCanvas*>(obj))
1827 return;
1828
1829 TQtWidget *tipped = static_cast<TQtWidget*>(sender());
1830
1831 if (evt==11/*kMouseReleaseEvent*/)
1832 {
1833 if (dynamic_cast<Camera*>(obj))
1834 {
1835 const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
1836 const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
1837
1838 Camera *cam = static_cast<Camera*>(obj);
1839 const int idx = cam->GetIdx(xx, yy);
1840
1841 cout << "Select: " << idx << endl;
1842
1843 fPixelIdx->setValue(idx);
1844 ChoosePixel(*cam, idx);
1845
1846 }
1847 return;
1848 }
1849
1850 if (evt==61/*kMouseDoubleClickEvent*/)
1851 {
1852 if (dynamic_cast<Camera*>(obj))
1853 {
1854 const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
1855 const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
1856
1857 Camera *cam = static_cast<Camera*>(obj);
1858 const int idx = cam->GetIdx(xx, yy);
1859
1860 cout << "Toggle: " << idx << endl;
1861
1862 ChoosePixel(*cam, idx);
1863
1864 fPixelIdx->setValue(idx);
1865
1866 Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", uint16_t(idx));
1867 }
1868
1869 if (dynamic_cast<TAxis*>(obj))
1870 static_cast<TAxis*>(obj)->UnZoom();
1871
1872 return;
1873 }
1874
1875 // Find the object which will get picked by the GetObjectInfo
1876 // due to buffer overflows in many root-versions
1877 // in TH1 and TProfile we have to work around and implement
1878 // our own GetObjectInfo which make everything a bit more
1879 // complicated.
1880#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
1881 const char *objectInfo =
1882 obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
1883#else
1884 const char *objectInfo = dynamic_cast<TH1*>(obj) ?
1885 "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
1886#endif
1887
1888 QString tipText;
1889 tipText += obj->GetName();
1890 tipText += " [";
1891 tipText += obj->ClassName();
1892 tipText += "]: ";
1893 tipText += objectInfo;
1894
1895 if (dynamic_cast<Camera*>(obj))
1896 {
1897 const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
1898 const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
1899
1900 Camera *cam = static_cast<Camera*>(obj);
1901 int idx = fPatch[cam->GetIdx(xx, yy)];
1902
1903 tipText+=" Patch=";
1904 tipText+=QString::number(idx);
1905 }
1906
1907
1908 fStatusBar->showMessage(tipText, 3000);
1909
1910 gSystem->ProcessEvents();
1911 //QWhatsThis::display(tipText)
1912 }
1913
1914 void slot_RootUpdate()
1915 {
1916 gSystem->ProcessEvents();
1917 QTimer::singleShot(0, this, SLOT(slot_RootUpdate()));
1918 }
1919
1920 void ChoosePatch(Camera &cam, int idx)
1921 {
1922 cam.Reset();
1923
1924 fThresholdIdx->setValue(idx);
1925
1926 const int patch = idx%4;
1927 const int board = (idx/4)%10;
1928 const int crate = (idx/4)/10;
1929
1930 fThresholdCrate->setValue(crate);
1931 fThresholdBoard->setValue(board);
1932 fThresholdPatch->setValue(patch);
1933
1934 //fThresholdVal->setEnabled(idx>=0);
1935 //fThresholdVolt->setEnabled(idx>=0);
1936 fPatchRate->setEnabled(idx>=0);
1937 if (idx<0)
1938 return;
1939
1940 fThresholdVal->setValue(fFtmStaticData.fThreshold[idx]);
1941 fPatchRate->setValue(cam.GetData(idx));
1942
1943 for (unsigned int i=0; i<fPatch.size(); i++)
1944 if (fPatch[i]==idx)
1945 cam.SetBold(i);
1946 }
1947
1948 void ChoosePixel(Camera &cam, int idx)
1949 {
1950 cam.SetWhite(idx);
1951 ChoosePatch(cam, fPatch[idx]);
1952
1953 fPixelEnable->setChecked(fFtmStaticData.IsEnabled(idx));
1954 }
1955
1956 void UpdatePatch(int idx)
1957 {
1958 Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
1959 ChoosePatch(*cam, idx);
1960 }
1961
1962 void on_fThresholdIdx_valueChanged(int idx)
1963 {
1964 UpdatePatch(idx);
1965 }
1966
1967 void UpdateThresholdIdx()
1968 {
1969 const int crate = fThresholdCrate->value();
1970 const int board = fThresholdBoard->value();
1971 const int patch = fThresholdPatch->value();
1972
1973 const int id = patch + board*4 + crate*40;
1974
1975 UpdatePatch(id);
1976 }
1977
1978 void on_fThresholdPatch_valueChanged(int)
1979 {
1980 UpdateThresholdIdx();
1981 }
1982 void on_fThresholdBoard_valueChanged(int)
1983 {
1984 UpdateThresholdIdx();
1985 }
1986 void on_fThresholdCrate_valueChanged(int)
1987 {
1988 UpdateThresholdIdx();
1989 }
1990
1991 void on_fPixelIdx_valueChanged(int idx)
1992 {
1993 Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
1994 ChoosePixel(*cam, idx);
1995
1996 fRatesCanv->GetCanvas()->Modified();
1997 fRatesCanv->GetCanvas()->Update();
1998 }
1999#endif
2000
2001 TGraph fGraphFtmTemp[4];
2002 TGraph fGraphFtmRate;
2003 TGraph fGraphPatchRate[160];
2004 TGraph fGraphBoardRate[40];
2005
2006 map<int, int> fPatch;
2007
2008#ifdef HAVE_ROOT
2009 void DrawTimeFrame(const char *ytitle)
2010 {
2011 const double tm = Time().RootTime();
2012
2013 TH1F h("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
2014 h.SetDirectory(0);
2015// h.SetBit(TH1::kCanRebin);
2016 h.SetStats(kFALSE);
2017// h.SetMinimum(0);
2018// h.SetMaximum(1);
2019 h.SetXTitle("Time");
2020 h.SetYTitle(ytitle);
2021 h.GetXaxis()->CenterTitle();
2022 h.GetYaxis()->CenterTitle();
2023 h.GetXaxis()->SetTimeDisplay(true);
2024 h.GetXaxis()->SetTimeFormat("%Mh%S'");
2025 h.GetXaxis()->SetLabelSize(0.025);
2026 h.GetYaxis()->SetLabelSize(0.025);
2027 h.GetYaxis()->SetTitleOffset(1.2);
2028// h.GetYaxis()->SetTitleSize(1.2);
2029 h.DrawCopy()->SetDirectory(0);
2030 }
2031#endif
2032
2033public:
2034 FactGui() :
2035 fFtuStatus(40), //fMapHW(1440)
2036 fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
2037
2038 fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
2039 fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHTLY", const_cast<char*>(""), 0, this),
2040 fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", const_cast<char*>(""), 0, this),
2041 fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", const_cast<char*>(""), 0, this),
2042
2043 fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
2044 fDimFtmTriggerCounter("FTM_CONTROL/TRIGGER_COUNTER", (void*)NULL, 0, this),
2045 fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
2046 fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
2047 fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
2048 fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this),
2049 fDimFtmCounter ("FTM_CONTROL/COUNTER", (void*)NULL, 0, this),
2050 fDimFadFiles ("FAD_CONTROL/FILES", (void*)NULL, 0, this),
2051 fDimFadRuns ("FAD_CONTROL/RUNS", (void*)NULL, 0, this),
2052 fDimFadEvents ("FAD_CONTROL/EVENTS", (void*)NULL, 0, this),
2053 fDimFadCurrentEvent ("FAD_CONTROL/CURRENT_EVENT", (void*)NULL, 0, this),
2054 fDimFadConnections ("FAD_CONTROL/CONNECTIONS", (void*)NULL, 0, this)
2055 {
2056 fTriggerWidget->setEnabled(false);
2057 fFtuWidget->setEnabled(false);
2058 fRatesWidget->setEnabled(false);
2059 fFadWidget->setEnabled(false);
2060 fLoggerWidget->setEnabled(false);
2061
2062 fChatSend->setEnabled(false);
2063 fChatMessage->setEnabled(false);
2064
2065 DimClient::sendCommand("CHAT/MSG", "GUI online.");
2066 // + MessageDimRX
2067
2068 // --------------------------------------------------------------------------
2069
2070 ifstream fin1("fact-trigger-all.txt");
2071
2072 int l = 0;
2073
2074 string buf;
2075 while (getline(fin1, buf, '\n'))
2076 {
2077 buf = Tools::Trim(buf);
2078 if (buf[0]=='#')
2079 continue;
2080
2081 stringstream str(buf);
2082 for (int i=0; i<9; i++)
2083 {
2084 int n;
2085 str >> n;
2086
2087 fPatch[n] = l;
2088 }
2089 l++;
2090 }
2091
2092 // --------------------------------------------------------------------------
2093/*
2094 ifstream fin2("FACTmapV3.txt");
2095
2096 l = 0;
2097
2098 while (getline(fin2, buf, '\n'))
2099 {
2100 buf = Tools::Trim(buf);
2101 if (buf[0]=='#')
2102 continue;
2103
2104 int softid, hardid, geom_i, geom_j, gapd;
2105
2106 stringstream str(buf);
2107
2108 str >> softid;
2109 str >> hardid;
2110 str >> geom_i;
2111 str >> geom_j;
2112 str >> gapd;
2113
2114 fMapHW[softid] = hardid;
2115 fMapSW[hardid] = softid;
2116
2117 l++;
2118 }
2119*/
2120 // --------------------------------------------------------------------------
2121#ifdef HAVE_ROOT
2122
2123 fGraphFtmRate.SetLineColor(kBlue);
2124 fGraphFtmRate.SetMarkerColor(kBlue);
2125 fGraphFtmRate.SetMarkerStyle(kFullDotMedium);
2126
2127 for (int i=0; i<160; i++)
2128 {
2129 fGraphPatchRate[i].SetName("PatchRate");
2130 fGraphPatchRate[i].SetLineColor(kBlue);
2131 fGraphPatchRate[i].SetMarkerColor(kBlue);
2132 fGraphPatchRate[i].SetMarkerStyle(kFullDotMedium);
2133 }
2134 for (int i=0; i<40; i++)
2135 {
2136 fGraphBoardRate[i].SetName("BoardRate");
2137 fGraphBoardRate[i].SetLineColor(kBlue);
2138 fGraphBoardRate[i].SetMarkerColor(kBlue);
2139 fGraphBoardRate[i].SetMarkerStyle(kFullDotMedium);
2140 }
2141 /*
2142 TCanvas *c = fFtmTempCanv->GetCanvas();
2143 c->SetBit(TCanvas::kNoContextMenu);
2144 c->SetBorderMode(0);
2145 c->SetFrameBorderMode(0);
2146 c->SetFillColor(kWhite);
2147 c->SetRightMargin(0.03);
2148 c->SetTopMargin(0.03);
2149 c->cd();
2150 */
2151 //CreateTimeFrame("Temperature / °C");
2152
2153 fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
2154 fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
2155 fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
2156 fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
2157
2158 fGraphFtmTemp[1].SetLineColor(kBlue);
2159 fGraphFtmTemp[2].SetLineColor(kRed);
2160 fGraphFtmTemp[3].SetLineColor(kGreen);
2161
2162 fGraphFtmTemp[1].SetMarkerColor(kBlue);
2163 fGraphFtmTemp[2].SetMarkerColor(kRed);
2164 fGraphFtmTemp[3].SetMarkerColor(kGreen);
2165
2166 //fGraphFtmTemp[0].Draw("LP");
2167 //fGraphFtmTemp[1].Draw("LP");
2168 //fGraphFtmTemp[2].Draw("LP");
2169 //fGraphFtmTemp[3].Draw("LP");
2170
2171 // --------------------------------------------------------------------------
2172
2173 TCanvas *c = fFtmRateCanv->GetCanvas();
2174 c->SetBit(TCanvas::kNoContextMenu);
2175 c->SetBorderMode(0);
2176 c->SetFrameBorderMode(0);
2177 c->SetFillColor(kWhite);
2178 c->SetRightMargin(0.03);
2179 c->SetTopMargin(0.03);
2180 c->SetGrid();
2181 c->cd();
2182
2183 DrawTimeFrame("Trigger rate [Hz]");
2184
2185 fTriggerCounter0 = -1;
2186
2187 fGraphFtmRate.SetMarkerStyle(kFullDotSmall);
2188 fGraphFtmRate.Draw("LP");
2189
2190 // --------------------------------------------------------------------------
2191
2192 c = fRatesCanv->GetCanvas();
2193 c->SetBit(TCanvas::kNoContextMenu);
2194 c->SetBorderMode(0);
2195 c->SetFrameBorderMode(0);
2196 c->SetFillColor(kWhite);
2197 c->cd();
2198
2199 Camera *cam = new Camera;
2200 cam->SetBit(kCanDelete);
2201 cam->Draw();
2202
2203 ChoosePixel(*cam, 1);
2204
2205// QTimer::singleShot(0, this, SLOT(slot_RootUpdate()));
2206
2207 //widget->setMouseTracking(true);
2208 //widget->EnableSignalEvents(kMouseMoveEvent);
2209
2210 fFtmRateCanv->setMouseTracking(true);
2211 fFtmRateCanv->EnableSignalEvents(kMouseMoveEvent);
2212
2213 fRatesCanv->setMouseTracking(true);
2214 fRatesCanv->EnableSignalEvents(kMouseMoveEvent|kMouseReleaseEvent|kMouseDoubleClickEvent);
2215
2216 connect(fRatesCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
2217 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
2218 connect(fFtmRateCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
2219 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
2220#endif
2221 }
2222
2223 ~FactGui()
2224 {
2225 UnsubscribeAllServers();
2226 }
2227};
2228
2229#endif
Note: See TracBrowser for help on using the repository browser.