casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UtilsTVI.h
Go to the documentation of this file.
1 //# UtilsTVI.h: This file contains the interface definition of the MSTransformManager class.
2 //#
3 //# CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
4 //# Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
5 //# Copyright (C) European Southern Observatory, 2011, All rights reserved.
6 //#
7 //# This library is free software; you can redistribute it and/or
8 //# modify it under the terms of the GNU Lesser General Public
9 //# License as published by the Free software Foundation; either
10 //# version 2.1 of the License, or (at your option) any later version.
11 //#
12 //# This library is distributed in the hope that it will be useful,
13 //# but WITHOUT ANY WARRANTY, without even the implied warranty of
14 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 //# Lesser General Public License for more details.
16 //#
17 //# You should have received a copy of the GNU Lesser General Public
18 //# License along with this library; if not, write to the Free Software
19 //# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 //# MA 02111-1307 USA
21 //# $Id: $
22 
23 #ifndef UtilsTVI_H_
24 #define UtilsTVI_H_
25 
26 // casacore containers
32 
33 // Measurement Set
35 
36 // Standard Lib
37 #include <map>
38 #include <float.h>
39 
40 // NOTE: See implementation include below
41 
42 
43 namespace casa { //# NAMESPACE CASA - BEGIN
44 
45 namespace vi { //# NAMESPACE VI - BEGIN
46 
47 
49 // DataCubeHolderBase class
51 
53 {
54 
55 public:
56 
58  virtual ~DataCubeHolderBase() {}
59  virtual DataCubeHolderBase * selfReference() = 0;
60  virtual void setMatrixIndex(casacore::uInt matrixIndex) = 0;
61  virtual void setVectorIndex(casacore::uInt vectorIndex) = 0;
67 
68  // Methods controlling internal iteration
69  // gmoellen (2017Mar06)
70  virtual void setupVecIter() = 0;
71  virtual void reset() = 0;
72  virtual void next() = 0;
73  virtual casacore::Bool pastEnd() = 0;
74 
75 protected:
76 
82 };
83 
85 // DataCubeHolder class
87 
88 template <class T> class DataCubeHolder : public DataCubeHolderBase
89 {
90 
91 public:
92 
94  : veciter_p(0)
95  {
96  cube_p.reference(dataCube);
97  cubeShape_p = cube_p.shape();
98  }
99 
101  : veciter_p(0)
102  {
103  cube_p.reference(dataCube);
104  cubeShape_p = cube_p.shape();
105  }
106 
108  : veciter_p(0)
109  {
110  matrix_p.reference(dataMatrix);
111  matrixShape_p = matrix_p.shape();
112  }
113 
115  : veciter_p(0)
116  {
117  matrix_p.reference(dataMatrix);
118  matrixShape_p = matrix_p.shape();
119  }
120 
122  : veciter_p(0)
123  {
124  vector_p.reference(dataVector);
125  vectorShape_p = vector_p.shape();
126  }
127 
129  : veciter_p(0)
130  {
131  vector_p.reference(dataVector);
132  vectorShape_p = vector_p.shape();
133  }
134 
135  // Destructor must delete the iterator
136  // gmoellen (2017Mar06)
138  {
139  if (veciter_p) delete veciter_p;
140  }
141 
142 
145 
146  void setMatrixIndex(casacore::uInt matrixIndex)
147  {
148  matrix_p.resize(); // Resize to 0 to avoid shape conformance problems
149  matrixIndex_p = matrixIndex;
150  matrix_p.reference(cube_p.xyPlane(matrixIndex));
151  matrixShape_p = matrix_p.shape();
152 
153  return;
154  }
155 
156  void setVectorIndex(casacore::uInt vectorIndex)
157  {
158  vector_p.resize(); // Resize to 0 to avoid shape conformance problems
159  vectorIndex_p = vectorIndex;
160  vector_p.reference(matrix_p.row(vectorIndex));
161  vectorShape_p = vector_p.shape();
162 
163  return;
164  }
165 
167  {
169  return static_cast<DataCubeHolderBase*>(selfRef);
170  }
171 
172 
173  // Methods controlling internal iteration
174  // gmoellen (2017Mar06)
175  virtual void setupVecIter() {
176  // Construct the iterator, selecting the channel axis cursor
177  if (veciter_p) delete veciter_p;
178  veciter_p = new casacore::VectorIterator<T>(cube_p,1); // normally deleted in dtor
179  // refer vector_p to the iterator's vector; this will stay sync'd
180  vector_p.reference(veciter_p->vector());
181  vectorShape_p = vector_p.shape();
182  // NB: matrix_p refers to nothing (forever, in this context)
183  }
184  // NB: the reference calls below can be avoided if vector_p is a _c++_ reference
185  // initialzed in the DCH ctor to reference veciter_p's internal Vector
186  virtual void reset() {veciter_p->reset(); vector_p.reference(veciter_p->vector());}
187  virtual void next() {veciter_p->next(); vector_p.reference(veciter_p->vector());}
188  virtual casacore::Bool pastEnd() {return veciter_p->pastEnd(); }
189 
190 protected:
191 
195 
196  // Iterator for cube_p
197  // gmoellen (2017Mar06)
199 
200 };
201 
203 // DataCubeMap class
205 
206 class DataCubeMap
207 {
208 
209 public:
210 
211  DataCubeMap();
212  DataCubeMap(DataCubeMap& other);
213  virtual ~DataCubeMap();
214 
215  void add(casacore::MS::PredefinedColumns key,DataCubeHolderBase* dataCubeHolder);
216  void add(casacore::MS::PredefinedColumns key,DataCubeHolderBase &dataCubeHolder);
217 
219 
221  {
222  DataCubeHolder<T> *dataCubeHolder = static_cast< DataCubeHolder<T>* >(dataCubeMap_p[key]);
223  return dataCubeHolder->getVector();
224  }
225 
227  {
228  DataCubeHolder<T> *dataCubeHolder = static_cast< DataCubeHolder<T>* >(dataCubeMap_p[key]);
229  return dataCubeHolder->getVector();
230  }
231 
232  void setMatrixIndex(casacore::uInt rowIndex);
233  void setVectorIndex(casacore::uInt vectorIndex);
234 
238 
239  size_t nelements();
240 
241  // Methods controlling iteration
242  // gmoellen (2017Mar06)
243  virtual void setupVecIter();
244  void reset();
245  void next();
247 
248 
249 protected:
250 
251  std::map<casacore::MS::PredefinedColumns, DataCubeHolderBase*> dataCubeMap_p;
252  std::map<casacore::MS::PredefinedColumns, DataCubeHolderBase*>::iterator dataCubeMapIter_p;
253 };
254 
255 
257 // Convenience methods
259 
261 {
262  return weight > FLT_MIN ? 1.0 / std::sqrt (weight) : -1.0;
263 }
264 
266 {
267  return sigma > FLT_MIN ? 1.0 / (sigma * sigma) : 0.0;
268 }
269 
273 
277 
280 
281 
282 
283 } //# NAMESPACE VI - END
284 
285 } //# NAMESPACE CASA - END
286 
287 
288 #endif /* UtilsTVI_H_ */
289 
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
virtual void setupVecIter()
Methods controlling iteration gmoellen (2017Mar06)
A 1-D Specialization of the Array class.
casacore::Float sigmaToWeight(casacore::Float sigma)
Definition: UtilsTVI.h:265
virtual void setupVecIter()
Methods controlling internal iteration gmoellen (2017Mar06)
Definition: UtilsTVI.h:175
casacore::Bool present(casacore::MS::PredefinedColumns key)
casacore::IPosition vectorShape_p
Definition: UtilsTVI.h:81
virtual casacore::Bool pastEnd()=0
casacore::IPosition & getMatrixShape()
casacore::Cube< T > cube_p
Definition: UtilsTVI.h:192
DataCubeHolderBase * selfReference()
Definition: UtilsTVI.h:166
void accumulateWeightMatrix(const casacore::Matrix< casacore::Float > &weightMatrix, const casacore::Matrix< casacore::Bool > &flags, casacore::Vector< casacore::Float > &result)
casacore::Matrix< T > matrix_p
Definition: UtilsTVI.h:193
casacore::uInt matrixIndex_p
Definition: UtilsTVI.h:77
casacore::IPosition & getCubeShape()
DataCubeHolder(const casacore::Matrix< T > &dataMatrix)
Definition: UtilsTVI.h:114
A 3-D Specialization of the Array class.
casacore::VectorIterator< T > * veciter_p
Iterator for cube_p gmoellen (2017Mar06)
Definition: UtilsTVI.h:198
void setMatrixIndex(casacore::uInt rowIndex)
A 2-D Specialization of the Array class.
casacore::Matrix< T > & getMatrix()
Definition: UtilsTVI.h:143
casacore::IPosition & getVectorShape()
PredefinedColumns
The Main table colums with predefined meaning.
Definition: MSMainEnums.h:65
virtual void setupVecIter()=0
Methods controlling internal iteration gmoellen (2017Mar06)
casacore::uInt getMatrixIndex()
void setMatrixIndex(casacore::uInt matrixIndex)
Definition: UtilsTVI.h:146
casacore::IPosition matrixShape_p
Definition: UtilsTVI.h:80
casacore::IPosition & getMatrixShape()
void accumulateWeightCube(const casacore::Cube< casacore::Float > &weightCube, const casacore::Cube< casacore::Bool > &flags, casacore::Matrix< casacore::Float > &result)
virtual ~DataCubeHolder()
Destructor must delete the iterator gmoellen (2017Mar06)
Definition: UtilsTVI.h:137
DataCubeHolder(casacore::Cube< T > &dataCube)
Definition: UtilsTVI.h:93
virtual void reset()
NB: the reference calls below can be avoided if vector_p is a _c++_ reference initialzed in the DCH c...
Definition: UtilsTVI.h:186
void accumulateFlagCube(const casacore::Cube< casacore::Bool > &flagCube, casacore::Vector< casacore::Bool > &flagRow)
virtual void setMatrixIndex(casacore::uInt matrixIndex)=0
casacore::IPosition & getVectorShape()
virtual void next()
Definition: UtilsTVI.h:187
std::map< casacore::MS::PredefinedColumns, DataCubeHolderBase * >::iterator dataCubeMapIter_p
Definition: UtilsTVI.h:252
virtual casacore::Bool pastEnd()
Definition: UtilsTVI.h:188
LatticeExprNode sqrt(const LatticeExprNode &expr)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Convenience methods *casacore::Float weightToSigma(casacore::Float weight)
Definition: UtilsTVI.h:260
std::map< casacore::MS::PredefinedColumns, DataCubeHolderBase * > dataCubeMap_p
Definition: UtilsTVI.h:251
float Float
Definition: aipstype.h:54
DataCubeHolder(casacore::Vector< T > &dataVector)
Definition: UtilsTVI.h:121
virtual DataCubeHolderBase * selfReference()=0
DataCubeHolder(casacore::Matrix< T > &dataMatrix)
Definition: UtilsTVI.h:107
casacore::Vector< T > & getVector()
Definition: UtilsTVI.h:144
casacore::uInt vectorIndex_p
Definition: UtilsTVI.h:78
Iterate an Vector cursor through another Array.
Definition: VectorIter.h:74
casacore::uInt getVectorIndex()
void add(casacore::MS::PredefinedColumns key, DataCubeHolderBase *dataCubeHolder)
DataCubeHolder(const casacore::Vector< T > &dataVector)
Definition: UtilsTVI.h:128
casacore::Vector< T > vector_p
Definition: UtilsTVI.h:194
virtual void setVectorIndex(casacore::uInt vectorIndex)=0
casacore::IPosition cubeShape_p
Definition: UtilsTVI.h:79
casacore::IPosition & getCubeShape()
void setVectorIndex(casacore::uInt vectorIndex)
Definition: UtilsTVI.h:156
casacore::Matrix< T > & getMatrix(casacore::MS::PredefinedColumns key)
Definition: UtilsTVI.h:226
void setVectorIndex(casacore::uInt vectorIndex)
casacore::Bool pastEnd()
unsigned int uInt
Definition: aipstype.h:51
DataCubeHolder(const casacore::Cube< T > &dataCube)
Definition: UtilsTVI.h:100
casacore::Vector< T > & getVector(casacore::MS::PredefinedColumns key)
Definition: UtilsTVI.h:220