00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4DabcMonitor.h"
00015
00016 #include "TGo4QSettings.h"
00017 #include "TGo4BrowserProxy.h"
00018 #include "TGo4Slot.h"
00019 #include "TGo4LockGuard.h"
00020
00021 #include <QDateTime>
00022 #include <QtCore/QTimer>
00023
00024 #include "TH1.h"
00025
00026 #include <iostream>
00027
00031
00032 void TGo4DabcInfo::infoHandler()
00033 {
00034 fxOwner->infoUpdated(this);
00035 }
00036
00037 void TGo4DabcNodesInfo::infoHandler()
00038 {
00039 fxOwner->nodesUpdated(this);
00040 }
00041
00042
00043 void TGo4DabcServiceInfo::infoHandler()
00044 {
00045 fxOwner->servicesUpdated(this);
00046 }
00047
00048 void TGo4DabcStateInfo::infoHandler()
00049 {
00050 fxOwner->stateUpdated(this);
00051 }
00052
00053 void TGo4DabcRateInfo::infoHandler()
00054 {
00055 fxOwner->rateUpdated(this);
00056 }
00057
00063
00064 TGo4DabcMonitor::TGo4DabcMonitor( QWidget* parent, const char* name)
00065 : QGo4Widget(parent,name)
00066 {
00067 setupUi(this);
00068
00069
00070 strncpy(gNolinkStateRecord.status,"not available",16);
00071 gNolinkRateRecord.value=-1.0;
00072 fxServerInfo = 0;
00073 fxLastTimestamp = 0;
00074 fbRebuildNodeTable=true;
00075 fbDisplayNodeTable=false;
00076 fbRebuildRateTable=true;
00077 fbDisplayRateTable=false;
00078
00079 fbTableBeingCreated=false;
00080
00081
00082 NodeTable->setColumnCount(5);
00083
00084
00085 NodeTable->setColumnHidden( DABCMON_NODE_INDEXCOL, true) ;
00086 NodeTable->setColumnWidth ( DABCMON_NODE_INDEXCOL, 1) ;
00087
00088
00089
00090
00091 NodeTable->setHorizontalHeaderItem(DABCMON_NODE_NODECOL, new QTableWidgetItem(tr( "Context" ) ));
00092 NodeTable->setHorizontalHeaderItem(DABCMON_NODE_STATECOL, new QTableWidgetItem( tr( "State" ) ));
00093 NodeTable->setHorizontalHeaderItem(DABCMON_NODE_CHECKCOL , new QTableWidgetItem( tr( "Ratemeters" ) ));
00094 NodeTable->setHorizontalHeaderItem(DABCMON_NODE_LOGCOL, new QTableWidgetItem( tr( "Service list" ) ));
00095
00096 RateTable->setColumnCount(5);
00097
00098 RateTable->setColumnHidden( DABCMON_RATE_INDEXCOL, true) ;
00099 RateTable->setColumnWidth ( DABCMON_RATE_INDEXCOL,1) ;
00100
00101
00102
00103 RateTable->setHorizontalHeaderItem(DABCMON_RATE_NAMECOL, new QTableWidgetItem(tr( "Name" ) ));
00104 RateTable->setHorizontalHeaderItem(DABCMON_RATE_RATECOL, new QTableWidgetItem(tr( "Value" ) ));
00105 RateTable->setHorizontalHeaderItem(DABCMON_RATE_TRENDCOL, new QTableWidgetItem(tr( "Trending" ) ));
00106 RateTable->setHorizontalHeaderItem(DABCMON_RATE_STATSCOL, new QTableWidgetItem(tr( "Statistics" ) ));
00107 FullPrintDIMButton->setDisabled(true);
00108 dimServiceFilterEdit->setDisabled(true);
00109
00110
00111
00112
00113 fxDabcNodes.clear();
00114 fxServices.clear();
00115 fxRates.clear();
00116 fxStates.clear();
00117 fxShowRateFlags.clear();
00118 fxShowLogFlags.clear();
00119 fxTrendingFlags.clear();
00120 fbTrendingInit.clear();
00121 fxStatsFlags.clear();
00122 fbStatsInit.clear();
00123 fxRateQueues.clear();
00124 fxTrendHistoRefnames.clear();
00125 fxStatHistoRefnames.clear();
00126 fxStateRecords.clear();
00127 fxRateRecords.clear();
00128 fxRateSum.clear();
00129 fxRateCount.clear();
00130 fxDisplayTimer=new QTimer(this);
00131 fxDisplayTimer->connect( fxDisplayTimer, SIGNAL(timeout()), this, SLOT(displayAll()) );
00132 fxDisplayTimer->start(500);
00133 fxAverageTimer=new QTimer(this);
00134 fxAverageTimer->connect( fxAverageTimer, SIGNAL(timeout()), this, SLOT(displayAverageHistograms()));
00135
00136
00137 fiTrendBins=100;
00138 fiStatBins=100;
00139
00140 fbTrendingForward=false;
00141 fbHistogramming=false;
00142 fbDisplayHistograms=false;
00143
00144
00145 QString node=go4sett->getDabcMonitorNode();
00146
00147 dimDnsNodeEdit->setText(node);
00148 fiTrendBins=go4sett->getDabcMonitorBins();
00149 fiStatBins=fiTrendBins;
00150 TrendBinsBox->setValue(fiTrendBins);
00151 FrequencyBox->setValue(go4sett->getDabcMonitorFreq());
00152 fbTrendingForward=!(go4sett->getMbsMonitorBackwardsTrending());
00153
00154
00155 controlBox->setVisible(false);
00156
00157
00158
00159
00160
00161 }
00162
00163
00164 TGo4DabcMonitor::~TGo4DabcMonitor()
00165 {
00166 }
00167
00168
00172
00173
00174
00175 void TGo4DabcMonitor::storeSettings()
00176 {
00177
00178 go4sett->setDabcMonitorNode(fxDnsNode);
00179 go4sett->setDabcMonitorBins(fiTrendBins);
00180 go4sett->setDabcMonitorFreq(FrequencyBox->value());
00181 go4sett->setDabcMonitorBackwardsTrending(!fbTrendingForward);
00182 }
00183
00184
00185 void TGo4DabcMonitor::refreshDIMSlot()
00186 {
00187 TGo4LockGuard gard(0,true);
00188
00189
00190 fxDnsNode = dimDnsNodeEdit->text().trimmed();
00191 if(fxDnsNode.isEmpty()) return;
00192 DimClient::setDnsNode(fxDnsNode.toLatin1().constData());
00193 if (fxServerInfo!=0) {
00194 delete fxServerInfo;
00195 fxServerInfo = 0;
00196 }
00197
00198 FullPrintDIMButton->setDisabled(true);
00199 dimServiceFilterEdit->setDisabled(true);
00200 fxServerInfo = new TGo4DabcNodesInfo("DIS_DNS/SERVER_LIST",0,"Name server not available", this);
00201 storeSettings();
00202 }
00203
00204
00205 void TGo4DabcMonitor::logDIMSlot()
00206 {
00207 TGo4LockGuard gard(0,true);
00208
00209 for(int nix=0; nix<fxDabcNodes.size(); ++nix)
00210 {
00211 if(fxShowLogFlags[nix] )
00212 {
00213
00214 createLogServices(nix);
00215 }
00216 }
00217 }
00218
00219
00220 void TGo4DabcMonitor::histogramCheckToggled( bool val )
00221 {
00222 TGo4LockGuard gard(0,true);
00223
00224 fbHistogramming=val;
00225
00226 if(val)
00227 {
00228 for(int nodeix=0;nodeix<fbTrendingInit.size();++nodeix)
00229 {
00230 std::vector <std::vector <bool> > & nodevec=fbTrendingInit[nodeix];
00231 for(int rateix=0; rateix<nodevec.size();++rateix)
00232 {
00233 std::vector <bool> & hisvec= nodevec[rateix];
00234 for (int hisix=0; hisix<hisvec.size();++hisix)
00235 {
00236 hisvec[hisix]=val;
00237 }
00238 }
00239 }
00240 for(int nodeix=0;nodeix<fbStatsInit.size();++nodeix)
00241 {
00242 std::vector <std::vector <bool> > & nodevec=fbStatsInit[nodeix];
00243 for(int rateix=0; rateix<nodevec.size();++rateix)
00244 {
00245 std::vector <bool> & hisvec= nodevec[rateix];
00246 for (int hisix=0; hisix<hisvec.size();++hisix)
00247 {
00248 hisvec[hisix]=val;
00249 }
00250 }
00251 }
00252 }
00253
00254 for (int nodeix=0;nodeix<fxRateSum.size();++nodeix)
00255 {
00256 std::vector<float> & nodevec=fxRateSum[nodeix];
00257 for(int rateix=0; rateix<nodevec.size();++rateix)
00258 {
00259 nodevec[rateix]=0;
00260 }
00261 }
00262 for(int nodeix=0;nodeix<fxRateCount.size();++nodeix)
00263 {
00264 std::vector<unsigned int> & nodevec=fxRateCount[nodeix];
00265 for(int rateix=0; rateix<nodevec.size();++rateix)
00266 {
00267 nodevec[rateix]=0;
00268 }
00269 }
00270 TrendBinsBox->setDisabled(val);
00271 storeSettings();
00272 }
00273
00274
00275 void TGo4DabcMonitor::averageCheckToggled( bool val )
00276 {
00277
00278 FrequencyBox->setDisabled(val);
00279 if(val)
00280 {
00281
00282 float milsecs=1000*FrequencyBox->value();
00283 fxAverageTimer->start(milsecs);
00284
00285 }
00286 else
00287 {
00288
00289 fxAverageTimer->stop();
00290 }
00291 storeSettings();
00292 }
00293
00294
00295 void TGo4DabcMonitor::binsizeChanged( int val )
00296 {
00297
00298 fiTrendBins=val;
00299 fiStatBins=val;
00300
00301 }
00302
00303
00304
00305
00306
00307 void TGo4DabcMonitor::nodeTableChangedSlot( int row, int column )
00308 {
00309 TGo4LockGuard gard(0,true);
00310 if(fbTableBeingCreated) return;
00311
00312
00313 QString ixtext;
00314 if (NodeTable->item(row, DABCMON_NODE_INDEXCOL))
00315 ixtext = NodeTable->item(row, DABCMON_NODE_INDEXCOL)->text();
00316 int ix=ixtext.toInt();
00317
00318 if(column==DABCMON_NODE_CHECKCOL)
00319 {
00320
00321 bool on=false;
00322 QTableWidgetItem* checkitem = NodeTable->item(row, DABCMON_NODE_CHECKCOL);
00323 if(checkitem)
00324 on = (checkitem->checkState() == Qt::Checked);
00325 else
00326 std::cout<<"!!!!!!!!!! NEVER COME HERE: wrong rate checktableitem at tablerow "<<row <<std::endl;
00327
00328
00329 fxShowRateFlags[ix]=on;
00330
00331 if(on)
00332 createRateServices(ix);
00333 else
00334 deleteRateServices(ix);
00335 }
00336 else if (column==DABCMON_NODE_LOGCOL)
00337 {
00338 QTableWidgetItem* checkitem = NodeTable->item(row, DABCMON_NODE_LOGCOL);
00339 bool on=false;
00340 if(checkitem)
00341 on = (checkitem->checkState() == Qt::Checked);
00342 else
00343 std::cout<<"!!!!!!!!!! NEVER COME HERE: wrong log checktableitem at tablerow "<<row <<std::endl;
00344
00345 fxShowLogFlags[ix]=on;
00346
00347 bool disablebutton=true;
00348 for(int t=0;t<fxShowLogFlags.size();++t)
00349 {
00350 if(fxShowLogFlags[t])
00351 {
00352 disablebutton=false;
00353 break;
00354 }
00355 }
00356 FullPrintDIMButton->setDisabled(disablebutton);
00357 dimServiceFilterEdit->setDisabled(disablebutton);
00358
00359 }
00360 }
00361
00362
00363 void TGo4DabcMonitor::rateTableChangedSlot(int row, int column)
00364 {
00365 TGo4LockGuard gard(0,true);
00366 if(fbTableBeingCreated) return;
00367
00368 if(column==DABCMON_RATE_TRENDCOL)
00369 {
00370
00371 bool on=false;
00372 QTableWidgetItem* checkitem= RateTable->item(row, DABCMON_RATE_TRENDCOL);
00373 if(checkitem)
00374 on = (checkitem->checkState() == Qt::Checked);
00375 else
00376 std::cout<<"!!!!!!!!!! NEVER COME HERE: wrong checktableitem at tablerow "<<row <<std::endl;
00377
00378 int nix=0;
00379 int rix=0;
00380 if(!getRateIndices(row, nix, rix))
00381 std::cout<<"!!!!!!!!!! NEVER COME HERE: get RateIndices could not get indices for row "<<row <<std::endl;
00382 fxTrendingFlags[nix].at(rix)=on;
00383
00384 fbTrendingInit[nix].at(rix).at(0)=on;
00385 fbTrendingInit[nix].at(rix).at(1)=on;
00386 }
00387 else if(column==DABCMON_RATE_STATSCOL)
00388 {
00389
00390 bool on=false;
00391 QTableWidgetItem* checkitem = RateTable->item(row, DABCMON_RATE_STATSCOL);
00392 if(checkitem)
00393 on = (checkitem->checkState() == Qt::Checked);
00394 else
00395 std::cout<<"!!!!!!!!!! NEVER COME HERE: wrong checktableitem at tablerow "<<row <<std::endl;
00396
00397 int nix=0;
00398 int rix=0;
00399 if(!getRateIndices(row, nix, rix))
00400 std::cout<<"!!!!!!!!!! NEVER COME HERE: get RateIndices could not get indices for row "<<row <<std::endl;
00401
00402 fxStatsFlags[nix].at(rix)=on;
00403
00404 fbStatsInit[nix].at(rix).at(0)=on;
00405 fbStatsInit[nix].at(rix).at(1)=on;
00406 }
00407 }
00408
00412
00413
00414 void TGo4DabcMonitor::infoUpdated( TGo4DabcInfo * info )
00415 {
00416
00417 TGo4LockGuard gard(0,true);
00418
00419 QDateTime timestamp;
00420 timestamp.setTime_t (info->getTimestamp());
00421 std::cout<<"DIM service " << info->getName() <<":"<<std::endl;
00422
00423 if(info->getServiceType()=="int")
00424 std::cout<<" - "<< info->getInt();
00425 else if (info->getServiceType()=="float")
00426 std::cout<<" - "<< info->getFloat();
00427 else if (info->getServiceType()=="double")
00428 std::cout<<" - "<< info->getDouble();
00429 else if (info->getServiceType()=="char")
00430 std::cout<<" - "<< info->getString();
00431 else
00432 {
00433
00434 char* ptr=(char*) info->getData();
00435 int size=info->getSize();
00436 QString format=info->getServiceType();
00437 std::cout<<" - structure of format " << format.toLatin1().constData() <<std::endl;
00438 QStringList elements = format.split(";",QString::SkipEmptyParts);
00439 for ( QStringList::Iterator it = elements.begin(); it != elements.end(); ++it )
00440 {
00441 QString component=*it;
00442 QString type=component.section(':',0,0);
00443 QString slen=component.section(':',1,1);
00444 int length=slen.toInt();
00445
00446 QString content="";
00447 QString prompt=" - "+type+" ("+slen+") \t>";
00448 if(type=="C")
00449 {
00450 content=ptr;
00451 content.truncate(length);
00452 ptr+=length;
00453 }
00454 else if(type=="L")
00455 {
00456 int* cursor= (int*) ptr;
00457 for(int t=0; t<length; ++t)
00458 {
00459 QString val;
00460 content+= val.setNum(*cursor,10);
00461 cursor++;
00462 }
00463 ptr= (char*) cursor;
00464 }
00465 else if(type=="F")
00466 {
00467 float* cursor= (float*) ptr;
00468 for(int t=0; t<length; ++t)
00469 {
00470 QString val;
00471 content+= val.setNum( *cursor, 'g',5);
00472 cursor++;
00473 }
00474 ptr= (char*) cursor;
00475 }
00476
00477 else
00478 {
00479
00480 for(int t=0; t<length; ++t)
00481 {
00482 QString val;
00483 content+= val.setNum(*ptr,10);
00484 content+=":";
00485 ptr++;
00486 }
00487 }
00488 std::cout<<prompt.toLatin1().constData()<<content.toLatin1().constData() << "< "<<std::endl;;
00489 int currentposition= (long) ptr - (long) info->getData();
00490 if(currentposition > size)
00491 {
00492 std::cout<<" !!!!!!!!!!!!!!!! structure iterator exceeds service size "<<size <<std::endl;
00493 break;
00494 }
00495 }
00496 }
00497 std::cout<<" - (timestamp:"<<timestamp.toString().toLatin1().constData()<<")" <<std::endl;
00498 delete info;
00499 }
00500
00501
00502 void TGo4DabcMonitor::nodesUpdated( TGo4DabcNodesInfo * info )
00503 {
00504 TGo4LockGuard gard(0,true);
00505
00506 QString servers=info->getString();
00507 fxNodelist = servers.split("|", QString::SkipEmptyParts);
00508 refreshNodes();
00509 fbDisplayNodeTable=true;
00510 fbDisplayRateTable=true;
00511 }
00512
00513 void TGo4DabcMonitor::servicesUpdated( TGo4DabcServiceInfo * info )
00514 {
00515 TGo4LockGuard gard(0,true);
00516
00517
00518 unsigned int index=-1;
00519 for(unsigned int ix=0; ix<fxServices.size(); ++ix)
00520 {
00521 if(info==fxServices[ix])
00522 {
00523 index=ix;
00524 break;
00525 }
00526 }
00527 if(index<0)
00528 {
00529 std::cout<<"!!!!!!!!!!!servicesUpdated: unknown service info" << (int*) info<<std::endl;
00530 }
00531 else
00532 {
00533 if(index>fxStates.size() )
00534 {
00535 std::cout<<"!!!!!!!!!!!NEVER COME HERE: services updated out of bounds, index=" << index<<std::endl;
00536 return;
00537 }
00538 QString services=info->getString();
00539
00540
00541
00542 QStringList servlist = services.split(0x0A, QString::SkipEmptyParts);
00543 QString stateservice="";
00544 for ( QStringList::Iterator sit = servlist.begin(); sit != servlist.end(); ++sit )
00545 {
00546 QString service=*sit;
00547
00548 if(service.contains("RunStatus") || service.contains("Acquisition") )
00549 {
00550 stateservice=service.section('|',0,0);
00551 break;
00552 }
00553 }
00554
00555 if(!stateservice.isEmpty())
00556 {
00557
00558 bool recreate=false;
00559 if(fxStates[index]!=0)
00560 {
00561
00562 if(stateservice==fxStates[index]->getName())
00563 {
00564
00565 recreate=false;
00566 }
00567 else
00568 {
00569
00570 delete fxStates[index];
00571 fxStates[index]=0;
00572 recreate=true;
00573 }
00574
00575 }
00576 else
00577 {
00578
00579 recreate= true;
00580 }
00581
00582 if(recreate)
00583 {
00584
00585 TGo4DabcStateInfo* sinfo= new TGo4DabcStateInfo(stateservice.toLatin1().constData(), 0, &gNolinkStateRecord, sizeof(dabc::StatusRec), this);
00586 fxStates[index]=sinfo;
00587 }
00588 }
00589 else
00590 {
00591
00592
00593
00594
00595
00596 }
00597 }
00598 }
00599
00600
00601 void TGo4DabcMonitor::stateUpdated( TGo4DabcStateInfo * info )
00602 {
00603 TGo4LockGuard gard(0,true);
00604
00605
00606 unsigned int index=-1;
00607 for(unsigned int ix=0; ix<fxStates.size(); ++ix)
00608 {
00609 if(info==fxStates[ix])
00610 {
00611 index=ix;
00612 break;
00613 }
00614 }
00615
00616 if(index<0)
00617 {
00618 std::cout<<"ERROR in stateUpdated(): object not in list, pointer " << (int*) info<<std::endl;
00619 }
00620 else
00621 {
00622 dabc::StatusRec* currentstate=(dabc::StatusRec*) info->getData();
00623 if(index>fxStateRecords.size())
00624 {
00625 std::cout<<"!!!!!!!!!!!NEVER COME HERE: state updated out of bounds, index=" << index<<std::endl;
00626 return;
00627 }
00628 fxStateRecords[index]=TGo4DabcState(currentstate);
00629 fbDisplayNodeTable=true;
00630 fxLastTimestamp=info->getTimestamp( );
00631 }
00632 }
00633
00634
00635 void TGo4DabcMonitor::rateUpdated( TGo4DabcRateInfo * info )
00636 {
00637 TGo4LockGuard gard(0,true);
00638
00639
00640
00641 unsigned int nodeindex=-1;
00642 unsigned int rateindex=-1;
00643 for(unsigned int ix=0; ix<fxRates.size(); ++ix)
00644 {
00645 std::vector<TGo4DabcRateInfo*> & rvec=fxRates[ix];
00646 for(unsigned int rix=0;rix< rvec.size();++rix)
00647 {
00648
00649 if(info==rvec[rix])
00650 {
00651 nodeindex=ix;
00652 rateindex=rix;
00653 break;
00654 }
00655 }
00656 }
00657
00658 if(nodeindex<0)
00659 {
00660 std::cout<<"ERROR in rateUpdated(): object not in list, pointer " << (int*) info<<std::endl;
00661 }
00662 else
00663 {
00664 dabc::RateRec* currentrate=(dabc::RateRec*) info->getData();
00665 if(nodeindex>fxRateRecords.size())
00666 {
00667 std::cout<<"!!!!!!!!!!!NEVER COME HERE: rate updated out of bounds, nodeindex=" << nodeindex<<std::endl;
00668 return;
00669 }
00670 std::vector<TGo4DabcRate> & recordvec= fxRateRecords[nodeindex];
00671 if(rateindex>recordvec.size())
00672 {
00673 std::cout<<"!!!!!!!!!!!NEVER COME HERE: rate updated out of bounds, rateindex=" << rateindex<<std::endl;
00674 return;
00675 }
00676 recordvec[rateindex]=TGo4DabcRate(currentrate, info->getName());
00677 bool trendon=fxTrendingFlags[nodeindex].at(rateindex);
00678 bool statson=fxStatsFlags[nodeindex].at(rateindex);
00679 if(fbHistogramming && (trendon || statson))
00680 {
00681 std::vector< std::deque <float> > & qvec= fxRateQueues[nodeindex];
00682 if(rateindex>qvec.size())
00683 {
00684 std::cout<<"!!!!!!!!!!!NEVER COME HERE: rate queue vector out of bounds, rateindex=" << rateindex<<std::endl;
00685 return;
00686 }
00687 qvec[rateindex].push_back(currentrate->value);
00688 fbDisplayHistograms=true;
00689 }
00690 fxLastTimestamp=info->getTimestamp( );
00691 fbDisplayRateTable=true;
00692 }
00693 }
00694
00695
00699
00700 void TGo4DabcMonitor::refreshNodes()
00701 {
00702 TGo4LockGuard gard(0,true);
00703
00704 fbRebuildNodeTable=true;
00705 fbRebuildRateTable=true;
00706 fxDabcNodes.clear();
00707
00708 clearRates();
00709 clearServices();
00710 clearStates();
00711 for ( QStringList::Iterator it = fxNodelist.begin(); it != fxNodelist.end(); ++it )
00712 {
00713 QString current=*it;
00714 if(current.contains("DIS_DNS")) continue;
00715
00716 QString prefix=current.section('/', 0, 0 );
00717 QString rest=current.section('/', 1, 1 );
00718 QString reducednode=rest.section('@',0,0);
00719
00720
00721 if(prefix==current)
00722 {
00723
00724 reducednode=current.section('@',0,0);;
00725 }
00726
00727
00728
00729
00730 fxDabcNodes.push_back(reducednode);
00731
00732 QString sinfoname=current.section('@',0,0) + "/SERVICE_LIST";
00733
00734 TGo4DabcServiceInfo* servinfo= new TGo4DabcServiceInfo(sinfoname.toLatin1().constData(), 0, "not available", this);
00735 fxServices.push_back(servinfo);
00736 fxStates.push_back(0);
00737 fxStateRecords.push_back(TGo4DabcState());
00738
00739 std::vector<TGo4DabcRateInfo*> rinfovec;
00740 rinfovec.clear();
00741 fxRates.push_back(rinfovec);
00742 std::vector<TGo4DabcRate> ratevec;
00743 ratevec.clear();
00744 fxRateRecords.push_back(ratevec);
00745 fxShowRateFlags.push_back(false);
00746 std::vector<float> sumvec;
00747 fxRateSum.push_back(sumvec);
00748 std::vector<unsigned int> countvec;
00749 fxRateCount.push_back(countvec);
00750 std::vector<bool> trendvec;
00751 trendvec.clear();
00752 fxTrendingFlags.push_back(trendvec);
00753 std::vector <std::vector<bool> >initvec;
00754 fbTrendingInit.push_back(initvec);
00755 fxStatsFlags.push_back(trendvec);
00756 fbStatsInit.push_back(initvec);
00757 std::vector < std::vector <QString> >namesvec;
00758 fxTrendHistoRefnames.push_back(namesvec);
00759 fxStatHistoRefnames.push_back(namesvec);
00760 fxShowLogFlags.push_back(false);
00761 std::vector< std::deque <float> > rateqvec;
00762 fxRateQueues.push_back(rateqvec);
00763
00764 }
00765 }
00766
00767
00768
00769
00770 void TGo4DabcMonitor::clearStates()
00771 {
00772 TGo4LockGuard gard(0,true);
00773 std::vector<TGo4DabcStateInfo*>::iterator iter;
00774 for(iter=fxStates.begin(); iter!=fxStates.end(); ++iter)
00775 {
00776 delete *iter;
00777 }
00778 fxStates.clear();
00779 fxStateRecords.clear();
00780 fxShowRateFlags.clear();
00781 fxShowLogFlags.clear();
00782 }
00783
00784 void TGo4DabcMonitor::clearServices()
00785 {
00786 TGo4LockGuard gard(0,true);
00787 std::vector<TGo4DabcServiceInfo*>::iterator iter;
00788 for(iter=fxServices.begin(); iter!=fxServices.end(); ++iter)
00789 {
00790 delete *iter;
00791 }
00792 fxServices.clear();
00793 }
00794
00795
00796 void TGo4DabcMonitor::clearRates()
00797 {
00798 TGo4LockGuard gard(0,true);
00799 std::vector<std::vector<TGo4DabcRateInfo*> >::iterator nodeiter;
00800 for(nodeiter=fxRates.begin(); nodeiter!=fxRates.end(); ++nodeiter)
00801 {
00802 std::vector<TGo4DabcRateInfo*> nodevec=*nodeiter;
00803 std::vector<TGo4DabcRateInfo*>::iterator iter;
00804 for(iter=nodevec.begin(); iter!=nodevec.end(); ++iter)
00805 {
00806 delete *iter;
00807 }
00808 }
00809 fxRates.clear();
00810 fxTrendingFlags.clear();
00811 fbTrendingInit.clear();
00812 fxStatsFlags.clear();
00813 fbStatsInit.clear();
00814 fxTrendHistoRefnames.clear();
00815 fxStatHistoRefnames.clear();
00816 fxRateRecords.clear();
00817 fxRateQueues.clear();
00818 fxRateSum.clear();
00819 fxRateCount.clear();
00820 }
00821
00822
00823 void TGo4DabcMonitor::createRateServices( int nodeindex )
00824 {
00825 TGo4LockGuard gard(0,true);
00826
00827
00828 QString services=fxServices[nodeindex]->getString();
00829
00830
00831
00832 QStringList servlist = services.split(0x0A, QString::SkipEmptyParts);
00833 QString rateservice="";
00834 for ( QStringList::Iterator sit = servlist.begin(); sit != servlist.end(); ++sit )
00835 {
00836 QString service = *sit;
00837
00838
00839 if(service.contains("F:1;L:1;F:1;F:1;F:1;F:1;C:16;C:16;C"))
00840 {
00841
00842 fxRateRecords[nodeindex].push_back(TGo4DabcRate());
00843 std::deque <float> ratequeue;
00844 fxRateQueues[nodeindex].push_back(ratequeue);
00845 fxRateSum[nodeindex].push_back(0);
00846 fxRateCount[nodeindex].push_back(0);
00847
00848 fxTrendingFlags[nodeindex].push_back(false);
00849 std::vector <bool> hisvec;
00850 hisvec.push_back(false);
00851 hisvec.push_back(false);
00852 fbTrendingInit[nodeindex].push_back(hisvec);
00853 std::vector <QString> namesvec;
00854 namesvec.push_back("undefined histogram");
00855 namesvec.push_back("undefined histogram");
00856 fxTrendHistoRefnames[nodeindex].push_back(namesvec);
00857
00858 fxStatsFlags[nodeindex].push_back(false);
00859 fbStatsInit[nodeindex].push_back(hisvec);
00860 fxStatHistoRefnames[nodeindex].push_back(namesvec);
00861 QString rname=service.section('|',0,0);
00862
00863 TGo4DabcRateInfo* rinfo=new TGo4DabcRateInfo(rname.toLatin1().constData(), 0, &gNolinkRateRecord , sizeof(dabc:: RateRec), this);
00864 fxRates[nodeindex].push_back(rinfo);
00865 }
00866 }
00867 }
00868
00869
00870 void TGo4DabcMonitor::deleteRateServices( int nodeindex )
00871 {
00872 TGo4LockGuard gard(0,true);
00873
00874 std::vector<TGo4DabcRateInfo*> & nodevec=fxRates[nodeindex];
00875 std::vector<TGo4DabcRateInfo*>::iterator iter;
00876 for(iter=nodevec.begin(); iter!=nodevec.end(); ++iter)
00877 {
00878 delete *iter;
00879 }
00880 nodevec.clear();
00881 fxTrendingFlags[nodeindex].clear();
00882 fbTrendingInit[nodeindex].clear();
00883 fxTrendHistoRefnames[nodeindex].clear();
00884 fxStatsFlags[nodeindex].clear();
00885 fbStatsInit[nodeindex].clear();
00886 fxStatHistoRefnames[nodeindex].clear();
00887 fxRateRecords[nodeindex].clear();
00888 fxRateSum[nodeindex].clear();
00889 fxRateCount[nodeindex].clear();
00890 fbDisplayRateTable=true;
00891
00892 }
00893
00894 void TGo4DabcMonitor::createLogServices(int nodeindex)
00895 {
00896 TGo4LockGuard gard(0,true);
00897
00898 QRegExp filter(dimServiceFilterEdit->text().trimmed());
00899 filter.setPatternSyntax(QRegExp::Wildcard);
00900 std::cout<<std::endl<< "---- Retrieving current DIM variables from node "<<fxDabcNodes[nodeindex].toLatin1().constData()<<" with filter:"<<filter.pattern().toLatin1().constData() <<std::endl;
00901
00902
00903 QString services=fxServices[nodeindex]->getString();
00904
00905
00906
00907 QStringList servlist = services.split(0x0A, QString::SkipEmptyParts);
00908 QString logservice="";
00909 for ( QStringList::Iterator sit = servlist.begin(); sit != servlist.end(); ++sit )
00910 {
00911 QString service=*sit;
00912 QString sformat=service.section('|',1,1);
00913 QString sname=service.section('|',0,0);
00914 QString scom=service.section('|',2,2);
00915 if(sname.contains("SERVICE_LIST")) continue;
00916 if(scom.contains("CMD")) continue;
00917 if(filter.indexIn(sname)<0) continue;
00918
00919
00920 if(sformat=="C")
00921 {
00922 TGo4DabcInfo* info= new TGo4DabcInfo(sname.toLatin1().constData(),1,"not available", this);
00923 }
00924 else if(sformat=="L")
00925 {
00926 TGo4DabcInfo* info= new TGo4DabcInfo(sname.toLatin1().constData(),1, (int) -1, this);
00927 }
00928 else
00929 {
00930 TGo4DabcInfo* info= new TGo4DabcInfo(sname.toLatin1().constData(),1, &gNolinkRateRecord , sizeof(dabc:: RateRec), sformat.toLatin1().constData(), this);
00931 }
00932 }
00933 }
00934
00935
00936
00937
00938
00939
00940
00944
00945
00946 void TGo4DabcMonitor::displayNodeTable()
00947 {
00948 TGo4LockGuard gard(0,true);
00949 fbTableBeingCreated=true;
00950
00951 if(fbRebuildNodeTable)
00952 {
00953
00954
00955 NodeTable->setRowCount(0);
00956 int maxnodes = fxDabcNodes.size();
00957 NodeTable->setRowCount(maxnodes);
00958 for(int ix=0; ix<maxnodes; ++ix)
00959 fillNodeTableRow(ix, ix, true);
00960 fbRebuildNodeTable=false;
00961 }
00962 else
00963 {
00964
00965 int tablesize = NodeTable->rowCount();
00966 int maxnodes = fxDabcNodes.size();
00967 if(maxnodes!=tablesize)
00968 {
00969 std::cout<<"!!!!!!!!!! NEVER COME HERE: table size "<<tablesize<<" does not match number of nodes "<<maxnodes <<std::endl;
00970 return;
00971 }
00972
00973 for(int ix=0; ix<maxnodes; ++ix)
00974 {
00975 int tableindex=-1;
00976 for(int j=0; j<tablesize;++j)
00977 {
00978 QString ixtext;
00979 if (NodeTable->item(j, DABCMON_NODE_INDEXCOL))
00980 ixtext = NodeTable->item(j, DABCMON_NODE_INDEXCOL)->text();
00981 int tix=ixtext.toInt();
00982 if(tix==ix)
00983 {
00984 tableindex=j;
00985 break;
00986 }
00987 }
00988 if(tableindex<0)
00989 {
00990 std::cout<<"!!!!!!!!!! NEVER COME HERE: could not find tableindex for "<<ix <<std::endl;
00991 continue;
00992 }
00993 else
00994 {
00995
00996 }
00997 fillNodeTableRow(tableindex, ix, false);
00998 }
00999 }
01000 ensurePolished();
01001 update();
01002 show();
01003 fbTableBeingCreated=false;
01004 }
01005
01006
01007 void TGo4DabcMonitor::fillNodeTableRow( int tableindex, int nodeindex, bool createnew )
01008 {
01009 NodeTable->setSortingEnabled(false);
01010
01011
01012
01013 NodeTable->setItem(tableindex, DABCMON_NODE_NODECOL, new QTableWidgetItem(fxDabcNodes[nodeindex]));
01014
01015 QPixmap pixmap = QPixmap(":/icons/eventitem.png").scaledToHeight(NodeTable->rowHeight(tableindex),Qt::SmoothTransformation);
01016
01017 QTableWidgetItem* item = 0;
01018 if(nodeindex>fxStateRecords.size())
01019 std::cout<<" !!!!!!!!!! nodeindex exceeds size of states "<<fxStateRecords.size()<<std::endl;
01020 QString col =fxStateRecords[nodeindex].fxColor.toLower();
01021
01022
01023
01024
01025
01026
01027 pixmap.fill(fxStateRecords[nodeindex].fxColor.toLower());
01028 item = new QTableWidgetItem(pixmap, fxStateRecords[nodeindex].fxState);
01029 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01030 NodeTable->setItem(tableindex, DABCMON_NODE_STATECOL, item);
01031 if(createnew) {
01032 item = new QTableWidgetItem(QString::number(nodeindex));
01033
01034
01035
01036 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01037 NodeTable->setItem(tableindex, DABCMON_NODE_INDEXCOL, item);
01038
01039 item = new QTableWidgetItem("Show" );
01040 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01041 item->setCheckState(fxShowRateFlags[nodeindex] ? Qt::Checked : Qt::Unchecked);
01042 NodeTable->setItem( tableindex,DABCMON_NODE_CHECKCOL, item);
01043
01044 item= new QTableWidgetItem("Dump");
01045 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01046 item->setCheckState(fxShowLogFlags[nodeindex] ? Qt::Checked : Qt::Unchecked);
01047 NodeTable->setItem(tableindex,DABCMON_NODE_LOGCOL, item);
01048 } else {
01049 QTableWidgetItem* checkitem= NodeTable->item(tableindex, DABCMON_NODE_CHECKCOL);
01050 if(checkitem)
01051 checkitem->setCheckState(fxShowRateFlags[nodeindex] ? Qt::Checked : Qt::Unchecked);
01052 else
01053 std::cout<<"!!!!!!!!!! NEVER COME HERE: wrong rate checktableitem at index "<<nodeindex <<std::endl;
01054 QTableWidgetItem* checklogitem = NodeTable->item(tableindex, DABCMON_NODE_LOGCOL);
01055 if(checklogitem)
01056 checklogitem->setCheckState(fxShowLogFlags[nodeindex] ? Qt::Checked : Qt::Unchecked);
01057 else
01058 std::cout<<"!!!!!!!!!! NEVER COME HERE: wrong logchecktableitem at index "<<nodeindex <<std::endl;
01059 }
01060 NodeTable->setSortingEnabled(true);
01061 }
01062
01063
01064
01065
01066 void TGo4DabcMonitor::displayRateTable()
01067 {
01068 TGo4LockGuard gard(0,true);
01069 fbTableBeingCreated=true;
01070
01071
01072 int numrates=0;
01073 int maxnodes=fxRateRecords.size();
01074 for(int ix=0; ix<maxnodes; ++ix)
01075 {
01076 numrates+=fxRateRecords[ix].size();
01077 }
01078 int tablesize = RateTable->rowCount();
01079 int tablecursor = -1;
01080 if(fbRebuildRateTable)
01081 {
01082
01083
01084
01085 RateTable->setRowCount(0);
01086 RateTable->setRowCount(numrates);
01087 int tableindex=0;
01088
01089 for(int ix=0; ix<maxnodes; ++ix)
01090 {
01091 std::vector<TGo4DabcRate> & rvec=fxRateRecords[ix];
01092
01093 for(int rix=0; rix<rvec.size();++rix)
01094 {
01095
01096 fillRateTableRow(tableindex, ix, rix, true);
01097 tableindex++;
01098
01099 }
01100 }
01101
01102 fbRebuildRateTable=false;
01103 }
01104 else
01105 {
01106
01107 if(numrates>tablesize)
01108 {
01109
01110
01111 tablecursor=tablesize;
01112
01113 RateTable->setRowCount(numrates);
01114 }
01115 else if(numrates<tablesize)
01116 {
01117
01118
01119 }
01120 else
01121 {
01122
01123 }
01124 tablesize = RateTable->rowCount();
01125 bool usedrows[tablesize];
01126 for(int t=0;t<tablesize;++t){usedrows[t]=false;}
01127 for(int nix=0; nix<maxnodes; ++nix)
01128 {
01129 std::vector<TGo4DabcRate> & rvec=fxRateRecords[nix];
01130 for(int rix=0; rix<rvec.size();++rix)
01131 {
01132
01133 int tableindex=-1;
01134 for(int j=0; j<tablesize;++j)
01135 {
01136 int tablenodeix=-1;
01137 int tablerateix=-1;
01138 if(!getRateIndices(j, tablenodeix, tablerateix)) continue;
01139 if(tablenodeix==nix && tablerateix==rix)
01140 {
01141 tableindex=j;
01142 break;
01143 }
01144 }
01145 if(tableindex<0)
01146 {
01147
01148
01149 if(tablecursor<0)
01150 {
01151 std::cout<<"!!!!!!!!!! NEVER COME HERE: tablecursor undefined for new entry ("<<nix<<","<<rix<<")" <<std::endl;
01152 continue;
01153 }
01154 fillRateTableRow(tablecursor, nix, rix, true);
01155 usedrows[tablecursor]=true;
01156 tablecursor++;
01157 }
01158 else
01159 {
01160
01161 usedrows[tableindex]=true;
01162 fillRateTableRow(tableindex, nix, rix, false);
01163 }
01164 }
01165 }
01166 int offset=0;
01167 for(int rownum=0;rownum<tablesize;++rownum)
01168 {
01169 if(usedrows[rownum]==false)
01170 {
01171
01172 RateTable->removeRow(rownum-offset);
01173
01174 offset++;
01175 }
01176 }
01177 }
01178 ensurePolished();
01179 update();
01180 show();
01181 fbTableBeingCreated=false;
01182 }
01183
01184 void TGo4DabcMonitor::fillRateTableRow( int tableindex, int nodeindex, int rateindex, bool createnew )
01185 {
01186 RateTable->setSortingEnabled(false);
01187
01188 std::vector<TGo4DabcRate> & rvec=fxRateRecords[nodeindex];
01189 QString val;
01190 val.setNum(rvec[rateindex].fxRate);
01191 val+=" "+rvec[rateindex].fxUnits;
01192
01193 QTableWidgetItem* item = 0;
01194 if(rvec[rateindex].fxRate<0) {
01195 QPixmap pixmap = QPixmap(":/icons/info1.png").scaledToHeight(RateTable->rowHeight(tableindex),Qt::SmoothTransformation);
01196 item = new QTableWidgetItem( QIcon(pixmap), val);
01197 } else
01198 item = new QTableWidgetItem(val);
01199 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01200 RateTable->setItem(tableindex, DABCMON_RATE_RATECOL, item);
01201
01202 if(createnew) {
01203 QString namestring=rvec[rateindex].fxName.section('/',1);
01204 QTableWidgetItem* item = new QTableWidgetItem(namestring);
01205 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01206 RateTable->setItem(tableindex, DABCMON_RATE_NAMECOL, item);
01207
01208 QString indexstring = QString::number(nodeindex)+":"+QString::number(rateindex);
01209 item = new QTableWidgetItem(indexstring);
01210 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01211 RateTable->setItem(tableindex, DABCMON_RATE_INDEXCOL, item);
01212
01213 item = new QTableWidgetItem("histogram" );
01214 item->setCheckState(fxTrendingFlags[nodeindex].at(rateindex) ? Qt::Checked : Qt::Unchecked);
01215 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01216 RateTable->setItem( tableindex,DABCMON_RATE_TRENDCOL, item);
01217
01218 item = new QTableWidgetItem ("histogram" );
01219 item->setCheckState(fxStatsFlags[nodeindex].at(rateindex) ? Qt::Checked : Qt::Unchecked );
01220 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
01221 RateTable->setItem( tableindex,DABCMON_RATE_STATSCOL, item);
01222 } else {
01223 QTableWidgetItem* trendcheckitem= RateTable->item(tableindex, DABCMON_RATE_TRENDCOL);
01224 if(trendcheckitem)
01225 trendcheckitem->setCheckState(fxTrendingFlags[nodeindex].at(rateindex) ? Qt::Checked : Qt::Unchecked);
01226 else
01227 std::cout<<"!!!!!!!!!! NEVER COME HERE: wrong trend checktableitem at table index "<<tableindex <<std::endl;
01228 QTableWidgetItem* statcheckitem = RateTable->item(tableindex, DABCMON_RATE_STATSCOL);
01229 if(statcheckitem)
01230 statcheckitem->setCheckState(fxStatsFlags[nodeindex].at(rateindex) ? Qt::Checked : Qt::Unchecked);
01231 else
01232 std::cout<<"!!!!!!!!!! NEVER COME HERE: wrong stat checktableitem at table index "<<tableindex <<std::endl;
01233 }
01234 RateTable->setSortingEnabled(true);
01235 }
01236
01237
01238 bool TGo4DabcMonitor::getRateIndices( int tablerow, int & nodeix, int & rateix )
01239 {
01240 if (RateTable->item(tablerow, DABCMON_RATE_INDEXCOL)==0) return false;
01241
01242 QString ixtext= RateTable->item(tablerow, DABCMON_RATE_INDEXCOL)->text();
01243 QString nstring=ixtext.section( ':', 0,0);
01244 if(nstring.isEmpty()) return false;
01245 nodeix=nstring.toInt();
01246 QString rstring=ixtext.section( ':', 1,1);
01247 rateix=rstring.toInt();
01248 return true;
01249 }
01250
01251
01252
01253
01254 void TGo4DabcMonitor::displaySampleHistograms()
01255 {
01256 TGo4LockGuard gard(0,true);
01257
01258 for(int nodeix=0;nodeix<fxTrendingFlags.size();++nodeix)
01259 {
01260 std::vector<bool> & trendvec=fxTrendingFlags[nodeix];
01261 if(nodeix>fxStatsFlags.size())
01262 {
01263 std::cout <<"--NEVER COME HERE: node index mismatch in displaySampleHistograms for nix="<< nodeix<<std::endl;
01264 return;
01265 }
01266 std::vector<bool> & statsvec=fxStatsFlags[nodeix];
01267 for(int rateix=0; rateix<trendvec.size();++rateix)
01268 {
01269 bool trending=trendvec[rateix];
01270 if(rateix>statsvec.size())
01271 {
01272 std::cout <<"--NEVER COME HERE: rate index mismatch in displaySampleHistograms for rix)"<< rateix<<std::endl;;
01273 return;
01274 }
01275 bool statisting=statsvec[rateix];
01276 if(trending || statisting)
01277 {
01278
01279 if(nodeix>fxRateQueues.size())
01280 {
01281 std::cout <<"--NEVER COME HERE: node index mismatch in displaySampleHistograms queues for nix="<< nodeix<<std::endl;
01282 return;
01283 }
01284 std::vector< std::deque <float> > & qvec =fxRateQueues[nodeix];
01285 if(rateix>qvec.size())
01286 {
01287 std::cout <<"--NEVER COME HERE: rate index mismatch in displaySampleHistograms queues for rix)"<< rateix<<std::endl;;
01288 return;
01289 }
01290 std::deque<float> &ratequeue = qvec[rateix];
01291
01292 while (!ratequeue.empty())
01293 {
01294 float val=ratequeue.front();
01295 ratequeue.pop_front();
01296
01297 fxRateSum[nodeix].at(rateix)+=val;
01298 fxRateCount[nodeix].at(rateix)++;
01299 if(!TrendSampleCheck->isChecked()) continue;
01300 if(trending)
01301 updateTrending(nodeix,rateix, 0, val);
01302 if(statisting)
01303 updateStats(nodeix,rateix,0, val);
01304 }
01305 }
01306 }
01307 }
01308 }
01309
01310
01311 void TGo4DabcMonitor::displayAverageHistograms()
01312 {
01313 TGo4LockGuard gard(0,true);
01314 if(!fbHistogramming) return;
01315
01316 for(int nodeix=0;nodeix<fxTrendingFlags.size();++nodeix)
01317 {
01318 std::vector<bool> & trendvec=fxTrendingFlags[nodeix];
01319 if(nodeix>fxStatsFlags.size())
01320 {
01321 std::cout <<"--NEVER COME HERE: node index mismatch in displaySampleHistograms for nix="<< nodeix<<std::endl;
01322 return;
01323 }
01324 std::vector<bool> & statsvec=fxStatsFlags[nodeix];
01325 for(int rateix=0; rateix<trendvec.size();++rateix)
01326 {
01327 bool trending=trendvec[rateix];
01328 if(rateix>statsvec.size())
01329 {
01330 std::cout <<"--NEVER COME HERE: rate index mismatch in displaySampleHistograms for rix)"<< rateix<<std::endl;;
01331 return;
01332 }
01333 bool statisting=statsvec[rateix];
01334 if(trending || statisting)
01335 {
01336 float val=-2;
01337 float sum= fxRateSum[nodeix].at(rateix);
01338 unsigned int count= fxRateCount[nodeix].at(rateix);
01339 if(count!=0) val=sum/count;
01340 fxRateSum[nodeix].at(rateix)=0.;
01341 fxRateCount[nodeix].at(rateix)=0;
01342 if(trending)
01343 updateTrending(nodeix,rateix,1, val);
01344 if(statisting)
01345 updateStats(nodeix,rateix,1,val);
01346 }
01347 }
01348 }
01349 }
01350
01351
01352
01353 void TGo4DabcMonitor::displayAll()
01354 {
01355
01356 TGo4LockGuard gard(0,true);
01357 QDateTime timestamp;
01358 timestamp.setTime_t (fxLastTimestamp);
01359
01360 DateLabel->setText(timestamp.toString());
01361 if(fbDisplayNodeTable)
01362 {
01363 displayNodeTable();
01364 fbDisplayNodeTable=false;
01365 }
01366 if(fbDisplayRateTable)
01367 {
01368 displayRateTable();
01369 fbDisplayRateTable=false;
01370 }
01371
01372
01373 if(fbDisplayHistograms)
01374 {
01375 displaySampleHistograms();
01376 fbDisplayHistograms=false;
01377 }
01378
01379 }
01380
01384
01385
01386
01387 void TGo4DabcMonitor::updateTrending( int nodeix, int rateix, int hisix, double value)
01388 {
01389 QString & refname= fxTrendHistoRefnames[nodeix].at(rateix).at(hisix);
01390 QString name=fxRateRecords[nodeix].at(rateix).fxName;
01391 QString foldername=name.section( '/', 1,2);
01392 name=name.section( '/', 3);
01393 name.replace( QChar('/'), "-" );
01394 switch(hisix)
01395 {
01396 case 0:
01397 default:
01398 name=name+"-TrendingFast";
01399 break;
01400 case 1:
01401 name=name+"-TrendingAverage";
01402 break;
01403 };
01404 foldername.replace( QChar('/'), "-" );
01405 QString & title=fxRateRecords[nodeix].at(rateix).fxUnits;
01406
01407
01408 TH1* his=0;
01409 TGo4Slot* histoslot=0;
01410 if(!fbTrendingInit[nodeix].at(rateix).at(hisix)) histoslot=Browser()->BrowserSlot(refname.toLatin1().constData());
01411 if(histoslot==0)
01412 {
01413 Axis_t lo,up;
01414 if(fbTrendingForward)
01415 {
01416 lo=0;
01417 switch(hisix)
01418 {
01419 case 0:
01420 default:
01421 up=1*fiTrendBins;
01422 break;
01423 case 1:
01424 up=1*fiTrendBins*FrequencyBox->value();
01425 break;
01426 };
01427 }
01428 else
01429 {
01430 switch(hisix)
01431 {
01432 case 0:
01433 default:
01434 lo=-1*fiTrendBins;
01435 break;
01436 case 1:
01437 lo=-1*fiTrendBins*FrequencyBox->value();
01438 break;
01439 };
01440 up=0;
01441 }
01442 his=new TH1F(name.toLatin1().constData(), title.toLatin1().constData(), fiTrendBins,lo,up);
01443 TAxis* xax=his->GetXaxis();
01444 switch(hisix)
01445 {
01446 case 0:
01447 default:
01448 xax->SetTitle("updates");
01449 break;
01450 case 1:
01451 xax->SetTitle("s");
01452 break;
01453 };
01454 xax->CenterTitle();
01455
01456
01457 TGo4Slot* hisdataslot=Browser()->DataSlot(refname.toLatin1().constData());
01458 if(hisdataslot)
01459 {
01460 hisdataslot->AssignObject(his,true);
01461 }
01462 else
01463 {
01464
01465 QString folder="DABC/"+foldername;
01466 refname=Browser()->SaveToMemory(folder.toLatin1().constData(), his, true);
01467 }
01468 histoslot=Browser()->BrowserSlot(refname.toLatin1().constData());
01469 }
01470 else
01471 {
01472 his=dynamic_cast<TH1*>(histoslot->GetAssignedObject());
01473 }
01474 IncTrending(his,value,fbTrendingForward);
01475 if(histoslot)
01476 {
01477 histoslot->ForwardEvent(histoslot, TGo4Slot::evObjUpdated);
01478 Browser()->SetItemTimeDate(histoslot);
01479 fbTrendingInit[nodeix].at(rateix).at(hisix)=false;
01480 }
01481 }
01482
01483
01484 void TGo4DabcMonitor::IncTrending( TH1 * histo, double value, bool forwards )
01485 {
01486 if(histo==0) return;
01487 int bins=histo->GetNbinsX();
01488
01489 int j,dj;
01490 if(forwards)
01491 dj=-1;
01492 else
01493 dj=+1;
01494 for(int i=0;i<bins;i++)
01495 {
01496 if(forwards)
01497 j=bins-i;
01498 else
01499 j=i;
01500 double oldval=histo->GetBinContent(j+dj);
01501 histo->SetBinContent(j,oldval);
01502 }
01503 histo->SetBinContent(j+dj,value);
01504 }
01505
01506
01507
01508 void TGo4DabcMonitor::updateStats( int nodeix, int rateix, int hix , double value)
01509 {
01510
01511 QString & refname= fxStatHistoRefnames[nodeix].at(rateix).at(hix);
01512 QString name=fxRateRecords[nodeix].at(rateix).fxName;
01513 QString foldername=name.section( '/', 1,2);
01514 name=name.section( '/', 3);
01515 name.replace( QChar('/'), "-" );
01516 switch(hix)
01517 {
01518 case 0:
01519 default:
01520 name=name+"-StatsFast";
01521 break;
01522 case 1:
01523 name=name+"-StatsAverage";
01524 break;
01525 };
01526 foldername.replace( QChar('/'), "-" );
01527 QString title="counts";
01528 QString & xtitle=fxRateRecords[nodeix].at(rateix).fxUnits;
01529
01530 TH1* his=0;
01531 TGo4Slot* histoslot=0;
01532 if(! fbStatsInit[nodeix].at(rateix).at(hix)) histoslot=Browser()->BrowserSlot(refname.toLatin1().constData());
01533 if(histoslot==0)
01534 {
01535 Axis_t lo,up;
01536 lo=fxRateRecords[nodeix].at(rateix).fxLower;
01537 up=fxRateRecords[nodeix].at(rateix).fxUpper;
01538 if(lo==up)
01539 {
01540 lo=0;
01541 up=100;
01542
01543 }
01544 his=new TH1F(name.toLatin1().constData(),title.toLatin1().constData(),fiStatBins,lo,up);
01545 TAxis* xax=his->GetXaxis();
01546 xax->SetTitle(xtitle.toLatin1().constData());
01547 xax->CenterTitle();
01548 TGo4Slot* hisdataslot=Browser()->DataSlot(refname.toLatin1().constData());
01549 if(hisdataslot)
01550 {
01551 hisdataslot->AssignObject(his,true);
01552 }
01553 else
01554 {
01555
01556 QString folder="DABC/"+foldername;
01557 refname=Browser()->SaveToMemory(folder.toLatin1().constData(), his, true);
01558 }
01559 histoslot=Browser()->BrowserSlot(refname.toLatin1().constData());
01560 }
01561 else
01562 {
01563 his=dynamic_cast<TH1*>(histoslot->GetAssignedObject());
01564 }
01565 his->Fill(value);
01566 if(histoslot)
01567 {
01568 histoslot->ForwardEvent(histoslot, TGo4Slot::evObjUpdated);
01569 Browser()->SetItemTimeDate(histoslot);
01570 fbStatsInit[nodeix].at(rateix).at(hix)=false;
01571 }
01572 }
01573
01574
01575
01576
01577