Line data Source code
1 : //# CTDesc.cc: Implementation of CTDesc.h
2 : //# Copyright (C) 2011
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: casa-feedback@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 :
29 : #include <synthesis/CalTables/CTDesc.h>
30 : #include <synthesis/CalTables/CTEnums.h>
31 : #include <casacore/tables/Tables/ScaColDesc.h>
32 : #include <casacore/tables/Tables/ArrColDesc.h>
33 : #include <casacore/tables/Tables/SetupNewTab.h>
34 : #include <casacore/tables/Tables/TableRecord.h>
35 : #include <casacore/measures/TableMeasures/TableMeasRefDesc.h>
36 : #include <casacore/measures/TableMeasures/TableMeasValueDesc.h>
37 : #include <casacore/measures/TableMeasures/TableMeasDesc.h>
38 : #include <casacore/measures/TableMeasures/TableQuantumDesc.h>
39 : #include <casacore/measures/Measures/MEpoch.h>
40 : #include <casacore/measures/Measures/MFrequency.h>
41 : #include <casacore/measures/Measures/MDirection.h>
42 : #include <casacore/casa/Containers/Record.h>
43 : #include <casacore/casa/Arrays/IPosition.h>
44 : #include <stdcasa/version.h>
45 :
46 : using namespace casacore;
47 : namespace casa { //# NAMESPACE CASA - BEGIN
48 :
49 : //----------------------------------------------------------------------------
50 :
51 0 : CTDesc::CTDesc() :
52 0 : addObsId_(true),
53 0 : itsCalMainDesc(defaultCalMain())
54 : {
55 : // Default null constructor for new calibration table description (v1.0)
56 : // Output to private data:
57 : // itsCalMainDesc TableDesc Table descriptor (cal_main)
58 : // itsCalHistoryDesc TableDesc Table descriptor (cal_history)
59 : //
60 0 : };
61 :
62 : //----------------------------------------------------------------------------
63 :
64 6165 : CTDesc::CTDesc(Bool addObsId) :
65 6165 : addObsId_(addObsId),
66 6165 : itsCalMainDesc(defaultCalMain())
67 : {
68 : // Alternative ctor to support OBS_ID opt-out
69 : // Output to private data:
70 : // itsCalMainDesc TableDesc Table descriptor (cal_main)
71 : // itsCalHistoryDesc TableDesc Table descriptor (cal_history)
72 : //
73 6165 : };
74 :
75 : //----------------------------------------------------------------------------
76 :
77 3253 : CTDesc::CTDesc (const String& partype,
78 : const String& msname,
79 : const String& viscal,
80 3253 : const String& polbasis) :
81 3253 : addObsId_(true),
82 3253 : itsCalMainDesc(defaultCalMain(partype,msname,viscal,polbasis))
83 : {
84 : // Constructor for new calibration table description (v1.0)
85 : // Inputs:
86 : // type const String& Cal table type (eg. "P Jones")
87 : // Output to private data:
88 : // itsCalMainDesc TableDesc Table descriptor (cal_main)
89 : // itsCalHistoryDesc TableDesc Table descriptor (cal_history)
90 : //
91 3253 : };
92 :
93 : //----------------------------------------------------------------------------
94 : /***
95 : TableDesc CalTableDesc::defaultCalHistory()
96 : {
97 : // Generate the default table descriptor for the Cal History sub-table
98 : // Output:
99 : // defaultCalHistory TableDesc Default Cal History descriptor
100 : //
101 : TableDesc td ("Cal History", "2.0", TableDesc::Scratch);
102 : td.comment() = "Calibration history sub-table";
103 : td.addColumn (ScalarColumnDesc <String> (NCT::fieldName (NCT::CAL_PARMS),
104 : ColumnDesc::Direct));
105 : td.addColumn (ScalarColumnDesc <String> (NCT::fieldName (NCT::CAL_TABLES),
106 : ColumnDesc::Direct));
107 : td.addColumn (ScalarColumnDesc <String> (NCT::fieldName (NCT::CAL_SELECT),
108 : ColumnDesc::Direct));
109 : td.addColumn (ScalarColumnDesc <String> (NCT::fieldName (NCT::CAL_NOTES),
110 : ColumnDesc::Direct));
111 : return td;
112 : };
113 : ***/
114 : //----------------------------------------------------------------------------
115 :
116 9418 : TableDesc CTDesc::defaultCalMain (const String& partype,
117 : const String& msname,
118 : const String& viscal,
119 : const String& polbasis)
120 : {
121 : // Generate the default table descriptor for the Cal Main sub-table
122 : // Input:
123 : // type const String& Cal table type (eg. "P Jones")
124 : // Output:
125 : // defaultCalMain TableDesc Default Cal Main descriptor
126 : //
127 : // Set up table descriptor and add comment field
128 9418 : TableDesc td (viscal, "1.0", TableDesc::Scratch);
129 9418 : td.comment() = "New calibration table";
130 :
131 : // Define keywords
132 9418 : Record keyWordRec;
133 : // Cal_desc and cal_history indices
134 : // calibration type
135 9418 : keyWordRec.define ("ParType", partype);
136 9418 : keyWordRec.define ("MSName",msname);
137 9418 : keyWordRec.define ("VisCal",viscal);
138 9418 : keyWordRec.define ("PolBasis",polbasis);
139 9418 : keyWordRec.define ("CASA_Version",VersionInfo::str()); // Basic CASA version string
140 : // Add to table descriptor
141 9418 : td.rwKeywordSet().assign (keyWordRec);
142 :
143 : // Cal Main columns (MS Main indices)
144 : // keys
145 9418 : td.addColumn (ScalarColumnDesc <Double> (NCT::fieldName (NCT::TIME),
146 : ColumnDesc::Direct));
147 9418 : td.addColumn (ScalarColumnDesc <Int> (NCT::fieldName (NCT::FIELD_ID),
148 : ColumnDesc::Direct));
149 9418 : td.addColumn (ScalarColumnDesc <Int> (NCT::fieldName (NCT::SPECTRAL_WINDOW_ID),
150 : ColumnDesc::Direct));
151 9418 : td.addColumn (ScalarColumnDesc <Int> (NCT::fieldName (NCT::ANTENNA1),
152 : ColumnDesc::Direct));
153 : // ANTENNA2 is refant (when relevant), or 2nd antenna for baseline-based
154 9418 : td.addColumn (ScalarColumnDesc <Int> (NCT::fieldName (NCT::ANTENNA2),
155 : ColumnDesc::Direct));
156 : //non keys
157 9418 : td.addColumn (ScalarColumnDesc <Double> (NCT::fieldName (NCT::INTERVAL),
158 : ColumnDesc::Direct));
159 9418 : td.addColumn (ScalarColumnDesc <Int> (NCT::fieldName (NCT::SCAN_NUMBER),
160 : ColumnDesc::Direct));
161 :
162 : // We might be opting out of OBS_ID... (usually not)
163 : // (usually not; this is to maintain support for older existing
164 : // cal tables that don't have this column)
165 9418 : if (addObsId_) {
166 3253 : td.addColumn (ScalarColumnDesc <Int> (NCT::fieldName (NCT::OBSERVATION_ID),
167 : ColumnDesc::Direct));
168 : }
169 : //Parameter columns
170 9418 : if (partype=="Complex")
171 3151 : td.addColumn (ArrayColumnDesc <Complex> (NCT::fieldName (NCT::CPARAM)));
172 6267 : else if (partype=="Float")
173 102 : td.addColumn (ArrayColumnDesc <Float> (NCT::fieldName (NCT::FPARAM)));
174 :
175 : // TBD: we should handle improper partype better, but conformant()
176 : // currently requires neither PARAM column in case of default defaultCalMain...
177 : // else
178 : // throw(AipsError("CTDesc(): Unknown ParType requested."));
179 :
180 9418 : td.addColumn (ArrayColumnDesc <Float> (NCT::fieldName (NCT::PARAMERR)));
181 9418 : td.addColumn (ArrayColumnDesc <Bool> (NCT::fieldName (NCT::FLAG)));
182 9418 : td.addColumn (ArrayColumnDesc <Float> (NCT::fieldName (NCT::SNR)));
183 9418 : td.addColumn (ArrayColumnDesc <Float> (NCT::fieldName (NCT::WEIGHT)));
184 :
185 : // Add TableMeasures information for designated Measures/Quanta columns
186 : //
187 : // TIME
188 9418 : TableMeasValueDesc timeMeasVal (td, NCT::fieldName (NCT::TIME));
189 9418 : TableMeasRefDesc timeMeasRef (MEpoch::DEFAULT);
190 9418 : TableMeasDesc<MEpoch> timeMeasCol (timeMeasVal, timeMeasRef);
191 9418 : timeMeasCol.write (td);
192 :
193 : // TIME fix Unit
194 18836 : TableQuantumDesc timeQuantDesc (td, NCT::fieldName (NCT::TIME),
195 18836 : Unit ("s"));
196 9418 : timeQuantDesc.write (td);
197 : // INTERVAL
198 18836 : TableQuantumDesc intervalQuantDesc (td, NCT::fieldName(NCT::INTERVAL),
199 18836 : Unit ("s"));
200 9418 : intervalQuantDesc.write (td);
201 :
202 18836 : return td;
203 9418 : };
204 :
205 : //----------------------------------------------------------------------------
206 :
207 9418 : TableDesc CTDesc::calMainDesc()
208 : {
209 : // Return the main calibration table descriptor
210 : // Output:
211 : // calMainDesc TableDesc Table descriptor (cal_main)
212 : //
213 9418 : return itsCalMainDesc;
214 : };
215 :
216 : //----------------------------------------------------------------------------
217 : /***
218 : TableDesc CTDesc::calHistoryDesc()
219 : {
220 : // Return the calibration history sub-table descriptor
221 : // Output:
222 : // calHistoryDesc TableDesc Table descriptor (cal_history)
223 : //
224 : return itsCalHistoryDesc;
225 : };
226 : ***/
227 : //----------------------------------------------------------------------------
228 :
229 0 : TableDesc CTDesc::insertDesc (const TableDesc& tableDesc,
230 : const TableDesc& insert,
231 : const String& insertAfter)
232 : {
233 : // Insert one table descriptor into another after a specified
234 : // column name.
235 : // Input:
236 : // tableDesc const TableDesc& Input table descriptor
237 : // insert const TableDesc& Table descriptor to be inserted
238 : // insertAfter const String& Column name to insert after
239 : // Output:
240 : // insertDesc TableDesc Output table descriptor
241 : //
242 0 : TableDesc tdout;
243 : ColumnDesc* colDesc;
244 0 : Int ncol = tableDesc.ncolumn();
245 : Int jcol;
246 :
247 : // Loop over the number of columns in the input table descriptor
248 0 : for (jcol = 0; jcol < ncol; jcol++) {
249 0 : colDesc = new ColumnDesc (tableDesc.columnDesc (jcol));
250 :
251 : // Add column to output descriptor
252 0 : tdout.addColumn (*colDesc);
253 :
254 : // Insert second descriptor if appropriate
255 0 : if (colDesc->name() == insertAfter) {
256 0 : tdout.add (insert);
257 : };
258 0 : delete colDesc;
259 : };
260 :
261 0 : return tdout;
262 0 : };
263 :
264 : //----------------------------------------------------------------------------
265 :
266 :
267 : } //# NAMESPACE CASA - END
268 :
|