source: branches/Release2.0/src/STTcal.cpp@ 2937

Last change on this file since 2937 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.3 KB
Line 
1
2//
3// C++ Implementation: STTcal
4//
5// Description:
6//
7//
8// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
9//
10// Copyright: See COPYING file that comes with this distribution
11//
12//
13#include <casa/Exceptions/Error.h>
14#include <tables/Tables/TableDesc.h>
15#include <tables/Tables/SetupNewTab.h>
16#include <tables/Tables/ScaColDesc.h>
17#include <tables/Tables/ArrColDesc.h>
18#include <tables/Tables/TableRecord.h>
19#include <tables/Tables/TableParse.h>
20#include <tables/Tables/TableRow.h>
21#include <casa/Containers/RecordField.h>
22
23#include "STTcal.h"
24
25
26using namespace casa;
27
28namespace asap {
29
30const casa::String STTcal::name_ = "TCAL";
31
32STTcal::STTcal(const Scantable& parent) :
33 STSubTable( parent, name_ )
34{
35 setup();
36}
37
38STTcal& asap::STTcal::operator =( const STTcal & other )
39{
40 if ( this != &other ) {
41 static_cast<STSubTable&>(*this) = other;
42 timeCol_.attach(table_,"TIME");
43 tcalCol_.attach(table_,"TCAL");
44 }
45 return *this;
46}
47
48asap::STTcal::STTcal( casa::Table tab ) : STSubTable(tab, name_)
49{
50 timeCol_.attach(table_,"TIME");
51 tcalCol_.attach(table_,"TCAL");
52
53}
54
55STTcal::~STTcal()
56{
57}
58
59void asap::STTcal::setup( )
60{
61 // add to base class table
62 table_.addColumn(ScalarColumnDesc<String>("TIME"));
63 table_.addColumn(ArrayColumnDesc<Float>("TCAL"));
64
65 // new cached columns
66 timeCol_.attach(table_,"TIME");
67 tcalCol_.attach(table_,"TCAL");
68}
69
70uInt STTcal::addEntry( const String& time, const Vector<Float>& cal)
71{
72 // test if this already exists
73 Table result = table_( table_.col("TIME") == time );
74 uInt resultid = 0;
75 if ( result.nrow() > 0) {
76 ROScalarColumn<uInt> c(result, "ID");
77 c.get(0, resultid);
78 } else {
79 uInt rno = table_.nrow();
80 table_.addRow();
81 // get last assigned tcal_id and increment
82 if ( rno > 0 ) {
83 idCol_.get(rno-1, resultid);
84 resultid++;
85 }
86 tcalCol_.put(rno, cal);
87 timeCol_.put(rno, time);
88 idCol_.put(rno, resultid);
89 }
90 return resultid;
91}
92
93void STTcal::getEntry( String& time, Vector<Float>& tcal, uInt id )
94{
95 Table t = table_(table_.col("ID") == Int(id) );
96 if (t.nrow() == 0 ) {
97 throw(AipsError("STTcal::getEntry - id out of range"));
98 }
99 ROTableRow row(t);
100 // get first row - there should only be one matching id
101 const TableRecord& rec = row.get(0);
102 time = rec.asString("TIME");
103 tcal.resize();
104 Vector<Float> out;
105 rec.get("TCAL",out);
106 tcal = out;
107}
108
109} //namespace
Note: See TracBrowser for help on using the repository browser.