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

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