Changeset 2003 for trunk/src


Ignore:
Timestamp:
02/21/11 16:09:55 (14 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-2718

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

Introduced binary search in detecting SYSCAL and POINTING rows.


Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/MSFiller.cpp

    r2002 r2003  
    569569          MSSysCal caltabsel( caltab( caltab.col("ANTENNA_ID") == antenna_ && caltab.col("FEED_ID") == feedId && caltab.col("SPECTRAL_WINDOW_ID") == spwId ).sort("TIME") ) ;
    570570          ROScalarMeasColumn<MEpoch> scTimeCol( caltabsel, "TIME" ) ;
    571           Block<MEpoch> scTime( caltabsel.nrow() ) ;
     571          Vector<MEpoch> scTime( caltabsel.nrow() ) ;
    572572          for ( uInt irow = 0 ; irow < caltabsel.nrow() ; irow++ )
    573573            scTime[irow] = scTimeCol( irow ) ;
     
    13051305}
    13061306
    1307 void MSFiller::getSysCalTime( Block<MEpoch> &scTime, Vector<Double> &scInterval, Block<MEpoch> &tcol, Block<Double> &tstr, Block<Int> &tidx )
     1307void MSFiller::getSysCalTime( Vector<MEpoch> &scTime, Vector<Double> &scInterval, Block<MEpoch> &tcol, Block<Double> &tstr, Block<Int> &tidx )
    13081308{
    13091309  double startSec = gettimeofday_sec() ;
     
    13151315  uInt idx = 0 ;
    13161316  const Double half = 0.5e0 ;
     1317  // execute  binary search
     1318  idx = binarySearch( scTime, tcol[0].get( "s" ).getValue() ) ;
     1319  if ( idx != 0 )
     1320    idx -= 1 ;
    13171321  for ( uInt i = 0 ; i < nrow ; i++ ) {
    13181322    Double t = tcol[i].get( "s" ).getValue() ;
     
    13401344  }
    13411345  double endSec = gettimeofday_sec() ;
    1342   os_ << "end MSFiller::getSysCalTime() endSec=" << endSec << " (" << endSec-startSec << "sec) scnrow = " << scnrow << "tcol.nelements() = " << tcol.nelements() << LogIO::POST ;
     1346  os_ << "end MSFiller::getSysCalTime() endSec=" << endSec << " (" << endSec-startSec << "sec) scnrow = " << scnrow << " tcol.nelements = " << tcol.nelements() << LogIO::POST ;
    13431347  return ;
    13441348}
     
    14101414  ROArrayMeasColumn<MDirection> dmcol( tab, "DIRECTION" ) ;
    14111415  ROArrayColumn<Double> dcol( tab, "DIRECTION" ) ;
     1416  // binary search if idx == 0
     1417  if ( idx == 0 ) {
     1418    uInt nrowb = 75000 ;
     1419    if ( nrow > nblock ) {
     1420      uInt nblock = nrow / nrowb + 1 ;
     1421      for ( uInt iblock = 0 ; iblock < nblock ; iblock++ ) {
     1422        uInt high = min( nblock, nrow-iblock*nblock ) ;
     1423
     1424        if ( tcol( high-1 ).get( "s" ).getValue() < t ) {
     1425          idx = iblock * nblock ;
     1426          continue ;
     1427        }
     1428
     1429        Vector<MEpoch> tarr( high ) ;
     1430        for ( uInt irow = 0 ; irow < high ; irow++ ) {
     1431          tarr[irow] = tcol( iblock*nblock+irow ) ;
     1432        }
     1433
     1434        uInt bidx = binarySearch( tarr, t ) ;
     1435
     1436        idx = iblock * nblock + bidx ;
     1437        break ;
     1438      }
     1439    }
     1440    else {
     1441      Vector<MEpoch> tarr( nrow ) ;
     1442      for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
     1443        tarr[irow] = tcol( irow ) ;
     1444      }
     1445      idx = binarySearch( tarr, t ) ;
     1446    }
     1447  }
    14121448  // ensure that tcol(idx) < t
    14131449  //os_ << "tcol(idx) = " << tcol(idx).get("s").getValue() << " t = " << t << " diff = " << tcol(idx).get("s").getValue()-t << endl ;
     
    14861522}
    14871523
     1524uInt MSFiller::binarySearch( Vector<MEpoch> &timeList, Double target )
     1525{
     1526  Int low = 0 ;
     1527  Int high = timeList.nelements() ;
     1528  uInt idx = 0 ;
     1529
     1530  while ( low <= high ) {
     1531    idx = (Int)( 0.5 * ( low + high ) ) ;
     1532    Double t = timeList[idx].get( "s" ).getValue() ;
     1533    if ( t < target )
     1534      low = idx + 1 ;
     1535    else if ( t > target )
     1536      high = idx - 1 ;
     1537    else
     1538      return idx ;
     1539  }
     1540
     1541  idx = max( 0, min( low, high ) ) ;
     1542
     1543  return idx ;
     1544 
     1545}
     1546
    14881547} ;
    14891548
  • trunk/src/MSFiller.h

    r2002 r2003  
    8484  // assume that tab is selected by ANTENNA_ID, FEED_ID, SPECTRAL_WINDOW_ID
    8585  // and sorted by TIME
    86   void getSysCalTime( casa::Block<casa::MEpoch> &scTimeIn, casa::Vector<casa::Double> &scInterval, casa::Block<casa::MEpoch> &tcol, casa::Block<casa::Double> &scTimeOut, casa::Block<casa::Int> &tidx ) ;
     86  void getSysCalTime( casa::Vector<casa::MEpoch> &scTimeIn, casa::Vector<casa::Double> &scInterval, casa::Block<casa::MEpoch> &tcol, casa::Block<casa::Double> &scTimeOut, casa::Block<casa::Int> &tidx ) ;
    8787
    8888  // get tsys by time stamp
     
    9999  // create key for TCAL table
    100100  casa::String keyTcal( casa::Int feedid, casa::Int spwid, casa::String stime ) ;
     101
     102  // binary search
     103  casa::uInt binarySearch( casa::Vector<casa::MEpoch> &timeList, casa::Double target ) ;
    101104 
    102105  casa::CountedPtr<Scantable> table_ ;
Note: See TracChangeset for help on using the changeset viewer.