casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MSPolnParse.h
Go to the documentation of this file.
00001 //# MSPolnParse.h: Classes to hold results from poln grammar parseing
00002 //# Copyright (C) 1994,1995,1997,1998,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 //# $Id: MSPolnParse.h 20749 2009-09-30 14:24:05Z gervandiepen $
00027 
00028 #ifndef MS_MSPOLNPARSE_H
00029 #define MS_MSPOLNPARSE_H
00030 
00031 //# Includes
00032 #include <ms/MeasurementSets/MSParse.h>
00033 #include <casa/Containers/OrderedMap.h>
00034 #include <casa/Containers/MapIO.h>
00035 #include <ms/MeasurementSets/MSPolarization.h>
00036 #include <ms/MeasurementSets/MSPolColumns.h>
00037 #include <ms/MeasurementSets/MSPolIndex.h>
00038 #include <ms/MeasurementSets/MSDataDescIndex.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 //# Forward Declarations
00043 
00044 
00045 // <summary>
00046 // Class to hold values from field grammar parser
00047 // </summary>
00048 
00049 // <use visibility=local>
00050 
00051 // <reviewed reviewer="" date="" tests="">
00052 // </reviewed>
00053 
00054 // <prerequisite>
00055 //# Classes you should understand before using this one.
00056 // </prerequisite>
00057 
00058 // <etymology>
00059 // MSPolnParse is the class used to parse a polarization selection command.
00060 // </etymology>
00061 
00062 // <synopsis> 
00063 //
00064 // MSPolnParse is used by the parser of polarization sub-expression
00065 // statements of the type [SPW:]POLN.  Since this is a relatively
00066 // simple expression to tokenize and parse, this parser is written
00067 // without Bison or Flex.  The methods of this class take an
00068 // expression, and internally generate a list of the Data Description
00069 // IDs that should be used to select the rows in the MS main table.
00070 // The map of Polarization IDs (row numbers in the POLARIZATION
00071 // sub-table) and the list of indices to be used to pick the user
00072 // selected polarzation data (in the DATA columns of the MS main
00073 // table) is also generated.  This map is intended to be used along
00074 // with the map of SPW and selected channels to apply the in-row
00075 // selection (Slice on the data columns).
00076 //
00077 // </synopsis>
00078 
00079 // <motivation> 
00080 // It is necessary to be able to give a data selection
00081 // command in ASCII.  This can be used in a CLI or in the table
00082 // browser to get a subset of a table or to sort a table.
00083 // </motivation>
00084 
00085 //# <todo asof="$DATE:$">
00086 //# A List of bugs, limitations, extensions or planned refinements.
00087 //# </todo>
00088 
00089 
00090 class MSPolnParse : public MSParse
00091 {
00092 public:
00093   // Default constructor
00094   MSPolnParse ();
00095   //  ~MSPolnParse() {cleanup();};
00096 
00097   // Associate the ms and the shorthand.
00098   MSPolnParse (const MeasurementSet* ms);
00099 
00100   const TableExprNode selectFromIDList(const Vector<Int>& ddIDs);
00101 
00102   // Get table expression node object.
00103   const TableExprNode node();
00104   //  static MSPolnParse* thisMSSParser;
00105   void reset() {polMap_p.clear(); ddIDList_p.resize(0);};
00106   void cleanup() {/*if (node_p) delete node_p;node_p=0x0;*/};
00107   Int theParser(const String& command); 
00108                 // Vector<Int>& selectedDDIDs, 
00109                 // Matrix<Int>& selectedSpwPolnMap);
00110   OrderedMap<Int, Vector<Int> > selectedPolnMap()           {return polMap_p;}
00111   OrderedMap<Int, Vector<Vector<Int> > > selectedSetupMap() {return setupMap_p;}
00112   Vector<Int> selectedDDIDs()                               {return ddIDList_p;}
00113 private:
00114   Vector<Int> getMapToDDIDs(MSDataDescIndex& msDDNdx, MSPolarizationIndex& msPolNdx,
00115                             const Vector<Int>& spwIDs, Vector<Int>& polnIDs,
00116                             Vector<Int>& polIndices);
00117   Vector<Int> matchPolIDsToPolTableRow(const Vector<Int>& polIds,
00118                                        OrderedMap<Int, Vector<Int> >& polIndexMap,
00119                                        Vector<Int>& polIndices,
00120                                        Bool addToMap=False);
00121   Vector<Int> getPolnIDs(const String& polSpec, Vector<Int>& polIndices);
00122   Vector<Int> getPolnIndices(const Int& polnID, const Vector<Int>& polnIDList);
00123   //
00124   // These are the versions used in the code.
00125   Vector<Int> getPolnIDsV2(const String& polSpec, Vector<Int>& polTypes);
00126   Vector<Int> getMapToDDIDsV2(const String& polExpr, 
00127                               const Vector<Int>& spwIDs, 
00128                               Vector<Int>& polnIDs,
00129                               Vector<Int>& polnIndices);
00130   TableExprNode node_p;
00131   Vector<Int> ddIDList_p;
00132   OrderedMap<Int, Vector<Int> > polMap_p;
00133   OrderedMap<Int, Vector<Vector<Int> > > setupMap_p;
00134 
00135   void setIDLists(const Int key, const Int ndx, Vector<Int>& val);
00136 };
00137 
00138 } //# NAMESPACE CASA - END
00139 
00140 #endif