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