FACT++  1.0
FactGui.h
Go to the documentation of this file.
1 #ifndef FACT_FactGui
2 #define FACT_FactGui
3 
4 #include "MainWindow.h"
5 
6 #include <iomanip>
7 #include <valarray>
8 
9 #include <boost/regex.hpp>
10 
11 #include <QTimer>
12 #include <QtSql/QSqlError>
13 #include <QtSql/QSqlTableModel>
14 #include <QStandardItemModel>
15 
16 #include "CheckBoxDelegate.h"
17 
18 #include "src/Dim.h"
19 #include "src/Converter.h"
20 #include "src/Configuration.h"
21 #include "src/DimNetwork.h"
22 #include "src/tools.h"
23 #include "src/DimData.h"
24 #include "externals/PixelMap.h"
25 
26 #ifdef HAVE_ROOT
27 #include "TROOT.h"
28 #include "TSystem.h"
29 #include "TGraph.h"
30 #include "TGraphErrors.h"
31 #include "TH2.h"
32 #include "TBox.h"
33 #include "TStyle.h"
34 #include "TMarker.h"
35 #include "TColor.h"
36 #endif
37 
38 #include "QCameraWidget.h"
39 
40 #include "src/FAD.h"
41 #include "src/HeadersMCP.h"
42 #include "src/HeadersFTM.h"
43 #include "src/HeadersFAD.h"
44 #include "src/HeadersFSC.h"
45 #include "src/HeadersBIAS.h"
46 #include "src/HeadersDrive.h"
47 #include "src/HeadersFeedback.h"
48 #include "src/HeadersRateScan.h"
49 #include "src/HeadersRateControl.h"
51 
52 using namespace std;
53 
54 // #########################################################################
55 
56 class FactGui : public MainWindow, public DimNetwork, public DimInfoHandler
57 {
58 private:
59  class FunctionEvent : public QEvent
60  {
61  public:
62  function<void(const QEvent &)> fFunction;
63 
64  FunctionEvent(const function<void(const QEvent &)> &f)
65  : QEvent((QEvent::Type)QEvent::registerEventType()),
66  fFunction(f) { }
67 
68  bool Exec() { fFunction(*this); return true; }
69  };
70 
71  valarray<int8_t> fFtuStatus;
72 
74 
75  //vector<int> fPixelMapHW; // Software -> Hardware
76  vector<int> fPatchMapHW; // Software -> Hardware
77 
78  bool fInChoosePatchTH; // FIXME. Find a better solution
79  bool fInChooseBiasHv; // FIXME. Find a better solution
80  bool fInChooseBiasCam; // FIXME. Find a better solution
81 
83 
88 
96 
115  //DimStampedInfo fDimFadStatistics2;
117 
122 
125 
130 
132 
134 
135  map<string, DimInfo*> fServices;
136 
137  // ========================== LED Colors ================================
138 
140  {
154  };
155 
156  void SetLedColor(QPushButton *button, LedColor_t col, const Time &t)
157  {
158  switch (col)
159  {
160  case kLedRed:
161  button->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
162  break;
163 
164  case kLedGreen:
165  button->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
166  break;
167 
168  case kLedGreenBar:
169  button->setIcon(QIcon(":/Resources/icons/green bar.png"));
170  break;
171 
172  case kLedGreenWarn:
173  button->setIcon(QIcon(":/Resources/icons/green warn.png"));
174  break;
175 
176  case kLedGreenCheck:
177  button->setIcon(QIcon(":/Resources/icons/green check.png"));
178  break;
179 
180  case kLedYellow:
181  button->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
182  break;
183 
184  case kLedOrange:
185  button->setIcon(QIcon(":/Resources/icons/orange circle 1.png"));
186  break;
187 
188  case kLedGray:
189  button->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
190  break;
191 
192  case kLedWarnBorder:
193  button->setIcon(QIcon(":/Resources/icons/warning 1.png"));
194  break;
195 
196  case kLedWarn:
197  button->setIcon(QIcon(":/Resources/icons/warning 2.png"));
198  break;
199 
200  case kLedWarnTriangle:
201  button->setIcon(QIcon(":/Resources/icons/warning 3.png"));
202  break;
203 
204  case kLedWarnTriangleBorder:
205  button->setIcon(QIcon(":/Resources/icons/warning 4.png"));
206  break;
207 
208  case kLedInProgress:
209  button->setIcon(QIcon(":/Resources/icons/in progress.png"));
210  break;
211 
212  }
213 
214  //button->setToolTip("Last change: "+QDateTime::currentDateTimeUtc().toString()+" UTC");
215  button->setToolTip(("Last change: "+t.GetAsStr()+" (UTC)").c_str());
216  }
217 
218  // ===================== Services and Commands ==========================
219 
220  QStandardItem *AddServiceItem(const string &server, const string &service, bool iscmd)
221  {
222  QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
223  QListView *services = iscmd ? fDimCmdCommands : fDimSvcServices;
224  QListView *description = iscmd ? fDimCmdDescription : fDimSvcDescription;
225 
226  QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
227  if (!m)
228  {
229  m = new QStandardItemModel(this);
230  servers->setModel(m);
231  services->setModel(m);
232  description->setModel(m);
233  }
234 
235  QList<QStandardItem*> l = m->findItems(server.c_str());
236 
237  if (l.size()>1)
238  {
239  cout << "hae" << endl;
240  return 0;
241  }
242 
243  QStandardItem *col = l.size()==0 ? NULL : l[0];
244 
245  if (!col)
246  {
247  col = new QStandardItem(server.c_str());
248  m->appendRow(col);
249 
250  if (!services->rootIndex().isValid())
251  {
252  services->setRootIndex(col->index());
253  servers->setCurrentIndex(col->index());
254  }
255  }
256 
257  QStandardItem *item = 0;
258  for (int i=0; i<col->rowCount(); i++)
259  {
260  QStandardItem *coli = col->child(i);
261  if (coli->text().toStdString()==service)
262  return coli;
263  }
264 
265  item = new QStandardItem(service.c_str());
266  col->appendRow(item);
267  col->sortChildren(0);
268 
269  if (!description->rootIndex().isValid())
270  {
271  description->setRootIndex(item->index());
272  services->setCurrentIndex(item->index());
273  }
274 
275  if (!iscmd)
276  item->setCheckable(true);
277 
278  return item;
279  }
280 
281  void AddDescription(QStandardItem *item, const vector<Description> &vec)
282  {
283  if (!item)
284  return;
285  if (vec.size()==0)
286  return;
287 
288  item->setToolTip(vec[0].comment.c_str());
289 
290  const string str = Description::GetHtmlDescription(vec);
291 
292  QStandardItem *desc = new QStandardItem(str.c_str());
293  desc->setSelectable(false);
294  item->setChild(0, 0, desc);
295  }
296 
297  void AddServer(const string &s)
298  {
300 
301  const State state = GetState(s, GetCurrentState(s));
302 
303  QApplication::postEvent(this,
304  new FunctionEvent(bind(&FactGui::handleAddServer, this, s, state)));
305  }
306 
307  void AddService(const string &server, const string &service, const string &fmt, bool iscmd)
308  {
309  const vector<Description> v = GetDescription(server, service);
310 
311  QApplication::postEvent(this,
312  new FunctionEvent(bind(&FactGui::handleAddService, this, server, service, fmt, iscmd, v)));
313  }
314 
315  void RemoveService(string server, string service, bool iscmd)
316  {
317  UnsubscribeService(server+'/'+service, true);
318 
319  QApplication::postEvent(this,
320  new FunctionEvent(bind(&FactGui::handleRemoveService, this, server, service, iscmd)));
321  }
322 
323  void RemoveAllServices(const string &server)
324  {
325  UnsubscribeAllServices(server);
326 
327  QApplication::postEvent(this,
328  new FunctionEvent(bind(&FactGui::handleRemoveAllServices, this, server)));
329  }
330 
331  void AddDescription(const string &server, const string &service, const vector<Description> &vec)
332  {
333  const bool iscmd = IsCommand(server, service)==true;
334 
335  QApplication::postEvent(this,
336  new FunctionEvent(bind(&FactGui::handleAddDescription, this, server, service, vec, iscmd)));
337  }
338 
339  // ======================================================================
340 
341  void handleAddServer(const string &server, const State &state)
342  {
343  handleStateChanged(Time(), server, state);
344  }
345 
346  void handleAddService(const string &server, const string &service, const string &/*fmt*/, bool iscmd, const vector<Description> &vec)
347  {
348  QStandardItem *item = AddServiceItem(server, service, iscmd);
349  AddDescription(item, vec);
350  }
351 
352  void handleRemoveService(const string &server, const string &service, bool iscmd)
353  {
354  QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
355 
356  QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
357  if (!m)
358  return;
359 
360  QList<QStandardItem*> l = m->findItems(server.c_str());
361  if (l.size()!=1)
362  return;
363 
364  for (int i=0; i<l[0]->rowCount(); i++)
365  {
366  QStandardItem *row = l[0]->child(i);
367  if (row->text().toStdString()==service)
368  {
369  l[0]->removeRow(row->index().row());
370  return;
371  }
372  }
373  }
374 
375  void handleRemoveAllServices(const string &server)
376  {
377  handleStateChanged(Time(), server, State(-2, "Offline", "No connection via DIM."));
378 
379  QStandardItemModel *m = 0;
380  if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
381  {
382  QList<QStandardItem*> l = m->findItems(server.c_str());
383  if (l.size()==1)
384  m->removeRow(l[0]->index().row());
385  }
386 
387  if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
388  {
389  QList<QStandardItem*> l = m->findItems(server.c_str());
390  if (l.size()==1)
391  m->removeRow(l[0]->index().row());
392  }
393  }
394 
395  void handleAddDescription(const string &server, const string &service, const vector<Description> &vec, bool iscmd)
396  {
397  QStandardItem *item = AddServiceItem(server, service, iscmd);
398  AddDescription(item, vec);
399  }
400 
401  // ======================================================================
402 
403  void SubscribeService(const string &service)
404  {
405  if (fServices.find(service)!=fServices.end())
406  {
407  cerr << "ERROR - We are already subscribed to " << service << endl;
408  return;
409  }
410 
411  fServices[service] = new DimStampedInfo(service.c_str(), (void*)NULL, 0, this);
412  }
413 
414  void UnsubscribeService(const string &service, bool allow_unsubscribed=false)
415  {
416  const map<string,DimInfo*>::iterator i=fServices.find(service);
417 
418  if (i==fServices.end())
419  {
420  if (!allow_unsubscribed)
421  cerr << "ERROR - We are not subscribed to " << service << endl;
422  return;
423  }
424 
425  delete i->second;
426 
427  fServices.erase(i);
428  }
429 
430  void UnsubscribeAllServices(const string &server)
431  {
432  for (map<string,DimInfo*>::iterator i=fServices.begin();
433  i!=fServices.end(); i++)
434  if (i->first.substr(0, server.length()+1)==server+'/')
435  {
436  delete i->second;
437  fServices.erase(i);
438  }
439  }
440 
441  // ======================= DNS ==========================================
442 
443  uint32_t fDimVersion;
444 
446  {
447  ostringstream dns;
448  dns << (fDimVersion==0?"No connection":"Connection");
449  dns << " to DIM DNS (" << getenv("DIM_DNS_NODE") << ")";
450  dns << (fDimVersion==0?".":" established");
451 
452  ostringstream str;
453  str << "V" << fDimVersion/100 << 'r' << fDimVersion%100;
454 
455  LedColor_t led = kLedGreen;
456  if (fDimVersion>0)
457  {
458  dns << fixed << setprecision(1) << right;
459  if (fFreeSpaceLogger!=UINT64_MAX)
460  dns << "<pre> * Data logger: " << setw(7) << fFreeSpaceLogger*1e-7 << " GB</pre>";
461  if (fFreeSpaceData!=UINT64_MAX)
462  dns << "<pre> * Event Builder: " << setw(7) << fFreeSpaceData*1e-7 << " GB</pre>";
463 
464  if (fFreeSpaceLogger<500000000 || fFreeSpaceData<500000000)
465  led = kLedGreenWarn;
466  if (fFreeSpaceLogger<200000000 || fFreeSpaceData<200000000)
467  led = kLedWarnTriangleBorder;
468 
469  if (led!=kLedGreen)
470  str << " (Disk space!)";
471  }
472 
473  fStatusDNSLabel->setToolTip(dns.str().c_str());
474 
475  SetLedColor(fStatusDNSLed, fDimVersion==0 ? kLedRed : led, Time());
476 
477  fStatusDNSLabel->setText(fDimVersion==0?"Offline":str.str().c_str());
478  }
479 
480  void handleDimDNS(const DimData &d)
481  {
482  fDimVersion = d.size()!=4 ? 0 : d.get<uint32_t>();
483 
484  UpdateGlobalStatus();
485 
486  fShutdown->setEnabled(fDimVersion!=0);
487  fShutdownAll->setEnabled(fDimVersion!=0);
488  }
489 
490 
491  // ======================= Logger =======================================
492 
494 
495  void handleLoggerStats(const DimData &d)
496  {
497  const bool connected = d.size()!=0;
498 
499  fLoggerET->setEnabled(connected);
500  fLoggerRate->setEnabled(connected);
501  fLoggerWritten->setEnabled(connected);
502  fLoggerFreeSpace->setEnabled(connected);
503  fLoggerSpaceLeft->setEnabled(connected);
504 
505  fFreeSpaceLogger = UINT64_MAX;
506  UpdateGlobalStatus();
507 
508  if (!connected)
509  return;
510 
511  const uint64_t *vals = d.ptr<uint64_t>();
512 
513  const size_t space = vals[0];
514  const size_t written = vals[1];
515  const size_t rate = float(vals[2])/vals[3];
516 
517  fFreeSpaceLogger = space;
518  UpdateGlobalStatus();
519 
520  fLoggerFreeSpace->setSuffix(" MB");
521  fLoggerFreeSpace->setDecimals(0);
522  fLoggerFreeSpace->setValue(space*1e-6);
523 
524  if (space> 1000000) // > 1GB
525  {
526  fLoggerFreeSpace->setSuffix(" GB");
527  fLoggerFreeSpace->setDecimals(2);
528  fLoggerFreeSpace->setValue(space*1e-9);
529  }
530  if (space>= 3000000) // >= 3GB
531  {
532  fLoggerFreeSpace->setSuffix(" GB");
533  fLoggerFreeSpace->setDecimals(1);
534  fLoggerFreeSpace->setValue(space*1e-9);
535  }
536  if (space>=100000000) // >= 100GB
537  {
538  fLoggerFreeSpace->setSuffix(" GB");
539  fLoggerFreeSpace->setDecimals(0);
540  fLoggerFreeSpace->setValue(space*1e-9);
541  }
542 
543  fLoggerET->setTime(QTime().addSecs(rate>0?space/rate:0));
544  fLoggerRate->setValue(rate*1e-3); // kB/s
545  fLoggerWritten->setValue(written*1e-6);
546 
547  fLoggerRate->setSuffix(" kB/s");
548  fLoggerRate->setDecimals(2);
549  fLoggerRate->setValue(rate);
550  if (rate> 2) // > 2kB/s
551  {
552  fLoggerRate->setSuffix(" kB/s");
553  fLoggerRate->setDecimals(1);
554  fLoggerRate->setValue(rate);
555  }
556  if (rate>=100) // >100kB/s
557  {
558  fLoggerRate->setSuffix(" kB/s");
559  fLoggerRate->setDecimals(0);
560  fLoggerRate->setValue(rate);
561  }
562  if (rate>=1000) // >100kB/s
563  {
564  fLoggerRate->setSuffix(" MB/s");
565  fLoggerRate->setDecimals(2);
566  fLoggerRate->setValue(rate*1e-3);
567  }
568  if (rate>=10000) // >1MB/s
569  {
570  fLoggerRate->setSuffix(" MB/s");
571  fLoggerRate->setDecimals(1);
572  fLoggerRate->setValue(rate*1e-3);
573  }
574  if (rate>=100000) // >10MB/s
575  {
576  fLoggerRate->setSuffix(" MB/s");
577  fLoggerRate->setDecimals(0);
578  fLoggerRate->setValue(rate*1e-3);
579  }
580 
581  if (space/1000000>static_cast<size_t>(fLoggerSpaceLeft->maximum()))
582  fLoggerSpaceLeft->setValue(fLoggerSpaceLeft->maximum()); // GB
583  else
584  fLoggerSpaceLeft->setValue(space/1000000); // MB
585  }
586 
588  {
589  const bool connected = d.size()!=0;
590 
591  fLoggerFilenameNight->setEnabled(connected);
592  if (!connected)
593  return;
594 
595  fLoggerFilenameNight->setText(d.c_str()+4);
596 
597  const uint32_t files = d.get<uint32_t>();
598 
599  SetLedColor(fLoggerLedLog, files&1 ? kLedGreen : kLedGray, d.time);
600  SetLedColor(fLoggerLedRep, files&2 ? kLedGreen : kLedGray, d.time);
601  SetLedColor(fLoggerLedFits, files&4 ? kLedGreen : kLedGray, d.time);
602  }
603 
605  {
606  const bool connected = d.size()!=0;
607 
608  fLoggerFilenameRun->setEnabled(connected);
609  if (!connected)
610  return;
611 
612  fLoggerFilenameRun->setText(d.c_str()+4);
613 
614  const uint32_t files = d.get<uint32_t>();
615 
616  SetLedColor(fLoggerLedLog, files&1 ? kLedGreen : kLedGray, d.time);
617  SetLedColor(fLoggerLedRep, files&2 ? kLedGreen : kLedGray, d.time);
618  SetLedColor(fLoggerLedFits, files&4 ? kLedGreen : kLedGray, d.time);
619  }
620 
622  {
623  const bool connected = d.size()!=0;
624 
625  fLoggerSubscriptions->setEnabled(connected);
626  fLoggerOpenFiles->setEnabled(connected);
627  if (!connected)
628  return;
629 
630  const uint32_t *vals = d.ptr<uint32_t>();
631 
632  fLoggerSubscriptions->setValue(vals[0]);
633  fLoggerOpenFiles->setValue(vals[1]);
634  }
635 
636 
637  // ===================== All ============================================
638 
639  bool CheckSize(const DimData &d, size_t sz, bool print=true) const
640  {
641  if (d.size()==0)
642  return false;
643 
644  if (d.size()!=sz)
645  {
646  if (print)
647  cerr << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected=" << sz << endl;
648  return false;
649  }
650 
651  return true;
652  }
653 
654  // ===================== FAD ============================================
655 
656  uint64_t fFreeSpaceData;
657 
659  {
660  const bool connected = d.size()!=0;
661 
662  fEvtBuilderET->setEnabled(connected);
663  fEvtBuilderRate->setEnabled(connected);
664  fEvtBuilderWritten->setEnabled(connected);
665  fEvtBuilderFreeSpace->setEnabled(connected);
666  fEvtBuilderSpaceLeft->setEnabled(connected);
667 
668  fFreeSpaceData = UINT64_MAX;
669  UpdateGlobalStatus();
670 
671  if (!connected)
672  return;
673 
674  const uint64_t *vals = d.ptr<uint64_t>();
675 
676  const size_t space = vals[0];
677  const size_t written = vals[1];
678  const size_t rate = float(vals[2])/vals[3];
679 
680  fFreeSpaceData = space;
681  UpdateGlobalStatus();
682 
683  fEvtBuilderFreeSpace->setSuffix(" MB");
684  fEvtBuilderFreeSpace->setDecimals(0);
685  fEvtBuilderFreeSpace->setValue(space*1e-6);
686 
687  if (space> 1000000) // > 1GB
688  {
689  fEvtBuilderFreeSpace->setSuffix(" GB");
690  fEvtBuilderFreeSpace->setDecimals(2);
691  fEvtBuilderFreeSpace->setValue(space*1e-9);
692  }
693  if (space>= 3000000) // >= 3GB
694  {
695  fEvtBuilderFreeSpace->setSuffix(" GB");
696  fEvtBuilderFreeSpace->setDecimals(1);
697  fEvtBuilderFreeSpace->setValue(space*1e-9);
698  }
699  if (space>=100000000) // >= 100GB
700  {
701  fEvtBuilderFreeSpace->setSuffix(" GB");
702  fEvtBuilderFreeSpace->setDecimals(0);
703  fEvtBuilderFreeSpace->setValue(space*1e-9);
704  }
705 
706  fEvtBuilderET->setTime(QTime().addSecs(rate>0?space/rate:0));
707  fEvtBuilderRate->setValue(rate*1e-3); // kB/s
708  fEvtBuilderWritten->setValue(written*1e-6);
709 
710  fEvtBuilderRate->setSuffix(" kB/s");
711  fEvtBuilderRate->setDecimals(2);
712  fEvtBuilderRate->setValue(rate);
713  if (rate> 2) // > 2kB/s
714  {
715  fEvtBuilderRate->setSuffix(" kB/s");
716  fEvtBuilderRate->setDecimals(1);
717  fEvtBuilderRate->setValue(rate);
718  }
719  if (rate>=100) // >100kB/s
720  {
721  fEvtBuilderRate->setSuffix(" kB/s");
722  fEvtBuilderRate->setDecimals(0);
723  fEvtBuilderRate->setValue(rate);
724  }
725  if (rate>=1000) // >100kB/s
726  {
727  fEvtBuilderRate->setSuffix(" MB/s");
728  fEvtBuilderRate->setDecimals(2);
729  fEvtBuilderRate->setValue(rate*1e-3);
730  }
731  if (rate>=10000) // >1MB/s
732  {
733  fEvtBuilderRate->setSuffix(" MB/s");
734  fEvtBuilderRate->setDecimals(1);
735  fEvtBuilderRate->setValue(rate*1e-3);
736  }
737  if (rate>=100000) // >10MB/s
738  {
739  fEvtBuilderRate->setSuffix(" MB/s");
740  fEvtBuilderRate->setDecimals(0);
741  fEvtBuilderRate->setValue(rate*1e-3);
742  }
743 
744  if (space/1000000>static_cast<size_t>(fEvtBuilderSpaceLeft->maximum()))
745  fEvtBuilderSpaceLeft->setValue(fEvtBuilderSpaceLeft->maximum()); // GB
746  else
747  fEvtBuilderSpaceLeft->setValue(space/1000000); // MB
748  }
749 
750  void handleFadRuns(const DimData &d)
751  {
752  if (d.size()==0)
753  return;
754 
755  if (d.size()<8)
756  {
757  cerr << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected>=8" << endl;
758  return;
759  }
760 
761  const uint32_t *ptr = d.ptr<uint32_t>();
762 
763  fEvtBldLastOpened->setValue(ptr[0]);
764  fEvtBldLastClosed->setValue(ptr[1]);
765 
766  if (d.size()>=8)
767  fEvtBldFilename->setText(d.ptr<char>(8));
768 
769  fEvtBldLastOpened->setEnabled(d.qos);
770  fEvtBldLastClosed->setEnabled(d.qos);
771  fEvtBldFilename->setEnabled(d.qos);
772  }
773 
774  void handleFadStartRun(const DimData &d)
775  {
776  if (!CheckSize(d, 16))
777  return;
778 
779  const int64_t *runs = d.ptr<int64_t>();
780 
781  fFadRunNoCur->setValue(runs[0]);
782  fFadRunNoNext->setValue(runs[1]);
783  fFadRunNoCur->setEnabled(runs[0]>=0);
784  //fMcpStopRun->setEnabled(runs[0]>=0);
785 
786  }
787 
788  void handleFadEvents(const DimData &d)
789  {
790  if (!CheckSize(d, 16))
791  return;
792 
793  const uint32_t *ptr = d.ptr<uint32_t>();
794 
795  fEvtsSuccessCurRun->setValue(ptr[0]);
796  fEvtsSuccessTotal->setValue(ptr[1]);
797  fEvtBldEventId->setValue(ptr[2]);
798  fFadEvtCounter->setValue(ptr[2]);
799  fEvtBldTriggerId->setValue(ptr[3]);
800  }
801 
803  {
804  if (d.size()==0)
805  {
806  fFadTempMin->setEnabled(false);
807  fFadTempMax->setEnabled(false);
808  SetLedColor(fFadLedTemp, kLedGray, d.time);
809  return;
810  }
811 
812  if (!CheckSize(d, sizeof(uint16_t)+160*sizeof(float)))
813  return;
814 
815  const float *ptr = d.ptr<float>(2);
816 
817  fFadTempMin->setEnabled(true);
818  fFadTempMax->setEnabled(true);
819 
820  float min = FLT_MAX;
821  float max = -FLT_MAX;
822 
823  vector<float> mn(40, FLT_MAX);
824  vector<float> mx(40, -FLT_MAX);
825  for (int i=0; i<160; i++)
826  {
827  if (!finite(ptr[i]))
828  continue;
829 
830  if (ptr[i]<min)
831  min = ptr[i];
832  if (ptr[i]>max)
833  max = ptr[i];
834 
835  if (ptr[i]<mn[i/4])
836  mn[i/4] = ptr[i];
837  if (ptr[i]>mx[i/4])
838  mx[i/4] = ptr[i];
839  }
840 
841  fFadTempMin->setValue(min);
842  fFadTempMax->setValue(max);
843 
844  handleFadToolTip(d.time, fFadTempMin, mn.data());
845  handleFadToolTip(d.time, fFadTempMax, mx.data());
846  }
847 
848  void handleFadRefClock(const DimData &d)
849  {
850  if (d.size()==0)
851  {
852  fFadRefClockMin->setEnabled(false);
853  fFadRefClockMax->setEnabled(false);
854  SetLedColor(fFadLedRefClock, kLedGray, d.time);
855  return;
856  }
857 
858  if (!CheckSize(d, sizeof(uint16_t)+40*sizeof(float)))
859  return;
860 
861  const float *ptr = d.ptr<float>(2);
862 
863  fFadRefClockMin->setEnabled(true);
864  fFadRefClockMax->setEnabled(true);
865 
866  float min = FLT_MAX;
867  float max = -FLT_MAX;
868  for (int i=0; i<40; i++)
869  {
870  if (!finite(ptr[i]))
871  continue;
872 
873  if (ptr[i]<min)
874  min = ptr[i];
875  if (ptr[i]>max)
876  max = ptr[i];
877  }
878 
879  fFadRefClockMin->setValue(min);
880  fFadRefClockMax->setValue(max);
881 
882  const int64_t diff = int64_t(max) - int64_t(min);
883 
884  SetLedColor(fFadLedRefClock, abs(diff)>3?kLedRed:kLedGreen, d.time);
885 
886  handleFadToolTip(d.time, fFadLedRefClock, ptr);
887  }
888 
889  void handleFadRoi(const DimData &d)
890  {
891  if (d.size()==0)
892  {
893  fFadRoi->setEnabled(false);
894  fFadRoiCh9->setEnabled(false);
895  //SetLedColor(fFadLedRoi, kLedGray, d.time);
896  return;
897  }
898 
899  if (!CheckSize(d, 2*sizeof(uint16_t)))
900  return;
901 
902  const uint16_t *ptr = d.ptr<uint16_t>();
903 
904  fFadRoi->setEnabled(true);
905  fFadRoiCh9->setEnabled(true);
906 
907  fFadRoi->setValue(ptr[0]);
908  fFadRoiCh9->setValue(ptr[1]);
909 
910  //SetLedColor(fFadLedRoi, kLedGray, d.time);
911  }
912 
913  void handleDac(QPushButton *led, QSpinBox *box, const DimData &d, int idx)
914  {
915  if (d.size()==0)
916  {
917  box->setEnabled(false);
918  SetLedColor(led, kLedGray, d.time);
919  return;
920  }
921 
922  const uint16_t *ptr = d.ptr<uint16_t>()+idx*42;
923 
924  box->setEnabled(true);
925  box->setValue(ptr[40]==ptr[41]?ptr[40]:0);
926 
927  SetLedColor(led, ptr[40]==ptr[41]?kLedGreen:kLedOrange, d.time);
928  handleFadToolTip(d.time, led, ptr);
929  }
930 
931  void handleFadDac(const DimData &d)
932  {
933  if (!CheckSize(d, 8*42*sizeof(uint16_t)) && !d.size()==0)
934  return;
935 
936  handleDac(fFadLedDac0, fFadDac0, d, 0);
937  handleDac(fFadLedDac1, fFadDac1, d, 1);
938  handleDac(fFadLedDac2, fFadDac2, d, 2);
939  handleDac(fFadLedDac3, fFadDac3, d, 3);
940  handleDac(fFadLedDac4, fFadDac4, d, 4);
941  handleDac(fFadLedDac5, fFadDac5, d, 5);
942  handleDac(fFadLedDac6, fFadDac6, d, 6);
943  handleDac(fFadLedDac7, fFadDac7, d, 7);
944  }
945 
946  EVENT *fEventData;
947 
948  void DrawHorizontal(TH1 *hf, double xmax, TH1 &h, double scale)
949  {
950  for (Int_t i=1;i<=h.GetNbinsX();i++)
951  {
952  if (h.GetBinContent(i)<0.5 || h.GetBinContent(i)>h.GetEntries()-0.5)
953  continue;
954 
955  TBox * box=new TBox(xmax, h.GetBinLowEdge(i),
956  xmax+h.GetBinContent(i)*scale,
957  h.GetBinLowEdge(i+1));
958 
959  box->SetFillStyle(0);
960  box->SetLineColor(h.GetLineColor());
961  box->SetLineStyle(kSolid);
962  box->SetBit(kCannotPick|kNoContextMenu);
963  //box->Draw();
964 
965  hf->GetListOfFunctions()->Add(box);
966  }
967  }
968 
970  {
971  if (!fEventData)
972  return;
973 
974 #ifdef HAVE_ROOT
975  TCanvas *c = fAdcDataCanv->GetCanvas();
976 
977  TH1 *hf = dynamic_cast<TH1*>(c->FindObject("Frame"));
978  TH1 *h = dynamic_cast<TH1*>(c->FindObject("EventData"));
979  TH1 *d0 = dynamic_cast<TH1*>(c->FindObject("DrsCalib0"));
980  TH1 *d1 = dynamic_cast<TH1*>(c->FindObject("DrsCalib1"));
981  TH1 *d2 = dynamic_cast<TH1*>(c->FindObject("DrsCalib2"));
982 
983  const int roi = fAdcPhysical->isChecked() ? 1024 : (fEventData->Roi>0 ? fEventData->Roi : 1);
984 
985  if ((hf && hf->GetNbinsX()!=roi) ||
986  (dynamic_cast<TH2*>(h) && !fAdcPersistent->isChecked()) ||
987  (!dynamic_cast<TH2*>(h) && fAdcPersistent->isChecked()))
988  {
989  delete hf;
990  delete h;
991  delete d0;
992  delete d1;
993  delete d2;
994  d0 = 0;
995  d1 = 0;
996  d2 = 0;
997  hf = 0;
998  }
999 
1000  if (!hf)
1001  {
1002  hf = new TH1F("Frame", "", roi, -0.5, roi-0.5);
1003  hf->SetDirectory(0);
1004  hf->SetBit(kCanDelete);
1005  hf->SetStats(kFALSE);
1006  hf->SetYTitle("Voltage [mV]");
1007  hf->GetXaxis()->CenterTitle();
1008  hf->GetYaxis()->CenterTitle();
1009  hf->SetMinimum(-1250);
1010  hf->SetMaximum(2150);
1011 
1012  if (!fAdcPersistent->isChecked())
1013  h = new TH1F("EventData", "", roi, -0.5, roi-0.5);
1014  else
1015  {
1016  h = new TH2F("EventData", "", roi, -0.5, roi-0.5, 6751, -2350.5*2000/4096, 4400.5*2000/4096);
1017  h->SetContour(50);
1018  gStyle->SetPalette(1, 0);
1019  }
1020 
1021  h->SetDirectory(0);
1022  h->SetBit(kCanDelete);
1023  h->SetMarkerStyle(kFullDotMedium);
1024  h->SetMarkerColor(kBlue);
1025 
1026  c->GetListOfPrimitives()->Add(hf, "");
1027 
1028  if (dynamic_cast<TH2*>(h))
1029  c->GetListOfPrimitives()->Add(h, "col same");
1030  }
1031 
1032  if (d0 && !(fDrsCalibBaselineOn->isChecked() && fDrsCalibBaseline->value()>0))
1033  {
1034  delete d0;
1035  d0 = 0;
1036  }
1037  if (d1 && !(fDrsCalibGainOn->isChecked() && fDrsCalibGain->value()>0))
1038  {
1039  delete d1;
1040  d1 = 0;
1041  }
1042  if (d2 && !(fDrsCalibTrgOffsetOn->isChecked() && fDrsCalibTrgOffset->value()>0))
1043  {
1044  delete d2;
1045  d2 = 0;
1046  }
1047 
1048  if (!d0 && fDrsCalibBaselineOn->isChecked() && fDrsCalibBaseline->value()>0)
1049  {
1050  d0 = new TH1F("DrsCalib0", "", roi, -0.5, roi-0.5);
1051  d0->SetDirectory(0);
1052  d0->SetBit(kCanDelete);
1053  d0->SetMarkerStyle(kFullDotSmall);
1054  d0->SetMarkerColor(kRed);
1055  d0->SetLineColor(kRed);
1056  c->GetListOfPrimitives()->Add(d0, "PEX0same");
1057  }
1058 
1059  if (!d1 && fDrsCalibGainOn->isChecked() && fDrsCalibGain->value()>0)
1060  {
1061  d1 = new TH1F("DrsCalib1", "", roi, -0.5, roi-0.5);
1062  d1->SetDirectory(0);
1063  d1->SetBit(kCanDelete);
1064  d1->SetMarkerStyle(kFullDotSmall);
1065  d1->SetMarkerColor(kMagenta);
1066  d1->SetLineColor(kMagenta);
1067  c->GetListOfPrimitives()->Add(d1, "PEX0same");
1068  }
1069 
1070  if (!d2 && fDrsCalibTrgOffsetOn->isChecked() && fDrsCalibTrgOffset->value()>0)
1071  {
1072  d2 = new TH1F("DrsCalib2", "", roi, -0.5, roi-0.5);
1073  d2->SetDirectory(0);
1074  d2->SetBit(kCanDelete);
1075  d2->SetMarkerStyle(kFullDotSmall);
1076  d2->SetMarkerColor(kGreen);
1077  d2->SetLineColor(kGreen);
1078  c->GetListOfPrimitives()->Add(d2, "PEX0same");
1079  }
1080 
1081  if (!dynamic_cast<TH2*>(h) && !c->GetListOfPrimitives()->FindObject(h))
1082  c->GetListOfPrimitives()->Add(h, "PLsame");
1083 
1084  // -----------------------------------------------------------
1085 
1086  const uint32_t p =
1087  fAdcChannel->value() +
1088  fAdcChip->value() * 9+
1089  fAdcBoard->value() * 36+
1090  fAdcCrate->value() *360;
1091 
1092  ostringstream str;
1093  str << "CBPX = " << fAdcCrate->value() << '|' << fAdcBoard->value() << '|' << fAdcChip->value() << '|' << fAdcChannel->value() << " (" << p << ")";
1094  str << " EventNum = " << fEventData->EventNum;
1095  str << " TriggerNum = " << fEventData->TriggerNum;
1096  str << " TriggerType = " << fEventData->TriggerType;
1097  str << " BoardTime = " << fEventData->BoardTime[fAdcBoard->value()+fAdcCrate->value()*10];
1098  str << " (" << Time(fEventData->PCTime, fEventData->PCUsec) << ")";
1099  hf->SetTitle(str.str().c_str());
1100  str.str("");
1101  str << "ADC Pipeline (start cell: " << fEventData->StartPix[p] << ")";
1102  hf->SetXTitle(str.str().c_str());
1103 
1104  // -----------------------------------------------------------
1105 
1106  const int16_t start = fEventData->StartPix[p];
1107 
1108  fDrsCalibBaseline->setEnabled(fDrsCalibBaseline->value()>0);
1109  fDrsCalibGain->setEnabled(fDrsCalibGain->value()>0);
1110  fDrsCalibTrgOffset->setEnabled(fDrsCalibTrgOffset->value()>0);
1111  fDrsCalibROI->setEnabled(fDrsCalibROI->value()>0);
1112 
1113  fDrsCalibBaseline2->setEnabled(fDrsCalibBaseline->value()>0);
1114  fDrsCalibGain2->setEnabled(fDrsCalibGain->value()>0);
1115  fDrsCalibTrgOffset2->setEnabled(fDrsCalibTrgOffset->value()>0);
1116  fDrsCalibROI2->setEnabled(fDrsCalibROI->value()>0);
1117 
1118  SetLedColor(fFadLedDrsBaseline, fDrsCalibBaseline->value()>0 ?kLedGreen:kLedGray, Time());
1119  SetLedColor(fFadLedDrsGain, fDrsCalibGain->value()>0 ?kLedGreen:kLedGray, Time());
1120  SetLedColor(fFadLedDrsTrgOff, fDrsCalibTrgOffset->value()>0?kLedGreen:kLedGray, Time());
1121 
1122  if (d0)//fDrsCalibBaseline->value()==0 || start<0)
1123  d0->Reset();
1124  if (d1)//fDrsCalibGain->value()==0 || start<0)
1125  d1->Reset();
1126  if (d2)//fDrsCalibTrgOffset->value()==0 || start<0)
1127  d2->Reset();
1128 
1129  if (!dynamic_cast<TH2*>(h))
1130  h->Reset();
1131  if (d0)
1132  d0->SetEntries(0);
1133  if (d1)
1134  d1->SetEntries(0);
1135  if (d2)
1136  d2->SetEntries(0);
1137 
1138  for (int i=0; i<fEventData->Roi; i++)
1139  {
1140  // FIXME: physcial: i -> (i+start)%1024
1141  // FIXME: logical: i -> i
1142 
1143  const int ii = fAdcPhysical->isChecked() ? (i+start)%1024 : i;
1144 
1145  //if (dynamic_cast<TH2*>(h))
1146  h->Fill(ii, reinterpret_cast<float*>(fEventData->Adc_Data)[p*fEventData->Roi+i]);
1147  //else
1148  // h->SetBinContent(i+1, reinterpret_cast<float*>(fEventData->Adc_Data)[p*fEventData->Roi+i]);
1149  if (start<0)
1150  continue;
1151 
1152  if (d0)
1153  {
1154  d0->SetBinContent(ii+1, fDrsCalibration[1440*1024*0 + p*1024+(start+i)%1024]);
1155  d0->SetBinError(ii+1, fDrsCalibration[1440*1024*1 + p*1024+(start+i)%1024]);
1156 
1157  }
1158  if (d1)
1159  {
1160  d1->SetBinContent(ii+1, fDrsCalibration[1440*1024*2 + p*1024+(start+i)%1024]);
1161  d1->SetBinError(ii+1, fDrsCalibration[1440*1024*3 + p*1024+(start+i)%1024]);
1162  }
1163  if (d2)
1164  {
1165  d2->SetBinContent(ii+1, fDrsCalibration[1440*1024*4 + p*1024 + i]);
1166  d2->SetBinError(ii+1, fDrsCalibration[1440*1024*5 + p*1024 + i]);
1167  }
1168  }
1169 
1170  // -----------------------------------------------------------
1171  if (fAdcDynamicScale->isEnabled() && fAdcDynamicScale->isChecked())
1172  {
1173  h->SetMinimum();
1174  h->SetMaximum();
1175 
1176  hf->SetMinimum(h->GetMinimum());
1177  hf->SetMaximum(h->GetMaximum());
1178  }
1179  if (fAdcManualScale->isEnabled() && fAdcManualScale->isChecked())
1180  {
1181  if (h->GetMinimumStored()==-1111)
1182  {
1183  h->SetMinimum(-1150);//-1026);
1184  hf->SetMinimum(-1150);//-1026);
1185  }
1186  if (h->GetMaximumStored()==-1111)
1187  {
1188  h->SetMaximum(2150);//1025);
1189  hf->SetMaximum(2150);//1025);
1190  }
1191  }
1192 
1193  if (fAdcAutoScale->isEnabled() && fAdcAutoScale->isChecked())
1194  {
1195  h->SetMinimum();
1196  h->SetMaximum();
1197 
1198  if (h->GetMinimum()<hf->GetMinimum())
1199  hf->SetMinimum(h->GetMinimum());
1200  if (h->GetMaximum()>hf->GetMaximum())
1201  hf->SetMaximum(h->GetMaximum());
1202  }
1203 
1204  if (dynamic_cast<TH2*>(h))
1205  {
1206  h->SetMinimum();
1207  h->SetMaximum();
1208  }
1209 
1210  // -----------------------------------------------------------
1211 
1212  const int imin = ceil(hf->GetMinimum());
1213  const int imax = floor(hf->GetMaximum());
1214 
1215  TH1S hd("", "", imax-imin+1, imin-0.5, imax+0.5);
1216  hd.SetDirectory(0);
1217  TH1S h0("", "", imax-imin+1, imin-0.5, imax+0.5);
1218  h0.SetDirectory(0);
1219  TH1S h1("", "", imax-imin+1, imin-0.5, imax+0.5);
1220  h1.SetDirectory(0);
1221  TH1S h2("", "", imax-imin+1, imin-0.5, imax+0.5);
1222  h2.SetDirectory(0);
1223  hd.SetLineColor(h->GetLineColor());
1224  if (d0)
1225  h0.SetLineColor(d0->GetLineColor());
1226  if (d1)
1227  h1.SetLineColor(d1->GetLineColor());
1228  if (d2)
1229  h2.SetLineColor(d2->GetLineColor());
1230 
1231  for (int i=0; i<fEventData->Roi; i++)
1232  {
1233  if (!dynamic_cast<TH2*>(h))
1234  hd.Fill(h->GetBinContent(i+1));
1235  if (d0)
1236  h0.Fill(d0->GetBinContent(i+1));
1237  if (d1)
1238  h1.Fill(d1->GetBinContent(i+1));
1239  if (d2)
1240  h2.Fill(d2->GetBinContent(i+1));
1241  }
1242 
1243  double mm = hd.GetMaximum(hd.GetEntries());
1244  if (h0.GetMaximum(h0.GetEntries())>mm)
1245  mm = h0.GetMaximum();
1246  if (h1.GetMaximum(h1.GetEntries())>mm)
1247  mm = h1.GetMaximum();
1248  if (h2.GetMaximum(h2.GetEntries())>mm)
1249  mm = h2.GetMaximum();
1250 
1251  TIter Next(hf->GetListOfFunctions());
1252  TObject *obj = 0;
1253  while ((obj=Next()))
1254  if (dynamic_cast<TBox*>(obj))
1255  delete hf->GetListOfFunctions()->Remove(obj);
1256 
1257  const double l = h->GetBinLowEdge(h->GetXaxis()->GetLast()+1);
1258  const double m = c->GetX2();
1259 
1260  const double scale = 0.9*(m-l)/mm;
1261 
1262  DrawHorizontal(hf, l, h2, scale);
1263  DrawHorizontal(hf, l, h1, scale);
1264  DrawHorizontal(hf, l, h0, scale);
1265  DrawHorizontal(hf, l, hd, scale);
1266 
1267  // -----------------------------------------------------------
1268 
1269  c->Modified();
1270  c->Update();
1271 #endif
1272  }
1273 
1274  void handleFadRawData(const DimData &d)
1275  {
1276  if (d.size()==0)
1277  return;
1278 
1279  if (fAdcStop->isChecked())
1280  return;
1281 
1282  const EVENT &dat = d.ref<EVENT>();
1283 
1284  if (d.size()<sizeof(EVENT))
1285  {
1286  cerr << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected>=" << sizeof(EVENT) << endl;
1287  return;
1288  }
1289 
1290  if (d.size()!=sizeof(EVENT)+dat.Roi*4*1440+dat.Roi*4*160)
1291  {
1292  cerr << "Size mismatch in " << d.name << ": Found=" << d.size() << " Expected=" << dat.Roi*4*1440+sizeof(EVENT) << " [roi=" << dat.Roi << "]" << endl;
1293  return;
1294  }
1295 
1296  delete [] reinterpret_cast<char*>(fEventData);
1297  fEventData = reinterpret_cast<EVENT*>(new char[d.size()]);
1298  memcpy(fEventData, d.ptr<void>(), d.size());
1299 
1300  DisplayEventData();
1301  }
1302 
1304  {
1305  if (!CheckSize(d, 4*1440*sizeof(float)))
1306  return;
1307 
1308  if (fEventsStop->isChecked())
1309  return;
1310 
1311  const float *ptr = d.ptr<float>();
1312 
1313  valarray<double> arr1(1440);
1314  valarray<double> arr2(1440);
1315  valarray<double> arr3(1440);
1316  valarray<double> arr4(1440);
1317 
1318  for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
1319  {
1320  arr1[it->index] = ptr[0*1440+it->hw()];
1321  arr2[it->index] = ptr[1*1440+it->hw()];
1322  arr3[it->index] = ptr[2*1440+it->hw()];
1323  arr4[it->index] = ptr[3*1440+it->hw()];
1324  }
1325 
1326  fEventCanv1->SetData(arr1);
1327  fEventCanv2->SetData(arr2);
1328  fEventCanv3->SetData(arr3);
1329  fEventCanv4->SetData(arr4);
1330 
1331  fEventCanv1->updateCamera();
1332  fEventCanv2->updateCamera();
1333  fEventCanv3->updateCamera();
1334  fEventCanv4->updateCamera();
1335  }
1336 
1337  vector<float> fDrsCalibration;
1338 
1340  {
1341  const size_t sz = 1024*1440*6+1024*160*2;
1342 
1343  if (d.size()==0)
1344  {
1345  fDrsCalibBaseline->setValue(-1);
1346  fDrsCalibGain->setValue(-1);
1347  fDrsCalibTrgOffset->setValue(-1);
1348  fDrsCalibROI->setValue(-1);
1349 
1350  fDrsCalibBaseline2->setValue(-1);
1351  fDrsCalibGain2->setValue(-1);
1352  fDrsCalibTrgOffset2->setValue(-1);
1353  fDrsCalibROI2->setValue(-1);
1354 
1355  fDrsCalibration.assign(sz, 0);
1356  DisplayEventData();
1357  return;
1358  }
1359 
1360  if (!CheckSize(d, sz*sizeof(float)+4*sizeof(uint32_t)))
1361  // Do WHAT?
1362  return;
1363 
1364  const uint32_t *run = d.ptr<uint32_t>();
1365 
1366  fDrsCalibROI->setValue(run[0]);
1367  fDrsCalibBaseline->setValue(run[1]);
1368  fDrsCalibGain->setValue(run[2]);
1369  fDrsCalibTrgOffset->setValue(run[3]);
1370 
1371  fDrsCalibROI2->setValue(run[0]);
1372  fDrsCalibBaseline2->setValue(run[1]);
1373  fDrsCalibGain2->setValue(run[2]);
1374  fDrsCalibTrgOffset2->setValue(run[3]);
1375 
1376  const float *dat = d.ptr<float>(sizeof(uint32_t)*4);
1377  fDrsCalibration.assign(dat, dat+sz);
1378 
1379  DisplayEventData();
1380  }
1381 
1382 // vector<uint8_t> fFadConnections;
1383 
1385  {
1386  if (!CheckSize(d, 41))
1387  {
1388  fStatusEventBuilderLabel->setText("Offline");
1389  fStatusEventBuilderLabel->setToolTip("FADs or fadctrl seems to be offline.");
1390  fGroupEthernet->setEnabled(false);
1391  fGroupOutput->setEnabled(false);
1392 
1393  SetLedColor(fStatusEventBuilderLed, kLedGray, d.time);
1394  return;
1395  }
1396 
1397  const uint8_t *ptr = d.ptr<uint8_t>();
1398 
1399  for (int i=0; i<40; i++)
1400  {
1401  const uint8_t stat1 = ptr[i]&3;
1402  const uint8_t stat2 = ptr[i]>>3;
1403 
1404  if (stat1==0 && stat2==0)
1405  {
1406  SetLedColor(fFadLED[i], kLedGray, d.time);
1407  continue;
1408  }
1409  if (stat1>=2 && stat2==8)
1410  {
1411  SetLedColor(fFadLED[i], stat1==2?kLedGreen:kLedGreenCheck, d.time);
1412  continue;
1413  }
1414 
1415  if (stat1==1 && stat2==1)
1416  SetLedColor(fFadLED[i], kLedRed, d.time);
1417  else
1418  SetLedColor(fFadLED[i], kLedOrange, d.time);
1419  }
1420 
1421 
1422  const bool runs = ptr[40]!=0;
1423 
1424  fStatusEventBuilderLabel->setText(runs?"Running":"Not running");
1425  fStatusEventBuilderLabel->setToolTip(runs?"Event builder thread running.":"Event builder thread stopped.");
1426 
1427  fGroupEthernet->setEnabled(runs);
1428  fGroupOutput->setEnabled(runs);
1429 
1430  SetLedColor(fStatusEventBuilderLed, runs?kLedGreen:kLedRed, d.time);
1431 
1432 // fFadConnections.assign(ptr, ptr+40);
1433  }
1434 
1435  template<typename T>
1436  void handleFadToolTip(const Time &time, QWidget *w, T *ptr)
1437  {
1438  ostringstream tip;
1439  tip << "<table border='1'><tr><th colspan='11'>" << time.GetAsStr() << " (UTC)</th></tr><tr><th></th>";
1440  for (int b=0; b<10; b++)
1441  tip << "<th>" << b << "</th>";
1442  tip << "</tr>";
1443 
1444  for (int c=0; c<4; c++)
1445  {
1446  tip << "<tr><th>" << c << "</th>";
1447  for (int b=0; b<10; b++)
1448  tip << "<td>" << ptr[c*10+b] << "</td>";
1449  tip << "</tr>";
1450  }
1451  tip << "</table>";
1452 
1453  w->setToolTip(tip.str().c_str());
1454  }
1455 
1456  template<typename T, class S>
1457  void handleFadMinMax(const DimData &d, QPushButton *led, S *wmin, S *wmax=0)
1458  {
1459  if (!CheckSize(d, 42*sizeof(T)))
1460  return;
1461 
1462  const T *ptr = d.ptr<T>();
1463  const T min = ptr[40];
1464  const T max = ptr[41];
1465 
1466  if (max==0 && min>max)
1467  SetLedColor(led, kLedGray, d.time);
1468  else
1469  SetLedColor(led, min==max?kLedGreen: kLedOrange, d.time);
1470 
1471  if (!wmax && max!=min)
1472  wmin->setValue(0);
1473  else
1474  wmin->setValue(min);
1475 
1476  if (wmax)
1477  wmax->setValue(max);
1478 
1479  handleFadToolTip(d.time, led, ptr);
1480  }
1481 
1483  {
1484  handleFadMinMax<float, QDoubleSpinBox>(d, fFadLedFwVersion, fFadFwVersion);
1485  }
1486 
1488  {
1489  handleFadMinMax<uint32_t, QSpinBox>(d, fFadLedRunNumber, fFadRunNumber);
1490  }
1491 
1493  {
1494  handleFadMinMax<uint16_t, QSpinBox>(d, fFadLedPrescaler, fFadPrescaler);
1495  }
1496 
1497  void handleFadDNA(const DimData &d)
1498  {
1499  if (!CheckSize(d, 40*sizeof(uint64_t)))
1500  return;
1501 
1502  const uint64_t *ptr = d.ptr<uint64_t>();
1503 
1504  ostringstream tip;
1505  tip << "<table width='100%'>";
1506  tip << "<tr><th>Crate</th><td></td><th>Board</th><td></td><th>DNA</th></tr>";
1507 
1508  for (int i=0; i<40; i++)
1509  {
1510  tip << dec;
1511  tip << "<tr>";
1512  tip << "<td align='center'>" << i/10 << "</td><td>:</td>";
1513  tip << "<td align='center'>" << i%10 << "</td><td>:</td>";
1514  tip << hex;
1515  tip << "<td>0x" << setfill('0') << setw(16) << ptr[i] << "</td>";
1516  tip << "</tr>";
1517  }
1518  tip << "</table>";
1519 
1520  fFadDNA->setText(tip.str().c_str());
1521  }
1522 
1523  void SetFadLed(QPushButton *led, const DimData &d, uint16_t bitmask, bool invert=false)
1524  {
1525  if (d.size()==0)
1526  {
1527  SetLedColor(led, kLedGray, d.time);
1528  return;
1529  }
1530 
1531  const bool quality = d.ptr<uint16_t>()[0]&bitmask;
1532  const bool value = d.ptr<uint16_t>()[1]&bitmask;
1533  const uint16_t *ptr = d.ptr<uint16_t>()+2;
1534 
1535  SetLedColor(led, quality?kLedOrange:(value^invert?kLedGreen:kLedGreenBar), d.time);
1536 
1537  ostringstream tip;
1538  tip << "<table border='1'><tr><th colspan='11'>" << d.time.GetAsStr() << " (UTC)</th></tr><tr><th></th>";
1539  for (int b=0; b<10; b++)
1540  tip << "<th>" << b << "</th>";
1541  tip << "</tr>";
1542 
1543  /*
1544  tip << "<tr>" << hex;
1545  tip << "<th>" << d.ptr<uint16_t>()[0] << " " << (d.ptr<uint16_t>()[0]&bitmask) << "</th>";
1546  tip << "<th>" << d.ptr<uint16_t>()[1] << " " << (d.ptr<uint16_t>()[1]&bitmask) << "</th>";
1547  tip << "</tr>";
1548  */
1549 
1550  for (int c=0; c<4; c++)
1551  {
1552  tip << "<tr><th>" << dec << c << "</th>" << hex;
1553  for (int b=0; b<10; b++)
1554  {
1555  tip << "<td>"
1556  << (ptr[c*10+b]&bitmask)
1557  << "</td>";
1558  }
1559  tip << "</tr>";
1560  }
1561  tip << "</table>";
1562 
1563  led->setToolTip(tip.str().c_str());
1564  }
1565 
1566  void handleFadStatus(const DimData &d)
1567  {
1568  if (d.size()!=0 && !CheckSize(d, 42*sizeof(uint16_t)))
1569  return;
1570 
1571  SetFadLed(fFadLedDrsEnabled, d, FAD::EventHeader::kDenable);
1572  SetFadLed(fFadLedDrsWrite, d, FAD::EventHeader::kDwrite);
1573  SetFadLed(fFadLedDcmLocked, d, FAD::EventHeader::kDcmLocked);
1574  SetFadLed(fFadLedDcmReady, d, FAD::EventHeader::kDcmReady);
1575  SetFadLed(fFadLedSpiSclk, d, FAD::EventHeader::kSpiSclk);
1576  SetFadLed(fFadLedRefClockTooLow, d, FAD::EventHeader::kRefClkTooLow, true);
1577  SetFadLed(fFadLedBusyOn, d, FAD::EventHeader::kBusyOn);
1578  SetFadLed(fFadLedBusyOff, d, FAD::EventHeader::kBusyOff);
1579  SetFadLed(fFadLedTriggerLine, d, FAD::EventHeader::kTriggerLine);
1580  SetFadLed(fFadLedContTrigger, d, FAD::EventHeader::kContTrigger);
1581  SetFadLed(fFadLedSocket, d, FAD::EventHeader::kSock17);
1582  SetFadLed(fFadLedPllLock, d, 0xf000);
1583  }
1584 
1586  {
1587  if (!CheckSize(d, sizeof(GUI_STAT)))
1588  return;
1589 
1590  const GUI_STAT &stat = d.ref<GUI_STAT>();
1591 
1592  fFadBufferMax->setValue(stat.totMem/1000000); // Memory::allocated
1593  fFadBuffer->setMaximum(stat.maxMem/100); // g_maxMem
1594  fFadBuffer->setValue(stat.usdMem/100); // Memory::inuse
1595 
1596  uint32_t sum = 0;
1597  int cnt = 0;
1598 
1599  for (int i=0; i<40; i++)
1600  {
1601  if (stat.numConn[i]==1)
1602  {
1603  sum += stat.rateBytes[i];
1604  cnt++;
1605  }
1606  }
1607 
1608  fFadEvtConn->setValue(cnt);
1609 
1610  fFadEvtBufNew->setValue(stat.bufNew); // Incomplete in buffer (evtCtrl)
1611  fFadEvtBufEvt->setValue(stat.bufTot); // Complete events in buffer (max_inuse)
1612 
1613  fFadEvtCheck->setValue(stat.bufEvt); // Complete in buffer
1614  fFadEvtWrite->setValue(stat.bufWrite);
1615  fFadEvtProc->setValue(stat.bufProc);
1616 
1617  if (stat.deltaT==0)
1618  return;
1619 
1620  //fFadEthernetRateMin->setValue(min/stat.deltaT);
1621  //fFadEthernetRateMax->setValue(max/stat.deltaT);
1622  fFadEthernetRateTot->setValue(sum/stat.deltaT);
1623  fFadEthernetRateAvg->setValue(cnt==0 ? 0 : sum/cnt/stat.deltaT);
1624 
1625  fFadTransmission->setValue(1000*stat.rateNew/stat.deltaT);
1626  fFadWriteRate->setValue(1000*stat.rateWrite/stat.deltaT);
1627  }
1628 
1629  /*
1630  void handleFadStatistics2(const DimData &d)
1631  {
1632  if (!CheckSize(d, sizeof(EVT_STAT)))
1633  return;
1634 
1635  //const EVT_STAT &stat = d.ref<EVT_STAT>();
1636  }*/
1637 
1639  {
1640  if (!CheckSize(d, sizeof(uint16_t)))
1641  return;
1642 
1643  const uint16_t &fmt = d.get<uint16_t>();
1644 
1645  SetLedColor(fFadLedFileFormatNone, fmt==FAD::kNone ?kLedGreen:kLedGray, d.time);
1646  SetLedColor(fFadLedFileFormatDebug, fmt==FAD::kDebug?kLedGreen:kLedGray, d.time);
1647  SetLedColor(fFadLedFileFormatRaw, fmt==FAD::kRaw ?kLedGreen:kLedGray, d.time);
1648  SetLedColor(fFadLedFileFormatFits, fmt==FAD::kFits ?kLedGreen:kLedGray, d.time);
1649  SetLedColor(fFadLedFileFormatZFits, fmt==FAD::kZFits?kLedGreen:kLedGray, d.time);
1650  SetLedColor(fFadLedFileFormatCalib, fmt==FAD::kCalib?kLedGreen:kLedGray, d.time);
1651  }
1652 
1653  // ===================== FTM ============================================
1654 
1656 
1658  {
1659 #ifdef HAVE_ROOT
1660  TCanvas *c = fFtmRateCanv->GetCanvas();
1661 
1662  TH1 *h = (TH1*)c->FindObject("TimeFrame");
1663 
1664  if (sdata.fTimeStamp<=fTriggerRates.fTimeStamp)
1665  {
1666  fGraphFtmRate.Set(0);
1667 
1668  const double tm = Time().RootTime();
1669 
1670  h->SetBins(1, tm, tm+60);
1671  h->GetXaxis()->SetTimeFormat("%M'%S\"%F1995-01-01 00:00:00 GMT");
1672  h->GetXaxis()->SetTitle("Time");
1673 
1674  c->Modified();
1675  c->Update();
1676  return;
1677  }
1678 
1679  const double t1 = h->GetXaxis()->GetXmax();
1680  const double t0 = h->GetXaxis()->GetXmin();
1681 
1682  const double now = t0+sdata.fTimeStamp/1000000.;
1683 
1684  h->SetBins(h->GetNbinsX()+1, t0, now+1);
1685  fGraphFtmRate.SetPoint(fGraphFtmRate.GetN(), now, sdata.fTriggerRate);
1686 
1687  if (t1-t0>300)
1688  {
1689  h->GetXaxis()->SetTimeFormat("%Hh%M'%F1995-01-01 00:00:00 GMT");
1690  h->GetXaxis()->SetTitle("Time");
1691  }
1692 
1693  h->SetMinimum(0);
1694 
1695  c->Modified();
1696  c->Update();
1697 #endif
1698  }
1699 
1701  {
1702  if (fThresholdIdx->value()>=0)
1703  {
1704  const int isw = fThresholdIdx->value();
1705  const int ihw = fPatchMapHW[isw];
1706  fPatchRate->setValue(sdata.fPatchRate[ihw]);
1707  fBoardRate->setValue(sdata.fBoardRate[ihw/4]);
1708  }
1709 
1710  const bool b = fBoardRatesEnabled->isChecked();
1711 
1712  valarray<double> dat(0., 1440);
1713 
1714  // fPatch converts from software id to software patch id
1715  for (int i=0; i<1440; i++)
1716  {
1717  const int ihw = fPixelMap.index(i).hw()/9;
1718  dat[i] = b ? sdata.fBoardRate[ihw/4] : sdata.fPatchRate[ihw];
1719  }
1720 
1721  fRatesCanv->SetData(dat);
1722  fRatesCanv->updateCamera();
1723  }
1724 
1725  int64_t fTimeStamp0;
1726 
1728  {
1729  UpdateRatesCam(fTriggerRates);
1730  }
1731 
1733  {
1734 #ifdef HAVE_ROOT
1735  if (fTimeStamp0<0)
1736  {
1737  fTimeStamp0 = sdata.fTimeStamp;
1738  return;
1739  }
1740 
1741  TCanvas *c = fFtmRateCanv->GetCanvas();
1742 
1743  TH1 *h = (TH1*)c->FindObject("TimeFrame");
1744 
1745  const double tdiff = sdata.fTimeStamp-fTimeStamp0;
1746  fTimeStamp0 = sdata.fTimeStamp;
1747 
1748  if (tdiff<0)
1749  {
1750  for (int i=0; i<160; i++)
1751  fGraphPatchRate[i].Set(0);
1752  for (int i=0; i<40; i++)
1753  fGraphBoardRate[i].Set(0);
1754 
1755  return;
1756  }
1757 
1758  //const double t1 = h->GetXaxis()->GetXmax();
1759  const double t0 = h->GetXaxis()->GetXmin();
1760 
1761  for (int i=0; i<160; i++)
1762  if (fFtuStatus[i/4]>0)
1763  fGraphPatchRate[i].SetPoint(fGraphPatchRate[i].GetN(),
1764  t0+sdata.fTimeStamp/1000000., sdata.fPatchRate[i]);
1765  for (int i=0; i<40; i++)
1766  if (fFtuStatus[i]>0)
1767  fGraphBoardRate[i].SetPoint(fGraphBoardRate[i].GetN(),
1768  t0+sdata.fTimeStamp/1000000., sdata.fBoardRate[i]);
1769 
1770  c->Modified();
1771  c->Update();
1772 #endif
1773  }
1774 
1776  {
1777  if (!CheckSize(d, sizeof(FTM::DimTriggerRates)))
1778  return;
1779 
1780  const FTM::DimTriggerRates &sdata = d.ref<FTM::DimTriggerRates>();
1781 
1782  fFtmTime->setText(QString::number(sdata.fTimeStamp/1000000., 'f', 6)+ " s");
1783  fTriggerCounter->setText(QString::number(sdata.fTriggerCounter));
1784 
1785  if (sdata.fTimeStamp>0)
1786  fTriggerCounterRate->setValue(1000000.*sdata.fTriggerCounter/sdata.fTimeStamp);
1787  else
1788  fTriggerCounterRate->setValue(0);
1789 
1790  // ----------------------------------------------
1791 
1792  fOnTime->setText(QString::number(sdata.fOnTimeCounter/1000000., 'f', 6)+" s");
1793 
1794  if (sdata.fTimeStamp>0)
1795  fOnTimeRel->setValue(100.*sdata.fOnTimeCounter/sdata.fTimeStamp);
1796  else
1797  fOnTimeRel->setValue(0);
1798 
1799  // ----------------------------------------------
1800 
1801  UpdateTriggerRate(sdata);
1802  UpdateRatesGraphs(sdata);
1803  UpdateRatesCam(sdata);
1804 
1805  fTriggerRates = sdata;
1806  }
1807 
1808  void handleFtmCounter(const DimData &d)
1809  {
1810  if (!CheckSize(d, sizeof(uint32_t)*6))
1811  return;
1812 
1813  const uint32_t *sdata = d.ptr<uint32_t>();
1814 
1815  fFtmCounterH->setValue(sdata[0]);
1816  fFtmCounterS->setValue(sdata[1]);
1817  fFtmCounterD->setValue(sdata[2]);
1818  fFtmCounterF->setValue(sdata[3]);
1819  fFtmCounterE->setValue(sdata[4]);
1820  fFtmCounterR->setValue(sdata[5]);
1821  }
1822 
1824  {
1825  if (!CheckSize(d, sizeof(FTM::DimDynamicData)))
1826  return;
1827 
1828  const FTM::DimDynamicData &sdata = d.ref<FTM::DimDynamicData>();
1829 
1830  fFtmTemp0->setValue(sdata.fTempSensor[0]*0.1);
1831  fFtmTemp1->setValue(sdata.fTempSensor[1]*0.1);
1832  fFtmTemp2->setValue(sdata.fTempSensor[2]*0.1);
1833  fFtmTemp3->setValue(sdata.fTempSensor[3]*0.1);
1834 
1835  SetLedColor(fClockCondLed, sdata.fState&FTM::kFtmLocked ? kLedGreen : kLedRed, d.time);
1836  }
1837 
1839  {
1840 #ifdef HAVE_ROOT
1841  TCanvas *c = fFtmRateCanv->GetCanvas();
1842 
1843  TList * l = c->GetListOfPrimitives();
1844 
1845 
1846  while (c->FindObject("PatchRate"))
1847  l->Remove(c->FindObject("PatchRate"));
1848 
1849  while (c->FindObject("BoardRate"))
1850  l->Remove(c->FindObject("BoardRate"));
1851 
1852  if (fRatePatch1->value()>=0)
1853  {
1854  fGraphPatchRate[fRatePatch1->value()].SetLineColor(kRed);
1855  fGraphPatchRate[fRatePatch1->value()].SetMarkerColor(kRed);
1856  l->Add(&fGraphPatchRate[fRatePatch1->value()], "PL");
1857  }
1858  if (fRatePatch2->value()>=0)
1859  {
1860  fGraphPatchRate[fRatePatch2->value()].SetLineColor(kGreen);
1861  fGraphPatchRate[fRatePatch2->value()].SetMarkerColor(kGreen);
1862  l->Add(&fGraphPatchRate[fRatePatch2->value()], "PL");
1863  }
1864  if (fRateBoard1->value()>=0)
1865  {
1866  fGraphBoardRate[fRateBoard1->value()].SetLineColor(kMagenta);
1867  fGraphBoardRate[fRateBoard1->value()].SetMarkerColor(kMagenta);
1868  l->Add(&fGraphBoardRate[fRateBoard1->value()], "PL");
1869  }
1870  if (fRateBoard2->value()>=0)
1871  {
1872  fGraphBoardRate[fRateBoard2->value()].SetLineColor(kCyan);
1873  fGraphBoardRate[fRateBoard2->value()].SetMarkerColor(kCyan);
1874  l->Add(&fGraphBoardRate[fRateBoard2->value()], "PL");
1875  }
1876 
1877  c->Modified();
1878  c->Update();
1879 #endif
1880  }
1881 
1883 
1884  void SetFtuLed(int idx, int counter, const Time &t)
1885  {
1886  if (counter==0 || counter>3)
1887  counter = 3;
1888 
1889  if (counter<0)
1890  counter = 0;
1891 
1892  const LedColor_t col[4] = { kLedGray, kLedGreen, kLedOrange, kLedRed };
1893 
1894  SetLedColor(fFtuLED[idx], col[counter], t);
1895 
1896  fFtuStatus[idx] = counter;
1897  }
1898 
1899  void SetFtuStatusLed(const Time &t)
1900  {
1901  const int max = fFtuStatus.max();
1902 
1903  switch (max)
1904  {
1905  case 0:
1906  SetLedColor(fStatusFTULed, kLedGray, t);
1907  fStatusFTULabel->setText("All disabled");
1908  fStatusFTULabel->setToolTip("All FTUs are disabled");
1909  break;
1910 
1911  case 1:
1912  SetLedColor(fStatusFTULed, kLedGreen, t);
1913  fStatusFTULabel->setToolTip("Communication with FTU is smooth.");
1914  fStatusFTULabel->setText("ok");
1915  break;
1916 
1917  case 2:
1918  SetLedColor(fStatusFTULed, kLedOrange, t);
1919  fStatusFTULabel->setText("Warning");
1920  fStatusFTULabel->setToolTip("At least one FTU didn't answer immediately");
1921  break;
1922 
1923  case 3:
1924  SetLedColor(fStatusFTULed, kLedRed, t);
1925  fStatusFTULabel->setToolTip("At least one FTU didn't answer!");
1926  fStatusFTULabel->setText("ERROR");
1927  break;
1928  }
1929 
1930  const int cnt = count(&fFtuStatus[0], &fFtuStatus[40], 0);
1931  fFtuAllOn->setEnabled(cnt!=0);
1932  fFtuAllOff->setEnabled(cnt!=40);
1933  }
1934 
1936  {
1937  if (!CheckSize(d, sizeof(FTM::DimStaticData)))
1938  return;
1939 
1940  const FTM::DimStaticData &sdata = d.ref<FTM::DimStaticData>();
1941 
1942  fTriggerInterval->setValue(sdata.fTriggerInterval);
1943  fPhysicsCoincidence->setValue(sdata.fMultiplicityPhysics);
1944  fCalibCoincidence->setValue(sdata.fMultiplicityCalib);
1945  fPhysicsWindow->setValue(sdata.fWindowPhysics);
1946  fCalibWindow->setValue(sdata.fWindowCalib);
1947 
1948  fTriggerDelay->setValue(sdata.fDelayTrigger);
1949  fTimeMarkerDelay->setValue(sdata.fDelayTimeMarker);
1950  fDeadTime->setValue(sdata.fDeadTime);
1951 
1952  fClockCondR0->setValue(sdata.fClockConditioner[0]);
1953  fClockCondR1->setValue(sdata.fClockConditioner[1]);
1954  fClockCondR8->setValue(sdata.fClockConditioner[2]);
1955  fClockCondR9->setValue(sdata.fClockConditioner[3]);
1956  fClockCondR11->setValue(sdata.fClockConditioner[4]);
1957  fClockCondR13->setValue(sdata.fClockConditioner[5]);
1958  fClockCondR14->setValue(sdata.fClockConditioner[6]);
1959  fClockCondR15->setValue(sdata.fClockConditioner[7]);
1960 
1961  const uint32_t R0 = sdata.fClockConditioner[0];
1962  const uint32_t R14 = sdata.fClockConditioner[6];
1963  const uint32_t R15 = sdata.fClockConditioner[7];
1964 
1965  const uint32_t Ndiv = (R15&0x1ffff00)<<2;
1966  const uint32_t Rdiv = (R14&0x007ff00)>>8;
1967  const uint32_t Cdiv = (R0 &0x000ff00)>>8;
1968 
1969  double freq = 40.*Ndiv/(Rdiv*Cdiv);
1970 
1971  fClockCondFreqRes->setValue(freq);
1972 
1973  //fClockCondFreq->setEditText("");
1974  fClockCondFreq->setCurrentIndex(0);
1975 
1976  fTriggerSeqPed->setValue(sdata.fTriggerSeqPed);
1977  fTriggerSeqLPint->setValue(sdata.fTriggerSeqLPint);
1978  fTriggerSeqLPext->setValue(sdata.fTriggerSeqLPext);
1979 
1980  fLpIntIntensity->setValue(sdata.fIntensityLPint);
1981  fLpExtIntensity->setValue(sdata.fIntensityLPext);
1982 
1983  fLpIntGroup1->setChecked(sdata.HasLPintG1());
1984  fLpIntGroup2->setChecked(sdata.HasLPintG2());
1985  fLpExtGroup1->setChecked(sdata.HasLPextG1());
1986  fLpExtGroup2->setChecked(sdata.HasLPextG2());
1987 
1988  fEnableTrigger->setChecked(sdata.HasTrigger());
1989  fEnableVeto->setChecked(sdata.HasVeto());
1990  fEnableExt1->setChecked(sdata.HasExt1());
1991  fEnableExt2->setChecked(sdata.HasExt2());
1992  fEnableClockCond->setChecked(sdata.HasClockConditioner());
1993 
1994  uint16_t multiplicity = sdata.fMultiplicity[0];
1995 
1996  for (int i=0; i<40; i++)
1997  {
1998  if (!sdata.IsActive(i))
1999  SetFtuLed(i, -1, d.time);
2000  else
2001  {
2002  if (fFtuStatus[i]==0)
2003  SetFtuLed(i, 1, d.time);
2004  }
2005  fFtuLED[i]->setChecked(false);
2006 
2007  if (sdata.fMultiplicity[i]!=multiplicity)
2008  multiplicity = -1;
2009 
2010  }
2011  SetFtuStatusLed(d.time);
2012 
2013  fNoutof4Val->setValue(multiplicity);
2014 
2015  for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
2016  fRatesCanv->SetEnable(it->index, sdata.IsEnabled(it->hw()));
2017 
2018  const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
2019  fPixelEnable->setChecked(sdata.IsEnabled(entry.hw()));
2020 
2021  if (fThresholdIdx->value()>=0)
2022  {
2023  const int isw = fThresholdIdx->value();
2024  const int ihw = fPatchMapHW[isw];
2025  fThresholdVal->setValue(sdata.fThreshold[ihw]);
2026  }
2027 
2028  fPrescalingVal->setValue(sdata.fPrescaling[0]);
2029 
2030  fFtmStaticData = sdata;
2031  }
2032 
2034  {
2035  if (!CheckSize(d, sizeof(FTM::DimPassport)))
2036  return;
2037 
2038  const FTM::DimPassport &sdata = d.ref<FTM::DimPassport>();
2039 
2040  stringstream str1, str2;
2041  str1 << hex << "0x" << setfill('0') << setw(16) << sdata.fBoardId;
2042  str2 << sdata.fFirmwareId;
2043 
2044  fFtmBoardId->setText(str1.str().c_str());
2045  fFtmFirmwareId->setText(str2.str().c_str());
2046  }
2047 
2048  void handleFtmFtuList(const DimData &d)
2049  {
2050  if (!CheckSize(d, sizeof(FTM::DimFtuList)))
2051  return;
2052 
2053  fFtuPing->setChecked(false);
2054 
2055  const FTM::DimFtuList &sdata = d.ref<FTM::DimFtuList>();
2056 
2057  stringstream str;
2058  str << "<table width='100%'>" << setfill('0');
2059  str << "<tr><th>Num</th><th></th><th>Addr</th><th></th><th>DNA</th></tr>";
2060  for (int i=0; i<40; i++)
2061  {
2062  str << "<tr>";
2063  str << "<td align='center'>" << dec << i << hex << "</td>";
2064  str << "<td align='center'>:</td>";
2065  str << "<td align='center'>0x" << setw(2) << (int)sdata.fAddr[i] << "</td>";
2066  str << "<td align='center'>:</td>";
2067  str << "<td align='center'>0x" << setw(16) << sdata.fDNA[i] << "</td>";
2068  str << "</tr>";
2069  }
2070  str << "</table>";
2071 
2072  fFtuDNA->setText(str.str().c_str());
2073 
2074  fFtuAnswersTotal->setValue(sdata.fNumBoards);
2075  fFtuAnswersCrate0->setValue(sdata.fNumBoardsCrate[0]);
2076  fFtuAnswersCrate1->setValue(sdata.fNumBoardsCrate[1]);
2077  fFtuAnswersCrate2->setValue(sdata.fNumBoardsCrate[2]);
2078  fFtuAnswersCrate3->setValue(sdata.fNumBoardsCrate[3]);
2079 
2080  for (int i=0; i<40; i++)
2081  SetFtuLed(i, sdata.IsActive(i) ? sdata.fPing[i] : -1, d.time);
2082 
2083  SetFtuStatusLed(d.time);
2084  }
2085 
2086  void handleFtmError(const DimData &d)
2087  {
2088  if (!CheckSize(d, sizeof(FTM::DimError)))
2089  return;
2090 
2091  const FTM::DimError &sdata = d.ref<FTM::DimError>();
2092 
2093  SetFtuLed(sdata.fError.fDestAddress, sdata.fError.fNumCalls, d.time);
2094  SetFtuStatusLed(d.time);
2095 
2096  // FIXME: Write to special window!
2097  //Out() << "Error:" << endl;
2098  //Out() << sdata.fError << endl;
2099  }
2100 
2101  // ========================== FSC =======================================
2102 
2103  void SetFscValue(QDoubleSpinBox *box, const DimData &d, int idx, bool enable)
2104  {
2105  //box->setEnabled(enable);
2106  if (!enable)
2107  {
2108  box->setToolTip(d.time.GetAsStr().c_str());
2109  return;
2110  }
2111 
2112  ostringstream str;
2113  str << d.time << " -- " << d.get<float>() << "s";
2114 
2115  box->setToolTip(str.str().c_str());
2116  box->setValue(d.get<float>(idx*4+4));
2117  }
2118 
2119 
2120  void handleFscTemp(const DimData &d)
2121  {
2122  const bool enable = d.size()>0 && CheckSize(d, 60*sizeof(float));
2123  if (!enable)
2124  return;
2125 
2126  QDoubleSpinBox *boxes[] = {
2127  fTempCam00, fTempCam01,
2128  fTempCam10, fTempCam11, fTempCam12, fTempCam13, fTempCam14,
2129  fTempCam20, fTempCam21, fTempCam22, fTempCam23, fTempCam24, fTempCam25,
2130  fTempCam30, fTempCam31, fTempCam32, fTempCam33, fTempCam34,
2131  fTempCam40, fTempCam41, fTempCam42, fTempCam43, fTempCam44, fTempCam45,
2132  fTempCam50, fTempCam51, fTempCam52, fTempCam53, fTempCam54,
2133  fTempCam60, fTempCam61,
2134  // 0:b/f 1:b/f 2:b/f 3:b/f
2135  fTempCrate0back, fTempCrate0front,
2136  fTempCrate1back, fTempCrate1front,
2137  fTempCrate2back, fTempCrate2front,
2138  fTempCrate3back, fTempCrate3front,
2139  // 0:b/f 1:b/f 2:b/f 3:b/f
2140  fTempPS0back, fTempPS0front,
2141  fTempPS1back, fTempPS1front,
2142  fTempPS2back, fTempPS2front,
2143  fTempPS3back, fTempPS3front,
2144  // AUX PS: FTM t/b; FSC t/b
2145  fTempAuxFTMtop, fTempAuxFTMbottom,
2146  fTempAuxFSCtop, fTempAuxFSCbottom,
2147  // Backpanel: FTM t/b; FSC t/b
2148  fTempBackpanelFTMtop, fTempBackpanelFTMbottom,
2149  fTempBackpanelFSCtop, fTempBackpanelFSCbottom,
2150  // top front/back; bottom front/back
2151  fTempSwitchboxTopFront, fTempSwitchboxTopBack,
2152  fTempSwitchboxBottomFront, fTempSwitchboxBottomBack,
2153  };
2154 
2155  for (int i=0; i<59; i++)
2156  SetFscValue(boxes[i], d, i, enable);
2157 
2158  if (!enable)
2159  return;
2160 
2161  const float *ptr = d.ptr<float>();
2162 
2163  double avg = 0;
2164  int num = 0;
2165  for (int i=1; i<32; i++)
2166  if (ptr[i]!=0)
2167  {
2168  avg += ptr[i];
2169  num ++;
2170  }
2171 
2172  fTempCamAvg->setValue(num?avg/num:0);
2173  }
2174 
2175  void handleFscVolt(const DimData &d)
2176  {
2177  const bool enable = d.size()>0 && CheckSize(d, 31*sizeof(float));
2178  if (!enable)
2179  return;
2180 
2181  QDoubleSpinBox *boxes[] = {
2182  fVoltFad00, fVoltFad10, fVoltFad20, fVoltFad30,
2183  fVoltFad01, fVoltFad11, fVoltFad21, fVoltFad31,
2184  fVoltFad02, fVoltFad12, fVoltFad22, fVoltFad32,
2185  fVoltFPA00, fVoltFPA10, fVoltFPA20, fVoltFPA30,
2186  fVoltFPA01, fVoltFPA11, fVoltFPA21, fVoltFPA31,
2187  fVoltFPA02, fVoltFPA12, fVoltFPA22, fVoltFPA32,
2188  fVoltETH0, fVoltETH1,
2189  fVoltFTM0, fVoltFTM1,
2190  fVoltFFC, fVoltFLP,
2191  };
2192 
2193  for (int i=0; i<30; i++)
2194  SetFscValue(boxes[i], d, i, enable);
2195  }
2196 
2197  void handleFscCurrent(const DimData &d)
2198  {
2199  const bool enable = d.size()>0 && CheckSize(d, 31*sizeof(float));
2200  if (!enable)
2201  return;
2202 
2203  QDoubleSpinBox *boxes[] = {
2204  fAmpFad00, fAmpFad10, fAmpFad20, fAmpFad30,
2205  fAmpFad01, fAmpFad11, fAmpFad21, fAmpFad31,
2206  fAmpFad02, fAmpFad12, fAmpFad22, fAmpFad32,
2207  fAmpFPA00, fAmpFPA10, fAmpFPA20, fAmpFPA30,
2208  fAmpFPA01, fAmpFPA11, fAmpFPA21, fAmpFPA31,
2209  fAmpFPA02, fAmpFPA12, fAmpFPA22, fAmpFPA32,
2210  fAmpETH0, fAmpETH1,
2211  fAmpFTM0, fAmpFTM1,
2212  fAmpFFC, fAmpFLP,
2213  };
2214 
2215  for (int i=0; i<30; i++)
2216  SetFscValue(boxes[i], d, i, enable);
2217  }
2218 
2220  {
2221  const bool enable = d.size()>0 && CheckSize(d, 5*sizeof(float));
2222 
2223  SetFscValue(fHumidity1, d, 0, enable);
2224  SetFscValue(fHumidity2, d, 1, enable);
2225  SetFscValue(fHumidity3, d, 2, enable);
2226  SetFscValue(fHumidity4, d, 3, enable);
2227  }
2228 
2229  // ========================== Feedback ==================================
2230 
2231 #ifdef HAVE_ROOT
2232  TGraphErrors fGraphFeedbackDev;
2233  TGraphErrors fGraphFeedbackCmd;
2234 
2235  void UpdateFeedback(TQtWidget &rwidget, const Time &time, TGraphErrors &graph, double avg, double rms)
2236  {
2237  TCanvas *c = rwidget.GetCanvas();
2238 
2239  TH1 *h = (TH1*)c->FindObject("TimeFrame");
2240 
2241  while (graph.GetN()>500)
2242  graph.RemovePoint(0);
2243 
2244  const double now = time.RootTime();
2245 
2246  while (graph.GetN()>0 && now-graph.GetX()[0]>3600)
2247  graph.RemovePoint(0);
2248 
2249  const int n = graph.GetN();
2250 
2251  const double xmin = n>0 ? graph.GetX()[0] : now;
2252 
2253  h->SetBins(n+1, xmin-1, now+1);
2254  graph.SetPoint(n, now, avg);
2255  graph.SetPointError(n, 0, rms);
2256 
2257  h->GetXaxis()->SetTimeFormat(now-xmin>300 ? "%Hh%M'%F1995-01-01 00:00:00 GMT" : "%M'%S\"%F1995-01-01 00:00:00 GMT");
2258 
2259  c->Modified();
2260  c->Update();
2261  }
2262 #endif
2263 
2264  vector <float> fVecFeedbackCurrents;
2265 
2267  {
2268  if (!CheckSize(d, (416+1+1+1+1+1+416+1+1)*sizeof(float)+sizeof(uint32_t)))
2269  return;
2270 
2271  const float *ptr = d.ptr<float>();
2272  const float *Uov = ptr+416+6;
2273 
2274  fVecFeedbackCurrents.assign(ptr, ptr+416);
2275 
2276  valarray<double> datc(0., 1440);
2277  valarray<double> datu(0., 1440);
2278 
2279  // fPatch converts from software id to software patch id
2280  for (int i=0; i<1440; i++)
2281  {
2282  const PixelMapEntry &entry = fPixelMap.index(i);
2283 
2284  datc[i] = fVecFeedbackCurrents[entry.hv()];
2285  datu[i] = Uov[entry.hv()];
2286 
2287  if (fVecBiasCurrent.size()>0)
2288  {
2289  fBiasCamA->SetEnable(i, uint16_t(fVecBiasCurrent[entry.hv()])!=0x8000);
2290  fBiasCamA->highlightPixel(i, fVecBiasCurrent[entry.hv()]<0);
2291  }
2292  }
2293 
2294  fBiasCamA->SetData(datc);
2295  fBiasCamA->updateCamera();
2296 
2297  UpdateBiasValues();
2298 
2299  // --------------------------------------------------------
2300 
2301  double avg = 0;
2302  double rms = 0;
2303 
2304  for (int i=0; i<320; i++)
2305  {
2306  avg += Uov[i];
2307  rms += Uov[i]*Uov[i];
2308  }
2309 
2310  avg /= 320;
2311  rms /= 320;
2312  rms = sqrt(rms-avg*avg);
2313 
2314 
2315  fFeedbackDevCam->SetData(datu);
2316  //fFeedbackCmdCam->SetData(cmd);
2317 
2318  fFeedbackDevCam->updateCamera();
2319  //fFeedbackCmdCam->updateCamera();
2320 
2321 #ifdef HAVE_ROOT
2322  UpdateFeedback(*fFeedbackDev, d.time, fGraphFeedbackDev, avg, rms);
2323  //UpdateFeedback(*fFeedbackCmd, d.time, fGraphFeedbackCmd, avgcmd, rmscmd);
2324 #endif
2325  }
2326 
2327  // ======================= Rate Scan ====================================
2328 
2329  TGraph fGraphRateScan[201];
2330 
2331  void UpdateRateScan(uint32_t th, const float *rates)
2332  {
2333 #ifdef HAVE_ROOT
2334  TCanvas *c = fRateScanCanv->GetCanvas();
2335 
2336  TH1 *h = (TH1*)c->FindObject("Frame");
2337 
2338  if (fGraphRateScan[0].GetN()==0 || th<fGraphRateScan[0].GetX()[fGraphRateScan[0].GetN()-1])
2339  {
2340  h->SetBins(1, th<10 ? 0 : th-10, th+10);
2341  h->SetMinimum(1);
2342  h->SetMaximum(rates[0]*2);
2343 
2344  for (int i=0; i<201; i++)
2345  {
2346  fGraphRateScan[i].Set(0);
2347  fGraphRateScan[i].SetPoint(fGraphRateScan[i].GetN(), th, rates[i]);
2348  }
2349 
2350  c->SetGrid();
2351  c->SetLogy();
2352 
2353  c->Modified();
2354  c->Update();
2355  return;
2356  }
2357 
2358  const double dac = h->GetXaxis()->GetXmin();
2359  h->SetBins(h->GetNbinsX()+1, dac, th+10);
2360 
2361  for (int i=0; i<201; i++)
2362  fGraphRateScan[i].SetPoint(fGraphRateScan[i].GetN(), th, rates[i]);
2363 
2364  c->Modified();
2365  c->Update();
2366 #endif
2367  }
2368 
2370  {
2371 #ifdef HAVE_ROOT
2372  TCanvas *c = fRateScanCanv->GetCanvas();
2373 
2374  TList *l = c->GetListOfPrimitives();
2375 
2376  while (c->FindObject("PatchRate"))
2377  l->Remove(c->FindObject("PatchRate"));
2378 
2379  while (c->FindObject("BoardRate"))
2380  l->Remove(c->FindObject("BoardRate"));
2381 
2382  if (fRateScanPatch1->value()>=0)
2383  {
2384  fGraphRateScan[fRateScanPatch1->value()+41].SetLineColor(kRed);
2385  fGraphRateScan[fRateScanPatch1->value()+41].SetMarkerColor(kRed);
2386  l->Add(&fGraphRateScan[fRateScanPatch1->value()+41], "PL");
2387  }
2388  if (fRateScanPatch2->value()>=0)
2389  {
2390  fGraphRateScan[fRateScanPatch2->value()+41].SetLineColor(kGreen);
2391  fGraphRateScan[fRateScanPatch2->value()+41].SetMarkerColor(kGreen);
2392  l->Add(&fGraphRateScan[fRateScanPatch2->value()+41], "PL");
2393  }
2394  if (fRateScanBoard1->value()>=0)
2395  {
2396  fGraphRateScan[fRateScanBoard1->value()+1].SetLineColor(kMagenta);
2397  fGraphRateScan[fRateScanBoard1->value()+1].SetMarkerColor(kMagenta);
2398  l->Add(&fGraphRateScan[fRateScanBoard1->value()+1], "PL");
2399  }
2400  if (fRateScanBoard2->value()>=0)
2401  {
2402  fGraphRateScan[fRateScanBoard2->value()+1].SetLineColor(kCyan);
2403  fGraphRateScan[fRateScanBoard2->value()+1].SetMarkerColor(kCyan);
2404  l->Add(&fGraphRateScan[fRateScanBoard2->value()+1], "PL");
2405  }
2406 
2407  c->Modified();
2408  c->Update();
2409 #endif
2410  }
2411 
2412  void handleRateScan(const DimData &d)
2413  {
2414  if (!CheckSize(d, 206*sizeof(float)))
2415  return;
2416 
2417  UpdateRateScan(d.get<uint32_t>(8), d.ptr<float>(20));
2418  }
2419 
2420  // ===================== MAGIC Weather ==================================
2421 
2423  {
2424  if (!CheckSize(d, 7*sizeof(float)+sizeof(uint16_t)))
2425  return;
2426 
2427  const float *ptr = d.ptr<float>(2);
2428 
2429  fMagicTemp->setValue(ptr[0]);
2430  fMagicDew->setValue(ptr[1]);
2431  fMagicHum->setValue(ptr[2]);
2432  fMagicPressure->setValue(ptr[3]);
2433  fMagicWind->setValue(ptr[4]);
2434  fMagicGusts->setValue(ptr[5]);
2435 
2436  static const char *dir[] =
2437  {
2438  "N", "NNE", "NE", "ENE",
2439  "E", "ESE", "SE", "SSE",
2440  "S", "SSW", "SW", "WSW",
2441  "W", "WNW", "NW", "NNW"
2442  };
2443 
2444  const uint16_t i = uint16_t(floor(fmod(ptr[6]+11.25, 360)/22.5));
2445  fMagicWindDir->setText(dir[i%16]);
2446  }
2447 
2448  // ========================== FSC =======================================
2449 
2450  vector<float> fVecBiasVolt;
2451  vector<int16_t> fVecBiasDac;
2452  vector<int16_t> fVecBiasCurrent;
2453 
2454  void handleBiasVolt(const DimData &d)
2455  {
2456  if (!CheckSize(d, 416*sizeof(float)))
2457  return;
2458 
2459  const float *ptr = d.ptr<float>();
2460  fVecBiasVolt.assign(ptr, ptr+416);
2461 
2462  on_fBiasDispRefVolt_stateChanged();
2463  }
2464 
2465  void handleBiasDac(const DimData &d)
2466  {
2467  if (!CheckSize(d, 2*416*sizeof(int16_t)))
2468  return;
2469 
2470  const int16_t *ptr = d.ptr<int16_t>();
2471  fVecBiasDac.assign(ptr, ptr+2*416);
2472 
2473  on_fBiasDispRefVolt_stateChanged();
2474  UpdateBiasValues();
2475  }
2476 
2478 
2480  {
2481  if (!CheckSize(d, 416*sizeof(int16_t)))
2482  return;
2483 
2484  const int16_t *ptr = d.ptr<int16_t>();
2485 
2486  fVecBiasCurrent.assign(ptr, ptr+416);
2487 
2488  valarray<double> dat(0., 1440);
2489 
2490  // fPatch converts from software id to software patch id
2491  for (int i=0; i<1440; i++)
2492  {
2493  const PixelMapEntry &entry = fPixelMap.index(i);
2494 
2495  dat[i] = abs(ptr[entry.hv()]) * 5000./4096;
2496 
2497  fBiasCamA->SetEnable(i, uint16_t(ptr[entry.hv()])!=0x8000);
2498  fBiasCamA->highlightPixel(i, ptr[entry.hv()]<0);
2499  }
2500 
2501  if (fStateFeedback<Feedback::State::kCalibrated)
2502  fBiasCamA->SetData(dat);
2503 
2504  fBiasCamA->updateCamera();
2505 
2506  UpdateBiasValues();
2507  }
2508 
2509  // ====================== MessageImp ====================================
2510 
2512 
2513  void handleStateChanged(const Time &time, const string &server,
2514  const State &s)
2515  {
2516  // FIXME: Prefix tooltip with time
2517  if (server=="MCP")
2518  {
2519  // FIXME: Enable FTU page!!!
2520  fStatusMCPLabel->setText(s.name.c_str());
2521  fStatusMCPLabel->setToolTip(s.comment.c_str());
2522 
2523  if (s.index<MCP::State::kDisconnected) // No Dim connection
2524  SetLedColor(fStatusMCPLed, kLedGray, time);
2525  if (s.index==MCP::State::kDisconnected) // Disconnected
2526  SetLedColor(fStatusMCPLed, kLedRed, time);
2527  if (s.index==MCP::State::kConnecting) // Connecting
2528  SetLedColor(fStatusMCPLed, kLedOrange, time);
2529  if (s.index==MCP::State::kConnected) // Connected
2530  SetLedColor(fStatusMCPLed, kLedYellow, time);
2531  if (s.index==MCP::State::kIdle || s.index>=MCP::State::kConfigured) // Idle, TriggerOn, TakingData
2532  SetLedColor(fStatusMCPLed, kLedGreen, time);
2533 
2535  SetLedColor(fStatusMCPLed, kLedGreenBar, time);
2536 
2537  fMcpStartRun->setEnabled(s.index>=MCP::State::kIdle);
2538  fMcpStopRun->setEnabled(s.index>=MCP::State::kIdle);
2539  fMcpReset->setEnabled(s.index>=MCP::State::kIdle && MCP::State::kConfigured);
2540  }
2541 
2542  if (server=="FTM_CONTROL")
2543  {
2544  // FIXME: Enable FTU page!!!
2545  fStatusFTMLabel->setText(s.name.c_str());
2546  fStatusFTMLabel->setToolTip(s.comment.c_str());
2547 
2548  bool enable = false;
2549  const bool configuring =
2554 
2555  if (s.index<FTM::State::kDisconnected) // No Dim connection
2556  SetLedColor(fStatusFTMLed, kLedGray, time);
2557  if (s.index==FTM::State::kDisconnected) // Dim connection / FTM disconnected
2558  SetLedColor(fStatusFTMLed, kLedYellow, time);
2559  if (s.index==FTM::State::kConnected ||
2560  s.index==FTM::State::kIdle ||
2562  configuring) // Dim connection / FTM connected
2563  SetLedColor(fStatusFTMLed, kLedGreen, time);
2564  if (s.index==FTM::State::kTriggerOn) // Dim connection / FTM connected
2565  SetLedColor(fStatusFTMLed, kLedGreenCheck, time);
2566  if (s.index==FTM::State::kConnected ||
2567  s.index==FTM::State::kIdle ||
2568  s.index==FTM::State::kValid) // Dim connection / FTM connected
2569  enable = true;
2570  if (s.index>=FTM::State::kConfigError1) // Dim connection / FTM connected
2571  SetLedColor(fStatusFTMLed, kLedGreenWarn, time);
2572 
2573  fFtmStartRun->setEnabled(!configuring && enable && s.index!=FTM::State::kTriggerOn);
2574  fFtmStopRun->setEnabled(!configuring && !enable);
2575 
2576  fTriggerWidget->setEnabled(enable);
2577  fFtuGroupEnable->setEnabled(enable);
2578  fRatesControls->setEnabled(enable);
2579  fFtuWidget->setEnabled(s.index>FTM::State::kDisconnected);
2580 
2582  SetFtuStatusLed(time);
2583  else
2584  {
2585  SetLedColor(fStatusFTULed, kLedGray, time);
2586  fStatusFTULabel->setText("Offline");
2587  fStatusFTULabel->setToolTip("FTM is not online.");
2588  }
2589  }
2590 
2591  if (server=="FAD_CONTROL")
2592  {
2593  fStatusFADLabel->setText(s.name.c_str());
2594  fStatusFADLabel->setToolTip(s.comment.c_str());
2595 
2596  bool enable = false;
2597 
2598  if (s.index<FAD::State::kOffline) // No Dim connection
2599  {
2600  SetLedColor(fStatusFADLed, kLedGray, time);
2601 
2602  // Timing problem - sometimes they stay gray :(
2603  //for (int i=0; i<40; i++)
2604  // SetLedColor(fFadLED[i], kLedGray, time);
2605 
2606  /*
2607  fStatusEventBuilderLabel->setText("Offline");
2608  fStatusEventBuilderLabel->setToolTip("No connection to fadctrl.");
2609  fEvtBldWidget->setEnabled(false);
2610 
2611  SetLedColor(fStatusEventBuilderLed, kLedGray, time);
2612  */
2613  }
2614  if (s.index==FAD::State::kOffline) // Dim connection / FTM disconnected
2615  SetLedColor(fStatusFADLed, kLedRed, time);
2616  if (s.index==FAD::State::kDisconnected) // Dim connection / FTM disconnected
2617  SetLedColor(fStatusFADLed, kLedOrange, time);
2618  if (s.index==FAD::State::kConnecting) // Dim connection / FTM disconnected
2619  {
2620  SetLedColor(fStatusFADLed, kLedYellow, time);
2621  // FIXME FIXME FIXME: The LEDs are not displayed when disabled!
2622  enable = true;
2623  }
2624  if (s.index>=FAD::State::kConnected) // Dim connection / FTM connected
2625  {
2626  SetLedColor(fStatusFADLed, kLedGreen, time);
2627  enable = true;
2628  }
2629 
2630  fFadWidget->setEnabled(enable);
2631 
2632  fFadStart->setEnabled (s.index==FAD::State::kOffline);
2633  fFadStop->setEnabled (s.index >FAD::State::kOffline);
2634  fFadAbort->setEnabled (s.index >FAD::State::kOffline);
2635  fFadSoftReset->setEnabled(s.index >FAD::State::kOffline);
2636  fFadHardReset->setEnabled(s.index >FAD::State::kOffline);
2637  }
2638 
2639  if (server=="FSC_CONTROL")
2640  {
2641  fStatusFSCLabel->setText(s.name.c_str());
2642  fStatusFSCLabel->setToolTip(s.comment.c_str());
2643 
2644  bool enable = false;
2645 
2646  if (s.index<FSC::State::kDisconnected) // No Dim connection
2647  SetLedColor(fStatusFSCLed, kLedGray, time);
2648  if (s.index==FSC::State::kDisconnected) // Dim connection / FTM disconnected
2649  SetLedColor(fStatusFSCLed, kLedRed, time);
2650  if (s.index>=FSC::State::kConnected) // Dim connection / FTM disconnected
2651  {
2652  SetLedColor(fStatusFSCLed, kLedGreen, time);
2653  enable = true;
2654  }
2655 
2656  fAuxWidget->setEnabled(enable);
2657  }
2658 
2659  if (server=="DRIVE_CONTROL")
2660  {
2661  fStatusDriveLabel->setText(s.name.c_str());
2662  fStatusDriveLabel->setToolTip(s.comment.c_str());
2663 
2664  if (s.index<Drive::State::kDisconnected) // No Dim connection
2665  SetLedColor(fStatusDriveLed, kLedGray, time);
2666  if (s.index==Drive::State::kDisconnected) // Dim connection / No connection to cosy
2667  SetLedColor(fStatusDriveLed, kLedRed, time);
2669  //if (s.index==Drive::State::kConnected || /*s.index==Drive::State::kNotReady ||*/ s.index==Drive::State::kLocked) // Not Ready
2670  SetLedColor(fStatusDriveLed, kLedGreenBar, time);
2671  if (s.index==Drive::State::kInitialized) // Connected / Armed
2672  SetLedColor(fStatusDriveLed, kLedGreen, time);
2674  SetLedColor(fStatusDriveLed, kLedInProgress, time);
2675  if (s.index==Drive::State::kTracking || s.index==Drive::State::kOnTrack) // Tracking
2676  SetLedColor(fStatusDriveLed, kLedGreenCheck, time);
2677  if (s.index>0xff) // Error
2678  SetLedColor(fStatusDriveLed, kLedGreenWarn, time);
2679  }
2680 
2681  if (server=="BIAS_CONTROL")
2682  {
2683  fStatusBiasLabel->setText(s.name.c_str());
2684  fStatusBiasLabel->setToolTip(s.comment.c_str());
2685 
2686  if (s.index<1) // No Dim connection
2687  SetLedColor(fStatusBiasLed, kLedGray, time);
2688  if (s.index==BIAS::State::kDisconnected) // Dim connection / FTM disconnected
2689  SetLedColor(fStatusBiasLed, kLedRed, time);
2690  if (s.index==BIAS::State::kConnecting || s.index==BIAS::State::kInitializing) // Connecting / Initializing
2691  SetLedColor(fStatusBiasLed, kLedOrange, time);
2692  if (s.index==BIAS::State::kVoltageOff || BIAS::State::kLocked) // At reference
2693  SetLedColor(fStatusBiasLed, kLedGreenBar, time);
2694  if (s.index==BIAS::State::kNotReferenced) // At reference
2695  SetLedColor(fStatusBiasLed, kLedGreenWarn, time);
2696  if (s.index==BIAS::State::kRamping) // Ramping
2697  SetLedColor(fStatusBiasLed, kLedInProgress, time);
2698  if (s.index==BIAS::State::kVoltageOn) // At reference
2699  SetLedColor(fStatusBiasLed, kLedGreenCheck, time);
2700  if (s.index==BIAS::State::kOverCurrent) // Over current
2701  SetLedColor(fStatusBiasLed, kLedWarnBorder, time);
2702  if (s.index==BIAS::State::kExpertMode) // ExpertMode
2703  SetLedColor(fStatusBiasLed, kLedWarnTriangleBorder, time);
2704 
2705  fBiasWidget->setEnabled(s.index>=BIAS::State::kInitializing);
2706  }
2707 
2708  if (server=="FEEDBACK")
2709  {
2710  fStatusFeedbackLabel->setText(s.name.c_str());
2711  fStatusFeedbackLabel->setToolTip(s.comment.c_str());
2712 
2713  const bool connected = s.index> Feedback::State::kConnecting;
2715 
2716  if (s.index<=Feedback::State::kConnecting) // NoDim / Disconnected
2717  SetLedColor(fStatusFeedbackLed, kLedRed, time);
2718  if (s.index<Feedback::State::kDisconnected) // No Dim connection
2719  SetLedColor(fStatusFeedbackLed, kLedGray, time);
2720  if (s.index==Feedback::State::kConnecting) // Connecting
2721  SetLedColor(fStatusFeedbackLed, kLedOrange, time);
2722  if (connected) // Connected
2723  SetLedColor(fStatusFeedbackLed, kLedYellow, time);
2724  if (idle)
2725  SetLedColor(fStatusFeedbackLed, kLedGreen, time);
2727  SetLedColor(fStatusFeedbackLed, kLedGreenCheck, time);
2729  SetLedColor(fStatusFeedbackLed, kLedInProgress, time);
2730 
2731  fFeedbackWidget->setEnabled(connected);
2732 
2733  fFeedbackCalibrate->setEnabled(s.index==Feedback::State::kConnected || s.index==Feedback::State::kCalibrated);
2734  fFeedbackStart->setEnabled(s.index==Feedback::State::kCalibrated);
2735  fFeedbackStop->setEnabled(s.index>Feedback::State::kCalibrated);
2736  fFeedbackOvervoltage->setEnabled(connected);
2737 
2738  const bool enable = s.index>=Feedback::State::kCalibrated;
2739 
2740  fFeedbackFrameLeft->setEnabled(enable);
2741  fFeedbackCanvLeft->setEnabled(enable);
2742 
2743  fStateFeedback = s.index;
2744  }
2745 
2746  if (server=="RATE_CONTROL")
2747  {
2748  fStatusRateControlLabel->setText(s.name.c_str());
2749  fStatusRateControlLabel->setToolTip(s.comment.c_str());
2750 
2752  SetLedColor(fStatusRateControlLed, kLedGreenCheck, time);
2754  SetLedColor(fStatusRateControlLed, kLedGreen, time);
2756  SetLedColor(fStatusRateControlLed, kLedInProgress, time);
2758  SetLedColor(fStatusRateControlLed, kLedGreenBar, time);
2760  SetLedColor(fStatusRateControlLed, kLedOrange, time);
2762  SetLedColor(fStatusRateControlLed, kLedRed, time);
2764  SetLedColor(fStatusRateControlLed, kLedGray, time);
2765  }
2766 
2767  if (server=="DATA_LOGGER")
2768  {
2769  fStatusLoggerLabel->setText(s.name.c_str());
2770  fStatusLoggerLabel->setToolTip(s.comment.c_str());
2771 
2772  bool enable = true;
2773 
2774  if (s.index<30) // Ready/Waiting
2775  SetLedColor(fStatusLoggerLed, kLedYellow, time);
2776  if (s.index==30) // Ready/Waiting
2777  SetLedColor(fStatusLoggerLed, kLedGreen, time);
2778  if (s.index<-1) // Offline
2779  {
2780  SetLedColor(fStatusLoggerLed, kLedGray, time);
2781  enable = false;
2782  }
2783  if (s.index>=0x100) // Error
2784  SetLedColor(fStatusLoggerLed, kLedRed, time);
2785  if (s.index==40) // Logging
2786  SetLedColor(fStatusLoggerLed, kLedGreen, time);
2787 
2788  fLoggerWidget->setEnabled(enable);
2789  fLoggerStart->setEnabled(s.index>-1 && s.index<30);
2790  fLoggerStop->setEnabled(s.index>=30);
2791  }
2792 
2793  if (server=="MAGIC_WEATHER")
2794  {
2795  fStatusWeatherLabel->setText(s.name.c_str());
2796 
2798  SetLedColor(fStatusWeatherLed, kLedGreen, time);
2800  SetLedColor(fStatusWeatherLed, kLedRed, time);
2802  SetLedColor(fStatusWeatherLed, kLedGray, time);
2803  }
2804 
2805  if (server=="CHAT")
2806  {
2807  fStatusChatLabel->setText(s.name.c_str());
2808 
2809  fChatOnline = s.index==0;
2810 
2811  SetLedColor(fStatusChatLed, fChatOnline ? kLedGreen : kLedGray, time);
2812 
2813  fChatSend->setEnabled(fChatOnline);
2814  fChatMessage->setEnabled(fChatOnline);
2815  }
2816 
2817  if (server=="RATESCAN")
2818  fRateScanControls->setEnabled(s.index>=RateScan::State::kConnected);
2819 
2820  if (server=="SCHEDULER")
2821  {
2822  fStatusSchedulerLabel->setText(s.name.c_str());
2823 
2824  SetLedColor(fStatusSchedulerLed, s.index>=0 ? kLedGreen : kLedRed, time);
2825  }
2826  }
2827 
2829  {
2830  if (fTabWidget->tabText(which)=="Chat")
2831  fTabWidget->setTabIcon(which, QIcon());
2832  }
2833 
2834  void handleWrite(const Time &time, const string &text, int qos)
2835  {
2836  stringstream out;
2837 
2838  if (text.substr(0, 6)=="CHAT: ")
2839  {
2840  if (qos==MessageImp::kDebug)
2841  return;
2842 
2843  out << "<font size='-1' color='navy'>[<B>";
2844  out << time.GetAsStr("%H:%M:%S");
2845  out << "</B>]</FONT> " << text.substr(6);
2846  fChatText->append(out.str().c_str());
2847 
2848  if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
2849  return;
2850 
2851  static int num = 0;
2852  if (num++<2)
2853  return;
2854 
2855  for (int i=0; i<fTabWidget->count(); i++)
2856  if (fTabWidget->tabText(i)=="Chat")
2857  {
2858  fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
2859  break;
2860  }
2861 
2862  return;
2863  }
2864 
2865 
2866  out << "<font style='font-family:monospace' color='";
2867 
2868  switch (qos)
2869  {
2870  case kMessage: out << "black"; break;
2871  case kInfo: out << "green"; break;
2872  case kWarn: out << "#FF6600"; break;
2873  case kError: out << "maroon"; break;
2874  case kFatal: out << "maroon"; break;
2875  case kDebug: out << "navy"; break;
2876  default: out << "navy"; break;
2877  }
2878  out << "'>";
2879  out << time.GetAsStr("%H:%M:%S.%f").substr(0,12);
2880  out << " - " << text << "</font>";
2881 
2882  fLogText->append(out.str().c_str());
2883 
2884  if (qos>=kWarn && qos!=kDebug && qos!=kComment)
2885  fTextEdit->append(out.str().c_str());
2886  }
2887 
2888  void IndicateStateChange(const Time &time, const string &server)
2889  {
2890  const State s = GetState(server, GetCurrentState(server));
2891 
2892  QApplication::postEvent(this,
2893  new FunctionEvent(bind(&FactGui::handleStateChanged, this, time, server, s)));
2894  }
2895 
2896  int Write(const Time &time, const string &txt, int qos)
2897  {
2898  QApplication::postEvent(this,
2899  new FunctionEvent(bind(&FactGui::handleWrite, this, time, txt, qos)));
2900 
2901  return 0;
2902  }
2903 
2904  // ====================== Dim infoHandler================================
2905 
2906  void handleDimService(const string &txt)
2907  {
2908  fDimSvcText->append(txt.c_str());
2909  }
2910 
2912  {
2913  const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
2914 
2915  stringstream dummy;
2916  const Converter conv(dummy, fmt, false);
2917 
2918  const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
2919 
2920  stringstream out;
2921  out << "<font size'-1' color='navy'>[";
2922  out << tm.GetAsStr("%H:%M:%S.%f").substr(0,12);
2923  out << "]</font> <B>" << info.getName() << "</B> - ";
2924 
2925  bool iserr = 2;
2926  if (!conv)
2927  {
2928  out << "Compilation of format string '" << fmt << "' failed!";
2929  }
2930  else
2931  {
2932  try
2933  {
2934  const string dat = info.getSize()==0 ? "&lt;empty&gt;" : conv.GetString(info.getData(), info.getSize());
2935  out << dat;
2936  iserr = info.getSize()==0;
2937  }
2938  catch (const runtime_error &e)
2939  {
2940  out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
2941  }
2942  }
2943 
2944  // srand(hash<string>()(string(info.getName())));
2945  // int bg = rand()&0xffffff;
2946 
2947  int bg = hash<string>()(string(info.getName()));
2948 
2949  // allow only light colors
2950  bg = ~(bg&0x1f1f1f)&0xffffff;
2951 
2952  if (iserr==2)
2953  bg = 0xffffff;
2954 
2955  stringstream bgcol;
2956  bgcol << hex << setfill('0') << setw(6) << bg;
2957 
2958  const string col = iserr==0 ? "black" : (iserr==1 ? "#FF6600" : "black");
2959  const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
2960 
2961  QApplication::postEvent(this,
2962  new FunctionEvent(bind(&FactGui::handleDimService, this, str)));
2963  }
2964 
2965  void CallInfoHandler(void (FactGui::*handler)(const DimData&), const DimData &d)
2966  {
2967  fInHandler = true;
2968  (this->*handler)(d);
2969  fInHandler = false;
2970  }
2971 
2972  /*
2973  void CallInfoHandler(const boost::function<void()> &func)
2974  {
2975  // This ensures that newly received values are not sent back to the emitter
2976  // because changing the value emits the valueChanged signal (or similar)
2977  fInHandler = true;
2978  func();
2979  fInHandler = false;
2980  }*/
2981 
2982  void PostInfoHandler(void (FactGui::*handler)(const DimData&))
2983  {
2984  //const boost::function<void()> f = boost::bind(handler, this, DimData(getInfo()));
2985 
2986  FunctionEvent *evt = new FunctionEvent(bind(&FactGui::CallInfoHandler, this, handler, DimData(getInfo())));
2987  // FunctionEvent *evt = new FunctionEvent(boost::bind(&FactGui::CallInfoHandler, this, f));
2988  // FunctionEvent *evt = new FunctionEvent(boost::bind(handler, this, DimData(getInfo()))));
2989 
2990  QApplication::postEvent(this, evt);
2991  }
2992 
2994  {
2995  // Initialize the time-stamp (what a weird workaround...)
2996  if (getInfo())
2997  getInfo()->getTimestamp();
2998 
2999  if (getInfo()==&fDimDNS)
3000  return PostInfoHandler(&FactGui::handleDimDNS);
3001 #ifdef DEBUG_DIM
3002  cout << "HandleDimInfo " << getInfo()->getName() << endl;
3003 #endif
3004  if (getInfo()==&fDimLoggerStats)
3005  return PostInfoHandler(&FactGui::handleLoggerStats);
3006 
3007 // if (getInfo()==&fDimFadFiles)
3008 // return PostInfoHandler(&FactGui::handleFadFiles);
3009 
3010  if (getInfo()==&fDimFadWriteStats)
3011  return PostInfoHandler(&FactGui::handleFadWriteStats);
3012 
3013  if (getInfo()==&fDimFadConnections)
3014  return PostInfoHandler(&FactGui::handleFadConnections);
3015 
3016  if (getInfo()==&fDimFadFwVersion)
3017  return PostInfoHandler(&FactGui::handleFadFwVersion);
3018 
3019  if (getInfo()==&fDimFadRunNumber)
3020  return PostInfoHandler(&FactGui::handleFadRunNumber);
3021 
3022  if (getInfo()==&fDimFadDNA)
3023  return PostInfoHandler(&FactGui::handleFadDNA);
3024 
3025  if (getInfo()==&fDimFadTemperature)
3026  return PostInfoHandler(&FactGui::handleFadTemperature);
3027 
3028  if (getInfo()==&fDimFadRefClock)
3029  return PostInfoHandler(&FactGui::handleFadRefClock);
3030 
3031  if (getInfo()==&fDimFadRoi)
3032  return PostInfoHandler(&FactGui::handleFadRoi);
3033 
3034  if (getInfo()==&fDimFadDac)
3035  return PostInfoHandler(&FactGui::handleFadDac);
3036 
3037  if (getInfo()==&fDimFadDrsCalibration)
3038  return PostInfoHandler(&FactGui::handleFadDrsCalibration);
3039 
3040  if (getInfo()==&fDimFadPrescaler)
3041  return PostInfoHandler(&FactGui::handleFadPrescaler);
3042 
3043  if (getInfo()==&fDimFadStatus)
3044  return PostInfoHandler(&FactGui::handleFadStatus);
3045 
3046  if (getInfo()==&fDimFadStatistics1)
3047  return PostInfoHandler(&FactGui::handleFadStatistics1);
3048 
3049  //if (getInfo()==&fDimFadStatistics2)
3050  // return PostInfoHandler(&FactGui::handleFadStatistics2);
3051 
3052  if (getInfo()==&fDimFadFileFormat)
3053  return PostInfoHandler(&FactGui::handleFadFileFormat);
3054 
3055  if (getInfo()==&fDimFadEvents)
3056  return PostInfoHandler(&FactGui::handleFadEvents);
3057 
3058  if (getInfo()==&fDimFadRuns)
3059  return PostInfoHandler(&FactGui::handleFadRuns);
3060 
3061  if (getInfo()==&fDimFadStartRun)
3062  return PostInfoHandler(&FactGui::handleFadStartRun);
3063 
3064  if (getInfo()==&fDimFadRawData)
3065  return PostInfoHandler(&FactGui::handleFadRawData);
3066 
3067  if (getInfo()==&fDimFadEventData)
3068  return PostInfoHandler(&FactGui::handleFadEventData);
3069 
3070 /*
3071  if (getInfo()==&fDimFadSetup)
3072  return PostInfoHandler(&FactGui::handleFadSetup);
3073 */
3074  if (getInfo()==&fDimLoggerFilenameNight)
3075  return PostInfoHandler(&FactGui::handleLoggerFilenameNight);
3076 
3077  if (getInfo()==&fDimLoggerNumSubs)
3078  return PostInfoHandler(&FactGui::handleLoggerNumSubs);
3079 
3080  if (getInfo()==&fDimLoggerFilenameRun)
3081  return PostInfoHandler(&FactGui::handleLoggerFilenameRun);
3082 
3083  if (getInfo()==&fDimFtmTriggerRates)
3084  return PostInfoHandler(&FactGui::handleFtmTriggerRates);
3085 
3086  if (getInfo()==&fDimFtmCounter)
3087  return PostInfoHandler(&FactGui::handleFtmCounter);
3088 
3089  if (getInfo()==&fDimFtmDynamicData)
3090  return PostInfoHandler(&FactGui::handleFtmDynamicData);
3091 
3092  if (getInfo()==&fDimFtmPassport)
3093  return PostInfoHandler(&FactGui::handleFtmPassport);
3094 
3095  if (getInfo()==&fDimFtmFtuList)
3096  return PostInfoHandler(&FactGui::handleFtmFtuList);
3097 
3098  if (getInfo()==&fDimFtmStaticData)
3099  return PostInfoHandler(&FactGui::handleFtmStaticData);
3100 
3101  if (getInfo()==&fDimFtmError)
3102  return PostInfoHandler(&FactGui::handleFtmError);
3103 
3104  if (getInfo()==&fDimFscTemp)
3105  return PostInfoHandler(&FactGui::handleFscTemp);
3106 
3107  if (getInfo()==&fDimFscVolt)
3108  return PostInfoHandler(&FactGui::handleFscVolt);
3109 
3110  if (getInfo()==&fDimFscCurrent)
3111  return PostInfoHandler(&FactGui::handleFscCurrent);
3112 
3113  if (getInfo()==&fDimFscHumidity)
3114  return PostInfoHandler(&FactGui::handleFscHumidity);
3115 
3116  //if (getInfo()==&fDimBiasNominal)
3117  // return PostInfoHandler(&FactGui::handleBiasNominal);
3118 
3119  if (getInfo()==&fDimBiasVolt)
3120  return PostInfoHandler(&FactGui::handleBiasVolt);
3121 
3122  if (getInfo()==&fDimBiasDac)
3123  return PostInfoHandler(&FactGui::handleBiasDac);
3124 
3125  if (getInfo()==&fDimBiasCurrent)
3126  return PostInfoHandler(&FactGui::handleBiasCurrent);
3127 
3128  if (getInfo()==&fDimFeedbackCalibrated)
3129  return PostInfoHandler(&FactGui::handleFeedbackCalibratedCurrents);
3130 
3131  if (getInfo()==&fDimRateScan)
3132  return PostInfoHandler(&FactGui::handleRateScan);
3133 
3134  if (getInfo()==&fDimMagicWeather)
3135  return PostInfoHandler(&FactGui::handleMagicWeather);
3136 
3137 // if (getInfo()==&fDimFadFiles)
3138 // return PostInfoHandler(&FactGui::handleFadFiles);
3139 
3140  for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
3141  if (i->second==getInfo())
3142  {
3143  infoHandlerService(*i->second);
3144  return;
3145  }
3146 
3147  //DimNetwork::infoHandler();
3148  }
3149 
3150 
3151  // ======================================================================
3152 
3153  bool event(QEvent *evt)
3154  {
3155  if (dynamic_cast<FunctionEvent*>(evt))
3156  return static_cast<FunctionEvent*>(evt)->Exec();
3157 
3158  if (dynamic_cast<CheckBoxEvent*>(evt))
3159  {
3160  const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
3161  const QStandardItem *par = item.parent();
3162  if (par)
3163  {
3164  const QString server = par->text();
3165  const QString service = item.text();
3166 
3167  const string s = (server+'/'+service).toStdString();
3168 
3169  if (item.checkState()==Qt::Checked)
3170  SubscribeService(s);
3171  else
3172  UnsubscribeService(s);
3173  }
3174  }
3175 
3176  return MainWindow::event(evt); // unrecognized
3177  }
3178 
3180  {
3181  const QString server = fDimCmdServers->currentIndex().data().toString();
3182  const QString command = fDimCmdCommands->currentIndex().data().toString();
3183  const QString arguments = fDimCmdLineEdit->displayText();
3184 
3185  // FIXME: Sending a command exactly when the info Handler changes
3186  // the list it might lead to confusion.
3187  try
3188  {
3189  SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
3190  fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
3191  fDimCmdLineEdit->clear();
3192  }
3193  catch (const runtime_error &e)
3194  {
3195  stringstream txt;
3196  txt << e.what();
3197 
3198  string buffer;
3199  while (getline(txt, buffer, '\n'))
3200  fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
3201  }
3202  }
3203 
3204 #ifdef HAVE_ROOT
3205  void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *canv)
3206  {
3207  // kMousePressEvent // TCanvas processed QEvent mousePressEvent
3208  // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
3209  // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
3210  // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
3211  // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
3212  // kEnterEvent // TCanvas processed QEvent enterEvent
3213  // kLeaveEvent // TCanvas processed QEvent leaveEvent
3214 
3215  if (dynamic_cast<TCanvas*>(obj))
3216  return;
3217 
3218  TQtWidget *tipped = static_cast<TQtWidget*>(sender());
3219 
3220  if (evt==11/*kMouseReleaseEvent*/)
3221  return;
3222 
3223  if (evt==61/*kMouseDoubleClickEvent*/)
3224  return;
3225 
3226  if (obj)
3227  {
3228  // Find the object which will get picked by the GetObjectInfo
3229  // due to buffer overflows in many root-versions
3230  // in TH1 and TProfile we have to work around and implement
3231  // our own GetObjectInfo which make everything a bit more
3232  // complicated.
3233  canv->cd();
3234 #if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
3235  const char *objectInfo =
3236  obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
3237 #else
3238  const char *objectInfo = dynamic_cast<TH1*>(obj) ?
3239  "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
3240 #endif
3241 
3242  QString tipText;
3243  tipText += obj->GetName();
3244  tipText += " [";
3245  tipText += obj->ClassName();
3246  tipText += "]: ";
3247  tipText += objectInfo;
3248 
3249  fStatusBar->showMessage(tipText, 3000);
3250  }
3251 
3252  gSystem->DispatchOneEvent(kFALSE);
3253  //gSystem->ProcessEvents();
3254  //QWhatsThis::display(tipText)
3255  }
3256 
3257  void slot_RootUpdate()
3258  {
3259  gSystem->DispatchOneEvent(kFALSE);
3260  //gSystem->ProcessEvents();
3261  QTimer::singleShot(10, this, SLOT(slot_RootUpdate()));
3262  }
3263 #endif
3264 
3265  void ChoosePatchThreshold(Camera &cam, int isw)
3266  {
3267  cam.Reset();
3268 
3269  fThresholdIdx->setValue(isw);
3270 
3271  const int ihw = isw<0 ? 0 : fPatchMapHW[isw];
3272 
3273  fPatchRate->setEnabled(isw>=0);
3274  fThresholdCrate->setEnabled(isw>=0);
3275  fThresholdBoard->setEnabled(isw>=0);
3276  fThresholdPatch->setEnabled(isw>=0);
3277 
3278  if (isw<0)
3279  return;
3280 
3281  const int patch = ihw%4;
3282  const int board = (ihw/4)%10;
3283  const int crate = (ihw/4)/10;
3284 
3285  fInChoosePatchTH = true;
3286 
3287  fThresholdCrate->setValue(crate);
3288  fThresholdBoard->setValue(board);
3289  fThresholdPatch->setValue(patch);
3290 
3291  fInChoosePatchTH = false;
3292 
3293  fThresholdVal->setValue(fFtmStaticData.fThreshold[ihw]);
3294  fPatchRate->setValue(fTriggerRates.fPatchRate[ihw]);
3295  fBoardRate->setValue(fTriggerRates.fBoardRate[ihw/4]);
3296 
3297  // Loop over the software idx of all pixels
3298 // for (unsigned int i=0; i<1440; i++)
3299 // if (fPatchHW[i]==ihw)
3300 // cam.SetBold(i);
3301  }
3302 
3304  {
3305  fPixelIdx->setValue(isw);
3306 
3307  const PixelMapEntry &entry = fPixelMap.index(isw);
3308  fPixelEnable->setChecked(fFtmStaticData.IsEnabled(entry.hw()));
3309  }
3310 
3312  {
3313  fPixelIdx->setValue(isw);
3314 
3315  const PixelMapEntry &entry = fPixelMap.index(isw);
3316  Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", uint16_t(entry.hw()));
3317  }
3318 
3319  void slot_CameraMouseMove(int isw)
3320  {
3321  const PixelMapEntry &entry = fPixelMap.index(isw);
3322 
3323  QString tipText;
3324  tipText += fRatesCanv->GetName();
3325  ostringstream str;
3326  str << setfill('0') <<
3327  " || HW: " << entry.crate() << "|" << entry.board() << "|" << entry.patch() << "|" << entry.pixel() << " (crate|board|patch|pixel)" <<
3328  " || HV: " << entry.hv_board << "|" << setw(2) << entry.hv_channel << " (board|channel)" <<
3329  " || ID: " << isw;
3330 
3331 
3332  tipText += str.str().c_str();
3333  fStatusBar->showMessage(tipText, 3000);
3334  }
3335 
3337  {
3338  int ii = 0;
3339  for (; ii<160; ii++)
3340  if (fPixelMap.index(isw).hw()/9==fPatchMapHW[ii])
3341  break;
3342 
3343  fRatesCanv->SetWhite(isw);
3344  ChoosePatchThreshold(*fRatesCanv, ii);
3345 
3346  const PixelMapEntry &entry = fPixelMap.index(isw);
3347  fPixelEnable->setChecked(fFtmStaticData.IsEnabled(entry.hw()));
3348  }
3349 
3350  // ------------------- Bias display ---------------------
3351 
3353  {
3354  const int b = fBiasHvBoard->value();
3355  const int c = fBiasHvChannel->value();
3356 
3357  const int ihw = b*32+c;
3358 
3359  if (fVecBiasVolt.size()>0)
3360  {
3361  fBiasVoltCur->setValue(fVecBiasVolt[ihw]);
3362  SetLedColor(fBiasNominalLed,
3363  fVecBiasDac[ihw]==fVecBiasDac[ihw+416]?kLedGreen:kLedRed, Time());
3364  }
3365 
3366  if (fVecBiasCurrent.size()>0)
3367  {
3368  const double val = abs(fVecBiasCurrent[ihw]) * 5000./4096;
3369  fBiasCurrent->setValue(val);
3370  SetLedColor(fBiasOverCurrentLed,
3371  fVecBiasCurrent[ihw]<0?kLedRed:kLedGreen, Time());
3372  }
3373 
3374  const bool calibrated = fStateFeedback>=Feedback::State::kCalibrated &&
3375  fVecFeedbackCurrents.size()>0;
3376 
3377  fBiasCalibrated->setValue(calibrated ? fVecFeedbackCurrents[ihw] : 0);
3378  fBiasCalibrated->setEnabled(calibrated);
3379  }
3380 
3381  void UpdateBiasCam(const PixelMapEntry &entry)
3382  {
3383  fInChooseBiasCam = true;
3384 
3385  fBiasCamCrate->setValue(entry.crate());
3386  fBiasCamBoard->setValue(entry.board());
3387  fBiasCamPatch->setValue(entry.patch());
3388  fBiasCamPixel->setValue(entry.pixel());
3389 
3390  fInChooseBiasCam = false;
3391  }
3392 
3394  {
3395  if (fInChooseBiasHv)
3396  return;
3397 
3398  const int b = fBiasHvBoard->value();
3399  const int ch = fBiasHvChannel->value();
3400 
3401  // FIXME: Mark corresponding patch in camera
3402  const PixelMapEntry &entry = fPixelMap.hv(b, ch);
3403  fBiasCamV->SetWhite(entry.index);
3404  fBiasCamA->SetWhite(entry.index);
3405  fBiasCamV->updateCamera();
3406  fBiasCamA->updateCamera();
3407 
3408  UpdateBiasCam(entry);
3409  UpdateBiasValues();
3410  }
3411 
3412  void UpdateBiasHv(const PixelMapEntry &entry)
3413  {
3414  fInChooseBiasHv = true;
3415 
3416  fBiasHvBoard->setValue(entry.hv_board);
3417  fBiasHvChannel->setValue(entry.hv_channel);
3418 
3419  fInChooseBiasHv = false;
3420  }
3421 
3423  {
3424  if (fInChooseBiasCam)
3425  return;
3426 
3427  const int crate = fBiasCamCrate->value();
3428  const int board = fBiasCamBoard->value();
3429  const int patch = fBiasCamPatch->value();
3430  const int pixel = fBiasCamPixel->value();
3431 
3432  // FIXME: Display corresponding patches
3433  const PixelMapEntry &entry = fPixelMap.cbpx(crate, board, patch, pixel);
3434  fBiasCamV->SetWhite(entry.index);
3435  fBiasCamA->SetWhite(entry.index);
3436  fBiasCamV->updateCamera();
3437  fBiasCamA->updateCamera();
3438 
3439  UpdateBiasHv(entry);
3440  UpdateBiasValues();
3441  }
3442 
3444  {
3445  const PixelMapEntry &entry = fPixelMap.index(isw);
3446 
3447  UpdateBiasHv(entry);
3448  UpdateBiasCam(entry);
3449  UpdateBiasValues();
3450  }
3451 
3453  {
3454  // FIXME: Display patches for which ref==cur
3455 
3456  valarray<double> dat(0., 1440);
3457  fBiasCamV->setTitle("Applied BIAS voltage");
3458 
3459  if (fVecBiasVolt.size()>0 && fVecBiasDac.size()>0)
3460  {
3461  for (int i=0; i<1440; i++)
3462  {
3463  const PixelMapEntry &entry = fPixelMap.index(i);
3464 
3465  dat[i] = fVecBiasVolt[entry.hv()];
3466  fBiasCamV->highlightPixel(i, fVecBiasDac[entry.hv()]!=fVecBiasDac[entry.hv()+416]);
3467  }
3468 
3469  fBiasCamV->SetData(dat);
3470  }
3471 
3472  fBiasCamV->updateCamera();
3473  }
3474 
3475  // ------------------------------------------------------
3476 
3478  {
3479  if (fInHandler)
3480  return;
3481 
3482  const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
3483 
3484  Dim::SendCommand(b==Qt::Unchecked ?
3485  "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
3486  uint16_t(entry.hw()));
3487  }
3488 
3490  {
3491  const PixelMapEntry &entry = fPixelMap.index(fPixelIdx->value());
3492  Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PIXELS_EXCEPT", uint16_t(entry.hw()));
3493  }
3494 
3496  {
3497  const int16_t isw = fThresholdIdx->value();
3498  const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3499  if (ihw<0)
3500  return;
3501 
3502  Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PATCHES_EXCEPT", ihw);
3503  }
3504 
3506  {
3507  const int16_t isw = fThresholdIdx->value();
3508  const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3509  if (ihw<0)
3510  return;
3511 
3512  Dim::SendCommand("FTM_CONTROL/ENABLE_PATCH", ihw);
3513  }
3514 
3516  {
3517  const int16_t isw = fThresholdIdx->value();
3518  const int16_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3519  if (ihw<0)
3520  return;
3521 
3522  Dim::SendCommand("FTM_CONTROL/DISABLE_PATCH", ihw);
3523  }
3524 
3526  {
3527  fThresholdVolt->setValue(2500./4095*v);
3528 
3529  const int32_t isw = fThresholdIdx->value();
3530  const int32_t ihw = isw<0 ? -1 : fPatchMapHW[isw];
3531 
3532  const int32_t d[2] = { ihw, v };
3533 
3534  if (!fInHandler)
3535  Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
3536  }
3537 
3538  TGraph fGraphFtmTemp[4];
3540  TGraph fGraphPatchRate[160];
3541  TGraph fGraphBoardRate[40];
3542 
3543 #ifdef HAVE_ROOT
3544  TH1 *DrawTimeFrame(const char *ytitle)
3545  {
3546  const double tm = Time().RootTime();
3547 
3548  TH1F *h=new TH1F("TimeFrame", "", 1, tm, tm+60);//Time().RootTime()-1./24/60/60, Time().RootTime());
3549  h->SetDirectory(0);
3550  h->SetBit(kCanDelete);
3551  h->SetStats(kFALSE);
3552 // h.SetMinimum(0);
3553 // h.SetMaximum(1);
3554  h->SetXTitle("Time");
3555  h->SetYTitle(ytitle);
3556  h->GetXaxis()->CenterTitle();
3557  h->GetYaxis()->CenterTitle();
3558  h->GetXaxis()->SetTimeDisplay(true);
3559  h->GetXaxis()->SetTimeFormat("%Mh%S'%F1995-01-01 00:00:00 GMT");
3560  h->GetXaxis()->SetLabelSize(0.025);
3561  h->GetYaxis()->SetLabelSize(0.025);
3562  h->GetYaxis()->SetTitleOffset(1.2);
3563  // h.GetYaxis()->SetTitleSize(1.2);
3564  return h;
3565  }
3566 #endif
3567 
3568  pair<string,string> Split(const string &str) const
3569  {
3570  const size_t p = str.find_first_of('|');
3571  if (p==string::npos)
3572  return make_pair(str, "");
3573 
3574  return make_pair(str.substr(0, p), str.substr(p+1));
3575  }
3576 
3577 public:
3579  fFtuStatus(40),
3580  /*fPixelMapHW(1440),*/ fPatchMapHW(160),
3581  fInChoosePatchTH(false),
3582  fInChooseBiasHv(false), fInChooseBiasCam(false),
3583  fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
3584  //-
3585  fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
3586  fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHTLY", (void*)NULL, 0, this),
3587  fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", (void*)NULL, 0, this),
3588  fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", (void*)NULL, 0, this),
3589  //-
3590  fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
3591  fDimFtmTriggerRates ("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this),
3592  fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
3593  fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
3594  fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
3595  fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this),
3596  fDimFtmCounter ("FTM_CONTROL/COUNTER", (void*)NULL, 0, this),
3597  //-
3598  fDimFadWriteStats ("FAD_CONTROL/STATS", (void*)NULL, 0, this),
3599  fDimFadStartRun ("FAD_CONTROL/START_RUN", (void*)NULL, 0, this),
3600  fDimFadRuns ("FAD_CONTROL/RUNS", (void*)NULL, 0, this),
3601  fDimFadEvents ("FAD_CONTROL/EVENTS", (void*)NULL, 0, this),
3602  fDimFadRawData ("FAD_CONTROL/RAW_DATA", (void*)NULL, 0, this),
3603  fDimFadEventData ("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, this),
3604  fDimFadConnections ("FAD_CONTROL/CONNECTIONS", (void*)NULL, 0, this),
3605  fDimFadFwVersion ("FAD_CONTROL/FIRMWARE_VERSION", (void*)NULL, 0, this),
3606  fDimFadRunNumber ("FAD_CONTROL/RUN_NUMBER", (void*)NULL, 0, this),
3607  fDimFadDNA ("FAD_CONTROL/DNA", (void*)NULL, 0, this),
3608  fDimFadTemperature ("FAD_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3609  fDimFadPrescaler ("FAD_CONTROL/PRESCALER", (void*)NULL, 0, this),
3610  fDimFadRefClock ("FAD_CONTROL/REFERENCE_CLOCK", (void*)NULL, 0, this),
3611  fDimFadRoi ("FAD_CONTROL/REGION_OF_INTEREST", (void*)NULL, 0, this),
3612  fDimFadDac ("FAD_CONTROL/DAC", (void*)NULL, 0, this),
3613  fDimFadDrsCalibration ("FAD_CONTROL/DRS_CALIBRATION", (void*)NULL, 0, this),
3614  fDimFadStatus ("FAD_CONTROL/STATUS", (void*)NULL, 0, this),
3615  fDimFadStatistics1 ("FAD_CONTROL/STATISTICS1", (void*)NULL, 0, this),
3616  //fDimFadStatistics2 ("FAD_CONTROL/STATISTICS2", (void*)NULL, 0, this),
3617  fDimFadFileFormat ("FAD_CONTROL/FILE_FORMAT", (void*)NULL, 0, this),
3618  //-
3619  fDimFscTemp ("FSC_CONTROL/TEMPERATURE", (void*)NULL, 0, this),
3620  fDimFscVolt ("FSC_CONTROL/VOLTAGE", (void*)NULL, 0, this),
3621  fDimFscCurrent ("FSC_CONTROL/CURRENT", (void*)NULL, 0, this),
3622  fDimFscHumidity ("FSC_CONTROL/HUMIDITY", (void*)NULL, 0, this),
3623  //-
3624  fDimFeedbackCalibrated ("FEEDBACK/CALIBRATED_CURRENTS", (void*)NULL, 0, this),
3625  //-
3626  fDimBiasNominal ("BIAS_CONTROL/NOMINAL", (void*)NULL, 0, this),
3627  fDimBiasVolt ("BIAS_CONTROL/VOLTAGE", (void*)NULL, 0, this),
3628  fDimBiasDac ("BIAS_CONTROL/DAC", (void*)NULL, 0, this),
3629  fDimBiasCurrent ("BIAS_CONTROL/CURRENT", (void*)NULL, 0, this),
3630  //-
3631  fDimRateScan ("RATE_SCAN/DATA", (void*)NULL, 0, this),
3632  //-
3633  fDimMagicWeather ("MAGIC_WEATHER/DATA", (void*)NULL, 0, this),
3634  //-
3635  fDimVersion(0),
3636  fFreeSpaceLogger(UINT64_MAX), fFreeSpaceData(UINT64_MAX),
3637  fEventData(0),
3638  fDrsCalibration(1440*1024*6+160*1024*2),
3639  fTimeStamp0(0)
3640  {
3641  fClockCondFreq->addItem("--- Hz", QVariant(-1));
3642  fClockCondFreq->addItem("800 MHz", QVariant(800));
3643  fClockCondFreq->addItem("1 GHz", QVariant(1000));
3644  fClockCondFreq->addItem("2 GHz", QVariant(2000));
3645  fClockCondFreq->addItem("3 GHz", QVariant(3000));
3646  fClockCondFreq->addItem("4 GHz", QVariant(4000));
3647  fClockCondFreq->addItem("5 GHz", QVariant(5000));
3648 
3649  cout << "-- run counter ---" << endl;
3650  fMcpNumEvents->addItem("unlimited", QVariant(0));
3651  const vector<uint32_t> runcount = conf.Vec<uint32_t>("run-count");
3652  for (vector<uint32_t>::const_iterator it=runcount.begin(); it!=runcount.end(); it++)
3653  {
3654  cout << *it << endl;
3655  ostringstream str;
3656  str << *it;
3657  fMcpNumEvents->addItem(str.str().c_str(), QVariant(*it));
3658  }
3659 
3660  cout << "-- run times ---" << endl;
3661  fMcpTime->addItem("unlimited", QVariant(0));
3662  const vector<string> runtime = conf.Vec<string>("run-time");
3663  for (vector<string>::const_iterator it=runtime.begin(); it!=runtime.end(); it++)
3664  {
3665  const pair<string,string> p = Split(*it);
3666  cout << *it << "|" << p.second << "|" << p.first << "|" << endl;
3667  fMcpTime->addItem(p.second.c_str(), QVariant(stoi(p.first)));
3668  }
3669 
3670  cout << "-- run types ---" << endl;
3671  const vector<string> runtype = conf.Vec<string>("run-type");
3672  for (vector<string>::const_iterator it=runtype.begin(); it!=runtype.end(); it++)
3673  {
3674  const pair<string,string> p = Split(*it);
3675  cout << *it << "|" << p.second << "|" << p.first << "|" << endl;
3676  fMcpRunType->addItem(p.second.c_str(), QVariant(p.first.c_str()));
3677  }
3678 
3679  fTriggerWidget->setEnabled(false);
3680  fFtuWidget->setEnabled(false);
3681  fFtuGroupEnable->setEnabled(false);
3682  fRatesControls->setEnabled(false);
3683  fFadWidget->setEnabled(false);
3684  fGroupEthernet->setEnabled(false);
3685  fGroupOutput->setEnabled(false);
3686  fLoggerWidget->setEnabled(false);
3687  fBiasWidget->setEnabled(false);
3688  fAuxWidget->setEnabled(false);
3689 
3690  fChatSend->setEnabled(false);
3691  fChatMessage->setEnabled(false);
3692 
3693  DimClient::sendCommand("CHAT/MSG", "GUI online.");
3694  // + MessageDimRX
3695 
3696  // --------------------------------------------------------------------------
3697 
3698  if (!fPixelMap.Read(conf.Get<string>("pixel-map-file")))
3699  {
3700  cerr << "ERROR - Problems reading " << conf.Get<string>("pixel-map-file") << endl;
3701  exit(-1);
3702  }
3703 
3704  // --------------------------------------------------------------------------
3705 
3706  ifstream fin3("PatchList.txt");
3707 
3708  string buf;
3709 
3710  int l = 0;
3711  while (getline(fin3, buf, '\n'))
3712  {
3713  buf = Tools::Trim(buf);
3714  if (buf[0]=='#')
3715  continue;
3716 
3717  unsigned int softid, hardid;
3718 
3719  stringstream str(buf);
3720 
3721  str >> softid;
3722  str >> hardid;
3723 
3724  if (softid>=fPatchMapHW.size())
3725  continue;
3726 
3727  fPatchMapHW[softid] = hardid-1;
3728 
3729  l++;
3730  }
3731 
3732  if (l!=160)
3733  cerr << "WARNING - Problems reading PatchList.txt" << endl;
3734 
3735  // --------------------------------------------------------------------------
3736 
3737  fCommentsWidget->setEnabled(false);
3738 
3739  static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))");
3740 
3741  const string database = conf.Get<string>("CommentDB");
3742 
3743  if (!database.empty())
3744  {
3745  boost::smatch what;
3746  if (!boost::regex_match(database, what, expr, boost::match_extra))
3747  throw runtime_error("Couldn't parse '"+database+"'.");
3748 
3749  if (what.size()!=10)
3750  throw runtime_error("Error parsing '"+database+"'.");
3751 
3752  const string user = what[2];
3753  const string passwd = what[4];
3754  const string server = what[5];
3755  const string db = what[9];
3756  const int port = atoi(string(what[7]).c_str());
3757 
3758  QSqlDatabase qdb = QSqlDatabase::addDatabase("QMYSQL");
3759  qdb.setHostName(server.c_str());
3760  qdb.setDatabaseName(db.c_str());
3761  qdb.setUserName(user.c_str());
3762  qdb.setPassword(passwd.c_str());
3763  qdb.setPort(port);
3764  qdb.setConnectOptions("CLIENT_SSL=1;MYSQL_OPT_RECONNECT=1");
3765  if (qdb.open())
3766  {
3767  QSqlTableModel *model = new QSqlTableModel(fTableComments, qdb);
3768  model->setTable("runcomments");
3769  model->setEditStrategy(QSqlTableModel::OnManualSubmit);
3770 
3771  const bool ok2 = model->select();
3772 
3773  if (ok2)
3774  {
3775  fTableComments->setModel(model);
3776  fTableComments->resizeColumnsToContents();
3777  fTableComments->resizeRowsToContents();
3778 
3779  connect(fCommentSubmit, SIGNAL(clicked()), model, SLOT(submitAll()));
3780  connect(fCommentRevert, SIGNAL(clicked()), model, SLOT(revertAll()));
3781  connect(fCommentUpdateLayout, SIGNAL(clicked()), fTableComments, SLOT(resizeColumnsToContents()));
3782  connect(fCommentUpdateLayout, SIGNAL(clicked()), fTableComments, SLOT(resizeRowsToContents()));
3783 
3784  fCommentsWidget->setEnabled(true);
3785  }
3786  else
3787  cout << "\n==> ERROR: Select on table failed.\n" << endl;
3788  }
3789  else
3790  cout << "\n==> ERROR: Connection to database failed:\n "
3791  << qdb.lastError().text().toStdString() << endl << endl;
3792  }
3793 
3794  // --------------------------------------------------------------------------
3795 #ifdef HAVE_ROOT
3796 
3797  fGraphFeedbackDev.SetLineColor(kBlue);
3798  fGraphFeedbackDev.SetMarkerColor(kBlue);
3799  fGraphFeedbackDev.SetMarkerStyle(kFullDotMedium);
3800 
3801  fGraphFeedbackCmd.SetLineColor(kBlue);
3802  fGraphFeedbackCmd.SetMarkerColor(kBlue);
3803  fGraphFeedbackCmd.SetMarkerStyle(kFullDotMedium);
3804 
3805  // Evolution of control deviation
3806  // Evolution of command values (bias voltage change)
3807  fGraphFeedbackDev.SetName("ControlDev");
3808  fGraphFeedbackCmd.SetName("CommandVal");
3809 
3810  TCanvas *c = fFeedbackDev->GetCanvas();
3811  c->SetBorderMode(0);
3812  c->SetFrameBorderMode(0);
3813  c->SetFillColor(kWhite);
3814  c->SetRightMargin(0.03);
3815  c->SetTopMargin(0.03);
3816  c->SetGrid();
3817 
3818  TH1 *hf = DrawTimeFrame("Overvoltage [V] ");
3819  hf->GetXaxis()->SetLabelSize(0.07);
3820  hf->GetYaxis()->SetLabelSize(0.07);
3821  hf->GetYaxis()->SetTitleSize(0.08);
3822  hf->GetYaxis()->SetTitleOffset(0.55);
3823  hf->GetXaxis()->SetTitle("");
3824  hf->GetYaxis()->SetRangeUser(0, 1.5);
3825 
3826  c->GetListOfPrimitives()->Add(hf, "");
3827  c->GetListOfPrimitives()->Add(&fGraphFeedbackDev, "LP");
3828 
3829  c = fFeedbackCmd->GetCanvas();
3830  c->SetBorderMode(0);
3831  c->SetFrameBorderMode(0);
3832  c->SetFillColor(kWhite);
3833  c->SetRightMargin(0.03);
3834  c->SetTopMargin(0.03);
3835  c->SetGrid();
3836 
3837  hf = DrawTimeFrame("Command temp delta [V] ");
3838  hf->GetXaxis()->SetLabelSize(0.07);
3839  hf->GetYaxis()->SetLabelSize(0.07);
3840  hf->GetYaxis()->SetTitleSize(0.08);
3841  hf->GetYaxis()->SetTitleOffset(0.55);
3842  hf->GetXaxis()->SetTitle("");
3843  hf->GetYaxis()->SetRangeUser(-2, 2);
3844 
3845  c->GetListOfPrimitives()->Add(hf, "");
3846  c->GetListOfPrimitives()->Add(&fGraphFeedbackCmd, "LP");
3847 
3848  // --------------------------------------------------------------------------
3849 
3850  c = fRateScanCanv->GetCanvas();
3851  //c->SetBit(TCanvas::kNoContextMenu);
3852  c->SetBorderMode(0);
3853  c->SetFrameBorderMode(0);
3854  c->SetFillColor(kWhite);
3855  c->SetRightMargin(0.03);
3856  c->SetTopMargin(0.03);
3857  c->SetGrid();
3858 
3859  TH1F *h=new TH1F("Frame", "", 1, 0, 1);
3860  h->SetDirectory(0);
3861  h->SetBit(kCanDelete);
3862  h->SetStats(kFALSE);
3863  h->SetXTitle("Threshold [DAC]");
3864  h->SetYTitle("Rate [Hz]");
3865  h->GetXaxis()->CenterTitle();
3866  h->GetYaxis()->CenterTitle();
3867  h->GetXaxis()->SetLabelSize(0.025);
3868  h->GetYaxis()->SetLabelSize(0.025);
3869  h->GetYaxis()->SetTitleOffset(1.2);
3870  c->GetListOfPrimitives()->Add(h, "");
3871 
3872  fGraphRateScan[0].SetName("CameraRate");
3873  for (int i=0; i<40; i++)
3874  {
3875  fGraphRateScan[i+1].SetName("BoardRate");
3876  fGraphRateScan[i+1].SetMarkerStyle(kFullDotMedium);
3877  }
3878  for (int i=0; i<160; i++)
3879  {
3880  fGraphRateScan[i+41].SetName("PatchRate");
3881  fGraphRateScan[i+41].SetMarkerStyle(kFullDotMedium);
3882  }
3883 
3884  fGraphRateScan[0].SetLineColor(kBlue);
3885  fGraphRateScan[0].SetMarkerColor(kBlue);
3886  fGraphRateScan[0].SetMarkerStyle(kFullDotSmall);
3887  c->GetListOfPrimitives()->Add(&fGraphRateScan[0], "LP");
3888 
3889  // --------------------------------------------------------------------------
3890 
3891  c = fFtmRateCanv->GetCanvas();
3892  //c->SetBit(TCanvas::kNoContextMenu);
3893  c->SetBorderMode(0);
3894  c->SetFrameBorderMode(0);
3895  c->SetFillColor(kWhite);
3896  c->SetRightMargin(0.03);
3897  c->SetTopMargin(0.03);
3898  c->SetGrid();
3899 
3900  hf = DrawTimeFrame("Trigger rate [Hz]");
3901  hf->GetYaxis()->SetRangeUser(0, 1010);
3902 
3903  for (int i=0; i<160; i++)
3904  {
3905  fGraphPatchRate[i].SetName("PatchRate");
3906  //fGraphPatchRate[i].SetLineColor(kBlue);
3907  //fGraphPatchRate[i].SetMarkerColor(kBlue);
3908  fGraphPatchRate[i].SetMarkerStyle(kFullDotMedium);
3909  }
3910  for (int i=0; i<40; i++)
3911  {
3912  fGraphBoardRate[i].SetName("BoardRate");
3913  //fGraphBoardRate[i].SetLineColor(kBlue);
3914  //fGraphBoardRate[i].SetMarkerColor(kBlue);
3915  fGraphBoardRate[i].SetMarkerStyle(kFullDotMedium);
3916  }
3917 
3918  fGraphFtmRate.SetLineColor(kBlue);
3919  fGraphFtmRate.SetMarkerColor(kBlue);
3920  fGraphFtmRate.SetMarkerStyle(kFullDotSmall);
3921 
3922  c->GetListOfPrimitives()->Add(hf, "");
3923  c->GetListOfPrimitives()->Add(&fGraphFtmRate, "LP");
3924 
3925  /*
3926  TCanvas *c = fFtmTempCanv->GetCanvas();
3927  c->SetBit(TCanvas::kNoContextMenu);
3928  c->SetBorderMode(0);
3929  c->SetFrameBorderMode(0);
3930  c->SetFillColor(kWhite);
3931  c->SetRightMargin(0.03);
3932  c->SetTopMargin(0.03);
3933  c->cd();
3934  */
3935  //CreateTimeFrame("Temperature / �C");
3936 
3937  fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
3938  fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
3939  fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
3940  fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
3941 
3942  fGraphFtmTemp[1].SetLineColor(kBlue);
3943  fGraphFtmTemp[2].SetLineColor(kRed);
3944  fGraphFtmTemp[3].SetLineColor(kGreen);
3945 
3946  fGraphFtmTemp[1].SetMarkerColor(kBlue);
3947  fGraphFtmTemp[2].SetMarkerColor(kRed);
3948  fGraphFtmTemp[3].SetMarkerColor(kGreen);
3949 
3950  //fGraphFtmTemp[0].Draw("LP");
3951  //fGraphFtmTemp[1].Draw("LP");
3952  //fGraphFtmTemp[2].Draw("LP");
3953  //fGraphFtmTemp[3].Draw("LP");
3954 
3955  // --------------------------------------------------------------------------
3956 
3957  c = fAdcDataCanv->GetCanvas();
3958  //c->SetBit(TCanvas::kNoContextMenu);
3959  c->SetBorderMode(0);
3960  c->SetFrameBorderMode(0);
3961  c->SetFillColor(kWhite);
3962  c->SetRightMargin(0.10);
3963  c->SetGrid();
3964  //c->cd();
3965 #endif
3966 
3967  // --------------------------------------------------------------------------
3968  fFeedbackDevCam->assignPixelMap(fPixelMap);
3969  fFeedbackDevCam->setAutoscaleLowerLimit((fFeedbackDevMin->minimum()+0.5*fFeedbackDevMin->singleStep()));
3970  fFeedbackDevCam->SetMin(fFeedbackDevMin->value());
3971  fFeedbackDevCam->SetMax(fFeedbackDevMax->value());
3972  fFeedbackDevCam->updateCamera();
3973 
3974  fFeedbackCmdCam->assignPixelMap(fPixelMap);
3975  fFeedbackCmdCam->setAutoscaleLowerLimit((fFeedbackCmdMin->minimum()+0.5*fFeedbackCmdMin->singleStep()));
3976  fFeedbackCmdCam->SetMin(fFeedbackCmdMin->value());
3977  fFeedbackCmdCam->SetMax(fFeedbackCmdMax->value());
3978  fFeedbackCmdCam->updateCamera();
3979 
3980  // --------------------------------------------------------------------------
3981 
3982  fBiasCamV->assignPixelMap(fPixelMap);
3983  fBiasCamV->setAutoscaleLowerLimit((fBiasVoltMin->minimum()+0.5*fBiasVoltMin->singleStep()));
3984  fBiasCamV->SetMin(fBiasVoltMin->value());
3985  fBiasCamV->SetMax(fBiasVoltMax->value());
3986  fBiasCamV->updateCamera();
3987 
3988  fBiasCamA->assignPixelMap(fPixelMap);
3989  fBiasCamA->setAutoscaleLowerLimit((fBiasCurrentMin->minimum()+0.5*fBiasCurrentMin->singleStep()));
3990  fBiasCamA->SetMin(fBiasCurrentMin->value());
3991  fBiasCamA->SetMax(fBiasCurrentMax->value());
3992  fBiasCamA->updateCamera();
3993 
3994  // --------------------------------------------------------------------------
3995 
3996  fRatesCanv->assignPixelMap(fPixelMap);
3997  fRatesCanv->setAutoscaleLowerLimit((fRatesMin->minimum()+0.5*fRatesMin->singleStep())*0.001);
3998  fRatesCanv->SetMin(fRatesMin->value());
3999  fRatesCanv->SetMax(fRatesMax->value());
4000  fRatesCanv->updateCamera();
4001  on_fPixelIdx_valueChanged(0);
4002 
4003  // --------------------------------------------------------------------------
4004 
4005  fRatesCanv->setTitle("Patch rates");
4006  fRatesCanv->setUnits("Hz");
4007 
4008  fBiasCamA->setTitle("BIAS current");
4009  fBiasCamA->setUnits("uA");
4010 
4011  fBiasCamV->setTitle("Applied BIAS voltage");
4012  fBiasCamV->setUnits("V");
4013 
4014  fEventCanv1->setTitle("Average (all slices)");
4015  fEventCanv2->setTitle("RMS (all slices)");
4016  fEventCanv3->setTitle("Maximum (all slices)");
4017  fEventCanv4->setTitle("Position of maximum (all slices)");
4018 
4019  fEventCanv1->setUnits("mV");
4020  fEventCanv2->setUnits("mV");
4021  fEventCanv3->setUnits("mV");
4022  fEventCanv4->setUnits("slice");
4023 
4024  // --------------------------------------------------------------------------
4025 
4026  fFeedbackDevCam->setTitle("Control deviation (Pulser amplitude voltage)");
4027  fFeedbackCmdCam->setTitle("Applied voltage change (BIAS voltage)");
4028 
4029  fFeedbackDevCam->setUnits("mV");
4030  fFeedbackCmdCam->setUnits("mV");
4031 
4032  // --------------------------------------------------------------------------
4033 
4034  QTimer::singleShot(1000, this, SLOT(slot_RootUpdate()));
4035 
4036  //widget->setMouseTracking(true);
4037  //widget->EnableSignalEvents(kMouseMoveEvent);
4038 
4039  fFtmRateCanv->setMouseTracking(true);
4040  fFtmRateCanv->EnableSignalEvents(kMouseMoveEvent);
4041 
4042  fAdcDataCanv->setMouseTracking(true);
4043  fAdcDataCanv->EnableSignalEvents(kMouseMoveEvent);
4044 
4045  fRatesCanv->setMouseTracking(true);
4046  fEventCanv1->setMouseTracking(true);
4047  fEventCanv2->setMouseTracking(true);
4048  fEventCanv3->setMouseTracking(true);
4049  fEventCanv4->setMouseTracking(true);
4050 
4051  fBiasCamV->setMouseTracking(true);
4052  fBiasCamA->setMouseTracking(true);
4053 
4054  fFeedbackDevCam->setMouseTracking(true);
4055  fFeedbackCmdCam->setMouseTracking(true);
4056 
4057  fEventCanv1->ShowPixelCursor(true);
4058  fEventCanv2->ShowPixelCursor(true);
4059  fEventCanv3->ShowPixelCursor(true);
4060  fEventCanv4->ShowPixelCursor(true);
4061 
4062  fEventCanv1->ShowPatchCursor(true);
4063  fEventCanv2->ShowPatchCursor(true);
4064  fEventCanv3->ShowPatchCursor(true);
4065  fEventCanv4->ShowPatchCursor(true);
4066 
4067  fFeedbackDevCam->ShowPixelCursor(true);
4068  fFeedbackCmdCam->ShowPixelCursor(true);
4069 
4070  fFeedbackDevCam->ShowPatchCursor(true);
4071  fFeedbackCmdCam->ShowPatchCursor(true);
4072 
4073  connect(fRatesCanv, SIGNAL(signalPixelMoveOver(int)),
4074  this, SLOT(slot_CameraMouseMove(int)));
4075  connect(fEventCanv1, SIGNAL(signalPixelMoveOver(int)),
4076  this, SLOT(slot_CameraMouseMove(int)));
4077  connect(fEventCanv2, SIGNAL(signalPixelMoveOver(int)),
4078  this, SLOT(slot_CameraMouseMove(int)));
4079  connect(fEventCanv3, SIGNAL(signalPixelMoveOver(int)),
4080  this, SLOT(slot_CameraMouseMove(int)));
4081  connect(fEventCanv4, SIGNAL(signalPixelMoveOver(int)),
4082  this, SLOT(slot_CameraMouseMove(int)));
4083 
4084  connect(fBiasCamV, SIGNAL(signalPixelMoveOver(int)),
4085  this, SLOT(slot_CameraMouseMove(int)));
4086  connect(fBiasCamA, SIGNAL(signalPixelMoveOver(int)),
4087  this, SLOT(slot_CameraMouseMove(int)));
4088 
4089  connect(fFeedbackDevCam, SIGNAL(signalPixelMoveOver(int)),
4090  this, SLOT(slot_CameraMouseMove(int)));
4091  connect(fFeedbackCmdCam, SIGNAL(signalPixelMoveOver(int)),
4092  this, SLOT(slot_CameraMouseMove(int)));
4093 
4094  connect(fRatesCanv, SIGNAL(signalPixelDoubleClick(int)),
4095  this, SLOT(slot_CameraDoubleClick(int)));
4096  connect(fRatesCanv, SIGNAL(signalCurrentPixel(int)),
4097  this, SLOT(slot_ChoosePixelThreshold(int)));
4098  connect(fBiasCamV, SIGNAL(signalCurrentPixel(int)),
4099  this, SLOT(slot_ChooseBiasChannel(int)));
4100  connect(fBiasCamA, SIGNAL(signalCurrentPixel(int)),
4101  this, SLOT(slot_ChooseBiasChannel(int)));
4102 
4103  connect(fFtmRateCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
4104  this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
4105  connect(fAdcDataCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
4106  this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
4107  }
4108 
4110  {
4111  // Unsubscribe all services
4112  for (map<string,DimInfo*>::iterator i=fServices.begin();
4113  i!=fServices.end(); i++)
4114  delete i->second;
4115 
4116  // This is allocated as a chuck of chars
4117  delete [] reinterpret_cast<char*>(fEventData);
4118  }
4119 };
4120 
4121 #endif
int start(int initState)
Definition: feeserver.c:1740
char * getFormat()
Definition: diccpp.cxx:120
void handleFadWriteStats(const DimData &d)
Definition: FactGui.h:658
void UpdateRateScan(uint32_t th, const float *rates)
Definition: FactGui.h:2331
vector< float > fVecFeedbackCurrents
Definition: FactGui.h:2264
void handleStateChanged(const Time &time, const string &server, const State &s)
Definition: FactGui.h:2513
bool HasTrigger() const
Definition: HeadersFTM.h:415
void UpdateTriggerRate(const FTM::DimTriggerRates &sdata)
Definition: FactGui.h:1657
uint16_t fNumBoards
Definition: HeadersFTM.h:677
uint16_t fTriggerSeqPed
Definition: HeadersFTM.h:390
bool HasLPintG1() const
Definition: HeadersFTM.h:426
Set color Cyan.
Definition: WindowLog.h:22
static int sendCommand(const char *name, int data)
Definition: diccpp.cxx:1098
float fPatchRate[160]
Definition: HeadersFTM.h:191
void handleFadStatistics1(const DimData &d)
Definition: FactGui.h:1585
void handleFscVolt(const DimData &d)
Definition: FactGui.h:2175
FTM::DimStaticData fFtmStaticData
Definition: FactGui.h:1882
DimStampedInfo fDimFadDNA
Definition: FactGui.h:106
int crate() const
Bias supply channel.
Definition: PixelMap.h:35
Set color White.
Definition: WindowLog.h:23
DimStampedInfo fDimLoggerStats
Definition: FactGui.h:84
DimStampedInfo fDimFtmStaticData
Definition: FactGui.h:93
void handleFadPrescaler(const DimData &d)
Definition: FactGui.h:1492
DimStampedInfo fDimFadRawData
Definition: FactGui.h:101
void handleFadRunNumber(const DimData &d)
Definition: FactGui.h:1487
int patch() const
Definition: PixelMap.h:37
void handleFtmFtuList(const DimData &d)
Definition: FactGui.h:2048
void on_fThresholdDisableOthers_clicked()
Definition: FactGui.h:3495
void PostInfoHandler(void(FactGui::*handler)(const DimData &))
Definition: FactGui.h:2982
void infoHandlerService(DimInfo &info)
Definition: FactGui.h:2911
DimStampedInfo fDimFeedbackCalibration
Definition: FactGui.h:123
void slot_CameraDoubleClick(int isw)
Definition: FactGui.h:3311
uint16_t fTriggerSeqLPint
Definition: HeadersFTM.h:194
float fOnTime
Definition: HeadersFTM.h:194
const PixelMapEntry & cbpx(int c) const
Definition: PixelMap.h:118
DimStampedInfo fDimFadDrsCalibration
Definition: FactGui.h:112
std::string comment
Name (e.g. &#39;Connected&#39;)
Definition: State.h:13
void handleRemoveAllServices(const string &server)
Definition: FactGui.h:375
void handleAddService(const string &server, const string &service, const string &, bool iscmd, const vector< Description > &vec)
Definition: FactGui.h:346
vector< float > fVecBiasVolt
Definition: FactGui.h:2450
Definition: did.h:42
void on_fBoardRatesEnabled_toggled(bool)
Definition: FactGui.h:1727
void handleFadDac(const DimData &d)
Definition: FactGui.h:931
int i
Definition: db_dim_client.c:21
void handleAddServer(const string &server, const State &state)
Definition: FactGui.h:341
void handleAddDescription(const string &server, const string &service, const vector< Description > &vec, bool iscmd)
Definition: FactGui.h:395
bool CheckSize(const DimData &d, size_t sz, bool print=true) const
Definition: FactGui.h:639
Set color Green.
Definition: WindowLog.h:18
void handleDimService(const string &txt)
Definition: FactGui.h:2906
DimStampedInfo fDimFeedbackCalibrated
Definition: FactGui.h:124
void UpdateBiasHv(const PixelMapEntry &entry)
Definition: FactGui.h:3412
void on_fBiasDispRefVolt_stateChanged(int=0)
Definition: FactGui.h:3452
DimStampedInfo fDimBiasVolt
Definition: FactGui.h:127
uint16_t fTriggerInterval
only 8 bit used
Definition: HeadersFTM.h:224
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
void AddServer(const string &s)
Definition: FactGui.h:297
T Get(const std::string &var)
uint8_t fIntensityLPext
Intensity of LEDs (0-127)
Definition: HeadersFTM.h:395
void handleLoggerFilenameRun(const DimData &d)
Definition: FactGui.h:604
int Write(const Time &time, const string &txt, int qos)
Definition: FactGui.h:2896
Set color Red.
Definition: WindowLog.h:17
void SetFtuStatusLed(const Time &t)
Definition: FactGui.h:1899
void slot_ChoosePixelThreshold(int isw)
Definition: FactGui.h:3303
uint16_t fDestAddress
Definition: HeadersFTM.h:713
void handleFtmTriggerRates(const DimData &d)
Definition: FactGui.h:1775
void handleFadStartRun(const DimData &d)
Definition: FactGui.h:774
float fBoardRate[40]
Definition: HeadersFTM.h:589
void on_fPixelDisableOthers_clicked()
Definition: FactGui.h:3489
void handleFtmPassport(const DimData &d)
Definition: FactGui.h:2033
DimStampedInfo fDimDNS
Definition: FactGui.h:82
uint8_t fPing[40]
Address of FTU board.
Definition: HeadersFTM.h:682
STL namespace.
uint32_t fClockConditioner[8]
Definition: HeadersFTM.h:407
void AddDescription(QStandardItem *item, const vector< Description > &vec)
Definition: FactGui.h:281
bool HasLPintG2() const
Definition: HeadersFTM.h:427
uint32_t fTriggerCounter
Definition: HeadersFAD.h:177
DimStampedInfo fDimFadRunNumber
Definition: FactGui.h:105
void on_fThresholdVal_valueChanged(int v)
Definition: FactGui.h:3525
const std::string name
Definition: DimData.h:6
void CallInfoHandler(void(FactGui::*handler)(const DimData &), const DimData &d)
Definition: FactGui.h:2965
void handleLoggerNumSubs(const DimData &d)
Definition: FactGui.h:621
uint16_t fMultiplicityPhysics
Intensity of LEDs (0-127)
Definition: HeadersFTM.h:397
pair< string, string > Split(const string &str) const
Definition: FactGui.h:3568
uint16_t fWindowPhysics
Definition: HeadersFTM.h:400
uint8_t fIntensityLPint
Enable for LED group 1/2 (LightPulserEnable)
Definition: HeadersFTM.h:394
Definition: dic.hxx:31
DimStampedInfo fDimFscCurrent
Definition: FactGui.h:120
std::vector< T > Vec(const std::string &var)
DimStampedInfo fDimFadFileFormat
Definition: FactGui.h:116
DimStampedInfo fDimFtmTriggerRates
Definition: FactGui.h:90
void handleFadToolTip(const Time &time, QWidget *w, T *ptr)
Definition: FactGui.h:1436
void on_fThresholdEnablePatch_clicked()
Definition: FactGui.h:3505
float fBoardRate[40]
Definition: HeadersFTM.h:190
void handleDac(QPushButton *led, QSpinBox *box, const DimData &d, int idx)
Definition: FactGui.h:913
DimStampedInfo fDimBiasDac
Definition: FactGui.h:128
uint16_t fDeadTime
(4ns * x + 8ns) FTM internal programmable delay between trigger descision and time marker output ...
Definition: HeadersFTM.h:235
DimStampedInfo fDimFadStartRun
Definition: FactGui.h:98
void ChoosePatchThreshold(Camera &cam, int isw)
Definition: FactGui.h:3265
void handleFadRawData(const DimData &d)
Definition: FactGui.h:1274
uint32_t fDeadTime
Definition: HeadersFTM.h:405
std::string GetString(std::stringstream &line) const
Definition: Converter.cc:294
int getTimestampMillisecs()
Definition: diccpp.cxx:114
int index
Definition: State.h:11
void print(std::ostream &out) const
DimStampedInfo fDimFadStatistics1
Definition: FactGui.h:114
DimStampedInfo fDimFtmFtuList
Definition: FactGui.h:92
void handleFadFileFormat(const DimData &d)
Definition: FactGui.h:1638
QStandardItem * AddServiceItem(const string &server, const string &service, bool iscmd)
Definition: FactGui.h:220
void SetLedColor(QPushButton *button, LedColor_t col, const Time &t)
Definition: FactGui.h:156
void infoHandler()
Definition: FactGui.h:2993
int getSize()
Definition: dic.hxx:100
void handleRateScan(const DimData &d)
Definition: FactGui.h:2412
void AddDescription(const string &server, const string &service, const vector< Description > &vec)
Definition: FactGui.h:331
uint16_t fDelayTimeMarker
Definition: HeadersFTM.h:404
uint16_t fPrescaling[40]
Definition: HeadersFTM.h:412
void handleFadEventData(const DimData &d)
Definition: FactGui.h:1303
DimStampedInfo fDimRateScan
Definition: FactGui.h:131
void UpdateRatesGraphs(const FTM::DimTriggerRates &sdata)
Definition: FactGui.h:1732
FTM::DimTriggerRates fTriggerRates
Definition: FactGui.h:1655
void AddService(const string &server, const string &service, const string &fmt, bool iscmd)
Definition: FactGui.h:307
int pixel() const
Definition: PixelMap.h:38
const Time time
Definition: DimData.h:9
DimStampedInfo fDimFtmCounter
Definition: FactGui.h:95
DimStampedInfo fDimBiasNominal
Definition: FactGui.h:126
Definition: DimData.h:3
void handleFadDrsCalibration(const DimData &d)
Definition: FactGui.h:1339
void handleFeedbackCalibratedCurrents(const DimData &d)
Definition: FactGui.h:2266
void DrawHorizontal(TH1 *hf, double xmax, TH1 &h, double scale)
Definition: FactGui.h:948
void SetFscValue(QDoubleSpinBox *box, const DimData &d, int idx, bool enable)
Definition: FactGui.h:2103
uint8_t fNumBoardsCrate[4]
Number of boards answered in total.
Definition: HeadersFTM.h:678
DimStampedInfo fDimFadWriteStats
Definition: FactGui.h:97
void handleWrite(const Time &time, const string &text, int qos)
Definition: FactGui.h:2834
void UpdateRatesCam(const FTM::DimTriggerRates &sdata)
Definition: FactGui.h:1700
void handleFtmDynamicData(const DimData &d)
Definition: FactGui.h:1823
Implements automatic subscription to MESSAGE and STATE services.
Definition: DimNetwork.h:61
void handleFadRefClock(const DimData &d)
Definition: FactGui.h:848
bool SendCommand(const std::string &command)
Definition: Dim.h:26
FactGui(Configuration &conf)
Definition: FactGui.h:3578
void SetFadLed(QPushButton *led, const DimData &d, uint16_t bitmask, bool invert=false)
Definition: FactGui.h:1523
void handleFscHumidity(const DimData &d)
Definition: FactGui.h:2219
uint8_t fAddr[40]
DNA of FTU board.
Definition: HeadersFTM.h:681
DimStampedInfo fDimFadConnections
Definition: FactGui.h:103
PixelMap fPixelMap
Definition: FactGui.h:73
void UpdateBiasCam(const PixelMapEntry &entry)
Definition: FactGui.h:3381
Set color Magenta.
Definition: WindowLog.h:21
void AddServer(const std::string &s)
A list with all MESSAGE services to which we subscribed.
Definition: DimNetwork.cc:68
void on_fDimCmdSend_clicked()
Needs access to DimNetwork thus it is implemented in the derived class.
Definition: FactGui.h:3179
FunctionEvent(const function< void(const QEvent &)> &f)
Definition: FactGui.h:64
void slot_ChooseBiasChannel(int isw)
Definition: FactGui.h:3443
DimStampedInfo fDimFscTemp
Definition: FactGui.h:118
int getTimestamp()
Definition: diccpp.cxx:107
const T & ref(uint32_t offset=0) const
Definition: DimData.h:35
uint16_t fTriggerSeqLPext
Definition: HeadersFTM.h:195
bool Set(bool &rc, const QString &value)
DimStampedInfo fDimFadTemperature
Definition: FactGui.h:107
int board() const
Definition: PixelMap.h:36
void handleRemoveService(const string &server, const string &service, bool iscmd)
Definition: FactGui.h:352
int hv_board
gAPD index
Definition: PixelMap.h:30
int fStateFeedback
Definition: FactGui.h:2477
uint16_t qos
Definition: HeadersGPS.h:29
A message used for debugging only.
Definition: MessageImp.h:23
bool HasLPextG2() const
Definition: HeadersFTM.h:425
void handleBiasCurrent(const DimData &d)
Definition: FactGui.h:2479
void UpdateBiasValues()
Definition: FactGui.h:3352
const int qos
Definition: DimData.h:5
static std::string GetHtmlDescription(const std::vector< Description > &vec)
Definition: Description.cc:140
uint16_t fMultiplicity[40]
Definition: HeadersFTM.h:411
DimStampedInfo fDimFscVolt
Definition: FactGui.h:119
int hv() const
Definition: PixelMap.h:42
void BiasCamChannelChanged()
Definition: FactGui.h:3422
DimStampedInfo fDimFadRefClock
Definition: FactGui.h:109
bool HasExt1() const
Definition: HeadersFTM.h:420
const PixelMapEntry & index(int idx) const
Definition: PixelMap.h:107
Set color Blue.
Definition: WindowLog.h:20
int hv_channel
Bias suppply board.
Definition: PixelMap.h:31
size_t size() const
Definition: DimData.h:39
double RootTime() const
Definition: Time.cc:222
void handleFadStatus(const DimData &d)
Definition: FactGui.h:1566
bool fInChooseBiasHv
Definition: FactGui.h:79
void * getData()
Definition: diccpp.cxx:213
DimStampedInfo fDimFtmError
Definition: FactGui.h:91
uint32_t fDimVersion
Definition: FactGui.h:443
uint64_t fDNA[40]
Number of boards answered per crate.
Definition: HeadersFTM.h:680
EVENT * fEventData
Definition: FactGui.h:946
void handleFadRoi(const DimData &d)
Definition: FactGui.h:889
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
std::map< std::string, std::string > Split(std::string &, bool=false)
Definition: tools.cc:230
void UpdateGlobalStatus()
Definition: FactGui.h:445
DimStampedInfo fDimBiasCurrent
Definition: FactGui.h:129
DimStampedInfo fDimFadEventData
Definition: FactGui.h:102
T get(uint32_t offset=0) const
Definition: DimData.h:29
uint16_t fWindowCalib
Definition: HeadersFTM.h:401
void handleBiasVolt(const DimData &d)
Definition: FactGui.h:2454
Commandline parsing, resource file parsing and database access.
Definition: Configuration.h:9
static int run
Definition: dim_fork.cxx:9
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
DimStampedInfo fDimFadRuns
Definition: FactGui.h:99
int count
Definition: db_dim_server.c:18
void handleFadFwVersion(const DimData &d)
Definition: FactGui.h:1482
uint16_t fTriggerSeqPed
Definition: HeadersFTM.h:196
DimStampedInfo fDimFadFwVersion
Definition: FactGui.h:104
const char * c_str() const
Definition: DimData.h:37
void handleFscTemp(const DimData &d)
Definition: FactGui.h:2120
LedColor_t
Definition: FactGui.h:139
DimStampedInfo fDimLoggerNumSubs
Definition: FactGui.h:87
uint16_t fTriggerInterval
Definition: HeadersFTM.h:386
void handleFtmCounter(const DimData &d)
Definition: FactGui.h:1808
valarray< int8_t > fFtuStatus
Definition: FactGui.h:71
uint16_t fFirmwareId
Definition: HeadersFTM.h:144
uint32_t fTriggerCounter
Definition: HeadersFTM.h:587
bool HasLPextG1() const
Definition: HeadersFTM.h:424
void DisplayEventData()
Definition: FactGui.h:969
uint16_t fMultiplicityCalib
Definition: HeadersFTM.h:398
float fTempSensor[4]
Definition: HeadersFTM.h:548
void handleDimDNS(const DimData &d)
Definition: FactGui.h:480
vector< float > fDrsCalibration
Definition: FactGui.h:1337
DimStampedInfo fDimFtmDynamicData
Definition: FactGui.h:94
bool HasClockConditioner() const
Definition: HeadersFTM.h:422
bool fInChoosePatchTH
Definition: FactGui.h:78
vector< int16_t > fVecBiasDac
Definition: FactGui.h:2451
uint16_t fTriggerSeqLPint
Definition: HeadersFTM.h:388
bool IsEnabled(int i) const
Definition: HeadersFTM.h:430
int counter
Definition: db_dim_client.c:19
bool event(QEvent *evt)
Definition: FactGui.h:3153
void handleFtmStaticData(const DimData &d)
Definition: FactGui.h:1935
uint16_t fDelayTrigger
Definition: HeadersFTM.h:403
uint16_t fThreshold[160]
Definition: HeadersFTM.h:410
bool fInChooseBiasCam
Definition: FactGui.h:80
uint16_t fTriggerSeqLPext
Definition: HeadersFTM.h:389
function< void(const QEvent &)> fFunction
Definition: FactGui.h:62
bool IsActive(int i) const
Definition: HeadersFTM.h:429
uint64_t fBoardId
Definition: HeadersFTM.h:143
void on_fPixelEnable_stateChanged(int b)
Definition: FactGui.h:3477
void RemoveService(string server, string service, bool iscmd)
Definition: FactGui.h:315
void handleLoggerFilenameNight(const DimData &d)
Definition: FactGui.h:587
void handleLoggerStats(const DimData &d)
Definition: FactGui.h:495
TT t
Definition: test_client.c:26
static void handler(int conn_id, char *packet, int size, int status)
Definition: webServer.c:635
bool HasVeto() const
Definition: HeadersFTM.h:421
void handleFtmError(const DimData &d)
Definition: FactGui.h:2086
void DisplayRateScan()
Definition: FactGui.h:2369
std::string name
Index (e.g. 1)
Definition: State.h:12
int hw() const
Definition: PixelMap.h:39
void handleFadMinMax(const DimData &d, QPushButton *led, S *wmin, S *wmax=0)
Definition: FactGui.h:1457
std::string Trim(const std::string &str)
Definition: tools.cc:68
void DisplayRates()
Definition: FactGui.h:1838
void slot_CameraMouseMove(int isw)
Definition: FactGui.h:3319
void handleFadTemperature(const DimData &d)
Definition: FactGui.h:802
DimStampedInfo fDimFscHumidity
Definition: FactGui.h:121
int64_t fTimeStamp0
Definition: FactGui.h:1725
uint64_t fFreeSpaceLogger
Definition: FactGui.h:493
void on_fPixelIdx_valueChanged(int isw)
Definition: FactGui.h:3336
DimStampedInfo fDimMagicWeather
Definition: FactGui.h:133
void handleMagicWeather(const DimData &d)
Definition: FactGui.h:2422
void handleFadConnections(const DimData &d)
Definition: FactGui.h:1384
uint16_t fNumCalls
Definition: HeadersFTM.h:710
DimStampedInfo fDimLoggerFilenameRun
Definition: FactGui.h:86
void SubscribeService(const string &service)
Definition: FactGui.h:403
void handleBiasDac(const DimData &d)
Definition: FactGui.h:2465
DimStampedInfo fDimFadPrescaler
Definition: FactGui.h:108
vector< int16_t > fVecBiasCurrent
Definition: FactGui.h:2452
void UnsubscribeService(const string &service, bool allow_unsubscribed=false)
Definition: FactGui.h:414
Definition: Camera.h:15
void handleFadEvents(const DimData &d)
Definition: FactGui.h:788
bool IsActive(int i) const
Definition: HeadersFTM.h:703
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
Definition: Time.cc:240
TGraph fGraphFtmRate
Definition: FactGui.h:3539
void IndicateStateChange(const Time &time, const string &server)
Definition: FactGui.h:2888
void BiasHvChannelChanged()
Definition: FactGui.h:3393
void SetFtuLed(int idx, int counter, const Time &t)
Definition: FactGui.h:1884
DimStampedInfo fDimFadStatus
Definition: FactGui.h:113
bool Read(const std::string &fname)
Definition: PixelMap.h:56
void on_fThresholdDisablePatch_clicked()
Definition: FactGui.h:3515
void handleFscCurrent(const DimData &d)
Definition: FactGui.h:2197
void handleFadRuns(const DimData &d)
Definition: FactGui.h:750
DimStampedInfo fDimFadDac
Definition: FactGui.h:111
void on_fTabWidget_currentChanged(int which)
Definition: FactGui.h:2828
A compiler for the DIM data format string.
Definition: Converter.h:16
uint64_t fFreeSpaceData
Definition: FactGui.h:656
void handleFadDNA(const DimData &d)
Definition: FactGui.h:1497
void RemoveAllServices(const string &server)
Definition: FactGui.h:323
DimStampedInfo fDimFtmPassport
Definition: FactGui.h:89
const T * ptr(uint32_t offset=0) const
Definition: DimData.h:32
DimStampedInfo fDimFadEvents
Definition: FactGui.h:100
bool HasExt2() const
Definition: HeadersFTM.h:419
DimStampedInfo fDimLoggerFilenameNight
Definition: FactGui.h:85
An event posted by the CheckBoxDelegate if the CheckBox is used.
uint64_t fOnTimeCounter
Definition: HeadersFTM.h:586
const PixelMapEntry & hv(int board, int channel) const
Definition: PixelMap.h:139
DimStampedInfo fDimFadRoi
Definition: FactGui.h:110
void UnsubscribeAllServices(const string &server)
Definition: FactGui.h:430
float fPatchRate[160]
Definition: HeadersFTM.h:590
~FactGui()
Definition: FactGui.h:4109
map< string, DimInfo * > fServices
Definition: FactGui.h:135
char * getName()
Definition: dic.hxx:101
vector< int > fPatchMapHW
Definition: FactGui.h:76
uint32_t freq
Definition: HeadersSQM.h:90
bool fChatOnline
Definition: FactGui.h:2511