Changeset 322


Ignore:
Timestamp:
01/30/05 01:30:41 (20 years ago)
Author:
kil064
Message:

cache all the ScalarColumn and ArrayColumn objects to avoid reconstructnig
themn for every row get/put.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMemTable.cc

    r321 r322  
    5050
    5151#include <tables/Tables/ExprNode.h>
    52 #include <tables/Tables/ScalarColumn.h>
    53 #include <tables/Tables/ArrayColumn.h>
    5452#include <tables/Tables/TableRecord.h>
    5553#include <measures/Measures/MFrequency.h>
     
    7371{
    7472  setup();
     73cerr << "Call SDMemTable::attach" << endl;
     74  attach();
    7575}
    7676
     
    100100    polSel_ = other.polSel_;
    101101  }
     102//
     103  attach();
    102104  //cerr << "hello from CC SDMemTable @ " << this << endl;
    103105}
     
    135137     chanMask_ = other.chanMask_;
    136138     table_ = other.table_.copyToMemoryTable(String("dummy"));
     139     attach();
    137140  }
    138141  //cerr << "hello from ASS SDMemTable @ " << this << endl;
     
    151154  TableDesc td("", "1", TableDesc::Scratch);
    152155  td.comment() = "A SDMemTable";
     156//
    153157  td.addColumn(ScalarColumnDesc<Double>("TIME"));
    154158  td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
     
    175179}
    176180
     181void SDMemTable::attach ()
     182{
     183  timeCol_.attach(table_, "TIME");
     184  srcnCol_.attach(table_, "SRCNAME");
     185  specCol_.attach(table_, "SPECTRA");
     186  flagsCol_.attach(table_, "FLAGTRA");
     187  tsCol_.attach(table_, "TSYS");
     188  scanCol_.attach(table_, "SCANID");
     189  integrCol_.attach(table_, "INTERVAL");
     190  freqidCol_.attach(table_, "FREQID");
     191  dirCol_.attach(table_, "DIRECTION");
     192  fldnCol_.attach(table_, "FIELDNAME");
     193  tcaltCol_.attach(table_, "TCALTIME");
     194  tcalCol_.attach(table_, "TCAL");
     195  azCol_.attach(table_, "AZIMUTH");
     196  elCol_.attach(table_, "ELEVATION");
     197  paraCol_.attach(table_, "PARANGLE");
     198  rbeamCol_.attach(table_, "REFBEAM");
     199  histCol_.attach(table_, "HISTORY");
     200}
     201
     202
    177203std::string SDMemTable::getSourceName(Int whichRow) const
    178204{
    179   ROScalarColumn<String> src(table_, "SRCNAME");
    180205  String name;
    181   src.get(whichRow, name);
     206  srcnCol_.get(whichRow, name);
    182207  return name;
    183208}
     
    187212  Double tm;
    188213  if (whichRow > -1) {
    189     ROScalarColumn<Double> src(table_, "TIME");
    190     src.get(whichRow, tm);
     214    timeCol_.get(whichRow, tm);
    191215  } else {
    192216    table_.keywordSet().get("UTC",tm);
     
    204228double SDMemTable::getInterval(Int whichRow) const
    205229{
    206   ROScalarColumn<Double> src(table_, "INTERVAL");
    207230  Double intval;
    208   src.get(whichRow, intval);
     231  integrCol_.get(whichRow, intval);
    209232  return intval;
    210233}
     
    246269bool SDMemTable::setMask(std::vector<int> whichChans)
    247270{
    248   ROArrayColumn<uChar> spec(table_, "FLAGTRA");
    249271  std::vector<int>::iterator it;
    250   uInt n = spec.shape(0)(3);
     272  uInt n = flagsCol_.shape(0)(3);
    251273  if (whichChans.empty()) {
    252274    chanMask_ = std::vector<bool>(n,true);
     
    264286std::vector<bool> SDMemTable::getMask(Int whichRow) const {
    265287  std::vector<bool> mask;
    266   ROArrayColumn<uChar> spec(table_, "FLAGTRA");
    267288  Array<uChar> arr;
    268   spec.get(whichRow, arr);
     289  flagsCol_.get(whichRow, arr);
    269290  ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
    270291  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
     
    294315{
    295316  std::vector<float> spectrum;
    296   ROArrayColumn<Float> spec(table_, "SPECTRA");
    297317  Array<Float> arr;
    298   spec.get(whichRow, arr);
     318  specCol_.get(whichRow, arr);
    299319  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
    300320  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
     
    412432// Continue with km/s or Hz.  Get FreqID
    413433
    414   ROArrayColumn<uInt> fid(table_, "FREQID");
    415434  Vector<uInt> v;
    416   fid.get(whichRow, v);
     435  freqidCol_.get(whichRow, v);
    417436  uInt specidx = v(IFSel_);
    418437
     
    455474std::string SDMemTable::getAbcissaString(Int whichRow) const
    456475{
    457   ROArrayColumn<uInt> fid(table_, "FREQID");
    458476  Table t = table_.keywordSet().asTable("FREQUENCIES");
    459477//
     
    464482//
    465483  Vector<uInt> v;
    466   fid.get(whichRow, v);
     484  freqidCol_.get(whichRow, v);
    467485  uInt specidx = v(IFSel_);
    468486
     
    485503void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
    486504{
    487   ArrayColumn<Float> spec(table_, "SPECTRA");
    488505  Array<Float> arr;
    489   spec.get(whichRow, arr);
     506  specCol_.get(whichRow, arr);
    490507  if (spectrum.size() != arr.shape()(3)) {
    491508    throw(AipsError("Attempting to set spectrum with incorrect length."));
     
    504521    it++;
    505522  }
    506   spec.put(whichRow, arr);
     523  specCol_.put(whichRow, arr);
    507524}
    508525
    509526void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
    510527{
    511   ROArrayColumn<Float> spec(table_, "SPECTRA");
    512528  Array<Float> arr;
    513   spec.get(whichRow, arr);
     529  specCol_.get(whichRow, arr);
    514530  spectrum.resize(arr.shape()(3));
    515531  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
     
    528544/*
    529545void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
    530   ROArrayColumn<uChar> spec(table_, "FLAGTRA");
    531546  Array<uChar> arr;
    532   spec.get(whichRow, arr);
     547  flagsCol_.get(whichRow, arr);
    533548  mask.resize(arr.shape()(3));
    534549
     
    563578                                                Bool useSelection) const
    564579{
    565   ROArrayColumn<Float> spec(table_, "SPECTRA");
    566580  Array<Float> arr;
    567   ROArrayColumn<uChar> flag(table_, "FLAGTRA");
    568581  Array<uChar> farr;
    569   spec.get(whichRow, arr);
    570   flag.get(whichRow, farr);
     582  specCol_.get(whichRow, arr);
     583  flagsCol_.get(whichRow, farr);
    571584  Array<Bool> barr(farr.shape());convertArray(barr, farr);
    572585  MaskedArray<Float> marr;
     
    609622Float SDMemTable::getTsys(Int whichRow) const
    610623{
    611   ROArrayColumn<Float> ts(table_, "TSYS");
    612624  Array<Float> arr;
    613   ts.get(whichRow, arr);
     625  tsCol_.get(whichRow, arr);
    614626  Float out;
    615627  IPosition ip(arr.shape());
     
    622634{
    623635  MDirection::Types mdr = getDirectionReference();
    624   ROArrayColumn<Double> dir(table_, "DIRECTION");
    625636  Array<Double> posit;
    626   dir.get(whichRow,posit);
     637  dirCol_.get(whichRow,posit);
    627638  Vector<Double> wpos(2);
    628639  wpos[0] = posit(IPosition(2,beamSel_,0));
     
    637648  MEpoch::Types met = getTimeReference();
    638649//
    639   ROScalarColumn<Double> tme(table_, "TIME");
    640650  Double obstime;
    641   tme.get(whichRow,obstime);
     651  timeCol_.get(whichRow,obstime);
    642652  MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
    643653  return MEpoch(tm2, met);
     
    878888bool SDMemTable::putSDContainer(const SDContainer& sdc)
    879889{
    880   ScalarColumn<Double> mjd(table_, "TIME");
    881   ScalarColumn<String> srcn(table_, "SRCNAME");
    882   ScalarColumn<String> fldn(table_, "FIELDNAME");
    883   ArrayColumn<Float> spec(table_, "SPECTRA");
    884   ArrayColumn<uChar> flags(table_, "FLAGTRA");
    885   ArrayColumn<Float> ts(table_, "TSYS");
    886   ScalarColumn<Int> scan(table_, "SCANID");
    887   ScalarColumn<Double> integr(table_, "INTERVAL");
    888   ArrayColumn<uInt> freqid(table_, "FREQID");
    889   ArrayColumn<Double> dir(table_, "DIRECTION");
    890   ScalarColumn<Int> rbeam(table_, "REFBEAM");
    891   ArrayColumn<Float> tcal(table_, "TCAL");
    892   ScalarColumn<String> tcalt(table_, "TCALTIME");
    893   ScalarColumn<Float> az(table_, "AZIMUTH");
    894   ScalarColumn<Float> el(table_, "ELEVATION");
    895   ScalarColumn<Float> para(table_, "PARANGLE");
    896   ArrayColumn<String> hist(table_, "HISTORY");
    897 
    898890  uInt rno = table_.nrow();
    899891  table_.addRow();
    900892
    901   mjd.put(rno, sdc.timestamp);
    902   srcn.put(rno, sdc.sourcename);
    903   fldn.put(rno, sdc.fieldname);
    904   spec.put(rno, sdc.getSpectrum());
    905   flags.put(rno, sdc.getFlags());
    906   ts.put(rno, sdc.getTsys());
    907   scan.put(rno, sdc.scanid);
    908   integr.put(rno, sdc.interval);
    909   freqid.put(rno, sdc.getFreqMap());
    910   dir.put(rno, sdc.getDirection());
    911   rbeam.put(rno, sdc.refbeam);
    912   tcal.put(rno, sdc.tcal);
    913   tcalt.put(rno, sdc.tcaltime);
    914   az.put(rno, sdc.azimuth);
    915   el.put(rno, sdc.elevation);
    916   para.put(rno, sdc.parangle);
    917   hist.put(rno, sdc.getHistory());
     893//  mjd.put(rno, sdc.timestamp);
     894  timeCol_.put(rno, sdc.timestamp);
     895  srcnCol_.put(rno, sdc.sourcename);
     896  fldnCol_.put(rno, sdc.fieldname);
     897  specCol_.put(rno, sdc.getSpectrum());
     898  flagsCol_.put(rno, sdc.getFlags());
     899  tsCol_.put(rno, sdc.getTsys());
     900  scanCol_.put(rno, sdc.scanid);
     901  integrCol_.put(rno, sdc.interval);
     902  freqidCol_.put(rno, sdc.getFreqMap());
     903  dirCol_.put(rno, sdc.getDirection());
     904  rbeamCol_.put(rno, sdc.refbeam);
     905  tcalCol_.put(rno, sdc.tcal);
     906  tcaltCol_.put(rno, sdc.tcaltime);
     907  azCol_.put(rno, sdc.azimuth);
     908  elCol_.put(rno, sdc.elevation);
     909  paraCol_.put(rno, sdc.parangle);
     910  histCol_.put(rno, sdc.getHistory());
    918911
    919912  return true;
     
    922915SDContainer SDMemTable::getSDContainer(uInt whichRow) const
    923916{
    924   ROScalarColumn<Double> mjd(table_, "TIME");
    925   ROScalarColumn<String> srcn(table_, "SRCNAME");
    926   ROScalarColumn<String> fldn(table_, "FIELDNAME");
    927   ROArrayColumn<Float> spec(table_, "SPECTRA");
    928   ROArrayColumn<uChar> flags(table_, "FLAGTRA");
    929   ROArrayColumn<Float> ts(table_, "TSYS");
    930   ROScalarColumn<Int> scan(table_, "SCANID");
    931   ROScalarColumn<Double> integr(table_, "INTERVAL");
    932   ROArrayColumn<uInt> freqid(table_, "FREQID");
    933   ROArrayColumn<Double> dir(table_, "DIRECTION");
    934   ROScalarColumn<Int> rbeam(table_, "REFBEAM");
    935   ROArrayColumn<Float> tcal(table_, "TCAL");
    936   ROScalarColumn<String> tcalt(table_, "TCALTIME");
    937   ROScalarColumn<Float> az(table_, "AZIMUTH");
    938   ROScalarColumn<Float> el(table_, "ELEVATION");
    939   ROScalarColumn<Float> para(table_, "PARANGLE");
    940   ROArrayColumn<String> hist(table_, "HISTORY");
    941 
    942917  SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
    943   mjd.get(whichRow, sdc.timestamp);
    944   srcn.get(whichRow, sdc.sourcename);
    945   integr.get(whichRow, sdc.interval);
    946   scan.get(whichRow, sdc.scanid);
    947   fldn.get(whichRow, sdc.fieldname);
    948   rbeam.get(whichRow, sdc.refbeam);
    949   az.get(whichRow, sdc.azimuth);
    950   el.get(whichRow, sdc.elevation);
    951   para.get(whichRow, sdc.parangle);
     918  timeCol_.get(whichRow, sdc.timestamp);
     919  srcnCol_.get(whichRow, sdc.sourcename);
     920  integrCol_.get(whichRow, sdc.interval);
     921  scanCol_.get(whichRow, sdc.scanid);
     922  fldnCol_.get(whichRow, sdc.fieldname);
     923  rbeamCol_.get(whichRow, sdc.refbeam);
     924  azCol_.get(whichRow, sdc.azimuth);
     925  elCol_.get(whichRow, sdc.elevation);
     926  paraCol_.get(whichRow, sdc.parangle);
    952927  Vector<Float> tc;
    953   tcal.get(whichRow, tc);
     928  tcalCol_.get(whichRow, tc);
    954929  sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
    955   tcalt.get(whichRow, sdc.tcaltime);
     930  tcaltCol_.get(whichRow, sdc.tcaltime);
    956931  Array<Float> spectrum;
    957932  Array<Float> tsys;
     
    960935  Array<Double> direction;
    961936  Vector<String> histo;
    962   spec.get(whichRow, spectrum);
     937  specCol_.get(whichRow, spectrum);
    963938  sdc.putSpectrum(spectrum);
    964   flags.get(whichRow, flagtrum);
     939  flagsCol_.get(whichRow, flagtrum);
    965940  sdc.putFlags(flagtrum);
    966   ts.get(whichRow, tsys);
     941  tsCol_.get(whichRow, tsys);
    967942  sdc.putTsys(tsys);
    968   freqid.get(whichRow, fmap);
     943  freqidCol_.get(whichRow, fmap);
    969944  sdc.putFreqMap(fmap);
    970   dir.get(whichRow, direction);
     945  dirCol_.get(whichRow, direction);
    971946  sdc.putDirection(direction);
    972   hist.get(whichRow, histo);
     947  histCol_.get(whichRow, histo);
    973948  sdc.putHistory(histo);
    974949  return sdc;
     
    1024999Int SDMemTable::nScan() const {
    10251000  Int n = 0;
    1026   ROScalarColumn<Int> scans(table_, "SCANID");
    10271001  Int previous = -1;Int current=0;
    1028   for (uInt i=0; i< scans.nrow();i++) {
    1029     scans.getScalar(i,current);
     1002  for (uInt i=0; i< scanCol_.nrow();i++) {
     1003    scanCol_.getScalar(i,current);
    10301004    if (previous != current) {
    10311005      previous = current;
     
    10961070
    10971071std::string SDMemTable::summary() const  {
    1098   ROScalarColumn<Int> scans(table_, "SCANID");
    1099   ROScalarColumn<String> srcs(table_, "SRCNAME");
    11001072
    11011073  // get number of integrations per scan
     
    11041076  int scount = 0;
    11051077  std::vector<int> cycles;
    1106   for (uInt i=0; i<scans.nrow();++i) {
    1107     while (idx == cIdx && i<scans.nrow()) {
    1108       scans.getScalar(++i,cIdx);
     1078  for (uInt i=0; i<scanCol_.nrow();++i) {
     1079    while (idx == cIdx && i<scanCol_.nrow()) {
     1080      scanCol_.getScalar(++i,cIdx);
    11091081      ++scount;
    11101082    }
     
    11671139 
    11681140  std::vector<int>::iterator it = cycles.begin();
    1169   for (uInt i=0; i< scans.nrow();i++) {
    1170     scans.getScalar(i,current);
     1141  for (uInt i=0; i< scanCol_.nrow();i++) {
     1142    scanCol_.getScalar(i,current);
    11711143    if (previous != current) {
    1172       srcs.getScalar(i,name);
     1144      srcnCol_.getScalar(i,name);
    11731145      previous = current;
    11741146      String t = formatSec(Double(getInterval(i)));
     
    12311203bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
    12321204{
    1233   ArrayColumn<String> histo(table_, "HISTORY");
    12341205  Vector<String> history;
    1235   histo.get(whichRow, history);
     1206  histCol_.get(whichRow, history);
    12361207  history.resize(history.nelements()+1,True);
    12371208  history[history.nelements()-1] = hist;
    1238   histo.put(whichRow, history);
     1209  histCol_.put(whichRow, history);
    12391210}
    12401211
    12411212std::vector<std::string> SDMemTable::history(int whichRow) const
    12421213{
    1243   ROArrayColumn<String> hist(table_, "HISTORY");
    12441214  Vector<String> history;
    1245   hist.get(whichRow, history);
     1215  histCol_.get(whichRow, history);
    12461216  std::vector<std::string> stlout;
    12471217  // there is no Array<String>.tovector(std::vector<std::string>), so
     
    12731243void SDMemTable::flag(int whichRow)
    12741244{
    1275   ArrayColumn<uChar> spec(table_, "FLAGTRA");
    12761245  Array<uChar> arr;
    1277   spec.get(whichRow, arr);
     1246  flagsCol_.get(whichRow, arr);
    12781247
    12791248  ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
     
    12881257  }
    12891258
    1290   spec.put(whichRow, arr);
     1259  flagsCol_.put(whichRow, arr);
    12911260}
    12921261
  • trunk/src/SDMemTable.h

    r306 r322  
    3737// AIPS++
    3838 #include <casa/aips.h>
     39#include <casa/Arrays/MaskedArray.h>
    3940#include <casa/BasicSL/String.h>
     41#include <coordinates/Coordinates/SpectralCoordinate.h>
    4042#include <tables/Tables/Table.h>
    41 #include <casa/Arrays/MaskedArray.h>
     43#include <tables/Tables/ArrayColumn.h>
     44#include <tables/Tables/ScalarColumn.h>
     45
    4246#include "SDDefs.h"
    4347
    44 #include <coordinates/Coordinates/SpectralCoordinate.h>
     48
    4549
    4650namespace asap {
     
    4953class SDHeader;
    5054class SDFrequencyTable;
     55
     56
    5157
    5258
     
    210216  casa::String formatDirection(const casa::MDirection& md) const;
    211217  void setup();
     218  void attach();
    212219  // the current cursor into the array
    213220  casa::Int IFSel_,beamSel_,polSel_;
     
    215222  // the underlying memory table
    216223  casa::Table table_;
     224
     225// Cached Columns to avoid reconstructing them for each row get/put
     226  casa::ScalarColumn<casa::Double> timeCol_, integrCol_;
     227  casa::ScalarColumn<casa::Float> azCol_, elCol_, paraCol_;
     228  casa::ScalarColumn<casa::String> srcnCol_, fldnCol_, tcaltCol_;
     229  casa::ScalarColumn<casa::Int> scanCol_, rbeamCol_;
     230  casa::ArrayColumn<casa::Float> specCol_, tsCol_, tcalCol_;
     231  casa::ArrayColumn<casa::Double> dirCol_;
     232  casa::ArrayColumn<casa::uChar> flagsCol_;
     233  casa::ArrayColumn<casa::uInt> freqidCol_;
     234  casa::ArrayColumn<casa::String> histCol_;
    217235};
    218236
Note: See TracChangeset for help on using the changeset viewer.