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_TABLEPROXY_H
00029 #define TABLES_TABLEPROXY_H
00030
00031
00032
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/tables/Tables/Table.h>
00035 #include <casacore/casa/Containers/Record.h>
00036 #include <casacore/casa/Arrays/Vector.h>
00037 #include <vector>
00038
00039
00040
00041 namespace casacore {
00042 class ValueHolder;
00043 class RecordFieldId;
00044 class Table;
00045 class TableLock;
00046 class ColumnDesc;
00047 class TableExprNode;
00048 template<class T> class Vector;
00049 class Slicer;
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
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 class TableProxy
00104 {
00105 public:
00106
00107
00108 TableProxy();
00109
00110
00111 TableProxy (const Table& table)
00112 : table_p (table) {}
00113
00114
00115 TableProxy (const String& tableName,
00116 const Record& lockOptions,
00117 int option);
00118
00119
00120 TableProxy (const String& tableName,
00121 const Record& lockOptions,
00122 const String& endianFormat,
00123 const String& memType,
00124 int nrow,
00125 const Record& tableDesc,
00126 const Record& dmInfo);
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 TableProxy (const Vector<String>& tableNames,
00138 const Vector<String>& concatenateSubTableNames,
00139 const Record& lockOptions,
00140 int option);
00141 TableProxy (const std::vector<TableProxy>& tables,
00142 const Vector<String>& concatenateSubTableNames,
00143 int dummy1=0, int dummy2=0, int dummy3=0);
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 TableProxy (const String& command,
00155 const std::vector<TableProxy>& tables);
00156
00157
00158
00159
00160
00161 TableProxy (const String& fileName,
00162 const String& headerName,
00163 const String& tableName,
00164 Bool autoHeader,
00165 const IPosition& autoShape,
00166 const String& separator,
00167 const String& commentMarker,
00168 Int firstLine,
00169 Int lastLine,
00170 const Vector<String>& columnNames = Vector<String>(),
00171 const Vector<String>& dataTypes = Vector<String>());
00172
00173
00174 TableProxy (const TableProxy&);
00175
00176
00177 ~TableProxy();
00178
00179
00180 TableProxy& operator= (const TableProxy&);
00181
00182
00183
00184 TableProxy selectRows (const Vector<Int>& rownrs,
00185 const String& outName);
00186
00187
00188 void reopenRW();
00189
00190
00191 void resync();
00192
00193
00194 void flush (Bool recursive);
00195
00196
00197 void close();
00198
00199
00200
00201 String endianFormat() const;
00202
00203
00204 void lock (Bool mode, Int nattempts);
00205
00206
00207 void unlock();
00208
00209
00210 Bool hasDataChanged();
00211
00212
00213 Bool hasLock (Bool mode);
00214
00215
00216
00217 Record lockOptions();
00218
00219
00220
00221 Bool isMultiUsed (Bool checkSubTables);
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 String toAscii (const String& asciiFile,
00245 const String& headerFile,
00246 const Vector<String>& columns,
00247 const String& sep,
00248 const Vector<Int>& precision,
00249 Bool useBrackets);
00250
00251
00252 void rename (const String& newTableName);
00253
00254
00255
00256 TableProxy copy (const String& newTableName,
00257 Bool toMemoryTable,
00258 Bool deepCopy,
00259 Bool valueCopy,
00260 const String& endianFormat,
00261 const Record& dminfo,
00262 Bool noRows);
00263
00264
00265
00266 void copyRows (TableProxy& out,
00267 Int startIn,
00268 Int startOut,
00269 Int nrow);
00270
00271
00272 void deleteTable (Bool checkSubTables);
00273
00274
00275 Record tableInfo();
00276
00277
00278 void putTableInfo (const Record& value);
00279
00280
00281 void addReadmeLine (const String& line);
00282
00283
00284 Bool isReadable() const;
00285
00286
00287 Bool isWritable() const;
00288
00289
00290 void setMaximumCacheSize (const String& columnName,
00291 Int nbytes);
00292
00293
00294 void addColumns (const Record& tableDesc,
00295 const Record& dminfo,
00296 Bool addToParent);
00297
00298
00299 void renameColumn (const String& nameOld,
00300 const String& nameNew);
00301
00302
00303 void removeColumns (const Vector<String>& columnNames);
00304
00305
00306 void addRow (Int nrow);
00307
00308
00309 void removeRow (const Vector<Int>& rownrs);
00310
00311
00312
00313
00314
00315
00316 ValueHolder getColumn (const String& columnName,
00317 Int row,
00318 Int nrow,
00319 Int incr);
00320 void getColumnVH (const String& columnName,
00321 Int row,
00322 Int nrow,
00323 Int incr,
00324 const ValueHolder& vh);
00325 Record getVarColumn (const String& columnName,
00326 Int row,
00327 Int nrow,
00328 Int incr);
00329
00330
00331
00332
00333
00334 ValueHolder getColumnSlice (const String& columnName,
00335 Int row,
00336 Int nrow,
00337 Int incr,
00338 const Vector<Int>& blc,
00339 const Vector<Int>& trc,
00340 const Vector<Int>& inc);
00341 ValueHolder getColumnSliceIP (const String& columnName,
00342 const IPosition& blc,
00343 const IPosition& trc,
00344 const IPosition& inc,
00345 Int row,
00346 Int nrow,
00347 Int incr);
00348 void getColumnSliceVH (const String& columnName,
00349 Int row,
00350 Int nrow,
00351 Int incr,
00352 const Vector<Int>& blc,
00353 const Vector<Int>& trc,
00354 const Vector<Int>& inc,
00355 const ValueHolder& vh);
00356 void getColumnSliceVHIP (const String& columnName,
00357 const IPosition& blc,
00358 const IPosition& trc,
00359 const IPosition& inc,
00360 Int row,
00361 Int nrow,
00362 Int incr,
00363 const ValueHolder& vh);
00364
00365
00366
00367
00368
00369
00370
00371 void putColumn (const String& columnName,
00372 Int row,
00373 Int nrow,
00374 Int incr,
00375 const ValueHolder&);
00376 void putVarColumn (const String& columnName,
00377 Int row,
00378 Int nrow,
00379 Int incr,
00380 const Record& values);
00381
00382
00383
00384
00385 void putColumnSlice (const String& columnName,
00386 Int row,
00387 Int nrow,
00388 Int incr,
00389 const Vector<Int>& blc,
00390 const Vector<Int>& trc,
00391 const Vector<Int>& inc,
00392 const ValueHolder&);
00393 void putColumnSliceIP (const String& columnName,
00394 const ValueHolder&,
00395 const IPosition& blc,
00396 const IPosition& trc,
00397 const IPosition& inc,
00398 Int row,
00399 Int nrow,
00400 Int incr);
00401
00402
00403
00404
00405 Bool cellContentsDefined (const String& columnName,
00406 Int rownr);
00407
00408
00409 ValueHolder getCell (const String& columnName,
00410 Int row);
00411 void getCellVH (const String& columnName,
00412 Int row, const ValueHolder& vh);
00413
00414
00415
00416
00417 ValueHolder getCellSlice (const String& columnName,
00418 Int row,
00419 const Vector<Int>& blc,
00420 const Vector<Int>& trc,
00421 const Vector<Int>& inc);
00422 ValueHolder getCellSliceIP (const String& columnName,
00423 Int row,
00424 const IPosition& blc,
00425 const IPosition& trc,
00426 const IPosition& inc);
00427 void getCellSliceVH (const String& columnName,
00428 Int row,
00429 const Vector<Int>& blc,
00430 const Vector<Int>& trc,
00431 const Vector<Int>& inc,
00432 const ValueHolder& vh);
00433 void getCellSliceVHIP (const String& columnName,
00434 Int row,
00435 const IPosition& blc,
00436 const IPosition& trc,
00437 const IPosition& inc,
00438 const ValueHolder& vh);
00439
00440
00441
00442 void putCell (const String& columnName,
00443 const Vector<Int>& rownrs,
00444 const ValueHolder&);
00445
00446
00447
00448
00449 void putCellSlice (const String& columnName,
00450 Int row,
00451 const Vector<Int>& blc,
00452 const Vector<Int>& trc,
00453 const Vector<Int>& inc,
00454 const ValueHolder&);
00455 void putCellSliceIP (const String& columnName,
00456 Int row,
00457 const ValueHolder&,
00458 const IPosition& blc,
00459 const IPosition& trc,
00460 const IPosition& inc);
00461
00462
00463
00464
00465
00466 Vector<String> getColumnShapeString (const String& columnName,
00467 Int rownr,
00468 Int nrow,
00469 Int incr,
00470 Bool cOrder = False);
00471
00472
00473
00474
00475 ValueHolder getKeyword (const String& columnName,
00476 const String& keywordName,
00477 Int keywordIndex);
00478
00479
00480
00481 Record getKeywordSet (const String& columnName);
00482
00483
00484
00485
00486
00487
00488 void putKeyword (const String& columnName,
00489 const String& keywordName,
00490 Int keywordIndex,
00491 Bool makeSubRecord,
00492 const ValueHolder&);
00493
00494
00495
00496
00497
00498
00499 void putKeywordSet (const String& columnName,
00500 const Record& valueSet);
00501
00502
00503
00504 void removeKeyword (const String& columnName,
00505 const String& keywordName,
00506 Int keywordIndex);
00507
00508
00509
00510
00511
00512
00513 Vector<String> getFieldNames (const String& columnName,
00514 const String& keywordName,
00515 Int keywordIndex);
00516
00517
00518 String tableName();
00519
00520
00521 Vector<String> getPartNames (Bool recursive);
00522
00523
00524 Int ncolumns();
00525
00526
00527 Int nrows();
00528
00529
00530 Vector<Int> shape();
00531
00532
00533 Vector<Int> rowNumbers (TableProxy& other);
00534
00535
00536 Vector<String> columnNames();
00537
00538
00539 Bool isScalarColumn (const String& columnName);
00540
00541
00542
00543
00544 String columnDataType (const String& columnName);
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555 String columnArrayType (const String& columnName);
00556
00557
00558 Record getDataManagerInfo();
00559
00560
00561 Record getProperties (const String& name, Bool byColumn);
00562
00563
00564 void setProperties (const String& name, Bool byColumn,
00565 const Record& properties);
00566
00567
00568
00569 Record getTableDescription (Bool actual,
00570 Bool cOrder=False);
00571
00572
00573
00574 Record getColumnDescription (const String& columnName,
00575 Bool actual,
00576 Bool cOrder=False);
00577
00578
00579 String getAsciiFormat() const;
00580
00581
00582 Record getCalcResult() const;
00583
00584
00585 String showStructure (Bool showDataMan=True, Bool showColumns=True,
00586 Bool showSubTables=False, Bool sortColumns=False) const;
00587
00588
00589
00590 Table& table()
00591 { return table_p; }
00592 const Table& table() const
00593 { return table_p; }
00594
00595
00596
00597
00598
00599
00600
00601 static Record getKeyValues (const TableRecord& keySet);
00602 static void putKeyValues (TableRecord& keySet, const Record& valueSet);
00603
00604
00605
00606 private:
00607
00608
00609 static TableLock makeLockOptions (const Record& options);
00610
00611
00612
00613 static Table::EndianFormat makeEndianFormat (const String& endianFormat);
00614
00615
00616 static Bool makeHC (const Record& gdesc, TableDesc& tabdesc,
00617 String& message);
00618
00619
00620 Bool getColInfo (const String& colName, Bool useBrackets,
00621 String& type, String& message);
00622
00623
00624
00625 void printValueHolder (const ValueHolder& vh, ostream& os,
00626 const String& sep, Int prec, Bool useBrackets) const;
00627 template<typename T>
00628 void printArray (const Array<T>& arr, ostream& os,
00629 const String& sep) const;
00630 void printArrayValue (ostream& os, Bool v, const String&) const
00631 {os << v;}
00632 void printArrayValue (ostream& os, Int v, const String&) const
00633 {os << v;}
00634 void printArrayValue (ostream& os, Int64 v, const String&) const
00635 {os << v;}
00636 void printArrayValue (ostream& os, Double v, const String&) const
00637 {os << v;}
00638 void printArrayValue (ostream& os, const DComplex& v, const String&) const
00639 {os << v;}
00640 void printArrayValue (ostream& os, const String& v, const String&) const
00641 {os << '"' << v << '"';}
00642
00643
00644
00645
00646 Int64 getRowsCheck (const String& columnName,
00647 Int64 row, Int64 nrow, Int64 incr,
00648 const String& caller);
00649
00650
00651
00652
00653 Int64 getRowsSliceCheck (Slicer& slicer,
00654 const String& columnName,
00655 Int64 row, Int64 nrow, Int64 incr,
00656 const IPosition& blc,
00657 const IPosition& trc,
00658 const IPosition& inc,
00659 const String& caller);
00660
00661
00662
00663 Int checkRowColumn (Table& table,
00664 const String& colName,
00665 Int64 rownr, Int64 nrow, Int64 incr,
00666 const String& caller);
00667
00668
00669
00670 ValueHolder getValueFromTable (const String& colName,
00671 Int rownr, Int nrow, Int incr,
00672 Bool isCell);
00673 void getValueFromTable (const String& colName,
00674 Int rownr, Int nrow, Int incr,
00675 Bool isCell, const ValueHolder& vh);
00676
00677
00678
00679 ValueHolder getValueSliceFromTable(const String& colName,
00680 const Slicer& slicer,
00681 Int rownr, Int nrow, Int incr,
00682 Bool isCell);
00683 void getValueSliceFromTable(const String& colName,
00684 const Slicer& slicer,
00685 Int rownr, Int nrow, Int incr,
00686 Bool isCell, const ValueHolder& vh);
00687
00688
00689
00690 void putValueInTable (const String& colName,
00691 Int rownr, Int nrow, Int incr,
00692 Bool isCell, const ValueHolder&);
00693
00694
00695
00696 void putValueSliceInTable (const String& colName,
00697 const Slicer& slicer,
00698 Int rownr, Int nrow, Int incr,
00699 Bool isCell, const ValueHolder&);
00700
00701
00702
00703
00704
00705
00706
00707
00708 void findKeyId (RecordFieldId& fieldid,
00709 const TableRecord*& keySet,
00710 const String& keyname,
00711 const String& column);
00712 void findKeyId (RecordFieldId& fieldid,
00713 TableRecord*& keySet,
00714 const String& keyname,
00715 const String& column,
00716 Bool mustExist, Bool change, Bool makeSubRecord);
00717
00718
00719
00720 static ValueHolder getKeyValue (const TableRecord& keySet,
00721 const RecordFieldId& fieldId);
00722
00723
00724 static void putKeyValue (TableRecord& keySet,
00725 const RecordFieldId& fieldId,
00726 const ValueHolder& value);
00727
00728
00729
00730
00731
00732 static Bool makeTableDesc (const Record& gdesc, TableDesc& tabdesc,
00733 String& message);
00734
00735
00736
00737 static Bool addArrayColumnDesc (TableDesc& tableDesc,
00738 const String& valueType,
00739 const String& columnName,
00740 const String& comment,
00741 const String& dataManagerType,
00742 const String& dataManagerGroup,
00743 int options,
00744 Int ndim, const Vector<Int>& shape,
00745 Bool cOrder,
00746 String& message);
00747
00748
00749 static Record recordColumnDesc (const ColumnDesc&, Bool cOrder);
00750
00751
00752 static Record recordHCDesc (const TableDesc& tableDesc);
00753
00754
00755
00756 void setDefaultForSlicer (IPosition& vec) const;
00757
00758
00759
00760 static void calcValues (Record& rec, const TableExprNode& expr);
00761
00762
00763
00764 void syncTable (Table& table);
00765
00766
00767 static String getTypeStr (DataType);
00768
00769
00770 static IPosition fillAxes (const IPosition&, Bool cOrder);
00771
00772
00773
00774 static void stillSameShape (Int& same, IPosition& shape,
00775 const IPosition& newShape);
00776
00777
00778
00779 template<typename T>
00780 static Array<T> record2Array (const Record& rec)
00781 {
00782 if (rec.empty()) {
00783 return Array<T>();
00784 }
00785 Array<T> tmp;
00786 rec.get (0, tmp);
00787 IPosition shp(tmp.shape());
00788 shp.append (IPosition(1, rec.size()));
00789 Array<T> arr(shp);
00790 ArrayIterator<T> iter(arr, tmp.ndim());
00791 for (uInt i=0; i<rec.size(); ++i, iter.next()) {
00792 rec.get (i, iter.array());
00793 }
00794 return arr;
00795 }
00796
00797
00798
00799 Table table_p;
00800 String asciiFormat_p;
00801 Record calcResult_p;
00802 };
00803
00804 }
00805
00806 #endif