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

Last change on this file since 10524 was 10524, checked in by tbretz, 14 years ago
Encapsulated root stuff into ifdef's; removed the root update timer - it is not necessary if we don't allow user interaction; implemented more accurate colors for the FTU Leds
File size: 50.8 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/Converter.h"
17#include "src/HeadersFTM.h"
18#include "src/DimNetwork.h"
19#include "src/tools.h"
20
21#include "TROOT.h"
22#include "TSystem.h"
23#include "TGraph.h"
24#include "TH1.h"
25#include "TStyle.h"
26#include "TMarker.h"
27#include "TColor.h"
28#include "TQtTimer.h"
29
30#define HAS_ROOT
31
32using namespace std;
33
34// #########################################################################
35
36class Camera : public TObject
37{
38 typedef pair<double,double> Position;
39 typedef vector<Position> Positions;
40
41 Positions fGeom;
42
43 void CreatePalette()
44 {
45 /*
46 double ss[5] = {0., 0.10, 0.45, 0.75, 1.00};
47 double rr[5] = {0., 0.35, 0.85, 1.00, 1.00};
48 double gg[5] = {0., 0.10, 0.20, 0.73, 1.00};
49 double bb[5] = {0., 0.03, 0.06, 0.00, 1.00};
50 */
51 double ss[5] = {0., 0.25, 0.50, 0.75, 1.00};
52 double rr[5] = {0., 0.00, 0.00, 1.00, 1.00};
53 double gg[5] = {0., 0.00, 1.00, 0.00, 1.00};
54 double bb[5] = {0., 1.00, 0.00, 0.00, 1.00};
55
56 const Int_t nn = 1438;
57
58 Int_t idx = TColor::CreateGradientColorTable(5, ss, rr, gg, bb, nn);
59 for (int i=0; i<nn; i++)
60 fPalette.push_back(idx++);
61 }
62
63 void CreateGeometry()
64 {
65 const double gsSin60 = sqrt(3.)/2;
66
67 const int rings = 23;
68
69 // add the first pixel to the list
70
71 fGeom.push_back(make_pair(0, -0.5));
72
73 for (int ring=1; ring<=rings; ring++)
74 {
75 for (int s=0; s<6; s++)
76 {
77 for (int i=1; i<=ring; i++)
78 {
79 double xx, yy;
80 switch (s)
81 {
82 case 0: // Direction South East
83 xx = (ring+i)*0.5;
84 yy = (-ring+i)*gsSin60;
85 break;
86
87 case 1: // Direction North East
88 xx = ring-i*0.5;
89 yy = i*gsSin60;
90 break;
91
92 case 2: // Direction North
93 xx = ring*0.5-i;
94 yy = ring*gsSin60;
95 break;
96
97 case 3: // Direction North West
98 xx = -(ring+i)*0.5;
99 yy = (ring-i)*gsSin60;
100 break;
101
102 case 4: // Direction South West
103 xx = 0.5*i-ring;
104 yy = -i*gsSin60;
105 break;
106
107 case 5: // Direction South
108 xx = i-ring*0.5;
109 yy = -ring*gsSin60;
110 break;
111 }
112
113 if (xx*xx + yy*yy - xx > 395.75)
114 continue;
115
116 fGeom.push_back(make_pair(yy, xx-0.5));
117 }
118 }
119 }
120 }
121
122 valarray<double> fData;
123 map<int, bool> fBold;
124 map<int, bool> fEnable;
125
126 int fWhite;
127
128public:
129 Camera() : fData(0., 1438), fWhite(-1)
130 {
131 CreatePalette();
132 CreateGeometry();
133
134 for (int i=0; i<1438; i++)
135 fData[i] = i;
136 }
137
138 void Reset() { fBold.clear(); }
139
140 void SetBold(int idx) { fBold[idx]=true; }
141 void SetWhite(int idx) { fWhite=idx; }
142 void SetEnable(int idx, bool b) { fEnable[idx]=b; }
143 void Toggle(int idx) { fEnable[idx]=!fEnable[idx]; }
144
145 const char *GetName() const { return "Camera"; }
146
147 vector<Int_t> fPalette;
148
149 void Paint(const Position &p)
150 {
151 static const Double_t fgCos60 = 0.5; // TMath::Cos(60/TMath::RadToDeg());
152 static const Double_t fgSin60 = sqrt(3.)/2; // TMath::Sin(60/TMath::RadToDeg());
153
154 static const Double_t fgDy[6] = { fgCos60, 0., -fgCos60, -fgCos60, 0., fgCos60 };
155 static const Double_t fgDx[6] = { fgSin60/3, fgSin60*2/3, fgSin60/3, -fgSin60/3, -fgSin60*2/3, -fgSin60/3 };
156
157 //
158 // calculate the positions of the pixel corners
159 //
160 Double_t x[7], y[7];
161 for (Int_t i=0; i<7; i++)
162 {
163 x[i] = p.first + fgDx[i%6];
164 y[i] = p.second + fgDy[i%6];
165 }
166
167 gPad->PaintFillArea(6, x, y);
168 gPad->PaintPolyLine(7, x, y);
169
170 }
171
172 void Paint(Option_t *)
173 {
174 gStyle->SetPalette(fPalette.size(), fPalette.data());
175
176
177 const double r = double(gPad->GetWw())/gPad->GetWh();
178 const double max = 20.5; // 20.5 rings in x and y
179
180 if (r>1)
181 gPad->Range(-r*max, -max, r*max, max);
182 else
183 gPad->Range(-max, -max/r, max, max/r);
184
185
186 const double min = fData.min();
187 const double scale = fData.max()-fData.min();
188
189 TAttFill fill(0, 1001);
190 TAttLine line;
191
192 int cnt=0;
193 for (Positions::iterator p=fGeom.begin(); p!=fGeom.end(); p++, cnt++)
194 {
195 if (fBold[cnt])
196 continue;
197
198
199 const int col = (fData[cnt]-min)/scale*(fPalette.size()-1);
200
201 if (fEnable[cnt])
202 fill.SetFillColor(gStyle->GetColorPalette(col));
203 else
204 fill.SetFillColor(kWhite);
205
206 fill.Modify();
207
208 Paint(*p);
209 }
210
211 line.SetLineWidth(2);
212 line.Modify();
213
214 cnt = 0;
215 for (Positions::iterator p=fGeom.begin(); p!=fGeom.end(); p++, cnt++)
216 {
217 if (!fBold[cnt])
218 continue;
219
220 const int col = (fData[cnt]-min)/scale*(fPalette.size()-1);
221
222 if (fEnable[cnt])
223 fill.SetFillColor(gStyle->GetColorPalette(col));
224 else
225 fill.SetFillColor(kWhite);
226 fill.Modify();
227
228 Paint(*p);
229 }
230
231 TMarker m(0,0,kStar);
232 m.DrawMarker(0, 0);
233
234 if (fWhite<0)
235 return;
236
237 const Position &p = fGeom[fWhite];
238
239 line.SetLineColor(kWhite);
240 line.Modify();
241
242 const int col = (fData[fWhite]-min)/scale*(fPalette.size()-1);
243
244 if (fEnable[fWhite])
245 fill.SetFillColor(gStyle->GetColorPalette(col));
246 else
247 fill.SetFillColor(kWhite);
248 fill.Modify();
249
250 Paint(p);
251 }
252
253 int GetIdx(float px, float py) const
254 {
255 static const double sqrt3 = sqrt(3);
256
257 int idx = 0;
258 for (Positions::const_iterator p=fGeom.begin(); p!=fGeom.end(); p++, idx++)
259 {
260 const Double_t dy = py - p->second;
261 if (fabs(dy)>0.5)
262 continue;
263
264 const Double_t dx = px - p->first;
265
266 if (TMath::Abs(dy + dx*sqrt3) > 1)
267 continue;
268
269 if (TMath::Abs(dy - dx*sqrt3) > 1)
270 continue;
271
272 return idx;
273 }
274 return -1;
275 }
276
277 char* GetObjectInfo(Int_t px, Int_t py) const
278 {
279 static stringstream stream;
280 static string str;
281
282 const float x = gPad->PadtoX(gPad->AbsPixeltoX(px));
283 const float y = gPad->PadtoY(gPad->AbsPixeltoY(py));
284
285 const int idx = GetIdx(x, y);
286
287 stream.seekp(0);
288 if (idx>=0)
289 stream << "Pixel=" << idx << " Data=" << fData[idx] << '\0';
290
291 str = stream.str();
292 return const_cast<char*>(str.c_str());
293 }
294
295 Int_t DistancetoPrimitive(Int_t px, Int_t py)
296 {
297 const float x = gPad->PadtoX(gPad->AbsPixeltoX(px));
298 const float y = gPad->PadtoY(gPad->AbsPixeltoY(py));
299
300 return GetIdx(x, y)>=0 ? 0 : 99999;
301 }
302
303 void SetData(const valarray<double> &data)
304 {
305 fData = data;
306 }
307};
308
309// #########################################################################
310
311
312class FactGui : public MainWindow, public DimNetwork
313{
314private:
315 class FunctionEvent : public QEvent
316 {
317 public:
318 boost::function<void(const QEvent &)> fFunction;
319
320 FunctionEvent(const boost::function<void(const QEvent &)> &f)
321 : QEvent((QEvent::Type)QEvent::registerEventType()),
322 fFunction(f) { }
323
324 bool Exec() { fFunction(*this); return true; }
325 };
326
327 vector<bool> fFtuDisabled;
328
329 DimStampedInfo fDimDNS;
330
331 DimStampedInfo fDimLoggerStats;
332 DimStampedInfo fDimLoggerFilenameNight;
333 DimStampedInfo fDimLoggerFilenameRun;
334 DimStampedInfo fDimLoggerNumSubs;
335
336 DimStampedInfo fDimFtmPassport;
337 DimStampedInfo fDimFtmTriggerCounter;
338 DimStampedInfo fDimFtmError;
339 DimStampedInfo fDimFtmFtuList;
340 DimStampedInfo fDimFtmStaticData;
341 DimStampedInfo fDimFtmDynamicData;
342
343 vector<DimInfo*> fDim;
344 map<string, DimInfo*> fServices;
345
346 // ===================== Services and Commands ==========================
347
348 QStandardItem *AddServiceItem(const std::string &server, const std::string &service, bool iscmd)
349 {
350 QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
351 QListView *services = iscmd ? fDimCmdCommands : fDimSvcServices;
352 QListView *description = iscmd ? fDimCmdDescription : fDimSvcDescription;
353
354 QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
355 if (!m)
356 {
357 m = new QStandardItemModel(this);
358 servers->setModel(m);
359 services->setModel(m);
360 description->setModel(m);
361 }
362
363 QList<QStandardItem*> l = m->findItems(server.c_str());
364
365 if (l.size()>1)
366 {
367 cout << "hae" << endl;
368 return 0;
369 }
370
371 QStandardItem *col = l.size()==0 ? NULL : l[0];
372
373 if (!col)
374 {
375 col = new QStandardItem(server.c_str());
376 m->appendRow(col);
377
378 if (!services->rootIndex().isValid())
379 {
380 services->setRootIndex(col->index());
381 servers->setCurrentIndex(col->index());
382 }
383 }
384
385 QStandardItem *item = 0;
386 for (int i=0; i<col->rowCount(); i++)
387 {
388 QStandardItem *coli = col->child(i);
389 if (coli->text().toStdString()==service)
390 return coli;
391 }
392
393 item = new QStandardItem(service.c_str());
394 col->appendRow(item);
395
396 if (!description->rootIndex().isValid())
397 {
398 description->setRootIndex(item->index());
399 services->setCurrentIndex(item->index());
400 }
401
402 if (!iscmd)
403 item->setCheckable(true);
404
405 return item;
406 }
407
408 void AddDescription(QStandardItem *item, const vector<Description> &vec)
409 {
410 if (!item)
411 return;
412 if (vec.size()==0)
413 return;
414
415 item->setToolTip(vec[0].comment.c_str());
416
417 const string str = Description::GetHtmlDescription(vec);
418
419 QStandardItem *desc = new QStandardItem(str.c_str());
420 desc->setSelectable(false);
421 item->setChild(0, 0, desc);
422 }
423
424 void AddServer(const std::string &s)
425 {
426 DimNetwork::AddServer(s);
427
428 QApplication::postEvent(this,
429 new FunctionEvent(boost::bind(&FactGui::handleAddServer, this, s)));
430 }
431
432 void RemoveServer(const std::string &s)
433 {
434 UnsubscribeServer(s);
435
436 DimNetwork::RemoveServer(s);
437
438 QApplication::postEvent(this,
439 new FunctionEvent(boost::bind(&FactGui::handleRemoveServer, this, s)));
440 }
441
442 void RemoveAllServers()
443 {
444 UnsubscribeAllServers();
445
446 vector<string> v = GetServerList();
447 for (vector<string>::iterator i=v.begin(); i<v.end(); i++)
448 QApplication::postEvent(this,
449 new FunctionEvent(boost::bind(&FactGui::handleStateOffline, this, *i)));
450
451 DimNetwork::RemoveAllServers();
452
453 QApplication::postEvent(this,
454 new FunctionEvent(boost::bind(&FactGui::handleRemoveAllServers, this)));
455 }
456
457 void AddService(const std::string &server, const std::string &service, const std::string &fmt, bool iscmd)
458 {
459 QApplication::postEvent(this,
460 new FunctionEvent(boost::bind(&FactGui::handleAddService, this, server, service, fmt, iscmd)));
461 }
462
463 void RemoveService(const std::string &server, const std::string &service, bool iscmd)
464 {
465 if (fServices.find(server+'/'+service)!=fServices.end())
466 UnsubscribeService(server+'/'+service);
467
468 QApplication::postEvent(this,
469 new FunctionEvent(boost::bind(&FactGui::handleRemoveService, this, server, service, iscmd)));
470 }
471
472 void RemoveAllServices(const std::string &server)
473 {
474 UnsubscribeServer(server);
475
476 QApplication::postEvent(this,
477 new FunctionEvent(boost::bind(&FactGui::handleRemoveAllServices, this, server)));
478 }
479
480 void AddDescription(const std::string &server, const std::string &service, const vector<Description> &vec)
481 {
482 QApplication::postEvent(this,
483 new FunctionEvent(boost::bind(&FactGui::handleAddDescription, this, server, service, vec)));
484 }
485
486 // ======================================================================
487
488 void handleAddServer(const std::string &server)
489 {
490 const State s = GetState(server, GetCurrentState(server));
491 handleStateChanged(Time(), server, s);
492 }
493
494 void handleRemoveServer(const string &server)
495 {
496 handleStateOffline(server);
497 handleRemoveAllServices(server);
498 }
499
500 void handleRemoveAllServers()
501 {
502 QStandardItemModel *m = 0;
503 if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
504 m->removeRows(0, m->rowCount());
505
506 if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
507 m->removeRows(0, m->rowCount());
508 }
509
510 void handleAddService(const std::string &server, const std::string &service, const std::string &/*fmt*/, bool iscmd)
511 {
512 QStandardItem *item = AddServiceItem(server, service, iscmd);
513 const vector<Description> v = GetDescription(server, service);
514 AddDescription(item, v);
515 }
516
517 void handleRemoveService(const std::string &server, const std::string &service, bool iscmd)
518 {
519 QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
520
521 QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
522 if (!m)
523 return;
524
525 QList<QStandardItem*> l = m->findItems(server.c_str());
526 if (l.size()!=1)
527 return;
528
529 for (int i=0; i<l[0]->rowCount(); i++)
530 {
531 QStandardItem *row = l[0]->child(i);
532 if (row->text().toStdString()==service)
533 {
534 l[0]->removeRow(row->index().row());
535 return;
536 }
537 }
538 }
539
540 void handleRemoveAllServices(const std::string &server)
541 {
542 QStandardItemModel *m = 0;
543 if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
544 {
545 QList<QStandardItem*> l = m->findItems(server.c_str());
546 if (l.size()==1)
547 m->removeRow(l[0]->index().row());
548 }
549
550 if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
551 {
552 QList<QStandardItem*> l = m->findItems(server.c_str());
553 if (l.size()==1)
554 m->removeRow(l[0]->index().row());
555 }
556 }
557
558 void handleAddDescription(const std::string &server, const std::string &service, const vector<Description> &vec)
559 {
560 const bool iscmd = IsCommand(server, service)==true;
561
562 QStandardItem *item = AddServiceItem(server, service, iscmd);
563 AddDescription(item, vec);
564 }
565
566 // ======================================================================
567
568 void SubscribeService(const string &service)
569 {
570 if (fServices.find(service)!=fServices.end())
571 {
572 cout << "ERROR - We are already subscribed to " << service << endl;
573 return;
574 }
575
576 fServices[service] = new DimStampedInfo(service.c_str(), (void*)NULL, 0, this);
577 }
578
579 void UnsubscribeService(const string &service)
580 {
581 const map<string,DimInfo*>::iterator i=fServices.find(service);
582
583 if (i==fServices.end())
584 {
585 cout << "ERROR - We are not subscribed to " << service << endl;
586 return;
587 }
588
589 delete i->second;
590
591 fServices.erase(i);
592 }
593
594 void UnsubscribeServer(const string &server)
595 {
596 for (map<string,DimInfo*>::iterator i=fServices.begin();
597 i!=fServices.end(); i++)
598 if (i->first.substr(0, server.length()+1)==server+'/')
599 {
600 delete i->second;
601 fServices.erase(i);
602 }
603 }
604
605 void UnsubscribeAllServers()
606 {
607 for (map<string,DimInfo*>::iterator i=fServices.begin();
608 i!=fServices.end(); i++)
609 delete i->second;
610
611 fServices.clear();
612 }
613
614 // ======================================================================
615
616 struct DimData
617 {
618 Time time;
619 int qos;
620 string name;
621 string format;
622 vector<char> data;
623
624 DimInfo *info; // this is ONLY for a fast check of the type of the DimData!!
625
626 DimData(DimInfo *inf) :
627 time(inf->getTimestamp(), inf->getTimestampMillisecs()*1000),
628 qos(inf->getQuality()),
629 name(inf->getName()),
630 format(inf->getFormat()),
631 data(inf->getString(), inf->getString()+inf->getSize()),
632 info(inf)
633 {
634 }
635
636 template<typename T>
637 T get() const { return *reinterpret_cast<const T*>(data.data()); }
638
639 vector<char> vec(int b) const { return vector<char>(data.begin()+b, data.end()); }
640 string str(unsigned int b) const { return b>=data.size()?string():string(data.data()+b, data.size()-b); }
641 const char *c_str() const { return (char*)data.data(); }
642
643 vector<boost::any> any() const
644 {
645 const Converter conv(format);
646 conv.Print();
647 return conv.GetAny(data.data(), data.size());
648 }
649 int size() const { return data.size(); }
650 const void *ptr() const { return data.data(); }
651 };
652
653 // ======================= DNS ==========================================
654
655 void handleDimDNS(int version)
656 {
657 ostringstream str;
658 str << "V" << version/100 << 'r' << version%100;
659
660 if (version==0)
661 fStatusDNSLed->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
662 else
663 fStatusDNSLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
664
665 fStatusDNSLabel->setText(version==0?"Offline":str.str().c_str());
666 fStatusDNSLabel->setToolTip(version==0?"No connection to DIM DNS.":"Connection to DIM DNS established.");
667 }
668
669
670 // ======================= Logger =======================================
671
672 void handleLoggerStats(const DimData &d)
673 {
674 const bool connected = d.size()!=0;
675
676 fLoggerET->setEnabled(connected);
677 fLoggerRate->setEnabled(connected);
678 fLoggerWritten->setEnabled(connected);
679 fLoggerFreeSpace->setEnabled(connected);
680 fLoggerSpaceLeft->setEnabled(connected);
681
682 if (!connected)
683 return;
684
685 const vector<boost::any> any = d.any();
686
687 const size_t rate = boost::any_cast<int>(any[2]);
688 const size_t space = boost::any_cast<long long>(any[1]);
689 const size_t written = boost::any_cast<long long>(any[0]);
690
691 fLoggerFreeSpace->setSuffix(" MB");
692 fLoggerFreeSpace->setDecimals(0);
693 fLoggerFreeSpace->setValue(space*1e-6);
694
695 if (space> 1000000) // > 1GB
696 {
697 fLoggerFreeSpace->setSuffix(" GB");
698 fLoggerFreeSpace->setDecimals(2);
699 fLoggerFreeSpace->setValue(space*1e-9);
700 }
701 if (space>= 3000000) // >= 3GB
702 {
703 fLoggerFreeSpace->setSuffix(" GB");
704 fLoggerFreeSpace->setDecimals(1);
705 fLoggerFreeSpace->setValue(space*1e-9);
706 }
707 if (space>=100000000) // >= 100GB
708 {
709 fLoggerFreeSpace->setSuffix(" GB");
710 fLoggerFreeSpace->setDecimals(0);
711 fLoggerFreeSpace->setValue(space*1e-9);
712 }
713
714 fLoggerET->setTime(QTime().addSecs(rate>0?space/rate:0));
715 fLoggerRate->setValue(rate*1e-3); // kB/s
716 fLoggerWritten->setValue(written*1e-6);
717
718 fLoggerRate->setSuffix(" kB/s");
719 fLoggerRate->setDecimals(2);
720 fLoggerRate->setValue(rate*1e-3);
721 if (rate> 2000) // > 2kB/s
722 {
723 fLoggerRate->setSuffix(" kB/s");
724 fLoggerRate->setDecimals(1);
725 fLoggerRate->setValue(rate*1e-3);
726 }
727 if (rate>=100000) // >100kB/s
728 {
729 fLoggerRate->setSuffix(" kB/s");
730 fLoggerRate->setDecimals(0);
731 fLoggerRate->setValue(rate*1e-3);
732 }
733 if (rate>=1000000) // >100kB/s
734 {
735 fLoggerRate->setSuffix(" MB/s");
736 fLoggerRate->setDecimals(2);
737 fLoggerRate->setValue(rate*1e-6);
738 }
739 if (rate>=10000000) // >1MB/s
740 {
741 fLoggerRate->setSuffix(" MB/s");
742 fLoggerRate->setDecimals(1);
743 fLoggerRate->setValue(rate*1e-6);
744 }
745 if (rate>=100000000) // >10MB/s
746 {
747 fLoggerRate->setSuffix(" MB/s");
748 fLoggerRate->setDecimals(0);
749 fLoggerRate->setValue(rate*1e-6);
750 }
751
752 if (space/10000000>static_cast<size_t>(fLoggerSpaceLeft->maximum()))
753 fLoggerSpaceLeft->setValue(fLoggerSpaceLeft->maximum()); // MB
754 else
755 fLoggerSpaceLeft->setValue(space/10000000); // MB
756 }
757
758 void handleLoggerFilenameNight(const DimData &d)
759 {
760 const bool connected = d.size()!=0;
761
762 fLoggerFilenameNight->setEnabled(connected);
763 if (connected)
764 fLoggerFilenameNight->setText(d.c_str());
765
766 if (d.qos&1)
767 fLoggerLedLog->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
768 else
769 fLoggerLedLog->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
770
771 if (d.qos&2)
772 fLoggerLedRep->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
773 else
774 fLoggerLedRep->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
775
776 if (d.qos&4)
777 fLoggerLedFits->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
778 else
779 fLoggerLedFits->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
780 }
781
782 void handleLoggerFilenameRun(const DimData &d)
783 {
784 const bool connected = d.size()!=0;
785
786 fLoggerFilenameRun->setEnabled(connected);
787 if (connected)
788 fLoggerFilenameRun->setText(d.c_str());
789
790 if (d.qos&1)
791 fLoggerLedLog->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
792 else
793 fLoggerLedLog->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
794
795 if (d.qos&2)
796 fLoggerLedRep->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
797 else
798 fLoggerLedRep->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
799
800 if (d.qos&4)
801 fLoggerLedFits->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
802 else
803 fLoggerLedFits->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
804 }
805
806 void handleLoggerNumSubs(const DimData &d)
807 {
808 const bool connected = d.size()!=0;
809
810 fLoggerSubscriptions->setEnabled(connected);
811 fLoggerOpenFiles->setEnabled(connected);
812 if (!connected)
813 return;
814
815 const vector<boost::any> any = d.any();
816
817 fLoggerSubscriptions->setValue(boost::any_cast<int>(any[0]));
818 fLoggerOpenFiles->setValue(boost::any_cast<int>(any[1]));
819 }
820
821 // ===================== FTM ============================================
822
823 void handleFtmTriggerCounter(const DimData &d)
824 {
825 if (d.size()==0)
826 return;
827
828 if (d.size()!=sizeof(FTM::DimTriggerCounter))
829 {
830 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimTriggerCounter) << endl;
831 return;
832 }
833
834 const FTM::DimTriggerCounter &sdata = *reinterpret_cast<const FTM::DimTriggerCounter*>(d.ptr());
835
836 fFtmTime->setText(QString::number(sdata.fTimeStamp));
837 fTriggerCounter->setText(QString::number(sdata.fTriggerCounter));
838 }
839
840 void handleFtmDynamicData(const DimData &d)
841 {
842 if (d.size()==0)
843 return;
844
845 if (d.size()!=sizeof(FTM::DimDynamicData))
846 {
847 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimDynamicData) << endl;
848 return;
849 }
850
851 const FTM::DimDynamicData &sdata = *reinterpret_cast<const FTM::DimDynamicData*>(d.ptr());
852
853 fFtmTime->setText(QString::number(sdata.fTimeStamp));
854 fOnTime->setText(QString::number(sdata.fOnTimeCounter));
855
856 fFtmTemp0->setValue(sdata.fTempSensor[0]*0.1);
857 fFtmTemp1->setValue(sdata.fTempSensor[1]*0.1);
858 fFtmTemp2->setValue(sdata.fTempSensor[2]*0.1);
859 fFtmTemp3->setValue(sdata.fTempSensor[3]*0.1);
860
861
862 // ----------------------------------------------
863#ifdef HAS_ROOT
864 TCanvas *c = fFtmTempCanv->GetCanvas();
865
866 static int cntr = 0;
867 double_t tm = cntr++;//Time().RootTime();
868
869 TH1 *h = (TH1*)c->FindObject("MyFrame");
870 h->FindBin(tm);
871
872 fGraphFtmTemp[0].SetPoint(fGraphFtmTemp[0].GetN(), tm, sdata.fTempSensor[0]*0.1);
873 fGraphFtmTemp[1].SetPoint(fGraphFtmTemp[1].GetN(), tm, sdata.fTempSensor[1]*0.1);
874 fGraphFtmTemp[2].SetPoint(fGraphFtmTemp[2].GetN(), tm, sdata.fTempSensor[2]*0.1);
875 fGraphFtmTemp[3].SetPoint(fGraphFtmTemp[3].GetN(), tm, sdata.fTempSensor[3]*0.1);
876
877 c->Modified();
878 c->Update();
879
880 // ----------------------------------------------
881
882 valarray<double> dat(0., 1438);
883
884 for (int i=0; i<1438; i++)
885 dat[i] = sdata.fRatePatch[fPatch[i]];
886
887 c = fRatesCanv->GetCanvas();
888 Camera *cam = (Camera*)c->FindObject("Camera");
889
890 cam->SetData(dat);
891
892 c->Modified();
893 c->Update();
894#endif
895 }
896
897 FTM::DimStaticData fFtmStaticData;
898
899 void handleFtmStaticData(const DimData &d)
900 {
901 if (d.size()==0)
902 return;
903
904 if (d.size()!=sizeof(FTM::DimStaticData))
905 {
906 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimStaticData) << endl;
907 return;
908 }
909
910 const FTM::DimStaticData &sdata = *reinterpret_cast<const FTM::DimStaticData*>(d.ptr());
911
912 fTriggerInterval->setValue(sdata.fTriggerInterval);
913 fPhysicsCoincidence->setValue(sdata.fCoincidencePhysics);
914 fCalibCoincidence->setValue(sdata.fCoincidenceCalib);
915 fPhysicsWindow->setValue(sdata.fWindowPhysics);
916 fCalibWindow->setValue(sdata.fWindowCalib);
917
918 fTriggerDelay->setValue(sdata.fDelayTrigger);
919 fTimeMarkerDelay->setValue(sdata.fDelayTimeMarker);
920 fDeadTime->setValue(sdata.fDeadTime);
921
922 fClockCondR0->setValue(sdata.fClockConditioner[0]);
923 fClockCondR1->setValue(sdata.fClockConditioner[1]);
924 fClockCondR8->setValue(sdata.fClockConditioner[2]);
925 fClockCondR9->setValue(sdata.fClockConditioner[3]);
926 fClockCondR11->setValue(sdata.fClockConditioner[4]);
927 fClockCondR13->setValue(sdata.fClockConditioner[5]);
928 fClockCondR14->setValue(sdata.fClockConditioner[6]);
929 fClockCondR15->setValue(sdata.fClockConditioner[7]);
930
931 fTriggerSeqPed->setValue(sdata.fTriggerSeqPed);
932 fTriggerSeqLP1->setValue(sdata.fTriggerSeqLP1);
933 fTriggerSeqLP2->setValue(sdata.fTriggerSeqLP2);
934
935 fEnableTrigger->setChecked(sdata.HasTrigger());
936 fEnableLP1->setChecked(sdata.HasLP1());
937 fEnableLP2->setChecked(sdata.HasLP2());
938 fEnableVeto->setChecked(sdata.HasVeto());
939 fEnablePedestal->setChecked(sdata.HasPedestal());
940 fEnableExt1->setChecked(sdata.HasExt1());
941 fEnableExt2->setChecked(sdata.HasExt2());
942 fEnableTimeMarker->setChecked(sdata.HasTimeMarker());
943
944 for (int i=0; i<40; i++)
945 {
946 if (!sdata.IsActive(i))
947 {
948 fFtuLED[i]->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
949 fFtuDisabled[i] = true;
950 }
951 else
952 {
953 if (fFtuDisabled[i])
954 {
955 fFtuLED[i]->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
956 fFtuDisabled[i] = false;
957 }
958 }
959 }
960
961#ifdef HAS_ROOT
962 Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
963 for (int i=0; i<1438; i++)
964 cam->SetEnable(i, sdata.IsEnabled(i));
965#endif
966
967 const int patch1 = fThresholdIdx->value();
968 fThresholdVal->setValue(sdata.fThreshold[patch1<0?0:patch1]);
969
970 fPrescalingVal->setValue(sdata.fPrescaling[0]);
971
972 fFtmStaticData = sdata;
973 }
974
975 void handleFtmPassport(const DimData &d)
976 {
977 if (d.size()==0)
978 return;
979
980 if (d.size()!=sizeof(FTM::DimPassport))
981 {
982 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimPassport) << endl;
983 return;
984 }
985
986 const FTM::DimPassport &sdata = *reinterpret_cast<const FTM::DimPassport*>(d.ptr());
987
988 stringstream str1, str2;
989 str1 << hex << "0x" << setfill('0') << setw(16) << sdata.fBoardId;
990 str2 << sdata.fFirmwareId;
991
992 fFtmBoardId->setText(str1.str().c_str());
993 fFtmFirmwareId->setText(str2.str().c_str());
994 }
995
996 void handleFtmFtuList(const DimData &d)
997 {
998 if (d.size()==0)
999 return;
1000
1001 if (d.size()!=sizeof(FTM::DimFtuList))
1002 {
1003 cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimFtuList) << endl;
1004 return;
1005 }
1006
1007 const FTM::DimFtuList &sdata = *reinterpret_cast<const FTM::DimFtuList*>(d.ptr());
1008
1009 stringstream str;
1010 str << "<table width='100%'>" << setfill('0');
1011 str << "<tr><th>Num</th><th></th><th>Addr</th><th></th><th>DNA</th></tr>";
1012 for (int i=0; i<40; i++)
1013 {
1014 str << "<tr>";
1015 str << "<td align='center'>" << dec << i << hex << "</td>";
1016 str << "<td align='center'>:</td>";
1017 str << "<td align='center'>0x" << setw(2) << (int)sdata.fAddr[i] << "</td>";
1018 str << "<td align='center'>:</td>";
1019 str << "<td align='center'>0x" << setw(16) << sdata.fDNA[i] << "</td>";
1020 str << "</tr>";
1021 }
1022 str << "</table>";
1023
1024 fFtuDNA->setText(str.str().c_str());
1025
1026 fFtuAnswersTotal->setValue(sdata.fNumBoards);
1027 fFtuAnswersCrate0->setValue(sdata.fNumBoardsCrate[0]);
1028 fFtuAnswersCrate1->setValue(sdata.fNumBoardsCrate[1]);
1029 fFtuAnswersCrate2->setValue(sdata.fNumBoardsCrate[2]);
1030 fFtuAnswersCrate3->setValue(sdata.fNumBoardsCrate[3]);
1031
1032 // Same: When error received: Needs decoding
1033 for (int i=0; i<40; i++)
1034 {
1035 if (sdata.IsActive(i))
1036 {
1037 if (sdata.fPing[i]==0)
1038 fFtuLED[i]->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
1039
1040 if (sdata.fPing[i]==1)
1041 fFtuLED[i]->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
1042
1043 if (sdata.fPing[i]>1)
1044 fFtuLED[i]->setIcon(QIcon(":/Resources/icons/orange circle 1.png"));
1045
1046 fFtuDisabled[i] = false;
1047 }
1048 else
1049 {
1050 fFtuLED[i]->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
1051 fFtuDisabled[i] = true;
1052 }
1053
1054 }
1055 }
1056
1057 void handleFtmError(const DimData &d)
1058 {
1059 if (d.size()==0)
1060 return;
1061
1062 const Converter conv(d.format);
1063 cout << "Error:" << endl;
1064 cout << conv.GetString(&d.data[0], d.size()) << endl;
1065 }
1066
1067 // ====================== MessageImp ====================================
1068
1069 bool fChatOnline;
1070
1071 void handleStateChanged(const Time &/*time*/, const std::string &server,
1072 const State &s)
1073 {
1074 // FIXME: Prefix tooltip with time
1075 if (server=="FTM_CONTROL")
1076 {
1077 fStatusFTMLabel->setText(s.name.c_str());
1078 fStatusFTMLabel->setToolTip(s.comment.c_str());
1079
1080 bool enable = false;
1081
1082 if (s.index<FTM::kDisconnected) // No Dim connection
1083 fStatusFTMLed->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
1084 if (s.index==FTM::kDisconnected) // Dim connection / FTM disconnected
1085 fStatusFTMLed->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
1086 if (s.index==FTM::kConnected || s.index==FTM::kIdle) // Dim connection / FTM connected
1087 {
1088 fStatusFTMLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
1089 enable = true;
1090 }
1091
1092 fTriggerWidget->setEnabled(enable);
1093 fFtuWidget->setEnabled(enable);
1094 fRatesWidget->setEnabled(enable);
1095 }
1096
1097 if (server=="FAD_CONTROL")
1098 {
1099 fStatusFADLabel->setText(s.name.c_str());
1100 fStatusFADLabel->setToolTip(s.comment.c_str());
1101
1102 if (s.index<FTM::kDisconnected) // No Dim connection
1103 fStatusFADLed->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
1104 if (s.index==FTM::kDisconnected) // Dim connection / FTM disconnected
1105 fStatusFADLed->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
1106 if (s.index==FTM::kConnected) // Dim connection / FTM connected
1107 fStatusFADLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
1108 }
1109
1110 if (server=="DATA_LOGGER")
1111 {
1112 fStatusLoggerLabel->setText(s.name.c_str());
1113 fStatusLoggerLabel->setToolTip(s.comment.c_str());
1114
1115 bool enable = true;
1116
1117 if (s.index<=30) // Ready/Waiting
1118 fStatusLoggerLed->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
1119 if (s.index<-1) // Offline
1120 {
1121 fStatusLoggerLed->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
1122 enable = false;
1123 }
1124 if (s.index>=0x100) // Error
1125 fStatusLoggerLed->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
1126 if (s.index==40) // Logging
1127 fStatusLoggerLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
1128
1129 fLoggerWidget->setEnabled(enable);
1130 }
1131
1132 if (server=="CHAT")
1133 {
1134 fStatusChatLabel->setText(s.name.c_str());
1135
1136 fChatOnline = s.index==0;
1137
1138 if (fChatOnline) // Dim connection / FTM connected
1139 fStatusChatLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
1140 else
1141 fStatusChatLed->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
1142 }
1143 }
1144
1145 void handleStateOffline(const string &server)
1146 {
1147 handleStateChanged(Time(), server, State(-2, "Offline", "No connection via DIM."));
1148 }
1149
1150 void on_fTabWidget_currentChanged(int which)
1151 {
1152 if (fTabWidget->tabText(which)=="Chat")
1153 fTabWidget->setTabIcon(which, QIcon());
1154 }
1155
1156 void handleWrite(const Time &time, const string &text, int qos)
1157 {
1158 stringstream out;
1159
1160 if (text.substr(0, 6)=="CHAT: ")
1161 {
1162 out << "<font size='-1' color='navy'>[<B>";
1163 out << Time::fmt("%H:%M:%S") << time << "</B>]</FONT> ";
1164 out << text.substr(6);
1165 fChatText->append(out.str().c_str());
1166
1167 if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
1168 return;
1169
1170 static int num = 0;
1171 if (num++<2)
1172 return;
1173
1174 for (int i=0; i<fTabWidget->count(); i++)
1175 if (fTabWidget->tabText(i)=="Chat")
1176 {
1177 fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
1178 break;
1179 }
1180
1181 return;
1182 }
1183
1184
1185 out << "<font color='";
1186
1187 switch (qos)
1188 {
1189 case kMessage: out << "black"; break;
1190 case kInfo: out << "green"; break;
1191 case kWarn: out << "#FF6600"; break;
1192 case kError: out << "maroon"; break;
1193 case kFatal: out << "maroon"; break;
1194 case kDebug: out << "navy"; break;
1195 default: out << "navy"; break;
1196 }
1197 out << "'>" << time.GetAsStr() << " - " << text << "</font>";
1198
1199 fLogText->append(out.str().c_str());
1200
1201 if (qos>=kWarn)
1202 fTextEdit->append(out.str().c_str());
1203 }
1204
1205 void IndicateStateChange(const Time &time, const std::string &server)
1206 {
1207 const State s = GetState(server, GetCurrentState(server));
1208
1209 QApplication::postEvent(this,
1210 new FunctionEvent(boost::bind(&FactGui::handleStateChanged, this, time, server, s)));
1211 }
1212
1213 int Write(const Time &time, const string &txt, int qos)
1214 {
1215 QApplication::postEvent(this,
1216 new FunctionEvent(boost::bind(&FactGui::handleWrite, this, time, txt, qos)));
1217
1218 return 0;
1219 }
1220
1221 // ====================== Dim infoHandler================================
1222
1223 void handleDimInfo(const DimData &d)
1224 {
1225 if (d.info==&fDimDNS)
1226 return handleDimDNS(d.get<unsigned int>());
1227
1228 cout << "HandleDimInfo " << d.name << endl;
1229
1230 if (d.info==&fDimLoggerStats)
1231 return handleLoggerStats(d);
1232
1233 if (d.info==&fDimLoggerFilenameNight)
1234 return handleLoggerFilenameNight(d);
1235
1236 if (d.info==&fDimLoggerNumSubs)
1237 return handleLoggerNumSubs(d);
1238
1239 if (d.info==&fDimLoggerFilenameRun)
1240 return handleLoggerFilenameRun(d);
1241
1242 if (d.info==&fDimFtmTriggerCounter)
1243 return handleFtmTriggerCounter(d);
1244
1245 if (d.info==&fDimFtmDynamicData)
1246 return handleFtmDynamicData(d);
1247
1248 if (d.info==&fDimFtmPassport)
1249 return handleFtmPassport(d);
1250
1251 if (d.info==&fDimFtmFtuList)
1252 return handleFtmFtuList(d);
1253
1254 if (d.info==&fDimFtmStaticData)
1255 return handleFtmStaticData(d);
1256
1257 if (d.info==&fDimFtmError)
1258 return handleFtmError(d);
1259 }
1260
1261 void handleDimService(const string &txt)
1262 {
1263 fDimSvcText->append(txt.c_str());
1264 }
1265
1266
1267 void infoHandlerService(DimInfo &info)
1268 {
1269 const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
1270
1271 stringstream dummy;
1272 const Converter conv(dummy, fmt, false);
1273
1274 const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
1275
1276 stringstream out;
1277 out << "<font size'-1' color='navy'>[" << Time::fmt("%H:%M:%S.%f") << tm << "]</font> <B>" << info.getName() << "</B> - ";
1278
1279 bool iserr = true;
1280 if (!conv)
1281 {
1282 out << "Compilation of format string '" << fmt << "' failed!";
1283 }
1284 else
1285 {
1286 try
1287 {
1288 const string dat = conv.GetString(info.getData(), info.getSize());
1289 out << dat;
1290 iserr = false;
1291 }
1292 catch (const runtime_error &e)
1293 {
1294 out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
1295 }
1296 }
1297
1298 // srand(hash<string>()(string(info.getName())));
1299 // int bg = rand()&0xffffff;
1300
1301 int bg = hash<string>()(string(info.getName()));
1302
1303 // allow only light colors
1304 bg = ~(bg&0x1f1f1f)&0xffffff;
1305
1306 if (iserr)
1307 bg = 0xffffff;
1308
1309 stringstream bgcol;
1310 bgcol << hex << setfill('0') << setw(6) << bg;
1311
1312 const string col = iserr ? "red" : "black";
1313 const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
1314
1315 QApplication::postEvent(this,
1316 new FunctionEvent(boost::bind(&FactGui::handleDimService, this, str)));
1317 }
1318
1319 void infoHandler()
1320 {
1321 // Initialize the time-stamp (what a weird workaround...)
1322 getInfo()->getTimestamp();
1323
1324 if (std::find(fDim.begin(), fDim.end(), getInfo())!=fDim.end())
1325 {
1326 QApplication::postEvent(this,
1327 new FunctionEvent(boost::bind(&FactGui::handleDimInfo, this, DimData(getInfo()))));
1328 return;
1329 }
1330
1331 for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
1332 if (i->second==getInfo())
1333 {
1334 infoHandlerService(*i->second);
1335 return;
1336 }
1337
1338 DimNetwork::infoHandler();
1339 }
1340
1341
1342 // ======================================================================
1343
1344 bool event(QEvent *evt)
1345 {
1346 if (dynamic_cast<FunctionEvent*>(evt))
1347 return static_cast<FunctionEvent*>(evt)->Exec();
1348
1349 if (dynamic_cast<CheckBoxEvent*>(evt))
1350 {
1351 const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
1352 const QStandardItem *par = item.parent();
1353 if (par)
1354 {
1355 const QString server = par->text();
1356 const QString service = item.text();
1357
1358 const string s = (server+'/'+service).toStdString();
1359
1360 if (item.checkState()==Qt::Checked)
1361 SubscribeService(s);
1362 else
1363 UnsubscribeService(s);
1364 }
1365 }
1366
1367 return MainWindow::event(evt); // unrecognized
1368 }
1369
1370 void on_fDimCmdSend_clicked()
1371 {
1372 const QString server = fDimCmdServers->currentIndex().data().toString();
1373 const QString command = fDimCmdCommands->currentIndex().data().toString();
1374 const QString arguments = fDimCmdLineEdit->displayText();
1375
1376 // FIXME: Sending a command exactly when the info Handler changes
1377 // the list it might lead to confusion.
1378 try
1379 {
1380 SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
1381 fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
1382 fDimCmdLineEdit->clear();
1383 }
1384 catch (const runtime_error &e)
1385 {
1386 stringstream txt;
1387 txt << e.what();
1388
1389 string buffer;
1390 while (getline(txt, buffer, '\n'))
1391 fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
1392 }
1393 }
1394 void ChoosePatch(Camera &cam, int idx)
1395 {
1396 cam.Reset();
1397
1398 fThresholdIdx->setValue(idx);
1399 fThresholdVal->setValue(fFtmStaticData.fThreshold[idx<0?0:idx]);
1400
1401 if (idx<0)
1402 return;
1403
1404 for (unsigned int i=0; i<fPatch.size(); i++)
1405 if (fPatch[i]==idx)
1406 cam.SetBold(i);
1407 }
1408
1409 void ChoosePixel(Camera &cam, int idx)
1410 {
1411 cam.SetWhite(idx);
1412 ChoosePatch(cam, fPatch[idx]);
1413 }
1414
1415#ifdef HAS_ROOT
1416 void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *)
1417 {
1418 // kMousePressEvent // TCanvas processed QEvent mousePressEvent
1419 // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
1420 // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
1421 // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
1422 // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
1423 // kEnterEvent // TCanvas processed QEvent enterEvent
1424 // kLeaveEvent // TCanvas processed QEvent leaveEvent
1425 if (dynamic_cast<TCanvas*>(obj))
1426 return;
1427
1428 TQtWidget *tipped = static_cast<TQtWidget*>(sender());
1429
1430 if (evt==11/*kMouseReleaseEvent*/)
1431 {
1432 if (dynamic_cast<Camera*>(obj))
1433 {
1434 const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
1435 const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
1436
1437 Camera *cam = static_cast<Camera*>(obj);
1438 const int idx = cam->GetIdx(xx, yy);
1439
1440 ChoosePixel(*cam, idx);
1441 }
1442 return;
1443 }
1444
1445 if (evt==61/*kMouseDoubleClickEvent*/)
1446 {
1447 if (dynamic_cast<Camera*>(obj))
1448 {
1449 const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
1450 const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
1451
1452 Camera *cam = static_cast<Camera*>(obj);
1453 const int idx = cam->GetIdx(xx, yy);
1454
1455 cam->Toggle(idx);
1456 }
1457 return;
1458 }
1459
1460 // Find the object which will get picked by the GetObjectInfo
1461 // due to buffer overflows in many root-versions
1462 // in TH1 and TProfile we have to work around and implement
1463 // our own GetObjectInfo which make everything a bit more
1464 // complicated.
1465#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
1466 const char *objectInfo =
1467 obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
1468#else
1469 const char *objectInfo = dynamic_cast<TH1*>(obj) ?
1470 "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
1471#endif
1472
1473 QString tipText;
1474 tipText += obj->GetName();
1475 tipText += " [";
1476 tipText += obj->ClassName();
1477 tipText += "]: ";
1478 tipText += objectInfo;
1479
1480 if (dynamic_cast<Camera*>(obj))
1481 {
1482 const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
1483 const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
1484
1485 Camera *cam = static_cast<Camera*>(obj);
1486 int idx = fPatch[cam->GetIdx(xx, yy)];
1487
1488 tipText+=" Patch=";
1489 tipText+=QString::number(idx);
1490 }
1491
1492
1493 fStatusBar->showMessage(tipText, 3000);
1494
1495 gSystem->ProcessEvents();
1496 //QWhatsThis::display(tipText)
1497 }
1498
1499 void slot_RootUpdate()
1500 {
1501 gSystem->ProcessEvents();
1502 QTimer::singleShot(0, this, SLOT(slot_RootUpdate()));
1503 }
1504
1505 void on_fThresholdIdx_valueChanged(int idx)
1506 {
1507 Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
1508 ChoosePatch(*cam, idx);
1509 }
1510#endif
1511
1512 TGraph fGraphFtmTemp[4];
1513
1514 map<int, int> fPatch;
1515
1516public:
1517 FactGui() :
1518 fFtuDisabled(40),
1519 fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
1520
1521 fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
1522 fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHT", const_cast<char*>(""), 0, this),
1523 fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", const_cast<char*>(""), 0, this),
1524 fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", const_cast<char*>(""), 0, this),
1525
1526 fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
1527 fDimFtmTriggerCounter("FTM_CONTROL/TRIGGER_COUNTER", (void*)NULL, 0, this),
1528 fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
1529 fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
1530 fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
1531 fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this)
1532
1533
1534 {
1535 DimClient::sendCommand("CHAT/MSG", "GUI online.");
1536 // + MessageDimRX
1537
1538 fDim.push_back(&fDimFtmDynamicData);
1539 fDim.push_back(&fDimFtmTriggerCounter);
1540 fDim.push_back(&fDimFtmStaticData);
1541 fDim.push_back(&fDimFtmFtuList);
1542 fDim.push_back(&fDimFtmPassport);
1543 fDim.push_back(&fDimFtmError);
1544 fDim.push_back(&fDimLoggerStats);
1545 fDim.push_back(&fDimLoggerFilenameNight);
1546 fDim.push_back(&fDimLoggerFilenameRun);
1547 fDim.push_back(&fDimLoggerNumSubs);
1548 fDim.push_back(&fDimDNS);
1549
1550 fTriggerWidget->setEnabled(false);
1551 fFtuWidget->setEnabled(false);
1552 fRatesWidget->setEnabled(false);
1553 fLoggerWidget->setEnabled(false);
1554
1555 // --------------------------------------------------------------------------
1556
1557 ifstream fin("fact-trigger-all.txt");
1558
1559 int l = 0;
1560
1561 string buf;
1562 while (getline(fin, buf, '\n'))
1563 {
1564 buf = Tools::Trim(buf);
1565 if (buf[0]=='#')
1566 continue;
1567
1568 stringstream str(buf);
1569 for (int i=0; i<9; i++)
1570 {
1571 int n;
1572 str >> n;
1573
1574 fPatch[n] = l;
1575 }
1576 l++;
1577 }
1578
1579 // --------------------------------------------------------------------------
1580#ifdef HAS_ROOT
1581 TCanvas *c = fFtmTempCanv->GetCanvas();
1582 c->SetBit(TCanvas::kNoContextMenu);
1583 c->SetBorderMode(0);
1584 c->SetFrameBorderMode(0);
1585 c->SetFillColor(kWhite);
1586 c->SetRightMargin(0.03);
1587 c->SetTopMargin(0.03);
1588 c->cd();
1589
1590 TH1F h("MyFrame", "", 1000, 0, 1);//Time().RootTime()-1./24/60/60, Time().RootTime());
1591 h.SetDirectory(0);
1592 h.SetBit(TH1::kCanRebin);
1593 h.SetStats(kFALSE);
1594 h.SetMinimum(-20);
1595 h.SetMaximum(100);
1596 h.SetXTitle("Time");
1597 h.SetYTitle("Temperature / °C");
1598 h.GetXaxis()->CenterTitle();
1599 h.GetYaxis()->CenterTitle();
1600// h.GetXaxis()->SetTitleSize(1.2);
1601// h.GetYaxis()->SetTitleSize(1.2);
1602 h.DrawCopy();
1603
1604 fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
1605 fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
1606 fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
1607 fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
1608
1609 fGraphFtmTemp[1].SetLineColor(kBlue);
1610 fGraphFtmTemp[2].SetLineColor(kRed);
1611 fGraphFtmTemp[3].SetLineColor(kGreen);
1612
1613 fGraphFtmTemp[1].SetMarkerColor(kBlue);
1614 fGraphFtmTemp[2].SetMarkerColor(kRed);
1615 fGraphFtmTemp[3].SetMarkerColor(kGreen);
1616
1617 fGraphFtmTemp[0].Draw("LP");
1618 fGraphFtmTemp[1].Draw("LP");
1619 fGraphFtmTemp[2].Draw("LP");
1620 fGraphFtmTemp[3].Draw("LP");
1621
1622 // --------------------------------------------------------------------------
1623
1624 c = fRatesCanv->GetCanvas();
1625 c->SetBit(TCanvas::kNoContextMenu);
1626 c->SetBorderMode(0);
1627 c->SetFrameBorderMode(0);
1628 c->SetFillColor(kWhite);
1629 c->cd();
1630
1631 Camera *cam = new Camera;
1632 cam->SetBit(kCanDelete);
1633 cam->Draw();
1634
1635 ChoosePixel(*cam, 1);
1636
1637// QTimer::singleShot(0, this, SLOT(slot_RootUpdate()));
1638
1639 //widget->setMouseTracking(true);
1640 //widget->EnableSignalEvents(kMouseMoveEvent);
1641
1642 fFtmTempCanv->setMouseTracking(true);
1643 fFtmTempCanv->EnableSignalEvents(kMouseMoveEvent);
1644
1645 fRatesCanv->setMouseTracking(true);
1646 fRatesCanv->EnableSignalEvents(kMouseMoveEvent|kMouseReleaseEvent|kMouseDoubleClickEvent);
1647
1648 connect(fRatesCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
1649 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
1650 connect(fFtmTempCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
1651 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
1652#endif
1653 }
1654
1655 ~FactGui()
1656 {
1657 UnsubscribeAllServers();
1658 }
1659};
1660
1661#endif
Note: See TracBrowser for help on using the repository browser.