source: trunk/src/STMolecules.cpp@ 2676

Last change on this file since 2676 was 2243, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: 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...

Added maxRow = 1 in selection using TableExprNode when
finding at least one row is enough.


File size: 5.4 KB
RevLine 
[809]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>
[1819]16#include <tables/Tables/ArrColDesc.h>
[809]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
[1819]22#include <tables/Tables/TableProxy.h>
23
[809]24#include "STMolecules.h"
25
26
27using namespace casa;
28
29namespace asap {
30
31const casa::String STMolecules::name_ = "MOLECULES";
32
[849]33STMolecules::STMolecules(const Scantable& parent) :
34 STSubTable( parent, name_ )
[809]35{
36 setup();
37}
38
[856]39asap::STMolecules::STMolecules( casa::Table tab ) : STSubTable(tab, name_)
[849]40{
41 restfreqCol_.attach(table_,"RESTFREQUENCY");
42 nameCol_.attach(table_,"NAME");
43 formattednameCol_.attach(table_,"FORMATTEDNAME");
44}
[809]45
46STMolecules::~STMolecules()
47{
48}
49
[849]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
[809]61void asap::STMolecules::setup( )
62{
63 // add to base class table
[1819]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"));
[809]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
[1819]77/***
[809]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}
[1819]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()) &&
[2242]110 all(table_.col("RESTFREQUENCY")== restfreq), 1 );
[1819]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}
[809]130
[1819]131
132
133
134/***
[870]135void STMolecules::getEntry( Double& restfreq, String& name,
136 String& formattedname, uInt id ) const
[830]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
[1819]144
[830]145 const TableRecord& rec = row.get(0);
146 restfreq = rec.asDouble("RESTFREQUENCY");
147 name = rec.asString("NAME");
148 formattedname = rec.asString("FORMATTEDNAME");
[809]149}
[1819]150***/
151void STMolecules::getEntry( Vector<Double>& restfreq, Vector<String>& name,
152 Vector<String>& formattedname, uInt id ) const
153{
[2243]154 Table t = table_(table_.col("ID") == Int(id), 1 );
[1819]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
[830]160
[1819]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
[847]170std::vector< double > asap::STMolecules::getRestFrequencies( ) const
171{
172 std::vector<double> out;
[1819]173 //TableProxy itsTable(table_);
174 //Record rec;
[847]175 Vector<Double> rfs = restfreqCol_.getColumn();
176 rfs.tovector(out);
[1819]177 //rec = itsTable.getVarColumn("RESTFREQUENCY", 0, 1, 1);
[847]178 return out;
179}
180
[1819]181std::vector< double > asap::STMolecules::getRestFrequency( uInt id ) const
[870]182{
[1819]183 std::vector<double> out;
[2243]184 Table t = table_(table_.col("ID") == Int(id), 1 );
[870]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);
[1819]190 //return double(rec.asDouble("RESTFREQUENCY"));
191 Vector<Double> rfs = rec.asArrayDouble("RESTFREQUENCY");
192 rfs.tovector(out);
193 return out;
[870]194}
[849]195
[1819]196int asap::STMolecules::nrow() const
197{
198 return int(table_.nrow());
199}
[870]200
[849]201}//namespace
202
Note: See TracBrowser for help on using the repository browser.