LCOV - code coverage report
Current view: top level - flagging/Flagging - FlagAgentQuack.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 69 0.0 %
Date: 2024-10-28 15:53:10 Functions: 0 5 0.0 %

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

Generated by: LCOV version 1.16