FieldRecord.h

Go to the documentation of this file.
00001 /*
00002  * FieldRecord.h
00003  *
00004  *  Created on: Jan 27, 2016
00005  *      Author: nakazato
00006  */
00007 
00008 #ifndef SINGLEDISH_FILLER_FIELDRECORD_H_
00009 #define SINGLEDISH_FILLER_FIELDRECORD_H_
00010 
00011 #include <casacore/casa/Arrays/Matrix.h>
00012 #include <casacore/casa/BasicSL/String.h>
00013 #include <casacore/measures/Measures/MDirection.h>
00014 #include <casacore/ms/MeasurementSets/MSField.h>
00015 #include <casacore/ms/MeasurementSets/MSFieldColumns.h>
00016 
00017 namespace casa { //# NAMESPACE CASA - BEGIN
00018 
00019 // forward decleration
00020 template<class Reader>
00021 class SingleDishMSFiller;
00022 
00023 namespace sdfiller { //# NAMESPACE SDFILLER - BEGIN
00024 
00025 struct FieldRecord {
00026   typedef MSField AssociatingTable;
00027   typedef MSFieldColumns AssociatingColumns;
00028 
00029 private:
00030   // external resource
00031   Record source_map;
00032   AssociatingTable table;
00033 
00034 public:
00035   // meta
00036   Int field_id;
00037   String source_name;
00038   MDirection::Types frame;
00039 
00040   // mandatory
00041   String name;
00042   Double time;
00043   Matrix<Double> direction;
00044 
00045   // optional
00046   String code;
00047 
00048   // for dummy entry
00049   Int const d_source_id = -1;
00050   String const d_name = "";
00051   Int const d_num_poly = 0;
00052   Double const d_time = 0.0;
00053   Matrix<Double> const d_direction = Matrix<Double>(2, 1, 0.0);
00054 
00055   // method
00056   void clear() {
00057     field_id = -1;
00058     source_name = "";
00059     name = "";
00060     time = -1.0;
00061     direction.resize();
00062     frame = MDirection::N_Types;
00063     code = "";
00064   }
00065 
00066   FieldRecord &operator=(FieldRecord const &other) {
00067     source_map = other.source_map;
00068     table = other.table;
00069     field_id = other.field_id;
00070     source_name = other.source_name;
00071     frame = other.frame;
00072     name = other.name;
00073     time = other.time;
00074     direction = other.direction;
00075     code = other.code;
00076     return *this;
00077   }
00078 
00079   void add(AssociatingTable &table, AssociatingColumns &columns) {
00080     uInt ufield_id = (uInt) field_id;
00081     uInt nrow = table.nrow();
00082     if (nrow == 0) {
00083       // set direction frame information
00084       setFrame(columns);
00085     }
00086     if (nrow <= ufield_id) {
00087       table.addRow(ufield_id - nrow + 1);
00088       uInt new_nrow = table.nrow();
00089       for (uInt i = nrow; i < new_nrow - 1; ++i) {
00090         columns.sourceId().put(i, d_source_id);
00091         columns.name().put(i, d_name);
00092         columns.time().put(i, d_time);
00093         columns.numPoly().put(i, d_num_poly);
00094         columns.delayDir().put(i, d_direction);
00095         columns.phaseDir().put(i, d_direction);
00096         columns.referenceDir().put(i, d_direction);
00097       }
00098     }
00099   }
00100 
00101   Bool fill(uInt /*irow*/, AssociatingColumns &columns) {
00102     if (field_id < 0) {
00103       return False;
00104     }
00105 
00106     uInt nrow = columns.nrow();
00107     if (nrow == 0) {
00108       // set direction frame information
00109       setFrame(columns);
00110     }
00111 
00112     if (table.nrow() <= (uInt) field_id) {
00113       return False;
00114     }
00115 
00116     columns.name().put(field_id, name);
00117     columns.time().put(field_id, time);
00118     Int source_id = -1;
00119     if (source_map.isDefined(source_name)) {
00120       source_id = source_map.asInt(source_name);
00121     }
00122     columns.sourceId().put(field_id, source_id);
00123     columns.delayDir().put(field_id, direction);
00124     columns.phaseDir().put(field_id, direction);
00125     columns.referenceDir().put(field_id, direction);
00126     Int num_poly = direction.shape()[1] - 1;
00127     columns.numPoly().put(field_id, num_poly);
00128     if (code.size() > 0) {
00129       columns.code().put(field_id, code);
00130     }
00131     return True;
00132   }
00133 
00134 private:
00135   void setFrame(AssociatingColumns &columns) {
00136     TableRecord &record = columns.delayDir().rwKeywordSet();
00137     Record meas_info = record.asRecord("MEASINFO");
00138     String direction_frame = MDirection::showType(frame);
00139     meas_info.define("Ref", direction_frame);
00140     record.defineRecord("MEASINFO", meas_info);
00141     columns.phaseDir().rwKeywordSet().defineRecord("MEASINFO", meas_info);
00142     columns.referenceDir().rwKeywordSet().defineRecord("MEASINFO", meas_info);
00143   }
00144 
00145   template<class Reader>
00146   friend class casa::SingleDishMSFiller;
00147 };
00148 
00149 } //# NAMESPACE SDFILLER - END
00150 } //# NAMESPACE CASA - END
00151 
00152 #endif /* SINGLEDISH_FILLER_FIELDRECORD_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1