// // C++ Interface: FillerBase // // Description: // // // Author: Malte Marquarding , (C) 2010 // // Copyright: See COPYING file that comes with this distribution // // #include #include #include "FillerBase.h" using namespace casa; namespace asap { FillerBase::FillerBase(casa::CountedPtr stable) : table_(stable) { row_ = TableRow(table_->table()); // FIT_ID is -1 by default RecordFieldPtr fitIdCol( row_.record(), "FIT_ID" ) ; *fitIdCol = -1 ; mEntry_.resize( 0 ) ; mIdx_.resize( 0 ) ; fEntry_.resize( 0 ) ; fIdx_.resize( 0 ) ; wEntry_.resize( 0 ) ; wIdx_.resize( 0 ) ; } void FillerBase::setHeader(const STHeader& header) { table_->setHeader(header); } void FillerBase::setSpectrum(const Vector& spectrum, const Vector& flags, const Vector& tsys) { RecordFieldPtr< Array > specCol(row_.record(), "SPECTRA"); RecordFieldPtr< Array > flagCol(row_.record(), "FLAGTRA"); RecordFieldPtr< Array > tsysCol(row_.record(), "TSYS"); //*specCol = spectrum; //*flagCol = flags; //*tsysCol = tsys; specCol.define(spectrum); flagCol.define(flags); tsysCol.define(tsys); } void FillerBase::setFlagrow(uInt flag) { RecordFieldPtr flagrowCol(row_.record(), "FLAGROW"); *flagrowCol = flag; } void FillerBase::setOpacity(Float opacity) { RecordFieldPtr tauCol(row_.record(), "OPACITY") ; *tauCol = opacity ; } void FillerBase::setIndex(uInt scanno, uInt cycleno, uInt ifno, uInt polno, uInt beamno) { RecordFieldPtr beamCol(row_.record(), "BEAMNO"); RecordFieldPtr ifCol(row_.record(), "IFNO"); RecordFieldPtr polCol(row_.record(), "POLNO"); RecordFieldPtr cycleCol(row_.record(), "CYCLENO"); RecordFieldPtr scanCol(row_.record(), "SCANNO"); *beamCol = beamno; *cycleCol = cycleno; *ifCol = ifno; *polCol = polno; *scanCol = scanno; } void FillerBase::setFrequency(Double refpix, Double refval, Double incr) { /// @todo this has to change when nchan isn't global anymore uInt nEntry = fEntry_.size() ; Int idx = -1 ; Vector entry( 3 ) ; entry[0] = refpix ; entry[1] = refval ; entry[2] = incr ; for ( uInt i = 0 ; i < nEntry ; i++ ) { if ( allEQ( entry, fEntry_[i] ) ) { idx = i ; break ; } } uInt id ; if ( idx != -1 ) id = fIdx_[idx] ; else { id= table_->frequencies().addEntry(refpix, refval, incr); RecordFieldPtr mfreqidCol(row_.record(), "FREQ_ID"); fEntry_.push_back( entry ) ; fIdx_.push_back( id ) ; } RecordFieldPtr mfreqidCol(row_.record(), "FREQ_ID"); *mfreqidCol = id; } void FillerBase::setMolecule(const Vector& restfreq) { uInt nEntry = mEntry_.size() ; Int idx = -1 ; for ( uInt i = 0 ; i < nEntry ; i++ ) { if ( restfreq.conform( mEntry_[i] ) && allEQ( restfreq, mEntry_[i] ) ) { idx = i ; break ; } } uInt id ; if ( idx != -1 ) id = mIdx_[idx] ; else { Vector tmp ; id = table_->molecules().addEntry(restfreq,tmp,tmp) ; mEntry_.push_back( restfreq.copy() ) ; mIdx_.push_back( id ) ; } RecordFieldPtr molidCol(row_.record(), "MOLECULE_ID"); *molidCol = id; } void FillerBase::setDirection(const Vector& dir, Float az, Float el) { RecordFieldPtr > dirCol(row_.record(), "DIRECTION"); *dirCol = dir; RecordFieldPtr azCol(row_.record(), "AZIMUTH"); *azCol = az; RecordFieldPtr elCol(row_.record(), "ELEVATION"); *elCol = el; } void FillerBase::setFocus(Float pa, Float faxis, Float ftan, Float frot) { RecordFieldPtr mfocusidCol(row_.record(), "FOCUS_ID"); uInt id = table_->focus().addEntry(pa, faxis, ftan, frot); *mfocusidCol = id; } void FillerBase::setTime(Double mjd, Double interval) { RecordFieldPtr mjdCol(row_.record(), "TIME"); *mjdCol = mjd; RecordFieldPtr intCol(row_.record(), "INTERVAL"); *intCol = interval; } void FillerBase::setWeather(Float temperature, Float pressure, Float humidity, Float windspeed, Float windaz) { uInt nEntry = wEntry_.size() ; Int idx = -1 ; Vector entry( 5 ) ; entry[0] = temperature ; entry[1] = pressure ; entry[2] = humidity ; entry[3] = windspeed ; entry[4] = windaz ; for ( uInt i = 0 ; i < nEntry ; i++ ) { if ( allEQ( entry, wEntry_[i] ) ) { idx = i ; break ; } } uInt id ; if ( idx != -1 ) id = wIdx_[idx] ; else { id = table_->weather().addEntry(temperature, pressure, humidity, windspeed, windaz); wEntry_.push_back( entry ) ; wIdx_.push_back( id ) ; } RecordFieldPtr mweatheridCol(row_.record(), "WEATHER_ID"); *mweatheridCol = id; } void FillerBase::setTcal(const String& tcaltime, const Vector& tcal) { uInt id = table_->tcal().addEntry(tcaltime, tcal); RecordFieldPtr mcalidCol(row_.record(), "TCAL_ID"); *mcalidCol = id; } void FillerBase::setScanRate(const Vector& srate) { RecordFieldPtr > srateCol(row_.record(), "SCANRATE"); *srateCol = srate; } void FillerBase::setReferenceBeam(Int beamno) { RecordFieldPtr rbCol(row_.record(), "REFBEAMNO"); *rbCol = beamno; } void FillerBase::setSource(const std::string& name, Int type, const std::string& fieldname, const Vector& dir, const Vector& propermot, Double velocity) { RecordFieldPtr srcnCol(row_.record(), "SRCNAME"); *srcnCol = name; RecordFieldPtr srctCol(row_.record(), "SRCTYPE"); *srctCol = type; RecordFieldPtr fieldnCol(row_.record(), "FIELDNAME"); *fieldnCol = fieldname; RecordFieldPtr > spmCol(row_.record(), "SRCPROPERMOTION"); *spmCol = propermot; RecordFieldPtr > sdirCol(row_.record(), "SRCDIRECTION"); *sdirCol = dir; RecordFieldPtr svelCol(row_.record(), "SRCVELOCITY"); *svelCol = velocity; } void FillerBase::commitRow() { table_->table().addRow(); row_.put(table_->table().nrow()-1); } void FillerBase::setWeather2(Float temperature, Float pressure, Float humidity, Float windspeed, Float windaz) { uInt nEntry = wEntry_.size() ; Int idx = -1 ; Vector entry( 5 ) ; entry[0] = temperature ; entry[1] = pressure ; entry[2] = humidity ; entry[3] = windspeed ; entry[4] = windaz ; for ( uInt i = 0 ; i < nEntry ; i++ ) { if ( allEQ( entry, wEntry_[i] ) ) { idx = i ; break ; } } uInt id ; if ( idx != -1 ) id = wIdx_[idx] ; else { Table tab = table_->weather().table() ; Table subt = tab( tab.col("TEMPERATURE") == temperature \ && tab.col("PRESSURE") == pressure \ && tab.col("HUMIDITY") == humidity \ && tab.col("WINDSPEED") == windspeed \ && tab.col("WINDAZ") == windaz, 1 ) ; Int nrow = tab.nrow() ; Int nrowSel = subt.nrow() ; if ( nrowSel == 0 ) { tab.addRow( 1, True ) ; TableRow row( tab ) ; TableRecord &rec = row.record() ; RecordFieldPtr rfpi ; rfpi.attachToRecord( rec, "ID" ) ; *rfpi = (uInt)nrow ; RecordFieldPtr rfp ; rfp.attachToRecord( rec, "TEMPERATURE" ) ; *rfp = temperature ; rfp.attachToRecord( rec, "PRESSURE" ) ; *rfp = pressure ; rfp.attachToRecord( rec, "HUMIDITY" ) ; *rfp = humidity ; rfp.attachToRecord( rec, "WINDSPEED" ) ; *rfp = windspeed ; rfp.attachToRecord( rec, "WINDAZ" ) ; *rfp = windaz ; row.put( nrow, rec ) ; id = (uInt)nrow ; } else { ROTableColumn tc( subt, "ID" ) ; id = tc.asuInt( 0 ) ; } wEntry_.push_back( entry ) ; wIdx_.push_back( id ) ; } RecordFieldPtr mweatheridCol(row_.record(), "WEATHER_ID"); *mweatheridCol = id; } void FillerBase::setTcal2(const String& tcaltime, const Vector& tcal) { uInt id = 0 ; Table tab = table_->tcal().table() ; Table result = //tab( nelements(tab.col("TCAL")) == uInt (tcal.size()) && // all(tab.col("TCAL")== tcal) && // tab.col("TIME") == tcaltime, 1 ) ; tab( nelements(tab.col("TCAL")) == uInt (tcal.size()) && all(tab.col("TCAL")== tcal), 1 ) ; if ( result.nrow() > 0 ) { ROTableColumn tmpCol( result, "ID" ) ; tmpCol.getScalar( 0, id ) ; } else { uInt rno = tab.nrow(); tab.addRow(); TableColumn idCol( tab, "ID" ) ; TableColumn tctimeCol( tab, "TIME" ) ; ArrayColumn tcalCol( tab, "TCAL" ) ; // get last assigned _id and increment if ( rno > 0 ) { idCol.getScalar(rno-1, id); id++; } tctimeCol.putScalar(rno, tcaltime); tcalCol.put(rno, tcal); idCol.putScalar(rno, id); } RecordFieldPtr mcalidCol(row_.record(), "TCAL_ID"); *mcalidCol = id; } };