casa  $Rev:20696$
PlotMSCacheIndexer.h
Go to the documentation of this file.
00001 //# PlotMSCache.h: 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 PLOTMSCACHEINDEXER_H_
00028 #define PLOTMSCACHEINDEXER_H_
00029 
00030 #include <plotms/PlotMS/PlotMSConstants.h>
00031 
00032 #include <plotms/Data/PlotMSCache.h>
00033 #include <casa/aips.h>
00034 #include <casa/Arrays.h>
00035 #include <casa/Containers/Block.h>
00036 
00037 namespace casa {
00038 
00039 //# Forward declarations.
00040 class PlotMSApp;
00041 class PlotMSCacheIndexer;  // needed for method pointer typedefs
00042 
00043 typedef Double(PlotMSCache::*PlotMSCacheMemPtr)(Int,Int);
00044 typedef    Int(PlotMSCacheIndexer::*IndexerMethodPtr)(Int,Int);
00045 typedef   void(PlotMSCacheIndexer::*CollapseMethodPtr)(Int,Array<Bool>&);
00046  
00047 class PlotMSCacheIndexer {
00048 
00049 public:
00050     // Convenient access to class name.
00051     static const String CLASS_NAME;
00052     
00053   // Constructor which takes parent PlotMS.
00054   PlotMSCacheIndexer(PlotMSCache* plotmscache);
00055   
00056   // Destructor
00057   ~PlotMSCacheIndexer();
00058 
00059   // Set up indexing for the plot 
00060   void setUpPlot(PMS::Axis xAxis, PMS::Axis yAxis);
00061 
00062   // Report the total number of points currently arranged for plotting
00063   //  (TBD: this is incorrect unless ALL cache spaces are full!!)
00064   Int nPoints() const { return (nPoints_.nelements() > 0) ? nPoints_(nChunk()-1) : 0; };
00065 
00066   // CAche shapes:
00067   Matrix<Int>& chunkShapes() { return plotmscache_->chunkShapes(); };
00068 
00069   // Return if the indexer is ready (setUpPlot has been run)
00070   inline Bool indexerReady() const { return indexerReady_; };
00071 
00072   // Get X and Y limits 
00073   // TBD: flagged/unflagged
00074   void getRanges(Double& minX, Double& maxX, Double& minY, Double& maxY);
00075 
00076   // Get single values for x-y plotting by global index
00077   Double getX(Int i);
00078   Double getY(Int i);
00079   void getXY(Int i, Double& x, Double& y);
00080   Bool getFlagMask(Int i);
00081 
00082   // Get single values by chunk and relative index  
00083   //  (implicitly requires that get?FromCache_ method pointers are set)
00084   Double getX(Int ch,Int irel) { return ((*plotmscache_).*getXFromCache_)(ch,irel); };
00085   Double getY(Int ch,Int irel) { return ((*plotmscache_).*getYFromCache_)(ch,irel); };
00086 
00087   // Locate datum nearest to specified x,y (amp vs freq hardwired versions)
00088   PlotLogMessage* locateRange(const Vector<PlotRegion>& regions);
00089   PlotLogMessage* flagRange(const PlotMSFlagging& flagging,
00090                             const Vector<PlotRegion>& regions, Bool flag = True);
00091 
00092 
00093   // Report meta info for current value of currChunk_/irel_
00094   void reportMeta(Double x, Double y,stringstream& ss);
00095 
00096   // Set flags in the cache
00097   void flagInCache(const PlotMSFlagging& flagging,Bool flag);
00098 
00099   // Sets the plot mask for a single chunk
00100   void setPlotMask(Int chunk);
00101 
00102   // Clean up the plot mask
00103   void deleteMask();
00104 
00105   // Set flags in the MS
00106   void flagInVisSet(const PlotMSFlagging& flagging,Vector<Int>& chunks, Vector<Int>& relids,Bool flag);
00107 
00108 
00109 private:
00110     
00111   // Forbid copy for now
00112   PlotMSCacheIndexer(const PlotMSCacheIndexer& mc);
00113 
00114   void getAxesMask(PMS::Axis axis,Vector<Bool>& axismask);
00115 
00116   void setMethod(PlotMSCacheMemPtr& getmethod, PMS::Axis axis);
00117   void setIndexer(IndexerMethodPtr& indexmethod, PMS::Axis axis);
00118   void setCollapser(CollapseMethodPtr& collmethod, PMS::Axis axis);
00119 
00120   // Directly implemented index calculators
00121   //  (generic index methods point to one of these depending upon axis choice)
00122   Int getIndex0000(Int ch,Int irel) { return 0;  (void)irel; (void)ch; };
00123   Int getIndex1000(Int ch,Int irel) { return irel%icorrmax_(ch);  (void)irel; };
00124   Int getIndex0100(Int ch,Int irel) { return (irel/nperchan_(ch))%ichanmax_(ch);  (void)irel; };
00125   Int getIndex0010(Int ch,Int irel) { return (irel/nperbsln_(ch))%ibslnmax_(ch);  (void)irel; };
00126   Int getIndex0110(Int ch,Int irel) { return (irel/nperchan_(ch))%ichanbslnmax_(ch);  (void)irel; };
00127   Int getIndex1110(Int ch,Int irel) { return irel%idatamax_(ch);  (void)irel; };
00128   Int getIndex0001(Int ch,Int irel) { return (irel/nperant_(ch))%iantmax_(ch);  (void)irel; };
00129   //  TBD:  corr/bsln-dep (e.g., WEIGHT)
00130   //  inline Int getIndex1010(Int ch,Int irel) { return 
00131   
00132   // Generate collapsed versions of the plmask 
00133   void collapseMask0000(Int ch,Array<Bool>& collmask);
00134   void collapseMask1000(Int ch,Array<Bool>& collmask);
00135   void collapseMask0100(Int ch,Array<Bool>& collmask);
00136   void collapseMask0010(Int ch,Array<Bool>& collmask);
00137   void collapseMask0110(Int ch,Array<Bool>& collmask);
00138   void collapseMask1110(Int ch,Array<Bool>& collmask);
00139   void collapseMask0001(Int ch,Array<Bool>& collmask);
00140   //  void collapseMask1010(Int ch,Array<Bool>& collmask);
00141 
00142   // Report the number of chunks
00143   Int nChunk() const { return plotmscache_->nChunk(); };
00144 
00145   // Report the reference time for this cache (in seconds)
00146   inline Double refTime() { return plotmscache_->refTime(); };
00147 
00148   // Set currChunk_ according to a supplied index
00149   void setChunk(Int i);
00150 
00151   // Computes the X and Y limits for the currently set axes.  In the future we
00152   // may want to cache ALL ranges for all loaded values to avoid recomputation.
00153   void computeRanges();
00154   
00155   // Returns the number of points loaded for the given axis or 0 if not loaded.
00156   unsigned int nPointsForAxis(PMS::Axis axis) const;
00157   
00158   // Convenience methods that call log() with the given method name and the
00159   // appropriate event type.
00160   // <group>
00161   void logInfo(const String& method, const String& message) {
00162       log(method, message, PlotLogger::MSG_INFO); }
00163   void logDebug(const String& method, const String& message) {
00164       log(method, message, PlotLogger::MSG_DEBUG); }
00165   void logWarn(const String& method, const String& message) {
00166       log(method, message, PlotLogger::MSG_WARN); }
00167   void logError(const String& method, const String& message) {
00168       log(method, message, PlotLogger::MSG_ERROR); }
00169   // </group>
00170   
00171   // Logs the given message from the given method name as the given event type
00172   // (see PlotLogger).
00173   void log(const String& method, const String& message, int eventType);
00174 
00175   // Private data
00176    
00177   // Parent plotms.
00178   PlotMSCache* plotmscache_;
00179 
00180   // Pointers to methods for axis flexibility
00181   PlotMSCacheMemPtr getXFromCache_, getYFromCache_;
00182   IndexerMethodPtr XIndexer_, YIndexer_;
00183   CollapseMethodPtr collapseXMask_, collapseYMask_;
00184 
00185   // The in-focus chunk and relative index offset
00186   Int currChunk_, irel_, lasti_;
00187 
00188   // The cumulative running total of points
00189   Vector<Int> nPoints_;
00190 
00191   // Current setup/state.
00192   PMS::Axis currentX_, currentY_;
00193   bool indexerReady_;
00194 
00195   // Axes mask
00196   Vector<Bool> netAxesMask_;
00197 
00198   // Indexing parameters
00199   Vector<Int> icorrmax_, ichanmax_, ibslnmax_, idatamax_;
00200   Vector<Int> nperchan_, nperbsln_, nperant_;
00201   Vector<Int> ichanbslnmax_;
00202   Vector<Int> iantmax_;
00203 
00204   // collapsed flag mask for plotting
00205   PtrBlock<Array<Bool>*> plmask_;
00206 
00207   // Nominal axes limits
00208   Double xmin_,ymin_,xflmin_,yflmin_,xmax_,ymax_,xflmax_,yflmax_;
00209 
00210 
00211 };
00212 
00213 typedef CountedPtr<PlotMSCacheIndexer> PlotMSCacheIndexerPtr;
00214 
00215 }
00216 
00217 #endif /* PLOTMSCACHEINDER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines