00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef PLOTMSCACHEBASE_H_
00028 #define PLOTMSCACHEBASE_H_
00029
00030 #include <plotms/PlotMS/PlotMSAveraging.h>
00031 #include <plotms/PlotMS/PlotMSConstants.h>
00032 #include <plotms/PlotMS/PlotMSFlagging.h>
00033 #include <plotms/PlotMS/PlotMSTransformations.h>
00034 #include <plotms/PlotMS/PlotMSCalibration.h>
00035
00036 #include <casa/aips.h>
00037 #include <casa/Arrays.h>
00038 #include <casa/Containers/Block.h>
00039 #include <measures/Measures/MFrequency.h>
00040
00041 #include <QVector>
00042
00043 namespace casa {
00044
00045
00046 class PlotMSApp;
00047 class PlotMSIndexer;
00048 class ThreadCommunication;
00049
00050 class PlotMSCacheBase {
00051
00052
00053 friend class PlotMSIndexer;
00054
00055
00056
00057 public:
00058
00059
00060
00061 enum Type {MS, CAL};
00062
00063 static const unsigned int THREAD_SEGMENT;
00064 static const PMS::Axis METADATA[];
00065 static const unsigned int N_METADATA;
00066
00067 static bool axisIsMetaData(PMS::Axis axis);
00068
00069
00070
00071 PlotMSCacheBase(PlotMSApp* parent);
00072
00073
00074 virtual ~PlotMSCacheBase();
00075
00076
00077
00078 virtual PlotMSCacheBase::Type cacheType() const = 0;
00079
00080
00081 virtual String polname(Int ipol)=0;
00082
00083
00084 virtual void setFilename(String filename) = 0;
00085 String calType() const { return calType_; };
00086 bool polnRatio() const { return polnRatio_; };
00087
00088
00089 int nmetadata() const {return N_METADATA;};
00090 PMS::Axis metadata(int i) {return METADATA[i];};
00091
00092
00093
00094 Int nIter( int dataIndex ) const;
00095
00096 PlotMSIndexer& indexer( int dataIndex, uInt i) {
00097 return (*indexer_[dataIndex][i]);
00098 };
00099 PlotMSIndexer& indexer0() {
00100 return *indexer0_;
00101 };
00102 void resizeIndexer( int size );
00103 int getDataCount() const {
00104 return currentX_.size();
00105 }
00106
00107 PMS::Axis getIterAxis() const;
00108
00109
00110 Int nChunk() const { return nChunk_; };
00111
00112
00113 bool cacheReady() const { return dataLoaded_; }
00114
00115
00116 bool wasCanceled() const { return userCanceled_; }
00117
00118
00119 inline Matrix<Int>& chunkShapes() {return chshapes_;};
00120
00121
00122
00123 inline Bool goodChunk(Int ichunk) {return goodChunk_(ichunk); };
00124
00125
00126
00127 inline bool hasReferenceValue(PMS::Axis axis) { return (axis==PMS::TIME && cacheReady()); };
00128 inline double referenceValue(PMS::Axis axis) { return (hasReferenceValue(axis) ? refTime() : 0.0); };
00129
00130
00131 inline Double refTime() const { return refTime_p; };
00132
00133
00134 inline MFrequency::Types getFreqFrame() const { return freqFrame_; };
00135
00136
00137
00138
00139
00140 std::vector<pair<PMS::Axis, unsigned int> > loadedAxes() const;
00141
00142
00143 PlotMSAveraging& averaging() { return averaging_; }
00144
00145
00146 PlotMSTransformations& transformations() { return transformations_; }
00147
00148
00149
00150
00151
00152
00153
00154
00155 virtual void load(const std::vector<PMS::Axis>& axes,
00156 const std::vector<PMS::DataColumn>& data,
00157 const String& filename,
00158 const PlotMSSelection& selection,
00159 const PlotMSAveraging& averaging,
00160 const PlotMSTransformations& transformations,
00161 const PlotMSCalibration& calibration,
00162 ThreadCommunication* thread = NULL);
00163
00164
00165
00166 void clear();
00167 void clearRanges();
00168
00169
00170 void release(const std::vector<PMS::Axis>& axes);
00171
00172
00173 bool isIndexerInitialized( PMS::Axis iteraxis, Bool globalXRange,
00174 Bool globalYRange, int dataIndex ) const;
00175 void setUpIndexer(PMS::Axis iteraxis=PMS::SCAN,
00176 Bool globalXRange=False, Bool globalYRange=False, int dataIndex = 0);
00177
00178
00179 inline Array<Bool>& flag(Int chunk) { return *flag_[chunk]; };
00180 inline Vector<Bool>& flagrow(Int chunk) { return *flagrow_[chunk]; };
00181
00182
00183 inline Double getScan(Int chnk,Int irel) { return scan_(chnk); (void)irel; };
00184 inline Double getField(Int chnk,Int irel) { return field_(chnk); (void)irel; };
00185 inline Double getTime(Int chnk,Int irel) { return time_(chnk); (void)irel; };
00186 inline Double getTimeIntr(Int chnk,Int irel) { return timeIntr_(chnk); (void)irel; };
00187 inline Double getSpw(Int chnk,Int irel) { return spw_(chnk); (void)irel; };
00188 inline Double getFreq(Int chnk,Int irel) { return *(freq_[chnk]->data()+irel); };
00189 inline Double getVel(Int chnk,Int irel) { return *(vel_[chnk]->data()+irel); };
00190 inline Double getChan(Int chnk,Int irel) { return *(chan_[chnk]->data()+irel); };
00191 inline Double getCorr(Int chnk,Int irel) { return *(corr_[chnk]->data()+irel); };
00192 inline Double getAnt1(Int chnk,Int irel) { return *(antenna1_[chnk]->data()+irel); };
00193 inline Double getAnt2(Int chnk,Int irel) { return *(antenna2_[chnk]->data()+irel); };
00194 inline Double getBsln(Int chnk,Int irel) { return *(baseline_[chnk]->data()+irel); };
00195 inline Double getRow(Int chnk,Int irel) { return *(row_[chnk]->data()+irel); };
00196 inline Double getObsid(Int chnk,Int irel) { return *(obsid_[chnk]->data()+irel); };
00197 inline Double getIntent(Int chnk,Int irel) { return *(intent_[chnk]->data()+irel); };
00198 inline Double getFeed1(Int chnk,Int irel) { return *(feed1_[chnk]->data()+irel); };
00199 inline Double getFeed2(Int chnk,Int irel) { return *(feed2_[chnk]->data()+irel); };
00200
00201 inline Double getAmp(Int chnk,Int irel) { return *(amp_[chnk]->data()+irel); };
00202 inline Double getPha(Int chnk,Int irel) { return *(pha_[chnk]->data()+irel); };
00203 inline Double getReal(Int chnk,Int irel) { return *(real_[chnk]->data()+irel); };
00204 inline Double getImag(Int chnk,Int irel) { return *(imag_[chnk]->data()+irel); };
00205 inline Double getFlag(Int chnk,Int irel) { return *(flag_[chnk]->data()+irel); };
00206 inline Double getFlagRow(Int chnk,Int irel) { return *(flagrow_[chnk]->data()+irel); };
00207
00208 inline Double getWt(Int chnk,Int irel) { return *(wt_[chnk]->data()+irel); };
00209 inline Double getWtxAmp(Int chnk, Int irel) { return *(wtxamp_[chnk]->data()+irel); }
00210 inline Double getWtSp(Int chnk,Int irel) { return *(wtsp_[chnk]->data()+irel); };
00211 inline Double getSigma(Int chnk,Int irel) { return *(sigma_[chnk]->data()+irel); };
00212 inline Double getSigmaSp(Int chnk,Int irel) { return *(sigmasp_[chnk]->data()+irel); };
00213
00214 inline Double getUVDist(Int chnk,Int irel) { return *(uvdist_[chnk]->data()+irel); };
00215 inline Double getUVDistL(Int chnk,Int irel) { return *(uvdistL_[chnk]->data()+irel); };
00216 inline Double getU(Int chnk,Int irel) { return *(u_[chnk]->data()+irel); };
00217 inline Double getV(Int chnk,Int irel) { return *(v_[chnk]->data()+irel); };
00218 inline Double getW(Int chnk,Int irel) { return *(w_[chnk]->data()+irel); };
00219 inline Double getUwave(Int chnk,Int irel) { return *(uwave_[chnk]->data()+irel); };
00220 inline Double getVwave(Int chnk,Int irel) { return *(vwave_[chnk]->data()+irel); };
00221 inline Double getWwave(Int chnk,Int irel) { return *(wwave_[chnk]->data()+irel); };
00222
00223
00224 inline Double getAz0(Int chnk,Int irel) { return az0_(chnk); (void)irel; };
00225 inline Double getEl0(Int chnk,Int irel) { return el0_(chnk); (void)irel; };
00226 inline Double getRadialVelocity0(Int chnk, Int irel){ return radialVelocity_(chnk); (void)irel;};
00227 inline Double getRHO0(Int chnk, Int irel){return rho_(chnk); (void)irel; };
00228 inline Double getHA0(Int chnk,Int irel) { return ha0_(chnk); (void)irel; };
00229 inline Double getPA0(Int chnk,Int irel) { return pa0_(chnk); (void)irel; };
00230
00231
00232 inline Double getAntenna(Int chnk,Int irel) { return *(antenna_[chnk]->data()+irel); };
00233 inline Double getAz(Int chnk,Int irel) { return *(az_[chnk]->data()+irel); };
00234 inline Double getEl(Int chnk,Int irel) { return *(el_[chnk]->data()+irel); };
00235 inline Double getParAng(Int chnk,Int irel) { return *(parang_[chnk]->data()+irel); };
00236
00237
00238 inline Double getPar(Int chnk,Int irel) { return *(par_[chnk]->data()+irel); };
00239 inline Double getSnr(Int chnk,Int irel) { return *(snr_[chnk]->data()+irel); };
00240
00241
00242 inline Vector<Int> getChansPerBin(Int chnk,Int irel) { return (*chansPerBin_[chnk])[irel]; };
00243
00244 Record locateInfo(int plotIterIndex, const Vector<PlotRegion>& regions,
00245 bool showUnflagged, bool showFlagged, bool selectAll );
00246
00247 PlotLogMessage* locateRange( int plotIterIndex, const Vector<PlotRegion> & regions,
00248 bool showUnflagged, bool showFlagged);
00249
00250 PlotLogMessage* flagRange( int plotIterIndex, casa::PlotMSFlagging& flagging,
00251 const Vector<PlotRegion>& regions, bool showFlagged);
00252
00253
00254 String getTimeBounds( int iterValue );
00255
00256 pair<Double,Double> getTimeBounds() const;
00257
00258 pair<Double,Double> getXAxisBounds() const;
00259 pair<Double,Double> getYAxisBounds() const;
00260
00261 protected:
00262
00263
00264 PlotMSCacheBase(const PlotMSCacheBase&);
00265
00266
00267 void increaseChunks(Int nc=0);
00268
00269
00270
00271 virtual void loadIt(std::vector<PMS::Axis>& loadAxes,
00272 std::vector<PMS::DataColumn>& loadData,
00273 ThreadCommunication* thread = NULL)=0;
00274
00275 virtual void flagToDisk(const PlotMSFlagging& flagging,
00276 Vector<Int>& chunks,
00277 Vector<Int>& relids,
00278 Bool flag,
00279 PlotMSIndexer* indexer, int dataIndex)=0;
00280
00281
00282 void deleteCache();
00283 void deleteIndexer();
00284
00285
00286
00287 virtual bool isEphemeris() {return false;};
00288 bool isEphemerisAxis( PMS::Axis axis ) const;
00289
00290 void setAxesMask(PMS::Axis axis,Vector<Bool>& axismask);
00291
00292
00293 Vector<Bool> netAxesMask(PMS::Axis xaxis,PMS::Axis yaxis);
00294
00295
00296 void setPlotMask( Int dataIndex);
00297 void setPlotMask(Int dataIndex, Int chunk);
00298
00299
00300 void deletePlotMask();
00301
00302
00303 unsigned int nPointsForAxis(PMS::Axis axis) const;
00304
00305
00306
00307
00308 void logInfo(const String& method, const String& message) {
00309 log(method, message, PlotLogger::MSG_INFO); }
00310 void logDebug(const String& method, const String& message) {
00311 log(method, message, PlotLogger::MSG_DEBUG); }
00312 void logWarn(const String& method, const String& message) {
00313 log(method, message, PlotLogger::MSG_WARN); }
00314 void logError(const String& method, const String& message) {
00315 log(method, message, PlotLogger::MSG_ERROR); }
00316
00317 void logLoad(const String& message) {
00318 log(PMS::LOG_ORIGIN_LOAD_CACHE, message, PMS::LOG_EVENT_LOAD_CACHE); }
00319 void logFlag(const String& message) {
00320 log(PMS::LOG_ORIGIN_FLAG, message, PMS::LOG_EVENT_FLAG); }
00321
00322
00323
00324
00325 void log(const String& method, const String& message, int eventType);
00326
00327
00328 int findColorIndex( int chunk, bool initialize );
00329
00330
00331
00332
00333
00334
00335
00336 PlotMSApp* plotms_;
00337
00338
00339 PlotMSIndexer* indexer0_;
00340
00341
00342 std::vector<PtrBlock<PlotMSIndexer*> > indexer_;
00343
00344
00345 Int nChunk_;
00346
00347
00348 Double refTime_p;
00349
00350
00351 Int nAnt_;
00352
00353
00354
00355 MFrequency::Types freqFrame_;
00356
00357
00358 Double minX_,maxX_,minY_,maxY_;
00359
00360
00361 Matrix<Int> chshapes_;
00362 Vector<Bool> goodChunk_;
00363 Vector<Double> time_, timeIntr_;
00364 Vector<Int> field_, spw_, scan_;
00365 PtrBlock<Vector<uInt>*> row_;
00366 PtrBlock<Vector<Int>*> antenna1_, antenna2_, baseline_;
00367 PtrBlock<Vector<Double>*> uvdist_, u_, v_, w_;
00368 PtrBlock<Matrix<Double>*> uvdistL_, uwave_, vwave_, wwave_;
00369 PtrBlock<Vector<Double>*> freq_, vel_;
00370 PtrBlock<Vector<Int>*> chan_;
00371 PtrBlock<Array<Int>*> chansPerBin_;
00372 PtrBlock<Vector<Int>*> corr_;
00373 PtrBlock<Vector<Int>*> obsid_;
00374 PtrBlock<Vector<Int>*> intent_;
00375 PtrBlock<Vector<Int>*> feed1_, feed2_;
00376
00377
00378 PtrBlock<Vector<Float>*> pa_;
00379
00380
00381 PtrBlock<Array<Float>*> amp_, pha_, real_, imag_, wtxamp_;
00382 PtrBlock<Array<Bool>*> flag_;
00383 PtrBlock<Vector<Bool>*> flagrow_;
00384
00385 PtrBlock<Array<Float>*> wt_,wtsp_;
00386 PtrBlock<Array<Float>*> sigma_,sigmasp_;
00387
00388 PtrBlock<Vector<Float>*> parang_;
00389 PtrBlock<Vector<Int>*> antenna_;
00390 PtrBlock<Vector<Double>*> az_,el_;
00391
00392
00393 Vector<Double> radialVelocity_, rho_;
00394 Vector<Double> az0_,el0_,ha0_,pa0_;
00395
00396 PtrBlock<Array<Float>*> par_, snr_, tsys_;
00397
00398
00399 bool dataLoaded_;
00400 bool userCanceled_;
00401 std::vector<PMS::Axis> currentX_;
00402 std::vector<PMS::Axis> currentY_;
00403 map<PMS::Axis, bool> loadedAxes_;
00404 map<PMS::Axis, PMS::DataColumn> loadedAxesData_;
00405 map<PMS::Axis, bool> pendingLoadAxes_;
00406
00407
00408 Double xminG_,yminG_,xflminG_,yflminG_,xmaxG_,ymaxG_,xflmaxG_,yflmaxG_;
00409
00410
00411 String filename_;
00412 PlotMSSelection selection_;
00413 PlotMSAveraging averaging_;
00414 PlotMSTransformations transformations_;
00415 PlotMSCalibration calibration_;
00416
00417
00418 std::vector<Vector<Bool> > netAxesMask_;
00419
00420
00421 std::vector<PtrBlock<Array<Bool>* > > plmask_;
00422
00423
00424 Vector<String> antnames_;
00425 Vector<String> stanames_;
00426 Vector<String> antstanames_;
00427 Vector<String> fldnames_;
00428 Vector<String> intentnames_;
00429 Array<Double> positions_;
00430
00431 PMS::Axis iterAxis;
00432 bool ephemerisInitialized;
00433 ::QVector<double> uniqueTimes;
00434
00435
00436 String calType_;
00437
00438 bool polnRatio_;
00439
00440 private:
00441 void _updateAntennaMask( Int a, Vector<Bool>& antMask, const Vector<Int> selectedAntennas );
00442 bool axisIsValid(PMS::Axis axis, const PlotMSAveraging& averaging);
00443
00444 };
00445 typedef CountedPtr<PlotMSCacheBase> PlotMSCacheBasePtr;
00446
00447
00448 }
00449
00450 #endif