LCOV - code coverage report
Current view: top level - synthesis/Utilities - AppRC.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 68 0.0 %
Date: 2024-11-06 17:42:47 Functions: 0 11 0.0 %

          Line data    Source code
       1             : // -*- C++ -*-
       2             : //# AppRC.cc: Implementation of the AppRC class
       3             : //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
       4             : //# Associated Universities, Inc. Washington DC, USA.
       5             : //#
       6             : //# This library is free software; you can redistribute it and/or modify it
       7             : //# under the terms of the GNU Library General Public License as published by
       8             : //# the Free Software Foundation; either version 2 of the License, or (at your
       9             : //# option) any later version.
      10             : //#
      11             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      12             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      14             : //# License for more details.
      15             : //#
      16             : //# You should have received a copy of the GNU Library General Public License
      17             : //# along with this library; if not, write to the Free Software Foundation,
      18             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      19             : //#
      20             : //# Correspondence concerning AIPS++ should be addressed as follows:
      21             : //#        Internet email: casa-feedback@nrao.edu.
      22             : //#        Postal address: AIPS++ Project Office
      23             : //#                        National Radio Astronomy Observatory
      24             : //#                        520 Edgemont Road
      25             : //#                        Charlottesville, VA 22903-2475 USA
      26             : //#
      27             : //# $Id$
      28             : #include <synthesis/Utilities/AppRC.h>
      29             : #include <casacore/casa/OS/RegularFile.h>
      30             : #include <casacore/casa/OS/HostInfo.h>
      31             : #include <synthesis/TransformMachines/Utils.h>
      32             : using namespace casacore;
      33             : namespace casa{
      34             :   //
      35             :   //--------------------------------------------------------------
      36             :   //
      37           0 :   AppRC::~AppRC() 
      38             :   {
      39             :     // if (deleteFile_p)
      40             :     //   {
      41             :     //  RegularFile ff(fileName_p);
      42             :     //  cerr << id_p << " " << fileName_p << endl;
      43             :     //  if (ff.exists()) 
      44             :     //    {
      45             :     //      if (id_p != "") 
      46             :     //        cerr << id_p << " removing " << fileName_p << endl;
      47             :     //      ff.remove();
      48             :     //    }
      49             :     //  else
      50             :     //    {
      51             :     //      if (id_p != "") 
      52             :     //        cerr << id_p << " did not find " << fileName_p << endl;
      53             :     //    }
      54             :     //   }
      55             : 
      56           0 :   };
      57             :   //
      58             :   //--------------------------------------------------------------
      59             :   //
      60           0 :   void AppRC::init(const string& filename, const Bool addPID,
      61             :                    const Bool deleteFile) 
      62             :   {
      63           0 :     addPID_p=addPID; deleteFile_p=deleteFile;
      64           0 :     if (rc_p == NULL)
      65             :       {
      66           0 :         ostringstream tt; 
      67           0 :         tt << filename;
      68           0 :         if (addPID_p) 
      69             :           {
      70           0 :             setPID();
      71           0 :             tt << "_" << myPID_p;
      72             :           }
      73           0 :         fileName_p=tt.str();
      74             :         //cerr << fileName_p <<endl; 
      75           0 :         if(fileName_p.size() >0){
      76           0 :           Casarc::setDefaultPath(fileName_p);
      77           0 :           rc_p = &Casarc::instance(fileName_p);
      78             :         }
      79             :         else
      80           0 :           rc_p = &Casarc::instance();
      81             :         //cerr << rc_p->path() << endl;
      82           0 :       }
      83           0 :   };
      84             :   //
      85             :   //--------------------------------------------------------------
      86             :   //
      87           0 :   string AppRC::get(const string& name) 
      88           0 :   {return rc_p->get(name);}
      89             :   //
      90             :   //--------------------------------------------------------------
      91             :   //
      92           0 :   string AppRC::get(const string& name, Int& val) 
      93             :   {
      94           0 :     string strVal=rc_p->get(name); 
      95           0 :     if (strVal != "")
      96           0 :       val=atoi(strVal.c_str());
      97           0 :     return strVal;
      98           0 :   }
      99             :   //
     100             :   //--------------------------------------------------------------
     101             :   //
     102           0 :   string AppRC::get(const string& name, Float& val) 
     103             :   {
     104           0 :     string strVal=rc_p->get(name); 
     105           0 :     if (strVal != "")
     106           0 :       val=(Float)atof(strVal.c_str());
     107           0 :     return strVal;
     108           0 :   }
     109             :   //
     110             :   //--------------------------------------------------------------
     111             :   //
     112           0 :   string AppRC::get(const string& name, Double& val) 
     113             :   {
     114           0 :     string strVal=rc_p->get(name); 
     115           0 :     if (strVal != "")
     116           0 :       val=(Double)atof(strVal.c_str());
     117           0 :     return strVal;
     118           0 :   }
     119             :   //
     120             :   //--------------------------------------------------------------
     121             :   //
     122           0 :   void AppRC::put(const string& name, const string& val) 
     123           0 :   {rc_p->put(name,val);}
     124             :   //
     125             :   //--------------------------------------------------------------
     126             :   //
     127           0 :   void AppRC::put(const string& name, const Int& val) 
     128             :   {
     129           0 :     ostringstream tt; tt << val;
     130           0 :     put(name,tt.str());
     131           0 :   }
     132             :   //
     133             :   //--------------------------------------------------------------
     134             :   //
     135           0 :   void AppRC::put(const string& name, const Float& val) 
     136             :   {
     137           0 :     ostringstream tt; tt << val;
     138           0 :     put(name,tt.str());
     139           0 :   }
     140             :   //
     141             :   //--------------------------------------------------------------
     142             :   //
     143           0 :   void AppRC::put(const string& name, const Double& val) 
     144             :   {
     145           0 :     ostringstream tt; tt << val;
     146           0 :     put(name,tt.str());
     147             :  
     148           0 :  }
     149             :  
     150           0 :   Double AppRC::getMemoryAvailable(string envVarName)
     151             :   {
     152           0 :     AppRC myRC;
     153           0 :     string def_rc_val=myRC.get("system.resources.memory");
     154           0 :     Double memval=-1.0;
     155           0 :     if(def_rc_val.size() >0){
     156             :       //This is in MB usually
     157           0 :       stringstream(def_rc_val) >> memval;     
     158           0 :       memval*=1e6;
     159             :     }
     160           0 :     if(memval < 0.0){
     161             :       //This is in KB
     162           0 :       memval=HostInfo::memoryTotal(true);
     163           0 :       memval*=1e3;
     164             :     }
     165           0 :     Double valfromenv=-1.0;
     166             :     //Assuming it is in MB
     167           0 :     valfromenv=SynthesisUtils::getenv(envVarName.c_str(), valfromenv);
     168           0 :     valfromenv *=1e6;
     169           0 :     if(valfromenv <0.0)
     170           0 :       return memval;
     171           0 :     return valfromenv;
     172           0 :   }
     173             : 
     174             : };

Generated by: LCOV version 1.16