00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef TABLES_EXPRNODESET_H
00029 #define TABLES_EXPRNODESET_H
00030
00031
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/tables/TaQL/ExprNodeRep.h>
00034 #include <casacore/tables/TaQL/ExprNodeArray.h>
00035 #include <casacore/casa/Containers/Block.h>
00036
00037 namespace casacore {
00038
00039
00040 class TableExprNode;
00041 class IPosition;
00042 class Slicer;
00043 template<class T> class Vector;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 class TableExprNodeSetElem : public TableExprNodeRep
00094 {
00095 public:
00096
00097 explicit TableExprNodeSetElem (const TableExprNode& node);
00098
00099
00100
00101
00102
00103
00104 TableExprNodeSetElem (const TableExprNode* start,
00105 const TableExprNode* end,
00106 const TableExprNode* incr,
00107 Bool isEndExcl = False);
00108
00109
00110
00111 TableExprNodeSetElem (Bool isLeftClosed, const TableExprNode& start,
00112 const TableExprNode& end, Bool isRightClosed);
00113
00114
00115 TableExprNodeSetElem (Bool isLeftClosed, const TableExprNode& start);
00116
00117
00118 TableExprNodeSetElem (const TableExprNode& end, Bool isRightClosed);
00119
00120
00121 TableExprNodeSetElem (const TableExprNodeSetElem&);
00122
00123 ~TableExprNodeSetElem();
00124
00125
00126 void show (ostream& os, uInt indent) const;
00127
00128
00129 virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00130
00131
00132 virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
00133
00134
00135 Bool isDiscrete() const;
00136
00137
00138 Bool isSingle() const;
00139
00140
00141
00142 Bool isLeftClosed() const;
00143 Bool isRightClosed() const;
00144
00145
00146
00147
00148
00149
00150 TableExprNodeRep* start() const;
00151 TableExprNodeRep* end() const;
00152 TableExprNodeRep* increment() const;
00153
00154
00155
00156
00157
00158
00159
00160 void fillVector (Vector<Bool>& vec, Int64& cnt,
00161 const TableExprId& id) const;
00162 void fillVector (Vector<Int64>& vec, Int64& cnt,
00163 const TableExprId& id) const;
00164 void fillVector (Vector<Double>& vec, Int64& cnt,
00165 const TableExprId& id) const;
00166 void fillVector (Vector<DComplex>& vec, Int64& cnt,
00167 const TableExprId& id) const;
00168 void fillVector (Vector<String>& vec, Int64& cnt,
00169 const TableExprId& id) const;
00170 void fillVector (Vector<MVTime>& vec, Int64& cnt,
00171 const TableExprId& id) const;
00172
00173
00174
00175
00176
00177
00178
00179
00180 void matchBool (Bool* match, const Bool* value, uInt nval,
00181 const TableExprId& id) const;
00182 void matchInt (Bool* match, const Int64* value, uInt nval,
00183 const TableExprId& id) const;
00184 void matchDouble (Bool* match, const Double* value, uInt nval,
00185 const TableExprId& id) const;
00186 void matchDComplex (Bool* match, const DComplex* value, uInt nval,
00187 const TableExprId& id) const;
00188 void matchString (Bool* match, const String* value, uInt nval,
00189 const TableExprId& id) const;
00190 void matchDate (Bool* match, const MVTime* value, uInt nval,
00191 const TableExprId& id) const;
00192
00193
00194
00195
00196
00197 TableExprNodeSetElem* evaluate (const TableExprId& id) const;
00198
00199
00200 void checkTable();
00201
00202
00203 virtual void adaptSetUnits (const Unit&);
00204
00205 private:
00206
00207 TableExprNodeSetElem& operator= (const TableExprNodeSetElem&);
00208
00209
00210
00211 TableExprNodeSetElem (const TableExprNodeSetElem& that,
00212 TableExprNodeRep* start, TableExprNodeRep* end,
00213 TableExprNodeRep* incr);
00214
00215
00216 void setup (Bool isLeftClosed, const TableExprNode* start,
00217 const TableExprNode* end, Bool isRightClosed);
00218
00219
00220 TableExprNodeRep* itsStart;
00221 TableExprNodeRep* itsEnd;
00222 TableExprNodeRep* itsIncr;
00223 Bool itsEndExcl;
00224 Bool itsLeftClosed;
00225 Bool itsRightClosed;
00226 Bool itsDiscrete;
00227 Bool itsSingle;
00228 };
00229
00230
00231
00232 inline Bool TableExprNodeSetElem::isDiscrete() const
00233 {
00234 return itsDiscrete;
00235 }
00236 inline Bool TableExprNodeSetElem::isSingle() const
00237 {
00238 return itsSingle;
00239 }
00240 inline Bool TableExprNodeSetElem::isLeftClosed() const
00241 {
00242 return itsLeftClosed;
00243 }
00244 inline Bool TableExprNodeSetElem::isRightClosed() const
00245 {
00246 return itsRightClosed;
00247 }
00248 inline TableExprNodeRep* TableExprNodeSetElem::start() const
00249 {
00250 return itsStart;
00251 }
00252 inline TableExprNodeRep* TableExprNodeSetElem::end() const
00253 {
00254 return itsEnd;
00255 }
00256 inline TableExprNodeRep* TableExprNodeSetElem::increment() const
00257 {
00258 return itsIncr;
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 class TableExprNodeSet : public TableExprNodeRep
00306 {
00307 public:
00308
00309 TableExprNodeSet();
00310
00311
00312
00313
00314 TableExprNodeSet (const IPosition&);
00315
00316
00317
00318
00319
00320
00321 TableExprNodeSet (const Slicer&);
00322
00323
00324
00325
00326
00327 TableExprNodeSet (const Vector<uInt>& rownrs, const TableExprNodeSet&);
00328
00329 TableExprNodeSet(const TableExprNodeSet&);
00330
00331 ~TableExprNodeSet();
00332
00333
00334
00335
00336
00337 void add (const TableExprNodeSetElem&, Bool adaptType=False);
00338
00339
00340 void show (ostream& os, uInt indent) const;
00341
00342
00343 virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00344
00345
00346 virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
00347
00348
00349
00350
00351
00352 void checkEqualDataTypes() const;
00353
00354
00355
00356 Bool isSingle() const;
00357
00358
00359
00360
00361 Bool isDiscrete() const;
00362
00363
00364 Bool isBounded() const;
00365
00366
00367 uInt nelements() const;
00368
00369
00370 const TableExprNodeSetElem& operator[] (uInt index) const;
00371
00372
00373 Bool hasArrays() const;
00374
00375
00376
00377 TableExprNodeRep* setOrArray() const;
00378
00379 template<typename T>
00380 MArray<T> toArray (const TableExprId& id) const;
00381
00382
00383
00384 virtual MArray<Bool> getArrayBool (const TableExprId& id);
00385 virtual MArray<Int64> getArrayInt (const TableExprId& id);
00386 virtual MArray<Double> getArrayDouble (const TableExprId& id);
00387 virtual MArray<DComplex> getArrayDComplex (const TableExprId& id);
00388 virtual MArray<String> getArrayString (const TableExprId& id);
00389 virtual MArray<MVTime> getArrayDate (const TableExprId& id);
00390
00391
00392
00393
00394 virtual Bool hasBool (const TableExprId& id, Bool value);
00395 virtual Bool hasInt (const TableExprId& id, Int64 value);
00396 virtual Bool hasDouble (const TableExprId& id, Double value);
00397 virtual Bool hasDComplex (const TableExprId& id, const DComplex& value);
00398 virtual Bool hasString (const TableExprId& id, const String& value);
00399 virtual Bool hasDate (const TableExprId& id, const MVTime& value);
00400 virtual MArray<Bool> hasArrayBool (const TableExprId& id,
00401 const MArray<Bool>& value);
00402 virtual MArray<Bool> hasArrayInt (const TableExprId& id,
00403 const MArray<Int64>& value);
00404 virtual MArray<Bool> hasArrayDouble (const TableExprId& id,
00405 const MArray<Double>& value);
00406 virtual MArray<Bool> hasArrayDComplex (const TableExprId& id,
00407 const MArray<DComplex>& value);
00408 virtual MArray<Bool> hasArrayString (const TableExprId& id,
00409 const MArray<String>& value);
00410 virtual MArray<Bool> hasArrayDate (const TableExprId& id,
00411 const MArray<MVTime>& value);
00412
00413
00414
00415 virtual void adaptSetUnits (const Unit&);
00416
00417 private:
00418
00419 TableExprNodeSet& operator= (const TableExprNodeSet&);
00420
00421
00422 void deleteElems();
00423
00424
00425 TableExprNodeRep* toConstArray() const;
00426
00427
00428
00429 void getArray (MArray<Bool>& marr, TableExprNodeRep* node,
00430 const TableExprId& id) const
00431 { marr.reference (node->getArrayBool (id)); }
00432 void getArray (MArray<Int64>& marr, TableExprNodeRep* node,
00433 const TableExprId& id) const
00434 { marr.reference (node->getArrayInt (id)); }
00435 void getArray (MArray<Double>& marr, TableExprNodeRep* node,
00436 const TableExprId& id) const
00437 { marr.reference (node->getArrayDouble (id)); }
00438 void getArray (MArray<DComplex>& marr, TableExprNodeRep* node,
00439 const TableExprId& id) const
00440 { marr.reference (node->getArrayDComplex (id)); }
00441 void getArray (MArray<String>& marr, TableExprNodeRep* node,
00442 const TableExprId& id) const
00443 { marr.reference (node->getArrayString (id)); }
00444 void getArray (MArray<MVTime>& marr, TableExprNodeRep* node,
00445 const TableExprId& id) const
00446 { marr.reference (node->getArrayDate (id)); }
00447
00448
00449
00450
00451 void combineIntIntervals();
00452 void combineDoubleIntervals();
00453 void combineDateIntervals();
00454
00455
00456
00457
00458
00459 typedef Bool (TableExprNodeSet::* FindFuncPtr) (Double value);
00460 Bool findOpenOpen (Double value);
00461 Bool findOpenClosed (Double value);
00462 Bool findClosedOpen (Double value);
00463 Bool findClosedClosed (Double value);
00464 void setFindFunc (Bool isLeftClosed, Bool isRightClosed);
00465
00466
00467 PtrBlock<TableExprNodeSetElem*> itsElems;
00468 Bool itsSingle;
00469 Bool itsDiscrete;
00470 Bool itsBounded;
00471 Bool itsCheckTypes;
00472 Bool itsAllIntervals;
00473 Block<Double> itsStart;
00474 Block<Double> itsEnd;
00475 FindFuncPtr itsFindFunc;
00476 };
00477
00478
00479 inline Bool TableExprNodeSet::isSingle() const
00480 {
00481 return itsSingle;
00482 }
00483 inline Bool TableExprNodeSet::isDiscrete() const
00484 {
00485 return itsDiscrete;
00486 }
00487 inline Bool TableExprNodeSet::isBounded() const
00488 {
00489 return itsBounded;
00490 }
00491 inline uInt TableExprNodeSet::nelements() const
00492 {
00493 return itsElems.nelements();
00494 }
00495 inline const TableExprNodeSetElem&
00496 TableExprNodeSet::operator[] (uInt index) const
00497 {
00498 return *(itsElems[index]);
00499 }
00500
00501
00502 template<typename T>
00503 MArray<T> TableExprNodeSet::toArray (const TableExprId& id) const
00504 {
00505
00506 DebugAssert (itsBounded, AipsError);
00507 Int64 n = nelements();
00508 if (hasArrays()) {
00509
00510 MArray<T> marr;
00511 getArray (marr, itsElems[0]->start(), id);
00512 if (marr.isNull()) return marr;
00513 Array<T> result (marr.array());
00514 Array<Bool> mask (marr.mask());
00515 IPosition shp = result.shape();
00516 uInt naxes = shp.size();
00517 shp.append (IPosition(1,n));
00518 result.resize (shp, True);
00519 if (! mask.empty()) mask.resize (shp, True);
00520 ArrayIterator<T> iter(result, shp.size()-1);
00521 IPosition s(shp);
00522 IPosition e(shp);
00523 s[naxes] = 0;
00524 e[naxes] = 0;
00525 for (Int64 i=1; i<n; i++) {
00526 iter.next();
00527 s[naxes]++;
00528 e[naxes]++;
00529 MArray<T> marr;
00530 getArray (marr, itsElems[i]->start(), id);
00531 if (marr.isNull()) return marr;
00532 if (! marr.shape().isEqual (iter.array().shape())) {
00533 throw TableInvExpr("Shapes of nested arrays do not match");
00534 }
00535 iter.array() = marr.array();
00536 if (marr.hasMask()) {
00537 if (mask.empty()) {
00538 mask.resize (shp);
00539 mask = False;
00540 }
00541 mask(s,e) = marr.mask();
00542 } else if (! mask.empty()) {
00543 mask(s,e) = False;
00544 }
00545 }
00546 return MArray<T>(result, mask);
00547 } else {
00548 Int64 n = nelements();
00549 Int64 cnt = 0;
00550 Vector<T> result (n);
00551 for (Int64 i=0; i<n; i++) {
00552 itsElems[i]->fillVector (result, cnt, id);
00553 }
00554 result.resize (cnt, True);
00555 return MArray<T>(result);
00556 }
00557 }
00558
00559
00560
00561 }
00562
00563 #endif