Changeset 2371


Ignore:
Timestamp:
12/15/11 17:14:29 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-2816

Ready for Test: No

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...

Direct array data access in STGrid::getData and STGrid::saveData.
Modified duplicate table copy in STGrid::saveData.


Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STGrid.cpp

    r2369 r2371  
    2121#include <measures/Measures/MDirection.h>
    2222
    23 #include <Scantable.h>
    2423#include <MathUtils.h>
    2524
     
    305304  double t0, t1 ;
    306305  t0 = mathutil::gettimeofday_sec() ;
    307   data.resize( gdata.shape() ) ;  //data = 0.0 ;
     306  data.resize( gdata.shape() ) ;
    308307  uInt len = data.nelements() ;
    309308  Float *w0_p ;
     
    466465  Table tab ;
    467466  selectData( tab ) ;
    468   ROScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
    469   Vector<uInt> pols = polnoCol.getColumn() ;
    470   Vector<uInt> pollistOrg ;
    471   uInt npolOrg = 0 ;
    472   for ( uInt i = 0 ; i < pols.size() ; i++ ) {
    473     if ( allNE( pollistOrg, pols[i] ) ) {
    474       pollistOrg.resize( npolOrg+1, True ) ;
    475       pollistOrg[npolOrg] = pols[i] ;
    476       npolOrg++ ;
    477     }
    478   }
    479   if ( pollist_.size() == 0 )
    480     pollist_ = pollistOrg ;
    481   else {
    482     Vector<uInt> newlist ;
    483     uInt newsize = 0 ;
    484     for ( uInt i = 0 ; i < pollist_.size() ; i++ ) {
    485       if ( anyEQ( pols, pollist_[i] ) ) {
    486         newlist.resize( newsize+1, True ) ;
    487         newlist[newsize] = pollist_[i] ;
    488         newsize++ ;
    489       }
    490     }
    491     pollist_ = newlist ;
    492   }
    493   npol_ = pollist_.size() ;
    494   ROArrayColumn<uChar> tmpCol( tab, "FLAGTRA" ) ;
    495   nchan_ = tmpCol( 0 ).nelements() ;
    496   nrow_ = tab.nrow() / npolOrg ;
     467  updatePolList( tab ) ;
    497468//   cout << "npol_ = " << npol_ << endl ;
    498469//   cout << "nchan_ = " << nchan_ << endl ;
     
    503474  Cube<Float> tsys( npol_, nchan_, nrow_ ) ;
    504475  Matrix<Double> tint( npol_, nrow_ ) ;
     476  // boolean for pointer access
     477  Bool bsp, bfl, bfr, bts, bti ;
     478  // pointer to the data
     479  Float *sp_p = spectra.getStorage( bsp ) ;
     480  uChar *fl_p = flagtra.getStorage( bfl ) ;
     481  uInt *fr_p = rflag.getStorage( bfr ) ;
     482  Float *ts_p = tsys.getStorage( bts ) ;
     483  Double *ti_p = tint.getStorage( bti ) ;
     484  // working pointer
     485  Float *wsp_p = sp_p ;
     486  uChar *wfl_p = fl_p ;
     487  uInt *wfr_p = fr_p ;
     488  Float *wts_p = ts_p ;
     489  Double *wti_p = ti_p ;
     490  uInt len = nchan_ * nrow_ ;
     491  IPosition mshape( 2, nchan_, nrow_ ) ;
     492  IPosition vshape( 1, nrow_ ) ;
    505493  for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
    506494    Table subt = tab( tab.col("POLNO") == pollist_[ipol] ) ;
     
    511499    ROArrayColumn<Float> tsysCol( subt, "TSYS" ) ;
    512500    ROScalarColumn<Double> tintCol( subt, "INTERVAL" ) ;
    513     Matrix<Float> tmpF = spectra.yzPlane( ipol ) ;
    514     Matrix<uChar> tmpUC = flagtra.yzPlane( ipol ) ;
    515     Vector<uInt> tmpUI = rflag.row( ipol ) ;
    516     spectraCol.getColumn( tmpF ) ;
    517     flagtraCol.getColumn( tmpUC ) ;
    518     rflagCol.getColumn( tmpUI ) ;
     501    Matrix<Float> spSlice( mshape, wsp_p, SHARE ) ;
     502    Matrix<uChar> flSlice( mshape, wfl_p, SHARE ) ;
     503    Vector<uInt> frSlice( vshape, wfr_p, SHARE ) ;
     504    spectraCol.getColumn( spSlice ) ;
     505    flagtraCol.getColumn( flSlice ) ;
     506    rflagCol.getColumn( frSlice ) ;
    519507    if ( ipol == 0 )
    520508      directionCol.getColumn( direction ) ;
    521     Matrix<Float> tmpF2 = tsysCol.getColumn() ;
    522     Vector<Double> tmpD = tint.row( ipol ) ;
    523     if ( tmpF2.shape()(0) == nchan_ ) {
    524       tsys.yzPlane( ipol ) = tmpF2 ;
     509    Vector<Float> tmpF = tsysCol( 0 ) ;
     510    Vector<Double> tmpD( vshape, wti_p, SHARE ) ;
     511    Matrix<Float> tsSlice( mshape, wts_p, SHARE ) ;
     512    if ( tmpF.nelements() == (uInt)nchan_ ) {
     513      tsysCol.getColumn( tsSlice ) ;
    525514    }
    526515    else {
    527       tsys.yzPlane( ipol ) = tmpF2(0,0) ;
     516      tsSlice = tmpF( 0 ) ;
    528517    }
    529518    tintCol.getColumn( tmpD ) ;
    530   }
     519
     520    wsp_p += len ;
     521    wfl_p += len ;
     522    wfr_p += nrow_ ;
     523    wts_p += len ;
     524    wti_p += nrow_ ;
     525  }
     526  spectra.putStorage( sp_p, bsp ) ;
     527  flagtra.putStorage( fl_p, bfl ) ;
     528  rflag.putStorage( fr_p, bfr ) ;
     529  tsys.putStorage( ts_p, bts ) ;
     530  tint.putStorage( ti_p, bti ) ;
    531531
    532532  getWeight( weight, tsys, tint ) ;
     533}
     534
     535void STGrid::updatePolList( Table &tab )
     536{
     537  ROScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
     538  Vector<uInt> pols = polnoCol.getColumn() ;
     539  Vector<uInt> pollistOrg ;
     540  uInt npolOrg = 0 ;
     541  uInt polno ;
     542  for ( uInt i = 0 ; i < polnoCol.nrow() ; i++ ) {
     543    //polno = polnoCol( i ) ;
     544    polno = pols( i ) ;
     545    if ( allNE( pollistOrg, polno ) ) {
     546      pollistOrg.resize( npolOrg+1, True ) ;
     547      pollistOrg[npolOrg] = polno ;
     548      npolOrg++ ;
     549    }
     550  }
     551  if ( pollist_.size() == 0 )
     552    pollist_ = pollistOrg ;
     553  else {
     554    Vector<uInt> newlist ;
     555    uInt newsize = 0 ;
     556    for ( uInt i = 0 ; i < pollist_.size() ; i++ ) {
     557      if ( anyEQ( pollistOrg, pollist_[i] ) ) {
     558        newlist.resize( newsize+1, True ) ;
     559        newlist[newsize] = pollist_[i] ;
     560        newsize++ ;
     561      }
     562    }
     563    pollist_.assign( newlist ) ;
     564  }
     565  npol_ = pollist_.size() ;
     566  if ( npol_ == 0 ) {
     567    LogIO os( LogOrigin("STGrid","updatePolList",WHERE) ) ;
     568    os << LogIO::SEVERE << "Empty pollist" << LogIO::EXCEPTION ;
     569  }
     570  nrow_ = tab.nrow() / npolOrg ;
     571  ROArrayColumn<uChar> tmpCol( tab, "FLAGTRA" ) ;
     572  nchan_ = tmpCol( 0 ).nelements() ;
     573//   LogIO os( LogOrigin("STGrid","updatePolList",WHERE) ) ;
     574//   os << "npol_ = " << npol_ << "(" << pollist_ << ")" << endl
     575//      << "nchan_ = " << nchan_ << endl
     576//      << "nrow_ = " << nrow_ << LogIO::POST ;
    533577}
    534578
     
    793837
    794838  //Int polno = 0 ;
    795   string outfile_ ;
     839  String outfile_ ;
    796840  if ( outfile.size() == 0 ) {
    797841    if ( infile_.lastchar() == '/' ) {
     
    806850    outfile_ = outfile ;
    807851  }
    808   CountedPtr<Scantable> ref( new Scantable( infile_, Table::Plain ) ) ;
    809   //cout << "ref->nchan()=" << ref->nchan() << endl ;
    810   CountedPtr<Scantable> out( new Scantable( *ref, True ) ) ;
    811   Table tab = out->table() ;
     852  Table tab ;
     853  prepareTable( tab, outfile_ ) ;
    812854  IPosition dshape = data_.shape() ;
    813855  Int nrow = nx_ * ny_ * npol_ ;
     
    822864  ScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
    823865  Int irow = 0 ;
     866  Vector<Float> sp( nchan_ ) ;
     867  Bool bsp, bdata ;
     868  const Float *data_p = data_.getStorage( bdata ) ;
     869  Float *wsp_p, *sp_p ;
     870  const Float *wdata_p = data_p ;
     871  long step = nx_ * ny_ * npol_ ;
     872  long offset ;
    824873  for ( Int iy = 0 ; iy < ny_ ; iy++ ) {
     874    dir(1) = center_(1) - ( cpix(1) - (Double)iy ) * celly_ ;
    825875    for ( Int ix = 0 ; ix < nx_ ; ix++ ) {
     876      dir(0) = center_(0) - ( cpix(0) - (Double)ix ) * cellx_ ;
    826877      for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
    827         IPosition start( 4, ix, iy, ipol, 0 ) ;
    828         IPosition end( 4, ix, iy, ipol, nchan_-1 ) ;
    829         IPosition inc( 4, 1, 1, 1, 1 ) ;
    830         Vector<Float> sp = data_( start, end, inc ) ;
    831         dir(0) = center_(0) - ( cpix(0) - (Double)ix ) * cellx_ ;
    832         dir(1) = center_(1) - ( cpix(1) - (Double)iy ) * celly_ ;
     878        offset = ix + iy * nx_ + ipol * nx_ * ny_ ;
     879        //os << "offset = " << offset << LogIO::POST ;
     880        sp_p = sp.getStorage( bsp ) ;
     881        wsp_p = sp_p ;
     882        wdata_p = data_p + offset ;
     883        for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
     884          *wsp_p = *wdata_p ;
     885          wsp_p++ ;
     886          wdata_p += step ;
     887        }
     888        sp.putStorage( sp_p, bsp ) ;
    833889        spectraCol.put( irow, sp ) ;
    834890        directionCol.put( irow, dir ) ;
     
    838894    }
    839895  }
    840   //cout << "outfile_=" << outfile_ << endl ;
    841   out->makePersistent( outfile_ ) ;
     896  data_.freeStorage( data_p, bdata ) ;
    842897
    843898  t1 = mathutil::gettimeofday_sec() ;
     
    847902}
    848903
    849 }
     904void STGrid::prepareTable( Table &tab, String &name )
     905{
     906  Table t( infile_, Table::Old ) ;
     907  t.deepCopy( name, Table::New, False, t.endianFormat(), True ) ;
     908  tab = Table( name, Table::Update ) ;
     909}
     910}
  • trunk/src/STGrid.h

    r2369 r2371  
    111111  Double polMean( const Double *p ) ;
    112112
     113  void updatePolList( Table &tab ) ;
     114
     115  void prepareTable( Table &tab, String &name ) ;
     116
    113117  String infile_ ;
    114118  Int ifno_ ;
Note: See TracChangeset for help on using the changeset viewer.