casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CalMainBuffer.h
Go to the documentation of this file.
00001 //# CalMainBuffer.h: Calibration main table buffer
00002 //# Copyright (C) 1996,1997,1998,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 adressed 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 CALIBRATION_CALMAINBUFFER_H
00030 #define CALIBRATION_CALMAINBUFFER_H
00031 
00032 #include <synthesis/CalTables/CalDescBuffer.h>
00033 #include <synthesis/CalTables/CalHistoryBuffer.h>
00034 #include <synthesis/CalTables/CalTable.h>
00035 #include <synthesis/CalTables/CalMainColumns.h>
00036 #include <synthesis/MSVis/MSCalEnums.h>
00037 #include <synthesis/MSVis/VisBuffer.h>
00038 #include <synthesis/CalTables/CalIterBase.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 // <summary> 
00043 // CalMainBuffer: Calibration main table buffer
00044 // </summary>
00045 
00046 // <use visibility=export>
00047 
00048 // <reviewed reviewer="" date="" tests="" demos="">
00049 
00050 // <prerequisite>
00051 //   <li> <linkto class="CalTable">CalTable</linkto> module
00052 //   <li> <linkto class="CalIterBase">CalIterBase</linkto> module
00053 // </prerequisite>
00054 //
00055 // <etymology>
00056 // From "calibration main table" and "buffer"
00057 // </etymology>
00058 //
00059 // <synopsis>
00060 // The CalMainBuffer class holds a buffer, optionally connected to a 
00061 // calibration main table iterator (of base type CalIterBase). 
00062 // Specializations for baseline-based, time-variable and solvable 
00063 // VisJones calibration table formats are provided through 
00064 // inheritance.
00065 // </synopsis>
00066 //
00067 // <example>
00068 // <srcblock>
00069 // </srcblock>
00070 // </example>
00071 //
00072 // <motivation>
00073 // Encapsulate calibration main table data buffers.
00074 // </motivation>
00075 //
00076 // <todo asof="01/08/01">
00077 // (i) Deal with non-standard columns.
00078 // </todo>
00079 
00080 class CalMainBuffer 
00081 {
00082  public:
00083   // Default constructor. No connection to an underlying
00084   // calibration table iterator in this case.
00085   CalMainBuffer();
00086 
00087   // Construct from a set of calibration buffer indices and
00088   // their specified values. Non-index columns will be set 
00089   // to default values. There is no connection to an underlying 
00090   // calibration table iterator in this case.
00091   CalMainBuffer (const Vector<Int>& calIndices, 
00092                  const Block<Vector<Int> >& indexValues);
00093 
00094   // Construct from a calibration table iterator. The calibration
00095   // buffer will remain synchronized with the iterator.
00096   CalMainBuffer (CalIterBase& calIter);
00097 
00098   // Default destructor
00099   virtual ~CalMainBuffer();
00100 
00101   // Synchronize the buffer (if attached to an iterator)
00102   virtual void synchronize();
00103 
00104   // Force an explicit read to cache for all columns 
00105   // (if attached to an iterator)
00106   virtual void fillCache();
00107 
00108   // Write the current buffer at the end of a specified cal table;
00109   // returns the number of rows appended.
00110   virtual Int append (CalTable& calTable);
00111 
00112   // Maximum number of rows in the calibration buffer
00113   virtual Int nRow();
00114 
00115   // Accessors for the contained cal_desc and cal_history buffers
00116   virtual CalDescBuffer& calDescBuffer() {return *calDescBuf_p;};
00117   virtual CalHistoryBuffer& calHistoryBuffer() {return *calHistBuf_p;};
00118 
00119   // Data field accessors
00120   virtual Vector<MEpoch>& timeMeas();
00121   virtual Vector<Quantity>& timeEPQuant();
00122   virtual Vector<Quantity>& intervalQuant();
00123   virtual Vector<Int>& antenna1();
00124   virtual Vector<Int>& feed1();
00125   virtual Vector<Int>& fieldId();
00126   virtual Vector<Int>& arrayId();
00127   virtual Vector<Int>& obsId();
00128   virtual Vector<Int>& scanNo();
00129   virtual Vector<Int>& processorId();
00130   virtual Vector<Int>& stateId();
00131   virtual Vector<Int>& phaseId();
00132   virtual Vector<Int>& pulsarBin();
00133   virtual Vector<Int>& pulsarGateId();
00134   virtual Vector<Int>& freqGrp();
00135   virtual Vector<String>& freqGrpName();
00136   virtual Vector<String>& fieldName();
00137   virtual Vector<String>& fieldCode();
00138   virtual Vector<String>& sourceName();
00139   virtual Vector<String>& sourceCode();
00140   virtual Vector<Int>& calGrp();
00141   virtual Array<Complex>& gain();
00142   virtual Array<Int>& refAnt();
00143   virtual Array<Int>& refFeed();
00144   virtual Array<Int>& refReceptor();
00145   virtual Array<MFrequency>& refFreqMeas();
00146   virtual Vector<Int>& measFreqRef();
00147   virtual Array<MDirection>& refDirMeas();
00148   virtual Vector<Int>& measDirRef();
00149   virtual Vector<Int>& calDescId();
00150   virtual Vector<Int>& calHistoryId(); 
00151 
00152   // Generic access to integer columns by MSCalEnums enumeration. Throws
00153   // an exception if the column is not recognized or is not an integer column.
00154   virtual Vector<Int>& asVecInt (const MSCalEnums::colDef& calEnum);
00155 
00156   // Generic access to string columns by MSCalEnums enumeration. Throws
00157   // an exception if the column is not recognized or is not a string column.
00158   virtual Vector<String>& asVecString (const MSCalEnums::colDef& calEnum);
00159 
00160   // Find the matching rows for a given antenna1 id.
00161   virtual Vector<Int> matchAntenna1 (const Int& antennaId);
00162 
00163   // Find the matching rows for a given antenna1 id. and field id. pair
00164   virtual Vector<Int> matchAntenna1AndFieldId (const Int& antennaId,
00165                                                const Int& fldId);
00166 
00167   // Find the matching rows for a given antenna1 id. and freq. group name
00168   virtual Vector<Int> matchAntenna1AndFreqGrp (const Int& antennaId,
00169                                                const String& frqGrpName);
00170 
00171  protected:
00172   // Factory method to create a columns accessor object of the appropriate type
00173   virtual CalMainColumns* newCalMainCol (CalTable& calTable)
00174     {return new CalMainColumns (calTable);};
00175 
00176   // Access to the columns accessor object
00177   virtual CalMainColumns* calMainCol() {return calMainCol_p;};
00178 
00179   // Is the buffer connected to an underlying iterator ?
00180   Bool connectedToIter() {return connectedToIter_p;};
00181 
00182   // Invalidate the current cache. 
00183   virtual void invalidate();
00184 
00185   // <group>
00186   // Span an empty cal buffer by taking all permutations of the
00187   // values of a specified set of cal indices, specified as
00188   // enums from class MSCalEnums:
00189   //
00190   // Use a visibility buffer to define the index values 
00191   virtual void fillIndices (const Vector<Int>& calIndices,
00192                             const VisBuffer& vb);
00193 
00194   // Define the index values directly
00195   virtual void fillIndices (const Vector<Int>& calIndices,
00196                             const Block<Vector<Int> >& indexValues);
00197   // </group>
00198 
00199   // <group>
00200   // Fill the cal buffer attribute columns in an empty cal buffer,
00201   // after the cal indices have been set using fillIndices(). The 
00202   // cal indices, specified as enums from class MSCalEnums, are excluded
00203   // as non-attribute columns.
00204   //
00205   // Use a visibility buffer to define the attribute values
00206   virtual void fillAttributes(const Vector<Int>& calIndices,
00207                               const VisBuffer& vb);
00208 
00209   // Set default attribute values
00210   virtual void fillAttributes(const Vector<Int>& calIndices);
00211 
00212   // </group>
00213 
00214   // Utility function to test for membership in a list of calibration enums
00215   Bool excluded(const MSCalEnums::colDef& calEnum, 
00216                 const Vector<Int>& excludeIndices);
00217 
00218  private:
00219   // True if connected to underlying iterator
00220   Bool connectedToIter_p;
00221 
00222   // Ptr to calibration table iterator
00223   CalIterBase* calIter_p;
00224 
00225   // Ptr to cal main columns accessor
00226   CalMainColumns* calMainCol_p;
00227 
00228   // Contained sub-table cal_desc and cal_history buffers
00229   CalDescBuffer* calDescBuf_p;
00230   CalHistoryBuffer* calHistBuf_p;
00231 
00232   // Buffer fields
00233   Vector<MEpoch> timeMeas_p;
00234   Vector<Quantity> timeEPQuant_p;
00235   Vector<Quantity> intervalQuant_p;
00236   Vector<Int> antenna1_p;
00237   Vector<Int> feed1_p;
00238   Vector<Int> fieldId_p;
00239   Vector<Int> arrayId_p;
00240   Vector<Int> obsId_p;
00241   Vector<Int> scanNo_p;
00242   Vector<Int> processorId_p;
00243   Vector<Int> stateId_p;
00244   Vector<Int> phaseId_p;
00245   Vector<Int> pulsarBin_p;
00246   Vector<Int> pulsarGateId_p;
00247   Vector<Int> freqGrp_p;
00248   Vector<String> freqGrpName_p;
00249   Vector<String> fieldName_p;
00250   Vector<String> fieldCode_p;
00251   Vector<String> sourceName_p;
00252   Vector<String> sourceCode_p;
00253   Vector<Int> calGrp_p;
00254   Array<Complex> gain_p;
00255   Array<Int> refAnt_p;
00256   Array<Int> refFeed_p;
00257   Array<Int> refReceptor_p;
00258   Array<MFrequency> refFreqMeas_p;
00259   Vector<Int> measFreqRef_p;
00260   Array<MDirection> refDirMeas_p;
00261   Vector<Int> measDirRef_p;
00262   Vector<Int> calDescId_p;
00263   Vector<Int> calHistoryId_p;
00264 
00265   // Buffer field status flags
00266   Bool timeMeasOK_p;
00267   Bool timeEPQuantOK_p;
00268   Bool intervalQuantOK_p;
00269   Bool antenna1OK_p;
00270   Bool feed1OK_p;
00271   Bool fieldIdOK_p;
00272   Bool arrayIdOK_p;
00273   Bool obsIdOK_p;
00274   Bool scanNoOK_p;
00275   Bool processorIdOK_p;
00276   Bool stateIdOK_p;
00277   Bool phaseIdOK_p;
00278   Bool pulsarBinOK_p;
00279   Bool pulsarGateIdOK_p;
00280   Bool freqGrpOK_p;
00281   Bool freqGrpNameOK_p;
00282   Bool fieldNameOK_p;
00283   Bool fieldCodeOK_p;
00284   Bool sourceNameOK_p;
00285   Bool sourceCodeOK_p;
00286   Bool calGrpOK_p;
00287   Bool gainOK_p;
00288   Bool refAntOK_p;
00289   Bool refFeedOK_p;
00290   Bool refReceptorOK_p;
00291   Bool refFreqMeasOK_p;
00292   Bool measFreqRefOK_p;
00293   Bool refDirMeasOK_p;
00294   Bool measDirRefOK_p;
00295   Bool calDescIdOK_p;
00296   Bool calHistoryIdOK_p;
00297 };
00298 
00299 
00300 } //# NAMESPACE CASA - END
00301 
00302 #endif
00303    
00304   
00305 
00306 
00307