source: trunk/src/SDMemTableWrapper.h@ 475

Last change on this file since 475 was 465, checked in by mar637, 20 years ago

Added SDFitTable to handle fits and expose them to python vi the sdfit class.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
RevLine 
[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]42namespace asap {
[2]43
44class SDMemTableWrapper {
45
46public:
[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(int scan) {
66 SDMemTableWrapper getScan(std::vector<int> scan) {
67 casa::String cond("SELECT FROM $1 WHERE SCANID IN ");
68 casa::Vector<casa::Int> v(scan);
69 casa::ostringstream oss;
70 oss << v;
71 cond += casa::String(oss);
[80]72 return SDMemTableWrapper(*this, cond);
[2]73 }
[80]74
75 SDMemTableWrapper getSource(const std::string& source) {
[186]76 casa::String cond("SELECT * from $1 WHERE SRCNAME == pattern('");
77 cond += source;cond += "')";
[80]78 return SDMemTableWrapper(*this, cond);
79 }
80
[51]81 std::vector<float> getSpectrum(int whichRow=0) const {
[2]82 return table_->getSpectrum(whichRow);
83 }
[41]84
[455]85 std::vector<float> getStokesSpectrum(int whichRow=0, bool doPol=false,
86 float paOff=0.0) const {
[426]87 return table_->getStokesSpectrum(whichRow, doPol, paOff);
[421]88 }
89
[455]90 std::vector<float> getCircularSpectrum(int whichRow=0,
91 bool doRR=true) const {
[431]92 return table_->getCircularSpectrum(whichRow, doRR);
93 }
94
[158]95 std::vector<double> getAbcissa(int whichRow=0) const {
96 return table_->getAbcissa(whichRow);
[41]97 }
[158]98 std::string getAbcissaString(int whichRow=0) const {
99 return table_->getAbcissaString(whichRow);
[105]100 }
[41]101
[157]102 std::vector<float> getTsys() {
103 int nRow = table_->nRow();
104 std::vector<float> result(nRow);
105 for (uint i=0; i<nRow; i++) {
106 result[i] = table_->getTsys(i);
107 }
108 return result;
109 }
110
[51]111 std::string getTime(int whichRow=0) {return table_->getTime(whichRow);}
[2]112
[207]113 std::string getFluxUnit() const {return table_->getFluxUnit();}
[220]114 void setFluxUnit(const std::string& unit) {table_->setFluxUnit(unit);}
[207]115
[238]116 void setInstrument(const std::string& name) {table_->setInstrument(name);}
117
[90]118 std::vector<bool> getMask(int whichRow=0) const {
119 return table_->getMask(whichRow);
[16]120 }
[90]121 bool setMask(const std::vector<int> mvals) const {
122 return table_->setMask(mvals);
123 }
[2]124
[90]125 void flag(int whichRow=-1) {
126 table_->flag(whichRow);
127 }
[51]128 std::string getSourceName(int whichRow=0) {
[2]129 return table_->getSourceName(whichRow);
130 }
131
[90]132 void setSpectrum(std::vector<float> spectrum, int whichRow=0) {
133 table_->setSpectrum(spectrum, whichRow);
134 }
135
[2]136 bool setIF(int whichIF=0) {return table_->setIF(whichIF);}
137 bool setBeam(int whichBeam=0) {return table_->setBeam(whichBeam);}
[90]138 bool setPol(int whichPol=0) {return table_->setPol(whichPol);}
[2]139
140 int getIF() {return table_->getIF();}
141 int getBeam() {return table_->getBeam();}
[90]142 int getPol() {return table_->getPol();}
[2]143
[18]144 int nIF() {return table_->nIF();}
145 int nBeam() {return table_->nBeam();}
[90]146 int nPol() {return table_->nPol();}
147 int nChan() {return table_->nChan();}
148 int nScan() {return table_->nScan();}
149 int nRow() {return table_->nRow();}
[2]150
151 //sets the mask
152 bool setChannels(const std::vector<int>& whichChans) {
[90]153 return setChannels(whichChans);
[2]154 }
155 void makePersistent(const std::string& fname) {
156 table_->makePersistent(fname);
157 }
[90]158
[401]159 bool setRestFreqs(const std::vector<double>& restfreqs,
160 const std::string& unit,
161 const std::vector<std::string>& lines,
162 const std::string& source, int whichIF) {
[392]163 casa::Vector<casa::Double> restFreqs2(restfreqs);
164 return table_->setRestFreqs(restFreqs2, casa::String(unit),
[401]165 lines, casa::String(source),
[392]166 casa::Int(whichIF));
[90]167 }
[251]168
[401]169 void spectralLines() const {table_->spectralLines();}
170
[251]171 std::vector<double> getRestFreqs() {
172 return table_->getRestFreqs();
173 }
174
[105]175 void setCoordInfo(std::vector<string> theinfo) {
176 table_->setCoordInfo(theinfo);
177 }
178 std::vector<string> getCoordInfo() const {
179 return table_->getCoordInfo();
180 }
[90]181
[125]182 casa::CountedPtr<SDMemTable> getCP() const {return table_;}
[138]183 SDMemTable* getPtr() {return &(*table_);}
[380]184
185 std::string summary(bool verbose=false) const {
186 return table_->summary(verbose);
187 }
[186]188
[207]189 std::vector<std::string> history(int whichRow=0) {
190 return table_->history(whichRow);
191 }
192
[455]193 void addFit(int whichRow, const std::vector<double>& p,
194 const std::vector<bool>& m, const std::vector<string>& f,
195 const std::vector<int>& c) {
196
197 casa::Vector<casa::Double> p2(p);
198 casa::Vector<casa::Bool> m2(m);
[465]199 casa::Vector<casa::String> f2 = mathutil::toVectorString(f);
[455]200 casa::Vector<casa::Int> c2(c);
201 table_->addFit(casa::uInt(whichRow), p2,m2,f2,c2);
202 }
[465]203 SDFitTable getSDFitTable(int whichRow) {
204 return table_->getSDFitTable(casa::uInt(whichRow));
205 }
[455]206
[465]207
[2]208private:
[125]209 casa::CountedPtr<SDMemTable> table_;
[2]210};
211
212} // namespace
213#endif
[421]214
Note: See TracBrowser for help on using the repository browser.