SysCalRecord.h

Go to the documentation of this file.
00001 /*
00002  * SysCalRecord.h
00003  *
00004  *  Created on: Jan 27, 2016
00005  *      Author: nakazato
00006  */
00007 
00008 #ifndef SINGLEDISH_FILLER_SYSCALRECORD_H_
00009 #define SINGLEDISH_FILLER_SYSCALRECORD_H_
00010 
00011 #include <casacore/casa/BasicSL/String.h>
00012 #include <casacore/casa/OS/Path.h>
00013 #include <casacore/measures/Measures/MPosition.h>
00014 #include <casacore/ms/MeasurementSets/MeasurementSet.h>
00015 #include <casacore/ms/MeasurementSets/MSSysCal.h>
00016 #include <casacore/ms/MeasurementSets/MSSysCalColumns.h>
00017 
00018 namespace casa { //# NAMESPACE CASA - BEGIN
00019 namespace sdfiller { //# NAMESPACE SDFILLER - BEGIN
00020 
00021 struct SysCalRecord {
00022   typedef MSSysCal AssociatingTable;
00023   typedef MSSysCalColumns AssociatingColumns;
00024 
00025   // mandatory
00026   Int antenna_id;
00027   Int feed_id;
00028   Int spw_id;
00029   Double time;
00030   Double interval;
00031 
00032   // optional
00033   Vector<Float> tcal;
00034   Matrix<Float> tcal_spectrum;
00035   Vector<Float> tsys;
00036   Matrix<Float> tsys_spectrum;
00037 
00038   // method
00039   void clear() {
00040     antenna_id = -1;
00041     feed_id = -1;
00042     spw_id = -1;
00043     time = 0.0;
00044     interval = 0.0;
00045     tcal.resize();
00046     tcal_spectrum.resize();
00047     tsys.resize();
00048     tsys_spectrum.resize();
00049   }
00050 
00051   SysCalRecord &operator=(SysCalRecord const &other) {
00052     antenna_id = other.antenna_id;
00053     feed_id = other.feed_id;
00054     spw_id = other.spw_id;
00055     time = other.time;
00056     interval = other.interval;
00057     tcal = other.tcal;
00058     tcal_spectrum = other.tcal_spectrum;
00059     tsys = other.tsys;
00060     tsys_spectrum = other.tsys_spectrum;
00061     return *this;
00062   }
00063 
00064   void add(AssociatingTable &table, AssociatingColumns &/*columns*/) {
00065     table.addRow(1, True);
00066   }
00067 
00068   Bool fill(uInt irow, AssociatingColumns &columns) {
00069     if (columns.nrow() <= irow) {
00070       return False;
00071     }
00072 
00073     columns.antennaId().put(irow, antenna_id);
00074     columns.feedId().put(irow, feed_id);
00075     columns.spectralWindowId().put(irow, spw_id);
00076     columns.time().put(irow, time);
00077     columns.interval().put(irow, interval);
00078     if (tcal.size() > 0) {
00079       columns.tcal().put(irow, tcal);
00080     }
00081     if (tcal_spectrum.size() > 0) {
00082       columns.tcalSpectrum().put(irow, tcal_spectrum);
00083     }
00084     if (tsys.size() > 0) {
00085       columns.tsys().put(irow, tsys);
00086     }
00087     if (tsys_spectrum.size() > 0) {
00088       columns.tsysSpectrum().put(irow, tsys_spectrum);
00089     }
00090     return True;
00091   }
00092 };
00093 
00094 struct SysCalTableRecord {
00095   enum Status {
00096     Spectral, Scalar, NotDefined
00097   };
00098   SysCalTableRecord(MeasurementSet *ms, uInt irow, SysCalRecord const &record) :
00099       ms_(ms), columns_(ms->sysCal()), irow_(irow) {
00100     antenna_id = record.antenna_id;
00101     feed_id = record.feed_id;
00102     spw_id = record.spw_id;
00103     ROScalarColumn<Int> num_chan_column(ms_->spectralWindow(), "NUM_CHAN");
00104     num_chan = num_chan_column(spw_id);
00105     if (record.tsys_spectrum.empty()) {
00106       num_corr = record.tsys.size();
00107       tsys_status = Status::Scalar;
00108       if (record.tsys.empty()) {
00109         tsys_nominal = -1.0f;
00110         tsys_status = Status::NotDefined;
00111       } else {
00112         tsys_nominal = record.tsys[0];
00113       }
00114     } else {
00115       num_corr = record.tsys_spectrum.shape()[0];
00116       tsys_status = Status::Spectral;
00117       tsys_nominal = record.tsys_spectrum(0, 0);
00118     }
00119     if (record.tcal_spectrum.empty()) {
00120       tcal_status = Status::Scalar;
00121       if (record.tcal.empty()) {
00122         tcal_nominal = -1.0f;
00123         tcal_status = Status::NotDefined;
00124       } else {
00125         tcal_nominal = record.tcal[0];
00126       }
00127     } else {
00128       tcal_status = Status::Spectral;
00129       tcal_nominal = record.tcal_spectrum(0, 0);
00130     }
00131   }
00132   SysCalTableRecord(SysCalTableRecord const &other) :
00133       ms_(other.ms_), columns_(ms_->sysCal()), irow_(other.irow_) {
00134     antenna_id = other.antenna_id;
00135     feed_id = other.feed_id;
00136     spw_id = other.spw_id;
00137     num_chan = other.num_chan;
00138     num_corr = other.num_corr;
00139     tsys_status = other.tsys_status;
00140     tcal_status = other.tcal_status;
00141     tsys_nominal = other.tsys_nominal;
00142     tcal_nominal = other.tcal_nominal;
00143   }
00144   Int antenna_id;
00145   Int feed_id;
00146   Int spw_id;
00147   Int num_chan;
00148   Int num_corr;
00149   Status tsys_status;
00150   Status tcal_status;
00151   Float tsys_nominal;
00152   Float tcal_nominal;
00153 
00154   // returns true if two SysCalTableRecord objects are exactly same
00155   bool operator==(SysCalTableRecord const &record) {
00156     String ms_name = Path(ms_->tableName()).resolvedName();
00157     String ms_name_record = Path(record.ms_->tableName()).resolvedName();
00158     return ms_name == ms_name_record && irow_ == record.irow_
00159         && antenna_id == record.antenna_id && feed_id == record.feed_id
00160         && spw_id == record.spw_id && num_chan == record.num_chan
00161         && num_corr == record.num_corr && tsys_status == record.tsys_status
00162         && tcal_status == record.tcal_status
00163         && tsys_nominal == record.tsys_nominal
00164         && tcal_nominal == record.tcal_nominal;
00165   }
00166 
00167   // returns true if given SysCalRecord is effectively the same
00168   bool operator==(SysCalRecord const &record) {
00169     bool is_meta_equal = antenna_id == record.antenna_id
00170         && feed_id == record.feed_id && spw_id == record.spw_id;
00171     if (!is_meta_equal) {
00172       return false;
00173     }
00174 
00175     bool is_tsys_same;
00176     if (tsys_status == Status::Spectral) {
00177       is_tsys_same = num_chan > 0
00178           && (uInt) num_chan == record.tsys_spectrum.ncolumn() && num_corr > 0
00179           && (uInt) num_corr == record.tsys_spectrum.nrow()
00180           && tsys_nominal == record.tsys_spectrum(0, 0)
00181           && allEQ(columns_.tsysSpectrum()(irow_), record.tsys_spectrum);
00182     } else if (tsys_status == Status::Scalar) {
00183       is_tsys_same = num_corr > 0 && (uInt) num_corr == record.tsys.size()
00184           && tsys_nominal == record.tsys[0]
00185           && allEQ(columns_.tsys()(irow_), record.tsys);
00186     } else {
00187       is_tsys_same = record.tsys_spectrum.empty() && record.tsys.empty();
00188     }
00189 
00190     if (!is_tsys_same) {
00191       return false;
00192     }
00193 
00194     bool is_tcal_same;
00195     if (tcal_status == Status::Spectral) {
00196       is_tcal_same = num_chan > 0
00197           && (uInt) num_chan == record.tcal_spectrum.ncolumn() && num_corr > 0
00198           && (uInt) num_corr == record.tcal_spectrum.nrow()
00199           && tcal_nominal == record.tcal_spectrum(0, 0)
00200           && allEQ(columns_.tcalSpectrum()(irow_), record.tcal_spectrum);
00201     } else if (tcal_status == Status::Scalar) {
00202       is_tcal_same = num_corr > 0 && (uInt) num_corr == record.tcal.size()
00203           && tcal_nominal == record.tcal[0]
00204           && allEQ(columns_.tcal()(irow_), record.tcal);
00205     } else {
00206       is_tcal_same = record.tcal_spectrum.empty() && record.tcal.empty();
00207     }
00208 
00209     if (!is_tcal_same) {
00210       return false;
00211     }
00212 
00213     return true;
00214   }
00215 
00216 private:
00217   MeasurementSet *ms_;
00218   MSSysCalColumns columns_;
00219   uInt irow_;
00220 };
00221 
00222 } //# NAMESPACE SDFILLER - END
00223 } //# NAMESPACE CASA - END
00224 
00225 #endif /* SINGLEDISH_FILLER_SYSCALRECORD_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1