casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
OldGBTBackendTable.h
Go to the documentation of this file.
00001 //# OldGBTBackendTable.h:  GBT backend tables with AIPS++ Look and Feel.
00002 //# Copyright (C) 1995,1997,1999,2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id$
00028 
00029 #ifndef NRAO_OLDGBTBACKENDTABLE_H
00030 #define NRAO_OLDGBTBACKENDTABLE_H
00031 
00032 #include <casa/aips.h>
00033 #include <fits/FITS/FITSTable.h>
00034 #include <casa/Containers/Record.h>
00035 #include <casa/Containers/RecordField.h>
00036 #include <casa/Containers/Block.h>
00037 #include <casa/Containers/RecordDesc.h>
00038 #include <casa/Utilities/DataType.h>
00039 #include <tables/Tables/TableColumn.h>
00040 #include <tables/Tables/TableRecord.h>
00041 #include <casa/Arrays/IPosition.h>
00042 #include <casa/Arrays/Vector.h>
00043 #include <casa/Arrays/Matrix.h>
00044 #include <fits/FITS/hdu.h>
00045 
00046 #include <casa/namespace.h>
00047 //# Forward declarations
00048 namespace casa { //# NAMESPACE CASA - BEGIN
00049 class String;
00050 class HeaderDataUnit;
00051 class Table;
00052 class FitsInput;
00053 class BinaryTable;
00054 } //# NAMESPACE CASA - END
00055 
00056 
00057 // <summary>
00058 // Attach a FITSTabular to a GBT backend FITS file
00059 // </summary>
00060 //
00061 // <use visibility=export>
00062 //
00063 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00064 // </reviewed>
00065 //
00066 // <prerequisite>
00067 //   <li> General knowledge of FITS binary and ASCII tables.
00068 //   <li> General knowledge of the GBT FITS file format for backend data.
00069 // </prerequisite>
00070 //
00071 // <etymology>
00072 // </etymology>
00073 //
00074 // <synopsis>
00075 // OldGBTBackendTable is a FITSTabular which is attached to a GBT FITS 
00076 // backend file.   GBT FITS backend files contain a DATA table and 
00077 // several anciliary tables that correspond to the axes of the data 
00078 // column in the DATA table.  This class makes such a file appear as a 
00079 // single table.
00080 // </synopsis>
00081 //
00082 // <example>
00083 // </example>
00084 //
00085 // <motivation>
00086 // </motivation>
00087 //
00088 // <todo asof="1995/06/01">
00089 //   <li>
00090 // </todo>
00091 
00092 class OldGBTBackendTable : public FITSTabular
00093 {
00094 public:
00095     // The file name
00096     OldGBTBackendTable(const String &fileName);
00097     ~OldGBTBackendTable();
00098 
00099     // Attach this OldGBTBackendTable to a new file name.
00100     Bool reopen(const String &fileName);
00101     virtual const String &name() const { return name_p;}
00102     virtual Bool isValid() const {return isValid_p;}
00103 
00104     virtual const TableRecord &keywords() const {return keywords_p;}
00105     virtual const RecordDesc &description() const {return description_p;}
00106     virtual const Record &units() const {return units_p;}
00107     virtual const Record &displayFormats() const {return disps_p;}
00108     virtual const Record &nulls() const {return nulls_p;}
00109 
00110     virtual Bool pastEnd() const {
00111         return (row_nr_p >= max_row_nr_p || ! isValid());
00112     }
00113     virtual void next() {if (isValid()) fill_row();}
00114     virtual const Record &currentRow() const {return row_p;}
00115 private:
00116     // Undefined and inaccessible. An alternative would be to use reference
00117     // semantics like Table.
00118     OldGBTBackendTable();
00119     OldGBTBackendTable(const OldGBTBackendTable &);
00120     OldGBTBackendTable &operator=(const OldGBTBackendTable &);
00121 
00122     void fill_row();
00123     void clear_self();
00124 
00125     void putField(void *fieldPtr, FitsBase &base, DataType dtype, 
00126                   Int nelements = -1, uInt offset = 0);
00127     void putColumn(void *fieldPtr, const ROTableColumn& tabCol, 
00128                    uInt tabRow, DataType dtype, uInt index = 0);
00129 
00130     Bool isValid_p;
00131 
00132     String name_p;
00133 
00134     Int row_nr_p;
00135     Int max_row_nr_p;
00136     // Used by dataOffset to convert phase number and receiver nr to an 
00137     // offset in the data array
00138     uInt phase_offset_p, rec_offset_p;
00139     // one table phase and one for receiver info, these are held in memory
00140     // that may need to be changed if these supporting table get to be
00141     // too large
00142     Table *phase_table_p, *rec_table_p;
00143     // Similarly, we need a map of table column number to row field number
00144     // for each supporting table, this holds that info, if a value is < 0
00145     // then that column is not in use in the row
00146     Block<Int> phase_map_p, rec_map_p;
00147     // and this is the field that will hold the current row number
00148     // for each support table
00149     RecordFieldPtr<Int> *phase_id_p, *rec_id_p;
00150     // SP (and possibly other?) types of backends have most of the columns 
00151     // indexed by receiver number - we need to make that transparent so 
00152     // here we determine which Fields are so indexed
00153     Block<Bool> rcvrIndexed_p;
00154 
00155     // The total duration of a subscan (individual row in data table)
00156     Double duration_p;
00157     // this is a cumulative duration offset
00158     Double duration_offset_p;
00159     // the  time at the center of each phase averaged over all cycles
00160     // relative to UTCSTART at the start of the integration
00161     Matrix<Double> center_phase_time_p;
00162 
00163     // the time 
00164     RecordFieldPtr<Double> *time_p;
00165     // the UTCSTART and UTDATE field numbers
00166     Int utcstartField_p, utdateField_p;
00167     // sometime utcstart is in RADIANS (spectral processor), but mostly it
00168     // is in seconds - this factor is usually 1 but is sometimes seconds/radian
00169     Double ut_factor_p;
00170     // We need to know if the utcstart column is a keyword or an actual column
00171     Bool utcIsColumn_p;
00172     // only the Holo backend has this, but use it when available
00173     Int dmjdField_p;
00174 
00175     // one table for the DATA table, this is the only fitsio kept active
00176     // throughout the life of the object
00177     BinaryTable *data_table_p;
00178     // this is the map from table column to row field
00179     // Int is < 0 for DATA since that is handled sepearately
00180     Block<Int> data_map_p;
00181     // This is needed to prevent a memory leak, it corresponds to the above binary table
00182     FitsInput * fitsIO_p;
00183     // the field number in the data_table_p of the DATA column
00184     Int dataCol_p;
00185     // this field in row_fields_p holds the data
00186     Int dataField_p;
00187     // the number of elements of data to write at a time
00188     uInt datalength_p;
00189 
00190     // This is a merged collection from all the tables, it may not
00191     // be that useful
00192     TableRecord keywords_p;
00193     // This is a merged description from all the tables, it also contains
00194     // some things that are in the keywords, it corresponds to the
00195     // description actually seen for each row.
00196     RecordDesc description_p;
00197     // These are only the units of the for data table columns.
00198     Record units_p;
00199     // these are also from the data table columns only.
00200     Record disps_p;
00201     Record nulls_p;
00202     // The current row
00203     Record row_p;
00204     // One per field in row_p, of the right type. i.e. casting required.
00205     Block<void *> row_fields_p;
00206 
00207     // this is needed strictly for a bug in the SP FITS files involving
00208     // utcstart and utdate
00209     Double oldStart_p;
00210 
00211     Double utcstart() const { return scalarFieldAsDouble(utcstartField_p); }
00212     Double utdate() const { return scalarFieldAsDouble(utdateField_p); }
00213     Double scalarFieldAsDouble(Int whichField) const;
00214     // This is ugly - These are the reserved FITS keywords that I think do NOT belong
00215     // in the output table - essentially these are keywords that describe the FITS file
00216     // as opposed to the data therin.  They are fundamental to FITS, not the data.
00217 
00218     Vector<String> ignoredFITS;
00219     void init_ignoredFITS();
00220 
00221     // these should probably be made public/static members of the RecordDesc class?
00222     RecordDesc descriptionFromOKKeys(const TableRecord& kwset);
00223     RecordDesc descriptionFromTableDesc(const TableDesc& tabDesc);
00224 };
00225 
00226 
00227 #ifndef AIPS_NO_TEMPLATE_SRC
00228 #include <nrao/FITS/OldGBTBackendTable.tcc>
00229 #endif //# AIPS_NO_TEMPLATE_SRC
00230 #endif