Changeset 81 for tools


Ignore:
Timestamp:
07/03/09 15:02:17 (15 years ago)
Author:
ogrimm
Message:
Fixed segmentation violation bug (was due to repeated calls to tmpfile())
Location:
tools/ddd
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tools/ddd/Functions.cpp

    r74 r81  
    2222
    2323  // Write run header to temporary file 
    24   FILE *Tmpfile = tmpfile();
    25   if(Tmpfile==NULL) {
    26     QMessageBox::warning(this, "ddd Message","Could not open temporary file.",QMessageBox::Ok);
    27     CloseDatafile();
    28     return;
    29   }
    30 
     24  rewind(Tmpfile);
    3125  switch (RD->OpenDataFile(FilenameBox->text().toAscii().data(), Tmpfile)) {
    3226    case CTX_FOPEN:   QMessageBox::warning(this, "ddd Message","Could not open file.",QMessageBox::Ok);
     
    4943  QString text = in.readAll();
    5044  RunHeaderDisplay->setPlainText(text);
    51   fclose(Tmpfile);
    5245
    5346  // Enable spin boxes, set ranges and display first event
     
    8881// +++ Read event header and display event (only called if Datafile is open) +++
    8982void ddd::DisplayEvent(int) {
     83
     84  PixelID->setText(PixMap->DRS_to_Pixel(BoardNo->value(), ChannelNo->value()/10, ChannelNo->value()%10).c_str());  // Translate to pixel ID
     85  if(Socket->state() == QAbstractSocket::ConnectedState) return; // do not execute if socket is open
     86 
     87  // Read event
     88  rewind(Tmpfile);
     89  if (RD->ReadEvent(EventNo->value(), Tmpfile) != CTX_OK) {
     90    QMessageBox::warning(this, "ddd Warning","Could not read event.",QMessageBox::Ok);
     91    EventHeaderDisplay->clear();
     92    return;
     93  }
    9094 
    91   PixelID->setText(PixMap->DRS_to_Pixel(BoardNo->value(),ChannelNo->value()/10,ChannelNo->value()%10).c_str());
    92   if(Socket->state() == QAbstractSocket::ConnectedState) return; // do not execute if socket is open
    93  
    94   // Read event
    95   FILE *Tmpfile = tmpfile();
    96 
    97    switch(RD->ReadEvent(EventNo->value(), Tmpfile)) {
    98     case !CTX_OK: 
    99       QMessageBox::warning(this, "ddd Warning","Could not read event.",QMessageBox::Ok);
    100       EventHeaderDisplay->clear();
    101       break;
    102     default:  // Print event header and trigger cell information from event data
    103       rewind(Tmpfile);
    104       QTextStream in(Tmpfile);
    105       QString text = in.readAll();
    106       text.append("\nTrigger cells: ");
    107       for (unsigned int i=0; i<RD->RHeader->NBoards*RD->RHeader->NChips; i++) {
    108         QString a;
    109         text.append(a.sprintf("%d ", *((int *)RD->Data + i)));
    110       }
    111       EventHeaderDisplay->setPlainText(text);
    112      
    113       // Case data in double format required by qwt library
    114       double* x = new double [RD->RHeader->Samples];
    115       double* y = new double [RD->RHeader->Samples];
    116 
    117       for (unsigned int i=0; i<RD->RHeader->Samples; i++) {
    118         x[i] = (double) (i/RD->BStruct[BoardNo->value()].NomFreq);
    119         y[i] = (double) *((short *) (RD->Data + RD->RHeader->NBoards*RD->RHeader->NChips*sizeof(int)) + BoardNo->value()*RD->RHeader->NChips*RD->RHeader->NChannels *
    120                  RD->RHeader->Samples+ChannelNo->value()*RD->RHeader->Samples+i)*RD->BStruct[BoardNo->value()].ScaleFactor;
    121       }
    122       Signal->setData(x, y, RD->RHeader->Samples);
    123       Signal->show();
    124       Zoomer->setZoomBase(Signal->boundingRect());
    125 
    126       //Get data for M0 display (event based)
    127 
    128       double z[6][6];//36 pixels
    129 
    130       for(unsigned int i=0; i<RD->RHeader->NBoards; i++) {//board loop
    131         for(unsigned int j=0; j<RD->RHeader->NChips; j++) {//chip loop
    132           for(unsigned int k=0; k<RD->RHeader->NChannels; k++) {//channel loop
    133 
    134             //only interested in M0 data
    135             if( ( (i==0 || i==1) && (j<=1) && (k<=7) ) || ( (i==2) && (j==0) && (k<=3) ) ) {
    136 
    137               //get module, superpixel and pixel number from pixel name
    138 
    139               std::string pixelname = PixMap->DRS_to_Pixel(i,j,k);
    140               char pixelname_copy[256];
    141               memset(pixelname_copy,'\0',256);
    142               pixelname.copy(pixelname_copy, 256);
    143              
    144               char delim[] = "-";
    145               char *buffer = NULL;
    146               int module = -1;
    147               int superpixel = -1;
    148               int pixel = -1;
    149              
    150               buffer = strtok(pixelname_copy, delim);
    151               module = atoi(buffer);
    152               buffer = strtok(NULL, delim);
    153               superpixel = atoi(buffer);
    154               buffer = strtok(NULL, delim);
    155               pixel = atoi(buffer);
    156                
    157               //usual M0 mapping
    158               //int binx = 5-(int((superpixel-1)/3)*2)-(int((pixel%4)/2));
    159               //int biny = 5-(((superpixel-1)%3)*2)-(int((pixel-1)/2));
    160                      
    161               //M0 upside down
    162               int binx = 5-(5-(int((superpixel-1)/3)*2)-(int((pixel%4)/2)));
    163               int biny = 5-(5-(((superpixel-1)%3)*2)-(int((pixel-1)/2)));
    164 
    165               //search maximum sample amplitude within user specified window
    166               //start bin is always smaller than stop bin (taken care of by updated ranges)
    167               int StartBin = (int)(M0Start->value());
    168               int StopBin = (int)(M0Stop->value());
    169              
    170               for(int l=StartBin; l<=StopBin; l++){
    171                  
    172                 float sample = *((short *) (RD->Data + RD->RHeader->NBoards*RD->RHeader->NChips*sizeof(int)) +
    173                                  i*RD->RHeader->NChips*RD->RHeader->NChannels*RD->RHeader->Samples+
    174                                  j*RD->RHeader->NChannels*RD->RHeader->Samples+
    175                                  k*RD->RHeader->Samples+
    176                                  l)*RD->BStruct[i].ScaleFactor;
    177                
    178                 if (sample > z[binx][biny]) {
    179                   z[binx][biny]=sample;
    180                 }
    181                
    182               }//sample loop
    183 
    184             }//only M0 data
    185            
    186           }//channel loop
    187         }//chip loop
    188       }//board loop
    189      
    190       //fill data to M0 display (event based)
    191       Signal2D->setData(SpectrogramDataM0(z));
    192       Graph2D->axisWidget(QwtPlot::yRight)->setColorMap(Signal2D->data().range(),Signal2D->colorMap());
    193       Graph2D->setAxisScale(QwtPlot::yRight,Signal2D->data().range().minValue(),Signal2D->data().range().maxValue() );
    194       Graph2D->replot();
    195       //Signal2D->show();
    196 
    197       //update ranges for start and stop bin to avoid startbin > stopbin
    198       M0Start->setRange(0, M0Stop->value()); 
    199       M0Stop->setRange(M0Start->value(),(RD->RHeader->Samples)-1);
    200 
    201       delete[] x;       delete[] y;
    202 
    203   }
    204   if(Tmpfile!=NULL) fclose(Tmpfile);
     95  // Print event header and trigger cell information from event data
     96  rewind(Tmpfile);
     97  QTextStream in(Tmpfile);
     98  QString text = in.readAll();
     99 
     100  text.append("\nTrigger cells: ");
     101  for (unsigned int i=0; i<RD->RHeader->NBoards*RD->RHeader->NChips; i++) {
     102    QString a;
     103    text.append(a.sprintf("%d ", *((int *)RD->Data + i)));
     104  }
     105  EventHeaderDisplay->setPlainText(text);
     106
     107  // Case data in double format required by qwt library
     108  double *x = new double [RD->RHeader->Samples];
     109  double *y = new double [RD->RHeader->Samples];
     110
     111  for (unsigned int i=0; i<RD->RHeader->Samples; i++) {
     112    x[i] = (double) (i/RD->BStruct[BoardNo->value()].NomFreq);
     113    y[i] = (double) *((short *) (RD->Data + RD->RHeader->NBoards*RD->RHeader->NChips*sizeof(int)) + BoardNo->value()*RD->RHeader->NChips*RD->RHeader->NChannels *
     114             RD->RHeader->Samples+ChannelNo->value()*RD->RHeader->Samples+i)*RD->BStruct[BoardNo->value()].ScaleFactor;
     115  }
     116
     117  Signal->setData(x, y, (int) RD->RHeader->Samples);
     118  Signal->show();
     119  Zoomer->setZoomBase(Signal->boundingRect());
     120 
     121  delete[] x;   delete[] y;
     122
     123  // ************************************   
     124  // Get data for M0 display (event based)
     125  // ************************************   
     126
     127  double z[6][6];//36 pixels
     128
     129  for(unsigned int i=0; i<RD->RHeader->NBoards; i++) {//board loop
     130    for(unsigned int j=0; j<RD->RHeader->NChips; j++) {//chip loop
     131      for(unsigned int k=0; k<RD->RHeader->NChannels; k++) {//channel loop
     132
     133        //only interested in M0 data
     134        if( ( (i==0 || i==1) && (j<=1) && (k<=7) ) || ( (i==2) && (j==0) && (k<=3) ) ) {
     135
     136          //get module, superpixel and pixel number from pixel name
     137
     138          std::string pixelname = PixMap->DRS_to_Pixel(i,j,k);
     139          char pixelname_copy[256];
     140          memset(pixelname_copy,'\0',256);
     141          pixelname.copy(pixelname_copy, 256);
     142
     143          char delim[] = "-";
     144          char *buffer = NULL;
     145          int module = -1;
     146          int superpixel = -1;
     147          int pixel = -1;
     148
     149          buffer = strtok(pixelname_copy, delim);
     150          module = atoi(buffer);
     151          buffer = strtok(NULL, delim);
     152          superpixel = atoi(buffer);
     153          buffer = strtok(NULL, delim);
     154          pixel = atoi(buffer);
     155
     156          //usual M0 mapping
     157          //int binx = 5-(int((superpixel-1)/3)*2)-(int((pixel%4)/2));
     158          //int biny = 5-(((superpixel-1)%3)*2)-(int((pixel-1)/2));
     159
     160          //M0 upside down
     161          int binx = 5-(5-(int((superpixel-1)/3)*2)-(int((pixel%4)/2)));
     162          int biny = 5-(5-(((superpixel-1)%3)*2)-(int((pixel-1)/2)));
     163
     164          //search maximum sample amplitude within user specified window
     165          //start bin is always smaller than stop bin (taken care of by updated ranges)
     166          int StartBin = (int)(M0Start->value());
     167          int StopBin = (int)(M0Stop->value());
     168
     169          for(int l=StartBin; l<=StopBin; l++){
     170
     171            float sample = *((short *) (RD->Data + RD->RHeader->NBoards*RD->RHeader->NChips*sizeof(int)) +
     172                             i*RD->RHeader->NChips*RD->RHeader->NChannels*RD->RHeader->Samples+
     173                             j*RD->RHeader->NChannels*RD->RHeader->Samples+
     174                             k*RD->RHeader->Samples+
     175                             l)*RD->BStruct[i].ScaleFactor;
     176
     177            if (sample > z[binx][biny]) {
     178              z[binx][biny]=sample;
     179            }
     180
     181          }//sample loop
     182        }//only M0 data
     183      }//channel loop
     184    }//chip loop
     185  }//board loop
     186
     187  //fill data to M0 display (event based)
     188  Signal2D->setData(SpectrogramDataM0(z));
     189  Graph2D->axisWidget(QwtPlot::yRight)->setColorMap(Signal2D->data().range(),Signal2D->colorMap());
     190  Graph2D->setAxisScale(QwtPlot::yRight,Signal2D->data().range().minValue(),Signal2D->data().range().maxValue() );
     191  Graph2D->replot();
     192
     193  //update ranges for start and stop bin to avoid startbin > stopbin
     194  M0Start->setRange(0, M0Stop->value()); 
     195  M0Stop->setRange(M0Start->value(),(RD->RHeader->Samples)-1);
    205196}
    206197
     
    304295  if (WaitForData && Text.endsWith(QLatin1String("==END=="))) {
    305296    // Extract text between ==START== and ==END==
    306     QByteArray Data=Text.mid(Text.lastIndexOf("==START==")+9,Text.length()-Text.lastIndexOf("==START==")-16).toAscii();
     297    QByteArray Data = Text.mid(Text.lastIndexOf("==START==")+9, Text.length() - Text.lastIndexOf("==START==")-16).toAscii();
    307298
    308299    char *NextNumber = strtok(Data.data()," ");  // Number of entries that follow
  • tools/ddd/GUI.cpp

    r66 r81  
    2424  PixMap = new PixelMap("../../config/PixelMap.txt", false);
    2525   
     26  Tmpfile = tmpfile();
     27  if(Tmpfile==NULL) {
     28    QMessageBox::warning(this, "ddd Message","Could not open temporary file.",QMessageBox::Ok);
     29  }
     30
    2631  //---------------------------------------------------------------------
    2732  //**************************** Main window ****************************
     
    107112  Signal->attach(Graph);
    108113  Signal->setStyle(QwtPlotCurve::Steps);
     114
     115  AutoscaleBox = new QCheckBox("Autoscale", Central);
     116  AutoscaleBox->setFont(QFont("Times", 10, QFont::Bold));
     117  AutoscaleBox->setToolTip("Scale axes automatically");
     118
     119  GraphLayout = new QVBoxLayout;
     120  GraphLayout->addWidget(Graph);
     121  GraphLayout->addWidget(AutoscaleBox);
    109122
    110123  // Text boxes for run and event header
     
    283296  delete M0Window;
    284297  delete PixMap;                delete RD;
     298 
     299  fclose(Tmpfile);
    285300}
    286301
  • tools/ddd/GUI.h

    r66 r81  
    2929
    3030    QPushButton *GetButton, *SocketButton, *Connect, *M0Display;
    31     QCheckBox *ContinuousBox;
     31    QCheckBox *ContinuousBox, *AutoscaleBox;
    3232    QToolButton *LoadButton;
    3333    QLineEdit *FilenameBox, *IPAddress, *Command, *PixelID;
     
    3939    QAction *OpenAction, *ConnectAction;
    4040    QGridLayout *SocketLayout, *MainLayout, *M0Layout;
     41    QVBoxLayout *GraphLayout;
    4142    QFormLayout *CommandLayout, *PortLayout, *AddressLayout, *FormLayout, *SpinLayout, *M0StartLayout, *M0StopLayout;
    4243   
     
    5455    RawDataCTX *RD;
    5556    PixelMap *PixMap;
     57    FILE *Tmpfile;
    5658     
    5759  public:
Note: See TracChangeset for help on using the changeset viewer.