// // C++ Implementation: STApplyTable // // Description: // // // Author: Takeshi Nakazato (C) 2012 // // Copyright: See COPYING file that comes with this distribution // // #include #include #include #include #include #include #include #include #include #include #include #include "Scantable.h" #include "STApplyTable.h" using namespace casacore; namespace asap { STApplyTable::STApplyTable( const Scantable& parent, const casacore::String& name ) { TableDesc td("", "1", TableDesc::Scratch); td.addColumn(ScalarColumnDesc("SCANNO")); td.addColumn(ScalarColumnDesc("CYCLENO")); td.addColumn(ScalarColumnDesc("BEAMNO")); td.addColumn(ScalarColumnDesc("IFNO")); td.addColumn(ScalarColumnDesc("POLNO")); td.addColumn(ScalarColumnDesc("FREQ_ID")); td.addColumn(ScalarColumnDesc("TIME")); TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default TableMeasValueDesc measVal(td, "TIME"); TableMeasDesc mepochCol(measVal, measRef); mepochCol.write(td); String tabname = parent.table().tableName()+"/"+name; SetupNewTable aNewTab(tabname, td, Table::Scratch); //table_ = Table(aNewTab, parent.table().tableType()); table_ = Table(aNewTab, Table::Memory); attachBaseColumns(); table_.rwKeywordSet().define("VERSION", 1); table_.rwKeywordSet().define("ScantableName", parent.table().tableName()); table_.rwKeywordSet().define("ApplyType", "NONE"); table_.rwKeywordSet().defineTable("FREQUENCIES", parent.frequencies().table()); table_.tableInfo().setType("ApplyTable"); originaltable_ = table_; } STApplyTable::STApplyTable(const String &name) { table_ = Table(name, Table::Update); attachBaseColumns(); originaltable_ = table_; } STApplyTable::~STApplyTable() { } void STApplyTable::attach() { attachBaseColumns(); attachOptionalColumns(); } void STApplyTable::attachBaseColumns() { scanCol_.attach(table_, "SCANNO"); cycleCol_.attach(table_, "CYCLENO"); beamCol_.attach(table_, "BEAMNO"); ifCol_.attach(table_, "IFNO"); polCol_.attach(table_, "POLNO"); timeCol_.attach(table_, "TIME"); timeMeasCol_.attach(table_, "TIME"); freqidCol_.attach(table_, "FREQ_ID"); } void STApplyTable::setSelection(STSelector &sel, bool sortByTime) { table_ = sel.apply(originaltable_); if (sortByTime) table_.sort("TIME", Sort::Descending); attach(); sel_ = sel; } void STApplyTable::unsetSelection() { table_ = originaltable_; attach(); sel_.reset(); } void STApplyTable::setbasedata(uInt irow, uInt scanno, uInt cycleno, uInt beamno, uInt ifno, uInt polno, uInt freqid, Double time) { scanCol_.put(irow, scanno); cycleCol_.put(irow, cycleno); beamCol_.put(irow, beamno); ifCol_.put(irow, ifno); polCol_.put(irow, polno); timeCol_.put(irow, time); freqidCol_.put(irow, freqid); } void STApplyTable::save(const String &name) { assert_(name.size() > 0, "Output name is empty."); table_.deepCopy(name, Table::New); } String STApplyTable::caltype() { if (table_.keywordSet().isDefined("ApplyType")) { return table_.keywordSet().asString("ApplyType"); } else return "NONE"; } STCalEnum::CalType STApplyTable::getCalType(const String &name) { Table t(name, Table::Old); return stringToType(t.keywordSet().asString("ApplyType")); } STCalEnum::CalType STApplyTable::getCalType(CountedPtr tab) { return stringToType(tab->caltype()); } STCalEnum::CalType STApplyTable::getCalType(STApplyTable *tab) { return stringToType(tab->caltype()); } STCalEnum::CalType STApplyTable::stringToType(const String &caltype) { if (caltype == "CALSKY_PSALMA") return STCalEnum::CalPSAlma; else if (caltype == "CALTSYS") return STCalEnum::CalTsys; else return STCalEnum::NoType; } Block STApplyTable::getFrequenciesRow(uInt id) { const TableRecord &rec = table_.keywordSet(); //rec.print(os_.output()); //os_ << LogIO::POST; Table ftab = rec.asTable("FREQUENCIES"); Table t = ftab(ftab.col("ID") == id); ROTableColumn col(t, "REFPIX"); Block r(3); r[0] = col.asdouble(0); col.attach(t, "REFVAL"); r[1] = col.asdouble(0); col.attach(t, "INCREMENT"); r[2] = col.asdouble(0); return r; } }