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