LCOV - code coverage report
Current view: top level - synthesis/MeasurementEquations - CCList.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 113 158 71.5 %
Date: 2025-07-23 00:22:00 Functions: 17 23 73.9 %

          Line data    Source code
       1             : //# CCList.cc:  implementation file for CCList
       2             : //# Copyright (C) 1996,1997,1998,1999
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //# $Id$
      27             : 
      28             : #include <synthesis/MeasurementEquations/CCList.h>
      29             : #include <casacore/casa/Arrays/Vector.h>
      30             : 
      31             : 
      32             : using namespace casacore;
      33             : namespace casa { //# NAMESPACE CASA - BEGIN
      34             : 
      35           0 : CCList::CCList()
      36           0 :   :itsPol(1),
      37           0 :    itsDim(2),
      38           0 :    itsComp(0),
      39           0 :    itsFlux(),
      40           0 :    itsPos(),
      41           0 :    itsSuspendOKCheck(false)
      42             : {
      43           0 :   DebugAssert(ok(), AipsError);
      44           0 : };
      45             : 
      46          20 : CCList::CCList(const uInt nPol, const uInt nDim, const uInt nComp)
      47          20 :   :itsPol(nPol),
      48          20 :    itsDim(nDim),
      49          20 :    itsComp(0),
      50          20 :    itsFlux(nPol*nComp),
      51          20 :    itsPos(nDim*nComp),
      52          20 :    itsSuspendOKCheck(false)
      53             : {
      54          20 :   DebugAssert(ok(), AipsError);
      55          20 : };
      56             : 
      57           0 : CCList::CCList(const CCList & other)
      58           0 :   :itsPol(other.itsPol),
      59           0 :    itsDim(other.itsDim),
      60           0 :    itsComp(other.itsComp),
      61           0 :    itsFlux(other.itsFlux),
      62           0 :    itsPos(other.itsPos),
      63           0 :    itsSuspendOKCheck(false)
      64             : {
      65           0 :   DebugAssert(ok(), AipsError);
      66           0 : };
      67             : 
      68          20 : CCList::~CCList() {
      69          20 :   DebugAssert(ok(), AipsError);
      70          20 : };
      71             : 
      72           0 : CCList & CCList::operator=(const CCList & other){
      73           0 :   if (this != &other) {
      74           0 :     itsPol = other.itsPol;
      75           0 :     itsDim = other.itsDim;
      76           0 :     itsComp = other.itsComp;
      77           0 :     itsFlux = other.itsFlux;
      78           0 :     itsPos = other.itsPos;
      79           0 :     itsSuspendOKCheck = other.itsSuspendOKCheck;
      80             :   }
      81           0 :   DebugAssert(ok(), AipsError);
      82           0 :   return *this;
      83             : };
      84             : 
      85          10 : Int * CCList::positionPtr() {
      86          10 :   DebugAssert(ok(), AipsError)
      87          10 :   return itsPos.storage();
      88             : };
      89             : 
      90           0 : const Int * CCList::positionPtr() const {
      91           0 :   DebugAssert(ok(), AipsError);
      92           0 :   return itsPos.storage();
      93             : };
      94             : 
      95          10 : Float * CCList::fluxPtr() {
      96          10 :   DebugAssert(ok(), AipsError);
      97          10 :   return itsFlux.storage();
      98             : };
      99             : 
     100          20 : const Float * CCList::fluxPtr() const {
     101          20 :   DebugAssert(ok(), AipsError);
     102          20 :   return itsFlux.storage();
     103             : };
     104             : 
     105          30 : Int * CCList::freePositionPtr() {
     106          30 :   DebugAssert(ok(), AipsError);
     107          30 :   return itsPos.storage() + nComp()*nDim();
     108             : };
     109             : 
     110           0 : const Int * CCList::freePositionPtr() const {
     111           0 :   DebugAssert(ok(), AipsError);
     112           0 :   return itsPos.storage() + nComp()*nDim();
     113             : };
     114             : 
     115          30 : Float * CCList::freeFluxPtr() {
     116          30 :   DebugAssert(ok(), AipsError);
     117          30 :   return itsFlux.storage() + nComp()*nPol();
     118             : };
     119             : 
     120           0 : const Float * CCList::freeFluxPtr() const {
     121           0 :   DebugAssert(ok(), AipsError);
     122           0 :   return itsFlux.storage() + nComp()*nPol();
     123             : };
     124             : 
     125          50 : uInt CCList::maxComp() const {
     126          50 :   DebugAssert(ok(), AipsError)
     127          50 :   return itsPos.nelements()/nDim();
     128             : };
     129             : 
     130          20 : uInt CCList::freeComp() const {
     131          20 :   DebugAssert(ok(), AipsError);
     132          20 :   return maxComp() - nComp();
     133             : };
     134             : 
     135          12 : void CCList::resize(const uInt newSize) {
     136          12 :   suspendOKCheck();
     137          12 :   Block<Int>  pr(itsPos);
     138          12 :   Block<Float> fr(itsFlux);
     139          12 :   itsPos.resize(nDim()*newSize);
     140          12 :   itsFlux.resize(nPol() * newSize);
     141          12 :   for (uInt i=0; i< nComp()*nDim(); i++) {
     142           0 :     itsPos[i] = pr[i];
     143             :   }
     144          12 :   for (uInt i=0; i< nComp()*nPol(); i++) {
     145           0 :     itsFlux[i] = fr[i];
     146             :   }
     147          12 :   reactivateOKCheck();
     148             : 
     149          12 :   DebugAssert(ok(), AipsError);
     150          12 : };
     151             : 
     152          10 : void CCList::addComp(const Block<Float> & flux, const Block<Int> & position) {
     153             : 
     154          10 :   if (nComp() >= maxComp() ) {
     155           2 :     resize(2*nComp()+1);
     156             :   }  
     157          10 :   Int * pos_p = freePositionPtr();
     158          10 :   Float * flux_p = freeFluxPtr();
     159          10 :   uInt n = flux.nelements();
     160          20 :   for (uInt i=0;i<n;i++) {
     161          10 :     *(flux_p+i) = flux[i];
     162             :   }
     163          10 :   *(pos_p) = position[0];
     164          10 :   *(pos_p+1) = position[1];
     165          10 :   nComp()++;
     166          10 : };
     167             : 
     168             : 
     169        1488 : Bool CCList::ok() const {
     170        1488 :   if (itsSuspendOKCheck) {
     171         112 :     return true;
     172             :   }
     173             :   // Be arbitary: disallow more than 4-D Clean Components
     174        1376 :   if ((itsDim < 1) || (itsDim > 4)) {  
     175           0 :     return false;
     176             :   }
     177        1376 :   if ((itsPol != 1) && (itsPol != 2) && (itsPol != 4)) {
     178           0 :     return false;
     179             :   }
     180        1376 :   if (itsComp*itsDim > itsPos.nelements()) {
     181           0 :     return false;
     182             :   }
     183        1376 :   if (itsComp*itsPol > itsFlux.nelements()) {
     184           0 :     return false;
     185             :   }
     186        1376 :   if (itsPos.nelements()/itsDim != itsFlux.nelements()/itsPol) {
     187           0 :     return false;
     188             :   }
     189        1376 :   return true;
     190             : };
     191             : 
     192         148 : Int * CCList::pixelPosition(const uInt whichPixel) {
     193         148 :   DebugAssert(whichPixel < nComp(), AipsError);
     194         148 :   DebugAssert(ok(), AipsError);
     195         148 :   return itsPos.storage() + whichPixel*nDim();
     196             : };
     197             : 
     198          10 : Float * CCList::pixelFlux(const uInt whichPixel) {
     199          10 :   DebugAssert(whichPixel < nComp(), AipsError);
     200          10 :   DebugAssert(ok(), AipsError);
     201          10 :   return itsFlux.storage() + whichPixel*nPol();
     202             : };
     203             : 
     204          10 : void  CCList::tiledSort(const IPosition & tileShape) {
     205          10 :   if (nComp() == 0) {
     206           0 :     return;
     207             :   }
     208          10 :   Vector<uInt> index(nComp());
     209          10 :   Block<Int> tileNumber(nComp());
     210          10 :   const Int tx = tileShape(0);
     211          10 :   const Int ty = tileShape(1);
     212             :   //  const Int tileArea = tx * tileShape(1);
     213             :   Int * posPtr;
     214             :   Int x, y;
     215             :   Int it, jt;
     216          20 :   for (uInt c = 0; c < nComp(); c++) {
     217          10 :     posPtr = pixelPosition(c);
     218          10 :     x = *posPtr;
     219          10 :     posPtr++;
     220          10 :     y = *posPtr;
     221             :     //    tileNumber[c] = (x + tx * y) % tileArea;   old algorithm
     222          10 :     it = (Int)(x/tx);
     223          10 :     jt = (Int)(y/ty);
     224          10 :     tileNumber[c] = jt*10000 + it;
     225             :   }
     226             : 
     227          10 :   AlwaysAssert(genSort(index, tileNumber) == nComp(), AipsError);
     228             : 
     229          10 :   Int * sortedPos = new Int[nDim()*nComp()];
     230          10 :   Float * sortedFlux = new Float[nPol()*nComp()];
     231             :   uInt whichElem, newElem;
     232          20 :   for (uInt c = 0; c < nComp(); c++) {
     233          10 :     whichElem = nDim()*index(c);
     234          10 :     newElem = nDim()*c;
     235          10 :     sortedPos[newElem] = itsPos[whichElem];
     236          10 :     whichElem++; newElem++;
     237          10 :     sortedPos[newElem] = itsPos[whichElem];
     238          10 :     whichElem = nPol()*index(c);
     239          10 :     newElem = nPol()*c;
     240          20 :     for (uInt k = 0; k < nPol(); k++) {
     241          10 :       sortedFlux[newElem] = itsFlux[whichElem];
     242          10 :       whichElem++; newElem++;
     243             :     }
     244             :   }
     245             : 
     246          10 :   suspendOKCheck();
     247          10 :   itsPos.replaceStorage((nDim()*nComp()), sortedPos);
     248          10 :   itsFlux.replaceStorage((nPol()*nComp()), sortedFlux);
     249          10 :   reactivateOKCheck();
     250          10 :   ok();
     251          10 : };
     252             : 
     253          22 : void CCList::suspendOKCheck() {
     254          22 :   itsSuspendOKCheck = true;
     255          22 : };
     256             : 
     257          22 : void CCList::reactivateOKCheck() {
     258          22 :   itsSuspendOKCheck = false;
     259          22 : };
     260             : 
     261             : 
     262             : } //# NAMESPACE CASA - END
     263             : 

Generated by: LCOV version 1.16