00001 //# CTSelection.h: Class to represent a selection on a CASA CalTable 00002 //# Copyright (C) 1996,1997,1998,1999,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$ 00028 00029 #ifndef SYNTHESIS_CTSELECTION_H 00030 #define SYNTHESIS_CTSELECTION_H 00031 00032 #include <casa/aips.h> 00033 #include <casa/BasicSL/String.h> 00034 #include <casa/Arrays/Vector.h> 00035 #include <measures/Measures/MEpoch.h> 00036 #include <measures/Measures/MRadialVelocity.h> 00037 #include <tables/TaQL/ExprNode.h> 00038 #include <ms/MeasurementSets/MeasurementSet.h> 00039 #include <ms/MSSel/MSSelection.h> 00040 #include <casa/Arrays/Matrix.h> 00041 #include <casa/Arrays/Cube.h> 00042 #include <ms/MSSel/MSSelectionError.h> 00043 #include <ms/MSSel/MSSelectionErrorHandler.h> 00044 #include <ms/MSSel/MSSelectableTable.h> 00045 #include <casa/Containers/OrderedMap.h> 00046 #include <casa/Containers/MapIO.h> 00047 #include <synthesis/CalTables/NewCalTable.h> 00048 00049 namespace casa { //# NAMESPACE CASA - BEGIN 00050 00051 // <summary> 00052 // CTSelection: Class to represent a selection on a CASA CalTable 00053 // </summary> 00054 00055 // <use visibility=export> 00056 00057 // <reviewed reviewer="" date="" tests="" demos=""> 00058 00059 // <prerequisite> 00060 // <li> <linkto class="MeasurementSet">MeasurementSet</linkto> module 00061 // </prerequisite> 00062 // 00063 // <etymology> 00064 // From "CalTable" and "selection". 00065 // </etymology> 00066 // 00067 // <synopsis> 00068 // The CTSelection class represents a selection on a CASA CalTable (CT). 00069 // 00070 // The purpose of this class is to provides a simple expression based 00071 // selection mechanism to both the end-user and developer wishing to 00072 // perform query operations over a measurement set. This class is a 00073 // specialization of the CASACORE MSSelection class. The 00074 // specialization this provides is that this workes with CT and uses 00075 // parsers specialization for CT where necessary. For a complete list 00076 // of the STaQL interface refer to the MeasurementSet Selection Syntax 00077 // document at: <a href="http://casa.nrao.edu/other_doc.shtml">Data 00078 // Selection</a> 00079 // 00080 // The sub-expressions are interpreted in the order which they were 00081 // set. The order however in not important - any dependency on the 00082 // order in which the expressions are evaluated is handled internally. 00083 // The result of parsing the expressions is TableExprNode (TEN). All 00084 // TENs from sub-expressions are finally ANDed and the resultant TEN 00085 // is used to select the rows of the MS table. 00086 // 00087 // </synopsis> 00088 // 00089 // <example> 00090 // <srcblock> 00091 // </srcblock> 00092 // </example> 00093 // 00094 // <motivation> 00095 // </motivation> 00096 // 00097 // <todo asof="Aug/14/2009"> 00098 // </todo> 00099 00100 class CTSelection: public MSSelection 00101 { 00102 public: 00103 00104 // Default null constructor, and destructor 00105 CTSelection(); 00106 virtual ~CTSelection(); 00107 00108 TableExprNode toTableExprNode(MSSelectableTable* msLike); 00109 // Construct using an MS and the various selection expressions to 00110 // be applied to the given MS. By default, the expressions will 00111 // be parsed immediately. With mode=PARSE_LATE, the parsing will 00112 // be done with a call to toTableExprNode(). 00113 CTSelection(const NewCalTable& ct, 00114 const MSSMode& mode= PARSE_NOW, 00115 const String& timeExpr="", 00116 const String& antennaExpr="", 00117 const String& fieldExpr="", 00118 const String& spwExpr="", 00119 const String& uvDistExpr="", 00120 const String& taqlExpr="", 00121 const String& polnExpr="", 00122 const String& scanExpr="", 00123 const String& arrayExpr="", 00124 const String& stateExpr="", 00125 const String& observationExpr=""); 00126 00127 // Construct from a record representing a selection item at the 00128 // CLI or user interface level. This is functionally same as the 00129 // constructor above with mode=PARSE_LATE. 00130 CTSelection(const Record& selectionItem); 00131 00132 // Copy constructor 00133 CTSelection(const CTSelection& other); 00134 00135 // Assignment operator 00136 CTSelection& operator=(const CTSelection& other); 00137 00138 // Accessor for result of parsing all of the selection 00139 // expressions. The final TableExprNode (TEN) is the result of 00140 // ANDing the TENs for the individual expressions. 00141 // TableExprNode getTEN(const MeasurementSet*ms = NULL); 00142 00143 // Accessor for the list of antenna-1 of the selected baselines. 00144 // Antennas affected by the baseline negation operator have the 00145 // antenna IDs multiplied by -1. 00146 00147 // // inline Vector<Int> getAntenna1List(const MeasurementSet* ms=NULL) 00148 // // {getTEN(ms); return antenna1IDs_p;} 00149 00150 // // Accessor for the list of antenna-2 of the selected baselines. 00151 // // Antennas affected by the baseline negation operator have the 00152 // // antenna IDs multiplied by -1. 00153 // // inline Vector<Int> getAntenna2List(const MeasurementSet* ms=NULL) 00154 // // {getTEN(ms); return antenna2IDs_p;} 00155 00156 // // inline Matrix<Int> getBaselineList(const MeasurementSet* ms=NULL) 00157 // // {getTEN(ms); return baselineIDs_p;} 00158 00159 // // // Accessor for the list of selected field IDs. 00160 // // inline Vector<Int> getFieldList(const MeasurementSet* ms=NULL) 00161 // // {// if (fieldIDs_p.nelements() <= 0) 00162 // // getTEN(ms); return fieldIDs_p;} 00163 00164 // // // Accessor for the list of the specified time range(s) as the 00165 // // // start and end MJD values. The time ranges are stored as columns, 00166 // // // i.e. the output Matrix is 2 x n_ranges. 00167 // // inline Matrix<Double> getTimeList(const MeasurementSet* ms=NULL) 00168 // // {getTEN(ms); return selectedTimesList_p;} 00169 00170 // // // Accessor for the list of the selected Spectral Window IDs. 00171 // // inline Vector<Int> getSpwList(const MeasurementSet* ms=NULL) 00172 // // {// if (spwIDs_p.nelements() <= 0) 00173 // // getTEN(ms); return spwIDs_p;} 00174 00175 00176 // // Matrix<Int> getChanList(const MeasurementSet* ms=NULL, 00177 // // const Int defaultStep=1, 00178 // // const Bool sorted=False); 00179 00180 // // // 00181 // // // Same as getChanList, except that the channels and steps are in Hz. 00182 // // // 00183 // // Matrix<Double> getChanFreqList(const MeasurementSet* ms=NULL, 00184 // // const Bool sorted=False); 00185 00186 // // // Accessor for the list of the selected Data Description IDs from 00187 // // // the SPW expression parsing. The actual 00188 // // // selected DDIDs would be an intersection of the DDIDs selected 00189 // // // from polarization and SPW expressions parsing (see 00190 // // // getDDIDList() above). 00191 // // inline Vector<Int> getSPWDDIDList(const MeasurementSet* ms=NULL) 00192 // // {if (spwDDIDs_p.nelements() <= 0) getTEN(ms); return spwDDIDs_p;} 00193 00194 // // // 00195 // // // The key in the ordered map returned by getPolMap() is the Data 00196 // // // Description ID (DDID). The value is a vector containing the 00197 // // // list of in-row indices to pick out the selected polarizations 00198 // // // (or equivalently, the list of indices for the vector in the 00199 // // // corrType column of the POLARIZATION sub-table). These are also 00200 // // // what the user intended (i.e., e.g. not all DD IDs due to user 00201 // // // POL expression might be selected due to SPW expressions). 00202 // // // 00203 // // inline OrderedMap<Int, Vector<Int> > getPolMap(const MeasurementSet* ms=NULL) 00204 // // {getTEN(ms); return selectedPolMap_p;}; 00205 00206 // // // 00207 // // // The key in the ordered map returned by getCorrMap() is the 00208 // // // pol. is the Data Description ID (DDID). The value is a set of 00209 // // // two vectors. The first vector is the list of the in-row 00210 // // // indices to pick out the selected polarizations (or 00211 // // // equivalently, the list of indices for the vector in the 00212 // // // corrType column of the POLARIZATION sub-table). 00213 // // // 00214 // // inline OrderedMap<Int, Vector<Vector<Int> > > getCorrMap(const MeasurementSet* ms=NULL) 00215 // // {getTEN(ms); return selectedSetupMap_p;}; 00216 00217 // // // Methods to convert the maps return by getChanList and 00218 // // // getCorrMap to a list of Slice which can be directly used by 00219 // // // Table system for in-row selection of frequency channels and 00220 // // // polarizations. 00221 // // void getChanSlices(Vector<Vector<Slice> >& chanslices, 00222 // // const MeasurementSet* ms=NULL, 00223 // // const Int defaultChanStep=1); 00224 00225 // // void getCorrSlices(Vector<Vector<Slice> >& corrslices, 00226 // // const MeasurementSet* ms=NULL); 00227 00228 // This version of reset() works with generic MSSeletableTable 00229 // object. Accessing the services of the CTSelection module via 00230 // this interface is recommended over the version of reset() that 00231 // uses MeasurementSet. 00232 void reset(MSSelectableTable& msLike, 00233 const MSSMode& mode = PARSE_NOW, 00234 const String& timeExpr = "", 00235 const String& antennaExpr = "", 00236 const String& fieldExpr = "", 00237 const String& spwExpr = "", 00238 const String& uvDistExpr = "", 00239 const String& taqlExpr = "", 00240 const String& polnExpr = "", 00241 const String& scanExpr = "", 00242 const String& arrayExpr = "", 00243 const String& stateExpr = "", 00244 const String& observationExpr = ""); 00245 00246 // // // Set the error handler to be used for reporting errors while 00247 // // // parsing the type of expression give by the first argument. 00248 // // void setErrorHandler(const MSExprType type, MSSelectionErrorHandler* mssEH, 00249 // // const Bool overRide=False); 00250 00251 // // // Initialize the error handler. This is set the error-handler to 00252 // // // the user supplied error handler via setErrorHandler() or to the 00253 // // // default built-in error handler. 00254 // // void initErrorHandler(const MSExprType tye=NO_EXPR); 00255 00256 // // // Execute the handleError() method of the error-handlers. This 00257 // // // is called in the catch code for any exceptions emitted from any 00258 // // // of the parsers. It is also called at the end of the 00259 // // // parsing cycle. 00260 // // void runErrorHandler(); 00261 }; 00262 00263 } //# NAMESPACE CASA - END 00264 00265 #endif 00266 00267