LCOV - code coverage report
Current view: top level - flagging/Flagging - FlagDataHandler.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 734 1302 56.4 %
Date: 2024-10-12 00:35:29 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        1093 : FlagDataHandler::FlagDataHandler(string tablename, uShort iterationApproach, Double timeInterval):
      41        1093 :                 tablename_p(tablename), iterationApproach_p(iterationApproach)
      42             : {
      43             :         // Initialize logger
      44        1093 :         logger_p = new LogIO(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
      45             : 
      46             :         // Set time interval
      47        1093 :         setTimeInterval(timeInterval);
      48             : 
      49             :         // Deactivate profiling by default
      50        1093 :         profiling_p = false;
      51             : 
      52             :         // Disable async I/O by default
      53        1093 :         enableAsyncIO(false);
      54             : 
      55             :         // Check if slurp is enabled
      56        1093 :         if (!asyncio_enabled_p)
      57             :         {
      58        1093 :                 slurp_p = true;
      59        1093 :                 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        1093 :         mapPolarizations_p = true;
      85             : 
      86             :         // Antenna pointing map is only needed by the Elevation agent and I have move it there
      87        1093 :         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        1093 :         mapScanStartStop_p = false;
      92        1093 :         mapScanStartStopFlagged_p = false;
      93             : 
      94             :         // Initialize Pre-Load columns
      95        1093 :         preLoadColumns_p.clear();
      96        1093 :         preLoadColumns_p.push_back(VisBufferComponent2::FieldId);
      97        1093 :         preLoadColumns_p.push_back(VisBufferComponent2::SpectralWindows);
      98        1093 :         preLoadColumns_p.push_back(VisBufferComponent2::Scan);
      99        1093 :         preLoadColumns_p.push_back(VisBufferComponent2::ArrayId);
     100        1093 :         preLoadColumns_p.push_back(VisBufferComponent2::ObservationId);
     101             : 
     102        1093 :         preLoadColumns_p.push_back(VisBufferComponent2::NRows);
     103        1093 :         preLoadColumns_p.push_back(VisBufferComponent2::NChannels);
     104        1093 :         preLoadColumns_p.push_back(VisBufferComponent2::NCorrelations);
     105             : 
     106             :         // Set the iteration approach based on the agent
     107        1093 :         setIterationApproach(iterationApproach);
     108             : 
     109             :         // Initialize selection ranges
     110        1093 :         anySelection_p = false;
     111        1093 :         inrowSelection_p = false;
     112        1093 :         timeSelection_p = String("");
     113        1093 :         baselineSelection_p = String("");
     114        1093 :         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        1093 :         spwSelection_p = String("");
     118        1093 :         uvwSelection_p = String("");
     119        1093 :         polarizationSelection_p = String("");
     120        1093 :         scanSelection_p = String("");
     121        1093 :         arraySelection_p = String("");
     122        1093 :         observationSelection_p = String("");
     123        1093 :         scanIntentSelection_p = String("");
     124             : 
     125             :         // Initialize iteration parameters
     126        1093 :         chunksInitialized_p = false;
     127        1093 :         buffersInitialized_p = false;
     128        1093 :         iteratorGenerated_p = false;
     129        1093 :         stopIteration_p = false;
     130        1093 :         processedRows_p = 0;
     131        1093 :         chunkNo_p = 0;
     132        1093 :         bufferNo_p = 0;
     133             : 
     134             :         // Initialize stats
     135        1093 :         stats_p = false;
     136        1093 :         cubeAccessCounter_p = 0;
     137        1093 :         chunkCounts_p = 0;
     138        1093 :         progressCounts_p = 0;
     139        1093 :         msCounts_p = 0;
     140        1093 :         printChunkSummary_p = true;
     141        1093 :         summaryThreshold_p = summaryThresholdInc_p;
     142        1093 :         chunkLineThreshold_p = chunkLineThresholdInc_p;;
     143             : 
     144             :         // Set all the initialized pointers to NULL
     145        1093 :         measurementSetSelection_p = NULL;
     146        1093 :         visibilityBuffer_p = NULL;
     147        1093 :         antennaNames_p = NULL;
     148        1093 :         antennaPositions_p = NULL;
     149        1093 :         antennaDiameters_p = NULL;
     150        1093 :         antennaPairMap_p = NULL;
     151        1093 :         subIntegrationMap_p = NULL;
     152        1093 :         corrProducts_p = NULL;
     153        1093 :         polarizationMap_p = NULL;
     154        1093 :         polarizationIndexMap_p = NULL;
     155        1093 :         antennaPointingMap_p = NULL;
     156        1093 :         scanStartStopMap_p = NULL;
     157        1093 :         lambdaMap_p = NULL;
     158        1093 :         fieldNames_p = NULL;
     159             : 
     160             :         // Initialize table characteristics
     161        1093 :         tableTye_p = MEASUREMENT_SET;
     162        1093 :         processorTableExist_p = true;
     163             : 
     164             :         // Initialize FlagDataHanler-FlagAgents state
     165        1093 :         flushFlags_p = false;
     166        1093 :         flushFlagRow_p = false;
     167        1093 :         loadProcessorTable_p = false;
     168             : 
     169             :         // Initialize time averaging options
     170        1093 :     timeAvgOptions_p = vi::AveragingOptions(vi::AveragingOptions::Nothing);
     171        1093 :     enableTimeAvg_p = false;
     172        1093 :     enableChanAvg_p = false;
     173             : 
     174        1093 :         return;
     175           0 : }
     176             : 
     177             : 
     178             : // -----------------------------------------------------------------------
     179             : // Default destructor
     180             : // -----------------------------------------------------------------------
     181        1093 : FlagDataHandler::~FlagDataHandler()
     182             : {
     183        1093 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     184        1093 :         *logger_p << LogIO::DEBUG1 << "FlagDataHandler::~FlagDataHandler()" << LogIO::POST;
     185             : 
     186             :         // Delete logger
     187        1093 :         if (logger_p) delete logger_p;
     188             : 
     189             :         // Delete MS objects
     190        1093 :         if (measurementSetSelection_p) delete measurementSetSelection_p;
     191             : 
     192             :         // Delete mapping members
     193        1093 :         if (antennaNames_p) delete antennaNames_p;
     194        1093 :         if (antennaPositions_p) delete antennaPositions_p;
     195        1093 :         if (antennaDiameters_p) delete antennaDiameters_p;
     196        1093 :         if (antennaPairMap_p) delete antennaPairMap_p;
     197        1093 :         if (subIntegrationMap_p) delete subIntegrationMap_p;
     198        1093 :         if (corrProducts_p) delete corrProducts_p;
     199        1093 :         if (polarizationMap_p) delete polarizationMap_p;
     200        1093 :         if (polarizationIndexMap_p) delete polarizationIndexMap_p;
     201        1093 :         if (antennaPointingMap_p) delete antennaPointingMap_p;
     202        1093 :         if (scanStartStopMap_p) delete scanStartStopMap_p;
     203        1093 :         if (lambdaMap_p) delete lambdaMap_p;
     204        1093 :         if (fieldNames_p) delete fieldNames_p;
     205             : 
     206        1093 :         return;
     207        1093 : }
     208             : 
     209             : 
     210             : // -----------------------------------------------------------------------
     211             : // Set iteration Approach
     212             : // -----------------------------------------------------------------------
     213             : void
     214        1169 : FlagDataHandler::setIterationApproach(uShort iterationApproach)
     215             : {
     216        1169 :         iterationApproach_p = iterationApproach;
     217             : 
     218        1169 :         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          76 :                 case COMPLETE_SCAN_MAP_ANTENNA_PAIRS_ONLY:
     258             :                 {
     259          76 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: COMPLETE_SCAN_MAP_ANTENNA_PAIRS_ONLY" << LogIO::POST;
     260          76 :                         sortOrder_p = Block<int>(6);
     261          76 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     262          76 :                         sortOrder_p[1] = MS::ARRAY_ID;
     263          76 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     264          76 :                         sortOrder_p[3] = MS::FIELD_ID;
     265          76 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     266          76 :                         sortOrder_p[5] = MS::TIME;
     267             : 
     268             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     269          76 :                         groupTimeSteps_p = true;
     270          76 :                         mapAntennaPairs_p = true;
     271          76 :                         mapSubIntegrations_p = false;
     272          76 :                         setMapAntennaPairs(true);
     273          76 :                         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        1093 :                 case  SUB_INTEGRATION:
     383             :                 {
     384        1093 :                         *logger_p << LogIO::DEBUG1 << " Iteration mode: SUB_INTEGRATION" << LogIO::POST;
     385        1093 :                         sortOrder_p = Block<int>(6);
     386        1093 :                         sortOrder_p[0] = MS::OBSERVATION_ID;
     387        1093 :                         sortOrder_p[1] = MS::ARRAY_ID;
     388        1093 :                         sortOrder_p[2] = MS::SCAN_NUMBER;
     389        1093 :                         sortOrder_p[3] = MS::FIELD_ID;
     390        1093 :                         sortOrder_p[4] = MS::DATA_DESC_ID;
     391        1093 :                         sortOrder_p[5] = MS::TIME;
     392             : 
     393             :                         // NOTE: groupTimeSteps_p=false selects only one time step per buffer
     394        1093 :                         groupTimeSteps_p = false;
     395        1093 :                         mapAntennaPairs_p = false;
     396        1093 :                         mapSubIntegrations_p = false;
     397        1093 :                         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        1169 :         iteratorGenerated_p = false;
     435        1169 :         chunksInitialized_p = false;
     436        1169 :         buffersInitialized_p = false;
     437        1169 :         stopIteration_p = false;
     438             : 
     439        1169 :         return;
     440             : }
     441             : 
     442             : // -----------------------------------------------------------------------
     443             : // Mapping functions as requested by Urvashi
     444             : // -----------------------------------------------------------------------
     445             : void
     446         819 : FlagDataHandler::generateAntennaPairMap()
     447             : {
     448         819 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     449             : 
     450             :         // Free previous map and create a new one
     451         819 :         if (antennaPairMap_p) delete antennaPairMap_p;
     452         819 :         antennaPairMap_p = new antennaPairMap();
     453             : 
     454             :         // Retrieve antenna vectors
     455         819 :         Vector<Int> antenna1Vector = visibilityBuffer_p->antenna1();
     456         819 :         Vector<Int> antenna2Vector = visibilityBuffer_p->antenna2();
     457             : 
     458             :         // Fill map
     459             :         Int ant1_i,ant2_i;
     460         819 :         uInt nRows = antenna1Vector.size();
     461      481168 :         for (uInt row_idx=0;row_idx<nRows;row_idx++)
     462             :         {
     463      480349 :                 ant1_i = antenna1Vector[row_idx];
     464      480349 :                 ant2_i = antenna2Vector[row_idx];
     465      480349 :                 if (antennaPairMap_p->find(std::make_pair(ant1_i,ant2_i)) == antennaPairMap_p->end())
     466             :                 {
     467       11111 :                         std::vector<uInt> newPair;
     468       11111 :                         newPair.push_back(row_idx);
     469       11111 :                         (*antennaPairMap_p)[std::make_pair(ant1_i,ant2_i)] = newPair;
     470       11111 :                 }
     471             :                 else
     472             :                 {
     473      469238 :                         (*antennaPairMap_p)[std::make_pair(ant1_i,ant2_i)].push_back(row_idx);
     474             :                 }
     475             :         }
     476         819 :         *logger_p << LogIO::DEBUG1 <<  " " << antennaPairMap_p->size() <<" Antenna pairs found in current buffer" << LogIO::POST;
     477             : 
     478        1638 :         return;
     479         819 : }
     480             : 
     481             : 
     482             : void
     483           0 : FlagDataHandler::generateSubIntegrationMap()
     484             : {
     485           0 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     486             : 
     487             :         // Free previous map and create a new one
     488           0 :         if (subIntegrationMap_p) delete subIntegrationMap_p;
     489           0 :         subIntegrationMap_p = new subIntegrationMap();
     490             : 
     491             :         // Retrieve antenna vectors
     492           0 :         Vector<Double> timeVector = visibilityBuffer_p->time();
     493             : 
     494             :         // Fill map
     495           0 :         uInt nRows = timeVector.size();
     496           0 :         for (uInt row_idx=0;row_idx<nRows;row_idx++)
     497             :         {
     498           0 :                 if (subIntegrationMap_p->find(timeVector[row_idx]) == subIntegrationMap_p->end())
     499             :                 {
     500           0 :                         std::vector<uInt> newSubIntegration;
     501           0 :                         newSubIntegration.push_back(row_idx);
     502           0 :                         (*subIntegrationMap_p)[timeVector[row_idx]] = newSubIntegration;
     503           0 :                 }
     504             :                 else
     505             :                 {
     506           0 :                         (*subIntegrationMap_p)[timeVector[row_idx]].push_back(row_idx);
     507             :                 }
     508             :         }
     509           0 :         *logger_p << LogIO::NORMAL <<  " " << subIntegrationMap_p->size() <<" Sub-Integrations (time steps) found in current buffer" << LogIO::POST;
     510             : 
     511           0 :         return;
     512           0 : }
     513             : 
     514             : 
     515             : void
     516      351167 : FlagDataHandler::generatePolarizationsMap()
     517             : {
     518      351167 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     519             : 
     520             :         // Free previous map and create a new one
     521      351167 :         if (polarizationMap_p) delete polarizationMap_p;
     522      351167 :         polarizationMap_p = new polarizationMap();
     523      351167 :         if (polarizationIndexMap_p) delete polarizationIndexMap_p;
     524      351167 :         polarizationIndexMap_p = new polarizationIndexMap();
     525             : 
     526      351167 :         uShort pos = 0;
     527      351167 :         Vector<Int> corrTypes = visibilityBuffer_p->correlationTypes();
     528             : 
     529      351167 :         const auto logprio = logger_p->priority();
     530      351167 :         if (logprio <= LogMessage::DEBUG2)
     531           0 :             *logger_p << LogIO::DEBUG2 << " Correlation type: " <<  corrTypes << LogIO::POST;
     532             : 
     533     1689005 :         for (Vector<Int>::iterator iter = corrTypes.begin(); iter != corrTypes.end();iter++)
     534             :         {
     535     1337838 :                 switch (*iter)
     536             :                 {
     537        1054 :                         case Stokes::I:
     538             :                         {
     539        1054 :                             if (logprio <= LogMessage::DEBUG2)
     540           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is I" << LogIO::POST;
     541        1054 :                             (*polarizationMap_p)[Stokes::I] = pos;
     542        1054 :                             (*polarizationIndexMap_p)[pos] = "I";
     543        1054 :                             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        4465 :                         case Stokes::XX:
     570             :                         {
     571        4465 :                             if (logprio <= LogMessage::DEBUG2)
     572           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is XX" << LogIO::POST;
     573        4465 :                             (*polarizationMap_p)[Stokes::XX] = pos;
     574        4465 :                             (*polarizationIndexMap_p)[pos] = "XX";
     575        4465 :                             break;
     576             :                         }
     577        1987 :                         case Stokes::YY:
     578             :                         {
     579        1987 :                             if (logprio <= LogMessage::DEBUG2)
     580           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is YY" << LogIO::POST;
     581        1987 :                             (*polarizationMap_p)[Stokes::YY] = pos;
     582        1987 :                             (*polarizationIndexMap_p)[pos] = "YY";
     583        1987 :                             break;
     584             :                         }
     585         888 :                         case Stokes::XY:
     586             :                         {
     587         888 :                             if (logprio <= LogMessage::DEBUG2)
     588           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is XY" << LogIO::POST;
     589         888 :                             (*polarizationMap_p)[Stokes::XY] = pos;
     590         888 :                             (*polarizationIndexMap_p)[pos] = "XY";
     591         888 :                             break;
     592             :                         }
     593         888 :                         case Stokes::YX:
     594             :                         {
     595         888 :                             if (logprio <= LogMessage::DEBUG2)
     596           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is YX" << LogIO::POST;
     597         888 :                             (*polarizationMap_p)[Stokes::YX] = pos;
     598         888 :                             (*polarizationIndexMap_p)[pos] = "YX";
     599         888 :                             break;
     600             :                         }
     601      336396 :                         case Stokes::RR:
     602             :                         {
     603      336396 :                             if (logprio <= LogMessage::DEBUG2)
     604           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is RR" << LogIO::POST;
     605      336396 :                             (*polarizationMap_p)[Stokes::RR] = pos;
     606      336396 :                             (*polarizationIndexMap_p)[pos] = "RR";
     607      336396 :                             break;
     608             :                         }
     609      336360 :                         case Stokes::LL:
     610             :                         {
     611      336360 :                             if (logprio <= LogMessage::DEBUG2)
     612           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is LL" << LogIO::POST;
     613      336360 :                             (*polarizationMap_p)[Stokes::LL] = pos;
     614      336360 :                             (*polarizationIndexMap_p)[pos] = "LL";
     615      336360 :                             break;
     616             :                         }
     617      319104 :                         case Stokes::RL:
     618             :                         {
     619      319104 :                             if (logprio <= LogMessage::DEBUG2)
     620           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is RL" << LogIO::POST;
     621      319104 :                             (*polarizationMap_p)[Stokes::RL] = pos;
     622      319104 :                             (*polarizationIndexMap_p)[pos] = "RL";
     623      319104 :                             break;
     624             :                         }
     625      319104 :                         case Stokes::LR:
     626             :                         {
     627      319104 :                             if (logprio <= LogMessage::DEBUG2)
     628           0 :                                 *logger_p << LogIO::DEBUG2 << " The " << pos << " th correlation is LR" << LogIO::POST;
     629      319104 :                             (*polarizationMap_p)[Stokes::LR] = pos;
     630      319104 :                             (*polarizationIndexMap_p)[pos] = "LR";
     631      319104 :                             break;
     632             :                         }
     633        8796 :                         case VisMapper::CALSOL1:
     634             :                         {
     635        8796 :                             if (logprio <= LogMessage::DEBUG2)
     636           0 :                                 *logger_p << LogIO::DEBUG2 << " Calibration solution 1 found at " << pos << LogIO::POST;
     637        8796 :                             (*polarizationMap_p)[VisMapper::CALSOL1] = pos;
     638        8796 :                             (*polarizationIndexMap_p)[pos] = "Sol1";
     639        8796 :                             break;
     640             :                         }
     641        8796 :                         case VisMapper::CALSOL2:
     642             :                         {
     643        8796 :                             if (logprio <= LogMessage::DEBUG2)
     644           0 :                                 *logger_p << LogIO::DEBUG2 << " Calibration solution 2 found at " << pos << LogIO::POST;
     645        8796 :                             (*polarizationMap_p)[VisMapper::CALSOL2] = pos;
     646        8796 :                             (*polarizationIndexMap_p)[pos] = "Sol2";
     647        8796 :                             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     1337838 :                 pos++;
     672      351167 :         }
     673             : 
     674      351167 :         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      351167 : }
     681             : 
     682             : void
     683           0 : FlagDataHandler::generateAntennaPointingMap()
     684             : {
     685           0 :         logger_p->origin(LogOrigin("FlagMSHandler",__FUNCTION__,WHERE));
     686             : 
     687             :         // Free previous map and create a new one
     688           0 :         if (antennaPointingMap_p) delete antennaPointingMap_p;
     689           0 :         antennaPointingMap_p = new antennaPointingMap();
     690             : 
     691           0 :         Vector<Double> time = visibilityBuffer_p->time();
     692           0 :         uInt nRows = time.size();
     693           0 :         antennaPointingMap_p->reserve(nRows);
     694           0 :         for (uInt row_i=0;row_i<nRows;row_i++)
     695             :         {
     696           0 :                 Vector<MDirection> azimuth_elevation = visibilityBuffer_p->azel(time[row_i]);
     697           0 :                 Int ant1 = visibilityBuffer_p->antenna1()[row_i];
     698           0 :                 Int ant2 = visibilityBuffer_p->antenna1()[row_i];
     699             : 
     700           0 :             double antenna1_elevation = azimuth_elevation[ant1].getAngle("deg").getValue()[1];
     701           0 :             double antenna2_elevation = azimuth_elevation[ant2].getAngle("deg").getValue()[1];
     702             : 
     703           0 :             vector<Double> item(2);
     704           0 :             item[0] = antenna1_elevation;
     705           0 :             item[1] = antenna2_elevation;
     706           0 :             antennaPointingMap_p->push_back(item);
     707           0 :         }
     708             : 
     709           0 :         *logger_p << LogIO::NORMAL << " Generated antenna pointing map with "
     710           0 :                         << antennaPointingMap_p->size() << " elements" << LogIO::POST;
     711             : 
     712           0 :         return;
     713           0 : }
     714             : 
     715             : 
     716             : // -----------------------------------------------------------------------
     717             : // Generate scan start stop map
     718             : // -----------------------------------------------------------------------
     719             : void
     720           0 : FlagDataHandler::generateScanStartStopMap()
     721             : {
     722           0 :         return;
     723             : }
     724             : 
     725             : 
     726             : // -----------------------------------------------------------------------
     727             : // Set Data Selection parameters
     728             : // -----------------------------------------------------------------------
     729             : bool
     730         974 : FlagDataHandler::setDataSelection(Record record)
     731             : {
     732         974 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     733             : 
     734             :         int exists;
     735             : 
     736         974 :         exists = record.fieldNumber ("array");
     737         974 :         if (exists >= 0)
     738             :         {
     739         950 :                 anySelection_p = true;
     740         950 :                 record.get (record.fieldNumber ("array"), arraySelection_p);
     741             : 
     742         950 :                 if (arraySelection_p.size())
     743             :                 {
     744           1 :                         *logger_p << LogIO::DEBUG1 << " array selection is " << arraySelection_p << LogIO::POST;
     745             :                 }
     746             :         }
     747             :         else
     748             :         {
     749          24 :                 arraySelection_p = String("");
     750          24 :                 *logger_p << LogIO::DEBUG1 << " no array selection" << LogIO::POST;
     751             :         }
     752             : 
     753         974 :         exists = record.fieldNumber ("field");
     754         974 :         if (exists >= 0)
     755             :         {
     756         951 :                 anySelection_p = true;
     757         951 :                 record.get (record.fieldNumber ("field"), fieldSelection_p);
     758             : 
     759         951 :                 if (fieldSelection_p.size())
     760             :                 {
     761          13 :                         *logger_p << LogIO::DEBUG1 << " field selection is " << fieldSelection_p << LogIO::POST;
     762             :                 }
     763             :         }
     764             :         else
     765             :         {
     766          23 :                 fieldSelection_p = String("");
     767          23 :                 *logger_p << LogIO::DEBUG1 << " no field selection" << LogIO::POST;
     768             :         }
     769             : 
     770         974 :         exists = record.fieldNumber ("scan");
     771         974 :         if (exists >= 0)
     772             :         {
     773         961 :                 anySelection_p = true;
     774         961 :                 record.get (record.fieldNumber ("scan"), scanSelection_p);
     775             : 
     776         961 :                 if (scanSelection_p.size())
     777             :                 {
     778          45 :                         *logger_p << LogIO::DEBUG1 << " scan selection is " << scanSelection_p << LogIO::POST;
     779             :                 }
     780             :         }
     781             :         else
     782             :         {
     783          13 :                 scanSelection_p = String("");
     784          13 :                 *logger_p << LogIO::DEBUG1 << " no scan selection" << LogIO::POST;
     785             :         }
     786             : 
     787         974 :         exists = record.fieldNumber ("timerange");
     788         974 :         if (exists >= 0)
     789             :         {
     790         952 :                 anySelection_p = true;
     791         952 :                 record.get (record.fieldNumber ("timerange"), timeSelection_p);
     792             : 
     793         952 :                 if (timeSelection_p.size())
     794             :                 {
     795          13 :                         *logger_p << LogIO::DEBUG1 << " timerange selection is " << timeSelection_p << LogIO::POST;
     796             :                 }
     797             :         }
     798             :         else
     799             :         {
     800          22 :                 timeSelection_p = String("");
     801          22 :                 *logger_p << LogIO::DEBUG1 << " no timerange selection" << LogIO::POST;
     802             :         }
     803             : 
     804         974 :         exists = record.fieldNumber ("spw");
     805         974 :         if (exists >= 0)
     806             :         {
     807         959 :                 anySelection_p = true;
     808         959 :                 record.get (record.fieldNumber ("spw"), spwSelection_p);
     809             : 
     810         959 :                 if (spwSelection_p.size())
     811             :                 {
     812         140 :                         *logger_p << LogIO::DEBUG1 << " spw selection is " << spwSelection_p << LogIO::POST;
     813             :                 }
     814             :         }
     815             :         else
     816             :         {
     817          15 :                 spwSelection_p = String("");
     818          15 :                 *logger_p << LogIO::DEBUG1 << " no spw selection" << LogIO::POST;
     819             :         }
     820             : 
     821         974 :         exists = record.fieldNumber ("antenna");
     822         974 :         if (exists >= 0)
     823             :         {
     824         951 :                 anySelection_p = true;
     825         951 :                 record.get (record.fieldNumber ("antenna"), baselineSelection_p);
     826             : 
     827         951 :                 if (baselineSelection_p.size())
     828             :                 {
     829          35 :                         *logger_p << LogIO::DEBUG1 << " antenna selection is " << baselineSelection_p << LogIO::POST;
     830             :                 }
     831             :         }
     832             :         else
     833             :         {
     834          23 :                 baselineSelection_p = String("");
     835          23 :                 *logger_p << LogIO::DEBUG1 << " no antenna selection" << LogIO::POST;
     836             :         }
     837             : 
     838         974 :         exists = record.fieldNumber ("uvrange");
     839         974 :         if (exists >= 0)
     840             :         {
     841         950 :                 anySelection_p = true;
     842         950 :                 record.get (record.fieldNumber ("uvrange"), uvwSelection_p);
     843             : 
     844         950 :                 if (uvwSelection_p.size())
     845             :                 {
     846           2 :                         *logger_p << LogIO::DEBUG1 << " uvrange selection is " << uvwSelection_p << LogIO::POST;
     847             :                 }
     848             :         }
     849             :         else
     850             :         {
     851          24 :                 uvwSelection_p = String("");
     852          24 :                 *logger_p << LogIO::DEBUG1 << " no uvrange selection" << LogIO::POST;
     853             :         }
     854             : 
     855         974 :         exists = record.fieldNumber ("correlation");
     856         974 :         if (exists >= 0)
     857             :         {
     858         950 :                 anySelection_p = true;
     859         950 :                 record.get (record.fieldNumber ("correlation"), polarizationSelection_p);
     860             : 
     861         950 :                 if (polarizationSelection_p.size())
     862             :                 {
     863           0 :                         *logger_p << LogIO::DEBUG1 << " correlation selection is " << polarizationSelection_p << LogIO::POST;
     864             :                 }
     865             :         }
     866             :         else
     867             :         {
     868          24 :                 polarizationSelection_p = String("");
     869          24 :                 *logger_p << LogIO::DEBUG1 << " no correlation selection" << LogIO::POST;
     870             :         }
     871             : 
     872         974 :         exists = record.fieldNumber ("observation");
     873         974 :         if (exists >= 0)
     874             :         {
     875         951 :                 anySelection_p = true;
     876         951 :                 record.get (record.fieldNumber ("observation"), observationSelection_p);
     877             : 
     878         951 :                 if (observationSelection_p.size())
     879             :                 {
     880           8 :                         *logger_p << LogIO::DEBUG1 << " observation selection is " << observationSelection_p << LogIO::POST;
     881             :                 }
     882             :         }
     883             :         else
     884             :         {
     885          23 :                 observationSelection_p = String("");
     886          23 :                 *logger_p << LogIO::DEBUG1 << " no observation selection" << LogIO::POST;
     887             :         }
     888             : 
     889         974 :         exists = record.fieldNumber ("intent");
     890         974 :         if (exists >= 0)
     891             :         {
     892         950 :                 anySelection_p = true;
     893         950 :                 record.get (record.fieldNumber ("intent"), scanIntentSelection_p);
     894             : 
     895         950 :                 if (scanIntentSelection_p.size())
     896             :                 {
     897           2 :                         *logger_p << LogIO::DEBUG1 << " scan intent selection is " << scanIntentSelection_p << LogIO::POST;
     898             :                 }
     899             :         }
     900             :         else
     901             :         {
     902          24 :                 scanIntentSelection_p = String("");
     903          24 :                 *logger_p << LogIO::DEBUG1 << " no scan intent selection" << LogIO::POST;
     904             :         }
     905             : 
     906         974 :         return true;
     907             : }
     908             : 
     909             : 
     910             : // -----------------------------------------------------------------------
     911             : // Set time interval
     912             : // -----------------------------------------------------------------------
     913             : void
     914        1169 : FlagDataHandler::setTimeInterval(Double timeInterval)
     915             : {
     916        1169 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     917        1169 :         if (timeInterval >= 0)
     918             :         {
     919        1169 :                 timeInterval_p = timeInterval;
     920        1169 :                 *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        1169 :         return;
     928             : }
     929             : 
     930             : 
     931             : // -----------------------------------------------------------------------
     932             : // Enable async i/o
     933             : // -----------------------------------------------------------------------
     934             : void
     935        1260 : FlagDataHandler::enableAsyncIO(Bool enable)
     936             : {
     937        1260 :         if (enable)
     938             :         {
     939             :                 // Check if async i/o is enabled (double check for ROVisibilityIteratorAsync and FlagDataHandler config)
     940         167 :                 asyncio_enabled_p = vi::VisibilityIterator2::isAsynchronousIoEnabled();
     941             : 
     942         167 :                 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         167 :                         *logger_p << LogIO::DEBUG1
     959             :                                   << " Asynchronous i/o not enabled for FlagDataHandler and CASA in general."
     960         167 :                                   << LogIO::POST;
     961             :                 }
     962             :         }
     963             :         else
     964             :         {
     965        1093 :                 asyncio_enabled_p = false;
     966             :         }
     967             : 
     968             : 
     969        1260 :         if (!asyncio_enabled_p)
     970             :         {
     971        1260 :                 slurp_p = true;
     972        1260 :                 AipsrcValue<Bool>::find (slurp_p,"FlagDataHandler.slurp", true);
     973             :         }
     974             :         else
     975             :         {
     976           0 :                 slurp_p = false;
     977             :         }
     978             : 
     979        1260 :         return;
     980             : }
     981             : 
     982             : 
     983             : // -----------------------------------------------------------------------
     984             : // Function to handled columns pre-load (to avoid problems with parallelism)
     985             : // -----------------------------------------------------------------------
     986             : void
     987        4194 : FlagDataHandler::preLoadColumn(VisBufferComponent2 column)
     988             : {
     989        4194 :         logger_p->origin(LogOrigin("FlagDataHandler",__FUNCTION__,WHERE));
     990             : 
     991        4194 :         if (std::find (preLoadColumns_p.begin(), preLoadColumns_p.end(), column) == preLoadColumns_p.end())
     992             :         {
     993        1549 :                 *logger_p << LogIO::DEBUG1 << " Adding column to list: "
     994        1549 :                           << VisBufferComponents2::name (column) << LogIO::POST;
     995        1549 :                 preLoadColumns_p.push_back(column);
     996             :         }
     997             : 
     998        4194 :         return;
     999             : }
    1000             : 
    1001             : 
    1002             : // -----------------------------------------------------------------------
    1003             : // Fill pre-fetch columns
    1004             : // -----------------------------------------------------------------------
    1005             : void
    1006      351167 : FlagDataHandler::preFetchColumns()
    1007             : {
    1008     3500063 :         for (vector<VisBufferComponent2>::iterator iter=preLoadColumns_p.begin();iter!=preLoadColumns_p.end();iter++)
    1009             :         {
    1010     3148896 :                 switch (*iter)
    1011             :                 {
    1012       86167 :                         case VisBufferComponent2::Antenna1:
    1013             :                         {
    1014       86167 :                                 if (asyncio_enabled_p)
    1015             :                                 {
    1016           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Antenna1);
    1017             :                                 }
    1018             :                                 else
    1019             :                                 {
    1020       86167 :                                         visibilityBuffer_p->antenna1();
    1021             :                                 }
    1022       86167 :                                 break;
    1023             :                         }
    1024       86167 :                         case VisBufferComponent2::Antenna2:
    1025             :                         {
    1026       86167 :                                 if (asyncio_enabled_p)
    1027             :                                 {
    1028           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Antenna2);
    1029             :                                 }
    1030             :                                 else
    1031             :                                 {
    1032       86167 :                                         visibilityBuffer_p->antenna2();
    1033             :                                 }
    1034       86167 :                                 break;
    1035             :                         }
    1036      351167 :                         case VisBufferComponent2::ArrayId:
    1037             :                         {
    1038      351167 :                                 if (asyncio_enabled_p)
    1039             :                                 {
    1040           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ArrayId);
    1041             :                                 }
    1042             :                                 else
    1043             :                                 {
    1044      351167 :                                         visibilityBuffer_p->arrayId();
    1045             :                                 }
    1046      351167 :                                 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      113638 :                         case VisBufferComponent2::CorrType:
    1075             :                         {
    1076      113638 :                                 if (asyncio_enabled_p)
    1077             :                                 {
    1078           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::CorrType);
    1079             :                                 }
    1080             :                                 else
    1081             :                                 {
    1082      113638 :                                         visibilityBuffer_p->correlationTypes();
    1083             :                                 }
    1084      113638 :                                 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        6602 :                         case VisBufferComponent2::VisibilityCubeCorrected:
    1099             :                         {
    1100        6602 :                                 if (asyncio_enabled_p)
    1101             :                                 {
    1102           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeCorrected);
    1103             :                                 }
    1104             :                                 else
    1105             :                                 {
    1106        6602 :                                         visibilityBuffer_p->visCubeCorrected();
    1107             :                                 }
    1108        6602 :                                 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      351167 :                         case VisBufferComponent2::FieldId:
    1195             :                         {
    1196      351167 :                                 if (asyncio_enabled_p)
    1197             :                                 {
    1198           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::FieldId);
    1199             :                                 }
    1200             :                                 else
    1201             :                                 {
    1202      351167 :                                         visibilityBuffer_p->fieldId();
    1203             :                                 }
    1204      351167 :                                 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        3324 :                         case VisBufferComponent2::VisibilityCubeModel:
    1293             :                         {
    1294        3324 :                                 if (asyncio_enabled_p)
    1295             :                                 {
    1296           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeModel);
    1297             :                                 }
    1298             :                                 else
    1299             :                                 {
    1300        3324 :                                         visibilityBuffer_p->visCubeModel();
    1301             :                                 }
    1302        3324 :                                 break;
    1303             :                         }
    1304      351167 :                         case VisBufferComponent2::NChannels:
    1305             :                         {
    1306      351167 :                                 if (asyncio_enabled_p)
    1307             :                                 {
    1308           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NChannels);
    1309             :                                 }
    1310             :                                 else
    1311             :                                 {
    1312      351167 :                                         visibilityBuffer_p->nChannels();
    1313             :                                 }
    1314      351167 :                                 break;
    1315             :                         }
    1316      351167 :                         case VisBufferComponent2::NCorrelations:
    1317             :                         {
    1318      351167 :                                 if (asyncio_enabled_p)
    1319             :                                 {
    1320           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NCorrelations);
    1321             :                                 }
    1322             :                                 else
    1323             :                                 {
    1324      351167 :                                         visibilityBuffer_p->nCorrelations();
    1325             :                                 }
    1326      351167 :                                 break;
    1327             :                         }
    1328      351167 :                         case VisBufferComponent2::NRows:
    1329             :                         {
    1330      351167 :                                 if (asyncio_enabled_p)
    1331             :                                 {
    1332           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::NRows);
    1333             :                                 }
    1334             :                                 else
    1335             :                                 {
    1336      351167 :                                         visibilityBuffer_p->nRows();
    1337             :                                 }
    1338      351167 :                                 break;
    1339             :                         }
    1340      351167 :                         case VisBufferComponent2::ObservationId:
    1341             :                         {
    1342      351167 :                                 if (asyncio_enabled_p)
    1343             :                                 {
    1344           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ObservationId);
    1345             :                                 }
    1346             :                                 else
    1347             :                                 {
    1348      351167 :                                         visibilityBuffer_p->observationId();
    1349             :                                 }
    1350      351167 :                                 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       30900 :                         case VisBufferComponent2::VisibilityCubeObserved:
    1365             :                         {
    1366       30900 :                                 if (asyncio_enabled_p)
    1367             :                                 {
    1368           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::VisibilityCubeObserved);
    1369             :                                 }
    1370             :                                 else
    1371             :                                 {
    1372       30900 :                                         visibilityBuffer_p->visCube();
    1373             :                                 }
    1374       30900 :                                 break;
    1375             :                         }
    1376         470 :                         case VisBufferComponent2::PhaseCenter:
    1377             :                         {
    1378         470 :                                 if (asyncio_enabled_p)
    1379             :                                 {
    1380           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::PhaseCenter);
    1381             :                                 }
    1382             :                                 else
    1383             :                                 {
    1384         470 :                                         visibilityBuffer_p->phaseCenter();
    1385             :                                 }
    1386         470 :                                 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         277 :                         case VisBufferComponent2::ProcessorId:
    1401             :                         {
    1402         277 :                                 if (asyncio_enabled_p)
    1403             :                                 {
    1404           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::ProcessorId);
    1405             :                                 }
    1406             :                                 else
    1407             :                                 {
    1408         277 :                                         visibilityBuffer_p->processorId();
    1409             :                                 }
    1410         277 :                                 break;
    1411             :                         }
    1412      351167 :                         case VisBufferComponent2::Scan:
    1413             :                         {
    1414      351167 :                                 if (asyncio_enabled_p)
    1415             :                                 {
    1416           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Scan);
    1417             :                                 }
    1418             :                                 else
    1419             :                                 {
    1420      351167 :                                         visibilityBuffer_p->scan();
    1421             :                                 }
    1422      351167 :                                 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      351167 :                         case VisBufferComponent2::SpectralWindows:
    1449             :                         {
    1450      351167 :                                 if (asyncio_enabled_p)
    1451             :                                 {
    1452           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::SpectralWindows);
    1453             :                                 }
    1454             :                                 else
    1455             :                                 {
    1456      351167 :                                         visibilityBuffer_p->spectralWindows();
    1457             :                                 }
    1458      351167 :                                 break;
    1459             :                         }
    1460          71 :                         case VisBufferComponent2::StateId:
    1461             :                         {
    1462          71 :                                 if (asyncio_enabled_p)
    1463             :                                 {
    1464           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::StateId);
    1465             :                                 }
    1466             :                                 else
    1467             :                                 {
    1468          71 :                                         visibilityBuffer_p->stateId();
    1469             :                                 }
    1470          71 :                                 break;
    1471             :                         }
    1472        8111 :                         case VisBufferComponent2::Time:
    1473             :                         {
    1474        8111 :                                 if (asyncio_enabled_p)
    1475             :                                 {
    1476           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Time);
    1477             :                                 }
    1478             :                                 else
    1479             :                                 {
    1480        8111 :                                         visibilityBuffer_p->time();
    1481             :                                 }
    1482        8111 :                                 break;
    1483             :                         }
    1484         470 :                         case VisBufferComponent2::TimeCentroid:
    1485             :                         {
    1486         470 :                                 if (asyncio_enabled_p)
    1487             :                                 {
    1488           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::TimeCentroid);
    1489             :                                 }
    1490             :                                 else
    1491             :                                 {
    1492         470 :                                         visibilityBuffer_p->timeCentroid();
    1493             :                                 }
    1494         470 :                                 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        3334 :                         case VisBufferComponent2::Uvw:
    1545             :                         {
    1546        3334 :                                 if (asyncio_enabled_p)
    1547             :                                 {
    1548           0 :                                         prefetchColumns_p->operator +=(VisBufferComponent2::Uvw);
    1549             :                                 }
    1550             :                                 else
    1551             :                                 {
    1552        3334 :                                         visibilityBuffer_p->uvw();
    1553             :                                 }
    1554        3334 :                                 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      351167 :         return;
    1605             : }
    1606             : 
    1607             : 
    1608             : // -----------------------------------------------------------------------
    1609             : // Methods to trigger generation of different maps
    1610             : // -----------------------------------------------------------------------
    1611             : void
    1612          76 : FlagDataHandler::setMapAntennaPairs(bool activated)
    1613             : {
    1614          76 :         mapAntennaPairs_p=activated;
    1615             :         // Pre-Load antenna1, antenna2
    1616          76 :         preLoadColumn(VisBufferComponent2::Antenna1);
    1617          76 :         preLoadColumn(VisBufferComponent2::Antenna2);
    1618          76 : }
    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         516 : FlagDataHandler::setMapPolarizations(bool activated)
    1632             : {
    1633         516 :         mapPolarizations_p=activated;
    1634             :         // Pre-Load corrType
    1635         516 :         preLoadColumn(VisBufferComponent2::CorrType);
    1636         516 : }
    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          14 : FlagDataHandler::setScanStartStopMap(bool activated)
    1657             : {
    1658          14 :         mapScanStartStop_p=activated;
    1659             :         // Pre-Load scan and time
    1660          14 :         preLoadColumn(VisBufferComponent2::Scan);
    1661          14 :         preLoadColumn(VisBufferComponent2::Time);
    1662          14 : }
    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          30 :         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          30 :         return weight_spectrum_p;
    1765          30 : }
    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       29969 : VisMapper::VisMapper(String expression,polarizationMap *polMap)
    1780             : {
    1781       29969 :         rightVis_p = NULL;
    1782       29969 :         leftVis_p = NULL;
    1783       29969 :         setExpressionMapping(expression,polMap);
    1784       29969 : }
    1785             : 
    1786             : 
    1787             : void
    1788       43321 : VisMapper::setParentCubes(CubeView<Complex> *leftVis,CubeView<Complex> *rightVis)
    1789             : {
    1790       43321 :         if (rightVis_p != NULL) delete rightVis_p;
    1791       43321 :         if (leftVis_p != NULL) delete leftVis_p;
    1792             : 
    1793       43321 :         leftVis_p = leftVis;
    1794       43321 :         IPosition leftVisSize = leftVis->shape(); // pol,chan,row
    1795       43321 :         reducedLength_p = IPosition(3);
    1796       43321 :         reducedLength_p(0) = leftVisSize(1); // chan
    1797       43321 :         reducedLength_p(1) = leftVisSize(2); // row
    1798       43321 :         if (selectedCorrelationProducts_p.size() > 0)
    1799             :         {
    1800       43321 :                 reducedLength_p(2) = selectedCorrelations_p.size(); //pols
    1801             :         }
    1802             :         else
    1803             :         {
    1804           0 :                 reducedLength_p(2) = leftVisSize(1); //pols
    1805             :         }
    1806             : 
    1807             : 
    1808       43321 :         if (rightVis != NULL)
    1809             :         {
    1810        3476 :                 rightVis_p = rightVis;
    1811        3476 :                 getVis_p = &VisMapper::diffVis;
    1812             :         }
    1813             :         else
    1814             :         {
    1815       39845 :                 rightVis_p = NULL;
    1816       39845 :                 getVis_p = &VisMapper::leftVis;
    1817             :         }
    1818       43321 : }
    1819             : 
    1820             : 
    1821             : void
    1822       29969 : VisMapper::setExpressionMapping(String expression,polarizationMap *polMap)
    1823             : {
    1824       29969 :         selectedCorrelationProducts_p.clear();
    1825       29969 :         selectedCorrelations_p.clear();
    1826       29969 :         selectedCorrelationStrings_p.clear();
    1827       29969 :         expression_p = expression;
    1828       29969 :         polMap_p = polMap;
    1829       29969 :         bool matchExpression = false;
    1830             : 
    1831             :         // Parse complex unitary function
    1832       29969 :         if (expression_p.find("REAL") != string::npos)
    1833             :         {
    1834        1038 :                 applyVisExpr_p = &VisMapper::real;
    1835             :         }
    1836       28931 :         else if (expression_p.find("IMAG") != string::npos)
    1837             :         {
    1838           0 :                 applyVisExpr_p = &VisMapper::imag;
    1839             :         }
    1840       28931 :         else if (expression_p.find("ARG") != string::npos)
    1841             :         {
    1842           0 :                 applyVisExpr_p = &VisMapper::arg;
    1843             :         }
    1844       28931 :         else if (expression_p.find("ABS") != string::npos)
    1845             :         {
    1846       28743 :                 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       29969 :         if (expression_p.find("WVR") != string::npos)
    1859             :         {
    1860          38 :                 if (polMap_p->find(Stokes::I) != polMap_p->end())
    1861             :                 {
    1862          38 :                         vector<uInt> selectedPolarizations;
    1863          38 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::I]);
    1864          38 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1865          38 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_i);
    1866          38 :                         selectedCorrelationStrings_p.push_back(string("I"));
    1867          38 :                         matchExpression = true;
    1868          38 :                 }
    1869             :                 else
    1870             :                 {
    1871             :                         //throw AipsError("Requested correlation product (WVR - I) not available");
    1872             :                 }
    1873             :         }
    1874       29969 :         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          52 :                 }
    1885             :                 else
    1886             :                 {
    1887             :                         //throw AipsError("Requested correlation product (XX) not available");
    1888             :                 }
    1889             :         }
    1890       29969 :         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          47 :                 }
    1901             :                 else
    1902             :                 {
    1903             :                         //throw AipsError("Requested correlation product (YY) not available");
    1904             :                 }
    1905             :         }
    1906       29969 :         if (expression_p.find("XY") != string::npos)
    1907             :         {
    1908           0 :                 if (polMap_p->find(Stokes::XY) != polMap_p->end())
    1909             :                 {
    1910           0 :                         vector<uInt> selectedPolarizations;
    1911           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XY]);
    1912           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1913           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::linear_xy);
    1914           0 :                         selectedCorrelationStrings_p.push_back(string("XY"));
    1915           0 :                         matchExpression = true;
    1916           0 :                 }
    1917             :                 else
    1918             :                 {
    1919             :                         //throw AipsError("Requested correlation product (XY) not available");
    1920             :                 }
    1921             :         }
    1922       29969 :         if (expression_p.find("YX") != string::npos)
    1923             :         {
    1924           0 :                 if (polMap_p->find(Stokes::YX) != polMap_p->end())
    1925             :                 {
    1926           0 :                         vector<uInt> selectedPolarizations;
    1927           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YX]);
    1928           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1929           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::linear_yx);
    1930           0 :                         selectedCorrelationStrings_p.push_back(string("YX"));
    1931           0 :                         matchExpression = true;
    1932           0 :                 }
    1933             :                 else
    1934             :                 {
    1935             :                         //throw AipsError("Requested correlation product (YX) not available");
    1936             :                 }
    1937             :         }
    1938       29969 :         if (expression_p.find("RR") != string::npos)
    1939             :         {
    1940       27709 :                 if (polMap_p->find(Stokes::RR) != polMap_p->end())
    1941             :                 {
    1942       27709 :                         vector<uInt> selectedPolarizations;
    1943       27709 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RR]);
    1944       27709 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1945       27709 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_rr);
    1946       27709 :                         selectedCorrelationStrings_p.push_back(string("RR"));
    1947       27709 :                         matchExpression = true;
    1948       27709 :                 }
    1949             :                 else
    1950             :                 {
    1951             :                         //throw AipsError("Requested correlation product (RR) not available");
    1952             :                 }
    1953             :         }
    1954       29969 :         if (expression_p.find("LL") != string::npos)
    1955             :         {
    1956       24583 :                 if (polMap_p->find(Stokes::LL) != polMap_p->end())
    1957             :                 {
    1958       24545 :                         vector<uInt> selectedPolarizations;
    1959       24545 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LL]);
    1960       24545 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1961       24545 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_ll);
    1962       24545 :                         selectedCorrelationStrings_p.push_back(string("LL"));
    1963       24545 :                         matchExpression = true;
    1964       24545 :                 }
    1965             :                 else
    1966             :                 {
    1967             :                         //throw AipsError("Requested correlation product (LL) not available");
    1968             :                 }
    1969             :         }
    1970       29969 :         if (expression_p.find("LR") != string::npos)
    1971             :         {
    1972       24016 :                 if (polMap_p->find(Stokes::LR) != polMap_p->end())
    1973             :                 {
    1974       24016 :                         vector<uInt> selectedPolarizations;
    1975       24016 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LR]);
    1976       24016 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1977       24016 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_lr);
    1978       24016 :                         selectedCorrelationStrings_p.push_back(string("LR"));
    1979       24016 :                         matchExpression = true;
    1980       24016 :                 }
    1981             :                 else
    1982             :                 {
    1983             :                         //throw AipsError("Requested correlation product (LR) not available");
    1984             :                 }
    1985             :         }
    1986       29969 :         if (expression_p.find("RL") != string::npos)
    1987             :         {
    1988       24016 :                 if (polMap_p->find(Stokes::RL) != polMap_p->end())
    1989             :                 {
    1990       24016 :                         vector<uInt> selectedPolarizations;
    1991       24016 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RL]);
    1992       24016 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    1993       24016 :                         selectedCorrelationProducts_p.push_back(&VisMapper::circular_rl);
    1994       24016 :                         selectedCorrelationStrings_p.push_back(string("RL"));
    1995       24016 :                         matchExpression = true;
    1996       24016 :                 }
    1997             :                 else
    1998             :                 {
    1999             :                         //throw AipsError("Requested correlation product (RL) not available");
    2000             :                 }
    2001             :         }
    2002       29969 :         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           0 :                 }
    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          33 :                 }
    2023           0 :                 else if ((polMap_p->find(Stokes::RR) != polMap_p->end()) and (polMap_p->find(Stokes::LL) != polMap_p->end()))
    2024             :                 {
    2025           0 :                         vector<uInt> selectedPolarizations;
    2026           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RR]);
    2027           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LL]);
    2028           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2029           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_i_from_circular);
    2030           0 :                         selectedCorrelationStrings_p.push_back(string("I = (RR+LL)/2"));
    2031           0 :                         matchExpression = true;
    2032           0 :                 }
    2033             :                 else
    2034             :                 {
    2035             :                         //throw AipsError("Requested Stokes parameter (I) cannot be computed from available polarizations");
    2036             :                 }
    2037             :         }
    2038       29969 :         if (expression_p.find("Q") != string::npos)
    2039             :         {
    2040           0 :                 if (polMap_p->find(Stokes::Q) != polMap_p->end())
    2041             :                 {
    2042           0 :                         vector<uInt> selectedPolarizations;
    2043           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::Q]);
    2044           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2045           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_q);
    2046           0 :                         selectedCorrelationStrings_p.push_back(string("Q"));
    2047           0 :                         matchExpression = true;
    2048           0 :                 }
    2049           0 :                 else if ((polMap_p->find(Stokes::XX) != polMap_p->end()) and (polMap_p->find(Stokes::YY) != polMap_p->end()))
    2050             :                 {
    2051           0 :                         vector<uInt> selectedPolarizations;
    2052           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XX]);
    2053           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YY]);
    2054           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2055           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_q_from_linear);
    2056           0 :                         selectedCorrelationStrings_p.push_back(string("Q = (XX-YY)/2"));
    2057           0 :                         matchExpression = true;
    2058           0 :                 }
    2059           0 :                 else if ((polMap_p->find(Stokes::RL) != polMap_p->end()) and (polMap_p->find(Stokes::LR) != polMap_p->end()))
    2060             :                 {
    2061           0 :                         vector<uInt> selectedPolarizations;
    2062           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RL]);
    2063           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LR]);
    2064           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2065           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_q_from_circular);
    2066           0 :                         selectedCorrelationStrings_p.push_back(string("Q = (RL-LR)/2"));
    2067           0 :                         matchExpression = true;
    2068           0 :                 }
    2069             :                 else
    2070             :                 {
    2071             :                         //throw AipsError("Requested Stokes parameter (Q) cannot be computed from available polarizations");
    2072             :                 }
    2073             :         }
    2074       29969 :         if (expression_p.find("U") != string::npos)
    2075             :         {
    2076           0 :                 if (polMap_p->find(Stokes::U) != polMap_p->end())
    2077             :                 {
    2078           0 :                         vector<uInt> selectedPolarizations;
    2079           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::U]);
    2080           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2081           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_u);
    2082           0 :                         selectedCorrelationStrings_p.push_back(string("U"));
    2083           0 :                         matchExpression = true;
    2084           0 :                 }
    2085           0 :                 else if ((polMap_p->find(Stokes::XY) != polMap_p->end()) and (polMap_p->find(Stokes::YX) != polMap_p->end()))
    2086             :                 {
    2087           0 :                         vector<uInt> selectedPolarizations;
    2088           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XY]);
    2089           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YX]);
    2090           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2091           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_u_from_linear);
    2092           0 :                         selectedCorrelationStrings_p.push_back(string("U = (XY-YX)/2"));
    2093           0 :                         matchExpression = true;
    2094           0 :                 }
    2095           0 :                 else if ((polMap_p->find(Stokes::RL) != polMap_p->end()) and (polMap_p->find(Stokes::LR) != polMap_p->end()))
    2096             :                 {
    2097           0 :                         vector<uInt> selectedPolarizations;
    2098           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RL]);
    2099           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LR]);
    2100           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2101           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_u_from_circular);
    2102           0 :                         selectedCorrelationStrings_p.push_back(string(" U = (RL-LR)/2i"));
    2103           0 :                         matchExpression = true;
    2104           0 :                 }
    2105             :                 else
    2106             :                 {
    2107             :                         //throw AipsError("Requested Stokes parameter (U) cannot be computed from available polarizations");
    2108             :                 }
    2109             :         }
    2110       29969 :         if ((expression_p.find("V") != string::npos) and (expression_p.find("WVR") == string::npos))
    2111             :         {
    2112           0 :                 if (polMap_p->find(Stokes::V) != polMap_p->end())
    2113             :                 {
    2114           0 :                         vector<uInt> selectedPolarizations;
    2115           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::V]);
    2116           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2117           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_v);
    2118           0 :                         selectedCorrelationStrings_p.push_back(string("V"));
    2119           0 :                         matchExpression = true;
    2120           0 :                 }
    2121           0 :                 else if ((polMap_p->find(Stokes::XY) != polMap_p->end()) and (polMap_p->find(Stokes::YX) != polMap_p->end()))
    2122             :                 {
    2123           0 :                         vector<uInt> selectedPolarizations;
    2124           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::XY]);
    2125           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::YX]);
    2126           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2127           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_v_from_linear);
    2128           0 :                         selectedCorrelationStrings_p.push_back(string("V = (XY-YX)/2i"));
    2129           0 :                         matchExpression = true;
    2130           0 :                 }
    2131           0 :                 else if ((polMap_p->find(Stokes::RR) != polMap_p->end()) and (polMap_p->find(Stokes::LL) != polMap_p->end()))
    2132             :                 {
    2133           0 :                         vector<uInt> selectedPolarizations;
    2134           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::RR]);
    2135           0 :                         selectedPolarizations.push_back((*polMap_p)[Stokes::LL]);
    2136           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2137           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::stokes_v_from_circular);
    2138           0 :                         selectedCorrelationStrings_p.push_back(string("V = (RR-LL)/2"));
    2139           0 :                         matchExpression = true;
    2140           0 :                 }
    2141             :                 else
    2142             :                 {
    2143             :                         //throw AipsError("Requested Stokes parameter (V) cannot be computed from available polarizations");
    2144             :                 }
    2145             :         }
    2146       29969 :         if (expression_p.find("SOL1") != string::npos)
    2147             :         {
    2148        1371 :                 if (polMap_p->find(VisMapper::CALSOL1) != polMap_p->end())
    2149             :                 {
    2150        1371 :                         vector<uInt> selectedPolarizations;
    2151        1371 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL1]);
    2152        1371 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2153        1371 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol1);
    2154        1371 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 1"));
    2155        1371 :                         matchExpression = true;
    2156        1371 :                 }
    2157             :                 else
    2158             :                 {
    2159             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2160             :                 }
    2161             :         }
    2162       29969 :         if (expression_p.find("SOL2") != string::npos)
    2163             :         {
    2164        1193 :                 if (polMap_p->find(VisMapper::CALSOL2) != polMap_p->end())
    2165             :                 {
    2166        1193 :                         vector<uInt> selectedPolarizations;
    2167        1193 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL2]);
    2168        1193 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2169        1193 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol2);
    2170        1193 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 2"));
    2171        1193 :                         matchExpression = true;
    2172        1193 :                 }
    2173             :                 else
    2174             :                 {
    2175             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2176             :                 }
    2177             :         }
    2178       29969 :         if (expression_p.find("SOL3") != string::npos)
    2179             :         {
    2180         686 :                 if (polMap_p->find(VisMapper::CALSOL3) != polMap_p->end())
    2181             :                 {
    2182           0 :                         vector<uInt> selectedPolarizations;
    2183           0 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL3]);
    2184           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2185           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol3);
    2186           0 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 3"));
    2187           0 :                         matchExpression = true;
    2188           0 :                 }
    2189             :                 else
    2190             :                 {
    2191             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2192             :                 }
    2193             :         }
    2194       29969 :         if (expression_p.find("SOL4") != string::npos)
    2195             :         {
    2196         686 :                 if (polMap_p->find(VisMapper::CALSOL4) != polMap_p->end())
    2197             :                 {
    2198           0 :                         vector<uInt> selectedPolarizations;
    2199           0 :                         selectedPolarizations.push_back((*polMap_p)[VisMapper::CALSOL4]);
    2200           0 :                         selectedCorrelations_p.push_back(selectedPolarizations);
    2201           0 :                         selectedCorrelationProducts_p.push_back(&VisMapper::calsol4);
    2202           0 :                         selectedCorrelationStrings_p.push_back(string("Calibration Solution 4"));
    2203           0 :                         matchExpression = true;
    2204           0 :                 }
    2205             :                 else
    2206             :                 {
    2207             :                         //throw AipsError("Requested Calibration solution element (Sol1) not available");
    2208             :                 }
    2209             :         }
    2210             : 
    2211             : 
    2212       29969 :         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       29969 : }
    2217             : 
    2218             : 
    2219       29969 : VisMapper::~VisMapper()
    2220             : {
    2221       29969 :         if (rightVis_p != NULL) delete rightVis_p;
    2222       29969 :         if (leftVis_p != NULL) delete leftVis_p;
    2223       29969 : }
    2224             : 
    2225             : 
    2226             : Float
    2227    46586036 : VisMapper::operator()(uInt chan, uInt row)
    2228             : {
    2229    46586036 :         Complex val = (*this.*selectedCorrelationProducts_p[0])(chan,row);
    2230    93172072 :         return (*this.*applyVisExpr_p)(val);
    2231             : }
    2232             : 
    2233             : 
    2234             : Float
    2235    74062129 : VisMapper::operator()(uInt pol, uInt chan, uInt row)
    2236             : {
    2237    74062129 :         Complex val = (*this.*selectedCorrelationProducts_p[pol])(chan,row);
    2238   148124258 :         return (*this.*applyVisExpr_p)(val);
    2239             : }
    2240             : 
    2241             : 
    2242             : Complex
    2243   683630084 : VisMapper::correlationProduct(uInt pol, uInt chan, uInt row)
    2244             : {
    2245   683630084 :         return (*this.*selectedCorrelationProducts_p[pol])(chan,row);
    2246             : }
    2247             : 
    2248             : 
    2249             : Complex
    2250   765505091 : VisMapper::leftVis(uInt pol, uInt chan, uInt row)
    2251             : {
    2252   765505091 :         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         608 : VisMapper::stokes_i(uInt chan, uInt row)
    2265             : {
    2266         608 :         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   204347788 : VisMapper::circular_rr(uInt chan, uInt row)
    2321             : {
    2322   204347788 :         return (*this.*getVis_p)((*polMap_p)[Stokes::RR],chan,row);
    2323             : }
    2324             : 
    2325             : 
    2326             : Complex
    2327   201196522 : VisMapper::circular_ll(uInt chan, uInt row)
    2328             : {
    2329   201196522 :         return (*this.*getVis_p)((*polMap_p)[Stokes::LL],chan,row);
    2330             : }
    2331             : 
    2332             : 
    2333             : Complex
    2334   187777853 : VisMapper::circular_rl(uInt chan, uInt row)
    2335             : {
    2336   187777853 :         return (*this.*getVis_p)((*polMap_p)[Stokes::RL],chan,row);
    2337             : }
    2338             : 
    2339             : 
    2340             : Complex
    2341   187776764 : VisMapper::circular_lr(uInt chan, uInt row)
    2342             : {
    2343   187776764 :         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      270000 :         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    10243711 : VisMapper::calsol1(uInt chan, uInt row)
    2417             : {
    2418    10243711 :         return (*this.*getVis_p)((*polMap_p)[VisMapper::CALSOL1],chan,row);
    2419             : }
    2420             : 
    2421             : 
    2422             : Complex
    2423    12472824 : VisMapper::calsol2(uInt chan, uInt row)
    2424             : {
    2425    12472824 :         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      344235 : FlagMapper::FlagMapper(Bool flag, vector< vector<uInt> > selectedCorrelations)
    2469             : {
    2470      344235 :         commonFlagsView_p = NULL;
    2471      344235 :         originalFlagsView_p = NULL;
    2472      344235 :         privateFlagsView_p = NULL;
    2473      344235 :         commonFlagRowView_p = NULL;
    2474      344235 :         originalFlagRowView_p = NULL;
    2475      344235 :         privateFlagRowView_p = NULL;
    2476      344235 :         setExpressionMapping(selectedCorrelations);
    2477      344235 :         nSelectedCorrelations_p = selectedCorrelations.size();
    2478      344235 :         flag_p = flag;
    2479      344235 : }
    2480             : 
    2481             : 
    2482             : void
    2483      361203 : FlagMapper::setParentCubes(CubeView<Bool> *commonFlagsView,CubeView<Bool> *originalFlagsView,CubeView<Bool> *privateFlagsView)
    2484             : {
    2485      361203 :         if (commonFlagsView_p != NULL) delete commonFlagsView_p;
    2486      361203 :         if (originalFlagsView_p != NULL) delete originalFlagsView_p;
    2487      361203 :         if (privateFlagsView_p != NULL) delete privateFlagsView_p;
    2488             : 
    2489      361203 :         commonFlagsView_p = commonFlagsView;
    2490      361203 :         originalFlagsView_p = originalFlagsView;
    2491      361203 :         if (privateFlagsView != NULL)
    2492             :         {
    2493           0 :                 privateFlagsView_p = privateFlagsView;
    2494           0 :                 applyFlag_p = &FlagMapper::applyPrivateFlags;
    2495             :         }
    2496             :         else
    2497             :         {
    2498      361203 :                 applyFlag_p = &FlagMapper::applyCommonFlags;
    2499             :         }
    2500             : 
    2501      361203 :         IPosition commonFlagCubeSize = commonFlagsView_p->shape(); // pol,chan,row
    2502      361203 :         reducedLength_p = IPosition(2);
    2503      361203 :         reducedLength_p(0) = commonFlagCubeSize(1); // chan
    2504      361203 :         reducedLength_p(1) = commonFlagCubeSize(2); // row
    2505             : 
    2506      361203 :         if (nSelectedCorrelations_p>0)
    2507             :         {
    2508      361203 :                 reducedLength_p(2) = nSelectedCorrelations_p; // pol
    2509             :         }
    2510             :         else
    2511             :         {
    2512           0 :                 reducedLength_p(2) = reducedLength_p(0);// pol
    2513             :         }
    2514             : 
    2515      361203 :         flagsPerRow_p = reducedLength_p(2)*reducedLength_p(0);
    2516      361203 : }
    2517             : 
    2518             : 
    2519             : void
    2520      361203 : FlagMapper::setParentFlagRow(VectorView<Bool> *commonFlagRowView,VectorView<Bool> *originalFlagRowView,VectorView<Bool> *privateFlagRowView)
    2521             : {
    2522      361203 :         if (commonFlagRowView_p != NULL) delete commonFlagRowView_p;
    2523      361203 :         if (originalFlagRowView_p != NULL) delete originalFlagRowView_p;
    2524      361203 :         if (privateFlagRowView_p != NULL) delete privateFlagRowView_p;
    2525             : 
    2526      361203 :         commonFlagRowView_p = commonFlagRowView;
    2527      361203 :         originalFlagRowView_p = originalFlagRowView;
    2528      361203 :         if (privateFlagRowView_p != NULL)
    2529             :         {
    2530           0 :                 privateFlagRowView_p = privateFlagRowView;
    2531           0 :                 applyFlagRow_p = &FlagMapper::applyPrivateFlagRow;
    2532             :         }
    2533             :         else
    2534             :         {
    2535      361203 :                 applyFlagRow_p = &FlagMapper::applyCommonFlagRow;
    2536             :         }
    2537             : 
    2538      361203 :         return;
    2539             : }
    2540             : 
    2541             : 
    2542             : void
    2543      344235 : FlagMapper::setExpressionMapping(vector< vector<uInt> > selectedCorrelations)
    2544             : {
    2545      344235 :         selectedCorrelations_p = selectedCorrelations;
    2546      344235 :         if (selectedCorrelations_p.empty())
    2547             :         {
    2548             :                 //throw AipsError("None of the correlations is eligible for flagging");
    2549             :         }
    2550      344235 : }
    2551             : 
    2552             : 
    2553      344235 : FlagMapper::~FlagMapper()
    2554             : {
    2555      344235 :         if (commonFlagsView_p != NULL) delete commonFlagsView_p;
    2556      344235 :         if (originalFlagsView_p != NULL) delete originalFlagsView_p;
    2557      344235 :         if (privateFlagsView_p != NULL) delete privateFlagsView_p;
    2558      344235 :         if (commonFlagRowView_p != NULL) delete commonFlagRowView_p;
    2559      344235 :         if (originalFlagRowView_p != NULL) delete originalFlagRowView_p;
    2560      344235 :         if (privateFlagRowView_p != NULL) delete privateFlagRowView_p;
    2561      344235 : }
    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    47437888 : FlagMapper::getModifiedFlags(uInt channel, uInt row)
    2579             : {
    2580    47437888 :         Bool combinedFlag = false;
    2581    94875776 :         for (auto &elem : selectedCorrelations_p[0])
    2582             :         {
    2583    47437888 :                 combinedFlag = combinedFlag | commonFlagsView_p->operator ()(elem, channel, row);
    2584             :         }
    2585             : 
    2586    47437888 :         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   614766296 : FlagMapper::getOriginalFlags(uInt pol, uInt channel, uInt row)
    2605             : {
    2606   614766296 :         Bool combinedFlag = false;
    2607  1229532592 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2608             :         {
    2609   614766296 :                 combinedFlag = combinedFlag | originalFlagsView_p->operator ()(*iter,channel,row);
    2610             :         }
    2611             : 
    2612   614766296 :         return combinedFlag;
    2613             : }
    2614             : 
    2615             : 
    2616             : Bool
    2617   471608002 : FlagMapper::getModifiedFlags(uInt pol, uInt channel, uInt row)
    2618             : {
    2619   471608002 :         Bool combinedFlag = false;
    2620   943216004 :         for (auto &elem : selectedCorrelations_p[pol])
    2621             :         {
    2622   471608002 :                 combinedFlag = combinedFlag | commonFlagsView_p->operator ()(elem, channel, row);
    2623             :         }
    2624             : 
    2625   471608002 :         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     5394031 : FlagMapper::setModifiedFlags(uInt pol, uInt channel, uInt row)
    2665             : {
    2666    10788062 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2667             :         {
    2668     5394031 :                 commonFlagsView_p->operator ()(*iter,channel,row) = flag_p;
    2669             :         }
    2670     5394031 : }
    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      812356 : FlagMapper::applyFlag(uInt channel, uInt row)
    2685             : {
    2686     1624712 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[0].begin();iter!=selectedCorrelations_p[0].end();iter++)
    2687             :         {
    2688      812356 :                 (*this.*applyFlag_p)(*iter,channel,row);
    2689             :         }
    2690      812356 : }
    2691             : 
    2692             : 
    2693             : void
    2694     4180206 : FlagMapper::applyFlag(uInt pol, uInt channel, uInt row)
    2695             : {
    2696     8360412 :         for (vector<uInt>::iterator iter=selectedCorrelations_p[pol].begin();iter!=selectedCorrelations_p[pol].end();iter++)
    2697             :         {
    2698     4180206 :                 (*this.*applyFlag_p)(*iter,channel,row);
    2699             :         }
    2700     4180206 : }
    2701             : 
    2702             : 
    2703             : void
    2704     5017825 : FlagMapper::applyFlagRow(uInt row)
    2705             : {
    2706             :         // Flag row
    2707     5017825 :         (*this.*applyFlagRow_p)(row);
    2708     5017825 : }
    2709             : 
    2710             : void
    2711     5458878 : FlagMapper::applyFlagInRow(uInt row)
    2712             : {
    2713             :         // Flag cube
    2714   291469277 :         for (uInt chan_i=0;chan_i<reducedLength_p(0);chan_i++)
    2715             :         {
    2716  1044077761 :                 for (vector< vector<uInt> >::iterator correlations=selectedCorrelations_p.begin();correlations!=selectedCorrelations_p.end();correlations++)
    2717             :                 {
    2718  1516134724 :                         for (vector<uInt>::iterator iter=correlations->begin();iter!=correlations->end();iter++)
    2719             :                         {
    2720   758067362 :                                 (*this.*applyFlag_p)(*iter,chan_i,row);
    2721             :                         }
    2722             :                 }
    2723             :         }
    2724     5458878 : }
    2725             : 
    2726             : 
    2727             : void
    2728   763059924 : 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   763059924 :         commonFlagsView_p->operator()(pol,channel,row) = flag_p;
    2732   763059924 :         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     5017825 : FlagMapper::applyCommonFlagRow(uInt row)
    2760             : {
    2761             :         // NOTE: Notice that the position is pol,channel,row, not the other way around
    2762     5017825 :         commonFlagRowView_p->operator()(row) = flag_p;
    2763     5017825 :         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