LCOV - code coverage report
Current view: top level - vesselbase - Vessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 64 78 82.1 %
Date: 2024-10-11 08:09:47 Functions: 10 11 90.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2023 The plumed team
       3             :    (see the PEOPLE file at the root of the distribution for a list of names)
       4             : 
       5             :    See http://www.plumed.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       8             : 
       9             :    plumed is free software: you can redistribute it and/or modify
      10             :    it under the terms of the GNU Lesser General Public License as published by
      11             :    the Free Software Foundation, either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    plumed is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU Lesser General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : #include "Vessel.h"
      23             : #include "ActionWithVessel.h"
      24             : #include "tools/Exception.h"
      25             : #include "tools/Communicator.h"
      26             : #include "tools/Log.h"
      27             : 
      28             : namespace PLMD {
      29             : namespace vesselbase {
      30             : 
      31             : Keywords VesselOptions::emptyKeys;
      32             : 
      33         600 : VesselOptions::VesselOptions(const std::string& thisname, const std::string& thislab, const unsigned& nlab, const std::string& params, ActionWithVessel* aa ):
      34         600 :   myname(thisname),
      35         600 :   mylabel(thislab),
      36         600 :   numlab(nlab),
      37         600 :   action(aa),
      38         600 :   keywords(emptyKeys),
      39         600 :   parameters(params)
      40             : {
      41         600 : }
      42             : 
      43         449 : VesselOptions::VesselOptions(const VesselOptions& da, const Keywords& keys ):
      44         449 :   myname(da.myname),
      45         449 :   mylabel(da.mylabel),
      46         449 :   numlab(da.numlab),
      47         449 :   action(da.action),
      48         449 :   keywords(keys),
      49         449 :   parameters(da.parameters)
      50             : {
      51         449 : }
      52             : 
      53         449 : void Vessel::registerKeywords( Keywords& keys ) {
      54         449 :   plumed_assert( keys.size()==0 );
      55         898 :   keys.add("optional","LABEL","the label used to reference this particular quantity");
      56         449 : }
      57             : 
      58         796 : std::string Vessel::transformName( const std::string& name ) {
      59         796 :   std::string tlabel=name;
      60             :   // Convert to lower case
      61        4607 :   std::transform( tlabel.begin(), tlabel.end(), tlabel.begin(), [](unsigned char c) { return std::tolower(c); } );
      62             :   // Remove any underscore characters (as these are reserved)
      63             :   for(unsigned i=0;; ++i) {
      64         978 :     std::size_t num=tlabel.find_first_of("_");
      65         978 :     if( num==std::string::npos ) break;
      66         182 :     tlabel.erase( tlabel.begin() + num, tlabel.begin() + num + 1 );
      67         182 :   }
      68         796 :   return tlabel;
      69             : }
      70             : 
      71         601 : Vessel::Vessel( const VesselOptions& da ):
      72         601 :   myname(da.myname),
      73         601 :   numlab(da.numlab),
      74         601 :   action(da.action),
      75         601 :   line(Tools::getWords( da.parameters )),
      76         601 :   keywords(da.keywords),
      77         601 :   finished_read(false)
      78             : {
      79         601 :   if( da.mylabel.length()>0) {
      80           0 :     mylabel=da.mylabel;
      81             :   } else {
      82        1607 :     if( keywords.exists("LABEL") ) parse("LABEL",mylabel);
      83         601 :     if( mylabel.length()==0 && numlab>=0 ) {
      84         938 :       mylabel=transformName( myname ); std::string nn;
      85         522 :       if(numlab>0) { Tools::convert( numlab, nn ); mylabel =  mylabel + "-" + nn; }
      86             :     }
      87             :   }
      88         601 : }
      89             : 
      90          89 : std::string Vessel::getName() const {
      91          89 :   return myname;
      92             : }
      93             : 
      94       28581 : std::string Vessel::getLabel() const {
      95       28581 :   return mylabel;
      96             : }
      97             : 
      98         172 : std::string Vessel::getAllInput() {
      99             :   std::string fullstring;
     100         731 :   for(unsigned i=0; i<line.size(); ++i) {
     101        1118 :     fullstring = fullstring + " " + line[i];
     102             :   }
     103         172 :   line.clear(); line.resize(0);
     104         172 :   return fullstring;
     105             : }
     106             : 
     107         122 : void Vessel::parseFlag(const std::string&key, bool & t) {
     108             :   // Check keyword has been registered
     109         122 :   plumed_massert(keywords.exists(key), "keyword " + key + " has not been registered");
     110             :   // Check keyword is a flag
     111         244 :   if(!keywords.style(key,"nohtml")) {
     112         244 :     plumed_massert(keywords.style(key,"flag"), "keyword " + key + " is not a flag");
     113             :   }
     114             : 
     115             :   // Read in the flag otherwise get the default value from the keywords object
     116         122 :   if(!Tools::parseFlag(line,key,t)) {
     117         198 :     if( keywords.style(key,"nohtml") ) {
     118           0 :       t=false;
     119         198 :     } else if ( !keywords.getLogicalDefault(key,t) ) {
     120           0 :       plumed_merror("there is a flag with no logical default in a vessel - weird");
     121             :     }
     122             :   }
     123         122 : }
     124             : 
     125         542 : void Vessel::checkRead() {
     126         542 :   if(!line.empty()) {
     127           0 :     std::string msg="cannot understand the following words from input : ";
     128           0 :     for(unsigned i=0; i<line.size(); i++) {
     129           0 :       if(i>0) msg = msg + ", ";
     130           0 :       msg = msg + line[i];
     131             :     }
     132           0 :     error(msg);
     133             :   }
     134         542 :   finished_read=true;
     135         542 :   std::string describe=description();
     136         542 :   if( describe.length()>0 && action ) action->log.printf("  %s\n", describe.c_str() );
     137         542 : }
     138             : 
     139           0 : [[noreturn]] void Vessel::error( const std::string& msg ) {
     140           0 :   if( action ) {
     141           0 :     action->log.printf("ERROR for keyword %s in action %s with label %s : %s \n \n",myname.c_str(), (action->getName()).c_str(), (action->getLabel()).c_str(), msg.c_str() );
     142           0 :     if(finished_read) keywords.print( action->log );
     143           0 :     plumed_merror("ERROR for keyword " + myname + " in action "  + action->getName() + " with label " + action->getLabel() + " : " + msg );
     144             :   } else {
     145           0 :     plumed_merror("ERROR: " + msg);
     146             :   }
     147             : }
     148             : 
     149             : }
     150             : }

Generated by: LCOV version 1.15