Changeset 2263 for branches


Ignore:
Timestamp:
08/04/11 15:42:43 (13 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: No

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

Tuning NROFiller.
Filler is about 6 times faster than before (~660sec->~110sec).

Location:
branches/parallel
Files:
7 edited

Legend:

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

    r2262 r2263  
    531531                            String &srcname,
    532532                            String &fieldname,
    533                             Array<Float> &spectra,
    534                             Array<uChar> &flagtra,
    535                             Array<Float> &tsys,
    536                             Array<Double> &direction,
     533                            Vector<Float> &spectra,
     534                            Vector<uChar> &flagtra,
     535                            Vector<Float> &tsys,
     536                            Vector<Double> &direction,
    537537                            Float &azimuth,
    538538                            Float &elevation,
     
    548548                            Float &winddir,     
    549549                            Double &srcvel,
    550                             Array<Double> &propermotion,
     550                            Vector<Double> &propermotion,
    551551                            Vector<Double> &srcdir,
    552                             Array<Double> &scanrate )
     552                            Vector<Double> &scanrate )
    553553{
    554554  // DEBUG
     
    589589
    590590  // restfreq (for MOLECULE_ID)
    591   Vector<Double> rf( IPosition( 1, 1 ) ) ;
    592   rf( 0 ) = record->FREQ0 ;
    593   restfreq = rf ;
     591  if ( restfreq.size() != 1 )
     592    restfreq.resize( 1 ) ;
     593  restfreq[0] = record->FREQ0 ;
    594594  //cout << "restfreq = " << rf << endl ;
    595595
     
    617617  // spectra
    618618  vector<double> spec = dataset_->getSpectrum( irow ) ;
    619   Array<Float> sp( IPosition( 1, spec.size() ) ) ;
     619  if ( spectra.size() != spec.size() )
     620    spectra.resize( spec.size() ) ;
    620621  int index = 0 ;
    621   for ( Array<Float>::iterator itr = sp.begin() ; itr != sp.end() ; itr++ ) {
     622  for ( Vector<Float>::iterator itr = spectra.begin() ; itr != spectra.end() ; itr++ ) {
    622623    *itr = spec[index++] ;
    623624  }
    624   spectra = sp ;
    625625  //cout << "spec.size() = " << spec.size() << endl ;
    626626 
    627627  // flagtra
    628   Array<uChar> flag( spectra.shape() ) ;
    629   flag.set( 0 ) ;
    630   flagtra = flag ;
     628  if ( flagtra.size() != spectra.size() )
     629    flagtra.resize( spectra.nelements() ) ;
     630  flagtra.set( 0 ) ;
    631631  //cout << "flag.size() = " << flag.size() << endl ;
    632632
    633633  // tsys
    634   Array<Float> tmp( IPosition( 1, 1 ), record->TSYS ) ;
    635   tsys = tmp ;
     634  if ( tsys.size() != 1 )
     635    tsys.resize( 1 ) ;
     636  tsys[0] = record->TSYS ;
    636637  //cout << "tsys[0] = " << tsys[0] << endl ;
    637638
     
    693694
    694695  // propermotion
    695   Array<Double> srcarr( IPosition( 1, 2 ) ) ;
    696   srcarr = 0.0 ;
    697   propermotion = srcarr ;
    698   //cout << "propermotion = [" << propermotion[0] << ", " << propermotion[1] << "]" << endl ;
     696  // do nothing
    699697
    700698  // srcdir
     
    703701
    704702  // scanrate
    705   Array<Double> sr( IPosition( 1, 1 ) ) ;
    706   sr = 0.0 ;
    707   scanrate = sr ;
    708   //cout << "scanrate = " << scanrate[0] << endl ;
     703  // do nothing
    709704
    710705  return 0 ;
  • branches/parallel/external-alma/atnf/PKSIO/NROReader.h

    r2262 r2263  
    139139                           String &srcname,
    140140                           String &fieldname,
    141                            Array<Float> &spectra,
    142                            Array<uChar> &flagtra,
    143                            Array<Float> &tsys,
    144                            Array<Double> &direction,
     141                           Vector<Float> &spectra,
     142                           Vector<uChar> &flagtra,
     143                           Vector<Float> &tsys,
     144                           Vector<Double> &direction,
    145145                           Float &azimuth,
    146146                           Float &elevation,
     
    156156                           Float &winddir,     
    157157                           Double &srcvel,
    158                            Array<Double> &propermotion,
     158                           Vector<Double> &propermotion,
    159159                           Vector<Double> &srcdir,
    160                            Array<Double> &scanrate ) ;
     160                           Vector<Double> &scanrate ) ;
    161161
    162162  // Get scan type
  • branches/parallel/src/FillerBase.cpp

    r2247 r2263  
    2424{
    2525    row_ = TableRow(table_->table());
     26
     27    mEntry_.resize( 0 ) ;
     28    mIdx_.resize( 0 ) ;
     29    fEntry_.resize( 0 ) ;
     30    fIdx_.resize( 0 ) ;
     31    wEntry_.resize( 0 ) ;
     32    wIdx_.resize( 0 ) ;
    2633}
    2734
     
    7885{
    7986  /// @todo this has to change when nchan isn't global anymore
    80   uInt id= table_->frequencies().addEntry(refpix, refval, incr);
     87  uInt nEntry = fEntry_.size() ;
     88  Int idx = -1 ;
     89  Vector<Double> entry( 3 ) ;
     90  entry[0] = refpix ;
     91  entry[1] = refval ;
     92  entry[2] = incr ;
     93  for ( uInt i = 0 ; i < nEntry ; i++ ) {
     94    if ( allEQ( entry, fEntry_[i] ) ) {
     95      idx = i ;
     96      break ;
     97    }
     98  }
     99  uInt id ;
     100  if ( idx != -1 )
     101    id = fIdx_[idx] ;
     102  else {
     103    id= table_->frequencies().addEntry(refpix, refval, incr);
     104    RecordFieldPtr<uInt> mfreqidCol(row_.record(), "FREQ_ID");
     105    fEntry_.push_back( entry ) ;
     106    fIdx_.push_back( id ) ;
     107  }
    81108  RecordFieldPtr<uInt> mfreqidCol(row_.record(), "FREQ_ID");
    82109  *mfreqidCol = id;
     
    87114void FillerBase::setMolecule(const Vector<Double>& restfreq)
    88115{
    89   Vector<String> tmp;
    90   uInt id = table_->molecules().addEntry(restfreq, tmp, tmp);
     116  uInt nEntry = mEntry_.size() ;
     117  Int idx = -1 ;
     118  for ( uInt i = 0 ; i < nEntry ; i++ ) {
     119    if ( restfreq.conform( mEntry_[i] ) ) {
     120      if ( allEQ( restfreq, mEntry_[i] ) ) {
     121        idx = i ;
     122        break ;
     123      }
     124    }
     125  }
     126  uInt id ;
     127  if ( idx != -1 )
     128    id = mIdx_[idx] ;
     129  else {
     130    Vector<String> tmp ;
     131    id = table_->molecules().addEntry(restfreq,tmp,tmp) ;
     132    mEntry_.push_back( restfreq ) ;
     133    mIdx_.push_back( id ) ;
     134  }
    91135  RecordFieldPtr<uInt> molidCol(row_.record(), "MOLECULE_ID");
    92136  *molidCol = id;
     
    125169                        Float windspeed, Float windaz)
    126170{
    127     uInt id = table_->weather().addEntry(temperature, pressure,
    128                                          humidity, windspeed, windaz);
    129     RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
    130     *mweatheridCol = id;
     171  uInt nEntry = wEntry_.size() ;
     172  Int idx = -1 ;
     173  Vector<Float> entry( 5 ) ;
     174  entry[0] = temperature ;
     175  entry[1] = pressure ;
     176  entry[2] = humidity ;
     177  entry[3] = windspeed ;
     178  entry[4] = windaz ;
     179  for ( uInt i = 0 ; i < nEntry ; i++ ) {
     180    if ( allEQ( entry, wEntry_[i] ) ) {
     181      idx = i ;
     182      break ;
     183    }
     184  }
     185  uInt id ;
     186  if ( idx != -1 )
     187    id = wIdx_[idx] ;
     188  else {
     189    id = table_->weather().addEntry(temperature, pressure,
     190                                    humidity, windspeed, windaz);
     191    wEntry_.push_back( entry ) ;
     192    wIdx_.push_back( id ) ;
     193  }
     194  RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
     195  *mweatheridCol = id;
    131196}
    132197
     
    183248                             Float windaz)
    184249{
     250  uInt nEntry = wEntry_.size() ;
     251  Int idx = -1 ;
     252  Vector<Float> entry( 5 ) ;
     253  entry[0] = temperature ;
     254  entry[1] = pressure ;
     255  entry[2] = humidity ;
     256  entry[3] = windspeed ;
     257  entry[4] = windaz ;
     258  for ( uInt i = 0 ; i < nEntry ; i++ ) {
     259    if ( allEQ( entry, wEntry_[i] ) ) {
     260      idx = i ;
     261      break ;
     262    }
     263  }
    185264  uInt id ;
    186   Table tab = table_->weather().table() ;
    187   Table subt = tab( tab.col("TEMPERATURE") == temperature \
    188                     && tab.col("PRESSURE") == pressure \
    189                     && tab.col("HUMIDITY") == humidity \
    190                     && tab.col("WINDSPEED") == windspeed \
    191                     && tab.col("WINDAZ") == windaz, 1 ) ;
    192   Int nrow = tab.nrow() ;
    193   Int nrowSel = subt.nrow() ;
    194   if ( nrowSel == 0 ) {
    195     tab.addRow( 1, True ) ;
    196     TableRow row( tab ) ;
    197     TableRecord &rec = row.record() ;
    198     RecordFieldPtr<casa::uInt> rfpi ;
    199     rfpi.attachToRecord( rec, "ID" ) ;
    200     *rfpi = (uInt)nrow ;
    201     RecordFieldPtr<casa::Float> rfp ;
    202     rfp.attachToRecord( rec, "TEMPERATURE" ) ;
    203     *rfp = temperature ;
    204     rfp.attachToRecord( rec, "PRESSURE" ) ;
    205     *rfp = pressure ;
    206     rfp.attachToRecord( rec, "HUMIDITY" ) ;
    207     *rfp = humidity ;
    208     rfp.attachToRecord( rec, "WINDSPEED" ) ;
    209     *rfp = windspeed ;
    210     rfp.attachToRecord( rec, "WINDAZ" ) ;
    211     *rfp = windaz ;
    212     row.put( nrow, rec ) ;
    213     id = (uInt)nrow ;
    214   }
    215   else {
    216     ROTableColumn tc( subt, "ID" ) ;
    217     id = tc.asuInt( 0 ) ;
     265  if ( idx != -1 )
     266    id = wIdx_[idx] ;
     267  else {
     268    Table tab = table_->weather().table() ;
     269    Table subt = tab( tab.col("TEMPERATURE") == temperature     \
     270                      && tab.col("PRESSURE") == pressure        \
     271                      && tab.col("HUMIDITY") == humidity        \
     272                      && tab.col("WINDSPEED") == windspeed      \
     273                      && tab.col("WINDAZ") == windaz, 1 ) ;
     274    Int nrow = tab.nrow() ;
     275    Int nrowSel = subt.nrow() ;
     276    if ( nrowSel == 0 ) {
     277      tab.addRow( 1, True ) ;
     278      TableRow row( tab ) ;
     279      TableRecord &rec = row.record() ;
     280      RecordFieldPtr<casa::uInt> rfpi ;
     281      rfpi.attachToRecord( rec, "ID" ) ;
     282      *rfpi = (uInt)nrow ;
     283      RecordFieldPtr<casa::Float> rfp ;
     284      rfp.attachToRecord( rec, "TEMPERATURE" ) ;
     285      *rfp = temperature ;
     286      rfp.attachToRecord( rec, "PRESSURE" ) ;
     287      *rfp = pressure ;
     288      rfp.attachToRecord( rec, "HUMIDITY" ) ;
     289      *rfp = humidity ;
     290      rfp.attachToRecord( rec, "WINDSPEED" ) ;
     291      *rfp = windspeed ;
     292      rfp.attachToRecord( rec, "WINDAZ" ) ;
     293      *rfp = windaz ;
     294      row.put( nrow, rec ) ;
     295      id = (uInt)nrow ;
     296    }
     297    else {
     298      ROTableColumn tc( subt, "ID" ) ;
     299      id = tc.asuInt( 0 ) ;
     300    }
     301    wEntry_.push_back( entry ) ;
     302    wIdx_.push_back( id ) ;
    218303  }
    219304  RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
  • branches/parallel/src/FillerBase.h

    r2247 r2263  
    2727// STL
    2828#include <string>
     29#include <vector>
    2930// AIPS++
    3031#include <casa/aips.h>
     
    103104    casa::String referenceRx_;
    104105    casa::TableRow row_;
     106 
     107    std::vector< casa::Vector<casa::Double> > mEntry_ ;
     108    std::vector<casa::uInt> mIdx_ ;
     109    std::vector< casa::Vector<casa::Double> > fEntry_ ;
     110    std::vector<casa::uInt> fIdx_ ;
     111    std::vector< casa::Vector<casa::Float> > wEntry_ ;
     112    std::vector<casa::uInt> wIdx_ ;
    105113};
    106114
  • branches/parallel/src/FillerWrapper.h

    r1904 r2263  
    4545      throw(AipsError("File does not exist"));
    4646    }
    47     filler_ = new PKSFiller(stable_);
    48     if (filler_->open(filename, rec)) {
    49       //    if (filler_->open(filename)) {
    50       attached_ = true;
    51       return;
     47    int fileType = dataType( filename ) ;
     48    if ( fileType == 0 ) {
     49      filler_ = new PKSFiller(stable_);
     50      if (filler_->open(filename, rec)) {
     51        attached_ = true;
     52        return;
     53      }
    5254    }
    53     filler_ = new NROFiller(stable_);
    54     if (filler_->open(filename, rec)) {
    55       //    if (filler_->open(filename)) {
    56       attached_ = true;
    57       return;
     55    else if ( fileType == 1 ) {
     56      filler_ = new NROFiller(stable_);
     57      if (filler_->open(filename, rec)) {
     58        attached_ = true;
     59        return;
     60      }
    5861    }
    5962    filler_ = 0;
     
    8184private:
    8285
     86  int dataType( const std::string &filename ) {
     87    int ret = -1 ;
     88    int pks = 0 ;
     89    int nro = 1 ;
     90    casa::File file( filename ) ;
     91    if ( file.isDirectory() )
     92      ret = pks ;
     93    else if ( file.isReadable() ) {
     94      FILE *f = fopen( filename.c_str(), "r") ;
     95      char buf[8] ;
     96      fread( buf, 6, 1, f ) ;
     97      fclose( f ) ;
     98      buf[7]='\0' ;
     99      // NRO data has two types:
     100      //  1) specific binary data for OTF observation
     101      //  2) (pseudo-)FITS data that doesn't have primary HDU
     102      // So, one can distinguish NRO and non-NRO data by examining
     103      // first keyword name.
     104      if ( casa::String( buf ) == "SIMPLE" ) {
     105        ret = pks ;
     106      }
     107      else {
     108        ret = nro ;
     109      }
     110    }
     111    return ret ;
     112  }
     113
    83114  FillerWrapper();
    84115  FillerWrapper(const FillerWrapper&);
  • branches/parallel/src/NROFiller.cpp

    r2262 r2263  
    100100  String srcname ;
    101101  String fieldname ;
    102   Array<Float> spectra ;
    103   Array<uChar> flagtra ;
    104   Array<Float> tsys ;
    105   Array<Double> direction ;
     102  Vector<Float> spectra ;
     103  Vector<uChar> flagtra ;
     104  Vector<Float> tsys ;
     105  Vector<Double> direction ;
    106106  Float azimuth ;
    107107  Float elevation ;
    108   Float parangle ;
     108  Float parangle = 0.0 ;
    109109  Float opacity ;
    110110  uInt tcalid ;
     
    117117  Float winddir ;
    118118  Double srcvel ;
    119   Array<Double> propermotion ;
     119  Vector<Double> propermotion( 2, 0.0 ) ;
    120120  Vector<Double> srcdir ;
    121   Array<Double> scanrate ;
     121  Vector<Double> scanrate( 2, 0.0 ) ;
    122122  Int rowCount = 0 ;
    123123
     
    126126  Vector<Float> defaultTcal( 1, 1.0 ) ;
    127127  String tcalTime = MVTime( header.utc ).string( MVTime::YMD ) ;
     128
     129  // TCAL subtable rows
     130  setTcal( tcalTime, defaultTcal ) ;
     131
     132  // FOCUS subtable rows
     133  setFocus( parangle ) ;
     134
    128135  for ( Int irow = 0 ; irow < (Int)nRow ; irow++ ) {
    129136    // check scan intent
     
    195202    setMolecule( restfreq ) ;
    196203
    197     // FOCUS subtable row
    198     setFocus( parangle ) ;
    199 
    200204    // WEATHER subtable row
    201     setWeather( temperature, pressure, humidity, windvel, winddir ) ;
    202 
    203     // TCAL subtable row
    204     // use default since NRO input is calibrated data
    205     setTcal( tcalTime, defaultTcal ) ;
    206    
     205    setWeather2( temperature, pressure, humidity, windvel, winddir ) ;
    207206
    208207    // set row attributes
    209208    // SPECTRA, FLAGTRA, and TSYS
    210     Vector<Float> spectrum( spectra );
    211     Vector<uChar> flags( flagtra ) ;
    212     Vector<Float> Tsys( tsys ) ;
    213     setSpectrum( spectrum, flags, Tsys ) ;
     209    setSpectrum( spectra, flagtra, tsys ) ;
    214210
    215211    // SCANNO, CYCLENO, IFNO, POLNO, and BEAMNO
    216     //uInt ifno = table_->frequencies().addEntry( (Double)fqs[0], (Double)fqs[1], (Double)fqs[2] ) ;
    217212    setIndex( scanno, cycleno, ifno, polno, beamno ) ;
    218213
     
    221216
    222217    // DIRECTION
    223     Vector<Double> dir( direction ) ;
    224     setDirection(dir, azimuth, elevation ) ;
     218    setDirection( direction, azimuth, elevation ) ;
    225219
    226220    // TIME and INTERVAL
     
    228222
    229223    // SRCNAME, SRCTYPE, FIELDNAME, SRCDIRECTION, SRCPROPERMOTION, and SRCVELOCITY
    230     Vector<Double> propermot( propermotion ) ;
    231     setSource( srcname, srcType, fieldname, srcdir, propermot, srcvel ) ;
     224    setSource( srcname, srcType, fieldname, srcdir, propermotion, srcvel ) ;
    232225
    233226    // SCANRATE
    234     Vector<Double> srate( scanrate ) ;
    235     setScanRate( srate ) ;
     227    setScanRate( scanrate ) ;
    236228
    237229    // OPACITY
  • branches/parallel/src/STFiller.cpp

    r2262 r2263  
    644644  String srcname ;
    645645  String fieldname ;
    646   Array<Float> spectra ;
    647   Array<uChar> flagtra ;
    648   Array<Float> tsys ;
    649   Array<Double> direction ;
     646  Vector<Float> spectra ;
     647  Vector<uChar> flagtra ;
     648  Vector<Float> tsys ;
     649  Vector<Double> direction ;
    650650  Float azimuth ;
    651651  Float elevation ;
     
    661661  Float winddir ;
    662662  Double srcvel ;
    663   Array<Double> propermotion ;
     663  Vector<Double> propermotion( 2, 0.0 ) ;
    664664  Vector<Double> srcdir ;
    665   Array<Double> scanrate ;
     665  Vector<Double> scanrate( 2, 0.0 ) ;
    666666  for ( i = 0 ; i < imax ; i++ ) {
    667667    string scanType = nreader_->getScanType( i ) ;
Note: See TracChangeset for help on using the changeset viewer.