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/Threads/PlotMSCacheThread.qo.h>
00036 #include <plotms/Threads/ThreadCommunication.h>
00037 #include <plotms/Data/PlotMSVBAverager.h>
00038 #include <plotms/Data/MSCacheVolMeter.h>
00039 
00040 #include <casa/aips.h>
00041 #include <casa/Arrays.h>
00042 #include <casa/Containers/Block.h>
00043 #include <msvis/MSVis/VisibilityIterator2.h>
00044 #include <msvis/MSVis/VisBuffer2.h>
00045 #include <msvis/MSVis/VisBufferUtil.h>
00046 #include <msvis/MSVis/ViFrequencySelection.h>
00047 
00048 namespace casa {
00049 
00050 //# Forward declarations.
00051 class PlotMSApp;
00052 class PlotMSIndexer;
00053 
00054 class MSCache : public PlotMSCacheBase {
00055     
00056   // Friend class declarations.
00057   friend class PlotMSIndexer;
00058 
00059 public:    
00060   
00061   // Constructor which takes parent PlotMS.
00062   MSCache(PlotMSApp* parent);
00063   
00064   // Destructor
00065   virtual ~MSCache();
00066 
00067   // Identify myself
00068   PlotMSCacheBase::Type cacheType() const { return PlotMSCacheBase::MS; };
00069 
00070   // ...not yet MS-specific... (or ever?)
00071   // Set up indexing for the plot
00072   //  void setUpIndexer(PMS::Axis iteraxis=PMS::SCAN,
00073   //                Bool globalXRange=False, Bool globalYRange=False);
00074 
00075   void setFilename(String filename) { filename_ = filename; };
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**/ThreadCommunication* thread = NULL);
00084 
00085   //Returns whether or not the ephemeris data has been
00086   //attached to a field - radial velocity and rho.
00087   virtual bool isEphemeris();
00088 private:
00089     
00090   // Forbid copy for now
00091   MSCache(const MSCache&);
00092 
00093   // Set up
00094   String getDataColumn(vector<PMS::Axis>& loadAxes, 
00095                        vector<PMS::DataColumn>& loadData);
00096   PMS::DataColumn checkReqDataColumn(PMS::DataColumn reqDataCol);
00097   String checkLoadedAxesDatacol();
00098   String normalizeColumnName(String plotmscol);
00099   void getNamesFromMS(MeasurementSet& ms);
00100   void logChansForSpws(MeasurementSet& ms, Int chanVal);
00101   void setUpVisIter(PlotMSSelection& selection,
00102                     PlotMSCalibration& calibration,
00103                     String dataColumn,
00104             Bool interactive=False,
00105                     Bool estimateMemory=False,
00106             ThreadCommunication* thread=NULL);
00107   vi::VisibilityIterator2* setUpVisIter(MeasurementSet& selectedMS,
00108         Vector<Vector<Slice> > chansel, Vector<Vector<Slice> > corrsel);
00109   void setUpFrequencySelectionChannels(vi::FrequencySelectionUsingChannels fs,
00110         Vector<Vector<Slice> > chansel);
00111 
00112   // clean up
00113   void deleteVi();
00114   void deleteVm();
00115   void loadError(String mesg);
00116 
00117   // Estimate cache size for averaging
00118   bool countChunks(vi::VisibilityIterator2& vi, Vector<Int>& nIterPerAve, 
00119                    /*PlotMSCacheThread**/ThreadCommunication* thread);
00120   void updateEstimateProgress(ThreadCommunication* thread);
00121 
00122   // Trap attempt to use to much memory (too many points)
00123   void trapExcessVolume(map<PMS::Axis,Bool> pendingLoadAxes);
00124   std::vector<IPosition> visBufferShapes_;
00125 
00126   // Loop over VisIter, filling the cache
00127   void loadChunks(vi::VisibilityIterator2& vi,
00128                   const vector<PMS::Axis> loadAxes,
00129                   const vector<PMS::DataColumn> loadData,
00130                   /*PlotMSCacheThread**/ThreadCommunication* thread);
00131   void loadChunks(vi::VisibilityIterator2& vi,
00132                   const PlotMSAveraging& averaging,
00133                   const Vector<Int>& nIterPerAve,
00134                   const vector<PMS::Axis> loadAxes,
00135                   const vector<PMS::DataColumn> loadData,
00136                   /*PlotMSCacheThread**/ThreadCommunication* thread);
00137   void updateProgress(ThreadCommunication* thread, Int chunk);
00138 
00139   // Force read on vb for requested axes 
00140   //   (so pre-cache averaging treats all data it should)
00141   void forceVBread(vi::VisBuffer2* vb,
00142                    vector<PMS::Axis> loadAxes,
00143                    vector<PMS::DataColumn> loadData);
00144 
00145   // Tell time averager which data column to read
00146   void discernData(vector<PMS::Axis> loadAxes,
00147                    vector<PMS::DataColumn> loadData,
00148                    PlotMSVBAverager& vba);
00149 
00150   // Loads the specific axis/metadata into the cache using the given VisBuffer.
00151   void loadAxis(vi::VisBuffer2* vb, Int vbnum, PMS::Axis axis,
00152                 PMS::DataColumn data = PMS::DEFAULT_DATACOLUMN);
00153 
00154   // Set flags in the MS
00155   virtual void flagToDisk(const PlotMSFlagging& flagging,
00156                           Vector<Int>& chunks, 
00157                           Vector<Int>& relids,
00158                           Bool setFlag,
00159                           PlotMSIndexer* indexer, int dataIndex);
00160 
00161   // Datacolumn to use (requested or "adjusted")
00162   String dataColumn_;
00163 
00164   // Create map of intent names to "intent ids" 
00165   // since state ids can duplicate intents.
00166   // Then use map to assign intent ids to replace state ids
00167   // (stateId -> intent string -> intentId)
00168   map<String, Int> intentIds_; 
00169   void mapIntentNamesToIds();   // create map
00170   // Use map to assign intent ids
00171   Vector<Int> assignIntentIds(Vector<Int>& stateIds);
00172 
00173   // Provisional flagging helpers
00174   Vector<Int> nVBPerAve_;
00175 
00176   // VisIterator pointer
00177   vi::VisibilityIterator2* vi_p;
00178 
00179   // Volume meter for volume calculation
00180   MSCacheVolMeter* vm_;
00181 
00182   Vector<Double> calcVelocity(vi::VisBuffer2* vb); 
00183 
00184   // For averaging done by PlotMSVBAverager;
00185   // Some axes need to come from VB2 attached to VI2
00186   bool useAveragedVisBuffer(PMS::Axis axis);
00187 
00188   bool ephemerisAvailable;
00189 };
00190 typedef CountedPtr<MSCache> MSCachePtr;
00191 
00192 
00193 }
00194 
00195 #endif /* MSCACHE_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1