GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4MBSViewer.cpp
Go to the documentation of this file.
1 // $Id: TGo4MBSViewer.cpp 2118 2018-06-28 14:30:37Z 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 #include <QButtonGroup>
28 
29 TGo4MBSViewer::TGo4MBSViewer(QWidget *parent, const char* name) :
30  QGo4Widget(parent,name),
31  fxRunMovie(0)
32 {
33  setupUi(this);
34 
35 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
36  RateEvents->setDigitCount(7);
37  SumEvents->setDigitCount(12);
38  RateBytes->setDigitCount(7);
39  SumBytes->setDigitCount(8);
40  ServerPercent->setDigitCount(3);
41  SumBytesFile->setDigitCount(9);
42 #else
43  RateEvents->setNumDigits(7);
44  SumEvents->setNumDigits(12);
45  RateBytes->setNumDigits(7);
46  SumBytes->setNumDigits(8);
47  ServerPercent->setNumDigits(3);
48  SumBytesFile->setNumDigits(9);
49 #endif
50 
51  fbIsMonitoring=false;
52  fbWarningState=false;
53  fbRunning=false;
54  fbGetSetup=false;
55  fbGetSetML=false;
56  fbGetSetMO=false;
57  fbTrending=false;
58  fbTrendingInit=true;
59  fbShowMore=false;
60  fbSingleRefresh=false;
61  fbTrendingForward=false; // define moving direction of trend histograms
62  fiTrendBins=1000;
63  // now overwrite some settings:
66  TrendCheck->setChecked(fbTrending);
68  TrendBinsBox->setValue(fiTrendBins);
70  MoreBox->setChecked(fbShowMore);
71  FrequencyBox->setValue(go4sett->getMbsMonitorFreq());
73 
74  StateGroup = new QButtonGroup(this);
75  StateGroup->setExclusive(false);
76  StateGroup->addButton(StatusRadio, 0);
77  StateGroup->addButton(SetupRadio, 1);
78  StateGroup->addButton(SetupMLRadio, 2);
79  StateGroup->addButton(SetupMORadio, 3);
80  StateGroup->button(0)->setChecked(true);
81  connect(StateGroup, SIGNAL(buttonClicked(int)), this, SLOT(StateGroup_clicked(int)));
82 
83 
84  fxHistoAccessName = "nosuchobject";
85  fxHistokBAccessName = "nosuchobject";
86  fxHistoEvRatioAccessName = "nosuchobject";
87  fxServerLabel = "NO SERVER";
88  fxTimer = new QTimer(this);
89  fxMovieResetTimer = new QTimer(this);
90  QString moviepath = ":/icons/mbslogorun.gif";
91  fxRunMovie= new QMovie(moviepath);
92  memset(&fxDaqStat, 0, sizeof(fxDaqStat));
98  fiLastDataNum=0;
99  fxDeltaClock.start();
100  connect( fxTimer, SIGNAL(timeout()), this, SLOT(Refresh()) );
101  connect( fxMovieResetTimer, SIGNAL(timeout()), this, SLOT(ResetRunIcon()) );
102  Display();
103 
104 }
105 
107 {
108  delete fxRunMovie;
109 }
110 
111 
113 {
114  // save settings:
119  go4sett->setMbsMonitorFreq(FrequencyBox->value());
122 }
123 
124 
126 {
127  fbIsMonitoring=true;
128  fbTrendingInit=true;
129  fiLastEventNum=0;
130  fiLastDataNum=0;
132  Refresh();
133  fxTimer->start(1000*FrequencyBox->value());
134  Display();
135  StoreSettings();
136 }
137 
138 
140 {
141  fbIsMonitoring=false;
142  fxTimer->stop();
143  StartMovieReset();
144  Display();
145  StoreSettings();
146 }
147 
148 
150 {
151  setWindowTitle("MBS Status - "+NodeEdit->text());
152  if(!fbSingleRefresh)
153  {
154  NodeEdit->setEnabled(!fbIsMonitoring);
155  MonitorButton->setEnabled(!fbIsMonitoring);
156  StopButton->setEnabled(fbIsMonitoring);
157  FrequencyBox->setEnabled(!fbIsMonitoring);
158  //TrendCheck->setEnabled(!fbIsMonitoring);
159  TrendBinsBox->setEnabled(!fbTrending);
160  }
161  MoreFrame->setVisible(fbShowMore);
162  SumEvents->display((double) fxDaqStat.bl_n_events);
163  //RateEvents->display((double) fxDaqStat.bl_r_events);
164  RateEvents->display((double) fiCalcedEventRate);
165  SumBytes->display((double) ((unsigned int) fxDaqStat.bl_n_kbyte/1024));
166  //RateBytes->display((double) fxDaqStat.bl_r_kbyte);
167  RateBytes->display((double) fiCalcedDataRate);
168  DateLabel->setText(fxRefTime);
169  SumBytesFile->display((double) ((unsigned int) fxDaqStat.bl_n_kbyte_file/1024));
170 
172  OutfileLabel->setText(fxDaqStat.c_file_name);
173  else
174  OutfileLabel->setText("- file closed -") ;
175 
176  ServerLabel->setText(fxServerLabel) ;
177  ServerPercent->display((int) fiEvRatio);
178  if(fbRunning && !fbWarningState){
179  RunPix->clear();
180  RunPix->setMovie(fxRunMovie);
181  fxRunMovie->start();
182  }
183  else{
184  RunPix->setWindowIcon(QIcon( ":/icons/mbsbutton.png" ));
185  if(fxRunMovie) fxRunMovie->stop();
186  }
187  WarnPix->setVisible(fbWarningState);
188 
189  // put here enable/disable setup buttons:
190  SetupRadio->setEnabled(fxDaqStat.bh_setup_loaded);
191  SetupMLRadio->setEnabled(fxDaqStat.bh_set_ml_loaded);
192  SetupMORadio->setEnabled(fxDaqStat.bh_set_mo_loaded);
193  if(fbWarningState)
194  std::cerr <<fxMessage.toLatin1().constData() << std::endl;
195 
196  ensurePolished();
197  update();
198  show();
199 }
200 
201 
203 {
204  // for the ratemeter and running state, we always get status block
205  if(fxNode.isEmpty()) return;
206  int state=f_mbs_status(const_cast<char*>(fxNode.toLatin1().constData()), &fxDaqStat);
207  if(state!=STC__SUCCESS) {
208  fxMessage.sprintf("MBS Status refresh node %s returned error %d at ",
209  fxNode.toLatin1().constData(), state);
210  fxMessage += QDateTime::currentDateTime().toString();
211  fbWarningState = true;
212  } else
213  fbWarningState = false;
214  //fxRefTime=QDateTime::currentDateTime ().toString();
217  int deltat=FrequencyBox->value();
218  int numperiods=1;
219  int deltamilsecs=deltat*1000.0; // default
220  if(fbIsMonitoring)
221  {
222  // only in monitoring mode: calculate rates ourselves, independent of mbs ratemter:
223  // NEW: first check real time diff since last call and correct rates:
224  deltamilsecs=fxDeltaClock.elapsed();
225  //std::cout <<"******* found ms:"<<deltamilsecs << std::endl;
226  fxDeltaClock.restart();
227  int deltasecs=deltamilsecs/1000;
228  if(!fbTrendingInit && (deltasecs>=deltat*2))
229  //if((deltasecs>=deltat*2)) // this one was for testing JAM
230  {
231  std::cout <<"Warning: MBS monitor found measuring interval:"<<deltasecs<<" s ("<<deltamilsecs <<" ms) exceeding timer period "<<deltat<<" s" << std::endl;
232  std::cout <<" Maybe timer was skipped?" << std::endl;
233  deltat=deltasecs;
234  numperiods=(deltat/ (int) FrequencyBox->value());
235  std::cout <<" Correcting number of measuring periods to:"<<numperiods << std::endl;
236  }
237  if(fiLastEventNum && deltamilsecs)
239  else
242 
243  if(fiLastDataNum && deltamilsecs)
244  {
246  fiCalcedDataRate=1000.*fiDataDelta/deltamilsecs;;
247  }
248  else
249  {
250  fiDataDelta=0;
252  }
254  // std::cout <<"Data rate:"<<fiCalcedDataRate << std::endl;
255  // std::cout <<"Data total:"<<fiLastDataNum << std::endl;
256  }
257  else
258  {
259  // single refresh on button press: use momentary mbs rate
262  }
263 
265  {
266  fxServerLabel.sprintf("streamserver %d%s",
268  if(fbIsMonitoring)
269  {
270  // own rate calculation for monitoring on:
271  if(fiLastServDataNum && deltamilsecs)
272  {
274  fiCalcedServDataRate=1000.*fiServDataDelta/deltamilsecs;
275  }
276  else
277  {
278  fiServDataDelta=0;
280  }
281  // std::cout <<"Streamserver rate:"<<fiCalcedServDataRate << std::endl;
282  // std::cout <<"Streamserver data:"<<fxDaqStat.bl_n_strserv_kbytes << std::endl;
283  // std::cout <<"Streamserver last data:"<<fiLastServDataNum << std::endl;
284  // std::cout <<"dt:"<<deltat << std::endl;
286  }
287  else
288  {
289  // single refresh: use ratio from current mbs calculated rates
291  fiDataDelta=0;
292  }
293  //fiEvRatio= (fiCalcedDataRate!=0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
294  //int curentratio=(fiCalcedDataRate!=0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
296  //std::cout<<"Eventratio="<<fiEvRatio<<" , currentratio="<<curentratio<< std::endl;
297  }
299  {
300  // calculate momentary rate for eventserver:
301 
302  fxServerLabel.sprintf("eventserver %s %d%s",
303  (fxDaqStat.bh_event_serv_ready ? "R" : "S"),
305  if(fbIsMonitoring)
306  {
307  // own rate calculation for monitoring on:
308  if(fiLastServDataNum && deltamilsecs)
309  {
311  fiCalcedServDataRate=1000.0*fiServDataDelta/deltamilsecs;
312  }
313  else
314  {
315  fiServDataDelta=0;
317  }
319  }
320  else
321  {
322  // single refresh: use ratio from current mbs calculated rates
324  fiDataDelta=0;
325  }
326  //fiEvRatio= (fiCalcedDataRate!=0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
328 
329  }
330  else
331  {
332  fxServerLabel="NO SERVER";
333  fiEvRatio=0;
334  }
335 
337  {
338  while((numperiods--) > 0)
339  {
340  UpdateTrending(); // use same values for all skipped periods
341  //std::cout <<"Update trending with numperiods:"<<numperiods << std::endl;
342  }
343  }
344  StartMovieReset();
345  Display();
346  //f_ut_seg_show (&fxDaqStat,0,0,0);
347 }
348 
349 
351 {
352  Refresh();
353 }
354 
355 
356 
357 void TGo4MBSViewer::NodeChanged( const QString & txt )
358 {
359  fxNode=txt;
360  fxNode.trimmed();
361 }
362 
363 
364 
365 
367 {
368  if(fbWarningState)
369  {
370  std::cout <<fxMessage.toLatin1().constData() << std::endl;
371  }
372  else
373  {
374  std::cout <<"\n------------------------------------------------" << std::endl;
375  if(StateGroup->button(0)->isChecked())
376  f_ut_seg_show (&fxDaqStat,0,0,0);
377  if(fbGetSetup)
378  f_ut_seg_show (0,&fxSetup,0,0);
379  else if(fbGetSetML)
380  f_ut_seg_show (0,0,&fxSetupML,0);
381  else if(fbGetSetMO)
382  f_ut_seg_show (0,0,0,&fxSetupMO);
383  }
384 
385 }
386 
388 {
389  // only one of these can be enabled
390  fbGetSetup=StateGroup->button(1)->isChecked();
391  fbGetSetML=StateGroup->button(2)->isChecked();
392  fbGetSetMO=StateGroup->button(3)->isChecked();
393  // if status is wanted, do not print setups:
394  // if(fbGetSetup=StateGroup->button(0)->isChecked()){
395  // fbGetSetup=false;
396  // fbGetSetML=false;
397  // fbGetSetMO=false;
398  // }
399 }
400 
401 
403 {
404  if(fxNode.isEmpty()) return;
405  if(fbGetSetup)
406  {
407  // request setup if selected
408 
409  int state=f_mbs_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetup);
410  if(state!=0)
411  {
412  fxMessage.sprintf("MBS Setup refresh returned error %d at ",state);
413  fxMessage+=QDateTime::currentDateTime().toString();
414  fbWarningState=true;
415  }
416  else
417  fbWarningState=false;
418  }
419 
420  else if(fbGetSetML)
421  {
422  // request setup multilayer if selected
423  int state=f_mbs_ml_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetupML);
424  if(state!=0)
425  {
426  fxMessage.sprintf("MBS Setup ML refresh returned error %d at",state);
427  fxMessage+=QDateTime::currentDateTime().toString();
428  fbWarningState=true;
429  }
430  else
431  fbWarningState=false;
432  }
433  else if(fbGetSetMO)
434  {
435  // request setup MO if selected
436  int state=f_mbs_mo_setup(const_cast<char*>(fxNode.toLatin1().constData()), &fxSetupMO);
437  if(state!=0)
438  {
439  fxMessage.sprintf("MBS Setup MO refresh returned error %d at",state);
440  fxMessage+=QDateTime::currentDateTime().toString();
441  fbWarningState=true;
442  }
443  else
444  fbWarningState=false;
445  }
446 
447  else {}
448  RefreshButtonClick(); // always get new status structure and display on window
449  ShowStatus();
450 }
451 
452 
454 {
455  if(!fbTrending) fbTrendingInit=true;
456  fbTrending=on;
458  Display();
459 }
460 
461 
463 {
464  TrendHisto(fxHistoAccessName,"MbsEventRate","Events/s",fiCalcedEventRate);
465  TrendHisto(fxHistokBAccessName,"MbsDataRate","kB/s",fiCalcedDataRate);
466  TrendHisto(fxHistoEvRatioAccessName,fxServerLabel.section(' ',0,0),"% Events served",fiEvRatio);
467  fbTrendingInit=false;
468 }
469 
470 
471 void TGo4MBSViewer::IncTrending( TH1 * histo, int value, bool forwards )
472 {
473  if(histo==0) return;
474  int bins=histo->GetNbinsX();
475  //bool forwards=true;
476  int j,dj;
477  if(forwards)
478  dj=-1;
479  else
480  dj=+1;
481  for(int i=0;i<bins;i++)
482  {
483  if(forwards)
484  j=bins-i;
485  else
486  j=i;
487  int oldval=histo->GetBinContent(j+dj);
488  histo->SetBinContent(j,oldval);
489  }
490  histo->SetBinContent(j+dj,value);
491 }
492 
493 
495 {
496  fbTrendingInit=true;
497 }
498 
499 
500 TH1* TGo4MBSViewer::TrendHisto( QString & refname ,const QString & name, const QString & title, int value)
501 {
502  TH1* his=0;
503  TGo4Slot* histoslot=0;
504  if(!fbTrendingInit) histoslot=Browser()->BrowserSlot(refname.toLatin1());
505  if(histoslot==0)
506  {
507  Axis_t lo,up;
509  {
510  lo=0;
511  up=1*fiTrendBins*FrequencyBox->value();
512  }
513  else
514  {
515  lo=-1*fiTrendBins*FrequencyBox->value();
516  up=0;
517  }
518  his=new TH1F(name.toLatin1(), title.toLatin1() ,fiTrendBins,lo,up);
519  TAxis* xax=his->GetXaxis();
520  xax->SetTitle("s");
521  xax->CenterTitle();
522  //xax->SetLimits(0,lo,up);
523 
524  TGo4Slot* hisdataslot=Browser()->DataSlot(refname.toLatin1());
525  if(hisdataslot)
526  {
527  hisdataslot->AssignObject(his,true);
528  }
529  else
530  {
531  refname=Browser()->SaveToMemory("Mbs", his, true);
532  }
533  histoslot=Browser()->BrowserSlot(refname.toLatin1());
534  }
535  else
536  {
537  his=dynamic_cast<TH1*>(histoslot->GetAssignedObject());
538  }
539  IncTrending(his,value,fbTrendingForward);
540  if(histoslot)
541  {
542  histoslot->ForwardEvent(histoslot, TGo4Slot::evObjUpdated);
543  Browser()->SetItemTimeDate(histoslot);
544  }
545  return his;
546 }
547 
548 
550 {
551  fbShowMore=on;
553  Display();
554 }
555 
556 
558 {
559  fiTrendBins=i;
560  fbTrendingInit=true;
561 }
562 
563 
565 {
566  bool trend=fbTrending;
567  bool monitoring=fbIsMonitoring;
568  fbTrending=false; // avoid to put direct refresh into the trending histogram
569  fbIsMonitoring=false; // avoid confuse rate calculations
570  fbSingleRefresh=true; // avoid changing state of control buttons
571  Refresh();
572  fbSingleRefresh=false;
573  fbIsMonitoring=monitoring;
574  fbTrending=trend;
575 
576 }
577 
578 
579 void TGo4MBSViewer::SetNode( const QString & txt )
580 {
581  fxNode=txt;
582  NodeEdit->setText(txt);
583 }
584 
585 
587 {
588  fbRunning=false;
589  Display();
590 }
591 
592 
594 {
595  if(!fbIsMonitoring) {
596  fxMovieResetTimer->setSingleShot(true);
597  fxMovieResetTimer->start(2000);
598  }
599 }
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