Changeset 10079 for fact


Ignore:
Timestamp:
01/05/11 12:25:06 (14 years ago)
Author:
ogrimm
Message:
Alarm window opens if Alarm/MasterAlarm increases
Location:
fact/Evidence/Edd
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • fact/Evidence/Edd/Edd.cc

    r10068 r10079  
    2222
    2323class EddDim *Handler;
    24 
     24QString DRSBoard = "drsdaq";
    2525
    2626// History chooser function (opens plot for numeric data, TextHist for all other)
     
    292292void EddPlot::Update(QString Name, int Time, QByteArray, QString Format, QString Text) {
    293293
     294  bool DoUpdate = false;
     295
    294296  // Determine which plot item this call belongs to
    295297  int ItemNo;
    296298  for (ItemNo=0; ItemNo<List.size(); ItemNo++) if (List[ItemNo].Name == Name) {
     299
     300        DoUpdate = true;
    297301
    298302        // If size limit reached, clear buffer
     
    335339  }
    336340
    337   UpdatePlot();
     341  if (DoUpdate) UpdatePlot();
    338342}
    339343
     
    414418  Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,canvas());
    415419  connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &)));
     420  connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(ReDoStats()));
    416421
    417422  Magnifier = new QwtPlotMagnifier(canvas());
     
    422427  Panner = new QwtPlotPanner(canvas());
    423428  Panner->setMouseButton(Qt::LeftButton, Qt::ShiftModifier);
     429  connect(Panner, SIGNAL(panned(int, int)), this, SLOT(ReDoStats()));
    424430
    425431  Picker = new QwtPicker(QwtPicker::CornerToCorner|QwtPicker::RectSelection, QwtPicker::RectRubberBand, QwtPicker::AlwaysOff, this);
     
    432438 
    433439  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);
    434447
    435448  // Context menu
     
    444457  StyleAction = Menu->addAction("Draw dots", this, SLOT(UpdatePlot()));
    445458  StyleAction->setCheckable(true);
     459  StatisticsAction = Menu->addAction("Statistics", this, SLOT(ReDoStats()));
     460  StatisticsAction->setCheckable(true);
    446461  Menu->addAction("Zoom out", this, SLOT(MenuZoomOut()));
    447462  Menu->addAction("Single trace", this, SLOT(MenuSingleTrace()));
     
    458473  for (int i=0; i<Items.size(); i++) delete Items[i].Signal;
    459474  delete Grid;
     475}
     476
     477// Print statistics to plot if requested
     478void 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();
    460520}
    461521
     
    522582  else setCanvasBackground(EddPlotBackgroundColor);
    523583
    524   replot();
     584  ReDoStats();
    525585}
    526586
     
    629689    setAxisAutoScale(QwtPlot::yLeft);
    630690  }
     691 
     692  UpdatePlot();
    631693}
    632694   
     
    717779    "Pan\tShift and left mouse button\n\n"
    718780        "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");
    720783}
    721784
     
    9551018EventScope::EventScope(QWidget *P): EddBasePlot(P), PixelMap("../../config/PixelMap.txt", false) {
    9561019
    957   Name = "drsdaq/EventData";
     1020  Name = DRSBoard+"/EventData";
    9581021  Active = false;
    9591022
     
    11661229void EventScope::SetActive(bool State) {
    11671230
    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");
    11701233  Active = State;
    11711234}
     
    12861349  Layout->addWidget(Plot, 0, 4, 12, 10);
    12871350
    1288   Line = new EddLineDisplay("drsdaq/Message");
     1351  Line = new EddLineDisplay("Feedback/Message");
    12891352  Line->setMaximumWidth(200);
    12901353  Layout->addWidget(Line, 0, 0, 1, 2);     
     
    16321695  TabWidget->setTabsClosable(true);
    16331696  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);
    16351698  TabWidget->addTab(new TP_Bias, "Bias");
    16361699  TabWidget->addTab(new TP_Feedback, "Feedback");
     
    16501713  resize(TabWidget->sizeHint()*1.1);
    16511714  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);
    16521720
    16531721   
     
    17241792}
    17251793
     1794// Check alarm level and if Alarm server is alive
     1795void 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
    17261842// Quit application when clicking close button on window
    17271843void GUI::closeEvent(QCloseEvent *) {
     1844
    17281845  qApp->quit();
    17291846}
     
    17331850int main(int argc, char *argv[]) {
    17341851
     1852  if (argc > 1) DRSBoard = "FADctrl";
     1853
    17351854  QApplication app(argc, argv);
    17361855  GUI MainWindow;
  • fact/Evidence/Edd/Edd.h

    r10068 r10079  
    5252          QVector<double> y;
    5353      double Smallest;
    54       double Largest;     
     54      double Largest;
     55          double Mean;
     56          double Sigma;
    5557    };
    5658    QList<struct PlotItem> Items;
     
    5961    QAction *NormAction;
    6062    QAction *StyleAction;
    61    
     63    QAction *StatisticsAction;
     64
    6265    QwtPlotPanner *Panner;
    6366    QwtPlotGrid *Grid;
     
    6669    QwtPicker *Picker;
    6770        QwtDoubleRect BBox;
     71        QwtPlotMarker *Stats;
    6872               
    6973  public:
     
    8084
    8185  private slots:
     86        void ReDoStats();
    8287    void HandleZoom(const QwtDoubleRect &);
    8388        void MouseSelection(const QwtPolygon &);
     
    385390    void MenuNewHistory();
    386391        void DetachTab(int);
     392        void CheckAlarm();
    387393};
    388394
Note: See TracChangeset for help on using the changeset viewer.