// // C++ Implementation: STMolecules // // Description: // // // Author: Malte Marquarding , (C) 2006 // // Copyright: See COPYING file that comes with this distribution // // #include #include #include #include #include #include #include #include #include "STMolecules.h" using namespace casa; namespace asap { const casa::String STMolecules::name_ = "MOLECULES"; STMolecules::STMolecules(casa::Table::TableType tt) : STSubTable( name_, tt ) { setup(); } STMolecules::~STMolecules() { } void asap::STMolecules::setup( ) { // add to base class table table_.addColumn(ScalarColumnDesc("RESTFREQUENCY")); table_.addColumn(ScalarColumnDesc("NAME")); table_.addColumn(ScalarColumnDesc("FORMATTEDNAME")); table_.rwKeywordSet().define("UNIT", String("Hz")); // new cached columns restfreqCol_.attach(table_,"RESTFREQUENCY"); nameCol_.attach(table_,"NAME"); formattednameCol_.attach(table_,"FORMATTEDNAME"); } uInt STMolecules::addEntry( Double restfreq, const String& name, const String& formattedname ) { Table result = table_( near(table_.col("RESTFREQUENCY"), restfreq) ); uInt resultid = 0; if ( result.nrow() > 0) { ROScalarColumn c(result, "ID"); c.get(0, resultid); } else { uInt rno = table_.nrow(); table_.addRow(); // get last assigned _id and increment if ( rno > 0 ) { idCol_.get(rno-1, resultid); resultid++; } restfreqCol_.put(rno, restfreq); nameCol_.put(rno, name); formattednameCol_.put(rno, formattedname); idCol_.put(rno, resultid); } return resultid; } void STMolecules::getEntry( Double restfreq, String& name, String& formattedname, uInt id ) { Table t = table_(table_.col("ID") == Int(id) ); if (t.nrow() == 0 ) { throw(AipsError("STMolecules::getEntry - id out of range")); } ROTableRow row(t); // get first row - there should only be one matching id const TableRecord& rec = row.get(0); restfreq = rec.asDouble("RESTFREQUENCY"); name = rec.asString("NAME"); formattedname = rec.asString("FORMATTEDNAME"); } } //namespace