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