[2] | 1 | //#---------------------------------------------------------------------------
|
---|
| 2 | //# SDMemTableWrapper.h: Wrapper classes to use CountedPtr
|
---|
| 3 | //#---------------------------------------------------------------------------
|
---|
| 4 | //# Copyright (C) 2004
|
---|
[125] | 5 | //# ATNF
|
---|
[2] | 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 | //#---------------------------------------------------------------------------
|
---|
[125] | 31 | #ifndef SDMEMTABLEWRAPPER_H
|
---|
| 32 | #define SDMEMTABLEWRAPPER_H
|
---|
[2] | 33 |
|
---|
| 34 | #include <vector>
|
---|
| 35 | #include <string>
|
---|
[380] | 36 | #include <casa/Arrays/Vector.h>
|
---|
[2] | 37 |
|
---|
[465] | 38 | #include "MathUtils.h"
|
---|
| 39 | #include "SDFitTable.h"
|
---|
[2] | 40 | #include "SDMemTable.h"
|
---|
| 41 |
|
---|
[83] | 42 | namespace asap {
|
---|
[2] | 43 |
|
---|
| 44 | class SDMemTableWrapper {
|
---|
| 45 |
|
---|
| 46 | public:
|
---|
[90] | 47 | SDMemTableWrapper(const std::string& name) :
|
---|
[2] | 48 | table_(new SDMemTable(name)) {;}
|
---|
[90] | 49 | SDMemTableWrapper() :
|
---|
[18] | 50 | table_(new SDMemTable()) {;}
|
---|
[90] | 51 |
|
---|
[125] | 52 | SDMemTableWrapper(casa::CountedPtr<SDMemTable> cp) : table_(cp) {;}
|
---|
[90] | 53 | //SDMemTableWrapper(SDMemTable* sdmt) : table_(sdmt) {;}
|
---|
| 54 | SDMemTableWrapper(const SDMemTableWrapper& mt) :
|
---|
| 55 | table_(mt.getCP()) {;}
|
---|
| 56 |
|
---|
[80] | 57 | SDMemTableWrapper(const SDMemTableWrapper& mt, const std::string& expr) :
|
---|
| 58 | table_(new SDMemTable(mt.getCP()->table(), expr)) {;}
|
---|
[90] | 59 |
|
---|
| 60 | SDMemTableWrapper copy() {
|
---|
| 61 | //CountedPtr<SDMemTable> cp = new SDMemTable(*this, False);
|
---|
[125] | 62 | return SDMemTableWrapper(new SDMemTable(*(this->getCP()), casa::False));
|
---|
[90] | 63 | }
|
---|
| 64 |
|
---|
[380] | 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);
|
---|
[80] | 71 | return SDMemTableWrapper(*this, cond);
|
---|
[2] | 72 | }
|
---|
[80] | 73 |
|
---|
| 74 | SDMemTableWrapper getSource(const std::string& source) {
|
---|
[186] | 75 | casa::String cond("SELECT * from $1 WHERE SRCNAME == pattern('");
|
---|
| 76 | cond += source;cond += "')";
|
---|
[80] | 77 | return SDMemTableWrapper(*this, cond);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[483] | 80 | SDMemTableWrapper getSQL(const std::string& sqlexpr) {
|
---|
| 81 | return SDMemTableWrapper(*this, sqlexpr);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[51] | 84 | std::vector<float> getSpectrum(int whichRow=0) const {
|
---|
[2] | 85 | return table_->getSpectrum(whichRow);
|
---|
| 86 | }
|
---|
[527] | 87 |
|
---|
[745] | 88 | std::vector<float> getStokesSpectrum(int whichRow=0,
|
---|
| 89 | bool linPol=false) const {
|
---|
[505] | 90 | return table_->getStokesSpectrum(whichRow, linPol);
|
---|
[421] | 91 | }
|
---|
| 92 |
|
---|
[539] | 93 | std::vector<float> stokesToPolSpectrum(int whichRow=0, bool linear=false,
|
---|
[745] | 94 | int polIdx=-1) const {
|
---|
[494] | 95 | return table_->stokesToPolSpectrum(whichRow, linear, polIdx);
|
---|
[431] | 96 | }
|
---|
| 97 |
|
---|
[527] | 98 | // std::string getPolarizationLabel(bool linear, bool stokes, bool linPol, int polIdx) const {
|
---|
| 99 | // Boost fails with 4 arguments.
|
---|
[745] | 100 | std::string getPolarizationLabel(bool linear, bool stokes,
|
---|
| 101 | bool linPol) const {
|
---|
[527] | 102 | int polIdx = -1;
|
---|
| 103 | return table_->getPolarizationLabel(linear, stokes, linPol, polIdx);
|
---|
[494] | 104 | }
|
---|
[527] | 105 |
|
---|
[158] | 106 | std::vector<double> getAbcissa(int whichRow=0) const {
|
---|
| 107 | return table_->getAbcissa(whichRow);
|
---|
[41] | 108 | }
|
---|
[158] | 109 | std::string getAbcissaString(int whichRow=0) const {
|
---|
| 110 | return table_->getAbcissaString(whichRow);
|
---|
[105] | 111 | }
|
---|
[41] | 112 |
|
---|
[157] | 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 |
|
---|
[51] | 122 | std::string getTime(int whichRow=0) {return table_->getTime(whichRow);}
|
---|
[2] | 123 |
|
---|
[207] | 124 | std::string getFluxUnit() const {return table_->getFluxUnit();}
|
---|
[220] | 125 | void setFluxUnit(const std::string& unit) {table_->setFluxUnit(unit);}
|
---|
[207] | 126 |
|
---|
[238] | 127 | void setInstrument(const std::string& name) {table_->setInstrument(name);}
|
---|
| 128 |
|
---|
[90] | 129 | std::vector<bool> getMask(int whichRow=0) const {
|
---|
| 130 | return table_->getMask(whichRow);
|
---|
[16] | 131 | }
|
---|
[2] | 132 |
|
---|
[90] | 133 | void flag(int whichRow=-1) {
|
---|
| 134 | table_->flag(whichRow);
|
---|
| 135 | }
|
---|
[51] | 136 | std::string getSourceName(int whichRow=0) {
|
---|
[2] | 137 | return table_->getSourceName(whichRow);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[90] | 140 | void setSpectrum(std::vector<float> spectrum, int whichRow=0) {
|
---|
| 141 | table_->setSpectrum(spectrum, whichRow);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[2] | 144 | bool setIF(int whichIF=0) {return table_->setIF(whichIF);}
|
---|
| 145 | bool setBeam(int whichBeam=0) {return table_->setBeam(whichBeam);}
|
---|
[90] | 146 | bool setPol(int whichPol=0) {return table_->setPol(whichPol);}
|
---|
[2] | 147 |
|
---|
| 148 | int getIF() {return table_->getIF();}
|
---|
| 149 | int getBeam() {return table_->getBeam();}
|
---|
[90] | 150 | int getPol() {return table_->getPol();}
|
---|
[2] | 151 |
|
---|
[18] | 152 | int nIF() {return table_->nIF();}
|
---|
| 153 | int nBeam() {return table_->nBeam();}
|
---|
[90] | 154 | int nPol() {return table_->nPol();}
|
---|
| 155 | int nChan() {return table_->nChan();}
|
---|
| 156 | int nScan() {return table_->nScan();}
|
---|
| 157 | int nRow() {return table_->nRow();}
|
---|
[494] | 158 | int nStokes() {return table_->nStokes();}
|
---|
[2] | 159 |
|
---|
| 160 | //sets the mask
|
---|
| 161 | bool setChannels(const std::vector<int>& whichChans) {
|
---|
[90] | 162 | return setChannels(whichChans);
|
---|
[2] | 163 | }
|
---|
| 164 | void makePersistent(const std::string& fname) {
|
---|
| 165 | table_->makePersistent(fname);
|
---|
| 166 | }
|
---|
[90] | 167 |
|
---|
[745] | 168 | bool setRestFreqs(const std::vector<double>& restfreqs,
|
---|
| 169 | const std::string& unit,
|
---|
[401] | 170 | const std::vector<std::string>& lines,
|
---|
| 171 | const std::string& source, int whichIF) {
|
---|
[392] | 172 | casa::Vector<casa::Double> restFreqs2(restfreqs);
|
---|
| 173 | return table_->setRestFreqs(restFreqs2, casa::String(unit),
|
---|
[401] | 174 | lines, casa::String(source),
|
---|
[392] | 175 | casa::Int(whichIF));
|
---|
[90] | 176 | }
|
---|
[401] | 177 |
|
---|
[745] | 178 | std::string spectralLines() const {return table_->spectralLines();}
|
---|
| 179 |
|
---|
[251] | 180 | std::vector<double> getRestFreqs() {
|
---|
| 181 | return table_->getRestFreqs();
|
---|
| 182 | }
|
---|
| 183 |
|
---|
[105] | 184 | void setCoordInfo(std::vector<string> theinfo) {
|
---|
| 185 | table_->setCoordInfo(theinfo);
|
---|
| 186 | }
|
---|
| 187 | std::vector<string> getCoordInfo() const {
|
---|
| 188 | return table_->getCoordInfo();
|
---|
| 189 | }
|
---|
[90] | 190 |
|
---|
[125] | 191 | casa::CountedPtr<SDMemTable> getCP() const {return table_;}
|
---|
[138] | 192 | SDMemTable* getPtr() {return &(*table_);}
|
---|
[380] | 193 |
|
---|
[745] | 194 | std::string summary(bool verbose=false) const {
|
---|
| 195 | return table_->summary(verbose);
|
---|
[380] | 196 | }
|
---|
[745] | 197 |
|
---|
| 198 | std::vector<std::string> getHistory() {
|
---|
| 199 | return table_->getHistory();
|
---|
[207] | 200 | }
|
---|
[745] | 201 | void addHistory(const std::string& hist) {
|
---|
| 202 | table_->addHistory(hist);
|
---|
[483] | 203 | }
|
---|
[207] | 204 |
|
---|
[455] | 205 | void addFit(int whichRow, const std::vector<double>& p,
|
---|
[745] | 206 | const std::vector<bool>& m, const std::vector<string>& f,
|
---|
| 207 | const std::vector<int>& c) {
|
---|
| 208 |
|
---|
[455] | 209 | casa::Vector<casa::Double> p2(p);
|
---|
[745] | 210 | casa::Vector<casa::Bool> m2(m);
|
---|
[465] | 211 | casa::Vector<casa::String> f2 = mathutil::toVectorString(f);
|
---|
[455] | 212 | casa::Vector<casa::Int> c2(c);
|
---|
| 213 | table_->addFit(casa::uInt(whichRow), p2,m2,f2,c2);
|
---|
| 214 | }
|
---|
[465] | 215 | SDFitTable getSDFitTable(int whichRow) {
|
---|
| 216 | return table_->getSDFitTable(casa::uInt(whichRow));
|
---|
| 217 | }
|
---|
[455] | 218 |
|
---|
[777] | 219 | void calculateAZEL() { table_->calculateAZEL(); };
|
---|
[465] | 220 |
|
---|
[2] | 221 | private:
|
---|
[125] | 222 | casa::CountedPtr<SDMemTable> table_;
|
---|
[2] | 223 | };
|
---|
| 224 |
|
---|
| 225 | } // namespace
|
---|
| 226 | #endif
|
---|
[421] | 227 |
|
---|