source: trunk/src/STFit.cpp@ 991

Last change on this file since 991 was 972, checked in by mar637, 19 years ago

Completed Ticket #7 - storing of fits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
RevLine 
[468]1
[960]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/Tables/TableParse.h>
20#include <tables/Tables/TableRow.h>
21#include <casa/Containers/RecordField.h>
22
[468]23#include "MathUtils.h"
[960]24#include "STFitEntry.h"
25#include "STFit.h"
[468]26
[960]27
[468]28using namespace casa;
29
[960]30namespace asap {
[468]31
[960]32const casa::String STFit::name_ = "FIT";
[468]33
[960]34STFit::STFit(const Scantable& parent) :
35 STSubTable( parent, name_ )
[468]36{
[960]37 setup();
[468]38}
39
[960]40STFit& asap::STFit::operator =( const STFit & other )
[468]41{
[960]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;
[468]51}
52
[960]53asap::STFit::STFit( casa::Table tab ) : STSubTable(tab, name_)
[468]54{
[960]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");
[468]60}
61
[960]62STFit::~STFit()
[468]63{
64}
65
[960]66void asap::STFit::setup( )
[468]67{
[960]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<Bool>("PARMASKS"));
73 table_.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
[468]74
[960]75 // new cached columns
76 funcCol_.attach(table_,"FUNCTIONS");
77 compCol_.attach(table_,"COMPONENTS");
78 parCol_.attach(table_,"PARAMETERS");
79 maskCol_.attach(table_,"PARMASKS");
80 frameCol_.attach(table_,"FRAMEINFO");
[468]81}
82
[960]83uInt STFit::addEntry( const STFitEntry& fit, Int id )
[468]84{
[960]85 uInt rno = table_.nrow();
[972]86 uInt resultid = 0;
[960]87 bool foundentry = false;
[972]88 // replace
[960]89 if ( id > -1 ) {
90 Table t = table_(table_.col("ID") == id );
91 if (t.nrow() > 0) {
92 rno = t.rowNumbers()[0];
93 resultid = id;
94 foundentry = true;
95 }
96 }
[972]97 // doesn't exist
[960]98 if ( rno > 0 && !foundentry ) {
99 idCol_.get(rno-1, resultid);
100 resultid++;
101 }
[972]102 // add new row if new id
103 if ( !foundentry ) table_.addRow();
104 cout << rno << " " << resultid << endl;
[960]105 funcCol_.put(rno, mathutil::toVectorString(fit.getFunctions()));
106 compCol_.put(rno, Vector<Int>(fit.getComponents()));
107 parCol_.put(rno, Vector<Double>(fit.getParameters()));
108 maskCol_.put(rno, Vector<Bool>(fit.getParmasks()));
109 frameCol_.put(rno, mathutil::toVectorString(fit.getFrameinfo()));
110 idCol_.put(rno, resultid);
111 return resultid;
[468]112}
113
[972]114void STFit::getEntry( STFitEntry& fit, uInt id ) const
[468]115{
[960]116 Table t = table_(table_.col("ID") == Int(id) );
117 if (t.nrow() == 0 ) {
118 throw(AipsError("STFit::getEntry - id out of range"));
119 }
120 ROTableRow row(t);
121 // get first row - there should only be one matching id
122 const TableRecord& rec = row.get(0);
123 std::vector<std::string> outstr;
124 Vector<String> vec;
125 rec.get("FUNCTIONS", vec);
126 fit.setFunctions(mathutil::tovectorstring(vec));
127 Vector<Int> ivec;
128 std::vector<int> istl;
129 rec.get("COMPONENTS", ivec);
130 ivec.tovector(istl);
131 fit.setComponents(istl);
132 Vector<Double> dvec;
133 std::vector<double> dstl;
134 rec.get("PARAMETERS", dvec);
135 dvec.tovector(dstl);
136 fit.setParameters(dstl);
137 Vector<Bool> bvec;
138 std::vector<bool> bstl;
139 rec.get("PARMASKS", bvec);
140 bvec.tovector(bstl);
141 fit.setParmasks(bstl);
142 vec.resize();
143 rec.get("FRAMEINFO", vec);
144 fit.setFrameinfo(mathutil::tovectorstring(vec));
[468]145}
146
[960]147} //namespace
Note: See TracBrowser for help on using the repository browser.