Scantable2MSReader.h

Go to the documentation of this file.
00001 /*
00002  * ScantableReader.h
00003  *
00004  *  Created on: Jan 5, 2016
00005  *      Author: nakazato
00006  */
00007 
00008 #ifndef SINGLEDISH_FILLER_SCANTABLE2MSREADER_H_
00009 #define SINGLEDISH_FILLER_SCANTABLE2MSREADER_H_
00010 
00011 #include <singledish/Filler/ReaderInterface.h>
00012 #include <singledish/Filler/ScantableIterator.h>
00013 
00014 #include <string>
00015 #include <memory>
00016 
00017 // casacore includes
00018 #include <casacore/casa/Containers/Record.h>
00019 #include <casacore/tables/Tables/TableRecord.h>
00020 #include <casacore/tables/Tables/ArrayColumn.h>
00021 #include <casacore/tables/Tables/ScalarColumn.h>
00022 
00023 namespace casa { //# NAMESPACE CASA - BEGIN
00024 
00025 class Scantable2MSReader: public ReaderInterface {
00026 public:
00027   Scantable2MSReader(std::string const &scantable_name);
00028   virtual ~Scantable2MSReader();
00029 
00030   // get number of rows for MAIN table
00031   virtual size_t getNumberOfRows() {
00032     if (!main_table_) {
00033       return 0;
00034     }
00035     return main_table_->nrow();
00036   }
00037 
00038   virtual Bool isFloatData() const {
00039     Bool is_float = True;
00040     if (!main_table_) {
00041       is_float = False;
00042     } else {
00043       String pol_type = main_table_->keywordSet().asString("POLTYPE");
00044       ROScalarColumn<uInt> polno_column(*main_table_, "POLNO");
00045       uInt max_pol = max(polno_column.getColumn());
00046 //      std::cout << "pol_type=" << pol_type << " max_pol=" << max_pol << std::endl;
00047       if ((max_pol == 3) && (pol_type == "linear" || pol_type == "circular")) {
00048         is_float = False;
00049       }
00050     }
00051 //    std::cout << "is_float = " << is_float << std::endl;
00052     return is_float;
00053   }
00054 
00055   // to get OBSERVATION table
00056   virtual Bool getObservationRow(sdfiller::ObservationRecord &record) {
00057     POST_START;
00058 
00059     Bool return_value = (*this.*get_observation_row_)(record);
00060 
00061     POST_END;
00062     return return_value;
00063   }
00064 
00065   // to get ANTENNA table
00066   virtual Bool getAntennaRow(sdfiller::AntennaRecord &record) {
00067     POST_START;
00068 
00069     Bool return_value = (*this.*get_antenna_row_)(record);
00070 
00071     POST_END;
00072     return return_value;
00073   }
00074 
00075   // to get PROCESSOR table
00076   virtual Bool getProcessorRow(sdfiller::ProcessorRecord &record) {
00077     POST_START;
00078 
00079     Bool return_value = (*this.*get_processor_row_)(record);
00080 
00081     POST_END;
00082     return return_value;
00083   }
00084 
00085   // to get SOURCE table
00086   virtual Bool getSourceRow(sdfiller::SourceRecord &record) {
00087     POST_START;
00088 
00089     Bool return_value = (*this.*get_source_row_)(record);
00090 
00091     POST_END;
00092     return return_value;
00093   }
00094 
00095   // to get FIELD table
00096   virtual Bool getFieldRow(sdfiller::FieldRecord &record) {
00097     POST_START;
00098 
00099     Bool return_value = (*this.*get_field_row_)(record);
00100 
00101     POST_END;
00102     return return_value;
00103   }
00104 
00105   // to get SOURCE table
00106   virtual Bool getSpectralWindowRow(sdfiller::SpectralWindowRecord &record) {
00107     POST_START;
00108 
00109     Bool return_value = (*this.*get_spw_row_)(record);
00110 
00111     POST_END;
00112     return return_value;
00113   }
00114 
00115   // for DataAccumulator
00116   virtual Bool getData(size_t irow, sdfiller::DataRecord &record);
00117 
00118 protected:
00119   void initializeSpecific();
00120   void finalizeSpecific();
00121 
00122 private:
00123   std::unique_ptr<Table> main_table_;
00124   Table tcal_table_;
00125   Table weather_table_;
00126 
00127   ROScalarColumn<uInt> scan_column_;ROScalarColumn<uInt> cycle_column_;ROScalarColumn<
00128       uInt> ifno_column_;ROScalarColumn<uInt> polno_column_;ROScalarColumn<uInt> beam_column_;ROScalarColumn<
00129       uInt> flagrow_column_;ROScalarColumn<Double> time_column_;ROScalarColumn<
00130       Double> interval_column_;ROScalarColumn<Int> srctype_column_;
00131   ArrayColumn<Float> data_column_;
00132   ArrayColumn<uChar> flag_column_;
00133   ArrayColumn<Double> direction_column_;
00134   ArrayColumn<Double> scanrate_column_;ROScalarColumn<String> fieldname_column_;
00135   ArrayColumn<Float> tsys_column_;ROScalarColumn<uInt> tcal_id_column_;ROScalarColumn<
00136       uInt> weather_id_column_;
00137   ArrayColumn<Float> tcal_column_;ROScalarColumn<Float> temperature_column_;ROScalarColumn<
00138       Float> pressure_column_;ROScalarColumn<Float> humidity_column_;ROScalarColumn<
00139       Float> wind_speed_column_;ROScalarColumn<Float> wind_direction_column_;
00140   Vector<uInt> sorted_rows_;
00141   ScantableFieldIterator::Product field_map_;
00142   ScantableFrequenciesIterator::Product num_chan_map_;
00143   std::map<uInt, uInt> tcal_id_map_;
00144   std::map<uInt, uInt> weather_id_map_;
00145   String pol_type_;
00146 
00147   Bool (Scantable2MSReader::*get_antenna_row_)(sdfiller::AntennaRecord &);
00148   Bool (Scantable2MSReader::*get_field_row_)(sdfiller::FieldRecord &);
00149   Bool (Scantable2MSReader::*get_observation_row_)(
00150       sdfiller::ObservationRecord &);
00151   Bool (Scantable2MSReader::*get_processor_row_)(sdfiller::ProcessorRecord &);
00152   Bool (Scantable2MSReader::*get_source_row_)(sdfiller::SourceRecord &);
00153   Bool (Scantable2MSReader::*get_spw_row_)(sdfiller::SpectralWindowRecord &);
00154 
00155   std::unique_ptr<ScantableFieldIterator> field_iter_;
00156   std::unique_ptr<ScantableFrequenciesIterator> freq_iter_;
00157   std::unique_ptr<ScantableSourceIterator> source_iter_;
00158 
00159   Bool getAntennaRowImpl(sdfiller::AntennaRecord &record);
00160   Bool getFieldRowImpl(sdfiller::FieldRecord &record);
00161   Bool getObservationRowImpl(sdfiller::ObservationRecord &record);
00162   Bool getProcessorRowImpl(sdfiller::ProcessorRecord &record);
00163   Bool getSourceRowImpl(sdfiller::SourceRecord &record);
00164   Bool getSpectralWindowRowImpl(sdfiller::SpectralWindowRecord &record);
00165 
00166   template<class _Record>
00167   Bool noMoreRowImpl(_Record &) {
00168     POST_START;POST_END;
00169     return False;
00170   }
00171 
00172   template<class _Iterator, class _Record, class _Func>
00173   Bool getRowImplTemplate(std::unique_ptr<_Iterator> &iter, _Record &record,
00174       _Func &func, typename _Iterator::Product *product = nullptr) {
00175     POST_START;
00176 
00177     if (!iter) {
00178       iter.reset(new _Iterator(*main_table_));
00179     }
00180 
00181     Bool more_data = iter->moreData();
00182     if (more_data) {
00183       iter->getEntry(record);
00184       iter->next();
00185     } else {
00186       // seems to be passed through all the table, deallocate iterator
00187       iter->getProduct(product);
00188       iter.reset(nullptr);
00189       // and then redirect function pointer to noMoreRowImpl
00190       func = &Scantable2MSReader::noMoreRowImpl<_Record>;
00191     }
00192 
00193     POST_END;
00194 
00195     return more_data;
00196   }
00197 };
00198 
00199 } //# NAMESPACE CASA - END
00200 
00201 #endif /* SINGLEDISH_FILLER_SCANTABLE2MSREADER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1