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