LCOV - code coverage report
Current view: top level - flagging/Flagging - FlagDataHandler.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 1302 0.0 %
Date: 2024-10-04 18:58:15 Functions: 0 83 0.0 %

          Line data    Source code
       1             : //# FlagDataHandler.h: This file contains the implementation of the FlagDataHandler class.
       2             : //#
       3             : //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
       4             : //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
       5             : //#  Copyright (C) European Southern Observatory, 2011, All rights reserved.
       6             : //#
       7             : //#  This library is free software; you can redistribute it and/or
       8             : //#  modify it under the terms of the GNU Lesser General Public
       9             : //#  License as published by the Free software Foundation; either
      10             : //#  version 2.1 of the License, or (at your option) any later version.
      11             : //#
      12             : //#  This library is distributed in the hope that it will be useful,
      13             : //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
      14             : //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             : //#  Lesser General Public License for more details.
      16             : //#
      17             : //#  You should have received a copy of the GNU Lesser General Public
      18             : //#  License along with this library; if not, write to the Free Software
      19             : //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      20             : //#  MA 02111-1307  USA
      21             : //# $Id: $
      22             : 
      23             : #include <flagging/Flagging/FlagDataHandler.h>
      24             : 
      25             : #include <casacore/ms/MSSel/MSSelection.h>
      26             : 
      27             : // .casarc (or .casa/rc) interface
      28             : #include <casacore/casa/System/AipsrcValue.h>
      29             : 
      30             : using namespace casacore;
      31             : namespace casa { //# NAMESPACE CASA - BEGIN
      32             : 
      33             : /////////////////////////////////////
      34             : /// FlagDataHandler implementation //
      35             : /////////////////////////////////////
      36             : 
      37             : // -----------------------------------------------------------------------
      38             : // Default constructor
      39             : // -----------------------------------------------------------------------
      40           0 : FlagDataHandler::FlagDataHandler(string tablename, uShort iterationApproach, Double timeInterval):
      41           0 :                 tablename_p(tablename), iterationApproach_p(iterationApproach)
      42             : {
      43             :         // Initialize logger
      44           0 :         logger_p = new LogIO(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
      45             : 
      46             :         // Set time interval
      47           0 :         setTimeInterval(timeInterval);
      48             : 
      49             :         // Deactivate profiling by default
      50           0 :         profiling_p = false;
      51             : 
      52             :         // Disable async I/O by default
      53           0 :         enableAsyncIO(false);
      54             : 
      55             :         // Check if slurp is enabled
      56           0 :         if (!asyncio_enabled_p)
      57             :         {
      58           0 :                 slurp_p = true;
      59           0 :                 AipsrcValue<Bool>::find (slurp_p,"FlagDataHandler.slurp", true);
      60             :         }
      61             :         else
      62             :         {
      63           0 :                 slurp_p = false;
      64             :         }
      65             : 
      66             :         // WARNING: By default the visibility iterator adds the following
      67             :         // default columns: ARRAY_ID and FIELD_ID,DATA_DESC_ID and TIME.
      68             :         // And they are needed for the correct operation of the VisibilityIterator
      69             :         // (it needs to know when any of these changes to be able to give
      70             :         // the correct coordinates with the data). If these columns are not
      71             :         // explicitly sorted on, they will be added BEFORE any others, with
      72             :         // unexpected iteration behaviour
      73             :         // See: MSIter::construct
      74             : 
      75             :         // WARNING: By specifying Time as a sort column we are not producing
      76             :         // chunks with only one time step, but just the other way around!
      77             :         // (all time steps are grouped in the same chunk). This is because TIME
      78             :         // is one of the 'implicit' sort columns, and as explained before it is
      79             :         // added BEFORE the ones specified by the user, resulting in chunks with
      80             :         // only one time step, thus invalidating the time interval effect.
      81             :         // See: MSIter.h
      82             : 
      83             :         // By default we map polarizations because they are needed for the per-chunk logs
      84           0 :         mapPolarizations_p = true;
      85             : 
      86             :         // Antenna pointing map is only needed by the Elevation agent and I have move it there
      87           0 :         mapAntennaPointing_p = false;
      88             : 
      89             :         // These mapping is for the Quack agent, but requires a complete MS iteration, so I put it here,
      90             :         // together with the full swap that I do to pre-compute the amount of memory necessary to run
      91           0 :         mapScanStartStop_p = false;
      92           0 :         mapScanStartStopFlagged_p = false;
      93             : 
      94             :         // Initialize Pre-Load columns
      95           0 :         preLoadColumns_p.clear();
      96           0 :         preLoadColumns_p.push_back(VisBufferComponent2::FieldId);
      97           0 :         preLoadColumns_p.push_back(VisBufferComponent2::SpectralWindows);
      98           0 :         preLoadColumns_p.push_back(VisBufferComponent2::Scan);
      99           0 :         preLoadColumns_p.push_back(VisBufferComponent2::ArrayId);
     100           0 :         preLoadColumns_p.push_back(VisBufferComponent2::ObservationId);
     101             : 
     102           0 :         preLoadColumns_p.push_back(VisBufferComponent2::NRows);
     103           0 :         preLoadColumns_p.push_back(VisBufferComponent2::NChannels);
     104           0 :         preLoadColumns_p.push_back(VisBufferComponent2::NCorrelations);
     105             : 
     106             :         // Set the iteration approach based on the agent
     107           0 :         setIterationApproach(iterationApproach);
     108             : 
     109             :         // Initialize selection ranges
     110           0 :         anySelection_p = false;
     111           0 :         inrowSelection_p = false;
     112           0 :         timeSelection_p = String("");
     113           0 :         baselineSelection_p = String("");
     114           0 :         fieldSelection_p = String("");
     115             :         // NOTE (after Dic 2011 testing): As far as I know spw selection does not have to be *
     116             :         // (can be empty) and in fact applying a spw selection slows down the MSSelection class
     117           0 :         spwSelection_p = String("");
     118           0 :         uvwSelection_p = String("");
     119           0 :         polarizationSelection_p = String("");
     120           0 :         scanSelection_p = String("");
     121           0 :         arraySelection_p = String("");
     122           0 :         observationSelection_p = String("");
     123           0 :         scanIntentSelection_p = String("");
     124             : 
     125             :         // Initialize iteration parameters
     126           0 :         chunksInitialized_p = false;
     127           0 :         buffersInitialized_p = false;
     128           0 :         iteratorGenerated_p = false;
     129           0 :         stopIteration_p = false;
     130           0 :         processedRows_p = 0;
     131           0 :         chunkNo_p = 0;
     132           0 :         bufferNo_p = 0;
     133             : 
     134             :         // Initialize stats
     135           0 :         stats_p = false;
     136           0 :         cubeAccessCounter_p = 0;
     137           0 :         chunkCounts_p = 0;
     138           0 :         progressCounts_p = 0;
     139           0 :         msCounts_p = 0;
     140           0 :         printChunkSummary_p = true;
     141           0 :         summaryThreshold_p = summaryThresholdInc_p;
     142           0 :         chunkLineThreshold_p = chunkLineThresholdInc_p;;
     143             : 
     144             :         // Set all the initialized pointers to NULL
     145           0 :         measurementSetSelection_p = NULL;
     146           0 :         visibilityBuffer_p = NULL;
     147           0 :         antennaNames_p = NULL;
     148           0 :         antennaPositions_p = NULL;
     149           0 :         antennaDiameters_p = NULL;
     150           0 :         antennaPairMap_p = NULL;
     151           0 :         subIntegrationMap_p = NULL;
     152           0 :         corrProducts_p = NULL;
     153           0 :         polarizationMap_p = NULL;
     154           0 :         polarizationIndexMap_p = NULL;
     155           0 :         antennaPointingMap_p = NULL;
     156           0 :         scanStartStopMap_p = NULL;
     157           0 :         lambdaMap_p = NULL;
     158           0 :         fieldNames_p = NULL;
     159             : 
     160             :         // Initialize table characteristics
     161           0 :         tableTye_p = MEASUREMENT_SET;
     162           0 :         processorTableExist_p = true;
     163             : 
     164             :         // Initialize FlagDataHanler-FlagAgents state
     165           0 :         flushFlags_p = false;
     166           0 :         flushFlagRow_p = false;
     167           0 :         loadProcessorTable_p = false;
     168             : 
     169             :         // Initialize time averaging options
     170           0 :     timeAvgOptions_p = vi::AveragingOptions(vi::AveragingOptions::Nothing);
     171           0 :     enableTimeAvg_p = false;
     172           0 :     enableChanAvg_p = false;
     173             : 
     174           0 :         return;
     175           0 : }
     176             : 
     177             : 
     178             : // -----------------------------------------------------------------------
     179             : // Default destructor
     180             : // -----------------------------------------------------------------------
     181           0 : FlagDataHandler::~FlagDataHandler()
     182             : {
     183           0 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     184           0 :         *logger_p << LogIO::DEBUG1 << "FlagDataHandler::~FlagDataHandler()" << LogIO::POST;
     185             : 
     186             :         // Delete logger
     187           0 :         if (logger_p) delete logger_p;
     188             : 
     189             :         // Delete MS objects
     190           0 :         if (measurementSetSelection_p) delete measurementSetSelection_p;
     191             : 
     192             :         // Delete mapping members
     193           0 :         if (antennaNames_p) delete antennaNames_p;
     194           0 :         if (antennaPositions_p) delete antennaPositions_p;
     195           0 :         if (antennaDiameters_p) delete antennaDiameters_p;
     196           0 :         if (antennaPairMap_p) delete antennaPairMap_p;
     197           0 :         if (subIntegrationMap_p) delete subIntegrationMap_p;
     198           0 :         if (corrProducts_p) delete corrProducts_p;
     199           0 :         if (polarizationMap_p) delete polarizationMap_p;
     200           0 :         if (polarizationIndexMap_p) delete polarizationIndexMap_p;
     201           0 :         if (antennaPointingMap_p) delete antennaPointingMap_p;
     202           0 :         if (scanStartStopMap_p) delete scanStartStopMap_p;
     203           0 :         if (lambdaMap_p) delete lambdaMap_p;
     204           0 :         if (fieldNames_p) delete fieldNames_p;
     205             : 
     206           0 :         return;
     207           0 : }
     208             : 
     209             : 
     210             : // -----------------------------------------------------------------------
     211             : // Set iteration Approach
     212             : // -----------------------------------------------------------------------
     213             : void
     214           0 : FlagDataHandler::setIterationApproach(uShort iterationApproach)
     215             : {
     216           0 :         iterationApproach_p = iterationApproach;
     217             : 
     218           0 :         switch (iterationApproach_p)
     219             :         {
     220           0 :                 case COMPLETE_SCAN_MAPPED:
     221             :                 {
     222           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMPLETE_SCAN_MAPPED" << LogIO::POST;
     223           0 :                         sortOrder_p = Block<int>(6);
     224           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     225           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     226           0 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     227           0 :                         sortOrder_p[3] = MS::FIELD_ID;
     228           0 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     229           0 :                         sortOrder_p[5] = MS::TIME;
     230             : 
     231             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     232           0 :                         groupTimeSteps_p = true;
     233           0 :                         mapAntennaPairs_p = true;
     234           0 :                         mapSubIntegrations_p = true;
     235           0 :                         setMapAntennaPairs(true);
     236           0 :                         setMapSubIntegrations(true);
     237           0 :                         break;
     238             :                 }
     239           0 :                 case COMPLETE_SCAN_MAP_SUB_INTEGRATIONS_ONLY:
     240             :                 {
     241           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMPLETE_SCAN_MAP_SUB_INTEGRATIONS_ONLY" << LogIO::POST;
     242           0 :                         sortOrder_p = Block<int>(6);
     243           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     244           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     245           0 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     246           0 :                         sortOrder_p[3] = MS::FIELD_ID;
     247           0 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     248           0 :                         sortOrder_p[5] = MS::TIME;
     249             : 
     250             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     251           0 :                         groupTimeSteps_p = true;
     252           0 :                         mapAntennaPairs_p = false;
     253           0 :                         mapSubIntegrations_p = true;
     254           0 :                         setMapSubIntegrations(true);
     255           0 :                         break;
     256             :                 }
     257           0 :                 case COMPLETE_SCAN_MAP_ANTENNA_PAIRS_ONLY:
     258             :                 {
     259           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMPLETE_SCAN_MAP_ANTENNA_PAIRS_ONLY" << LogIO::POST;
     260           0 :                         sortOrder_p = Block<int>(6);
     261           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     262           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     263           0 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     264           0 :                         sortOrder_p[3] = MS::FIELD_ID;
     265           0 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     266           0 :                         sortOrder_p[5] = MS::TIME;
     267             : 
     268             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     269           0 :                         groupTimeSteps_p = true;
     270           0 :                         mapAntennaPairs_p = true;
     271           0 :                         mapSubIntegrations_p = false;
     272           0 :                         setMapAntennaPairs(true);
     273           0 :                         break;
     274             :                 }
     275           0 :                 case COMPLETE_SCAN_UNMAPPED:
     276             :                 {
     277           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMPLETE_SCAN_UNMAPPED" << LogIO::POST;
     278           0 :                         sortOrder_p = Block<int>(6);
     279           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     280           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     281           0 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     282           0 :                         sortOrder_p[3] = MS::FIELD_ID;
     283           0 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     284           0 :                         sortOrder_p[5] = MS::TIME;
     285             : 
     286             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     287           0 :                         groupTimeSteps_p = true;
     288           0 :                         mapAntennaPairs_p = false;
     289           0 :                         mapSubIntegrations_p = false;
     290           0 :                         break;
     291             :                 }
     292           0 :                 case COMBINE_SCANS_MAPPED:
     293             :                 {
     294           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMBINE_SCANS_MAPPED" << LogIO::POST;
     295           0 :                         sortOrder_p = Block<int>(5);
     296           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     297           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     298           0 :                         sortOrder_p[2] = MS::FIELD_ID;
     299           0 :                         sortOrder_p[3] = MS::DATA_DESC_ID;
     300           0 :                         sortOrder_p[4] = MS::TIME;
     301             : 
     302             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     303           0 :                         groupTimeSteps_p = true;
     304           0 :                         mapAntennaPairs_p = true;
     305           0 :                         mapSubIntegrations_p = true;
     306           0 :                         setMapAntennaPairs(true);
     307           0 :                         setMapSubIntegrations(true);
     308           0 :                         break;
     309             :                 }
     310           0 :                 case COMBINE_SCANS_MAP_SUB_INTEGRATIONS_ONLY:
     311             :                 {
     312           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMBINE_SCANS_MAP_SUB_INTEGRATIONS_ONLY" << LogIO::POST;
     313           0 :                         sortOrder_p = Block<int>(5);
     314           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     315           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     316           0 :                         sortOrder_p[2] = MS::FIELD_ID;
     317           0 :                         sortOrder_p[3] = MS::DATA_DESC_ID;
     318           0 :                         sortOrder_p[4] = MS::TIME;
     319             : 
     320             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     321           0 :                         groupTimeSteps_p = true;
     322           0 :                         mapAntennaPairs_p = false;
     323           0 :                         mapSubIntegrations_p = true;
     324           0 :                         setMapSubIntegrations(true);
     325           0 :                         break;
     326             :                 }
     327           0 :                 case COMBINE_SCANS_MAP_ANTENNA_PAIRS_ONLY:
     328             :                 {
     329           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMBINE_SCANS_MAP_ANTENNA_PAIRS_ONLY" << LogIO::POST;
     330           0 :                         sortOrder_p = Block<int>(5);
     331           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     332           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     333           0 :                         sortOrder_p[2] = MS::FIELD_ID;
     334           0 :                         sortOrder_p[3] = MS::DATA_DESC_ID;
     335           0 :                         sortOrder_p[4] = MS::TIME;
     336             : 
     337             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     338           0 :                         groupTimeSteps_p = true;
     339           0 :                         mapAntennaPairs_p = true;
     340           0 :                         mapSubIntegrations_p = false;
     341           0 :                         setMapAntennaPairs(true);
     342           0 :                         break;
     343             :                 }
     344           0 :                 case COMBINE_SCANS_UNMAPPED:
     345             :                 {
     346           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMBINE_SCANS_UNMAPPED" << LogIO::POST;
     347           0 :                         sortOrder_p = Block<int>(5);
     348           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     349           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     350           0 :                         sortOrder_p[2] = MS::FIELD_ID;
     351           0 :                         sortOrder_p[3] = MS::DATA_DESC_ID;
     352           0 :                         sortOrder_p[4] = MS::TIME;
     353             : 
     354             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     355           0 :                         groupTimeSteps_p = true;
     356           0 :                         mapAntennaPairs_p = false;
     357           0 :                         mapSubIntegrations_p = false;
     358           0 :                         break;
     359             :                 }
     360           0 :                 case ANTENNA_PAIR:
     361             :                 {
     362           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: ANTENNA_PAIR" << LogIO::POST;
     363           0 :                         sortOrder_p = Block<int>(8);
     364           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     365           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     366           0 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     367           0 :                         sortOrder_p[3] = MS::FIELD_ID;
     368           0 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     369             :                         // NOTE: As requested by Urvashi, in this way we produce chunks
     370             :                         // per antenna pair with all the time steps grouped instead
     371             :                         // of chunks with entire integrations for a given time step.
     372           0 :                         sortOrder_p[5] = MS::ANTENNA1;
     373           0 :                         sortOrder_p[6] = MS::ANTENNA2;
     374           0 :                         sortOrder_p[7] = MS::TIME;
     375             : 
     376             :                         // NOTE: groupTimeSteps_p=true groups all time steps together in one buffer.
     377           0 :                         groupTimeSteps_p = true;
     378           0 :                         mapAntennaPairs_p = false;
     379           0 :                         mapSubIntegrations_p = false;
     380           0 :                         break;
     381             :                 }
     382           0 :                 case  SUB_INTEGRATION:
     383             :                 {
     384           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: SUB_INTEGRATION" << LogIO::POST;
     385           0 :                         sortOrder_p = Block<int>(6);
     386           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     387           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     388           0 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     389           0 :                         sortOrder_p[3] = MS::FIELD_ID;
     390           0 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     391           0 :                         sortOrder_p[5] = MS::TIME;
     392             : 
     393             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     394           0 :                         groupTimeSteps_p = false;
     395           0 :                         mapAntennaPairs_p = false;
     396           0 :                         mapSubIntegrations_p = false;
     397           0 :                         break;
     398             :                 }
     399           0 :                 case  ARRAY_FIELD:
     400             :                 {
     401           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: ARRAY_FIELD" << LogIO::POST;
     402           0 :                         sortOrder_p = Block<int>(4);
     403           0 :                         sortOrder_p[0] = MS::ARRAY_ID;
     404           0 :                         sortOrder_p[1] = MS::FIELD_ID;
     405           0 :                         sortOrder_p[2] = MS::DATA_DESC_ID;
     406           0 :                         sortOrder_p[3] = MS::TIME;
     407             : 
     408             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     409           0 :                         groupTimeSteps_p = false;
     410           0 :                         mapAntennaPairs_p = false;
     411           0 :                         mapSubIntegrations_p = false;
     412           0 :                         break;
     413             :                 }
     414           0 :                 default:
     415             :                 {
     416           0 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMPLETE_SCAN_UNMAPPED" << LogIO::POST;
     417           0 :                         sortOrder_p = Block<int>(6);
     418           0 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     419           0 :                         sortOrder_p[1] = MS::ARRAY_ID;
     420           0 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     421           0 :                         sortOrder_p[3] = MS::FIELD_ID;
     422           0 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     423           0 :                         sortOrder_p[5] = MS::TIME;
     424             : 
     425             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     426           0 :                         groupTimeSteps_p = true;
     427           0 :                         mapAntennaPairs_p = false;
     428           0 :                         mapSubIntegrations_p = false;
     429           0 :                         break;
     430             :                 }
     431             :         }
     432             : 
     433             :         // We have changed the iteration approach to the iterators has to be regenerated
     434           0 :         iteratorGenerated_p = false;
     435           0 :         chunksInitialized_p = false;
     436           0 :         buffersInitialized_p = false;
     437           0 :         stopIteration_p = false;
     438             : 
     439           0 :         return;
     440             : }
     441             : 
     442             : // -----------------------------------------------------------------------
     443             : // Mapping functions as requested by Urvashi
     444             : // -----------------------------------------------------------------------
     445             : void
     446           0 : FlagDataHandler::generateAntennaPairMap()
     447             : {
     448           0 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     449             : 
     450             :         // Free previous map and create a new one
     451           0 :         if (antennaPairMap_p) delete antennaPairMap_p;
     452           0 :         antennaPairMap_p = new antennaPairMap();
     453             : 
     454             :         // Retrieve antenna vectors
     455           0 :         Vector<Int> antenna1Vector = visibilityBuffer_p->antenna1();
     456           0 :         Vector<Int> antenna2Vector = visibilityBuffer_p->antenna2();
     457             : 
     458             :         // Fill map
     459             :         Int ant1_i,ant2_i;
     460           0 :         uInt nRows = antenna1Vector.size();
     461           0 :         for (uInt row_idx=0;row_idx<nRows;row_idx++)
     462             :         {
     463           0 :                 ant1_i = antenna1Vector[row_idx];
     464           0 :                 ant2_i = antenna2Vector[row_idx];
     465           0 :                 if (antennaPairMap_p->find(std::make_pair(ant1_i,ant2_i)) == antennaPairMap_p->end())
     466             :                 {
     467           0 :                         std::vector<uInt> newPair;
     468           0 :                         newPair.push_back(row_idx);
     469           0 :                         (*antennaPairMap_p)[std::make_pair(ant1_i,ant2_i)] = newPair;
     470           0 :                 }
     471             :                 else
     472             :                 {
     473           0 :                         (*antennaPairMap_p)[std::make_pair(ant1_i,ant2_i)].push_back(row_idx);
     474             :                 }
     475             :         }
     476           0 :         *logger_p << LogIO::DEBUG1 <<  " " << antennaPairMap_p->size() <<" Antenna pairs found in current buffer" << LogIO::POST;
     477             : 
     478           0 :         return;
     479           0 : }
     480             : 
     481             : 
     482             : void
     483           0 : FlagDataHandler::generateSubIntegrationMap()
     484             : {
     485           0 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     486             : 
     487             :         // Free previous map and create a new one
     488           0 :         if (subIntegrationMap_p) delete subIntegrationMap_p;
     489           0 :         subIntegrationMap_p = new subIntegrationMap();
     490             : 
     491             :         // Retrieve antenna vectors
     492           0 :         Vector<Double> timeVector = visibilityBuffer_p->time();
     493             : 
     494             :         // Fill map
     495           0 :         uInt nRows = timeVector.size();
     496           0 :         for (uInt row_idx=0;row_idx<nRows;row_idx++)
     497             :         {
     498           0 :                 if (subIntegrationMap_p->find(timeVector[row_idx]) == subIntegrationMap_p->end())
     499             :                 {
     500           0 :                         std::vector<uInt> newSubIntegration;
     501           0 :                         newSubIntegration.push_back(row_idx);
     502           0 :                         (*subIntegrationMap_p)[timeVector[row_idx]] = newSubIntegration;
     503           0 :                 }
     504             :                 else
     505             :                 {
     506           0 :                         (*subIntegrationMap_p)[timeVector[row_idx]].push_back(row_idx);
     507             :                 }
     508             :         }
     509           0 :         *logger_p << LogIO::NORMAL <<  " " << subIntegrationMap_p->size() <<" Sub-Integrations (time steps) found in current buffer" << LogIO::POST;
     510             : 
     511           0 :         return;
     512           0 : }
     513             : 
     514             : 
     515             : void
     516           0 : FlagDataHandler::generatePolarizationsMap()
     517             : {
     518           0 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     519             : 
     520             :         // Free previous map and create a new one
     521           0 :         if (polarizationMap_p) delete polarizationMap_p;
     522           0 :         polarizationMap_p = new polarizationMap();
     523           0 :         if (polarizationIndexMap_p) delete polarizationIndexMap_p;
     524           0 :         polarizationIndexMap_p = new polarizationIndexMap();
     525             : 
     526           0 :         uShort pos = 0;
     527           0 :         Vector<Int> corrTypes = visibilityBuffer_p->correlationTypes();
     528             : 
     529           0 :         const auto logprio = logger_p->priority();
     530           0 :         if (logprio <= LogMessage::DEBUG2)
     531           0 :             *logger_p << LogIO::DEBUG2 << " Correlation type: " <<  corrTypes << LogIO::POST;
     532             : 
     533           0 :         for (Vector<Int>::iterator iter = corrTypes.begin(); iter != corrTypes.end();iter++)
     534             :         {
     535           0 :                 switch (*iter)
     536             :                 {
     537           0 :                         case Stokes::I:
     538             :                         {
     539           0 :                             if (logprio <= LogMessage::DEBUG2)
     540           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is I" << LogIO::POST;
     541           0 :                             (*polarizationMap_p)[Stokes::I] = pos;
     542           0 :                             (*polarizationIndexMap_p)[pos] = "I";
     543           0 :                             break;
     544             :                         }
     545           0 :                         case Stokes::Q:
     546             :                         {
     547           0 :                             if (logprio <= LogMessage::DEBUG2)
     548           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is Q" << LogIO::POST;
     549           0 :                             (*polarizationMap_p)[Stokes::Q] = pos;
     550           0 :                             (*polarizationIndexMap_p)[pos] = "Q";
     551           0 :                             break;
     552             :                         }
     553           0 :                         case Stokes::U:
     554             :                         {
     555           0 :                             if (logprio <= LogMessage::DEBUG2)
     556           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is U" << LogIO::POST;
     557           0 :                             (*polarizationMap_p)[Stokes::U] = pos;
     558           0 :                             (*polarizationIndexMap_p)[pos] = "U";
     559           0 :                             break;
     560             :                         }
     561           0 :                         case Stokes::V:
     562             :                         {
     563           0 :                             if (logprio <= LogMessage::DEBUG2)
     564           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is V" << LogIO::POST;
     565           0 :                             (*polarizationMap_p)[Stokes::V] = pos;
     566           0 :                             (*polarizationIndexMap_p)[pos] = "V";
     567           0 :                             break;
     568             :                         }
     569           0 :                         case Stokes::XX:
     570             :                         {
     571           0 :                             if (logprio <= LogMessage::DEBUG2)
     572           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is XX" << LogIO::POST;
     573           0 :                             (*polarizationMap_p)[Stokes::XX] = pos;
     574           0 :                             (*polarizationIndexMap_p)[pos] = "XX";
     575           0 :                             break;
     576             :                         }
     577           0 :                         case Stokes::YY:
     578             :                         {
     579           0 :                             if (logprio <= LogMessage::DEBUG2)
     580           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is YY" << LogIO::POST;
     581           0 :                             (*polarizationMap_p)[Stokes::YY] = pos;
     582           0 :                             (*polarizationIndexMap_p)[pos] = "YY";
     583           0 :                             break;
     584             :                         }
     585           0 :                         case Stokes::XY:
     586             :                         {
     587           0 :                             if (logprio <= LogMessage::DEBUG2)
     588           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is XY" << LogIO::POST;
     589           0 :                             (*polarizationMap_p)[Stokes::XY] = pos;
     590           0 :                             (*polarizationIndexMap_p)[pos] = "XY";
     591           0 :                             break;
     592             :                         }
     593           0 :                         case Stokes::YX:
     594             :                         {
     595           0 :                             if (logprio <= LogMessage::DEBUG2)
     596           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is YX" << LogIO::POST;
     597           0 :                             (*polarizationMap_p)[Stokes::YX] = pos;
     598           0 :                             (*polarizationIndexMap_p)[pos] = "YX";
     599           0 :                             break;
     600             :                         }
     601           0 :                         case Stokes::RR:
     602             :                         {
     603           0 :                             if (logprio <= LogMessage::DEBUG2)
     604           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is RR" << LogIO::POST;
     605           0 :                             (*polarizationMap_p)[Stokes::RR] = pos;
     606           0 :                             (*polarizationIndexMap_p)[pos] = "RR";
     607           0 :                             break;
     608             :                         }
     609           0 :                         case Stokes::LL:
     610             :                         {
     611           0 :                             if (logprio <= LogMessage::DEBUG2)
     612           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is LL" << LogIO::POST;
     613           0 :                             (*polarizationMap_p)[Stokes::LL] = pos;
     614           0 :                             (*polarizationIndexMap_p)[pos] = "LL";
     615           0 :                             break;
     616             :                         }
     617           0 :                         case Stokes::RL:
     618             :                         {
     619           0 :                             if (logprio <= LogMessage::DEBUG2)
     620           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is RL" << LogIO::POST;
     621           0 :                             (*polarizationMap_p)[Stokes::RL] = pos;
     622           0 :                             (*polarizationIndexMap_p)[pos] = "RL";
     623           0 :                             break;
     624             :                         }
     625           0 :                         case Stokes::LR:
     626             :                         {
     627           0 :                             if (logprio <= LogMessage::DEBUG2)
     628           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is LR" << LogIO::POST;
     629           0 :                             (*polarizationMap_p)[Stokes::LR] = pos;
     630           0 :                             (*polarizationIndexMap_p)[pos] = "LR";
     631           0 :                             break;
     632             :                         }
     633           0 :                         case VisMapper::CALSOL1:
     634             :                         {
     635           0 :                             if (logprio <= LogMessage::DEBUG2)
     636           0 :                                 *logger_p << LogIO::DEBUG2 << " Calibration solution 1 found at " << pos << LogIO::POST;
     637           0 :                             (*polarizationMap_p)[VisMapper::CALSOL1] = pos;
     638           0 :                             (*polarizationIndexMap_p)[pos] = "Sol1";
     639           0 :                             break;
     640             :                         }
     641           0 :                         case VisMapper::CALSOL2:
     642             :                         {
     643           0 :                             if (logprio <= LogMessage::DEBUG2)
     644           0 :                                 *logger_p << LogIO::DEBUG2 << " Calibration solution 2 found at " << pos << LogIO::POST;
     645           0 :                             (*polarizationMap_p)[VisMapper::CALSOL2] = pos;
     646           0 :                             (*polarizationIndexMap_p)[pos] = "Sol2";
     647           0 :                             break;
     648             :                         }
     649           0 :                         case VisMapper::CALSOL3:
     650             :                         {
     651           0 :                             if (logprio <= LogMessage::DEBUG2)
     652           0 :                                 *logger_p << LogIO::DEBUG2 << " Calibration solution 3 found at " << pos << LogIO::POST;
     653           0 :                             (*polarizationMap_p)[VisMapper::CALSOL3] = pos;
     654           0 :                             (*polarizationIndexMap_p)[pos] = "Sol3";
     655           0 :                             break;
     656             :                         }
     657           0 :                         case VisMapper::CALSOL4:
     658             :                         {
     659           0 :                             if (logprio <= LogMessage::DEBUG2)
     660           0 :                                 *logger_p << LogIO::DEBUG2 << " Calibration solution 4 found at " << pos << LogIO::POST;
     661           0 :                             (*polarizationMap_p)[VisMapper::CALSOL4] = pos;
     662           0 :                             (*polarizationIndexMap_p)[pos] = "Sol4";
     663           0 :                             break;
     664             :                         }
     665           0 :                         default:
     666             :                         {
     667           0 :                             *logger_p << LogIO::WARN << " The " << pos << " th correlation is unknown: " << *iter << LogIO::POST;
     668           0 :                             break;
     669             :                         }
     670             :                 }
     671           0 :                 pos++;
     672           0 :         }
     673             : 
     674           0 :         if (logprio <= LogMessage::DEBUG2) {
     675           0 :             for (polarizationMap::iterator iter =polarizationMap_p->begin();iter != polarizationMap_p->end();iter++)
     676             :             {
     677           0 :                 *logger_p << LogIO::DEBUG2 << " Polarization map key: " << iter->first << " value: " << iter->second << LogIO::POST;
     678             :             }
     679             :         }
     680           0 : }
     681             : 
     682             : void
     683           0 : FlagDataHandler::generateAntennaPointingMap()
     684             : {
     685           0 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     686             : 
     687             :         // Free previous map and create a new one
     688           0 :         if (antennaPointingMap_p) delete antennaPointingMap_p;
     689           0 :         antennaPointingMap_p = new antennaPointingMap();
     690             : 
     691           0 :         Vector<Double> time = visibilityBuffer_p->time();
     692           0 :         uInt nRows = time.size();
     693           0 :         antennaPointingMap_p->reserve(nRows);
     694           0 :         for (uInt row_i=0;row_i<nRows;row_i++)
     695             :         {
     696           0 :                 Vector<MDirection> azimuth_elevation = visibilityBuffer_p->azel(time[row_i]);
     697           0 :                 Int ant1 = visibilityBuffer_p->antenna1()[row_i];
     698           0 :                 Int ant2 = visibilityBuffer_p->antenna1()[row_i];
     699             : 
     700           0 :             double antenna1_elevation = azimuth_elevation[ant1].getAngle("deg").getValue()[1];
     701           0 :             double antenna2_elevation = azimuth_elevation[ant2].getAngle("deg").getValue()[1];
     702             : 
     703           0 :             vector<Double> item(2);
     704           0 :             item[0] = antenna1_elevation;
     705           0 :             item[1] = antenna2_elevation;
     706           0 :             antennaPointingMap_p->push_back(item);
     707           0 :         }
     708             : 
     709           0 :         *logger_p << LogIO::NORMAL << " Generated antenna pointing map with "
     710           0 :                         << antennaPointingMap_p->size() << " elements" << LogIO::POST;
     711             : 
     712           0 :         return;
     713           0 : }
     714             : 
     715             : 
     716             : // -----------------------------------------------------------------------
     717             : // Generate scan start stop map
     718             : // -----------------------------------------------------------------------
     719             : void
     720           0 : FlagDataHandler::generateScanStartStopMap()
     721             : {
     722           0 :         return;
     723             : }
     724             : 
     725             : 
     726             : // -----------------------------------------------------------------------
     727             : // Set Data Selection parameters
     728             : // -----------------------------------------------------------------------
     729             : bool
     730           0 : FlagDataHandler::setDataSelection(Record record)
     731             : {
     732           0 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     733             : 
     734             :         int exists;
     735             : 
     736           0 :         exists = record.fieldNumber ("array");
     737           0 :         if (exists >= 0)
     738             :         {
     739           0 :                 anySelection_p = true;
     740           0 :                 record.get (record.fieldNumber ("array"), arraySelection_p);
     741             : 
     742           0 :                 if (arraySelection_p.size())
     743             :                 {
     744           0 :                         *logger_p << LogIO::DEBUG1 << " array selection is " << arraySelection_p << LogIO::POST;
     745             :                 }
     746             :         }
     747             :         else
     748             :         {
     749           0 :                 arraySelection_p = String("");
     750           0 :                 *logger_p << LogIO::DEBUG1 << " no array selection" << LogIO::POST;
     751             :         }
     752             : 
     753           0 :         exists = record.fieldNumber ("field");
     754           0 :         if (exists >= 0)
     755             :         {
     756           0 :                 anySelection_p = true;
     757           0 :                 record.get (record.fieldNumber ("field"), fieldSelection_p);
     758             : 
     759           0 :                 if (fieldSelection_p.size())
     760             :                 {
     761           0 :                         *logger_p << LogIO::DEBUG1 << " field selection is " << fieldSelection_p << LogIO::POST;
     762             :                 }
     763             :         }
     764             :         else
     765             :         {
     766           0 :                 fieldSelection_p = String("");
     767           0 :                 *logger_p << LogIO::DEBUG1 << " no field selection" << LogIO::POST;
     768             :         }
     769             : 
     770           0 :         exists = record.fieldNumber ("scan");
     771           0 :         if (exists >= 0)
     772             :         {
     773           0 :                 anySelection_p = true;
     774           0 :                 record.get (record.fieldNumber ("scan"), scanSelection_p);
     775             : 
     776           0 :                 if (scanSelection_p.size())
     777             :                 {
     778           0 :                         *logger_p << LogIO::DEBUG1 << " scan selection is " << scanSelection_p << LogIO::POST;
     779             :                 }
     780             :         }
     781             :         else
     782             :         {
     783           0 :                 scanSelection_p = String("");
     784           0 :                 *logger_p << LogIO::DEBUG1 << " no scan selection" << LogIO::POST;
     785             :         }
     786             : 
     787           0 :         exists = record.fieldNumber ("timerange");
     788           0 :         if (exists >= 0)
     789             :         {
     790           0 :                 anySelection_p = true;
     791           0 :                 record.get (record.fieldNumber ("timerange"), timeSelection_p);
     792             : 
     793           0 :                 if (timeSelection_p.size())
     794             :                 {
     795           0 :                         *logger_p << LogIO::DEBUG1 << " timerange selection is " << timeSelection_p << LogIO::POST;
     796             :                 }
     797             :         }
     798             :         else
     799             :         {
     800           0 :                 timeSelection_p = String("");
     801           0 :                 *logger_p << LogIO::DEBUG1 << " no timerange selection" << LogIO::POST;
     802             :         }
     803             : 
     804           0 :         exists = record.fieldNumber ("spw");
     805           0 :         if (exists >= 0)
     806             :         {
     807           0 :                 anySelection_p = true;
     808           0 :                 record.get (record.fieldNumber ("spw"), spwSelection_p);
     809             : 
     810           0 :                 if (spwSelection_p.size())
     811             :                 {
     812           0 :                         *logger_p << LogIO::DEBUG1 << " spw selection is " << spwSelection_p << LogIO::POST;
     813             :                 }
     814             :         }
     815             :         else
     816             :         {
     817           0 :                 spwSelection_p = String("");
     818           0 :                 *logger_p << LogIO::DEBUG1 << " no spw selection" << LogIO::POST;
     819             :         }
     820             : 
     821           0 :         exists = record.fieldNumber ("antenna");
     822           0 :         if (exists >= 0)
     823             :         {
     824           0 :                 anySelection_p = true;
     825           0 :                 record.get (record.fieldNumber ("antenna"), baselineSelection_p);
     826             : 
     827           0 :                 if (baselineSelection_p.size())
     828             :                 {
     829           0 :                         *logger_p << LogIO::DEBUG1 << " antenna selection is " << baselineSelection_p << LogIO::POST;
     830             :                 }
     831             :         }
     832             :         else
     833             :         {
     834           0 :                 baselineSelection_p = String("");
     835           0 :                 *logger_p << LogIO::DEBUG1 << " no antenna selection" << LogIO::POST;
     836             :         }
     837             : 
     838           0 :         exists = record.fieldNumber ("uvrange");
     839           0 :         if (exists >= 0)
     840             :         {
     841           0 :                 anySelection_p = true;
     842           0 :                 record.get (record.fieldNumber ("uvrange"), uvwSelection_p);
     843             : 
     844           0 :                 if (uvwSelection_p.size())
     845             :                 {
     846           0 :                         *logger_p << LogIO::DEBUG1 << " uvrange selection is " << uvwSelection_p << LogIO::POST;
     847             :                 }
     848             :         }
     849             :         else
     850             :         {
     851           0 :                 uvwSelection_p = String("");
     852           0 :                 *logger_p << LogIO::DEBUG1 << " no uvrange selection" << LogIO::POST;
     853             :         }
     854             : 
     855           0 :         exists = record.fieldNumber ("correlation");
     856           0 :         if (exists >= 0)
     857             :         {
     858           0 :                 anySelection_p = true;
     859           0 :                 record.get (record.fieldNumber ("correlation"), polarizationSelection_p);
     860             : 
     861           0 :                 if (polarizationSelection_p.size())
     862             :                 {
     863           0 :                         *logger_p << LogIO::DEBUG1 << " correlation selection is " << polarizationSelection_p << LogIO::POST;
     864             :                 }
     865             :         }
     866             :         else
     867             :         {
     868           0 :                 polarizationSelection_p = String("");
     869           0 :                 *logger_p << LogIO::DEBUG1 << " no correlation selection" << LogIO::POST;
     870             :         }
     871             : 
     872           0 :         exists = record.fieldNumber ("observation");
     873           0 :         if (exists >= 0)
     874             :         {
     875           0 :                 anySelection_p = true;
     876           0 :                 record.get (record.fieldNumber ("observation"), observationSelection_p);
     877             : 
     878           0 :                 if (observationSelection_p.size())
     879             :                 {
     880           0 :                         *logger_p << LogIO::DEBUG1 << " observation selection is " << observationSelection_p << LogIO::POST;
     881             :                 }
     882             :         }
     883             :         else
     884             :         {
     885           0 :                 observationSelection_p = String("");
     886           0 :                 *logger_p << LogIO::DEBUG1 << " no observation selection" << LogIO::POST;
     887             :         }
     888             : 
     889           0 :         exists = record.fieldNumber ("intent");
     890           0 :         if (exists >= 0)
     891             :         {
     892           0 :                 anySelection_p = true;
     893           0 :                 record.get (record.fieldNumber ("intent"), scanIntentSelection_p);
     894             : 
     895           0 :                 if (scanIntentSelection_p.size())
     896             :                 {
     897           0 :                         *logger_p << LogIO::DEBUG1 << " scan intent selection is " << scanIntentSelection_p << LogIO::POST;
     898             :                 }
     899             :         }
     900             :         else
     901             :         {
     902           0 :                 scanIntentSelection_p = String("");
     903           0 :                 *logger_p << LogIO::DEBUG1 << " no scan intent selection" << LogIO::POST;
     904             :         }
     905             : 
     906           0 :         return true;
     907             : }
     908             : 
     909             : 
     910             : // -----------------------------------------------------------------------
     911             : // Set time interval
     912             : // -----------------------------------------------------------------------
     913             : void
     914           0 : FlagDataHandler::setTimeInterval(Double timeInterval)
     915             : {
     916           0 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     917           0 :         if (timeInterval >= 0)
     918             :         {
     919           0 :                 timeInterval_p = timeInterval;
     920           0 :                 *logger_p << LogIO::DEBUG1 << "Set time interval to " << timeInterval_p << "s"<<LogIO::POST;
     921             :         }
     922             :         else
     923             :         {
     924           0 :                 *logger_p << LogIO::WARN << "Provided time interval is negative: " <<  timeInterval << LogIO::POST;
     925             :         }
     926             : 
     927           0 :         return;
     928             : }
     929             : 
     930             : 
     931             : // -----------------------------------------------------------------------
     932             : // Enable async i/o
     933             : // -----------------------------------------------------------------------
     934             : void
     935           0 : FlagDataHandler::enableAsyncIO(Bool enable)
     936             : {
     937           0 :         if (enable)
     938             :         {
     939             :                 // Check if async i/o is enabled (double check for ROVisibilityIteratorAsync and FlagDataHandler config)
     940           0 :                 asyncio_enabled_p = vi::VisibilityIterator2::isAsynchronousIoEnabled();
     941             : 
     942           0 :                 if (asyncio_enabled_p)
     943             :                 {
     944             :                         // Check Flag Data Handler config
     945           0 :                         Bool tmp = false;
     946           0 :                         Bool foundSetting = AipsrcValue<Bool>::find (tmp,"FlagDataHandler.asyncio", false);
     947           0 :                         tmp = ! foundSetting || tmp; // let global setting rule if no FlagDataHandler setting
     948           0 :                         if (!tmp)
     949             :                         {
     950           0 :                                 asyncio_enabled_p = false;
     951           0 :                                 *logger_p << LogIO::DEBUG1
     952             :                                           << " Asynchronous i/o not enabled for FlagDataHandler."
     953           0 :                                           << LogIO::POST;
     954             :                         }
     955             :                 }
     956             :                 else
     957             :                 {
     958           0 :                         *logger_p << LogIO::DEBUG1
     959             :                                   << " Asynchronous i/o not enabled for FlagDataHandler and CASA in general."
     960           0 :                                   << LogIO::POST;
     961             :                 }
     962             :         }
     963             :         else
     964             :         {
     965           0 :                 asyncio_enabled_p = false;
     966             :         }
     967             : 
     968             : 
     969           0 :         if (!asyncio_enabled_p)
     970             :         {
     971           0 :                 slurp_p = true;
     972           0 :                 AipsrcValue<Bool>::find (slurp_p,"FlagDataHandler.slurp", true);
     973             :         }
     974             :         else
     975             :         {
     976           0 :                 slurp_p = false;
     977             :         }
     978             : 
     979           0 :         return;
     980             : }
     981             : 
     982             : 
     983             : // -----------------------------------------------------------------------
     984             : // Function to handled columns pre-load (to avoid problems with parallelism)
     985             : // -----------------------------------------------------------------------
     986             : void
     987           0 : FlagDataHandler::preLoadColumn(VisBufferComponent2 column)
     988             : {
     989           0 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     990             : 
     991           0 :         if (std::find (preLoadColumns_p.begin(), preLoadColumns_p.end(), column) == preLoadColumns_p.end())
     992             :         {
     993           0 :                 *logger_p << LogIO::DEBUG1 << " Adding column to list: "
     994           0 :                           << VisBufferComponents2::name (column) << LogIO::POST;
     995           0 :                 preLoadColumns_p.push_back(column);
     996             :         }
     997             : 
     998           0 :         return;
     999             : }
    1000             : 
    1001             : 
    1002             : // -----------------------------------------------------------------------
    1003             : // Fill pre-fetch columns
    1004             : // -----------------------------------------------------------------------
    1005             : void
    1006           0 : FlagDataHandler::preFetchColumns()
    1007             : {
    1008           0 :         for (vector<VisBufferComponent2>::iterator iter=preLoadColumns_p.begin();iter!=preLoadColumns_p.end();iter++)
    1009             :         {
    1010           0 :                 switch (*iter)
    1011             :                 {
    1012           0 :                         case VisBufferComponent2::Antenna1:
    1013             :                         {
    1014           0 :                                 if (asyncio_enabled_p)
    1015             :                                 {
    1016           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Antenna1);
    1017             :                                 }
    1018             :                                 else
    1019             :                                 {
    1020           0 :                                         visibilityBuffer_p->antenna1();
    1021             :                                 }
    1022           0 :                                 break;
    1023             :                         }
    1024           0 :                         case VisBufferComponent2::Antenna2:
    1025             :                         {
    1026           0 :                                 if (asyncio_enabled_p)
    1027             :                                 {
    1028           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Antenna2);
    1029             :                                 }
    1030             :                                 else
    1031             :                                 {
    1032           0 :                                         visibilityBuffer_p->antenna2();
    1033             :                                 }
    1034           0 :                                 break;
    1035             :                         }
    1036           0 :                         case VisBufferComponent2::ArrayId:
    1037             :                         {
    1038           0 :                                 if (asyncio_enabled_p)
    1039             :                                 {
    1040           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ArrayId);
    1041             :                                 }
    1042             :                                 else
    1043             :                                 {
    1044           0 :                                         visibilityBuffer_p->arrayId();
    1045             :                                 }
    1046           0 :                                 break;
    1047             :                         }
    1048             :                         /*
    1049             :                         case VisBufferComponent2::Channel:
    1050             :                         {
    1051             :                                 if (asyncio_enabled_p)
    1052             :                                 {
    1053             :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Channel);
    1054             :                                 }
    1055             :                                 else
    1056             :                                 {
    1057             :                                         visibilityBuffer_p->getChannelNumbers(0);
    1058             :                                 }
    1059             :                                 break;
    1060             :                         }
    1061             :                         */
    1062           0 :                         case VisBufferComponent2::JonesC:
    1063             :                         {
    1064           0 :                                 if (asyncio_enabled_p)
    1065             :                                 {
    1066           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::JonesC);
    1067             :                                 }
    1068             :                                 else
    1069             :                                 {
    1070           0 :                                         visibilityBuffer_p->cjones();
    1071             :                                 }
    1072           0 :                                 break;
    1073             :                         }
    1074           0 :                         case VisBufferComponent2::CorrType:
    1075             :                         {
    1076           0 :                                 if (asyncio_enabled_p)
    1077             :                                 {
    1078           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::CorrType);
    1079             :                                 }
    1080             :                                 else
    1081             :                                 {
    1082           0 :                                         visibilityBuffer_p->correlationTypes();
    1083             :                                 }
    1084           0 :                                 break;
    1085             :                         }
    1086           0 :                         case VisBufferComponent2::VisibilityCorrected:
    1087             :                         {
    1088             : //                              if (asyncio_enabled_p)
    1089             : //                              {
    1090             : //                                      prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCorrected);
    1091             : //                              }
    1092             : //                              else
    1093             : //                              {
    1094             : //                                      visibilityBuffer_p->visCorrected ();
    1095             : //                              }
    1096           0 :                                 break;
    1097             :                         }
    1098           0 :                         case VisBufferComponent2::VisibilityCubeCorrected:
    1099             :                         {
    1100           0 :                                 if (asyncio_enabled_p)
    1101             :                                 {
    1102           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeCorrected);
    1103             :                                 }
    1104             :                                 else
    1105             :                                 {
    1106           0 :                                         visibilityBuffer_p->visCubeCorrected();
    1107             :                                 }
    1108           0 :                                 break;
    1109             :                         }
    1110           0 :                         case VisBufferComponent2::Direction1:
    1111             :                         {
    1112           0 :                                 if (asyncio_enabled_p)
    1113             :                                 {
    1114           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Direction1);
    1115             :                                 }
    1116             :                                 else
    1117             :                                 {
    1118           0 :                                         visibilityBuffer_p->direction1();
    1119             :                                 }
    1120           0 :                                 break;
    1121             :                         }
    1122           0 :                         case VisBufferComponent2::Direction2:
    1123             :                         {
    1124           0 :                                 if (asyncio_enabled_p)
    1125             :                                 {
    1126           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Direction2);
    1127             :                                 }
    1128             :                                 else
    1129             :                                 {
    1130           0 :                                         visibilityBuffer_p->direction2();
    1131             :                                 }
    1132           0 :                                 break;
    1133             :                         }
    1134           0 :                         case VisBufferComponent2::Exposure:
    1135             :                         {
    1136           0 :                                 if (asyncio_enabled_p)
    1137             :                                 {
    1138           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Exposure);
    1139             :                                 }
    1140             :                                 else
    1141             :                                 {
    1142           0 :                                         visibilityBuffer_p->exposure();
    1143             :                                 }
    1144           0 :                                 break;
    1145             :                         }
    1146           0 :                         case VisBufferComponent2::Feed1:
    1147             :                         {
    1148           0 :                                 if (asyncio_enabled_p)
    1149             :                                 {
    1150           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Feed1);
    1151             :                                 }
    1152             :                                 else
    1153             :                                 {
    1154           0 :                                         visibilityBuffer_p->feed1();
    1155             :                                 }
    1156           0 :                                 break;
    1157             :                         }
    1158           0 :                         case VisBufferComponent2::FeedPa1:
    1159             :                         {
    1160           0 :                                 if (asyncio_enabled_p)
    1161             :                                 {
    1162           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::FeedPa1);
    1163             :                                 }
    1164             :                                 else
    1165             :                                 {
    1166           0 :                                         visibilityBuffer_p->feedPa1();
    1167             :                                 }
    1168           0 :                                 break;
    1169             :                         }
    1170           0 :                         case VisBufferComponent2::Feed2:
    1171             :                         {
    1172           0 :                                 if (asyncio_enabled_p)
    1173             :                                 {
    1174           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Feed2);
    1175             :                                 }
    1176             :                                 else
    1177             :                                 {
    1178           0 :                                         visibilityBuffer_p->feed2();
    1179             :                                 }
    1180           0 :                                 break;
    1181             :                         }
    1182           0 :                         case VisBufferComponent2::FeedPa2:
    1183             :                         {
    1184           0 :                                 if (asyncio_enabled_p)
    1185             :                                 {
    1186           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::FeedPa2);
    1187             :                                 }
    1188             :                                 else
    1189             :                                 {
    1190           0 :                                         visibilityBuffer_p->feedPa2();
    1191             :                                 }
    1192           0 :                                 break;
    1193             :                         }
    1194           0 :                         case VisBufferComponent2::FieldId:
    1195             :                         {
    1196           0 :                                 if (asyncio_enabled_p)
    1197             :                                 {
    1198           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::FieldId);
    1199             :                                 }
    1200             :                                 else
    1201             :                                 {
    1202           0 :                                         visibilityBuffer_p->fieldId();
    1203             :                                 }
    1204           0 :                                 break;
    1205             :                         }
    1206             : //                      case VisBufferComponent2::Flag:
    1207             : //                      {
    1208             : //                              if (asyncio_enabled_p)
    1209             : //                              {
    1210             : //                                      prefetchColumns_p->operator +=(VisBufferComponent2::Flag);
    1211             : //                              }
    1212             : //                              else
    1213             : //                              {
    1214             : //                                      visibilityBuffer_p->flag();
    1215             : //                              }
    1216             : //                              break;
    1217             : //                      }
    1218           0 :                         case VisBufferComponent2::FlagCategory:
    1219             :                         {
    1220           0 :                                 if (asyncio_enabled_p)
    1221             :                                 {
    1222           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::FlagCategory);
    1223             :                                 }
    1224             :                                 else
    1225             :                                 {
    1226           0 :                                         visibilityBuffer_p->flagCategory();
    1227             :                                 }
    1228           0 :                                 break;
    1229             :                         }
    1230           0 :                         case VisBufferComponent2::FlagCube:
    1231             :                         {
    1232           0 :                                 if (asyncio_enabled_p)
    1233             :                                 {
    1234           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::FlagCube);
    1235             :                                 }
    1236             :                                 else
    1237             :                                 {
    1238           0 :                                         visibilityBuffer_p->flagCube();
    1239             :                                 }
    1240           0 :                                 break;
    1241             :                         }
    1242           0 :                         case VisBufferComponent2::FlagRow:
    1243             :                         {
    1244           0 :                                 if (asyncio_enabled_p)
    1245             :                                 {
    1246           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::FlagRow);
    1247             :                                 }
    1248             :                                 else
    1249             :                                 {
    1250           0 :                                         visibilityBuffer_p->flagRow();
    1251             :                                 }
    1252           0 :                                 break;
    1253             :                         }
    1254             :                         /*
    1255             :                         case VisBufferComponent2::Freq:
    1256             :                         {
    1257             :                                 if (asyncio_enabled_p)
    1258             :                                 {
    1259             :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Freq);
    1260             :                                 }
    1261             :                                 else
    1262             :                                 {
    1263             :                                         visibilityBuffer_p->getFrequencies(0);
    1264             :                                 }
    1265             :                                 break;
    1266             :                         }
    1267             :                         */
    1268           0 :                         case VisBufferComponent2::ImagingWeight:
    1269             :                         {
    1270           0 :                                 if (asyncio_enabled_p)
    1271             :                                 {
    1272           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ImagingWeight);
    1273             :                                 }
    1274             :                                 else
    1275             :                                 {
    1276           0 :                                         visibilityBuffer_p->imagingWeight();
    1277             :                                 }
    1278           0 :                                 break;
    1279             :                         }
    1280           0 :                         case VisBufferComponent2::VisibilityModel:
    1281             :                         {
    1282             : //                              if (asyncio_enabled_p)
    1283             : //                              {
    1284             : //                                      prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityModel);
    1285             : //                              }
    1286             : //                              else
    1287             : //                              {
    1288             : //                                      visibilityBuffer_p->visModel();
    1289             : //                              }
    1290           0 :                                 break;
    1291             :                         }
    1292           0 :                         case VisBufferComponent2::VisibilityCubeModel:
    1293             :                         {
    1294           0 :                                 if (asyncio_enabled_p)
    1295             :                                 {
    1296           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeModel);
    1297             :                                 }
    1298             :                                 else
    1299             :                                 {
    1300           0 :                                         visibilityBuffer_p->visCubeModel();
    1301             :                                 }
    1302           0 :                                 break;
    1303             :                         }
    1304           0 :                         case VisBufferComponent2::NChannels:
    1305             :                         {
    1306           0 :                                 if (asyncio_enabled_p)
    1307             :                                 {
    1308           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NChannels);
    1309             :                                 }
    1310             :                                 else
    1311             :                                 {
    1312           0 :                                         visibilityBuffer_p->nChannels();
    1313             :                                 }
    1314           0 :                                 break;
    1315             :                         }
    1316           0 :                         case VisBufferComponent2::NCorrelations:
    1317             :                         {
    1318           0 :                                 if (asyncio_enabled_p)
    1319             :                                 {
    1320           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NCorrelations);
    1321             :                                 }
    1322             :                                 else
    1323             :                                 {
    1324           0 :                                         visibilityBuffer_p->nCorrelations();
    1325             :                                 }
    1326           0 :                                 break;
    1327             :                         }
    1328           0 :                         case VisBufferComponent2::NRows:
    1329             :                         {
    1330           0 :                                 if (asyncio_enabled_p)
    1331             :                                 {
    1332           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NRows);
    1333             :                                 }
    1334             :                                 else
    1335             :                                 {
    1336           0 :                                         visibilityBuffer_p->nRows();
    1337             :                                 }
    1338           0 :                                 break;
    1339             :                         }
    1340           0 :                         case VisBufferComponent2::ObservationId:
    1341             :                         {
    1342           0 :                                 if (asyncio_enabled_p)
    1343             :                                 {
    1344           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ObservationId);
    1345             :                                 }
    1346             :                                 else
    1347             :                                 {
    1348           0 :                                         visibilityBuffer_p->observationId();
    1349             :                                 }
    1350           0 :                                 break;
    1351             :                         }
    1352           0 :                         case VisBufferComponent2::VisibilityObserved:
    1353             :                         {
    1354             : //                              if (asyncio_enabled_p)
    1355             : //                              {
    1356             : //                                      prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityObserved);
    1357             : //                              }
    1358             : //                              else
    1359             : //                              {
    1360             : //                                      visibilityBuffer_p->vis();
    1361             : //                              }
    1362           0 :                                 break;
    1363             :                         }
    1364           0 :                         case VisBufferComponent2::VisibilityCubeObserved:
    1365             :                         {
    1366           0 :                                 if (asyncio_enabled_p)
    1367             :                                 {
    1368           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeObserved);
    1369             :                                 }
    1370             :                                 else
    1371             :                                 {
    1372           0 :                                         visibilityBuffer_p->visCube();
    1373             :                                 }
    1374           0 :                                 break;
    1375             :                         }
    1376           0 :                         case VisBufferComponent2::PhaseCenter:
    1377             :                         {
    1378           0 :                                 if (asyncio_enabled_p)
    1379             :                                 {
    1380           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::PhaseCenter);
    1381             :                                 }
    1382             :                                 else
    1383             :                                 {
    1384           0 :                                         visibilityBuffer_p->phaseCenter();
    1385             :                                 }
    1386           0 :                                 break;
    1387             :                         }
    1388           0 :                         case VisBufferComponent2::PolFrame:
    1389             :                         {
    1390           0 :                                 if (asyncio_enabled_p)
    1391             :                                 {
    1392           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::PolFrame);
    1393             :                                 }
    1394             :                                 else
    1395             :                                 {
    1396           0 :                                         visibilityBuffer_p->polarizationFrame();
    1397             :                                 }
    1398           0 :                                 break;
    1399             :                         }
    1400           0 :                         case VisBufferComponent2::ProcessorId:
    1401             :                         {
    1402           0 :                                 if (asyncio_enabled_p)
    1403             :                                 {
    1404           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ProcessorId);
    1405             :                                 }
    1406             :                                 else
    1407             :                                 {
    1408           0 :                                         visibilityBuffer_p->processorId();
    1409             :                                 }
    1410           0 :                                 break;
    1411             :                         }
    1412           0 :                         case VisBufferComponent2::Scan:
    1413             :                         {
    1414           0 :                                 if (asyncio_enabled_p)
    1415             :                                 {
    1416           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Scan);
    1417             :                                 }
    1418             :                                 else
    1419             :                                 {
    1420           0 :                                         visibilityBuffer_p->scan();
    1421             :                                 }
    1422           0 :                                 break;
    1423             :                         }
    1424           0 :                         case VisBufferComponent2::Sigma:
    1425             :                         {
    1426           0 :                                 if (asyncio_enabled_p)
    1427             :                                 {
    1428           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Sigma);
    1429             :                                 }
    1430             :                                 else
    1431             :                                 {
    1432           0 :                                         visibilityBuffer_p->sigma();
    1433             :                                 }
    1434           0 :                                 break;
    1435             :                         }
    1436             : //                      case VisBufferComponent2::SigmaMat:
    1437             : //                      {
    1438             : //                              if (asyncio_enabled_p)
    1439             : //                              {
    1440             : //                                      prefetchColumns_p->operator +=(VisBufferComponent2::SigmaMat);
    1441             : //                              }
    1442             : //                              else
    1443             : //                              {
    1444             : //                                      visibilityBuffer_p->sigmaMat();
    1445             : //                              }
    1446             : //                              break;
    1447             : //                      }
    1448           0 :                         case VisBufferComponent2::SpectralWindows:
    1449             :                         {
    1450           0 :                                 if (asyncio_enabled_p)
    1451             :                                 {
    1452           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::SpectralWindows);
    1453             :                                 }
    1454             :                                 else
    1455             :                                 {
    1456           0 :                                         visibilityBuffer_p->spectralWindows();
    1457             :                                 }
    1458           0 :                                 break;
    1459             :                         }
    1460           0 :                         case VisBufferComponent2::StateId:
    1461             :                         {
    1462           0 :                                 if (asyncio_enabled_p)
    1463             :                                 {
    1464           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::StateId);
    1465             :                                 }
    1466             :                                 else
    1467             :                                 {
    1468           0 :                                         visibilityBuffer_p->stateId();
    1469             :                                 }
    1470           0 :                                 break;
    1471             :                         }
    1472           0 :                         case VisBufferComponent2::Time:
    1473             :                         {
    1474           0 :                                 if (asyncio_enabled_p)
    1475             :                                 {
    1476           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Time);
    1477             :                                 }
    1478             :                                 else
    1479             :                                 {
    1480           0 :                                         visibilityBuffer_p->time();
    1481             :                                 }
    1482           0 :                                 break;
    1483             :                         }
    1484           0 :                         case VisBufferComponent2::TimeCentroid:
    1485             :                         {
    1486           0 :                                 if (asyncio_enabled_p)
    1487             :                                 {
    1488           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::TimeCentroid);
    1489             :                                 }
    1490             :                                 else
    1491             :                                 {
    1492           0 :                                         visibilityBuffer_p->timeCentroid();
    1493             :                                 }
    1494           0 :                                 break;
    1495             :                         }
    1496           0 :                         case VisBufferComponent2::TimeInterval:
    1497             :                         {
    1498           0 :                                 if (asyncio_enabled_p)
    1499             :                                 {
    1500           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::TimeInterval);
    1501             :                                 }
    1502             :                                 else
    1503             :                                 {
    1504           0 :                                         visibilityBuffer_p->timeInterval();
    1505             :                                 }
    1506           0 :                                 break;
    1507             :                         }
    1508           0 :                         case VisBufferComponent2::Weight:
    1509             :                         {
    1510           0 :                                 if (asyncio_enabled_p)
    1511             :                                 {
    1512           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Weight);
    1513             :                                 }
    1514             :                                 else
    1515             :                                 {
    1516           0 :                                         visibilityBuffer_p->weight();
    1517             :                                 }
    1518           0 :                                 break;
    1519             :                         }
    1520             : //                      case VisBufferComponent2::WeightMat:
    1521             : //                      {
    1522             : //                              if (asyncio_enabled_p)
    1523             : //                              {
    1524             : //                                      prefetchColumns_p->operator +=(VisBufferComponent2::WeightMat);
    1525             : //                              }
    1526             : //                              else
    1527             : //                              {
    1528             : //                                      visibilityBuffer_p->weightMat();
    1529             : //                              }
    1530             : //                              break;
    1531             : //                      }
    1532           0 :                         case VisBufferComponent2::WeightSpectrum:
    1533             :                         {
    1534           0 :                                 if (asyncio_enabled_p)
    1535             :                                 {
    1536           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::WeightSpectrum);
    1537             :                                 }
    1538             :                                 else
    1539             :                                 {
    1540           0 :                                         visibilityBuffer_p->weightSpectrum();
    1541             :                                 }
    1542           0 :                                 break;
    1543             :                         }
    1544           0 :                         case VisBufferComponent2::Uvw:
    1545             :                         {
    1546           0 :                                 if (asyncio_enabled_p)
    1547             :                                 {
    1548           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Uvw);
    1549             :                                 }
    1550             :                                 else
    1551             :                                 {
    1552           0 :                                         visibilityBuffer_p->uvw();
    1553             :                                 }
    1554           0 :                                 break;
    1555             :                         }
    1556             :                         /*
    1557             :                         case VisBufferComponent2::UvwMat:
    1558             :                         {
    1559             :                                 if (asyncio_enabled_p)
    1560             :                                 {
    1561             :                                         prefetchColumns_p + VisBufferComponent2::UvwMat;
    1562             :                                 }
    1563             :                                 else
    1564             :                                 {
    1565             :                                         visibilityBuffer_p->uvwMat();
    1566             :                                 }
    1567             :                                 break;
    1568             :                         }
    1569             :                         */
    1570           0 :                         case VisBufferComponent2::AllBeamOffsetsZero:
    1571             :                         case VisBufferComponent2::AntennaMounts:
    1572             :                         case VisBufferComponent2::BeamOffsets:
    1573             :                         case VisBufferComponent2::DataDescriptionIds:
    1574             :                         case VisBufferComponent2::FloatData:
    1575             :                         case VisBufferComponent2::Frequencies:
    1576             :                         case VisBufferComponent2::NAntennas:
    1577             :                         case VisBufferComponent2::N_VisBufferComponents2:
    1578             :                         case VisBufferComponent2::PolarizationId:
    1579             :                         case VisBufferComponent2::ReceptorAngles:
    1580             :                         case VisBufferComponent2::RowIds:
    1581             :                         case VisBufferComponent2::SigmaSpectrum:
    1582             :                         case VisBufferComponent2::Unknown:
    1583             :                         case VisBufferComponent2::VisibilityCubeFloat:
    1584             :                         case VisBufferComponent2::WeightScaled:
    1585             :                         case VisBufferComponent2::WeightSpectrumScaled:
    1586             :             case VisBufferComponent2::Sigmas:
    1587             :             case VisBufferComponent2::SigmaSpectra:
    1588             :             case VisBufferComponent2::NRowsPerShape:
    1589             :             case VisBufferComponent2::NShapes:
    1590             :             case VisBufferComponent2::VisibilityCubesCorrected:
    1591             :             case VisBufferComponent2::NCorrelationsPerShape:
    1592             :             case VisBufferComponent2::WeightSpectra:
    1593             :             case VisBufferComponent2::NChannelsPerShape:
    1594             :             case VisBufferComponent2::VisibilityCubesObserved:
    1595             :             case VisBufferComponent2::VisibilityCubesModel:
    1596             :             case VisBufferComponent2::VisibilityCubesFloat:
    1597             :             case VisBufferComponent2::Weights:
    1598             :             case VisBufferComponent2::FlagCubes:
    1599             : 
    1600           0 :                             break; // nothing for these right now
    1601             :                 }
    1602             :         }
    1603             : 
    1604           0 :         return;
    1605             : }
    1606             : 
    1607             : 
    1608             : // -----------------------------------------------------------------------
    1609             : // Methods to trigger generation of different maps
    1610             : // -----------------------------------------------------------------------
    1611             : void
    1612           0 : FlagDataHandler::setMapAntennaPairs(bool activated)
    1613             : {
    1614           0 :         mapAntennaPairs_p=activated;
    1615             :         // Pre-Load antenna1, antenna2
    1616           0 :         preLoadColumn(VisBufferComponent2::Antenna1);
    1617           0 :         preLoadColumn(VisBufferComponent2::Antenna2);
    1618           0 : }
    1619             : 
    1620             : 
    1621             : void
    1622           0 : FlagDataHandler::setMapSubIntegrations(bool activated)
    1623             : {
    1624           0 :         mapSubIntegrations_p=activated;
    1625             :         // Pre-Load time
    1626           0 :         preLoadColumn(VisBufferComponent2::Time);
    1627           0 : }
    1628             : 
    1629             : 
    1630             : void
    1631           0 : FlagDataHandler::setMapPolarizations(bool activated)
    1632             : {
    1633           0 :         mapPolarizations_p=activated;
    1634             :         // Pre-Load corrType
    1635           0 :         preLoadColumn(VisBufferComponent2::CorrType);
    1636           0 : }
    1637             : 
    1638             : 
    1639             : void
    1640           0 : FlagDataHandler::setMapAntennaPointing(bool /*activated*/)
    1641             : {
    1642             :         // Antenna Pointing mapping is now done by the first
    1643             :         // Elevation agent, and stored as static variable
    1644             :         // mapAntennaPointing_p=activated;
    1645             : 
    1646             :         // Pre-Load time, antenna1 and antenna2
    1647             :         // Azel is derived and this only restriction
    1648             :         // is that it can be access by 1 thread only
    1649           0 :         preLoadColumn(VisBufferComponent2::Time);
    1650           0 :         preLoadColumn(VisBufferComponent2::Antenna1);
    1651           0 :         preLoadColumn(VisBufferComponent2::Antenna2);
    1652           0 : }
    1653             : 
    1654             : 
    1655             : void
    1656           0 : FlagDataHandler::setScanStartStopMap(bool activated)
    1657             : {
    1658           0 :         mapScanStartStop_p=activated;
    1659             :         // Pre-Load scan and time
    1660           0 :         preLoadColumn(VisBufferComponent2::Scan);
    1661           0 :         preLoadColumn(VisBufferComponent2::Time);
    1662           0 : }
    1663             : 
    1664             : 
    1665             : void
    1666           0 : FlagDataHandler::setScanStartStopFlaggedMap(bool activated)
    1667             : {
    1668           0 :         mapScanStartStopFlagged_p=activated;
    1669             :         // Pre-Load scan and time
    1670           0 :         preLoadColumn(VisBufferComponent2::Scan);
    1671           0 :         preLoadColumn(VisBufferComponent2::Time);
    1672           0 : }
    1673             : 
    1674             : // ----------------------------------------------------------------------------
    1675             : //  Set the time averaging iterator options for the visibility agents (clip, rflag, tfcrop)
    1676             : // ----------------------------------------------------------------------------
    1677             : void
    1678           0 : FlagDataHandler::setTimeAverageIter(bool activated)
    1679             : {
    1680           0 :     enableTimeAvg_p = activated;
    1681             : 
    1682             :     // Setup the time averaging options
    1683           0 :     if (dataColumnType_p == "DATA")
    1684             :     {
    1685           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageObserved;
    1686           0 :         timeAvgOptions_p |= vi::AveragingOptions::ObservedFlagWeightAvgFromSIGMA;
    1687             :     }
    1688           0 :     else if (dataColumnType_p == "CORRECTED")
    1689             :     {
    1690           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageCorrected;
    1691           0 :         timeAvgOptions_p |= vi::AveragingOptions::CorrectedFlagWeightAvgFromWEIGHT;
    1692             :     }
    1693           0 :     else if (dataColumnType_p == "MODEL")
    1694             :     {
    1695           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageModel;
    1696           0 :         timeAvgOptions_p |= vi::AveragingOptions::ModelPlainAvg;
    1697             :     }
    1698           0 :     else if (dataColumnType_p == "FLOAT_DATA")
    1699             :     {
    1700           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageFloat;
    1701             :     }
    1702           0 :     else if (dataColumnType_p == "RESIDUAL")
    1703             :     {
    1704           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageCorrected;
    1705           0 :         timeAvgOptions_p |= vi::AveragingOptions::CorrectedFlagWeightAvgFromWEIGHT;
    1706           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageModel;
    1707           0 :         timeAvgOptions_p |= vi::AveragingOptions::ModelFlagWeightAvgFromWEIGHT;
    1708             :     }
    1709             : 
    1710             :     // ensure preservation of flags (CAS-12737, CAS-12205, CAS-9985)
    1711           0 :     timeAvgOptions_p |= vi::AveragingOptions::flagdataFlagPropagation;
    1712           0 : }
    1713             : 
    1714             : // ----------------------------------------------------------------------------
    1715             : //  Set the channel averaging iterator options for the visibility agents (clip, rflag, tfcrop)
    1716             : // ----------------------------------------------------------------------------
    1717             : void
    1718           0 : FlagDataHandler::setChanAverageIter(Vector<Int> chanbin)
    1719             : {
    1720           0 :     enableChanAvg_p = true;
    1721             : 
    1722             :     // Store chanbin
    1723           0 :     if (chanbin.size() == 1)
    1724             :     {
    1725           0 :         chanAvgOptions_p.define("chanbin",chanbin(0));
    1726             :     }
    1727             :     else
    1728             :     {
    1729           0 :         chanAvgOptions_p.define("chanbin",chanbin);
    1730             :     }
    1731             : 
    1732             :     // ensure preservation of flags (CAS-12737, CAS-9985)
    1733           0 :     chanAvgOptions_p.define("flagdataFlagPropagation", true);
    1734             : 
    1735           0 :     return;
    1736             : }
    1737             : 
    1738             : // -----------------------------------------------------------------------
    1739             : // Get the WEIGHT_SPECTRUM visCube as a Complex
    1740             : // -----------------------------------------------------------------------
    1741             : Cube<Complex>&
    1742           0 : FlagDataHandler::weightVisCube()
    1743             : {
    1744             : 
    1745           0 :         Cube<Float> tmp = visibilityBuffer_p->weightSpectrum();
    1746             : 
    1747             :         // Transform Cube<Float> into Cube<Complex>
    1748           0 :         Cube<Complex> tmpTrans(tmp.shape());
    1749           0 :         tmpTrans(tmp.shape());
    1750           0 :         for (uInt idx1=0;idx1<tmp.shape()[0];idx1++)
    1751             :         {
    1752           0 :                 for (uInt idx2=0;idx2<tmp.shape()[1];idx2++)
    1753             :                 {
    1754           0 :                         for (uInt idx3=0;idx3<tmp.shape()[2];idx3++)
    1755             :                         {
    1756           0 :                                 tmpTrans(idx1,idx2,idx3) = Complex(tmp(idx1,idx2,idx3),0);
    1757             :                         }
    1758             :                 }
    1759             :         }
    1760             : 
    1761           0 :         weight_spectrum_p.resize(tmpTrans.shape(),false);
    1762           0 :         weight_spectrum_p = tmpTrans;
    1763             : 
    1764           0 :         return weight_spectrum_p;
    1765           0 : }
    1766             : 
    1767             : /////////////////////////////////////
    1768             : /// VisMapper implementation ////////
    1769             : /////////////////////////////////////
    1770           0 : VisMapper::VisMapper(String expression,polarizationMap *polMap,CubeView<Complex> *leftVis,CubeView<Complex> *rightVis)
    1771             : {
    1772           0 :         rightVis_p = NULL;
    1773           0 :         leftVis_p = NULL;
    1774           0 :         setParentCubes(leftVis,rightVis);
    1775           0 :         setExpressionMapping(expression,polMap);
    1776           0 : }
    1777             : 
    1778             : 
    1779           0 : VisMapper::VisMapper(String expression,polarizationMap *polMap)
    1780             : {
    1781           0 :         rightVis_p = NULL;
    1782           0 :         leftVis_p = NULL;
    1783           0 :         setExpressionMapping(expression,polMap);
    1784           0 : }
    1785             : 
    1786             : 
    1787             : void
    1788           0 : VisMapper::setParentCubes(CubeView<Complex> *leftVis,CubeView<Complex> *rightVis)
    1789             : {
    1790           0 :         if (rightVis_p != NULL) delete rightVis_p;
    1791           0 :         if (leftVis_p != NULL) delete leftVis_p;
    1792             : 
    1793           0 :         leftVis_p = leftVis;
    1794           0 :         IPosition leftVisSize = leftVis->shape(); // pol,chan,row
    1795           0 :         reducedLength_p = IPosition(3);
    1796           0 :         reducedLength_p(0) = leftVisSize(1); // chan
    1797           0 :         reducedLength_p(1) = leftVisSize(2); // row
    1798           0 :         if (selectedCorrelationProducts_p.size() > 0)
    1799             :         {
    1800           0 :                 reducedLength_p(2) = selectedCorrelations_p.size(); //pols
    1801             :         }
    1802             :         else
    1803             :         {
    1804           0 :                 reducedLength_p(2) = leftVisSize(1); //pols
    1805             :         }
    1806             : 
    1807             : 
    1808           0 :         if (rightVis != NULL)
    1809             :         {
    1810           0 :                 rightVis_p = rightVis;
    1811           0 :                 getVis_p = &VisMapper::diffVis;
    1812             :         }
    1813             :         else
    1814             :         {
    1815           0 :                 rightVis_p = NULL;
    1816           0 :                 getVis_p = &VisMapper::leftVis;
    1817             :         }
    1818           0 : }
    1819             : 
    1820             : 
    1821             : void
    1822           0 : VisMapper::setExpressionMapping(String expression,polarizationMap *polMap)
    1823             : {
    1824           0 :         selectedCorrelationProducts_p.clear();
    1825           0 :         selectedCorrelations_p.clear();
    1826           0 :         selectedCorrelationStrings_p.clear();
    1827           0 :         expression_p = expression;
    1828           0 :         polMap_p = polMap;
    1829           0 :         bool matchExpression = false;
    1830             : 
    1831             :         // Parse complex unitary function
    1832           0 :         if (expression_p.find("REAL") != string::npos)
    1833             :         {
    1834           0 :                 applyVisExpr_p = &VisMapper::real;
    1835             :         }
    1836           0 :         else if (expression_p.find("IMAG") != string::npos)
    1837             :         {
    1838           0 :                 applyVisExpr_p = &VisMapper::imag;
    1839             :         }
    1840           0 :         else if (expression_p.find("ARG") != string::npos)
    1841             :         {
    1842           0 :                 applyVisExpr_p = &VisMapper::arg;
    1843             :         }
    1844           0 :         else if (expression_p.find("ABS") != string::npos)
    1845             :         {
    1846           0 :                 applyVisExpr_p = &VisMapper::abs;
    1847             :         }
    1848           0 :         else if (expression_p.find("NORM") != string::npos)
    1849             :         {
    1850           0 :                 applyVisExpr_p = &VisMapper::norm;
    1851             :         }
    1852             :         else
    1853             :         {
    1854           0 :                 applyVisExpr_p = &VisMapper::abs;
    1855             :         }
    1856             : 
    1857             :         // Parse polarization
    1858           0 :         if (expression_p.find("WVR") != string::npos)
    1859             :         {
    1860           0 :                 if (polMap_p->find(Stokes::I) != polMap_p->end())
    1861             :                 {
    1862           0 :                         vector<uInt> selectedPolarizations;
    1863           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::I]);
    1864           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1865           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_i);
    1866           0 :                         selectedCorrelationStrings_p.push_back(string("I"));
    1867           0 :                         matchExpression = true;
    1868           0 :                 }
    1869             :                 else
    1870             :                 {
    1871             :                         //throw AipsError("Requested correlation product (WVR - I) not available");
    1872             :                 }
    1873             :         }
    1874           0 :         if (expression_p.find("XX") != string::npos)
    1875             :         {
    1876           0 :                 if (polMap_p->find(Stokes::XX) != polMap_p->end())
    1877             :                 {
    1878           0 :                         vector<uInt> selectedPolarizations;
    1879           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XX]);
    1880           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1881           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::linear_xx);
    1882           0 :                         selectedCorrelationStrings_p.push_back(string("XX"));
    1883           0 :                         matchExpression = true;
    1884           0 :                 }
    1885             :                 else
    1886             :                 {
    1887             :                         //throw AipsError("Requested correlation product (XX) not available");
    1888             :                 }
    1889             :         }
    1890           0 :         if (expression_p.find("YY") != string::npos)
    1891             :         {
    1892           0 :                 if (polMap_p->find(Stokes::YY) != polMap_p->end())
    1893             :                 {
    1894           0 :                         vector<uInt> selectedPolarizations;
    1895           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YY]);
    1896           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1897           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::linear_yy);
    1898           0 :                         selectedCorrelationStrings_p.push_back(string("YY"));
    1899           0 :                         matchExpression = true;
    1900           0 :                 }
    1901             :                 else
    1902             :                 {
    1903             :                         //throw AipsError("Requested correlation product (YY) not available");
    1904             :                 }
    1905             :         }
    1906           0 :         if (expression_p.find("XY") != string::npos)
    1907             :         {
    1908           0 :                 if (polMap_p->find(Stokes::XY) != polMap_p->end())
    1909             :                 {
    1910           0 :                         vector<uInt> selectedPolarizations;
    1911           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XY]);
    1912           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1913           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::linear_xy);
    1914           0 :                         selectedCorrelationStrings_p.push_back(string("XY"));
    1915           0 :                         matchExpression = true;
    1916           0 :                 }
    1917             :                 else
    1918             :                 {
    1919             :                         //throw AipsError("Requested correlation product (XY) not available");
    1920             :                 }
    1921             :         }
    1922           0 :         if (expression_p.find("YX") != string::npos)
    1923             :         {
    1924           0 :                 if (polMap_p->find(Stokes::YX) != polMap_p->end())
    1925             :                 {
    1926           0 :                         vector<uInt> selectedPolarizations;
    1927           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YX]);
    1928           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1929           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::linear_yx);
    1930           0 :                         selectedCorrelationStrings_p.push_back(string("YX"));
    1931           0 :                         matchExpression = true;
    1932           0 :                 }
    1933             :                 else
    1934             :                 {
    1935             :                         //throw AipsError("Requested correlation product (YX) not available");
    1936             :                 }
    1937             :         }
    1938           0 :         if (expression_p.find("RR") != string::npos)
    1939             :         {
    1940           0 :                 if (polMap_p->find(Stokes::RR) != polMap_p->end())
    1941             :                 {
    1942           0 :                         vector<uInt> selectedPolarizations;
    1943           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RR]);
    1944           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1945           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_rr);
    1946           0 :                         selectedCorrelationStrings_p.push_back(string("RR"));
    1947           0 :                         matchExpression = true;
    1948           0 :                 }
    1949             :                 else
    1950             :                 {
    1951             :                         //throw AipsError("Requested correlation product (RR) not available");
    1952             :                 }
    1953             :         }
    1954           0 :         if (expression_p.find("LL") != string::npos)
    1955             :         {
    1956           0 :                 if (polMap_p->find(Stokes::LL) != polMap_p->end())
    1957             :                 {
    1958           0 :                         vector<uInt> selectedPolarizations;
    1959           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LL]);
    1960           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1961           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_ll);
    1962           0 :                         selectedCorrelationStrings_p.push_back(string("LL"));
    1963           0 :                         matchExpression = true;
    1964           0 :                 }
    1965             :                 else
    1966             :                 {
    1967             :                         //throw AipsError("Requested correlation product (LL) not available");
    1968             :                 }
    1969             :         }
    1970           0 :         if (expression_p.find("LR") != string::npos)
    1971             :         {
    1972           0 :                 if (polMap_p->find(Stokes::LR) != polMap_p->end())
    1973             :                 {
    1974           0 :                         vector<uInt> selectedPolarizations;
    1975           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LR]);
    1976           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1977           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_lr);
    1978           0 :                         selectedCorrelationStrings_p.push_back(string("LR"));
    1979           0 :                         matchExpression = true;
    1980           0 :                 }
    1981             :                 else
    1982             :                 {
    1983             :                         //throw AipsError("Requested correlation product (LR) not available");
    1984             :                 }
    1985             :         }
    1986           0 :         if (expression_p.find("RL") != string::npos)
    1987             :         {
    1988           0 :                 if (polMap_p->find(Stokes::RL) != polMap_p->end())
    1989             :                 {
    1990           0 :                         vector<uInt> selectedPolarizations;
    1991           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RL]);
    1992           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1993           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_rl);
    1994           0 :                         selectedCorrelationStrings_p.push_back(string("RL"));
    1995           0 :                         matchExpression = true;
    1996           0 :                 }
    1997             :                 else
    1998             :                 {
    1999             :                         //throw AipsError("Requested correlation product (RL) not available");
    2000             :                 }
    2001             :         }
    2002           0 :         if (expression_p.find("I") != string::npos)
    2003             :         {
    2004           0 :                 if (polMap_p->find(Stokes::I) != polMap_p->end())
    2005             :                 {
    2006           0 :                         vector<uInt> selectedPolarizations;
    2007           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::I]);
    2008           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2009           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_i);
    2010           0 :                         selectedCorrelationStrings_p.push_back(string("I"));
    2011           0 :                         matchExpression = true;
    2012           0 :                 }
    2013           0 :                 else if ((polMap_p->find(Stokes::XX) != polMap_p->end()) and (polMap_p->find(Stokes::YY) != polMap_p->end()))
    2014             :                 {
    2015           0 :                         vector<uInt> selectedPolarizations;
    2016           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XX]);
    2017           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YY]);
    2018           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2019           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_i_from_linear);
    2020           0 :                         selectedCorrelationStrings_p.push_back(string("I = (XX+YY)/2"));
    2021           0 :                         matchExpression = true;
    2022           0 :                 }
    2023           0 :                 else if ((polMap_p->find(Stokes::RR) != polMap_p->end()) and (polMap_p->find(Stokes::LL) != polMap_p->end()))
    2024             :                 {
    2025           0 :                         vector<uInt> selectedPolarizations;
    2026           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RR]);
    2027           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LL]);
    2028           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2029           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_i_from_circular);
    2030           0 :                         selectedCorrelationStrings_p.push_back(string("I = (RR+LL)/2"));
    2031           0 :                         matchExpression = true;
    2032           0 :                 }
    2033             :                 else
    2034             :                 {
    2035             :                         //throw AipsError("Requested Stokes parameter (I) cannot be computed from available polarizations");
    2036             :                 }
    2037             :         }
    2038           0 :         if (expression_p.find("Q") != string::npos)
    2039             :         {
    2040           0 :                 if (polMap_p->find(Stokes::Q) != polMap_p->end())
    2041             :                 {
    2042           0 :                         vector<uInt> selectedPolarizations;
    2043           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::Q]);
    2044           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2045           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_q);
    2046           0 :                         selectedCorrelationStrings_p.push_back(string("Q"));
    2047           0 :                         matchExpression = true;
    2048           0 :                 }
    2049           0 :                 else if ((polMap_p->find(Stokes::XX) != polMap_p->end()) and (polMap_p->find(Stokes::YY) != polMap_p->end()))
    2050             :                 {
    2051           0 :                         vector<uInt> selectedPolarizations;
    2052           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XX]);
    2053           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YY]);
    2054           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2055           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_q_from_linear);
    2056           0 :                         selectedCorrelationStrings_p.push_back(string("Q = (XX-YY)/2"));
    2057           0 :                         matchExpression = true;
    2058           0 :                 }
    2059           0 :                 else if ((polMap_p->find(Stokes::RL) != polMap_p->end()) and (polMap_p->find(Stokes::LR) != polMap_p->end()))
    2060             :                 {
    2061           0 :                         vector<uInt> selectedPolarizations;
    2062           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RL]);
    2063           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LR]);
    2064           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2065           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_q_from_circular);
    2066           0 :                         selectedCorrelationStrings_p.push_back(string("Q = (RL-LR)/2"));
    2067           0 :                         matchExpression = true;
    2068           0 :                 }
    2069             :                 else
    2070             :                 {
    2071             :                         //throw AipsError("Requested Stokes parameter (Q) cannot be computed from available polarizations");
    2072             :                 }
    2073             :         }
    2074           0 :         if (expression_p.find("U") != string::npos)
    2075             :         {
    2076           0 :                 if (polMap_p->find(Stokes::U) != polMap_p->end())
    2077             :                 {
    2078           0 :                         vector<uInt> selectedPolarizations;
    2079           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::U]);
    2080           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2081           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_u);
    2082           0 :                         selectedCorrelationStrings_p.push_back(string("U"));
    2083           0 :                         matchExpression = true;
    2084           0 :                 }
    2085           0 :                 else if ((polMap_p->find(Stokes::XY) != polMap_p->end()) and (polMap_p->find(Stokes::YX) != polMap_p->end()))
    2086             :                 {
    2087           0 :                         vector<uInt> selectedPolarizations;
    2088           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XY]);
    2089           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YX]);
    2090           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2091           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_u_from_linear);
    2092           0 :                         selectedCorrelationStrings_p.push_back(string("U = (XY-YX)/2"));
    2093           0 :                         matchExpression = true;
    2094           0 :                 }
    2095           0 :                 else if ((polMap_p->find(Stokes::RL) != polMap_p->end()) and (polMap_p->find(Stokes::LR) != polMap_p->end()))
    2096             :                 {
    2097           0 :                         vector<uInt> selectedPolarizations;
    2098           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RL]);
    2099           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LR]);
    2100           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2101           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_u_from_circular);
    2102           0 :                         selectedCorrelationStrings_p.push_back(string(" U = (RL-LR)/2i"));
    2103           0 :                         matchExpression = true;
    2104           0 :                 }
    2105             :                 else
    2106             :                 {
    2107             :                         //throw AipsError("Requested Stokes parameter (U) cannot be computed from available polarizations");
    2108             :                 }
    2109             :         }
    2110           0 :         if ((expression_p.find("V") != string::npos) and (expression_p.find("WVR") == string::npos))
    2111             :         {
    2112           0 :                 if (polMap_p->find(Stokes::V) != polMap_p->end())
    2113             :                 {
    2114           0 :                         vector<uInt> selectedPolarizations;
    2115           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::V]);
    2116           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2117           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_v);
    2118           0 :                         selectedCorrelationStrings_p.push_back(string("V"));
    2119           0 :                         matchExpression = true;
    2120           0 :                 }
    2121           0 :                 else if ((polMap_p->find(Stokes::XY) != polMap_p->end()) and (polMap_p->find(Stokes::YX) != polMap_p->end()))
    2122             :                 {
    2123           0 :                         vector<uInt> selectedPolarizations;
    2124           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XY]);
    2125           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YX]);
    2126           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2127           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_v_from_linear);
    2128           0 :                         selectedCorrelationStrings_p.push_back(string("V = (XY-YX)/2i"));
    2129           0 :                         matchExpression = true;
    2130           0 :                 }
    2131           0 :                 else if ((polMap_p->find(Stokes::RR) != polMap_p->end()) and (polMap_p->find(Stokes::LL) != polMap_p->end()))
    2132             :                 {
    2133           0 :                         vector<uInt> selectedPolarizations;
    2134           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RR]);
    2135           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LL]);
    2136           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2137           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_v_from_circular);
    2138           0 :                         selectedCorrelationStrings_p.push_back(string("V = (RR-LL)/2"));
    2139           0 :                         matchExpression = true;
    2140           0 :                 }
    2141             :                 else
    2142             :                 {
    2143             :                         //throw AipsError("Requested Stokes parameter (V) cannot be computed from available polarizations");
    2144             :                 }
    2145             :         }
    2146           0 :         if (expression_p.find("SOL1") != string::npos)
    2147             :         {
    2148           0 :                 if (polMap_p->find(VisMapper::CALSOL1) != polMap_p->end())
    2149             :                 {
    2150           0 :                         vector<uInt> selectedPolarizations;
    2151           0 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL1]);
    2152           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2153           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol1);
    2154           0 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 1"));
    2155           0 :                         matchExpression = true;
    2156           0 :                 }
    2157             :                 else
    2158             :                 {
    2159             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2160             :                 }
    2161             :         }
    2162           0 :         if (expression_p.find("SOL2") != string::npos)
    2163             :         {
    2164           0 :                 if (polMap_p->find(VisMapper::CALSOL2) != polMap_p->end())
    2165             :                 {
    2166           0 :                         vector<uInt> selectedPolarizations;
    2167           0 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL2]);
    2168           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2169           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol2);
    2170           0 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 2"));
    2171           0 :                         matchExpression = true;
    2172           0 :                 }
    2173             :                 else
    2174             :                 {
    2175             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2176             :                 }
    2177             :         }
    2178           0 :         if (expression_p.find("SOL3") != string::npos)
    2179             :         {
    2180           0 :                 if (polMap_p->find(VisMapper::CALSOL3) != polMap_p->end())
    2181             :                 {
    2182           0 :                         vector<uInt> selectedPolarizations;
    2183           0 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL3]);
    2184           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2185           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol3);
    2186           0 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 3"));
    2187           0 :                         matchExpression = true;
    2188           0 :                 }
    2189             :                 else
    2190             :                 {
    2191             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2192             :                 }
    2193             :         }
    2194           0 :         if (expression_p.find("SOL4") != string::npos)
    2195             :         {
    2196           0 :                 if (polMap_p->find(VisMapper::CALSOL4) != polMap_p->end())
    2197             :                 {
    2198           0 :                         vector<uInt> selectedPolarizations;
    2199           0 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL4]);
    2200           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2201           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol4);
    2202           0 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 4"));
    2203           0 :                         matchExpression = true;
    2204           0 :                 }
    2205             :                 else
    2206             :                 {
    2207             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2208             :                 }
    2209             :         }
    2210             : 
    2211             : 
    2212           0 :         if (!matchExpression)
    2213             :         {
    2214             :                 //throw AipsError("Unknown polarization requested, (" + expression_p + ") supported types are: XX,YY,XY,YX,RR,LL,RL,LR,I,Q,U,V");
    2215             :         }
    2216           0 : }
    2217             : 
    2218             : 
    2219           0 : VisMapper::~VisMapper()
    2220             : {
    2221           0 :         if (rightVis_p != NULL) delete rightVis_p;
    2222           0 :         if (leftVis_p != NULL) delete leftVis_p;
    2223           0 : }
    2224             : 
    2225             : 
    2226             : Float
    2227           0 : VisMapper::operator()(uInt chan, uInt row)
    2228             : {
    2229           0 :         Complex val = (*this.*selectedCorrelationProducts_p[0])(chan,row);
    2230           0 :         return (*this.*applyVisExpr_p)(val);
    2231             : }
    2232             : 
    2233             : 
    2234             : Float
    2235           0 : VisMapper::operator()(uInt pol, uInt chan, uInt row)
    2236             : {
    2237           0 :         Complex val = (*this.*selectedCorrelationProducts_p[pol])(chan,row);
    2238           0 :         return (*this.*applyVisExpr_p)(val);
    2239             : }
    2240             : 
    2241             : 
    2242             : Complex
    2243           0 : VisMapper::correlationProduct(uInt pol, uInt chan, uInt row)
    2244             : {
    2245           0 :         return (*this.*selectedCorrelationProducts_p[pol])(chan,row);
    2246             : }
    2247             : 
    2248             : 
    2249             : Complex
    2250           0 : VisMapper::leftVis(uInt pol, uInt chan, uInt row)
    2251             : {
    2252           0 :         return leftVis_p->operator()(pol,chan,row);
    2253             : }
    2254             : 
    2255             : 
    2256             : Complex
    2257           0 : VisMapper::diffVis(uInt pol, uInt chan, uInt row)
    2258             : {
    2259           0 :         return leftVis_p->operator()(pol,chan,row)-rightVis_p->operator()(pol,chan,row);
    2260             : }
    2261             : 
    2262             : 
    2263             : Complex
    2264           0 : VisMapper::stokes_i(uInt chan, uInt row)
    2265             : {
    2266           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::I],chan,row);
    2267             : }
    2268             : 
    2269             : 
    2270             : Complex
    2271           0 : VisMapper::stokes_q(uInt chan, uInt row)
    2272             : {
    2273           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::Q],chan,row);
    2274             : }
    2275             : 
    2276             : 
    2277             : Complex
    2278           0 : VisMapper::stokes_u(uInt chan, uInt row)
    2279             : {
    2280           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::U],chan,row);
    2281             : }
    2282             : 
    2283             : 
    2284             : Complex
    2285           0 : VisMapper::stokes_v(uInt chan, uInt row)
    2286             : {
    2287           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::V],chan,row);
    2288             : }
    2289             : 
    2290             : 
    2291             : Complex
    2292           0 : VisMapper::linear_xx(uInt chan, uInt row)
    2293             : {
    2294           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::XX],chan,row);
    2295             : }
    2296             : 
    2297             : 
    2298             : Complex
    2299           0 : VisMapper::linear_yy(uInt chan, uInt row)
    2300             : {
    2301           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::YY],chan,row);
    2302             : }
    2303             : 
    2304             : 
    2305             : Complex
    2306           0 : VisMapper::linear_xy(uInt chan, uInt row)
    2307             : {
    2308           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::XY],chan,row);
    2309             : }
    2310             : 
    2311             : 
    2312             : Complex
    2313           0 : VisMapper::linear_yx(uInt chan, uInt row)
    2314             : {
    2315           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::YX],chan,row);
    2316             : }
    2317             : 
    2318             : 
    2319             : Complex
    2320           0 : VisMapper::circular_rr(uInt chan, uInt row)
    2321             : {
    2322           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::RR],chan,row);
    2323             : }
    2324             : 
    2325             : 
    2326             : Complex
    2327           0 : VisMapper::circular_ll(uInt chan, uInt row)
    2328             : {
    2329           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::LL],chan,row);
    2330             : }
    2331             : 
    2332             : 
    2333             : Complex
    2334           0 : VisMapper::circular_rl(uInt chan, uInt row)
    2335             : {
    2336           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::RL],chan,row);
    2337             : }
    2338             : 
    2339             : 
    2340             : Complex
    2341           0 : VisMapper::circular_lr(uInt chan, uInt row)
    2342             : {
    2343           0 :         return (*this.*getVis_p)((*polMap_p)[Stokes::LR],chan,row);
    2344             : }
    2345             : 
    2346             : 
    2347             : Complex
    2348           0 : VisMapper::stokes_i_from_linear(uInt chan, uInt row)
    2349             : {
    2350             :         // I = (XX+YY)/2
    2351           0 :         return ((*this.*getVis_p)((*polMap_p)[Stokes::XX],chan,row) + (*this.*getVis_p)((*polMap_p)[Stokes::YY],chan,row))/2;
    2352             : }
    2353             : 
    2354             : 
    2355             : Complex
    2356           0 : VisMapper::stokes_q_from_linear(uInt chan, uInt row)
    2357             : {
    2358             :         // Q = (XX-YY)/2
    2359           0 :         return ((*this.*getVis_p)((*polMap_p)[Stokes::XX],chan,row) - (*this.*getVis_p)((*polMap_p)[Stokes::YY],chan,row))/2;
    2360             : }
    2361             : 
    2362             : 
    2363             : Complex
    2364           0 : VisMapper::stokes_u_from_linear(uInt chan, uInt row)
    2365             : {
    2366             :         // U = (XY-YX)/2
    2367           0 :         return ((*this.*getVis_p)((*polMap_p)[Stokes::XY],chan,row) - (*this.*getVis_p)((*polMap_p)[Stokes::YX],chan,row))/2;
    2368             : }
    2369             : 
    2370             : 
    2371             : Complex
    2372           0 : VisMapper::stokes_v_from_linear(uInt chan, uInt row)
    2373             : {
    2374             :         // V = (XY-YX)/2i
    2375             :     using casacore::operator*;
    2376           0 :         return ((*this.*getVis_p)((*polMap_p)[Stokes::XY],chan,row) - (*this.*getVis_p)((*polMap_p)[Stokes::YX],chan,row))/(2*ImaginaryUnit);
    2377             : }
    2378             : 
    2379             : 
    2380             : Complex
    2381           0 : VisMapper::stokes_i_from_circular(uInt chan, uInt row)
    2382             : {
    2383             :         // I = (RR+LL)/2
    2384           0 :         return ((*this.*getVis_p)((*polMap_p)[Stokes::RR],chan,row) + (*this.*getVis_p)((*polMap_p)[Stokes::LL],chan,row))/2;
    2385             : }
    2386             : 
    2387             : 
    2388             : Complex
    2389           0 : VisMapper::stokes_q_from_circular(uInt chan, uInt row)
    2390             : {
    2391             :         // Q = (RL-LR)/2
    2392           0 :         return ((*this.*getVis_p)((*polMap_p)[Stokes::RL],chan,row) - (*this.*getVis_p)((*polMap_p)[Stokes::LR],chan,row))/2;
    2393             : }
    2394             : 
    2395             : 
    2396             : Complex
    2397           0 : VisMapper::stokes_u_from_circular(uInt chan, uInt row)
    2398             : {
    2399             :     using casacore::operator*;
    2400             : 
    2401             :         // U = (RL-LR)/2i
    2402           0 :         return ((*this.*getVis_p)((*polMap_p)[Stokes::RL],chan,row) - (*this.*getVis_p)((*polMap_p)[Stokes::LR],chan,row))/(2*ImaginaryUnit);
    2403             : }
    2404             : 
    2405             : 
    2406             : Complex
    2407           0 : VisMapper::stokes_v_from_circular(uInt chan, uInt row)
    2408             : {
    2409             :     using casacore::operator*;
    2410             : 
    2411             :         // V = (RR-LL)/2
    2412           0 :         return ((*this.*getVis_p)((*polMap_p)[Stokes::RR],chan,row) - (*this.*getVis_p)((*polMap_p)[Stokes::LL],chan,row))/(2*ImaginaryUnit);
    2413             : }
    2414             : 
    2415             : Complex
    2416           0 : VisMapper::calsol1(uInt chan, uInt row)
    2417             : {
    2418           0 :         return (*this.*getVis_p)((*polMap_p)[VisMapper::CALSOL1],chan,row);
    2419             : }
    2420             : 
    2421             : 
    2422             : Complex
    2423           0 : VisMapper::calsol2(uInt chan, uInt row)
    2424             : {
    2425           0 :         return (*this.*getVis_p)((*polMap_p)[VisMapper::CALSOL2],chan,row);
    2426             : }
    2427             : 
    2428             : 
    2429             : Complex
    2430           0 : VisMapper::calsol3(uInt chan, uInt row)
    2431             : {
    2432           0 :         return (*this.*getVis_p)((*polMap_p)[VisMapper::CALSOL3],chan,row);
    2433             : }
    2434             : 
    2435             : 
    2436             : Complex
    2437           0 : VisMapper::calsol4(uInt chan, uInt row)
    2438             : {
    2439           0 :         return (*this.*getVis_p)((*polMap_p)[VisMapper::CALSOL4],chan,row);
    2440             : }
    2441             : 
    2442             : 
    2443             : //////////////////////////////////////
    2444             : /// FlagMapper implementation ////////
    2445             : //////////////////////////////////////
    2446           0 : FlagMapper::FlagMapper(Bool flag,       vector< vector<uInt> > selectedCorrelations,
    2447             :                                                                         CubeView<Bool> *commonFlagsView,
    2448             :                                                                         CubeView<Bool> *originalFlagsView,
    2449             :                                                                         CubeView<Bool> *privateFlagsView,
    2450             :                                                                         VectorView<Bool> *commonFlagRowView,
    2451             :                                                                         VectorView<Bool> *originalFlagRowView,
    2452           0 :                                                                         VectorView<Bool> *privateFlagRowView)
    2453             : {
    2454           0 :         commonFlagsView_p = NULL;
    2455           0 :         originalFlagsView_p = NULL;
    2456           0 :         privateFlagsView_p = NULL;
    2457           0 :         commonFlagRowView_p = NULL;
    2458           0 :         originalFlagRowView_p = NULL;
    2459           0 :         privateFlagRowView_p = NULL;
    2460           0 :         setParentCubes(commonFlagsView,originalFlagsView,privateFlagsView);
    2461           0 :         setParentFlagRow(commonFlagRowView,originalFlagRowView,privateFlagRowView);
    2462           0 :         setExpressionMapping(selectedCorrelations);
    2463           0 :         nSelectedCorrelations_p = selectedCorrelations.size();
    2464           0 :         flag_p = flag;
    2465           0 : }
    2466             : 
    2467             : 
    2468           0 : FlagMapper::FlagMapper(Bool flag, vector< vector<uInt> > selectedCorrelations)
    2469             : {
    2470           0 :         commonFlagsView_p = NULL;
    2471           0 :         originalFlagsView_p = NULL;
    2472           0 :         privateFlagsView_p = NULL;
    2473           0 :         commonFlagRowView_p = NULL;
    2474           0 :         originalFlagRowView_p = NULL;
    2475           0 :         privateFlagRowView_p = NULL;
    2476           0 :         setExpressionMapping(selectedCorrelations);
    2477           0 :         nSelectedCorrelations_p = selectedCorrelations.size();
    2478           0 :         flag_p = flag;
    2479           0 : }
    2480             : 
    2481             : 
    2482             : void
    2483           0 : FlagMapper::setParentCubes(CubeView<Bool> *commonFlagsView,CubeView<Bool> *originalFlagsView,CubeView<Bool> *privateFlagsView)
    2484             : {
    2485           0 :         if (commonFlagsView_p != NULL) delete commonFlagsView_p;
    2486           0 :         if (originalFlagsView_p != NULL) delete originalFlagsView_p;
    2487           0 :         if (privateFlagsView_p != NULL) delete privateFlagsView_p;
    2488             : 
    2489           0 :         commonFlagsView_p = commonFlagsView;
    2490           0 :         originalFlagsView_p = originalFlagsView;
    2491           0 :         if (privateFlagsView != NULL)
    2492             :         {
    2493           0 :                 privateFlagsView_p = privateFlagsView;
    2494           0 :                 applyFlag_p = &FlagMapper::applyPrivateFlags;
    2495             :         }
    2496             :         else
    2497             :         {
    2498           0 :                 applyFlag_p = &FlagMapper::applyCommonFlags;
    2499             :         }
    2500             : 
    2501           0 :         IPosition commonFlagCubeSize = commonFlagsView_p->shape(); // pol,chan,row
    2502           0 :         reducedLength_p = IPosition(2);
    2503           0 :         reducedLength_p(0) = commonFlagCubeSize(1); // chan
    2504           0 :         reducedLength_p(1) = commonFlagCubeSize(2); // row
    2505             : 
    2506           0 :         if (nSelectedCorrelations_p>0)
    2507             :         {
    2508           0 :                 reducedLength_p(2) = nSelectedCorrelations_p; // pol
    2509             :         }
    2510             :         else
    2511             :         {
    2512           0 :                 reducedLength_p(2) = reducedLength_p(0);// pol
    2513             :         }
    2514             : 
    2515           0 :         flagsPerRow_p = reducedLength_p(2)*reducedLength_p(0);
    2516           0 : }
    2517             : 
    2518             : 
    2519             : void
    2520           0 : FlagMapper::setParentFlagRow(VectorView<Bool> *commonFlagRowView,VectorView<Bool> *originalFlagRowView,VectorView<Bool> *privateFlagRowView)
    2521             : {
    2522           0 :         if (commonFlagRowView_p != NULL) delete commonFlagRowView_p;
    2523           0 :         if (originalFlagRowView_p != NULL) delete originalFlagRowView_p;
    2524           0 :         if (privateFlagRowView_p != NULL) delete privateFlagRowView_p;
    2525             : 
    2526           0 :         commonFlagRowView_p = commonFlagRowView;
    2527           0 :         originalFlagRowView_p = originalFlagRowView;
    2528           0 :         if (privateFlagRowView_p != NULL)
    2529             :         {
    2530           0 :                 privateFlagRowView_p = privateFlagRowView;
    2531           0 :                 applyFlagRow_p = &FlagMapper::applyPrivateFlagRow;
    2532             :         }
    2533             :         else
    2534             :         {
    2535           0 :                 applyFlagRow_p = &FlagMapper::applyCommonFlagRow;
    2536             :         }
    2537             : 
    2538           0 :         return;
    2539             : }
    2540             : 
    2541             : 
    2542             : void
    2543           0 : FlagMapper::setExpressionMapping(vector< vector<uInt> > selectedCorrelations)
    2544             : {
    2545           0 :         selectedCorrelations_p = selectedCorrelations;
    2546           0 :         if (selectedCorrelations_p.empty())
    2547             :         {
    2548             :                 //throw AipsError("None of the correlations is eligible for flagging");
    2549             :         }
    2550           0 : }
    2551             : 
    2552             : 
    2553           0 : FlagMapper::~FlagMapper()
    2554             : {
    2555           0 :         if (commonFlagsView_p != NULL) delete commonFlagsView_p;
    2556           0 :         if (originalFlagsView_p != NULL) delete originalFlagsView_p;
    2557           0 :         if (privateFlagsView_p != NULL) delete privateFlagsView_p;
    2558           0 :         if (commonFlagRowView_p != NULL) delete commonFlagRowView_p;
    2559           0 :         if (originalFlagRowView_p != NULL) delete originalFlagRowView_p;
    2560           0 :         if (privateFlagRowView_p != NULL) delete privateFlagRowView_p;
    2561           0 : }
    2562             : 
    2563             : 
    2564             : Bool
    2565           0 : FlagMapper::getOriginalFlags(uInt channel, uInt row)
    2566             : {
    2567           0 :         Bool combinedFlag = false;
    2568           0 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[0].begin();iter!=selectedCorrelations_p[0].end();iter++)
    2569             :         {
    2570           0 :                 combinedFlag = combinedFlag | originalFlagsView_p->operator ()(*iter,channel,row);
    2571             :         }
    2572             : 
    2573           0 :         return combinedFlag;
    2574             : }
    2575             : 
    2576             : 
    2577             : Bool
    2578           0 : FlagMapper::getModifiedFlags(uInt channel, uInt row)
    2579             : {
    2580           0 :         Bool combinedFlag = false;
    2581           0 :         for (auto &elem : selectedCorrelations_p[0])
    2582             :         {
    2583           0 :                 combinedFlag = combinedFlag | commonFlagsView_p->operator ()(elem, channel, row);
    2584             :         }
    2585             : 
    2586           0 :         return combinedFlag;
    2587             : }
    2588             : 
    2589             : 
    2590             : Bool
    2591           0 : FlagMapper::getPrivateFlags(uInt channel, uInt row)
    2592             : {
    2593           0 :         Bool combinedFlag = false;
    2594           0 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[0].begin();iter!=selectedCorrelations_p[0].end();iter++)
    2595             :         {
    2596           0 :                 combinedFlag = combinedFlag | privateFlagsView_p->operator ()(*iter,channel,row);
    2597             :         }
    2598             : 
    2599           0 :         return combinedFlag;
    2600             : }
    2601             : 
    2602             : 
    2603             : Bool
    2604           0 : FlagMapper::getOriginalFlags(uInt pol, uInt channel, uInt row)
    2605             : {
    2606           0 :         Bool combinedFlag = false;
    2607           0 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2608             :         {
    2609           0 :                 combinedFlag = combinedFlag | originalFlagsView_p->operator ()(*iter,channel,row);
    2610             :         }
    2611             : 
    2612           0 :         return combinedFlag;
    2613             : }
    2614             : 
    2615             : 
    2616             : Bool
    2617           0 : FlagMapper::getModifiedFlags(uInt pol, uInt channel, uInt row)
    2618             : {
    2619           0 :         Bool combinedFlag = false;
    2620           0 :         for (auto &elem : selectedCorrelations_p[pol])
    2621             :         {
    2622           0 :                 combinedFlag = combinedFlag | commonFlagsView_p->operator ()(elem, channel, row);
    2623             :         }
    2624             : 
    2625           0 :         return combinedFlag;
    2626             : }
    2627             : 
    2628             : 
    2629             : Bool
    2630           0 : FlagMapper::getPrivateFlags(uInt pol, uInt channel, uInt row)
    2631             : {
    2632           0 :         Bool combinedFlag = false;
    2633           0 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2634             :         {
    2635           0 :                 combinedFlag = combinedFlag | privateFlagsView_p->operator ()(*iter,channel,row);
    2636             :         }
    2637             : 
    2638           0 :         return combinedFlag;
    2639             : }
    2640             : 
    2641             : 
    2642             : Bool
    2643           0 : FlagMapper::getOriginalFlagRow(uInt row)
    2644             : {
    2645           0 :         return originalFlagRowView_p->operator ()(row);
    2646             : }
    2647             : 
    2648             : 
    2649             : Bool
    2650           0 : FlagMapper::getModifiedFlagRow(uInt row)
    2651             : {
    2652           0 :         return commonFlagRowView_p->operator ()(row);
    2653             : }
    2654             : 
    2655             : 
    2656             : Bool
    2657           0 : FlagMapper::getPrivateFlagRow(uInt row)
    2658             : {
    2659           0 :         return privateFlagRowView_p->operator ()(row);
    2660             : }
    2661             : 
    2662             : 
    2663             : void
    2664           0 : FlagMapper::setModifiedFlags(uInt pol, uInt channel, uInt row)
    2665             : {
    2666           0 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2667             :         {
    2668           0 :                 commonFlagsView_p->operator ()(*iter,channel,row) = flag_p;
    2669             :         }
    2670           0 : }
    2671             : 
    2672             : 
    2673             : void
    2674           0 : FlagMapper::setPrivateFlags(uInt pol, uInt channel, uInt row)
    2675             : {
    2676           0 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2677             :         {
    2678           0 :                 privateFlagsView_p->operator ()(*iter,channel,row) = flag_p;
    2679             :         }
    2680           0 : }
    2681             : 
    2682             : 
    2683             : void
    2684           0 : FlagMapper::applyFlag(uInt channel, uInt row)
    2685             : {
    2686           0 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[0].begin();iter!=selectedCorrelations_p[0].end();iter++)
    2687             :         {
    2688           0 :                 (*this.*applyFlag_p)(*iter,channel,row);
    2689             :         }
    2690           0 : }
    2691             : 
    2692             : 
    2693             : void
    2694           0 : FlagMapper::applyFlag(uInt pol, uInt channel, uInt row)
    2695             : {
    2696           0 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2697             :         {
    2698           0 :                 (*this.*applyFlag_p)(*iter,channel,row);
    2699             :         }
    2700           0 : }
    2701             : 
    2702             : 
    2703             : void
    2704           0 : FlagMapper::applyFlagRow(uInt row)
    2705             : {
    2706             :         // Flag row
    2707           0 :         (*this.*applyFlagRow_p)(row);
    2708           0 : }
    2709             : 
    2710             : void
    2711           0 : FlagMapper::applyFlagInRow(uInt row)
    2712             : {
    2713             :         // Flag cube
    2714           0 :         for (uInt chan_i=0;chan_i<reducedLength_p(0);chan_i++)
    2715             :         {
    2716           0 :                 for (vector< vector<uInt> >::iterator correlations=selectedCorrelations_p.begin();correlations!=selectedCorrelations_p.end();correlations++)
    2717             :                 {
    2718           0 :                         for (vector<uInt>::iterator iter=correlations->begin();iter!=correlations->end();iter++)
    2719             :                         {
    2720           0 :                                 (*this.*applyFlag_p)(*iter,chan_i,row);
    2721             :                         }
    2722             :                 }
    2723             :         }
    2724           0 : }
    2725             : 
    2726             : 
    2727             : void
    2728           0 : FlagMapper::applyCommonFlags(uInt pol, uInt channel, uInt row)
    2729             : {
    2730             :         // NOTE: Notice that the position is pol,channel,row, not the other way around
    2731           0 :         commonFlagsView_p->operator()(pol,channel,row) = flag_p;
    2732           0 :         return;
    2733             : }
    2734             : 
    2735             : 
    2736             : void
    2737           0 : FlagMapper::applyPrivateFlags(uInt pol, uInt channel, uInt row)
    2738             : {
    2739             :         // NOTE: Notice that the position is pol,channel,row, not the other way around
    2740           0 :         commonFlagsView_p->operator()(pol,channel,row) = flag_p;
    2741           0 :         privateFlagsView_p->operator()(pol,channel,row) = flag_p;
    2742           0 :         return;
    2743             : }
    2744             : 
    2745             : 
    2746             : void
    2747           0 : FlagMapper::checkCommonFlags(uInt pol, uInt channel, uInt row)
    2748             : {
    2749             :         // NOTE: Notice that the position is pol,channel,row, not the other way around
    2750           0 :         if (commonFlagsView_p->operator()(pol,channel,row) != flag_p)
    2751             :         {
    2752           0 :                 cerr << "FlagMapper::" << __FUNCTION__ <<  " Flag missmatch at pol=" << pol << ",channel=" << channel << ",row=" << row << endl;
    2753             :         }
    2754           0 :         return;
    2755             : }
    2756             : 
    2757             : 
    2758             : void
    2759           0 : FlagMapper::applyCommonFlagRow(uInt row)
    2760             : {
    2761             :         // NOTE: Notice that the position is pol,channel,row, not the other way around
    2762           0 :         commonFlagRowView_p->operator()(row) = flag_p;
    2763           0 :         return;
    2764             : }
    2765             : 
    2766             : 
    2767             : void
    2768           0 : FlagMapper::applyPrivateFlagRow(uInt row)
    2769             : {
    2770             :         // NOTE: Notice that the position is pol,channel,row, not the other way around
    2771           0 :         commonFlagRowView_p->operator()(row) = flag_p;
    2772           0 :         originalFlagRowView_p->operator()(row) = flag_p;
    2773           0 :         return;
    2774             : }
    2775             : 
    2776             : } //# NAMESPACE CASA - END
    2777             : 

Generated by: LCOV version 1.16