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

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