[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 ;
|
---|
[1778] | 30 | }
|
---|
| 31 |
|
---|
[1793] | 32 | void FillerBase::setHeader(const STHeader& header)
|
---|
| 33 | {
|
---|
| 34 | table_->setHeader(header);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[1778] | 37 | void FillerBase::setSpectrum(const Vector<Float>& spectrum,
|
---|
[1788] | 38 | const Vector<uChar>& flags,
|
---|
| 39 | const Vector<Float>& tsys)
|
---|
[1778] | 40 | {
|
---|
| 41 | RecordFieldPtr< Array<Float> > specCol(row_.record(), "SPECTRA");
|
---|
| 42 | RecordFieldPtr< Array<uChar> > flagCol(row_.record(), "FLAGTRA");
|
---|
[1788] | 43 | RecordFieldPtr< Array<Float> > tsysCol(row_.record(), "TSYS");
|
---|
| 44 |
|
---|
[1876] | 45 | //*specCol = spectrum;
|
---|
| 46 | //*flagCol = flags;
|
---|
| 47 | //*tsysCol = tsys;
|
---|
| 48 | specCol.define(spectrum);
|
---|
| 49 | flagCol.define(flags);
|
---|
| 50 | tsysCol.define(tsys);
|
---|
[1778] | 51 | }
|
---|
| 52 |
|
---|
[1803] | 53 | void FillerBase::setFlagrow(uInt flag)
|
---|
| 54 | {
|
---|
| 55 | RecordFieldPtr<uInt> flagrowCol(row_.record(), "FLAGROW");
|
---|
| 56 | *flagrowCol = flag;
|
---|
| 57 | }
|
---|
[1788] | 58 |
|
---|
| 59 | void FillerBase::setOpacity(Float opacity)
|
---|
| 60 | {
|
---|
| 61 | RecordFieldPtr<Float> tauCol(row_.record(), "OPACITY") ;
|
---|
| 62 | *tauCol = opacity ;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[1778] | 65 | void 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");
|
---|
[1780] | 72 | RecordFieldPtr<uInt> scanCol(row_.record(), "SCANNO");
|
---|
[1778] | 73 | *beamCol = beamno;
|
---|
| 74 | *cycleCol = cycleno;
|
---|
| 75 | *ifCol = ifno;
|
---|
| 76 | *polCol = polno;
|
---|
| 77 | *scanCol = scanno;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | void FillerBase::setFrequency(Double refpix, Double refval,
|
---|
[1780] | 81 | Double incr)
|
---|
[1778] | 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 |
|
---|
[1780] | 91 | void FillerBase::setMolecule(const Vector<Double>& restfreq)
|
---|
[1778] | 92 | {
|
---|
[1780] | 93 | Vector<String> tmp;
|
---|
| 94 | uInt id = table_->molecules().addEntry(restfreq, tmp, tmp);
|
---|
[1778] | 95 | RecordFieldPtr<uInt> molidCol(row_.record(), "MOLECULE_ID");
|
---|
| 96 | *molidCol = id;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[1780] | 99 | void FillerBase::setDirection(const Vector<Double>& dir,
|
---|
[1778] | 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 |
|
---|
| 110 | void 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 |
|
---|
[1809] | 118 | void FillerBase::setTime(Double mjd, Double interval)
|
---|
[1778] | 119 | {
|
---|
| 120 | RecordFieldPtr<Double> mjdCol(row_.record(), "TIME");
|
---|
| 121 | *mjdCol = mjd;
|
---|
| 122 | RecordFieldPtr<Double> intCol(row_.record(), "INTERVAL");
|
---|
| 123 | *intCol = interval;
|
---|
| 124 |
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | void 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 |
|
---|
| 137 | void 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 |
|
---|
| 145 | void FillerBase::setScanRate(const Vector<Double>& srate)
|
---|
| 146 | {
|
---|
| 147 | RecordFieldPtr<Array<Double> > srateCol(row_.record(), "SCANRATE");
|
---|
| 148 | *srateCol = srate;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | void FillerBase::setReferenceBeam(Int beamno)
|
---|
| 152 | {
|
---|
| 153 | RecordFieldPtr<Int> rbCol(row_.record(), "REFBEAMNO");
|
---|
| 154 | *rbCol = beamno;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | void FillerBase::setSource(const std::string& name, Int type,
|
---|
| 158 | const std::string& fieldname,
|
---|
| 159 | const Vector<Double>& dir,
|
---|
| 160 | const Vector<Double>& propermot,
|
---|
[1780] | 161 | Double velocity)
|
---|
[1778] | 162 | {
|
---|
| 163 | RecordFieldPtr<String> srcnCol(row_.record(), "SRCNAME");
|
---|
[1780] | 164 | *srcnCol = name;
|
---|
[1778] | 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");
|
---|
[1780] | 170 | *spmCol = propermot;
|
---|
[1778] | 171 | RecordFieldPtr<Array<Double> > sdirCol(row_.record(), "SRCDIRECTION");
|
---|
[1780] | 172 | *sdirCol = dir;
|
---|
[1778] | 173 | RecordFieldPtr<Double> svelCol(row_.record(), "SRCVELOCITY");
|
---|
[1780] | 174 | *svelCol = velocity;
|
---|
[1778] | 175 | }
|
---|
| 176 |
|
---|
| 177 | void FillerBase::commitRow()
|
---|
| 178 | {
|
---|
| 179 | table_->table().addRow();
|
---|
| 180 | row_.put(table_->table().nrow()-1);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[2209] | 183 | void 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 ) ;
|
---|
| 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 |
|
---|
| 227 | void FillerBase::setTcal2(const String& tcaltime,
|
---|
| 228 | const Vector<Float>& tcal)
|
---|
| 229 | {
|
---|
| 230 | uInt id ;
|
---|
| 231 | Table tab = table_->tcal().table() ;
|
---|
| 232 | Int nrow = tab.nrow() ;
|
---|
| 233 | Vector<uInt> rowList( 0 ) ;
|
---|
| 234 | ArrayColumn<Float> tcalCol( tab, "TCAL" ) ;
|
---|
| 235 | TableColumn timeCol( tab, "TIME" ) ;
|
---|
| 236 | TableColumn idCol( tab, "ID" ) ;
|
---|
| 237 | uInt nelem = tcal.nelements() ;
|
---|
| 238 | for ( Int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 239 | if ( tcalCol.shape(irow)[0] == nelem ) {
|
---|
| 240 | rowList.resize( rowList.nelements()+1, True ) ;
|
---|
| 241 | rowList[rowList.nelements()-1] = irow ;
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | //cout << "rowList = " << rowList << endl ;
|
---|
| 246 |
|
---|
| 247 | if ( rowList.nelements() == 0 ) {
|
---|
| 248 | // add new row
|
---|
| 249 | tab.addRow( 1 ) ;
|
---|
| 250 | //cout << "tab.nrow() = " << tab.nrow() << endl ;
|
---|
| 251 | tcalCol.put( nrow, tcal ) ;
|
---|
| 252 | timeCol.putScalar( nrow, tcaltime ) ;
|
---|
| 253 | id = (uInt)nrow ;
|
---|
| 254 | idCol.putScalar( nrow, id ) ;
|
---|
| 255 | }
|
---|
| 256 | else {
|
---|
| 257 | uInt ichan = 0 ;
|
---|
| 258 | while ( rowList.nelements() > 1 && ichan < nelem ) {
|
---|
| 259 | Vector<uInt> tmp = rowList.copy() ;
|
---|
| 260 | rowList.resize( 0 ) ;
|
---|
| 261 | for ( uInt irow = 0 ; irow < tmp.nelements() ; irow++ ) {
|
---|
| 262 | Vector<Float> t = tcalCol( tmp[irow] ) ;
|
---|
| 263 | if ( t[ichan] == tcal[ichan] ) {
|
---|
| 264 | rowList.resize( rowList.nelements()+1, True ) ;
|
---|
| 265 | rowList[rowList.nelements()-1] = irow ;
|
---|
| 266 | }
|
---|
| 267 | }
|
---|
| 268 | ichan++ ;
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | //cout << "updated rowList = " << rowList << endl ;
|
---|
| 272 |
|
---|
| 273 | if ( rowList.nelements() == 0 ) {
|
---|
| 274 | // add new row
|
---|
| 275 | tab.addRow( 1, True ) ;
|
---|
| 276 | //cout << "tab.nrow() = " << tab.nrow() << endl ;
|
---|
| 277 | tcalCol.put( nrow, tcal ) ;
|
---|
| 278 | timeCol.putScalar( nrow, tcaltime ) ;
|
---|
| 279 | id = (uInt)nrow ;
|
---|
| 280 | idCol.putScalar( nrow, id ) ;
|
---|
| 281 | }
|
---|
| 282 | else {
|
---|
| 283 | Vector<Float> t = tcalCol( rowList[0] ) ;
|
---|
| 284 | if ( allEQ( t, tcal ) ) {
|
---|
| 285 | ROTableColumn tc( tab, "ID" ) ;
|
---|
| 286 | id = tc.asuInt( rowList[0] ) ;
|
---|
| 287 | }
|
---|
| 288 | else {
|
---|
| 289 | // add new row
|
---|
| 290 | tab.addRow( 1, True ) ;
|
---|
| 291 | //cout << "tab.nrow() = " << tab.nrow() << endl ;
|
---|
| 292 | tcalCol.put( nrow, tcal ) ;
|
---|
| 293 | timeCol.putScalar( nrow, tcaltime ) ;
|
---|
| 294 | id = (uInt)nrow ;
|
---|
| 295 | idCol.putScalar( nrow, id ) ;
|
---|
| 296 | }
|
---|
| 297 | }
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | RecordFieldPtr<uInt> mcalidCol(row_.record(), "TCAL_ID");
|
---|
| 301 | *mcalidCol = id;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
[1778] | 304 | };
|
---|