source: trunk/src/STFocus.cpp@ 876

Last change on this file since 876 was 856, checked in by mar637, 19 years ago

added name()
reworked copy constructor for (Table tab) to also pass name to base class

File size: 2.6 KB
Line 
1//
2// C++ Implementation: STFocus
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
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>
17#include <tables/Tables/TableParse.h>
18#include <tables/Tables/TableRow.h>
19#include <casa/Containers/RecordField.h>
20
21#include "STFocus.h"
22
23
24using namespace casa;
25
26namespace asap {
27
28const casa::String STFocus::name_ = "FOCUS";
29
30STFocus::STFocus(const Scantable& parent ) :
31 STSubTable( parent, name_ )
32{
33 setup();
34}
35
36asap::STFocus::STFocus( casa::Table tab ) : STSubTable(tab, name_)
37{
38 rotationCol_.attach(table_,"ROTATION");
39 angleCol_.attach(table_,"ANGLE");
40 tanCol_.attach(table_,"TAN");
41}
42
43STFocus::~STFocus()
44{
45}
46
47STFocus & asap::STFocus::operator =( const STFocus & other )
48{
49 if (this != &other) {
50 static_cast<STSubTable&>(*this) = other;
51 rotationCol_.attach(table_,"ROTATION");
52 angleCol_.attach(table_,"ANGLE");
53 tanCol_.attach(table_,"TAN");
54 }
55 return *this;
56}
57void asap::STFocus::setup( )
58{
59 // add to base class table
60 table_.addColumn(ScalarColumnDesc<Float>("ROTATION"));
61 table_.addColumn(ScalarColumnDesc<Float>("ANGLE"));
62 table_.addColumn(ScalarColumnDesc<Float>("TAN"));
63
64 // new cached columns
65 rotationCol_.attach(table_,"ROTATION");
66 angleCol_.attach(table_,"ANGLE");
67 tanCol_.attach(table_,"TAN");
68}
69
70uInt STFocus::addEntry( Float rotation, Float angle, Float ftan)
71{
72 Table result = table_( near(table_.col("ROTATION"), rotation)
73 && near(table_.col("ANGLE"), angle)
74 && near(table_.col("TAN"), ftan) );
75 uInt resultid = 0;
76 if ( result.nrow() > 0) {
77 ROScalarColumn<uInt> c(result, "ID");
78 c.get(0, resultid);
79 } else {
80 uInt rno = table_.nrow();
81 table_.addRow();
82 // get last assigned _id and increment
83 if ( rno > 0 ) {
84 idCol_.get(rno-1, resultid);
85 resultid++;
86 }
87 rotationCol_.put(rno, rotation);
88 angleCol_.put(rno, angle);
89 tanCol_.put(rno, ftan);
90 idCol_.put(rno, resultid);
91 }
92 return resultid;
93}
94
95void asap::STFocus::getEntry( Float& rotation, Float& angle, Float& ftan,
96 uInt id)
97{
98 Table t = table_(table_.col("ID") == Int(id) );
99 if (t.nrow() == 0 ) {
100 throw(AipsError("STFocus::getEntry - id out of range"));
101 }
102 ROTableRow row(t);
103 // get first row - there should only be one matching id
104 const TableRecord& rec = row.get(0);
105 rotation = rec.asFloat("ROTATION");
106 angle = rec.asFloat("ANGLE");
107 ftan = rec.asFloat("TAN");
108}
109
110
111}
Note: See TracBrowser for help on using the repository browser.