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