LCOV - code coverage report
Current view: top level - vesselbase - Vessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 70 86 81.4 %
Date: 2026-03-30 13:16:06 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         620 : VesselOptions::VesselOptions(const std::string& thisname, const std::string& thislab, const unsigned& nlab, const std::string& params, ActionWithVessel* aa ):
      34         620 :   myname(thisname),
      35         620 :   mylabel(thislab),
      36         620 :   numlab(nlab),
      37         620 :   action(aa),
      38         620 :   keywords(emptyKeys),
      39         620 :   parameters(params) {
      40         620 : }
      41             : 
      42         469 : VesselOptions::VesselOptions(const VesselOptions& da, const Keywords& keys ):
      43         469 :   myname(da.myname),
      44         469 :   mylabel(da.mylabel),
      45         469 :   numlab(da.numlab),
      46         469 :   action(da.action),
      47         469 :   keywords(keys),
      48         469 :   parameters(da.parameters) {
      49         469 : }
      50             : 
      51         469 : void Vessel::registerKeywords( Keywords& keys ) {
      52         469 :   plumed_assert( keys.size()==0 );
      53         938 :   keys.add("optional","LABEL","the label used to reference this particular quantity");
      54         469 : }
      55             : 
      56         836 : std::string Vessel::transformName( const std::string& name ) {
      57         836 :   std::string tlabel=name;
      58             :   // Convert to lower case
      59         836 :   std::transform( tlabel.begin(), tlabel.end(), tlabel.begin(), [](unsigned char c) {
      60        4161 :     return std::tolower(c);
      61             :   } );
      62             :   // Remove any underscore characters (as these are reserved)
      63             :   for(unsigned i=0;; ++i) {
      64        1056 :     std::size_t num=tlabel.find_first_of("_");
      65        1056 :     if( num==std::string::npos ) {
      66             :       break;
      67             :     }
      68         220 :     tlabel.erase( tlabel.begin() + num, tlabel.begin() + num + 1 );
      69         220 :   }
      70         836 :   return tlabel;
      71             : }
      72             : 
      73         621 : Vessel::Vessel( const VesselOptions& da ):
      74         621 :   myname(da.myname),
      75         621 :   numlab(da.numlab),
      76         621 :   action(da.action),
      77         621 :   line(Tools::getWords( da.parameters )),
      78         621 :   keywords(da.keywords),
      79         621 :   finished_read(false) {
      80         621 :   if( da.mylabel.length()>0) {
      81           0 :     mylabel=da.mylabel;
      82             :   } else {
      83        1242 :     if( keywords.exists("LABEL") ) {
      84         850 :       parse("LABEL",mylabel);
      85             :     }
      86         621 :     if( mylabel.length()==0 && numlab>=0 ) {
      87         978 :       mylabel=transformName( myname );
      88             :       std::string nn;
      89         489 :       if(numlab>0) {
      90          53 :         Tools::convert( numlab, nn );
      91         106 :         mylabel =  mylabel + "-" + nn;
      92             :       }
      93             :     }
      94             :   }
      95         621 : }
      96             : 
      97          89 : std::string Vessel::getName() const {
      98          89 :   return myname;
      99             : }
     100             : 
     101       28661 : std::string Vessel::getLabel() const {
     102       28661 :   return mylabel;
     103             : }
     104             : 
     105         191 : std::string Vessel::getAllInput() {
     106             :   std::string fullstring;
     107         844 :   for(unsigned i=0; i<line.size(); ++i) {
     108        1306 :     fullstring = fullstring + " " + line[i];
     109             :   }
     110         191 :   line.clear();
     111         191 :   line.resize(0);
     112         191 :   return fullstring;
     113             : }
     114             : 
     115         122 : void Vessel::parseFlag(const std::string&key, bool & t) {
     116             :   // Check keyword has been registered
     117         122 :   plumed_massert(keywords.exists(key), "keyword " + key + " has not been registered");
     118             :   // Check keyword is a flag
     119         244 :   if(!keywords.style(key,"nohtml")) {
     120         244 :     plumed_massert(keywords.style(key,"flag"), "keyword " + key + " is not a flag");
     121             :   }
     122             : 
     123             :   // Read in the flag otherwise get the default value from the keywords object
     124         122 :   if(!Tools::parseFlag(line,key,t)) {
     125         198 :     if( keywords.style(key,"nohtml") ) {
     126           0 :       t=false;
     127          99 :     } else if ( !keywords.getLogicalDefault(key,t) ) {
     128           0 :       plumed_merror("there is a flag with no logical default in a vessel - weird");
     129             :     }
     130             :   }
     131         122 : }
     132             : 
     133         562 : void Vessel::checkRead() {
     134         562 :   if(!line.empty()) {
     135           0 :     std::string msg="cannot understand the following words from input : ";
     136           0 :     for(unsigned i=0; i<line.size(); i++) {
     137           0 :       if(i>0) {
     138           0 :         msg = msg + ", ";
     139             :       }
     140           0 :       msg = msg + line[i];
     141             :     }
     142           0 :     error(msg);
     143             :   }
     144         562 :   finished_read=true;
     145         562 :   std::string describe=description();
     146         562 :   if( describe.length()>0 && action ) {
     147         417 :     action->log.printf("  %s\n", describe.c_str() );
     148             :   }
     149         562 : }
     150             : 
     151           0 : [[noreturn]] void Vessel::error( const std::string& msg ) {
     152           0 :   if( action ) {
     153           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() );
     154           0 :     if(finished_read) {
     155           0 :       keywords.print( action->log );
     156             :     }
     157           0 :     plumed_merror("ERROR for keyword " + myname + " in action "  + action->getName() + " with label " + action->getLabel() + " : " + msg );
     158             :   } else {
     159           0 :     plumed_merror("ERROR: " + msg);
     160             :   }
     161             : }
     162             : 
     163             : }
     164             : }

Generated by: LCOV version 1.16