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/Tables/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 |
|
---|
28 | using namespace casa;
|
---|
29 |
|
---|
30 | namespace asap {
|
---|
31 |
|
---|
32 | const casa::String STFit::name_ = "FIT";
|
---|
33 |
|
---|
34 | STFit::STFit(const Scantable& parent) :
|
---|
35 | STSubTable( parent, name_ )
|
---|
36 | {
|
---|
37 | setup();
|
---|
38 | }
|
---|
39 |
|
---|
40 | STFit& 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 |
|
---|
53 | asap::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 |
|
---|
62 | STFit::~STFit()
|
---|
63 | {
|
---|
64 | }
|
---|
65 |
|
---|
66 | void 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<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 | maskCol_.attach(table_,"PARMASKS");
|
---|
80 | frameCol_.attach(table_,"FRAMEINFO");
|
---|
81 | }
|
---|
82 |
|
---|
83 | uInt STFit::addEntry( const STFitEntry& fit, Int id )
|
---|
84 | {
|
---|
85 | uInt rno = table_.nrow();
|
---|
86 | uInt resultid;
|
---|
87 | bool foundentry = false;
|
---|
88 | if ( id > -1 ) {
|
---|
89 | Table t = table_(table_.col("ID") == id );
|
---|
90 | if (t.nrow() > 0) {
|
---|
91 | rno = t.rowNumbers()[0];
|
---|
92 | resultid = id;
|
---|
93 | foundentry = true;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | if ( rno > 0 && !foundentry ) {
|
---|
97 | idCol_.get(rno-1, resultid);
|
---|
98 | resultid++;
|
---|
99 | }
|
---|
100 | if ( !foundentry )table_.addRow();
|
---|
101 |
|
---|
102 | funcCol_.put(rno, mathutil::toVectorString(fit.getFunctions()));
|
---|
103 | compCol_.put(rno, Vector<Int>(fit.getComponents()));
|
---|
104 | parCol_.put(rno, Vector<Double>(fit.getParameters()));
|
---|
105 | maskCol_.put(rno, Vector<Bool>(fit.getParmasks()));
|
---|
106 | frameCol_.put(rno, mathutil::toVectorString(fit.getFrameinfo()));
|
---|
107 | idCol_.put(rno, resultid);
|
---|
108 | return resultid;
|
---|
109 | }
|
---|
110 |
|
---|
111 | void STFit::getEntry( STFitEntry& fit, uInt id )
|
---|
112 | {
|
---|
113 | Table t = table_(table_.col("ID") == Int(id) );
|
---|
114 | if (t.nrow() == 0 ) {
|
---|
115 | throw(AipsError("STFit::getEntry - id out of range"));
|
---|
116 | }
|
---|
117 | ROTableRow row(t);
|
---|
118 | // get first row - there should only be one matching id
|
---|
119 | const TableRecord& rec = row.get(0);
|
---|
120 | std::vector<std::string> outstr;
|
---|
121 | Vector<String> vec;
|
---|
122 | rec.get("FUNCTIONS", vec);
|
---|
123 | fit.setFunctions(mathutil::tovectorstring(vec));
|
---|
124 | Vector<Int> ivec;
|
---|
125 | std::vector<int> istl;
|
---|
126 | rec.get("COMPONENTS", ivec);
|
---|
127 | ivec.tovector(istl);
|
---|
128 | fit.setComponents(istl);
|
---|
129 | Vector<Double> dvec;
|
---|
130 | std::vector<double> dstl;
|
---|
131 | rec.get("PARAMETERS", dvec);
|
---|
132 | dvec.tovector(dstl);
|
---|
133 | fit.setParameters(dstl);
|
---|
134 | Vector<Bool> bvec;
|
---|
135 | std::vector<bool> bstl;
|
---|
136 | rec.get("PARMASKS", bvec);
|
---|
137 | bvec.tovector(bstl);
|
---|
138 | fit.setParmasks(bstl);
|
---|
139 | vec.resize();
|
---|
140 | rec.get("FRAMEINFO", vec);
|
---|
141 | fit.setFrameinfo(mathutil::tovectorstring(vec));
|
---|
142 | }
|
---|
143 |
|
---|
144 | } //namespace
|
---|