// // 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 #include #include "STMolecules.h" using namespace casa; namespace asap { const casa::String STMolecules::name_ = "MOLECULES"; STMolecules::STMolecules(const Scantable& parent) : STSubTable( parent, name_ ) { setup(); } asap::STMolecules::STMolecules( casa::Table tab ) : STSubTable(tab, name_) { restfreqCol_.attach(table_,"RESTFREQUENCY"); nameCol_.attach(table_,"NAME"); formattednameCol_.attach(table_,"FORMATTEDNAME"); } STMolecules::~STMolecules() { } STMolecules & asap::STMolecules::operator =( const STMolecules & other ) { if ( this != &other ) { static_cast(*this) = other; restfreqCol_.attach(table_,"RESTFREQUENCY"); nameCol_.attach(table_,"NAME"); formattednameCol_.attach(table_,"FORMATTEDNAME"); } return *this; } void asap::STMolecules::setup( ) { // add to base class table //table_.addColumn(ScalarColumnDesc("RESTFREQUENCY")); table_.addColumn(ArrayColumnDesc("RESTFREQUENCY")); //table_.addColumn(ScalarColumnDesc("NAME")); table_.addColumn(ArrayColumnDesc("NAME")); //table_.addColumn(ScalarColumnDesc("FORMATTEDNAME")); table_.addColumn(ArrayColumnDesc("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; } ***/ uInt STMolecules::addEntry( Vector restfreq, const Vector& name, const Vector& formattedname ) { // How to handle this...? Table result = table_( nelements(table_.col("RESTFREQUENCY")) == uInt (restfreq.size()) && all(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 ) const { 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"); } ***/ void STMolecules::getEntry( Vector& restfreq, Vector& name, Vector& formattedname, uInt id ) const { 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"); restfreq = rec.asArrayDouble("RESTFREQUENCY"); //name = rec.asString("NAME"); name = rec.asArrayString("NAME"); //formattedname = rec.asString("FORMATTEDNAME"); formattedname = rec.asArrayString("FORMATTEDNAME"); } std::vector< double > asap::STMolecules::getRestFrequencies( ) const { std::vector out; //TableProxy itsTable(table_); //Record rec; Vector rfs = restfreqCol_.getColumn(); rfs.tovector(out); //rec = itsTable.getVarColumn("RESTFREQUENCY", 0, 1, 1); return out; } std::vector< double > asap::STMolecules::getRestFrequency( uInt id ) const { std::vector out; Table t = table_(table_.col("ID") == Int(id) ); if (t.nrow() == 0 ) { throw(AipsError("STMolecules::getRestFrequency - id out of range")); } ROTableRow row(t); const TableRecord& rec = row.get(0); //return double(rec.asDouble("RESTFREQUENCY")); Vector rfs = rec.asArrayDouble("RESTFREQUENCY"); rfs.tovector(out); return out; } int asap::STMolecules::nrow() const { return int(table_.nrow()); } }//namespace