00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4MBSViewer.h"
00015
00016 #include "Riostream.h"
00017 #include "TSystem.h"
00018 #include "TH1.h"
00019
00020 #include "TGo4Slot.h"
00021 #include "TGo4BrowserProxy.h"
00022 #include "TGo4QSettings.h"
00023 #include "f_stccomm.h"
00024
00025 #include <QTimer>
00026 #include <QDateTime>
00027
00028 TGo4MBSViewer::TGo4MBSViewer(QWidget *parent, const char* name) :
00029 QGo4Widget(parent,name),
00030 fxRunMovie(0)
00031 {
00032 setupUi(this);
00033
00034 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
00035 RateEvents->setDigitCount(7);
00036 SumEvents->setDigitCount(12);
00037 RateBytes->setDigitCount(7);
00038 SumBytes->setDigitCount(8);
00039 ServerPercent->setDigitCount(3);
00040 SumBytesFile->setDigitCount(9);
00041 #else
00042 RateEvents->setNumDigits(7);
00043 SumEvents->setNumDigits(12);
00044 RateBytes->setNumDigits(7);
00045 SumBytes->setNumDigits(8);
00046 ServerPercent->setNumDigits(3);
00047 SumBytesFile->setNumDigits(9);
00048 #endif
00049
00050 fbIsMonitoring=false;
00051 fbWarningState=false;
00052 fbRunning=false;
00053 fbGetSetup=false;
00054 fbGetSetML=false;
00055 fbGetSetMO=false;
00056 fbTrending=false;
00057 fbTrendingInit=true;
00058 fbShowMore=false;
00059 fbSingleRefresh=false;
00060 fbTrendingForward=false;
00061 fiTrendBins=1000;
00062
00063 SetNode(go4sett->getMbsMonitorNode());
00064 fbTrending=go4sett->getMbsMonitorTrend();
00065 TrendCheck->setChecked(fbTrending);
00066 fiTrendBins=go4sett->getMbsMonitorBins();
00067 TrendBinsBox->setValue(fiTrendBins);
00068 fbShowMore=go4sett->getMbsMonitorMore();
00069 MoreBox->setChecked(fbShowMore);
00070 FrequencyBox->setValue(go4sett->getMbsMonitorFreq());
00071 fbTrendingForward=!(go4sett->getMbsMonitorBackwardsTrending());
00072
00073 StateGroup = new QButtonGroup(this);
00074 StateGroup->setExclusive(false);
00075 StateGroup->addButton(StatusRadio, 0);
00076 StateGroup->addButton(SetupRadio, 1);
00077 StateGroup->addButton(SetupMLRadio, 2);
00078 StateGroup->addButton(SetupMORadio, 3);
00079 StateGroup->button(0)->setChecked(true);
00080 connect(StateGroup, SIGNAL(buttonClicked(int)), this, SLOT(StateGroup_clicked(int)));
00081
00082
00083 fxHistoAccessName = "nosuchobject";
00084 fxHistokBAccessName = "nosuchobject";
00085 fxHistoEvRatioAccessName = "nosuchobject";
00086 fxServerLabel = "NO SERVER";
00087 fxTimer = new QTimer(this);
00088 fxMovieResetTimer = new QTimer(this);
00089 QString moviepath = ":/icons/mbslogorun.gif";
00090 fxRunMovie= new QMovie(moviepath);
00091 memset(&fxDaqStat, 0, sizeof(fxDaqStat));
00092 fiCalcedEventRate=0;
00093 fiCalcedDataRate=0;
00094 fiCalcedServDataRate=0;
00095 fiLastServDataNum=0;
00096 fiLastEventNum=0;
00097 fiLastDataNum=0;
00098 fxDeltaClock.start();
00099 connect( fxTimer, SIGNAL(timeout()), this, SLOT(Refresh()) );
00100 connect( fxMovieResetTimer, SIGNAL(timeout()), this, SLOT(ResetRunIcon()) );
00101 Display();
00102
00103 }
00104
00105 TGo4MBSViewer::~TGo4MBSViewer()
00106 {
00107 delete fxRunMovie;
00108 }
00109
00110
00111 void TGo4MBSViewer::StoreSettings()
00112 {
00113
00114 go4sett->setMbsMonitorNode(fxNode);
00115 go4sett->setMbsMonitorTrend(fbTrending);
00116 go4sett->setMbsMonitorBins(fiTrendBins);
00117 go4sett->setMbsMonitorMore(fbShowMore);
00118 go4sett->setMbsMonitorFreq(FrequencyBox->value());
00119 go4sett->setMbsMonitorMonitorActive(fbIsMonitoring);
00120 go4sett->setMbsMonitorBackwardsTrending(!fbTrendingForward);
00121 }
00122
00123
00124 void TGo4MBSViewer::TimerStart()
00125 {
00126 fbIsMonitoring=true;
00127 fbTrendingInit=true;
00128 fiLastEventNum=0;
00129 fiLastDataNum=0;
00130 fiLastServDataNum=0;
00131 Refresh();
00132 fxTimer->start(1000*FrequencyBox->value());
00133 Display();
00134 StoreSettings();
00135 }
00136
00137
00138 void TGo4MBSViewer::TimerStop()
00139 {
00140 fbIsMonitoring=false;
00141 fxTimer->stop();
00142 StartMovieReset();
00143 Display();
00144 StoreSettings();
00145 }
00146
00147
00148 void TGo4MBSViewer::Display()
00149 {
00150 setWindowTitle("MBS Status - "+NodeEdit->text());
00151 if(!fbSingleRefresh)
00152 {
00153 NodeEdit->setEnabled(!fbIsMonitoring);
00154 MonitorButton->setEnabled(!fbIsMonitoring);
00155 StopButton->setEnabled(fbIsMonitoring);
00156 FrequencyBox->setEnabled(!fbIsMonitoring);
00157
00158 TrendBinsBox->setEnabled(!fbTrending);
00159 }
00160 MoreFrame->setVisible(fbShowMore);
00161 SumEvents->display((double) fxDaqStat.bl_n_events);
00162
00163 RateEvents->display((double) fiCalcedEventRate);
00164 SumBytes->display((double) ((unsigned int) fxDaqStat.bl_n_kbyte/1024));
00165
00166 RateBytes->display((double) fiCalcedDataRate);
00167 DateLabel->setText(fxRefTime);
00168 SumBytesFile->display((double) ((unsigned int) fxDaqStat.bl_n_kbyte_file/1024));
00169
00170 if(fxDaqStat.l_open_file)
00171 OutfileLabel->setText(fxDaqStat.c_file_name);
00172 else
00173 OutfileLabel->setText("- file closed -") ;
00174
00175 ServerLabel->setText(fxServerLabel) ;
00176 ServerPercent->display((int) fiEvRatio);
00177 if(fbRunning && !fbWarningState){
00178 RunPix->clear();
00179 RunPix->setMovie(fxRunMovie);
00180 fxRunMovie->start();
00181 }
00182 else{
00183 RunPix->setWindowIcon(QIcon( ":/icons/mbsbutton.png" ));
00184 if(fxRunMovie) fxRunMovie->stop();
00185 }
00186 WarnPix->setVisible(fbWarningState);
00187
00188
00189 SetupRadio->setEnabled(fxDaqStat.bh_setup_loaded);
00190 SetupMLRadio->setEnabled(fxDaqStat.bh_set_ml_loaded);
00191 SetupMORadio->setEnabled(fxDaqStat.bh_set_mo_loaded);
00192 if(fbWarningState)
00193 std::cerr <<fxMessage.toLatin1().constData() << std::endl;
00194
00195 ensurePolished();
00196 update();
00197 show();
00198 }
00199
00200
00201 void TGo4MBSViewer::Refresh()
00202 {
00203
00204 if(fxNode.isEmpty()) return;
00205 int state=f_mbs_status(const_cast<char*>(fxNode.toLatin1().constData()), &fxDaqStat);
00206 if(state!=STC__SUCCESS) {
00207 fxMessage.sprintf("MBS Status refresh node %s returned error %d at ",
00208 fxNode.toLatin1().constData(), state);
00209 fxMessage += QDateTime::currentDateTime().toString();
00210 fbWarningState = true;
00211 } else
00212 fbWarningState = false;
00213
00214 fxRefTime=fxDaqStat.c_date;
00215 fbRunning=fxDaqStat.bh_acqui_running;
00216 int deltat=FrequencyBox->value();
00217 int numperiods=1;
00218 int deltamilsecs=deltat*1000.0;
00219 if(fbIsMonitoring)
00220 {
00221
00222
00223 deltamilsecs=fxDeltaClock.elapsed();
00224
00225 fxDeltaClock.restart();
00226 int deltasecs=deltamilsecs/1000;
00227 if(!fbTrendingInit && (deltasecs>=deltat*2))
00228
00229 {
00230 std::cout <<"Warning: MBS monitor found measuring interval:"<<deltasecs<<" s ("<<deltamilsecs <<" ms) exceeding timer period "<<deltat<<" s" << std::endl;
00231 std::cout <<" Maybe timer was skipped?" << std::endl;
00232 deltat=deltasecs;
00233 numperiods=(deltat/ (int) FrequencyBox->value());
00234 std::cout <<" Correcting number of measuring periods to:"<<numperiods << std::endl;
00235 }
00236 if(fiLastEventNum && deltamilsecs)
00237 fiCalcedEventRate=1000.*(fxDaqStat.bl_n_events-fiLastEventNum)/deltamilsecs;
00238 else
00239 fiCalcedEventRate=0;
00240 fiLastEventNum=fxDaqStat.bl_n_events;
00241
00242 if(fiLastDataNum && deltamilsecs)
00243 {
00244 fiDataDelta=(fxDaqStat.bl_n_kbyte-fiLastDataNum);
00245 fiCalcedDataRate=1000.*fiDataDelta/deltamilsecs;;
00246 }
00247 else
00248 {
00249 fiDataDelta=0;
00250 fiCalcedDataRate=0;
00251 }
00252 fiLastDataNum=fxDaqStat.bl_n_kbyte;
00253
00254
00255 }
00256 else
00257 {
00258
00259 fiCalcedEventRate = fxDaqStat.bl_r_events;
00260 fiCalcedDataRate = fxDaqStat.bl_r_kbyte;
00261 }
00262
00263 if(fxDaqStat.bh_running[SYS__stream_serv])
00264 {
00265 fxServerLabel.sprintf("streamserver %d%s",
00266 (fxDaqStat.bl_strsrv_scale!=0 ? 100/fxDaqStat.bl_strsrv_scale : 0),"%");
00267 if(fbIsMonitoring)
00268 {
00269
00270 if(fiLastServDataNum && deltamilsecs)
00271 {
00272 fiServDataDelta=(fxDaqStat.bl_n_strserv_kbytes-fiLastServDataNum);
00273 fiCalcedServDataRate=1000.*fiServDataDelta/deltamilsecs;
00274 }
00275 else
00276 {
00277 fiServDataDelta=0;
00278 fiCalcedServDataRate=0;
00279 }
00280
00281
00282
00283
00284 fiLastServDataNum=fxDaqStat.bl_n_strserv_kbytes;
00285 }
00286 else
00287 {
00288
00289 fiCalcedServDataRate=fxDaqStat.bl_r_strserv_kbytes;
00290 fiDataDelta=0;
00291 }
00292
00293
00294 fiEvRatio= (fiDataDelta!=0 ? 100* fiServDataDelta /fiDataDelta : 0);
00295
00296 }
00297 else if(fxDaqStat.bh_running[SYS__event_serv])
00298 {
00299
00300
00301 fxServerLabel.sprintf("eventserver %s %d%s",
00302 (fxDaqStat.bh_event_serv_ready ? "R" : "S"),
00303 (fxDaqStat.bl_evtsrv_scale!=0 ? 100/fxDaqStat.bl_evtsrv_scale : 0),"%");
00304 if(fbIsMonitoring)
00305 {
00306
00307 if(fiLastServDataNum && deltamilsecs)
00308 {
00309 fiServDataDelta=(fxDaqStat.bl_n_evserv_kbytes-fiLastServDataNum);
00310 fiCalcedServDataRate=1000.0*fiServDataDelta/deltamilsecs;
00311 }
00312 else
00313 {
00314 fiServDataDelta=0;
00315 fiCalcedServDataRate=0;
00316 }
00317 fiLastServDataNum=fxDaqStat.bl_n_evserv_kbytes;
00318 }
00319 else
00320 {
00321
00322 fiCalcedServDataRate=fxDaqStat.bl_r_evserv_kbytes;
00323 fiDataDelta=0;
00324 }
00325
00326 fiEvRatio= (fiDataDelta!=0 ? 100* fiServDataDelta /fiDataDelta : 0);
00327
00328 }
00329 else
00330 {
00331 fxServerLabel="NO SERVER";
00332 fiEvRatio=0;
00333 }
00334
00335 if(fbTrending && !fbWarningState && fbIsMonitoring)
00336 {
00337 while((numperiods--) > 0)
00338 {
00339 UpdateTrending();
00340
00341 }
00342 }
00343 StartMovieReset();
00344 Display();
00345
00346 }
00347
00348
00349 void TGo4MBSViewer::NodeEditEnter()
00350 {
00351 Refresh();
00352 }
00353
00354
00355
00356 void TGo4MBSViewer::NodeChanged( const QString & txt )
00357 {
00358 fxNode=txt;
00359 fxNode.trimmed();
00360 }
00361
00362
00363
00364
00365 void TGo4MBSViewer::ShowStatus()
00366 {
00367 if(fbWarningState)
00368 {
00369 std::cout <<fxMessage.toLatin1().constData() << std::endl;
00370 }
00371 else
00372 {
00373 std::cout <<"\n------------------------------------------------" << std::endl;
00374 if(StateGroup->button(0)->isChecked())
00375 f_ut_seg_show (&fxDaqStat,0,0,0);
00376 if(fbGetSetup)
00377 f_ut_seg_show (0,&fxSetup,0,0);
00378 else if(fbGetSetML)
00379 f_ut_seg_show (0,0,&fxSetupML,0);
00380 else if(fbGetSetMO)
00381 f_ut_seg_show (0,0,0,&fxSetupMO);
00382 }
00383
00384 }
00385
00386 void TGo4MBSViewer::StateGroup_clicked( int id)
00387 {
00388
00389 fbGetSetup=StateGroup->button(1)->isChecked();
00390 fbGetSetML=StateGroup->button(2)->isChecked();
00391 fbGetSetMO=StateGroup->button(3)->isChecked();
00392
00393
00394
00395
00396
00397
00398 }
00399
00400
00401 void TGo4MBSViewer::PrintStatus()
00402 {
00403 if(fxNode.isEmpty()) return;
00404 if(fbGetSetup)
00405 {
00406
00407
00408 int state=f_mbs_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetup);
00409 if(state!=0)
00410 {
00411 fxMessage.sprintf("MBS Setup refresh returned error %d at ",state);
00412 fxMessage+=QDateTime::currentDateTime().toString();
00413 fbWarningState=true;
00414 }
00415 else
00416 fbWarningState=false;
00417 }
00418
00419 else if(fbGetSetML)
00420 {
00421
00422 int state=f_mbs_ml_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetupML);
00423 if(state!=0)
00424 {
00425 fxMessage.sprintf("MBS Setup ML refresh returned error %d at",state);
00426 fxMessage+=QDateTime::currentDateTime().toString();
00427 fbWarningState=true;
00428 }
00429 else
00430 fbWarningState=false;
00431 }
00432 else if(fbGetSetMO)
00433 {
00434
00435 int state=f_mbs_mo_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetupMO);
00436 if(state!=0)
00437 {
00438 fxMessage.sprintf("MBS Setup MO refresh returned error %d at",state);
00439 fxMessage+=QDateTime::currentDateTime().toString();
00440 fbWarningState=true;
00441 }
00442 else
00443 fbWarningState=false;
00444 }
00445
00446 else {}
00447 RefreshButtonClick();
00448 ShowStatus();
00449 }
00450
00451
00452 void TGo4MBSViewer::TrendSwitched( bool on )
00453 {
00454 if(!fbTrending) fbTrendingInit=true;
00455 fbTrending=on;
00456 go4sett->setMbsMonitorTrend(fbTrending);
00457 Display();
00458 }
00459
00460
00461 void TGo4MBSViewer::UpdateTrending()
00462 {
00463 TrendHisto(fxHistoAccessName,"MbsEventRate","Events/s",fiCalcedEventRate);
00464 TrendHisto(fxHistokBAccessName,"MbsDataRate","kB/s",fiCalcedDataRate);
00465 TrendHisto(fxHistoEvRatioAccessName,fxServerLabel.section(' ',0,0),"% Events served",fiEvRatio);
00466 fbTrendingInit=false;
00467 }
00468
00469
00470 void TGo4MBSViewer::IncTrending( TH1 * histo, int value, bool forwards )
00471 {
00472 if(histo==0) return;
00473 int bins=histo->GetNbinsX();
00474
00475 int j,dj;
00476 if(forwards)
00477 dj=-1;
00478 else
00479 dj=+1;
00480 for(int i=0;i<bins;i++)
00481 {
00482 if(forwards)
00483 j=bins-i;
00484 else
00485 j=i;
00486 int oldval=histo->GetBinContent(j+dj);
00487 histo->SetBinContent(j,oldval);
00488 }
00489 histo->SetBinContent(j+dj,value);
00490 }
00491
00492
00493 void TGo4MBSViewer::FrequencyBox_valueChanged( int )
00494 {
00495 fbTrendingInit=true;
00496 }
00497
00498
00499 TH1* TGo4MBSViewer::TrendHisto( QString & refname ,const QString & name, const QString & title, int value)
00500 {
00501 TH1* his=0;
00502 TGo4Slot* histoslot=0;
00503 if(!fbTrendingInit) histoslot=Browser()->BrowserSlot(refname.toLatin1());
00504 if(histoslot==0)
00505 {
00506 Axis_t lo,up;
00507 if(fbTrendingForward)
00508 {
00509 lo=0;
00510 up=1*fiTrendBins*FrequencyBox->value();
00511 }
00512 else
00513 {
00514 lo=-1*fiTrendBins*FrequencyBox->value();
00515 up=0;
00516 }
00517 his=new TH1F(name.toLatin1(), title.toLatin1() ,fiTrendBins,lo,up);
00518 TAxis* xax=his->GetXaxis();
00519 xax->SetTitle("s");
00520 xax->CenterTitle();
00521
00522
00523 TGo4Slot* hisdataslot=Browser()->DataSlot(refname.toLatin1());
00524 if(hisdataslot)
00525 {
00526 hisdataslot->AssignObject(his,true);
00527 }
00528 else
00529 {
00530 refname=Browser()->SaveToMemory("Mbs", his, true);
00531 }
00532 histoslot=Browser()->BrowserSlot(refname.toLatin1());
00533 }
00534 else
00535 {
00536 his=dynamic_cast<TH1*>(histoslot->GetAssignedObject());
00537 }
00538 IncTrending(his,value,fbTrendingForward);
00539 if(histoslot)
00540 {
00541 histoslot->ForwardEvent(histoslot, TGo4Slot::evObjUpdated);
00542 Browser()->SetItemTimeDate(histoslot);
00543 }
00544 return his;
00545 }
00546
00547
00548 void TGo4MBSViewer::MoreBox_toggled( bool on)
00549 {
00550 fbShowMore=on;
00551 go4sett->setMbsMonitorMore(fbShowMore);
00552 Display();
00553 }
00554
00555
00556 void TGo4MBSViewer::TrendBinsBox_valueChanged( int i)
00557 {
00558 fiTrendBins=i;
00559 fbTrendingInit=true;
00560 }
00561
00562
00563 void TGo4MBSViewer::RefreshButtonClick()
00564 {
00565 bool trend=fbTrending;
00566 bool monitoring=fbIsMonitoring;
00567 fbTrending=false;
00568 fbIsMonitoring=false;
00569 fbSingleRefresh=true;
00570 Refresh();
00571 fbSingleRefresh=false;
00572 fbIsMonitoring=monitoring;
00573 fbTrending=trend;
00574
00575 }
00576
00577
00578 void TGo4MBSViewer::SetNode( const QString & txt )
00579 {
00580 fxNode=txt;
00581 NodeEdit->setText(txt);
00582 }
00583
00584
00585 void TGo4MBSViewer::ResetRunIcon()
00586 {
00587 fbRunning=false;
00588 Display();
00589 }
00590
00591
00592 void TGo4MBSViewer::StartMovieReset()
00593 {
00594 if(!fbIsMonitoring) {
00595 fxMovieResetTimer->setSingleShot(true);
00596 fxMovieResetTimer->start(2000);
00597 }
00598 }