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