source: branches/alma/src/STMolecules.cpp@ 2188

Last change on this file since 2188 was 1626, checked in by Kana Sugimoto, 15 years ago

New Development: No

JIRA Issue: No

Ready to Release: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s):

Description:

Merged Wes's bug fix to local branch.


File size: 5.4 KB
Line 
1//
2// C++ Implementation: STMolecules
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <casa/Exceptions/Error.h>
13#include <tables/Tables/TableDesc.h>
14#include <tables/Tables/SetupNewTab.h>
15#include <tables/Tables/ScaColDesc.h>
16#include <tables/Tables/ArrColDesc.h>
17#include <tables/Tables/TableRecord.h>
18#include <tables/Tables/TableParse.h>
19#include <tables/Tables/TableRow.h>
20#include <casa/Containers/RecordField.h>
21
22#include <tables/Tables/TableProxy.h>
23
24#include "STMolecules.h"
25
26
27using namespace casa;
28
29namespace asap {
30
31const casa::String STMolecules::name_ = "MOLECULES";
32
33STMolecules::STMolecules(const Scantable& parent) :
34 STSubTable( parent, name_ )
35{
36 setup();
37}
38
39asap::STMolecules::STMolecules( casa::Table tab ) : STSubTable(tab, name_)
40{
41 restfreqCol_.attach(table_,"RESTFREQUENCY");
42 nameCol_.attach(table_,"NAME");
43 formattednameCol_.attach(table_,"FORMATTEDNAME");
44}
45
46STMolecules::~STMolecules()
47{
48}
49
50STMolecules & asap::STMolecules::operator =( const STMolecules & other )
51{
52 if ( this != &other ) {
53 static_cast<STSubTable&>(*this) = other;
54 restfreqCol_.attach(table_,"RESTFREQUENCY");
55 nameCol_.attach(table_,"NAME");
56 formattednameCol_.attach(table_,"FORMATTEDNAME");
57 }
58 return *this;
59}
60
61void asap::STMolecules::setup( )
62{
63 // add to base class table
64 //table_.addColumn(ScalarColumnDesc<Double>("RESTFREQUENCY"));
65 table_.addColumn(ArrayColumnDesc<Double>("RESTFREQUENCY"));
66 //table_.addColumn(ScalarColumnDesc<String>("NAME"));
67 table_.addColumn(ArrayColumnDesc<String>("NAME"));
68 //table_.addColumn(ScalarColumnDesc<String>("FORMATTEDNAME"));
69 table_.addColumn(ArrayColumnDesc<String>("FORMATTEDNAME"));
70 table_.rwKeywordSet().define("UNIT", String("Hz"));
71 // new cached columns
72 restfreqCol_.attach(table_,"RESTFREQUENCY");
73 nameCol_.attach(table_,"NAME");
74 formattednameCol_.attach(table_,"FORMATTEDNAME");
75}
76
77/***
78uInt STMolecules::addEntry( Double restfreq, const String& name,
79 const String& formattedname )
80{
81
82 Table result =
83 table_( near(table_.col("RESTFREQUENCY"), restfreq) );
84 uInt resultid = 0;
85 if ( result.nrow() > 0) {
86 ROScalarColumn<uInt> c(result, "ID");
87 c.get(0, resultid);
88 } else {
89 uInt rno = table_.nrow();
90 table_.addRow();
91 // get last assigned _id and increment
92 if ( rno > 0 ) {
93 idCol_.get(rno-1, resultid);
94 resultid++;
95 }
96 restfreqCol_.put(rno, restfreq);
97 nameCol_.put(rno, name);
98 formattednameCol_.put(rno, formattedname);
99 idCol_.put(rno, resultid);
100 }
101 return resultid;
102}
103***/
104uInt STMolecules::addEntry( Vector<Double> restfreq, const Vector<String>& name,
105 const Vector<String>& formattedname )
106{
107// How to handle this...?
108 Table result =
109 table_( nelements(table_.col("RESTFREQUENCY")) == uInt (restfreq.size()) &&
110 all(table_.col("RESTFREQUENCY")== restfreq) );
111 uInt resultid = 0;
112 if ( result.nrow() > 0) {
113 ROScalarColumn<uInt> c(result, "ID");
114 c.get(0, resultid);
115 } else {
116 uInt rno = table_.nrow();
117 table_.addRow();
118 // get last assigned _id and increment
119 if ( rno > 0 ) {
120 idCol_.get(rno-1, resultid);
121 resultid++;
122 }
123 restfreqCol_.put(rno, restfreq);
124 nameCol_.put(rno, name);
125 formattednameCol_.put(rno, formattedname);
126 idCol_.put(rno, resultid);
127 }
128 return resultid;
129}
130
131
132
133
134/***
135void STMolecules::getEntry( Double& restfreq, String& name,
136 String& formattedname, uInt id ) const
137{
138 Table t = table_(table_.col("ID") == Int(id) );
139 if (t.nrow() == 0 ) {
140 throw(AipsError("STMolecules::getEntry - id out of range"));
141 }
142 ROTableRow row(t);
143 // get first row - there should only be one matching id
144
145 const TableRecord& rec = row.get(0);
146 restfreq = rec.asDouble("RESTFREQUENCY");
147 name = rec.asString("NAME");
148 formattedname = rec.asString("FORMATTEDNAME");
149}
150***/
151void STMolecules::getEntry( Vector<Double>& restfreq, Vector<String>& name,
152 Vector<String>& formattedname, uInt id ) const
153{
154 Table t = table_(table_.col("ID") == Int(id) );
155 if (t.nrow() == 0 ) {
156 throw(AipsError("STMolecules::getEntry - id out of range"));
157 }
158 ROTableRow row(t);
159 // get first row - there should only be one matching id
160
161 const TableRecord& rec = row.get(0);
162 //restfreq = rec.asDouble("RESTFREQUENCY");
163 restfreq = rec.asArrayDouble("RESTFREQUENCY");
164 //name = rec.asString("NAME");
165 name = rec.asArrayString("NAME");
166 //formattedname = rec.asString("FORMATTEDNAME");
167 formattedname = rec.asArrayString("FORMATTEDNAME");
168}
169
170std::vector< double > asap::STMolecules::getRestFrequencies( ) const
171{
172 std::vector<double> out;
173 //TableProxy itsTable(table_);
174 //Record rec;
175 Vector<Double> rfs = restfreqCol_.getColumn();
176 rfs.tovector(out);
177 //rec = itsTable.getVarColumn("RESTFREQUENCY", 0, 1, 1);
178 return out;
179}
180
181std::vector< double > asap::STMolecules::getRestFrequency( uInt id ) const
182{
183 std::vector<double> out;
184 Table t = table_(table_.col("ID") == Int(id) );
185 if (t.nrow() == 0 ) {
186 throw(AipsError("STMolecules::getRestFrequency - id out of range"));
187 }
188 ROTableRow row(t);
189 const TableRecord& rec = row.get(0);
190 //return double(rec.asDouble("RESTFREQUENCY"));
191 Vector<Double> rfs = rec.asArrayDouble("RESTFREQUENCY");
192 rfs.tovector(out);
193 return out;
194}
195
196int asap::STMolecules::nrow() const
197{
198 return int(table_.nrow());
199}
200
201}//namespace
202
Note: See TracBrowser for help on using the repository browser.