LCOV - code coverage report
Current view: top level - msvis/MSVis - VWBT.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 63 0.0 %
Date: 2024-10-12 00:35:29 Functions: 0 9 0.0 %

          Line data    Source code
       1             : //# VWBT.h: This file contains the implementation of the VWBT class.
       2             : //#
       3             : //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
       4             : //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
       5             : //#  Copyright (C) European Southern Observatory, 2011, All rights reserved.
       6             : //#
       7             : //#  This library is free software; you can redistribute it and/or
       8             : //#  modify it under the terms of the GNU Lesser General Public
       9             : //#  License as published by the Free software Foundation; either
      10             : //#  version 2.1 of the License, or (at your option) any later version.
      11             : //#
      12             : //#  This library is distributed in the hope that it will be useful,
      13             : //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
      14             : //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             : //#  Lesser General Public License for more details.
      16             : //#
      17             : //#  You should have received a copy of the GNU Lesser General Public
      18             : //#  License along with this library; if not, write to the Free Software
      19             : //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      20             : //#  MA 02111-1307  USA
      21             : //# $Id: $
      22             : 
      23             : #include <msvis/MSVis/VWBT.h>
      24             : 
      25             : using namespace casacore;
      26             : namespace casa { //# NAMESPACE CASA - BEGIN
      27             : 
      28           0 : VWBT::VWBT(VisibilityIterator *visibilityIterator,
      29             :                    casa::async::Mutex * msAccessMutex,
      30           0 :            bool groupRows)
      31             : {
      32           0 :    visibilityIterator_p = visibilityIterator;
      33           0 :    msAccessMutex_p = msAccessMutex;
      34           0 :    groupRows_p = groupRows;
      35             : 
      36           0 :    terminationRequested_p = false;
      37           0 :    threadTerminated_p = false;
      38           0 :    writing_p = false;
      39             : 
      40           0 :    flagCube_p = NULL;
      41             : 
      42           0 :    initialize();
      43           0 : }
      44             : 
      45           0 : VWBT::~VWBT ()
      46             : {
      47           0 :         if (flagCube_p) delete flagCube_p;
      48           0 : }
      49             : 
      50             : void
      51           0 : VWBT::initialize()
      52             : {
      53             :         // Acquire lock
      54           0 :         msAccessMutex_p->acquirelock();
      55             : 
      56             :         // Initialize chunks
      57           0 :         visibilityIterator_p->originChunks();
      58             : 
      59             :         // Initialize first chunk
      60           0 :         if (groupRows_p)
      61             :         {
      62           0 :                 Int nRowChunk = visibilityIterator_p->nRowChunk();
      63           0 :                 visibilityIterator_p->setRowBlocking(nRowChunk);
      64             :         }
      65           0 :         visibilityIterator_p->origin();
      66             : 
      67             :         // Release lock
      68           0 :         msAccessMutex_p->unlock();
      69           0 : }
      70             : 
      71             : void *
      72           0 : VWBT::run ()
      73             : {
      74           0 :         while (!terminationRequested_p)
      75             :         {
      76           0 :                 if (writing_p)
      77             :                 {
      78             :                         // Acquire lock
      79           0 :                         msAccessMutex_p->acquirelock();
      80             : 
      81             :                         // Write flag cube
      82           0 :                         visibilityIterator_p->setFlag(*flagCube_p);
      83           0 :                         writing_p = false;
      84             : 
      85             :                         // Perform next iteration
      86           0 :                         bool moreBuffers = next();
      87             : 
      88             :                         // Release lock
      89           0 :                         msAccessMutex_p->unlock();
      90             : 
      91             :                         // Exit if there is no more data
      92           0 :                         if (!moreBuffers) break;
      93             :                 }
      94             :                 else
      95             :                 {
      96           0 :                         sched_yield();
      97             :                 }
      98             :         }
      99             : 
     100           0 :         threadTerminated_p = true;
     101             : 
     102           0 :         return NULL;
     103             : }
     104             : 
     105             : void
     106           0 : VWBT::start()
     107             : {
     108           0 :         casa::async::Thread::startThread();
     109             : 
     110           0 :         return;
     111             : }
     112             : 
     113             : void
     114           0 : VWBT::terminate ()
     115             : {
     116           0 :         terminationRequested_p = true;
     117           0 :         while (!threadTerminated_p)
     118             :         {
     119           0 :                 sched_yield();
     120             :         }
     121           0 :         casa::async::Thread::terminate();
     122             : 
     123           0 :         return;
     124             : }
     125             : 
     126             : bool
     127           0 : VWBT::next()
     128             : {
     129             :         // Check if we have more vis buffers in the current chunk
     130           0 :         (*visibilityIterator_p)++;
     131           0 :         if (visibilityIterator_p->more())
     132             :         {
     133           0 :                 return true;
     134             :         }
     135             :         // If there are not more buffers we go to the next chunk
     136             :         else
     137             :         {
     138           0 :                 visibilityIterator_p->nextChunk();
     139             : 
     140             :                 // If the new chunk is valid initialize it
     141           0 :                 if (visibilityIterator_p->moreChunks())
     142             :                 {
     143             :                         // Check if all the rows have to be loaded in a single vis buffer
     144           0 :                         if (groupRows_p)
     145             :                         {
     146           0 :                                 Int nRowChunk = visibilityIterator_p->nRowChunk();
     147           0 :                                 visibilityIterator_p->setRowBlocking(nRowChunk);
     148             :                         }
     149             :                         // Initialize sub-chunks (vis buffers)
     150           0 :                         visibilityIterator_p->origin();
     151           0 :                         return true;
     152             :                 }
     153             :                 else
     154             :                 {
     155           0 :                         return false;
     156             :                 }
     157             :         }
     158             : }
     159             : 
     160             : void
     161           0 : VWBT::setFlag(Cube<Bool> flagCube)
     162             : {
     163             :         // Wait until prev. flag cube is written
     164           0 :         while (writing_p)
     165             :         {
     166           0 :                 sched_yield();
     167             :         }
     168             : 
     169             :         // Delete prev. flag cube
     170           0 :         if (flagCube_p) delete flagCube_p;
     171             : 
     172             :         // Prepare next flag cube to be written
     173           0 :         flagCube_p = new Cube<Bool>(flagCube);
     174           0 :         writing_p = true;
     175             : 
     176           0 :         return;
     177             : }
     178             : 
     179             : 
     180             : } //# NAMESPACE CASA - END
     181             : 
     182             : 

Generated by: LCOV version 1.16