[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> |
---|
[1446] | 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 | |
---|
[1446] | 22 | #include <tables/Tables/TableProxy.h> |
---|
| 23 | |
---|
[809] | 24 | #include "STMolecules.h" |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | using namespace casa; |
---|
| 28 | |
---|
| 29 | namespace asap { |
---|
| 30 | |
---|
| 31 | const casa::String STMolecules::name_ = "MOLECULES"; |
---|
| 32 | |
---|
[849] | 33 | STMolecules::STMolecules(const Scantable& parent) : |
---|
| 34 | STSubTable( parent, name_ ) |
---|
[809] | 35 | { |
---|
| 36 | setup(); |
---|
| 37 | } |
---|
| 38 | |
---|
[856] | 39 | asap::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 | |
---|
| 46 | STMolecules::~STMolecules() |
---|
| 47 | { |
---|
| 48 | } |
---|
| 49 | |
---|
[849] | 50 | STMolecules & 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] | 61 | void asap::STMolecules::setup( ) |
---|
| 62 | { |
---|
| 63 | // add to base class table |
---|
[1446] | 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 | |
---|
[1446] | 77 | /*** |
---|
[809] | 78 | uInt 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 | } |
---|
[1446] | 103 | ***/ |
---|
| 104 | uInt STMolecules::addEntry( Vector<Double> restfreq, const Vector<String>& name, |
---|
| 105 | const Vector<String>& formattedname ) |
---|
| 106 | { |
---|
| 107 | // How to handle this...? |
---|
| 108 | Table result = |
---|
[1626] | 109 | table_( nelements(table_.col("RESTFREQUENCY")) == uInt (restfreq.size()) && |
---|
[1446] | 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 | } |
---|
[809] | 130 | |
---|
[1446] | 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | /*** |
---|
[870] | 135 | void 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 |
---|
[1446] | 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 | } |
---|
[1446] | 150 | ***/ |
---|
| 151 | void 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 |
---|
[830] | 160 | |
---|
[1446] | 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] | 170 | std::vector< double > asap::STMolecules::getRestFrequencies( ) const |
---|
| 171 | { |
---|
| 172 | std::vector<double> out; |
---|
[1446] | 173 | //TableProxy itsTable(table_); |
---|
| 174 | //Record rec; |
---|
[847] | 175 | Vector<Double> rfs = restfreqCol_.getColumn(); |
---|
| 176 | rfs.tovector(out); |
---|
[1446] | 177 | //rec = itsTable.getVarColumn("RESTFREQUENCY", 0, 1, 1); |
---|
[847] | 178 | return out; |
---|
| 179 | } |
---|
| 180 | |
---|
[1446] | 181 | std::vector< double > asap::STMolecules::getRestFrequency( uInt id ) const |
---|
[870] | 182 | { |
---|
[1446] | 183 | std::vector<double> out; |
---|
[870] | 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); |
---|
[1446] | 190 | //return double(rec.asDouble("RESTFREQUENCY")); |
---|
| 191 | Vector<Double> rfs = rec.asArrayDouble("RESTFREQUENCY"); |
---|
| 192 | rfs.tovector(out); |
---|
| 193 | return out; |
---|
[870] | 194 | } |
---|
[849] | 195 | |
---|
[1446] | 196 | int asap::STMolecules::nrow() const |
---|
| 197 | { |
---|
| 198 | return int(table_.nrow()); |
---|
| 199 | } |
---|
[870] | 200 | |
---|
[849] | 201 | }//namespace |
---|
| 202 | |
---|