GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4MBSViewer.cpp
Go to the documentation of this file.
1// $Id$
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 fuer 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 <iostream>
17
18#include "TH1.h"
19
20#include "TGo4Slot.h"
21#include "TGo4BrowserProxy.h"
22#include "TGo4QSettings.h"
23
24#include <QTimer>
25#include <QDateTime>
26#include <QButtonGroup>
27#include <QMovie>
28
29extern "C"
30{
31 #include "f_stccomm.h"
32 #include "f_mbs_status.h"
33 #include "f_ut_seg_show.h"
34}
35
36
37TGo4MBSViewer::TGo4MBSViewer(QWidget *parent, const char *name) :
38 QGo4Widget(parent,name),
39 fxRunMovie(nullptr)
40{
41 setupUi(this);
42
43 QObject::connect(FullPrintButton, &QPushButton::clicked, this, &TGo4MBSViewer::PrintState);
44 QObject::connect(MonitorButton, &QPushButton::clicked, this, &TGo4MBSViewer::TimerStart);
45 QObject::connect(StopButton, &QPushButton::clicked, this, &TGo4MBSViewer::TimerStop);
46 QObject::connect(RefreshButton, &QPushButton::clicked, this, &TGo4MBSViewer::RefreshButtonClick);
47 QObject::connect(NodeEdit, &QGo4LineEdit::returnPressed, this, &TGo4MBSViewer::NodeEditEnter);
48 QObject::connect(NodeEdit, &QGo4LineEdit::textChanged, this, &TGo4MBSViewer::NodeChanged);
49 QObject::connect(TrendCheck, &QCheckBox::toggled, this, &TGo4MBSViewer::TrendSwitched);
50 QObject::connect(FrequencyBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &TGo4MBSViewer::FrequencyBox_valueChanged);
51 QObject::connect(MoreBox, &QCheckBox::toggled, this, &TGo4MBSViewer::MoreBox_toggled);
52 QObject::connect(TrendBinsBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &TGo4MBSViewer::TrendBinsBox_valueChanged);
53
54 // new JAM22:
55 QObject::connect(StatusRadio, &QRadioButton::clicked, this, &TGo4MBSViewer::StateGroup_clicked);
56 QObject::connect(SetupRadio, &QRadioButton::clicked, this, &TGo4MBSViewer::StateGroup_clicked);
57 QObject::connect(SetupMLRadio, &QRadioButton::clicked, this, &TGo4MBSViewer::StateGroup_clicked);
58 QObject::connect(SetupMORadio, &QRadioButton::clicked, this, &TGo4MBSViewer::StateGroup_clicked);
59
60 RateEvents->setDigitCount(7);
61 SumEvents->setDigitCount(12);
62 RateBytes->setDigitCount(7);
63 SumBytes->setDigitCount(8);
64 ServerPercent->setDigitCount(3);
65 SumBytesFile->setDigitCount(9);
66
67 fbIsMonitoring=false;
68 fbWarningState=false;
69 fbRunning=false;
70 fbGetStatus=true;
71 fbGetSetup=false;
72 fbGetSetML=false;
73 fbGetSetMO=false;
74 fbTrending=false;
75 fbTrendingInit=true;
76 fbShowMore=false;
77 fbSingleRefresh=false;
78 fbTrendingForward=false; // define moving direction of trend histograms
79 fiTrendBins=1000;
80 // now overwrite some settings:
81 SetNode(go4sett->getMbsMonitorNode());
82 fbTrending=go4sett->getMbsMonitorTrend();
83 TrendCheck->setChecked(fbTrending);
84 fiTrendBins=go4sett->getMbsMonitorBins();
85 TrendBinsBox->setValue(fiTrendBins);
86 fbShowMore=go4sett->getMbsMonitorMore();
87 MoreBox->setChecked(fbShowMore);
88 FrequencyBox->setValue(go4sett->getMbsMonitorFreq());
89 fbTrendingForward=!(go4sett->getMbsMonitorBackwardsTrending());
90
91 fxHistoAccessName = "nosuchobject";
92 fxHistokBAccessName = "nosuchobject";
93 fxHistoEvRatioAccessName = "nosuchobject";
94 fxServerLabel = "NO SERVER";
95 fxTimer = new QTimer(this);
96 fxMovieResetTimer = new QTimer(this);
97 QString moviepath = ":/icons/mbslogorun.gif";
98 fxRunMovie = new QMovie(moviepath);
99 memset(&fxDaqStat, 0, sizeof(fxDaqStat));
104 fiLastEventNum = 0;
105 fiLastDataNum = 0;
106 fxDeltaClock.start();
107 QObject::connect(fxTimer, &QTimer::timeout, this, &TGo4MBSViewer::Refresh);
108 QObject::connect(fxMovieResetTimer, &QTimer::timeout, this, &TGo4MBSViewer::ResetRunIcon);
109 Display();
110
111}
112
117
118
120{
121 // save settings:
122 go4sett->setMbsMonitorNode(fxNode);
123 go4sett->setMbsMonitorTrend(fbTrending);
124 go4sett->setMbsMonitorBins(fiTrendBins);
125 go4sett->setMbsMonitorMore(fbShowMore);
126 go4sett->setMbsMonitorFreq(FrequencyBox->value());
127 go4sett->setMbsMonitorMonitorActive(fbIsMonitoring);
128 go4sett->setMbsMonitorBackwardsTrending(!fbTrendingForward);
129}
130
131
133{
134 fbIsMonitoring = true;
135 fbTrendingInit = true;
136 fiLastEventNum = 0;
137 fiLastDataNum = 0;
139 Refresh();
140 fxTimer->start(1000 * FrequencyBox->value());
141 Display();
143}
144
146{
147 fbIsMonitoring=false;
148 fxTimer->stop();
150 Display();
152}
153
154
156{
157 setWindowTitle("MBS Status - "+NodeEdit->text());
158 if(!fbSingleRefresh)
159 {
160 NodeEdit->setEnabled(!fbIsMonitoring);
161 MonitorButton->setEnabled(!fbIsMonitoring);
162 StopButton->setEnabled(fbIsMonitoring);
163 FrequencyBox->setEnabled(!fbIsMonitoring);
164 //TrendCheck->setEnabled(!fbIsMonitoring);
165 TrendBinsBox->setEnabled(!fbTrending);
166 }
167 MoreFrame->setVisible(fbShowMore);
168 SumEvents->display((double) fxDaqStat.bl_n_events);
169 //RateEvents->display((double) fxDaqStat.bl_r_events);
170 RateEvents->display((double) fiCalcedEventRate);
171 SumBytes->display((double) ((unsigned int) fxDaqStat.bl_n_kbyte/1024));
172 //RateBytes->display((double) fxDaqStat.bl_r_kbyte);
173 RateBytes->display((double) fiCalcedDataRate);
174 DateLabel->setText(fxRefTime);
175 SumBytesFile->display((double) ((unsigned int) fxDaqStat.bl_n_kbyte_file/1024));
176
177 if(fxDaqStat.l_open_file)
178 OutfileLabel->setText(fxDaqStat.c_file_name);
179 else
180 OutfileLabel->setText("- file closed -");
181
182 ServerLabel->setText(fxServerLabel);
183 ServerPercent->display((int) fiEvRatio);
185 RunPix->clear();
186 RunPix->setMovie(fxRunMovie);
187 fxRunMovie->start();
188 }
189 else{
190 RunPix->setWindowIcon(QIcon( ":/icons/mbsbutton.png" ));
191 if(fxRunMovie) fxRunMovie->stop();
192 }
193 WarnPix->setVisible(fbWarningState);
194
195 // put here enable/disable setup buttons:
196 SetupRadio->setEnabled(fxDaqStat.bh_setup_loaded);
197 SetupMLRadio->setEnabled(fxDaqStat.bh_set_ml_loaded);
198 SetupMORadio->setEnabled(fxDaqStat.bh_set_mo_loaded);
200 std::cerr <<fxMessage.toLatin1().constData() << std::endl;
201
202 ensurePolished();
203 update();
204 show();
205}
206
207
209{
210 // for the ratemeter and running state, we always get status block
211 if(fxNode.isEmpty()) return;
212 int state=f_mbs_status(const_cast<char *>(fxNode.toLatin1().constData()), &fxDaqStat);
213 if(state!=STC__SUCCESS) {
214 fxMessage = QString("MBS Status refresh node %1 returned error %2 at ").arg(fxNode).arg(state);
215 fxMessage += QDateTime::currentDateTime().toString();
216 fbWarningState = true;
217 } else
218 fbWarningState = false;
219 //fxRefTime=QDateTime::currentDateTime ().toString();
220 fxRefTime=fxDaqStat.c_date;
221 fbRunning=fxDaqStat.bh_acqui_running;
222 int deltat=FrequencyBox->value();
223 int numperiods=1;
224 int deltamilsecs=deltat*1000.0; // default
226 {
227 // only in monitoring mode: calculate rates ourselves, independent of mbs ratemter:
228 // NEW: first check real time diff since last call and correct rates:
229 deltamilsecs=fxDeltaClock.elapsed();
230 fxDeltaClock.restart();
231 int deltasecs=deltamilsecs/1000;
232 if(!fbTrendingInit && (deltasecs>=deltat*2))
233 //if((deltasecs>=deltat*2)) // this one was for testing JAM
234 {
235 std::cout <<"Warning: MBS monitor found measuring interval:"<<deltasecs<<" s ("<<deltamilsecs <<" ms) exceeding timer period "<<deltat<<" s" << std::endl;
236 std::cout <<" Maybe timer was skipped?" << std::endl;
237 deltat=deltasecs;
238 numperiods=(deltat/ (int) FrequencyBox->value());
239 std::cout <<" Correcting number of measuring periods to:"<<numperiods << std::endl;
240 }
241 if(fiLastEventNum && deltamilsecs)
242 fiCalcedEventRate = 1000.*(fxDaqStat.bl_n_events-fiLastEventNum)/deltamilsecs;
243 else
245 fiLastEventNum=fxDaqStat.bl_n_events;
246
247 if(fiLastDataNum && deltamilsecs)
248 {
249 fiDataDelta = (fxDaqStat.bl_n_kbyte-fiLastDataNum);
250 fiCalcedDataRate = 1000.*fiDataDelta/deltamilsecs;
251 }
252 else
253 {
254 fiDataDelta = 0;
256 }
257 fiLastDataNum=fxDaqStat.bl_n_kbyte;
258 // std::cout <<"Data rate:"<<fiCalcedDataRate << std::endl;
259 // std::cout <<"Data total:"<<fiLastDataNum << std::endl;
260 }
261 else
262 {
263 // single refresh on button press: use momentary mbs rate
264 fiCalcedEventRate = fxDaqStat.bl_r_events;
265 fiCalcedDataRate = fxDaqStat.bl_r_kbyte;
266 }
267
268 if(fxDaqStat.bh_running[SYS__stream_serv])
269 {
270 fxServerLabel = QString("streamserver %1%2").arg((int)(fxDaqStat.bl_strsrv_scale != 0 ? 100/fxDaqStat.bl_strsrv_scale : 0)).arg("%");
271
273 {
274 // own rate calculation for monitoring on:
275 if(fiLastServDataNum && deltamilsecs)
276 {
277 fiServDataDelta=(fxDaqStat.bl_n_strserv_kbytes-fiLastServDataNum);
278 fiCalcedServDataRate=1000.*fiServDataDelta/deltamilsecs;
279 }
280 else
281 {
282 fiServDataDelta = 0;
284 }
285 // std::cout <<"Streamserver rate:"<<fiCalcedServDataRate << std::endl;
286 // std::cout <<"Streamserver data:"<<fxDaqStat.bl_n_strserv_kbytes << std::endl;
287 // std::cout <<"Streamserver last data:"<<fiLastServDataNum << std::endl;
288 // std::cout <<"dt:"<<deltat << std::endl;
289 fiLastServDataNum=fxDaqStat.bl_n_strserv_kbytes;
290 }
291 else
292 {
293 // single refresh: use ratio from current mbs calculated rates
294 fiCalcedServDataRate = fxDaqStat.bl_r_strserv_kbytes;
295 fiDataDelta = 0;
296 }
297 //fiEvRatio= (fiCalcedDataRate != 0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
298 //int curentratio=(fiCalcedDataRate != 0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
300 }
301 else if(fxDaqStat.bh_running[SYS__event_serv])
302 {
303 // calculate momentary rate for eventserver:
304
305 fxServerLabel = QString("eventserver %1 %2%3")
306 .arg(fxDaqStat.bh_event_serv_ready ? "R" : "S")
307 .arg((int)(fxDaqStat.bl_evtsrv_scale != 0 ? 100/fxDaqStat.bl_evtsrv_scale : 0)).arg("%");
309 {
310 // own rate calculation for monitoring on:
311 if(fiLastServDataNum && deltamilsecs)
312 {
313 fiServDataDelta=(fxDaqStat.bl_n_evserv_kbytes-fiLastServDataNum);
314 fiCalcedServDataRate=1000.0*fiServDataDelta/deltamilsecs;
315 }
316 else
317 {
318 fiServDataDelta = 0;
320 }
321 fiLastServDataNum = fxDaqStat.bl_n_evserv_kbytes;
322 }
323 else
324 {
325 // single refresh: use ratio from current mbs calculated rates
326 fiCalcedServDataRate = fxDaqStat.bl_r_evserv_kbytes;
327 fiDataDelta = 0;
328 }
329 //fiEvRatio= (fiCalcedDataRate != 0 ? 100* fiCalcedServDataRate /fiCalcedDataRate : 0);
331
332 }
333 else
334 {
335 fxServerLabel = "NO SERVER";
336 fiEvRatio = 0;
337 }
338
340 {
341 while((numperiods--) > 0)
342 {
343 UpdateTrending(); // use same values for all skipped periods
344 }
345 }
347 Display();
348 //f_ut_seg_show (&fxDaqStat,0,0,0);
349}
350
352{
353 Refresh();
354}
355
356
357void TGo4MBSViewer::NodeChanged( const QString & txt )
358{
359 fxNode = txt.trimmed();
360}
361
363{
365 {
366 std::cout <<fxMessage.toLatin1().constData() << std::endl;
367 }
368 else
369 {
370 std::cout <<"\n------------------------------------------------" << std::endl;
371 if(fbGetStatus)
372 f_ut_seg_show (&fxDaqStat,nullptr,nullptr,nullptr);
373 if(fbGetSetup)
374 f_ut_seg_show (nullptr,&fxSetup,nullptr,nullptr);
375 else if(fbGetSetML)
376 f_ut_seg_show (nullptr,nullptr,&fxSetupML,nullptr);
377 else if(fbGetSetMO)
378 f_ut_seg_show (nullptr,nullptr,nullptr,&fxSetupMO);
379 }
380}
381
383{
384 // JAM23-11-2022: do the old complicated attempt a bit better:
385 fbGetStatus=StatusRadio->isChecked();
386 fbGetSetup=SetupRadio->isChecked();
387 fbGetSetML=SetupMLRadio->isChecked();
388 fbGetSetMO=SetupMORadio->isChecked();
389// printf("StateGroup_clicked: fbGetStatus=%d, fbGetSetup=%d, fbGetSetML=%d, fbGetSetMO=%d\n",
390// fbGetStatus,fbGetSetup, fbGetSetML, fbGetSetMO);
391}
392
393
395{
396 if(fxNode.isEmpty()) return;
397 if(fbGetSetup)
398 {
399 // request setup if selected
400
401 int state = f_mbs_setup(const_cast<char *>(fxNode.toLatin1().constData()), &fxSetup);
402 if(state)
403 {
404 fxMessage = QString("MBS Setup refresh returned error %1 at %2").arg(state).arg(QDateTime::currentDateTime().toString());
405 fbWarningState = true;
406 }
407 else
408 fbWarningState=false;
409 }
410
411 else if(fbGetSetML)
412 {
413 // request setup multilayer if selected
414 int state = f_mbs_ml_setup(const_cast<char *>(fxNode.toLatin1().constData()), &fxSetupML);
415 if(state != 0)
416 {
417 fxMessage = QString("MBS Setup ML refresh returned error %1 at %2").arg(state).arg(QDateTime::currentDateTime().toString());
418 fbWarningState = true;
419 }
420 else
421 fbWarningState = false;
422 }
423 else if(fbGetSetMO)
424 {
425 // request setup MO if selected
426 int state = f_mbs_mo_setup(const_cast<char *>(fxNode.toLatin1().constData()), &fxSetupMO);
427 if(state != 0)
428 {
429 fxMessage = QString("MBS Setup MO refresh returned error %1 at %2").arg(state).arg(QDateTime::currentDateTime().toString());
430 fbWarningState = true;
431 }
432 else
433 fbWarningState = false;
434 }
435
436 else {}
437 RefreshButtonClick(); // always get new status structure and display on window
438 ShowStatus();
439}
440
441
443{
444 if(!fbTrending) fbTrendingInit=true;
445 fbTrending=on;
446 go4sett->setMbsMonitorTrend(fbTrending);
447 Display();
448}
449
450
452{
453 TrendHisto(fxHistoAccessName, "MbsEventRate", "Events/s", fiCalcedEventRate);
454 TrendHisto(fxHistokBAccessName, "MbsDataRate", "kB/s", fiCalcedDataRate);
455 TrendHisto(fxHistoEvRatioAccessName, fxServerLabel.section(' ',0,0), "% Events served", fiEvRatio);
456 fbTrendingInit = false;
457}
458
459
460void TGo4MBSViewer::IncTrending( TH1 *histo, int value, bool forwards )
461{
462 if(!histo) return;
463 int bins=histo->GetNbinsX();
464 //bool forwards=true;
465 int j,dj;
466 if(forwards)
467 dj=-1;
468 else
469 dj=+1;
470 for (int i = 0; i < bins; i++) {
471 if (forwards)
472 j = bins - i;
473 else
474 j = i;
475 int oldval = histo->GetBinContent(j + dj);
476 histo->SetBinContent(j, oldval);
477 }
478 histo->SetBinContent(j + dj, value);
479}
480
481
486
487
488TH1 *TGo4MBSViewer::TrendHisto( QString & refname ,const QString & name, const QString & title, int value)
489{
490 TH1 *his = nullptr;
491 TGo4Slot *histoslot = nullptr;
492 if(!fbTrendingInit) histoslot = Browser()->BrowserSlot(refname.toLatin1());
493 if(!histoslot) {
494 Axis_t lo,up;
495 if (fbTrendingForward) {
496 lo = 0;
497 up = 1 * fiTrendBins * FrequencyBox->value();
498 } else {
499 lo = -1 * fiTrendBins * FrequencyBox->value();
500 up = 0;
501 }
502 his = new TH1F(name.toLatin1(), title.toLatin1(), fiTrendBins, lo, up);
503 TAxis *xax = his->GetXaxis();
504 xax->SetTitle("s");
505 xax->CenterTitle();
506 //xax->SetLimits(0,lo,up);
507
508 TGo4Slot *hisdataslot=Browser()->DataSlot(refname.toLatin1());
509 if (hisdataslot) {
510 hisdataslot->AssignObject(his, true);
511 } else {
512 refname = Browser()->SaveToMemory("Mbs", his, true);
513 }
514 histoslot = Browser()->BrowserSlot(refname.toLatin1());
515 }
516 else
517 {
518 his = dynamic_cast<TH1 *>(histoslot->GetAssignedObject());
519 }
521 if(histoslot)
522 {
523 histoslot->ForwardEvent(histoslot, TGo4Slot::evObjUpdated);
524 Browser()->SetItemTimeDate(histoslot);
525 }
526 return his;
527}
528
529
531{
532 fbShowMore=on;
533 go4sett->setMbsMonitorMore(fbShowMore);
534 Display();
535}
536
537
543
544
546{
547 bool trend=fbTrending;
548 bool monitoring=fbIsMonitoring;
549 fbTrending=false; // avoid to put direct refresh into the trending histogram
550 fbIsMonitoring=false; // avoid confuse rate calculations
551 fbSingleRefresh=true; // avoid changing state of control buttons
552 Refresh();
553 fbSingleRefresh=false;
554 fbIsMonitoring=monitoring;
555 fbTrending=trend;
556
557}
558
559void TGo4MBSViewer::SetNode( const QString & txt )
560{
561 fxNode=txt;
562 NodeEdit->setText(txt);
563}
564
565
567{
568 fbRunning=false;
569 Display();
570}
571
573{
574 if(!fbIsMonitoring) {
575 fxMovieResetTimer->setSingleShot(true);
576 fxMovieResetTimer->start(2000);
577 }
578}
TGo4QSettings * go4sett
QGo4Widget(QWidget *parent=nullptr, const char *name=nullptr, Qt::WindowFlags f=Qt::Widget)
TGo4BrowserProxy * Browser()
TGo4Slot * BrowserSlot(const char *item=nullptr)
TString SaveToMemory(const char *pathname, TObject *obj, Bool_t ownership, Bool_t overwrite=kFALSE)
TGo4Slot * DataSlot(const char *item)
static void SetItemTimeDate(TGo4Slot *slot, const char *stime=nullptr, const char *sdate=nullptr)
s_daqst fxDaqStat
QTimer * fxTimer
QString fxRefTime
virtual void UpdateTrending()
QElapsedTimer fxDeltaClock
s_set_mo fxSetupMO
virtual ~TGo4MBSViewer()
QString fxHistokBAccessName
virtual void MoreBox_toggled(bool on)
QString fxHistoAccessName
QString fxServerLabel
TGo4MBSViewer(QWidget *parent=nullptr, const char *name=nullptr)
virtual void RefreshButtonClick()
virtual void ResetRunIcon()
virtual void TrendSwitched(bool on)
virtual void FrequencyBox_valueChanged(int)
virtual void TrendBinsBox_valueChanged(int i)
virtual void NodeEditEnter()
virtual void NodeChanged(const QString &txt)
virtual void Refresh()
virtual void StoreSettings()
virtual void TimerStart()
virtual void PrintState()
virtual void Display()
virtual void ShowStatus()
TH1 * TrendHisto(QString &refname, const QString &name, const QString &title, int value)
QMovie * fxRunMovie
virtual void StartMovieReset()
virtual void SetNode(const QString &txt)
s_set_ml fxSetupML
virtual void TimerStop()
QTimer * fxMovieResetTimer
QString fxHistoEvRatioAccessName
virtual void IncTrending(TH1 *histo, int value, bool forwards)
QString fxMessage
virtual void StateGroup_clicked(int id)
@ evObjUpdated
Definition TGo4Slot.h:49
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=nullptr)
Definition TGo4Slot.cxx:565
Bool_t AssignObject(TObject *obj, Bool_t owner)
Definition TGo4Slot.cxx:344
TObject * GetAssignedObject()
Definition TGo4Slot.cxx:356
INTS4 f_mbs_status(CHARS *c_node, s_daqst *ps_daqst)
INTS4 f_mbs_ml_setup(CHARS *c_node, s_set_ml *ps_set_ml)
INTS4 f_mbs_setup(CHARS *c_node, s_setup *ps_setup)
INTS4 f_mbs_mo_setup(CHARS *c_node, s_set_mo *ps_set_mo)
#define STC__SUCCESS
Definition f_stccomm.h:369
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)
#define SYS__event_serv
Definition sys_def.h:37
#define SYS__stream_serv
Definition sys_def.h:44