Changeset 850


Ignore:
Timestamp:
02/28/06 10:49:29 (19 years ago)
Author:
mar637
Message:

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

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STSelector.cpp

    r842 r850  
    1212#include <tables/Tables/ExprNode.h>
    1313#include <tables/Tables/TableParse.h>
     14#include <tables/Tables/ExprNode.h>
    1415#include <casa/BasicSL/String.h>
    1516#include <casa/iostream.h>
    1617#include <casa/iomanip.h>
    1718
     19#include "MathUtils.h"
    1820#include "STSelector.h"
    1921
     
    2628}
    2729
    28 STSelector::STSelector( const STSelector & other ) :
    29   selections_(other.selections_),
     30STSelector::STSelector( const STSelector&  other ) :
     31  intselections_(other.intselections_),
     32  stringselections_(other.stringselections_),
    3033  taql_(other.taql_) {
    3134}
     
    3437{
    3538  if (&other != this) {
    36     this->selections_ = other.selections_;
     39    this->intselections_ = other.intselections_;
     40    this->stringselections_ = other.stringselections_;
    3741    this->taql_ = other.taql_;
    3842  }
     
    4650void STSelector::setScans( const std::vector< int >& scans )
    4751{
    48   set("SCANNO", scans);
     52  setint("SCANNO", scans);
    4953}
    5054
    5155void STSelector::setBeams( const std::vector< int >& beams )
    5256{
    53   set("BEAMNO", beams);
     57  setint("BEAMNO", beams);
    5458}
    5559
    5660void STSelector::setIFs( const std::vector< int >& ifs )
    5761{
    58   set("IFNO", ifs);
     62  setint("IFNO", ifs);
    5963}
    6064
    6165void STSelector::setPolarizations( const std::vector< int >& pols )
    6266{
    63   set("POLNO", pols);
     67  setint("POLNO", pols);
    6468}
    6569
    6670void asap::STSelector::setCycles( const std::vector< int >& cycs )
    6771{
    68   set("CYCLENO", cycs);
    69 }
    70 
    71 void STSelector::set(const std::string& key, const std::vector< int >& val)
     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)
    7282{
    7383  if ( val.size() > 0 ) {
    74     selections_[key] = val;
     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;
    7593  }
    7694}
     
    87105  }
    88106  TableExprNode query;
    89   idmap::const_iterator it = selections_.begin();
    90   for (it; it != selections_.end(); ++it) {
     107  intidmap::const_iterator it = intselections_.begin();
     108  for (it; it != intselections_.end(); ++it) {
    91109    TableExprNode theset(Vector<Int>( (*it).second ));
    92110    if ( query.isNull() ) {
     
    96114    }
    97115  }
     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  }
    98125  // add taql query
    99126  if ( taql_.size() > 0 ) {
     
    105132      tmpt = tableCommand(taql_, tab);
    106133    }
    107     return tmpt.copyToMemoryTable("dummy");
     134    return tmpt;
    108135  } 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];
     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];
    117144  }
    118145}
     
    120147std::vector< int > STSelector::getScans( )
    121148{
    122   return get("SCANNO");
     149  return getint("SCANNO");
    123150}
    124151
    125152std::vector< int > STSelector::getBeams( )
    126153{
    127   return get("BEAMNO");
     154  return getint("BEAMNO");
    128155}
    129156
    130157std::vector< int > STSelector::getIFs( )
    131158{
    132   return get("IFNO");
     159  return getint("IFNO");
    133160}
    134161
    135162std::vector< int > STSelector::getPols( )
    136163{
    137   return get("POLNO");
     164  return getint("POLNO");
    138165}
    139166
    140167std::vector< int > asap::STSelector::getCycles( )
    141168{
    142   return get("CYCLENO");
     169  return getint("CYCLENO");
    143170}
    144171
     
    153180  }
    154181
    155   idmap::const_iterator it = selections_.begin();
    156   while (it != selections_.end()) {
    157     if ( it != selections_.begin() )
     182  intidmap::const_iterator it = intselections_.begin();
     183  while (it != intselections_.end()) {
     184    if ( it != intselections_.begin() )
    158185      oss << setw(15) << " ";
    159186    oss << it->first << ": " << Vector<Int>(it->second);
    160187    ++it;
    161     if ( it != selections_.end() ) oss << endl;
     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;
    162197  }
    163198  if ( taql_.size() > 0 ) {
     
    169204bool asap::STSelector::empty( ) const
    170205{
    171   return (selections_.empty() && taql_.size() == 0 );
    172 }
     206  return (intselections_.empty() && taql_.size() == 0 );
     207}
  • trunk/src/STSelector.h

    r842 r850  
    4141  void setPolarizations(const std::vector<int>& pols);
    4242  void setCycles(const std::vector<int>& cycs);
    43   void setTaQL(const std::string& taql);
     43  void setName(const std::string&);
     44  virtual void setTaQL(const std::string& taql);
    4445
    4546  std::vector<int> getScans();
     
    5253  casa::Table operator()(const casa::Table& tab) { return apply(tab); };
    5354
    54   void reset() { selections_.clear(); taql_ = "";};
     55  void reset() { intselections_.clear();stringselections_.clear(); taql_ = "";};
    5556
    5657  bool empty() const;
     
    5859  std::string print();
    5960
     61protected:
     62  std::vector< int > getint( const std::string& key);
     63  std::vector< std::string > getstring( const std::string& key);
     64
     65  void setint(const std::string& key, const std::vector< int >& val);
     66  void setstring(const std::string& key, const std::vector< std::string >& val);
     67
    6068private:
    61   //
    62   std::vector< int > get( const std::string& key);
    63   void set(const std::string& key, const std::vector< int >& val);
    64 
    65   typedef std::map<std::string, std::vector<int> > idmap;
     69  typedef std::map<std::string, std::vector<int> > intidmap;
     70  typedef std::map<std::string, std::vector<std::string> > stringidmap;
    6671  // has to be mutable, as to stl limitations
    67   mutable idmap selections_;
     72  mutable intidmap intselections_;
     73  mutable stringidmap stringselections_;
    6874  std::string taql_;
    6975};
Note: See TracChangeset for help on using the changeset viewer.