Line data Source code
1 : //# FlagAgentQuack.cc: This file contains the implementation of the FlagAgentQuack 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/FlagAgentQuack.h> 24 : 25 : using namespace casacore; 26 : namespace casa { //# NAMESPACE CASA - BEGIN 27 : 28 18 : FlagAgentQuack::FlagAgentQuack(FlagDataHandler *dh, Record config, Bool writePrivateFlagCube, Bool flag): 29 18 : FlagAgentBase(dh,config,ROWS,writePrivateFlagCube,flag) 30 : { 31 19 : setAgentParameters(config); 32 : 33 : // Request loading antenna pointing map to FlagDataHandler 34 17 : flagDataHandler_p->setScanStartStopMap(true); 35 17 : if (quackincrement_p) flagDataHandler_p->setScanStartStopFlaggedMap(true); 36 18 : } 37 : 38 34 : FlagAgentQuack::~FlagAgentQuack() 39 : { 40 : // Compiler automagically calls FlagAgentBase::~FlagAgentBase() 41 34 : } 42 : 43 : void 44 18 : FlagAgentQuack::setAgentParameters(Record config) 45 : { 46 18 : logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE)); 47 : int exists; 48 : 49 18 : exists = config.fieldNumber ("quackinterval"); 50 18 : if (exists >= 0) 51 : { 52 18 : if( config.type(exists) != TpDouble && config.type(exists) != TpFloat && config.type(exists) != TpInt ) 53 : { 54 0 : throw( AipsError ( "Parameter 'quackinterval' must be of type 'double'" ) ); 55 : } 56 : 57 18 : quackinterval_p = config.asDouble("quackinterval"); 58 : 59 18 : if (quackinterval_p <= 0) 60 : { 61 1 : throw( AipsError ( "Parameter 'quackinterval' must be greater than zero." ) ); 62 : } 63 : } 64 : else 65 : { 66 0 : quackinterval_p = 1.0; 67 : } 68 : 69 17 : *logger_p << logLevel_p << " quackinterval is " << quackinterval_p << LogIO::POST; 70 : 71 17 : exists = config.fieldNumber ("quackmode"); 72 17 : String quackmode; 73 17 : if (exists >= 0) 74 : { 75 12 : if( config.type(exists) != TpString ) 76 : { 77 0 : throw( AipsError ( "Parameter 'quackmode' must be of type 'string'" ) ); 78 : } 79 : 80 12 : quackmode = config.asString("quackmode"); 81 12 : if (quackmode == "beg") 82 : { 83 4 : quackmode_p = BEGINNING_OF_SCAN; 84 : } 85 8 : else if (quackmode == "endb") 86 : { 87 5 : quackmode_p = END_OF_SCAN; 88 : } 89 3 : else if (quackmode == "end") 90 : { 91 1 : quackmode_p = ALL_BUT_END_OF_SCAN; 92 : } 93 2 : else if (quackmode == "tail") 94 : { 95 2 : quackmode_p = ALL_BUT_BEGINNING_OF_SCAN; 96 : } 97 : else 98 : { 99 0 : throw( AipsError ( "Unsupported quack mode: " + quackmode + ". Supported modes: beg,endb,end,tail (following AIPS convention)" ) ); 100 : } 101 : } 102 : else 103 : { 104 5 : quackmode_p = BEGINNING_OF_SCAN; 105 5 : quackmode = "beg"; 106 : } 107 : 108 17 : *logger_p << logLevel_p << " quackmode is " << quackmode << LogIO::POST; 109 : 110 17 : exists = config.fieldNumber ("quackincrement"); 111 17 : if (exists >= 0) 112 : { 113 14 : if( config.type(exists) != TpBool ) 114 : { 115 0 : throw( AipsError ( "Parameter 'quackincrement' must be of type 'bool'" ) ); 116 : } 117 : 118 14 : quackincrement_p = config.asBool("quackincrement"); 119 : } 120 : else 121 : { 122 3 : quackincrement_p = false; 123 : } 124 17 : *logger_p << logLevel_p << " quackincrement is " << quackincrement_p << LogIO::POST; 125 : 126 : 127 34 : return; 128 17 : } 129 : 130 : bool 131 289113 : FlagAgentQuack::computeRowFlags(const vi::VisBuffer2 &visBuffer, FlagMapper &/*flags*/, uInt row) 132 : { 133 289113 : logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE)); 134 : 135 : // Get scan for each particular row to cover for the "combine scans" case 136 289113 : Int scan = visBuffer.scan()[row]; 137 : 138 : // First of all check if this scan is in the scan start/stop map 139 289113 : if ( (*flagDataHandler_p->getMapScanStartStop()).find(scan) == (*flagDataHandler_p->getMapScanStartStop()).end()) 140 : { 141 : /* *logger_p << LogIO::WARN << " start/stop time for scan " 142 : << scan << " not found" << LogIO::POST;*/ 143 7938 : return false; 144 : } 145 : 146 : // If the scan is available in the map, then we proceed with the algorithm 147 281175 : Double scan_start = (*flagDataHandler_p->getMapScanStartStop())[scan].at(0); 148 281175 : Double scan_stop = (*flagDataHandler_p->getMapScanStartStop())[scan].at(1); 149 281175 : Double row_time = visBuffer.time()[row]; 150 281175 : bool flagRow = false; 151 : 152 281175 : switch (quackmode_p) 153 : { 154 107889 : case BEGINNING_OF_SCAN: 155 : { 156 107889 : if (row_time <= (scan_start + quackinterval_p)) flagRow = true; 157 107889 : break; 158 : } 159 105327 : case END_OF_SCAN: 160 : { 161 105327 : if (row_time >= (scan_stop - quackinterval_p)) flagRow = true; 162 105327 : break; 163 : } 164 45306 : case ALL_BUT_BEGINNING_OF_SCAN: 165 : { 166 45306 : if (row_time > (scan_start + quackinterval_p)) flagRow = true; 167 45306 : break; 168 : } 169 22653 : case ALL_BUT_END_OF_SCAN: 170 : { 171 22653 : if (row_time < (scan_stop - quackinterval_p)) flagRow = true; 172 22653 : break; 173 : } 174 : } 175 : 176 281175 : return flagRow; 177 : } 178 : 179 : } //# NAMESPACE CASA - END 180 : 181 :