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

Last change on this file since 11803 was 11803, checked in by tbretz, 13 years ago
Fixed text displayed in CameraMouseMove
File size: 108.0 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 "TH2.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 (dynamic_cast<TH2*>(h) && !fAdcPersistant->isChecked()) ||
1182 (!dynamic_cast<TH2*>(h) && fAdcPersistant->isChecked()))
1183 {
1184 delete hf;
1185 delete h;
1186 delete d0;
1187 delete d1;
1188 delete d2;
1189 hf = 0;
1190 }
1191
1192 if (!hf)
1193 {
1194 c->cd();
1195
1196 const int roi = fEventData->Roi>0 ? fEventData->Roi : 1;
1197
1198 hf = new TH1F("Frame", "", roi, -0.5, roi-0.5);
1199 hf->SetDirectory(0);
1200 hf->SetBit(kCanDelete);
1201 hf->SetStats(kFALSE);
1202 hf->SetYTitle("Voltage [mV]");
1203 hf->GetXaxis()->CenterTitle();
1204 hf->GetYaxis()->CenterTitle();
1205 hf->SetMinimum(-1250);
1206 hf->SetMaximum(2150);
1207
1208 if (!fAdcPersistant->isChecked())
1209 h = new TH1F("EventData", "", roi, -0.5, roi-0.5);
1210 else
1211 {
1212 h = new TH2F("EventData", "", roi, -0.5, roi-0.5, 3301, -1150.5, 2150.5);
1213 h->SetContour(50);
1214 gStyle->SetPalette(1, 0);
1215 }
1216
1217 h->SetDirectory(0);
1218 h->SetBit(kCanDelete);
1219 h->SetMarkerStyle(kFullDotMedium);
1220 h->SetMarkerColor(kBlue);
1221
1222
1223 d0 = new TH1F("DrsCalib0", "", roi, -0.5, roi-0.5);
1224 d0->SetDirectory(0);
1225 d0->SetBit(kCanDelete);
1226 d0->SetMarkerStyle(kFullDotSmall);
1227 d0->SetMarkerColor(kRed);
1228 d0->SetLineColor(kRed);
1229
1230 d1 = new TH1F("DrsCalib1", "", roi, -0.5, roi-0.5);
1231 d1->SetDirectory(0);
1232 d1->SetBit(kCanDelete);
1233 d1->SetMarkerStyle(kFullDotSmall);
1234 d1->SetMarkerColor(kMagenta);
1235 d1->SetLineColor(kMagenta);
1236
1237 d2 = new TH1F("DrsCalib2", "", roi, -0.5, roi-0.5);
1238 d2->SetDirectory(0);
1239 d2->SetBit(kCanDelete);
1240 d2->SetMarkerStyle(kFullDotSmall);
1241 d2->SetMarkerColor(kGreen);
1242 d2->SetLineColor(kGreen);
1243
1244 hf->Draw("");
1245
1246 if (dynamic_cast<TH2*>(h))
1247 h->Draw("col same");
1248
1249 d0->Draw("PEX0same");
1250 d1->Draw("PEX0same");
1251 d2->Draw("PEX0same");
1252
1253 if (!dynamic_cast<TH2*>(h))
1254 h->Draw("PLsame");
1255
1256 gPad = NULL;
1257 }
1258
1259 // -----------------------------------------------------------
1260
1261 const uint32_t p =
1262 fAdcChannel->value() +
1263 fAdcChip->value() * 9+
1264 fAdcBoard->value() * 36+
1265 fAdcCrate->value() *360;
1266
1267 ostringstream str;
1268 str << "EventNum = " << fEventData->EventNum;
1269 str << " TriggerNum = " << fEventData->TriggerNum;
1270 str << " TriggerType = " << fEventData->TriggerType;
1271 str << " BoardTime = " << fEventData->BoardTime[fAdcBoard->value()+fAdcCrate->value()*10];
1272 str << " (" << Time(fEventData->PCTime, fEventData->PCUsec) << ")";
1273 hf->SetTitle(str.str().c_str());
1274 str.str("");
1275 str << "ADC Pipeline (start cell: " << fEventData->StartPix[p] << ")";
1276 hf->SetXTitle(str.str().c_str());
1277
1278 // -----------------------------------------------------------
1279
1280 const int16_t start = fEventData->StartPix[p];
1281 if (fDrsRuns[0]==0 || start<0)
1282 d0->Reset();
1283 if (fDrsRuns[1]==0 || start<0)
1284 d1->Reset();
1285 if (fDrsRuns[2]==0 || start<0)
1286 d2->Reset();
1287
1288 if (!dynamic_cast<TH2*>(h))
1289 h->Reset();
1290 d0->SetEntries(0);
1291 d1->SetEntries(0);
1292 d2->SetEntries(0);
1293
1294 for (int i=0; i<fEventData->Roi; i++)
1295 {
1296 //if (dynamic_cast<TH2*>(h))
1297 h->Fill(i, reinterpret_cast<float*>(fEventData->Adc_Data)[p*fEventData->Roi+i]);
1298 //else
1299 // h->SetBinContent(i+1, reinterpret_cast<float*>(fEventData->Adc_Data)[p*fEventData->Roi+i]);
1300 if (start<0)
1301 continue;
1302
1303 if (fDrsRuns[0]>0)
1304 {
1305 d0->SetBinContent(i+1, fDrsCalibration[1440*1024*0 + p*1024+(start+i)%1024]);
1306 d0->SetBinError(i+1, fDrsCalibration[1440*1024*1 + p*1024+(start+i)%1024]);
1307
1308 }
1309 if (fDrsRuns[1]>0)
1310 {
1311 d1->SetBinContent(i+1, fDrsCalibration[1440*1024*2 + p*1024+(start+i)%1024]);
1312 d1->SetBinError(i+1, fDrsCalibration[1440*1024*3 + p*1024+(start+i)%1024]);
1313 }
1314 if (fDrsRuns[2]>0)
1315 {
1316 d2->SetBinContent(i+1, fDrsCalibration[1440*1024*4 + p*1024 + i]);
1317 d2->SetBinError(i+1, fDrsCalibration[1440*1024*5 + p*1024 + i]);
1318 }
1319 }
1320
1321 // -----------------------------------------------------------
1322 if (fAdcDynamicScale->isEnabled() && fAdcDynamicScale->isChecked())
1323 {
1324 h->SetMinimum();
1325 h->SetMaximum();
1326
1327 hf->SetMinimum(h->GetMinimum());
1328 hf->SetMaximum(h->GetMaximum());
1329 }
1330 if (fAdcManualScale->isEnabled() && fAdcManualScale->isChecked())
1331 {
1332 if (h->GetMinimumStored()==-1111)
1333 {
1334 h->SetMinimum(-1150);//-1026);
1335 hf->SetMinimum(-1150);//-1026);
1336 }
1337 if (h->GetMaximumStored()==-1111)
1338 {
1339 h->SetMaximum(2150);//1025);
1340 hf->SetMaximum(2150);//1025);
1341 }
1342 }
1343
1344 if (fAdcAutoScale->isEnabled() && fAdcAutoScale->isChecked())
1345 {
1346 h->SetMinimum();
1347 h->SetMaximum();
1348
1349 if (h->GetMinimum()<hf->GetMinimum())
1350 hf->SetMinimum(h->GetMinimum());
1351 if (h->GetMaximum()>hf->GetMaximum())
1352 hf->SetMaximum(h->GetMaximum());
1353 }
1354
1355 if (dynamic_cast<TH2*>(h))
1356 {
1357 h->SetMinimum();
1358 h->SetMaximum();
1359 }
1360
1361 // -----------------------------------------------------------
1362
1363 const int imin = ceil(hf->GetMinimum());
1364 const int imax = floor(hf->GetMaximum());
1365
1366 TH1S hd("", "", imax-imin+1, imin-0.5, imax+0.5);
1367 hd.SetDirectory(0);
1368 TH1S h0("", "", imax-imin+1, imin-0.5, imax+0.5);
1369 h0.SetDirectory(0);
1370 TH1S h1("", "", imax-imin+1, imin-0.5, imax+0.5);
1371 h1.SetDirectory(0);
1372 TH1S h2("", "", imax-imin+1, imin-0.5, imax+0.5);
1373 h2.SetDirectory(0);
1374 hd.SetLineColor(h->GetLineColor());
1375 h0.SetLineColor(d0->GetLineColor());
1376 h1.SetLineColor(d1->GetLineColor());
1377 h2.SetLineColor(d2->GetLineColor());
1378
1379 for (int i=0; i<fEventData->Roi; i++)
1380 {
1381 if (!dynamic_cast<TH2*>(h))
1382 hd.Fill(h->GetBinContent(i+1));
1383 h0.Fill(d0->GetBinContent(i+1));
1384 h1.Fill(d1->GetBinContent(i+1));
1385 h2.Fill(d2->GetBinContent(i+1));
1386 }
1387
1388 double mm = hd.GetMaximum(hd.GetEntries());
1389 if (h0.GetMaximum(h0.GetEntries())>mm)
1390 mm = h0.GetMaximum();
1391 if (h1.GetMaximum(h1.GetEntries())>mm)
1392 mm = h1.GetMaximum();
1393 if (h2.GetMaximum(h2.GetEntries())>mm)
1394 mm = h2.GetMaximum();
1395
1396 TIter Next(hf->GetListOfFunctions());
1397 TObject *obj = 0;
1398 while ((obj=Next()))
1399 if (dynamic_cast<TBox*>(obj))
1400 delete hf->GetListOfFunctions()->Remove(obj);
1401
1402 const double l = h->GetBinLowEdge(h->GetXaxis()->GetLast()+1);
1403 const double m = c->GetX2();
1404
1405 const double scale = 0.9*(m-l)/mm;
1406
1407 c->cd();
1408
1409 DrawHorizontal(hf, l, h2, scale);
1410 DrawHorizontal(hf, l, h1, scale);
1411 DrawHorizontal(hf, l, h0, scale);
1412 DrawHorizontal(hf, l, hd, scale);
1413
1414 // -----------------------------------------------------------
1415
1416 c->Modified();
1417 c->Update();
1418#endif
1419 }
1420
1421 void handleFadRawData(const DimData &d)
1422 {
1423 if (d.size()==0)
1424 return;
1425
1426 if (fAdcStop->isChecked())
1427 return;
1428
1429 const EVENT &dat = d.ref<EVENT>();
1430
1431 if (d.size()<sizeof(EVENT))
1432 {
1433 cout << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected>=" << sizeof(EVENT) << endl;
1434 return;
1435 }
1436
1437 if (d.size()!=sizeof(EVENT)+dat.Roi*4*1440)
1438 {
1439 cout << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected=" << dat.Roi*4*1440+sizeof(EVENT) << " [roi=" << dat.Roi << "]" << endl;
1440 return;
1441 }
1442
1443 delete fEventData;
1444 fEventData = reinterpret_cast<EVENT*>(new char[d.size()]);
1445 memcpy(fEventData, d.ptr<void>(), d.size());
1446
1447 DisplayEventData();
1448 }
1449
1450 void handleFadEventData(const DimData &d)
1451 {
1452 if (!CheckSize(d, 4*1440*sizeof(float)))
1453 return;
1454
1455// static int cnt=0;
1456// if (cnt++%10>0)
1457// return;
1458
1459 const float *ptr = d.ptr<float>();
1460
1461// TCanvas *c = fEventCanv->GetCanvas();
1462 Camera *cam1 = fEventCanv1;//(Camera*)c->GetPad(1)->FindObject("Camera");
1463 Camera *cam2 = fEventCanv2;//(Camera*)c->GetPad(2)->FindObject("Camera");
1464 Camera *cam3 = fEventCanv3;//(Camera*)c->GetPad(3)->FindObject("Camera");
1465 Camera *cam4 = fEventCanv4;//(Camera*)c->GetPad(4)->FindObject("Camera");
1466
1467 valarray<double> arr1(1440);
1468 valarray<double> arr2(1440);
1469 valarray<double> arr3(1440);
1470 valarray<double> arr4(1440);
1471
1472 for (int i=0; i<1440; i++)
1473 {
1474 arr1[i] = ptr[0*1440+fPixelMapHW[i]];
1475 arr2[i] = ptr[1*1440+fPixelMapHW[i]];
1476 arr3[i] = ptr[2*1440+fPixelMapHW[i]];
1477 arr4[i] = ptr[3*1440+fPixelMapHW[i]];
1478 }
1479
1480 cam1->SetData(arr1);
1481 cam2->SetData(arr2);
1482 cam3->SetData(arr3);
1483 cam4->SetData(arr4);
1484
1485// c->GetPad(1)->Modified();
1486// c->GetPad(2)->Modified();
1487// c->GetPad(3)->Modified();
1488// c->GetPad(4)->Modified();
1489
1490// c->Update();
1491 }
1492
1493 uint32_t fDrsRuns[3];
1494 vector<float> fDrsCalibration;
1495
1496 void handleFadDrsCalibration(const DimData &d)
1497 {
1498 if (d.size()==0)
1499 {
1500 fDrsRuns[0] = 0;
1501 fDrsRuns[1] = 0;
1502 fDrsRuns[2] = 0;
1503 fDrsCalibration.assign(1024*1440*6, 0);
1504 DisplayEventData();
1505 return;
1506 }
1507
1508 if (!CheckSize(d, 1024*1440*6*sizeof(float)+3*sizeof(uint32_t)))
1509 // Do WHAT?
1510 return;
1511
1512 const uint32_t *run = d.ptr<uint32_t>();
1513 fDrsRuns[0] = run[0];
1514 fDrsRuns[1] = run[1];
1515 fDrsRuns[2] = run[2];
1516
1517 const float *dat = d.ptr<float>(sizeof(uint32_t)*3);
1518 fDrsCalibration.assign(dat, dat+1024*1440*6);
1519
1520 DisplayEventData();
1521 }
1522
1523// vector<uint8_t> fFadConnections;
1524
1525 void handleFadConnections(const DimData &d)
1526 {
1527 if (!CheckSize(d, 41))
1528 {
1529 fStatusEventBuilderLabel->setText("Offline");
1530 fStatusEventBuilderLabel->setToolTip("FADs or fadctrl seems to be offline.");
1531 fEvtBldWidget->setEnabled(false);
1532
1533 SetLedColor(fStatusEventBuilderLed, kLedGray, d.time);
1534 return;
1535 }
1536
1537 const uint8_t *ptr = d.ptr<uint8_t>();
1538
1539 for (int i=0; i<40; i++)
1540 {
1541 const uint8_t stat1 = ptr[i]&3;
1542 const uint8_t stat2 = ptr[i]>>3;
1543
1544 if (stat1==0 && stat2==0)
1545 {
1546 SetLedColor(fFadLED[i], kLedGray, d.time);
1547 continue;
1548 }
1549 if (stat1==2 && stat2==8)
1550 {
1551 SetLedColor(fFadLED[i], kLedGreen, d.time);
1552 continue;
1553 }
1554
1555 if (stat1==1 && stat2==1)
1556 SetLedColor(fFadLED[i], kLedRed, d.time);
1557 else
1558 SetLedColor(fFadLED[i], kLedOrange, d.time);
1559 }
1560
1561
1562 const bool runs = ptr[40]!=0;
1563
1564 fStatusEventBuilderLabel->setText(runs?"Running":"Not running");
1565 fStatusEventBuilderLabel->setToolTip(runs?"Event builder thread running.":"Event builder thread stopped.");
1566 fEvtBldWidget->setEnabled(runs);
1567
1568 SetLedColor(fStatusEventBuilderLed, runs?kLedGreen:kLedRed, d.time);
1569
1570// fFadConnections.assign(ptr, ptr+40);
1571 }
1572
1573 template<typename T>
1574 void handleFadToolTip(const Time &time, QWidget *w, T *ptr)
1575 {
1576 ostringstream tip;
1577 tip << "<table border='1'><tr><th colspan='11'>" << time.GetAsStr() << " (UTC)</th></tr><tr><th></th>";
1578 for (int b=0; b<10; b++)
1579 tip << "<th>" << b << "</th>";
1580 tip << "</tr>";
1581
1582 for (int c=0; c<4; c++)
1583 {
1584 tip << "<tr><th>" << c << "</th>";
1585 for (int b=0; b<10; b++)
1586 tip << "<td>" << ptr[c*10+b] << "</td>";
1587 tip << "</tr>";
1588 }
1589 tip << "</table>";
1590
1591 w->setToolTip(tip.str().c_str());
1592 }
1593
1594 template<typename T, class S>
1595 void handleFadMinMax(const DimData &d, QPushButton *led, S *wmin, S *wmax=0)
1596 {
1597 if (!CheckSize(d, 42*sizeof(T)))
1598 return;
1599
1600 const T *ptr = d.ptr<T>();
1601 const T min = ptr[40];
1602 const T max = ptr[41];
1603
1604 if (max==0 && min>max)
1605 SetLedColor(led, kLedGray, d.time);
1606 else
1607 SetLedColor(led, min==max?kLedGreen: kLedOrange, d.time);
1608
1609 if (!wmax && max!=min)
1610 wmin->setValue(0);
1611 else
1612 wmin->setValue(min);
1613
1614 if (wmax)
1615 wmax->setValue(max);
1616
1617 handleFadToolTip(d.time, led, ptr);
1618 }
1619
1620 void handleFadFwVersion(const DimData &d)
1621 {
1622 handleFadMinMax<float, QDoubleSpinBox>(d, fFadLedFwVersion, fFadFwVersion);
1623 }
1624
1625 void handleFadRunNumber(const DimData &d)
1626 {
1627 handleFadMinMax<uint32_t, QSpinBox>(d, fFadLedRunNumber, fFadRunNumber);
1628 }
1629
1630 void handleFadPrescaler(const DimData &d)
1631 {
1632 handleFadMinMax<uint16_t, QSpinBox>(d, fFadLedPrescaler, fFadPrescaler);
1633 }
1634
1635 void handleFadDNA(const DimData &d)
1636 {
1637 if (!CheckSize(d, 40*sizeof(uint64_t)))
1638 return;
1639
1640 const uint64_t *ptr = d.ptr<uint64_t>();
1641
1642 ostringstream tip;
1643 tip << "<table width='100%'>";
1644 tip << "<tr><th>Crate</th><td></td><th>Board</th><td></td><th>DNA</th></tr>";
1645
1646 for (int i=0; i<40; i++)
1647 {
1648 tip << dec;
1649 tip << "<tr>";
1650 tip << "<td align='center'>" << i/10 << "</td><td>:</td>";
1651 tip << "<td align='center'>" << i%10 << "</td><td>:</td>";
1652 tip << hex;
1653 tip << "<td>0x" << setfill('0') << setw(16) << ptr[i] << "</td>";
1654 tip << "</tr>";
1655 }
1656 tip << "</table>";
1657
1658 fFadDNA->setText(tip.str().c_str());
1659 }
1660
1661 void SetFadLed(QPushButton *led, const DimData &d, uint16_t bitmask, bool invert=false)
1662 {
1663 if (d.size()==0)
1664 {
1665 SetLedColor(led, kLedGray, d.time);
1666 return;
1667 }
1668
1669 const bool quality = d.ptr<uint16_t>()[0]&bitmask;
1670 const bool value = d.ptr<uint16_t>()[1]&bitmask;
1671 const uint16_t *ptr = d.ptr<uint16_t>()+2;
1672
1673 SetLedColor(led, quality?kLedOrange:(value^invert?kLedGreen:kLedRed), d.time);
1674
1675 ostringstream tip;
1676 tip << "<table border='1'><tr><th colspan='11'>" << d.time.GetAsStr() << " (UTC)</th></tr><tr><th></th>";
1677 for (int b=0; b<10; b++)
1678 tip << "<th>" << b << "</th>";
1679 tip << "</tr>";
1680
1681 /*
1682 tip << "<tr>" << hex;
1683 tip << "<th>" << d.ptr<uint16_t>()[0] << " " << (d.ptr<uint16_t>()[0]&bitmask) << "</th>";
1684 tip << "<th>" << d.ptr<uint16_t>()[1] << " " << (d.ptr<uint16_t>()[1]&bitmask) << "</th>";
1685 tip << "</tr>";
1686 */
1687
1688 for (int c=0; c<4; c++)
1689 {
1690 tip << "<tr><th>" << dec << c << "</th>" << hex;
1691 for (int b=0; b<10; b++)
1692 {
1693 tip << "<td>"
1694 << (ptr[c*10+b]&bitmask)
1695 << "</td>";
1696 }
1697 tip << "</tr>";
1698 }
1699 tip << "</table>";
1700
1701 led->setToolTip(tip.str().c_str());
1702 }
1703
1704 void handleFadStatus(const DimData &d)
1705 {
1706 if (d.size()!=0 && !CheckSize(d, 42*sizeof(uint16_t)))
1707 return;
1708
1709 SetFadLed(fFadLedDrsEnabled, d, FAD::EventHeader::kDenable);
1710 SetFadLed(fFadLedDrsWrite, d, FAD::EventHeader::kDwrite);
1711 SetFadLed(fFadLedDcmLocked, d, FAD::EventHeader::kDcmLocked);
1712 SetFadLed(fFadLedDcmReady, d, FAD::EventHeader::kDcmReady);
1713 SetFadLed(fFadLedSpiSclk, d, FAD::EventHeader::kSpiSclk);
1714 SetFadLed(fFadLedRefClockTooLow, d, FAD::EventHeader::kRefClkTooLow, true);
1715 SetFadLed(fFadLedBusyOn, d, FAD::EventHeader::kBusyOn);
1716 SetFadLed(fFadLedBusyOff, d, FAD::EventHeader::kBusyOff);
1717 SetFadLed(fFadLedTriggerLine, d, FAD::EventHeader::kTriggerLine);
1718 SetFadLed(fFadLedContTrigger, d, FAD::EventHeader::kContTrigger);
1719 SetFadLed(fFadLedSocket, d, FAD::EventHeader::kSock17);
1720 SetFadLed(fFadLedPllLock, d, 0xf000);
1721 }
1722
1723 void handleFadStatistics1(const DimData &d)
1724 {
1725 if (!CheckSize(d, sizeof(GUI_STAT)))
1726 return;
1727
1728 const GUI_STAT &stat = d.ref<GUI_STAT>();
1729
1730 /*
1731 //info about status of the main threads
1732 int32_t readStat ; //read thread
1733 int32_t procStat ; //processing thread(s)
1734 int32_t writStat ; //write thread
1735 */
1736
1737 fFadBufferMax->setValue(stat.totMem/1000000);
1738 fFadBuffer->setMaximum(stat.totMem/100);
1739 fFadBuffer->setValue((stat.maxMem>stat.totMem?stat.totMem:stat.maxMem)/100); // Max mem used in last second
1740
1741 uint32_t sum = 0;
1742 int32_t min = 0x7fffff;
1743 int32_t max = 0;
1744
1745 int cnt = 0;
1746 int err = 0;
1747
1748 for (int i=0; i<40; i++)
1749 {
1750 if (stat.numConn[i]!=7)
1751 continue;
1752
1753 cnt++;
1754
1755 sum += stat.rateBytes[i];
1756 err += stat.errConn[i];
1757
1758 if (stat.rateBytes[i]<min)
1759 min = stat.rateBytes[i];
1760 if (stat.rateBytes[i]>max)
1761 max = stat.rateBytes[i];
1762 }
1763
1764 fFadEvtConn->setValue(cnt);
1765 fFadEvtConnErr->setValue(err);
1766
1767 fFadEvtBufNew->setValue(stat.bufNew); // Incomplete in buffer
1768 fFadEvtBufEvt->setValue(stat.bufEvt); // Complete in buffer
1769 fFadEvtBufMax->setValue(stat.maxEvt); // Complete in buffer
1770 fFadEvtWrite->setValue(stat.evtWrite-stat.evtSkip-stat.evtErr);
1771 fFadEvtSkip->setValue(stat.evtSkip);
1772 fFadEvtErr->setValue(stat.evtErr);
1773
1774 if (stat.deltaT==0)
1775 return;
1776
1777 fFadEthernetRateMin->setValue(min/stat.deltaT);
1778 fFadEthernetRateMax->setValue(max/stat.deltaT);
1779 fFadEthernetRateTot->setValue(sum/stat.deltaT);
1780 fFadEthernetRateAvg->setValue(cnt==0 ? 0 : sum/cnt/stat.deltaT);
1781 fFadEvtRateNew->setValue(1000*stat.rateNew/stat.deltaT);
1782 fFadEvtRateWrite->setValue(1000*stat.rateWrite/stat.deltaT);
1783 }
1784
1785 void handleFadStatistics2(const DimData &d)
1786 {
1787 if (!CheckSize(d, sizeof(EVT_STAT)))
1788 return;
1789
1790 //const EVT_STAT &stat = d.ref<EVT_STAT>();
1791
1792 /*
1793 //some info about what happened since start of program (or last 'reset')
1794 uint32_t reset ; //#if increased, reset all counters
1795 uint32_t numRead[MAX_SOCK] ; //how often succesfull read from N sockets per loop
1796
1797 uint64_t gotByte[NBOARDS] ; //#Bytes read per Board
1798 uint32_t gotErr[NBOARDS] ; //#Communication Errors per Board
1799
1800 uint32_t evtGet; //#new Start of Events read
1801 uint32_t evtTot; //#complete Events read
1802
1803 uint32_t evtErr; //#Events with Errors
1804 uint32_t evtSkp; //#Events incomplete (timeout)
1805
1806
1807 uint32_t procTot; //#Events processed
1808 uint32_t procErr; //#Events showed problem in processing
1809 uint32_t procTrg; //#Events accepted by SW trigger
1810 uint32_t procSkp; //#Events rejected by SW trigger
1811
1812 uint32_t feedTot; //#Events used for feedBack system
1813 uint32_t feedErr; //#Events rejected by feedBack
1814
1815 uint32_t wrtTot; //#Events written to disk
1816 uint32_t wrtErr; //#Events with write-error
1817
1818 uint32_t runOpen; //#Runs opened
1819 uint32_t runClose; //#Runs closed
1820 uint32_t runErr; //#Runs with open/close errors
1821
1822
1823 //info about current connection status
1824 uint8_t numConn[NBOARDS] ; //#Sockets succesfully open per board
1825 */
1826 }
1827
1828 // ===================== FTM ============================================
1829
1830 void UpdateTriggerRate(const FTM::DimTriggerRates &sdata)
1831 {
1832#ifdef HAVE_ROOT
1833 TCanvas *c = fFtmRateCanv->GetCanvas();
1834
1835 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1836
1837 if (sdata.fTriggerRate<0)
1838 {
1839 fGraphFtmRate.Set(0);
1840
1841 const double tm = Time().RootTime();
1842
1843 h->SetBins(1, tm, tm+60);
1844 h->GetXaxis()->SetTimeFormat("%M'%S\"");
1845 h->GetXaxis()->SetTitle("Time");
1846
1847 c->Modified();
1848 c->Update();
1849 return;
1850 }
1851
1852 const double t1 = h->GetXaxis()->GetXmax();
1853 const double t0 = h->GetXaxis()->GetXmin();
1854
1855 const double now = t0+sdata.fTimeStamp/1000000.;
1856
1857 h->SetBins(h->GetNbinsX()+1, t0, now+1);
1858 fGraphFtmRate.SetPoint(fGraphFtmRate.GetN(), now, sdata.fTriggerRate);
1859
1860 if (t1-t0>60)
1861 {
1862 h->GetXaxis()->SetTimeFormat("%Hh%M'");
1863 h->GetXaxis()->SetTitle("Time");
1864 }
1865
1866 h->SetMinimum(0);
1867
1868 c->Modified();
1869 c->Update();
1870#endif
1871 }
1872
1873 void UpdateRatesCam(const FTM::DimTriggerRates &sdata)
1874 {
1875#ifdef HAVE_ROOT
1876 if (fThresholdIdx->value()>=0)
1877 {
1878 const int isw = fThresholdIdx->value();
1879 const int ihw = fPatchMapHW[isw];
1880 fPatchRate->setValue(sdata.fPatchRate[ihw]);
1881 }
1882
1883 valarray<double> dat(0., 1440);
1884
1885 // fPatch converts from software id to software patch id
1886 for (int i=0; i<1440; i++)
1887 {
1888 const int ihw = fPatchHW[i];
1889// const int isw = fPatch[i];
1890// const int ihw = fPatchMapHW[isw];
1891 dat[i] = sdata.fPatchRate[ihw];
1892 }
1893
1894// TCanvas *c = fRatesCanv->GetCanvas();
1895// Camera *cam = (Camera*)c->FindObject("Camera");
1896
1897 fRatesCanv->SetData(dat);
1898
1899// c->Modified();
1900// c->Update();
1901#endif
1902 }
1903
1904 int64_t fTimeStamp0;
1905
1906 void UpdateRatesGraphs(const FTM::DimTriggerRates &sdata)
1907 {
1908#ifdef HAVE_ROOT
1909 if (fTimeStamp0<0)
1910 {
1911 fTimeStamp0 = sdata.fTimeStamp;
1912 return;
1913 }
1914
1915 TCanvas *c = fFtmRateCanv->GetCanvas();
1916
1917 TH1 *h = (TH1*)c->FindObject("TimeFrame");
1918
1919 const double tdiff = sdata.fTimeStamp-fTimeStamp0;
1920 fTimeStamp0 = sdata.fTimeStamp;
1921
1922 if (tdiff<0)
1923 {
1924 for (int i=0; i<160; i++)
1925 fGraphPatchRate[i].Set(0);
1926 for (int i=0; i<40; i++)
1927 fGraphBoardRate[i].Set(0);
1928
1929 return;
1930 }
1931
1932 //const double t1 = h->GetXaxis()->GetXmax();
1933 const double t0 = h->GetXaxis()->GetXmin();
1934
1935 for (int i=0; i<160; i++)
1936 fGraphPatchRate[i].SetPoint(fGraphPatchRate[i].GetN(),
1937 t0+sdata.fTimeStamp/1000000., sdata.fPatchRate[i]);
1938 for (int i=0; i<40; i++)
1939 fGraphBoardRate[i].SetPoint(fGraphBoardRate[i].GetN(),
1940 t0+sdata.fTimeStamp/1000000., sdata.fBoardRate[i]);
1941
1942 c->Modified();
1943 c->Update();
1944#endif
1945 }
1946
1947 void handleFtmTriggerRates(const DimData &d)
1948 {
1949 if (!CheckSize(d, sizeof(FTM::DimTriggerRates)))
1950 return;
1951
1952 const FTM::DimTriggerRates &sdata = d.ref<FTM::DimTriggerRates>();
1953
1954 fFtmTime->setText(QString::number(sdata.fTimeStamp/1000000., 'f', 6)+ " s");
1955 fTriggerCounter->setText(QString::number(sdata.fTriggerCounter));
1956
1957 if (sdata.fTimeStamp>0)
1958 fTriggerCounterRate->setValue(1000000.*sdata.fTriggerCounter/sdata.fTimeStamp);
1959 else
1960 fTriggerCounterRate->setValue(0);
1961
1962 // ----------------------------------------------
1963
1964 fOnTime->setText(QString::number(sdata.fOnTimeCounter/1000000., 'f', 6)+" s");
1965
1966 if (sdata.fTimeStamp>0)
1967 fOnTimeRel->setValue(100.*sdata.fOnTimeCounter/sdata.fTimeStamp);
1968 else
1969 fOnTimeRel->setValue(0);
1970
1971 // ----------------------------------------------
1972
1973 UpdateTriggerRate(sdata);
1974 UpdateRatesGraphs(sdata);
1975 UpdateRatesCam(sdata);
1976 }
1977
1978 void handleFtmCounter(const DimData &d)
1979 {
1980 if (!CheckSize(d, sizeof(uint32_t)*6))
1981 return;
1982
1983 const uint32_t *sdata = d.ptr<uint32_t>();
1984
1985 fFtmCounterH->setValue(sdata[0]);
1986 fFtmCounterS->setValue(sdata[1]);
1987 fFtmCounterD->setValue(sdata[2]);
1988 fFtmCounterF->setValue(sdata[3]);
1989 fFtmCounterE->setValue(sdata[4]);
1990 fFtmCounterR->setValue(sdata[5]);
1991 }
1992
1993 void handleFtmDynamicData(const DimData &d)
1994 {
1995 if (!CheckSize(d, sizeof(FTM::DimDynamicData)))
1996 return;
1997
1998 const FTM::DimDynamicData &sdata = d.ref<FTM::DimDynamicData>();
1999
2000 fFtmTemp0->setValue(sdata.fTempSensor[0]*0.1);
2001 fFtmTemp1->setValue(sdata.fTempSensor[1]*0.1);
2002 fFtmTemp2->setValue(sdata.fTempSensor[2]*0.1);
2003 fFtmTemp3->setValue(sdata.fTempSensor[3]*0.1);
2004
2005 SetLedColor(fClockCondLed, sdata.fState&FTM::kFtmLocked ? kLedGreen : kLedRed, d.time);
2006 }
2007
2008 void DisplayRates()
2009 {
2010#ifdef HAVE_ROOT
2011 TCanvas *c = fFtmRateCanv->GetCanvas();
2012
2013 while (c->FindObject("PatchRate"))
2014 c->GetListOfPrimitives()->Remove(c->FindObject("PatchRate"));
2015
2016 while (c->FindObject("BoardRate"))
2017 c->GetListOfPrimitives()->Remove(c->FindObject("BoardRate"));
2018
2019 c->cd();
2020
2021 if (fRatePatch1->value()>=0)
2022 {
2023 fGraphPatchRate[fRatePatch1->value()].SetLineColor(kRed);
2024 fGraphPatchRate[fRatePatch1->value()].SetMarkerColor(kRed);
2025 fGraphPatchRate[fRatePatch1->value()].Draw("PL");
2026 }
2027 if (fRatePatch2->value()>=0)
2028 {
2029 fGraphPatchRate[fRatePatch2->value()].SetLineColor(kGreen);
2030 fGraphPatchRate[fRatePatch2->value()].SetMarkerColor(kGreen);
2031 fGraphPatchRate[fRatePatch2->value()].Draw("PL");
2032 }
2033 if (fRateBoard1->value()>=0)
2034 {
2035 fGraphBoardRate[fRateBoard1->value()].SetLineColor(kMagenta);
2036 fGraphBoardRate[fRateBoard1->value()].SetMarkerColor(kMagenta);
2037 fGraphBoardRate[fRateBoard1->value()].Draw("PL");
2038 }
2039 if (fRateBoard2->value()>=0)
2040 {
2041 fGraphBoardRate[fRateBoard2->value()].SetLineColor(kCyan);
2042 fGraphBoardRate[fRateBoard2->value()].SetMarkerColor(kCyan);
2043 fGraphBoardRate[fRateBoard2->value()].Draw("PL");
2044 }
2045#endif
2046 }
2047
2048 void on_fRatePatch1_valueChanged(int)
2049 {
2050 DisplayRates();
2051 }
2052
2053 void on_fRatePatch2_valueChanged(int)
2054 {
2055 DisplayRates();
2056 }
2057
2058 void on_fRateBoard1_valueChanged(int)
2059 {
2060 DisplayRates();
2061 }
2062
2063 void on_fRateBoard2_valueChanged(int)
2064 {
2065 DisplayRates();
2066 }
2067
2068 FTM::DimStaticData fFtmStaticData;
2069
2070 void SetFtuLed(int idx, int counter, const Time &t)
2071 {
2072 if (counter==0 || counter>3)
2073 counter = 3;
2074
2075 if (counter<0)
2076 counter = 0;
2077
2078 const LedColor_t col[4] = { kLedGray, kLedGreen, kLedOrange, kLedRed };
2079
2080 SetLedColor(fFtuLED[idx], col[counter], t);
2081
2082 fFtuStatus[idx] = counter;
2083 }
2084
2085 void SetFtuStatusLed(const Time &t)
2086 {
2087 const int max = fFtuStatus.max();
2088
2089 switch (max)
2090 {
2091 case 0:
2092 SetLedColor(fStatusFTULed, kLedGray, t);
2093 fStatusFTULabel->setText("All disabled");
2094 fStatusFTULabel->setToolTip("All FTUs are disabled");
2095 break;
2096
2097 case 1:
2098 SetLedColor(fStatusFTULed, kLedGreen, t);
2099 fStatusFTULabel->setToolTip("Communication with FTU is smooth.");
2100 fStatusFTULabel->setText("ok");
2101 break;
2102
2103 case 2:
2104 SetLedColor(fStatusFTULed, kLedOrange, t);
2105 fStatusFTULabel->setText("Warning");
2106 fStatusFTULabel->setToolTip("At least one FTU didn't answer immediately");
2107 break;
2108
2109 case 3:
2110 SetLedColor(fStatusFTULed, kLedRed, t);
2111 fStatusFTULabel->setToolTip("At least one FTU didn't answer!");
2112 fStatusFTULabel->setText("ERROR");
2113 break;
2114 }
2115
2116 const int cnt = count(&fFtuStatus[0], &fFtuStatus[40], 0);
2117 fFtuAllOn->setEnabled(cnt!=0);
2118 fFtuAllOff->setEnabled(cnt!=40);
2119 }
2120
2121 void handleFtmStaticData(const DimData &d)
2122 {
2123 if (!CheckSize(d, sizeof(FTM::DimStaticData)))
2124 return;
2125
2126 const FTM::DimStaticData &sdata = d.ref<FTM::DimStaticData>();
2127
2128 fTriggerInterval->setValue(sdata.fTriggerInterval);
2129 fPhysicsCoincidence->setValue(sdata.fMultiplicityPhysics);
2130 fCalibCoincidence->setValue(sdata.fMultiplicityCalib);
2131 fPhysicsWindow->setValue(sdata.fWindowPhysics);
2132 fCalibWindow->setValue(sdata.fWindowCalib);
2133
2134 fTriggerDelay->setValue(sdata.fDelayTrigger);
2135 fTimeMarkerDelay->setValue(sdata.fDelayTimeMarker);
2136 fDeadTime->setValue(sdata.fDeadTime);
2137
2138 fClockCondR0->setValue(sdata.fClockConditioner[0]);
2139 fClockCondR1->setValue(sdata.fClockConditioner[1]);
2140 fClockCondR8->setValue(sdata.fClockConditioner[2]);
2141 fClockCondR9->setValue(sdata.fClockConditioner[3]);
2142 fClockCondR11->setValue(sdata.fClockConditioner[4]);
2143 fClockCondR13->setValue(sdata.fClockConditioner[5]);
2144 fClockCondR14->setValue(sdata.fClockConditioner[6]);
2145 fClockCondR15->setValue(sdata.fClockConditioner[7]);
2146
2147 const uint32_t R0 = sdata.fClockConditioner[0];
2148 const uint32_t R14 = sdata.fClockConditioner[6];
2149 const uint32_t R15 = sdata.fClockConditioner[7];
2150
2151 const uint32_t Ndiv = (R15&0x1ffff00)<<2;
2152 const uint32_t Rdiv = (R14&0x007ff00)>>8;
2153 const uint32_t Cdiv = (R0 &0x000ff00)>>8;
2154
2155 double freq = 40.*Ndiv/(Rdiv*Cdiv);
2156
2157 fClockCondFreqRes->setValue(freq);
2158
2159 //fClockCondFreq->setEditText("");
2160 fClockCondFreq->setCurrentIndex(0);
2161
2162 fTriggerSeqPed->setValue(sdata.fTriggerSeqPed);
2163 fTriggerSeqLPint->setValue(sdata.fTriggerSeqLPint);
2164 fTriggerSeqLPext->setValue(sdata.fTriggerSeqLPext);
2165
2166 fLpIntIntensity->setValue(sdata.fIntensityLPint);
2167 fLpExtIntensity->setValue(sdata.fIntensityLPext);
2168
2169 fLpIntGroup1->setChecked(sdata.HasLPintG1());
2170 fLpIntGroup2->setChecked(sdata.HasLPintG2());
2171 fLpExtGroup1->setChecked(sdata.HasLPextG1());
2172 fLpExtGroup2->setChecked(sdata.HasLPextG2());
2173
2174 fEnableTrigger->setChecked(sdata.HasTrigger());
2175 fEnableVeto->setChecked(sdata.HasVeto());
2176 fEnableExt1->setChecked(sdata.HasExt1());
2177 fEnableExt2->setChecked(sdata.HasExt2());
2178 fEnableClockCond->setChecked(sdata.HasClockConditioner());
2179
2180 for (int i=0; i<40; i++)
2181 {
2182 if (!sdata.IsActive(i))
2183 SetFtuLed(i, -1, d.time);
2184 else
2185 {
2186 if (fFtuStatus[i]==0)
2187 SetFtuLed(i, 1, d.time);
2188 }
2189 fFtuLED[i]->setChecked(false);
2190 }
2191 SetFtuStatusLed(d.time);
2192
2193#ifdef HAVE_ROOT
2194// Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
2195 for (int isw=0; isw<1440; isw++)
2196 {
2197 const int ihw = fPixelMapHW[isw];
2198 fRatesCanv->SetEnable(isw, sdata.IsEnabled(ihw));
2199 }
2200
2201// fRatesCanv->GetCanvas()->Modified();
2202// fRatesCanv->GetCanvas()->Update();
2203#endif
2204
2205 {
2206 const int isw = fPixelIdx->value();
2207 const int ihw = fPixelMapHW[isw];
2208 const bool on = sdata.IsEnabled(ihw);
2209 fPixelEnable->setChecked(on);
2210 }
2211
2212 if (fThresholdIdx->value()>=0)
2213 {
2214 const int isw = fThresholdIdx->value();
2215 const int ihw = fPatchMapHW[isw];
2216 fThresholdVal->setValue(sdata.fThreshold[ihw]);
2217 }
2218
2219 fPrescalingVal->setValue(sdata.fPrescaling[0]);
2220
2221 fFtmStaticData = sdata;
2222 }
2223
2224 void handleFtmPassport(const DimData &d)
2225 {
2226 if (!CheckSize(d, sizeof(FTM::DimPassport)))
2227 return;
2228
2229 const FTM::DimPassport &sdata = d.ref<FTM::DimPassport>();
2230
2231 stringstream str1, str2;
2232 str1 << hex << "0x" << setfill('0') << setw(16) << sdata.fBoardId;
2233 str2 << sdata.fFirmwareId;
2234
2235 fFtmBoardId->setText(str1.str().c_str());
2236 fFtmFirmwareId->setText(str2.str().c_str());
2237 }
2238
2239 void handleFtmFtuList(const DimData &d)
2240 {
2241 if (!CheckSize(d, sizeof(FTM::DimFtuList)))
2242 return;
2243
2244 fFtuPing->setChecked(false);
2245
2246 const FTM::DimFtuList &sdata = d.ref<FTM::DimFtuList>();
2247
2248 stringstream str;
2249 str << "<table width='100%'>" << setfill('0');
2250 str << "<tr><th>Num</th><th></th><th>Addr</th><th></th><th>DNA</th></tr>";
2251 for (int i=0; i<40; i++)
2252 {
2253 str << "<tr>";
2254 str << "<td align='center'>" << dec << i << hex << "</td>";
2255 str << "<td align='center'>:</td>";
2256 str << "<td align='center'>0x" << setw(2) << (int)sdata.fAddr[i] << "</td>";
2257 str << "<td align='center'>:</td>";
2258 str << "<td align='center'>0x" << setw(16) << sdata.fDNA[i] << "</td>";
2259 str << "</tr>";
2260 }
2261 str << "</table>";
2262
2263 fFtuDNA->setText(str.str().c_str());
2264
2265 fFtuAnswersTotal->setValue(sdata.fNumBoards);
2266 fFtuAnswersCrate0->setValue(sdata.fNumBoardsCrate[0]);
2267 fFtuAnswersCrate1->setValue(sdata.fNumBoardsCrate[1]);
2268 fFtuAnswersCrate2->setValue(sdata.fNumBoardsCrate[2]);
2269 fFtuAnswersCrate3->setValue(sdata.fNumBoardsCrate[3]);
2270
2271 for (int i=0; i<40; i++)
2272 SetFtuLed(i, sdata.IsActive(i) ? sdata.fPing[i] : -1, d.time);
2273
2274 SetFtuStatusLed(d.time);
2275 }
2276
2277 void handleFtmError(const DimData &d)
2278 {
2279 if (!CheckSize(d, sizeof(FTM::DimError)))
2280 return;
2281
2282 const FTM::DimError &sdata = d.ref<FTM::DimError>();
2283
2284 SetFtuLed(sdata.fError.fDestAddress, sdata.fError.fNumCalls, d.time);
2285 SetFtuStatusLed(d.time);
2286
2287 // FIXME: Write to special window!
2288 //Out() << "Error:" << endl;
2289 //Out() << sdata.fError << endl;
2290 }
2291
2292 // ====================== MessageImp ====================================
2293
2294 bool fChatOnline;
2295
2296 void handleStateChanged(const Time &time, const std::string &server,
2297 const State &s)
2298 {
2299 // FIXME: Prefix tooltip with time
2300 if (server=="FTM_CONTROL")
2301 {
2302 // FIXME: Enable FTU page!!!
2303 fStatusFTMLabel->setText(s.name.c_str());
2304 fStatusFTMLabel->setToolTip(s.comment.c_str());
2305
2306 bool enable = false;
2307
2308 if (s.index<FTM::StateMachine::kDisconnected) // No Dim connection
2309 SetLedColor(fStatusFTMLed, kLedGray, time);
2310 if (s.index==FTM::StateMachine::kDisconnected) // Dim connection / FTM disconnected
2311 SetLedColor(fStatusFTMLed, kLedYellow, time);
2312 if (s.index==FTM::StateMachine::kConnected ||
2313 s.index==FTM::StateMachine::kIdle ||
2314 s.index==FTM::StateMachine::kConfiguring1 ||
2315 s.index==FTM::StateMachine::kConfiguring2 ||
2316 s.index==FTM::StateMachine::kConfigured ||
2317 s.index==FTM::StateMachine::kTakingData) // Dim connection / FTM connected
2318 SetLedColor(fStatusFTMLed, kLedGreen, time);
2319
2320 if (s.index==FTM::StateMachine::kConnected ||
2321 s.index==FTM::StateMachine::kIdle) // Dim connection / FTM connected
2322 enable = true;
2323
2324 fTriggerWidget->setEnabled(enable);
2325 fFtuGroupEnable->setEnabled(enable);
2326 fRatesControls->setEnabled(enable);
2327 fFtuWidget->setEnabled(s.index>FTM::StateMachine::kDisconnected);
2328
2329 if (s.index>=FTM::StateMachine::kConnected)
2330 SetFtuStatusLed(time);
2331 else
2332 {
2333 SetLedColor(fStatusFTULed, kLedGray, time);
2334 fStatusFTULabel->setText("Offline");
2335 fStatusFTULabel->setToolTip("FTM is not online.");
2336 }
2337 }
2338
2339 if (server=="FAD_CONTROL")
2340 {
2341 fStatusFADLabel->setText(s.name.c_str());
2342 fStatusFADLabel->setToolTip(s.comment.c_str());
2343
2344 bool enable = false;
2345
2346 if (s.index<FAD::kOffline) // No Dim connection
2347 {
2348 SetLedColor(fStatusFADLed, kLedGray, time);
2349
2350 // Timing problem - sometimes they stay gray :(
2351 //for (int i=0; i<40; i++)
2352 // SetLedColor(fFadLED[i], kLedGray, time);
2353
2354 /*
2355 fStatusEventBuilderLabel->setText("Offline");
2356 fStatusEventBuilderLabel->setToolTip("No connection to fadctrl.");
2357 fEvtBldWidget->setEnabled(false);
2358
2359 SetLedColor(fStatusEventBuilderLed, kLedGray, time);
2360 */
2361 }
2362 if (s.index==FAD::kOffline) // Dim connection / FTM disconnected
2363 SetLedColor(fStatusFADLed, kLedRed, time);
2364 if (s.index==FAD::kDisconnected) // Dim connection / FTM disconnected
2365 SetLedColor(fStatusFADLed, kLedOrange, time);
2366 if (s.index==FAD::kConnecting) // Dim connection / FTM disconnected
2367 {
2368 SetLedColor(fStatusFADLed, kLedYellow, time);
2369 // FIXME FIXME FIXME: The LEDs are not displayed when disabled!
2370 enable = true;
2371 }
2372 if (s.index>=FAD::kConnected) // Dim connection / FTM connected
2373 {
2374 SetLedColor(fStatusFADLed, kLedGreen, time);
2375 enable = true;
2376 }
2377
2378 fFadWidget->setEnabled(enable);
2379 }
2380
2381 if (server=="FSC_CONTROL")
2382 {
2383 fStatusFSCLabel->setText(s.name.c_str());
2384 fStatusFSCLabel->setToolTip(s.comment.c_str());
2385
2386 bool enable = false;
2387
2388 if (s.index<1) // No Dim connection
2389 SetLedColor(fStatusFSCLed, kLedGray, time);
2390 if (s.index==1) // Dim connection / FTM disconnected
2391 SetLedColor(fStatusFSCLed, kLedRed, time);
2392 if (s.index>=2) // Dim connection / FTM disconnected
2393 {
2394 SetLedColor(fStatusFSCLed, kLedGreen, time);
2395 enable = true;
2396 }
2397
2398 //fFscWidget->setEnabled(enable);
2399 }
2400
2401 if (server=="DATA_LOGGER")
2402 {
2403 fStatusLoggerLabel->setText(s.name.c_str());
2404 fStatusLoggerLabel->setToolTip(s.comment.c_str());
2405
2406 bool enable = true;
2407
2408 if (s.index<=30) // Ready/Waiting
2409 SetLedColor(fStatusLoggerLed, kLedYellow, time);
2410 if (s.index<-1) // Offline
2411 {
2412 SetLedColor(fStatusLoggerLed, kLedGray, time);
2413 enable = false;
2414 }
2415 if (s.index>=0x100) // Error
2416 SetLedColor(fStatusLoggerLed, kLedRed, time);
2417 if (s.index==40) // Logging
2418 SetLedColor(fStatusLoggerLed, kLedGreen, time);
2419
2420 fLoggerWidget->setEnabled(enable);
2421 }
2422
2423 if (server=="CHAT")
2424 {
2425 fStatusChatLabel->setText(s.name.c_str());
2426
2427 fChatOnline = s.index==0;
2428
2429 SetLedColor(fStatusChatLed, fChatOnline ? kLedGreen : kLedGray, time);
2430
2431 fChatSend->setEnabled(fChatOnline);
2432 fChatMessage->setEnabled(fChatOnline);
2433 }
2434
2435 if (server=="SCHEDULER")
2436 {
2437 fStatusSchedulerLabel->setText(s.name.c_str());
2438
2439 SetLedColor(fStatusSchedulerLed, s.index>=0 ? kLedGreen : kLedRed, time);
2440 }
2441 }
2442
2443 void on_fTabWidget_currentChanged(int which)
2444 {
2445 if (fTabWidget->tabText(which)=="Chat")
2446 fTabWidget->setTabIcon(which, QIcon());
2447 }
2448
2449 void handleWrite(const Time &time, const string &text, int qos)
2450 {
2451 stringstream out;
2452
2453 if (text.substr(0, 6)=="CHAT: ")
2454 {
2455 if (qos==MessageImp::kDebug)
2456 return;
2457
2458 out << "<font size='-1' color='navy'>[<B>";
2459 out << time.GetAsStr("%H:%M:%S");
2460 out << "</B>]</FONT> " << text.substr(6);
2461 fChatText->append(out.str().c_str());
2462
2463 if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
2464 return;
2465
2466 static int num = 0;
2467 if (num++<2)
2468 return;
2469
2470 for (int i=0; i<fTabWidget->count(); i++)
2471 if (fTabWidget->tabText(i)=="Chat")
2472 {
2473 fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
2474 break;
2475 }
2476
2477 return;
2478 }
2479
2480
2481 out << "<font style='font-family:monospace' color='";
2482
2483 switch (qos)
2484 {
2485 case kMessage: out << "black"; break;
2486 case kInfo: out << "green"; break;
2487 case kWarn: out << "#FF6600"; break;
2488 case kError: out << "maroon"; break;
2489 case kFatal: out << "maroon"; break;
2490 case kDebug: out << "navy"; break;
2491 default: out << "navy"; break;
2492 }
2493 out << "'>";
2494 out << time.GetAsStr("%H:%M:%S.%f").substr(0,12);
2495 out << " - " << text << "</font>";
2496
2497 fLogText->append(out.str().c_str());
2498
2499 if (qos>=kWarn && qos!=kDebug)
2500 fTextEdit->append(out.str().c_str());
2501 }
2502
2503 void IndicateStateChange(const Time &time, const std::string &server)
2504 {
2505 const State s = GetState(server, GetCurrentState(server));
2506
2507 QApplication::postEvent(this,
2508 new FunctionEvent(boost::bind(&FactGui::handleStateChanged, this, time, server, s)));
2509 }
2510
2511 int Write(const Time &time, const string &txt, int qos)
2512 {
2513 QApplication::postEvent(this,
2514 new FunctionEvent(boost::bind(&FactGui::handleWrite, this, time, txt, qos)));
2515
2516 return 0;
2517 }
2518
2519 // ====================== Dim infoHandler================================
2520
2521 void handleDimService(const string &txt)
2522 {
2523 fDimSvcText->append(txt.c_str());
2524 }
2525
2526 void infoHandlerService(DimInfo &info)
2527 {
2528 const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
2529
2530 stringstream dummy;
2531 const Converter conv(dummy, fmt, false);
2532
2533 const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
2534
2535 stringstream out;
2536 out << "<font size'-1' color='navy'>[";
2537 out << tm.GetAsStr("%H:%M:%S.%f").substr(0,12);
2538 out << "]</font> <B>" << info.getName() << "</B> - ";
2539
2540 bool iserr = true;
2541 if (!conv)
2542 {
2543 out << "Compilation of format string '" << fmt << "' failed!";
2544 }
2545 else
2546 {
2547 try
2548 {
2549 const string dat = conv.GetString(info.getData(), info.getSize());
2550 out << dat;
2551 iserr = false;
2552 }
2553 catch (const runtime_error &e)
2554 {
2555 out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
2556 }
2557 }
2558
2559 // srand(hash<string>()(string(info.getName())));
2560 // int bg = rand()&0xffffff;
2561
2562 int bg = hash<string>()(string(info.getName()));
2563
2564 // allow only light colors
2565 bg = ~(bg&0x1f1f1f)&0xffffff;
2566
2567 if (iserr)
2568 bg = 0xffffff;
2569
2570 stringstream bgcol;
2571 bgcol << hex << setfill('0') << setw(6) << bg;
2572
2573 const string col = iserr ? "red" : "black";
2574 const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
2575
2576 QApplication::postEvent(this,
2577 new FunctionEvent(boost::bind(&FactGui::handleDimService, this, str)));
2578 }
2579
2580 void CallInfoHandler(void (FactGui::*handler)(const DimData&), const DimData &d)
2581 {
2582 fInHandler = true;
2583 (this->*handler)(d);
2584 fInHandler = false;
2585 }
2586
2587 /*
2588 void CallInfoHandler(const boost::function<void()> &func)
2589 {
2590 // This ensures that newly received values are not sent back to the emitter
2591 // because changing the value emits the valueChanged signal (or similar)
2592 fInHandler = true;
2593 func();
2594 fInHandler = false;
2595 }*/
2596
2597 void PostInfoHandler(void (FactGui::*handler)(const DimData&))
2598 {
2599 //const boost::function<void()> f = boost::bind(handler, this, DimData(getInfo()));
2600
2601 FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, handler, DimData(getInfo())));
2602 // FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, f));
2603 // FunctionEvent *evt = new FunctionEvent(boost::bind(handler, this, DimData(getInfo()))));
2604
2605 QApplication::postEvent(this, evt);
2606 }
2607
2608 void infoHandler()
2609 {
2610 // Initialize the time-stamp (what a weird workaround...)
2611 if (getInfo())
2612 getInfo()->getTimestamp();
2613
2614 if (getInfo()==&fDimDNS)
2615 return PostInfoHandler(&FactGui::handleDimDNS);
2616#ifdef DEBUG_DIM
2617 cout << "HandleDimInfo " << getInfo()->getName() << endl;
2618#endif
2619 if (getInfo()==&fDimLoggerStats)
2620 return PostInfoHandler(&FactGui::handleLoggerStats);
2621
2622// if (getInfo()==&fDimFadFiles)
2623// return PostInfoHandler(&FactGui::handleFadFiles);
2624
2625 if (getInfo()==&fDimFadWriteStats)
2626 return PostInfoHandler(&FactGui::handleFadWriteStats);
2627
2628 if (getInfo()==&fDimFadConnections)
2629 return PostInfoHandler(&FactGui::handleFadConnections);
2630
2631 if (getInfo()==&fDimFadFwVersion)
2632 return PostInfoHandler(&FactGui::handleFadFwVersion);
2633
2634 if (getInfo()==&fDimFadRunNumber)
2635 return PostInfoHandler(&FactGui::handleFadRunNumber);
2636
2637 if (getInfo()==&fDimFadDNA)
2638 return PostInfoHandler(&FactGui::handleFadDNA);
2639
2640 if (getInfo()==&fDimFadTemperature)
2641 return PostInfoHandler(&FactGui::handleFadTemperature);
2642
2643 if (getInfo()==&fDimFadRefClock)
2644 return PostInfoHandler(&FactGui::handleFadRefClock);
2645
2646 if (getInfo()==&fDimFadRoi)
2647 return PostInfoHandler(&FactGui::handleFadRoi);
2648
2649 if (getInfo()==&fDimFadDac)
2650 return PostInfoHandler(&FactGui::handleFadDac);
2651
2652 if (getInfo()==&fDimFadDrsCalibration)
2653 return PostInfoHandler(&FactGui::handleFadDrsCalibration);
2654
2655 if (getInfo()==&fDimFadPrescaler)
2656 return PostInfoHandler(&FactGui::handleFadPrescaler);
2657
2658 if (getInfo()==&fDimFadStatus)
2659 return PostInfoHandler(&FactGui::handleFadStatus);
2660
2661 if (getInfo()==&fDimFadStatistics1)
2662 return PostInfoHandler(&FactGui::handleFadStatistics1);
2663
2664 if (getInfo()==&fDimFadStatistics2)
2665 return PostInfoHandler(&FactGui::handleFadStatistics2);
2666
2667 if (getInfo()==&fDimFadEvents)
2668 return PostInfoHandler(&FactGui::handleFadEvents);
2669
2670 if (getInfo()==&fDimFadRuns)
2671 return PostInfoHandler(&FactGui::handleFadRuns);
2672
2673 if (getInfo()==&fDimFadRawData)
2674 return PostInfoHandler(&FactGui::handleFadRawData);
2675
2676 if (getInfo()==&fDimFadEventData)
2677 return PostInfoHandler(&FactGui::handleFadEventData);
2678
2679/*
2680 if (getInfo()==&fDimFadSetup)
2681 return PostInfoHandler(&FactGui::handleFadSetup);
2682*/
2683 if (getInfo()==&fDimLoggerFilenameNight)
2684 return PostInfoHandler(&FactGui::handleLoggerFilenameNight);
2685
2686 if (getInfo()==&fDimLoggerNumSubs)
2687 return PostInfoHandler(&FactGui::handleLoggerNumSubs);
2688
2689 if (getInfo()==&fDimLoggerFilenameRun)
2690 return PostInfoHandler(&FactGui::handleLoggerFilenameRun);
2691
2692 if (getInfo()==&fDimFtmTriggerRates)
2693 return PostInfoHandler(&FactGui::handleFtmTriggerRates);
2694
2695 if (getInfo()==&fDimFtmCounter)
2696 return PostInfoHandler(&FactGui::handleFtmCounter);
2697
2698 if (getInfo()==&fDimFtmDynamicData)
2699 return PostInfoHandler(&FactGui::handleFtmDynamicData);
2700
2701 if (getInfo()==&fDimFtmPassport)
2702 return PostInfoHandler(&FactGui::handleFtmPassport);
2703
2704 if (getInfo()==&fDimFtmFtuList)
2705 return PostInfoHandler(&FactGui::handleFtmFtuList);
2706
2707 if (getInfo()==&fDimFtmStaticData)
2708 return PostInfoHandler(&FactGui::handleFtmStaticData);
2709
2710 if (getInfo()==&fDimFtmError)
2711 return PostInfoHandler(&FactGui::handleFtmError);
2712
2713// if (getInfo()==&fDimFadFiles)
2714// return PostInfoHandler(&FactGui::handleFadFiles);
2715
2716 for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
2717 if (i->second==getInfo())
2718 {
2719 infoHandlerService(*i->second);
2720 return;
2721 }
2722
2723 DimNetwork::infoHandler();
2724 }
2725
2726
2727 // ======================================================================
2728
2729 bool event(QEvent *evt)
2730 {
2731 if (dynamic_cast<FunctionEvent*>(evt))
2732 return static_cast<FunctionEvent*>(evt)->Exec();
2733
2734 if (dynamic_cast<CheckBoxEvent*>(evt))
2735 {
2736 const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
2737 const QStandardItem *par = item.parent();
2738 if (par)
2739 {
2740 const QString server = par->text();
2741 const QString service = item.text();
2742
2743 const string s = (server+'/'+service).toStdString();
2744
2745 if (item.checkState()==Qt::Checked)
2746 SubscribeService(s);
2747 else
2748 UnsubscribeService(s);
2749 }
2750 }
2751
2752 return MainWindow::event(evt); // unrecognized
2753 }
2754
2755 void on_fDimCmdSend_clicked()
2756 {
2757 const QString server = fDimCmdServers->currentIndex().data().toString();
2758 const QString command = fDimCmdCommands->currentIndex().data().toString();
2759 const QString arguments = fDimCmdLineEdit->displayText();
2760
2761 // FIXME: Sending a command exactly when the info Handler changes
2762 // the list it might lead to confusion.
2763 try
2764 {
2765 SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
2766 fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
2767 fDimCmdLineEdit->clear();
2768 }
2769 catch (const runtime_error &e)
2770 {
2771 stringstream txt;
2772 txt << e.what();
2773
2774 string buffer;
2775 while (getline(txt, buffer, '\n'))
2776 fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
2777 }
2778 }
2779
2780#ifdef HAVE_ROOT
2781 void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *canv)
2782 {
2783 // kMousePressEvent // TCanvas processed QEvent mousePressEvent
2784 // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
2785 // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
2786 // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
2787 // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
2788 // kEnterEvent // TCanvas processed QEvent enterEvent
2789 // kLeaveEvent // TCanvas processed QEvent leaveEvent
2790
2791 if (dynamic_cast<TCanvas*>(obj))
2792 return;
2793
2794 TQtWidget *tipped = static_cast<TQtWidget*>(sender());
2795
2796 if (evt==11/*kMouseReleaseEvent*/)
2797 {
2798 if (dynamic_cast<Camera*>(obj))
2799 {
2800 const float xx = canv->AbsPixeltoX(tipped->GetEventX());
2801 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
2802//ETIENNE MESS HERE
2803 // Camera *cam = static_cast<Camera*>(obj);
2804 // const int isw = cam->GetIdx(xx, yy);
2805
2806 // fPixelIdx->setValue(isw);
2807 // ChoosePixel(*cam, isw);
2808 }
2809 return;
2810 }
2811
2812 if (evt==61/*kMouseDoubleClickEvent*/)
2813 {
2814 if (dynamic_cast<Camera*>(obj) && fRatesControls->isEnabled())
2815 {
2816 const float xx = canv->AbsPixeltoX(tipped->GetEventX());
2817 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
2818//ETIENNE MESS HERE
2819// Camera *cam = static_cast<Camera*>(obj);
2820// const int isw = cam->GetIdx(xx, yy);
2821
2822 // ChoosePixel(*cam, isw);
2823
2824 // fPixelIdx->setValue(isw);
2825
2826 // const uint16_t ihw = fPixelMapHW[isw];
2827
2828 // Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", ihw);
2829 }
2830 if (dynamic_cast<TAxis*>(obj))
2831 static_cast<TAxis*>(obj)->UnZoom();
2832
2833 return;
2834 }
2835
2836 if (obj)
2837 {
2838 // Find the object which will get picked by the GetObjectInfo
2839 // due to buffer overflows in many root-versions
2840 // in TH1 and TProfile we have to work around and implement
2841 // our own GetObjectInfo which make everything a bit more
2842 // complicated.
2843 canv->cd();
2844#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
2845 const char *objectInfo =
2846 obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
2847#else
2848 const char *objectInfo = dynamic_cast<TH1*>(obj) ?
2849 "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
2850#endif
2851
2852 QString tipText;
2853 tipText += obj->GetName();
2854 tipText += " [";
2855 tipText += obj->ClassName();
2856 tipText += "]: ";
2857 tipText += objectInfo;
2858
2859 if (dynamic_cast<Camera*>(obj))
2860 {
2861 const float xx = canv->AbsPixeltoX(tipped->GetEventX());
2862 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
2863
2864//ETIENNE MESS HERE
2865// Camera *cam = static_cast<Camera*>(obj);
2866
2867// const int isw = cam->GetIdx(xx, yy);
2868// const int ihw = fPixelMapHW[isw];
2869
2870// const int idx = fPatchHW[isw];
2871
2872// int ii = 0;
2873// for (; ii<160; ii++)
2874// if (idx==fPatchMapHW[ii])
2875// break;
2876
2877
2878// const int patch = ihw%4;
2879// const int board = (ihw/4)%10;
2880// const int crate = (ihw/4)/10;
2881
2882// ostringstream str;
2883// str << " (hw=" << ihw << ") Patch=" << ii << " (hw=" << fPatchMapHW[idx] << "; Crate=" << crate << " Board=" << board << " Patch=" << patch << ")";
2884
2885// tipText += str.str().c_str();
2886 }
2887 fStatusBar->showMessage(tipText, 3000);
2888 }
2889
2890 gSystem->DispatchOneEvent(kFALSE);
2891 //gSystem->ProcessEvents();
2892 //QWhatsThis::display(tipText)
2893 }
2894
2895 void slot_RootUpdate()
2896 {
2897 gSystem->DispatchOneEvent(kFALSE);
2898 //gSystem->ProcessEvents();
2899 QTimer::singleShot(10, this, SLOT(slot_RootUpdate()));
2900 }
2901
2902 void ChoosePatch(Camera &cam, int isw)
2903 {
2904 cam.Reset();
2905
2906 fThresholdIdx->setValue(isw);
2907
2908 const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
2909
2910 fPatchRate->setEnabled(isw>=0);
2911 fThresholdCrate->setEnabled(isw>=0);
2912 fThresholdBoard->setEnabled(isw>=0);
2913 fThresholdPatch->setEnabled(isw>=0);
2914
2915 if (isw<0)
2916 return;
2917
2918 const int patch = ihw%4;
2919 const int board = (ihw/4)%10;
2920 const int crate = (ihw/4)/10;
2921
2922 fInChoosePatch = true;
2923
2924 fThresholdCrate->setValue(crate);
2925 fThresholdBoard->setValue(board);
2926 fThresholdPatch->setValue(patch);
2927
2928 fInChoosePatch = false;
2929
2930 fThresholdVal->setValue(fFtmStaticData.fThreshold[ihw]);
2931 fPatchRate->setValue(cam.GetData(isw));
2932
2933 // Loop over the software idx of all pixels
2934 for (unsigned int i=0; i<1440; i++)
2935 if (fPatchHW[i]==ihw)
2936 cam.SetBold(i);
2937 }
2938
2939 void ChoosePixel(Camera &cam, int isw)
2940 {
2941 const int ihw = fPixelMapHW[isw];
2942
2943 int ii = 0;
2944 for (; ii<160; ii++)
2945 if (fPatchHW[isw]==fPatchMapHW[ii])
2946 break;
2947
2948 cam.SetWhite(isw);
2949 ChoosePatch(cam, ii);
2950
2951 const bool on = fFtmStaticData.IsEnabled(ihw);
2952 fPixelEnable->setChecked(on);
2953 }
2954 void slot_ChoosePixel(int isw)
2955 {
2956 fPixelIdx->setValue(isw);
2957 const uint16_t ihw = fPixelMapHW[isw];
2958 const bool on = fFtmStaticData.IsEnabled(ihw);
2959 fPixelEnable->setChecked(on);
2960 }
2961 void slot_CameraDoubleClick(int isw)
2962 {
2963 fPixelIdx->setValue(isw);
2964 const uint16_t ihw = fPixelMapHW[isw];
2965 Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", ihw);
2966 }
2967 void slot_CameraMouseMove(int isw)
2968 {
2969 const int ihw = fPixelMapHW[isw];
2970 const int idx = fPatchHW[isw];
2971 int ii = 0;
2972 for (; ii<160;ii++)
2973 if (idx ==fPatchMapHW[ii])
2974 break;
2975
2976 const int patch = idx%4;
2977 const int board = (idx/4)%10;
2978 const int crate = (idx/4)/10;
2979 QString tipText;
2980 tipText += fRatesCanv->GetName();
2981 ostringstream str;
2982 str << " || Pixel=" << isw << " (hw=" << ihw << ") || Patch=" << ii << " (hw=" << fPatchMapHW[idx] << "; Crate=" << crate << " Board=" << board << " Patch=" << patch << ")";
2983 tipText += str.str().c_str();
2984 fStatusBar->showMessage(tipText, 3000);
2985 }
2986
2987 void UpdatePatch(int isw)
2988 {
2989//ETIENNE MESS HERE
2990// Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
2991// ChoosePatch(*cam, isw);
2992 }
2993
2994 void on_fThresholdIdx_valueChanged(int isw)
2995 {
2996 UpdatePatch(isw);
2997
2998// fRatesCanv->GetCanvas()->Modified();
2999 // fRatesCanv->GetCanvas()->Update();
3000 }
3001
3002 void UpdateThresholdIdx()
3003 {
3004 if (fInChoosePatch)
3005 return;
3006
3007 const int crate = fThresholdCrate->value();
3008 const int board = fThresholdBoard->value();
3009 const int patch = fThresholdPatch->value();
3010
3011 const int ihw = patch + board*4 + crate*40;
3012
3013 int isw = 0;
3014 for (; isw<160; isw++)
3015 if (ihw==fPatchMapHW[isw])
3016 break;
3017
3018 UpdatePatch(isw);
3019 }
3020
3021 void on_fThresholdPatch_valueChanged(int)
3022 {
3023 UpdateThresholdIdx();
3024 }
3025 void on_fThresholdBoard_valueChanged(int)
3026 {
3027 UpdateThresholdIdx();
3028 }
3029 void on_fThresholdCrate_valueChanged(int)
3030 {
3031 UpdateThresholdIdx();
3032 }
3033
3034 void on_fPixelIdx_valueChanged(int isw)
3035 {
3036//ETIENNE MESS HERE
3037// Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
3038 // ChoosePixel(*cam, isw);
3039 ChoosePixel(*fRatesCanv, isw);
3040
3041// fRatesCanv->GetCanvas()->Modified();
3042// fRatesCanv->GetCanvas()->Update();
3043 }
3044
3045 void on_fRatesMin_valueChanged(int min)
3046 {
3047//ETIENNE MESS HERE
3048// Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
3049 // cam->SetMin(min);
3050 fRatesCanv->SetMin(min);
3051
3052// fRatesCanv->GetCanvas()->Modified();
3053// fRatesCanv->GetCanvas()->Update();
3054 }
3055
3056 void on_fRatesMax_valueChanged(int max)
3057 {
3058//ETIENNE MESS HERE
3059// Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
3060// cam->SetMax(max);
3061 fRatesCanv->SetMax(max);
3062
3063// fRatesCanv->GetCanvas()->Modified();
3064// fRatesCanv->GetCanvas()->Update();
3065 }
3066
3067#endif
3068
3069 void on_fPixelEnable_stateChanged(int b)
3070 {
3071 if (fInHandler)
3072 return;
3073
3074 const uint16_t isw = fPixelIdx->value();
3075 const uint16_t ihw = fPixelMapHW[isw];
3076
3077 Dim::SendCommand(b==Qt::Unchecked ?
3078 "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
3079 ihw);
3080 }
3081
3082 void on_fPixelDisableOthers_clicked()
3083 {
3084 const uint16_t isw = fPixelIdx->value();
3085 const uint16_t ihw = fPixelMapHW[isw];
3086
3087 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PIXELS_EXCEPT", ihw);
3088 }
3089
3090 void on_fThresholdDisableOthers_clicked()
3091 {
3092 const int16_t isw = fThresholdIdx->value();
3093 const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3094
3095 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PATCHES_EXCEPT", ihw);
3096 }
3097
3098 void on_fThresholdVal_valueChanged(int v)
3099 {
3100 fThresholdVolt->setValue(2500./4095*v);
3101
3102 const int32_t isw = fThresholdIdx->value();
3103 const int32_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3104
3105 const int32_t d[2] = { ihw, v };
3106
3107 if (!fInHandler)
3108 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
3109 }
3110
3111 TGraph fGraphFtmTemp[4];
3112 TGraph fGraphFtmRate;
3113 TGraph fGraphPatchRate[160];
3114 TGraph fGraphBoardRate[40];
3115
3116#ifdef HAVE_ROOT
3117 TH1 *DrawTimeFrame(const char *ytitle)
3118 {
3119 const double tm = Time().RootTime();
3120
3121 TH1F *h=new TH1F("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
3122 h->SetDirectory(0);
3123 h->SetBit(kCanDelete);
3124 h->SetStats(kFALSE);
3125// h.SetMinimum(0);
3126// h.SetMaximum(1);
3127 h->SetXTitle("Time");
3128 h->SetYTitle(ytitle);
3129 h->GetXaxis()->CenterTitle();
3130 h->GetYaxis()->CenterTitle();
3131 h->GetXaxis()->SetTimeDisplay(true);
3132 h->GetXaxis()->SetTimeFormat("%Mh%S'");
3133 h->GetXaxis()->SetLabelSize(0.025);
3134 h->GetYaxis()->SetLabelSize(0.025);
3135 h->GetYaxis()->SetTitleOffset(1.2);
3136 // h.GetYaxis()->SetTitleSize(1.2);
3137 h->Draw();
3138
3139 return h;
3140 }
3141#endif
3142
3143public:
3144 FactGui() :
3145 fFtuStatus(40),
3146 fPixelMapHW(1440), fPatchMapHW(160), fPatchHW(1440),
3147 fInChoosePatch(false),
3148 fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
3149 //-
3150 fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
3151 fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHTLY", (void*)NULL, 0, this),
3152 fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", (void*)NULL, 0, this),
3153 fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", (void*)NULL, 0, this),
3154 //-
3155 fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
3156 fDimFtmTriggerRates ("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this),
3157 fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
3158 fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
3159 fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
3160 fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this),
3161 fDimFtmCounter ("FTM_CONTROL/COUNTER", (void*)NULL, 0, this),
3162 //-
3163 fDimFadWriteStats ("FAD_CONTROL/STATS", (void*)NULL, 0, this),
3164 fDimFadRuns ("FAD_CONTROL/RUNS", (void*)NULL, 0, this),
3165 fDimFadEvents ("FAD_CONTROL/EVENTS", (void*)NULL, 0, this),
3166 fDimFadRawData ("FAD_CONTROL/RAW_DATA", (void*)NULL, 0, this),
3167 fDimFadEventData ("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, this),
3168 fDimFadConnections ("FAD_CONTROL/CONNECTIONS", (void*)NULL, 0, this),
3169 fDimFadFwVersion ("FAD_CONTROL/FIRMWARE_VERSION", (void*)NULL, 0, this),
3170 fDimFadRunNumber ("FAD_CONTROL/RUN_NUMBER", (void*)NULL, 0, this),
3171 fDimFadDNA ("FAD_CONTROL/DNA", (void*)NULL, 0, this),
3172 fDimFadTemperature ("FAD_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3173 fDimFadPrescaler ("FAD_CONTROL/PRESCALER", (void*)NULL, 0, this),
3174 fDimFadRefClock ("FAD_CONTROL/REFERENCE_CLOCK", (void*)NULL, 0, this),
3175 fDimFadRoi ("FAD_CONTROL/REGION_OF_INTEREST", (void*)NULL, 0, this),
3176 fDimFadDac ("FAD_CONTROL/DAC", (void*)NULL, 0, this),
3177 fDimFadDrsCalibration ("FAD_CONTROL/DRS_CALIBRATION", (void*)NULL, 0, this),
3178 fDimFadStatus ("FAD_CONTROL/STATUS", (void*)NULL, 0, this),
3179 fDimFadStatistics1 ("FAD_CONTROL/STATISTICS1", (void*)NULL, 0, this),
3180 fDimFadStatistics2 ("FAD_CONTROL/STATISTICS2", (void*)NULL, 0, this),
3181 //-
3182 fEventData(0), fDrsCalibration(1440*1024*6),
3183 fTimeStamp0(0)
3184
3185 {
3186 fClockCondFreq->addItem("--- Hz", QVariant(-1));
3187 fClockCondFreq->addItem("800 MHz", QVariant(800));
3188 fClockCondFreq->addItem("1 GHz", QVariant(1000));
3189 fClockCondFreq->addItem("2 GHz", QVariant(2000));
3190 fClockCondFreq->addItem("3 GHz", QVariant(3000));
3191 fClockCondFreq->addItem("4 GHz", QVariant(4000));
3192 fClockCondFreq->addItem("5 GHz", QVariant(5000));
3193
3194 fMcpNumEvents->addItem("unlimited", QVariant(0));
3195 fMcpNumEvents->addItem("100", QVariant(100));
3196 fMcpNumEvents->addItem("300", QVariant(300));
3197 fMcpNumEvents->addItem("1000", QVariant(1000));
3198 fMcpNumEvents->addItem("3000", QVariant(3000));
3199 fMcpNumEvents->addItem("10000", QVariant(10000));
3200 fMcpNumEvents->addItem("30000", QVariant(30000));
3201
3202 fMcpTime->addItem("unlimited", QVariant(0));
3203 fMcpTime->addItem("00:30", QVariant(30));
3204 fMcpTime->addItem("01:00", QVariant(60));
3205 fMcpTime->addItem("02:30", QVariant(150));
3206 fMcpTime->addItem("05:00", QVariant(300));
3207 fMcpTime->addItem("10:00", QVariant(600));
3208 fMcpTime->addItem("15:00", QVariant(900));
3209 fMcpTime->addItem("20:00", QVariant(1200));
3210 fMcpTime->addItem("30:00", QVariant(1800));
3211 fMcpTime->addItem("60:00", QVariant(3600));
3212
3213 fMcpRunType->addItem("Data", QVariant("data"));
3214 fMcpRunType->addItem("Pedestal", QVariant("pedestal"));
3215 fMcpRunType->addItem("DRS Calib", QVariant("drs-calib"));
3216 fMcpRunType->addItem("Light pulser", QVariant("light-pulser"));
3217
3218 fTriggerWidget->setEnabled(false);
3219 fFtuWidget->setEnabled(false);
3220 fFtuGroupEnable->setEnabled(false);
3221 fRatesControls->setEnabled(false);
3222 fFadWidget->setEnabled(false);
3223 fEvtBldWidget->setEnabled(false);
3224 fLoggerWidget->setEnabled(false);
3225
3226 fChatSend->setEnabled(false);
3227 fChatMessage->setEnabled(false);
3228
3229 DimClient::sendCommand("CHAT/MSG", "GUI online.");
3230 // + MessageDimRX
3231
3232 // --------------------------------------------------------------------------
3233
3234 ifstream fin1("Trigger-Patches.txt");
3235
3236 int l = 0;
3237
3238 string buf;
3239 while (getline(fin1, buf, '\n'))
3240 {
3241 buf = Tools::Trim(buf);
3242 if (buf[0]=='#')
3243 continue;
3244
3245 stringstream str(buf);
3246 for (int i=0; i<9; i++)
3247 {
3248 unsigned int n;
3249 str >> n;
3250
3251 if (n>=fPatchHW.size())
3252 continue;
3253
3254 fPatchHW[n] = l;
3255 }
3256 l++;
3257 }
3258
3259 if (l!=160)
3260 cerr << "WARNING - Problems reading Trigger-Patches.txt" << endl;
3261
3262 // --------------------------------------------------------------------------
3263
3264 ifstream fin2("MasterList-v3.txt");
3265
3266 l = 0;
3267
3268 while (getline(fin2, buf, '\n'))
3269 {
3270 buf = Tools::Trim(buf);
3271 if (buf[0]=='#')
3272 continue;
3273
3274 unsigned int softid, hardid, dummy;
3275
3276 stringstream str(buf);
3277
3278 str >> softid;
3279 str >> dummy;
3280 str >> hardid;
3281
3282 if (softid>=fPixelMapHW.size())
3283 continue;
3284
3285 fPixelMapHW[softid] = hardid;
3286
3287 l++;
3288 }
3289
3290 if (l!=1440)
3291 cerr << "WARNING - Problems reading MasterList-v3.txt" << endl;
3292
3293 // --------------------------------------------------------------------------
3294
3295 ifstream fin3("PatchList.txt");
3296
3297 l = 0;
3298
3299 while (getline(fin3, buf, '\n'))
3300 {
3301 buf = Tools::Trim(buf);
3302 if (buf[0]=='#')
3303 continue;
3304
3305 unsigned int softid, hardid;
3306
3307 stringstream str(buf);
3308
3309 str >> softid;
3310 str >> hardid;
3311
3312 if (softid>=fPatchMapHW.size())
3313 continue;
3314
3315 fPatchMapHW[softid] = hardid-1;
3316
3317 l++;
3318 }
3319
3320 if (l!=160)
3321 cerr << "WARNING - Problems reading PatchList.txt" << endl;
3322
3323 // --------------------------------------------------------------------------
3324#ifdef HAVE_ROOT
3325
3326 fGraphFtmRate.SetLineColor(kBlue);
3327 fGraphFtmRate.SetMarkerColor(kBlue);
3328 fGraphFtmRate.SetMarkerStyle(kFullDotMedium);
3329
3330 for (int i=0; i<160; i++)
3331 {
3332 fGraphPatchRate[i].SetName("PatchRate");
3333 //fGraphPatchRate[i].SetLineColor(kBlue);
3334 //fGraphPatchRate[i].SetMarkerColor(kBlue);
3335 fGraphPatchRate[i].SetMarkerStyle(kFullDotMedium);
3336 }
3337 for (int i=0; i<40; i++)
3338 {
3339 fGraphBoardRate[i].SetName("BoardRate");
3340 //fGraphBoardRate[i].SetLineColor(kBlue);
3341 //fGraphBoardRate[i].SetMarkerColor(kBlue);
3342 fGraphBoardRate[i].SetMarkerStyle(kFullDotMedium);
3343 }
3344 /*
3345 TCanvas *c = fFtmTempCanv->GetCanvas();
3346 c->SetBit(TCanvas::kNoContextMenu);
3347 c->SetBorderMode(0);
3348 c->SetFrameBorderMode(0);
3349 c->SetFillColor(kWhite);
3350 c->SetRightMargin(0.03);
3351 c->SetTopMargin(0.03);
3352 c->cd();
3353 */
3354 //CreateTimeFrame("Temperature / �C");
3355
3356 fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
3357 fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
3358 fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
3359 fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
3360
3361 fGraphFtmTemp[1].SetLineColor(kBlue);
3362 fGraphFtmTemp[2].SetLineColor(kRed);
3363 fGraphFtmTemp[3].SetLineColor(kGreen);
3364
3365 fGraphFtmTemp[1].SetMarkerColor(kBlue);
3366 fGraphFtmTemp[2].SetMarkerColor(kRed);
3367 fGraphFtmTemp[3].SetMarkerColor(kGreen);
3368
3369 //fGraphFtmTemp[0].Draw("LP");
3370 //fGraphFtmTemp[1].Draw("LP");
3371 //fGraphFtmTemp[2].Draw("LP");
3372 //fGraphFtmTemp[3].Draw("LP");
3373
3374 // --------------------------------------------------------------------------
3375
3376 TCanvas *c = fFtmRateCanv->GetCanvas();
3377 //c->SetBit(TCanvas::kNoContextMenu);
3378 c->SetBorderMode(0);
3379 c->SetFrameBorderMode(0);
3380 c->SetFillColor(kWhite);
3381 c->SetRightMargin(0.03);
3382 c->SetTopMargin(0.03);
3383 c->SetGrid();
3384 c->cd();
3385
3386 TH1 *hf = DrawTimeFrame("Trigger rate [Hz]");
3387 hf->GetYaxis()->SetRangeUser(0, 1010);
3388
3389 fGraphFtmRate.SetMarkerStyle(kFullDotSmall);
3390 fGraphFtmRate.Draw("LP");
3391
3392 // --------------------------------------------------------------------------
3393
3394//ETIENNE MESS HERE
3395// c = fRatesCanv->GetCanvas();
3396 //c->SetBit(TCanvas::kNoContextMenu);
3397// c->SetBorderMode(0);
3398// c->SetFrameBorderMode(0);
3399// c->SetFillColor(kWhite);
3400// c->cd();
3401
3402 Camera *cam = fRatesCanv;//new Camera;
3403// cam->SetBit(kCanDelete);
3404 cam->SetMin(fRatesMin->value());
3405 cam->SetMax(fRatesMax->value());
3406// cam->Draw();
3407 cam->updateGL();
3408
3409 ChoosePixel(*cam, 0);
3410
3411 // --------------------------------------------------------------------------
3412
3413 c = fAdcDataCanv->GetCanvas();
3414 //c->SetBit(TCanvas::kNoContextMenu);
3415 c->SetBorderMode(0);
3416 c->SetFrameBorderMode(0);
3417 c->SetFillColor(kWhite);
3418 c->SetRightMargin(0.10);
3419 c->SetGrid();
3420 c->cd();
3421
3422 // --------------------------------------------------------------------------
3423
3424/* c = fEventCanv->GetCanvas();
3425 c->SetBit(TCanvas::kNoContextMenu);
3426 c->SetBorderMode(0);
3427 c->SetFrameBorderMode(0);
3428 c->SetFillColor(kWhite);
3429 c->Divide(2,2);
3430 c->cd(1);
3431 gPad->SetBorderMode(0);
3432 gPad->SetFrameBorderMode(0);
3433 gPad->SetFillColor(kWhite);
3434 //ETIENNE MESS HERE
3435// Camera *cam1 = new Camera;
3436// cam1->SetBit(kCanDelete);
3437// cam1->Draw();
3438 c->cd(2);
3439 gPad->SetBorderMode(0);
3440 gPad->SetFrameBorderMode(0);
3441 gPad->SetFillColor(kWhite);
3442// Camera *cam2 = new Camera;
3443// cam2->SetBit(kCanDelete);
3444// cam2->Draw();
3445 c->cd(3);
3446 gPad->SetBorderMode(0);
3447 gPad->SetFrameBorderMode(0);
3448 gPad->SetFillColor(kWhite);
3449// Camera *cam3 = new Camera;
3450// cam3->SetBit(kCanDelete);
3451// cam3->Draw();
3452 c->cd(4);
3453 gPad->SetBorderMode(0);
3454 gPad->SetFrameBorderMode(0);
3455 gPad->SetFillColor(kWhite);
3456 // Camera *cam4 = new Camera;
3457// cam4->SetBit(kCanDelete);
3458// cam4->Draw();
3459
3460*/
3461
3462 // Create histogram?
3463
3464 // --------------------------------------------------------------------------
3465
3466 QTimer::singleShot(1000, this, SLOT(slot_RootUpdate()));
3467
3468 //widget->setMouseTracking(true);
3469 //widget->EnableSignalEvents(kMouseMoveEvent);
3470
3471 fFtmRateCanv->setMouseTracking(true);
3472 fFtmRateCanv->EnableSignalEvents(kMouseMoveEvent);
3473
3474 fAdcDataCanv->setMouseTracking(true);
3475 fAdcDataCanv->EnableSignalEvents(kMouseMoveEvent);
3476
3477 fRatesCanv->setMouseTracking(true);
3478//ETIENNE MESS HERE
3479// fRatesCanv->EnableSignalEvents(kMouseMoveEvent|kMouseReleaseEvent|kMouseDoubleClickEvent);
3480// connect(fRatesCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
3481// this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
3482 connect(fRatesCanv, SIGNAL(signalPixelMoveOver(int)),
3483 this, SLOT(slot_CameraMouseMove(int)));
3484 connect(fEventCanv1, SIGNAL(signalCurrentPixel(int)),
3485 this, SLOT(slot_CameraMouseMove(int)));
3486 connect(fEventCanv2, SIGNAL(signalCurrentPixel(int)),
3487 this, SLOT(slot_CameraMouseMove(int)));
3488 connect(fEventCanv3, SIGNAL(signalCurrentPixel(int)),
3489 this, SLOT(slot_CameraMouseMove(int)));
3490 connect(fEventCanv4, SIGNAL(signalCurrentPixel(int)),
3491 this, SLOT(slot_CameraMouseMove(int)));
3492
3493 connect(fRatesCanv, SIGNAL(signalPixelDoubleClick(int)),
3494 this, SLOT(slot_CameraDoubleClick(int)));
3495 connect(fRatesCanv, SIGNAL(signalCurrentPixel(int)),
3496 this, SLOT(slot_ChoosePixel(int)));
3497 connect(fFtmRateCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
3498 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
3499 connect(fAdcDataCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
3500 this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
3501#endif
3502 }
3503
3504 ~FactGui()
3505 {
3506 // Unsubscribe all services
3507 for (map<string,DimInfo*>::iterator i=fServices.begin();
3508 i!=fServices.end(); i++)
3509 delete i->second;
3510
3511 delete fEventData;
3512 }
3513};
3514
3515#endif
Note: See TracBrowser for help on using the repository browser.