source: trunk/src/STTcal.cpp@ 845

Last change on this file since 845 was 830, checked in by mar637, 19 years ago

added getEntry to support export for STWriter.

File size: 2.0 KB
Line 
1//
2// C++ Implementation: STTcal
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/ArrColDesc.h>
17#include <tables/Tables/TableRecord.h>
18#include <tables/Tables/TableParse.h>
19#include <tables/Tables/TableRow.h>
20#include <casa/Containers/RecordField.h>
21
22#include "STTcal.h"
23
24
25using namespace casa;
26
27namespace asap {
28
29const casa::String STTcal::name_ = "TCAL";
30
31STTcal::STTcal(casa::Table::TableType tt) :
32 STSubTable( name_, tt )
33{
34 setup();
35}
36
37
38STTcal::~STTcal()
39{
40}
41
42void asap::STTcal::setup( )
43{
44 // add to base class table
45 table_.addColumn(ScalarColumnDesc<String>("TIME"));
46 table_.addColumn(ArrayColumnDesc<Float>("TCAL"));
47
48 // new cached columns
49 timeCol_.attach(table_,"TIME");
50 tcalCol_.attach(table_,"TCAL");
51}
52
53uInt STTcal::addEntry( const String& time, const Vector<Float>& cal)
54{
55 // test if this already exists
56 Table result = table_( table_.col("TIME") == time );
57 uInt resultid = 0;
58 if ( result.nrow() > 0) {
59 ROScalarColumn<uInt> c(result, "ID");
60 c.get(0, resultid);
61 } else {
62 uInt rno = table_.nrow();
63 table_.addRow();
64 // get last assigned tcal_id and increment
65 if ( rno > 0 ) {
66 idCol_.get(rno-1, resultid);
67 resultid++;
68 }
69 tcalCol_.put(rno, cal);
70 timeCol_.put(rno, time);
71 idCol_.put(rno, resultid);
72 }
73 return resultid;
74}
75
76void STTcal::getEntry( String& time, Vector<Float>& tcal, uInt id )
77{
78 Table t = table_(table_.col("ID") == Int(id) );
79 if (t.nrow() == 0 ) {
80 throw(AipsError("STTcal::getEntry - id out of range"));
81 }
82 ROTableRow row(t);
83 // get first row - there should only be one matching id
84 const TableRecord& rec = row.get(0);
85 time = rec.asString("TIME");
86 tcal.resize();
87 Vector<Float> out;
88 rec.get("TCAL",out);
89 tcal = out;
90}
91
92} //namespace
93
Note: See TracBrowser for help on using the repository browser.