casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CTSelection.h
Go to the documentation of this file.
1 //# CTSelection.h: Class to represent a selection on a CASA CalTable
2 //# Copyright (C) 1996,1997,1998,1999,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef SYNTHESIS_CTSELECTION_H
30 #define SYNTHESIS_CTSELECTION_H
31 
32 #include <casa/aips.h>
33 #include <ms/MSSel/MSSelection.h>
36 
37 namespace casa { //# NAMESPACE CASA - BEGIN
38 
39 // <summary>
40 // CTSelection: Class to represent a selection on a CASA CalTable
41 // </summary>
42 
43 // <use visibility=export>
44 
45 // <reviewed reviewer="" date="" tests="" demos="">
46 
47 // <prerequisite>
48 // <li> <linkto class="NewCalTable">NewCalTable</linkto> module
49 // <li> <linkto class="casacore::MSSelection">MSSelection</linkto> module
50 // </prerequisite>
51 //
52 // <etymology>
53 // From "CalTable" and "selection".
54 // </etymology>
55 //
56 // <synopsis>
57 // The CTSelection class represents a selection on a CASA CalTable (CT).
58 //
59 // The purpose of this class is to provides a simple expression based
60 // selection mechanism to both the end-user and developer wishing to
61 // perform query operations over a measurement set. This class is a
62 // specialization of the CASACORE casacore::MSSelection class in order to
63 // override the antenna selection to select ANTENNA1 only instead of
64 // baselines, then using MSSelection as usual with the revised antennaExpr
65 // and taqlExpr.
66 //
67 // For a complete list of the STaQL interface refer to the
68 // casacore::MeasurementSet Selection Syntax document at: <a
69 // href="http://casa.nrao.edu/other_doc.shtml">Data Selection</a>
70 //
71 // The sub-expressions are interpreted in the order which they were
72 // set. The order however in not important - any dependency on the
73 // order in which the expressions are evaluated is handled internally.
74 // The result of parsing the expressions is casacore::TableExprNode (TEN).
75 // All TENs from sub-expressions are finally ANDed and the resultant TEN
76 // is used to select the rows of the NewCalTable.
77 //
78 // </synopsis>
79 //
80 // <example>
81 // <srcblock>
82 // </srcblock>
83 // </example>
84 //
85 // <motivation>
86 // </motivation>
87 //
88 // <todo asof="Aug/14/2009">
89 // </todo>
90 
92  {
93  public:
94 
95  // Default null constructor, and destructor
96  CTSelection();
97  virtual ~CTSelection();
98 
99  // Construct using a NewCalTable and the various selection expressions to
100  // be applied to the given CT. By default, the expressions will
101  // be parsed immediately. With mode=PARSE_LATE, the parsing will
102  // be done with a call to toTableExprNode().
103  CTSelection(const NewCalTable& ct,
104  const casacore::MSSelection::MSSMode& mode=
106  const casacore::String& timeExpr="",
107  const casacore::String& antennaExpr="",
108  const casacore::String& fieldExpr="",
109  const casacore::String& spwExpr="",
110  // const String& uvDistExpr="", // not supported
111  const casacore::String& taqlExpr="",
112  //const String& polnExpr="",, // not supported
113  const casacore::String& scanExpr="",
114  //const String& arrayExpr="",i // not supported
115  const casacore::String& stateExpr="",
116  const casacore::String& observationExpr="");
117 
118  // Construct from a record representing a selection item at the
119  // CLI or user interface level. This is functionally same as the
120  // constructor above with mode=PARSE_LATE.
121  CTSelection(const casacore::Record& selectionItem);
122 
123  // Copy constructor
124  CTSelection(const CTSelection& other);
125 
126  // Assignment operator
127  CTSelection& operator=(const CTSelection& other);
128 
131 
133 
134  // clear selections
137  { msSelection_p->clear(type); }
138 
139  // Expression setters. The following set*Expr() methods only set
140  // the expressions. Parsing is done with a call to
141  // toTableExprNode().
142  inline casacore::Bool setFieldExpr(const casacore::String& fieldExpr) {
143  return msSelection_p->setFieldExpr(fieldExpr); }
144  inline casacore::Bool setSpwExpr(const casacore::String& spwExpr) {
145  return msSelection_p->setSpwExpr(spwExpr); }
146  inline casacore::Bool setScanExpr(const casacore::String& scanExpr) {
147  return msSelection_p->setScanExpr(scanExpr); }
148  inline casacore::Bool setTimeExpr(const casacore::String& timeExpr) {
149  return msSelection_p->setTimeExpr(timeExpr); }
150  inline casacore::Bool setStateExpr(const casacore::String& stateExpr) {
151  return msSelection_p->setStateExpr(stateExpr); }
153  const casacore::String& observationExpr) {
154  return msSelection_p->setObservationExpr(observationExpr); }
155  inline casacore::Bool setAntennaExpr(const casacore::String& antennaExpr) {
156  return msSelection_p->setAntennaExpr(antennaExpr); }
157  inline casacore::Bool setTaQLExpr(const casacore::String& taqlExpr) {
158  return msSelection_p->setTaQLExpr(taqlExpr); }
159 
160  // Accessors for items selected:
161 
162  // Accessor for the list of antenna-1 selected.
163  // Antennas affected by the baseline negation operator have the
164  // antenna IDs multiplied by -1.
165  // TBD: does this work with taql?
167  const casacore::MeasurementSet* ms=NULL)
168  { return msSelection_p->getAntenna1List(ms); }
169 
170  // Accessor for the list of antenna-2 of the selected baselines.
171  // Antennas affected by the baseline negation operator have the
172  // antenna IDs multiplied by -1.
174  const casacore::MeasurementSet* ms=NULL)
175  { return msSelection_p->getAntenna2List(ms); }
176 
177  // Accessor for the list of selected field IDs.
179  const casacore::MeasurementSet* ms=NULL)
180  { return msSelection_p->getFieldList(ms); }
181 
182  // Accessor for the list of the specified time range(s) as the
183  // start and end MJD values. The time ranges are stored as columns.
184  // Change 5/21/17: returns [startTime, stopTime, dT] CAS-10142
186  const casacore::MeasurementSet* ms=NULL)
187  { return msSelection_p->getTimeList(ms); }
188 
189  // Accessor for the list of the selected Spectral Window IDs.
191  const casacore::MeasurementSet* ms=NULL)
192  { return msSelection_p->getSpwList(ms); }
193 
194  // Accessor for the list of the selected Observation IDs.
196  const casacore::MeasurementSet* ms=NULL)
197  { return msSelection_p->getObservationList(ms); }
198 
199  // Accessor for the list of the selected Scan IDs.
201  const casacore::MeasurementSet* ms=NULL)
202  { return msSelection_p->getScanList(ms); }
203 
204  // // casacore::Matrix<casacore::Int> getChanList(
205  // // const casacore::MeasurementSet* ms=NULL,
206  // // const casacore::Int defaultStep=1,
207  // // const casacore::Bool sorted=false);
208  // // { return msSelection_p->getChanList(ms, defaultStep, sorted); }
209 
210  // // //
211  // // // Same as getChanList, except that the channels and steps are in Hz.
212  // // //
213  // // casacore::Matrix<casacore::Double> getChanFreqList(
214  // // const casacore::MeasurementSet* ms=NULL,
215  // // const casacore::Bool sorted=false);
216  // // { return msSelection_p->getChanFreqList(ms, sorted); }
217 
218  // This version of reset() works with generic MSSelectableTable
219  // object. Accessing the services of the CTSelection module via
220  // this interface is recommended over the version of reset() that
221  // uses MeasurementSet.
222  void reset(casacore::MSSelectableTable& msLike,
223  const casacore::MSSelection::MSSMode& mode =
225  const casacore::String& timeExpr = "",
226  const casacore::String& antennaExpr = "",
227  const casacore::String& fieldExpr = "",
228  const casacore::String& spwExpr = "",
229  // const String& uvDistExpr = "", // not supported
230  const casacore::String& taqlExpr = "",
231  // const String& polnExpr = "", // not supported
232  const casacore::String& scanExpr = "",
233  // const String& arrayExpr = "", // not supported
234  const casacore::String& stateExpr = "",
235  const casacore::String& observationExpr = "");
236 
237 private:
238 
239  // Resets msSelection_p expressions for antenna selection:
240  // use taqlExpr to select on ANTENNA1 only for antenna selection,
241  // use antennaExpr for baseline selection
242  void doCalAntennaSel(const casacore::String& antennaExpr,
244  // append baseline selection and set taql selection
247 
248  // Reference antenna:
249  // get reference antenna ids from cal table ANTENNA2 column
252  // check if antennaId is a reference antenna
253  bool isRefAntenna(casacore::Int antennaId,
255  // make baseline strings for ref ant with all ref ants
258 
259  // Antenna ID 0:
260  // check if zero is selected (else it is negated but there is no -0)
261  bool zeroIsSelected(casacore::String antennaExpr,
263 
265  };
266 
267 } //# NAMESPACE CASA - END
268 
269 #endif
270 
271 
casacore::Vector< casacore::Int > getAntenna2List(const casacore::MeasurementSet *ms=NULL)
Accessor for the list of antenna-2 of the selected baselines.
Definition: CTSelection.h:173
Vector< Int > getObservationList(const MeasurementSet *ms=NULL)
Accessor for the list of the selected observation IDs.
Definition: MSSelection.h:207
Vector< Int > getScanList(const MeasurementSet *ms=NULL)
Accessor for the list of the selected scan IDs.
Definition: MSSelection.h:203
int Int
Definition: aipstype.h:50
Vector< Int > getAntenna1List(const MeasurementSet *ms=NULL)
Accessor for the list of antenna-1 of the selected baselines.
Definition: MSSelection.h:229
Vector< Int > getFieldList(const MeasurementSet *ms=NULL)
Accessor for the list of selected field IDs.
Definition: MSSelection.h:261
casacore::Bool setStateExpr(const casacore::String &stateExpr)
Definition: CTSelection.h:150
casacore::Vector< casacore::Int > getSpwList(const casacore::MeasurementSet *ms=NULL)
Accessor for the list of the selected Spectral Window IDs.
Definition: CTSelection.h:190
casacore::Vector< casacore::Int > getFieldList(const casacore::MeasurementSet *ms=NULL)
Accessor for the list of selected field IDs.
Definition: CTSelection.h:178
casacore::Vector< casacore::Int > getRefAntIds(casacore::MSSelectableTable *msLike)
Reference antenna: get reference antenna ids from cal table ANTENNA2 column.
Bool setSpwExpr(const String &spwExpr)
void doCalAntennaSel(const casacore::String &antennaExpr, casacore::MSSelectableTable *msLike)
Resets msSelection_p expressions for antenna selection: use taqlExpr to select on ANTENNA1 only for a...
casacore::Vector< casacore::Int > getAntenna1List(const casacore::MeasurementSet *ms=NULL)
Accessors for items selected:
Definition: CTSelection.h:166
Bool setAntennaExpr(const String &antennaExpr)
Expression setters.
casacore::Vector< casacore::Int > getScanList(const casacore::MeasurementSet *ms=NULL)
Accessor for the list of the selected Scan IDs.
Definition: CTSelection.h:200
Handle class for a table column expression tree.
Definition: ExprNode.h:155
virtual Type type()
Return the type enum.
Bool setObservationExpr(const String &observationExpr)
Bool setFieldExpr(const String &fieldExpr)
casacore::Bool setObservationExpr(const casacore::String &observationExpr)
Definition: CTSelection.h:152
CTSelection: Class to represent a selection on a CASA CalTable.
Definition: CTSelection.h:91
casacore::Matrix< casacore::Double > getTimeList(const casacore::MeasurementSet *ms=NULL)
Accessor for the list of the specified time range(s) as the start and end MJD values.
Definition: CTSelection.h:185
TableExprNode getTEN(const MeasurementSet *ms=NULL)
Accessor for result of parsing all of the selection expressions.
casacore::String getRefAntBaselines(casacore::Int antId, casacore::Vector< casacore::Int > refantIds, casacore::String neg)
make baseline strings for ref ant with all ref ants
Bool setTaQLExpr(const String &taqlExpr)
Vector< Int > getAntenna2List(const MeasurementSet *ms=NULL)
Accessor for the list of antenna-2 of the selected baselines.
Definition: MSSelection.h:236
casacore::Vector< casacore::Int > getObservationList(const casacore::MeasurementSet *ms=NULL)
Accessor for the list of the selected Observation IDs.
Definition: CTSelection.h:195
casacore::MSSelection * msSelection_p
Definition: CTSelection.h:264
void clear(const casacore::MSSelection::MSExprType type=casacore::MSSelection::NO_EXPR)
clear selections
Definition: CTSelection.h:135
casacore::Bool setFieldExpr(const casacore::String &fieldExpr)
Expression setters.
Definition: CTSelection.h:142
CTSelection & operator=(const CTSelection &other)
Assignment operator.
casacore::Bool setSpwExpr(const casacore::String &spwExpr)
Definition: CTSelection.h:144
Vector< Int > getSpwList(const MeasurementSet *ms=NULL)
Accessor for the list of the selected Spectral Window IDs.
Definition: MSSelection.h:287
MSSelection: Class to represent a selection on an MS.
Definition: MSSelection.h:118
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Bool setTimeExpr(const casacore::String &timeExpr)
Definition: CTSelection.h:148
casacore::Bool setAntennaExpr(const casacore::String &antennaExpr)
Definition: CTSelection.h:155
Bool setTimeExpr(const String &timeExpr)
Bool setScanExpr(const String &scanExpr)
MSSelectableTable: An interface class used by MSSelection module to access the sub-tables and main-ta...
casacore::Bool setTaQLExpr(const casacore::String &taqlExpr)
Definition: CTSelection.h:157
void reset(casacore::MSSelectableTable &msLike, const casacore::MSSelection::MSSMode &mode=casacore::MSSelection::PARSE_NOW, const casacore::String &timeExpr="", const casacore::String &antennaExpr="", const casacore::String &fieldExpr="", const casacore::String &spwExpr="", const casacore::String &taqlExpr="", const casacore::String &scanExpr="", const casacore::String &stateExpr="", const casacore::String &observationExpr="")
// casacore::Matrix&lt;casacore::Int&gt; getChanList( const casacore::MeasurementSet* ms=NULL, const casacore::Int defaultStep=1, const casacore::Bool sorted=false); { return msSelection_p-&gt;getChanList(ms, defaultStep, sorted); }
virtual ~CTSelection()
A Table intended to hold astronomical data (a set of Measurements).
casacore::TableExprNode getTEN()
Definition: CTSelection.h:132
bool isRefAntenna(casacore::Int antennaId, casacore::Vector< casacore::Int > refantIds)
check if antennaId is a reference antenna
bool zeroIsSelected(casacore::String antennaExpr, casacore::MSSelectableTable *msLike)
Antenna ID 0: check if zero is selected (else it is negated but there is no -0)
Bool setStateExpr(const String &stateExpr)
void clear(const MSExprType type=NO_EXPR)
Clear sub-expression and reset priority.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
CTSelection()
Default null constructor, and destructor.
casacore::TableExprNode toTableExprNode(casacore::MSSelectableTable *msLike)
Matrix< Double > getTimeList(const MeasurementSet *ms=NULL)
Accessor for the list of the specified time range(s) as the start and end MJD values.
Definition: MSSelection.h:272
void setAntennaSelections(casacore::String antsel, casacore::MSSelectableTable *msLike)
append baseline selection and set taql selection
casacore::Bool setScanExpr(const casacore::String &scanExpr)
Definition: CTSelection.h:146