source: branches/plotter2/src/STHistory.cpp@ 2980

Last change on this file since 2980 was 2820, checked in by Malte Marquarding, 11 years ago

Issue #293: added scantbale.drop_history and added extra parameters to scantable.history to allow selection of rows

File size: 2.2 KB
Line 
1//
2// C++ Implementation: STHistory
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/TableParse.h>
17#include <tables/Tables/TableRow.h>
18#include <tables/Tables/TableCopy.h>
19
20#include "STDefs.h"
21#include "STHistory.h"
22#include "MathUtils.h"
23
24using namespace casa;
25
26namespace asap {
27
28const casa::String STHistory::name_ = "HISTORY";
29
30STHistory::STHistory(const Scantable& parent ) :
31 STSubTable( parent, name_ )
32{
33 setup();
34}
35
36asap::STHistory::STHistory( casa::Table tab ) : STSubTable(tab, name_)
37{
38 itemCol_.attach(table_,"ITEM");
39}
40
41STHistory::~STHistory()
42{
43}
44
45STHistory& asap::STHistory::operator =( const STHistory & other )
46{
47 if (this != &other) {
48 static_cast<STSubTable&>(*this) = other;
49 itemCol_.attach(table_,"ITEM");
50 }
51 return *this;
52}
53void asap::STHistory::setup( )
54{
55 // add to base class table
56 table_.addColumn(ScalarColumnDesc<String>("ITEM"));
57
58 // new cached columns
59 itemCol_.attach(table_,"ITEM");
60}
61
62uInt STHistory::addEntry( const String& item)
63{
64 uInt rno = table_.nrow();
65 table_.addRow();
66 itemCol_.put(rno, item);
67 idCol_.put(rno, 0);
68 return 0;
69}
70
71void asap::STHistory::getEntry( String& item, uInt id)
72{
73 Table t = table_(table_.col("ID") == Int(id), 1 );
74 if (t.nrow() == 0 ) {
75 throw(AipsError("STHistory::getEntry - id out of range"));
76 }
77 item = "";
78}
79
80void asap::STHistory::append( const STHistory & other )
81{
82 const Table& t = other.table();
83 if (other.nrow() > 0) {
84 addEntry(asap::SEPERATOR);
85 TableCopy::copyRows(table_, t, table_.nrow(), 0, t.nrow());
86 addEntry(asap::SEPERATOR);
87 }
88
89}
90
91std::vector<std::string> asap::STHistory::getHistory( int nrow,
92 int start) const
93{
94 if (nrow < 0) {
95 nrow = this->nrow();
96 }
97 AlwaysAssert(nrow <= this->nrow(), AipsError);
98 Vector<String> rows;
99 Slicer slice(IPosition(1, start), IPosition(1, nrow));
100
101 rows = itemCol_.getColumnRange(slice);
102 return mathutil::tovectorstring(rows);
103}
104
105 void asap::STHistory::drop() {
106 table_.removeRow(table_.rowNumbers());
107 }
108
109}
Note: See TracBrowser for help on using the repository browser.