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