Changeset 2598 for branches


Ignore:
Timestamp:
07/12/12 11:32:35 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Speed up NRODataset::getSpectrum.

  • Share allocated memory as much as possible.
  • Dropped integer array creation.


File:
1 edited

Legend:

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

    r2596 r2598  
    357357  // size of spectrum is not chmax_ but dataset_->getNCH() after binding
    358358  const int nchan = NUMCH ;
    359   vector<double> bspec( nchan, 0.0 ) ;  // spectrum "after" binding
     359  vector<double> spec( chmax_ ) ;  // spectrum "before" binding
    360360  // DEBUG
    361361  //cout << "NRODataset::getSpectrum()  nchan = " << nchan << " chmax_ = " << chmax_ << endl ;
     
    375375  if ( ( scale == 0.0 ) && ( offset == 0.0 ) ) {
    376376    //cerr << "NRODataset::getSpectrum()  zero spectrum (" << i << ")" << endl ;
    377     return bspec ;
     377    LogIO os( LogOrigin("NRODataset","getSpectrum",WHERE) ) ;
     378    os << LogIO::WARN << "zero spectrum for row " << i << LogIO::POST ;
     379    if ( spec.size() != nchan )
     380      spec.resize( nchan ) ;
     381    for ( vector<double>::iterator i = spec.begin() ;
     382          i != spec.end() ; i++ )
     383      *i = 0.0 ;
     384    return spec ;
    378385  }
    379386  unsigned char *cdata = (unsigned char *)record->LDATA ;
     
    383390  int chmin = CHMIN ;
    384391
    385   // char -> int
    386   int *ispec = new int[chmax_] ;
    387   int *int_p = ispec ;
     392  // char -> int -> double
     393  vector<double>::iterator iter = spec.begin() ;
    388394
    389395  static const int shift_right[] = {
     
    398404  int j = 0 ;
    399405  for ( int i = 0 ; i < chmax_ ; i++ ) {
     406    // char -> int
    400407    int ivalue = 0 ;
    401408    if ( bit == 12 ) {  // 12 bit qunatization
     
    410417      //cerr << "NRODataset::getSpectrum()  ispec[" << i << "] is out of range" << endl ;
    411418      LogIO os( LogOrigin( "NRODataset", "getSpectrum", WHERE ) ) ;
    412       os << LogIO::SEVERE << "ispec[" << i << "] is out of range" << LogIO::EXCEPTION ;
    413       delete ispec ;
    414       return bspec ;
     419      os << LogIO::SEVERE << "ivalue for row " << i << " is out of range" << LogIO::EXCEPTION ;
     420      if ( spec.size() != nchan )
     421        spec.resize( nchan ) ;
     422      for ( vector<double>::iterator i = spec.begin() ;
     423            i != spec.end() ; i++ )
     424        *i = 0.0 ;
     425      return spec ;
    415426    }
    416427    // DEBUG
    417428    //cout << "NRODataset::getSpectrum()  ispec[" << i << "] = " << ispec[i] << endl ;
    418429    //
    419     *int_p = ivalue ;
    420     int_p++ ;
    421   }
    422 
    423   double *const spec = new double[ chmax_ ] ;  // spectrum "before" binding
    424   // int -> double
    425   int_p = ispec ;
    426   double *double_p = spec ;
    427   for ( int i = 0 ; i < chmax_ ; i++ ) {
    428     *double_p = (double)( (*int_p) * scale + offset ) * dscale ;
     430
     431    // int -> double
     432    *iter = (double)( ivalue * scale + offset ) * dscale ;
    429433    // DEBUG
    430     //cout << "NRODataset::getSpectrum()  spec[" << i << "] = " << spec[i] << endl ;
     434    //cout << "NRODataset::getSpectrum()  spec[" << i << "] = " << *iter << endl ;
    431435    //
    432     int_p++ ;
    433     double_p++ ;
    434   }
    435   delete ispec ;
    436 
    437   // channel binding
     436    iter++ ;
     437  }
     438
     439  // channel binding if necessary
    438440  if ( cbind != 1 ) {
    439     double_p = &(spec[chmin]) ;
    440     for ( vector<double>::iterator i = bspec.begin() ;
    441           i != bspec.end() ; i++ ) {
     441    iter = spec.begin() ;
     442    advance( iter, chmin ) ;
     443    vector<double>::iterator iter2 = spec.begin() ;
     444    for ( int i = 0 ; i < nchan ; i++ ) {
    442445      double sum0 = 0 ;
    443446      double sum1 = 0 ;
    444447      for ( int j = 0 ; j < cbind ; j++ ) {
    445         sum0 += *double_p ;
     448        sum0 += *iter ;
    446449        sum1 += 1.0 ;
    447         double_p++ ;
     450        iter++ ;
    448451      }
    449       *i = sum0 / sum1 ;
    450       i++ ;
     452      *iter2 = sum0 / sum1 ;
     453      iter2++ ;
    451454      // DEBUG
    452455      //cout << "NRODataset::getSpectrum()  bspec[" << i << "] = " << bspec[i] << endl ;
    453456      //
    454457    }
    455   }
    456   else {
    457     double_p = spec ;
    458     for ( vector<double>::iterator i = bspec.begin() ;
    459           i != bspec.end() ; i++ ) {
    460       *i = *double_p ;
    461       double_p++ ;
    462     }
    463   }
    464   delete[] spec;
     458    spec.resize( nchan ) ;
     459  }
    465460
    466461  // DEBUG
     
    468463  //
    469464
    470   return bspec ;
     465  return spec ;
    471466}
    472467
Note: See TracChangeset for help on using the changeset viewer.