casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ASDM2MSFiller.h
Go to the documentation of this file.
00001 // ASDM2MSFiller.h: implementation of a MeasurementSet's filler
00002 // for Francois Viallefond & Frederic Badia ALMA Simulator
00003 //
00004 //  Copyright (C) 2001
00005 //  OBSERVATOIRE DE PARIS - DEMIRM
00006 //  Avenue Denfert Rochereau - 75014 - PARIS
00007 //
00008 //  This program is free software; you can redistribute it and/or modify
00009 //  it under the terms of the GNU General Public License as published by
00010 //  the Free Software Foundation; either version 2 of the License, or
00011 //  (at your option) any later version.
00012 //
00013 //  This program is distributed in the hope that it will be useful,
00014 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //  GNU General Public License for more details.
00017 //
00018 //  You should have received a copy of the GNU General Public License
00019 //  along with this program; if not, write to the Free Software
00020 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 //
00022 //
00023 //
00025 #if !defined(ALMA_ASDM2MSFILLER_H)
00026 #define ALMA_ASDM2MSFILLER_H
00027 //# Includes
00028 
00029 #include <casa/aips.h>
00030 #include <casa/Utilities/Assert.h>
00031 #include <tables/Tables.h>
00032 #include <ms/MeasurementSets/MeasurementSet.h>
00033 #include <ms/MeasurementSets/MSAntennaColumns.h>
00034 #include <ms/MeasurementSets/MSDataDescColumns.h>
00035 #include <ms/MeasurementSets/MSFeedColumns.h>
00036 #include <ms/MeasurementSets/MSFieldColumns.h>
00037 #include <ms/MeasurementSets/MSFlagCmdColumns.h>
00038 #include <ms/MeasurementSets/MSHistoryColumns.h>
00039 #include <ms/MeasurementSets/MSMainColumns.h>
00040 
00041 #include <ms/MeasurementSets/MSObsColumns.h>
00042 #include <ms/MeasurementSets/MSPointingColumns.h>
00043 #include <ms/MeasurementSets/MSPolColumns.h>
00044 #include <ms/MeasurementSets/MSProcessorColumns.h>
00045 #include <ms/MeasurementSets/MSSourceColumns.h>
00046 #include <ms/MeasurementSets/MSStateColumns.h>
00047 #include <ms/MeasurementSets/MSSpWindowColumns.h>
00048 #include <ms/MeasurementSets/MSSysCalColumns.h>
00049 #include <ms/MeasurementSets/MSWeatherColumns.h>
00050 
00051 #include <tables/Tables/StandardStMan.h>
00052 #include <tables/Tables/TiledShapeStMan.h>
00053 #include <tables/Tables/SetupNewTab.h>
00054 #include <tables/Tables/TableDesc.h>
00055 #include <tables/Tables/TableRecord.h>
00056 #include <casa/Arrays/Vector.h>
00057 #include <casa/Arrays/Cube.h>
00058 #include <casa/Arrays/Matrix.h>
00059 #include <casa/Arrays/ArrayMath.h>
00060 #include <casa/Arrays/ArrayUtil.h>
00061 #include <casa/Arrays/ArrayLogical.h>
00062 #include <casa/Containers/Block.h>
00063 #include <casa/Containers/OrderedMap.h>
00064 #include <measures/Measures/MPosition.h>
00065 #include <measures/Measures/MBaseline.h>
00066 #include <measures/Measures/Muvw.h>
00067 #include <measures/Measures/MeasTable.h>
00068 #include <measures/Measures/Stokes.h>
00069 #include <measures/Measures/MeasConvert.h>
00070 #include <measures/TableMeasures/TableMeasValueDesc.h>
00071 #include <measures/TableMeasures/TableMeasOffsetDesc.h>
00072 #include <measures/TableMeasures/TableMeasRefDesc.h>
00073 #include <measures/TableMeasures/TableMeasDesc.h>
00074 #include <measures/Measures/MeasConvert.h>
00075 #include "measures/Measures/Stokes.h"
00076 #include <casa/BasicSL/Constants.h>
00077 #include <casa/OS/File.h>
00078 #include <casa/OS/Path.h>
00079 #include <complex>
00080 
00081 #include <vector>
00082 
00083 
00084 using namespace casa;
00085 using namespace std;
00086 
00087 //# Forward Declarations
00088 
00089 class TimeRange;
00090 class MPosition;
00091 class MeasFrame;
00092 class MeasurementSet;
00093 class MSMainColumns;
00094 
00095 //
00096 // A structure to define a range of rows in the Pointing table where the attribute overTheTop is defined and with which value.
00097 //
00098 struct s_overTheTop {
00099   unsigned int  start;   // The index of the first row of the range. 
00100   unsigned int  len;     // The number of consecutive rows in the range.
00101   bool value;   // The value of overTheTop in that range.
00102 };
00103 
00104 //
00105 // Class timeMgr is a utility to help for the management
00106 // of time in tables with TIME and INTERVAL columns
00107 class timeMgr {
00108  private:
00109   int index;
00110   double startTime;
00111 
00112  public:
00113   timeMgr();
00114   timeMgr(int i, double t);
00115   void   setIndex(int i);
00116   void   setStartTime(double t);
00117   int    getIndex();
00118   double getStartTime();
00119 };
00120 
00121 
00122 // Class ddMgr is a utility to help for the management
00123 // of DataDescription, SpectralWindow and Polarization ids.
00124 // Here we provide enough space to store 100 values for 
00125 // each quantity; this is very likeky far beyond the actual
00126 // needs.
00127 class ddMgr {
00128  private:
00129   int     numCorr[100];
00130   int     numChan[100];
00131   struct  {
00132     int polId;
00133     int swId;
00134   } dd[100];
00135   
00136  public:
00137 
00138   ddMgr();
00139 
00140   int setNumCorr(int i, int numChan);
00141   int setNumChan(int i, int numCorr);
00142 
00143   int getNumCorr(int i);
00144   int getNumChan(int i);
00145 
00146   int setDD(int i, int polId, int swId); 
00147 
00148   int getPolId(int i);
00149   int getSwId(int i);
00150 };
00151 
00152 
00153  
00154 // Class ASDM2MSFiller
00155 class ASDM2MSFiller
00156 {
00157  private:
00158   double         itsCreationTime;
00159   const string   itsName;
00160   int            itsNumAntenna;
00161   int            itsNumChan;
00162   int            itsNumCorr;
00163   casa::MeasurementSet *itsMS;
00164   casa::MSMainColumns  *itsMSCol;
00165   /*
00166     Block<timeMgr> itsFeedTimeMgr;
00167     Block<timeMgr> itsPointingTimeMgr;
00168     Block<timeMgr> itsSyscalTimeMgr;
00169     Block<timeMgr> itsWeatherTimeMgr;
00170     Block<timeMgr> itsObservationTimeMgr;
00171   */
00172     
00173   String     itsMSPath;
00174   timeMgr* itsFeedTimeMgr;
00175   timeMgr* itsFieldTimeMgr;
00176   timeMgr* itsObservationTimeMgr;
00177   timeMgr* itsPointingTimeMgr;
00178   //OrderedMap<int, timeMgr> itsSourceTimeMgr;
00179   timeMgr* itsSourceTimeMgr;
00180   timeMgr* itsSyscalTimeMgr;
00181   timeMgr* itsWeatherTimeMgr;
00182     
00183   Bool     itsWithRadioMeters;     /* Are we building an ALMA MS ?*/
00184   Bool     itsFirstScan;
00185   uInt     itsMSMainRow;
00186   /*TiledDataStManAccessor itsImWgtAcc;*/
00187   Block<IPosition> itsDataShapes;
00188 
00189   int itsScanNumber;
00190   int itsNCat;
00191     
00192   ddMgr    itsDDMgr;
00193 
00194          
00195   int createMS(const string& msName, 
00196                bool complexData, 
00197                bool withCompression, 
00198                const string& telName, 
00199                int maxNumCorr,
00200                int maxNumChan,
00201                bool withCorrectedData=false,
00202                bool useAsdmStMan4DATA=false);
00203 
00204   const char** getPolCombinations(int numCorr);
00205     
00206   static map<string, MDirection::Types> string2MDirection;
00207   static map<string, MDirection::Types> string2MDirectionInit();
00208    
00209  public:  
00210   ASDM2MSFiller (const string&  name_,
00211                  double         creation_time_,
00212                  bool           withRadioMeters,
00213                  bool           complexData,
00214                  bool           withCompression,
00215                  const string&  telName, 
00216                  int            intintmaxNumCorr,
00217                  int            maxNumChan,
00218                  bool           withCorrectedData=false,
00219                  bool           useAsdmStMan4DATA=false);
00220   
00221   // Destructor
00222   ~ASDM2MSFiller();
00223 
00224   const casa::MeasurementSet* ms();
00225 
00226   int addAntenna(const string&   name_,
00227                  const string&   station_,
00228                  double          lx_,
00229                  double          ly_,
00230                  double          lz_,
00231                  double          offset_x_,
00232                  double          offset_y_,
00233                  double          offset_z_,
00234                  float           dish_diam_);
00235 
00236 
00237   void addData (bool                      complexData,
00238                 vector<double>            &time_,
00239                 vector<int>               &antennaId1_,
00240                 vector<int>               &antennaId2_,
00241                 vector<int>               &feedId1_,
00242                 vector<int>               &feedId2_,
00243                 vector<int>               &dataDescId_,
00244                 int                       processorId_,
00245                 int                       fieldId_,
00246                 vector<double>            &interval_,
00247                 vector<double>            &exposure_,
00248                 vector<double>            &timeCentroid_,
00249                 int                       scanNumber_,
00250                 int                       arrayId_,
00251                 int                       observationId_,
00252                 vector<int>               &stateId_,
00253                 vector<pair<int, int> >   &nChanNPol_,
00254                 vector<double>            &uvw_);
00255 
00256   void addData (bool                      complexData,
00257                 vector<double>            &time_,
00258                 vector<int>               &antennaId1_,
00259                 vector<int>               &antennaId2_,
00260                 vector<int>               &feedId1_,
00261                 vector<int>               &feedId2_,
00262                 vector<int>               &dataDescId_,
00263                 int                       processorId_,
00264                 vector<int>               &fieldId_,
00265                 vector<double>            &interval_,
00266                 vector<double>            &exposure_,
00267                 vector<double>            &timeCentroid_,
00268                 int                       scanNumber_,
00269                 int                       arrayId_,
00270                 int                       observationId_,
00271                 vector<int>               &stateId_,
00272                 vector<double>            &uvw_,
00273                 vector<vector<unsigned int> >      &dataShape_,
00274                 vector<float *>           &uncorrectedData_,
00275                 vector<float *>           &correctedData_,
00276                 vector<unsigned int>      &flag_);
00277 
00278   void addData (bool                      complexData,
00279                 vector<double>            &time_,
00280                 vector<int>               &antennaId1_,
00281                 vector<int>               &antennaId2_,
00282                 vector<int>               &feedId1_,
00283                 vector<int>               &feedId2_,
00284                 vector<int>               &dataDescId_,
00285                 int                       processorId_,
00286                 vector<int>               &fieldId_,
00287                 vector<double>            &interval_,
00288                 vector<double>            &exposure_,
00289                 vector<double>            &timeCentroid_,
00290                 int                       scanNumber_,
00291                 int                       arrayId_,
00292                 int                       observationId_,
00293                 vector<int>               &stateId_,
00294                 vector<double>            &uvw_,
00295                 vector<vector<unsigned int> >      &dataShape_,
00296                 vector<float *>           &data_,
00297                 vector<unsigned int>      &flag_);
00298   
00299 
00300                
00301   int  addDataDescription(int spectral_window_id_,
00302                           int polarizarion_id_);
00303 
00304   int  addUniqueDataDescription(int spectral_window_id_,
00305                                 int polarizarion_id_);
00306 
00307   int  exists(char *path);
00308   String msPath();
00309 
00310 
00311   void addFeed(int      antenna_id_,
00312                int      feed_id_,
00313                int      spectral_window_id_,
00314                double   time_,
00315                double   interval_,
00316                int      num_receptors_,
00317                int      beam_id_,
00318                vector<double> &   beam_offset_,
00319                vector<std::string> & pol_type_,
00320                vector<std::complex<float> > & polarization_response_,
00321                vector<double>&   position_,  // Must be a 3 elements vector !!!
00322                vector<double>&   receptor_angle_);
00323   
00324   void addField( const string&                  name_,
00325                  const string&                  code_,
00326                  double                         time_,
00327                  int                            num_poly_,
00328                  vector<vector<double> >&       delay_dir_,
00329                  vector<vector<double> >&       phase_dir_,
00330                  vector<vector<double> >&       reference_dir_,
00331                  const string&                  direction_code_,
00332                  int                            source_id_);
00333 
00334   void addFlagCmd(double        time_,
00335                   double        interval_,
00336                   const string& type_,
00337                   const string& reason_,
00338                   int           level_,
00339                   int           severity_,
00340                   int           applied_,
00341                   string&       command_);
00342 
00343   void addHistory( double               time_,
00344                    int                  observation_id_,
00345                    const string&        message_,
00346                    const string&        priority_,
00347                    const string&        origin_,
00348                    int                  object_id_,
00349                    const string&        application_,
00350                    const string&        cli_command_,
00351                    const string&        app_parms_ );
00352 
00353   void addObservation(const string&             telescopeName_,
00354                       double                    startTime_,
00355                       double                    endTime_,
00356                       const string&             observer_,
00357                       const vector<string>&     log_,
00358                       const string&             schedule_type_,
00359                       const vector<string>&     schedule_,
00360                       const string&             project_,
00361                       double                    release_date_);
00362 
00363   void addPointingSlice(unsigned int                  n_row_,
00364                         vector<int>&                  antenna_id_,
00365                         vector<double>&               time_,
00366                         vector<double>&               interval_,
00367                         vector<double>&               direction_,
00368                         vector<double>&               target_,
00369                         vector<double>&               pointing_offset_,
00370                         vector<double>&               encoder_,
00371                         vector<bool>&                 tracking_,
00372                         bool                          overTheTopExists4All_,
00373                         vector<bool>&                 v_overTheTop_,
00374                         vector<s_overTheTop>&         v_s_overTheTop_);
00375 
00376   int  addPolarization(int num_corr_,
00377                        vector<int>& corr_type_,
00378                        vector<int>& corr_product_);
00379 
00380   int addUniquePolarization(int num_corr_,
00381                             //                      const vector<Stokes::StokesTypes>& corr_type_,
00382                             const vector<int>& corr_type_,
00383                             const vector<int>& corr_product_);
00384 
00385   void addProcessor(string& type_,
00386                     string& sub_type_,
00387                     int  type_id_,
00388                     int  mode_id_);
00389 
00390   void addSource(int             source_id_,
00391                  double          time_,
00392                  double          interval_,
00393                  int             spectral_window_id_,
00394                  int             num_lines_,
00395                  string&         name_,
00396                  int             calibration_group_,
00397                  string&         code_,
00398                  vector<double>& direction_,
00399                  string&         direction_code_,
00400                  vector<double>& position_,
00401                  vector<double>& proper_motion_,
00402                  vector<string>& transition_,
00403                  vector<double>& rest_frequency_,
00404                  vector<double>& sysvel_);
00405                  
00406   int  addSpectralWindow(int                    num_chan_,
00407                          const string&          name_,
00408                          double                 ref_frequency_,
00409                          const vector<double>&  chan_freq_,
00410                          const vector<double>&  chan_width_,
00411                          int                    meas_freq_ref_,
00412                          const vector<double>&  effective_bw_,
00413                          const vector<double>&  resolution_,
00414                          double                 total_bandwidth_,
00415                          int                    net_sideband_,
00416                          int                    bbc_no_,
00417                          int                    if_conv_chain_,
00418                          int                    freq_group_,
00419                          const string&          freq_group_name_,
00420                          int                    num_assoc_,
00421                          const vector<int>&     assoc_sp_id_,
00422                          const vector<string>&  assoc_nature_);
00423 
00424   int  addUniqueState(bool sig_,
00425                       bool ref_,
00426                       double cal_,
00427                       double load_,
00428                       unsigned int sub_scan_,
00429                       string& obs_mode_,
00430                       bool flag_row_);
00431   
00432   
00433   void addState(bool    sig_,
00434                 bool    ref_,
00435                 double  cal_,
00436                 double  load_,
00437                 int     sub_scan_,
00438                 string& obs_mode_);
00439   
00440   void addSysCal(int    antenna_id,
00441                  int    feed_id,
00442                  int    spectral_window_id,
00443                  double time_,
00444                  double interval_,
00445                  int    numReceptor_,
00446                  int    numChan_,
00447                  pair<bool, vector<float> >& tcal_spectrum_pair,
00448                  pair<bool, bool>&           tcal_flag_pair,
00449                  pair<bool, vector<float> >& trx_spectrum_pair,
00450                  pair<bool, bool>&           trx_flag_pair,
00451                  pair<bool, vector<float> >& tsky_spectrum_pair,
00452                  pair<bool, bool>&           tsky_flag_pair,
00453                  pair<bool, vector<float> >& tsys_spectrum_pair,
00454                  pair<bool, bool>&           tsys_flag_pair,
00455                  pair<bool, vector<float> >& tant_spectrum_pair,
00456                  pair<bool, bool>&           tant_flag_pair,
00457                  pair<bool, vector<float> >& tant_tsys_spectrum_pair,
00458                  pair<bool, bool>&           tant_tsys_flag_pair);
00459 
00460  void addWeather(int                            antenna_id_,
00461                   double                        time_,
00462                   double                        interval_,
00463                   const pair<bool, float>&      pressure_opt_,
00464                   const pair<bool, float>&      relHumidity_opt_,
00465                   const pair<bool, float>&      temperature_opt_,
00466                   const pair<bool, float>&      windDirection_opt_,
00467                   const pair<bool, float>&      windSpeed_opt_,
00468                   const pair<bool, float>&      dewPoint_opt_,
00469                   int                           wx_station_id_,
00470                   vector<double>&               wx_station_position_);
00471 
00483   void addCalDevice(int                         antennaId,
00484                     int                         feedId,
00485                     int                         spectralWindowId,
00486                     double                      time,
00487                     double                      interval,
00488                     unsigned int                numCalLoad,
00489                     vector<string>              calloadNames,
00490                     unsigned int                numReceptor,
00491                     vector<vector<float> >&     calEff,
00492                     vector<vector<float> >&     noiseCal,
00493                     vector<double >&            temperatureLoad);
00494 
00517   void addSysPower(int                  antennaId,
00518                    int                  feedId,
00519                    int                  spectralWindowId,
00520                    double               time,
00521                    double               interval,
00522                    unsigned int         numReceptor,
00523                    vector<float>&       switchedPowerDifference,
00524                    vector<float>&       switchedPowerSum,
00525                    vector<float>&       requantizerGain); 
00526 
00527   void addSysPowerSlice(unsigned int    nRow,
00528                         vector<int>&    antennaId,
00529                         vector<int>&    spectralWindowId,
00530                         vector<int>&    feedId,
00531                         vector<double>& time,
00532                         vector<double>& interval,
00533                         unsigned int    numReceptor,
00534                         vector<float>&  switchedPowerDifference,
00535                         vector<float>&  switchedPowerSum,
00536                         vector<float>&  requantizerGain);
00537 
00538   void end(double time_);
00539 };
00540 #endif
00541