source: trunk/src/FillerBase.cpp @ 2242

Last change on this file since 2242 was 2242, 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: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Added maxRow=1 in table selection using TableExprNode? when
finding at least one row is enough.


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