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 "SDMemTable.h"
|
---|
39 |
|
---|
40 | namespace asap {
|
---|
41 |
|
---|
42 | class SDMemTableWrapper {
|
---|
43 |
|
---|
44 | public:
|
---|
45 | SDMemTableWrapper(const std::string& name) :
|
---|
46 | table_(new SDMemTable(name)) {;}
|
---|
47 | SDMemTableWrapper() :
|
---|
48 | table_(new SDMemTable()) {;}
|
---|
49 |
|
---|
50 | SDMemTableWrapper(casa::CountedPtr<SDMemTable> cp) : table_(cp) {;}
|
---|
51 | //SDMemTableWrapper(SDMemTable* sdmt) : table_(sdmt) {;}
|
---|
52 | SDMemTableWrapper(const SDMemTableWrapper& mt) :
|
---|
53 | table_(mt.getCP()) {;}
|
---|
54 |
|
---|
55 | SDMemTableWrapper(const SDMemTableWrapper& mt, const std::string& expr) :
|
---|
56 | table_(new SDMemTable(mt.getCP()->table(), expr)) {;}
|
---|
57 |
|
---|
58 | SDMemTableWrapper copy() {
|
---|
59 | //CountedPtr<SDMemTable> cp = new SDMemTable(*this, False);
|
---|
60 | return SDMemTableWrapper(new SDMemTable(*(this->getCP()), casa::False));
|
---|
61 | }
|
---|
62 |
|
---|
63 | //SDMemTableWrapper getScan(int scan) {
|
---|
64 | SDMemTableWrapper getScan(std::vector<int> scan) {
|
---|
65 | casa::String cond("SELECT FROM $1 WHERE SCANID IN ");
|
---|
66 | casa::Vector<casa::Int> v(scan);
|
---|
67 | casa::ostringstream oss;
|
---|
68 | oss << v;
|
---|
69 | cond += casa::String(oss);
|
---|
70 | return SDMemTableWrapper(*this, cond);
|
---|
71 | }
|
---|
72 |
|
---|
73 | SDMemTableWrapper getSource(const std::string& source) {
|
---|
74 | casa::String cond("SELECT * from $1 WHERE SRCNAME == pattern('");
|
---|
75 | cond += source;cond += "')";
|
---|
76 | return SDMemTableWrapper(*this, cond);
|
---|
77 | }
|
---|
78 |
|
---|
79 | std::vector<float> getSpectrum(int whichRow=0) const {
|
---|
80 | return table_->getSpectrum(whichRow);
|
---|
81 | }
|
---|
82 |
|
---|
83 | std::vector<float> getStokesSpectrum(int whichRow=0, bool doPol=false,
|
---|
84 | float paOff=0.0) const {
|
---|
85 | return table_->getStokesSpectrum(whichRow, doPol, paOff);
|
---|
86 | }
|
---|
87 |
|
---|
88 | std::vector<float> getCircularSpectrum(int whichRow=0,
|
---|
89 | bool doRR=true) const {
|
---|
90 | return table_->getCircularSpectrum(whichRow, doRR);
|
---|
91 | }
|
---|
92 |
|
---|
93 | std::vector<double> getAbcissa(int whichRow=0) const {
|
---|
94 | return table_->getAbcissa(whichRow);
|
---|
95 | }
|
---|
96 | std::string getAbcissaString(int whichRow=0) const {
|
---|
97 | return table_->getAbcissaString(whichRow);
|
---|
98 | }
|
---|
99 |
|
---|
100 | std::vector<float> getTsys() {
|
---|
101 | int nRow = table_->nRow();
|
---|
102 | std::vector<float> result(nRow);
|
---|
103 | for (uint i=0; i<nRow; i++) {
|
---|
104 | result[i] = table_->getTsys(i);
|
---|
105 | }
|
---|
106 | return result;
|
---|
107 | }
|
---|
108 |
|
---|
109 | std::string getTime(int whichRow=0) {return table_->getTime(whichRow);}
|
---|
110 |
|
---|
111 | std::string getFluxUnit() const {return table_->getFluxUnit();}
|
---|
112 | void setFluxUnit(const std::string& unit) {table_->setFluxUnit(unit);}
|
---|
113 |
|
---|
114 | void setInstrument(const std::string& name) {table_->setInstrument(name);}
|
---|
115 |
|
---|
116 | std::vector<bool> getMask(int whichRow=0) const {
|
---|
117 | return table_->getMask(whichRow);
|
---|
118 | }
|
---|
119 | bool setMask(const std::vector<int> mvals) const {
|
---|
120 | return table_->setMask(mvals);
|
---|
121 | }
|
---|
122 |
|
---|
123 | void flag(int whichRow=-1) {
|
---|
124 | table_->flag(whichRow);
|
---|
125 | }
|
---|
126 | std::string getSourceName(int whichRow=0) {
|
---|
127 | return table_->getSourceName(whichRow);
|
---|
128 | }
|
---|
129 |
|
---|
130 | void setSpectrum(std::vector<float> spectrum, int whichRow=0) {
|
---|
131 | table_->setSpectrum(spectrum, whichRow);
|
---|
132 | }
|
---|
133 |
|
---|
134 | bool setIF(int whichIF=0) {return table_->setIF(whichIF);}
|
---|
135 | bool setBeam(int whichBeam=0) {return table_->setBeam(whichBeam);}
|
---|
136 | bool setPol(int whichPol=0) {return table_->setPol(whichPol);}
|
---|
137 |
|
---|
138 | int getIF() {return table_->getIF();}
|
---|
139 | int getBeam() {return table_->getBeam();}
|
---|
140 | int getPol() {return table_->getPol();}
|
---|
141 |
|
---|
142 | int nIF() {return table_->nIF();}
|
---|
143 | int nBeam() {return table_->nBeam();}
|
---|
144 | int nPol() {return table_->nPol();}
|
---|
145 | int nChan() {return table_->nChan();}
|
---|
146 | int nScan() {return table_->nScan();}
|
---|
147 | int nRow() {return table_->nRow();}
|
---|
148 |
|
---|
149 | //sets the mask
|
---|
150 | bool setChannels(const std::vector<int>& whichChans) {
|
---|
151 | return setChannels(whichChans);
|
---|
152 | }
|
---|
153 | void makePersistent(const std::string& fname) {
|
---|
154 | table_->makePersistent(fname);
|
---|
155 | }
|
---|
156 |
|
---|
157 | bool setRestFreqs(const std::vector<double>& restfreqs,
|
---|
158 | const std::string& unit,
|
---|
159 | const std::vector<std::string>& lines,
|
---|
160 | const std::string& source, int whichIF) {
|
---|
161 | casa::Vector<casa::Double> restFreqs2(restfreqs);
|
---|
162 | return table_->setRestFreqs(restFreqs2, casa::String(unit),
|
---|
163 | lines, casa::String(source),
|
---|
164 | casa::Int(whichIF));
|
---|
165 | }
|
---|
166 |
|
---|
167 | void spectralLines() const {table_->spectralLines();}
|
---|
168 |
|
---|
169 | std::vector<double> getRestFreqs() {
|
---|
170 | return table_->getRestFreqs();
|
---|
171 | }
|
---|
172 |
|
---|
173 | void setCoordInfo(std::vector<string> theinfo) {
|
---|
174 | table_->setCoordInfo(theinfo);
|
---|
175 | }
|
---|
176 | std::vector<string> getCoordInfo() const {
|
---|
177 | return table_->getCoordInfo();
|
---|
178 | }
|
---|
179 |
|
---|
180 | casa::CountedPtr<SDMemTable> getCP() const {return table_;}
|
---|
181 | SDMemTable* getPtr() {return &(*table_);}
|
---|
182 |
|
---|
183 | std::string summary(bool verbose=false) const {
|
---|
184 | return table_->summary(verbose);
|
---|
185 | }
|
---|
186 |
|
---|
187 | std::vector<std::string> history(int whichRow=0) {
|
---|
188 | return table_->history(whichRow);
|
---|
189 | }
|
---|
190 |
|
---|
191 | void addFit(int whichRow, const std::vector<double>& p,
|
---|
192 | const std::vector<bool>& m, const std::vector<string>& f,
|
---|
193 | const std::vector<int>& c) {
|
---|
194 |
|
---|
195 | casa::Vector<casa::Double> p2(p);
|
---|
196 | casa::Vector<casa::Bool> m2(m);
|
---|
197 | casa::Vector<casa::String> f2(f.size());
|
---|
198 | casa::uInt i=0;
|
---|
199 | std::vector<std::string>::const_iterator it;
|
---|
200 | for (it=f.begin();it != f.end();++it) {
|
---|
201 | f2[i] = casa::String(*it);
|
---|
202 | }
|
---|
203 | casa::Vector<casa::Int> c2(c);
|
---|
204 | table_->addFit(casa::uInt(whichRow), p2,m2,f2,c2);
|
---|
205 | }
|
---|
206 |
|
---|
207 | private:
|
---|
208 | casa::CountedPtr<SDMemTable> table_;
|
---|
209 | };
|
---|
210 |
|
---|
211 | } // namespace
|
---|
212 | #endif
|
---|
213 |
|
---|