source: trunk/src/STFit.cpp@ 3145

Last change on this file since 3145 was 3106, checked in by Takeshi Nakazato, 8 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes/No

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...


Check-in asap modifications from Jim regarding casacore namespace conversion.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1
2//
3// C++ Implementation: STFit
4//
5// Description:
6//
7//
8// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
9//
10// Copyright: See COPYING file that comes with this distribution
11//
12//
13#include <casa/Exceptions/Error.h>
14#include <tables/Tables/TableDesc.h>
15#include <tables/Tables/SetupNewTab.h>
16#include <tables/Tables/ScaColDesc.h>
17#include <tables/Tables/ArrColDesc.h>
18#include <tables/Tables/TableRecord.h>
19#include <tables/TaQL/TableParse.h>
20#include <tables/Tables/TableRow.h>
21#include <casa/Containers/RecordField.h>
22
23#include "MathUtils.h"
24#include "STFitEntry.h"
25#include "STFit.h"
26
27using namespace casacore;
28
29namespace asap {
30
31const String STFit::name_ = "FIT";
32
33STFit::STFit(const Scantable& parent) :
34 STSubTable( parent, name_ )
35{
36 setup();
37}
38
39STFit& asap::STFit::operator =( const STFit & other )
40{
41 if ( this != &other ) {
42 static_cast<STSubTable&>(*this) = other;
43 funcCol_.attach(table_,"FUNCTIONS");
44 compCol_.attach(table_,"COMPONENTS");
45 parCol_.attach(table_,"PARAMETERS");
46 maskCol_.attach(table_,"PARMASKS");
47 frameCol_.attach(table_,"FRAMEINFO");
48 }
49 return *this;
50}
51
52asap::STFit::STFit( casacore::Table tab ) : STSubTable(tab, name_)
53{
54 funcCol_.attach(table_,"FUNCTIONS");
55 compCol_.attach(table_,"COMPONENTS");
56 parCol_.attach(table_,"PARAMETERS");
57 maskCol_.attach(table_,"PARMASKS");
58 frameCol_.attach(table_,"FRAMEINFO");
59}
60
61STFit::~STFit()
62{
63}
64
65void asap::STFit::setup( )
66{
67 // add to base class table
68 table_.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
69 table_.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
70 table_.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
71 // table_.addColumn(ArrayColumnDesc<Double>("ERRORS"));
72 table_.addColumn(ArrayColumnDesc<Bool>("PARMASKS"));
73 table_.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
74
75 // new cached columns
76 funcCol_.attach(table_,"FUNCTIONS");
77 compCol_.attach(table_,"COMPONENTS");
78 parCol_.attach(table_,"PARAMETERS");
79 // errCol_.attach(table_,"ERRORS");
80 maskCol_.attach(table_,"PARMASKS");
81 frameCol_.attach(table_,"FRAMEINFO");
82}
83
84uInt STFit::addEntry( const STFitEntry& fit, Int id )
85{
86 uInt rno = table_.nrow();
87 uInt resultid = 0;
88 bool foundentry = false;
89 // replace
90 if ( id > -1 ) {
91 Table t = table_(table_.col("ID") == id, 1 );
92 if (t.nrow() > 0) {
93 rno = t.rowNumbers(table_)[0];
94 resultid = id;
95 foundentry = true;
96 }
97 }
98 // doesn't exist
99 if ( rno > 0 && !foundentry ) {
100 idCol_.get(rno-1, resultid);
101 resultid++;
102 }
103 // add new row if new id
104 if ( !foundentry ) table_.addRow();
105
106 funcCol_.put(rno, mathutil::toVectorString(fit.getFunctions()));
107 compCol_.put(rno, Vector<Int>(fit.getComponents()));
108 const std::vector<float>& pvec = fit.getParameters();
109 Vector<Double> dvec(pvec.size());
110 for (size_t i=0; i < dvec.nelements(); ++i) {
111 dvec[i] = Double(pvec[i]);
112 }
113 parCol_.put(rno, dvec);
114 /*
115 const std::vector<double>& evec = fit.getErrors();
116 for (size_t i=0; i < dvec.nelements(); ++i) {
117 dvec[i] = Double(evec[i]);
118 }
119 errCol_.put(rno, dvec);
120 */
121 maskCol_.put(rno, Vector<Bool>(fit.getParmasks()));
122 frameCol_.put(rno, mathutil::toVectorString(fit.getFrameinfo()));
123 idCol_.put(rno, resultid);
124
125 return resultid;
126}
127
128void STFit::getEntry( STFitEntry& fit, uInt id ) const
129{
130 Table t = table_(table_.col("ID") == Int(id), 1 );
131 if (t.nrow() == 0 ) {
132 throw(AipsError("STFit::getEntry - id out of range"));
133 }
134 ROTableRow row(t);
135 // get first row - there should only be one matching id
136 const TableRecord& rec = row.get(0);
137 std::vector<std::string> outstr;
138 Vector<String> vec;
139 rec.get("FUNCTIONS", vec);
140 fit.setFunctions(mathutil::tovectorstring(vec));
141 Vector<Int> ivec;
142 std::vector<int> istl;
143 rec.get("COMPONENTS", ivec);
144 ivec.tovector(istl);
145 fit.setComponents(istl);
146 Vector<Double> dvec;
147 rec.get("PARAMETERS", dvec);
148 std::vector<float> dstl(dvec.begin(), dvec.end());
149 fit.setParameters(dstl);
150 /*
151 dvec.tovector(dstl);
152 fit.setParameters(dstl);
153 dvec.resize();
154 rec.get("ERRORS", dvec);
155 dvec.tovector(dstl);
156 fit.setErrors(dstl);
157 */
158 Vector<Bool> bvec;
159 std::vector<bool> bstl;
160 rec.get("PARMASKS", bvec);
161 bvec.tovector(bstl);
162 fit.setParmasks(bstl);
163 vec.resize();
164 rec.get("FRAMEINFO", vec);
165 fit.setFrameinfo(mathutil::tovectorstring(vec));
166}
167
168} //namespace
Note: See TracBrowser for help on using the repository browser.