casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MSConcat.h
Go to the documentation of this file.
00001 //# MSConcat.h: A class for concatenating MeasurementSets.
00002 //# Copyright (C) 2000,2002,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: MSConcat.h 20648 2009-06-29 07:22:00Z gervandiepen $
00028 
00029 #ifndef MS_MSCONCAT_H
00030 #define MS_MSCONCAT_H
00031 
00032 #include <casa/aips.h>
00033 #include <ms/MeasurementSets/MSColumns.h>
00034 #include <ms/MeasurementSets/MeasurementSet.h>
00035 #include <casa/Arrays/IPosition.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 class TableDesc;
00040 class ROMSMainColumns;
00041 class ROMSDataDescColumns;
00042 class ROMSSpWindowColumns;
00043 class ROMSPolarizationColumns;
00044 class MSAntenna;
00045 class MSDataDescription;
00046 class MSFeed;
00047 class MSField;
00048 class MSPolarization;
00049 class MSSpectralWindow;
00050 template <class T> class Block;
00051 
00052 // <summary>A class with functions for concatenating MeasurementSets</summary>
00053 
00054 // <use visibility=export>
00055 
00056 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00057 // </reviewed>
00058 
00059 // <prerequisite>
00060 //   <li> SomeClass
00061 //   <li> SomeOtherClass
00062 //   <li> some concept
00063 // </prerequisite>
00064 //
00065 // <etymology>
00066 // </etymology>
00067 //
00068 // <synopsis>
00069 // </synopsis>
00070 //
00071 // <example>
00072 // </example>
00073 //
00074 // <motivation>
00075 // </motivation>
00076 //
00077 // <templating arg=T>
00078 //    <li>
00079 //    <li>
00080 // </templating>
00081 //
00082 // <thrown>
00083 //    <li>
00084 //    <li>
00085 // </thrown>
00086 //
00087 // <todo asof="yyyy/mm/dd">
00088 //   <li> add this feature
00089 //   <li> fix this bug
00090 //   <li> start discussion of this possible extension
00091 // </todo>
00092 
00093 class MSConcat: public MSColumns
00094 {
00095 public:
00096   MSConcat(MeasurementSet& ms);
00097 
00098   void virtualconcat(MeasurementSet& otherMS, 
00099                      const Bool checkShapeAndCateg=True,
00100                      const String& obsidAndScanTableName="");
00101 
00102   void concatenate(const MeasurementSet& otherMS,
00103                    const uInt handling=0,   // 0 (default): complete concat of all tables
00104                                             // 1 : don't concatenate the MAIN table
00105                                             // 2 : don't concatenate the POINTING table
00106                                             // 3 : neither concat MAIN nor POINTING table
00107                    const String& destMSName=""); // support for virtual concat
00108 
00109   void setTolerance(Quantum<Double>& freqTol, Quantum<Double>& dirTol); 
00110   void setWeightScale(const Float weightScale); 
00111   void setRespectForFieldName(const Bool respectFieldName); // If True, fields of same direction are not merged
00112                                                             // if their name is different
00113 
00114 private:
00115   MSConcat();
00116   static IPosition isFixedShape(const TableDesc& td);
00117   static IPosition getShape(const ROMSDataDescColumns& ddCols, 
00118                             const ROMSSpWindowColumns& spwCols, 
00119                             const ROMSPolarizationColumns& polCols, 
00120                             uInt whichShape);
00121   void checkShape(const IPosition& otherShape) const;
00122   void checkCategories(const ROMSMainColumns& otherCols) const;
00123   Bool checkEphIdInField(const ROMSFieldColumns& otherFldCol) const;
00124   Bool copyPointing(const MSPointing& otherPoint, const Block<uInt>& newAntIndices);
00125   Bool copyPointingB(MSPointing& otherPoint, const Block<uInt>& newAntIndices);
00126   Int copyObservation(const MSObservation& otherObs, const Bool remRedunObsId=True);
00127                              // by default remove redundant observation table rows
00128   Block<uInt> copyAntennaAndFeed(const MSAntenna& otherAnt,
00129                                  const MSFeed& otherFeed);
00130   Block<uInt> copyState(const MSState& otherState);
00131   Block<uInt> copyField(const MeasurementSet& otherms);
00132   Block<uInt> copySpwAndPol(const MSSpectralWindow& otherSpw,
00133                             const MSPolarization& otherPol,
00134                             const MSDataDescription& otherDD);
00135   Bool copySource(const MeasurementSet& otherms);
00136   Bool updateSource();
00137   Bool sourceRowsEquivalent(const MSSourceColumns& sourceCol, 
00138                             const uInt& rowi, const uInt& rowj,
00139                             const Bool dontTestDirection=False);
00140 
00141   Bool obsRowsEquivalent(const MSObservationColumns& obsCol, 
00142                          const uInt& rowi, const uInt& rowj);
00143 
00144 
00145   void updateModelDataKeywords(MeasurementSet& ms);
00146 
00147   MeasurementSet itsMS;
00148   IPosition itsFixedShape;
00149   Quantum<Double> itsFreqTol;
00150   Quantum<Double> itsDirTol;
00151   Float itsWeightScale;
00152   Bool itsRespectForFieldName;
00153   Vector<Bool> itsChanReversed;
00154   SimpleOrderedMap <Int, Int> newSourceIndex_p;
00155   SimpleOrderedMap <Int, Int> newSourceIndex2_p;
00156   SimpleOrderedMap <Int, Int> newSPWIndex_p;
00157   SimpleOrderedMap <Int, Int> newObsIndexA_p;
00158   SimpleOrderedMap <Int, Int> newObsIndexB_p;
00159   SimpleOrderedMap <Int, Int> solSystObjects_p;
00160 
00161   Bool doSource_p;
00162   Bool doSource2_p;
00163   Bool doSPW_p;
00164   Bool doObsA_p;
00165   Bool doObsB_p;
00166 
00167 };
00168 
00169 template<class T>
00170 Bool areEQ(const ROScalarColumn<T>& col, uInt row_i, uInt row_j) 
00171 {
00172   T value_i, value_j;
00173   col.get(row_i, value_i);
00174   col.get(row_j, value_j);
00175   return (value_i == value_j);
00176 }
00177 
00178 template<class T>
00179 Bool areEQ(const ROArrayColumn<T>& col, uInt row_i, uInt row_j) 
00180 {
00181   Bool rval(False);
00182   Array<T> arr_i;
00183   Array<T> arr_j;
00184   
00185   col.get(row_i, arr_i, True);
00186   col.get(row_j, arr_j, True);
00187   Int ni = arr_i.nelements();
00188   Int nj = arr_j.nelements();
00189   if( (ni==0 && nj==0) ||    // no data is regarded as equal
00190       allEQ(arr_i, arr_j)){
00191     rval = True;
00192   }
00193   return rval;
00194 }
00195 
00196 
00197 
00198 } //# NAMESPACE CASA - END
00199 
00200 #endif
00201 
00202 
00203