casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GBTMSDataDescFiller.h
Go to the documentation of this file.
00001 //# GBTMSDataDescFiller.h: GBTMSDataDescFiller fills the MSDataDescription table for GBT fillers
00002 //# Copyright (C) 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_GBTMSDATADESCFILLER_H
00030 #define NRAO_GBTMSDATADESCFILLER_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Containers/Block.h>
00035 #include <casa/Containers/RecordField.h>
00036 #include <tables/Tables/TableColumn.h>
00037 #include <ms/MeasurementSets/MSDataDescription.h>
00038 
00039 //# Forward Declarations
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 class MSDataDescColumns;
00042 class Table;
00043 class ColumnsIndex;
00044 } //# NAMESPACE CASA - END
00045 
00046 #include <casa/namespace.h>
00047 
00048 // <summary>
00049 // GBTMSDataDescFiller fills the MSDataDescription table for GBT fillers
00050 // </summary>
00051 
00052 // <use visibility=local>
00053 
00054 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 //   <li> MeasurementSets
00059 //   <li> GBT FITS files
00060 // </prerequisite>
00061 //
00062 // <etymology>
00063 // This class puts GBT data (fills) into the MSDataDescription table.
00064 // </etymology>
00065 //
00066 // <synopsis>
00067 // This class puts the appropriate values for the GBT in an MSDataDescription
00068 // table (which has been previously created as part of a MeasurementSet).
00069 // On each fill() any necessary additions to the MSDataDescription are made.
00070 // This filler keeps a certain number of the most recent data descriptionn IDs and
00071 // the information that makes them unique in a cache.  If a new set of
00072 // information matches that cached information, that ID is reused, otherwise
00073 // new rows are added to the MSDataDescription table.
00074 //
00075 // It will often be the case that several spectral window ids are filled at
00076 // the same time, hence it is necessary to fill several data descriptions at
00077 // the same time.  During a fill, these are associated with a specific receiver id.
00078 //
00079 // The data description Ids are available to be used by 
00080 // other GBTMS*Fillers as other subtables are filled in turn.
00081 //
00082 // Until the GBT polarization and spectral window information is fully available,
00083 // the data description also includes a NS_GBT_RECEIVER_ID column.  This column
00084 // is a key into the GBT_type_* tables.
00085 // </synopsis>
00086 //
00087 // <example>
00088 // </example>
00089 //
00090 // <motivation>
00091 // Writing a filler is a daunting task.  There are various dependencies
00092 // between the subtables.  It helps to encapsulate the knowlege and
00093 // task of filling a specific subtable to separate classes.
00094 // </motivation>
00095 //
00096 //#! <thrown>
00097 //#! A list of exceptions thrown if errors are discovered in the function.
00098 //#! This tag will appear in the body of the header file, preceding the
00099 //#! declaration of each function which throws an exception.
00100 //#! </thrown>
00101 
00102 class GBTMSDataDescFiller
00103 {
00104 public:
00105 
00106     // The default ctor.  No MSDataDescriotion table has been attached yet.
00107     // Calling fill on such a filler will throw an exception.
00108     // It is present so that this object can be instantiated before
00109     // an MSDataDescription has been created.
00110     GBTMSDataDescFiller();
00111 
00112     // A filler attached to an MSDataDescription table
00113     GBTMSDataDescFiller(MSDataDescription &msDataDesc);
00114 
00115     ~GBTMSDataDescFiller();
00116 
00117     // attach it to an MSDataDescription
00118     void attach(MSDataDescription &msDataDesc);
00119 
00120     // fill using the given polarization ID and spectral window ids
00121     void fill(Int polarizationId, const Vector<Int> &specWinIds, 
00122               const Vector<Int> &receiverIds = Vector<Int>());
00123 
00124     Int fill(Int polarizationId, Int specWinId);
00125 
00126     // What is the data description ID associated with the indicated receiver?
00127     // Returns -1 if there is no association yet
00128     Int dataDescriptionId(uInt whichReceiver) const;
00129 
00130     // Return a vector of the most recently filled data description ids
00131     const Vector<Int> &dataDescriptionIds() const {return dataDescIds_p;}
00132 
00133     // The number of receivers which currently have known data description ids
00134     // from the last fill().
00135     Int nrec() const {return receiverMap_p.nelements();}
00136 
00137     // set the cache size - max  number of data description ids and their
00138     // associate information to keep, this always
00139     // re-initializes the cache from the DATA_DESCRIPTION table making it 
00140     // potentially expensive to use.
00141     void setCacheSize(uInt newCacheSize);
00142 
00143     // get the cache size
00144     uInt getCacheSize() const {return cacheSize_p;}
00145 
00146     // flush the underlying MS subtable
00147     void flush() {msDataDesc_p->flush();}
00148 
00149 private:
00150     MSDataDescription *msDataDesc_p;
00151     MSDataDescColumns *msDataDescCols_p;
00152 
00153     // The current Ids
00154     Vector<Int> dataDescIds_p;
00155 
00156     // The map from receiver number to data description ID for the
00157     // current set of Ids
00158     // dataDescIds_p(receiverMap_p[whichReceiver]);
00159     Block<Int> receiverMap_p;
00160 
00161     // the table holding the cache, its temporary
00162     Table *theCache_p;
00163 
00164     // the columns in the cache
00165     TableColumn idCacheCol_p, spWinIdCacheCol_p, polIdCacheCol_p, receiverIdCacheCol_p;
00166 
00167     // The NS_GBT_RECEIVER_ID column in the actual table
00168     TableColumn receiverIdCol_p;
00169 
00170     // The ColumnsIndex for the cache
00171     ColumnsIndex *cacheIndx_p;
00172 
00173     // The pointers to the fields in the index key
00174     RecordFieldPtr<Int> spWinIdKey_p, polIdKey_p, receiverIdKey_p;
00175 
00176     // The next row number to get trashed in the cache when a new ID is generated
00177     uInt nextCacheRow_p;
00178 
00179     // The maximum number of rows in the cache (cache size)
00180     uInt cacheSize_p;
00181 
00182     // initialize the above for the first time
00183     void init(MSDataDescription &msDataDesc);
00184 
00185     // check and optionally fill a row from the index returns the Id
00186     Int checkAndFill(Int polarizationId, Int specWinId, Int receiverId);
00187     
00188 
00189     // undefined and unavailable
00190     GBTMSDataDescFiller(const GBTMSDataDescFiller &other);
00191     void operator=(const GBTMSDataDescFiller &other);
00192 };
00193 
00194 #endif
00195 
00196