casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MSFieldColumns.h
Go to the documentation of this file.
00001 //# MSFieldColumns.h: provides easy access to MSField columns
00002 //# Copyright (C) 1996,1999,2000
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 addressed 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 //# $Id: MSFieldColumns.h 19944 2007-02-27 11:14:34Z Malte.Marquarding $
00027 
00028 #ifndef MS_MSFIELDCOLUMNS_H
00029 #define MS_MSFIELDCOLUMNS_H
00030 
00031 #include <casa/aips.h>
00032 #include <measures/Measures/MDirection.h>
00033 #include <measures/Measures/MEpoch.h>
00034 #include <measures/Measures/MCDirection.h>
00035 #include <measures/Measures/MCEpoch.h>
00036 #include <measures/Measures/MRadialVelocity.h>
00037 #include <measures/Measures/MeasComet.h>
00038 #include <measures/TableMeasures/ArrayMeasColumn.h>
00039 #include <measures/TableMeasures/ScalarMeasColumn.h>
00040 #include <measures/TableMeasures/ScalarQuantColumn.h>
00041 #include <tables/Tables/ArrayColumn.h>
00042 #include <tables/Tables/ScalarColumn.h>
00043 #include <casa/BasicSL/String.h>
00044 #include <casa/Containers/SimOrdMap.h>
00045 
00046 namespace casa { //# NAMESPACE CASA - BEGIN
00047 
00048 class MVDirection;
00049 class MSField;
00050 template <class Qtype> class Quantum;
00051 template <class T> class Matrix;
00052 
00053 // <summary>
00054 // A class to provide easy access to MSField columns
00055 // </summary>
00056 
00057 // <use visibility=export>
00058 
00059 // <reviewed reviewer="Bob Garwood" date="1997/02/01" tests="" demos="">
00060 // </reviewed>
00061 
00062 // <prerequisite>
00063 //   <li> MSField
00064 //   <li> ArrayColumn
00065 //   <li> ScalarColumn
00066 // </prerequisite>
00067 //
00068 // <etymology>
00069 // ROMSFieldColumns stands for Read-Only MeasurementSet Field Table columns.
00070 // </etymology>
00071 //
00072 // <synopsis>
00073 // This class provides read-only access to the columns in the MSField Table.
00074 // It does the declaration of all the Scalar and ArrayColumns with the
00075 // correct types, so the application programmer doesn't have to
00076 // worry about getting those right. There is an access function
00077 // for every predefined column. Access to non-predefined columns will still
00078 // have to be done with explicit declarations.
00079 // See <linkto class=ROMSColumns> ROMSColumns</linkto> for an example.
00080 // </synopsis>
00081 //
00082 // <motivation>
00083 // See <linkto class=MSColumns> MSColumns</linkto> for the motivation.
00084 // </motivation>
00085 
00086 class ROMSFieldColumns
00087 {
00088 public:
00089   // Construct from the supplied Table
00090   ROMSFieldColumns(const MSField& msField);
00091 
00092   // The desctructor does nothing special
00093   ~ROMSFieldColumns();
00094 
00095   // Read-only access to required columns
00096   // <group>
00097   const ROScalarColumn<String>& code() const {return code_p;}
00098   const ROArrayColumn<Double>& delayDir() const {return delayDir_p;}
00099   const ROArrayMeasColumn<MDirection>& delayDirMeasCol() const 
00100     {return delayDirMeas_p;}
00101   const ROScalarColumn<Bool>& flagRow() const {return flagRow_p;}
00102   const ROScalarColumn<String>& name() const {return name_p;}
00103   const ROScalarColumn<Int>& numPoly() const {return numPoly_p;}
00104   const ROArrayColumn<Double>& phaseDir() const {return phaseDir_p;}
00105   const ROArrayMeasColumn<MDirection>& phaseDirMeasCol() const 
00106     {return phaseDirMeas_p;}
00107   const ROArrayColumn<Double>& referenceDir() const {return referenceDir_p;}
00108   const ROArrayMeasColumn<MDirection>& referenceDirMeasCol() const 
00109     {return referenceDirMeas_p;}
00110   const ROScalarColumn<Int>& sourceId() const {return sourceId_p;}
00111   const ROScalarColumn<Double>& time() const {return time_p;}
00112   const ROScalarQuantColumn<Double>& timeQuant() const { return timeQuant_p;}
00113   const ROScalarMeasColumn<MEpoch>& timeMeas() const { return timeMeas_p;}
00114   // </group>
00115 
00116   // Read-only access to optional columns
00117   // <group>
00118   const ROScalarColumn<Int>& ephemerisId() const {return ephemerisId_p;}
00119   // </group>
00120 
00121   // Access to interpolated directions from polynomials or ephemerides, 
00122   // the default time of zero will return the 0th order element of the polynomial.
00123   // or, if there is an ephemeris, the position at the time origin of the ephemeris.
00124   // 
00125   // In addtion to the directions, if there is an ephemeris available,
00126   // also the radial velocity and the distance rho can be accessed.
00127   //
00128   // The method needInterTime returns True if there is a polynomial or ephemeris
00129   // connected to this field table row, and an interpolation time value should
00130   // be provided.
00131   // The method ephemPath returns the absolute path to the ephemeris table connected to 
00132   // the field table row, an empty string if there is none.  
00133   // <group>
00134   MDirection delayDirMeas(Int row, Double time = 0) const;
00135   MDirection phaseDirMeas(Int row, Double time = 0) const;
00136   MDirection referenceDirMeas(Int row, Double time = 0) const;
00137   MRadialVelocity radVelMeas(Int row, Double time = 0) const;
00138   Quantity rho(Int row, Double time = 0) const;
00139   Bool needInterTime(Int row) const;
00140   String ephemPath(Int row) const;
00141 
00142   // </group>
00143 
00144   // Convenience function that returns the number of rows in any of the columns
00145   uInt nrow() const {return name_p.nrow();}
00146 
00147   // returns the last row that has a reference direction, phase direction and
00148   // delay direction that match, to within the specified angular separation,
00149   // the supplied values. Only matches on rows where the direction is constant
00150   // ie., NUM_POLY is 0 and where FLAG_ROW is False. Throws an exception
00151   // (AipsError) if the reference frames do not match or if the separation does
00152   // not have angular units (when compiled in debug mode). Returns -1 if no
00153   // match could be found. If tryRow is positive, then that row is tested to
00154   // see if it matches before any others are tested. Setting tryRow to a
00155   // positive value greater than the table length will throw an exception
00156   // (AipsError), when compiled in debug mode.
00157   Int matchDirection(const MDirection& referenceDirection, 
00158                      const MDirection& delayDirection,
00159                      const MDirection& phaseDirection,
00160                      const Quantum<Double>& maxSeparation, 
00161                      Int tryRow=-1,
00162                      Double time=0);
00163 
00164   // Update the MeasComets objects belonging to this FIELD table.
00165   // Needed when the entries in the EPHEMERIS_ID column have changed.
00166   void updateMeasComets();
00167 
00168 
00169 protected:
00170   //# default constructor creates a object that is not usable. Use the attach
00171   //# function correct this.
00172   ROMSFieldColumns();
00173 
00174   //# attach this object to the supplied table.
00175   void attach(const MSField& msField);
00176 
00177   Int measCometIndex(int row) const;
00178   String measCometsPath_p;
00179   Vector<MeasComet*> measCometsV_p;
00180   SimpleOrderedMap <Int, Int> ephIdToMeasComet_p;
00181 
00182   // Extract the direction Measure from the corresponding ephemeris
00183   // using the nominal position as an offset.
00184   // Note that interTime is assumed to use the same time reference frame
00185   // as originEpoch.
00186   MDirection extractDirMeas(const MDirection& offsetDir, 
00187                             Int index, Double& interTime, 
00188                             MEpoch originEpoch) const;
00189 
00190   void getMJDs(Double& originMJD, Double& interMJD, 
00191                const Double interTime, const MEpoch originEpoch) const;
00192 
00193 private:
00194   //# Make the assignment operator and the copy constructor private to prevent
00195   //# any compiler generated one from being used.
00196   ROMSFieldColumns(const ROMSFieldColumns&);
00197   ROMSFieldColumns& operator=(const ROMSFieldColumns&);
00198 
00199   //# Check if any optional columns exist and if so attach them.
00200   //# Initialise the necessary MeasComet objects if the EPHEMERIS_ID column is present.
00201   void attachOptionalCols(const MSField& msField);
00202   
00203   //# Functions which check the supplied values against the relevant column and
00204   //# the specified row. The row must have a numpoly value of zero. The mvdir
00205   //# argument is a temporary that is passed in to prevent it from being
00206   //# created inside these small functions.
00207   // <group>
00208   Bool matchReferenceDir(uInt row, const MVDirection& dirVal,
00209                          const Double& sepInRad, 
00210                          MVDirection& mvdir, Double time=0) const;
00211   Bool matchDelayDir(uInt row, const MVDirection& dirVal, 
00212                      const Double& sepInRad,
00213                      MVDirection& mvdir, Double time=0) const;
00214   Bool matchPhaseDir(uInt row, const MVDirection& dirVal,
00215                      const Double& sepInRad,
00216                      MVDirection& mvdir, Double time=0) const;
00217   // </group>
00218 
00219   //# required columns
00220   ROScalarColumn<String> name_p;
00221   ROScalarColumn<String> code_p;
00222   ROScalarColumn<Double> time_p;
00223   ROScalarColumn<Int> numPoly_p;
00224   ROArrayColumn<Double> delayDir_p;
00225   ROArrayColumn<Double> phaseDir_p;
00226   ROArrayColumn<Double> referenceDir_p;
00227   ROScalarColumn<Int> sourceId_p;
00228   ROScalarColumn<Bool> flagRow_p;
00229   //# optional columns
00230   ROScalarColumn<Int> ephemerisId_p;
00231 
00232   //# Access to Measure columns
00233   ROScalarMeasColumn<MEpoch> timeMeas_p;
00234   ROArrayMeasColumn<MDirection> delayDirMeas_p;
00235   ROArrayMeasColumn<MDirection> phaseDirMeas_p;
00236   ROArrayMeasColumn<MDirection> referenceDirMeas_p;
00237 
00238   //# Access to Quantum columns
00239   ROScalarQuantColumn<Double> timeQuant_p;
00240 };
00241 
00242 // <summary>
00243 // A class to provide easy read-write access to MSField columns
00244 // </summary>
00245 
00246 // <use visibility=export>
00247 
00248 // <reviewed reviewer="Bob Garwood" date="1997/02/01" tests="" demos="">
00249 // </reviewed>
00250 
00251 // <prerequisite>
00252 //   <li> MSField
00253 //   <li> ArrayColumn
00254 //   <li> ScalarColumn
00255 // </prerequisite>
00256 //
00257 // <etymology>
00258 // MSFieldColumns stands for MeasurementSet Field Table columns.
00259 // </etymology>
00260 //
00261 // <synopsis>
00262 // This class provides access to the columns in the MSField Table,
00263 // it does the declaration of all the Scalar and ArrayColumns with the
00264 // correct types, so the application programmer doesn't have to
00265 // worry about getting those right. There is an access function
00266 // for every predefined column. Access to non-predefined columns will still
00267 // have to be done with explicit declarations.
00268 // See <linkto class=MSColumns> MSColumns</linkto> for an example.
00269 // </synopsis>
00270 //
00271 // <motivation>
00272 // See <linkto class=MSColumns> MSColumns</linkto> for the motivation.
00273 // </motivation>
00274 
00275 class MSFieldColumns: public ROMSFieldColumns
00276 {
00277 public:
00278   // Construct from the supplied Table
00279   MSFieldColumns(MSField& msField);
00280 
00281   // The desctructor does nothing special
00282   ~MSFieldColumns();
00283 
00284   // Read-write access to required columns
00285   //
00286   // Note that the direction measures with a stored polynomial have Col() added
00287   // to their name. They are better accessed via the functions that have the
00288   // same name, without the Col suffix, that will do the interpolation for
00289   // you. These functions are in the ROMSFieldColumns class.
00290   // <group>
00291   ScalarColumn<String>& code() {return code_p;}
00292   ArrayColumn<Double>& delayDir() {return delayDir_p;}
00293   ArrayMeasColumn<MDirection>& delayDirMeasCol() 
00294     {return delayDirMeas_p;}
00295   ScalarColumn<Bool>& flagRow() {return flagRow_p;}
00296   ScalarColumn<String>& name() {return name_p;}
00297   ScalarColumn<Int>& numPoly() {return numPoly_p;}
00298   ArrayColumn<Double>& phaseDir() {return phaseDir_p;}
00299   ArrayMeasColumn<MDirection>& phaseDirMeasCol() 
00300     {return phaseDirMeas_p;}
00301   ArrayColumn<Double>& referenceDir() {return referenceDir_p;}
00302   ArrayMeasColumn<MDirection>& referenceDirMeasCol() 
00303     {return referenceDirMeas_p;}
00304   ScalarColumn<Int>& sourceId() {return sourceId_p;}
00305   ScalarColumn<Double>& time() {return time_p;}
00306   ScalarQuantColumn<Double>& timeQuant() { return timeQuant_p;}
00307   ScalarMeasColumn<MEpoch>& timeMeas() { return timeMeas_p;}
00308   // </group>
00309 
00310   // Read-write access to optional columns
00311   // <group>
00312   ScalarColumn<Int>& ephemerisId() {return ephemerisId_p;}
00313   // </group>
00314 
00315   // Read-only access to required columns
00316   // <group>
00317   const ROScalarColumn<String>& code() const {
00318     return ROMSFieldColumns::code();}
00319   const ROArrayColumn<Double>& delayDir() const {
00320     return ROMSFieldColumns::delayDir();}
00321   const ROArrayMeasColumn<MDirection>& delayDirMeasCol() const {
00322     return ROMSFieldColumns::delayDirMeasCol();}
00323   const ROScalarColumn<Bool>& flagRow() const {
00324     return ROMSFieldColumns::flagRow();}
00325   const ROScalarColumn<String>& name() const {
00326     return ROMSFieldColumns::name();}
00327   const ROScalarColumn<Int>& numPoly() const {
00328     return ROMSFieldColumns::numPoly();}
00329   const ROArrayColumn<Double>& phaseDir() const {
00330     return ROMSFieldColumns::phaseDir();}
00331   const ROArrayMeasColumn<MDirection>& phaseDirMeasCol() const {
00332     return ROMSFieldColumns::phaseDirMeasCol();}
00333   const ROArrayColumn<Double>& referenceDir() const {
00334     return ROMSFieldColumns::referenceDir();}
00335   const ROArrayMeasColumn<MDirection>& referenceDirMeasCol() const {
00336     return ROMSFieldColumns::referenceDirMeasCol();}
00337   const ROScalarColumn<Int>& sourceId() const {
00338     return ROMSFieldColumns::sourceId();}
00339   const ROScalarColumn<Double>& time() const {
00340     return ROMSFieldColumns::time();}
00341   const ROScalarQuantColumn<Double>& timeQuant() const {
00342     return ROMSFieldColumns::timeQuant();}
00343   const ROScalarMeasColumn<MEpoch>& timeMeas() const { 
00344     return ROMSFieldColumns::timeMeas();}
00345   // </group>
00346 
00347   // Read-only access to optional columns
00348   // <group>
00349   const ROScalarColumn<Int>& ephemerisId() const {
00350     return ROMSFieldColumns::ephemerisId();}
00351   // </group>
00352 
00353   // Interpolate the direction Measure polynomial
00354   static MDirection interpolateDirMeas(const Array<MDirection>& arrDir, 
00355                                        Int numPoly, Double interTime, 
00356                                        Double timeOrigin);
00357 
00358 
00359   // set the epoch reference type for the TIME column. 
00360   // <note role=tip>
00361   // In principle this function can only be used if the table is empty,
00362   // otherwise already written values may thereafter have an incorrect
00363   // reference, offset, or unit.  However, it is possible that part of the
00364   // table gets written before these values are known.  In that case the
00365   // reference, offset, or units can be set by using a False
00366   // <src>tableMustBeEmpty</src> argument.
00367   // </note>
00368   void setEpochRef(MEpoch::Types ref, Bool tableMustBeEmpty=True);
00369 
00370   // set the direction reference type for the REFERENCE_DIR, DELAY_DIR &
00371   // PHASE_DIR columns. This can only be done when the table has no
00372   // rows. Trying to do so at other times will throw an exception.
00373   void setDirectionRef(MDirection::Types ref);
00374 
00375 protected:
00376   //# default constructor creates a object that is not usable. Use the attach
00377   //# function correct this.
00378   MSFieldColumns();
00379 
00380   //# attach this object to the supplied table.
00381   void attach(MSField& msField);
00382 
00383 private:
00384   //# Make the assignment operator and the copy constructor private to prevent
00385   //# any compiler generated one from being used.
00386   MSFieldColumns(const MSFieldColumns&);
00387   MSFieldColumns& operator=(const MSFieldColumns&);
00388 
00389   //# Check if any optional columns exist and if so attach them.
00390   //# Initialise the necessary MeasComet objects if the EPHEMERIS_ID column is present.
00391   void attachOptionalCols(MSField& msField);
00392   
00393   //# required columns
00394   ScalarColumn<String> name_p;
00395   ScalarColumn<String> code_p;
00396   ScalarColumn<Double> time_p;
00397   ScalarColumn<Int> numPoly_p;
00398   ArrayColumn<Double> delayDir_p;
00399   ArrayColumn<Double> phaseDir_p;
00400   ArrayColumn<Double> referenceDir_p;
00401   ScalarColumn<Int> sourceId_p;
00402   ScalarColumn<Bool> flagRow_p;
00403   //# optional columns
00404   ScalarColumn<Int> ephemerisId_p;
00405   
00406   //# Access to Measure columns
00407   ScalarMeasColumn<MEpoch> timeMeas_p;
00408   ArrayMeasColumn<MDirection> delayDirMeas_p;
00409   ArrayMeasColumn<MDirection> phaseDirMeas_p;
00410   ArrayMeasColumn<MDirection> referenceDirMeas_p;
00411 
00412   //# Access to Quantum columns
00413   ScalarQuantColumn<Double> timeQuant_p;
00414 
00415 };
00416 
00417 
00418 } //# NAMESPACE CASA - END
00419 
00420 #endif