Changeset 2911
- Timestamp:
- 04/01/14 13:05:18 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STIdxIter.cpp
r2580 r2911 5 5 #include <casa/Arrays/ArrayMath.h> 6 6 #include <casa/Arrays/ArrayIO.h> 7 #include <casa/Utilities/DataType.h> 7 8 #include <tables/Tables/ScalarColumn.h> 9 #include <tables/Tables/TableRow.h> 10 #include <tables/Tables/TableRecord.h> 8 11 #include "STIdxIter.h" 9 12 … … 502 505 } 503 506 507 STIdxIter2::STIdxIter2() 508 : cols_(), 509 table_(), 510 counter_(0), 511 num_iter_(0), 512 num_row_(0), 513 sorter_(), 514 index_(), 515 unique_(), 516 pointer_() 517 { 518 } 519 520 STIdxIter2::STIdxIter2( const string &name, 521 const vector<string> &cols ) 522 : cols_(cols), 523 table_(name, Table::Old), 524 counter_(0), 525 num_iter_(0), 526 num_row_(0), 527 sorter_(), 528 index_(), 529 unique_(), 530 pointer_() 531 { 532 init(); 533 } 534 535 STIdxIter2::STIdxIter2( const CountedPtr<Scantable> &s, 536 const vector<string> &cols ) 537 : cols_(cols), 538 table_(s->table()), 539 counter_(0), 540 num_iter_(0), 541 num_row_(0), 542 sorter_(), 543 index_(), 544 unique_(), 545 pointer_() 546 { 547 init(); 548 } 549 550 STIdxIter2::~STIdxIter2() 551 { 552 deallocate(); 553 } 554 555 void STIdxIter2::deallocate() 556 { 557 for (vector<void*>::iterator i = pointer_.begin(); i != pointer_.end(); ++i) { 558 free(*i); 559 } 560 } 561 562 Record STIdxIter2::currentValue() { 563 assert(counter_ < num_iter_); 564 Vector<String> cols(cols_.size()); 565 for (uInt i = 0; i < cols.nelements(); ++i) { 566 cols[i] = cols_[i]; 567 } 568 const ROTableRow row(table_, cols); 569 const TableRecord rec = row.get(index_[unique_[counter_]]); 570 return Record(rec); 571 } 572 573 Bool STIdxIter2::pastEnd() { 574 return counter_ >= num_iter_; 575 } 576 577 void STIdxIter2::next() { 578 counter_++; 579 } 580 581 vector<uInt> STIdxIter2::tovector( Vector<uInt> v ) 582 { 583 vector<uInt> ret ; 584 v.tovector( ret ) ; 585 return ret ; 586 } 587 588 Vector<uInt> STIdxIter2::getRows( StorageInitPolicy policy ) 589 { 590 assert(num_iter_ > 1); 591 assert(counter_ < num_iter_); 592 if (counter_ == num_iter_ - 1) { 593 uInt start = unique_[counter_]; 594 uInt num_row = num_row_ - start; 595 Vector<uInt> rows(IPosition(1, num_row), &(index_.data()[start]), policy); 596 return rows; 597 } 598 else { 599 uInt start = unique_[counter_]; 600 uInt end = unique_[counter_ + 1]; 601 uInt num_row = end - start; 602 Vector<uInt> rows(IPosition(1, num_row), &(index_.data()[start]), policy); 603 return rows; 604 } 605 } 606 607 void STIdxIter2::init() 608 { 609 for (uInt i = 0; i < cols_.size(); ++i) { 610 addSortKey(cols_[i]); 611 } 612 num_row_ = table_.nrow(); 613 sorter_.sort(index_, num_row_); 614 num_iter_ = sorter_.unique(unique_, index_); 615 // cout << "num_row_ = " << num_row_ << endl 616 // << "num_iter_ = " << num_iter_ << endl; 617 // cout << "unique_ = " << unique_ << endl; 618 // cout << "index_ = " << index_ << endl; 619 } 620 621 void STIdxIter2::addSortKey(const string &name) 622 { 623 const ColumnDesc &desc = table_.tableDesc().columnDesc(name); 624 const DataType dtype = desc.trueDataType(); 625 switch (dtype) { 626 case TpUInt: 627 addColumnToKey<uInt, TpUInt>(name); 628 break; 629 case TpInt: 630 addColumnToKey<Int, TpInt>(name); 631 break; 632 case TpFloat: 633 addColumnToKey<Float, TpFloat>(name); 634 break; 635 case TpDouble: 636 addColumnToKey<Double, TpDouble>(name); 637 break; 638 case TpComplex: 639 addColumnToKey<Complex, TpComplex>(name); 640 break; 641 // case TpString: 642 // addColumnToKey<String, TpString>(name); 643 // break; 644 default: 645 deallocate(); 646 stringstream oss; 647 oss << name << ": data type is not supported" << endl; 648 throw(AipsError(oss.str())); 649 } 650 } 651 652 template<class T, DataType U> 653 void STIdxIter2::addColumnToKey(const string &name) 654 { 655 uInt nrow = table_.nrow(); 656 void *raw_storage = malloc(sizeof(T) * nrow); 657 T *storage = reinterpret_cast<T*>(raw_storage); 658 Vector<T> array(IPosition(1, nrow), storage, SHARE); 659 ROScalarColumn<T> col(table_, name); 660 col.getColumn(array); 661 sorter_.sortKey(storage, U, 0, Sort::Ascending); 662 pointer_.push_back(raw_storage); 663 } 504 664 } // namespace 665 -
trunk/src/STIdxIter.h
r2580 r2911 8 8 #include <casa/Arrays/IPosition.h> 9 9 #include <casa/BasicSL/String.h> 10 11 #include <casa/Utilities/Sort.h> 10 12 11 13 #include "Scantable.h" … … 155 157 } ; 156 158 159 class STIdxIter2 160 { 161 public: 162 STIdxIter2() ; 163 STIdxIter2( const string &name, 164 const vector<string> &cols ) ; 165 STIdxIter2( const CountedPtr<Scantable> &s, 166 const vector<string> &cols ) ; 167 virtual ~STIdxIter2() ; 168 Record currentValue(); 169 Bool pastEnd() ; 170 void next() ; 171 Vector<uInt> getRows(StorageInitPolicy policy=COPY) ; 172 vector<uInt> getRowsSTL() { return tovector( getRows() ) ; } ; 173 virtual void init(); 174 private: 175 vector<uInt> tovector(Vector<uInt> v); 176 void addSortKey(const string &name); 177 template<class T, DataType U> void addColumnToKey(const string &name); 178 void deallocate(); 179 vector<string> cols_; 180 Table table_; 181 uInt counter_; 182 uInt num_iter_; 183 uInt num_row_; 184 Sort sorter_; 185 Vector<uInt> index_; 186 Vector<uInt> unique_; 187 vector<void*> pointer_; 188 } ; 189 157 190 } // namespace 158 191 #endif /* _ASAP_INDEX_ITERATOR_H_ */ -
trunk/src/STMath.cpp
r2905 r2911 3621 3621 cols[1] = "POLNO" ; 3622 3622 cols[2] = "IFNO" ; 3623 STIdxIter *iter = new STIdxIterAcc( out, cols ) ;3623 STIdxIter2 iter( out, cols ) ; 3624 3624 STSelector sel ; 3625 while ( !iter ->pastEnd() ) {3626 Vector<uInt> ids = iter->current() ;3625 while ( !iter.pastEnd() ) { 3626 Record ids = iter.currentValue() ; 3627 3627 stringstream ss ; 3628 3628 ss << "SELECT FROM $1 WHERE " 3629 << "BEAMNO==" << ids [0]<< "&&"3630 << "POLNO==" << ids [1]<< "&&"3631 << "IFNO==" << ids [2];3629 << "BEAMNO==" << ids.asuInt(cols[0]) << "&&" 3630 << "POLNO==" << ids.asuInt(cols[1]) << "&&" 3631 << "IFNO==" << ids.asuInt(cols[2]) ; 3632 3632 //cout << "TaQL string: " << ss.str() << endl ; 3633 3633 sel.setTaQL( ss.str() ) ; 3634 3634 aoff->setSelection( sel ) ; 3635 Vector<uInt> rows = iter ->getRows( SHARE ) ;3635 Vector<uInt> rows = iter.getRows( SHARE ) ; 3636 3636 // out should be an exact copy of s except that SPECTRA column is empty 3637 3637 calibrateALMA( out, s, aoff, rows ) ; 3638 3638 aoff->unsetSelection() ; 3639 3639 sel.reset() ; 3640 iter->next() ; 3641 } 3642 delete iter ; 3640 iter.next() ; 3641 } 3643 3642 s->table_ = torg ; 3644 3643 s->attach() ;
Note:
See TracChangeset
for help on using the changeset viewer.