source: trunk/src/STFit.cpp @ 3084

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

New Development: No

JIRA Issue: No

Ready for Test: Yes

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...


Get rid of warnings from table module that warns the change of the location of some header files.

  • 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
27
28using namespace casa;
29
30namespace asap {
31
32const casa::String STFit::name_ = "FIT";
33
34STFit::STFit(const Scantable& parent) :
35  STSubTable( parent, name_ )
36{
37  setup();
38}
39
40STFit& asap::STFit::operator =( const STFit & other )
41{
42  if ( this != &other ) {
43    static_cast<STSubTable&>(*this) = other;
44    funcCol_.attach(table_,"FUNCTIONS");
45    compCol_.attach(table_,"COMPONENTS");
46    parCol_.attach(table_,"PARAMETERS");
47    maskCol_.attach(table_,"PARMASKS");
48    frameCol_.attach(table_,"FRAMEINFO");
49  }
50  return *this;
51}
52
53asap::STFit::STFit( casa::Table tab ) : STSubTable(tab, name_)
54{
55    funcCol_.attach(table_,"FUNCTIONS");
56    compCol_.attach(table_,"COMPONENTS");
57    parCol_.attach(table_,"PARAMETERS");
58    maskCol_.attach(table_,"PARMASKS");
59    frameCol_.attach(table_,"FRAMEINFO");
60}
61
62STFit::~STFit()
63{
64}
65
66void asap::STFit::setup( )
67{
68  // add to base class table
69  table_.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
70  table_.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
71  table_.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
72  //  table_.addColumn(ArrayColumnDesc<Double>("ERRORS"));
73  table_.addColumn(ArrayColumnDesc<Bool>("PARMASKS"));
74  table_.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
75
76  // new cached columns
77  funcCol_.attach(table_,"FUNCTIONS");
78  compCol_.attach(table_,"COMPONENTS");
79  parCol_.attach(table_,"PARAMETERS");
80  //  errCol_.attach(table_,"ERRORS");
81  maskCol_.attach(table_,"PARMASKS");
82  frameCol_.attach(table_,"FRAMEINFO");
83}
84
85uInt STFit::addEntry( const STFitEntry& fit, Int id )
86{
87  uInt rno = table_.nrow();
88  uInt resultid = 0;
89  bool foundentry = false;
90  // replace
91  if ( id > -1 ) {
92    Table t = table_(table_.col("ID") == id, 1 );
93    if (t.nrow() > 0) {
94      rno = t.rowNumbers(table_)[0];
95      resultid = id;
96      foundentry = true;
97    }
98  }
99  // doesn't exist
100  if ( rno > 0  && !foundentry ) {
101    idCol_.get(rno-1, resultid);
102    resultid++;
103  }
104  // add new row if new id
105  if ( !foundentry ) table_.addRow();
106
107  funcCol_.put(rno, mathutil::toVectorString(fit.getFunctions()));
108  compCol_.put(rno, Vector<Int>(fit.getComponents()));
109  const std::vector<float>& pvec = fit.getParameters();
110  Vector<Double> dvec(pvec.size());
111  for (size_t i=0; i < dvec.nelements(); ++i) {
112    dvec[i] = Double(pvec[i]);
113  }
114  parCol_.put(rno, dvec);
115  /*
116  const std::vector<double>& evec = fit.getErrors();
117  for (size_t i=0; i < dvec.nelements(); ++i) {
118    dvec[i] = Double(evec[i]);
119  }
120  errCol_.put(rno, dvec);
121  */
122  maskCol_.put(rno, Vector<Bool>(fit.getParmasks()));
123  frameCol_.put(rno, mathutil::toVectorString(fit.getFrameinfo()));
124  idCol_.put(rno, resultid);
125
126  return resultid;
127}
128
129void STFit::getEntry( STFitEntry& fit, uInt id ) const
130{
131  Table t = table_(table_.col("ID") == Int(id), 1 );
132  if (t.nrow() == 0 ) {
133    throw(AipsError("STFit::getEntry - id out of range"));
134  }
135  ROTableRow row(t);
136  // get first row - there should only be one matching id
137  const TableRecord& rec = row.get(0);
138  std::vector<std::string> outstr;
139  Vector<String> vec;
140  rec.get("FUNCTIONS", vec);
141  fit.setFunctions(mathutil::tovectorstring(vec));
142  Vector<Int> ivec;
143  std::vector<int> istl;
144  rec.get("COMPONENTS", ivec);
145  ivec.tovector(istl);
146  fit.setComponents(istl);
147  Vector<Double> dvec;
148  rec.get("PARAMETERS", dvec);
149  std::vector<float> dstl(dvec.begin(), dvec.end());
150  fit.setParameters(dstl);
151  /*
152  dvec.tovector(dstl);
153  fit.setParameters(dstl);
154  dvec.resize();
155  rec.get("ERRORS", dvec);
156  dvec.tovector(dstl);
157  fit.setErrors(dstl);
158  */
159  Vector<Bool> bvec;
160  std::vector<bool> bstl;
161  rec.get("PARMASKS", bvec);
162  bvec.tovector(bstl);
163  fit.setParmasks(bstl);
164  vec.resize();
165  rec.get("FRAMEINFO", vec);
166  fit.setFrameinfo(mathutil::tovectorstring(vec));
167}
168
169} //namespace
Note: See TracBrowser for help on using the repository browser.