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 15 : FlagAgentQuack::FlagAgentQuack(FlagDataHandler *dh, Record config, Bool writePrivateFlagCube, Bool flag): 29 15 : FlagAgentBase(dh,config,ROWS,writePrivateFlagCube,flag) 30 : { 31 16 : setAgentParameters(config); 32 : 33 : // Request loading antenna pointing map to FlagDataHandler 34 14 : flagDataHandler_p->setScanStartStopMap(true); 35 14 : if (quackincrement_p) flagDataHandler_p->setScanStartStopFlaggedMap(true); 36 15 : } 37 : 38 28 : FlagAgentQuack::~FlagAgentQuack() 39 : { 40 : // Compiler automagically calls FlagAgentBase::~FlagAgentBase() 41 28 : } 42 : 43 : void 44 15 : FlagAgentQuack::setAgentParameters(Record config) 45 : { 46 15 : logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE)); 47 : int exists; 48 : 49 15 : exists = config.fieldNumber ("quackinterval"); 50 15 : if (exists >= 0) 51 : { 52 15 : 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 15 : quackinterval_p = config.asDouble("quackinterval"); 58 : 59 15 : 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 14 : *logger_p << logLevel_p << " quackinterval is " << quackinterval_p << LogIO::POST; 70 : 71 14 : exists = config.fieldNumber ("quackmode"); 72 14 : String quackmode; 73 14 : 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 2 : quackmode_p = BEGINNING_OF_SCAN; 105 2 : quackmode = "beg"; 106 : } 107 : 108 14 : *logger_p << logLevel_p << " quackmode is " << quackmode << LogIO::POST; 109 : 110 14 : exists = config.fieldNumber ("quackincrement"); 111 14 : 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 0 : quackincrement_p = false; 123 : } 124 14 : *logger_p << logLevel_p << " quackincrement is " << quackincrement_p << LogIO::POST; 125 : 126 : 127 28 : return; 128 14 : } 129 : 130 : bool 131 251772 : FlagAgentQuack::computeRowFlags(const vi::VisBuffer2 &visBuffer, FlagMapper &/*flags*/, uInt row) 132 : { 133 251772 : logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE)); 134 : 135 : // Get scan for each particular row to cover for the "combine scans" case 136 251772 : Int scan = visBuffer.scan()[row]; 137 : 138 : // First of all check if this scan is in the scan start/stop map 139 251772 : 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 243834 : Double scan_start = (*flagDataHandler_p->getMapScanStartStop())[scan].at(0); 148 243834 : Double scan_stop = (*flagDataHandler_p->getMapScanStartStop())[scan].at(1); 149 243834 : Double row_time = visBuffer.time()[row]; 150 243834 : bool flagRow = false; 151 : 152 243834 : switch (quackmode_p) 153 : { 154 70548 : case BEGINNING_OF_SCAN: 155 : { 156 70548 : if (row_time <= (scan_start + quackinterval_p)) flagRow = true; 157 70548 : 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 243834 : return flagRow; 177 : } 178 : 179 : } //# NAMESPACE CASA - END 180 : 181 :