source: trunk/src/STIdxIter.h@ 2911

Last change on this file since 2911 was 2911, checked in by Takeshi Nakazato, 11 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: test_sdcal

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Defined new index iterator class, STIdxIter2.
STIdxIter2 has almost same functionality as STIdxIter and support
various kind of data.


File size: 5.1 KB
RevLine 
[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
15using namespace std ;
16using namespace casa ;
17
18namespace asap {
19class IndexIterator
20{
21public:
[2533]22 IndexIterator( IPosition &shape ) ;
23 Block<uInt> current() { return idx_m ; } ;
[2519]24 Bool pastEnd() ;
25 void next() ;
26private:
27 uInt nfield_m ;
28 Block<uInt> prod_m ;
29 Block<uInt> idx_m ;
30 uInt niter_m ;
31 uInt maxiter_m ;
32} ;
33
34class ArrayIndexIterator
35{
36public:
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]44protected:
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
55class ArrayIndexIteratorNormal : public ArrayIndexIterator
56{
57public:
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
64class ArrayIndexIteratorAcc : public ArrayIndexIterator
65{
66public:
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]71private:
[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
80class STIdxIter
81{
82public:
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]96protected:
97 ArrayIndexIterator *iter_m ;
98 virtual void init( Table &t,
99 const vector<string> &cols ) = 0 ;
100private:
101 vector<uInt> tovector( Vector<uInt> v ) ;
102} ;
103
104class STIdxIterNormal : public STIdxIter
105{
106public:
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() ;
113protected:
114 void init( Table &t,
115 const vector<string> &cols ) ;
116} ;
117
118class STIdxIterAcc : public STIdxIter
119{
120public:
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() ;
127protected:
[2536]128 virtual void init( Table &t,
129 const vector<string> &cols ) ;
[2519]130} ;
131
[2537]132class STIdxIterExAcc : public STIdxIter
133{
134public:
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() ;
143protected:
144 virtual void init( Table &t,
145 const vector<string> &cols ) ;
146private:
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]159class STIdxIter2
160{
161public:
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();
174private:
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_ */
Note: See TracBrowser for help on using the repository browser.