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