[2519] | 1 | #ifndef _ASAP_INDEX_ITERATOR_H_ |
---|
| 2 | #define _ASAP_INDEX_ITERATOR_H_ |
---|
| 3 | |
---|
| 4 | #include <vector> |
---|
| 5 | #include <casa/Containers/Block.h> |
---|
| 6 | #include <casa/Arrays/Vector.h> |
---|
| 7 | #include <casa/Arrays/Matrix.h> |
---|
[2533] | 8 | #include <casa/Arrays/IPosition.h> |
---|
[2537] | 9 | #include <casa/BasicSL/String.h> |
---|
[2519] | 10 | |
---|
[2911] | 11 | #include <casa/Utilities/Sort.h> |
---|
| 12 | |
---|
[2519] | 13 | #include "Scantable.h" |
---|
| 14 | |
---|
| 15 | using namespace std ; |
---|
| 16 | using namespace casa ; |
---|
| 17 | |
---|
[2920] | 18 | namespace { |
---|
| 19 | vector<string> split(const string &str, char delim) |
---|
| 20 | { |
---|
| 21 | vector<string> result; |
---|
| 22 | size_t current = 0; |
---|
| 23 | size_t found; |
---|
| 24 | while ((found = str.find_first_of(delim, current)) != string::npos) { |
---|
| 25 | result.push_back(string(str, current, found - current)); |
---|
| 26 | current = found + 1; |
---|
| 27 | } |
---|
| 28 | result.push_back(string(str, current, str.size() - current)); |
---|
| 29 | return result; |
---|
| 30 | } |
---|
| 31 | } // anonymous namespace |
---|
| 32 | |
---|
[2519] | 33 | namespace asap { |
---|
[2911] | 34 | class STIdxIter2 |
---|
| 35 | { |
---|
| 36 | public: |
---|
[2920] | 37 | template<class T> |
---|
| 38 | static void Iterate(T &processor, const string cols_list) |
---|
| 39 | { |
---|
| 40 | vector<string> cols = split(cols_list, ','); |
---|
| 41 | // for (vector<string>::iterator i = cols.begin(); i != cols.end(); ++i) |
---|
| 42 | // cout << *i << endl; |
---|
| 43 | STIdxIter2 iter(processor.target(), cols); |
---|
| 44 | STSelector sel ; |
---|
| 45 | while ( !iter.pastEnd() ) { |
---|
| 46 | const Record current = iter.currentValue() ; |
---|
| 47 | Vector<uInt> rows = iter.getRows( SHARE ) ; |
---|
| 48 | // any process |
---|
| 49 | processor.Process(cols, current, rows); |
---|
| 50 | // go next |
---|
| 51 | iter.next() ; |
---|
| 52 | } |
---|
| 53 | } |
---|
[2911] | 54 | STIdxIter2() ; |
---|
| 55 | STIdxIter2( const string &name, |
---|
| 56 | const vector<string> &cols ) ; |
---|
| 57 | STIdxIter2( const CountedPtr<Scantable> &s, |
---|
| 58 | const vector<string> &cols ) ; |
---|
| 59 | virtual ~STIdxIter2() ; |
---|
| 60 | Record currentValue(); |
---|
| 61 | Bool pastEnd() ; |
---|
| 62 | void next() ; |
---|
| 63 | Vector<uInt> getRows(StorageInitPolicy policy=COPY) ; |
---|
| 64 | vector<uInt> getRowsSTL() { return tovector( getRows() ) ; } ; |
---|
| 65 | virtual void init(); |
---|
| 66 | private: |
---|
| 67 | vector<uInt> tovector(Vector<uInt> v); |
---|
| 68 | void addSortKey(const string &name); |
---|
| 69 | template<class T, DataType U> void addColumnToKey(const string &name); |
---|
[2918] | 70 | void addColumnToKeyTpString(const string &name); |
---|
[2911] | 71 | void deallocate(); |
---|
| 72 | vector<string> cols_; |
---|
| 73 | Table table_; |
---|
| 74 | uInt counter_; |
---|
| 75 | uInt num_iter_; |
---|
| 76 | uInt num_row_; |
---|
| 77 | Sort sorter_; |
---|
| 78 | Vector<uInt> index_; |
---|
| 79 | Vector<uInt> unique_; |
---|
| 80 | vector<void*> pointer_; |
---|
[2918] | 81 | vector<Vector<String> > string_storage_; |
---|
[2911] | 82 | } ; |
---|
| 83 | |
---|
[2519] | 84 | } // namespace |
---|
| 85 | #endif /* _ASAP_INDEX_ITERATOR_H_ */ |
---|