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