LCOV - code coverage report
Current view: top level - singledishfiller/Filler - SysCalRecord.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 98 0.0 %
Date: 2024-10-04 16:51:10 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /*
       2             :  * SysCalRecord.h
       3             :  *
       4             :  *  Created on: Jan 27, 2016
       5             :  *      Author: nakazato
       6             :  */
       7             : 
       8             : #ifndef SINGLEDISH_FILLER_SYSCALRECORD_H_
       9             : #define SINGLEDISH_FILLER_SYSCALRECORD_H_
      10             : 
      11             : #include <casacore/casa/BasicSL/String.h>
      12             : #include <casacore/casa/OS/Path.h>
      13             : #include <casacore/measures/Measures/MPosition.h>
      14             : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
      15             : #include <casacore/ms/MeasurementSets/MSSysCal.h>
      16             : #include <casacore/ms/MeasurementSets/MSSysCalColumns.h>
      17             : 
      18             : namespace casa { //# NAMESPACE CASA - BEGIN
      19             : namespace sdfiller { //# NAMESPACE SDFILLER - BEGIN
      20             : 
      21             : struct SysCalRecord {
      22             :   typedef casacore::MSSysCal AssociatingTable;
      23             :   typedef casacore::MSSysCalColumns AssociatingColumns;
      24             : 
      25             :   // mandatory
      26             :   casacore::Int antenna_id;
      27             :   casacore::Int feed_id;
      28             :   casacore::Int spw_id;
      29             :   casacore::Double time;
      30             :   casacore::Double interval;
      31             : 
      32             :   // optional
      33             :   casacore::Vector<casacore::Float> tcal;
      34             :   casacore::Matrix<casacore::Float> tcal_spectrum;
      35             :   casacore::Vector<casacore::Float> tsys;
      36             :   casacore::Matrix<casacore::Float> tsys_spectrum;
      37             : 
      38             :   // method
      39           0 :   void clear() {
      40           0 :     antenna_id = -1;
      41           0 :     feed_id = -1;
      42           0 :     spw_id = -1;
      43           0 :     time = 0.0;
      44           0 :     interval = 0.0;
      45           0 :     tcal.resize();
      46           0 :     tcal_spectrum.resize();
      47           0 :     tsys.resize();
      48           0 :     tsys_spectrum.resize();
      49           0 :   }
      50             : 
      51             :   SysCalRecord &operator=(SysCalRecord const &other) {
      52             :     antenna_id = other.antenna_id;
      53             :     feed_id = other.feed_id;
      54             :     spw_id = other.spw_id;
      55             :     time = other.time;
      56             :     interval = other.interval;
      57             :     tcal = other.tcal;
      58             :     tcal_spectrum = other.tcal_spectrum;
      59             :     tsys = other.tsys;
      60             :     tsys_spectrum = other.tsys_spectrum;
      61             :     return *this;
      62             :   }
      63             : 
      64             :   void add(AssociatingTable &table, AssociatingColumns &/*columns*/) {
      65             :     table.addRow(1, true);
      66             :   }
      67             : 
      68           0 :   casacore::Bool fill(casacore::uInt irow, AssociatingColumns &columns) {
      69           0 :     if (columns.nrow() <= irow) {
      70           0 :       return false;
      71             :     }
      72             : 
      73           0 :     columns.antennaId().put(irow, antenna_id);
      74           0 :     columns.feedId().put(irow, feed_id);
      75           0 :     columns.spectralWindowId().put(irow, spw_id);
      76           0 :     columns.time().put(irow, time);
      77           0 :     columns.interval().put(irow, interval);
      78           0 :     if (tcal.size() > 0) {
      79           0 :       columns.tcal().put(irow, tcal);
      80             :     }
      81           0 :     if (tcal_spectrum.size() > 0) {
      82           0 :       columns.tcalSpectrum().put(irow, tcal_spectrum);
      83             :     }
      84           0 :     if (tsys.size() > 0) {
      85           0 :       columns.tsys().put(irow, tsys);
      86             :     }
      87           0 :     if (tsys_spectrum.size() > 0) {
      88           0 :       columns.tsysSpectrum().put(irow, tsys_spectrum);
      89             :     }
      90           0 :     return true;
      91             :   }
      92             : };
      93             : 
      94             : struct SysCalTableRecord {
      95             :   enum Status {
      96             :     Spectral, Scalar, NotDefined
      97             :   };
      98           0 :   SysCalTableRecord(casacore::MeasurementSet *ms, casacore::uInt irow, SysCalRecord const &record) :
      99           0 :       ms_(ms), columns_(ms->sysCal()), irow_(irow) {
     100           0 :     antenna_id = record.antenna_id;
     101           0 :     feed_id = record.feed_id;
     102           0 :     spw_id = record.spw_id;
     103           0 :     casacore::ScalarColumn<casacore::Int> num_chan_column(ms_->spectralWindow(), "NUM_CHAN");
     104           0 :     num_chan = num_chan_column(spw_id);
     105           0 :     if (record.tsys_spectrum.empty()) {
     106           0 :       num_corr = record.tsys.size();
     107           0 :       tsys_status = Status::Scalar;
     108           0 :       if (record.tsys.empty()) {
     109           0 :         tsys_nominal = -1.0f;
     110           0 :         tsys_status = Status::NotDefined;
     111             :       } else {
     112           0 :         tsys_nominal = record.tsys[0];
     113             :       }
     114             :     } else {
     115           0 :       num_corr = record.tsys_spectrum.shape()[0];
     116           0 :       tsys_status = Status::Spectral;
     117           0 :       tsys_nominal = record.tsys_spectrum(0, 0);
     118             :     }
     119           0 :     if (record.tcal_spectrum.empty()) {
     120           0 :       tcal_status = Status::Scalar;
     121           0 :       if (record.tcal.empty()) {
     122           0 :         tcal_nominal = -1.0f;
     123           0 :         tcal_status = Status::NotDefined;
     124             :       } else {
     125           0 :         tcal_nominal = record.tcal[0];
     126             :       }
     127             :     } else {
     128           0 :       tcal_status = Status::Spectral;
     129           0 :       tcal_nominal = record.tcal_spectrum(0, 0);
     130             :     }
     131           0 :   }
     132           0 :   SysCalTableRecord(SysCalTableRecord const &other) :
     133           0 :       ms_(other.ms_), columns_(ms_->sysCal()), irow_(other.irow_) {
     134           0 :     antenna_id = other.antenna_id;
     135           0 :     feed_id = other.feed_id;
     136           0 :     spw_id = other.spw_id;
     137           0 :     num_chan = other.num_chan;
     138           0 :     num_corr = other.num_corr;
     139           0 :     tsys_status = other.tsys_status;
     140           0 :     tcal_status = other.tcal_status;
     141           0 :     tsys_nominal = other.tsys_nominal;
     142           0 :     tcal_nominal = other.tcal_nominal;
     143           0 :   }
     144             :   casacore::Int antenna_id;
     145             :   casacore::Int feed_id;
     146             :   casacore::Int spw_id;
     147             :   casacore::Int num_chan;
     148             :   casacore::Int num_corr;
     149             :   Status tsys_status;
     150             :   Status tcal_status;
     151             :   casacore::Float tsys_nominal;
     152             :   casacore::Float tcal_nominal;
     153             : 
     154             :   // returns true if two SysCalTableRecord objects are exactly same
     155             :   bool operator==(SysCalTableRecord const &record) {
     156             :     casacore::String ms_name = casacore::Path(ms_->tableName()).resolvedName();
     157             :     casacore::String ms_name_record = casacore::Path(record.ms_->tableName()).resolvedName();
     158             :     return ms_name == ms_name_record && irow_ == record.irow_
     159             :         && antenna_id == record.antenna_id && feed_id == record.feed_id
     160             :         && spw_id == record.spw_id && num_chan == record.num_chan
     161             :         && num_corr == record.num_corr && tsys_status == record.tsys_status
     162             :         && tcal_status == record.tcal_status
     163             :         && tsys_nominal == record.tsys_nominal
     164             :         && tcal_nominal == record.tcal_nominal;
     165             :   }
     166             : 
     167             :   // returns true if given SysCalRecord is effectively the same
     168           0 :   bool operator==(SysCalRecord const &record) {
     169           0 :     bool is_meta_equal = antenna_id == record.antenna_id
     170           0 :         && feed_id == record.feed_id && spw_id == record.spw_id;
     171           0 :     if (!is_meta_equal) {
     172           0 :       return false;
     173             :     }
     174             : 
     175             :     bool is_tsys_same;
     176           0 :     if (tsys_status == Status::Spectral) {
     177           0 :       is_tsys_same = num_chan > 0
     178           0 :           && (casacore::uInt) num_chan == record.tsys_spectrum.ncolumn() && num_corr > 0
     179           0 :           && (casacore::uInt) num_corr == record.tsys_spectrum.nrow()
     180           0 :           && tsys_nominal == record.tsys_spectrum(0, 0)
     181           0 :           && allEQ(columns_.tsysSpectrum()(irow_), record.tsys_spectrum);
     182           0 :     } else if (tsys_status == Status::Scalar) {
     183           0 :       is_tsys_same = num_corr > 0 && (casacore::uInt) num_corr == record.tsys.size()
     184           0 :           && tsys_nominal == record.tsys[0]
     185           0 :           && allEQ(columns_.tsys()(irow_), record.tsys);
     186             :     } else {
     187           0 :       is_tsys_same = record.tsys_spectrum.empty() && record.tsys.empty();
     188             :     }
     189             : 
     190           0 :     if (!is_tsys_same) {
     191           0 :       return false;
     192             :     }
     193             : 
     194             :     bool is_tcal_same;
     195           0 :     if (tcal_status == Status::Spectral) {
     196           0 :       is_tcal_same = num_chan > 0
     197           0 :           && (casacore::uInt) num_chan == record.tcal_spectrum.ncolumn() && num_corr > 0
     198           0 :           && (casacore::uInt) num_corr == record.tcal_spectrum.nrow()
     199           0 :           && tcal_nominal == record.tcal_spectrum(0, 0)
     200           0 :           && allEQ(columns_.tcalSpectrum()(irow_), record.tcal_spectrum);
     201           0 :     } else if (tcal_status == Status::Scalar) {
     202           0 :       is_tcal_same = num_corr > 0 && (casacore::uInt) num_corr == record.tcal.size()
     203           0 :           && tcal_nominal == record.tcal[0]
     204           0 :           && allEQ(columns_.tcal()(irow_), record.tcal);
     205             :     } else {
     206           0 :       is_tcal_same = record.tcal_spectrum.empty() && record.tcal.empty();
     207             :     }
     208             : 
     209           0 :     if (!is_tcal_same) {
     210           0 :       return false;
     211             :     }
     212             : 
     213           0 :     return true;
     214             :   }
     215             : 
     216             : private:
     217             :   casacore::MeasurementSet *ms_;
     218             :   casacore::MSSysCalColumns columns_;
     219             :   casacore::uInt irow_;
     220             : };
     221             : 
     222             : } //# NAMESPACE SDFILLER - END
     223             : } //# NAMESPACE CASA - END
     224             : 
     225             : #endif /* SINGLEDISH_FILLER_SYSCALRECORD_H_ */

Generated by: LCOV version 1.16