casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ASDMTableBase.h
Go to the documentation of this file.
00001 #ifndef _ASDMTABLEBASE_H_
00002 #define _ASDMTABLEBASE_H_
00003 
00004 #include <ms/MeasurementSets/MeasurementSet.h>
00005 #include <tables/Tables/TableDesc.h>
00006 #include <tables/Tables/ScaColDesc.h>
00007 #include <tables/Tables/ArrColDesc.h>
00008 #include <tables/Tables/TableRow.h>
00009 #include <casa/Arrays/Vector.h>
00010 #include <casa/Arrays/Matrix.h>
00011 #include <casa/Arrays/Cube.h>
00012 #include <casa/Containers/RecordDesc.h>
00013 #include <casa/Containers/RecordField.h>
00014 #include <casa/Containers/RecordInterface.h>
00015 #include <tables/Tables/SetupNewTab.h>
00016 #include <tables/Tables/TableRecord.h>
00017 #include <tables/Tables/TableLock.h>
00018 #include <tables/Tables/ScalarColumn.h>
00019 #include <tables/Tables/ArrayColumn.h>
00020 #include <casa/Exceptions/Error.h>
00021 #include <casa/Utilities/Assert.h>
00022 using namespace casa;
00023 
00024 #include "ASDM.h"
00025 #include "ArrayTime.h"
00026 #include "ArrayTimeInterval.h"
00027 using namespace asdm;
00028 
00029 template<typename T>
00030 class ASDM_TABLE_SINGLETON {
00031  protected:
00032   ASDM_TABLE_SINGLETON() {;}
00033   ~ASDM_TABLE_SINGLETON() {;}
00034 
00035  public:
00036   static T *instance() {
00037     if ( NULL == instance_)
00038       instance_ = new T;
00039     return (static_cast<T*>(instance_));
00040   }
00041 
00042   private:
00043     static T *instance_;
00044 };
00045 
00046 template<typename T>
00047 T *ASDM_TABLE_SINGLETON<T>::instance_ = NULL;
00048 
00049 class ASDM_TABLE_BASE {
00050  protected:
00051   ASDM_TABLE_BASE();
00052   virtual~ASDM_TABLE_BASE();
00053   string name_;
00054   Table* table_p_;
00055 
00056  public:
00057   Table* table_p();
00058   const string& name() const;
00059   virtual const TableDesc& tableDesc() const = 0;
00060   void buildAndAttachTable(MS* attachMS);
00061   virtual void fill(const ASDM& asdm) = 0;
00062 
00063   template<typename T, typename U>  Vector<U> basic2CASA1D(const vector<T>& v) {
00064     Vector<U> result;
00065     if (v.size() == 0)
00066       return result;
00067 
00068     result.resize(v.size());
00069     for (unsigned int i = 0; i < v.size(); i++)
00070       result(i) = v.at(i);
00071     return result;
00072   }
00073 
00074   template<typename T, typename U>  Matrix<U> basic2CASA2D(const vector<vector <T> >& v) {
00075     Matrix<U> result;
00076     if (v.size() == 0 || v.at(0).size() == 0)
00077       return result;
00078 
00079     result.resize(v.size(), v.at(0).size());
00080     for (unsigned int i = 0; i < v.size(); i++)
00081       for (unsigned int j = 0; j < v.at(0).size(); j++)
00082         result(i,j) = v.at(i).at(j);
00083     return result;
00084   }
00085 
00086 
00087   template<typename T, typename U>  Cube<U> basic2CASA3D(const vector<vector <vector <T> > >& v) {
00088     Cube<U> result;
00089     if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0)
00090       return result;
00091 
00092 
00093     result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
00094     for (unsigned int i = 0; i < v.size(); i++)
00095       for (unsigned int j = 0; j < v.at(0).size(); j++)
00096         for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
00097           result(i,j,k) = v.at(i).at(j).at(k);
00098     return result;
00099   }
00100 
00101   template<typename T, typename U>  Vector<U> ext2CASA1D(const vector<T>& v) {
00102     Vector<U> result;
00103     if (v.size() == 0)
00104       return result;
00105 
00106     result.resize(v.size());
00107     for (unsigned int i = 0; i < v.size(); i++)
00108       result(i) = v.at(i).get();
00109     return result;
00110   }
00111 
00112   template<typename T, typename U>  Matrix<U> ext2CASA2D(const vector<vector <T> >& v) {
00113     Matrix<U> result;
00114     if (v.size() == 0 || v.at(0).size() == 0)
00115       return result;
00116 
00117     result.resize(v.size(), v.at(0).size());
00118     for (unsigned int i = 0; i < v.size(); i++)
00119       for (unsigned int j = 0; j < v.at(0).size(); j++)
00120         result(i,j) = v.at(i).at(j).get();
00121     return result;
00122   }
00123 
00124 
00125   template<typename T, typename U>  Cube<U> ext2CASA3D(const vector<vector <vector <T> > >& v) {
00126     Cube<U> result;
00127     if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0)
00128       return result;
00129 
00130 
00131     result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
00132     for (unsigned int i = 0; i < v.size(); i++)
00133       for (unsigned int j = 0; j < v.at(0).size(); j++)
00134         for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
00135           result(i,j,k) = v.at(i).at(j).at(k).get();
00136     return result;
00137   }
00138 
00139   template<typename T, typename U>  Vector<U> _2CASAString1D(const vector<T>& v) {
00140     Vector<U> result;
00141     if (v.size() == 0)
00142       return result;
00143 
00144     result.resize(v.size());
00145     for (unsigned int i = 0; i < v.size(); i++)
00146       result(i) = v.at(i).toString();
00147     return result;
00148   }
00149 
00150   template<typename T, typename U>  Matrix<U> _2CASAString2D(const vector<vector <T> >& v) {
00151     Matrix<U> result;
00152     if (v.size() == 0 || v.at(0).size() == 0)
00153       return result;
00154 
00155     result.resize(v.size(), v.at(0).size());
00156     for (unsigned int i = 0; i < v.size(); i++)
00157       for (unsigned int j = 0; j < v.at(0).size(); j++)
00158         result(i,j) = v.at(i).at(j).toString();
00159     return result;
00160   }
00161 
00162 
00163   template<typename T, typename U>  Cube<U> _2CASAString3D(const vector<vector <vector <T> > >& v) {
00164     Cube<U> result;
00165     if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0)
00166       return result;
00167 
00168 
00169     result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
00170     for (unsigned int i = 0; i < v.size(); i++)
00171       for (unsigned int j = 0; j < v.at(0).size(); j++)
00172         for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
00173           result(i,j,k) = v.at(i).at(j).at(k).toString();
00174     return result;
00175   }
00176 
00177 
00178   template<typename enumT, typename CenumT>  Vector<String> enum2CASA1D (const vector<enumT>& v) {
00179     Vector<String> result;
00180     if (v.size() == 0) return result;
00181 
00182     result.resize(v.size());
00183     for (unsigned int i = 0; i < v.size(); i++)
00184       result(i) = CenumT::name(v.at(i));
00185     return result;
00186   }
00187 
00188   template<typename enumT, typename CenumT>  Matrix<String> enum2CASA2D (const vector<vector<enumT> >& v) {
00189     Matrix<String> result;
00190     if (v.size() == 0 || v.at(0).size() == 0) return result;
00191 
00192     result.resize(v.size(), v.at(0).size());
00193     for (unsigned int i = 0; i < v.size(); i++)
00194       for (unsigned int j = 0 ; j < v.at(0).size(); j++)
00195         result(i,j) = CenumT::name(v.at(i).at(j));
00196     return result;
00197   }
00198 
00199   template<typename enumT, typename CenumT>  Cube<String> enum2CASA3D (const vector<vector<vector<enumT> > >& v) {
00200     Cube<String> result;
00201     if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0) == 0) return result;
00202 
00203     result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
00204     for (unsigned int i = 0; i < v.size(); i++)
00205       for (unsigned int j = 0 ; j < v.at(0).size(); j++)
00206         for (unsigned int k = 0 ; k < v.at(0).at(0).size(); k++)
00207           result(i,j,k) = CenumT::name(v.at(i).at(j).at(k));
00208     return result;
00209   }
00210 
00211   template<typename T, typename U> Vector<U> interval2CASA1D(const vector<T>& v) {
00212     Vector<U> result;
00213     if (v.size()==0) return result;
00214 
00215     result.resize(v.size());
00216     for (unsigned int i = 0; i < v.size(); i++)
00217       result(i) = v.at(i).get()/1e09;
00218     return result;
00219   }
00220 
00221   template<typename T, typename U> Matrix<U> interval2CASA2D(const vector<vector<T> >& v) {
00222     Matrix<U> result;
00223     if (v.size()==0 || v.at(0).size()) return result;
00224 
00225     result.resize(v.size(), v.at(0).size());
00226     for (unsigned int i = 0; i < v.size(); i++)
00227       for (unsigned int j = 0; j < v.at(0).size(); j++)
00228         result(i,j) = v.at(i).at(j).get()/1.e09;
00229     return result;
00230   }
00231 
00232   template<typename T, typename U> Cube<U> interval2CASA3D(const vector<vector< vector<T> > >& v) {
00233     Cube<U> result;
00234     if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0) return result;
00235 
00236     result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
00237     for (unsigned int i = 0; i < v.size(); i++)
00238       for (unsigned int j = 0; j < v.at(0).size(); j++)
00239         for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
00240           result(i,j,k) = v.at(i).at(j).at(k).get()/1.e09;
00241     return result;
00242   }
00243 
00244   template<typename U>  Vector<U> at2CASA1D(const vector<ArrayTime>& v) {
00245     Vector<U> result;
00246     if (v.size()==0) return result;
00247 
00248     result.resize(v.size());
00249     for (unsigned int i = 0; i < v.size(); i++)
00250       result(i) = v.at(i).get()/1e09;
00251     return result;
00252   }
00253 
00254   template<typename U> Matrix<U> at2CASA2D(const vector<vector<ArrayTime> >& v) {
00255     Matrix<U> result;
00256     if (v.size()==0 || v.at(0).size()) return result;
00257 
00258     result.resize(v.size(), v.at(0).size());
00259     for (unsigned int i = 0; i < v.size(); i++)
00260       for (unsigned int j = 0; j < v.at(0).size(); j++)
00261         result(i,j) = v.at(i).at(j).get()/1.e09;
00262     return result;
00263   }
00264 
00265   template<typename U>  Cube<U> at2CASA3D(const vector<vector< vector<ArrayTime> > >& v) {
00266     Cube<U> result;
00267     if (v.size() == 0 || v.at(0).size() == 0 || v.at(0).at(0).size() == 0) return result;
00268 
00269     result.resize(v.size(), v.at(0).size(), v.at(0).at(0).size());
00270     for (unsigned int i = 0; i < v.size(); i++)
00271       for (unsigned int j = 0; j < v.at(0).size(); j++)
00272         for (unsigned int k = 0; k < v.at(0).at(0).size(); k++)
00273           result(i,j,k) = v.at(i).at(j).at(k).get()/1.e09;
00274     return result;
00275   }
00276 
00277   template<typename U> Vector<U> ati2CASA1D(const ArrayTimeInterval& ati) {
00278     Vector<U> result(2);
00279     result(0) = ((double) ati.getStart().get()) / ArrayTime::unitsInASecond;
00280     result(1) = ((double) ati.getDuration().get()) / ArrayTime::unitsInASecond;
00281     return result;
00282   }
00283 
00284   template<typename U> Matrix<U> ati2CASA2D(const vector<ArrayTimeInterval>& v) {
00285     Matrix<U> result;
00286     if (v.size() == 0) return result;
00287 
00288     result.resize(v.size(), 2);
00289     for (vector<ArrayTimeInterval>::size_type i = 0; i < v.size(); i++) {
00290       result(i, 0) = ((double) v[i].getStart().get()) / ArrayTime::unitsInASecond;
00291       result(i, 1) = ((double) v[i].getDuration().get()) / ArrayTime::unitsInASecond;
00292     }
00293     return result;
00294   }
00295 
00296   template<typename U> Cube<U> ati2CASA3D(const vector<vector<ArrayTimeInterval> >& v) {
00297     Cube<U> result;
00298     if (v.size() == 0 || v.at(0).size() == 0) return result;
00299 
00300     result.resize(v.size(), v.at(0).size(), 2);
00301     for (vector<vector<ArrayTimeInterval> >::size_type i = 0; i < v.size(); i++) {
00302       for (vector<ArrayTimeInterval>::size_type j = 0; j < v.at(0).size(); j++) {
00303         result(i, j, 0) = ((double) v[i][j].getStart().get()) / ArrayTime::unitsInASecond;
00304         result(i, j, 1) = ((double) v[i][j].getDuration().get()) / ArrayTime::unitsInASecond;
00305       }
00306     }
00307     return result;
00308   }
00309 
00310 };
00311 #endif // _ASDMTABLEBASE_H_