Changeset 10904 for fact/tools


Ignore:
Timestamp:
06/03/11 15:42:44 (13 years ago)
Author:
ogrimm
Message:
Add browsing of raw data files
Location:
fact/tools/Edd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/Edd/Edd.cc

    r10642 r10904  
    2222
    2323// Constructor
    24 EventScope::EventScope(QWidget *P): EddBasePlot(P), PixelMap(PixelMapText, false) {
    25 
     24EventScope::EventScope(class TP_DAQ *Page, QWidget *P): EddBasePlot(P), PixelMap(PixelMapText, false) {
     25
     26  // Initalise
     27  LastPath = ".";
    2628  Name = DRSBoard+"/EventData";
    27 
     29  DAQPage = Page;
     30  Active = false;
     31
     32  // Open temporary files
    2833  Tmpfile = tmpfile();
    2934  if(Tmpfile == NULL) {
    3035    QMessageBox::warning(this, "Edd Message", "Could not open temporary file.", QMessageBox::Ok);
     36        return;
     37  }
     38
     39  if (!File.open()) {
     40        QMessageBox::warning(this, "Edd Message","Could not open temporary file.",QMessageBox::Ok);
     41        return;
    3142  }
    3243
     
    4960  AddTrace(0,0,0);
    5061
    51   // Connect to DIM handler
    52   if (connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString))) == false) {
    53     printf("Failed connection for %s\n", Name.toAscii().data());
    54   }
    5562  SetActive(true);
    5663}
     
    116123  disconnect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), this, SLOT(Update(QString, int, QByteArray, QString, QString)));
    117124 
    118   // Open tempory file and write event data to this file
    119   QTemporaryFile File;
    120   if (!File.open()) {
    121         QMessageBox::warning(this, "Edd Message","Could not open temporary file.",QMessageBox::Ok);
    122         return;
    123   }
     125  // Clear temporary file and write event data to this file
     126  File.resize(0);
    124127  if (File.write(Data) == -1) {
    125128        QMessageBox::warning(this, "Edd Message","Could not write data to temporary file.",QMessageBox::Ok);
     
    127130  }
    128131
     132  // Open temporary raw data file
     133  OpenRawFile(File.fileName());
     134 
     135  // Reconnect after processing
     136  connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString)));
     137}
     138
     139
     140// New event number selected in raw data browser
     141void EventScope::OpenRawFile(QString Filename) {
     142
     143  // Request filename to open if none given
     144  if (Filename.isEmpty()) {
     145    Filename = QFileDialog::getOpenFileName(this, "Open raw file", LastPath, "Raw data files (*.raw);; All files (*)");
     146    if (Filename == NULL) return;
     147  }
     148
     149  DAQPage->FilenameBox->setText(Filename);
     150  LastPath = QFileInfo(Filename).absolutePath();
     151 
    129152  // Prepare temporary file for run header 
    130153  ftruncate(fileno(Tmpfile), 0);
    131154  rewind(Tmpfile);
    132155
    133   // Open file with RawDataCTX
    134   switch (ErrCode = RD->OpenDataFile(File.fileName().toAscii().data(), Tmpfile)) {
    135     case CTX_FOPEN:             QMessageBox::warning(this, "Edd Message","Could not open file.",QMessageBox::Ok);
    136                                                 return;
    137     case CTX_RHEADER:   QMessageBox::warning(this, "Edd Message","Could not read run header.",QMessageBox::Ok);
    138                                         return;
    139     case CTX_BSTRUCT:   QMessageBox::warning(this, "Edd Message","Could not read board structures.",QMessageBox::Ok);
    140                                                 return;
    141         default: break;
    142   }
    143 
    144   // Emit signal containing run header
     156  // Write run header to temporary file 
     157  switch (ErrCode = RD->OpenDataFile(Filename.toAscii().data(), Tmpfile)) {
     158    case CTX_FOPEN:   QMessageBox::warning(this, "Edd Message","Could not open file.",QMessageBox::Ok);
     159                      return;
     160    case CTX_RHEADER: QMessageBox::warning(this, "Edd Message","Could not read run header.",QMessageBox::Ok);
     161                                          return;
     162    case CTX_BSTRUCT: QMessageBox::warning(this, "Edd Message","Could not read board structures.",QMessageBox::Ok);
     163                                          return;
     164    default:              break;
     165  }
     166  RunHeader *R = RD->RHeader;
     167
     168  if (R->MagicNum == MAGICNUM_OPEN) {
     169    QMessageBox::warning(this, "Edd Message","Magic number in run header indicates that the file has not been closed properly.",QMessageBox::Ok);
     170  }
     171  if (R->MagicNum == MAGICNUM_ERROR) {
     172    QMessageBox::warning(this, "Edd Message","Magic number in run header indicates that an error occurred while writing the file.",QMessageBox::Ok);
     173  }
     174 
     175  // Print run header to display
    145176  rewind(Tmpfile);
    146   QTextStream Stream(Tmpfile);
    147   emit(RunHeaderChanged(Stream.readAll()));
     177  QTextStream in(Tmpfile);
     178  QString text = in.readAll();
     179  DAQPage->RunHeaderDisplay->setPlainText(text);
     180
     181  // Update spin box ranges on DAQ page 
     182  DAQPage->Event->setRange(0, R->Events-1);
     183  DAQPage->Event->setEnabled(true);
     184
     185  DAQPage->Channel->setRange(0, R->NChannels-1);
     186  DAQPage->Chip->setRange(0, R->NChips-1);
     187  DAQPage->Board->setRange(0, R->NBoards-1);
     188 
     189  // Display first event
     190  NewEventNum(0);
     191}
     192
     193// New event number selected in raw data browser
     194void EventScope::NewEventNum(int Event) {
    148195
    149196  // Prepare temporary file for event header 
     
    151198  rewind(Tmpfile);
    152199
    153   // Write event header text to file
    154   if (RD->ReadEvent(0, Tmpfile) != CTX_OK) {
    155     QMessageBox::warning(this, "Edd Warning","Could not read event.",QMessageBox::Ok);
     200  // Read event
     201  if (RD->ReadEvent(Event, Tmpfile) != CTX_OK) {
     202    QMessageBox::warning(this, "Edd Message","Could not read event.",QMessageBox::Ok);
     203    DAQPage->EventHeaderDisplay->clear();
    156204    return;
    157205  }
    158 
    159   // Add trigger cells to file
    160   fprintf(Tmpfile, "\nTrigger cells:");
    161   int *TrigCells = (int *) RD->Data;
    162   for (unsigned int i=0; i<RD->RHeader->NBoards; i++) {
    163     fprintf(Tmpfile, "\n Board %d   ", i);
    164         for (unsigned int j=0; j<RD->RHeader->NChips; j++) fprintf(Tmpfile, "%d ", *(TrigCells++));
    165   }
    166 
    167   // Emit signal containing run header
    168   rewind(Tmpfile);
    169   emit(EventHeaderChanged(Stream.readAll()));
    170 
    171   // Update display
     206 
     207  // Plot traces for event
    172208  PlotTraces();
    173  
    174   // Reconnect after processing
    175   connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString)));
    176209}
    177210
     
    182215  unsigned int Cell, Trig;
    183216  static int Last = 0;
    184  
     217
    185218  // Only process if valid data in RawDataCTX class
    186219  if (ErrCode != CTX_OK) return;
     220
     221  // Print event header and trigger cell information from event data
     222  rewind(Tmpfile);
     223  QTextStream in(Tmpfile);
     224  QString text = in.readAll();
     225 
     226  text.append("\nTrigger cells: ");
     227  for (unsigned int i=0; i<RD->RHeader->NBoards*RD->RHeader->NChips; i++) {
     228    QString a;
     229    text.append(a.sprintf("%d ", *((int *)RD->Data + i)));
     230  }
     231  DAQPage->EventHeaderDisplay->setPlainText(text);
    187232 
    188233  // Set x axis title
     
    268313void EventScope::SetActive(bool State) {
    269314
    270   static bool Active = false;
    271 
    272   if (State && !Active) Handler->Subscribe(DRSBoard+"/EventData");
    273   if (!State && Active) Handler->Unsubscribe(DRSBoard+"/EventData");
     315  if (State && !Active) {
     316        Handler->Subscribe(DRSBoard+"/EventData");
     317        connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString)));
     318  }
     319  if (!State && Active) {
     320        Handler->Unsubscribe(DRSBoard+"/EventData");
     321        disconnect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), this, SLOT(Update(QString, int, QByteArray, QString, QString)));
     322  }
    274323  Active = State;
    275324}
     
    494543// Event scope page
    495544//
    496 TP_DAQ::TP_DAQ() {
     545TP_DAQ::TP_DAQ(bool IsBrowser) {
    497546
    498547  EddLineDisplay *Line;
     
    501550  QGridLayout *Layout = new QGridLayout(this);
    502551
    503   // Run-related information
    504   Line = new EddLineDisplay("drsdaq/RunNumber");
    505   Line->setMaximumWidth(100);
    506   Layout->addWidget(Line, 0, 1, 1, 1);     
    507   Line = new EddLineDisplay(DRSBoard+"/EventNumber");
    508   Line->setMaximumWidth(100);
    509   Layout->addWidget(Line, 0, 2, 1, 1);     
    510   Line = new EddLineDisplay("drsdaq/RunSizeMB");
    511   Line->setMaximumWidth(100);
    512   Layout->addWidget(Line, 0, 3, 1, 1);     
    513   Line = new EddLineDisplay("drsdaq/FileSizeMB");
    514   Line->setMaximumWidth(100);
    515   Layout->addWidget(Line, 0, 4, 1, 1);     
    516   Line = new EddLineDisplay("drsdaq/FileName");
    517   Line->setMaximumWidth(200);
    518   Layout->addWidget(Line, 0, 5, 1, 1);     
    519 
    520   // Message service
    521   Line = new EddLineDisplay(DRSBoard+"/Message");
    522   Line->setMaximumWidth(200);
    523   Layout->addWidget(Line, 1, 1, 1, 2);     
    524 
    525552  // Event scope
    526   Scope = new EventScope;
     553  Scope = new EventScope(this);
    527554  Scope->setMinimumWidth(700);
     555
     556  if (IsBrowser) Scope->SetActive(false);
     557
     558  // FilenameBox must exist also for online browser (but not added to layout)
     559  FilenameBox = new QLineEdit();
     560
     561  if (!IsBrowser) {
     562        // Message service
     563        Line = new EddLineDisplay(DRSBoard+"/Message");
     564        Line->setMinimumWidth(500);
     565        Layout->addWidget(Line, 0, 1, 1, 6);     
     566
     567        // Run-related information
     568        Line = new EddLineDisplay(DRSBoard+"/EventNumber");
     569        Line->setMaximumWidth(100);
     570        Layout->addWidget(Line, 0, 8, 1, 1);     
     571        Line = new EddLineDisplay(DRSBoard+"/FileSizeMB");
     572        Line->setMaximumWidth(100);
     573        Layout->addWidget(Line, 0, 9, 1, 1);     
     574  }
     575  else {
     576        // Filename box
     577        Layout->addWidget(FilenameBox, 0, 1, 1, 6);     
     578        connect(FilenameBox, SIGNAL(returnPressed()), SLOT(OpenDataFile()));
     579        FilenameBox->setToolTip("Raw data file name");
     580
     581    // Browse botton
     582        QToolButton *LoadButton = new QToolButton();
     583        LoadButton->setToolButtonStyle (Qt::ToolButtonTextOnly);
     584        LoadButton->setText("...");
     585        Layout->addWidget(LoadButton, 0, 7, 1, 1);     
     586        connect(LoadButton, SIGNAL(clicked()), Scope, SLOT(OpenRawFile()));
     587        LoadButton->setToolTip("Open file dialog to select raw data file");
     588  }
    528589
    529590  // Text boxes for run and event header
     
    538599  TabWidget->addTab(RunHeaderDisplay, "&Run Header");
    539600  TabWidget->addTab(EventHeaderDisplay, "&Event Header");
    540   Layout->addWidget(TabWidget, 2, 1, 6, 5);
     601  Layout->addWidget(TabWidget, 1, 1, 7, 12);
    541602
    542603  // Channel number
    543604  Channel = new QSpinBox;
    544605  connect(Channel, SIGNAL(valueChanged(int)), SLOT(UpdateScope(int)));
    545   Channel->setToolTip("DRS channel number");
     606  Channel->setToolTip("Channel number");
    546607
    547608  // Chip number
    548609  Chip = new QSpinBox;
    549610  connect(Chip, SIGNAL(valueChanged(int)), SLOT(UpdateScope(int)));
    550   Chip->setToolTip("DRS chip number");
     611  Chip->setToolTip("Chip number");
    551612
    552613  // Board number
    553614  Board = new QSpinBox;
    554615  connect(Board, SIGNAL(valueChanged(int)), SLOT(UpdateScope(int)));
    555   Board->setToolTip("DRS board number");
     616  Board->setToolTip("Board number");
    556617
    557618  // Pixel ID
     
    562623  connect(PixelID, SIGNAL(valueChanged(int)), SLOT(TranslatePixelID(int)));
    563624  PixelID->setToolTip("Pixel identification");
     625
     626  // Add trace permanently
     627  QPushButton *Button = new QPushButton("Keep trace");
     628  Button->setToolTip("Keep trace in display");
     629  Button->setMaximumWidth(80);
     630  connect(Button, SIGNAL(clicked()), SLOT(KeepCurrent()));
    564631 
    565632  // Layout of pixel addressing widgets
     
    570637  FormLayout->addRow("Channel", Channel);
    571638  FormLayout->addRow("Pixel ID", PixelID);
     639  FormLayout->addRow("", Button);
    572640  Layout->addLayout(FormLayout, 0, 0, 4, 1);
    573  
    574   // Add trace permanently
    575   QPushButton *Button = new QPushButton("Keep trace");
    576   Button->setToolTip("Keep trace in display");
    577   Button->setMaximumWidth(80);
    578   Layout->addWidget(Button, 4, 0);
    579   connect(Button, SIGNAL(clicked()), SLOT(KeepCurrent()));
    580 
    581   // Stop/start
     641
     642  // Spin box for event number
     643  Event = new QSpinBox;
     644  Event->setToolTip("Event number");
     645  Event->setEnabled (false);
     646 
     647  // Stop/start button
    582648  StartStopButton = new QPushButton("Stop");
    583649  StartStopButton->setToolTip("Start/stop display");
     
    589655  StartStopButton->setPalette(Palette);
    590656  StartStopButton->setFont(QFont("Times", 10, QFont::Bold));
    591   Layout->addWidget(StartStopButton, 6, 0);
    592   connect(StartStopButton, SIGNAL(toggled(bool)), SLOT(StartStop(bool)));
    593 
    594 
     657
     658  if (IsBrowser) {
     659        FormLayout = new QFormLayout();
     660        FormLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
     661        FormLayout->addRow("Event Num", Event);
     662        Layout->addLayout(FormLayout, 6, 0);
     663        connect(Event, SIGNAL(valueChanged(int)), Scope, SLOT(NewEventNum(int)));
     664  }
     665  else {
     666        Layout->addWidget(StartStopButton, 6, 0);
     667        connect(StartStopButton, SIGNAL(toggled(bool)), SLOT(StartStop(bool)));
     668  }
     669 
    595670  // Event display page
    596671  EddWindow *New = new EddWindow("Pixel display", "Edd - Event display");
     
    620695
    621696  // Connect slots for updating displays
    622   connect(Scope, SIGNAL(RunHeaderChanged(QString)), RunHeaderDisplay, SLOT(setPlainText(QString)));
    623   connect(Scope, SIGNAL(EventHeaderChanged(QString)), EventHeaderDisplay, SLOT(setPlainText(QString)));
    624 
    625   StartStop(false);
     697  if (!IsBrowser) StartStop(false);
    626698  connect(Scope, SIGNAL(PixelData(QVector<double>)), SLOT(SetPixelData(QVector<double>)));
    627699
     
    662734  Scope->SetActive(!State);
    663735  StartStopButton->setText(State ? "Start" : "Stop");
    664   if (!State) connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), Scope, SLOT(Update(QString, int, QByteArray, QString, QString)));
    665   else disconnect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), Scope, SLOT(Update(QString, int, QByteArray, QString, QString)));
     736  //if (!State) connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), Scope, SLOT(Update(QString, int, QByteArray, QString, QString)));
     737  //else disconnect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), Scope, SLOT(Update(QString, int, QByteArray, QString, QString)));
     738}
     739
     740// Open raw data file
     741void TP_DAQ::OpenDataFile() {
     742
     743  Scope->OpenRawFile(FilenameBox->text());
    666744}
    667745
     
    794872  TabWidget->setTabsClosable(true);
    795873  connect(TabWidget, SIGNAL(tabCloseRequested(int)), SLOT(DetachTab(int)));
    796   TabWidget->addTab(new TP_DAQ, "Event scope");
     874  TabWidget->addTab(new TP_DAQ(false), "Event scope");
    797875  TabWidget->addTab(new TP_FADctrl, "FADctrl");
    798876  TabWidget->addTab(new TP_Bias, "Bias");
     
    803881  // Set features of main window
    804882  setStatusBar(new QStatusBar(this));
    805   setWindowTitle("Edd - Evidence Data Display - Node: " + QString(getenv("DIM_DNS_NODE")));
     883  setWindowTitle("Edd - Evidence Data Display - Node: " + QString(DimServer::getDnsNode()) + ":" + QString::number(DimServer::getDnsPort()));
    806884  setCentralWidget(TabWidget);
    807885
     
    809887  QMenu* Menu = menuBar()->addMenu("&Menu");
    810888  Menu->addAction("New history plot", this, SLOT(MenuNewHistory()));
     889  Menu->addAction("Raw data browser", this, SLOT(MenuRawDataBrowser()));
    811890  Menu->addSeparator();
    812891  Menu->addAction("About", this, SLOT(MenuAbout()));
     
    820899  //setMaximumSize(QApplication::desktop()->screenGeometry(this).size()*0.9);
    821900  TabWidget->resize(Size);
    822 TabWidget->setMaximumSize(QApplication::desktop()->screenGeometry(this).size()*0.9);
     901  TabWidget->setMaximumSize(QApplication::desktop()->screenGeometry(this).size()*0.9);
    823902  show();
    824903
     
    867946}
    868947
     948// Raw data browser
     949void GUI::MenuRawDataBrowser() {
     950
     951  DetachTab(0, true);
     952}
     953
    869954// Open tab as separate window
    870 void GUI::DetachTab(int Tab) {
     955void GUI::DetachTab(int Tab, bool IsDAQBrowser) {
    871956
    872957  QWidget *W = NULL;
     
    877962
    878963  switch(Tab) {
    879         case 0: W = new TP_DAQ; break;
    880         case 1: W = new TP_Bias; break;
    881         case 2: W = new TP_Feedback; break;
    882         case 3: W = new TP_Environment; break;
    883         case 4: W = new TP_Evidence; break;
     964        case 0: W = new TP_DAQ(IsDAQBrowser); break;
     965        case 1: W = new TP_FADctrl; break;
     966        case 2: W = new TP_Bias; break;
     967        case 3: W = new TP_Feedback; break;
     968        case 4: W = new TP_Environment; break;
     969        case 5: W = new TP_Evidence; break;
    884970        default: break;
    885971  }
     
    892978
    893979  W->setParent(M);
     980  W->resize(size());
    894981  M->resize(size());
    895   M->setWindowTitle("Edd - " + TabWidget->tabText(Tab));
     982  if (!IsDAQBrowser) M->setWindowTitle("Edd - " + TabWidget->tabText(Tab));
     983  else M->setWindowTitle("Edd - Raw Data Browser");
    896984  M->show();
     985 
     986  return;
    897987}
    898988
  • fact/tools/Edd/Edd.h

    r10280 r10904  
    77
    88#define SVN_REVISION "$Revision: 10143 $"
     9
     10class TP_DAQ;
    911
    1012// Event oscilloscope
     
    2022    QList<struct ItemDetails> List;
    2123
     24        class TP_DAQ *DAQPage;
    2225    QString Name;
    23         RawDataCTX *RD;
    24         CTX_ErrCode ErrCode;
     26        bool Active;
    2527        QAction *PhysPipeAction;
    2628        QAction *PersistanceAction;
    2729        FILE *Tmpfile;
     30        QTemporaryFile File;
     31        QString LastPath;
    2832
    2933  public:
    30     EventScope(QWidget * = NULL);
     34    EventScope(class TP_DAQ *, QWidget * = NULL);
    3135    ~EventScope();
    3236       
     
    3539        void SetActive(bool);
    3640        QString ToPixel(unsigned int, unsigned int, unsigned int, unsigned int);
     41        RawDataCTX *RD;
     42        CTX_ErrCode ErrCode;
    3743
    3844  private slots:
     
    4046        void PlotTraces();
    4147        void DeleteCurve(QwtPlotCurve *);
     48        void NewEventNum(int);
     49
     50  public slots:
     51        void OpenRawFile(QString=QString());
    4252       
    4353  signals:
    44         void RunHeaderChanged(QString);
    45         void EventHeaderChanged(QString);
    4654        void PixelData(QVector<double>);
    4755};
     
    8290
    8391  private:
    84         EventScope *Scope;
    85     QPlainTextEdit *RunHeaderDisplay, *EventHeaderDisplay;
    86 
    87         QSpinBox *Channel, *Chip, *Board, *PixelID;
    8892        QFormLayout *FormLayout;
    8993        QWidget *Display;
     
    98102        void ShowPixelDisplay();
    99103        void SetPixelData(QVector<double>);
     104        void OpenDataFile();
    100105
    101106  public:
    102         TP_DAQ();       
    103         ~TP_DAQ();     
     107        TP_DAQ(bool);   
     108        ~TP_DAQ();
     109       
     110        EventScope *Scope;
     111        QSpinBox *Channel, *Chip, *Board, *PixelID, *Event;
     112    QPlainTextEdit *RunHeaderDisplay, *EventHeaderDisplay;
     113        QLineEdit *FilenameBox;
    104114};
    105115
     
    132142    void MenuAbout();
    133143    void MenuNewHistory();
    134         void DetachTab(int);
     144    void MenuRawDataBrowser();
     145        void DetachTab(int, bool=false);
    135146        void CheckAlarm();
    136147};
Note: See TracChangeset for help on using the changeset viewer.