source: trunk/src/STIdxIter.h @ 2913

Last change on this file since 2913 was 2911, checked in by Takeshi Nakazato, 10 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
Line 
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 <casa/Utilities/Sort.h>
12
13#include "Scantable.h"
14
15using namespace std ;
16using namespace casa ;
17
18namespace asap {
19class IndexIterator
20{
21public:
22  IndexIterator( IPosition &shape ) ;
23  Block<uInt> current() { return idx_m ; } ;
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 ;
43  virtual Vector<uInt> getRows( StorageInitPolicy policy=COPY ) = 0 ;
44protected:
45  IndexIterator *iter_m ;
46  uInt nrow_m ;
47  uInt ncol_m ;
48  Block<uInt> storage_m ;
49  Matrix<uInt> arr_m ;
50  IPosition pos_m ;
51  Vector<uInt> current_m ;
52  vector< vector<uInt> > idxlist_m ;
53} ;
54
55class ArrayIndexIteratorNormal : public ArrayIndexIterator
56{
57public:
58  ArrayIndexIteratorNormal( Matrix<uInt> &arr,
59                            vector< vector<uInt> > idlist=vector< vector<uInt> >() ) ;
60  void next() ;
61  Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
62} ;
63
64class ArrayIndexIteratorAcc : public ArrayIndexIterator
65{
66public:
67  ArrayIndexIteratorAcc( Matrix<uInt> &arr,
68                         vector< vector<uInt> > idlist=vector< vector<uInt> >() ) ;
69  void next() ;
70  Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
71private:
72  Int isChanged( Block<uInt> &idx ) ;
73  uInt *updateStorage( Int &icol, uInt *base, uInt &v ) ;
74
75  Block<uInt> prev_m ;
76  Block<uInt> len_m ;
77  Block<Bool> skip_m ;
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() ) ; } ;
94  // !!!you should not use policy=TAKE_OVER since it causes problem!!!
95  Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
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,
109                   const vector<string> &cols ) ;
110  STIdxIterNormal( const CountedPtr<Scantable> &s,
111                   const vector<string> &cols ) ;
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,
123                const vector<string> &cols ) ;
124  STIdxIterAcc( const CountedPtr<Scantable> &s,
125                const vector<string> &cols ) ;
126  ~STIdxIterAcc() ;
127protected:
128  virtual void init( Table &t,
129                     const vector<string> &cols ) ;
130} ;
131
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 ;
155  Int srctypeid_m ;
156  Int srcnameid_m ;
157} ;
158
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
190} // namespace
191#endif /* _ASAP_INDEX_ITERATOR_H_ */
Note: See TracBrowser for help on using the repository browser.