| 1 | //#---------------------------------------------------------------------------
|
|---|
| 2 | //# SDMemTableWrapper.h: Wrapper classes to use CountedPtr
|
|---|
| 3 | //#---------------------------------------------------------------------------
|
|---|
| 4 | //# Copyright (C) 2004
|
|---|
| 5 | //# ATNF
|
|---|
| 6 | //#
|
|---|
| 7 | //# This program is free software; you can redistribute it and/or modify it
|
|---|
| 8 | //# under the terms of the GNU General Public License as published by the Free
|
|---|
| 9 | //# Software Foundation; either version 2 of the License, or (at your option)
|
|---|
| 10 | //# any later version.
|
|---|
| 11 | //#
|
|---|
| 12 | //# This program is distributed in the hope that it will be useful, but
|
|---|
| 13 | //# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|---|
| 15 | //# Public License for more details.
|
|---|
| 16 | //#
|
|---|
| 17 | //# You should have received a copy of the GNU General Public License along
|
|---|
| 18 | //# with this program; if not, write to the Free Software Foundation, Inc.,
|
|---|
| 19 | //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
|
|---|
| 20 | //#
|
|---|
| 21 | //# Correspondence concerning this software should be addressed as follows:
|
|---|
| 22 | //# Internet email: Malte.Marquarding@csiro.au
|
|---|
| 23 | //# Postal address: Malte Marquarding,
|
|---|
| 24 | //# Australia Telescope National Facility,
|
|---|
| 25 | //# P.O. Box 76,
|
|---|
| 26 | //# Epping, NSW, 2121,
|
|---|
| 27 | //# AUSTRALIA
|
|---|
| 28 | //#
|
|---|
| 29 | //# $Id:
|
|---|
| 30 | //#---------------------------------------------------------------------------
|
|---|
| 31 | #ifndef SDMEMTABLEWRAPPER_H
|
|---|
| 32 | #define SDMEMTABLEWRAPPER_H
|
|---|
| 33 |
|
|---|
| 34 | #include <vector>
|
|---|
| 35 | #include <string>
|
|---|
| 36 | #include <casa/Arrays/Vector.h>
|
|---|
| 37 |
|
|---|
| 38 | #include "MathUtils.h"
|
|---|
| 39 | #include "SDFitTable.h"
|
|---|
| 40 | #include "SDMemTable.h"
|
|---|
| 41 |
|
|---|
| 42 | namespace asap {
|
|---|
| 43 |
|
|---|
| 44 | class SDMemTableWrapper {
|
|---|
| 45 |
|
|---|
| 46 | public:
|
|---|
| 47 | SDMemTableWrapper(const std::string& name) :
|
|---|
| 48 | table_(new SDMemTable(name)) {;}
|
|---|
| 49 | SDMemTableWrapper() :
|
|---|
| 50 | table_(new SDMemTable()) {;}
|
|---|
| 51 |
|
|---|
| 52 | SDMemTableWrapper(casa::CountedPtr<SDMemTable> cp) : table_(cp) {;}
|
|---|
| 53 | //SDMemTableWrapper(SDMemTable* sdmt) : table_(sdmt) {;}
|
|---|
| 54 | SDMemTableWrapper(const SDMemTableWrapper& mt) :
|
|---|
| 55 | table_(mt.getCP()) {;}
|
|---|
| 56 |
|
|---|
| 57 | SDMemTableWrapper(const SDMemTableWrapper& mt, const std::string& expr) :
|
|---|
| 58 | table_(new SDMemTable(mt.getCP()->table(), expr)) {;}
|
|---|
| 59 |
|
|---|
| 60 | SDMemTableWrapper copy() {
|
|---|
| 61 | //CountedPtr<SDMemTable> cp = new SDMemTable(*this, False);
|
|---|
| 62 | return SDMemTableWrapper(new SDMemTable(*(this->getCP()), casa::False));
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | SDMemTableWrapper getScan(std::vector<int> scan) {
|
|---|
| 66 | casa::String cond("SELECT FROM $1 WHERE SCANID IN ");
|
|---|
| 67 | casa::Vector<casa::Int> v(scan);
|
|---|
| 68 | casa::ostringstream oss;
|
|---|
| 69 | oss << v;
|
|---|
| 70 | cond += casa::String(oss);
|
|---|
| 71 | return SDMemTableWrapper(*this, cond);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | SDMemTableWrapper getSource(const std::string& source) {
|
|---|
| 75 | casa::String cond("SELECT * from $1 WHERE SRCNAME == pattern('");
|
|---|
| 76 | cond += source;cond += "')";
|
|---|
| 77 | return SDMemTableWrapper(*this, cond);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | SDMemTableWrapper getSQL(const std::string& sqlexpr) {
|
|---|
| 81 | return SDMemTableWrapper(*this, sqlexpr);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | std::vector<float> getSpectrum(int whichRow=0) const {
|
|---|
| 85 | return table_->getSpectrum(whichRow);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | std::vector<float> getStokesSpectrum(int whichRow=0,
|
|---|
| 89 | bool linPol=false) const {
|
|---|
| 90 | return table_->getStokesSpectrum(whichRow, linPol);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | std::vector<float> stokesToPolSpectrum(int whichRow=0, bool linear=false,
|
|---|
| 94 | int polIdx=-1) const {
|
|---|
| 95 | return table_->stokesToPolSpectrum(whichRow, linear, polIdx);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | // std::string getPolarizationLabel(bool linear, bool stokes, bool linPol, int polIdx) const {
|
|---|
| 99 | // Boost fails with 4 arguments.
|
|---|
| 100 | std::string getPolarizationLabel(bool linear, bool stokes,
|
|---|
| 101 | bool linPol) const {
|
|---|
| 102 | int polIdx = -1;
|
|---|
| 103 | return table_->getPolarizationLabel(linear, stokes, linPol, polIdx);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | std::vector<double> getAbcissa(int whichRow=0) const {
|
|---|
| 107 | return table_->getAbcissa(whichRow);
|
|---|
| 108 | }
|
|---|
| 109 | std::string getAbcissaString(int whichRow=0) const {
|
|---|
| 110 | return table_->getAbcissaString(whichRow);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | std::vector<float> getTsys() {
|
|---|
| 114 | int nRow = table_->nRow();
|
|---|
| 115 | std::vector<float> result(nRow);
|
|---|
| 116 | for (uint i=0; i<nRow; i++) {
|
|---|
| 117 | result[i] = table_->getTsys(i);
|
|---|
| 118 | }
|
|---|
| 119 | return result;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | std::string getTime(int whichRow=0) {return table_->getTime(whichRow);}
|
|---|
| 123 |
|
|---|
| 124 | std::string getFluxUnit() const {return table_->getFluxUnit();}
|
|---|
| 125 | void setFluxUnit(const std::string& unit) {table_->setFluxUnit(unit);}
|
|---|
| 126 |
|
|---|
| 127 | void setInstrument(const std::string& name) {table_->setInstrument(name);}
|
|---|
| 128 |
|
|---|
| 129 | std::vector<bool> getMask(int whichRow=0) const {
|
|---|
| 130 | return table_->getMask(whichRow);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | void flagSpectrum(const std::vector<bool>& flags, int whichRow=-1) {
|
|---|
| 134 | table_->flagSpectrum(flags, whichRow);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | std::string getSourceName(int whichRow=0) {
|
|---|
| 138 | return table_->getSourceName(whichRow);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | float getElevation(int whichRow=0) {
|
|---|
| 142 | return table_->getElevation(whichRow);
|
|---|
| 143 | }
|
|---|
| 144 | float getAzimuth(int whichRow=0) {
|
|---|
| 145 | return table_->getAzimuth(whichRow);
|
|---|
| 146 | }
|
|---|
| 147 | float getParAngle(int whichRow=0) {
|
|---|
| 148 | return table_->getParAngle(whichRow);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | void setSpectrum(std::vector<float> spectrum, int whichRow=0) {
|
|---|
| 152 | table_->setSpectrum(spectrum, whichRow);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | bool setIF(int whichIF=0) {return table_->setIF(whichIF);}
|
|---|
| 156 | bool setBeam(int whichBeam=0) {return table_->setBeam(whichBeam);}
|
|---|
| 157 | bool setPol(int whichPol=0) {return table_->setPol(whichPol);}
|
|---|
| 158 |
|
|---|
| 159 | int getIF() {return table_->getIF();}
|
|---|
| 160 | int getBeam() {return table_->getBeam();}
|
|---|
| 161 | int getPol() {return table_->getPol();}
|
|---|
| 162 |
|
|---|
| 163 | int nIF() {return table_->nIF();}
|
|---|
| 164 | int nBeam() {return table_->nBeam();}
|
|---|
| 165 | int nPol() {return table_->nPol();}
|
|---|
| 166 | int nChan() {return table_->nChan();}
|
|---|
| 167 | int nScan() {return table_->nScan();}
|
|---|
| 168 | int nRow() {return table_->nRow();}
|
|---|
| 169 | int nStokes() {return table_->nStokes();}
|
|---|
| 170 |
|
|---|
| 171 | //sets the mask
|
|---|
| 172 | bool setChannels(const std::vector<int>& whichChans) {
|
|---|
| 173 | return setChannels(whichChans);
|
|---|
| 174 | }
|
|---|
| 175 | void makePersistent(const std::string& fname) {
|
|---|
| 176 | table_->makePersistent(fname);
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | bool setRestFreqs(const std::vector<double>& restfreqs,
|
|---|
| 180 | const std::string& unit,
|
|---|
| 181 | const std::vector<std::string>& lines,
|
|---|
| 182 | const std::string& source, int whichIF) {
|
|---|
| 183 | casa::Vector<casa::Double> restFreqs2(restfreqs);
|
|---|
| 184 | return table_->setRestFreqs(restFreqs2, casa::String(unit),
|
|---|
| 185 | lines, casa::String(source),
|
|---|
| 186 | casa::Int(whichIF));
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | std::string spectralLines() const {return table_->spectralLines();}
|
|---|
| 190 |
|
|---|
| 191 | std::vector<double> getRestFreqs() {
|
|---|
| 192 | return table_->getRestFreqs();
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | void setCoordInfo(std::vector<string> theinfo) {
|
|---|
| 196 | table_->setCoordInfo(theinfo);
|
|---|
| 197 | }
|
|---|
| 198 | std::vector<string> getCoordInfo() const {
|
|---|
| 199 | return table_->getCoordInfo();
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | casa::CountedPtr<SDMemTable> getCP() const {return table_;}
|
|---|
| 203 | SDMemTable* getPtr() {return &(*table_);}
|
|---|
| 204 |
|
|---|
| 205 | std::string summary(bool verbose=false) const {
|
|---|
| 206 | return table_->summary(verbose);
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | std::vector<std::string> getHistory() {
|
|---|
| 210 | return table_->getHistory();
|
|---|
| 211 | }
|
|---|
| 212 | void addHistory(const std::string& hist) {
|
|---|
| 213 | table_->addHistory(hist);
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | void addFit(int whichRow, const std::vector<double>& p,
|
|---|
| 217 | const std::vector<bool>& m, const std::vector<string>& f,
|
|---|
| 218 | const std::vector<int>& c) {
|
|---|
| 219 |
|
|---|
| 220 | casa::Vector<casa::Double> p2(p);
|
|---|
| 221 | casa::Vector<casa::Bool> m2(m);
|
|---|
| 222 | casa::Vector<casa::String> f2 = mathutil::toVectorString(f);
|
|---|
| 223 | casa::Vector<casa::Int> c2(c);
|
|---|
| 224 | table_->addFit(casa::uInt(whichRow), p2,m2,f2,c2);
|
|---|
| 225 | }
|
|---|
| 226 | SDFitTable getSDFitTable(int whichRow) {
|
|---|
| 227 | return table_->getSDFitTable(casa::uInt(whichRow));
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | void calculateAZEL() { table_->calculateAZEL(); };
|
|---|
| 231 |
|
|---|
| 232 | private:
|
|---|
| 233 | casa::CountedPtr<SDMemTable> table_;
|
|---|
| 234 | };
|
|---|
| 235 |
|
|---|
| 236 | } // namespace
|
|---|
| 237 | #endif
|
|---|
| 238 |
|
|---|