source: branches/alma/src/STSelector.cpp@ 2582

Last change on this file since 2582 was 1693, checked in by Takeshi Nakazato, 15 years ago

New Development: No

JIRA Issue: Yes CAS-1908

Ready to Release: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes

Module(s): Module Names change impacts.

Description: Describe your changes here...

Changed a tagging as the source type is tagged by using SRCTYPE, not
an extra string in SRCNAME. To do this, I have defined a selection method
by SRCTYPE in STSelector class. I have newly added python_SrcType.cpp
that defines a Python interface of SrcType enums which is defined
in atnf/PKSIO/SrcType.h.

Since I have added new file in the src directory, I have modified src/Makefile
to compile new file.

File size: 8.5 KB
RevLine 
[812]1//
2// C++ Implementation: STSelector
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <tables/Tables/ExprNode.h>
13#include <tables/Tables/TableParse.h>
[850]14#include <tables/Tables/ExprNode.h>
[812]15#include <casa/BasicSL/String.h>
16#include <casa/iostream.h>
17#include <casa/iomanip.h>
[902]18#include <casa/Exceptions/Error.h>
[812]19
[850]20#include "MathUtils.h"
[902]21#include "STPol.h"
[812]22#include "STSelector.h"
23
24using namespace asap;
25using namespace casa;
26
27STSelector::STSelector() :
28 taql_("")
29{
30}
31
[850]32STSelector::STSelector( const STSelector& other ) :
33 intselections_(other.intselections_),
34 stringselections_(other.stringselections_),
[939]35 poltypes_(other.poltypes_),
[995]36 order_(other.order_),
37 taql_(other.taql_)
38{
[812]39}
40
41STSelector& STSelector::operator=( const STSelector& other )
42{
43 if (&other != this) {
[850]44 this->intselections_ = other.intselections_;
45 this->stringselections_ = other.stringselections_;
[812]46 this->taql_ = other.taql_;
[954]47 this->poltypes_ = other.poltypes_;
48 this->order_ = other.order_;
[812]49 }
50 return *this;
51}
52
53STSelector::~STSelector()
54{
55}
56
57void STSelector::setScans( const std::vector< int >& scans )
58{
[850]59 setint("SCANNO", scans);
[812]60}
61
62void STSelector::setBeams( const std::vector< int >& beams )
63{
[850]64 setint("BEAMNO", beams);
[812]65}
66
67void STSelector::setIFs( const std::vector< int >& ifs )
68{
[850]69 setint("IFNO", ifs);
[812]70}
71
72void STSelector::setPolarizations( const std::vector< int >& pols )
73{
[850]74 setint("POLNO", pols);
[954]75 poltypes_ = std::vector<std::string>();
[812]76}
77
[842]78void asap::STSelector::setCycles( const std::vector< int >& cycs )
79{
[850]80 setint("CYCLENO", cycs);
[842]81}
82
[850]83void asap::STSelector::setName( const std::string& sname )
[812]84{
[1387]85 std::string sql = "SELECT FROM $1 WHERE SRCNAME == pattern('"+sname+"')";
[850]86 setTaQL(sql);
87}
88
[1693]89void STSelector::setTypes( const std::vector< int >& types )
90{
91 setint("SRCTYPE", types);
92}
93
[850]94void STSelector::setint(const std::string& key, const std::vector< int >& val)
95{
[812]96 if ( val.size() > 0 ) {
[850]97 intselections_[key] = val;
[812]98 }
99}
100
[850]101void STSelector::setstring( const std::string& key,
102 const std::vector<std::string>& val )
103{
104 if ( val.size() > 0 ) {
105 stringselections_[key] = val;
106 }
107}
108
[812]109void STSelector::setTaQL( const std::string& taql )
110{
111 taql_ = taql;
112}
113
[902]114
115void asap::STSelector::setSortOrder( const std::vector< std::string > & order )
116{
117 order_.resize(order.size(), True);
[995]118 for (unsigned int i=0;i<order.size();++i) {
[902]119 order_[i] = order[i];
120 }
121}
122
[1639]123void STSelector::setRows( const std::vector< int >& rows )
124{
125 rowselection_ = rows;
126}
127
128// Table STSelector::apply( const Table& tab )
129// {
130// if ( empty() ) {
131// return sort(tab);
132// }
133// TableExprNode query;
134// intidmap::const_iterator it;
135// for (it = intselections_.begin(); it != intselections_.end(); ++it) {
136// TableExprNode theset(Vector<Int>( (*it).second ));
137// if ( query.isNull() ) {
138// query = tab.col((*it).first).in(theset);
139// } else {
140// query = tab.col((*it).first).in(theset) && query;
141// }
142// }
143// stringidmap::const_iterator it1;
144// for (it1 = stringselections_.begin(); it1 != stringselections_.end(); ++it1) {
145// TableExprNode theset(mathutil::toVectorString( (*it1).second ));
146// if ( query.isNull() ) {
147// query = tab.col((*it1).first).in(theset);
148// } else {
149// query = tab.col((*it1).first).in(theset) && query;
150// }
151// }
152// // add taql query
153// if ( taql_.size() > 0 ) {
154// Table tmpt = tab;
155// std::string pytaql = "USING STYLE PYTHON " + taql_;
156
157// if ( !query.isNull() ) { // taql and selection
158// tmpt = tableCommand(pytaql, tab(query));
159// } else { // taql only
160// tmpt = tableCommand(pytaql, tab);
161// }
162// return sort(tmpt);
163// } else {
164// if ( query.isNull() ) {
165// return sort(tab);
166// } else {
167// return sort(tab(query));
168// }
169// }
170// }
[812]171Table STSelector::apply( const Table& tab )
172{
173 if ( empty() ) {
[902]174 return sort(tab);
[812]175 }
[1639]176 Table basetab = tab;
177 // Important!! Be sure to apply row selection first.
178 if (rowselection_.size() > 0){
179 //Vector<Int> intrownrs(rowselection_);
180 Vector<uInt> rownrs( rowselection_.size() );
181 convertArray(rownrs, Vector<Int> ( rowselection_ ));
182 basetab = tab( rownrs );
183 ///TableExprNode theset(Vector<Int>( rowselection_ ));
184 ///query = tab.nodeRownr().in(theset);
185 }
[812]186 TableExprNode query;
[995]187 intidmap::const_iterator it;
[1000]188 for (it = intselections_.begin(); it != intselections_.end(); ++it) {
[812]189 TableExprNode theset(Vector<Int>( (*it).second ));
190 if ( query.isNull() ) {
[1639]191 //query = tab.col((*it).first).in(theset);
192 query = basetab.col((*it).first).in(theset);
[812]193 } else {
[1639]194 //query = tab.col((*it).first).in(theset) && query;
195 query = basetab.col((*it).first).in(theset) && query;
[812]196 }
197 }
[995]198 stringidmap::const_iterator it1;
199 for (it1 = stringselections_.begin(); it1 != stringselections_.end(); ++it1) {
[850]200 TableExprNode theset(mathutil::toVectorString( (*it1).second ));
201 if ( query.isNull() ) {
[1639]202 //query = tab.col((*it1).first).in(theset);
203 query = basetab.col((*it1).first).in(theset);
[850]204 } else {
[1639]205 //query = tab.col((*it1).first).in(theset) && query;
206 query = basetab.col((*it1).first).in(theset) && query;
[850]207 }
208 }
[812]209 // add taql query
210 if ( taql_.size() > 0 ) {
[1639]211 //Table tmpt = tab;
212 Table tmpt = basetab;
[1603]213 std::string pytaql = "USING STYLE PYTHON " + taql_;
[812]214
215 if ( !query.isNull() ) { // taql and selection
[1639]216 //tmpt = tableCommand(pytaql, tab(query));
217 tmpt = tableCommand(pytaql, basetab(query));
[812]218 } else { // taql only
[1639]219 //tmpt = tableCommand(pytaql, tab);
220 tmpt = tableCommand(pytaql, basetab);
[812]221 }
[902]222 return sort(tmpt);
[812]223 } else {
[902]224 if ( query.isNull() ) {
[1639]225 //return sort(tab);
226 return sort(basetab);
[902]227 } else {
[1639]228 //return sort(tab(query));
229 return sort(basetab(query));
[902]230 }
[812]231 }
232}
233
[939]234std::vector< int > STSelector::getint( const std::string& key ) const
[812]235{
[850]236 if (intselections_.count(key) > 0) {
[869]237 return intselections_[key];
[812]238 }
[869]239 return std::vector<int>();
[812]240}
241
[939]242std::vector< int > STSelector::getScans( ) const
[812]243{
[850]244 return getint("SCANNO");
[812]245}
246
[939]247std::vector< int > STSelector::getBeams( ) const
[812]248{
[850]249 return getint("BEAMNO");
[812]250}
251
[939]252std::vector< int > STSelector::getIFs( ) const
[812]253{
[850]254 return getint("IFNO");
[812]255}
256
[939]257std::vector< int > STSelector::getPols( ) const
[812]258{
[850]259 return getint("POLNO");
[812]260}
261
[939]262std::vector< int > asap::STSelector::getCycles( ) const
[842]263{
[850]264 return getint("CYCLENO");
[842]265}
266
[1693]267std::vector< int > asap::STSelector::getTypes( ) const
268{
269 return getint("SRCTYPE") ;
270}
271
[812]272std::string asap::STSelector::print( )
273{
274 ostringstream oss;
275 oss.flags(std::ios_base::left);
276 oss << setw(15) << "Selection:";
277 if ( empty() ) {
278 oss << "none";
279 return String(oss);
280 }
281
[850]282 intidmap::const_iterator it = intselections_.begin();
283 while (it != intselections_.end()) {
284 if ( it != intselections_.begin() )
[812]285 oss << setw(15) << " ";
286 oss << it->first << ": " << Vector<Int>(it->second);
287 ++it;
[850]288 if ( it != intselections_.end() ) oss << endl;
[812]289 }
[850]290 stringidmap::const_iterator it1 = stringselections_.begin();
291 while (it1 != stringselections_.end()) {
292 if ( it1 != stringselections_.begin() )
293 oss << setw(15) << " ";
294 oss << it1->first << ": " << mathutil::toVectorString(it1->second);
295 ++it1;
296 if ( it1 != stringselections_.end() ) oss << endl;
297 }
[812]298 if ( taql_.size() > 0 ) {
299 oss << endl << setw(15) << "" << taql_;
300 }
301 return String(oss);
302}
303
304bool asap::STSelector::empty( ) const
305{
[1639]306 //return (intselections_.empty() && taql_.size() == 0 );
307 return (intselections_.empty() && taql_.size() == 0 && rowselection_.size() == 0);
[812]308}
[902]309
310casa::Table asap::STSelector::sort( const casa::Table & tab )
311{
312 if (order_.nelements() > 0) {
313 Table t = tab.sort(order_);
314 return t;
315 } else {
316 return tab;
317 }
318}
319
320
321void asap::STSelector::setPolFromStrings( const std::vector< std::string >& pols )
322{
323 poltypes_.clear();
324 std::vector<int> polints;
[995]325 std::vector<std::string>::const_iterator strit;
326 for (strit = pols.begin(); strit != pols.end(); ++strit) {
[902]327 std::pair<int, std::string> val;
328 try {
329 val = STPol::polFromString(*strit);
330 } catch (AipsError& e) {
331 poltypes_.clear();
332 throw(e);
333 }
334 polints.push_back(val.first);
335 poltypes_.push_back(val.second);
336 }
337 setint("POLNO", polints);
338}
339
[939]340std::vector< std::string > asap::STSelector::getPolTypes( ) const
[902]341{
342 return poltypes_;
343}
[939]344
345std::vector<std::string> asap::STSelector::getSortOrder() const
346{
347 std::vector<std::string> out;
348 for (uInt i=0;i<order_.nelements(); ++i)
349 out.push_back(order_[i]);
350 return out;
351}
Note: See TracBrowser for help on using the repository browser.