GSI Object Oriented Online Offline (Go4)  GO4-5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4MBSViewer.cpp
Go to the documentation of this file.
1 // $Id: TGo4MBSViewer.cpp 1142 2014-01-24 09:21:25Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4MBSViewer.h"
15 
16 #include "Riostream.h"
17 #include "TSystem.h"
18 #include "TH1.h"
19 
20 #include "TGo4Slot.h"
21 #include "TGo4BrowserProxy.h"
22 #include "TGo4QSettings.h"
23 #include "f_stccomm.h"
24 
25 #include <QTimer>
26 #include <QDateTime>
27 
28 TGo4MBSViewer::TGo4MBSViewer(QWidget *parent, const char* name) :
29  QGo4Widget(parent,name),
30  fxRunMovie(0)
31 {
32  setupUi(this);
33 
34 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
35  RateEvents->setDigitCount(7);
36  SumEvents->setDigitCount(12);
37  RateBytes->setDigitCount(7);
38  SumBytes->setDigitCount(8);
39  ServerPercent->setDigitCount(3);
40  SumBytesFile->setDigitCount(9);
41 #else
42  RateEvents->setNumDigits(7);
43  SumEvents->setNumDigits(12);
44  RateBytes->setNumDigits(7);
45  SumBytes->setNumDigits(8);
46  ServerPercent->setNumDigits(3);
47  SumBytesFile->setNumDigits(9);
48 #endif
49 
50  fbIsMonitoring=false;
51  fbWarningState=false;
52  fbRunning=false;
53  fbGetSetup=false;
54  fbGetSetML=false;
55  fbGetSetMO=false;
56  fbTrending=false;
57  fbTrendingInit=true;
58  fbShowMore=false;
59  fbSingleRefresh=false;
60  fbTrendingForward=false; // define moving direction of trend histograms
61  fiTrendBins=1000;
62  // now overwrite some settings:
65  TrendCheck->setChecked(fbTrending);
67  TrendBinsBox->setValue(fiTrendBins);
69  MoreBox->setChecked(fbShowMore);
70  FrequencyBox->setValue(go4sett->getMbsMonitorFreq());
72 
73  StateGroup = new QButtonGroup(this);
74  StateGroup->setExclusive(false);
75  StateGroup->addButton(StatusRadio, 0);
76  StateGroup->addButton(SetupRadio, 1);
77  StateGroup->addButton(SetupMLRadio, 2);
78  StateGroup->addButton(SetupMORadio, 3);
79  StateGroup->button(0)->setChecked(true);
80  connect(StateGroup, SIGNAL(buttonClicked(int)), this, SLOT(StateGroup_clicked(int)));
81 
82 
83  fxHistoAccessName = "nosuchobject";
84  fxHistokBAccessName = "nosuchobject";
85  fxHistoEvRatioAccessName = "nosuchobject";
86  fxServerLabel = "NO SERVER";
87  fxTimer = new QTimer(this);
88  fxMovieResetTimer = new QTimer(this);
89  QString moviepath = ":/icons/mbslogorun.gif";
90  fxRunMovie= new QMovie(moviepath);
91  memset(&fxDaqStat, 0, sizeof(fxDaqStat));
97  fiLastDataNum=0;
98  fxDeltaClock.start();
99  connect( fxTimer, SIGNAL(timeout()), this, SLOT(Refresh()) );
100  connect( fxMovieResetTimer, SIGNAL(timeout()), this, SLOT(ResetRunIcon()) );
101  Display();
102 
103 }
104 
106 {
107  delete fxRunMovie;
108 }
109 
110 
112 {
113  // save settings:
118  go4sett->setMbsMonitorFreq(FrequencyBox->value());
121 }
122 
123 
125 {
126  fbIsMonitoring=true;
127  fbTrendingInit=true;
128  fiLastEventNum=0;
129  fiLastDataNum=0;
131  Refresh();
132  fxTimer->start(1000*FrequencyBox->value());
133  Display();
134  StoreSettings();
135 }
136 
137 
139 {
140  fbIsMonitoring=false;
141  fxTimer->stop();
142  StartMovieReset();
143  Display();
144  StoreSettings();
145 }
146 
147 
149 {
150  setWindowTitle("MBS Status - "+NodeEdit->text());
151  if(!fbSingleRefresh)
152  {
153  NodeEdit->setEnabled(!fbIsMonitoring);
154  MonitorButton->setEnabled(!fbIsMonitoring);
155  StopButton->setEnabled(fbIsMonitoring);
156  FrequencyBox->setEnabled(!fbIsMonitoring);
157  //TrendCheck->setEnabled(!fbIsMonitoring);
158  TrendBinsBox->setEnabled(!fbTrending);
159  }
160  MoreFrame->setVisible(fbShowMore);
161  SumEvents->display((double) fxDaqStat.bl_n_events);
162  //RateEvents->display((double) fxDaqStat.bl_r_events);
163  RateEvents->display((double) fiCalcedEventRate);
164  SumBytes->display((double) ((unsigned int) fxDaqStat.bl_n_kbyte/1024));
165  //RateBytes->display((double) fxDaqStat.bl_r_kbyte);
166  RateBytes->display((double) fiCalcedDataRate);
167  DateLabel->setText(fxRefTime);
168  SumBytesFile->display((double) ((unsigned int) fxDaqStat.bl_n_kbyte_file/1024));
169 
171  OutfileLabel->setText(fxDaqStat.c_file_name);
172  else
173  OutfileLabel->setText("- file closed -") ;
174 
175  ServerLabel->setText(fxServerLabel) ;
176  ServerPercent->display((int) fiEvRatio);
177  if(fbRunning && !fbWarningState){
178  RunPix->clear();
179  RunPix->setMovie(fxRunMovie);
180  fxRunMovie->start();
181  }
182  else{
183  RunPix->setWindowIcon(QIcon( ":/icons/mbsbutton.png" ));
184  if(fxRunMovie) fxRunMovie->stop();
185  }
186  WarnPix->setVisible(fbWarningState);
187 
188  // put here enable/disable setup buttons:
189  SetupRadio->setEnabled(fxDaqStat.bh_setup_loaded);
190  SetupMLRadio->setEnabled(fxDaqStat.bh_set_ml_loaded);
191  SetupMORadio->setEnabled(fxDaqStat.bh_set_mo_loaded);
192  if(fbWarningState)
193  std::cerr <<fxMessage.toLatin1().constData() << std::endl;
194 
195  ensurePolished();
196  update();
197  show();
198 }
199 
200 
202 {
203  // for the ratemeter and running state, we always get status block
204  if(fxNode.isEmpty()) return;
205  int state=f_mbs_status(const_cast<char*>(fxNode.toLatin1().constData()), &fxDaqStat);
206  if(state!=STC__SUCCESS) {
207  fxMessage.sprintf("MBS Status refresh node %s returned error %d at ",
208  fxNode.toLatin1().constData(), state);
209  fxMessage += QDateTime::currentDateTime().toString();
210  fbWarningState = true;
211  } else
212  fbWarningState = false;
213  //fxRefTime=QDateTime::currentDateTime ().toString();
216  int deltat=FrequencyBox->value();
217  int numperiods=1;
218  int deltamilsecs=deltat*1000.0; // default
219  if(fbIsMonitoring)
220  {
221  // only in monitoring mode: calculate rates ourselves, independent of mbs ratemter:
222  // NEW: first check real time diff since last call and correct rates:
223  deltamilsecs=fxDeltaClock.elapsed();
224  //std::cout <<"******* found ms:"<<deltamilsecs << std::endl;
225  fxDeltaClock.restart();
226  int deltasecs=deltamilsecs/1000;
227  if(!fbTrendingInit && (deltasecs>=deltat*2))
228  //if((deltasecs>=deltat*2)) // this one was for testing JAM
229  {
230  std::cout <<"Warning: MBS monitor found measuring interval:"<<deltasecs<<" s ("<<deltamilsecs <<" ms) exceeding timer period "<<deltat<<" s" << std::endl;
231  std::cout <<" Maybe timer was skipped?" << std::endl;
232  deltat=deltasecs;
233  numperiods=(deltat/ (int) FrequencyBox->value());
234  std::cout <<" Correcting number of measuring periods to:"<<numperiods << std::endl;
235  }
236  if(fiLastEventNum && deltamilsecs)
238  else
241 
242  if(fiLastDataNum && deltamilsecs)
243  {
245  fiCalcedDataRate=1000.*fiDataDelta/deltamilsecs;;
246  }
247  else
248  {
249  fiDataDelta=0;
251  }
253  // std::cout <<"Data rate:"<<fiCalcedDataRate << std::endl;
254  // std::cout <<"Data total:"<<fiLastDataNum << std::endl;
255  }
256  else
257  {
258  // single refresh on button press: use momentary mbs rate
261  }
262 
264  {
265  fxServerLabel.sprintf("streamserver %d%s",
267  if(fbIsMonitoring)
268  {
269  // own rate calculation for monitoring on:
270  if(fiLastServDataNum && deltamilsecs)
271  {
273  fiCalcedServDataRate=1000.*fiServDataDelta/deltamilsecs;
274  }
275  else
276  {
277  fiServDataDelta=0;
279  }
280  // std::cout <<"Streamserver rate:"<<fiCalcedServDataRate << std::endl;
281  // std::cout <<"Streamserver data:"<<fxDaqStat.bl_n_strserv_kbytes << std::endl;
282  // std::cout <<"Streamserver last data:"<<fiLastServDataNum << std::endl;
283  // std::cout <<"dt:"<<deltat << std::endl;
285  }
286  else
287  {
288  // single refresh: use ratio from current mbs calculated rates
290  fiDataDelta=0;
291  }
292  //fiEvRatio= (fiCalcedDataRate!=0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
293  //int curentratio=(fiCalcedDataRate!=0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
295  //std::cout<<"Eventratio="<<fiEvRatio<<" , currentratio="<<curentratio<< std::endl;
296  }
298  {
299  // calculate momentary rate for eventserver:
300 
301  fxServerLabel.sprintf("eventserver %s %d%s",
302  (fxDaqStat.bh_event_serv_ready ? "R" : "S"),
304  if(fbIsMonitoring)
305  {
306  // own rate calculation for monitoring on:
307  if(fiLastServDataNum && deltamilsecs)
308  {
310  fiCalcedServDataRate=1000.0*fiServDataDelta/deltamilsecs;
311  }
312  else
313  {
314  fiServDataDelta=0;
316  }
318  }
319  else
320  {
321  // single refresh: use ratio from current mbs calculated rates
323  fiDataDelta=0;
324  }
325  //fiEvRatio= (fiCalcedDataRate!=0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
327 
328  }
329  else
330  {
331  fxServerLabel="NO SERVER";
332  fiEvRatio=0;
333  }
334 
336  {
337  while((numperiods--) > 0)
338  {
339  UpdateTrending(); // use same values for all skipped periods
340  //std::cout <<"Update trending with numperiods:"<<numperiods << std::endl;
341  }
342  }
343  StartMovieReset();
344  Display();
345  //f_ut_seg_show (&fxDaqStat,0,0,0);
346 }
347 
348 
350 {
351  Refresh();
352 }
353 
354 
355 
356 void TGo4MBSViewer::NodeChanged( const QString & txt )
357 {
358  fxNode=txt;
359  fxNode.trimmed();
360 }
361 
362 
363 
364 
366 {
367  if(fbWarningState)
368  {
369  std::cout <<fxMessage.toLatin1().constData() << std::endl;
370  }
371  else
372  {
373  std::cout <<"\n------------------------------------------------" << std::endl;
374  if(StateGroup->button(0)->isChecked())
375  f_ut_seg_show (&fxDaqStat,0,0,0);
376  if(fbGetSetup)
377  f_ut_seg_show (0,&fxSetup,0,0);
378  else if(fbGetSetML)
379  f_ut_seg_show (0,0,&fxSetupML,0);
380  else if(fbGetSetMO)
381  f_ut_seg_show (0,0,0,&fxSetupMO);
382  }
383 
384 }
385 
387 {
388  // only one of these can be enabled
389  fbGetSetup=StateGroup->button(1)->isChecked();
390  fbGetSetML=StateGroup->button(2)->isChecked();
391  fbGetSetMO=StateGroup->button(3)->isChecked();
392  // if status is wanted, do not print setups:
393  // if(fbGetSetup=StateGroup->button(0)->isChecked()){
394  // fbGetSetup=false;
395  // fbGetSetML=false;
396  // fbGetSetMO=false;
397  // }
398 }
399 
400 
402 {
403  if(fxNode.isEmpty()) return;
404  if(fbGetSetup)
405  {
406  // request setup if selected
407 
408  int state=f_mbs_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetup);
409  if(state!=0)
410  {
411  fxMessage.sprintf("MBS Setup refresh returned error %d at ",state);
412  fxMessage+=QDateTime::currentDateTime().toString();
413  fbWarningState=true;
414  }
415  else
416  fbWarningState=false;
417  }
418 
419  else if(fbGetSetML)
420  {
421  // request setup multilayer if selected
422  int state=f_mbs_ml_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetupML);
423  if(state!=0)
424  {
425  fxMessage.sprintf("MBS Setup ML refresh returned error %d at",state);
426  fxMessage+=QDateTime::currentDateTime().toString();
427  fbWarningState=true;
428  }
429  else
430  fbWarningState=false;
431  }
432  else if(fbGetSetMO)
433  {
434  // request setup MO if selected
435  int state=f_mbs_mo_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetupMO);
436  if(state!=0)
437  {
438  fxMessage.sprintf("MBS Setup MO refresh returned error %d at",state);
439  fxMessage+=QDateTime::currentDateTime().toString();
440  fbWarningState=true;
441  }
442  else
443  fbWarningState=false;
444  }
445 
446  else {}
447  RefreshButtonClick(); // always get new status structure and display on window
448  ShowStatus();
449 }
450 
451 
453 {
454  if(!fbTrending) fbTrendingInit=true;
455  fbTrending=on;
457  Display();
458 }
459 
460 
462 {
463  TrendHisto(fxHistoAccessName,"MbsEventRate","Events/s",fiCalcedEventRate);
464  TrendHisto(fxHistokBAccessName,"MbsDataRate","kB/s",fiCalcedDataRate);
465  TrendHisto(fxHistoEvRatioAccessName,fxServerLabel.section(' ',0,0),"% Events served",fiEvRatio);
466  fbTrendingInit=false;
467 }
468 
469 
470 void TGo4MBSViewer::IncTrending( TH1 * histo, int value, bool forwards )
471 {
472  if(histo==0) return;
473  int bins=histo->GetNbinsX();
474  //bool forwards=true;
475  int j,dj;
476  if(forwards)
477  dj=-1;
478  else
479  dj=+1;
480  for(int i=0;i<bins;i++)
481  {
482  if(forwards)
483  j=bins-i;
484  else
485  j=i;
486  int oldval=histo->GetBinContent(j+dj);
487  histo->SetBinContent(j,oldval);
488  }
489  histo->SetBinContent(j+dj,value);
490 }
491 
492 
494 {
495  fbTrendingInit=true;
496 }
497 
498 
499 TH1* TGo4MBSViewer::TrendHisto( QString & refname ,const QString & name, const QString & title, int value)
500 {
501  TH1* his=0;
502  TGo4Slot* histoslot=0;
503  if(!fbTrendingInit) histoslot=Browser()->BrowserSlot(refname.toLatin1());
504  if(histoslot==0)
505  {
506  Axis_t lo,up;
508  {
509  lo=0;
510  up=1*fiTrendBins*FrequencyBox->value();
511  }
512  else
513  {
514  lo=-1*fiTrendBins*FrequencyBox->value();
515  up=0;
516  }
517  his=new TH1F(name.toLatin1(), title.toLatin1() ,fiTrendBins,lo,up);
518  TAxis* xax=his->GetXaxis();
519  xax->SetTitle("s");
520  xax->CenterTitle();
521  //xax->SetLimits(0,lo,up);
522 
523  TGo4Slot* hisdataslot=Browser()->DataSlot(refname.toLatin1());
524  if(hisdataslot)
525  {
526  hisdataslot->AssignObject(his,true);
527  }
528  else
529  {
530  refname=Browser()->SaveToMemory("Mbs", his, true);
531  }
532  histoslot=Browser()->BrowserSlot(refname.toLatin1());
533  }
534  else
535  {
536  his=dynamic_cast<TH1*>(histoslot->GetAssignedObject());
537  }
538  IncTrending(his,value,fbTrendingForward);
539  if(histoslot)
540  {
541  histoslot->ForwardEvent(histoslot, TGo4Slot::evObjUpdated);
542  Browser()->SetItemTimeDate(histoslot);
543  }
544  return his;
545 }
546 
547 
549 {
550  fbShowMore=on;
552  Display();
553 }
554 
555 
557 {
558  fiTrendBins=i;
559  fbTrendingInit=true;
560 }
561 
562 
564 {
565  bool trend=fbTrending;
566  bool monitoring=fbIsMonitoring;
567  fbTrending=false; // avoid to put direct refresh into the trending histogram
568  fbIsMonitoring=false; // avoid confuse rate calculations
569  fbSingleRefresh=true; // avoid changing state of control buttons
570  Refresh();
571  fbSingleRefresh=false;
572  fbIsMonitoring=monitoring;
573  fbTrending=trend;
574 
575 }
576 
577 
578 void TGo4MBSViewer::SetNode( const QString & txt )
579 {
580  fxNode=txt;
581  NodeEdit->setText(txt);
582 }
583 
584 
586 {
587  fbRunning=false;
588  Display();
589 }
590 
591 
593 {
594  if(!fbIsMonitoring) {
595  fxMovieResetTimer->setSingleShot(true);
596  fxMovieResetTimer->start(2000);
597  }
598 }
int fiCalcedServDataRate
QString fxHistoEvRatioAccessName
INTU4 bl_r_events
Definition: s_daqst.h:48
virtual void StateGroup_clicked(int id)
QMovie * fxRunMovie
virtual void TimerStop()
QTimer * fxTimer
TString SaveToMemory(const char *pathname, TObject *obj, Bool_t ownership, Bool_t overwrite=kFALSE)
void setMbsMonitorMonitorActive(bool on=true)
void setMbsMonitorTrend(bool on=true)
QString fxServerLabel
INTU4 bl_r_kbyte
Definition: s_daqst.h:51
#define SYS__stream_serv
Definition: sys_def.h:35
INTU4 bl_evtsrv_scale
Definition: s_daqst.h:107
virtual void MoreBox_toggled(bool on)
virtual void StartMovieReset()
INTU4 bl_strsrv_scale
Definition: s_daqst.h:101
virtual void Display()
#define SYS__event_serv
Definition: sys_def.h:28
INTU4 bh_set_ml_loaded
Definition: s_daqst.h:34
INTU4 bl_n_kbyte
Definition: s_daqst.h:41
virtual void PrintStatus()
INTU4 bl_n_kbyte_file
Definition: s_daqst.h:47
virtual void TrendSwitched(bool on)
TH1 * TrendHisto(QString &refname, const QString &name, const QString &title, int value)
INTS4 f_mbs_status(CHARS *c_node, s_daqst *ps_daqst)
Definition: f_mbs_status.c:55
QString fxHistoAccessName
QString fxMessage
virtual void StoreSettings()
virtual void FrequencyBox_valueChanged(int)
INTS4 f_mbs_mo_setup(CHARS *c_node, s_set_mo *ps_set_mo)
Definition: f_mbs_status.c:175
virtual void TrendBinsBox_valueChanged(int i)
INTU4 bh_setup_loaded
Definition: s_daqst.h:33
bool fbTrendingForward
TGo4BrowserProxy * Browser()
Definition: QGo4Widget.cpp:223
QButtonGroup * StateGroup
#define STC__SUCCESS
Definition: f_stccomm.h:364
INTU4 bl_n_strserv_kbytes
Definition: s_daqst.h:45
INTU4 bh_acqui_running
Definition: s_daqst.h:31
INTU4 bl_n_events
Definition: s_daqst.h:38
TGo4Slot * DataSlot(const char *item)
virtual void UpdateTrending()
s_set_mo fxSetupMO
TObject * GetAssignedObject()
Definition: TGo4Slot.cxx:373
INTS4 f_mbs_ml_setup(CHARS *c_node, s_set_ml *ps_set_ml)
Definition: f_mbs_status.c:132
virtual void IncTrending(TH1 *histo, int value, bool forwards)
virtual void SetNode(const QString &txt)
INTU4 bh_event_serv_ready
Definition: s_daqst.h:100
INTS4 f_mbs_setup(CHARS *c_node, s_setup *ps_setup)
Definition: f_mbs_status.c:87
virtual void RefreshButtonClick()
bool getMbsMonitorTrend()
bool getMbsMonitorMore()
INTU4 bl_r_strserv_kbytes
Definition: s_daqst.h:56
virtual void Refresh()
void setMbsMonitorNode(const QString &name)
TGo4QSettings * go4sett
QString fxHistokBAccessName
TGo4MBSViewer(QWidget *parent=0, const char *name=0)
virtual void NodeEditEnter()
TGo4Slot * BrowserSlot(const char *item)
INTS4 l_open_file
Definition: s_daqst.h:70
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)
Definition: f_ut_seg_show.c:51
s_set_ml fxSetupML
bool getMbsMonitorBackwardsTrending()
CHARS c_date[SBS__STR_LEN_64]
Definition: s_daqst.h:128
INTU4 bh_set_mo_loaded
Definition: s_daqst.h:35
QString getMbsMonitorNode()
virtual ~TGo4MBSViewer()
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=0)
Definition: TGo4Slot.cxx:585
virtual void ResetRunIcon()
s_daqst fxDaqStat
Bool_t AssignObject(TObject *obj, Bool_t owner)
Definition: TGo4Slot.cxx:361
QTimer * fxMovieResetTimer
void setMbsMonitorBins(int num)
INTU4 bh_running[SYS__N_MAX_PROCS]
Definition: s_daqst.h:83
void setMbsMonitorBackwardsTrending(bool on=true)
INTU4 bl_r_evserv_kbytes
Definition: s_daqst.h:54
virtual void NodeChanged(const QString &txt)
virtual void TimerStart()
void setMbsMonitorFreq(int secs)
static void SetItemTimeDate(TGo4Slot *slot, const char *stime=0, const char *sdate=0)
void setMbsMonitorMore(bool on=true)
INTU4 bl_n_evserv_kbytes
Definition: s_daqst.h:43
CHARS c_file_name[256]
Definition: s_daqst.h:142
virtual void ShowStatus()
QString fxRefTime