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