PlotMSIndexer.h

Go to the documentation of this file.
00001 //# PlotMSIndexer.h: Cache indexer 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 PLOTMSINDEXER_H_
00028 #define PLOTMSINDEXER_H_
00029 
00030 #include <casa/aips.h>
00031 #include <casa/Arrays.h>
00032 #include <casa/Containers/Block.h>
00033 #include <graphics/GenericPlotter/PlotData.h>
00034 
00035 #include <plotms/PlotMS/PlotMSConstants.h>
00036 #include <plotms/Data/PlotMSCacheBase.h>
00037 
00038 
00039 
00040 namespace casa {
00041 
00042 //# Forward declarations.
00043 class PlotMSApp;
00044 class PlotMSIndexer;  // needed for method pointer typedefs
00045 
00046 typedef Double(PlotMSCacheBase::*CacheMemPtr)(Int,Int);
00047 typedef    Int(PlotMSIndexer::*IndexerMethPtr)(Int,Int);
00048 typedef   void(PlotMSIndexer::*CollapseMethPtr)(Int,Array<Bool>&);
00049  
00050 class PlotMSIndexer : public PlotMaskedPointData, public PlotBinnedData {
00051 
00052 public:
00053 
00054   // Convenient access to class name.
00055   static const String CLASS_NAME;
00056   
00057   // A ctor that makes an empty Indexer (for plot initialization)
00058   PlotMSIndexer();
00059     
00060   // Constructor which takes parent PlotMSCache, x and y axes (non-iteration)
00061   PlotMSIndexer(PlotMSCacheBase* plotmscache, PMS::Axis xAxis, PMS::Axis yAxis, int index);
00062   // Constructor which supports iteration
00063   PlotMSIndexer(PlotMSCacheBase* plotmscache, PMS::Axis xAxis, PMS::Axis yAxis,
00064                 PMS::Axis iterAxis, Int iterValue, int index);
00065   
00066   // Destructor
00067   ~PlotMSIndexer();
00068 
00069   // Implemented PlotData methods.
00070   // <group>
00071   bool willDeleteData() const { return true; }
00072   void setDeleteData(bool del = true)   { (void)del; }
00073   bool isValid() const { return true;};
00074   // </group>
00075 
00076   // Implemented PlotPointData methods.
00077   // <group>
00078   unsigned int size() const;
00079   double xAt(unsigned int i) const;
00080   double yAt(unsigned int i) const;
00081   void xAndYAt(unsigned int index, double& x, double& y) const;
00082   bool minsMaxes(double& xMin, double& xMax, double& yMin, double& yMax);
00083   // </group>
00084     
00085   // Implemented PlotMaskedPointData methods.
00086   // <group>
00087   bool maskedAt(unsigned int index) const;
00088   void xyAndMaskAt(unsigned int index, double& x, double& y, bool& mask) const;
00089   // </group>
00090     
00091   // Unimplemented PlotMaskedPointData methods.
00092   // <group>
00093   unsigned int sizeMasked() const { return sizeMasked_; }
00094   unsigned int sizeUnmasked() const { return sizeUnMasked_; }
00095   bool maskedMinsMaxes(double& xMin, double& xMax, double& yMin,double& yMax);
00096   bool unmaskedMinsMaxes(double& xMin, double& xMax, double& yMin,double& yMax);
00097   // </group>
00098     
00099   // PlotBinnedData methods
00100   // <group>
00101   unsigned int numBins() const;
00102   unsigned int binAt(unsigned int i) const;
00103   bool isBinned() const;
00104   // </group>
00105 
00106   // Set up indexing for the plot 
00107   void setUpIndexing();
00108 
00109   // Set global min/max flag
00110   void setGlobalMinMax(Bool globalX=False,Bool globalY=False);
00111   bool isGlobalXRange() const;
00112   bool isGlobalYRange() const;
00113 
00114   // Report per-chunk point counters
00115   Vector<uInt> nPoints() { return nPoints_; };
00116   Vector<uInt> nCumulative() { return nCumulative_; };
00117 
00118   // Return if the indexer is ready (setUpPlot has been run)
00119   inline Bool indexerReady() const { return indexerReady_; };
00120 
00121   // Locate datum nearest to specified x,y
00122   Record getPointMetaData(Int i);
00123   Record locateInfo(const Vector<PlotRegion>& regions,
00124                     Bool showUnflagged, Bool showFlagged,
00125                     Bool selectAll = true);
00126   PlotLogMessage* locateRange(const Vector<PlotRegion>& regions,
00127                               Bool showUnflagged, Bool showFlagged);
00128   PlotLogMessage* flagRange(const PlotMSFlagging& flagging,
00129                             const Vector<PlotRegion>& regions, Bool flag = True);
00130 
00131 
00132   // Report meta info for current value of currChunk_/irel_
00133   void reportMeta(Double x, Double y, Bool masked, stringstream& ss);
00134 
00135   // Set flags in the cache
00136   void flagInCache(const PlotMSFlagging& flagging,Bool flag);
00137 
00138   // Iteration label
00139   String iterLabel();
00140   String iterValue();
00141   String fileLabel();
00142 
00143   // Access to raw min/max data (no auto-global)
00144   bool maskedMinsMaxesRaw(double& xMin, double& xMax, double& yMin,double& yMax);
00145   bool unmaskedMinsMaxesRaw(double& xMin, double& xMax, double& yMin,double& yMax);
00146 
00147 
00148   // Directly implemented index calculators
00149   //  (generic index methods point to one of these depending upon axis choice)
00150   Int getIndex0000(Int ch,Int irel) { return 0;  (void)irel; (void)ch; };
00151   Int getIndex1000(Int ch,Int irel) { return irel%icorrmax_(ch);};
00152   Int getIndex0100(Int ch,Int irel) { return (irel/nperchan_(ch))%ichanmax_(ch);};
00153   Int getIndex0010(Int ch,Int irel) { return (irel/nperbsln_(ch))%ibslnmax_(ch);};
00154   Int getIndex0110(Int ch,Int irel) { return (irel/nperchan_(ch))%ichanbslnmax_(ch);};
00155   Int getIndex1010(Int ch,Int irel) { return (irel/nperbsln_(ch))*nperchan_(ch) + irel%nperchan_(ch);};
00156   Int getIndex1110(Int ch,Int irel) { return irel%idatamax_(ch);};
00157   Int getIndex0001(Int ch,Int irel) { return (irel/nperant_(ch))%iantmax_(ch);};
00158 
00159 
00160   // 
00161   bool colorize(bool doColorize, PMS::Axis colorizeAxis);
00162 
00163 
00164   
00165 
00166 private:
00167     
00168   // Forbid copy for now
00169   PlotMSIndexer(const PlotMSIndexer& mc);
00170 
00171   void setMethod(CacheMemPtr& getmethod, PMS::Axis axis);
00172   void setIndexer(IndexerMethPtr& indexmethod, PMS::Axis axis);
00173   //  void setCollapser(CollapseMethPtr& collmethod, PMS::Axis axis);
00174 
00175   // Generate collapsed versions of the plmask 
00176   /* not needed?  (gmoellen, 2011Mar15)
00177   void collapseMask0000(Int ch,Array<Bool>& collmask);
00178   void collapseMask1000(Int ch,Array<Bool>& collmask);
00179   void collapseMask0100(Int ch,Array<Bool>& collmask);
00180   void collapseMask0010(Int ch,Array<Bool>& collmask);
00181   void collapseMask0110(Int ch,Array<Bool>& collmask);
00182   void collapseMask1010(Int ch,Array<Bool>& collmask);
00183   void collapseMask1110(Int ch,Array<Bool>& collmask);
00184   void collapseMask0001(Int ch,Array<Bool>& collmask);
00185   */
00186 
00187   // Report the number of chunks
00188   Int nChunk() const { return (plotmscache_ ? plotmscache_->nChunk() : 0); };
00189 
00190   // Report the reference time for this cache (in seconds)
00191   inline Double refTime() { return plotmscache_->refTime(); };
00192 
00193   // Set currChunk_ according to a supplied index
00194   void setChunk(uInt i) const;
00195 
00196   // Computes the X and Y limits for the currently set axes.  In the future we
00197   // may want to cache ALL ranges for all loaded values to avoid recomputation.
00198   void computeRanges();
00199 
00200   // Compute baseline's length in meters between ant1 and ant2
00201   Double computeBaselineLength(Int ant1, Int ant2);
00202 
00203   // Convenience methods that call log() with the given method name and the
00204   // appropriate event type.
00205   // <group>
00206   void logInfo(const String& method, const String& message) {
00207       log(method, message, PlotLogger::MSG_INFO); }
00208   void logDebug(const String& method, const String& message) {
00209       log(method, message, PlotLogger::MSG_DEBUG); }
00210   void logWarn(const String& method, const String& message) {
00211       log(method, message, PlotLogger::MSG_WARN); }
00212   void logError(const String& method, const String& message) {
00213       log(method, message, PlotLogger::MSG_ERROR); }
00214   // </group>
00215   
00216   // Logs the given message from the given method name as the given event type
00217   // (see PlotLogger).
00218   void log(const String& method, const String& message, int eventType);
00219 
00220 
00221 
00222   // Private data
00223    
00224   // Parent plotms.
00225   PlotMSCacheBase* plotmscache_;
00226 
00227   // Pointers to methods for axis flexibility
00228   CacheMemPtr getXFromCache_, getYFromCache_,getColFromCache_;
00229   IndexerMethPtr XIndexer_, YIndexer_, ColIndexer_;
00230   //  CollapseMethPtr collapseXMask_, collapseYMask_;
00231 
00232   // The in-focus chunk and relative index offset
00233   mutable Int currChunk_, irel_;
00234   mutable uInt lasti_;
00235 
00236   // The number of points per chunk
00237   Vector<uInt> nPoints_;
00238 
00239   // The cumulative running total of points
00240   Vector<uInt> nCumulative_;
00241 
00242   // Segment point-counting Vectors
00243   Int nSegment_;
00244   mutable Int currSeg_;
00245   Vector<uInt> nSegPoints_,nCumulPoints_,cacheChunk_,cacheOffset_;
00246   
00247   // Current setup/state.
00248   PMS::Axis currentX_, currentY_;
00249   bool indexerReady_;
00250 
00251   // Indexing parameters
00252   Vector<Int> icorrmax_, ichanmax_, ibslnmax_, idatamax_;
00253   Vector<Int> nperchan_, nperbsln_, nperant_;
00254   Vector<Int> ichanbslnmax_;
00255   Vector<Int> iantmax_;
00256 
00257   // Nominal axes limits
00258   Double xmin_,ymin_,xflmin_,yflmin_,xmax_,ymax_,xflmax_,yflmax_;
00259   Int sizeMasked_, sizeUnMasked_;
00260   Bool globalXMinMax_,globalYMinMax_;
00261 
00262   // Iteration
00263   // <group>
00264   Bool iterate_;
00265   PMS::Axis iterAxis_;
00266   Int iterValue_;
00267   // </group>
00268 
00269   // Colorization
00270   // <group>
00271   bool itsColorize_;
00272   PMS::Axis itsColorizeAxis_;
00273   // </group>
00274   
00275   // Cope with const-ness in the get methods
00276   PlotMSIndexer* self;
00277 
00278 
00279   int dataIndex;
00280 
00281 };
00282 
00283 typedef CountedPtr<PlotMSIndexer> PlotMSIndexerPtr;
00284 
00285 }
00286 
00287 #endif /* PLOTMSCACHEINDER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1