source: trunk/src/STUpgrade.cpp@ 2330

Last change on this file since 2330 was 2321, checked in by Malte Marquarding, 13 years ago

Ticket #249: scantbable schema was changed. This required an update to scantable version 4. I have added a class STUpgrade to handle all schema upgrades. This is handled transparently in the scantable constructor

File size: 2.5 KB
Line 
1#include <tables/Tables/Table.h>
2#include <tables/Tables/ScaColDesc.h>
3#include <tables/Tables/ArrColDesc.h>
4#include <tables/Tables/ArrayColumn.h>
5
6#include "STUpgrade.h"
7
8
9using namespace casa;
10
11namespace asap {
12
13std::string STUpgrade::upgrade(const std::string& name) {
14 std::string inname = name;
15 Table origtab(name);
16 uInt version = origtab.keywordSet().asuInt("VERSION");
17 if (version == version_) {
18 return name;
19 }
20 if (version == 2) {
21 inname = two2three(inname);
22 version = 3;
23 }
24 if (version == 3) {
25 return three2four(inname);
26 }
27 throw(AipsError("Unsupported version of ASAP file."));
28}
29
30std::string STUpgrade::two2three(const std::string& name) {
31
32 std::string fname = name+".asap3";
33 Table origtab(name);
34 origtab.deepCopy(fname, Table::New);
35 Table tab(fname, Table::Update);
36 tab.removeColumn("PARANGLE");
37 Table tfocus = tab.rwKeywordSet().asTable("FOCUS");
38 ScalarColumnDesc<Float> pa("PARANGLE");
39 pa.setDefault(Float(0.0));
40 tfocus.addColumn(pa);
41 //tfocus.rwKeywordSet().define("PARALLACTIFY", False)
42 Int verid = tab.rwKeywordSet().fieldNumber("VERSION");
43 tab.rwKeywordSet().define(verid, uInt(3));
44 tab.tableInfo().setType("Scantable");
45 return fname;
46}
47
48std::string STUpgrade::three2four(const std::string& name) {
49 std::string fname = name+".asap4";
50 Table origtab(name);
51 origtab.deepCopy(fname, Table::New);
52 Table tab(fname, Table::Update);
53 Table moltable = tab.rwKeywordSet().asTable("MOLECULES");
54 Vector<String> cnames(3);
55 cnames[0] = "RESTFREQUENCY";
56 cnames[1] = "NAME";
57 cnames[2] = "FORMATTEDNAME";
58 ROScalarColumn<Double> rfcol(moltable, cnames[0]);
59 ROScalarColumn<String> nmecol(moltable, cnames[1]);
60 ROScalarColumn<String> fmtnmecol(moltable, cnames[2]);
61 Vector<Double> rf = rfcol.getColumn();
62 Vector<String> nme = nmecol.getColumn();
63 Vector<String> fmtnme = fmtnmecol.getColumn();
64 Array<Double> arf = rf.addDegenerate(1);
65 Array<String> anme = nme.addDegenerate(1);
66 Array<String> afmtnme = fmtnme.addDegenerate(1);
67 moltable.removeColumn(cnames);
68 moltable.addColumn(ArrayColumnDesc<Double>(cnames[0]));
69 moltable.addColumn(ArrayColumnDesc<String>(cnames[1]));
70 moltable.addColumn(ArrayColumnDesc<String>(cnames[2]));
71 ArrayColumn<Double> arfcol(moltable, cnames[0]);
72 ArrayColumn<String> anmecol(moltable, cnames[1]);
73 ArrayColumn<String> afmtnmecol(moltable, cnames[2] );
74 arfcol.putColumn(arf);
75 anmecol.putColumn(anme);
76 afmtnmecol.putColumn(afmtnme);
77
78 Int verid = tab.rwKeywordSet().fieldNumber("VERSION");
79 tab.rwKeywordSet().define(verid, uInt(4));
80 return fname;
81}
82
83}
Note: See TracBrowser for help on using the repository browser.