source: branches/hpc34/src/FillerBase.cpp@ 2780

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

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Fixed a bug that MOLECULES table has only one row even if input data
has multiple rest frequency settings.


File size: 9.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 // FIT_ID is -1 by default
28 RecordFieldPtr<Int> fitIdCol( row_.record(), "FIT_ID" ) ;
29 *fitIdCol = -1 ;
30
31 mEntry_.resize( 0 ) ;
32 mIdx_.resize( 0 ) ;
33 fEntry_.resize( 0 ) ;
34 fIdx_.resize( 0 ) ;
35 wEntry_.resize( 0 ) ;
36 wIdx_.resize( 0 ) ;
37}
38
39void FillerBase::setHeader(const STHeader& header)
40{
41 table_->setHeader(header);
42}
43
44void FillerBase::setSpectrum(const Vector<Float>& spectrum,
45 const Vector<uChar>& flags,
46 const Vector<Float>& tsys)
47{
48 RecordFieldPtr< Array<Float> > specCol(row_.record(), "SPECTRA");
49 RecordFieldPtr< Array<uChar> > flagCol(row_.record(), "FLAGTRA");
50 RecordFieldPtr< Array<Float> > tsysCol(row_.record(), "TSYS");
51
52 //*specCol = spectrum;
53 //*flagCol = flags;
54 //*tsysCol = tsys;
55 specCol.define(spectrum);
56 flagCol.define(flags);
57 tsysCol.define(tsys);
58}
59
60void FillerBase::setFlagrow(uInt flag)
61{
62 RecordFieldPtr<uInt> flagrowCol(row_.record(), "FLAGROW");
63 *flagrowCol = flag;
64}
65
66void FillerBase::setOpacity(Float opacity)
67{
68 RecordFieldPtr<Float> tauCol(row_.record(), "OPACITY") ;
69 *tauCol = opacity ;
70}
71
72void FillerBase::setIndex(uInt scanno, uInt cycleno, uInt ifno, uInt polno,
73 uInt beamno)
74{
75 RecordFieldPtr<uInt> beamCol(row_.record(), "BEAMNO");
76 RecordFieldPtr<uInt> ifCol(row_.record(), "IFNO");
77 RecordFieldPtr<uInt> polCol(row_.record(), "POLNO");
78 RecordFieldPtr<uInt> cycleCol(row_.record(), "CYCLENO");
79 RecordFieldPtr<uInt> scanCol(row_.record(), "SCANNO");
80 *beamCol = beamno;
81 *cycleCol = cycleno;
82 *ifCol = ifno;
83 *polCol = polno;
84 *scanCol = scanno;
85}
86
87void FillerBase::setFrequency(Double refpix, Double refval,
88 Double incr)
89{
90 /// @todo this has to change when nchan isn't global anymore
91 uInt nEntry = fEntry_.size() ;
92 Int idx = -1 ;
93 Vector<Double> entry( 3 ) ;
94 entry[0] = refpix ;
95 entry[1] = refval ;
96 entry[2] = incr ;
97 for ( uInt i = 0 ; i < nEntry ; i++ ) {
98 if ( allEQ( entry, fEntry_[i] ) ) {
99 idx = i ;
100 break ;
101 }
102 }
103 uInt id ;
104 if ( idx != -1 )
105 id = fIdx_[idx] ;
106 else {
107 id= table_->frequencies().addEntry(refpix, refval, incr);
108 RecordFieldPtr<uInt> mfreqidCol(row_.record(), "FREQ_ID");
109 fEntry_.push_back( entry ) ;
110 fIdx_.push_back( id ) ;
111 }
112 RecordFieldPtr<uInt> mfreqidCol(row_.record(), "FREQ_ID");
113 *mfreqidCol = id;
114
115}
116
117
118void FillerBase::setMolecule(const Vector<Double>& restfreq)
119{
120 uInt nEntry = mEntry_.size() ;
121 Int idx = -1 ;
122 for ( uInt i = 0 ; i < nEntry ; i++ ) {
123 if ( restfreq.conform( mEntry_[i] ) &&
124 allEQ( restfreq, mEntry_[i] ) ) {
125 idx = i ;
126 break ;
127 }
128 }
129 uInt id ;
130 if ( idx != -1 )
131 id = mIdx_[idx] ;
132 else {
133 Vector<String> tmp ;
134 id = table_->molecules().addEntry(restfreq,tmp,tmp) ;
135 mEntry_.push_back( restfreq.copy() ) ;
136 mIdx_.push_back( id ) ;
137 }
138 RecordFieldPtr<uInt> molidCol(row_.record(), "MOLECULE_ID");
139 *molidCol = id;
140}
141
142void FillerBase::setDirection(const Vector<Double>& dir,
143 Float az, Float el)
144{
145 RecordFieldPtr<Array<Double> > dirCol(row_.record(), "DIRECTION");
146 *dirCol = dir;
147 RecordFieldPtr<Float> azCol(row_.record(), "AZIMUTH");
148 *azCol = az;
149 RecordFieldPtr<Float> elCol(row_.record(), "ELEVATION");
150 *elCol = el;
151}
152
153void FillerBase::setFocus(Float pa, Float faxis,
154 Float ftan, Float frot)
155{
156 RecordFieldPtr<uInt> mfocusidCol(row_.record(), "FOCUS_ID");
157 uInt id = table_->focus().addEntry(pa, faxis, ftan, frot);
158 *mfocusidCol = id;
159}
160
161void FillerBase::setTime(Double mjd, Double interval)
162{
163 RecordFieldPtr<Double> mjdCol(row_.record(), "TIME");
164 *mjdCol = mjd;
165 RecordFieldPtr<Double> intCol(row_.record(), "INTERVAL");
166 *intCol = interval;
167
168}
169
170void FillerBase::setWeather(Float temperature, Float pressure,
171 Float humidity,
172 Float windspeed, Float windaz)
173{
174 uInt nEntry = wEntry_.size() ;
175 Int idx = -1 ;
176 Vector<Float> entry( 5 ) ;
177 entry[0] = temperature ;
178 entry[1] = pressure ;
179 entry[2] = humidity ;
180 entry[3] = windspeed ;
181 entry[4] = windaz ;
182 for ( uInt i = 0 ; i < nEntry ; i++ ) {
183 if ( allEQ( entry, wEntry_[i] ) ) {
184 idx = i ;
185 break ;
186 }
187 }
188 uInt id ;
189 if ( idx != -1 )
190 id = wIdx_[idx] ;
191 else {
192 id = table_->weather().addEntry(temperature, pressure,
193 humidity, windspeed, windaz);
194 wEntry_.push_back( entry ) ;
195 wIdx_.push_back( id ) ;
196 }
197 RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
198 *mweatheridCol = id;
199}
200
201void FillerBase::setTcal(const String& tcaltime,
202 const Vector<Float>& tcal)
203{
204 uInt id = table_->tcal().addEntry(tcaltime, tcal);
205 RecordFieldPtr<uInt> mcalidCol(row_.record(), "TCAL_ID");
206 *mcalidCol = id;
207}
208
209void FillerBase::setScanRate(const Vector<Double>& srate)
210{
211 RecordFieldPtr<Array<Double> > srateCol(row_.record(), "SCANRATE");
212 *srateCol = srate;
213}
214
215void FillerBase::setReferenceBeam(Int beamno)
216{
217 RecordFieldPtr<Int> rbCol(row_.record(), "REFBEAMNO");
218 *rbCol = beamno;
219}
220
221void FillerBase::setSource(const std::string& name, Int type,
222 const std::string& fieldname,
223 const Vector<Double>& dir,
224 const Vector<Double>& propermot,
225 Double velocity)
226{
227 RecordFieldPtr<String> srcnCol(row_.record(), "SRCNAME");
228 *srcnCol = name;
229 RecordFieldPtr<Int> srctCol(row_.record(), "SRCTYPE");
230 *srctCol = type;
231 RecordFieldPtr<String> fieldnCol(row_.record(), "FIELDNAME");
232 *fieldnCol = fieldname;
233 RecordFieldPtr<Array<Double> > spmCol(row_.record(), "SRCPROPERMOTION");
234 *spmCol = propermot;
235 RecordFieldPtr<Array<Double> > sdirCol(row_.record(), "SRCDIRECTION");
236 *sdirCol = dir;
237 RecordFieldPtr<Double> svelCol(row_.record(), "SRCVELOCITY");
238 *svelCol = velocity;
239}
240
241void FillerBase::commitRow()
242{
243 table_->table().addRow();
244 row_.put(table_->table().nrow()-1);
245}
246
247void FillerBase::setWeather2(Float temperature,
248 Float pressure,
249 Float humidity,
250 Float windspeed,
251 Float windaz)
252{
253 uInt nEntry = wEntry_.size() ;
254 Int idx = -1 ;
255 Vector<Float> entry( 5 ) ;
256 entry[0] = temperature ;
257 entry[1] = pressure ;
258 entry[2] = humidity ;
259 entry[3] = windspeed ;
260 entry[4] = windaz ;
261 for ( uInt i = 0 ; i < nEntry ; i++ ) {
262 if ( allEQ( entry, wEntry_[i] ) ) {
263 idx = i ;
264 break ;
265 }
266 }
267 uInt id ;
268 if ( idx != -1 )
269 id = wIdx_[idx] ;
270 else {
271 Table tab = table_->weather().table() ;
272 Table subt = tab( tab.col("TEMPERATURE") == temperature \
273 && tab.col("PRESSURE") == pressure \
274 && tab.col("HUMIDITY") == humidity \
275 && tab.col("WINDSPEED") == windspeed \
276 && tab.col("WINDAZ") == windaz, 1 ) ;
277 Int nrow = tab.nrow() ;
278 Int nrowSel = subt.nrow() ;
279 if ( nrowSel == 0 ) {
280 tab.addRow( 1, True ) ;
281 TableRow row( tab ) ;
282 TableRecord &rec = row.record() ;
283 RecordFieldPtr<casa::uInt> rfpi ;
284 rfpi.attachToRecord( rec, "ID" ) ;
285 *rfpi = (uInt)nrow ;
286 RecordFieldPtr<casa::Float> rfp ;
287 rfp.attachToRecord( rec, "TEMPERATURE" ) ;
288 *rfp = temperature ;
289 rfp.attachToRecord( rec, "PRESSURE" ) ;
290 *rfp = pressure ;
291 rfp.attachToRecord( rec, "HUMIDITY" ) ;
292 *rfp = humidity ;
293 rfp.attachToRecord( rec, "WINDSPEED" ) ;
294 *rfp = windspeed ;
295 rfp.attachToRecord( rec, "WINDAZ" ) ;
296 *rfp = windaz ;
297 row.put( nrow, rec ) ;
298 id = (uInt)nrow ;
299 }
300 else {
301 ROTableColumn tc( subt, "ID" ) ;
302 id = tc.asuInt( 0 ) ;
303 }
304 wEntry_.push_back( entry ) ;
305 wIdx_.push_back( id ) ;
306 }
307 RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
308 *mweatheridCol = id;
309}
310
311void FillerBase::setTcal2(const String& tcaltime,
312 const Vector<Float>& tcal)
313{
314 uInt id = 0 ;
315 Table tab = table_->tcal().table() ;
316 Table result =
317 //tab( nelements(tab.col("TCAL")) == uInt (tcal.size()) &&
318 // all(tab.col("TCAL")== tcal) &&
319 // tab.col("TIME") == tcaltime, 1 ) ;
320 tab( nelements(tab.col("TCAL")) == uInt (tcal.size()) &&
321 all(tab.col("TCAL")== tcal), 1 ) ;
322
323 if ( result.nrow() > 0 ) {
324 ROTableColumn tmpCol( result, "ID" ) ;
325 tmpCol.getScalar( 0, id ) ;
326 }
327 else {
328 uInt rno = tab.nrow();
329 tab.addRow();
330 TableColumn idCol( tab, "ID" ) ;
331 TableColumn tctimeCol( tab, "TIME" ) ;
332 ArrayColumn<Float> tcalCol( tab, "TCAL" ) ;
333 // get last assigned _id and increment
334 if ( rno > 0 ) {
335 idCol.getScalar(rno-1, id);
336 id++;
337 }
338 tctimeCol.putScalar(rno, tcaltime);
339 tcalCol.put(rno, tcal);
340 idCol.putScalar(rno, id);
341 }
342
343 RecordFieldPtr<uInt> mcalidCol(row_.record(), "TCAL_ID");
344 *mcalidCol = id;
345}
346
347};
Note: See TracBrowser for help on using the repository browser.