casacore
MSFieldColumns.h
Go to the documentation of this file.
1 //# MSFieldColumns.h: provides easy access to MSField columns
2 //# Copyright (C) 1996,1999,2000
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 //# $Id$
27 
28 #ifndef MS_MSFIELDCOLUMNS_H
29 #define MS_MSFIELDCOLUMNS_H
30 
31 #include <casacore/casa/aips.h>
32 #include <casacore/measures/Measures/MDirection.h>
33 #include <casacore/measures/Measures/MEpoch.h>
34 #include <casacore/measures/Measures/MCDirection.h>
35 #include <casacore/measures/Measures/MCEpoch.h>
36 #include <casacore/measures/Measures/MRadialVelocity.h>
37 #include <casacore/measures/Measures/MeasComet.h>
38 #include <casacore/measures/TableMeasures/ArrayMeasColumn.h>
39 #include <casacore/measures/TableMeasures/ScalarMeasColumn.h>
40 #include <casacore/measures/TableMeasures/ScalarQuantColumn.h>
41 #include <casacore/tables/Tables/ArrayColumn.h>
42 #include <casacore/tables/Tables/ScalarColumn.h>
43 #include <casacore/casa/BasicSL/String.h>
44 #include <casacore/casa/Containers/SimOrdMap.h>
45 
46 namespace casacore { //# NAMESPACE CASACORE - BEGIN
47 
48 class MVDirection;
49 class MSField;
50 template <class Qtype> class Quantum;
51 template <class T> class Matrix;
52 
53 // <summary>
54 // A class to provide easy access to MSField columns
55 // </summary>
56 
57 // <use visibility=export>
58 
59 // <reviewed reviewer="Bob Garwood" date="1997/02/01" tests="" demos="">
60 // </reviewed>
61 
62 // <prerequisite>
63 // <li> MSField
64 // <li> ArrayColumn
65 // <li> ScalarColumn
66 // </prerequisite>
67 //
68 // <etymology>
69 // ROMSFieldColumns stands for Read-Only MeasurementSet Field Table columns.
70 // </etymology>
71 //
72 // <synopsis>
73 // This class provides read-only access to the columns in the MSField Table.
74 // It does the declaration of all the Scalar and ArrayColumns with the
75 // correct types, so the application programmer doesn't have to
76 // worry about getting those right. There is an access function
77 // for every predefined column. Access to non-predefined columns will still
78 // have to be done with explicit declarations.
79 // See <linkto class=ROMSColumns> ROMSColumns</linkto> for an example.
80 // </synopsis>
81 //
82 // <motivation>
83 // See <linkto class=MSColumns> MSColumns</linkto> for the motivation.
84 // </motivation>
85 
87 {
88 public:
89  // Construct from the supplied Table
90  ROMSFieldColumns(const MSField& msField);
91 
92  // The desctructor does nothing special
94 
95  // Read-only access to required columns
96  // <group>
97  const ROScalarColumn<String>& code() const {return code_p;}
98  const ROArrayColumn<Double>& delayDir() const {return delayDir_p;}
99  const ROArrayMeasColumn<MDirection>& delayDirMeasCol() const
100  {return delayDirMeas_p;}
101  const ROScalarColumn<Bool>& flagRow() const {return flagRow_p;}
102  const ROScalarColumn<String>& name() const {return name_p;}
103  const ROScalarColumn<Int>& numPoly() const {return numPoly_p;}
104  const ROArrayColumn<Double>& phaseDir() const {return phaseDir_p;}
105  const ROArrayMeasColumn<MDirection>& phaseDirMeasCol() const
106  {return phaseDirMeas_p;}
107  const ROArrayColumn<Double>& referenceDir() const {return referenceDir_p;}
108  const ROArrayMeasColumn<MDirection>& referenceDirMeasCol() const
109  {return referenceDirMeas_p;}
110  const ROScalarColumn<Int>& sourceId() const {return sourceId_p;}
111  const ROScalarColumn<Double>& time() const {return time_p;}
112  const ROScalarQuantColumn<Double>& timeQuant() const { return timeQuant_p;}
113  const ROScalarMeasColumn<MEpoch>& timeMeas() const { return timeMeas_p;}
114  // </group>
115 
116  // Read-only access to optional columns
117  // <group>
118  const ROScalarColumn<Int>& ephemerisId() const {return ephemerisId_p;}
119  // </group>
120 
121  // Access to interpolated directions from polynomials or ephemerides,
122  // the default time of zero will return the 0th order element of the polynomial.
123  // or, if there is an ephemeris, the position at the time origin of the ephemeris.
124  //
125  // In addtion to the directions, if there is an ephemeris available,
126  // also the radial velocity and the distance rho can be accessed.
127  //
128  // The method needInterTime returns True if there is a polynomial or ephemeris
129  // connected to this field table row, and an interpolation time value should
130  // be provided.
131  // The method ephemPath returns the absolute path to the ephemeris table connected to
132  // the field table row, an empty string if there is none.
133  // <group>
134  MDirection delayDirMeas(Int row, Double time = 0) const;
135  MDirection phaseDirMeas(Int row, Double time = 0) const;
136  MDirection referenceDirMeas(Int row, Double time = 0) const;
137  MRadialVelocity radVelMeas(Int row, Double time = 0) const;
138  Quantity rho(Int row, Double time = 0) const;
139  Bool needInterTime(Int row) const;
140  String ephemPath(Int row) const;
141 
142  // </group>
143 
144  // Convenience function that returns the number of rows in any of the columns
145  uInt nrow() const {return name_p.nrow();}
146 
147  // returns the last row that has a reference direction, phase direction and
148  // delay direction that match, to within the specified angular separation,
149  // the supplied values. Only matches on rows where the direction is constant
150  // ie., NUM_POLY is 0 and where FLAG_ROW is False. Throws an exception
151  // (AipsError) if the reference frames do not match or if the separation does
152  // not have angular units (when compiled in debug mode). Returns -1 if no
153  // match could be found. If tryRow is positive, then that row is tested to
154  // see if it matches before any others are tested. Setting tryRow to a
155  // positive value greater than the table length will throw an exception
156  // (AipsError), when compiled in debug mode.
157  Int matchDirection(const MDirection& referenceDirection,
158  const MDirection& delayDirection,
159  const MDirection& phaseDirection,
160  const Quantum<Double>& maxSeparation,
161  Int tryRow=-1,
162  Double time=0);
163 
164  // Update the MeasComets objects belonging to this FIELD table.
165  // Needed when the entries in the EPHEMERIS_ID column have changed.
166  void updateMeasComets();
167 
168 
169 protected:
170  //# default constructor creates a object that is not usable. Use the attach
171  //# function correct this.
173 
174  //# attach this object to the supplied table.
175  void attach(const MSField& msField);
176 
177  Int measCometIndex(int row) const;
181 
182  // Extract the direction Measure from the corresponding ephemeris
183  // using the nominal position as an offset.
184  // Note that interTime is assumed to use the same time reference frame
185  // as originEpoch.
186  MDirection extractDirMeas(const MDirection& offsetDir,
187  Int index, Double& interTime,
188  MEpoch originEpoch) const;
189 
190  void getMJDs(Double& originMJD, Double& interMJD,
191  const Double interTime, const MEpoch originEpoch) const;
192 
193 private:
194  //# Make the assignment operator and the copy constructor private to prevent
195  //# any compiler generated one from being used.
198 
199  //# Check if any optional columns exist and if so attach them.
200  //# Initialise the necessary MeasComet objects if the EPHEMERIS_ID column is present.
201  void attachOptionalCols(const MSField& msField);
202 
203  //# Functions which check the supplied values against the relevant column and
204  //# the specified row. The row must have a numpoly value of zero. The mvdir
205  //# argument is a temporary that is passed in to prevent it from being
206  //# created inside these small functions.
207  // <group>
208  Bool matchReferenceDir(uInt row, const MVDirection& dirVal,
209  const Double& sepInRad,
210  MVDirection& mvdir, Double time=0) const;
211  Bool matchDelayDir(uInt row, const MVDirection& dirVal,
212  const Double& sepInRad,
213  MVDirection& mvdir, Double time=0) const;
214  Bool matchPhaseDir(uInt row, const MVDirection& dirVal,
215  const Double& sepInRad,
216  MVDirection& mvdir, Double time=0) const;
217  // </group>
218 
219  //# required columns
220  ROScalarColumn<String> name_p;
221  ROScalarColumn<String> code_p;
222  ROScalarColumn<Double> time_p;
223  ROScalarColumn<Int> numPoly_p;
224  ROArrayColumn<Double> delayDir_p;
225  ROArrayColumn<Double> phaseDir_p;
226  ROArrayColumn<Double> referenceDir_p;
227  ROScalarColumn<Int> sourceId_p;
228  ROScalarColumn<Bool> flagRow_p;
229  //# optional columns
230  ROScalarColumn<Int> ephemerisId_p;
231 
232  //# Access to Measure columns
233  ROScalarMeasColumn<MEpoch> timeMeas_p;
234  ROArrayMeasColumn<MDirection> delayDirMeas_p;
235  ROArrayMeasColumn<MDirection> phaseDirMeas_p;
236  ROArrayMeasColumn<MDirection> referenceDirMeas_p;
237 
238  //# Access to Quantum columns
239  ROScalarQuantColumn<Double> timeQuant_p;
240 };
241 
242 // <summary>
243 // A class to provide easy read-write access to MSField columns
244 // </summary>
245 
246 // <use visibility=export>
247 
248 // <reviewed reviewer="Bob Garwood" date="1997/02/01" tests="" demos="">
249 // </reviewed>
250 
251 // <prerequisite>
252 // <li> MSField
253 // <li> ArrayColumn
254 // <li> ScalarColumn
255 // </prerequisite>
256 //
257 // <etymology>
258 // MSFieldColumns stands for MeasurementSet Field Table columns.
259 // </etymology>
260 //
261 // <synopsis>
262 // This class provides access to the columns in the MSField Table,
263 // it does the declaration of all the Scalar and ArrayColumns with the
264 // correct types, so the application programmer doesn't have to
265 // worry about getting those right. There is an access function
266 // for every predefined column. Access to non-predefined columns will still
267 // have to be done with explicit declarations.
268 // See <linkto class=MSColumns> MSColumns</linkto> for an example.
269 // </synopsis>
270 //
271 // <motivation>
272 // See <linkto class=MSColumns> MSColumns</linkto> for the motivation.
273 // </motivation>
274 
276 {
277 public:
278  // Construct from the supplied Table
279  MSFieldColumns(MSField& msField);
280 
281  // The desctructor does nothing special
282  ~MSFieldColumns();
283 
284  // Read-write access to required columns
285  //
286  // Note that the direction measures with a stored polynomial have Col() added
287  // to their name. They are better accessed via the functions that have the
288  // same name, without the Col suffix, that will do the interpolation for
289  // you. These functions are in the ROMSFieldColumns class.
290  // <group>
294  {return delayDirMeas_p;}
300  {return phaseDirMeas_p;}
303  {return referenceDirMeas_p;}
308  // </group>
309 
310  // Read-write access to optional columns
311  // <group>
313  // </group>
314 
315  // Read-only access to required columns
316  // <group>
317  const ROScalarColumn<String>& code() const {
318  return ROMSFieldColumns::code();}
319  const ROArrayColumn<Double>& delayDir() const {
320  return ROMSFieldColumns::delayDir();}
321  const ROArrayMeasColumn<MDirection>& delayDirMeasCol() const {
323  const ROScalarColumn<Bool>& flagRow() const {
324  return ROMSFieldColumns::flagRow();}
325  const ROScalarColumn<String>& name() const {
326  return ROMSFieldColumns::name();}
327  const ROScalarColumn<Int>& numPoly() const {
328  return ROMSFieldColumns::numPoly();}
329  const ROArrayColumn<Double>& phaseDir() const {
330  return ROMSFieldColumns::phaseDir();}
331  const ROArrayMeasColumn<MDirection>& phaseDirMeasCol() const {
333  const ROArrayColumn<Double>& referenceDir() const {
335  const ROArrayMeasColumn<MDirection>& referenceDirMeasCol() const {
337  const ROScalarColumn<Int>& sourceId() const {
338  return ROMSFieldColumns::sourceId();}
339  const ROScalarColumn<Double>& time() const {
340  return ROMSFieldColumns::time();}
341  const ROScalarQuantColumn<Double>& timeQuant() const {
342  return ROMSFieldColumns::timeQuant();}
343  const ROScalarMeasColumn<MEpoch>& timeMeas() const {
344  return ROMSFieldColumns::timeMeas();}
345  // </group>
346 
347  // Read-only access to optional columns
348  // <group>
349  const ROScalarColumn<Int>& ephemerisId() const {
351  // </group>
352 
353  // Interpolate the direction Measure polynomial
354  static MDirection interpolateDirMeas(const Array<MDirection>& arrDir,
355  Int numPoly, Double interTime,
356  Double timeOrigin);
357 
358 
359  // set the epoch reference type for the TIME column.
360  // <note role=tip>
361  // In principle this function can only be used if the table is empty,
362  // otherwise already written values may thereafter have an incorrect
363  // reference, offset, or unit. However, it is possible that part of the
364  // table gets written before these values are known. In that case the
365  // reference, offset, or units can be set by using a False
366  // <src>tableMustBeEmpty</src> argument.
367  // </note>
368  void setEpochRef(MEpoch::Types ref, Bool tableMustBeEmpty=True);
369 
370  // set the direction reference type for the REFERENCE_DIR, DELAY_DIR &
371  // PHASE_DIR columns. This can only be done when the table has no
372  // rows. Trying to do so at other times will throw an exception.
373  void setDirectionRef(MDirection::Types ref);
374 
375 protected:
376  //# default constructor creates a object that is not usable. Use the attach
377  //# function correct this.
378  MSFieldColumns();
379 
380  //# attach this object to the supplied table.
381  void attach(MSField& msField);
382 
383 private:
384  //# Make the assignment operator and the copy constructor private to prevent
385  //# any compiler generated one from being used.
388 
389  //# Check if any optional columns exist and if so attach them.
390  //# Initialise the necessary MeasComet objects if the EPHEMERIS_ID column is present.
391  void attachOptionalCols(MSField& msField);
392 
393  //# required columns
403  //# optional columns
405 
406  //# Access to Measure columns
411 
412  //# Access to Quantum columns
414 
415 };
416 
417 
418 } //# NAMESPACE CASACORE - END
419 
420 #endif
const ROScalarColumn< Double > & time() const
A Measure: astronomical direction.
Definition: MDirection.h:174
A 1-D Specialization of the Array class.
Definition: ArrayIO.h:45
const ROArrayColumn< Double > & referenceDir() const
ROScalarColumn< String > name_p
int Int
Definition: aipstype.h:47
const ROScalarColumn< String > & name() const
Bool matchPhaseDir(uInt row, const MVDirection &dirVal, const Double &sepInRad, MVDirection &mvdir, Double time=0) const
ScalarColumn< String > & code()
Read-write access to required columns.
ScalarColumn< Bool > flagRow_p
ScalarMeasColumn< MEpoch > & timeMeas()
const ROArrayMeasColumn< MDirection > & delayDirMeasCol() const
ScalarColumn< String > code_p
const ROArrayMeasColumn< MDirection > & phaseDirMeasCol() const
const ROScalarColumn< Int > & sourceId() const
ROScalarColumn< Int > sourceId_p
void getMJDs(Double &originMJD, Double &interMJD, const Double interTime, const MEpoch originEpoch) const
ScalarColumn< Int > ephemerisId_p
const ROScalarColumn< Bool > & flagRow() const
MDirection delayDirMeas(Int row, Double time=0) const
Access to interpolated directions from polynomials or ephemerides, the default time of zero will retu...
A class to provide easy access to MSField columns.
uInt nrow() const
Convenience function that returns the number of rows in any of the columns.
ArrayColumn< Double > phaseDir_p
ROScalarMeasColumn< MEpoch > timeMeas_p
MDirection extractDirMeas(const MDirection &offsetDir, Int index, Double &interTime, MEpoch originEpoch) const
Extract the direction Measure from the corresponding ephemeris using the nominal position as an offse...
const ROScalarColumn< String > & name() const
Bool matchReferenceDir(uInt row, const MVDirection &dirVal, const Double &sepInRad, MVDirection &mvdir, Double time=0) const
ArrayColumn< Double > & referenceDir()
const ROScalarColumn< Int > & numPoly() const
ROScalarColumn< String > code_p
const ROArrayColumn< Double > & referenceDir() const
ScalarColumn< Double > time_p
const ROScalarColumn< Int > & sourceId() const
const ROArrayMeasColumn< MDirection > & referenceDirMeasCol() const
const ROScalarColumn< Double > & time() const
A Measure: radial velocity.
const ROScalarColumn< Int > & ephemerisId() const
Read-only access to optional columns.
Read only access to table array Measure columns.
Definition: MBaseline.h:45
ArrayMeasColumn< MDirection > & delayDirMeasCol()
A Measure: instant in time.
Definition: MEpoch.h:104
String ephemPath(Int row) const
~ROMSFieldColumns()
The desctructor does nothing special.
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition: MDirection.h:188
A class to provide easy read-write access to MSField columns.
ROScalarQuantColumn< Double > timeQuant_p
ScalarColumn< Int > & numPoly()
ScalarQuantColumn< Double > & timeQuant()
MDirection referenceDirMeas(Int row, Double time=0) const
const ROArrayColumn< Double > & phaseDir() const
const ROArrayMeasColumn< MDirection > & delayDirMeasCol() const
Vector< MeasComet * > measCometsV_p
const ROScalarColumn< Int > & ephemerisId() const
Read-only access to optional columns.
ArrayColumn< Double > & phaseDir()
const ROScalarColumn< Int > & numPoly() const
const ROScalarQuantColumn< Double > & timeQuant() const
Int matchDirection(const MDirection &referenceDirection, const MDirection &delayDirection, const MDirection &phaseDirection, const Quantum< Double > &maxSeparation, Int tryRow=-1, Double time=0)
returns the last row that has a reference direction, phase direction and delay direction that match...
ScalarColumn< String > & name()
ScalarColumn< Int > & sourceId()
ROScalarColumn< Int > ephemerisId_p
ScalarColumn< Int > sourceId_p
ROScalarColumn< Int > numPoly_p
double Double
Definition: aipstype.h:52
MRadialVelocity radVelMeas(Int row, Double time=0) const
const ROArrayColumn< Double > & delayDir() const
ROArrayMeasColumn< MDirection > phaseDirMeas_p
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
ROScalarColumn< Double > time_p
const ROArrayMeasColumn< MDirection > & referenceDirMeasCol() const
ArrayMeasColumn< MDirection > & referenceDirMeasCol()
Bool needInterTime(Int row) const
ROArrayColumn< Double > delayDir_p
template <class T, class U> class vector;
Definition: Array.h:169
Quantity rho(Int row, Double time=0) const
A Table intended to hold a MeasurementSet FIELD table.
Definition: MSField.h:78
ArrayColumn< Double > delayDir_p
const ROArrayColumn< Double > & phaseDir() const
void attachOptionalCols(const MSField &msField)
ScalarColumn< Int > & ephemerisId()
Read-write access to optional columns.
ArrayMeasColumn< MDirection > & phaseDirMeasCol()
ArrayMeasColumn< MDirection > referenceDirMeas_p
ROArrayMeasColumn< MDirection > delayDirMeas_p
ROScalarColumn< Bool > flagRow_p
const ROScalarMeasColumn< MEpoch > & timeMeas() const
MDirection phaseDirMeas(Int row, Double time=0) const
ROArrayColumn< Double > referenceDir_p
ScalarColumn< Int > numPoly_p
void updateMeasComets()
Update the MeasComets objects belonging to this FIELD table.
ScalarColumn< Bool > & flagRow()
ScalarQuantColumn< Double > timeQuant_p
ArrayMeasColumn< MDirection > phaseDirMeas_p
const ROScalarColumn< String > & code() const
Read-only access to required columns.
const ROScalarMeasColumn< MEpoch > & timeMeas() const
const ROScalarColumn< String > & code() const
Read-only access to required columns.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
ScalarMeasColumn< MEpoch > timeMeas_p
ROArrayMeasColumn< MDirection > referenceDirMeas_p
Read only access to table scalar Measure columns.
Definition: MBaseline.h:46
Vector of three direction cosines.
Definition: MVDirection.h:106
ArrayColumn< Double > referenceDir_p
void attach(const MSField &msField)
Access to a scalar table column with arbitrary data type.
Definition: CopyRecord.h:47
ArrayColumn< Double > & delayDir()
Types
Types of known MEpochs Caution: The order defines the order in the translation matrix in the MCEpoch...
Definition: MEpoch.h:117
Int measCometIndex(int row) const
const ROArrayColumn< Double > & delayDir() const
ScalarColumn< String > name_p
ArrayMeasColumn< MDirection > delayDirMeas_p
const Bool True
Definition: aipstype.h:40
ROMSFieldColumns & operator=(const ROMSFieldColumns &)
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const ROArrayMeasColumn< MDirection > & phaseDirMeasCol() const
ScalarColumn< Double > & time()
unsigned int uInt
Definition: aipstype.h:48
const ROScalarQuantColumn< Double > & timeQuant() const
ROArrayColumn< Double > phaseDir_p
SimpleOrderedMap< Int, Int > ephIdToMeasComet_p
Bool matchDelayDir(uInt row, const MVDirection &dirVal, const Double &sepInRad, MVDirection &mvdir, Double time=0) const
const ROScalarColumn< Bool > & flagRow() const