Source
2199
2199
// channel number is already handled).
2200
2200
2201
2201
channelSelectorCache_p->add(newSelector, frameOfReference);
2202
2202
2203
2203
return newSelector;
2204
2204
}
2205
2205
2206
2206
Int
2207
2207
VisibilityIteratorImpl2::getPolarizationId(Int spectralWindowId, Int msId) const
2208
2208
{
2209
-
ThrowIf(msId != this->msId(),
2210
-
String::format("Requested MS number is %d but current is %d", msId,
2211
-
this->msId()));
2212
-
2213
-
const ROScalarColumn<Int> & spwIds =
2214
-
subtableColumns_p->dataDescription().spectralWindowId();
2215
-
2216
-
// This will break if the same spectral window is referenced by two
2217
-
// different data_descrption IDs. Ideally, this whole thing should be
2218
-
// reworked to used DDIDs with spectral window ID only used internally.
2219
-
2220
-
for (uInt i = 0; i < spwIds.nrow(); i++) {
2221
-
if (spwIds(i) == spectralWindowId) {
2222
-
return subtableColumns_p->dataDescription().polarizationId()(i);
2223
-
}
2224
-
}
2209
+
ThrowIf(msId != this->msId(),
2210
+
String::format("Requested MS number is %d but current is %d", msId,
2211
+
this->msId()));
2212
+
2213
+
auto & ddCols = subtableColumns_p->dataDescription();
2214
+
auto nSpw = subtableColumns_p->spectralWindow().nrow();
2215
+
2216
+
// This will break if the same spectral window is referenced by two
2217
+
// different data_descrption IDs. Ideally, this whole thing should be
2218
+
// reworked to used DDIDs with spectral window ID only used internally.
2219
+
2220
+
for (Int iSpw = 0; iSpw < nSpw; iSpw++) {
2221
+
if (iSpw == spectralWindowId) {
2222
+
Int polID = -1;
2223
+
for (Int idd = 0; idd < ddCols.spectralWindowId().nrow(); idd++) {
2224
+
if(ddCols.spectralWindowId()(idd) == iSpw)
2225
+
polID = ddCols.polarizationId()(iSpw);
2226
+
}
2227
+
// If the SPW is not found in the DD return -1, rather than failing.
2228
+
// This can happen for the so-called phantom SPWs. See CAS-11734
2229
+
return polID;
2230
+
}
2231
+
}
2225
2232
2226
-
ThrowIf(true, String::format(
2227
-
"Could not find entry for spectral window id"
2228
-
"%d in data_description in MS #%d", spectralWindowId, msId));
2233
+
ThrowIf(true, String::format(
2234
+
"Could not find entry for spectral window id"
2235
+
"%d in data_description in MS #%d", spectralWindowId, msId));
2229
2236
2230
-
return -1; // Can't get here so make the compiler happy
2237
+
return -1; // Can't get here so make the compiler happy
2231
2238
}
2232
2239
2233
2240
2234
2241
vi::ChannelSelector *
2235
2242
VisibilityIteratorImpl2::makeChannelSelectorC(
2236
-
const FrequencySelection & selectionIn,
2237
-
Double time,
2238
-
Int msId,
2239
-
Int spectralWindowId,
2240
-
Int polarizationId) const
2241
-
{
2242
-
const FrequencySelectionUsingChannels & selection =
2243
-
dynamic_cast<const FrequencySelectionUsingChannels &>(selectionIn);
2244
-
2245
-
if (selection.refinementNeeded()) {
2246
-
auto spwcFetcher =
2247
-
[this, msId]
2248
-
(int spwId, double lowerFrequency, double upperFrequency)
2249
-
{
2250
-
const SpectralWindowChannels & spwChannels =
2251
-
getSpectralWindowChannels(msId, spwId);
2252
-
return spwChannels.getIntersection(
2253
-
lowerFrequency, upperFrequency);
2254
-
};
2255
-
selection.applyRefinement(spwcFetcher);
2256
-
}
2257
-
2258
-
vector<Slice> frequencySlices;
2259
-
2260
-
// Iterate over all of the frequency selections for the specified spectral
2261
-
// window and collect them into a vector of Slice objects.
2262
-
2263
-
for (FrequencySelectionUsingChannels::const_iterator i = selection.begin();
2264
-
i != selection.end();
2265
-
i++) {
2266
-
2267
-
frequencySlices.push_back(i->getSlice());
2268
-
}
2269
-
2270
-
if (frequencySlices.empty()) {
2271
-
2272
-
// And empty selection implies all channels
2273
-
2274
-
Int nChannels =
2275
-
subtableColumns_p->spectralWindow().numChan()(spectralWindowId);
2276
-
frequencySlices.push_back(Slice(0, nChannels, 1));
2277
-
}
2243
+
const FrequencySelection & selectionIn,
2244
+
Double time,
2245
+
Int msId,
2246
+
Int spectralWindowId,
2247
+
Int polarizationId) const
2248
+
{
2249
+
const FrequencySelectionUsingChannels & selection =
2250
+
dynamic_cast<const FrequencySelectionUsingChannels &>(selectionIn);
2251
+
2252
+
if (selection.refinementNeeded())
2253
+
{
2254
+
auto spwcFetcher =
2255
+
[this, msId]
2256
+
(int spwId, double lowerFrequency, double upperFrequency)
2257
+
{
2258
+
const SpectralWindowChannels & spwChannels =
2259
+
getSpectralWindowChannels(msId, spwId);
2260
+
return spwChannels.getIntersection(
2261
+
lowerFrequency, upperFrequency);
2262
+
};
2263
+
selection.applyRefinement(spwcFetcher);
2264
+
}
2278
2265
2279
-
ChannelSlicer slices(2);
2266
+
vector<Slice> frequencySlices;
2280
2267
2281
-
// Install the polarization selections
2268
+
// Iterate over all of the frequency selections for the specified spectral
2269
+
// window and collect them into a vector of Slice objects.
2270
+
for (FrequencySelectionUsingChannels::const_iterator i = selection.begin();
2271
+
i != selection.end(); i++)
2272
+
{
2282
2273
2283
-
Vector<Slice> correlationSlices =
2284
-
selection.getCorrelationSlices(polarizationId);
2285
-
if (correlationSlices.empty()) {
2274
+
frequencySlices.push_back(i->getSlice());
2275
+
}
2286
2276
2287
-
Int nCorrelations =
2288
-
subtableColumns_p->polarization().numCorr().get(polarizationId);
2277
+
if (frequencySlices.empty())
2278
+
{
2279
+
// And empty selection implies all channels
2280
+
Int nChannels =
2281
+
subtableColumns_p->spectralWindow().numChan()(spectralWindowId);
2282
+
frequencySlices.push_back(Slice(0, nChannels, 1));
2283
+
}
2289
2284
2290
-
correlationSlices = Vector<Slice>(1, Slice(0, nCorrelations));
2291
-
}
2285
+
ChannelSlicer slices(2);
2292
2286
2293
-
slices.setSubslicer(0, ChannelSubslicer(correlationSlices));
2287
+
// Install the polarization selections
2288
+
if(polarizationId != -1)
2289
+
{
2290
+
Vector<Slice> correlationSlices =
2291
+
selection.getCorrelationSlices(polarizationId);
2294
2292
2295
-
// Create and install the frequency selections
2293
+
if (correlationSlices.empty())
2294
+
{
2295
+
Int nCorrelations =
2296
+
subtableColumns_p->polarization().numCorr().get(polarizationId);
2297
+
correlationSlices = Vector<Slice>(1, Slice(0, nCorrelations));
2298
+
}
2296
2299
2297
-
ChannelSubslicer frequencyAxis(frequencySlices.size());
2300
+
slices.setSubslicer(0, ChannelSubslicer(correlationSlices));
2298
2301
2299
-
for (Int i = 0; i <(int) frequencySlices.size(); i++) {
2300
-
frequencyAxis.setSlice(i, frequencySlices[i]);
2301
-
}
2302
+
}
2302
2303
2303
-
slices.setSubslicer(1, frequencyAxis);
2304
+
// Create and install the frequency selections
2305
+
ChannelSubslicer frequencyAxis(frequencySlices.size());
2306
+
for (Int i = 0; i <(int) frequencySlices.size(); i++)
2307
+
{
2308
+
frequencyAxis.setSlice(i, frequencySlices[i]);
2309
+
}
2304
2310
2305
-
// Package up the result and return it.
2311
+
slices.setSubslicer(1, frequencyAxis);
2306
2312
2307
-
ChannelSelector *result =
2308
-
new ChannelSelector(time, msId, spectralWindowId, polarizationId,
2309
-
slices);
2313
+
// Package up the result and return it.
2314
+
ChannelSelector *result =
2315
+
new ChannelSelector(time, msId, spectralWindowId, polarizationId,
2316
+
slices);
2310
2317
2311
-
return result;
2318
+
return result;
2312
2319
}
2313
2320
2314
2321
ChannelSelector *
2315
2322
VisibilityIteratorImpl2::makeChannelSelectorF(
2316
2323
const FrequencySelection & selectionIn,
2317
2324
Double time, Int msId, Int spectralWindowId,
2318
2325
Int polarizationId) const
2319
2326
{
2320
2327
// Make a ChannelSelector from a frame-based frequency selection.
2321
2328