Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMemTable.cc

    r18 r22  
    6565  beamSel_(0),
    6666  polSel_(0) {
    67   name_ = String(name);
    68   Table tab(name_);
    69   table_ = tab.copyToMemoryTable(name_);
     67  Table tab("dummy");
     68  table_ = tab.copyToMemoryTable("dummy");
    7069}
    7170
     
    7574  this->polSel_= other.polSel_;
    7675  this->chanMask_ = other.chanMask_;
    77   this->name_ = String("dummy");
    7876  this->table_ = other.table_.copyToMemoryTable(String("dummy"));
    7977  // clear all rows()
     
    9189  beamSel_(0),
    9290  polSel_(0) {
    93   name_ = String("SDMemTable");
    9491  String exprs = String("select * from $1 where SCANID == ")
    9592    +String::toString(scanID);
    9693  cerr << exprs << endl;
    9794  Table t = tableCommand(exprs,tab);
    98   table_ = t.copyToMemoryTable(name_);
     95  table_ = t.copyToMemoryTable("dummy");
    9996}
    10097
     
    119116  // Now create a new table from the description.
    120117
    121   SetupNewTable aNewTab(name_, td, Table::New);
     118  SetupNewTable aNewTab("dummy", td, Table::New);
    122119  table_ = Table(aNewTab, Table::Memory, 0); 
    123 }
    124 
    125 std::string SDMemTable::name() const {
    126   return name_;
    127120}
    128121
     
    206199  return mask;
    207200}
    208 std::vector<float> SDMemTable::getSpectrum(Int whichRow) const {
     201std::vector<float> SDMemTable::getSpectrum(Int whichRow) {
    209202
    210203  std::vector<float> spectrum;
     
    222215  }
    223216  return spectrum;
     217}
     218void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow=0) {
     219  ROArrayColumn<Float> spec(table_, "SPECTRA");
     220  Array<Float> arr;
     221  spec.get(whichRow, arr);
     222  spectrum.resize(arr.shape()(3));
     223  ArrayAccessor<Float, Axis<0> > aa0(arr);
     224  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
     225  ArrayAccessor<Float, Axis<1> > aa1(aa0);
     226  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
     227  ArrayAccessor<Float, Axis<2> > aa2(aa1);
     228  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
     229
     230  ArrayAccessor<Float, Axis<0> > va(spectrum);
     231  for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) {
     232    (*va) = (*i);
     233    va++;
     234  }
     235}
     236
     237void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow=0) const {
     238  ROArrayColumn<uChar> spec(table_, "FLAGTRA");
     239  Array<uChar> arr;
     240  spec.get(whichRow, arr);
     241  mask.resize(arr.shape()(3));
     242
     243  ArrayAccessor<uChar, Axis<0> > aa0(arr);
     244  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
     245  ArrayAccessor<uChar, Axis<1> > aa1(aa0);
     246  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
     247  ArrayAccessor<uChar, Axis<2> > aa2(aa1);
     248  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
     249
     250  Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
     251 
     252  ArrayAccessor<Bool, Axis<0> > va(mask);
     253  std::vector<bool> tmp;
     254  tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
     255                   // iterator should work on chanMask_??
     256  std::vector<bool>::iterator miter;
     257  miter = tmp.begin();
     258
     259  for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) {
     260    bool out =!static_cast<bool>(*i);
     261    if (useUserMask) {
     262      out = out && (*miter);
     263      miter++;
     264    }
     265    (*va) = out;
     266    va++;
     267  } 
    224268}
    225269
     
    303347}
    304348
     349SDContainer SDMemTable::getSDContainer(uInt whichRow) const {
     350  ROScalarColumn<Double> mjd(table_, "TIME");
     351  ROScalarColumn<String> srcn(table_, "SRCNAME");
     352  ROArrayColumn<Float> spec(table_, "SPECTRA");
     353  ROArrayColumn<uChar> flags(table_, "FLAGTRA");
     354  ROArrayColumn<Float> ts(table_, "TSYS");
     355  ROScalarColumn<Int> scan(table_, "SCANID");
     356  ROScalarColumn<Double> integr(table_, "INTERVAL");
     357
     358  SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
     359  mjd.get(whichRow, sdc.timestamp);
     360  srcn.get(whichRow, sdc.sourcename);
     361  integr.get(whichRow, sdc.interval);
     362  scan.get(whichRow, sdc.scanid);
     363  Array<Float> spectrum;
     364  Array<Float> tsys;
     365  Array<uChar> flagtrum;
     366  spec.get(whichRow, spectrum);
     367  sdc.putSpectrum(spectrum);
     368  flags.get(whichRow, flagtrum);
     369  sdc.putFlags(flagtrum);
     370  ts.get(whichRow, tsys);
     371  sdc.putTsys(tsys);
     372  return sdc;
     373}
    305374bool SDMemTable::putSDHeader(const SDHeader& sdh) {
    306375  table_.lock();
     
    322391  cerr << "Table Header set" << endl;
    323392  return true;
    324 }
    325 
     393}\
     394
     395SDHeader SDMemTable::getSDHeader() const {
     396  SDHeader sdh;
     397  table_.keywordSet().get("nBeam",sdh.nbeam);
     398  table_.keywordSet().get("nIF",sdh.nif);
     399  table_.keywordSet().get("nPol",sdh.npol);
     400  table_.keywordSet().get("nChan",sdh.nchan);
     401  table_.keywordSet().get("Observer", sdh.observer);
     402  table_.keywordSet().get("Project", sdh.project);
     403  table_.keywordSet().get("Obstype", sdh.obstype);
     404  table_.keywordSet().get("AntennaName", sdh.antennaname);
     405  table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
     406  table_.keywordSet().get("Equinox", sdh.equinox);
     407  table_.keywordSet().get("FreqRefFrame", sdh.freqref);
     408  table_.keywordSet().get("FreqRefVal", sdh.reffreq);
     409  table_.keywordSet().get("Bandwidth", sdh.bandwidth);
     410  table_.keywordSet().get("UTC", sdh.utc);
     411  return sdh;
     412}
    326413void SDMemTable::makePersistent(const std::string& filename) {
    327414  table_.deepCopy(filename,Table::New);
     
    376463  return n;
    377464}
    378 
    379465/*
    380466void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
Note: See TracChangeset for help on using the changeset viewer.