Changeset 232 for Evidence/Edd
- Timestamp:
- 06/30/10 08:48:02 (14 years ago)
- Location:
- Evidence/Edd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Edd/Edd.cc
r231 r232 64 64 65 65 W->setStatusTip(Status); 66 if (W->parent() == NULL) W->setToolTip(Status);67 66 68 67 return(Time != -1); … … 132 131 } 133 132 Text = Text.section(' ', 1); 134 } 135 else if (Format[0].toUpper() != 'C' ) Text = Text.section(' ', Index, Index);133 } 134 else if (Format[0].toUpper() != 'C' && Format != "I:1;C") Text = Text.section(' ', Index, Index); 136 135 137 136 if (!ShowAsTime) setText(Text); … … 233 232 ////////////////////////////////// 234 233 235 EddPlot::EddPlot(QString DIMService, int Index, QWidget *P): EddBasePlot(P) {234 EddPlot::EddPlot(QString Service, int Index, QWidget *P): EddBasePlot(P) { 236 235 237 236 // Widget properties … … 247 246 // Connect to DIM handler 248 247 if (connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString))) == false) { 249 printf("Failed connection for %s\n", DIMService.toAscii().data());248 printf("Failed connection for %s\n", Service.toAscii().data()); 250 249 } 251 250 … … 259 258 260 259 // DIM client 261 if (! DIMService.isEmpty()) AddService(DIMService, Index);260 if (!Service.isEmpty()) AddService(Service, Index); 262 261 } 263 262 … … 328 327 } 329 328 330 // Appen data only if service available329 // Append data only if service available 331 330 if (SetStatus(this, Name, Time, Format)) { 332 331 QString Txt = Text; … … 597 596 // Rescale y axis (increase range if selected rectangle larger than axis area) 598 597 if (R.right() < 0) { 599 if ( R.top() < plotLayout()->canvasRect().top()) {598 if (yMouse.maxValue() > axisScaleDiv(QwtPlot::yLeft)->upperBound()) { 600 599 yMouse.setMaxValue(yMouse.maxValue() + yPlot.width()); 601 600 } 602 if ( R.bottom() > plotLayout()->canvasRect().bottom()) {601 if (yMouse.minValue() < axisScaleDiv(QwtPlot::yLeft)->lowerBound()) { 603 602 yMouse.setMinValue(yMouse.minValue() - yPlot.width()); 604 603 } … … 609 608 // Rescale x axis (increase range if selected rectangle larger than axis area) 610 609 if (R.top() > plotLayout()->canvasRect().height()) { 611 if (R.left() < plotLayout()->canvasRect().left()) { 610 if (xMouse.maxValue() > axisScaleDiv(QwtPlot::xBottom)->upperBound()) { 611 xMouse.setMaxValue(xMouse.maxValue() + xPlot.width()); 612 } 613 if (xMouse.minValue() < axisScaleDiv(QwtPlot::xBottom)->lowerBound()) { 612 614 xMouse.setMinValue(xMouse.minValue() - xPlot.width()); 613 615 } 614 if (R.right() > plotLayout()->canvasRect().right()) { 615 xMouse.setMaxValue(xMouse.maxValue() + xPlot.width()); 616 } 616 617 617 setAxisScale(QwtPlot::xBottom, xMouse.minValue(), xMouse.maxValue()); 618 618 } … … 741 741 742 742 if (!Pure) { 743 // Get history for this service 743 // Get history for this service 744 744 const struct EvidenceHistory::Item *R; 745 745 class EvidenceHistory *Hist; … … 748 748 while ((R=Hist->Next()) != NULL) { 749 749 moveCursor (QTextCursor::Start); 750 insertPlainText(QString("(")+QDateTime::fromTime_t(R->Time).toString()+") " );751 insertPlainText(QString((char *) R->Data) + "\n");752 } 750 insertPlainText(QString("(")+QDateTime::fromTime_t(R->Time).toString()+") " + 751 QString::fromStdString(EvidenceServer::ToString(Hist->GetFormat(), (void *) R->Data, R->Size)) + "\n"); 752 } 753 753 } 754 754 Handler->DropHistory(Name); … … 814 814 } 815 815 816 // Destructor 816 817 EddDim::~EddDim() { 817 818 818 for (int i=0; i<HistoryList.size(); i++) delete HistoryList[i].HistClass; 819 QList<QString> L = HistoryList.keys(); 820 for(int i=0; i<L.size(); i++) delete HistoryList[L[i]].HistClass; 819 821 820 822 delete Mutex; … … 827 829 QMutexLocker Locker(Mutex); 828 830 829 // If already subscribed to service, increase usage count 830 for (int i=0; i<ServiceList.size(); i++) if (ServiceList[i].Name == Name) { 831 ServiceList[i].Count++; 832 // If service already received, reemit for new subscriber 833 if (!ServiceList[i].ByteArray.isEmpty()) { 834 YEP(Name, ServiceList[i].TimeStamp, ServiceList[i].ByteArray, ServiceList[i].Format, ServiceList[i].Text); 835 } 836 else YEP(Name, -1); 831 // If already subscribed to service, increase usage count and reemit data for new subscriber 832 if (ServiceList.contains(Name)) { 833 ServiceList[Name].Count++; 834 YEP(Name, ServiceList[Name].TimeStamp, ServiceList[Name].ByteArray, ServiceList[Name].Format, ServiceList[Name].Text); 837 835 return; 838 836 } 839 837 840 838 // Create new entry in service list 841 struct Item New; 842 New.Name = Name; 843 New.ByteArray = QByteArray(); 844 New.Count = 1; 845 New.DIMService = new DimStampedInfo(Name.toAscii().data(), INT_MAX, NO_LINK, this); 846 ServiceList.append(New); 847 839 ServiceList[Name].ByteArray = QByteArray(); 840 ServiceList[Name].TimeStamp = -1; 841 ServiceList[Name].Count = 1; 842 ServiceList[Name].DIMService = new DimStampedInfo(Name.toAscii().data(), INT_MAX, NO_LINK, this); 848 843 return; 849 844 } … … 855 850 QMutexLocker Locker(Mutex); 856 851 857 for (int i=0; i<ServiceList.size(); i++) if (ServiceList[i].Name == Name) { 858 ServiceList[i].Count--; 859 if (ServiceList[i].Count == 0) { 860 delete ServiceList[i].DIMService; 861 ServiceList.removeAt(i); 862 return; 863 } 852 if (ServiceList.contains(Name)) ServiceList[Name].Count--; 853 854 if (ServiceList[Name].Count == 0) { 855 delete ServiceList[Name].DIMService; 856 ServiceList.remove(Name); 857 return; 864 858 } 865 859 } … … 869 863 870 864 // History already available (only request again if too old) 871 for (int i=0; i<HistoryList.size(); i++) if (HistoryList[i].Name == Name) { 872 HistoryList[i].Count++; 873 if (time(NULL)-HistoryList[i].LastUpdate < 5) { 874 HistoryList[i].HistClass->Rewind(); 875 return HistoryList[i].HistClass; 865 if (HistoryList.contains(Name)) { 866 HistoryList[Name].Count++; 867 868 if (time(NULL)-HistoryList[Name].LastUpdate < 5) { 869 HistoryList[Name].HistClass->Rewind(); 870 return HistoryList[Name].HistClass; 876 871 } 877 HistoryList[ i].LastUpdate = time(NULL);878 if (HistoryList[ i].HistClass->GetHistory()) return HistoryList[i].HistClass;872 HistoryList[Name].LastUpdate = time(NULL); 873 if (HistoryList[Name].HistClass->GetHistory()) return HistoryList[Name].HistClass; 879 874 else return NULL; 880 875 } 881 876 882 877 // Create new history class 883 struct HistItem New; 884 New.Name = Name; 885 New.HistClass = new EvidenceHistory(Name.toStdString()); 886 New.Count = 1; 887 New.LastUpdate = time(NULL); 888 HistoryList.append(New); 889 890 if (New.HistClass->GetHistory()) return New.HistClass; 878 HistoryList[Name].HistClass = new EvidenceHistory(Name.toStdString()); 879 HistoryList[Name].Count = 1; 880 HistoryList[Name].LastUpdate = time(NULL); 881 882 if (HistoryList[Name].HistClass->GetHistory()) return HistoryList[Name].HistClass; 891 883 else return NULL; 892 884 } … … 895 887 void EddDim::DropHistory(QString Name) { 896 888 897 for (int i=0; i<HistoryList.size(); i++) { 898 if (HistoryList[i].Name == Name) HistoryList[i].Count--; 899 } 889 if (HistoryList.contains(Name)) HistoryList[Name].Count--; 900 890 } 901 891 … … 903 893 void EddDim::UpdateStatistics() { 904 894 905 // Remove unused histories after not less than 5 seconds906 for (int i=0; i<HistoryList.size(); i++) {907 if ((HistoryList[i].Count <= 0) && (time(NULL)-HistoryList[i].LastUpdate) > 5) {908 delete HistoryList[i].HistClass;909 HistoryList.removeAt(i);910 }911 }912 913 895 // Lock before accessing internal variables 914 896 QMutexLocker Locker(Mutex); 915 897 898 // Remove unused histories after not less than 5 seconds 899 QList<QString> L = HistoryList.keys(); 900 for(int i=0; i<L.size(); i++) { 901 if ((HistoryList[L[i]].Count <= 0) && (time(NULL)-HistoryList[L[i]].LastUpdate) > 5) { 902 delete HistoryList[L[i]].HistClass; 903 HistoryList.remove(L[i]); 904 } 905 } 906 916 907 float Rate = Volume/1024.0/10; 917 908 Volume = 0; 918 909 YEP("Edd/Rate_kBSec", time(NULL), QByteArray::number(Rate), "F", QString::number(Rate)); 919 Volume = 0; 920 } 921 922 // Store service information for usage by Subscribe() and update statistics 910 } 911 912 // Store service information for usage by Subscribe(), update statistics and emit signal to widgets 923 913 void EddDim::Update(QString Name, int Time, QByteArray Data, QString Format, QString Text) { 924 914 … … 926 916 QMutexLocker Locker(Mutex); 927 917 928 for (int i=0; i<ServiceList.size(); i++) if (ServiceList[i].Name == Name) { 929 ServiceList[i].TimeStamp = Time; 930 ServiceList[i].ByteArray = Data; 931 ServiceList[i].Format = Format; 932 ServiceList[i].Text = Text; 933 } 934 935 // Update statistics only for Dim services 918 // Store service data 919 if (ServiceList.contains(Name)) { 920 ServiceList[Name].TimeStamp = Time; 921 ServiceList[Name].ByteArray = Data; 922 ServiceList[Name].Format = Format; 923 ServiceList[Name].Text = Text; 924 } 925 926 // Update statistics only for actual Dim services 936 927 if (!Name.startsWith("Edd/")) Volume += Data.size(); 937 928 938 YEP(Name, Time, Data, Format, Text); 929 // Emit signal to all widgets 930 YEP(Name, Time, Data, Format, Text); 939 931 } 940 932 941 933 // Handling of DIM service update 934 // No locking allowed. Signal triggers only EddDim::Update() when the main event loop is idle. 942 935 void EddDim::infoHandler() { 943 936 … … 945 938 else { 946 939 INT(getInfo()->getName(), getInfo()->getTimestamp(), QByteArray((char *) getInfo()->getData(), 947 getInfo()->getSize()), getInfo()->getFormat(), QString::fromStdString(EvidenceServer::ToString(getInfo() )));940 getInfo()->getSize()), getInfo()->getFormat(), QString::fromStdString(EvidenceServer::ToString(getInfo()->getFormat(), getInfo()->getData(), getInfo()->getSize()))); 948 941 } 949 942 } … … 1235 1228 EddText *Text = new EddText("Bias/ConsoleOut", true); 1236 1229 Text->setFixedWidth(400); 1237 Layout->addWidget(Text, 11, 0, 4, 4); 1230 Layout->addWidget(Text, 11, 0, 4, 4); 1238 1231 } 1239 1232 … … 1249 1242 EddPlot *Plot = new EddPlot(); 1250 1243 for (int i=0; i<36; i++) { 1251 Line = new EddLineDisplay(" drsdaq/Average", i);1244 Line = new EddLineDisplay("Feedback/Average", i); 1252 1245 Line->setMaximumWidth(60); 1253 Layout->addWidget(Line, i%9+ 1, 0+i/9, 1, 1);1254 Plot->AddService(" drsdaq/Average", i);1246 Layout->addWidget(Line, i%9+2, 0+i/9, 1, 1); 1247 Plot->AddService("Feedback/Average", i); 1255 1248 } 1256 1249 Layout->addWidget(Plot, 0, 4, 12, 10); 1257 1258 //Graph = new EddPlot();1259 //for (int i=0; i<36; i++) {1260 //Text = Text.sprintf("Feedback/Sigma/ID%.2d/%.2d-%.3d",i/16, (i%16)/8, i%8);1261 //Graph->AddService(Text);1262 //}1263 //FeedbackLayout->addWidget(Graph, 10, 0, 10, 3);1264 1250 1265 1251 Line = new EddLineDisplay("drsdaq/Message"); 1266 1252 Line->setMaximumWidth(200); 1267 1253 Layout->addWidget(Line, 0, 0, 1, 2); 1268 Line = new EddLineDisplay("drsdaq/Count"); 1254 1255 Line = new EddLineDisplay("Feedback/State"); 1256 Line->setMaximumWidth(150); 1257 Layout->addWidget(Line, 1, 0, 1, 2); 1258 Line = new EddLineDisplay("Feedback/Count"); 1269 1259 Line->setMaximumWidth(60); 1270 Layout->addWidget(Line, 0, 2);1260 Layout->addWidget(Line, 1, 2); 1271 1261 1272 1262 QWidget *Button = new QPushButton("Details"); 1273 Layout->addWidget(Button, 1 0, 0, 1, 1);1263 Layout->addWidget(Button, 12, 0, 1, 1); 1274 1264 connect(Button, SIGNAL(pressed()), SLOT(FeedbackDetails())); 1275 1265 … … 1278 1268 void TP_Feedback::FeedbackDetails() { 1279 1269 1280 setAttribute(Qt::WA_DeleteOnClose); 1270 QMainWindow *M = new QMainWindow; 1271 M->setCentralWidget(new QWidget); 1272 M->setStatusBar(new QStatusBar(M)); 1273 M->setWindowTitle("Edd - Feedback Details"); 1274 M->setAttribute(Qt::WA_DeleteOnClose); 1275 1276 QGridLayout *Layout = new QGridLayout(M->centralWidget()); 1281 1277 EddLineDisplay *Line; 1282 QWidget *Widget = new QWidget();1283 QGridLayout *Layout = new QGridLayout(Widget);1284 1278 EddPlot *Plot = new EddPlot(); 1279 1285 1280 for (int i=0; i<36; i++) { 1286 Line = new EddLineDisplay("drsdaq/Sigma", i); 1287 Line->setMaximumWidth(50); 1288 Layout->addWidget(Line, i%9+1, 0+i/9, 1, 1); 1289 Plot->AddService("drsdaq/Sigma", i); 1290 } 1291 Layout->addWidget(Plot, 0, 4, 12, 10); 1292 1293 Widget->show(); 1281 Line = new EddLineDisplay("Feedback/Sigma", i); 1282 Line->setMaximumWidth(60); 1283 Layout->addWidget(Line, i%9, 0+i/9, 1, 1); 1284 Plot->AddService("Feedback/Sigma", i); 1285 1286 Line = new EddLineDisplay("Feedback/Target", i); 1287 Line->setMaximumWidth(60); 1288 Layout->addWidget(Line, i%9+10, 0+i/9, 1, 1); 1289 1290 Line = new EddLineDisplay("Feedback/Response", i); 1291 Line->setMaximumWidth(60); 1292 Layout->addWidget(Line, i%9+20, 0+i/9, 1, 1); 1293 } 1294 Layout->addWidget(Plot, 0, 4, 30, 12); 1295 1296 M->show(); 1294 1297 } 1295 1298 -
Evidence/Edd/Edd.h
r231 r232 36 36 bool SetStatus(QWidget *, QString, int, QString, int = -1); 37 37 38 38 39 // Base class for Edd plot 39 40 // DeleteCurve() is pure virtual and needs to be implemented iin the application class … … 213 214 private: 214 215 struct Item { 215 QString Name;216 216 DimStampedInfo *DIMService; 217 217 int Count; … … 221 221 QString Text; 222 222 }; 223 Q List<Item> ServiceList;223 QMap<QString, struct Item> ServiceList; 224 224 QMutex *Mutex; 225 225 226 226 struct HistItem { 227 QString Name;228 227 int Count; 229 228 int LastUpdate; 230 229 class EvidenceHistory *HistClass; 231 230 }; 232 Q List<HistItem> HistoryList;231 QMap<QString, struct HistItem> HistoryList; 233 232 234 233 long long Volume;
Note:
See TracChangeset
for help on using the changeset viewer.