source: trunk/src/STSelector.cpp@ 849

Last change on this file since 849 was 842, checked in by mar637, 19 years ago

added CYCLENO get/set

File size: 3.3 KB
Line 
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>
14#include <casa/BasicSL/String.h>
15#include <casa/iostream.h>
16#include <casa/iomanip.h>
17
18#include "STSelector.h"
19
20using namespace asap;
21using namespace casa;
22
23STSelector::STSelector() :
24 taql_("")
25{
26}
27
28STSelector::STSelector( const STSelector & other ) :
29 selections_(other.selections_),
30 taql_(other.taql_) {
31}
32
33STSelector& STSelector::operator=( const STSelector& other )
34{
35 if (&other != this) {
36 this->selections_ = other.selections_;
37 this->taql_ = other.taql_;
38 }
39 return *this;
40}
41
42STSelector::~STSelector()
43{
44}
45
46void STSelector::setScans( const std::vector< int >& scans )
47{
48 set("SCANNO", scans);
49}
50
51void STSelector::setBeams( const std::vector< int >& beams )
52{
53 set("BEAMNO", beams);
54}
55
56void STSelector::setIFs( const std::vector< int >& ifs )
57{
58 set("IFNO", ifs);
59}
60
61void STSelector::setPolarizations( const std::vector< int >& pols )
62{
63 set("POLNO", pols);
64}
65
66void asap::STSelector::setCycles( const std::vector< int >& cycs )
67{
68 set("CYCLENO", cycs);
69}
70
71void STSelector::set(const std::string& key, const std::vector< int >& val)
72{
73 if ( val.size() > 0 ) {
74 selections_[key] = val;
75 }
76}
77
78void STSelector::setTaQL( const std::string& taql )
79{
80 taql_ = taql;
81}
82
83Table STSelector::apply( const Table& tab )
84{
85 if ( empty() ) {
86 return tab;
87 }
88 TableExprNode query;
89 idmap::const_iterator it = selections_.begin();
90 for (it; it != selections_.end(); ++it) {
91 TableExprNode theset(Vector<Int>( (*it).second ));
92 if ( query.isNull() ) {
93 query = tab.col((*it).first).in(theset);
94 } else {
95 query = tab.col((*it).first).in(theset) && query;
96 }
97 }
98 // add taql query
99 if ( taql_.size() > 0 ) {
100 Table tmpt = tab;
101
102 if ( !query.isNull() ) { // taql and selection
103 tmpt = tableCommand(taql_, tab(query));
104 } else { // taql only
105 tmpt = tableCommand(taql_, tab);
106 }
107 return tmpt.copyToMemoryTable("dummy");
108 } else {
109 return tab(query).copyToMemoryTable("dummy");
110 }
111}
112
113std::vector< int > STSelector::get( const std::string& key)
114{
115 if (selections_.count(key) > 0) {
116 return std::vector<int>();//selections_[key];
117 }
118}
119
120std::vector< int > STSelector::getScans( )
121{
122 return get("SCANNO");
123}
124
125std::vector< int > STSelector::getBeams( )
126{
127 return get("BEAMNO");
128}
129
130std::vector< int > STSelector::getIFs( )
131{
132 return get("IFNO");
133}
134
135std::vector< int > STSelector::getPols( )
136{
137 return get("POLNO");
138}
139
140std::vector< int > asap::STSelector::getCycles( )
141{
142 return get("CYCLENO");
143}
144
145std::string asap::STSelector::print( )
146{
147 ostringstream oss;
148 oss.flags(std::ios_base::left);
149 oss << setw(15) << "Selection:";
150 if ( empty() ) {
151 oss << "none";
152 return String(oss);
153 }
154
155 idmap::const_iterator it = selections_.begin();
156 while (it != selections_.end()) {
157 if ( it != selections_.begin() )
158 oss << setw(15) << " ";
159 oss << it->first << ": " << Vector<Int>(it->second);
160 ++it;
161 if ( it != selections_.end() ) oss << endl;
162 }
163 if ( taql_.size() > 0 ) {
164 oss << endl << setw(15) << "" << taql_;
165 }
166 return String(oss);
167}
168
169bool asap::STSelector::empty( ) const
170{
171 return (selections_.empty() && taql_.size() == 0 );
172}
Note: See TracBrowser for help on using the repository browser.