LCOV - code coverage report
Current view: top level - msvis/MSVis - VBRemapper.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 80 0.0 %
Date: 2024-11-06 17:42:47 Functions: 0 5 0.0 %

          Line data    Source code
       1             : //# VBRemapper.cc: implementation for VisBuffer remapping objects.
       2             : //# Copyright (C) 2011
       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             : 
      27             : #include <msvis/MSVis/VBRemapper.h>
      28             : #include <msvis/MSVis/VisBuffer.h>
      29             : #include <msvis/MSVis/VisBufferComponents.h>
      30             : #include <msvis/MSVis/VisibilityIterator.h>
      31             : #include <casacore/casa/Arrays/Vector.h>
      32             : #include <casacore/casa/Exceptions/Error.h>
      33             : #include <casacore/casa/Logging/LogIO.h>
      34             : #include <map>
      35             : 
      36             : using namespace casacore;
      37             : namespace casa {
      38             : 
      39           0 : VBRemapper::VBRemapper()// :
      40             :   //  inToOutMaps_p()
      41             : {
      42           0 : }
      43             : 
      44           0 : VBRemapper::VBRemapper(const std::map<VisBufferComponents::EnumType, std::map<Int, Int> >& inToOutMaps) :
      45           0 :   inToOutMaps_p(inToOutMaps)
      46             : {
      47           0 : }
      48             : 
      49             : // VBRemapper& VBRemapper::operator=(const VBRemapper &other)
      50             : // {
      51             : //   // trivial so far.
      52             : //   vi_p = other.vi_p;
      53             : //   return *this;
      54             : // }
      55             : 
      56           0 : Bool VBRemapper::remap(VisBuffer& vb, const Bool squawk) const
      57             : {
      58           0 :   LogIO os(LogOrigin("VBRemapper", "remap()"));
      59           0 :   Bool retval = true;
      60             : 
      61           0 :   for(std::map<VisBufferComponents::EnumType,
      62           0 :         std::map<Int, Int> >::const_iterator c = inToOutMaps_p.begin();
      63           0 :       c != inToOutMaps_p.end(); ++c){
      64           0 :     Bool colOK = true;
      65             : 
      66           0 :     switch(c->first){
      67           0 :     case VisBufferComponents::Ant1:
      68           0 :       colOK = remapVector(vb.antenna1(), c->second);
      69           0 :       break;
      70           0 :     case VisBufferComponents::Ant2:
      71           0 :       colOK = remapVector(vb.antenna2(), c->second);
      72           0 :       break;
      73           0 :     case VisBufferComponents::ArrayId:
      74           0 :       colOK = remapScalar(vb.arrayIdRef(), c->second);
      75           0 :       break;
      76           0 :     case VisBufferComponents::DataDescriptionId:
      77           0 :       colOK = remapScalar(vb.dataDescriptionIdRef(), c->second);
      78           0 :       break;
      79           0 :     case VisBufferComponents::Feed1:
      80           0 :       colOK = remapVector(vb.feed1(), c->second);
      81           0 :       break;
      82           0 :     case VisBufferComponents::Feed2:
      83           0 :       colOK = remapVector(vb.feed2(), c->second);
      84           0 :       break;
      85           0 :     case VisBufferComponents::FieldId:
      86           0 :       colOK = remapScalar(vb.fieldIdRef(), c->second);
      87           0 :       break;
      88           0 :     case VisBufferComponents::ObservationId:
      89           0 :       colOK = remapVector(vb.observationId(), c->second);
      90           0 :       break;
      91           0 :     case VisBufferComponents::ProcessorId:
      92           0 :       colOK = remapVector(vb.processorId(), c->second);
      93           0 :       break;
      94           0 :     case VisBufferComponents::Scan:
      95           0 :       colOK = remapVector(vb.scan(), c->second);
      96           0 :       break;
      97           0 :     case VisBufferComponents::SpW:
      98           0 :       colOK = remapScalar(vb.spectralWindow(), c->second);
      99           0 :       break;
     100           0 :     case VisBufferComponents::StateId:
     101           0 :       colOK = remapVector(vb.stateId(), c->second);
     102           0 :       break;
     103           0 :     default:
     104           0 :       if(squawk){
     105             :         os << LogIO::WARN
     106           0 :            << "Remapping " << asyncio::PrefetchColumns::columnName(c->first)
     107             :            << " is not supported."
     108           0 :            << LogIO::POST;
     109             :       }
     110             :       // Do NOT set colOK; it would repeat the message.
     111           0 :       retval = false;
     112             :     }
     113           0 :     if(!colOK){
     114           0 :       retval = false;
     115           0 :       if(squawk){
     116             :         os << LogIO::WARN
     117           0 :            << "Unrecognized value remapping " << asyncio::PrefetchColumns::columnName(c->first)
     118           0 :            << LogIO::POST;
     119             :       }
     120             :     }
     121             :   }
     122           0 :   return retval;
     123           0 : }
     124             : 
     125           0 : Bool VBRemapper::remapScalar(Int& colref, const std::map<Int, Int>& mapper) const
     126             : {
     127           0 :   Bool retval = true;
     128           0 :   const std::map<Int, Int>::const_iterator it(mapper.find(colref));
     129             : 
     130           0 :   if(it != mapper.end()){
     131           0 :     const Int middleman(it->second);
     132             : 
     133           0 :     colref = middleman;
     134             :   }
     135             :   else
     136           0 :     retval = false;
     137           0 :   return retval;
     138             : }
     139             : 
     140           0 : Bool VBRemapper::remapVector(Vector<Int>& col, const std::map<Int, Int>& mapper) const
     141             : {
     142           0 :   Bool retval = true;
     143             : 
     144           0 :   if(mapper.size() > 0){
     145           0 :     for(Int row = col.nelements(); row--;){
     146           0 :       const std::map<Int, Int>::const_iterator it(mapper.find(col[row]));
     147             : 
     148           0 :       if(it != mapper.end()){
     149           0 :         const Int middleman = it->second;
     150             : 
     151           0 :         col[row] = middleman;
     152             :       }
     153             :       else
     154           0 :         retval = false;
     155             :     }
     156             :   }
     157             :   else
     158           0 :     retval = false;
     159             : 
     160           0 :   return retval;
     161             : }
     162             : 
     163             : using namespace casacore;
     164             : } // end namespace casa

Generated by: LCOV version 1.16