Line data Source code
1 : ///# MSTransform.cc: this defines MSTransform
2 : //# Copyright (C) 2000,2001,2002
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 : #include <stdarg.h>
28 : #include <sstream>
29 : #include <iostream>
30 : #include <vector>
31 : #include <casacore/casa/Utilities/Regex.h>
32 : #include <casacore/casa/OS/HostInfo.h>
33 : #include <casacore/casa/Exceptions/Error.h>
34 : #include <mstransform/MSTransform/MSTransform.h>
35 : #include <casacore/casa/stdio.h>
36 : #include <casacore/casa/math.h>
37 :
38 : using namespace casacore;
39 : namespace casa {
40 :
41 :
42 : // -----------------------------------------------------------------------
43 : // Default Constructor
44 : // -----------------------------------------------------------------------
45 1169 : MSTransform::MSTransform () : mdh_p()
46 : {
47 1169 : done();
48 1169 : }
49 :
50 :
51 : // -----------------------------------------------------------------------
52 : // Default Destructor
53 : // -----------------------------------------------------------------------
54 1169 : MSTransform::~MSTransform ()
55 : {
56 1169 : done();
57 1169 : }
58 :
59 : void
60 2338 : MSTransform::done()
61 : {
62 2338 : if(mdh_p){
63 1139 : auto *mdh = mdh_p.release();
64 1139 : delete mdh;
65 : }
66 :
67 : // Default values of parameters
68 2338 : msname_p = "";
69 2338 : outputms_p = "";
70 2338 : spw_p = "";
71 2338 : scan_p = "";
72 2338 : field_p = "";
73 2338 : antenna_p = "";
74 2338 : timerange_p = "";
75 2338 : correlation_p = "";
76 2338 : intent_p = "";
77 2338 : feed_p = "";
78 2338 : array_p = "";
79 2338 : uvrange_p = "";
80 2338 : observation_p = "";
81 :
82 2338 : config_p = Record();
83 2338 : datacolumn_p = "CORRECTED";
84 2338 : isconfigured_p = false;
85 :
86 2338 : return;
87 : }
88 :
89 :
90 :
91 : // ---------------------------------------------------------------------
92 : // MSTransform::configure
93 : // Configure the MSTransformManager and the parameters.
94 : // The config Record is mandatory and needs to have at least
95 : // the parameters for the input and output MSs.
96 : // This method may be called again to add or change parameters.
97 : // ---------------------------------------------------------------------
98 : bool
99 1139 : MSTransform::configure(Record config)
100 : {
101 1139 : log_p.origin(LogOrigin("MSTransform", __func__));
102 :
103 1139 : if (config.empty()){
104 0 : log_p << LogIO::SEVERE << "There is no configuration for the tool"
105 0 : << LogIO::POST;
106 0 : return false;
107 : }
108 :
109 : // First time configuration
110 1139 : if (!isconfigured_p){
111 :
112 : // The minimum configuration is the input and output MS names.
113 1139 : if (config.isDefined("inputms"))
114 1139 : config.get("inputms", msname_p);
115 : else{
116 0 : log_p << LogIO::SEVERE << "There is no \"inputms\" in configuration Record"
117 0 : << LogIO::POST;
118 0 : return false;
119 : }
120 :
121 1139 : if (config.isDefined("outputms"))
122 1139 : config.get("outputms", outputms_p);
123 : else{
124 0 : log_p << LogIO::SEVERE << "There is no \"outputms\" in configuration Record"
125 0 : << LogIO::POST;
126 0 : return false;
127 : }
128 :
129 1139 : if(mdh_p) {
130 0 : auto *mdh = mdh_p.release();
131 0 : delete mdh;
132 : }
133 :
134 : // Create an object for the MSTransformManager
135 1139 : mdh_p = std::unique_ptr<MSTransformManager>(new MSTransformManager());
136 : }
137 :
138 1139 : config_p = config;
139 :
140 : // The datacolumn must exist
141 1139 : if (config_p.isDefined("datacolumn")){
142 1139 : config_p.get("datacolumn", datacolumn_p);
143 1139 : datacolumn_p.upcase();
144 1139 : config_p.define("datacolumn", datacolumn_p);
145 : }
146 : else {
147 : // Add the default column to the Record
148 0 : config_p.define("datacolumn", datacolumn_p);
149 : }
150 :
151 : // Configure the MSTransformManager object
152 1139 : mdh_p->configure(config_p);
153 1139 : isconfigured_p = true;
154 :
155 : // TODO: should I check all the other parameters in the config_p Record?
156 : // Which other parameters should be checked here?
157 :
158 1139 : ostringstream os;
159 1139 : config_p.print(os);
160 1139 : String str(os.str());
161 1139 : log_p << LogIO::DEBUG1 << " Configuration Record " << LogIO::POST;
162 1139 : log_p << LogIO::DEBUG1 << str << LogIO::POST;
163 :
164 1139 : return true;
165 1139 : }
166 :
167 :
168 : // ---------------------------------------------------------------------
169 : // MSTransform::open
170 : // Setup the MSTranformDataHandler and generate the iterators
171 : // It assumes that MSTransform::configure is run first
172 : // ---------------------------------------------------------------------
173 : bool
174 1139 : MSTransform::open()
175 : {
176 :
177 1139 : log_p.origin(LogOrigin("MSTransform", __func__));
178 :
179 1139 : if (! isconfigured_p){
180 0 : log_p << LogIO::SEVERE << "There is no configuration for the tool"
181 0 : << LogIO::POST;
182 0 : return false;
183 : }
184 :
185 1139 : if(!mdh_p){
186 0 : log_p << LogIO::SEVERE << "The tool was not configured" << LogIO::POST;
187 0 : return false;
188 : }
189 :
190 : // Open the MS and select the data
191 1139 : mdh_p->open();
192 :
193 :
194 : // Setup the DataHandler
195 1118 : mdh_p->setup();
196 :
197 1107 : return true;
198 : }
199 :
200 : // ---------------------------------------------------------------------
201 : // MSTransform::run
202 : // Run the tool
203 : // TODO: For the moment it returns a Record, but verify this later
204 : // ---------------------------------------------------------------------
205 : Record
206 1107 : MSTransform::run()
207 : {
208 1107 : log_p.origin(LogOrigin("MSTransform", __func__));
209 :
210 1107 : if (! mdh_p){
211 0 : log_p << LogIO::SEVERE << "The tool is not configured. Please run mt.config and mt.open first."
212 0 : << LogIO::POST;
213 0 : return Record();
214 : }
215 :
216 1107 : vi::VisibilityIterator2 *visIter = mdh_p->getVisIter();
217 1107 : vi::VisBuffer2 *vb = visIter->getVisBuffer();
218 1107 : visIter->originChunks();
219 20579 : while (visIter->moreChunks())
220 : {
221 19472 : visIter->origin();
222 342724 : while (visIter->more())
223 : {
224 323252 : mdh_p->fillOutputMs(vb);
225 323252 : visIter->next();
226 : }
227 :
228 19472 : visIter->nextChunk();
229 : }
230 1107 : Record result;
231 1107 : visIter->result(result);
232 1107 : mdh_p->close();
233 :
234 1107 : return result;
235 1107 : }
236 :
237 : /*
238 : // ---------------------------------------------------------------------
239 : // MSTransform::defaultOptions
240 : // Set the defaults for all the parameters
241 : // Returns a Record with the default of each parameter
242 : // ---------------------------------------------------------------------
243 : Record &
244 : MSTransform::defaultOptions()
245 : {
246 : Record defaults;
247 :
248 : defaults.define("inputms", "");
249 : defaults.define("outputms", "");
250 : defaults.define("createmms", true);
251 : defaults.define("separationaxis", "both");
252 : defaults.define("numsubms", "");
253 : defaults.define("tileshape", "");
254 : defaults.define("spw", "");
255 : defaults.define("scan", "");
256 : defaults.define("antenna", "");
257 : defaults.define("array", "");
258 : defaults.define("correlation", "");
259 : defaults.define("field", "");
260 : defaults.define("timerange", "");
261 : defaults.define("uvrange", "");
262 : defaults.define("state", "");
263 : defaults.define("observation", "");
264 : defaults.define("datacolumn", "CORRECTED");
265 : defaults.define("realmodelcol", false);
266 : defaults.define("combinespws", false);
267 : defaults.define("freqaverage", false);
268 : defaults.define("freqbin", "");
269 : defaults.define("useweights", "");
270 : defaults.define("hanning", false);
271 : defaults.define("regridms", false);
272 : defaults.define("mode", "");
273 : defaults.define("nchan", "");
274 : defaults.define("start", "");
275 : defaults.define("width", "");
276 : defaults.define("interpolation", "");
277 : defaults.define("phasecenter", "");
278 : defaults.define("restfreq", "");
279 : defaults.define("outframe", "");
280 : defaults.define("veltype", "");
281 : defaults.define("separatespws", false);
282 : defaults.define("nspws", "");
283 : defaults.define("timeaverage", false);
284 : defaults.define("timebing", "");
285 : defaults.define("timespan", "");
286 : defaults.define("quantize_c", "");
287 : defaults.define("minbaselines", "");
288 :
289 : return defauts;
290 : }
291 : */
292 :
293 :
294 : // ---------------------------------------------------------------------
295 : // MSTransform::validateDataColumn
296 : // Check if datacolumn is valid
297 : // Return validated datacolumn
298 : // ---------------------------------------------------------------------
299 : /*
300 : String
301 : MSTransform::validateDataColumn(String datacol)
302 : {
303 : String ret = "";
304 : Bool checkcol = false;
305 : datacol.upcase();
306 :
307 : LogIO log_p(LogOrigin("MSTransform", __FUNCTION__, WHERE));
308 :
309 : if (mdh_p->checkIfColumnExists(datacol))
310 : ret = datacol;
311 : else {
312 : // Check if default column exist
313 : if (mdh_p->checkIfColumnExists("CORRECTED"))
314 : ret = "CORRECTED";
315 : }
316 :
317 : return ret;
318 : }
319 : */
320 :
321 :
322 :
323 : } //#end casa namespace
324 :
325 :
|