// // C++ Implementation: STFit // // 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 "MathUtils.h" #include "STFitEntry.h" #include "STFit.h" using namespace casa; namespace asap { const casa::String STFit::name_ = "FIT"; STFit::STFit(const Scantable& parent) : STSubTable( parent, name_ ) { setup(); } STFit& asap::STFit::operator =( const STFit & other ) { if ( this != &other ) { static_cast(*this) = other; funcCol_.attach(table_,"FUNCTIONS"); compCol_.attach(table_,"COMPONENTS"); parCol_.attach(table_,"PARAMETERS"); maskCol_.attach(table_,"PARMASKS"); frameCol_.attach(table_,"FRAMEINFO"); } return *this; } asap::STFit::STFit( casa::Table tab ) : STSubTable(tab, name_) { funcCol_.attach(table_,"FUNCTIONS"); compCol_.attach(table_,"COMPONENTS"); parCol_.attach(table_,"PARAMETERS"); maskCol_.attach(table_,"PARMASKS"); frameCol_.attach(table_,"FRAMEINFO"); } STFit::~STFit() { } void asap::STFit::setup( ) { // add to base class table table_.addColumn(ArrayColumnDesc("FUNCTIONS")); table_.addColumn(ArrayColumnDesc("COMPONENTS")); table_.addColumn(ArrayColumnDesc("PARAMETERS")); // table_.addColumn(ArrayColumnDesc("ERRORS")); table_.addColumn(ArrayColumnDesc("PARMASKS")); table_.addColumn(ArrayColumnDesc("FRAMEINFO")); // new cached columns funcCol_.attach(table_,"FUNCTIONS"); compCol_.attach(table_,"COMPONENTS"); parCol_.attach(table_,"PARAMETERS"); // errCol_.attach(table_,"ERRORS"); maskCol_.attach(table_,"PARMASKS"); frameCol_.attach(table_,"FRAMEINFO"); } uInt STFit::addEntry( const STFitEntry& fit, Int id ) { uInt rno = table_.nrow(); uInt resultid = 0; bool foundentry = false; // replace if ( id > -1 ) { Table t = table_(table_.col("ID") == id, 1 ); if (t.nrow() > 0) { rno = t.rowNumbers(table_)[0]; resultid = id; foundentry = true; } } // doesn't exist if ( rno > 0 && !foundentry ) { idCol_.get(rno-1, resultid); resultid++; } // add new row if new id if ( !foundentry ) table_.addRow(); funcCol_.put(rno, mathutil::toVectorString(fit.getFunctions())); compCol_.put(rno, Vector(fit.getComponents())); const std::vector& pvec = fit.getParameters(); Vector dvec(pvec.size()); for (size_t i=0; i < dvec.nelements(); ++i) { dvec[i] = Double(pvec[i]); } parCol_.put(rno, dvec); /* const std::vector& evec = fit.getErrors(); for (size_t i=0; i < dvec.nelements(); ++i) { dvec[i] = Double(evec[i]); } errCol_.put(rno, dvec); */ maskCol_.put(rno, Vector(fit.getParmasks())); frameCol_.put(rno, mathutil::toVectorString(fit.getFrameinfo())); idCol_.put(rno, resultid); return resultid; } void STFit::getEntry( STFitEntry& fit, uInt id ) const { Table t = table_(table_.col("ID") == Int(id), 1 ); if (t.nrow() == 0 ) { throw(AipsError("STFit::getEntry - id out of range")); } ROTableRow row(t); // get first row - there should only be one matching id const TableRecord& rec = row.get(0); std::vector outstr; Vector vec; rec.get("FUNCTIONS", vec); fit.setFunctions(mathutil::tovectorstring(vec)); Vector ivec; std::vector istl; rec.get("COMPONENTS", ivec); ivec.tovector(istl); fit.setComponents(istl); Vector dvec; rec.get("PARAMETERS", dvec); std::vector dstl(dvec.begin(), dvec.end()); fit.setParameters(dstl); /* dvec.tovector(dstl); fit.setParameters(dstl); dvec.resize(); rec.get("ERRORS", dvec); dvec.tovector(dstl); fit.setErrors(dstl); */ Vector bvec; std::vector bstl; rec.get("PARMASKS", bvec); bvec.tovector(bstl); fit.setParmasks(bstl); vec.resize(); rec.get("FRAMEINFO", vec); fit.setFrameinfo(mathutil::tovectorstring(vec)); } } //namespace