source: trunk/src/STSelector.cpp@ 880

Last change on this file since 880 was 869, checked in by mar637, 19 years ago

return empty std::vector<int> in ::get

File size: 4.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>
18
[850]19#include "MathUtils.h"
[812]20#include "STSelector.h"
21
22using namespace asap;
23using namespace casa;
24
25STSelector::STSelector() :
26 taql_("")
27{
28}
29
[850]30STSelector::STSelector( const STSelector& other ) :
31 intselections_(other.intselections_),
32 stringselections_(other.stringselections_),
[812]33 taql_(other.taql_) {
34}
35
36STSelector& STSelector::operator=( const STSelector& other )
37{
38 if (&other != this) {
[850]39 this->intselections_ = other.intselections_;
40 this->stringselections_ = other.stringselections_;
[812]41 this->taql_ = other.taql_;
42 }
43 return *this;
44}
45
46STSelector::~STSelector()
47{
48}
49
50void STSelector::setScans( const std::vector< int >& scans )
51{
[850]52 setint("SCANNO", scans);
[812]53}
54
55void STSelector::setBeams( const std::vector< int >& beams )
56{
[850]57 setint("BEAMNO", beams);
[812]58}
59
60void STSelector::setIFs( const std::vector< int >& ifs )
61{
[850]62 setint("IFNO", ifs);
[812]63}
64
65void STSelector::setPolarizations( const std::vector< int >& pols )
66{
[850]67 setint("POLNO", pols);
[812]68}
69
[842]70void asap::STSelector::setCycles( const std::vector< int >& cycs )
71{
[850]72 setint("CYCLENO", cycs);
[842]73}
74
[850]75void asap::STSelector::setName( const std::string& sname )
[812]76{
[850]77 std::string sql = "SELECT from $1 WHERE SRCNAME == pattern('"+sname+"')";
78 setTaQL(sql);
79}
80
81void STSelector::setint(const std::string& key, const std::vector< int >& val)
82{
[812]83 if ( val.size() > 0 ) {
[850]84 intselections_[key] = val;
[812]85 }
86}
87
[850]88void STSelector::setstring( const std::string& key,
89 const std::vector<std::string>& val )
90{
91 if ( val.size() > 0 ) {
92 stringselections_[key] = val;
93 }
94}
95
[812]96void STSelector::setTaQL( const std::string& taql )
97{
98 taql_ = taql;
99}
100
101Table STSelector::apply( const Table& tab )
102{
103 if ( empty() ) {
104 return tab;
105 }
106 TableExprNode query;
[850]107 intidmap::const_iterator it = intselections_.begin();
108 for (it; it != intselections_.end(); ++it) {
[812]109 TableExprNode theset(Vector<Int>( (*it).second ));
110 if ( query.isNull() ) {
111 query = tab.col((*it).first).in(theset);
112 } else {
113 query = tab.col((*it).first).in(theset) && query;
114 }
115 }
[850]116 stringidmap::const_iterator it1 = stringselections_.begin();
117 for (it1; it1 != stringselections_.end(); ++it1) {
118 TableExprNode theset(mathutil::toVectorString( (*it1).second ));
119 if ( query.isNull() ) {
120 query = tab.col((*it1).first).in(theset);
121 } else {
122 query = tab.col((*it1).first).in(theset) && query;
123 }
124 }
[812]125 // add taql query
126 if ( taql_.size() > 0 ) {
127 Table tmpt = tab;
128
129 if ( !query.isNull() ) { // taql and selection
130 tmpt = tableCommand(taql_, tab(query));
131 } else { // taql only
132 tmpt = tableCommand(taql_, tab);
133 }
[850]134 return tmpt;
[812]135 } else {
[850]136 return tab(query);
[812]137 }
138}
139
[850]140std::vector< int > STSelector::getint( const std::string& key )
[812]141{
[850]142 if (intselections_.count(key) > 0) {
[869]143 return intselections_[key];
[812]144 }
[869]145 return std::vector<int>();
[812]146}
147
148std::vector< int > STSelector::getScans( )
149{
[850]150 return getint("SCANNO");
[812]151}
152
153std::vector< int > STSelector::getBeams( )
154{
[850]155 return getint("BEAMNO");
[812]156}
157
158std::vector< int > STSelector::getIFs( )
159{
[850]160 return getint("IFNO");
[812]161}
162
163std::vector< int > STSelector::getPols( )
164{
[850]165 return getint("POLNO");
[812]166}
167
[842]168std::vector< int > asap::STSelector::getCycles( )
169{
[850]170 return getint("CYCLENO");
[842]171}
172
[812]173std::string asap::STSelector::print( )
174{
175 ostringstream oss;
176 oss.flags(std::ios_base::left);
177 oss << setw(15) << "Selection:";
178 if ( empty() ) {
179 oss << "none";
180 return String(oss);
181 }
182
[850]183 intidmap::const_iterator it = intselections_.begin();
184 while (it != intselections_.end()) {
185 if ( it != intselections_.begin() )
[812]186 oss << setw(15) << " ";
187 oss << it->first << ": " << Vector<Int>(it->second);
188 ++it;
[850]189 if ( it != intselections_.end() ) oss << endl;
[812]190 }
[850]191 stringidmap::const_iterator it1 = stringselections_.begin();
192 while (it1 != stringselections_.end()) {
193 if ( it1 != stringselections_.begin() )
194 oss << setw(15) << " ";
195 oss << it1->first << ": " << mathutil::toVectorString(it1->second);
196 ++it1;
197 if ( it1 != stringselections_.end() ) oss << endl;
198 }
[812]199 if ( taql_.size() > 0 ) {
200 oss << endl << setw(15) << "" << taql_;
201 }
202 return String(oss);
203}
204
205bool asap::STSelector::empty( ) const
206{
[850]207 return (intselections_.empty() && taql_.size() == 0 );
[812]208}
Note: See TracBrowser for help on using the repository browser.