Changeset 2266 for branches


Ignore:
Timestamp:
08/08/11 16:41:40 (13 years ago)
Author:
KohjiNakamura
Message:

optimize NRODataset::getSpectrum()

Location:
branches/parallel/external-alma/atnf/PKSIO
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/parallel/external-alma/atnf/PKSIO/NRODataset.cc

    r2262 r2266  
    7171  dataid_ = -1 ;
    7272
    73   // OS endian
    74   int i = 1 ;
    75   endian_ = -1 ;
    76   if ( *reinterpret_cast<char *>(&i) == 1 ) {
    77     endian_ = LITTLE_ENDIAN ;
    78     os << LogIO::NORMAL << "LITTLE_ENDIAN " << LogIO::POST ;
    79   }
    80   else {
    81     endian_ = BIG_ENDIAN ;
    82     os << LogIO::NORMAL << "BIG_ENDIAN " << LogIO::POST ;
    83   }
     73  // endian matches
    8474  same_ = -1 ;
    8575
     
    353343vector< vector<double> > NRODataset::getSpectrum()
    354344{
    355   vector< vector<double> > spec;
     345  vector< vector<double> > spec(rowNum_);
    356346
    357347  for ( int i = 0 ; i < rowNum_ ; i++ ) {
    358     spec.push_back( getSpectrum( i ) ) ;
     348    spec[i] = getSpectrum( i ) ;
    359349  }
    360350
     
    370360  //
    371361  // size of spectrum is not chmax_ but dataset_->getNCH() after binding
    372   int nchan = NUMCH ;
    373   vector<double> spec( chmax_, 0.0 ) ;  // spectrum "before" binding
     362  const int nchan = NUMCH ;
    374363  vector<double> bspec( nchan, 0.0 ) ;  // spectrum "after" binding
    375364  // DEBUG
     
    379368  NRODataRecord *record = getRecord( i ) ;
    380369
    381   int bit = IBIT ;   // fixed to 12 bit
     370  const int bit = IBIT ;   // fixed to 12 bit
    382371  double scale = record->SFCTR ;
    383372  // DEBUG
     
    392381    return bspec ;
    393382  }
    394   char *cdata = record->LDATA ;
     383  unsigned char *cdata = (unsigned char *)record->LDATA ;
    395384  vector<double> mscale = MLTSCF ;
    396385  double dscale = mscale[getIndex( i )] ;
     
    400389  // char -> int
    401390  vector<int> ispec( chmax_, 0 ) ;
    402   union SharedMemory {
    403     int ivalue ;
    404     unsigned char cbuf[4] ;
    405   } ;
    406   SharedMemory u ;
     391
     392  static const int shift_right[] = {
     393    4, 0
     394  };
     395  static const int start_pos[] = {
     396    0, 1
     397  };
     398  static const int incr[] = {
     399    0, 3
     400  };
    407401  int j = 0 ;
    408   char ctmp = 0x00 ;
    409   int sw = 0 ;
    410402  for ( int i = 0 ; i < chmax_ ; i++ ) {
     403    int ivalue = 0 ;
    411404    if ( bit == 12 ) {  // 12 bit qunatization
    412       u.ivalue = 0 ;
    413 
    414       if ( endian_ == BIG_ENDIAN ) {
    415         // big endian
    416         if ( sw == 0 ) {
    417           char c0 = (cdata[j] >> 4) & 0x0f ;
    418           char c1 = ((cdata[j] << 4) & 0xf0) | ((cdata[j+1] >> 4) & 0x0f) ;
    419           ctmp = cdata[j+1] & 0x0f ;
    420           u.cbuf[2] = c0 ;
    421           u.cbuf[3] = c1 ;
    422           j += 2 ;
    423           sw = 1 ;
    424         }
    425         else if ( sw == 1 ) {
    426           u.cbuf[2] = ctmp ;
    427           u.cbuf[3] = cdata[j] ;
    428           j++ ;
    429           sw = 0 ;
    430         }
    431       }
    432       else if ( endian_ == LITTLE_ENDIAN ) {
    433         // little endian
    434         if ( sw == 0 ) {
    435           char c0 = (cdata[j] >> 4) & 0x0f ;
    436           char c1 = ((cdata[j] << 4) & 0xf0) | ((cdata[j+1] >> 4) & 0x0f) ;
    437           ctmp = cdata[j+1] & 0x0f ;
    438           u.cbuf[1] = c0 ;
    439           u.cbuf[0] = c1 ;
    440           j += 2 ;
    441           sw = 1 ;
    442         }
    443         else if ( sw == 1 ) {
    444           u.cbuf[1] = ctmp ;
    445           u.cbuf[0] = cdata[j] ;
    446           j++ ;
    447           sw = 0 ;
    448         }
    449       }
    450     }
    451    
    452     ispec[i] = u.ivalue ;
     405      const int idx = j + start_pos[i & 1];
     406      const unsigned tmp = unsigned(cdata[idx]) << 8 | cdata[idx + 1];
     407      ivalue = int((tmp >> shift_right[i & 1]) & 0xFFF);
     408      j += incr[i & 1];
     409    }
     410
     411    ispec[i] = ivalue ;
    453412    if ( ( ispec[i] < 0 ) || ( ispec[i] > 4096 ) ) {
    454413      //cerr << "NRODataset::getSpectrum()  ispec[" << i << "] is out of range" << endl ;
     
    461420  }
    462421
     422  double *const spec = new double[ chmax_ ] ;  // spectrum "before" binding
    463423  // int -> double
    464424  for ( int i = 0 ; i < chmax_ ; i++ ) {
     
    490450      bspec[i] = spec[i] ;
    491451  }
     452  delete[] spec;
    492453
    493454  // DEBUG
  • branches/parallel/external-alma/atnf/PKSIO/NRODataset.h

    r2262 r2266  
    506506
    507507  // OS endian
    508   int endian_ ;
    509508  int same_ ;
    510509
Note: See TracChangeset for help on using the changeset viewer.