[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 |
|
---|
| 18 | namespace asap {
|
---|
| 19 | class IndexIterator
|
---|
| 20 | {
|
---|
| 21 | public:
|
---|
[2533] | 22 | IndexIterator( IPosition &shape ) ;
|
---|
| 23 | Block<uInt> current() { return idx_m ; } ;
|
---|
[2519] | 24 | Bool pastEnd() ;
|
---|
| 25 | void next() ;
|
---|
| 26 | private:
|
---|
| 27 | uInt nfield_m ;
|
---|
| 28 | Block<uInt> prod_m ;
|
---|
| 29 | Block<uInt> idx_m ;
|
---|
| 30 | uInt niter_m ;
|
---|
| 31 | uInt maxiter_m ;
|
---|
| 32 | } ;
|
---|
| 33 |
|
---|
| 34 | class ArrayIndexIterator
|
---|
| 35 | {
|
---|
| 36 | public:
|
---|
| 37 | ArrayIndexIterator( Matrix<uInt> &arr,
|
---|
| 38 | vector< vector<uInt> > idlist=vector< vector<uInt> >() ) ;
|
---|
| 39 | virtual ~ArrayIndexIterator() ;
|
---|
| 40 | Vector<uInt> current() ;
|
---|
| 41 | Bool pastEnd() ;
|
---|
| 42 | virtual void next() = 0 ;
|
---|
[2524] | 43 | virtual Vector<uInt> getRows( StorageInitPolicy policy=COPY ) = 0 ;
|
---|
[2519] | 44 | protected:
|
---|
| 45 | IndexIterator *iter_m ;
|
---|
| 46 | uInt nrow_m ;
|
---|
| 47 | uInt ncol_m ;
|
---|
[2533] | 48 | Block<uInt> storage_m ;
|
---|
[2519] | 49 | Matrix<uInt> arr_m ;
|
---|
[2533] | 50 | IPosition pos_m ;
|
---|
| 51 | Vector<uInt> current_m ;
|
---|
| 52 | vector< vector<uInt> > idxlist_m ;
|
---|
[2519] | 53 | } ;
|
---|
| 54 |
|
---|
| 55 | class ArrayIndexIteratorNormal : public ArrayIndexIterator
|
---|
| 56 | {
|
---|
| 57 | public:
|
---|
| 58 | ArrayIndexIteratorNormal( Matrix<uInt> &arr,
|
---|
| 59 | vector< vector<uInt> > idlist=vector< vector<uInt> >() ) ;
|
---|
| 60 | void next() ;
|
---|
[2524] | 61 | Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
|
---|
[2519] | 62 | } ;
|
---|
| 63 |
|
---|
| 64 | class ArrayIndexIteratorAcc : public ArrayIndexIterator
|
---|
| 65 | {
|
---|
| 66 | public:
|
---|
| 67 | ArrayIndexIteratorAcc( Matrix<uInt> &arr,
|
---|
| 68 | vector< vector<uInt> > idlist=vector< vector<uInt> >() ) ;
|
---|
| 69 | void next() ;
|
---|
[2524] | 70 | Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
|
---|
[2519] | 71 | private:
|
---|
[2536] | 72 | Int isChanged( Block<uInt> &idx ) ;
|
---|
[2519] | 73 | uInt *updateStorage( Int &icol, uInt *base, uInt &v ) ;
|
---|
| 74 |
|
---|
[2536] | 75 | Block<uInt> prev_m ;
|
---|
[2519] | 76 | Block<uInt> len_m ;
|
---|
[2536] | 77 | Block<Bool> skip_m ;
|
---|
[2519] | 78 | } ;
|
---|
| 79 |
|
---|
| 80 | class STIdxIter
|
---|
| 81 | {
|
---|
| 82 | public:
|
---|
| 83 | STIdxIter() ;
|
---|
| 84 | STIdxIter( const string &name,
|
---|
| 85 | const vector<string> &cols ) ;
|
---|
| 86 | STIdxIter( const CountedPtr<Scantable> &s,
|
---|
| 87 | const vector<string> &cols ) ;
|
---|
| 88 | virtual ~STIdxIter() ;
|
---|
| 89 | vector<uInt> currentSTL() { return tovector( iter_m->current() ) ; } ;
|
---|
| 90 | Vector<uInt> current() { return iter_m->current() ; } ;
|
---|
| 91 | Bool pastEnd() { return iter_m->pastEnd() ; } ;
|
---|
| 92 | void next() { iter_m->next() ; } ;
|
---|
| 93 | vector<uInt> getRowsSTL() { return tovector( iter_m->getRows() ) ; } ;
|
---|
[2536] | 94 | // !!!you should not use policy=TAKE_OVER since it causes problem!!!
|
---|
[2533] | 95 | Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
|
---|
[2519] | 96 | protected:
|
---|
| 97 | ArrayIndexIterator *iter_m ;
|
---|
| 98 | virtual void init( Table &t,
|
---|
| 99 | const vector<string> &cols ) = 0 ;
|
---|
| 100 | private:
|
---|
| 101 | vector<uInt> tovector( Vector<uInt> v ) ;
|
---|
| 102 | } ;
|
---|
| 103 |
|
---|
| 104 | class STIdxIterNormal : public STIdxIter
|
---|
| 105 | {
|
---|
| 106 | public:
|
---|
| 107 | STIdxIterNormal() ;
|
---|
| 108 | STIdxIterNormal( const string &name,
|
---|
[2536] | 109 | const vector<string> &cols ) ;
|
---|
[2519] | 110 | STIdxIterNormal( const CountedPtr<Scantable> &s,
|
---|
[2536] | 111 | const vector<string> &cols ) ;
|
---|
[2519] | 112 | ~STIdxIterNormal() ;
|
---|
| 113 | protected:
|
---|
| 114 | void init( Table &t,
|
---|
| 115 | const vector<string> &cols ) ;
|
---|
| 116 | } ;
|
---|
| 117 |
|
---|
| 118 | class STIdxIterAcc : public STIdxIter
|
---|
| 119 | {
|
---|
| 120 | public:
|
---|
| 121 | STIdxIterAcc() ;
|
---|
| 122 | STIdxIterAcc( const string &name,
|
---|
[2536] | 123 | const vector<string> &cols ) ;
|
---|
[2519] | 124 | STIdxIterAcc( const CountedPtr<Scantable> &s,
|
---|
[2536] | 125 | const vector<string> &cols ) ;
|
---|
[2519] | 126 | ~STIdxIterAcc() ;
|
---|
| 127 | protected:
|
---|
[2536] | 128 | virtual void init( Table &t,
|
---|
| 129 | const vector<string> &cols ) ;
|
---|
[2519] | 130 | } ;
|
---|
| 131 |
|
---|
[2537] | 132 | class STIdxIterExAcc : public STIdxIter
|
---|
| 133 | {
|
---|
| 134 | public:
|
---|
| 135 | STIdxIterExAcc() ;
|
---|
| 136 | STIdxIterExAcc( const string &name,
|
---|
| 137 | const vector<string> &cols ) ;
|
---|
| 138 | STIdxIterExAcc( const CountedPtr<Scantable> &s,
|
---|
| 139 | const vector<string> &cols ) ;
|
---|
| 140 | ~STIdxIterExAcc() ;
|
---|
| 141 | Int getSrcType() ;
|
---|
| 142 | String getSrcName() ;
|
---|
| 143 | protected:
|
---|
| 144 | virtual void init( Table &t,
|
---|
| 145 | const vector<string> &cols ) ;
|
---|
| 146 | private:
|
---|
| 147 | void processIntCol( Vector<Int> &in,
|
---|
| 148 | Vector<uInt> &out,
|
---|
| 149 | Block<Int> &val ) ;
|
---|
| 150 | void processStrCol( Vector<String> &in,
|
---|
| 151 | Vector<uInt> &out,
|
---|
| 152 | Block<String> &val ) ;
|
---|
| 153 | Block<Int> srctype_m ;
|
---|
| 154 | Block<String> srcname_m ;
|
---|
[2547] | 155 | Int srctypeid_m ;
|
---|
| 156 | Int srcnameid_m ;
|
---|
[2537] | 157 | } ;
|
---|
[2536] | 158 |
|
---|
[2911] | 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 |
|
---|
[2519] | 190 | } // namespace
|
---|
| 191 | #endif /* _ASAP_INDEX_ITERATOR_H_ */
|
---|