Changeset 2291 for trunk/src/MSFiller.h


Ignore:
Timestamp:
09/12/11 12:07:41 (13 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: MSFillerUtils and MSWriterUtils added

Test Programs: sd regressions, test_sdsave

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Rewrote MSFiller and MSWriter based on TableTraverse?.
TableTraverse? is changed a bit since it doesn't work on plain table.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/MSFiller.h

    r2289 r2291  
    1616// STL
    1717#include <string>
    18 
    19 // Boost
    20 #include <boost/pool/object_pool.hpp>
    2118
    2219// AIPS++
     
    2724#include <casa/Arrays/Cube.h>
    2825#include <casa/Logging/LogIO.h>
    29 
     26#include <casa/Containers/RecordField.h>
    3027#include <casa/Containers/Record.h>
    3128#include <casa/Containers/Block.h>
     29#include <casa/Quanta/MVTime.h>
    3230
    3331#include <ms/MeasurementSets/MeasurementSet.h>
    3432#include <ms/MeasurementSets/MSPointing.h>
    3533
     34#include <tables/Tables/ScalarColumn.h>
     35#include <tables/Tables/ArrayColumn.h>
     36#include <tables/Tables/TableRow.h>
     37
     38#include <measures/TableMeasures/ScalarMeasColumn.h>
     39#include <measures/TableMeasures/ArrayMeasColumn.h>
     40#include <measures/TableMeasures/ScalarQuantColumn.h>
     41#include <measures/TableMeasures/ArrayQuantColumn.h>
     42
     43#include "TableTraverse.h"
    3644#include "Scantable.h"
     45#include "MathUtils.h"
     46
     47using namespace casa;
    3748
    3849namespace asap
    3950{
     51
     52class MSFillerUtils {
     53protected:
     54  template<class T> void getScalar( const String &name,
     55                                    const uInt &idx,
     56                                    const Table &tab,
     57                                    T &val )
     58  {
     59    ROScalarColumn<T> col( tab, name ) ;
     60    val = col( idx ) ;
     61  }
     62  template<class T> void getArray( const String &name,
     63                                   const uInt &idx,
     64                                   const Table &tab,
     65                                   Array<T> &val )
     66  {
     67    ROArrayColumn<T> col( tab, name ) ;
     68    val = col( idx ) ;
     69  }
     70  template<class T> void getScalarMeas( const String &name,
     71                                        const uInt &idx,
     72                                        const Table &tab,
     73                                        T &val )
     74  {
     75    ROScalarMeasColumn<T> measCol( tab, name ) ;
     76    val = measCol( idx ) ;
     77  }
     78  template<class T> void getArrayMeas( const String &name,
     79                                       const uInt &idx,
     80                                       const Table &tab,
     81                                       Array<T> &val )
     82  {
     83    ROArrayMeasColumn<T> measCol( tab, name ) ;
     84    val = measCol( idx ) ;
     85  }
     86  template<class T> void getScalarQuant( const String &name,
     87                                         const uInt &idx,
     88                                         const Table &tab,
     89                                         Quantum<T> &val )
     90  {
     91    ROScalarQuantColumn<T> quantCol( tab, name ) ;
     92    val = quantCol( idx ) ;
     93  }
     94  template<class T> void getArrayQuant( const String &name,
     95                                        const uInt &idx,
     96                                        const Table &tab,
     97                                        Array< Quantum<T> > &val )
     98  {
     99    ROArrayQuantColumn<T> quantCol( tab, name ) ;
     100    val = quantCol( idx ) ;
     101  }
     102//   template<class T> void putField( const String &name,
     103//                                    TableRecord &rec,
     104//                                    T &val )
     105//   {
     106//     RecordFieldPtr<T> rf( rec, name ) ;
     107//     *rf = val ;
     108//   }
     109//   template<class T> void defineField( const String &name,
     110//                                       TableRecord &rec,
     111//                                       T &val )
     112//   {
     113//     RecordFieldPtr<T> rf( rec, name ) ;
     114//     rf.define( val ) ;
     115//   }
     116  template<class T> T interp( Double x0, Double x1, Double x, T y0, T y1 )
     117  {
     118    Double dx0 = x - x0 ;
     119    Double dx1 = x1 - x ;
     120    return ( y0 * dx1 + y1 * dx0 ) / ( x1 - x0 ) ;
     121  }
     122  String keyTcal( const Int &feedid, const Int &spwid, const Double &time )
     123  {
     124    String stime = MVTime( Quantity(time,Unit("s")) ).string( MVTime::YMD ) ;
     125    String sfeed = "FEED" + String::toString( feedid ) ;
     126    String sspw = "SPW" + String::toString( spwid ) ;
     127    return sfeed+":"+sspw+":"+stime ;
     128  }
     129  String keyTcal( const Int &feedid, const Int &spwid, const String &stime )
     130  {
     131    String sfeed = "FEED" + String::toString( feedid ) ;
     132    String sspw = "SPW" + String::toString( spwid ) ;
     133    return sfeed+":"+sspw+":"+stime ;
     134  }
     135};
    40136
    41137class MSFiller
    42138{
    43139public:
    44   explicit MSFiller(casa::CountedPtr<Scantable> stable) ;
     140  explicit MSFiller(CountedPtr<Scantable> stable) ;
    45141  virtual ~MSFiller() ;
    46142 
    47   virtual bool open(const std::string& filename, const casa::Record& rec) ;
     143  virtual bool open(const std::string& filename, const Record& rec) ;
    48144  virtual void fill() ;
    49145  virtual void close() ;
     
    65161  //void fillHistory() ;
    66162  //void fillFit() ;
    67   void fillTcal( boost::object_pool<casa::ROTableColumn> *poolr ) ;
    68 
    69   // get SRCTYPE from STATE_ID
    70   casa::Int getSrcType( casa::Int stateId, boost::object_pool<casa::ROTableColumn> *pool ) ;
    71 
    72   // get POLNO from CORR_TYPE
    73   casa::Block<casa::uInt> getPolNo( casa::Int corrType ) ;
    74 
    75   // get poltype from CORR_TYPE
    76   casa::String getPolType( casa::Int corrType ) ;
    77 
    78   // get WEATHER_ID
    79   casa::uInt getWeatherId( casa::uInt idx, casa::Double wtime ) ;
    80 
    81   // get time stamp in SYSCAL table
    82   // assume that tab is selected by ANTENNA_ID, FEED_ID, SPECTRAL_WINDOW_ID
    83   // and sorted by TIME
    84   void getSysCalTime( casa::Vector<casa::MEpoch> &scTimeIn, casa::Vector<casa::Double> &scInterval, casa::Block<casa::MEpoch> &tcol, casa::Block<casa::Int> &tidx ) ;
    85 
    86   // get TCAL_ID
    87   casa::Block<casa::uInt> getTcalId( casa::Int feedId, casa::Int spwId, casa::MEpoch &t ) ;
    88 
    89   // get direction for DIRECTION, AZIMUTH, and ELEVATION columns
    90   casa::uInt getDirection( casa::uInt idx,
    91                            casa::Vector<casa::Double> &dir,
    92                            casa::Vector<casa::Double> &srate,
    93                            casa::String &ref,
    94                            casa::Vector<casa::Double> &ptcol,
    95                            casa::ROArrayColumn<casa::Double> &pdcol,
    96                            casa::Double t ) ;
    97   casa::uInt getDirection( casa::uInt idx,
    98                            casa::Vector<casa::Double> &dir,
    99                            casa::Vector<casa::Double> &azel,
    100                            casa::Vector<casa::Double> &srate,
    101                            casa::Vector<casa::Double> &ptcol,
    102                            casa::ROArrayColumn<casa::Double> &pdcol,
    103                            casa::MEpoch &t, casa::MPosition &antpos ) ;
    104   void getSourceDirection( casa::Vector<casa::Double> &dir,
    105                            casa::Vector<casa::Double> &azel,
    106                            casa::Vector<casa::Double> &srate,
    107                            casa::MEpoch &t,
    108                            casa::MPosition &antpos,
    109                            casa::Vector<casa::MDirection> &srcdir ) ;
     163  void fillTcal() ;
    110164
    111165  // create key for TCAL table
    112   casa::String keyTcal( casa::Int feedid, casa::Int spwid, casa::String stime ) ;
    113 
    114   // binary search
    115   casa::uInt binarySearch( casa::Vector<casa::MEpoch> &timeList, casa::Double target ) ;
    116   casa::uInt binarySearch( casa::Vector<casa::Double> &timeList, casa::Double target ) ;
    117 
    118   // tool for HPC
    119 //   double gettimeofday_sec() ;
     166  String keyTcal( Int feedid, Int spwid, String stime ) ;
    120167
    121168  // get frequency frame
    122169  std::string getFrame() ;
    123170
    124   // reshape SPECTRA and FLAGTRA
    125   void reshapeSpectraAndFlagtra( casa::Cube<casa::Float> &sp,
    126                                  casa::Cube<casa::Bool> &fl,
    127                                  casa::Table &tab,
    128                                  casa::Int &npol,
    129                                  casa::Int &nchan,
    130                                  casa::Int &nrow,
    131                                  casa::Vector<casa::Int> &corrtype ) ;
    132 
    133171  // initialize header
    134172  void initHeader( STHeader &header ) ;
    135173
    136   // get value from table column using object pool
    137   casa::String asString( casa::String name,
    138                          casa::uInt idx,
    139                          casa::Table tab,
    140                          boost::object_pool<casa::ROTableColumn> *pool ) ;
    141   casa::Bool asBool( casa::String name,
    142                      casa::uInt idx,
    143                      casa::Table &tab,
    144                      boost::object_pool<casa::ROTableColumn> *pool ) ;
    145   casa::Int asInt( casa::String name,
    146                    casa::uInt idx,
    147                    casa::Table &tab,
    148                    boost::object_pool<casa::ROTableColumn> *pool ) ;
    149   casa::uInt asuInt( casa::String name,
    150                      casa::uInt idx,
    151                      casa::Table &tab,
    152                      boost::object_pool<casa::ROTableColumn> *pool ) ;
    153   casa::Float asFloat( casa::String name,
    154                        casa::uInt idx,
    155                        casa::Table &tab,
    156                        boost::object_pool<casa::ROTableColumn> *pool ) ;
    157   casa::Double asDouble( casa::String name,
    158                          casa::uInt idx,
    159                          casa::Table &tab,
    160                          boost::object_pool<casa::ROTableColumn> *pool ) ;
    161 
    162   void sourceInfo( casa::Int sourceId,
    163                    casa::Int spwId,
    164                    casa::String &name,
    165                    casa::MDirection &direction,
    166                    casa::Vector<casa::Double> &properMotion,
    167                    casa::Vector<casa::Double> &restFreqs,
    168                    casa::Vector<casa::String> &transitions,
    169                    casa::Vector<casa::Double> &sysVels,
    170                    boost::object_pool<casa::ROTableColumn> *pool ) ;
    171 
    172   void spectralSetup( casa::Int spwId,
    173                       casa::MEpoch &me,
    174                       casa::MPosition &mp,
    175                       casa::MDirection &md,
    176                       casa::Double &refpix,
    177                       casa::Double &refval,
    178                       casa::Double &increment,
    179                       casa::Int &nchan,
    180                       casa::String &freqref,
    181                       casa::Double &reffreq,
    182                       casa::Double &bandwidth,
    183                       boost::object_pool<casa::ROTableColumn> *pool ) ;
    184 
    185   casa::CountedPtr<Scantable> table_ ;
    186   casa::MeasurementSet mstable_ ;
    187   casa::String tablename_ ;
    188   casa::Int antenna_ ;
    189   casa::String antennaStr_ ;
    190   casa::Bool getPt_ ;
    191 
    192   casa::Bool isFloatData_ ;
    193   casa::Bool isData_ ;
    194 
    195   casa::Bool isDoppler_ ;
    196   casa::Bool isFlagCmd_ ;
    197   casa::Bool isFreqOffset_ ;
    198   casa::Bool isHistory_ ;
    199   casa::Bool isProcessor_ ;
    200   casa::Bool isSysCal_ ;
    201   casa::Bool isWeather_ ;
    202 
    203   casa::String colTsys_ ;
    204   casa::String colTcal_ ;
    205 
    206   casa::LogIO os_ ;
    207  
    208   casa::Vector<casa::Double> mwTime_ ;
    209   casa::Vector<casa::Double> mwInterval_ ;
    210   casa::Vector<casa::uInt> mwIndex_ ;
     174  CountedPtr<Scantable> table_ ;
     175  MeasurementSet mstable_ ;
     176  String tablename_ ;
     177  Int antenna_ ;
     178  String antennaStr_ ;
     179  Bool getPt_ ;
     180
     181  Bool isFloatData_ ;
     182  Bool isData_ ;
     183
     184  Bool isDoppler_ ;
     185  Bool isFlagCmd_ ;
     186  Bool isFreqOffset_ ;
     187  Bool isHistory_ ;
     188  Bool isProcessor_ ;
     189  Bool isSysCal_ ;
     190  Bool isWeather_ ;
     191
     192  String colTsys_ ;
     193  String colTcal_ ;
     194
     195  LogIO os_ ;
     196 
     197  Vector<Double> mwTime_ ;
     198  Vector<Double> mwInterval_ ;
     199  Vector<uInt> mwIndex_ ;
    211200
    212201  // Record for TCAL_ID
     
    214203  //           "SPW1": Vector<uInt>
    215204  //  ...
    216   casa::Record tcalrec_ ;
    217 
    218   //casa::ROTableColumn *scCol_ ;
     205  Record tcalrec_ ;
     206  //map< String,Vector<uInt> > tcalrec_ ;
    219207};
    220208
Note: See TracChangeset for help on using the changeset viewer.