LCOV - code coverage report
Current view: top level - flagging/Flagging - RFCommon.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 36 0.0 %
Date: 2024-10-04 16:51:10 Functions: 0 8 0.0 %

          Line data    Source code
       1             : //# RFCommon.h: this defines RFCommon
       2             : //# Copyright (C) 2000,2001
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //# $Id$
      27             : #ifndef FLAGGING_RFCOMMON_H
      28             : #define FLAGGING_RFCOMMON_H
      29             :     
      30             : #include <casacore/casa/Arrays/Vector.h>
      31             : #include <casacore/casa/Arrays/Matrix.h>
      32             : #include <casacore/casa/Containers/RecordInterface.h>
      33             : #include <casacore/casa/Containers/RecordInterface.h>
      34             : #include <casacore/casa/Logging/LogIO.h>
      35             : #include <algorithm>
      36             : #include <limits>
      37             : 
      38             : namespace casa { //# NAMESPACE CASA - BEGIN
      39             : 
      40             : // RFAs use bitwise flags
      41             : typedef casacore::uInt RFlagWord;
      42             : typedef casacore::Vector<RFlagWord> FlagVector;
      43             : typedef casacore::Matrix<RFlagWord> FlagMatrix;
      44             : 
      45             : // character constants for common agent parameters
      46             : const char 
      47             :     RF_GLISHINDEX[] = "_glishindex", // this is set automatically to indicate 1-based indexing
      48             :     
      49             :     RF_NAME[]    = "name",
      50             :     
      51             :     RF_DEBUG[]   = "debug",
      52             :     RF_PLOT[]    = "plot",
      53             :     RF_PLOTSCR[] = "plotscr",
      54             :     RF_GLOBAL[]  = "global",
      55             :     RF_TRIAL[]   = "trial",
      56             : 
      57             :     RF_RESET[]   = "reset",
      58             :     RF_FIGNORE[] = "fignore",
      59             :     RF_UNFLAG[]  = "unflag",
      60             :     RF_SHADOW[]  = "shadow",
      61             :     RF_ELEVATION[] = "elevation",
      62             :     
      63             :     RF_THR[]     = "thr",
      64             :     RF_ROW_THR[] = "rowthr",
      65             :     
      66             :     RF_HW[]      = "hw",
      67             :     RF_ROW_HW[]  = "rowhw",
      68             :     RF_ROW_DISABLE[] = "norow",
      69             : 
      70             :     RF_COLUMN[]  = "column",
      71             :     RF_EXPR[]    = "expr",
      72             :     
      73             :     RF_CLIP[]      = "clip",
      74             :     RF_FLAGRANGE[] = "flagrange",
      75             :     RF_MIN[]       = "min",
      76             :     RF_MAX[]       = "max",
      77             :     RF_CHANAVG[]   = "chanavg",
      78             :     
      79             :     RF_NDEG[]    = "ndeg",
      80             :     RF_SPWID[]   = "spwid", 
      81             :     RF_FREQS[]   = "fq",
      82             :     RF_CHANS[]   = "chan",
      83             :     RF_REGION[]  = "region",
      84             :     
      85             :     RF_NBINS[]   = "nbins",
      86             :     RF_MINPOP[]  = "minpop",
      87             :     
      88             :     RF_CORR[]    = "corr",
      89             :     RF_ANT[]     = "ant",
      90             :     RF_FIELD[]   = "field",
      91             :     RF_BASELINE[] = "baseline",
      92             :     RF_AUTOCORR[] = "autocorr",
      93             : 
      94             :     RF_INTENT[] = "intent",
      95             :     RF_SCAN[]    = "scan",
      96             :     RF_ARRAY[]   = "array",
      97             :     RF_OBSERVATION[] = "observation",
      98             :     RF_FEED[]    = "feed",
      99             :     RF_UVRANGE[] = "uvrange",
     100             :     RF_DIAMETER[] = "diameter",
     101             :     RF_LOWERLIMIT[]  = "lowerlimit",
     102             :     RF_UPPERLIMIT[]  = "upperlimit",
     103             :     
     104             :     RF_TIMERANGE[] = "timerng",
     105             :     RF_CENTERTIME[] = "timeslot",
     106             :     RF_TIMEDELTA[] = "dtime",
     107             :     
     108             :     RF_QUACK[]     = "quack",
     109             :     RF_QUACKMODE[] = "quackmode",
     110             :     RF_QUACKINC[]  = "quackinc",
     111             : 
     112             :     RF_NCHAN[] = "nchan",
     113             :     RF_START[] = "start",
     114             :     RF_STEP[] = "step",
     115             :     RF_MODE[] = "mode",
     116             :     RF_MSSELECT[] = "msselect";
     117             : 
     118             : // <summary>
     119             : // FlaggerEnums: collection of enums for various flagger classes
     120             : // </summary>
     121             : 
     122             : // <use visibility=local>
     123             : 
     124             : // <reviewed reviewer="" date="" tests="" demos="">
     125             : // </reviewed>
     126             : class FlaggerEnums 
     127             : {
     128             : public:
     129             :   typedef enum 
     130             :     { POLZN = 0,POL=POLZN,CORR=POLZN,
     131             :       CHAN  = 1,
     132             :       IFR   = 2,
     133             :       TIME  = 3,
     134             :       ROW   = 4,
     135             :       ANT   = 5,
     136             :       FEED  = 6,
     137             :       FEEDCORR  = 7,
     138             :       NONE  = -1,
     139             :       Num_StatEnums=8 
     140             :     } StatEnums;
     141             : 
     142             :   typedef enum 
     143             :   {
     144             :     FL_HONOR  = 0,
     145             :     FL_IGNORE = 1,
     146             :     FL_RESET  = 2
     147             :   } PreFlagPolicy;
     148             : };
     149             :    
     150             : 
     151             : // short inline function for checking the type of a record field
     152           0 : inline casacore::Bool fieldType ( const casacore::RecordInterface &parm,
     153             :                                   const casacore::String &id,casacore::DataType type,
     154             :                                   casacore::DataType type2 = casacore::TpNumberOfTypes )
     155             : {
     156           0 :   if( !parm.isDefined(id) || !parm.shape(id).product() )
     157           0 :     return false;
     158           0 :   casacore::DataType t = parm.dataType(id);
     159           0 :   return t==type || t==type2;
     160             : }
     161             :     
     162             : // short inline function for checking a field's data type against some function
     163           0 : inline casacore::Bool isField ( const casacore::RecordInterface &parm,const casacore::String &id,casacore::Bool (*func)(casacore::DataType) )
     164             : {
     165           0 :   if( !parm.isDefined(id) )
     166           0 :     return false;
     167           0 :   casacore::DataType type = parm.dataType(id);
     168           0 :   return (*func)(type);
     169             : }
     170             : 
     171             : // short inline function for checking that a field is a non-empty record
     172           0 : inline casacore::Bool isValidRecord ( const casacore::RecordInterface &parm,const casacore::String &id)
     173             : {
     174           0 :   if( !parm.isDefined(id) || parm.dataType(id) != casacore::TpRecord )
     175           0 :     return false;
     176           0 :   return parm.asRecord(id).nfields() > 0;
     177             : }
     178             :     
     179             : // casacore::Short inline function for checking if a record field is "set",
     180             : // i.e. exists, and is not an empty array or a boolean false.
     181           0 : inline casacore::Bool isFieldSet ( const casacore::RecordInterface &parm,const casacore::String &id )
     182             : {
     183           0 :   return parm.isDefined(id) && parm.shape(id).product() &&
     184           0 :           ( parm.dataType(id) != casacore::TpBool || parm.asBool(id) );
     185             : }
     186             :     
     187             : // casacore::Short inline function for returning the number of elements in a field
     188             : // (0 for no field, 1 for scalar, >1 for arrays)
     189           0 : inline casacore::uInt fieldSize ( const casacore::RecordInterface &parm,const casacore::String &id )
     190             : {
     191           0 :   return parm.isDefined(id) ? parm.shape(id).product() : 0;
     192             : }
     193             : 
     194             : // Basically just upcase(), but in a form suitable for casacore::Array::apply
     195           0 : inline casacore::String stringUpper ( const casacore::String &in )
     196             : {
     197           0 :   return upcase(in);
     198             : }
     199             : 
     200             : // a debug-printf function, for printf-ing debug messages
     201             : int dprintf( casacore::LogIO &os, const char *format, ... );
     202             : 
     203           0 : inline std::vector<bool> bitvec_from_ulong( unsigned long val, size_t len = std::numeric_limits<unsigned long>::digits ) {
     204           0 :     std::vector<bool> result(len,false);
     205           0 :     unsigned long mask = 1;
     206           0 :     for( size_t i=0; i < std::min((size_t)result.size( ),(size_t)std::numeric_limits<unsigned long>::digits); ++i ) {
     207           0 :         result[i] = mask & val ? true : false;
     208           0 :         mask = mask << 1;
     209             :     }
     210           0 :     return result;
     211           0 : }
     212             : 
     213           0 : inline unsigned long bitvec_to_ulong( const std::vector<bool> &val) {
     214           0 :     unsigned long result = 0;
     215           0 :     unsigned long mask = 1;
     216           0 :     for( size_t i=0; i < std::min((size_t)std::numeric_limits<unsigned long>::digits,(size_t)val.size()); ++i ) {
     217           0 :         result |= (val[i] ? mask : 0);
     218           0 :         mask = mask << 1;
     219             :     }
     220           0 :     return result;
     221             : }
     222             : 
     223             : } //# NAMESPACE CASA - END
     224             : 
     225             : #endif

Generated by: LCOV version 1.16