source: trunk/src/STApplyTable.cpp@ 2859

Last change on this file since 2859 was 2759, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: test_sdcal2

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

  • Throw exception when empty string is specified in STApplyTable::save().
  • Use TSYS in the data when Tsys calibration is not done.


File size: 4.6 KB
RevLine 
[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>
[2759]13#include <casa/Utilities/Assert.h>
[2696]14#include <tables/Tables/TableDesc.h>
15#include <tables/Tables/SetupNewTab.h>
16#include <tables/Tables/ScaColDesc.h>
17#include <tables/Tables/TableRecord.h>
[2720]18#include <tables/Tables/Table.h>
19#include <tables/Tables/ExprNode.h>
[2696]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
28using namespace casa;
29
30namespace asap {
31
32STApplyTable::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"));
[2720]40 td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID"));
[2696]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
[2720]62STApplyTable::STApplyTable(const String &name)
63{
64 table_ = Table(name, Table::Update);
65 attachBaseColumns();
66 originaltable_ = table_;
67}
[2696]68
[2720]69
[2696]70STApplyTable::~STApplyTable()
71{
72}
73
74void STApplyTable::attach()
75{
76 attachBaseColumns();
77 attachOptionalColumns();
78}
79
80void 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");
[2720]89 freqidCol_.attach(table_, "FREQ_ID");
[2696]90}
91
[2720]92void STApplyTable::setSelection(STSelector &sel, bool sortByTime)
[2696]93{
94 table_ = sel.apply(originaltable_);
[2720]95 if (sortByTime)
96 table_.sort("TIME", Sort::Descending);
[2696]97 attach();
98 sel_ = sel;
99}
100
101void STApplyTable::unsetSelection()
102{
103 table_ = originaltable_;
104 attach();
105 sel_.reset();
106}
107
108void STApplyTable::setbasedata(uInt irow, uInt scanno, uInt cycleno,
109 uInt beamno, uInt ifno, uInt polno,
[2720]110 uInt freqid, Double time)
[2696]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);
[2720]118 freqidCol_.put(irow, freqid);
[2696]119}
120
[2703]121void STApplyTable::save(const String &name)
122{
[2759]123 assert_<AipsError>(name.size() > 0, "Output name is empty.");
[2703]124 table_.deepCopy(name, Table::New);
[2696]125}
[2703]126
[2720]127String STApplyTable::caltype()
128{
129 if (table_.keywordSet().isDefined("ApplyType")) {
130 return table_.keywordSet().asString("ApplyType");
131 }
132 else
133 return "NONE";
[2703]134}
[2720]135
136STCalEnum::CalType STApplyTable::getCalType(const String &name)
137{
138 Table t(name, Table::Old);
139 return stringToType(t.keywordSet().asString("ApplyType"));
140}
141
142STCalEnum::CalType STApplyTable::getCalType(CountedPtr<STApplyTable> tab)
143{
144 return stringToType(tab->caltype());
145}
146
147STCalEnum::CalType STApplyTable::getCalType(STApplyTable *tab)
148{
149 return stringToType(tab->caltype());
150}
151
152STCalEnum::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
162Block<Double> STApplyTable::getFrequenciesRow(uInt id)
163{
164 const TableRecord &rec = table_.keywordSet();
[2734]165 //rec.print(os_.output());
166 //os_ << LogIO::POST;
[2720]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}
Note: See TracBrowser for help on using the repository browser.