NRO2MSReader.h

Go to the documentation of this file.
00001 /*
00002  * NROReader.h
00003  *
00004  *  Created on: May 9, 2016
00005  *      Author: wataru kawasaki
00006  */
00007 
00008 #ifndef SINGLEDISH_FILLER_NRO2MSREADER_H_
00009 #define SINGLEDISH_FILLER_NRO2MSREADER_H_
00010 
00011 #define STRING2CHAR(s) const_cast<char *>((s).c_str())
00012 
00013 #include <singledish/Filler/ReaderInterface.h>
00014 #include <singledish/Filler/NROData.h>
00015 #include <string>
00016 #include <memory>
00017 
00018 namespace casa { //# NAMESPACE CASA - BEGIN
00019   
00020 constexpr double kDay2Sec = 86400.0;
00021 constexpr double kSec2Day = 1.0 / kDay2Sec;
00022 
00023 class NRO2MSReader: public ReaderInterface {
00024 public:
00025   NRO2MSReader(std::string const &scantable_name);
00026   virtual ~NRO2MSReader();
00027 
00028   // get number of rows
00029   virtual size_t getNumberOfRows();
00030 
00031   virtual MDirection::Types getDirectionFrame();
00032   
00033   virtual Bool isFloatData() const {
00034     return True;
00035   }
00036 
00037   // to get OBSERVATION table
00038   virtual Bool getObservationRow(sdfiller::ObservationRecord &record) {
00039     POST_START;
00040     Bool return_value = (*this.*get_observation_row_)(record);
00041     POST_END;
00042     return return_value;
00043   }
00044 
00045   // to get ANTENNA table
00046   virtual Bool getAntennaRow(sdfiller::AntennaRecord &record) {
00047     POST_START;
00048     Bool return_value = (*this.*get_antenna_row_)(record);
00049     POST_END;
00050     return return_value;
00051   }
00052 
00053   // to get PROCESSOR table
00054   virtual Bool getProcessorRow(sdfiller::ProcessorRecord &record) {
00055     POST_START;
00056     Bool return_value = (*this.*get_processor_row_)(record);
00057     POST_END;
00058     return return_value;
00059   }
00060 
00061   // to get SOURCE table
00062   virtual Bool getSourceRow(sdfiller::SourceRecord &record) {
00063     POST_START;
00064     Bool return_value = (*this.*get_source_row_)(record);
00065     POST_END;
00066     return return_value;
00067   }
00068 
00069   // to get FIELD table
00070   virtual Bool getFieldRow(sdfiller::FieldRecord &record) {
00071     POST_START;
00072     Bool return_value = (*this.*get_field_row_)(record);
00073     POST_END;
00074     return return_value;
00075   }
00076 
00077   // to get SOURCE table
00078   virtual Bool getSpectralWindowRow(sdfiller::SpectralWindowRecord &record) {
00079     POST_START;
00080     Bool return_value = (*this.*get_spw_row_)(record);
00081     POST_END;
00082     return return_value;
00083   }
00084 
00085   // for DataAccumulator
00086   virtual Bool getData(size_t irow, sdfiller::DataRecord &record);
00087 
00088   virtual int getNROArraySize() {
00089     return obs_header_.NBEAM * obs_header_.NPOL * obs_header_.NSPWIN;
00090   }
00091   virtual int getNRONumBeam() {
00092     return obs_header_.NBEAM;
00093   }
00094   virtual int getNRONumPol() {
00095     return obs_header_.NPOL;
00096   }
00097   virtual int getNRONumSpw() {
00098     return obs_header_.NSPWIN;
00099   }
00100 
00101 protected:
00102   void initializeSpecific();
00103   void finalizeSpecific();
00104 
00105 private:
00106   FILE *fp_;
00107   sdfiller::NRODataObsHeader obs_header_;
00108   void readObsHeader();
00109   void readScanData(int const irow, sdfiller::NRODataScanData &data);
00110   void checkEndian();
00111   template<typename T>
00112   void convertEndian(T &value) {
00113     char volatile *first = reinterpret_cast<char volatile *>(&value) ;
00114     char volatile *last = first + sizeof(T) ;
00115     std::reverse(first, last) ;
00116   }
00117 
00118   bool same_endian_;
00119 
00120   template<typename T>
00121   void readHeader(T &v) {
00122     if ((int)fread(&v, 1, sizeof(T), fp_) != sizeof(T)) {
00123       cout << "read failed." << endl;
00124     }
00125     if (!same_endian_) {
00126       convertEndian(v);
00127     }
00128   }
00129 
00130   template<typename T>
00131   void readHeader(T *v, size_t numArray) {
00132     for (size_t i = 0; i < numArray; ++i) {
00133       readHeader<T>(v[i]);
00134     }
00135   }
00136 
00137   void readHeader(string &v, size_t strLength) {
00138     v.resize(strLength);
00139     if (fread(STRING2CHAR(v), 1, strLength, fp_) != strLength) {
00140       cout << "read failed." << endl;
00141     }
00142     v.resize(strlen(v.c_str())); // remove trailing null characters
00143   }
00144 
00145   void readHeader(string *v, size_t strLength, size_t numArray) {
00146     for (size_t i = 0; i < numArray; ++i) {
00147       readHeader(v[i], strLength);
00148     }
00149   }
00150 
00151   int beam_id_counter_;
00152   int source_spw_id_counter_;
00153   int spw_id_counter_;
00154   Vector<Double> time_range_sec_;
00155   int const len_obs_header_ = 15136;
00156   double getMJD(string const &time);
00157   double getIntMiddleTimeSec(sdfiller::NRODataScanData const &data);
00158   double getIntStartTimeSec(int const scanno);
00159   double getIntEndTimeSec(int const scanno);
00160   void getFullTimeRange();
00161   double getMiddleOfTimeRangeSec();
00162 
00163   Double const posx_ = -3.8710235e6;
00164   Double const posy_ =  3.4281068e6;
00165   Double const posz_ =  3.7240395e6;
00166 
00167   double getRestFrequency(int const spwno);
00168   string convertVRefName(string const &vref0);
00169 
00170   std::vector<double> getSpectrum(int const irow, sdfiller::NRODataScanData const &data);
00171   Int getPolNo(string const &rx);
00172 
00173   Bool (NRO2MSReader::*get_antenna_row_)(sdfiller::AntennaRecord &);
00174   Bool (NRO2MSReader::*get_field_row_)(sdfiller::FieldRecord &);
00175   Bool (NRO2MSReader::*get_observation_row_)(sdfiller::ObservationRecord &);
00176   Bool (NRO2MSReader::*get_processor_row_)(sdfiller::ProcessorRecord &);
00177   Bool (NRO2MSReader::*get_source_row_)(sdfiller::SourceRecord &);
00178   Bool (NRO2MSReader::*get_spw_row_)(sdfiller::SpectralWindowRecord &);
00179 
00180   Bool getAntennaRowImpl(sdfiller::AntennaRecord &record);
00181   Bool getFieldRowImpl(sdfiller::FieldRecord &record);
00182   Bool getObservationRowImpl(sdfiller::ObservationRecord &record);
00183   Bool getProcessorRowImpl(sdfiller::ProcessorRecord &record);
00184   Bool getSourceRowImpl(sdfiller::SourceRecord &record);
00185   Bool getSpectralWindowRowImpl(sdfiller::SpectralWindowRecord &record);
00186 
00187   template<class _Record>
00188   Bool noMoreRowImpl(_Record &) {
00189     POST_START;POST_END;
00190     return False;
00191   }
00192 };
00193 
00194 } //# NAMESPACE CASA - END
00195 
00196 #endif /* SINGLEDISH_FILLER_NRO2MSREADER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1