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/TableRecord.h> |
---|
17 | #include <tables/Tables/TableParse.h> |
---|
18 | #include <tables/Tables/TableRow.h> |
---|
19 | #include <casa/Containers/RecordField.h> |
---|
20 | |
---|
21 | #include "STMolecules.h" |
---|
22 | |
---|
23 | |
---|
24 | using namespace casa; |
---|
25 | |
---|
26 | namespace asap { |
---|
27 | |
---|
28 | const casa::String STMolecules::name_ = "MOLECULES"; |
---|
29 | |
---|
30 | STMolecules::STMolecules(const Scantable& parent) : |
---|
31 | STSubTable( parent, name_ ) |
---|
32 | { |
---|
33 | setup(); |
---|
34 | } |
---|
35 | |
---|
36 | asap::STMolecules::STMolecules( casa::Table tab ) : STSubTable(tab, name_) |
---|
37 | { |
---|
38 | restfreqCol_.attach(table_,"RESTFREQUENCY"); |
---|
39 | nameCol_.attach(table_,"NAME"); |
---|
40 | formattednameCol_.attach(table_,"FORMATTEDNAME"); |
---|
41 | } |
---|
42 | |
---|
43 | STMolecules::~STMolecules() |
---|
44 | { |
---|
45 | } |
---|
46 | |
---|
47 | STMolecules & asap::STMolecules::operator =( const STMolecules & other ) |
---|
48 | { |
---|
49 | if ( this != &other ) { |
---|
50 | static_cast<STSubTable&>(*this) = other; |
---|
51 | restfreqCol_.attach(table_,"RESTFREQUENCY"); |
---|
52 | nameCol_.attach(table_,"NAME"); |
---|
53 | formattednameCol_.attach(table_,"FORMATTEDNAME"); |
---|
54 | } |
---|
55 | return *this; |
---|
56 | } |
---|
57 | |
---|
58 | void asap::STMolecules::setup( ) |
---|
59 | { |
---|
60 | // add to base class table |
---|
61 | table_.addColumn(ScalarColumnDesc<Double>("RESTFREQUENCY")); |
---|
62 | table_.addColumn(ScalarColumnDesc<String>("NAME")); |
---|
63 | table_.addColumn(ScalarColumnDesc<String>("FORMATTEDNAME")); |
---|
64 | table_.rwKeywordSet().define("UNIT", String("Hz")); |
---|
65 | // new cached columns |
---|
66 | restfreqCol_.attach(table_,"RESTFREQUENCY"); |
---|
67 | nameCol_.attach(table_,"NAME"); |
---|
68 | formattednameCol_.attach(table_,"FORMATTEDNAME"); |
---|
69 | } |
---|
70 | |
---|
71 | uInt STMolecules::addEntry( Double restfreq, const String& name, |
---|
72 | const String& formattedname ) |
---|
73 | { |
---|
74 | |
---|
75 | Table result = |
---|
76 | table_( near(table_.col("RESTFREQUENCY"), restfreq) ); |
---|
77 | uInt resultid = 0; |
---|
78 | if ( result.nrow() > 0) { |
---|
79 | ROScalarColumn<uInt> c(result, "ID"); |
---|
80 | c.get(0, resultid); |
---|
81 | } else { |
---|
82 | uInt rno = table_.nrow(); |
---|
83 | table_.addRow(); |
---|
84 | // get last assigned _id and increment |
---|
85 | if ( rno > 0 ) { |
---|
86 | idCol_.get(rno-1, resultid); |
---|
87 | resultid++; |
---|
88 | } |
---|
89 | restfreqCol_.put(rno, restfreq); |
---|
90 | nameCol_.put(rno, name); |
---|
91 | formattednameCol_.put(rno, formattedname); |
---|
92 | idCol_.put(rno, resultid); |
---|
93 | } |
---|
94 | return resultid; |
---|
95 | } |
---|
96 | |
---|
97 | void STMolecules::getEntry( Double& restfreq, String& name, |
---|
98 | String& formattedname, uInt id ) const |
---|
99 | { |
---|
100 | Table t = table_(table_.col("ID") == Int(id) ); |
---|
101 | if (t.nrow() == 0 ) { |
---|
102 | throw(AipsError("STMolecules::getEntry - id out of range")); |
---|
103 | } |
---|
104 | ROTableRow row(t); |
---|
105 | // get first row - there should only be one matching id |
---|
106 | const TableRecord& rec = row.get(0); |
---|
107 | restfreq = rec.asDouble("RESTFREQUENCY"); |
---|
108 | name = rec.asString("NAME"); |
---|
109 | formattedname = rec.asString("FORMATTEDNAME"); |
---|
110 | } |
---|
111 | |
---|
112 | std::vector< double > asap::STMolecules::getRestFrequencies( ) const |
---|
113 | { |
---|
114 | std::vector<double> out; |
---|
115 | Vector<Double> rfs = restfreqCol_.getColumn(); |
---|
116 | rfs.tovector(out); |
---|
117 | return out; |
---|
118 | } |
---|
119 | |
---|
120 | double asap::STMolecules::getRestFrequency( uInt id ) const |
---|
121 | { |
---|
122 | Table t = table_(table_.col("ID") == Int(id) ); |
---|
123 | if (t.nrow() == 0 ) { |
---|
124 | throw(AipsError("STMolecules::getRestFrequency - id out of range")); |
---|
125 | } |
---|
126 | ROTableRow row(t); |
---|
127 | const TableRecord& rec = row.get(0); |
---|
128 | return double(rec.asDouble("RESTFREQUENCY")); |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | }//namespace |
---|
133 | |
---|