source: trunk/src/STSelector.cpp @ 850

Last change on this file since 850 was 850, checked in by mar637, 18 years ago

added string map, moved map to int map added pattern based name search

File size: 4.5 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 <tables/Tables/ExprNode.h>
15#include <casa/BasicSL/String.h>
16#include <casa/iostream.h>
17#include <casa/iomanip.h>
18
19#include "MathUtils.h"
20#include "STSelector.h"
21
22using namespace asap;
23using namespace casa;
24
25STSelector::STSelector() :
26  taql_("")
27{
28}
29
30STSelector::STSelector( const STSelector&  other ) :
31  intselections_(other.intselections_),
32  stringselections_(other.stringselections_),
33  taql_(other.taql_) {
34}
35
36STSelector& STSelector::operator=( const STSelector& other )
37{
38  if (&other != this) {
39    this->intselections_ = other.intselections_;
40    this->stringselections_ = other.stringselections_;
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{
52  setint("SCANNO", scans);
53}
54
55void STSelector::setBeams( const std::vector< int >& beams )
56{
57  setint("BEAMNO", beams);
58}
59
60void STSelector::setIFs( const std::vector< int >& ifs )
61{
62  setint("IFNO", ifs);
63}
64
65void STSelector::setPolarizations( const std::vector< int >& pols )
66{
67  setint("POLNO", pols);
68}
69
70void asap::STSelector::setCycles( const std::vector< int >& cycs )
71{
72  setint("CYCLENO", cycs);
73}
74
75void asap::STSelector::setName( const std::string& sname )
76{
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{
83  if ( val.size() > 0 ) {
84    intselections_[key] = val;
85  }
86}
87
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
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;
107  intidmap::const_iterator it = intselections_.begin();
108  for (it; it != intselections_.end(); ++it) {
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  }
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  }
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    }
134    return tmpt;
135  } else {
136    return tab(query);
137  }
138}
139
140std::vector< int > STSelector::getint( const std::string& key )
141{
142  if (intselections_.count(key) > 0) {
143    return  std::vector<int>();//intselections_[key];
144  }
145}
146
147std::vector< int > STSelector::getScans( )
148{
149  return getint("SCANNO");
150}
151
152std::vector< int > STSelector::getBeams( )
153{
154  return getint("BEAMNO");
155}
156
157std::vector< int > STSelector::getIFs( )
158{
159  return getint("IFNO");
160}
161
162std::vector< int > STSelector::getPols( )
163{
164  return getint("POLNO");
165}
166
167std::vector< int > asap::STSelector::getCycles( )
168{
169  return getint("CYCLENO");
170}
171
172std::string asap::STSelector::print( )
173{
174  ostringstream oss;
175  oss.flags(std::ios_base::left);
176  oss << setw(15) << "Selection:";
177  if ( empty() ) {
178    oss << "none";
179    return String(oss);
180  }
181
182  intidmap::const_iterator it = intselections_.begin();
183  while (it != intselections_.end()) {
184    if ( it != intselections_.begin() )
185      oss << setw(15) << " ";
186    oss << it->first << ": " << Vector<Int>(it->second);
187    ++it;
188    if ( it != intselections_.end() ) oss << endl;
189  }
190  stringidmap::const_iterator it1 = stringselections_.begin();
191  while (it1 != stringselections_.end()) {
192    if ( it1 != stringselections_.begin() )
193      oss << setw(15) << " ";
194    oss << it1->first << ": " << mathutil::toVectorString(it1->second);
195    ++it1;
196    if ( it1 != stringselections_.end() ) oss << endl;
197  }
198  if ( taql_.size() > 0 ) {
199    oss << endl << setw(15) << "" << taql_;
200  }
201  return String(oss);
202}
203
204bool asap::STSelector::empty( ) const
205{
206  return (intselections_.empty() && taql_.size() == 0 );
207}
Note: See TracBrowser for help on using the repository browser.