[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> |
---|
| 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(casa::Table::TableType tt) : |
---|
| 31 | STSubTable( name_, tt ) |
---|
| 32 | { |
---|
| 33 | setup(); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | STMolecules::~STMolecules() |
---|
| 38 | { |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | void asap::STMolecules::setup( ) |
---|
| 42 | { |
---|
| 43 | // add to base class table |
---|
| 44 | table_.addColumn(ScalarColumnDesc<Double>("RESTFREQUENCY")); |
---|
| 45 | table_.addColumn(ScalarColumnDesc<String>("NAME")); |
---|
| 46 | table_.addColumn(ScalarColumnDesc<String>("FORMATTEDNAME")); |
---|
| 47 | table_.rwKeywordSet().define("UNIT", String("Hz")); |
---|
| 48 | // new cached columns |
---|
| 49 | restfreqCol_.attach(table_,"RESTFREQUENCY"); |
---|
| 50 | nameCol_.attach(table_,"NAME"); |
---|
| 51 | formattednameCol_.attach(table_,"FORMATTEDNAME"); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | uInt STMolecules::addEntry( Double restfreq, const String& name, |
---|
| 55 | const String& formattedname ) |
---|
| 56 | { |
---|
| 57 | |
---|
| 58 | Table result = |
---|
| 59 | table_( near(table_.col("RESTFREQUENCY"), restfreq) ); |
---|
| 60 | uInt resultid = 0; |
---|
| 61 | if ( result.nrow() > 0) { |
---|
| 62 | ROScalarColumn<uInt> c(result, "ID"); |
---|
| 63 | c.get(0, resultid); |
---|
| 64 | } else { |
---|
| 65 | uInt rno = table_.nrow(); |
---|
| 66 | table_.addRow(); |
---|
| 67 | // get last assigned _id and increment |
---|
| 68 | if ( rno > 0 ) { |
---|
| 69 | idCol_.get(rno-1, resultid); |
---|
| 70 | resultid++; |
---|
| 71 | } |
---|
| 72 | restfreqCol_.put(rno, restfreq); |
---|
| 73 | nameCol_.put(rno, name); |
---|
| 74 | formattednameCol_.put(rno, formattedname); |
---|
| 75 | idCol_.put(rno, resultid); |
---|
| 76 | } |
---|
| 77 | return resultid; |
---|
| 78 | } |
---|
| 79 | |
---|
[830] | 80 | void STMolecules::getEntry( Double restfreq, String& name, |
---|
| 81 | String& formattedname, uInt id ) |
---|
| 82 | { |
---|
| 83 | Table t = table_(table_.col("ID") == Int(id) ); |
---|
| 84 | if (t.nrow() == 0 ) { |
---|
| 85 | throw(AipsError("STMolecules::getEntry - id out of range")); |
---|
| 86 | } |
---|
| 87 | ROTableRow row(t); |
---|
| 88 | // get first row - there should only be one matching id |
---|
| 89 | const TableRecord& rec = row.get(0); |
---|
| 90 | restfreq = rec.asDouble("RESTFREQUENCY"); |
---|
| 91 | name = rec.asString("NAME"); |
---|
| 92 | formattedname = rec.asString("FORMATTEDNAME"); |
---|
[809] | 93 | } |
---|
[830] | 94 | |
---|
| 95 | } //namespace |
---|