casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ASDMTableBase.h
Go to the documentation of this file.
1 #ifndef _ASDMTABLEBASE_H_
2 #define _ASDMTABLEBASE_H_
3 
9 #include <casa/Arrays/Vector.h>
10 #include <casa/Arrays/Matrix.h>
11 #include <casa/Arrays/Cube.h>
20 #include <casa/Exceptions/Error.h>
21 #include <casa/Utilities/Assert.h>
22 
23 #include <alma/ASDM/ASDM.h>
24 #include <alma/ASDM/ArrayTime.h>
26 
27 namespace asdm {
28 
29  template<typename T>
31  protected:
34  public:
35  static T *instance() {
36  if ( NULL == instance_)
37  instance_ = new T;
38  return (static_cast<T*>(instance_));
39  }
40  private:
41  static T *instance_;
42  };
43 
44  template<typename T> T *ASDM_TABLE_SINGLETON<T>::instance_ = NULL;
46  protected:
48  virtual~ASDM_TABLE_BASE();
49  std::string name_;
51  public:
53  const std::string& name() const;
54  virtual const casacore::TableDesc& tableDesc() const = 0;
55  void buildAndAttachTable(casacore::MS* attachMS);
56  virtual void fill(const ASDM& asdm) = 0;
57 
58  template<typename T, typename U> casacore::Vector<U> basic2CASA1D(const std::vector<T>& v) {
59  casacore::Vector<U> result;
60  if (v.size() == 0)
61  return result;
62 
63  result.resize(v.size());
64  for (unsigned int i = 0; i < v.size(); i++)
65  result(i) = v.at(i);
66  return result;
67  }
68 
69  template<typename T, typename U> casacore::Matrix<U> basic2CASA2D(const std::vector<std::vector <T> >& v) {
70  casacore::Matrix<U> result;
71  if (v.size() == 0 || v.at(0).size() == 0)
72  return result;
73 
74  result.resize(v.size(), v.at(0).size());
75  for (unsigned int i = 0; i < v.size(); i++)
76  for (unsigned int j = 0; j < v.at(0).size(); j++)
77  result(i,j) = v.at(i).at(j);
78  return result;
79  }
80 
81  template<typename T, typename U> casacore::Cube<U> basic2CASA3D(const std::vector<std::vector <std::vector <T> > >& v) {
82  casacore::Cube<U> result;
83  if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0)
84  return result;
85 
86  result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
87  for (unsigned int i = 0; i < v.size(); i++)
88  for (unsigned int j = 0; j < v.at(0).size(); j++)
89  for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
90  result(i,j,k) = v.at(i).at(j).at(k);
91  return result;
92  }
93 
94  template<typename T, typename U> casacore::Vector<U> ext2CASA1D(const std::vector<T>& v) {
95  casacore::Vector<U> result;
96  if (v.size() == 0)
97  return result;
98 
99  result.resize(v.size());
100  for (unsigned int i = 0; i < v.size(); i++)
101  result(i) = v.at(i).get();
102  return result;
103  }
104 
105  template<typename T, typename U> casacore::Matrix<U> ext2CASA2D(const std::vector<std::vector <T> >& v) {
106  casacore::Matrix<U> result;
107  if (v.size() == 0 || v.at(0).size() == 0)
108  return result;
109 
110  result.resize(v.size(), v.at(0).size());
111  for (unsigned int i = 0; i < v.size(); i++)
112  for (unsigned int j = 0; j < v.at(0).size(); j++)
113  result(i,j) = v.at(i).at(j).get();
114  return result;
115  }
116 
117  template<typename T, typename U> casacore::Cube<U> ext2CASA3D(const std::vector<std::vector <std::vector <T> > >& v) {
118  casacore::Cube<U> result;
119  if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0)
120  return result;
121 
122  result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
123  for (unsigned int i = 0; i < v.size(); i++)
124  for (unsigned int j = 0; j < v.at(0).size(); j++)
125  for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
126  result(i,j,k) = v.at(i).at(j).at(k).get();
127  return result;
128  }
129 
130  template<typename T, typename U> casacore::Vector<U> _2CASAString1D(const std::vector<T>& v) {
131  casacore::Vector<U> result;
132  if (v.size() == 0)
133  return result;
134 
135  result.resize(v.size());
136  for (unsigned int i = 0; i < v.size(); i++)
137  result(i) = v.at(i).toString();
138  return result;
139  }
140 
141  template<typename T, typename U> casacore::Matrix<U> _2CASAString2D(const std::vector<std::vector <T> >& v) {
142  casacore::Matrix<U> result;
143  if (v.size() == 0 || v.at(0).size() == 0)
144  return result;
145 
146  result.resize(v.size(), v.at(0).size());
147  for (unsigned int i = 0; i < v.size(); i++)
148  for (unsigned int j = 0; j < v.at(0).size(); j++)
149  result(i,j) = v.at(i).at(j).toString();
150  return result;
151  }
152 
153  template<typename T, typename U> casacore::Cube<U> _2CASAString3D(const std::vector<std::vector <std::vector <T> > >& v) {
154  casacore::Cube<U> result;
155  if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0)
156  return result;
157 
158  result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
159  for (unsigned int i = 0; i < v.size(); i++)
160  for (unsigned int j = 0; j < v.at(0).size(); j++)
161  for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
162  result(i,j,k) = v.at(i).at(j).at(k).toString();
163  return result;
164  }
165 
166  template<typename enumT, typename CenumT> casacore::Vector<casacore::String> enum2CASA1D (const std::vector<enumT>& v) {
168  if (v.size() == 0) return result;
169 
170  result.resize(v.size());
171  for (unsigned int i = 0; i < v.size(); i++)
172  result(i) = CenumT::name(v.at(i));
173  return result;
174  }
175 
176  template<typename enumT, typename CenumT> casacore::Matrix<casacore::String> enum2CASA2D (const std::vector<std::vector<enumT> >& v) {
178  if (v.size() == 0 || v.at(0).size() == 0) return result;
179 
180  result.resize(v.size(), v.at(0).size());
181  for (unsigned int i = 0; i < v.size(); i++)
182  for (unsigned int j = 0 ; j < v.at(0).size(); j++)
183  result(i,j) = CenumT::name(v.at(i).at(j));
184  return result;
185  }
186 
187  template<typename enumT, typename CenumT> casacore::Cube<casacore::String> enum2CASA3D (const std::vector<std::vector<std::vector<enumT> > >& v) {
189  if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0) == 0) return result;
190 
191  result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
192  for (unsigned int i = 0; i < v.size(); i++)
193  for (unsigned int j = 0 ; j < v.at(0).size(); j++)
194  for (unsigned int k = 0 ; k < v.at(0).at(0).size(); k++)
195  result(i,j,k) = CenumT::name(v.at(i).at(j).at(k));
196  return result;
197  }
198 
199  template<typename T, typename U> casacore::Vector<U> interval2CASA1D(const std::vector<T>& v) {
200  casacore::Vector<U> result;
201  if (v.size()==0) return result;
202 
203  result.resize(v.size());
204  for (unsigned int i = 0; i < v.size(); i++)
205  result(i) = v.at(i).get()/1e09;
206  return result;
207  }
208 
209  template<typename T, typename U> casacore::Matrix<U> interval2CASA2D(const std::vector<std::vector<T> >& v) {
210  casacore::Matrix<U> result;
211  if (v.size()==0 || v.at(0).size()) return result;
212 
213  result.resize(v.size(), v.at(0).size());
214  for (unsigned int i = 0; i < v.size(); i++)
215  for (unsigned int j = 0; j < v.at(0).size(); j++)
216  result(i,j) = v.at(i).at(j).get()/1.e09;
217  return result;
218  }
219 
220  template<typename T, typename U> casacore::Cube<U> interval2CASA3D(const std::vector<std::vector< std::vector<T> > >& v) {
221  casacore::Cube<U> result;
222  if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0) return result;
223 
224  result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
225  for (unsigned int i = 0; i < v.size(); i++)
226  for (unsigned int j = 0; j < v.at(0).size(); j++)
227  for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
228  result(i,j,k) = v.at(i).at(j).at(k).get()/1.e09;
229  return result;
230  }
231 
232  template<typename U> casacore::Vector<U> at2CASA1D(const std::vector<ArrayTime>& v) {
233  casacore::Vector<U> result;
234  if (v.size()==0) return result;
235 
236  result.resize(v.size());
237  for (unsigned int i = 0; i < v.size(); i++)
238  result(i) = v.at(i).get()/1e09;
239  return result;
240  }
241 
242  template<typename U> casacore::Matrix<U> at2CASA2D(const std::vector<std::vector<ArrayTime> >& v) {
243  casacore::Matrix<U> result;
244  if (v.size()==0 || v.at(0).size()) return result;
245 
246  result.resize(v.size(), v.at(0).size());
247  for (unsigned int i = 0; i < v.size(); i++)
248  for (unsigned int j = 0; j < v.at(0).size(); j++)
249  result(i,j) = v.at(i).at(j).get()/1.e09;
250  return result;
251  }
252 
253  template<typename U> casacore::Cube<U> at2CASA3D(const std::vector<std::vector< std::vector<ArrayTime> > >& v) {
254  casacore::Cube<U> result;
255  if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0) return result;
256 
257  result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
258  for (unsigned int i = 0; i < v.size(); i++)
259  for (unsigned int j = 0; j < v.at(0).size(); j++)
260  for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
261  result(i,j,k) = v.at(i).at(j).at(k).get()/1.e09;
262  return result;
263  }
264 
265  template<typename U> casacore::Vector<U> ati2CASA1D(const ArrayTimeInterval& ati) {
266  casacore::Vector<U> result(2);
267  result(0) = ((double) ati.getStart().get()) / ArrayTime::unitsInASecond;
268  result(1) = ((double) ati.getDuration().get()) / ArrayTime::unitsInASecond;
269  return result;
270  }
271 
272  template<typename U> casacore::Matrix<U> ati2CASA2D(const std::vector<ArrayTimeInterval>& v) {
273  casacore::Matrix<U> result;
274  if (v.size() == 0) return result;
275 
276  result.resize(v.size(), 2);
277  for (std::vector<ArrayTimeInterval>::size_type i = 0; i < v.size(); i++) {
278  result(i, 0) = ((double) v[i].getStart().get()) / ArrayTime::unitsInASecond;
279  result(i, 1) = ((double) v[i].getDuration().get()) / ArrayTime::unitsInASecond;
280  }
281  return result;
282  }
283 
284  template<typename U> casacore::Cube<U> ati2CASA3D(const std::vector<std::vector<ArrayTimeInterval> >& v) {
285  casacore::Cube<U> result;
286  if (v.size() == 0 || v.at(0).size() == 0) return result;
287 
288  result.resize(v.size(), v.at(0).size(), 2);
289  for (std::vector<std::vector<ArrayTimeInterval> >::size_type i = 0; i < v.size(); i++) {
290  for (std::vector<ArrayTimeInterval>::size_type j = 0; j < v.at(0).size(); j++) {
291  result(i, j, 0) = ((double) v[i][j].getStart().get()) / ArrayTime::unitsInASecond;
292  result(i, j, 1) = ((double) v[i][j].getDuration().get()) / ArrayTime::unitsInASecond;
293  }
294  }
295  return result;
296  }
297 
298  };
299 
300 } // end namespace asdm
301 
302 
303 #endif // _ASDMTABLEBASE_H_
casacore::Cube< U > at2CASA3D(const std::vector< std::vector< std::vector< ArrayTime > > > &v)
casacore::Cube< U > basic2CASA3D(const std::vector< std::vector< std::vector< T > > > &v)
Definition: ASDMTableBase.h:81
A 1-D Specialization of the Array class.
casacore::Cube< U > ext2CASA3D(const std::vector< std::vector< std::vector< T > > > &v)
casacore::Cube< casacore::String > enum2CASA3D(const std::vector< std::vector< std::vector< enumT > > > &v)
Main interface class to a read/write table.
Definition: Table.h:153
void buildAndAttachTable(casacore::MS *attachMS)
casacore::Matrix< U > at2CASA2D(const std::vector< std::vector< ArrayTime > > &v)
The ArrayTimeInterval class aggregates an instance of ArrayTime and an instance of Interval...
A 3-D Specialization of the Array class.
The ASDM class is the container for all tables.
Definition: ASDM.h:273
virtual void fill(const ASDM &asdm)=0
A 2-D Specialization of the Array class.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
casacore::Cube< U > _2CASAString3D(const std::vector< std::vector< std::vector< T > > > &v)
ArrayTime getStart() const
Getters.
casacore::Cube< U > ati2CASA3D(const std::vector< std::vector< ArrayTimeInterval > > &v)
T & at(size_t i1, size_t i2, size_t i3)
Definition: Cube.h:193
casacore::Matrix< U > basic2CASA2D(const std::vector< std::vector< T > > &v)
Definition: ASDMTableBase.h:69
int64_t get() const
Definition: Interval.h:295
casacore::Matrix< U > ati2CASA2D(const std::vector< ArrayTimeInterval > &v)
casacore::Matrix< U > ext2CASA2D(const std::vector< std::vector< T > > &v)
casacore::Matrix< U > _2CASAString2D(const std::vector< std::vector< T > > &v)
virtual const casacore::TableDesc & tableDesc() const =0
void resize(size_t nx, size_t ny, size_t nz, Bool copyValues=False)
Definition: Cube.h:138
virtual ~ASDM_TABLE_BASE()
casacore::Vector< U > ati2CASA1D(const ArrayTimeInterval &ati)
casacore::Table * table_p_
Definition: ASDMTableBase.h:50
casacore::Cube< U > interval2CASA3D(const std::vector< std::vector< std::vector< T > > > &v)
casacore::Vector< U > ext2CASA1D(const std::vector< T > &v)
Definition: ASDMTableBase.h:94
A Table intended to hold astronomical data (a set of Measurements).
casacore::Matrix< casacore::String > enum2CASA2D(const std::vector< std::vector< enumT > > &v)
casacore::Vector< U > at2CASA1D(const std::vector< ArrayTime > &v)
const std::string & name() const
static const int64_t unitsInASecond
Definition: ArrayTime.h:95
Interval getDuration() const
casacore::Vector< U > basic2CASA1D(const std::vector< T > &v)
Definition: ASDMTableBase.h:58
casacore::Vector< casacore::String > enum2CASA1D(const std::vector< enumT > &v)
void resize(size_t nx, size_t ny, Bool copyValues=False)
Definition: Matrix.h:154
casacore::Table * table_p()
Define the structure of a Casacore table.
Definition: TableDesc.h:187
void resize(size_t len, Bool copyValues=False)
Definition: Vector.h:167
casacore::Matrix< U > interval2CASA2D(const std::vector< std::vector< T > > &v)
casacore::Vector< U > interval2CASA1D(const std::vector< T > &v)
casacore::Vector< U > _2CASAString1D(const std::vector< T > &v)