casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GBTIFFiller.h
Go to the documentation of this file.
00001 //# GBTIFFiller: A filler for the GBT IF Manager FITS files.
00002 //# Copyright (C) 2000,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_GBTIFFILLER_H
00030 #define NRAO_GBTIFFILLER_H
00031 
00032 #include <nrao/GBTFillers/GBTSimpleTable.h>
00033 
00034 #include <casa/Arrays/Vector.h>
00035 #include <casa/Containers/Block.h>
00036 #include <casa/Containers/RecordField.h>
00037 #include <casa/Containers/SimOrdMap.h>
00038 #include <tables/Tables/Table.h>
00039 #include <tables/Tables/ScalarColumn.h>
00040 #include <casa/BasicSL/String.h>
00041 
00042 //# Forward declarations
00043 namespace casa { //# NAMESPACE CASA - BEGIN
00044 class ColumnsIndex;
00045 } //# NAMESPACE CASA - END
00046 
00047 #include <casa/namespace.h>
00048 
00049 // <summary>
00050 //  A filler for the GBT IF Manager FITS files.
00051 // </summary>
00052 
00053 // <use visibility=local>
00054 
00055 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00056 // </reviewed>
00057 
00058 // <prerequisite>
00059 //   <li> Stuff
00060 // </prerequisite>
00061 //
00062 // <etymology>
00063 // This fills a subtable of a MS using the contents of the IF fits file.
00064 // </etymology>
00065 //
00066 // <synopsis>
00067 // </synopsis>
00068 //
00069 // <example>
00070 // </example>
00071 //
00072 // <motivation>
00073 // It is necessary to have access to the frequency and polarization information 
00074 // during each scan for use in filling other parts of the MS.
00075 // </motivation>
00076 //
00077 // <thrown>
00078 //    <li>
00079 //    <li>
00080 // </thrown>
00081 //
00082 
00083 class GBTIFFiller
00084 {
00085 public:
00086     // makes a new NRAO_GBT_IF subtable if one is not already present in 
00087     // parent, otherwise it opens that one up as is.  The backend string is 
00088     // used throughout to indicate which backend device this corresponds to.
00089     // Each backend filler will have its own GBTIFFiller object.  Only rows 
00090     // appropriate for that backend are saved to the subtable.
00091     GBTIFFiller(Table &parent, const String &backend);
00092 
00093     virtual ~GBTIFFiller();
00094 
00095     // are all of the expected columns present - any SEVERE error results in
00096     // this being set to False
00097     virtual Bool isValid() const {return itsValid;}
00098 
00099     // fill the subtable using the indicated IF FITS file.  The return value
00100     // is the value of the IF_ID in the subtable used when filling from this file.
00101     virtual Int fill(const String &fileName);
00102 
00103     // Indicate which row number in the most recently filled IF FITS file matches
00104     // this combination of bank and port.  A return value of -1 indicates
00105     // that no match was found.  A LogIO::SEVERE message is emitted if more than
00106     // one match is found.  This should not happen, but it also would be bad to
00107     // throw an exception in that case since the rest of the filling process should
00108     // proceed.
00109     Int whichRow(const String &bank, Int port) const;
00110 
00111     // Return the column information from the most recently filled table.
00112     // <group>
00113     virtual const ROScalarColumn<Int> &feed() const {return itsFeedCol;}
00114     virtual const ROScalarColumn<Int> &srfeed1() const {return itsSRFeed1Col;}
00115     virtual const ROScalarColumn<Int> &srfeed2() const {return itsSRFeed2Col;}
00116     virtual const ROScalarColumn<Int> &highCal() const {return itsHighCalCol;}
00117     virtual const ROScalarColumn<String> &receiver() const {return itsReceiverCol;}
00118     virtual const ROScalarColumn<String> &receptor() const {return itsReceptorCol;}
00119     virtual const ROScalarColumn<String> &loCircuit() const {return itsLOCircuit;}
00120     virtual const ROScalarColumn<String> &loComponent() const {return itsLOComponent;}
00121     virtual const ROScalarColumn<String> &sideband() const {return itsSidebandCol;}
00122     virtual const ROScalarColumn<String> &polarize() const {return itsPolarizeCol;}
00123     virtual const ROScalarColumn<Float> &centerIF() const {return itsCenterIfCol;}
00124     virtual const ROScalarColumn<Float> &centerSky() const {return itsCenterSkyCol;}
00125     virtual const ROScalarColumn<Float> &bandwidth() const {return itsBandwidthCol;}
00126     virtual const ROScalarColumn<Double> &sffMultiplier() const {return itsSffMultiplierCol;}
00127     virtual const ROScalarColumn<Double> &sffSideband() const {return itsSffSidebandCol;}
00128     virtual const ROScalarColumn<Double> &sffOffset() const {return itsSffOffsetCol;}
00129     virtual const ROScalarColumn<String> &bank() const {return itsBankCol;}
00130     // </group>
00131 
00132     // Get the feed ID and receptor ID for a given row number, returns False if
00133     // the row number is not valid.  The feedIds start from 0 for each receiver
00134     // in the table.  The receptorIds start from 0 for each feed.  Also returns
00135     // the number of possible receptors for that feed.  These feedIds are used
00136     // in coordinating the filling of the data rows and may not be the same
00137     // as the FEED_ID in the FEED table, which corresponds to physical feeds - 
00138     // if multiple IFs are used, each IF/physical FEED has a unique FEED_ID here.
00139     Bool feedIds(Int whichRow, Int &feedId, Int &receptorId, Int &nReceptors) const;
00140 
00141     // return a reference to the current table
00142     const Table &currentTable() const { return itsCurrTable;}
00143 
00144     // return the index number of the underying simple table
00145     Int index() { return (itsMSTable) ? itsMSTable->index() : -1;}
00146 
00147     // get the backend used at construction time
00148     const String &backend() const { return itsBackend;}
00149 
00150     // Associate an IF frequency (for use in the sky frequency formula)
00151     // a number of channels and the reference channel at which IF
00152     // is valid with a specific bank and port in this table.
00153     // Returns False if bank and port are not found.  deltaFreq gives
00154     // the frequency increment per channel with increasing channel
00155     // number.  The bandwidth here should not be used because it
00156     // may go to zero if the IF manager determines that that signal
00157     // path has zero bandwidth at any point.  Instead, rely on the
00158     // backend.  The only exception is that if deltaFreq is zero,
00159     // use the bandwidth()/nchan here. That should only be used for
00160     // the DCR.
00161     Bool associateIF(const String &bank, Int port, 
00162                      Double ifFreq, Double refChan, Double deltaFreq,
00163                      Int nchan);
00164 
00165     // Get the associated IF frequency, nchan, refChan, and delta
00166     // frequency for the given bank and port.  Returns False if not found.
00167     Bool getIF(const String &bank, Int port, 
00168                Double &ifFreq, Double &refChan, Double &deltaFreq,
00169                Int &nchan);
00170 
00171     // flush the underlying simple table
00172     void flush() { itsMSTable->flush();}
00173 private:
00174     GBTSimpleTable *itsMSTable;
00175     Table itsCurrTable;
00176 
00177     mutable ColumnsIndex *itsIndex;
00178 
00179     mutable RecordFieldPtr<String> itsBankKey;
00180     mutable RecordFieldPtr<Int> itsPortKey;
00181 
00182     mutable Int itsLastRow;
00183 
00184     String itsBackend;
00185     Bool itsUseBank;
00186 
00187     Bool itsSingleReceptor;
00188 
00189     ROScalarColumn<String> itsReceiverCol, itsReceptorCol, itsLOCircuit,
00190         itsLOComponent, itsSidebandCol, itsPolarizeCol, itsBankCol;
00191 
00192     ROScalarColumn<Int> itsFeedCol, itsSRFeed1Col, itsSRFeed2Col, itsHighCalCol;
00193 
00194     ROScalarColumn<Float> itsCenterIfCol, itsCenterSkyCol, itsBandwidthCol;
00195     
00196     ROScalarColumn<Double> itsSffMultiplierCol, itsSffSidebandCol, itsSffOffsetCol;
00197 
00198     SimpleOrderedMap<String, Int> itsMaxFeedIdMap;
00199     SimpleOrderedMap<Int, Int> itsFeedIdMap;
00200 
00201     Block<Int> itsFeedIDs;
00202     Block<Int> itsReceptorIDs;
00203     Block<Int> itsNReceptors;
00204 
00205     Vector<Double> itsIFs, itsRefChans, itsDeltaFreqs;
00206     Vector<Int> itsNchans;
00207 
00208     Bool itsValid;
00209 
00210     void unknownReceiver(const String &rec, Int whichRow, Int &feedId);
00211 
00212     // digest table to get feedIds and receptor ids for each feed on each receiver
00213     void digestTable();
00214 
00215     // unavailable, undefined
00216     GBTIFFiller();
00217     GBTIFFiller(const GBTIFFiller &);
00218     GBTIFFiller &operator=(const GBTIFFiller &);
00219 };
00220 
00221 #endif
00222 
00223