LCOV - code coverage report
Current view: top level - flagging/Flagging - FlagDataHandler.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 720 1268 56.8 %
Date: 2023-11-06 10:06:49 Functions: 52 83 62.7 %

          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        1707 : FlagDataHandler::FlagDataHandler(string tablename, uShort iterationApproach, Double timeInterval):
      41        1707 :                 tablename_p(tablename), iterationApproach_p(iterationApproach)
      42             : {
      43             :         // Initialize logger
      44        1707 :         logger_p = new LogIO(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
      45             : 
      46             :         // Set time interval
      47        1707 :         setTimeInterval(timeInterval);
      48             : 
      49             :         // Deactivate profiling by default
      50        1707 :         profiling_p = false;
      51             : 
      52             :         // Disable async I/O by default
      53        1707 :         enableAsyncIO(false);
      54             : 
      55             :         // Check if slurp is enabled
      56        1707 :         if (!asyncio_enabled_p)
      57             :         {
      58        1707 :                 slurp_p = true;
      59        1707 :                 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        1707 :         mapPolarizations_p = true;
      85             : 
      86             :         // Antenna pointing map is only needed by the Elevation agent and I have move it there
      87        1707 :         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        1707 :         mapScanStartStop_p = false;
      92        1707 :         mapScanStartStopFlagged_p = false;
      93             : 
      94             :         // Initialize Pre-Load columns
      95        1707 :         preLoadColumns_p.clear();
      96        1707 :         preLoadColumns_p.push_back(VisBufferComponent2::FieldId);
      97        1707 :         preLoadColumns_p.push_back(VisBufferComponent2::SpectralWindows);
      98        1707 :         preLoadColumns_p.push_back(VisBufferComponent2::Scan);
      99        1707 :         preLoadColumns_p.push_back(VisBufferComponent2::ArrayId);
     100        1707 :         preLoadColumns_p.push_back(VisBufferComponent2::ObservationId);
     101             : 
     102        1707 :         preLoadColumns_p.push_back(VisBufferComponent2::NRows);
     103        1707 :         preLoadColumns_p.push_back(VisBufferComponent2::NChannels);
     104        1707 :         preLoadColumns_p.push_back(VisBufferComponent2::NCorrelations);
     105             : 
     106             :         // Set the iteration approach based on the agent
     107        1707 :         setIterationApproach(iterationApproach);
     108             : 
     109             :         // Initialize selection ranges
     110        1707 :         anySelection_p = false;
     111        1707 :         inrowSelection_p = false;
     112        1707 :         timeSelection_p = String("");
     113        1707 :         baselineSelection_p = String("");
     114        1707 :         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        1707 :         spwSelection_p = String("");
     118        1707 :         uvwSelection_p = String("");
     119        1707 :         polarizationSelection_p = String("");
     120        1707 :         scanSelection_p = String("");
     121        1707 :         arraySelection_p = String("");
     122        1707 :         observationSelection_p = String("");
     123        1707 :         scanIntentSelection_p = String("");
     124             : 
     125             :         // Initialize iteration parameters
     126        1707 :         chunksInitialized_p = false;
     127        1707 :         buffersInitialized_p = false;
     128        1707 :         iteratorGenerated_p = false;
     129        1707 :         stopIteration_p = false;
     130        1707 :         processedRows_p = 0;
     131        1707 :         chunkNo_p = 0;
     132        1707 :         bufferNo_p = 0;
     133             : 
     134             :         // Initialize stats
     135        1707 :         stats_p = false;
     136        1707 :         cubeAccessCounter_p = 0;
     137        1707 :         chunkCounts_p = 0;
     138        1707 :         progressCounts_p = 0;
     139        1707 :         msCounts_p = 0;
     140        1707 :         printChunkSummary_p = true;
     141        1707 :         summaryThreshold_p = summaryThresholdInc_p;
     142        1707 :         chunkLineThreshold_p = chunkLineThresholdInc_p;;
     143             : 
     144             :         // Set all the initialized pointers to NULL
     145        1707 :         measurementSetSelection_p = NULL;
     146        1707 :         visibilityBuffer_p = NULL;
     147        1707 :         antennaNames_p = NULL;
     148        1707 :         antennaPositions_p = NULL;
     149        1707 :         antennaDiameters_p = NULL;
     150        1707 :         antennaPairMap_p = NULL;
     151        1707 :         subIntegrationMap_p = NULL;
     152        1707 :         corrProducts_p = NULL;
     153        1707 :         polarizationMap_p = NULL;
     154        1707 :         polarizationIndexMap_p = NULL;
     155        1707 :         antennaPointingMap_p = NULL;
     156        1707 :         scanStartStopMap_p = NULL;
     157        1707 :         lambdaMap_p = NULL;
     158        1707 :         fieldNames_p = NULL;
     159             : 
     160             :         // Initialize table characteristics
     161        1707 :         tableTye_p = MEASUREMENT_SET;
     162        1707 :         processorTableExist_p = true;
     163             : 
     164             :         // Initialize FlagDataHanler-FlagAgents state
     165        1707 :         flushFlags_p = false;
     166        1707 :         flushFlagRow_p = false;
     167        1707 :         loadProcessorTable_p = false;
     168             : 
     169             :         // Initialize time averaging options
     170        1707 :     timeAvgOptions_p = vi::AveragingOptions(vi::AveragingOptions::Nothing);
     171        1707 :     enableTimeAvg_p = false;
     172        1707 :     enableChanAvg_p = false;
     173             : 
     174        1707 :         return;
     175             : }
     176             : 
     177             : 
     178             : // -----------------------------------------------------------------------
     179             : // Default destructor
     180             : // -----------------------------------------------------------------------
     181        1707 : FlagDataHandler::~FlagDataHandler()
     182             : {
     183        1707 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     184        1707 :         *logger_p << LogIO::DEBUG1 << "FlagDataHandler::~FlagDataHandler()" << LogIO::POST;
     185             : 
     186             :         // Delete logger
     187        1707 :         if (logger_p) delete logger_p;
     188             : 
     189             :         // Delete MS objects
     190        1707 :         if (measurementSetSelection_p) delete measurementSetSelection_p;
     191             : 
     192             :         // Delete mapping members
     193        1707 :         if (antennaNames_p) delete antennaNames_p;
     194        1707 :         if (antennaPositions_p) delete antennaPositions_p;
     195        1707 :         if (antennaDiameters_p) delete antennaDiameters_p;
     196        1707 :         if (antennaPairMap_p) delete antennaPairMap_p;
     197        1707 :         if (subIntegrationMap_p) delete subIntegrationMap_p;
     198        1707 :         if (corrProducts_p) delete corrProducts_p;
     199        1707 :         if (polarizationMap_p) delete polarizationMap_p;
     200        1707 :         if (polarizationIndexMap_p) delete polarizationIndexMap_p;
     201        1707 :         if (antennaPointingMap_p) delete antennaPointingMap_p;
     202        1707 :         if (scanStartStopMap_p) delete scanStartStopMap_p;
     203        1707 :         if (lambdaMap_p) delete lambdaMap_p;
     204        1707 :         if (fieldNames_p) delete fieldNames_p;
     205             : 
     206        1707 :         return;
     207        1707 : }
     208             : 
     209             : 
     210             : // -----------------------------------------------------------------------
     211             : // Set iteration Approach
     212             : // -----------------------------------------------------------------------
     213             : void
     214        1794 : FlagDataHandler::setIterationApproach(uShort iterationApproach)
     215             : {
     216        1794 :         iterationApproach_p = iterationApproach;
     217             : 
     218        1794 :         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          87 :                 case COMPLETE_SCAN_MAP_ANTENNA_PAIRS_ONLY:
     258             :                 {
     259          87 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMPLETE_SCAN_MAP_ANTENNA_PAIRS_ONLY" << LogIO::POST;
     260          87 :                         sortOrder_p = Block<int>(6);
     261          87 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     262          87 :                         sortOrder_p[1] = MS::ARRAY_ID;
     263          87 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     264          87 :                         sortOrder_p[3] = MS::FIELD_ID;
     265          87 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     266          87 :                         sortOrder_p[5] = MS::TIME;
     267             : 
     268             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     269          87 :                         groupTimeSteps_p = true;
     270          87 :                         mapAntennaPairs_p = true;
     271          87 :                         mapSubIntegrations_p = false;
     272          87 :                         setMapAntennaPairs(true);
     273          87 :                         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        1707 :                 case  SUB_INTEGRATION:
     383             :                 {
     384        1707 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: SUB_INTEGRATION" << LogIO::POST;
     385        1707 :                         sortOrder_p = Block<int>(6);
     386        1707 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     387        1707 :                         sortOrder_p[1] = MS::ARRAY_ID;
     388        1707 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     389        1707 :                         sortOrder_p[3] = MS::FIELD_ID;
     390        1707 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     391        1707 :                         sortOrder_p[5] = MS::TIME;
     392             : 
     393             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     394        1707 :                         groupTimeSteps_p = false;
     395        1707 :                         mapAntennaPairs_p = false;
     396        1707 :                         mapSubIntegrations_p = false;
     397        1707 :                         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        1794 :         iteratorGenerated_p = false;
     435        1794 :         chunksInitialized_p = false;
     436        1794 :         buffersInitialized_p = false;
     437        1794 :         stopIteration_p = false;
     438             : 
     439        1794 :         return;
     440             : }
     441             : 
     442             : // -----------------------------------------------------------------------
     443             : // Mapping functions as requested by Urvashi
     444             : // -----------------------------------------------------------------------
     445             : void
     446         845 : FlagDataHandler::generateAntennaPairMap()
     447             : {
     448         845 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     449             : 
     450             :         // Free previous map and create a new one
     451         845 :         if (antennaPairMap_p) delete antennaPairMap_p;
     452         845 :         antennaPairMap_p = new antennaPairMap();
     453             : 
     454             :         // Retrieve antenna vectors
     455        1690 :         Vector<Int> antenna1Vector = visibilityBuffer_p->antenna1();
     456        1690 :         Vector<Int> antenna2Vector = visibilityBuffer_p->antenna2();
     457             : 
     458             :         // Fill map
     459             :         Int ant1_i,ant2_i;
     460         845 :         uInt nRows = antenna1Vector.size();
     461      496470 :         for (uInt row_idx=0;row_idx<nRows;row_idx++)
     462             :         {
     463      495625 :                 ant1_i = antenna1Vector[row_idx];
     464      495625 :                 ant2_i = antenna2Vector[row_idx];
     465      495625 :                 if (antennaPairMap_p->find(std::make_pair(ant1_i,ant2_i)) == antennaPairMap_p->end())
     466             :                 {
     467       13499 :                         std::vector<uInt> newPair;
     468       13499 :                         newPair.push_back(row_idx);
     469       13499 :                         (*antennaPairMap_p)[std::make_pair(ant1_i,ant2_i)] = newPair;
     470             :                 }
     471             :                 else
     472             :                 {
     473      482126 :                         (*antennaPairMap_p)[std::make_pair(ant1_i,ant2_i)].push_back(row_idx);
     474             :                 }
     475             :         }
     476         845 :         *logger_p << LogIO::DEBUG1 <<  " " << antennaPairMap_p->size() <<" Antenna pairs found in current buffer" << LogIO::POST;
     477             : 
     478        1690 :         return;
     479             : }
     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             :                 }
     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             : }
     513             : 
     514             : 
     515             : void
     516      600713 : FlagDataHandler::generatePolarizationsMap()
     517             : {
     518      600713 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     519             : 
     520             :         // Free previous map and create a new one
     521      600713 :         if (polarizationMap_p) delete polarizationMap_p;
     522      600713 :         polarizationMap_p = new polarizationMap();
     523      600713 :         if (polarizationIndexMap_p) delete polarizationIndexMap_p;
     524      600713 :         polarizationIndexMap_p = new polarizationIndexMap();
     525             : 
     526      600713 :         uShort pos = 0;
     527     1201426 :         Vector<Int> corrTypes = visibilityBuffer_p->correlationTypes();
     528             : 
     529      600713 :         const auto logprio = logger_p->priority();
     530      600713 :         if (logprio <= LogMessage::DEBUG2)
     531           0 :             *logger_p << LogIO::DEBUG2 << " Correlation type: " <<  corrTypes << LogIO::POST;
     532             : 
     533     2824930 :         for (Vector<Int>::iterator iter = corrTypes.begin(); iter != corrTypes.end();iter++)
     534             :         {
     535     2224217 :                 switch (*iter)
     536             :                 {
     537        1384 :                         case Stokes::I:
     538             :                         {
     539        1384 :                             if (logprio <= LogMessage::DEBUG2)
     540           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is I" << LogIO::POST;
     541        1384 :                             (*polarizationMap_p)[Stokes::I] = pos;
     542        1384 :                             (*polarizationIndexMap_p)[pos] = "I";
     543        1384 :                             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       64740 :                         case Stokes::XX:
     570             :                         {
     571       64740 :                             if (logprio <= LogMessage::DEBUG2)
     572           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is XX" << LogIO::POST;
     573       64740 :                             (*polarizationMap_p)[Stokes::XX] = pos;
     574       64740 :                             (*polarizationIndexMap_p)[pos] = "XX";
     575       64740 :                             break;
     576             :                         }
     577       58991 :                         case Stokes::YY:
     578             :                         {
     579       58991 :                             if (logprio <= LogMessage::DEBUG2)
     580           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is YY" << LogIO::POST;
     581       58991 :                             (*polarizationMap_p)[Stokes::YY] = pos;
     582       58991 :                             (*polarizationIndexMap_p)[pos] = "YY";
     583       58991 :                             break;
     584             :                         }
     585       17890 :                         case Stokes::XY:
     586             :                         {
     587       17890 :                             if (logprio <= LogMessage::DEBUG2)
     588           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is XY" << LogIO::POST;
     589       17890 :                             (*polarizationMap_p)[Stokes::XY] = pos;
     590       17890 :                             (*polarizationIndexMap_p)[pos] = "XY";
     591       17890 :                             break;
     592             :                         }
     593       17890 :                         case Stokes::YX:
     594             :                         {
     595       17890 :                             if (logprio <= LogMessage::DEBUG2)
     596           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is YX" << LogIO::POST;
     597       17890 :                             (*polarizationMap_p)[Stokes::YX] = pos;
     598       17890 :                             (*polarizationIndexMap_p)[pos] = "YX";
     599       17890 :                             break;
     600             :                         }
     601      522044 :                         case Stokes::RR:
     602             :                         {
     603      522044 :                             if (logprio <= LogMessage::DEBUG2)
     604           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is RR" << LogIO::POST;
     605      522044 :                             (*polarizationMap_p)[Stokes::RR] = pos;
     606      522044 :                             (*polarizationIndexMap_p)[pos] = "RR";
     607      522044 :                             break;
     608             :                         }
     609      523448 :                         case Stokes::LL:
     610             :                         {
     611      523448 :                             if (logprio <= LogMessage::DEBUG2)
     612           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is LL" << LogIO::POST;
     613      523448 :                             (*polarizationMap_p)[Stokes::LL] = pos;
     614      523448 :                             (*polarizationIndexMap_p)[pos] = "LL";
     615      523448 :                             break;
     616             :                         }
     617      498532 :                         case Stokes::RL:
     618             :                         {
     619      498532 :                             if (logprio <= LogMessage::DEBUG2)
     620           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is RL" << LogIO::POST;
     621      498532 :                             (*polarizationMap_p)[Stokes::RL] = pos;
     622      498532 :                             (*polarizationIndexMap_p)[pos] = "RL";
     623      498532 :                             break;
     624             :                         }
     625      498532 :                         case Stokes::LR:
     626             :                         {
     627      498532 :                             if (logprio <= LogMessage::DEBUG2)
     628           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is LR" << LogIO::POST;
     629      498532 :                             (*polarizationMap_p)[Stokes::LR] = pos;
     630      498532 :                             (*polarizationIndexMap_p)[pos] = "LR";
     631      498532 :                             break;
     632             :                         }
     633       10383 :                         case VisMapper::CALSOL1:
     634             :                         {
     635       10383 :                             if (logprio <= LogMessage::DEBUG2)
     636           0 :                                 *logger_p << LogIO::DEBUG2 << " Calibration solution 1 found at " << pos << LogIO::POST;
     637       10383 :                             (*polarizationMap_p)[VisMapper::CALSOL1] = pos;
     638       10383 :                             (*polarizationIndexMap_p)[pos] = "Sol1";
     639       10383 :                             break;
     640             :                         }
     641       10383 :                         case VisMapper::CALSOL2:
     642             :                         {
     643       10383 :                             if (logprio <= LogMessage::DEBUG2)
     644           0 :                                 *logger_p << LogIO::DEBUG2 << " Calibration solution 2 found at " << pos << LogIO::POST;
     645       10383 :                             (*polarizationMap_p)[VisMapper::CALSOL2] = pos;
     646       10383 :                             (*polarizationIndexMap_p)[pos] = "Sol2";
     647       10383 :                             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     2224217 :                 pos++;
     672             :         }
     673             : 
     674      600713 :         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      600713 : }
     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             :         }
     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             : }
     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        1291 : FlagDataHandler::setDataSelection(Record record)
     731             : {
     732        1291 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     733             : 
     734             :         int exists;
     735             : 
     736        1291 :         exists = record.fieldNumber ("array");
     737        1291 :         if (exists >= 0)
     738             :         {
     739        1223 :                 anySelection_p = true;
     740        1223 :                 record.get (record.fieldNumber ("array"), arraySelection_p);
     741             : 
     742        1223 :                 if (arraySelection_p.size())
     743             :                 {
     744           1 :                         *logger_p << LogIO::DEBUG1 << " array selection is " << arraySelection_p << LogIO::POST;
     745             :                 }
     746             :         }
     747             :         else
     748             :         {
     749          68 :                 arraySelection_p = String("");
     750          68 :                 *logger_p << LogIO::DEBUG1 << " no array selection" << LogIO::POST;
     751             :         }
     752             : 
     753        1291 :         exists = record.fieldNumber ("field");
     754        1291 :         if (exists >= 0)
     755             :         {
     756        1226 :                 anySelection_p = true;
     757        1226 :                 record.get (record.fieldNumber ("field"), fieldSelection_p);
     758             : 
     759        1226 :                 if (fieldSelection_p.size())
     760             :                 {
     761          15 :                         *logger_p << LogIO::DEBUG1 << " field selection is " << fieldSelection_p << LogIO::POST;
     762             :                 }
     763             :         }
     764             :         else
     765             :         {
     766          65 :                 fieldSelection_p = String("");
     767          65 :                 *logger_p << LogIO::DEBUG1 << " no field selection" << LogIO::POST;
     768             :         }
     769             : 
     770        1291 :         exists = record.fieldNumber ("scan");
     771        1291 :         if (exists >= 0)
     772             :         {
     773        1259 :                 anySelection_p = true;
     774        1259 :                 record.get (record.fieldNumber ("scan"), scanSelection_p);
     775             : 
     776        1259 :                 if (scanSelection_p.size())
     777             :                 {
     778          77 :                         *logger_p << LogIO::DEBUG1 << " scan selection is " << scanSelection_p << LogIO::POST;
     779             :                 }
     780             :         }
     781             :         else
     782             :         {
     783          32 :                 scanSelection_p = String("");
     784          32 :                 *logger_p << LogIO::DEBUG1 << " no scan selection" << LogIO::POST;
     785             :         }
     786             : 
     787        1291 :         exists = record.fieldNumber ("timerange");
     788        1291 :         if (exists >= 0)
     789             :         {
     790        1227 :                 anySelection_p = true;
     791        1227 :                 record.get (record.fieldNumber ("timerange"), timeSelection_p);
     792             : 
     793        1227 :                 if (timeSelection_p.size())
     794             :                 {
     795          15 :                         *logger_p << LogIO::DEBUG1 << " timerange selection is " << timeSelection_p << LogIO::POST;
     796             :                 }
     797             :         }
     798             :         else
     799             :         {
     800          64 :                 timeSelection_p = String("");
     801          64 :                 *logger_p << LogIO::DEBUG1 << " no timerange selection" << LogIO::POST;
     802             :         }
     803             : 
     804        1291 :         exists = record.fieldNumber ("spw");
     805        1291 :         if (exists >= 0)
     806             :         {
     807        1243 :                 anySelection_p = true;
     808        1243 :                 record.get (record.fieldNumber ("spw"), spwSelection_p);
     809             : 
     810        1243 :                 if (spwSelection_p.size())
     811             :                 {
     812         177 :                         *logger_p << LogIO::DEBUG1 << " spw selection is " << spwSelection_p << LogIO::POST;
     813             :                 }
     814             :         }
     815             :         else
     816             :         {
     817          48 :                 spwSelection_p = String("");
     818          48 :                 *logger_p << LogIO::DEBUG1 << " no spw selection" << LogIO::POST;
     819             :         }
     820             : 
     821        1291 :         exists = record.fieldNumber ("antenna");
     822        1291 :         if (exists >= 0)
     823             :         {
     824        1226 :                 anySelection_p = true;
     825        1226 :                 record.get (record.fieldNumber ("antenna"), baselineSelection_p);
     826             : 
     827        1226 :                 if (baselineSelection_p.size())
     828             :                 {
     829          48 :                         *logger_p << LogIO::DEBUG1 << " antenna selection is " << baselineSelection_p << LogIO::POST;
     830             :                 }
     831             :         }
     832             :         else
     833             :         {
     834          65 :                 baselineSelection_p = String("");
     835          65 :                 *logger_p << LogIO::DEBUG1 << " no antenna selection" << LogIO::POST;
     836             :         }
     837             : 
     838        1291 :         exists = record.fieldNumber ("uvrange");
     839        1291 :         if (exists >= 0)
     840             :         {
     841        1223 :                 anySelection_p = true;
     842        1223 :                 record.get (record.fieldNumber ("uvrange"), uvwSelection_p);
     843             : 
     844        1223 :                 if (uvwSelection_p.size())
     845             :                 {
     846           2 :                         *logger_p << LogIO::DEBUG1 << " uvrange selection is " << uvwSelection_p << LogIO::POST;
     847             :                 }
     848             :         }
     849             :         else
     850             :         {
     851          68 :                 uvwSelection_p = String("");
     852          68 :                 *logger_p << LogIO::DEBUG1 << " no uvrange selection" << LogIO::POST;
     853             :         }
     854             : 
     855        1291 :         exists = record.fieldNumber ("correlation");
     856        1291 :         if (exists >= 0)
     857             :         {
     858        1223 :                 anySelection_p = true;
     859        1223 :                 record.get (record.fieldNumber ("correlation"), polarizationSelection_p);
     860             : 
     861        1223 :                 if (polarizationSelection_p.size())
     862             :                 {
     863           0 :                         *logger_p << LogIO::DEBUG1 << " correlation selection is " << polarizationSelection_p << LogIO::POST;
     864             :                 }
     865             :         }
     866             :         else
     867             :         {
     868          68 :                 polarizationSelection_p = String("");
     869          68 :                 *logger_p << LogIO::DEBUG1 << " no correlation selection" << LogIO::POST;
     870             :         }
     871             : 
     872        1291 :         exists = record.fieldNumber ("observation");
     873        1291 :         if (exists >= 0)
     874             :         {
     875        1227 :                 anySelection_p = true;
     876        1227 :                 record.get (record.fieldNumber ("observation"), observationSelection_p);
     877             : 
     878        1227 :                 if (observationSelection_p.size())
     879             :                 {
     880          11 :                         *logger_p << LogIO::DEBUG1 << " observation selection is " << observationSelection_p << LogIO::POST;
     881             :                 }
     882             :         }
     883             :         else
     884             :         {
     885          64 :                 observationSelection_p = String("");
     886          64 :                 *logger_p << LogIO::DEBUG1 << " no observation selection" << LogIO::POST;
     887             :         }
     888             : 
     889        1291 :         exists = record.fieldNumber ("intent");
     890        1291 :         if (exists >= 0)
     891             :         {
     892        1224 :                 anySelection_p = true;
     893        1224 :                 record.get (record.fieldNumber ("intent"), scanIntentSelection_p);
     894             : 
     895        1224 :                 if (scanIntentSelection_p.size())
     896             :                 {
     897           3 :                         *logger_p << LogIO::DEBUG1 << " scan intent selection is " << scanIntentSelection_p << LogIO::POST;
     898             :                 }
     899             :         }
     900             :         else
     901             :         {
     902          67 :                 scanIntentSelection_p = String("");
     903          67 :                 *logger_p << LogIO::DEBUG1 << " no scan intent selection" << LogIO::POST;
     904             :         }
     905             : 
     906        1291 :         return true;
     907             : }
     908             : 
     909             : 
     910             : // -----------------------------------------------------------------------
     911             : // Set time interval
     912             : // -----------------------------------------------------------------------
     913             : void
     914        1794 : FlagDataHandler::setTimeInterval(Double timeInterval)
     915             : {
     916        1794 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     917        1794 :         if (timeInterval >= 0)
     918             :         {
     919        1794 :                 timeInterval_p = timeInterval;
     920        1794 :                 *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        1794 :         return;
     928             : }
     929             : 
     930             : 
     931             : // -----------------------------------------------------------------------
     932             : // Enable async i/o
     933             : // -----------------------------------------------------------------------
     934             : void
     935        1902 : FlagDataHandler::enableAsyncIO(Bool enable)
     936             : {
     937        1902 :         if (enable)
     938             :         {
     939             :                 // Check if async i/o is enabled (double check for ROVisibilityIteratorAsync and FlagDataHandler config)
     940         195 :                 asyncio_enabled_p = vi::VisibilityIterator2::isAsynchronousIoEnabled();
     941             : 
     942         195 :                 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         195 :                         *logger_p << LogIO::DEBUG1
     959             :                                   << " Asynchronous i/o not enabled for FlagDataHandler and CASA in general."
     960         195 :                                   << LogIO::POST;
     961             :                 }
     962             :         }
     963             :         else
     964             :         {
     965        1707 :                 asyncio_enabled_p = false;
     966             :         }
     967             : 
     968             : 
     969        1902 :         if (!asyncio_enabled_p)
     970             :         {
     971        1902 :                 slurp_p = true;
     972        1902 :                 AipsrcValue<Bool>::find (slurp_p,"FlagDataHandler.slurp", true);
     973             :         }
     974             :         else
     975             :         {
     976           0 :                 slurp_p = false;
     977             :         }
     978             : 
     979        1902 :         return;
     980             : }
     981             : 
     982             : 
     983             : // -----------------------------------------------------------------------
     984             : // Function to handled columns pre-load (to avoid problems with parallelism)
     985             : // -----------------------------------------------------------------------
     986             : void
     987        8423 : FlagDataHandler::preLoadColumn(VisBufferComponent2 column)
     988             : {
     989        8423 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     990             : 
     991        8423 :         if (std::find (preLoadColumns_p.begin(), preLoadColumns_p.end(), column) == preLoadColumns_p.end())
     992             :         {
     993        1976 :                 *logger_p << LogIO::DEBUG1 << " Adding column to list: "
     994        1976 :                           << VisBufferComponents2::name (column) << LogIO::POST;
     995        1976 :                 preLoadColumns_p.push_back(column);
     996             :         }
     997             : 
     998        8423 :         return;
     999             : }
    1000             : 
    1001             : 
    1002             : // -----------------------------------------------------------------------
    1003             : // Fill pre-fetch columns
    1004             : // -----------------------------------------------------------------------
    1005             : void
    1006      600713 : FlagDataHandler::preFetchColumns()
    1007             : {
    1008     5957166 :         for (vector<VisBufferComponent2>::iterator iter=preLoadColumns_p.begin();iter!=preLoadColumns_p.end();iter++)
    1009             :         {
    1010     5356453 :                 switch (*iter)
    1011             :                 {
    1012      151663 :                         case VisBufferComponent2::Antenna1:
    1013             :                         {
    1014      151663 :                                 if (asyncio_enabled_p)
    1015             :                                 {
    1016           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Antenna1);
    1017             :                                 }
    1018             :                                 else
    1019             :                                 {
    1020      151663 :                                         visibilityBuffer_p->antenna1();
    1021             :                                 }
    1022      151663 :                                 break;
    1023             :                         }
    1024      151663 :                         case VisBufferComponent2::Antenna2:
    1025             :                         {
    1026      151663 :                                 if (asyncio_enabled_p)
    1027             :                                 {
    1028           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Antenna2);
    1029             :                                 }
    1030             :                                 else
    1031             :                                 {
    1032      151663 :                                         visibilityBuffer_p->antenna2();
    1033             :                                 }
    1034      151663 :                                 break;
    1035             :                         }
    1036      600713 :                         case VisBufferComponent2::ArrayId:
    1037             :                         {
    1038      600713 :                                 if (asyncio_enabled_p)
    1039             :                                 {
    1040           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ArrayId);
    1041             :                                 }
    1042             :                                 else
    1043             :                                 {
    1044      600713 :                                         visibilityBuffer_p->arrayId();
    1045             :                                 }
    1046      600713 :                                 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      154910 :                         case VisBufferComponent2::CorrType:
    1075             :                         {
    1076      154910 :                                 if (asyncio_enabled_p)
    1077             :                                 {
    1078           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::CorrType);
    1079             :                                 }
    1080             :                                 else
    1081             :                                 {
    1082      154910 :                                         visibilityBuffer_p->correlationTypes();
    1083             :                                 }
    1084      154910 :                                 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        6629 :                         case VisBufferComponent2::VisibilityCubeCorrected:
    1099             :                         {
    1100        6629 :                                 if (asyncio_enabled_p)
    1101             :                                 {
    1102           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeCorrected);
    1103             :                                 }
    1104             :                                 else
    1105             :                                 {
    1106        6629 :                                         visibilityBuffer_p->visCubeCorrected();
    1107             :                                 }
    1108        6629 :                                 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      600713 :                         case VisBufferComponent2::FieldId:
    1195             :                         {
    1196      600713 :                                 if (asyncio_enabled_p)
    1197             :                                 {
    1198           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::FieldId);
    1199             :                                 }
    1200             :                                 else
    1201             :                                 {
    1202      600713 :                                         visibilityBuffer_p->fieldId();
    1203             :                                 }
    1204      600713 :                                 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        3444 :                         case VisBufferComponent2::VisibilityCubeModel:
    1293             :                         {
    1294        3444 :                                 if (asyncio_enabled_p)
    1295             :                                 {
    1296           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeModel);
    1297             :                                 }
    1298             :                                 else
    1299             :                                 {
    1300        3444 :                                         visibilityBuffer_p->visCubeModel();
    1301             :                                 }
    1302        3444 :                                 break;
    1303             :                         }
    1304      600713 :                         case VisBufferComponent2::NChannels:
    1305             :                         {
    1306      600713 :                                 if (asyncio_enabled_p)
    1307             :                                 {
    1308           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NChannels);
    1309             :                                 }
    1310             :                                 else
    1311             :                                 {
    1312      600713 :                                         visibilityBuffer_p->nChannels();
    1313             :                                 }
    1314      600713 :                                 break;
    1315             :                         }
    1316      600713 :                         case VisBufferComponent2::NCorrelations:
    1317             :                         {
    1318      600713 :                                 if (asyncio_enabled_p)
    1319             :                                 {
    1320           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NCorrelations);
    1321             :                                 }
    1322             :                                 else
    1323             :                                 {
    1324      600713 :                                         visibilityBuffer_p->nCorrelations();
    1325             :                                 }
    1326      600713 :                                 break;
    1327             :                         }
    1328      600713 :                         case VisBufferComponent2::NRows:
    1329             :                         {
    1330      600713 :                                 if (asyncio_enabled_p)
    1331             :                                 {
    1332           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NRows);
    1333             :                                 }
    1334             :                                 else
    1335             :                                 {
    1336      600713 :                                         visibilityBuffer_p->nRows();
    1337             :                                 }
    1338      600713 :                                 break;
    1339             :                         }
    1340      600713 :                         case VisBufferComponent2::ObservationId:
    1341             :                         {
    1342      600713 :                                 if (asyncio_enabled_p)
    1343             :                                 {
    1344           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ObservationId);
    1345             :                                 }
    1346             :                                 else
    1347             :                                 {
    1348      600713 :                                         visibilityBuffer_p->observationId();
    1349             :                                 }
    1350      600713 :                                 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       31575 :                         case VisBufferComponent2::VisibilityCubeObserved:
    1365             :                         {
    1366       31575 :                                 if (asyncio_enabled_p)
    1367             :                                 {
    1368           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeObserved);
    1369             :                                 }
    1370             :                                 else
    1371             :                                 {
    1372       31575 :                                         visibilityBuffer_p->visCube();
    1373             :                                 }
    1374       31575 :                                 break;
    1375             :                         }
    1376        2014 :                         case VisBufferComponent2::PhaseCenter:
    1377             :                         {
    1378        2014 :                                 if (asyncio_enabled_p)
    1379             :                                 {
    1380           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::PhaseCenter);
    1381             :                                 }
    1382             :                                 else
    1383             :                                 {
    1384        2014 :                                         visibilityBuffer_p->phaseCenter();
    1385             :                                 }
    1386        2014 :                                 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         637 :                         case VisBufferComponent2::ProcessorId:
    1401             :                         {
    1402         637 :                                 if (asyncio_enabled_p)
    1403             :                                 {
    1404           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ProcessorId);
    1405             :                                 }
    1406             :                                 else
    1407             :                                 {
    1408         637 :                                         visibilityBuffer_p->processorId();
    1409             :                                 }
    1410         637 :                                 break;
    1411             :                         }
    1412      600713 :                         case VisBufferComponent2::Scan:
    1413             :                         {
    1414      600713 :                                 if (asyncio_enabled_p)
    1415             :                                 {
    1416           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Scan);
    1417             :                                 }
    1418             :                                 else
    1419             :                                 {
    1420      600713 :                                         visibilityBuffer_p->scan();
    1421             :                                 }
    1422      600713 :                                 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      600713 :                         case VisBufferComponent2::SpectralWindows:
    1449             :                         {
    1450      600713 :                                 if (asyncio_enabled_p)
    1451             :                                 {
    1452           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::SpectralWindows);
    1453             :                                 }
    1454             :                                 else
    1455             :                                 {
    1456      600713 :                                         visibilityBuffer_p->spectralWindows();
    1457             :                                 }
    1458      600713 :                                 break;
    1459             :                         }
    1460         142 :                         case VisBufferComponent2::StateId:
    1461             :                         {
    1462         142 :                                 if (asyncio_enabled_p)
    1463             :                                 {
    1464           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::StateId);
    1465             :                                 }
    1466             :                                 else
    1467             :                                 {
    1468         142 :                                         visibilityBuffer_p->stateId();
    1469             :                                 }
    1470         142 :                                 break;
    1471             :                         }
    1472       41151 :                         case VisBufferComponent2::Time:
    1473             :                         {
    1474       41151 :                                 if (asyncio_enabled_p)
    1475             :                                 {
    1476           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Time);
    1477             :                                 }
    1478             :                                 else
    1479             :                                 {
    1480       41151 :                                         visibilityBuffer_p->time();
    1481             :                                 }
    1482       41151 :                                 break;
    1483             :                         }
    1484        2014 :                         case VisBufferComponent2::TimeCentroid:
    1485             :                         {
    1486        2014 :                                 if (asyncio_enabled_p)
    1487             :                                 {
    1488           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::TimeCentroid);
    1489             :                                 }
    1490             :                                 else
    1491             :                                 {
    1492        2014 :                                         visibilityBuffer_p->timeCentroid();
    1493             :                                 }
    1494        2014 :                                 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          29 :                         case VisBufferComponent2::WeightSpectrum:
    1533             :                         {
    1534          29 :                                 if (asyncio_enabled_p)
    1535             :                                 {
    1536           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::WeightSpectrum);
    1537             :                                 }
    1538             :                                 else
    1539             :                                 {
    1540          29 :                                         visibilityBuffer_p->weightSpectrum();
    1541             :                                 }
    1542          29 :                                 break;
    1543             :                         }
    1544        4878 :                         case VisBufferComponent2::Uvw:
    1545             :                         {
    1546        4878 :                                 if (asyncio_enabled_p)
    1547             :                                 {
    1548           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Uvw);
    1549             :                                 }
    1550             :                                 else
    1551             :                                 {
    1552        4878 :                                         visibilityBuffer_p->uvw();
    1553             :                                 }
    1554        4878 :                                 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      600713 :         return;
    1605             : }
    1606             : 
    1607             : 
    1608             : // -----------------------------------------------------------------------
    1609             : // Methods to trigger generation of different maps
    1610             : // -----------------------------------------------------------------------
    1611             : void
    1612          87 : FlagDataHandler::setMapAntennaPairs(bool activated)
    1613             : {
    1614          87 :         mapAntennaPairs_p=activated;
    1615             :         // Pre-Load antenna1, antenna2
    1616          87 :         preLoadColumn(VisBufferComponent2::Antenna1);
    1617          87 :         preLoadColumn(VisBufferComponent2::Antenna2);
    1618          87 : }
    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         622 : FlagDataHandler::setMapPolarizations(bool activated)
    1632             : {
    1633         622 :         mapPolarizations_p=activated;
    1634             :         // Pre-Load corrType
    1635         622 :         preLoadColumn(VisBufferComponent2::CorrType);
    1636         622 : }
    1637             : 
    1638             : 
    1639             : void
    1640           8 : 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           8 :         preLoadColumn(VisBufferComponent2::Time);
    1650           8 :         preLoadColumn(VisBufferComponent2::Antenna1);
    1651           8 :         preLoadColumn(VisBufferComponent2::Antenna2);
    1652           8 : }
    1653             : 
    1654             : 
    1655             : void
    1656          17 : FlagDataHandler::setScanStartStopMap(bool activated)
    1657             : {
    1658          17 :         mapScanStartStop_p=activated;
    1659             :         // Pre-Load scan and time
    1660          17 :         preLoadColumn(VisBufferComponent2::Scan);
    1661          17 :         preLoadColumn(VisBufferComponent2::Time);
    1662          17 : }
    1663             : 
    1664             : 
    1665             : void
    1666           5 : FlagDataHandler::setScanStartStopFlaggedMap(bool activated)
    1667             : {
    1668           5 :         mapScanStartStopFlagged_p=activated;
    1669             :         // Pre-Load scan and time
    1670           5 :         preLoadColumn(VisBufferComponent2::Scan);
    1671           5 :         preLoadColumn(VisBufferComponent2::Time);
    1672           5 : }
    1673             : 
    1674             : // ----------------------------------------------------------------------------
    1675             : //  Set the time averaging iterator options for the visibility agents (clip, rflag, tfcrop)
    1676             : // ----------------------------------------------------------------------------
    1677             : void
    1678          32 : FlagDataHandler::setTimeAverageIter(bool activated)
    1679             : {
    1680          32 :     enableTimeAvg_p = activated;
    1681             : 
    1682             :     // Setup the time averaging options
    1683          32 :     if (dataColumnType_p == "DATA")
    1684             :     {
    1685          31 :         timeAvgOptions_p |= vi::AveragingOptions::AverageObserved;
    1686          31 :         timeAvgOptions_p |= vi::AveragingOptions::ObservedFlagWeightAvgFromSIGMA;
    1687             :     }
    1688           1 :     else if (dataColumnType_p == "CORRECTED")
    1689             :     {
    1690           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageCorrected;
    1691           0 :         timeAvgOptions_p |= vi::AveragingOptions::CorrectedFlagWeightAvgFromWEIGHT;
    1692             :     }
    1693           1 :     else if (dataColumnType_p == "MODEL")
    1694             :     {
    1695           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageModel;
    1696           0 :         timeAvgOptions_p |= vi::AveragingOptions::ModelPlainAvg;
    1697             :     }
    1698           1 :     else if (dataColumnType_p == "FLOAT_DATA")
    1699             :     {
    1700           0 :         timeAvgOptions_p |= vi::AveragingOptions::AverageFloat;
    1701             :     }
    1702           1 :     else if (dataColumnType_p == "RESIDUAL")
    1703             :     {
    1704           1 :         timeAvgOptions_p |= vi::AveragingOptions::AverageCorrected;
    1705           1 :         timeAvgOptions_p |= vi::AveragingOptions::CorrectedFlagWeightAvgFromWEIGHT;
    1706           1 :         timeAvgOptions_p |= vi::AveragingOptions::AverageModel;
    1707           1 :         timeAvgOptions_p |= vi::AveragingOptions::ModelFlagWeightAvgFromWEIGHT;
    1708             :     }
    1709             : 
    1710             :     // ensure preservation of flags (CAS-12737, CAS-12205, CAS-9985)
    1711          32 :     timeAvgOptions_p |= vi::AveragingOptions::flagdataFlagPropagation;
    1712          32 : }
    1713             : 
    1714             : // ----------------------------------------------------------------------------
    1715             : //  Set the channel averaging iterator options for the visibility agents (clip, rflag, tfcrop)
    1716             : // ----------------------------------------------------------------------------
    1717             : void
    1718          33 : FlagDataHandler::setChanAverageIter(Vector<Int> chanbin)
    1719             : {
    1720          33 :     enableChanAvg_p = true;
    1721             : 
    1722             :     // Store chanbin
    1723          33 :     if (chanbin.size() == 1)
    1724             :     {
    1725          33 :         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          33 :     chanAvgOptions_p.define("flagdataFlagPropagation", true);
    1734             : 
    1735          33 :     return;
    1736             : }
    1737             : 
    1738             : // -----------------------------------------------------------------------
    1739             : // Get the WEIGHT_SPECTRUM visCube as a Complex
    1740             : // -----------------------------------------------------------------------
    1741             : Cube<Complex>&
    1742          30 : FlagDataHandler::weightVisCube()
    1743             : {
    1744             : 
    1745          60 :         Cube<Float> tmp = visibilityBuffer_p->weightSpectrum();
    1746             : 
    1747             :         // Transform Cube<Float> into Cube<Complex>
    1748          30 :         Cube<Complex> tmpTrans(tmp.shape());
    1749          30 :         tmpTrans(tmp.shape());
    1750          78 :         for (uInt idx1=0;idx1<tmp.shape()[0];idx1++)
    1751             :         {
    1752        1236 :                 for (uInt idx2=0;idx2<tmp.shape()[1];idx2++)
    1753             :                 {
    1754        2748 :                         for (uInt idx3=0;idx3<tmp.shape()[2];idx3++)
    1755             :                         {
    1756        1560 :                                 tmpTrans(idx1,idx2,idx3) = Complex(tmp(idx1,idx2,idx3),0);
    1757             :                         }
    1758             :                 }
    1759             :         }
    1760             : 
    1761          30 :         weight_spectrum_p.resize(tmpTrans.shape(),false);
    1762          30 :         weight_spectrum_p = tmpTrans;
    1763             : 
    1764          60 :         return weight_spectrum_p;
    1765             : }
    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       30768 : VisMapper::VisMapper(String expression,polarizationMap *polMap)
    1780             : {
    1781       30768 :         rightVis_p = NULL;
    1782       30768 :         leftVis_p = NULL;
    1783       30768 :         setExpressionMapping(expression,polMap);
    1784       30768 : }
    1785             : 
    1786             : 
    1787             : void
    1788       47256 : VisMapper::setParentCubes(CubeView<Complex> *leftVis,CubeView<Complex> *rightVis)
    1789             : {
    1790       47256 :         if (rightVis_p != NULL) delete rightVis_p;
    1791       47256 :         if (leftVis_p != NULL) delete leftVis_p;
    1792             : 
    1793       47256 :         leftVis_p = leftVis;
    1794       94512 :         IPosition leftVisSize = leftVis->shape(); // pol,chan,row
    1795       47256 :         reducedLength_p = IPosition(3);
    1796       47256 :         reducedLength_p(0) = leftVisSize(1); // chan
    1797       47256 :         reducedLength_p(1) = leftVisSize(2); // row
    1798       47256 :         if (selectedCorrelationProducts_p.size() > 0)
    1799             :         {
    1800       47256 :                 reducedLength_p(2) = selectedCorrelations_p.size(); //pols
    1801             :         }
    1802             :         else
    1803             :         {
    1804           0 :                 reducedLength_p(2) = leftVisSize(1); //pols
    1805             :         }
    1806             : 
    1807             : 
    1808       47256 :         if (rightVis != NULL)
    1809             :         {
    1810        3476 :                 rightVis_p = rightVis;
    1811        3476 :                 getVis_p = &VisMapper::diffVis;
    1812             :         }
    1813             :         else
    1814             :         {
    1815       43780 :                 rightVis_p = NULL;
    1816       43780 :                 getVis_p = &VisMapper::leftVis;
    1817             :         }
    1818       47256 : }
    1819             : 
    1820             : 
    1821             : void
    1822       30768 : VisMapper::setExpressionMapping(String expression,polarizationMap *polMap)
    1823             : {
    1824       30768 :         selectedCorrelationProducts_p.clear();
    1825       30768 :         selectedCorrelations_p.clear();
    1826       30768 :         selectedCorrelationStrings_p.clear();
    1827       30768 :         expression_p = expression;
    1828       30768 :         polMap_p = polMap;
    1829       30768 :         bool matchExpression = false;
    1830             : 
    1831             :         // Parse complex unitary function
    1832       30768 :         if (expression_p.find("REAL") != string::npos)
    1833             :         {
    1834        1110 :                 applyVisExpr_p = &VisMapper::real;
    1835             :         }
    1836       29658 :         else if (expression_p.find("IMAG") != string::npos)
    1837             :         {
    1838           0 :                 applyVisExpr_p = &VisMapper::imag;
    1839             :         }
    1840       29658 :         else if (expression_p.find("ARG") != string::npos)
    1841             :         {
    1842           0 :                 applyVisExpr_p = &VisMapper::arg;
    1843             :         }
    1844       29658 :         else if (expression_p.find("ABS") != string::npos)
    1845             :         {
    1846       29470 :                 applyVisExpr_p = &VisMapper::abs;
    1847             :         }
    1848         188 :         else if (expression_p.find("NORM") != string::npos)
    1849             :         {
    1850          60 :                 applyVisExpr_p = &VisMapper::norm;
    1851             :         }
    1852             :         else
    1853             :         {
    1854         128 :                 applyVisExpr_p = &VisMapper::abs;
    1855             :         }
    1856             : 
    1857             :         // Parse polarization
    1858       30768 :         if (expression_p.find("WVR") != string::npos)
    1859             :         {
    1860          76 :                 if (polMap_p->find(Stokes::I) != polMap_p->end())
    1861             :                 {
    1862          76 :                         vector<uInt> selectedPolarizations;
    1863          76 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::I]);
    1864          76 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1865          76 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_i);
    1866          76 :                         selectedCorrelationStrings_p.push_back(string("I"));
    1867          76 :                         matchExpression = true;
    1868             :                 }
    1869             :                 else
    1870             :                 {
    1871             :                         //throw AipsError("Requested correlation product (WVR - I) not available");
    1872             :                 }
    1873             :         }
    1874       30768 :         if (expression_p.find("XX") != string::npos)
    1875             :         {
    1876          52 :                 if (polMap_p->find(Stokes::XX) != polMap_p->end())
    1877             :                 {
    1878          52 :                         vector<uInt> selectedPolarizations;
    1879          52 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XX]);
    1880          52 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1881          52 :                         selectedCorrelationProducts_p.push_back(&VisMapper::linear_xx);
    1882          52 :                         selectedCorrelationStrings_p.push_back(string("XX"));
    1883          52 :                         matchExpression = true;
    1884             :                 }
    1885             :                 else
    1886             :                 {
    1887             :                         //throw AipsError("Requested correlation product (XX) not available");
    1888             :                 }
    1889             :         }
    1890       30768 :         if (expression_p.find("YY") != string::npos)
    1891             :         {
    1892          50 :                 if (polMap_p->find(Stokes::YY) != polMap_p->end())
    1893             :                 {
    1894          47 :                         vector<uInt> selectedPolarizations;
    1895          47 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YY]);
    1896          47 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1897          47 :                         selectedCorrelationProducts_p.push_back(&VisMapper::linear_yy);
    1898          47 :                         selectedCorrelationStrings_p.push_back(string("YY"));
    1899          47 :                         matchExpression = true;
    1900             :                 }
    1901             :                 else
    1902             :                 {
    1903             :                         //throw AipsError("Requested correlation product (YY) not available");
    1904             :                 }
    1905             :         }
    1906       30768 :         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             :                 }
    1917             :                 else
    1918             :                 {
    1919             :                         //throw AipsError("Requested correlation product (XY) not available");
    1920             :                 }
    1921             :         }
    1922       30768 :         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             :                 }
    1933             :                 else
    1934             :                 {
    1935             :                         //throw AipsError("Requested correlation product (YX) not available");
    1936             :                 }
    1937             :         }
    1938       30768 :         if (expression_p.find("RR") != string::npos)
    1939             :         {
    1940       28261 :                 if (polMap_p->find(Stokes::RR) != polMap_p->end())
    1941             :                 {
    1942       28261 :                         vector<uInt> selectedPolarizations;
    1943       28261 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RR]);
    1944       28261 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1945       28261 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_rr);
    1946       28261 :                         selectedCorrelationStrings_p.push_back(string("RR"));
    1947       28261 :                         matchExpression = true;
    1948             :                 }
    1949             :                 else
    1950             :                 {
    1951             :                         //throw AipsError("Requested correlation product (RR) not available");
    1952             :                 }
    1953             :         }
    1954       30768 :         if (expression_p.find("LL") != string::npos)
    1955             :         {
    1956       25127 :                 if (polMap_p->find(Stokes::LL) != polMap_p->end())
    1957             :                 {
    1958       25089 :                         vector<uInt> selectedPolarizations;
    1959       25089 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LL]);
    1960       25089 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1961       25089 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_ll);
    1962       25089 :                         selectedCorrelationStrings_p.push_back(string("LL"));
    1963       25089 :                         matchExpression = true;
    1964             :                 }
    1965             :                 else
    1966             :                 {
    1967             :                         //throw AipsError("Requested correlation product (LL) not available");
    1968             :                 }
    1969             :         }
    1970       30768 :         if (expression_p.find("LR") != string::npos)
    1971             :         {
    1972       24426 :                 if (polMap_p->find(Stokes::LR) != polMap_p->end())
    1973             :                 {
    1974       24426 :                         vector<uInt> selectedPolarizations;
    1975       24426 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LR]);
    1976       24426 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1977       24426 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_lr);
    1978       24426 :                         selectedCorrelationStrings_p.push_back(string("LR"));
    1979       24426 :                         matchExpression = true;
    1980             :                 }
    1981             :                 else
    1982             :                 {
    1983             :                         //throw AipsError("Requested correlation product (LR) not available");
    1984             :                 }
    1985             :         }
    1986       30768 :         if (expression_p.find("RL") != string::npos)
    1987             :         {
    1988       24426 :                 if (polMap_p->find(Stokes::RL) != polMap_p->end())
    1989             :                 {
    1990       24426 :                         vector<uInt> selectedPolarizations;
    1991       24426 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RL]);
    1992       24426 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1993       24426 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_rl);
    1994       24426 :                         selectedCorrelationStrings_p.push_back(string("RL"));
    1995       24426 :                         matchExpression = true;
    1996             :                 }
    1997             :                 else
    1998             :                 {
    1999             :                         //throw AipsError("Requested correlation product (RL) not available");
    2000             :                 }
    2001             :         }
    2002       30768 :         if (expression_p.find("I") != string::npos)
    2003             :         {
    2004          33 :                 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             :                 }
    2013          33 :                 else if ((polMap_p->find(Stokes::XX) != polMap_p->end()) and (polMap_p->find(Stokes::YY) != polMap_p->end()))
    2014             :                 {
    2015          33 :                         vector<uInt> selectedPolarizations;
    2016          33 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XX]);
    2017          33 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YY]);
    2018          33 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2019          33 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_i_from_linear);
    2020          33 :                         selectedCorrelationStrings_p.push_back(string("I = (XX+YY)/2"));
    2021          33 :                         matchExpression = true;
    2022             :                 }
    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             :                 }
    2033             :                 else
    2034             :                 {
    2035             :                         //throw AipsError("Requested Stokes parameter (I) cannot be computed from available polarizations");
    2036             :                 }
    2037             :         }
    2038       30768 :         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             :                 }
    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             :                 }
    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             :                 }
    2069             :                 else
    2070             :                 {
    2071             :                         //throw AipsError("Requested Stokes parameter (Q) cannot be computed from available polarizations");
    2072             :                 }
    2073             :         }
    2074       30768 :         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             :                 }
    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             :                 }
    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             :                 }
    2105             :                 else
    2106             :                 {
    2107             :                         //throw AipsError("Requested Stokes parameter (U) cannot be computed from available polarizations");
    2108             :                 }
    2109             :         }
    2110       30768 :         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             :                 }
    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             :                 }
    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             :                 }
    2141             :                 else
    2142             :                 {
    2143             :                         //throw AipsError("Requested Stokes parameter (V) cannot be computed from available polarizations");
    2144             :                 }
    2145             :         }
    2146       30768 :         if (expression_p.find("SOL1") != string::npos)
    2147             :         {
    2148        1518 :                 if (polMap_p->find(VisMapper::CALSOL1) != polMap_p->end())
    2149             :                 {
    2150        1518 :                         vector<uInt> selectedPolarizations;
    2151        1518 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL1]);
    2152        1518 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2153        1518 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol1);
    2154        1518 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 1"));
    2155        1518 :                         matchExpression = true;
    2156             :                 }
    2157             :                 else
    2158             :                 {
    2159             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2160             :                 }
    2161             :         }
    2162       30768 :         if (expression_p.find("SOL2") != string::npos)
    2163             :         {
    2164        1388 :                 if (polMap_p->find(VisMapper::CALSOL2) != polMap_p->end())
    2165             :                 {
    2166        1388 :                         vector<uInt> selectedPolarizations;
    2167        1388 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL2]);
    2168        1388 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2169        1388 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol2);
    2170        1388 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 2"));
    2171        1388 :                         matchExpression = true;
    2172             :                 }
    2173             :                 else
    2174             :                 {
    2175             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2176             :                 }
    2177             :         }
    2178       30768 :         if (expression_p.find("SOL3") != string::npos)
    2179             :         {
    2180         881 :                 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             :                 }
    2189             :                 else
    2190             :                 {
    2191             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2192             :                 }
    2193             :         }
    2194       30768 :         if (expression_p.find("SOL4") != string::npos)
    2195             :         {
    2196         881 :                 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             :                 }
    2205             :                 else
    2206             :                 {
    2207             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2208             :                 }
    2209             :         }
    2210             : 
    2211             : 
    2212       30768 :         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       30768 : }
    2217             : 
    2218             : 
    2219       30768 : VisMapper::~VisMapper()
    2220             : {
    2221       30768 :         if (rightVis_p != NULL) delete rightVis_p;
    2222       30768 :         if (leftVis_p != NULL) delete leftVis_p;
    2223       30768 : }
    2224             : 
    2225             : 
    2226             : Float
    2227    46962252 : VisMapper::operator()(uInt chan, uInt row)
    2228             : {
    2229    46962252 :         Complex val = (*this.*selectedCorrelationProducts_p[0])(chan,row);
    2230    93924504 :         return (*this.*applyVisExpr_p)(val);
    2231             : }
    2232             : 
    2233             : 
    2234             : Float
    2235   110712333 : VisMapper::operator()(uInt pol, uInt chan, uInt row)
    2236             : {
    2237   110712333 :         Complex val = (*this.*selectedCorrelationProducts_p[pol])(chan,row);
    2238   221424666 :         return (*this.*applyVisExpr_p)(val);
    2239             : }
    2240             : 
    2241             : 
    2242             : Complex
    2243   699905540 : VisMapper::correlationProduct(uInt pol, uInt chan, uInt row)
    2244             : {
    2245   699905540 :         return (*this.*selectedCorrelationProducts_p[pol])(chan,row);
    2246             : }
    2247             : 
    2248             : 
    2249             : Complex
    2250   818806967 : VisMapper::leftVis(uInt pol, uInt chan, uInt row)
    2251             : {
    2252   818806967 :         return leftVis_p->operator()(pol,chan,row);
    2253             : }
    2254             : 
    2255             : 
    2256             : Complex
    2257    38908158 : VisMapper::diffVis(uInt pol, uInt chan, uInt row)
    2258             : {
    2259    38908158 :         return leftVis_p->operator()(pol,chan,row)-rightVis_p->operator()(pol,chan,row);
    2260             : }
    2261             : 
    2262             : 
    2263             : Complex
    2264        1216 : VisMapper::stokes_i(uInt chan, uInt row)
    2265             : {
    2266        1216 :         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      163663 : VisMapper::linear_xx(uInt chan, uInt row)
    2293             : {
    2294      163663 :         return (*this.*getVis_p)((*polMap_p)[Stokes::XX],chan,row);
    2295             : }
    2296             : 
    2297             : 
    2298             : Complex
    2299      163516 : VisMapper::linear_yy(uInt chan, uInt row)
    2300             : {
    2301      163516 :         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   218039648 : VisMapper::circular_rr(uInt chan, uInt row)
    2321             : {
    2322   218039648 :         return (*this.*getVis_p)((*polMap_p)[Stokes::RR],chan,row);
    2323             : }
    2324             : 
    2325             : 
    2326             : Complex
    2327   214416910 : VisMapper::circular_ll(uInt chan, uInt row)
    2328             : {
    2329   214416910 :         return (*this.*getVis_p)((*polMap_p)[Stokes::LL],chan,row);
    2330             : }
    2331             : 
    2332             : 
    2333             : Complex
    2334   198665021 : VisMapper::circular_rl(uInt chan, uInt row)
    2335             : {
    2336   198665021 :         return (*this.*getVis_p)((*polMap_p)[Stokes::RL],chan,row);
    2337             : }
    2338             : 
    2339             : 
    2340             : Complex
    2341   198663932 : VisMapper::circular_lr(uInt chan, uInt row)
    2342             : {
    2343   198663932 :         return (*this.*getVis_p)((*polMap_p)[Stokes::LR],chan,row);
    2344             : }
    2345             : 
    2346             : 
    2347             : Complex
    2348      135000 : VisMapper::stokes_i_from_linear(uInt chan, uInt row)
    2349             : {
    2350             :         // I = (XX+YY)/2
    2351      135000 :         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    12861595 : VisMapper::calsol1(uInt chan, uInt row)
    2417             : {
    2418    12861595 :         return (*this.*getVis_p)((*polMap_p)[VisMapper::CALSOL1],chan,row);
    2419             : }
    2420             : 
    2421             : 
    2422             : Complex
    2423    14469624 : VisMapper::calsol2(uInt chan, uInt row)
    2424             : {
    2425    14469624 :         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      564735 : FlagMapper::FlagMapper(Bool flag, vector< vector<uInt> > selectedCorrelations)
    2469             : {
    2470      564735 :         commonFlagsView_p = NULL;
    2471      564735 :         originalFlagsView_p = NULL;
    2472      564735 :         privateFlagsView_p = NULL;
    2473      564735 :         commonFlagRowView_p = NULL;
    2474      564735 :         originalFlagRowView_p = NULL;
    2475      564735 :         privateFlagRowView_p = NULL;
    2476      564735 :         setExpressionMapping(selectedCorrelations);
    2477      564735 :         nSelectedCorrelations_p = selectedCorrelations.size();
    2478      564735 :         flag_p = flag;
    2479      564735 : }
    2480             : 
    2481             : 
    2482             : void
    2483      585593 : FlagMapper::setParentCubes(CubeView<Bool> *commonFlagsView,CubeView<Bool> *originalFlagsView,CubeView<Bool> *privateFlagsView)
    2484             : {
    2485      585593 :         if (commonFlagsView_p != NULL) delete commonFlagsView_p;
    2486      585593 :         if (originalFlagsView_p != NULL) delete originalFlagsView_p;
    2487      585593 :         if (privateFlagsView_p != NULL) delete privateFlagsView_p;
    2488             : 
    2489      585593 :         commonFlagsView_p = commonFlagsView;
    2490      585593 :         originalFlagsView_p = originalFlagsView;
    2491      585593 :         if (privateFlagsView != NULL)
    2492             :         {
    2493           0 :                 privateFlagsView_p = privateFlagsView;
    2494           0 :                 applyFlag_p = &FlagMapper::applyPrivateFlags;
    2495             :         }
    2496             :         else
    2497             :         {
    2498      585593 :                 applyFlag_p = &FlagMapper::applyCommonFlags;
    2499             :         }
    2500             : 
    2501      585593 :         IPosition commonFlagCubeSize = commonFlagsView_p->shape(); // pol,chan,row
    2502      585593 :         reducedLength_p = IPosition(2);
    2503      585593 :         reducedLength_p(0) = commonFlagCubeSize(1); // chan
    2504      585593 :         reducedLength_p(1) = commonFlagCubeSize(2); // row
    2505             : 
    2506      585593 :         if (nSelectedCorrelations_p>0)
    2507             :         {
    2508      585593 :                 reducedLength_p(2) = nSelectedCorrelations_p; // pol
    2509             :         }
    2510             :         else
    2511             :         {
    2512           0 :                 reducedLength_p(2) = reducedLength_p(0);// pol
    2513             :         }
    2514             : 
    2515      585593 :         flagsPerRow_p = reducedLength_p(2)*reducedLength_p(0);
    2516      585593 : }
    2517             : 
    2518             : 
    2519             : void
    2520      585593 : FlagMapper::setParentFlagRow(VectorView<Bool> *commonFlagRowView,VectorView<Bool> *originalFlagRowView,VectorView<Bool> *privateFlagRowView)
    2521             : {
    2522      585593 :         if (commonFlagRowView_p != NULL) delete commonFlagRowView_p;
    2523      585593 :         if (originalFlagRowView_p != NULL) delete originalFlagRowView_p;
    2524      585593 :         if (privateFlagRowView_p != NULL) delete privateFlagRowView_p;
    2525             : 
    2526      585593 :         commonFlagRowView_p = commonFlagRowView;
    2527      585593 :         originalFlagRowView_p = originalFlagRowView;
    2528      585593 :         if (privateFlagRowView_p != NULL)
    2529             :         {
    2530           0 :                 privateFlagRowView_p = privateFlagRowView;
    2531           0 :                 applyFlagRow_p = &FlagMapper::applyPrivateFlagRow;
    2532             :         }
    2533             :         else
    2534             :         {
    2535      585593 :                 applyFlagRow_p = &FlagMapper::applyCommonFlagRow;
    2536             :         }
    2537             : 
    2538      585593 :         return;
    2539             : }
    2540             : 
    2541             : 
    2542             : void
    2543      564735 : FlagMapper::setExpressionMapping(vector< vector<uInt> > selectedCorrelations)
    2544             : {
    2545      564735 :         selectedCorrelations_p = selectedCorrelations;
    2546      564735 :         if (selectedCorrelations_p.empty())
    2547             :         {
    2548             :                 //throw AipsError("None of the correlations is eligible for flagging");
    2549             :         }
    2550      564735 : }
    2551             : 
    2552             : 
    2553      564735 : FlagMapper::~FlagMapper()
    2554             : {
    2555      564735 :         if (commonFlagsView_p != NULL) delete commonFlagsView_p;
    2556      564735 :         if (originalFlagsView_p != NULL) delete originalFlagsView_p;
    2557      564735 :         if (privateFlagsView_p != NULL) delete privateFlagsView_p;
    2558      564735 :         if (commonFlagRowView_p != NULL) delete commonFlagRowView_p;
    2559      564735 :         if (originalFlagRowView_p != NULL) delete originalFlagRowView_p;
    2560      564735 :         if (privateFlagRowView_p != NULL) delete privateFlagRowView_p;
    2561      564735 : }
    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    48009424 : FlagMapper::getModifiedFlags(uInt channel, uInt row)
    2579             : {
    2580    48009424 :         Bool combinedFlag = false;
    2581    96018848 :         for (auto &elem : selectedCorrelations_p[0])
    2582             :         {
    2583    48009424 :                 combinedFlag = combinedFlag | commonFlagsView_p->operator ()(elem, channel, row);
    2584             :         }
    2585             : 
    2586    48009424 :         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   629985272 : FlagMapper::getOriginalFlags(uInt pol, uInt channel, uInt row)
    2605             : {
    2606   629985272 :         Bool combinedFlag = false;
    2607  1259970544 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2608             :         {
    2609   629985272 :                 combinedFlag = combinedFlag | originalFlagsView_p->operator ()(*iter,channel,row);
    2610             :         }
    2611             : 
    2612   629985272 :         return combinedFlag;
    2613             : }
    2614             : 
    2615             : 
    2616             : Bool
    2617   692535308 : FlagMapper::getModifiedFlags(uInt pol, uInt channel, uInt row)
    2618             : {
    2619   692535308 :         Bool combinedFlag = false;
    2620  1385070616 :         for (auto &elem : selectedCorrelations_p[pol])
    2621             :         {
    2622   692535308 :                 combinedFlag = combinedFlag | commonFlagsView_p->operator ()(elem, channel, row);
    2623             :         }
    2624             : 
    2625   692535308 :         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     6059741 : FlagMapper::setModifiedFlags(uInt pol, uInt channel, uInt row)
    2665             : {
    2666    12119482 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2667             :         {
    2668     6059741 :                 commonFlagsView_p->operator ()(*iter,channel,row) = flag_p;
    2669             :         }
    2670     6059741 : }
    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      816333 : FlagMapper::applyFlag(uInt channel, uInt row)
    2685             : {
    2686     1632666 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[0].begin();iter!=selectedCorrelations_p[0].end();iter++)
    2687             :         {
    2688      816333 :                 (*this.*applyFlag_p)(*iter,channel,row);
    2689             :         }
    2690      816333 : }
    2691             : 
    2692             : 
    2693             : void
    2694     4718183 : FlagMapper::applyFlag(uInt pol, uInt channel, uInt row)
    2695             : {
    2696     9436366 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2697             :         {
    2698     4718183 :                 (*this.*applyFlag_p)(*iter,channel,row);
    2699             :         }
    2700     4718183 : }
    2701             : 
    2702             : 
    2703             : void
    2704     7288025 : FlagMapper::applyFlagRow(uInt row)
    2705             : {
    2706             :         // Flag row
    2707     7288025 :         (*this.*applyFlagRow_p)(row);
    2708     7288025 : }
    2709             : 
    2710             : void
    2711     8611719 : FlagMapper::applyFlagInRow(uInt row)
    2712             : {
    2713             :         // Flag cube
    2714   416797697 :         for (uInt chan_i=0;chan_i<reducedLength_p(0);chan_i++)
    2715             :         {
    2716  1545607665 :                 for (vector< vector<uInt> >::iterator correlations=selectedCorrelations_p.begin();correlations!=selectedCorrelations_p.end();correlations++)
    2717             :                 {
    2718  2274843374 :                         for (vector<uInt>::iterator iter=correlations->begin();iter!=correlations->end();iter++)
    2719             :                         {
    2720  1137421687 :                                 (*this.*applyFlag_p)(*iter,chan_i,row);
    2721             :                         }
    2722             :                 }
    2723             :         }
    2724     8611719 : }
    2725             : 
    2726             : 
    2727             : void
    2728  1142956203 : 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  1142956203 :         commonFlagsView_p->operator()(pol,channel,row) = flag_p;
    2732  1142956203 :         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     7288025 : FlagMapper::applyCommonFlagRow(uInt row)
    2760             : {
    2761             :         // NOTE: Notice that the position is pol,channel,row, not the other way around
    2762     7288025 :         commonFlagRowView_p->operator()(row) = flag_p;
    2763     7288025 :         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