00001
00002
00003
00004
00005
00006
00007
00008 #ifndef VBI2MSROW_H_
00009 #define VBI2MSROW_H_
00010
00011 #include <casa/Arrays/Array.h>
00012 #include <msvis/MSVis/MsRows.h>
00013
00014
00015
00016 namespace casa {
00017
00018 namespace vi {
00019
00020 class VisBufferImpl2;
00021
00022 }
00023
00024 }
00025
00026 namespace casa {
00027
00028 namespace ms {
00029
00030 class CachedArrayBase {
00031
00032 public:
00033
00034 CachedArrayBase () : cached_p (False) {}
00035 virtual ~CachedArrayBase () {}
00036
00037 void clearCache () { cached_p = False;}
00038
00039 protected:
00040
00041 Bool isCached () const { return cached_p;}
00042 void setCached () { cached_p = true;}
00043
00044 private:
00045
00046 Bool cached_p;
00047 };
00048
00049 template <typename T>
00050 class CachedPlane : public CachedArrayBase {
00051
00052 public:
00053
00054 typedef const Cube<T> & (casa::vi::VisBufferImpl2::* Accessor) () const;
00055
00056 CachedPlane (Accessor accessor) : accessor_p (accessor) {}
00057
00058 Matrix<T> &
00059 getCachedPlane (casa::vi::VisBufferImpl2 * vb, Int row)
00060 {
00061 if (! isCached()){
00062
00063
00064 referenceMatrix (cache_p, (vb ->* accessor_p)(), row);
00065 setCached ();
00066 }
00067
00068 return cache_p;
00069 }
00070
00071 private:
00072
00073 static void
00074 referenceMatrix (Matrix<T> & cache, const Cube<T> & src, Int row)
00075 {
00076 IPosition shape = src.shape ();
00077 shape.resize (2);
00078
00079
00080
00081
00082 T * storage = const_cast <T *> (& src (IPosition (3, 0, 0, row)));
00083
00084 cache.takeStorage (shape, storage, casa::SHARE);
00085 }
00086
00087 Accessor accessor_p;
00088 Matrix<T> cache_p;
00089 };
00090
00091 template <typename T>
00092 class CachedColumn : public CachedArrayBase {
00093
00094 public:
00095
00096 typedef const Matrix<T> & (casa::vi::VisBufferImpl2::* Accessor) () const;
00097
00098 CachedColumn (Accessor accessor) : accessor_p (accessor) {}
00099
00100 Vector<T> &
00101 getCachedColumn (casa::vi::VisBufferImpl2 * vb, Int row)
00102 {
00103 if (! isCached()){
00104
00105 referenceVector (cache_p, (vb ->* accessor_p)(), row);
00106 setCached ();
00107 }
00108
00109 return cache_p;
00110 }
00111
00112 private:
00113
00114 static void
00115 referenceVector (Vector<T> & cache, const Matrix<T> & src, Int row)
00116 {
00117 IPosition shape = src.shape ();
00118 shape.resize (1);
00119
00120
00121
00122
00123 T * storage = const_cast <T *> (& src (IPosition (2, 0, row)));
00124
00125 cache.takeStorage (shape, storage, casa::SHARE);
00126 }
00127
00128 Accessor accessor_p;
00129 Vector<T> cache_p;
00130 };
00131
00132
00133 class Vbi2MsRow : public MsRow {
00134
00135 public:
00136
00137
00138
00139
00140
00141
00142 Vbi2MsRow (Int row, const vi::VisBufferImpl2 * vb);
00143
00144
00145
00146 Vbi2MsRow (Int row, vi::VisBufferImpl2 * vb);
00147
00148 virtual ~Vbi2MsRow () {}
00149
00150 void changeRow (Int row);
00151 void copy (Vbi2MsRow * other,
00152 const VisBufferComponents2 & componentsToCopy);
00153
00154 Int antenna1 () const;
00155 Int antenna2 () const;
00156 Int arrayId () const;
00157 Int correlationType () const;
00158 Int dataDescriptionId () const;
00159 Int feed1 () const;
00160 Int feed2 () const;
00161 Int fieldId () const;
00162 Int observationId () const;
00163 Int rowId () const;
00164 Int processorId () const;
00165 Int scanNumber () const;
00166 Int stateId () const;
00167 Double exposure () const;
00168 Double interval () const;
00169 Int spectralWindow () const;
00170 Double time () const;
00171 Double timeCentroid () const;
00172
00173 void setAntenna1 (Int);
00174 void setAntenna2 (Int);
00175 void setArrayId (Int);
00176 void setCorrelationType (Int);
00177 void setDataDescriptionId (Int);
00178 void setFeed1 (Int);
00179 void setFeed2 (Int);
00180 void setFieldId (Int);
00181 void setObservationId (Int);
00182 void setProcessorId (Int);
00183 void setRowId (Int);
00184 void setScanNumber (Int);
00185 void setStateId (Int);
00186 void setExposure (Double);
00187 void setInterval (Double);
00188 void setSpectralWindow (Int);
00189 void setTime (Double);
00190 void setTimeCentroid (Double);
00191
00192 const Vector<Double> uvw () const;
00193 const Double & uvw (Int i) const;
00194 void setUvw (const Vector<Double> &);
00195 void setUvw (Int i, const Vector<Double> &);
00196
00197 const Complex & corrected (Int correlation, Int channel) const;
00198 const Matrix<Complex> & corrected () const;
00199 Matrix<Complex> & correctedMutable ();
00200 void setCorrected (Int correlation, Int channel, const Complex & value);
00201 void setCorrected (const Matrix<Complex> & value);
00202
00203 const Complex & model (Int correlation, Int channel) const;
00204 const Matrix<Complex> & model () const;
00205 Matrix<Complex> & modelMutable ();
00206 void setModel(Int correlation, Int channel, const Complex & value);
00207 void setModel (const Matrix<Complex> & value);
00208
00209 const Complex & observed (Int correlation, Int channel) const;
00210 const Matrix<Complex> & observed () const;
00211 Matrix<Complex> & observedMutable ();
00212 void setObserved (Int correlation, Int channel, const Complex & value);
00213 void setObserved (const Matrix<Complex> & value);
00214
00215 const Float & singleDishData (Int correlation, Int channel) const;
00216 const Matrix<Float> singleDishData () const;
00217 Matrix<Float> singleDishDataMutable ();
00218 void setSingleDishData (Int correlation, Int channel, const Float & value);
00219 void setSingleDishData (const Matrix<Float> & value);
00220
00221 Float sigma (Int correlation) const;
00222 const Vector<Float> & sigma () const;
00223 Vector<Float> & sigmaMutable () const;
00224 void setSigma (Int correlation, Float value);
00225 void setSigma (const Vector<Float> & value);
00226 Float weight (Int correlation) const;
00227 const Vector<Float> & weight () const;
00228 Vector<Float> & weightMutable () const;
00229 void setWeight (Int correlation, Float value);
00230 void setWeight (const Vector<Float> & value);
00231 Float weightSpectrum (Int correlation, Int channel) const;
00232 void setWeightSpectrum (Int correlation, Int channel, Float value);
00233 void setWeightSpectrum (const Matrix<Float> & value);
00234 const Matrix<Float> & weightSpectrum () const;
00235 Matrix<Float> & weightSpectrumMutable () const;
00236 Float sigmaSpectrum (Int correlation, Int channel) const;
00237 const Matrix<Float> & sigmaSpectrum () const;
00238 Matrix<Float> & sigmaSpectrumMutable () const;
00239 void setSigmaSpectrum (Int correlation, Int channel, Float value);
00240 void setSigmaSpectrum (const Matrix<Float> & value);
00241
00242 Bool isRowFlagged () const;
00243 const Matrix<Bool> & flags () const;
00244 void setFlags (const Matrix<Bool> & flags);
00245 Bool isFlagged (Int correlation, Int channel) const;
00246
00247 void setRowFlag (Bool isFlagged);
00248 void setFlags (Bool isFlagged, Int correlation, Int channel);
00249
00250 protected:
00251
00252 template <typename T>
00253 void addToCachedArrays (T & cachedArray)
00254 {
00255 arrayCaches_p.push_back (& cachedArray);
00256 }
00257
00258 void clearArrayCaches();
00259 Matrix<Bool> & flagsMutable ();
00260 vi::VisBufferImpl2 * getVbi () const;
00261
00262 private:
00263
00264 void configureArrayCaches();
00265
00266 mutable CachedPlane<Complex> correctedCache_p;
00267 mutable CachedPlane<Bool> flagCache_p;
00268 mutable CachedPlane<Complex> modelCache_p;
00269 mutable CachedPlane<Complex> observedCache_p;
00270 mutable CachedColumn<Float> sigmaCache_p;
00271 mutable CachedPlane<Float> sigmaSpectrumCache_p;
00272 mutable CachedColumn<Float> weightCache_p;
00273 mutable CachedPlane<Float> weightSpectrumCache_p;
00274
00275 std::vector<CachedArrayBase *> arrayCaches_p;
00276
00277 template <typename T, typename U>
00278 void
00279 copyIf (Bool copyThis, Vbi2MsRow * other,
00280 void (Vbi2MsRow::* setter) (T),
00281 U (Vbi2MsRow::* getter) () const);
00282
00283 vi::VisBufferImpl2 * vbi2_p;
00284
00285 };
00286
00287 }
00288
00289 }
00290
00291
00292 #endif