casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GBTBackendTable.h
Go to the documentation of this file.
00001 //# GBTBackendTable.h:  GBT backend tables with AIPS++ Look and Feel.
00002 //# Copyright (C) 1998,1999,2001,2002,2003
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_GBTBACKENDTABLE_H
00030 #define NRAO_GBTBACKENDTABLE_H
00031 
00032 #include <casa/aips.h>
00033 #include <nrao/FITS/GBTStateTable.h>
00034 #include <nrao/FITS/GBTScanLogReader.h>
00035 #include <fits/FITS/FITSTable.h>
00036 #include <casa/Arrays/Vector.h>
00037 #include <fits/FITS/CopyRecord.h>
00038 
00039 #include <casa/namespace.h>
00040 // forward declarations
00041 namespace casa { //# NAMESPACE CASA - BEGIN
00042 class String;
00043 class Table;
00044 } //# NAMESPACE CASA - END
00045 
00046 
00047 // <summary>
00048 // Attach a FITSTabular to a GBT backend FITS file
00049 // </summary>
00050 //
00051 // <use visibility=export>
00052 //
00053 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00054 // </reviewed>
00055 //
00056 // <prerequisite>
00057 // </prerequisite>
00058 //
00059 // <etymology>
00060 // </etymology>
00061 //
00062 // <synopsis>
00063 // GBTBackendTable is a FITSTabular which is attached to a GBT FITS 
00064 // backend file.   GBT FITS backend files contain a DATA table and 
00065 // several anciliary tables that correspond to the axes of the data 
00066 // column in the DATA table.  
00067 // </synopsis>
00068 //
00069 // <example>
00070 // </example>
00071 //
00072 // <motivation>
00073 // </motivation>
00074 //
00075 // <todo asof="1995/06/01">
00076 //   <li>
00077 // </todo>
00078 class GBTBackendTable : public FITSTabular
00079 {
00080 public:
00081     // Default constructor, not attached to any specific file
00082     GBTBackendTable();
00083     
00084     // Construct it from a file name
00085     GBTBackendTable(const String &fileName);
00086     ~GBTBackendTable();
00087 
00088     // Attach this GBTBackendTable to a new file name.
00089     // when resync is True, if fileName is the same as the
00090     // currently opened file, if there is one, then this just
00091     // closes and reopens the FITS file setting things right
00092     // back to the next row in the table, if there is one
00093     virtual Bool reopen(const String &fileName, Bool resync);
00094 
00095     // the reopen from FITSTabular, uses reopen here with resync=True
00096     virtual Bool reopen(const String &fileName) {return reopen(fileName, True);}
00097     
00098     // Return the type of this backend
00099     GBTScanLogReader::BACKENDS type() const {return itsType;}
00100 
00101     // return the name of the underlying table used at construction
00102     virtual const String &name() const {return dataTable_p->name();}
00103 
00104     // is this a valid GBTBackendTable?
00105     virtual Bool isValid() const {return isValid_p;}
00106 
00107     // The number of elements along the STATE axis
00108     virtual uInt nstate() const {return itsNstate;}
00109 
00110     // The number of elements along the frequency axis (defaults to 1
00111     // for non-spectral line data) for a specific sampler.
00112     // For most backends, this is a constant.  For the ACS
00113     // backend, if there are more than one banks involved, it
00114     // may vary with sampler.  The default implementation is
00115     // to return a constant.
00116     virtual uInt nchan(uInt whichSampler) const {return itsNchan;}
00117 
00118     // The number of elements along the sampler axis.
00119     virtual uInt nsamp() const {return itsNsamp;}
00120 
00121     // The bandwidth for the indicated sampler.  If this is < 0 then that
00122     // signals that it is not known here and it should be fetched from
00123     // the IF BANDWDTH column.
00124     virtual Double bw(uInt whichSampler) const {return itsBW[whichSampler];}
00125 
00126     // The center IF for the indicated sampler.  If this is < 0 then that
00127     // signals that it is not known here and it should be fetched from
00128     // the IF CENTER_IF column.
00129     virtual Double centerIF(uInt whichSampler) const {return itsCenterIF[whichSampler];}
00130 
00131     // Indicates whether frequency increases with channel number for the
00132     // given sampler.
00133     virtual Bool increases(uInt whichSampler) const {return itsIncreases[whichSampler];}
00134  
00135     // these keywords associated with the FITS data table.
00136     virtual const TableRecord &keywords() const {return keywords_p;}
00137 
00138     virtual const RecordDesc &description() const {return dataTable_p->description();}
00139     virtual const Record &units() const {return dataTable_p->units();}
00140     virtual const Record &displayFormats() const {return dataTable_p->displayFormats();}
00141     virtual const Record &nulls() const {return dataTable_p->nulls();}
00142 
00143     // is this now past the end of the FITS table?
00144     virtual Bool pastEnd() const {return dataTable_p->pastEnd();}
00145 
00146     // advance to the next row
00147     virtual void next() {
00148         dataTable_p->next();
00149         if (fieldCopier_p) fieldCopier_p->copy();
00150     }
00151     // return the current row
00152     virtual const Record &currentRow() const {return dataTable_p->currentRow();}
00153 
00154     // the unhandled keywords
00155     virtual const Record &unhandledKeywords() 
00156         { 
00157             if (!unhandledKeys_p) initUnhandledKeys();
00158             return *unhandledKeys_p;
00159         }
00160     // mark a keyword as handled
00161     virtual void handleKeyword(const String &kwname);
00162 
00163     // the unhandled fields in currentRow
00164     virtual const Record &unhandledFields()
00165         { 
00166             if (!unhandledFields_p) initUnhandledFields();
00167             return *unhandledFields_p;
00168         }
00169     // mark a field in currentRow as being handled
00170     virtual void handleField(const String &fieldname);
00171 
00172     // the ancilliary tables - empty tables when not present
00173     virtual const Table &sampler() const {return *sampler_p;}
00174     virtual const GBTStateTable &state() const {return state_p;}
00175     virtual const Table &actState() const {return *actState_p;}
00176     virtual const Table &port() const {return *port_p;}
00177 
00178     virtual uInt nrow() const {return dataTable_p->nrow();}
00179     virtual uInt rownr() const {return dataTable_p->rownr();}
00180 
00181     // FITSVER - FITS definition version for this device.
00182     // Default value: "0.0"
00183     virtual const String &fitsVers() const {return itsFitsVer;}
00184 
00185     // Leading integer (before decimal) in FITSVER - version of base class.
00186     virtual Int baseVersion() const {return itsBaseVer;}
00187 
00188     // Trailing integer (after decimal) in FITS - version of device.
00189     virtual Int deviceVersion() const {return itsDeviceVer;}
00190 
00191 private:
00192     GBTScanLogReader::BACKENDS itsType;
00193 
00194     FITSTable *dataTable_p;
00195     Table *sampler_p, *actState_p, *port_p;
00196     GBTStateTable state_p;
00197 
00198     TableRecord keywords_p;
00199     Record *unhandledKeys_p, *unhandledFields_p;
00200 
00201     CopyRecordToRecord *fieldCopier_p;
00202 
00203     Vector<Int> keyMap_p, fieldMap_p;
00204     Vector<Double> itsBW, itsCenterIF;
00205     Vector<Bool> itsIncreases;
00206 
00207     Bool isValid_p;
00208 
00209     uInt itsNstate, itsNchan, itsNsamp;
00210 
00211     String itsFitsVer;
00212     Int itsBaseVer, itsDeviceVer;
00213 
00214     void clear_self(Bool resync=False);
00215 
00216     // construct a Table from a FITSTable, it is the responsiblity
00217     // of the calling entity to delete the returned pointer
00218     // the constructed table is a Scratch table using the
00219     // AipsIO storage manager
00220     Table *tableFromFITS(FITSTable &fits);
00221 
00222     void initUnhandledKeys();
00223     void initUnhandledFields();
00224 
00225     // Undefined and inaccessible.
00226     GBTBackendTable(const GBTBackendTable &);
00227     GBTBackendTable &operator=(const GBTBackendTable &);
00228 };
00229 
00230 
00231 #endif