Changeset 232 for Evidence/Edd


Ignore:
Timestamp:
06/30/10 08:48:02 (14 years ago)
Author:
ogrimm
Message:
Made Lock()/Unlock() public, automatic configuration tracking for Bridge
Location:
Evidence/Edd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Edd/Edd.cc

    r231 r232  
    6464
    6565  W->setStatusTip(Status);
    66   if (W->parent() == NULL) W->setToolTip(Status);
    6766 
    6867  return(Time != -1);
     
    132131    }
    133132        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);
    136135
    137136  if (!ShowAsTime) setText(Text);
     
    233232//////////////////////////////////
    234233
    235 EddPlot::EddPlot(QString DIMService, int Index, QWidget *P): EddBasePlot(P) {
     234EddPlot::EddPlot(QString Service, int Index, QWidget *P): EddBasePlot(P) {
    236235
    237236  // Widget properties
     
    247246  // Connect to DIM handler
    248247  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());
    250249  }
    251250
     
    259258
    260259  // DIM client
    261   if (!DIMService.isEmpty()) AddService(DIMService, Index);
     260  if (!Service.isEmpty()) AddService(Service, Index);
    262261}
    263262
     
    328327        }
    329328
    330         // Appen data only if service available
     329        // Append data only if service available
    331330        if (SetStatus(this, Name, Time, Format)) {
    332331          QString Txt = Text;
     
    597596  // Rescale y axis (increase range if selected rectangle larger than axis area)
    598597  if (R.right() < 0) {
    599         if (R.top() < plotLayout()->canvasRect().top()) {
     598        if (yMouse.maxValue() > axisScaleDiv(QwtPlot::yLeft)->upperBound()) {
    600599          yMouse.setMaxValue(yMouse.maxValue() + yPlot.width());
    601600        }
    602         if (R.bottom() > plotLayout()->canvasRect().bottom()) {
     601        if (yMouse.minValue() < axisScaleDiv(QwtPlot::yLeft)->lowerBound()) {
    603602          yMouse.setMinValue(yMouse.minValue() - yPlot.width());
    604603        }
     
    609608  // Rescale x axis (increase range if selected rectangle larger than axis area)
    610609  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()) {
    612614          xMouse.setMinValue(xMouse.minValue() - xPlot.width());
    613615        }
    614         if (R.right() > plotLayout()->canvasRect().right()) {
    615           xMouse.setMaxValue(xMouse.maxValue() + xPlot.width());
    616         }
     616
    617617        setAxisScale(QwtPlot::xBottom, xMouse.minValue(), xMouse.maxValue());
    618618  }
     
    741741
    742742  if (!Pure) {
    743         // Get history for this service 
     743        // Get history for this service
    744744        const struct EvidenceHistory::Item *R;
    745745        class EvidenceHistory *Hist;
     
    748748          while ((R=Hist->Next()) != NULL) {
    749749                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          }     
    753753        }
    754754        Handler->DropHistory(Name);
     
    814814}
    815815
     816// Destructor
    816817EddDim::~EddDim() {
    817818
    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;
    819821
    820822  delete Mutex;
     
    827829  QMutexLocker Locker(Mutex);
    828830
    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);
    837835        return;
    838836  }
    839837
    840838  // 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);
    848843  return;
    849844}
     
    855850  QMutexLocker Locker(Mutex);
    856851
    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;
    864858  }
    865859}
     
    869863
    870864  // 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;
    876871        }
    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;
    879874        else return NULL;
    880875  }
    881876
    882877  // 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;
    891883  else return NULL;
    892884}
     
    895887void EddDim::DropHistory(QString Name) {
    896888
    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--;
    900890}
    901891
     
    903893void EddDim::UpdateStatistics() {
    904894
    905   // Remove unused histories after not less than 5 seconds
    906   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 
    913895  // Lock before accessing internal variables
    914896  QMutexLocker Locker(Mutex);
    915897
     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 
    916907  float Rate = Volume/1024.0/10;
    917 
     908  Volume = 0;
    918909  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
    923913void EddDim::Update(QString Name, int Time, QByteArray Data, QString Format, QString Text) {
    924914
     
    926916  QMutexLocker Locker(Mutex);
    927917
    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
    936927  if (!Name.startsWith("Edd/")) Volume += Data.size();
    937928 
    938   YEP(Name, Time, Data, Format, Text); 
     929  // Emit signal to all widgets
     930  YEP(Name, Time, Data, Format, Text);
    939931}
    940932
    941933// Handling of DIM service update
     934// No locking allowed. Signal triggers only EddDim::Update() when the main event loop is idle.
    942935void EddDim::infoHandler() {
    943936
     
    945938  else {
    946939        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())));
    948941  }
    949942}
     
    12351228  EddText *Text = new EddText("Bias/ConsoleOut", true);
    12361229  Text->setFixedWidth(400);
    1237   Layout->addWidget(Text, 11, 0, 4, 4);     
     1230  Layout->addWidget(Text, 11, 0, 4, 4);
    12381231}
    12391232
     
    12491242  EddPlot *Plot = new EddPlot();
    12501243  for (int i=0; i<36; i++) {
    1251     Line = new EddLineDisplay("drsdaq/Average", i);
     1244    Line = new EddLineDisplay("Feedback/Average", i);
    12521245        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);
    12551248  }
    12561249  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);
    12641250
    12651251  Line = new EddLineDisplay("drsdaq/Message");
    12661252  Line->setMaximumWidth(200);
    12671253  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");
    12691259  Line->setMaximumWidth(60);
    1270   Layout->addWidget(Line, 0, 2);     
     1260  Layout->addWidget(Line, 1, 2);     
    12711261
    12721262  QWidget *Button = new QPushButton("Details");
    1273   Layout->addWidget(Button, 10, 0, 1, 1);     
     1263  Layout->addWidget(Button, 12, 0, 1, 1);     
    12741264  connect(Button, SIGNAL(pressed()), SLOT(FeedbackDetails()));
    12751265
     
    12781268void TP_Feedback::FeedbackDetails() {
    12791269
    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());
    12811277  EddLineDisplay *Line;
    1282   QWidget *Widget = new QWidget();
    1283   QGridLayout *Layout = new QGridLayout(Widget);
    12841278  EddPlot *Plot = new EddPlot();
     1279
    12851280  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();
    12941297}
    12951298
  • Evidence/Edd/Edd.h

    r231 r232  
    3636bool SetStatus(QWidget *, QString, int, QString, int = -1);
    3737
     38
    3839// Base class for Edd plot
    3940// DeleteCurve() is pure virtual and needs to be implemented iin the application class
     
    213214  private:
    214215        struct Item {
    215           QString Name;
    216216          DimStampedInfo *DIMService;
    217217          int Count;
     
    221221          QString Text;
    222222        };
    223     QList<Item> ServiceList;
     223    QMap<QString, struct Item> ServiceList;
    224224    QMutex *Mutex;
    225225
    226226        struct HistItem {
    227           QString Name;
    228227          int Count;
    229228          int LastUpdate;
    230229          class EvidenceHistory *HistClass;
    231230        };
    232     QList<HistItem> HistoryList;
     231    QMap<QString, struct HistItem> HistoryList;
    233232
    234233        long long Volume;
Note: See TracChangeset for help on using the changeset viewer.