Changeset 2537 for branches


Ignore:
Timestamp:
05/18/12 19:16:51 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: see below

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Defined STIdxIterExAcc class that is able to handle Int and String scalar
columns. Also, fixed a bug in ArrayIndexIterartorAcc?.


Location:
branches/hpc33/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/hpc33/src/STIdxIter.cpp

    r2536 r2537  
    162162    pos_m[0] = len_m[0] ;
    163163    uInt offset = 0 ;
    164     while( offset <= ncol_m && !(skip_m[offset]) )
     164    while( offset < ncol_m && skip_m[offset] )
    165165      offset++ ;
    166166//     cout << "offset=" << offset << endl ;
    167167    return Vector<uInt>( pos_m, storage_m.storage()+offset*nrow_m, policy ) ;
    168168  }
    169   uInt *base = storage_m.storage() + (c+1) * nrow_m ;
     169  Int offset = c + 1 ;
     170  while( offset < ncol_m && skip_m[offset] )
     171    offset++ ;
     172//   cout << "offset = " << offset << endl ;
     173  uInt *base = storage_m.storage() + offset * nrow_m ;
    170174//   cout << "len_m[c+1]=" << len_m[c+1] << endl ;
    171175//   cout << "base=" << Vector<uInt>(IPosition(1,len_m[c+1]),base,SHARE) << endl ;
     
    176180  }
    177181  pos_m[0] = len_m[0] ;
     182//   cout << "pos_m=" << pos_m << endl ;
    178183  return Vector<uInt>( pos_m, base, policy ) ;
    179184}
     
    199204  }
    200205  else {
     206//     cout << "update " << icol << endl ;
    201207    uInt len = 0 ;
    202208    p = storage_m.storage() + icol * nrow_m ;
     
    348354}
    349355
     356STIdxIterExAcc::STIdxIterExAcc()
     357  : STIdxIter()
     358{
     359}
     360
     361STIdxIterExAcc::STIdxIterExAcc( const string &name,
     362                                const vector<string> &cols )
     363  : STIdxIter( name, cols )
     364{
     365  Table t( name, Table::Old ) ;
     366  init( t, cols ) ;
     367}
     368
     369STIdxIterExAcc::STIdxIterExAcc( const CountedPtr<Scantable> &s,
     370                                const vector<string> &cols )
     371  : STIdxIter( s, cols )
     372{
     373  init( s->table(), cols ) ;
     374}
     375
     376STIdxIterExAcc::~STIdxIterExAcc()
     377{
     378}
     379
     380void STIdxIterExAcc::init( Table &t,
     381                         const vector<string> &cols )
     382{
     383  uInt ncol = cols.size() ;
     384  uInt nrow = t.nrow() ;
     385  // array shape here is as follows if cols=["BEAMNO","POLNO","IFNO"]:
     386  // [[B0,B1,B2,...,BN],
     387  //  [P0,P1,P2,...,PN],
     388  //  [I0,I1,I2,...,IN]]
     389  // order of internal storage is
     390  // [B0,B1,B2,..,BN,P0,P1,P2,...,PN,I0,I1,I2,...,IN]
     391  Matrix<uInt> arr( nrow, ncol ) ;
     392  Vector<uInt> v ;
     393  ROScalarColumn<uInt> col ;
     394  ROScalarColumn<String> strCol ;
     395  ROScalarColumn<Int> intCol ;
     396  for ( uInt i = 0 ; i < ncol ; i++ ) {
     397    v.reference( arr.column( i ) ) ;
     398    if ( cols[i] == "SRCTYPE" ) {
     399      intCol.attach( t, cols[i] ) ;
     400      Vector<Int> srctype = intCol.getColumn() ;
     401      processIntCol( srctype, v, srctype_m ) ;
     402      srctypeid_m = i ;
     403    }
     404    else if ( cols[i] == "SRCNAME" ) {
     405      strCol.attach( t, cols[i] ) ;
     406      Vector<String> srcname = strCol.getColumn() ;
     407      processStrCol( srcname, v, srcname_m ) ;
     408      srcnameid_m = i ;
     409    }
     410    else {
     411      col.attach( t, cols[i] ) ;
     412      col.getColumn( v ) ;
     413    }
     414  }
     415  iter_m = new ArrayIndexIteratorAcc( arr ) ;
     416}
     417
     418void STIdxIterExAcc::processIntCol( Vector<Int> &in,
     419                                    Vector<uInt> &out,
     420                                    Block<Int> &val )
     421{
     422  uInt len = in.nelements() ;
     423  Vector<Int> tmp = in.copy() ;
     424  uInt n = genSort( tmp, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates ) ;
     425  val.resize( n ) ;
     426  for ( uInt i = 0 ; i < n ; i++ ) {
     427    val[i] = tmp[i] ;
     428//     cout << "val[" << i << "]=" << val[i] << endl ;
     429  }
     430  out.resize( len ) ;
     431  for ( uInt i = 0 ; i < len ; i++ ) {
     432    for ( uInt j = 0 ; j < n ; j++ ) {
     433      if ( in[i] == val[j] ) {
     434        out[i] = j ;
     435        break ;
     436      }
     437    }
     438  }
     439}
     440
     441void STIdxIterExAcc::processStrCol( Vector<String> &in,
     442                                    Vector<uInt> &out,
     443                                    Block<String> &val )
     444{
     445  uInt len = in.nelements() ;
     446  Vector<String> tmp = in.copy() ;
     447  uInt n = genSort( tmp, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates ) ;
     448  val.resize( n ) ;
     449  for ( uInt i = 0 ; i < n ; i++ ) {
     450    val[i] = tmp[i] ;
     451//     cout << "val[" << i << "]=" << val[i] << endl ;
     452  }
     453  out.resize( len ) ;
     454  for ( uInt i = 0 ; i < len ; i++ ) {
     455    for ( uInt j = 0 ; j < n ; j++ ) {
     456      if ( in[i] == val[j] ) {
     457        out[i] = j ;
     458        break ;
     459      }
     460    }
     461  }
     462}
     463
     464Int STIdxIterExAcc::getSrcType()
     465{
     466  if ( srctype_m.nelements() > 0 )
     467    return srctype_m[iter_m->current()[srctypeid_m]] ;
     468  else
     469    return -999 ;
     470}
     471
     472String STIdxIterExAcc::getSrcName()
     473{
     474  if ( srcname_m.nelements() > 0 )
     475    return srcname_m[iter_m->current()[srcnameid_m]] ;
     476  else
     477    return "" ;
     478}
     479
    350480} // namespace
  • branches/hpc33/src/STIdxIter.h

    r2536 r2537  
    77#include <casa/Arrays/Matrix.h>
    88#include <casa/Arrays/IPosition.h>
     9#include <casa/BasicSL/String.h>
    910
    1011#include "Scantable.h"
     
    127128} ;
    128129
    129 // class STIdxIterExAcc : public STIdxIterAcc
    130 // {
    131 //   STIdxIterExAcc() ;
    132 //   STIdxIterExAcc( const string &name,
    133 //                   const vector<string> &cols ) ;
    134 //   STIdxIterExAcc( const CountedPtr<Scantable> &s,
    135 //                   const vector<string> &cols ) ;
    136 //   ~STIdxIterExAcc() ;
    137 // protected:
    138 //   virtual void init( Table &t,
    139 //                      const vector<string> &cols ) ;
    140 // } ;
     130class STIdxIterExAcc : public STIdxIter
     131{
     132public:
     133  STIdxIterExAcc() ;
     134  STIdxIterExAcc( const string &name,
     135                  const vector<string> &cols ) ;
     136  STIdxIterExAcc( const CountedPtr<Scantable> &s,
     137                  const vector<string> &cols ) ;
     138  ~STIdxIterExAcc() ;
     139  Int getSrcType() ;
     140  String getSrcName() ;
     141protected:
     142  virtual void init( Table &t,
     143                     const vector<string> &cols ) ;
     144private:
     145  void processIntCol( Vector<Int> &in,
     146                      Vector<uInt> &out,
     147                      Block<Int> &val ) ;
     148  void processStrCol( Vector<String> &in,
     149                      Vector<uInt> &out,
     150                      Block<String> &val ) ;
     151  Block<Int> srctype_m ;
     152  Block<String> srcname_m ;
     153  uInt srctypeid_m ;
     154  uInt srcnameid_m ;
     155} ;
    141156
    142157} // namespace
Note: See TracChangeset for help on using the changeset viewer.