casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VLAFiller.h
Go to the documentation of this file.
00001 //# VLAFiller.h: 
00002 //# Copyright (C) 1999,2000,2001,2003
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 //#
00027 //# $Id$
00028 
00029 #ifndef NRAO_VLAFILLER_H
00030 #define NRAO_VLAFILLER_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Arrays/IPosition.h>
00035 #include <casa/Containers/Block.h>
00036 #include <casa/Containers/Record.h>
00037 #include <casa/Logging/LogIO.h>
00038 #include <ms/MeasurementSets/MSColumns.h>
00039 #include <ms/MeasurementSets/MeasurementSet.h>
00040 #include <measures/Measures/MBaseline.h>
00041 #include <measures/Measures/MDirection.h>
00042 #include <measures/Measures/Muvw.h>
00043 #include <measures/Measures/MFrequency.h>
00044 #include <measures/Measures/MeasConvert.h>
00045 #include <measures/Measures/MeasFrame.h>
00046 #include <measures/Measures/Stokes.h>
00047 #include <tables/Tables/TiledDataStManAccessor.h>
00048 #include <nrao/VLA/VLAEnum.h>
00049 #include <nrao/VLA/VLAFilterSet.h>
00050 #include <nrao/VLA/VLALogicalRecord.h>
00051     
00052 #include <casa/namespace.h>
00053 namespace casa { //# NAMESPACE CASA - BEGIN
00054 class Path;
00055 class MPosition;
00056 template <class T> class Vector;
00057 } //# NAMESPACE CASA - END
00058 
00059 struct IterationStatus;
00060 
00061 // <summary>Functions to convert from VLA archive format to a MeasurementSet</summary>
00062 
00063 // <use visibility=export>
00064 
00065 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00066 // </reviewed>
00067 
00068 // <prerequisite>
00069 //   <li> SomeClass
00070 //   <li> SomeOtherClass
00071 //   <li> some concept
00072 // </prerequisite>
00073 //
00074 // <etymology>
00075 // </etymology>
00076 //
00077 // <synopsis>
00078 // </synopsis>
00079 //
00080 // <example>
00081 // </example>
00082 //
00083 // <motivation>
00084 // </motivation>
00085 //
00086 // <templating arg=T>
00087 //    <li>
00088 //    <li>
00089 // </templating>
00090 //
00091 // <thrown>
00092 //    <li>
00093 //    <li>
00094 // </thrown>
00095 //
00096 // <todo asof="yyyy/mm/dd">
00097 //   <li> add this feature
00098 //   <li> fix this bug
00099 //   <li> start discussion of this possible extension
00100 // </todo>
00101 
00102 class VLAFiller: public MSColumns
00103 {
00104 public:
00105   // Construct a VLAFiller object that will data from the specified input, and
00106   // writes it to the supplied MeasurementSet.
00107   // We set the default tolerance for frequency to be 6 times of the
00108   // channel width and also give user the ability to pass in a tolerance
00109   // for frequency into vlafillerfromdisk(). The default tolerance of frequency
00110   // works for dataset G192. But for dataset NGC7538, one has to give a tolerance
00111   // as larger as 60 times its channel width ( 60000000Hz ). For other dataset, the
00112   // user has to try out the proper tolerance.
00113   VLAFiller(MeasurementSet& output, VLALogicalRecord& input, Double freqTolerance=0.0, Bool autocorr=False, const String& antnamescheme="new", const Bool& applyTsys=True);
00114 
00115   // Does nothing special
00116   ~VLAFiller();
00117 
00118   // Set the filter that will be used to restrict which input records get
00119   // copied to the output MS.
00120   void setFilter(const VLAFilterSet& filter);
00121 
00122   // fill the supplied MeasurementSet from the the supplied VLABuffer. The
00123   // number/type of messages describing the progress sent to the logger are
00124   // controlled using the verbose argument. If verbose is -1 or less then no
00125   // messages are sent to the logger. If verbose is zero then a summary is sent
00126   // to the logger just before this function completes. If verbose is one then
00127   // a message is sent for every record copied to the output MS. If verbose is
00128   // two a message is sent every second record and so on.
00129   void fill(Int verbose=1);
00130 
00131   // Construct an empty MeasurementSet with the supplied table name. Throw
00132   // an exception (AipsError) if the specified Table already exists unless the
00133   // overwrite argument is set to True.
00134   static MeasurementSet emptyMS(const Path& tableName, 
00135                                 const Bool overwrite=False);
00136   
00137   // Open the MeasurementSet with the supplied name. Throw an exception
00138   // (AipsError) if the specified Table does not exist. By default the Table is
00139   // opened for read/write access. The Type/SubType MUST be "Measurement
00140   // Set/VLA" ie., the MS must have been created with this class. Otherwise an
00141   // exception is thrown.
00142   static MeasurementSet openMS(const Path& tableName, 
00143                                const Bool readonly=False);
00144   
00145   // Return an empty MeasurementSet with the supplied table name. Creates a
00146   // empty measurement set unless one with the specified name already exists
00147   // and overwrite is False. Then it opens the existing measurement set for
00148   // read/write access.
00149   static MeasurementSet getMS(const Path& tableName, 
00150                               const Bool overwrite=False);
00151   
00152   // Set the stop Parameters for filling
00153    void setStopParams(String &, String &);
00154 private:
00155   // Read one record from the input and copies it to the MS if it is not
00156   // filtered out. Returns False if a record could not be read.
00157   Bool fillOne();
00158 
00159   // Send to the logger info about how the filler is going
00160   void logCurrentRecord(IterationStatus& counts);
00161   void logChanges(IterationStatus& counts);
00162 
00163   // Send to the logger info about how much data is in the (sub)tables
00164   void summarise();
00165 
00166   //# Add an entry to the antenna subtable
00167   uInt addAntenna(const MPosition& antennaPos, uInt whichAnt);
00168 
00169   //# Add an entry to the feed subtable
00170   void addFeed(uInt whichAnt);
00171 
00172   //# Add an entry to the field subtable
00173   uInt addField(const MDirection& refDir);
00174 
00175   //# Add an entry to the pointing subtable
00176   uInt addPointing(const MDirection& antennaDir,
00177                    const MDirection& fieldDir, uInt whichAnt);
00178   // # Add an entry to the doppler dubtable
00179   uInt addDoppler( const VLAEnum::CDA cda ); 
00180   //# Add an entry to the spectral-window subtable
00181   uInt addSpectralWindow(const VLAEnum::CDA cda, const MFrequency& refFreq,
00182                          const uInt nChan,
00183                          const Double bandwidth,
00184                          const uInt ifChain);
00185 
00186   //# Add an entry to the polarization subtable
00187   uInt addPolarization(const Vector<Stokes::StokesTypes>& pol);
00188 
00189   //# Add an entry to the data description subtable
00190   uInt addDataDescription(uInt spwId, uInt polId);
00191 
00192   //# Add an entry in the source subtable
00193   uInt addSource(const MDirection& dir );
00194 
00195   //# Add a hypercube to the columns that use the Tiled Data Storage manager.
00196   void addHypercubes(uInt nPol, uInt nChan);
00197 
00198   //# Add the specified number of rows tp the specified hypercubes
00199   void extendHypercubes(const Block<uInt>& nPol, const Block<uInt>& nChan, 
00200                         uInt rows);
00201   
00202   //# Reconcile duplicate field names
00203   void fixFieldDuplicates(MSField& msFld);
00204 
00205   //# Determine whether to stop the fill for on-line filling
00206   String projectCode;
00207   MVEpoch stopTime;
00208   Bool checkStop;
00209   Bool fillStarted;
00210   Bool stopFilling(VLALogicalRecord &);
00211   //# pol index RR=0, RL=1, LR=2, LL needed just for index data
00212   Int polIndexer(Stokes::StokesTypes& stokes);
00213   //# Contains a logical record
00214   VLALogicalRecord itsRecord;
00215 
00216   //# Only logical records that match the specified criteria will be used.
00217   VLAFilterSet itsInputFilters;
00218 
00219   //# The output MS
00220   MeasurementSet itsMS;
00221   
00222   //# The reference frame of the observation is cached here and used when
00223   //# conversions from the observed frame to the one used in the MS.
00224   MeasFrame itsFrame;
00225   //# The reference frame of the observation whose spw is identified different 
00226   //# from what in the SPECTRAL_WINDOWS table and been added in. So the current
00227   //# length of Vector equal the number of row in table SPECTRAL WINDOW( no use).
00228   //# Vector<MeasFrame> theirFrames;
00229   //# This is the direction reference for the Measurement set. It is cached
00230   //# here.
00231   MDirection::Types itsMSDirType;
00232   //# This is the reference frame of the last record copied. Initially it is
00233   //# set to a meaningless value.
00234   MDirection::Types itsDirType;
00235   //# This converter is used to convert from the direction types on the archive
00236   //# to the one in the Measurement set. Its is cached to prevent it
00237   //# continually having to be recreated. It is never used if all the data on
00238   //# the archive and all the data in the MS have the same direction type.
00239   MDirection::Convert itsDirCtr;
00240 
00241   //# This converter is used to convert from the direction types on the archive
00242   //# to Az, El. It is only needed for holography data.
00243   MDirection::Convert itsAzElCtr;
00244 
00245   //# This converter is used to convert the UVW coordinates from the type on
00246   //# the archive to the one in the Measurement set. It is cached to
00247   //# prevent it continually having to be recreated. It is never used if all
00248   //# the data on the archive and all the data in the MS have the same
00249   //# direction type.
00250   Muvw::Convert itsUvwCtr;
00251 
00252   //# This converter is used to convert from the channel frequency types on the
00253   //# archive to the one in the Measurement set. Its is cached hear to prevent
00254   //# it continually having to be recreated. It is only used if
00255   //# data in the archive was observed with online Doppler tracking.
00256   MFrequency::Convert itsFreqCtr;
00257 
00258   //# This converter is used to the VLA baselines which are in the HADEC frame
00259   //#to the ITRF frame so that they can be properly added with the VLA reference
00260   //# position, which is also in the ITRF frame.
00261   MBaseline::Convert itsBlCtr;
00262 
00263   //# The field Id for the most recently copied record. Negative if no record
00264   //# has been copied.
00265   Block<Int> itsFldId;
00266 
00267   //# The antenna Id's for all the antennas in the most recently copied
00268   //# record. Zero length if no record has been copied.
00269   Block<Int> itsAntId;
00270 
00271   //# The spectral window Id's for all the CDA's in the most recently copied
00272   //# record. Always of length 4. Contains -1 is the CDA is unused.
00273   Block<Int> itsSpId;
00274 
00275   //# The polarization Id for the most recently copied record. Negative if no
00276   //# record has been copied. There is one for each Spectral Id.
00277   Block<Int> itsPolId;
00278 
00279   //# The data description Id's for the most recently copied record. Negative
00280   //# if no record has been copied.
00281   Block<Block<Int> > itsDataId;
00282 
00283   //# The length of these blocks is set to the maximum number of
00284   //# subarrays(4). The itsNewScan block is true if the field, spectral window
00285   //# etc. has changed and the itsScan Block indicates the scan number.
00286   Bool itsNewScan;
00287   Block<Int> itsScan;
00288   //# A string, containing projkect names, that is accumulated when filling and
00289   //# written to the OBSERVATION subtable.
00290   String itsProject;
00291   //# The place to log messages
00292   LogIO itsLog;
00293 
00294   //# These data members needed because of the use of the TiledData Storage
00295   //# Manager. It may be possible to remove these when the TiledShape storage
00296   //# manager can be used (the holdup is currently in VisSet).
00297   TiledDataStManAccessor itsDataAcc;
00298   Record itsTileId;
00299   TiledDataStManAccessor itsSigmaAcc;
00300   TiledDataStManAccessor itsFlagAcc;
00301   TiledDataStManAccessor itsImagingWeightAcc;
00302   TiledDataStManAccessor itsModDataAcc;
00303   TiledDataStManAccessor itsCorrDataAcc;
00304   TiledDataStManAccessor itsChanFlagAcc;
00305   Block<IPosition> itsDataShapes;
00306   Double itsFreqTolerance;
00307   Bool itsApplyTsys;
00308   Bool itsNewAntName;
00309   Bool itsKeepAutoCorr;
00310   Bool itsEVLAisOn;
00311   Bool itsInitEpoch;
00312   Bool itsRevBeenWarned;
00313   
00314 };
00315 #endif