/usr/include/casacore/images/Images/PagedImage.tcc is in casacore-dev 2.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | //# PagedImage.cc: defines the PagedImage class
//# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2003
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
//# $Id$
#ifndef IMAGES_PAGEDIMAGE_TCC
#define IMAGES_PAGEDIMAGE_TCC
#include <casacore/images/Images/PagedImage.h>
#include <casacore/images/Regions/ImageRegion.h>
#include <casacore/images/Regions/RegionHandlerTable.h>
#include <casacore/images/Images/ImageInfo.h>
#include <casacore/lattices/Lattices/ArrayLattice.h>
#include <casacore/lattices/Lattices/LatticeNavigator.h>
#include <casacore/lattices/Lattices/LatticeStepper.h>
#include <casacore/lattices/Lattices/LatticeIterator.h>
#include <casacore/lattices/Lattices/PagedArrIter.h>
#include <casacore/lattices/LEL/LatticeExprNode.h>
#include <casacore/lattices/LEL/LatticeExpr.h>
#include <casacore/lattices/LRegions/LatticeRegion.h>
#include <casacore/casa/Logging/LogIO.h>
#include <casacore/casa/Logging/LogMessage.h>
#include <casacore/casa/Arrays/Array.h>
#include <casacore/casa/Arrays/ArrayMath.h>
#include <casacore/casa/Arrays/ArrayLogical.h>
#include <casacore/casa/Arrays/LogiArray.h>
#include <casacore/casa/Exceptions/Error.h>
#include <casacore/casa/OS/File.h>
#include <casacore/casa/OS/Path.h>
#include <casacore/casa/Arrays/IPosition.h>
#include <casacore/casa/Arrays/Slicer.h>
#include <casacore/tables/Tables/SetupNewTab.h>
#include <casacore/tables/Tables/TableLock.h>
#include <casacore/tables/Tables/Table.h>
#include <casacore/tables/Tables/TableDesc.h>
#include <casacore/tables/Tables/TableRecord.h>
#include <casacore/tables/Tables/TableInfo.h>
#include <casacore/tables/Tables/TableColumn.h>
#include <casacore/casa/BasicSL/String.h>
#include <casacore/casa/Utilities/Assert.h>
#include <casacore/casa/Quanta/UnitMap.h>
#include <casacore/casa/iostream.h>
#include <casacore/casa/sstream.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
template <class T>
PagedImage<T>::PagedImage (const TiledShape& shape,
const CoordinateSystem& coordinateInfo,
Table& table, uInt rowNumber)
: ImageInterface<T>(RegionHandlerTable(getTable, this)),
map_p (shape, table, "map", rowNumber),
regionPtr_p (0)
{
attach_logtable();
AlwaysAssert(setCoordinateInfo(coordinateInfo), AipsError);
setTableType();
}
template <class T>
PagedImage<T>::PagedImage (const TiledShape& shape,
const CoordinateSystem& coordinateInfo,
const String& filename,
TableLock::LockOption lockMode,
uInt rowNumber)
: ImageInterface<T>(RegionHandlerTable(getTable, this)),
regionPtr_p (0)
{
makePagedImage (shape, coordinateInfo, filename,
TableLock(lockMode), rowNumber);
}
template <class T>
PagedImage<T>::PagedImage (const TiledShape& shape,
const CoordinateSystem& coordinateInfo,
const String& filename,
const TableLock& lockOptions,
uInt rowNumber)
: ImageInterface<T>(RegionHandlerTable(getTable, this)),
regionPtr_p (0)
{
makePagedImage (shape, coordinateInfo, filename, lockOptions, rowNumber);
}
template <class T>
void PagedImage<T>::makePagedImage (const TiledShape& shape,
const CoordinateSystem& coordinateInfo,
const String& filename,
const TableLock& lockOptions,
uInt rowNumber)
{
SetupNewTable newtab (filename, TableDesc(), Table::New);
Table tab(newtab, lockOptions);
map_p = PagedArray<T> (shape, tab, "map", rowNumber);
attach_logtable();
AlwaysAssert(setCoordinateInfo(coordinateInfo), AipsError);
setTableType();
}
template <class T>
PagedImage<T>::PagedImage (const TiledShape& shape,
const CoordinateSystem& coordinateInfo,
const String& filename,
uInt rowNumber)
: ImageInterface<T>(RegionHandlerTable(getTable, this)),
regionPtr_p (0)
{
SetupNewTable newtab (filename, TableDesc(), Table::New);
Table tab(newtab);
map_p = PagedArray<T> (shape, tab, "map", rowNumber);
attach_logtable();
AlwaysAssert(setCoordinateInfo(coordinateInfo), AipsError);
setTableType();
}
template <class T>
PagedImage<T>::PagedImage (Table& table, MaskSpecifier spec, uInt rowNumber)
: ImageInterface<T>(RegionHandlerTable(getTable, this)),
map_p (table, "map", rowNumber),
regionPtr_p (0)
{
attach_logtable();
restoreAll (table.keywordSet());
applyMaskSpecifier (spec);
}
template <class T>
PagedImage<T>::PagedImage (const String& filename, MaskSpecifier spec,
uInt rowNumber)
: ImageInterface<T>(RegionHandlerTable(getTable, this)),
regionPtr_p (0)
{
Table tab(filename);
map_p = PagedArray<T>(tab, "map", rowNumber);
attach_logtable();
restoreAll (tab.keywordSet());
applyMaskSpecifier (spec);
}
template <class T>
PagedImage<T>::PagedImage (const String& filename,
const TableLock& lockOptions,
MaskSpecifier spec, uInt rowNumber)
: ImageInterface<T>(RegionHandlerTable(getTable, this)),
regionPtr_p (0)
{
makePagedImage (filename, lockOptions, spec, rowNumber);
}
template <class T>
PagedImage<T>::PagedImage (const String& filename,
TableLock::LockOption lockMode,
MaskSpecifier spec, uInt rowNumber)
: ImageInterface<T>(RegionHandlerTable(getTable, this)),
regionPtr_p (0)
{
makePagedImage (filename, TableLock(lockMode), spec, rowNumber);
}
template <class T>
void PagedImage<T>::makePagedImage (const String& filename,
const TableLock& lockOptions,
const MaskSpecifier& spec,
uInt rowNumber)
{
Table tab(filename, lockOptions);
map_p = PagedArray<T>(tab, "map", rowNumber);
attach_logtable();
restoreAll (tab.keywordSet());
applyMaskSpecifier (spec);
}
template <class T>
PagedImage<T>::PagedImage (const PagedImage<T>& other)
: ImageInterface<T>(other),
map_p (other.map_p),
regionPtr_p (0)
{
if (other.regionPtr_p != 0) {
regionPtr_p = new LatticeRegion (*other.regionPtr_p);
}
}
template <class T>
PagedImage<T>::~PagedImage()
{
// Close the logger here in case the image table is going to be deleted.
delete regionPtr_p;
logger().tempClose();
}
template <class T>
PagedImage<T>& PagedImage<T>::operator=(const PagedImage<T>& other)
{
if (this != &other) {
ImageInterface<T>::operator= (other);
map_p = other.map_p;
delete regionPtr_p;
regionPtr_p = 0;
if (other.regionPtr_p != 0) {
regionPtr_p = new LatticeRegion (*other.regionPtr_p);
}
}
return *this;
}
template <class T>
ImageInterface<T>* PagedImage<T>::cloneII() const
{
return new PagedImage<T> (*this);
}
template <class T>
void PagedImage<T>::restoreAll (const TableRecord& rec)
{
// Restore the coordinates.
CoordinateSystem* restoredCoords = CoordinateSystem::restore(rec, "coords");
AlwaysAssert(restoredCoords != 0, AipsError);
setCoordsMember (*restoredCoords);
delete restoredCoords;
// Restore the image info.
restoreImageInfo (rec);
// Restore the units.
restoreUnits (rec);
// Restore the miscinfo.
restoreMiscInfo (rec);
}
template<class T>
String PagedImage<T>::imageType() const
{
return className();
}
template<class T>
Bool PagedImage<T>::isPersistent() const
{
return True;
}
template<class T>
Bool PagedImage<T>::isPaged() const
{
return True;
}
template <class T>
Bool PagedImage<T>::isWritable() const
{
return map_p.isWritable();
}
template<class T>
void PagedImage<T>::reopenRW()
{
//# First reopen if needed.
map_p.reopen();
//# Open for write if not done yet and if writable.
if (!table().isWritable() && isWritable()) {
table().reopenRW();
}
}
template<class T>
Bool PagedImage<T>::hasPixelMask() const
{
return (regionPtr_p != 0 && regionPtr_p->hasMask());
}
template<class T>
const Lattice<Bool>& PagedImage<T>::pixelMask() const
{
if (regionPtr_p == 0) {
throw (AipsError ("PagedImage::pixelMask - no pixelmask used"));
}
return *regionPtr_p;
}
template<class T>
Lattice<Bool>& PagedImage<T>::pixelMask()
{
if (regionPtr_p == 0) {
throw (AipsError ("PagedImage::pixelMask - no pixelmask used"));
}
return *regionPtr_p;
}
template<class T>
const LatticeRegion* PagedImage<T>::getRegionPtr() const
{
return regionPtr_p;
}
template<class T>
void PagedImage<T>::setDefaultMask (const String& regionName)
{
// Reopen for write when needed and possible.
reopenRW();
// Use the new region as the image's mask.
applyMask (regionName);
// Store the new default name.
ImageInterface<T>::setDefaultMask (regionName);
}
template <class T>
void PagedImage<T>::useMask (MaskSpecifier spec)
{
applyMaskSpecifier (spec);
}
template<class T>
void PagedImage<T>::applyMaskSpecifier (const MaskSpecifier& spec)
{
// Use default mask if told to do so.
// If it does not exist, use no mask.
String name = spec.name();
if (spec.useDefault()) {
name = getDefaultMask();
if (! hasRegion (name, RegionHandler::Masks)) {
name = String();
}
}
applyMask (name);
}
template<class T>
void PagedImage<T>::applyMask (const String& maskName)
{
// No region if no mask name is given.
if (maskName.empty()) {
delete regionPtr_p;
regionPtr_p = 0;
return;
}
// Reconstruct the ImageRegion object.
// Turn the region into lattice coordinates.
ImageRegion* regPtr = getImageRegionPtr (maskName, RegionHandler::Masks);
LatticeRegion* latReg = new LatticeRegion
(regPtr->toLatticeRegion (coordinates(), shape()));
delete regPtr;
// The mask has to cover the entire image.
if (latReg->shape() != shape()) {
delete latReg;
throw (AipsError ("PagedImage::setDefaultMask - region " + maskName +
" does not cover the full image"));
}
// Replace current by new mask.
delete regionPtr_p;
regionPtr_p = latReg;
}
template <class T>
void PagedImage<T>::rename (const String& newName)
{
table().rename (newName, Table::New);
}
template <class T>
String PagedImage<T>::name (Bool stripPath) const
{
return map_p.name (stripPath);
}
template <class T>
uInt PagedImage<T>::rowNumber() const
{
return map_p.rowNumber();
}
template <class T>
IPosition PagedImage<T>::shape() const
{
return map_p.shape();
}
template<class T>
void PagedImage<T>::resize (const TiledShape& newShape)
{
if (newShape.shape().nelements() != coordinates().nPixelAxes()) {
throw(AipsError("PagedImage<T>::resize: coordinate info is "
"the incorrect shape."));
}
map_p.resize (newShape);
}
template <class T>
Bool PagedImage<T>::setCoordinateInfo (const CoordinateSystem& coords)
{
Bool ok = ImageInterface<T>::setCoordinateInfo(coords);
if (ok) {
reopenRW();
Table& tab = table();
if (tab.isWritable()) {
// Update the coordinates
if (tab.keywordSet().isDefined("coords")) {
tab.rwKeywordSet().removeField("coords");
}
if (!(coordinates().save(tab.rwKeywordSet(), "coords"))) {
LogIO os;
os << LogIO::SEVERE << "Error saving coordinates in image " << name()
<< LogIO::POST;
ok = False;
}
} else {
LogIO os;
os << LogIO::SEVERE << "Image " << name()
<< " is not writable; not saving coordinates"
<< LogIO::POST;
}
}
return ok;
}
template <class T>
Bool PagedImage<T>::doGetSlice(Array<T>& buffer, const Slicer& theSlice)
{
return map_p.doGetSlice(buffer, theSlice);
}
template <class T>
void PagedImage<T>::doPutSlice(const Array<T>& sourceBuffer,
const IPosition& where,
const IPosition& stride)
{
// if (throughmask_p || !mask_p) {
map_p.putSlice(sourceBuffer,where,stride);
// } else if (mask_p) {
// Array<T> map;
//Array<Bool> mask;
//IPosition shape(sourceBuffer.shape());
//mask_p->getSlice(mask, where, shape, stride, True);
//map_p.getSlice(map, where, shape, stride, True);
// use maskedarrays to do all the work.
//map(mask==False) = sourceBuffer;
//map_p.putSlice(map,where,stride);
// } else {
// throw(AipsError("PagedImage<T>::putSlice - throughmask==False but no "
// "mask exists."));
// }
}
// apply a function to all elements of the map
template <class T>
void PagedImage<T>::apply(T (*function)(T))
{
map_p.apply(function);
}
// apply a function to all elements of a const map;
template <class T>
void PagedImage<T>::apply(T (*function)(const T&))
{
map_p.apply(function);
}
template <class T>
void PagedImage<T>::apply(const Functional<T,T>& function)
{
map_p.apply(function);
}
template <class T>
T PagedImage<T>::getAt(const IPosition& where) const
{
return map_p(where);
}
template <class T>
void PagedImage<T>::putAt(const T& value, const IPosition& where) {
map_p.putAt (value, where);
}
template<class T>
void PagedImage<T>::restoreMiscInfo (const TableRecord& rec)
{
if (rec.isDefined("miscinfo") &&
rec.dataType("miscinfo") == TpRecord) {
setMiscInfoMember (rec.asRecord ("miscinfo"));
}
}
template<class T>
Bool PagedImage<T>::setMiscInfo (const RecordInterface& newInfo)
{
setMiscInfoMember (newInfo);
reopenRW();
Table& tab = table();
if (! tab.isWritable()) {
return False;
}
if (tab.keywordSet().isDefined("miscinfo")) {
tab.rwKeywordSet().removeField("miscinfo");
}
tab.rwKeywordSet().defineRecord("miscinfo", newInfo);
return True;
}
template <class T>
LatticeIterInterface<T>* PagedImage<T>::makeIter
(const LatticeNavigator& navigator,
Bool useRef) const
{
return map_p.makeIter (navigator, useRef);
}
template <class T>
Bool PagedImage<T>::ok() const
{
Int okay = (map_p.ndim() == coordinates().nPixelAxes());
return okay ? True : False;
}
template <class T>
PagedImage<T>& PagedImage<T>::operator+= (const Lattice<T>& other)
{
check_conformance(other);
// Use LEL, so a mask is also handled.
LatticeExpr<T> expr(*this + other);
this->copyData (expr);
return *this;
}
template<class T>
void PagedImage<T>::attach_logtable()
{
open_logtable();
}
template<class T>
void PagedImage<T>::open_logtable()
{
// Open logtable as readonly if main table is not writable.
Table& tab = table();
setLogMember (LoggerHolder (name() + "/logtable", tab.isWritable()));
// Insert the keyword if possible and if it does not exist yet.
if (tab.isWritable() && ! tab.keywordSet().isDefined ("logtable")) {
tab.rwKeywordSet().defineTable("logtable", Table(name() + "/logtable"));
}
}
template<class T>
Bool PagedImage<T>::setUnits(const Unit& newUnits)
{
setUnitMember (newUnits);
reopenRW();
Table& tab = table();
if (! tab.isWritable()) {
return False;
}
if (tab.keywordSet().isDefined("units")) {
tab.rwKeywordSet().removeField("units");
}
tab.rwKeywordSet().define("units", newUnits.getName());
return True;
}
template<class T>
void PagedImage<T>::restoreUnits (const TableRecord& rec)
{
Unit retval;
String unitName;
if (rec.isDefined("units")) {
if (rec.dataType("units") != TpString) {
LogIO os;
os << LogOrigin("PagedImage<T>", "units()", WHERE)
<< "'units' keyword in image table is not a string! Units not restored."
<< LogIO::SEVERE << LogIO::POST;
} else {
rec.get("units", unitName);
}
}
if (! unitName.empty()) {
// OK, non-empty unit, see if it's valid, if not try some known things to
// make a valid unit out of it.
if (! UnitVal::check(unitName)) {
// Beam and Pixel are the most common undefined units
UnitMap::putUser("Pixel",UnitVal(1.0),"Pixel unit");
UnitMap::putUser("Beam",UnitVal(1.0),"Beam area");
}
if (! UnitVal::check(unitName)) {
// OK, maybe we need FITS
UnitMap::addFITS();
}
if (!UnitVal::check(unitName)) {
// I give up!
LogIO os;
UnitMap::putUser(unitName, UnitVal(1.0, UnitDim::Dnon), unitName);
os << LogIO::WARN << "FITS unit \"" << unitName
<< "\" unknown to CASA - will treat it as non-dimensional."
<< LogIO::POST;
retval.setName(unitName);
retval.setValue(UnitVal(1.0, UnitDim::Dnon));
} else {
retval = Unit(unitName);
}
}
setUnitMember (retval);
}
template<class T>
void PagedImage<T>::removeRegion (const String& name,
RegionHandler::GroupType type,
Bool throwIfUnknown)
{
reopenRW();
// Remove the default mask if it is the region to be removed.
if (name == getDefaultMask()) {
setDefaultMask (String());
}
ImageInterface<T>::removeRegion (name, type, throwIfUnknown);
}
template<class T>
void PagedImage<T>::check_conformance(const Lattice<T>& other)
{
if (! this->conform(other)) {
throw AipsError("Shapes of image " + name() + " and other lattice do not conform");
}
}
template<class T>
uInt PagedImage<T>::maximumCacheSize() const
{
return map_p.maximumCacheSize();
}
template<class T>
void PagedImage<T>::setMaximumCacheSize(uInt howManyPixels)
{
map_p.setMaximumCacheSize(howManyPixels);
if (regionPtr_p != 0) {
regionPtr_p->setMaximumCacheSize(howManyPixels);
}
}
template<class T>
void PagedImage<T>::setCacheSizeFromPath(const IPosition& sliceShape,
const IPosition& windowStart,
const IPosition& windowLength,
const IPosition& axisPath)
{
map_p.setCacheSizeFromPath(sliceShape, windowStart, windowLength, axisPath);
if (regionPtr_p != 0) {
regionPtr_p->setCacheSizeFromPath(sliceShape, windowStart,
windowLength, axisPath);
}
}
template<class T>
void PagedImage<T>::setCacheSizeInTiles (uInt howManyTiles)
{
map_p.setCacheSizeInTiles (howManyTiles);
if (regionPtr_p != 0) {
regionPtr_p->setCacheSizeInTiles (howManyTiles);
}
}
template<class T>
void PagedImage<T>::clearCache()
{
map_p.clearCache();
if (regionPtr_p != 0) {
regionPtr_p->clearCache();
}
}
template<class T>
void PagedImage<T>::showCacheStatistics(ostream& os) const
{
os << "Pixel statistics : ";
map_p.showCacheStatistics(os);
if (regionPtr_p != 0) {
os << "Pixelmask statistics : ";
regionPtr_p->showCacheStatistics(os);
}
}
template<class T>
uInt PagedImage<T>::advisedMaxPixels() const
{
return map_p.advisedMaxPixels();
}
template<class T>
IPosition PagedImage<T>::doNiceCursorShape(uInt maxPixels) const
{
return map_p.niceCursorShape(maxPixels);
}
template<class T>
void PagedImage<T>::setTableType()
{
TableInfo& info(table().tableInfo());
const String reqdType = info.type(TableInfo::PAGEDIMAGE);
if (info.type() != reqdType) {
info.setType(reqdType);
}
const String reqdSubType = info.subType(TableInfo::PAGEDIMAGE);
if (info.subType() != reqdSubType) {
info.setSubType(reqdSubType);
}
}
template<class T>
Table& PagedImage<T>::getTable (void* imagePtr, Bool writable)
{
PagedImage<T>* im = static_cast<PagedImage<T>*>(imagePtr);
if (writable) {
im->reopenRW();
}
return im->map_p.table();
}
template<class T>
Bool PagedImage<T>::lock (FileLocker::LockType type, uInt nattempts)
{
return map_p.lock (type, nattempts);
}
template<class T>
void PagedImage<T>::unlock()
{
map_p.unlock();
logger().unlock();
if (regionPtr_p != 0) {
regionPtr_p->unlock();
}
}
template<class T>
Bool PagedImage<T>::hasLock (FileLocker::LockType type) const
{
return map_p.hasLock (type);
}
template<class T>
void PagedImage<T>::resync()
{
map_p.resync();
logger().resync();
if (regionPtr_p != 0
&& !regionPtr_p->hasLock (FileLocker::Read)) {
regionPtr_p->resync();
}
}
template<class T>
void PagedImage<T>::flush()
{
itsAttrHandler.flush();
map_p.flush();
logger().flush();
if (regionPtr_p != 0) {
regionPtr_p->flush();
}
}
template<class T>
void PagedImage<T>::tempClose()
{
map_p.tempClose();
logger().tempClose();
if (regionPtr_p != 0) {
regionPtr_p->tempClose();
}
}
template<class T>
void PagedImage<T>::reopen()
{
map_p.reopen();
if (regionPtr_p != 0) {
regionPtr_p->reopen();
}
}
template<class T>
Bool PagedImage<T>::setImageInfo (const ImageInfo& info)
{
// Set imageinfo in base class.
Bool ok = ImageInterface<T>::setImageInfo(info);
if (ok) {
// Make persistent in table keywords.
reopenRW();
Table& tab = table();
if (tab.isWritable()) {
// Delete existing one if there.
if (tab.keywordSet().isDefined("imageinfo")) {
tab.rwKeywordSet().removeField("imageinfo");
}
// Convert info to a record and save as keyword.
TableRecord rec;
String error;
if (imageInfo().toRecord(error, rec)) {
tab.rwKeywordSet().defineRecord("imageinfo", rec);
} else {
// Could not convert to record.
LogIO os;
os << LogIO::SEVERE << "Error saving ImageInfo in image " << name()
<< "; " << error << LogIO::POST;
ok = False;
}
} else {
// Table not writable.
LogIO os;
os << LogIO::SEVERE
<< "Image " << name() << " is not writable; not saving ImageInfo"
<< LogIO::POST;
}
}
return ok;
}
template<class T>
void PagedImage<T>::restoreImageInfo (const TableRecord& rec)
{
if (rec.isDefined("imageinfo")) {
String error;
ImageInfo info;
Bool ok = info.fromRecord (error, rec.asRecord("imageinfo"));
if (ok) {
setImageInfoMember (info);
} else {
LogIO os;
os << LogIO::WARN << "Failed to restore the ImageInfo in image " << name()
<< "; " << error << LogIO::POST;
}
}
}
template<class T>
ImageAttrHandler& PagedImage<T>::attrHandler (Bool createHandler)
{
return itsAttrHandler.attachTable (table(), createHandler);
}
} //# NAMESPACE CASACORE - END
#endif
|