casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
NewCalTable.h
Go to the documentation of this file.
00001 //# NewCalTable.h: Calibration table access and creation
00002 //# Copyright (C) 2011
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be adressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: NewCalTable.h 23641 2013-04-07 04:18:28Z george.moellenbrock $
00028 
00029 #ifndef CALIBRATION_NEWCALTABLE_H
00030 #define CALIBRATION_NEWCALTABLE_H
00031 
00032 #include <casa/aips.h>
00033 #include <tables/Tables/Table.h>
00034 #include <tables/Tables/ExprNode.h>
00035 #include <casa/Containers/Record.h>
00036 #include <casa/OS/Path.h>
00037 #include <casa/Utilities/Sort.h>
00038 #include <ms/MeasurementSets/MSObservation.h>
00039 #include <ms/MeasurementSets/MSAntenna.h>
00040 #include <ms/MeasurementSets/MSField.h>
00041 #include <ms/MeasurementSets/MSSpectralWindow.h>
00042 #include <ms/MeasurementSets/MSHistory.h>
00043 #include <ms/MeasurementSets/MSObsColumns.h>
00044 #include <ms/MeasurementSets/MSAntennaColumns.h>
00045 #include <ms/MeasurementSets/MSFieldColumns.h>
00046 #include <ms/MeasurementSets/MSSpWindowColumns.h>
00047 #include <ms/MeasurementSets/MSHistoryColumns.h>
00048 #include <synthesis/CalTables/CTDesc.h>
00049 #include <synthesis/CalTables/CTMainRecord.h>
00050 #include <synthesis/CalTables/CTMainColumns.h>
00051 #include <synthesis/CalTables/VisCalEnum.h>
00052 
00053 namespace casa { //# NAMESPACE CASA - BEGIN
00054 
00055 // <summary> 
00056 // NewCalTable: New Calibration table access and creation
00057 // </summary>
00058 
00059 // <use visibility=export>
00060 
00061 // <reviewed reviewer="" date="" tests="" demos="">
00062 
00063 // <prerequisite>
00064 //   <li> <linkto class="CalTableDesc">CalTableDesc</linkto> module
00065 // </prerequisite>
00066 //
00067 // <etymology>
00068 // From "calibration" and "table".
00069 // </etymology>
00070 //
00071 // <synopsis>
00072 // The NewCalTable classes provide basic access to calibration tables. This 
00073 // includes the creation of calibration tables, sorting and selection
00074 // capabilities, and basic data access. Specializations for baseline-based,
00075 // time-variable and solvable VisJones types, and sub-types, are provided 
00076 // through inheritance.
00077 // </etymology>
00078 //
00079 // <example>
00080 // <srcblock>
00081 // </srcblock>
00082 // </example>
00083 //
00084 // <motivation>
00085 // This class is used by other calibration table accessors and iterators.
00086 // </motivation>
00087 //
00088 // <todo asof="11/06/10">
00089 // </todo>
00090 
00091 
00092 // Typedefs for subtable objects
00093 typedef MSField CTField;
00094 typedef MSObservation CTObservation;
00095 typedef MSAntenna CTAntenna;
00096 typedef MSSpectralWindow CTSpectralWindow;
00097 typedef MSHistory CTHistory;
00098 typedef MSFieldColumns CTFieldColumns;
00099 typedef MSObservationColumns CTObservationColumns;
00100 typedef MSAntennaColumns CTAntennaColumns;
00101 typedef MSSpWindowColumns CTSpWindowColumns;
00102 typedef MSHistoryColumns CTHistoryColumns;
00103 typedef ROMSFieldColumns ROCTFieldColumns;
00104 typedef ROMSObservationColumns ROCTObservationColumns;
00105 typedef ROMSAntennaColumns ROCTAntennaColumns;
00106 typedef ROMSSpWindowColumns ROCTSpWindowColumns;
00107 typedef ROMSHistoryColumns ROCTHistoryColumns;
00108 
00109 class NewCalTable : public Table
00110 {
00111  public:
00112    // Default null constructor, and destructor
00113    NewCalTable();
00114    virtual ~NewCalTable();
00115 
00116    // Construct from a specified table name, calibration table descriptor 
00117    // and table access option. Used for creating new tables.
00118    NewCalTable (const String& tableName, CTDesc& ctableDesc,
00119                 Table::TableOption access = Table::New, 
00120                 Table::TableType ttype = Table::Plain);
00121 
00122    // Construct from setupNewTable 
00123    NewCalTable (SetupNewTable& newTab, uInt nrow = 0, Bool initialize = False);
00124    
00125    // Create an empty NewCalTable conveniently
00126    NewCalTable(String tableName,VisCalEnum::VCParType parType,
00127                String typeName,String msName,Bool doSingleChan);
00128 
00129    // Construct from a specified table name, and access option. Used
00130    // for accessing existing tables.
00131    NewCalTable (const String& tableName, 
00132                 Table::TableOption access = Table::Old, 
00133                 Table::TableType ttype = Table::Memory);
00134 
00135    static NewCalTable createCT(const String& tableName, 
00136                                Table::TableOption access, 
00137                                Table::TableType ttype, 
00138                                Bool doBackCompat=True);
00139 
00140    static NewCalTable* createCTptr(const String& tableName, 
00141                                    Table::TableOption access, 
00142                                    Table::TableType ttype, 
00143                                    Bool doBackCompat=True);
00144 
00145 
00146 
00147    // Construct from an existing table object
00148    NewCalTable (const Table& table);
00149 
00150    // Copy constructor
00151    NewCalTable (const NewCalTable& other);
00152 
00153    // Create a vanilla NewCalTable from shapes (for testing purposes)
00154    //  Default rTime is 2012/01/06/12:00:00
00155    NewCalTable(String tableName,String CorF,
00156                Int nObs=1, Int nScanPerObs=1,Int nTimePerScan=1,
00157                Int nAnt=1, Int nSpw=1, Vector<Int> nChan=Vector<Int>(1,1), 
00158                Int nFld=1, 
00159                Double rTime=0.0, Double tint=0.0,
00160                Bool disk=False, Bool verbose=False);
00161 
00162    // Assignment operator
00163    NewCalTable& operator= (const NewCalTable& other);
00164 
00165    // Handle backward compatibility
00166    static Bool CTBackCompat(const String& caltable);
00167 
00168    // Set the TableInfo record
00169    void setTableInfo();
00170 
00171    // initialize reference to subtables
00172    void createSubTables();
00173    void attachSubTables();
00174    void clearSubtables();
00175 
00176    void copyMemCalSubtables(const NewCalTable& other);
00177    void copyMemCalSubtable(const Table& otherSubtable, Table& subTable);
00178 
00179    // Complex parameters?  (else Float)
00180    Bool isComplex();
00181 
00182    // Report the polarization basis (from header record)
00183    String polBasis();
00184 
00185    // Get a row from cal_main
00186    Record getRowMain (const Int& jrow);
00187     
00188    // Put a row to cal_main
00189    void putRowMain (const Int& jrow, CTMainRecord& tableRec);
00190 
00191    // Get rows of the data from the main table
00192    //   void fillRowsMain ();
00193 
00194    // Set Meta data info from a parent MS 
00195    void setMetaInfo (const String& msName);
00196 
00197    //validate input table desc. over required caltable desc
00198    static Bool conformant(const TableDesc& tabDesc);
00199 
00200    // save to disk
00201    void writeToDisk(const String& tableName); 
00202 
00203    CTObservation& observation() {return observation_p;}
00204    CTAntenna& antenna() {return antenna_p;}
00205    CTField& field() {return field_p;}
00206    CTSpectralWindow& spectralWindow() {return spectralWindow_p;}
00207    CTHistory& history() {return history_p;}
00208    const CTObservation& observation() const {return observation_p;}
00209    const CTAntenna& antenna() const {return antenna_p;}
00210    const CTField& field() const {return field_p;}
00211    const CTSpectralWindow& spectralWindow() const {return spectralWindow_p;}
00212    const CTHistory& history() const {return history_p;}
00213 
00214    // Provide RO access to 
00215    //   inline ROCTMainColumns mcols() const {return ROCTMainColumns(*this);};
00216 
00217    static Complex NCTtestvalueC(Int iant,Int ispw,Int ich,Double time,Double refTime,Double tint);
00218    static Float NCTtestvalueF(Int iant,Int ispw,Int ich,Double time,Double refTime,Double tint);
00219 
00220    // Fill in antenna-based solutions
00221    //  (obsId-less version calls obsId-capable version w/ obsId=0)
00222    void fillAntBasedMainRows(uInt nrows, 
00223                              Double time,Double interval,
00224                              Int fieldId,uInt spwId,Int scanNo,
00225                              const Vector<Int>& ant1list, Int refant,
00226                              const Cube<Complex>& cparam,
00227                              const Cube<Bool>& flag,
00228                              const Cube<Float>& paramErr,
00229                              const Cube<Float>& snr);
00230    void fillAntBasedMainRows(uInt nrows, 
00231                              Double time,Double interval,
00232                              Int fieldId,uInt spwId,Int obsId,Int scanNo,
00233                              const Vector<Int>& ant1list, Int refant,
00234                              const Cube<Complex>& cparam,
00235                              const Cube<Bool>& flag,
00236                              const Cube<Float>& paramErr,
00237                              const Cube<Float>& snr);
00238 
00239    // Reset spw freq info
00240    void setSpwFreqs(Int spw, const Vector<Double>& freq, 
00241                     const Vector<Double>& chanwidth=Vector<Double>());
00242 
00243    // Add a line to the HISTORY table
00244    void addHistoryMessage(String app="",String message="none");
00245 
00246  private:
00247 
00248    // Services for generic test table ctor
00249    //  Default rTime is 2012/01/06/12:00:00
00250    void fillGenericContents(Int nObs=1, Int nScanPerObs=1, Int nTimePerScan=1,
00251                             Int nAnt=1, Int nSpw=1, Vector<Int> nChan=Vector<Int>(1,1), 
00252                             Int nFld=1, 
00253                             Double rTime=0.0, Double tint=0.0,
00254                             Bool verbose=False);
00255    void fillGenericObs(Int nObs);
00256    void fillGenericField(Int nFld);
00257    void fillGenericAntenna(Int nAnt);
00258    void fillGenericSpw(Int nSpw,Vector<Int>& nChan);
00259      
00260    // Force Spw subtable to be all nchan=1
00261    //  (very basic; uses chan n/2 freq)
00262    void makeSpwSingleChan();
00263 
00264    // Handle pre-4.1 caltables that don't have OBS_ID
00265    //  (by adding a phoney one with a single OBS_ID
00266    void addPhoneyObs();
00267 
00268    // The subtables
00269    CTObservation observation_p;
00270    CTAntenna antenna_p;
00271    CTField field_p;
00272    CTSpectralWindow spectralWindow_p;
00273    CTHistory history_p;
00274 
00275  };
00276 
00277 } //# NAMESPACE CASA - END
00278 
00279 #endif