[2696] | 1 | //
|
---|
| 2 | // C++ Implementation: STApplyTable
|
---|
| 3 | //
|
---|
| 4 | // Description:
|
---|
| 5 | //
|
---|
| 6 | //
|
---|
[2703] | 7 | // Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp> (C) 2012
|
---|
[2696] | 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>
|
---|
| 16 | #include <tables/Tables/TableRecord.h>
|
---|
[2720] | 17 | #include <tables/Tables/Table.h>
|
---|
| 18 | #include <tables/Tables/ExprNode.h>
|
---|
[2696] | 19 | #include <measures/TableMeasures/TableMeasDesc.h>
|
---|
| 20 | #include <measures/TableMeasures/TableMeasRefDesc.h>
|
---|
| 21 | #include <measures/TableMeasures/TableMeasValueDesc.h>
|
---|
| 22 |
|
---|
| 23 | #include "Scantable.h"
|
---|
| 24 | #include "STApplyTable.h"
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | using namespace casa;
|
---|
| 28 |
|
---|
| 29 | namespace asap {
|
---|
| 30 |
|
---|
| 31 | STApplyTable::STApplyTable( const Scantable& parent, const casa::String& name )
|
---|
| 32 | {
|
---|
| 33 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
| 34 | td.addColumn(ScalarColumnDesc<uInt>("SCANNO"));
|
---|
| 35 | td.addColumn(ScalarColumnDesc<uInt>("CYCLENO"));
|
---|
| 36 | td.addColumn(ScalarColumnDesc<uInt>("BEAMNO"));
|
---|
| 37 | td.addColumn(ScalarColumnDesc<uInt>("IFNO"));
|
---|
| 38 | td.addColumn(ScalarColumnDesc<uInt>("POLNO"));
|
---|
[2720] | 39 | td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID"));
|
---|
[2696] | 40 | td.addColumn(ScalarColumnDesc<Double>("TIME"));
|
---|
| 41 | TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default
|
---|
| 42 | TableMeasValueDesc measVal(td, "TIME");
|
---|
| 43 | TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
|
---|
| 44 | mepochCol.write(td);
|
---|
| 45 | String tabname = parent.table().tableName()+"/"+name;
|
---|
| 46 | SetupNewTable aNewTab(tabname, td, Table::Scratch);
|
---|
| 47 | //table_ = Table(aNewTab, parent.table().tableType());
|
---|
| 48 | table_ = Table(aNewTab, Table::Memory);
|
---|
| 49 | attachBaseColumns();
|
---|
| 50 |
|
---|
| 51 | table_.rwKeywordSet().define("VERSION", 1);
|
---|
| 52 | table_.rwKeywordSet().define("ScantableName", parent.table().tableName());
|
---|
| 53 | table_.rwKeywordSet().define("ApplyType", "NONE");
|
---|
| 54 | table_.rwKeywordSet().defineTable("FREQUENCIES", parent.frequencies().table());
|
---|
| 55 |
|
---|
| 56 | table_.tableInfo().setType("ApplyTable");
|
---|
| 57 |
|
---|
| 58 | originaltable_ = table_;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[2720] | 61 | STApplyTable::STApplyTable(const String &name)
|
---|
| 62 | {
|
---|
| 63 | table_ = Table(name, Table::Update);
|
---|
| 64 | attachBaseColumns();
|
---|
| 65 | originaltable_ = table_;
|
---|
| 66 | }
|
---|
[2696] | 67 |
|
---|
[2720] | 68 |
|
---|
[2696] | 69 | STApplyTable::~STApplyTable()
|
---|
| 70 | {
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | void STApplyTable::attach()
|
---|
| 74 | {
|
---|
| 75 | attachBaseColumns();
|
---|
| 76 | attachOptionalColumns();
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void STApplyTable::attachBaseColumns()
|
---|
| 80 | {
|
---|
| 81 | scanCol_.attach(table_, "SCANNO");
|
---|
| 82 | cycleCol_.attach(table_, "CYCLENO");
|
---|
| 83 | beamCol_.attach(table_, "BEAMNO");
|
---|
| 84 | ifCol_.attach(table_, "IFNO");
|
---|
| 85 | polCol_.attach(table_, "POLNO");
|
---|
| 86 | timeCol_.attach(table_, "TIME");
|
---|
| 87 | timeMeasCol_.attach(table_, "TIME");
|
---|
[2720] | 88 | freqidCol_.attach(table_, "FREQ_ID");
|
---|
[2696] | 89 | }
|
---|
| 90 |
|
---|
[2720] | 91 | void STApplyTable::setSelection(STSelector &sel, bool sortByTime)
|
---|
[2696] | 92 | {
|
---|
| 93 | table_ = sel.apply(originaltable_);
|
---|
[2720] | 94 | if (sortByTime)
|
---|
| 95 | table_.sort("TIME", Sort::Descending);
|
---|
[2696] | 96 | attach();
|
---|
| 97 | sel_ = sel;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | void STApplyTable::unsetSelection()
|
---|
| 101 | {
|
---|
| 102 | table_ = originaltable_;
|
---|
| 103 | attach();
|
---|
| 104 | sel_.reset();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | void STApplyTable::setbasedata(uInt irow, uInt scanno, uInt cycleno,
|
---|
| 108 | uInt beamno, uInt ifno, uInt polno,
|
---|
[2720] | 109 | uInt freqid, Double time)
|
---|
[2696] | 110 | {
|
---|
| 111 | scanCol_.put(irow, scanno);
|
---|
| 112 | cycleCol_.put(irow, cycleno);
|
---|
| 113 | beamCol_.put(irow, beamno);
|
---|
| 114 | ifCol_.put(irow, ifno);
|
---|
| 115 | polCol_.put(irow, polno);
|
---|
| 116 | timeCol_.put(irow, time);
|
---|
[2720] | 117 | freqidCol_.put(irow, freqid);
|
---|
[2696] | 118 | }
|
---|
| 119 |
|
---|
[2703] | 120 | void STApplyTable::save(const String &name)
|
---|
| 121 | {
|
---|
| 122 | table_.deepCopy(name, Table::New);
|
---|
[2696] | 123 | }
|
---|
[2703] | 124 |
|
---|
[2720] | 125 | String STApplyTable::caltype()
|
---|
| 126 | {
|
---|
| 127 | if (table_.keywordSet().isDefined("ApplyType")) {
|
---|
| 128 | return table_.keywordSet().asString("ApplyType");
|
---|
| 129 | }
|
---|
| 130 | else
|
---|
| 131 | return "NONE";
|
---|
[2703] | 132 | }
|
---|
[2720] | 133 |
|
---|
| 134 | STCalEnum::CalType STApplyTable::getCalType(const String &name)
|
---|
| 135 | {
|
---|
| 136 | Table t(name, Table::Old);
|
---|
| 137 | return stringToType(t.keywordSet().asString("ApplyType"));
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | STCalEnum::CalType STApplyTable::getCalType(CountedPtr<STApplyTable> tab)
|
---|
| 141 | {
|
---|
| 142 | return stringToType(tab->caltype());
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | STCalEnum::CalType STApplyTable::getCalType(STApplyTable *tab)
|
---|
| 146 | {
|
---|
| 147 | return stringToType(tab->caltype());
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | STCalEnum::CalType STApplyTable::stringToType(const String &caltype)
|
---|
| 151 | {
|
---|
| 152 | if (caltype == "CALSKY_PSALMA")
|
---|
| 153 | return STCalEnum::CalPSAlma;
|
---|
| 154 | else if (caltype == "CALTSYS")
|
---|
| 155 | return STCalEnum::CalTsys;
|
---|
| 156 | else
|
---|
| 157 | return STCalEnum::NoType;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | Block<Double> STApplyTable::getFrequenciesRow(uInt id)
|
---|
| 161 | {
|
---|
| 162 | const TableRecord &rec = table_.keywordSet();
|
---|
| 163 | rec.print(os_.output());
|
---|
| 164 | os_ << LogIO::POST;
|
---|
| 165 | Table ftab = rec.asTable("FREQUENCIES");
|
---|
| 166 | Table t = ftab(ftab.col("ID") == id);
|
---|
| 167 | ROTableColumn col(t, "REFPIX");
|
---|
| 168 | Block<Double> r(3);
|
---|
| 169 | r[0] = col.asdouble(0);
|
---|
| 170 | col.attach(t, "REFVAL");
|
---|
| 171 | r[1] = col.asdouble(0);
|
---|
| 172 | col.attach(t, "INCREMENT");
|
---|
| 173 | r[2] = col.asdouble(0);
|
---|
| 174 | return r;
|
---|
| 175 | }
|
---|
| 176 | }
|
---|