casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MSSpwIndex.h
Go to the documentation of this file.
00001 //# MSSpwIndex: index or lookup in a MeasurementSet subtable (DDID and SPW)
00002 //# Copyright (C) 2000,2001
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: MSSpwIndex.h 20266 2008-02-26 00:43:05Z gervandiepen $
00028 
00029 #ifndef MS_MSSPWINDEX_H
00030 #define MS_MSSPWINDEX_H
00031 
00032 //# includes
00033 #include <casa/aips.h>
00034 #include <casa/Arrays/Vector.h>
00035 #include <casa/BasicSL/String.h>
00036 #include <ms/MeasurementSets/MSColumns.h>
00037 #include <casa/Arrays/Matrix.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# forward declarations
00042 
00043 // <summary> 
00044 // Class to handle lookup or indexing into a MS Data_Desc_ID
00045 // and SpectralWindow subtables 
00046 // </summary>
00047 
00048 // <use visibility=export>
00049 //
00050 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00051 // </reviewed>
00052 
00053 // <prerequisite>
00054 //   <li> MeasurementSet
00055 // </prerequisite>
00056 //
00057 // <etymology>
00058 // From "MeasurementSet", "SpectralWindwo subtable" and "index".
00059 // </etymology>
00060 //
00061 // <synopsis> 
00062 //
00063 // This class provides lookup and two level indexing into an MS
00064 // DataDescription and SpectralWindow subtable. These services include
00065 // returning list of integer data description IDs (DDID), given a list
00066 // of Spectral window IDs or frequencies.  The DDIDs are then used for
00067 // selecting rows from the MS (since DDIDs are the primary keys in the
00068 // maintable - not the spectral window IDs).
00069 //
00070 // </synopsis>
00071 //
00072 // <example>
00073 // </example>
00074 //
00075 // <motivation> 
00076 // Collect together all subtable indexing and lookup for the data
00077 // description and spectral window subtable, for encapsulation and
00078 // efficiency.
00079 // </motivation>
00080 //
00081 // <thrown>
00082 //    <li>
00083 //    <li>
00084 // </thrown>
00085 //
00086 
00087 class MSSpwIndex 
00088 {
00089 public:
00090   enum MSSpwTypes {MSSPW_INDEXRANGE=0,MSSPW_INDEX=2, MSSPW_UNITHZ=4, MSSPW_UNITVELOCITY=5};
00091 
00092   // Construct from an MS FIELD subtable
00093   MSSpwIndex(const MSSpectralWindow& msSpw);
00094 
00095   // Null destructor
00096   virtual ~MSSpwIndex() {};
00097 
00098   // Look up FIELD_ID's for a given field name, or set of field names
00099   Vector<Int> matchName(const String& name);
00100   Vector<Int> matchName(const Vector<String>& names);
00101 
00102   Vector<Int> matchFrequencyRange(const Float f0,const Float f1,Bool approx, const Float f3=0);
00103 
00104   // A version of match freq range that does not throw an exception but returns
00105   // false if no match...else spw, start, nchan returns the matches 
00106   // f0 and f1 are in Hz and the match is done in the frame defined in the 
00107   // SpectralWindow table.
00108   Bool matchFrequencyRange(const Double f0, const Double f1, 
00109                            Vector<Int>& spw, Vector<Int>& start, 
00110                            Vector<Int>& nchan);
00111   // Look up FIELD_ID's for a given pattern/regex for source name/code
00112   Vector<Int> matchRegexOrPattern(const String& pattern,
00113                                        const Bool regex=False);
00114   // Look up FIELD_ID's for a given source id
00115   Vector<Int> matchId(const Vector<Int>& spwIds);
00116 
00117   Vector<Int> matchLT(const Int n);
00118   Vector<Int> matchGT(const Int n);
00119   Vector<Int> matchGTAndLT(const Int n0, const int n1);
00120   Vector<Int> matchLT(const Float*);
00121   Vector<Int> matchGT(const Float*);
00122   Vector<Int> matchGTAndLT(const Float* phyValMin, const Float *phyValMax);
00123   Vector<Float> convertToMKS(const Float f0, const Float f1, const String& unit); 
00124   Vector<Int> convertToChannelIndex(const Vector<Int>& spw, const Vector<Float>& freqList,
00125                                     Int& nFSpec);
00126   Vector<Int> convertToSpwIndex(const Vector<Float>& freqList,
00127                                 Int &nFSpec);
00128 private:
00129   Int findChanIndex_p(const Float& freq, const Vector<Double>& chanFreqList,
00130                       const Bool& greaterThan,
00131                       const Bool& ascendingOrder);
00132   // Construct from an MS FIELD subtable
00133   MSSpwIndex();
00134   // FIELD subtable column accessor
00135   ROMSSpWindowColumns msSpwSubTable_p;
00136   //  ROMSDataDescColumns msDataDescSubTable_p;
00137   enum MODES {EXACT=1, APPROX, RANGE};
00138   Vector<Int> spwIDs;
00139 };
00140 
00141 
00142 } //# NAMESPACE CASA - END
00143 
00144 #endif
00145