[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 |
|
---|
[842] | 66 | void asap::STSelector::setCycles( const std::vector< int >& cycs )
|
---|
| 67 | {
|
---|
| 68 | set("CYCLENO", cycs);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[812] | 71 | void STSelector::set(const std::string& key, const std::vector< int >& val)
|
---|
| 72 | {
|
---|
| 73 | if ( val.size() > 0 ) {
|
---|
| 74 | selections_[key] = val;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void STSelector::setTaQL( const std::string& taql )
|
---|
| 79 | {
|
---|
| 80 | taql_ = taql;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | Table 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 |
|
---|
| 113 | std::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 |
|
---|
| 120 | std::vector< int > STSelector::getScans( )
|
---|
| 121 | {
|
---|
| 122 | return get("SCANNO");
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | std::vector< int > STSelector::getBeams( )
|
---|
| 126 | {
|
---|
| 127 | return get("BEAMNO");
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | std::vector< int > STSelector::getIFs( )
|
---|
| 131 | {
|
---|
| 132 | return get("IFNO");
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | std::vector< int > STSelector::getPols( )
|
---|
| 136 | {
|
---|
| 137 | return get("POLNO");
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[842] | 140 | std::vector< int > asap::STSelector::getCycles( )
|
---|
| 141 | {
|
---|
| 142 | return get("CYCLENO");
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[812] | 145 | std::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 |
|
---|
| 169 | bool asap::STSelector::empty( ) const
|
---|
| 170 | {
|
---|
| 171 | return (selections_.empty() && taql_.size() == 0 );
|
---|
| 172 | }
|
---|