source: branches/parallel/src/FillerBase.cpp@ 2248

Last change on this file since 2248 was 2247, checked in by Takeshi Nakazato, 13 years ago

merged changes in trunk (r2209,r2202,r2243

File size: 7.3 KB
Line 
1//
2// C++ Interface: FillerBase
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2010
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12
13#include <casa/Containers/RecordField.h>
14#include <tables/Tables/ExprNode.h>
15
16#include "FillerBase.h"
17
18using namespace casa;
19
20namespace asap {
21
22FillerBase::FillerBase(casa::CountedPtr<Scantable> stable) :
23 table_(stable)
24{
25 row_ = TableRow(table_->table());
26}
27
28void FillerBase::setHeader(const STHeader& header)
29{
30 table_->setHeader(header);
31}
32
33void FillerBase::setSpectrum(const Vector<Float>& spectrum,
34 const Vector<uChar>& flags,
35 const Vector<Float>& tsys)
36{
37 RecordFieldPtr< Array<Float> > specCol(row_.record(), "SPECTRA");
38 RecordFieldPtr< Array<uChar> > flagCol(row_.record(), "FLAGTRA");
39 RecordFieldPtr< Array<Float> > tsysCol(row_.record(), "TSYS");
40
41 //*specCol = spectrum;
42 //*flagCol = flags;
43 //*tsysCol = tsys;
44 specCol.define(spectrum);
45 flagCol.define(flags);
46 tsysCol.define(tsys);
47}
48
49void FillerBase::setFlagrow(uInt flag)
50{
51 RecordFieldPtr<uInt> flagrowCol(row_.record(), "FLAGROW");
52 *flagrowCol = flag;
53}
54
55void FillerBase::setOpacity(Float opacity)
56{
57 RecordFieldPtr<Float> tauCol(row_.record(), "OPACITY") ;
58 *tauCol = opacity ;
59}
60
61void FillerBase::setIndex(uInt scanno, uInt cycleno, uInt ifno, uInt polno,
62 uInt beamno)
63{
64 RecordFieldPtr<uInt> beamCol(row_.record(), "BEAMNO");
65 RecordFieldPtr<uInt> ifCol(row_.record(), "IFNO");
66 RecordFieldPtr<uInt> polCol(row_.record(), "POLNO");
67 RecordFieldPtr<uInt> cycleCol(row_.record(), "CYCLENO");
68 RecordFieldPtr<uInt> scanCol(row_.record(), "SCANNO");
69 *beamCol = beamno;
70 *cycleCol = cycleno;
71 *ifCol = ifno;
72 *polCol = polno;
73 *scanCol = scanno;
74}
75
76void FillerBase::setFrequency(Double refpix, Double refval,
77 Double incr)
78{
79 /// @todo this has to change when nchan isn't global anymore
80 uInt id= table_->frequencies().addEntry(refpix, refval, incr);
81 RecordFieldPtr<uInt> mfreqidCol(row_.record(), "FREQ_ID");
82 *mfreqidCol = id;
83
84}
85
86
87void FillerBase::setMolecule(const Vector<Double>& restfreq)
88{
89 Vector<String> tmp;
90 uInt id = table_->molecules().addEntry(restfreq, tmp, tmp);
91 RecordFieldPtr<uInt> molidCol(row_.record(), "MOLECULE_ID");
92 *molidCol = id;
93}
94
95void FillerBase::setDirection(const Vector<Double>& dir,
96 Float az, Float el)
97{
98 RecordFieldPtr<Array<Double> > dirCol(row_.record(), "DIRECTION");
99 *dirCol = dir;
100 RecordFieldPtr<Float> azCol(row_.record(), "AZIMUTH");
101 *azCol = az;
102 RecordFieldPtr<Float> elCol(row_.record(), "ELEVATION");
103 *elCol = el;
104}
105
106void FillerBase::setFocus(Float pa, Float faxis,
107 Float ftan, Float frot)
108{
109 RecordFieldPtr<uInt> mfocusidCol(row_.record(), "FOCUS_ID");
110 uInt id = table_->focus().addEntry(pa, faxis, ftan, frot);
111 *mfocusidCol = id;
112}
113
114void FillerBase::setTime(Double mjd, Double interval)
115{
116 RecordFieldPtr<Double> mjdCol(row_.record(), "TIME");
117 *mjdCol = mjd;
118 RecordFieldPtr<Double> intCol(row_.record(), "INTERVAL");
119 *intCol = interval;
120
121}
122
123void FillerBase::setWeather(Float temperature, Float pressure,
124 Float humidity,
125 Float windspeed, Float windaz)
126{
127 uInt id = table_->weather().addEntry(temperature, pressure,
128 humidity, windspeed, windaz);
129 RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
130 *mweatheridCol = id;
131}
132
133void FillerBase::setTcal(const String& tcaltime,
134 const Vector<Float>& tcal)
135{
136 uInt id = table_->tcal().addEntry(tcaltime, tcal);
137 RecordFieldPtr<uInt> mcalidCol(row_.record(), "TCAL_ID");
138 *mcalidCol = id;
139}
140
141void FillerBase::setScanRate(const Vector<Double>& srate)
142{
143 RecordFieldPtr<Array<Double> > srateCol(row_.record(), "SCANRATE");
144 *srateCol = srate;
145}
146
147void FillerBase::setReferenceBeam(Int beamno)
148{
149 RecordFieldPtr<Int> rbCol(row_.record(), "REFBEAMNO");
150 *rbCol = beamno;
151}
152
153void FillerBase::setSource(const std::string& name, Int type,
154 const std::string& fieldname,
155 const Vector<Double>& dir,
156 const Vector<Double>& propermot,
157 Double velocity)
158{
159 RecordFieldPtr<String> srcnCol(row_.record(), "SRCNAME");
160 *srcnCol = name;
161 RecordFieldPtr<Int> srctCol(row_.record(), "SRCTYPE");
162 *srctCol = type;
163 RecordFieldPtr<String> fieldnCol(row_.record(), "FIELDNAME");
164 *fieldnCol = fieldname;
165 RecordFieldPtr<Array<Double> > spmCol(row_.record(), "SRCPROPERMOTION");
166 *spmCol = propermot;
167 RecordFieldPtr<Array<Double> > sdirCol(row_.record(), "SRCDIRECTION");
168 *sdirCol = dir;
169 RecordFieldPtr<Double> svelCol(row_.record(), "SRCVELOCITY");
170 *svelCol = velocity;
171}
172
173void FillerBase::commitRow()
174{
175 table_->table().addRow();
176 row_.put(table_->table().nrow()-1);
177}
178
179void FillerBase::setWeather2(Float temperature,
180 Float pressure,
181 Float humidity,
182 Float windspeed,
183 Float windaz)
184{
185 uInt id ;
186 Table tab = table_->weather().table() ;
187 Table subt = tab( tab.col("TEMPERATURE") == temperature \
188 && tab.col("PRESSURE") == pressure \
189 && tab.col("HUMIDITY") == humidity \
190 && tab.col("WINDSPEED") == windspeed \
191 && tab.col("WINDAZ") == windaz, 1 ) ;
192 Int nrow = tab.nrow() ;
193 Int nrowSel = subt.nrow() ;
194 if ( nrowSel == 0 ) {
195 tab.addRow( 1, True ) ;
196 TableRow row( tab ) ;
197 TableRecord &rec = row.record() ;
198 RecordFieldPtr<casa::uInt> rfpi ;
199 rfpi.attachToRecord( rec, "ID" ) ;
200 *rfpi = (uInt)nrow ;
201 RecordFieldPtr<casa::Float> rfp ;
202 rfp.attachToRecord( rec, "TEMPERATURE" ) ;
203 *rfp = temperature ;
204 rfp.attachToRecord( rec, "PRESSURE" ) ;
205 *rfp = pressure ;
206 rfp.attachToRecord( rec, "HUMIDITY" ) ;
207 *rfp = humidity ;
208 rfp.attachToRecord( rec, "WINDSPEED" ) ;
209 *rfp = windspeed ;
210 rfp.attachToRecord( rec, "WINDAZ" ) ;
211 *rfp = windaz ;
212 row.put( nrow, rec ) ;
213 id = (uInt)nrow ;
214 }
215 else {
216 ROTableColumn tc( subt, "ID" ) ;
217 id = tc.asuInt( 0 ) ;
218 }
219 RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
220 *mweatheridCol = id;
221}
222
223void FillerBase::setTcal2(const String& tcaltime,
224 const Vector<Float>& tcal)
225{
226 uInt id = 0 ;
227 Table tab = table_->tcal().table() ;
228 Table result =
229 //tab( nelements(tab.col("TCAL")) == uInt (tcal.size()) &&
230 // all(tab.col("TCAL")== tcal) &&
231 // tab.col("TIME") == tcaltime, 1 ) ;
232 tab( nelements(tab.col("TCAL")) == uInt (tcal.size()) &&
233 all(tab.col("TCAL")== tcal), 1 ) ;
234
235 if ( result.nrow() > 0 ) {
236 ROTableColumn tmpCol( result, "ID" ) ;
237 tmpCol.getScalar( 0, id ) ;
238 }
239 else {
240 uInt rno = tab.nrow();
241 tab.addRow();
242 TableColumn idCol( tab, "ID" ) ;
243 TableColumn tctimeCol( tab, "TIME" ) ;
244 ArrayColumn<Float> tcalCol( tab, "TCAL" ) ;
245 // get last assigned _id and increment
246 if ( rno > 0 ) {
247 idCol.getScalar(rno-1, id);
248 id++;
249 }
250 tctimeCol.putScalar(rno, tcaltime);
251 tcalCol.put(rno, tcal);
252 idCol.putScalar(rno, id);
253 }
254
255 RecordFieldPtr<uInt> mcalidCol(row_.record(), "TCAL_ID");
256 *mcalidCol = id;
257}
258
259};
Note: See TracBrowser for help on using the repository browser.