casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MSCache.h
Go to the documentation of this file.
00001 //# MSCache.h: MS-specific Data cache for plotms.
00002 //# Copyright (C) 2009
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 //# $Id: $
00027 #ifndef MSCACHE_H_
00028 #define MSCACHE_H_
00029 
00030 #include <plotms/Data/PlotMSCacheBase.h>
00031 
00032 #include <plotms/PlotMS/PlotMSAveraging.h>
00033 #include <plotms/PlotMS/PlotMSConstants.h>
00034 #include <plotms/PlotMS/PlotMSFlagging.h>
00035 #include <plotms/Actions/PlotMSCacheThread.qo.h>
00036 #include <plotms/Data/PlotMSVBAverager.h>
00037 #include <plotms/Data/MSCacheVolMeter.h>
00038 
00039 #include <casa/aips.h>
00040 #include <casa/Arrays.h>
00041 #include <casa/Containers/Block.h>
00042 #include <synthesis/MSVis/VisIterator.h>
00043 #include <synthesis/MSVis/VisBuffer.h>
00044 #include <synthesis/MSVis/VisBufferUtil.h>
00045 
00046 namespace casa {
00047 
00048 //# Forward declarations.
00049 class PlotMSApp;
00050 class PlotMSIndexer;
00051 
00052 class MSCache : public PlotMSCacheBase {
00053     
00054   // Friend class declarations.
00055   friend class PlotMSIndexer;
00056 
00057 public:    
00058   
00059   // Constructor which takes parent PlotMS.
00060   MSCache(PlotMSApp* parent);
00061   
00062   // Destructor
00063   virtual ~MSCache();
00064 
00065   // Identify myself
00066   PlotMSCacheBase::Type cacheType() { return PlotMSCacheBase::MS; };
00067 
00068   // Access to channel averaging bounds
00069   Matrix<Int>& chanAveBounds(Int spw) { return chanAveBounds_p(spw); };
00070   
00071   // ...not yet MS-specific... (or ever?)
00072   // Set up indexing for the plot
00073   //  void setUpIndexer(PMS::Axis iteraxis=PMS::SCAN,
00074   //                Bool globalXRange=False, Bool globalYRange=False);
00075 
00076   virtual String polname(Int ipol);
00077 
00078 protected:
00079 
00080   // MS-specific loadIt method
00081   virtual void loadIt(vector<PMS::Axis>& loadAxes,
00082                       vector<PMS::DataColumn>& loadData,
00083                       PlotMSCacheThread* thread = NULL);
00084 
00085 private:
00086     
00087   // Forbid copy for now
00088   MSCache(const MSCache&);
00089 
00090   // Setup the VisIter
00091   void setUpVisIter(const String& msname,
00092                     const PlotMSSelection& selection,
00093                     Bool readonly=True,
00094                     Bool chanselect=True,
00095                     Bool corrselect=True);
00096 
00097   // Count the chunks required in the cache
00098   void countChunks(ROVisibilityIterator& vi,PlotMSCacheThread* thread);  // old
00099   void countChunks(ROVisibilityIterator& vi, Vector<Int>& nIterPerAve,  // supports time-averaging 
00100                    const PlotMSAveraging& averaging,PlotMSCacheThread* thread);
00101 
00102   // Trap attempt to use to much memory (too many points)
00103   void trapExcessVolume(map<PMS::Axis,Bool> pendingLoadAxes);
00104 
00105   // Loop over VisIter, filling the cache
00106   void loadChunks(ROVisibilityIterator& vi,
00107                   const vector<PMS::Axis> loadAxes,
00108                   const vector<PMS::DataColumn> loadData,
00109                   const PlotMSAveraging& averaging,
00110                   PlotMSCacheThread* thread);
00111   void loadChunks(ROVisibilityIterator& vi,
00112                   const PlotMSAveraging& averaging,
00113                   const Vector<Int>& nIterPerAve,
00114                   const vector<PMS::Axis> loadAxes,
00115                   const vector<PMS::DataColumn> loadData,
00116                   PlotMSCacheThread* thread);
00117 
00118   // Force read on vb for requested axes 
00119   //   (so pre-cache averaging treats all data it should)
00120   void forceVBread(VisBuffer& vb,
00121                    vector<PMS::Axis> loadAxes,
00122                    vector<PMS::DataColumn> loadData);
00123 
00124   // Tell time averager which data column to read
00125   void discernData(vector<PMS::Axis> loadAxes,
00126                    vector<PMS::DataColumn> loadData,
00127                    PlotMSVBAverager& vba);
00128 
00129   // Loads the specific axis/metadata into the cache using the given VisBuffer.
00130   void loadAxis(VisBuffer& vb, Int vbnum, PMS::Axis axis,
00131                 PMS::DataColumn data = PMS::DEFAULT_DATACOLUMN);
00132 
00133   // Set flags in the MS
00134   virtual void flagToDisk(const PlotMSFlagging& flagging,
00135                           Vector<Int>& chunks, 
00136                           Vector<Int>& relids,
00137                           Bool flag,
00138                           PlotMSIndexer* indexer);
00139   
00140 
00141   // A container for channel averaging bounds
00142   Vector<Matrix<Int> > chanAveBounds_p;
00143 
00144   // Provisional flagging helpers
00145   Vector<Int> nVBPerAve_;
00146 
00147   // VisIterator pointer
00148   ROVisIterator* rvi_p;
00149   VisIterator* wvi_p;
00150 
00151   // VisBufferUtil for freq/vel calculations
00152   VisBufferUtil vbu_;
00153 
00154   // Volume meter for volume calculation
00155   MSCacheVolMeter vm_;
00156 
00157     
00158 };
00159 typedef CountedPtr<MSCache> MSCachePtr;
00160 
00161 
00162 }
00163 
00164 #endif /* MSCACHE_H_ */