Changeset 2449 for branches


Ignore:
Timestamp:
03/29/12 19:43:29 (12 years ago)
Author:
KohjiNakamura
Message:

probably faster TableExprNode?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/hpc33/src/STMath.cpp

    r2443 r2449  
    5656using namespace casa;
    5757using namespace asap;
     58
     59class TableExprPredicate {
     60public:
     61        virtual ~TableExprPredicate() {}
     62        virtual Bool match(Table const& table, const TableExprId& id) const = 0;
     63};
     64
     65class CustomTableExprNodeRep :public TableExprNodeRep {
     66        TableExprPredicate const & pred_;
     67public:
     68        CustomTableExprNodeRep(const Table &table,
     69                TableExprPredicate const & pred)
     70        :TableExprNodeRep(TableExprNodeRep::NTBool,
     71                TableExprNodeRep::VTScalar,
     72                TableExprNodeRep::OtUndef,
     73                table),
     74         pred_(pred) {}
     75        virtual Bool getBool(const TableExprId& id) {
     76                return pred_.match(table(), id);
     77        }
     78};
     79
     80class CustomTableExprNode: public TableExprNode {
     81        CustomTableExprNodeRep nodeRep;
     82public:
     83        CustomTableExprNode(Table const &table, TableExprPredicate const &pred)
     84        : nodeRep(table, pred), TableExprNode(&nodeRep) {
     85        }
     86        virtual ~CustomTableExprNode() {
     87        }
     88};
     89
     90template<typename T, size_t N>
     91class MyPredicate: public TableExprPredicate {
     92        Table const & table;
     93        ROScalarColumn<T> *cols[N];
     94        uInt const *values;
     95public:
     96        virtual ~MyPredicate() {
     97                for (size_t i = 0; i < N; i++) {
     98                        delete cols[i];
     99                }
     100        }
     101        MyPredicate(Table const &table_,
     102                char const*const colNames[],
     103                uInt const values_[]):
     104                        table(table_), values(values_) {
     105                for (size_t i = 0; i < N; i++) {
     106                        cols[i] = new ROScalarColumn<T>(table, colNames[i]);
     107                }
     108        }
     109        virtual Bool match(Table const& table, const TableExprId& id) const {
     110                for (size_t i = 0; i < N; i++) {
     111                        T v;
     112                        cols[i]->get(id.rownr(), v);
     113                        if (v != values[i]) {
     114                                return false;
     115                        }
     116                }
     117                return true;
     118        }
     119};
    58120
    59121// 2012/02/17 TN
     
    214276      ROScalarColumn<Double> tmp(tin, "TIME");
    215277      Double td;tmp.get(0,td);
     278
     279#if 1
     280      static char const*const colNames1[] = { "BEAMNO", "IFNO", "POLNO" };
     281      uInt const values1[] = { rec.asuInt("BEAMNO"), rec.asuInt("IFNO"), rec.asuInt("POLNO") };
     282      MyPredicate<uInt, 3> myPred(tin, colNames1, values1);
     283      CustomTableExprNode myExpr(tin, myPred);
     284      Table basesubt = tin(myExpr);
     285#else
    216286      Table basesubt = tin( tin.col("BEAMNO") == Int(rec.asuInt("BEAMNO"))
    217287                         && tin.col("IFNO") == Int(rec.asuInt("IFNO"))
    218288                         && tin.col("POLNO") == Int(rec.asuInt("POLNO")) );
     289#endif
    219290      Table subt;
    220291      if ( avmode == "SOURCE") {
Note: See TracChangeset for help on using the changeset viewer.