Changeset 212 for Evidence


Ignore:
Timestamp:
05/25/10 07:38:03 (15 years ago)
Author:
ogrimm
Message:
Histories from DColl remain available if service is unavailable
Location:
Evidence
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • Evidence/DColl.cc

    r209 r212  
    225225        char *Token = strtok(Info->getString(), "+-!@");       
    226226        while (Token != NULL) {
    227           if (*Info->getString()=='-' || *Info->getString()=='!') RemoveService(string(Token)+"/SERVICE_LIST");   
    228           else AddService(string(Token)+"/SERVICE_LIST");
     227          if (*Info->getString()=='+') AddService(string(Token)+"/SERVICE_LIST");
    229228          Token = strtok(NULL, "|"); // Skip server IP address
    230229          Token = strtok(NULL, "@");
     
    243242      if (strstr(Type, "|CMD")==NULL && strstr(Type, "|RPC")==NULL) {
    244243            // Add or remove service
    245             if (*Info->getString()=='-' || *Info->getString()=='!') RemoveService(Name);
    246                 else AddService(Name);
     244            if (*Info->getString()=='+') AddService(Name);
    247245          }
    248246          Name = strtok(NULL, "|");
  • Evidence/Edd/Edd.cc

    r208 r212  
    5858//////////////////////////////////////////
    5959
    60 // Constructor
    6160EddLineDisplay::EddLineDisplay(QString Name, int Index, QWidget *P):
    6261        QLineEdit(P), ServiceName(Name), Index(Index) {
     
    192191
    193192
     193//////////////////////////////////////////
     194// Sending string command to DIM server //
     195//////////////////////////////////////////
     196
     197EddCommand::EddCommand(QString Name, QWidget *P): QLineEdit(P), Name(Name) {
     198
     199  setToolTip("Send command "+Name); 
     200  connect(this, SIGNAL(returnPressed()), SLOT(SendCommand()));
     201}
     202
     203// Send command
     204void EddCommand::SendCommand() {
     205
     206  DimClient::sendCommand(Name.toAscii().data(), text().toAscii().data());
     207}
     208
     209
    194210//////////////////////////////////
    195211// History plot for DIM service //
    196212//////////////////////////////////
    197213
    198 // Constructor
    199214EddPlot::EddPlot(QString DIMService, int Index, QWidget *P): EddBasePlot(P) {
    200215
     
    269284        // If buffer empty, request new history buffer
    270285    if (List[ItemNo].Signal->dataSize() == 0) {
    271           int Time, Size;
     286          int Time, Size, Count=0;
    272287          void *Data;
    273 
    274           class EvidenceHistory *HistClass = Handler->GetHistory(List[ItemNo].Name);
    275          
    276           if (HistClass->GetHistory()) {
     288          class EvidenceHistory *Hist;
     289
     290          if ((Hist = Handler->GetHistory(List[ItemNo].Name)) != NULL) {
    277291                double Number=0;
    278                 while (HistClass->Next(Time, Size, Data)) {
     292                while (Hist->Next(Time, Size, Data)) {
    279293                  switch (Format[0].toUpper().toAscii()) {
    280294                case 'I':
     
    287301                  }
    288302                  AddPoint(ItemNo, Time, Number);
     303                  Count++;
    289304                }
    290305
    291306                // Local buffer at least twice as large as longest history
    292                 if (SizeLimit < 2*List[ItemNo].Signal->dataSize()) SizeLimit = 2*List[ItemNo].Signal->dataSize();
     307                if (SizeLimit < 2*Count) SizeLimit = 2*Count;
    293308          }
    294309        }
     
    708723        int Time, Size;
    709724        void *Data;
    710 
    711         class EvidenceHistory *HistClass = Handler->GetHistory(Name);
    712 
    713         if (HistClass->GetHistory()) {
    714           while (HistClass->Next(Time, Size, Data)) {
     725        class EvidenceHistory *Hist;
     726
     727        if ((Hist = Handler->GetHistory(Name)) != NULL) {
     728          while (Hist->Next(Time, Size, Data)) {
    715729                moveCursor (QTextCursor::Start);
    716730                insertPlainText(QString("(")+QDateTime::fromTime_t(Time).toString()+") ");       
     
    770784  TotalVolume = 0;
    771785
     786  // Timer to calculate data rates
    772787  QTimer *Timer = new QTimer(this);
    773788  Timer->connect(Timer, SIGNAL(timeout()), this, SLOT(UpdateStatistics()));
     
    783798
    784799  for (int i=0; i<HistoryList.size(); i++) delete HistoryList[i].HistClass;
     800
    785801  delete Mutex;
    786802}
     
    795811  for (int i=0; i<ServiceList.size(); i++) if (ServiceList[i].Name == Name) {
    796812        ServiceList[i].Count++;
    797         // If service already reveived, reemit for new subscriber
     813        // If service already received, reemit for new subscriber
    798814        if (!ServiceList[i].ByteArray.isEmpty()) {
    799815          YEP(Name, ServiceList[i].TimeStamp, ServiceList[i].ByteArray, ServiceList[i].Format, ServiceList[i].Text);
     
    832848class EvidenceHistory *EddDim::GetHistory(QString Name) {
    833849
    834   // If history already available, return this
     850  // History already available (only request again if too old)
    835851  for (int i=0; i<HistoryList.size(); i++) if (HistoryList[i].Name == Name) {
    836852        HistoryList[i].Count++;
    837         return HistoryList[i].HistClass;
    838   }
    839 
     853        if (time(NULL)-HistoryList[i].LastUpdate < 5) {
     854          HistoryList[i].HistClass->Rewind();
     855          return HistoryList[i].HistClass;
     856        }
     857        HistoryList[i].LastUpdate = time(NULL);
     858        if (HistoryList[i].HistClass->GetHistory()) return HistoryList[i].HistClass;
     859        else return NULL;
     860  }
     861
     862  // Create new history class
    840863  struct HistItem New;
    841864  New.Name = Name;
    842865  New.HistClass = new EvidenceHistory(Name.toStdString());
    843866  New.Count = 1;
     867  New.LastUpdate = time(NULL);
    844868  HistoryList.append(New);
    845869
    846   return New.HistClass;
    847 
     870  if (New.HistClass->GetHistory()) return New.HistClass;
     871  else return NULL;
    848872}
    849873
     
    906930EventScope::EventScope(QWidget *P): EddBasePlot(P), PixelMap("../../config/PixelMap.txt", false) {
    907931
    908   Name = "Feedback/EventData";
     932  Name = "drsdaq/EventData";
    909933
    910934  Tmpfile = tmpfile();
     
    10481072  else setAxisTitle(QwtPlot::xBottom, "Time from trigger minus one revolution (ns)");
    10491073 
    1050   // Loop through event data
     1074  // Loop through event data to update event scope
    10511075  RunHeader *R = RD->RHeader;
    10521076  for (int i=0; i<List.size(); i++) {
     
    10811105
    10821106  UpdatePlot();
     1107
     1108  // Loop through event data for pixel display
     1109  QVector<double> Pixel(R->NBoards*R->NChips*R->NChannels);
     1110  int Count = 0;
     1111
     1112  for (unsigned int Board=0; Board<R->NBoards; Board++) {
     1113  for (unsigned int Chip=0; Chip<R->NChips; Chip++) {
     1114  for (unsigned int Channel=0; Channel<R->NChannels; Channel++) {
     1115    Pixel[Count] = DBL_MIN;
     1116
     1117        for (unsigned int i=0; i<R->Samples; i++) {
     1118          y = *((short *) (RD->Data + R->NBoards*R->NChips*sizeof(int)) +
     1119                Board*R->NChips*R->NChannels*R->Samples + Chip*R->NChannels*R->Samples +
     1120                Channel*R->Samples + i) * RD->BStruct[Board].ScaleFactor;
     1121
     1122          if (y > Pixel[Count]) Pixel[Count] = y;
     1123    }
     1124        Count++;         
     1125  }}}
     1126 
     1127  emit(PixelData(Pixel));
    10831128}
    10841129
     
    10921137}
    10931138
    1094 //
    1095 // Tab page classes
    1096 //
    1097 
     1139//------------------------------------------------------------------
     1140//**************************** Tab pages ***************************
     1141//------------------------------------------------------------------
     1142
     1143//
    10981144// Environment page
     1145//
    10991146TP_Environment::TP_Environment() {
    11001147
     
    11041151  EddLineDisplay *Line = new EddLineDisplay("ARDUINO/Status");
    11051152  Line->setMaximumWidth(200);
    1106   Layout->addWidget(Line, 0, 0, 1, 3);     
     1153  Layout->addWidget(Line, 0, 0, 1, 2);     
    11071154
    11081155  // Generate plot and data displays
     
    11131160    Plot->AddService("ARDUINO/Data", i);
    11141161  }
    1115   Layout->addWidget(Plot, 0, 3, 6, 4);     
     1162  Layout->addWidget(Plot, 0, 2, 8, 7);     
    11161163
    11171164  // Night sky monitor
     
    11201167}
    11211168
     1169//
    11221170// Bias page
     1171//
    11231172TP_Bias::TP_Bias() {
    11241173
     
    11431192  Layout->addWidget(Line, 0, 0, 1, 3);     
    11441193
    1145   EddText *Text = new EddText("Bias/Textout", true);
     1194  EddCommand *Command = new EddCommand("Bias/Command");
     1195  Layout->addWidget(Command, 10, 0, 1, 4);   
     1196
     1197  EddText *Text = new EddText("Bias/StdOut", true);
    11461198  Text->setFixedWidth(400);
    1147   Layout->addWidget(Text, 10, 0, 4, 4);     
    1148 }
    1149 
     1199  Layout->addWidget(Text, 11, 0, 4, 4);     
     1200}
     1201
     1202//
    11501203// Feedback page
     1204//
    11511205TP_Feedback::TP_Feedback() {
    11521206
     
    11561210  EddPlot *Plot = new EddPlot();
    11571211  for (int i=0; i<36; i++) {
    1158     Line = new EddLineDisplay("Feedback/Average", i);
     1212    Line = new EddLineDisplay("drsdaq/Average", i);
     1213        Line->setMaximumWidth(60);
    11591214    Layout->addWidget(Line, i%9+1, 0+i/9, 1, 1);
    1160     Plot->AddService("Feedback/Average", i);
    1161   }
    1162   Layout->addWidget(Plot, 0, 4, 11, 3);
     1215    Plot->AddService("drsdaq/Average", i);
     1216  }
     1217  Layout->addWidget(Plot, 0, 4, 12, 10);
    11631218
    11641219  //Graph = new EddPlot();
     
    11691224  //FeedbackLayout->addWidget(Graph, 10, 0, 10, 3);
    11701225
    1171   Line = new EddLineDisplay("Feedback/Status");
     1226  Line = new EddLineDisplay("drsdaq/Status");
    11721227  Line->setMaximumWidth(200);
    1173   Layout->addWidget(Line, 0, 0, 1, 3);     
    1174   Line = new EddLineDisplay("Feedback/Count");
    1175   Layout->addWidget(Line, 0, 3, 1, 1);     
     1228  Layout->addWidget(Line, 0, 0, 1, 2);     
     1229  Line = new EddLineDisplay("drsdaq/Count");
     1230  Line->setMaximumWidth(60);
     1231  Layout->addWidget(Line, 0, 2);     
    11761232
    11771233  QWidget *Button = new QPushButton("Details");
     
    11881244  EddPlot *Plot = new EddPlot();
    11891245  for (int i=0; i<36; i++) {
    1190     Line = new EddLineDisplay("Feedback/Sigma", i);
     1246    Line = new EddLineDisplay("drsdaq/Sigma", i);
     1247        Line->setMaximumWidth(50);
    11911248    Layout->addWidget(Line, i%9+1, 0+i/9, 1, 1);
    1192     Plot->AddService("Feedback/Sigma", i);
    1193   }
    1194   Layout->addWidget(Plot, 0, 4, 11, 3);
     1249    Plot->AddService("drsdaq/Sigma", i);
     1250  }
     1251  Layout->addWidget(Plot, 0, 4, 12, 10);
    11951252 
    11961253  Widget->show();
    11971254}
    11981255
    1199 // DAQ page
     1256//
     1257// Event scope page
     1258//
    12001259TP_DAQ::TP_DAQ() {
    12011260
     
    12171276  TabWidget->addTab(RunHeaderDisplay, "&Run Header");
    12181277  TabWidget->addTab(EventHeaderDisplay, "&Event Header");
    1219   Layout->addWidget(TabWidget, 0, 1, 3, 3);
     1278  Layout->addWidget(TabWidget, 0, 1, 5, 3);
    12201279
    12211280  connect(Scope, SIGNAL(RunHeaderChanged(QString)), RunHeaderDisplay, SLOT(setPlainText(QString)));
     
    12501309  FormLayout->addRow("Board", Board);
    12511310  FormLayout->addRow("Pixel ID", PixelID);
    1252   Layout->addLayout(FormLayout, 0, 0);
     1311  Layout->addLayout(FormLayout, 0, 0, 2, 1);
    12531312 
    12541313  // Add trace permanently
     
    12581317  Layout->addWidget(Button, 2, 0);
    12591318  connect(Button, SIGNAL(clicked()), SLOT(KeepCurrent()));
    1260 }
    1261 
     1319
     1320  // Button to show event display
     1321  QPushButton *PixDisplay = new QPushButton("Pixel display");
     1322  PixDisplay->setFont(QFont("Times", 10, QFont::Bold));
     1323  PixDisplay->setToolTip("Show event display window");
     1324  Layout->addWidget(PixDisplay, 4, 0);
     1325  connect(PixDisplay, SIGNAL(clicked()), SLOT(ShowPixelDisplay()));
     1326
     1327  // Event display window
     1328  Display = new QWidget();
     1329  Display->setWindowTitle("Edd - Event display");
     1330 
     1331  Pixel = new QPushButton *[MAXPIXEL];
     1332  int Count = 0;
     1333  double x,y;
     1334 
     1335  for (int ix=-22; ix<=22; ix++) for (int iy=-19; iy<=20; iy++) { 
     1336    if (Count == MAXPIXEL) break;
     1337       
     1338        x = ix*0.866;
     1339        y = iy - (ix%2==0 ? 0.5:0);
     1340    if ((pow(x,2)+pow(y,2) >= 395) && !(abs(ix)==22 && iy==7)) continue;
     1341       
     1342    Pixel[Count] = new QPushButton(Display);
     1343        Pixel[Count]->setAutoFillBackground(true);
     1344        Pixel[Count]->setGeometry(x*12.5 + 250, y*12.5 + 250, 10, 10);
     1345        Pixel[Count]->show();
     1346        Count++;
     1347  }
     1348
     1349  connect(Scope, SIGNAL(PixelData(QVector<double>)), SLOT(SetPixelData(QVector<double>)));
     1350}
     1351
     1352TP_DAQ::~TP_DAQ() {
     1353
     1354  delete[] Pixel;
     1355}
     1356
     1357// Translate pixel ID to board, chip, channel
    12621358void TP_DAQ::TranslatePixelID() {
    12631359 
     
    12871383}
    12881384
    1289 // DAQ page
     1385// Show/hide pixel display
     1386void TP_DAQ::ShowPixelDisplay() {
     1387
     1388  Display->show();
     1389  Display->raise();
     1390}
     1391
     1392void TP_DAQ::SetPixelData(QVector<double> Data) {
     1393
     1394  QwtLinearColorMap Map;
     1395
     1396  for (int i=0; i<Data.size(); i++) {
     1397        Pixel[i]->setPalette(QPalette(Map.color(QwtDoubleInterval(300, 400), Data[i])));
     1398  }
     1399}
     1400
     1401
     1402//
     1403// Evidence page
     1404//
    12901405TP_Evidence::TP_Evidence() {
    12911406
     
    13671482  // Arrangement in tabs
    13681483  TabWidget = new QTabWidget(Central);
    1369   TabWidget->addTab(new TP_DAQ, "&drsdaq");
     1484  TabWidget->addTab(new TP_DAQ, "Event scope");
    13701485  TabWidget->addTab(new TP_Bias, "&Bias");
    13711486  TabWidget->addTab(new TP_Feedback, "&Feedback");
  • Evidence/Edd/Edd.h

    r208 r212  
    1919#include <qwt_plot_marker.h>
    2020#include <qwt_data.h>
     21#include <qwt_color_map.h>
    2122
    2223#include <limits.h>
     
    118119};
    119120
     121// Sending command to DIM server
     122class EddCommand: public QLineEdit {
     123    Q_OBJECT
     124
     125        QString Name;
     126       
     127  public:
     128    EddCommand(QString, QWidget * = NULL);
     129
     130  private slots:
     131        void SendCommand();     
     132};
     133
    120134// Graph class for history display
    121135class EddPlot: public EddBasePlot {
     
    213227          QString Name;
    214228          int Count;
     229          int LastUpdate;
    215230          class EvidenceHistory *HistClass;
    216231        };
     
    277292        void RunHeaderChanged(QString);
    278293        void EventHeaderChanged(QString);
     294        void PixelData(QVector<double>);
    279295};
    280296
     
    307323class TP_DAQ: public QWidget {
    308324  Q_OBJECT
     325  static const int MAXPIXEL = 1440;
    309326
    310327  private:
     
    315332        QLineEdit *PixelID;
    316333        QFormLayout *FormLayout;
     334        QWidget *Display;
     335        QPushButton **Pixel;
    317336
    318337  private slots:
     
    320339        void UpdateScope(int);
    321340        void KeepCurrent();
     341        void ShowPixelDisplay();
     342        void SetPixelData(QVector<double>);
    322343
    323344  public:
    324345        TP_DAQ();       
     346        ~TP_DAQ();     
    325347};
    326348
  • Evidence/Evidence.cc

    r209 r212  
    370370}
    371371
    372 // Requests service history
     372// Requests service history (returns true if data received OK)
    373373bool EvidenceHistory::GetHistory() {
    374374
    375375  DimRpcInfo R((char *) "ServiceHistory", NO_LINK);
    376376  R.setData((char *) Name.c_str());
     377
     378  // Check if data OK
    377379  if (!EvidenceServer::ServiceOK(&R)) return false;
    378 
     380  if (R.getSize() == 0) return false;
     381 
     382  // Copy data to buffer
    379383  delete[] Buffer;
    380384  BufferSize = R.getSize();
     
    382386
    383387  memcpy(Buffer, R.getData(), BufferSize);
    384   Offset = *(int *) Buffer;
     388  Rewind();
    385389 
    386390  return true;
     
    406410  return true;
    407411}
     412
     413// Reset to start of buffer
     414void EvidenceHistory::Rewind() {
     415
     416  if (Buffer != NULL) Offset = *(int *) Buffer;
     417}
  • Evidence/Evidence.h

    r209 r212  
    9191        bool GetHistory();
    9292        bool Next(int &, int &, void *&);
     93        void Rewind();
    9394};
    9495#endif
  • Evidence/readme.txt

    r209 r212  
    2828                        When regular expression compiling results in error, State is set to ERROR, not
    2929                        FATAL. The erroneous expression is ignored in the following.
     3025/5/2010       Service history remains available if service itself become unavailable
    3031                       
    3132
Note: See TracChangeset for help on using the changeset viewer.