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

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