casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GBTMSSpecWinFiller.h
Go to the documentation of this file.
00001 //# GBTMSSpecWinFiller.h: GBTMSSpecWinFiller fills the MSSpectralWindow table for GBT fillers
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_GBTMSSPECWINFILLER_H
00030 #define NRAO_GBTMSSPECWINFILLER_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Containers/RecordField.h>
00035 #include <tables/Tables/TableColumn.h>
00036 #include <casa/BasicSL/String.h>
00037 #include <ms/MeasurementSets/MSSpectralWindow.h>
00038 #include <measures/Measures/MFrequency.h>
00039 
00040 //# Forward Declarations
00041 namespace casa { //# NAMESPACE CASA - BEGIN
00042 class MSSpWindowColumns;
00043 class Table;
00044 class ColumnsIndex;
00045 } //# NAMESPACE CASA - END
00046 
00047 #include <casa/namespace.h>
00048 
00049 // <summary>
00050 // GBTMSSpecWinFiller fills the MSSpectralWindow table for GBT fillers
00051 // </summary>
00052 
00053 // <use visibility=local>
00054 
00055 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00056 // </reviewed>
00057 
00058 // <prerequisite>
00059 //   <li> MeasurementSets
00060 //   <li> GBT FITS files
00061 // </prerequisite>
00062 //
00063 // <etymology>
00064 // This class puts GBT data (fills) into the MSSpectralWindow table.
00065 // </etymology>
00066 //
00067 // <synopsis>
00068 // This class puts the appropriate values for the GBT in an MSSpectralWindow
00069 // table (which has been previously created as part of a MeasurementSet).
00070 // On each fill() any necessary additions to the MSSpectralWindow are made.
00071 // This filler keeps a certain number of the most spectral window IDs and
00072 // the information that makes them unique in a cache.  If a new set of
00073 // information matches that cached information, that ID is reused, otherwise
00074 // new rows are added to the MSSpectralWindow table.
00075 //
00076 // In principle, the number of spectral window Id may vary with the
00077 // the number of receivers in the backend (at least, thats the idea so far).
00078 // 
00079 // The specWinId is available to be used by 
00080 // other GBTMS*Fillers as other subtables are filled in turn.
00081 //
00082 // </synopsis>
00083 //
00084 // <example>
00085 // </example>
00086 //
00087 // <motivation>
00088 // Writing a filler is a daunting task.  There are various dependencies
00089 // between the subtables.  It helps to encapsulate the knowlege and
00090 // task of filling a specific subtable to separate classes.
00091 // </motivation>
00092 //
00093 //#! <thrown>
00094 //#! A list of exceptions thrown if errors are discovered in the function.
00095 //#! This tag will appear in the body of the header file, preceding the
00096 //#! declaration of each function which throws an exception.
00097 //#! </thrown>
00098 
00099 class GBTMSSpecWinFiller
00100 {
00101 public:
00102 
00103     // The default ctor.  No MSSpectralWindow table has been attached yet.
00104     // Calling fill on such a filler will throw an exception.
00105     // It is present so that this object can be instantiated before
00106     // an MSSpecWin has been created.
00107     GBTMSSpecWinFiller();
00108 
00109     // A filler attached to an MSSpectralWindow table
00110     GBTMSSpecWinFiller(MSSpectralWindow &msSpecWin);
00111 
00112     ~GBTMSSpecWinFiller();
00113 
00114     // attach it to an MSSpectralWindow
00115     void attach(MSSpectralWindow &msSpecWin);
00116 
00117     // fill using the indicated frequency axis description
00118     // returns the SPECTRAL_WINDOW_ID associated with this call to fill.
00119     // The tolerance is in Hz.  If this SW is within tolerance of an
00120     // already existing SW and the chanWidths are the same, that
00121     // existing SW will be re-used.  SPWs in the exclude vector will
00122     // not be used (that is used elsewhere to guarantee unique
00123     // spws even when they would otherwise match an existing spw).
00124     Int fill(uInt nfreq, Double centerFreq, Double centerChan, Double chanWidth,
00125              MFrequency::Types restFrame = MFrequency::TOPO,
00126              Double tolerance=10.0, const Vector<Int> &exclude = Vector<Int>());
00127 
00128     // fill a dummy (no spectral information actually present) row 
00129     // this is necessary until the IF manager is sufficient to supply 
00130     // frequency information for all of the backends.
00131     void fill(uInt nreceivers, uInt nfreq);
00132 
00133     // What is the spectral window ID associated with the indicated receiver
00134     // Returns -1 if there is no association yet
00135     Int spectralWindowId(uInt whichReceiver) const;
00136 
00137     // Return a vector of the spectral window Ids for each receiver
00138     const Vector<Int> &spectralWindowIds() const {return specWinIds_p;}
00139 
00140     // The number of receivers which currently have known spectral window Ids
00141     // from the last fill().
00142     Int nrec() const {return specWinIds_p.nelements();}
00143 
00144     Int nfreq() const {return nfreq_p;}
00145 
00146     // set the cache size - max  number of spectral window IDs and their
00147     // associate information to keep, this always
00148     // re-initializes the cache from the SPECTRAL_WINDOW table making it 
00149     // expensive to use.
00150     void setCacheSize(uInt newCacheSize);
00151 
00152     // get the cache size
00153     uInt getCacheSize() const {return cacheSize_p;}
00154 
00155     // flush the underlying MS subtable
00156     void flush() {msSpecWin_p->flush();}
00157 
00158 private:
00159     MSSpectralWindow *msSpecWin_p;
00160     MSSpWindowColumns *msSpecWinCols_p;
00161 
00162     // The current Ids
00163     Vector<Int> specWinIds_p;
00164 
00165     // from the last fill
00166     Int nfreq_p;
00167 
00168     // the table holding the cache, its temporary
00169     Table *theCache_p;
00170 
00171     // the columns in the cache
00172     TableColumn idCacheCol_p, nfreqCacheCol_p, obsfreqCacheCol_p,
00173         freqresCacheCol_p, refchanCacheCol_p, bwCacheCol_p,
00174         restFrameCacheCol_p;
00175 
00176     // The ColumnsIndex for the cache
00177     ColumnsIndex *cacheIndx_p;
00178 
00179     // The pointers to the fields in the index key
00180     RecordFieldPtr<Int> nfreqKey_p, restFrameKey_p;
00181     RecordFieldPtr<Double> refchanKey_p;
00182 
00183     // The next row number to get trashed in the cache when a new ID is 
00184     // generated
00185     uInt nextCacheRow_p;
00186 
00187     // The maximum number of rows in the cache (cache size)
00188     uInt cacheSize_p;
00189 
00190     // initialize the above for the first time
00191     void init(MSSpectralWindow &msSpecWin);
00192 
00193     // add a new row to the spectral window table using these value
00194     // return the new row number
00195     Int newSpecWin(Int nfreq, Double obsfreq, Double freqres, Double refchan, 
00196                    Double bw, Int restframe);
00197 
00198     // undefined and unavailable
00199     GBTMSSpecWinFiller(const GBTMSSpecWinFiller &other);
00200     void operator=(const GBTMSSpecWinFiller &other);
00201 };
00202 
00203 #endif
00204 
00205