[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 |
|
---|
| 22 | using namespace asap;
|
---|
| 23 | using namespace casa;
|
---|
| 24 |
|
---|
| 25 | STSelector::STSelector() :
|
---|
| 26 | taql_("")
|
---|
| 27 | {
|
---|
| 28 | }
|
---|
| 29 |
|
---|
[850] | 30 | STSelector::STSelector( const STSelector& other ) :
|
---|
| 31 | intselections_(other.intselections_),
|
---|
| 32 | stringselections_(other.stringselections_),
|
---|
[812] | 33 | taql_(other.taql_) {
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | STSelector& 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 |
|
---|
| 46 | STSelector::~STSelector()
|
---|
| 47 | {
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void STSelector::setScans( const std::vector< int >& scans )
|
---|
| 51 | {
|
---|
[850] | 52 | setint("SCANNO", scans);
|
---|
[812] | 53 | }
|
---|
| 54 |
|
---|
| 55 | void STSelector::setBeams( const std::vector< int >& beams )
|
---|
| 56 | {
|
---|
[850] | 57 | setint("BEAMNO", beams);
|
---|
[812] | 58 | }
|
---|
| 59 |
|
---|
| 60 | void STSelector::setIFs( const std::vector< int >& ifs )
|
---|
| 61 | {
|
---|
[850] | 62 | setint("IFNO", ifs);
|
---|
[812] | 63 | }
|
---|
| 64 |
|
---|
| 65 | void STSelector::setPolarizations( const std::vector< int >& pols )
|
---|
| 66 | {
|
---|
[850] | 67 | setint("POLNO", pols);
|
---|
[812] | 68 | }
|
---|
| 69 |
|
---|
[842] | 70 | void asap::STSelector::setCycles( const std::vector< int >& cycs )
|
---|
| 71 | {
|
---|
[850] | 72 | setint("CYCLENO", cycs);
|
---|
[842] | 73 | }
|
---|
| 74 |
|
---|
[850] | 75 | void 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 |
|
---|
| 81 | void 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] | 88 | void 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] | 96 | void STSelector::setTaQL( const std::string& taql )
|
---|
| 97 | {
|
---|
| 98 | taql_ = taql;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | Table 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] | 140 | std::vector< int > STSelector::getint( const std::string& key )
|
---|
[812] | 141 | {
|
---|
[850] | 142 | if (intselections_.count(key) > 0) {
|
---|
| 143 | return std::vector<int>();//intselections_[key];
|
---|
[812] | 144 | }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | std::vector< int > STSelector::getScans( )
|
---|
| 148 | {
|
---|
[850] | 149 | return getint("SCANNO");
|
---|
[812] | 150 | }
|
---|
| 151 |
|
---|
| 152 | std::vector< int > STSelector::getBeams( )
|
---|
| 153 | {
|
---|
[850] | 154 | return getint("BEAMNO");
|
---|
[812] | 155 | }
|
---|
| 156 |
|
---|
| 157 | std::vector< int > STSelector::getIFs( )
|
---|
| 158 | {
|
---|
[850] | 159 | return getint("IFNO");
|
---|
[812] | 160 | }
|
---|
| 161 |
|
---|
| 162 | std::vector< int > STSelector::getPols( )
|
---|
| 163 | {
|
---|
[850] | 164 | return getint("POLNO");
|
---|
[812] | 165 | }
|
---|
| 166 |
|
---|
[842] | 167 | std::vector< int > asap::STSelector::getCycles( )
|
---|
| 168 | {
|
---|
[850] | 169 | return getint("CYCLENO");
|
---|
[842] | 170 | }
|
---|
| 171 |
|
---|
[812] | 172 | std::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 |
|
---|
[850] | 182 | intidmap::const_iterator it = intselections_.begin();
|
---|
| 183 | while (it != intselections_.end()) {
|
---|
| 184 | if ( it != intselections_.begin() )
|
---|
[812] | 185 | oss << setw(15) << " ";
|
---|
| 186 | oss << it->first << ": " << Vector<Int>(it->second);
|
---|
| 187 | ++it;
|
---|
[850] | 188 | if ( it != intselections_.end() ) oss << endl;
|
---|
[812] | 189 | }
|
---|
[850] | 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 | }
|
---|
[812] | 198 | if ( taql_.size() > 0 ) {
|
---|
| 199 | oss << endl << setw(15) << "" << taql_;
|
---|
| 200 | }
|
---|
| 201 | return String(oss);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | bool asap::STSelector::empty( ) const
|
---|
| 205 | {
|
---|
[850] | 206 | return (intselections_.empty() && taql_.size() == 0 );
|
---|
[812] | 207 | }
|
---|