Changeset 10079
- Timestamp:
- 01/05/11 12:25:06 (14 years ago)
- Location:
- fact/Evidence/Edd
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/Evidence/Edd/Edd.cc
r10068 r10079 22 22 23 23 class EddDim *Handler; 24 24 QString DRSBoard = "drsdaq"; 25 25 26 26 // History chooser function (opens plot for numeric data, TextHist for all other) … … 292 292 void EddPlot::Update(QString Name, int Time, QByteArray, QString Format, QString Text) { 293 293 294 bool DoUpdate = false; 295 294 296 // Determine which plot item this call belongs to 295 297 int ItemNo; 296 298 for (ItemNo=0; ItemNo<List.size(); ItemNo++) if (List[ItemNo].Name == Name) { 299 300 DoUpdate = true; 297 301 298 302 // If size limit reached, clear buffer … … 335 339 } 336 340 337 UpdatePlot();341 if (DoUpdate) UpdatePlot(); 338 342 } 339 343 … … 414 418 Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,canvas()); 415 419 connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &))); 420 connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(ReDoStats())); 416 421 417 422 Magnifier = new QwtPlotMagnifier(canvas()); … … 422 427 Panner = new QwtPlotPanner(canvas()); 423 428 Panner->setMouseButton(Qt::LeftButton, Qt::ShiftModifier); 429 connect(Panner, SIGNAL(panned(int, int)), this, SLOT(ReDoStats())); 424 430 425 431 Picker = new QwtPicker(QwtPicker::CornerToCorner|QwtPicker::RectSelection, QwtPicker::RectRubberBand, QwtPicker::AlwaysOff, this); … … 432 438 433 439 insertLegend(new QwtLegend(), QwtPlot::TopLegend, 0.3); 440 441 // Marker for statistics text 442 Stats = new QwtPlotMarker(); 443 Stats->setLineStyle(QwtPlotMarker::NoLine); 444 Stats->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom); 445 Stats->hide(); 446 Stats->attach(this); 434 447 435 448 // Context menu … … 444 457 StyleAction = Menu->addAction("Draw dots", this, SLOT(UpdatePlot())); 445 458 StyleAction->setCheckable(true); 459 StatisticsAction = Menu->addAction("Statistics", this, SLOT(ReDoStats())); 460 StatisticsAction->setCheckable(true); 446 461 Menu->addAction("Zoom out", this, SLOT(MenuZoomOut())); 447 462 Menu->addAction("Single trace", this, SLOT(MenuSingleTrace())); … … 458 473 for (int i=0; i<Items.size(); i++) delete Items[i].Signal; 459 474 delete Grid; 475 } 476 477 // Print statistics to plot if requested 478 void EddBasePlot::ReDoStats() { 479 480 QString Text; 481 double Mean, Sigma; 482 unsigned long Count = 0; 483 484 // Set visibility of statistics box 485 Stats->setVisible(StatisticsAction->isChecked()); 486 487 for (int i=0; i<Items.size(); i++) { 488 Mean = 0; 489 Sigma = 0; 490 Count = 0; 491 492 // Calculate mean and sigma for data points currently visible 493 for (int j=0; j<Items[i].y.size(); j++) { 494 if (!axisScaleDiv(QwtPlot::xBottom)->contains(Items[i].x[j])) continue; 495 Mean += Items[i].y[j]; 496 Sigma += Items[i].y[j]*Items[i].y[j]; 497 Count++; 498 } 499 500 if (Count == 0) Mean = 0; 501 else Mean /= Count; 502 if (Count < 2) Sigma = 0; 503 else Sigma = sqrt(Count/(Count-1)*(Sigma/Count-Mean*Mean)); 504 505 // Prepare string 506 Text += Items[i].Signal->title().text() + ": m " + QString::number(Mean, 'f', 2) + ", s " + QString::number(Sigma, 'f', 2) + "\n"; 507 } 508 509 // Replot once to get axis correct 510 replot(); 511 512 // Print string to plot 513 QwtText text(Text); 514 text.setFont(QFont("Helvetica", 7)); 515 Stats->setValue(axisScaleDiv(QwtPlot::xBottom)->upperBound(), axisScaleDiv(QwtPlot::yLeft)->upperBound()); 516 Stats->setLabel(text); 517 518 // Replot again to update text 519 replot(); 460 520 } 461 521 … … 522 582 else setCanvasBackground(EddPlotBackgroundColor); 523 583 524 replot();584 ReDoStats(); 525 585 } 526 586 … … 629 689 setAxisAutoScale(QwtPlot::yLeft); 630 690 } 691 692 UpdatePlot(); 631 693 } 632 694 … … 717 779 "Pan\tShift and left mouse button\n\n" 718 780 "ESC cancels selection\n" 719 "Cursor keys move mouse"); 781 "Cursor keys move mouse\n\n" 782 "Statistics are calculated over the current x axis extend"); 720 783 } 721 784 … … 955 1018 EventScope::EventScope(QWidget *P): EddBasePlot(P), PixelMap("../../config/PixelMap.txt", false) { 956 1019 957 Name = "drsdaq/EventData";1020 Name = DRSBoard+"/EventData"; 958 1021 Active = false; 959 1022 … … 1166 1229 void EventScope::SetActive(bool State) { 1167 1230 1168 if (State && !Active) Handler->Subscribe( "drsdaq/EventData");1169 if (!State && Active) Handler->Unsubscribe( "drsdaq/EventData");1231 if (State && !Active) Handler->Subscribe(DRSBoard+"/EventData"); 1232 if (!State && Active) Handler->Unsubscribe(DRSBoard+"/EventData"); 1170 1233 Active = State; 1171 1234 } … … 1286 1349 Layout->addWidget(Plot, 0, 4, 12, 10); 1287 1350 1288 Line = new EddLineDisplay(" drsdaq/Message");1351 Line = new EddLineDisplay("Feedback/Message"); 1289 1352 Line->setMaximumWidth(200); 1290 1353 Layout->addWidget(Line, 0, 0, 1, 2); … … 1632 1695 TabWidget->setTabsClosable(true); 1633 1696 connect(TabWidget, SIGNAL(tabCloseRequested(int)), SLOT(DetachTab(int))); 1634 TabWidget->addTab(new TP_DAQ, "Event scope ");1697 TabWidget->addTab(new TP_DAQ, "Event scope " + DRSBoard); 1635 1698 TabWidget->addTab(new TP_Bias, "Bias"); 1636 1699 TabWidget->addTab(new TP_Feedback, "Feedback"); … … 1650 1713 resize(TabWidget->sizeHint()*1.1); 1651 1714 show(); 1715 1716 // Set timer to regularly check the master alarm 1717 QTimer *Timer = new QTimer(this); 1718 connect(Timer, SIGNAL(timeout()), this, SLOT(CheckAlarm())); 1719 Timer->start(5000); 1652 1720 } 1653 1721 … … 1724 1792 } 1725 1793 1794 // Check alarm level and if Alarm server is alive 1795 void GUI::CheckAlarm() { 1796 1797 static int WarnedLevel = 0; 1798 static bool AlarmServerWarned = false; 1799 1800 // === Check service Alarm/MasterAlarm === 1801 DimCurrentInfo MasterAlarm("Alarm/MasterAlarm", -1); 1802 1803 if (MasterAlarm.getInt() > WarnedLevel) { 1804 QSound::play(QApplication::applicationDirPath() + "/Error.wav"); 1805 1806 // Construct warning message box 1807 QMessageBox Box; 1808 Box.setWindowTitle("Edd Alarm"); 1809 Box.setText("Service 'Alarm/MasterAlarm' is at " + QString::number(MasterAlarm.getInt())); 1810 Box.setInformativeText("Shall the warning level be reset?"); 1811 Box.setIcon(QMessageBox::Warning); 1812 Box.setStandardButtons(QMessageBox::Yes | QMessageBox::No); 1813 Box.setDefaultButton(QMessageBox::No); 1814 1815 // Check if user wants to reset warned level 1816 if (Box.exec() == QMessageBox::Yes) WarnedLevel = 0; 1817 else WarnedLevel = MasterAlarm.getInt(); 1818 } 1819 1820 // If MasterAlam decreased, lower also warned level 1821 if (MasterAlarm.getInt() < WarnedLevel && MasterAlarm.getInt() >=0 ) WarnedLevel = MasterAlarm.getInt(); 1822 1823 // === Check Alarm server === 1824 DimCurrentInfo ServerList("DIS_DNS/SERVER_LIST", NO_LINK); 1825 std::string Result = EvidenceServer::ToString((char *) "C", ServerList.getData(), ServerList.getSize()); 1826 1827 // Warn if SERVER_LIST does not contain alarm server 1828 if (Result.find("Alarm@") == std::string::npos && !AlarmServerWarned) { 1829 QMessageBox Box; 1830 Box.setWindowTitle("Edd Alarm"); 1831 Box.setText("Alarm server is unavailable or in error"); 1832 Box.setIcon(QMessageBox::Critical); 1833 Box.setStandardButtons(QMessageBox::Ok); 1834 Box.setDefaultButton(QMessageBox::Ok); 1835 1836 AlarmServerWarned = true; 1837 } 1838 1839 if (Result.find("Alarm@") != std::string::npos) AlarmServerWarned = false; 1840 } 1841 1726 1842 // Quit application when clicking close button on window 1727 1843 void GUI::closeEvent(QCloseEvent *) { 1844 1728 1845 qApp->quit(); 1729 1846 } … … 1733 1850 int main(int argc, char *argv[]) { 1734 1851 1852 if (argc > 1) DRSBoard = "FADctrl"; 1853 1735 1854 QApplication app(argc, argv); 1736 1855 GUI MainWindow; -
fact/Evidence/Edd/Edd.h
r10068 r10079 52 52 QVector<double> y; 53 53 double Smallest; 54 double Largest; 54 double Largest; 55 double Mean; 56 double Sigma; 55 57 }; 56 58 QList<struct PlotItem> Items; … … 59 61 QAction *NormAction; 60 62 QAction *StyleAction; 61 63 QAction *StatisticsAction; 64 62 65 QwtPlotPanner *Panner; 63 66 QwtPlotGrid *Grid; … … 66 69 QwtPicker *Picker; 67 70 QwtDoubleRect BBox; 71 QwtPlotMarker *Stats; 68 72 69 73 public: … … 80 84 81 85 private slots: 86 void ReDoStats(); 82 87 void HandleZoom(const QwtDoubleRect &); 83 88 void MouseSelection(const QwtPolygon &); … … 385 390 void MenuNewHistory(); 386 391 void DetachTab(int); 392 void CheckAlarm(); 387 393 }; 388 394
Note:
See TracChangeset
for help on using the changeset viewer.