CMS 3D CMS Logo

EntryNode.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/EntryNode.h"
00002 #include "FWCore/ParameterSet/interface/Visitor.h"
00003 #include "FWCore/ParameterSet/interface/Entry.h"
00004 #include "FWCore/ParameterSet/interface/ReplaceNode.h"
00005 #include "FWCore/ParameterSet/interface/parse.h"
00006 #include "FWCore/Utilities/interface/EDMException.h"
00007 #include "FWCore/ParameterSet/interface/types.h"
00008 #include <boost/cstdint.hpp>
00009 
00010 #include <iosfwd>
00011 #include <iostream>
00012 namespace edm {
00013   namespace pset {
00014 
00015 
00016     EntryNode::EntryNode(const std::string& typ, const std::string& nam,
00017                          const std::string& val, bool untracked, int line):
00018       Node(nam, line),
00019       type_(typ),
00020       value_(val),
00021       tracked_(!untracked)
00022     {  }
00023 
00024 
00025     std::string EntryNode::type() const { return type_; }
00026 
00027 
00028     void EntryNode::print(std::ostream& ost, Node::PrintOptions options) const
00029     {
00030       const char* t = tracked_? "" : "untracked ";
00031       ost << t << type() << " " << name() << " = " << value();
00032     }
00033 
00034 
00035     void EntryNode::locate(const std::string & s, std::ostream & out) const
00036     {
00037       std::string match = "";
00038       if( value().find(s,0) != std::string::npos)
00039       {
00040         match = value();
00041       }
00042       if( name().find(s,0) != std::string::npos)
00043       {
00044         match = name();
00045       }
00046 
00047       if( match != "" )
00048       {
00049         print(out, COMPRESSED);
00050         out << std::endl;
00051         printTrace(out);
00052         out << std::endl;
00053       }
00054     }
00055 
00056     void EntryNode::accept(Visitor& v) const
00057     {
00058       v.visitEntry(*this);
00059     }
00060 
00061 
00062     void EntryNode::replaceWith(const ReplaceNode * replaceNode) {
00063       EntryNode * replacement = replaceNode->value<EntryNode>();
00064       if(replacement == 0) {
00065         throw edm::Exception(errors::Configuration)
00066           << "Cannot replace entry " << name()
00067           << " with " << replaceNode->type();
00068       }
00069       // replace the value, keep the type
00070       value_ = replacement->value_;
00071       setModified(true);
00072     }
00073 
00074 
00075     Entry EntryNode::makeEntry() const
00076     {
00077       // for checks of strtowhatever
00078       char * end;
00079       if(type()=="string") {
00080          std::string usethis(withoutQuotes(value_));
00081          return Entry(name(), usethis, tracked_);
00082      }
00083      else if (type()=="FileInPath") {
00084          edm::FileInPath fip(withoutQuotes(value_));
00085          return Entry(name(), fip, tracked_);
00086      }
00087      else if (type()=="InputTag") {
00088          edm::InputTag tag(withoutQuotes(value_));
00089          return Entry(name(), tag, tracked_);
00090      }
00091      else if (type()=="EventID") {
00092          // decodes, then encodes again
00093          edm::EventID eventID;
00094          edm::decode(eventID, value_);
00095          return Entry(name(), eventID, tracked_);
00096      }
00097      else if (type()=="LuminosityBlockID") {
00098          // decodes, then encodes again
00099          edm::LuminosityBlockID lumiID;
00100          edm::decode(lumiID, value_);
00101          return Entry(name(), lumiID, tracked_);
00102      }
00103      else if(type()=="double") {
00104          double d = strtod(value_.c_str(),&end);
00105          checkParse(value_, end);
00106          return Entry(name(), d, tracked_);
00107      }
00108      else if(type()=="int32") {
00109          int d = strtol(value_.c_str(),&end,0);
00110          checkParse(value_, end);
00111          return Entry(name(), d, tracked_);
00112      }
00113      else if(type()=="uint32") {
00114          unsigned int d = strtoul(value_.c_str(),&end,0);
00115          checkParse(value_, end);
00116          return Entry(name(), d, tracked_);
00117      }
00118      else if(type()=="int64") {
00119          boost::int64_t d = strtol(value_.c_str(),&end,0);
00120          checkParse(value_, end);
00121          return Entry(name(), d, tracked_);
00122      }
00123      else if(type()=="uint64") {
00124          boost::uint64_t d = strtoul(value_.c_str(),&end,0);
00125          checkParse(value_, end);
00126          return Entry(name(), d, tracked_);
00127      }
00128      else if(type()=="bool") {
00129          bool d(false);
00130          if(value_=="true" || value_=="T" || value_=="True" ||
00131             value_=="1" || value_=="on" || value_=="On")
00132            d = true;
00133          else if(value_=="false" || value_=="F" || value_=="False" ||
00134                  value_=="0" || value_=="off" || value_=="Off")
00135            d = false;
00136          else 
00137          {
00138             throw edm::Exception(errors::Configuration) << name()
00139                << " has a bad value for bool:" << value_
00140                << "\nfrom " << traceback();
00141          }
00142          return Entry(name(), d, tracked_);
00143      }
00144      else {
00145          throw edm::Exception(errors::Configuration)
00146            << "Bad Entry Node type: " << type()
00147            << "\nfrom " << traceback();
00148      }
00149 
00150    }
00151 
00152      void EntryNode::checkParse(const std::string & s, char * end) const
00153      {
00154        if(*end != 0)
00155        {
00156          throw edm::Exception(errors::Configuration) <<  "Cannot create a value of type " << type()
00157             <<  " for parameter " << name() << " from input " << s
00158             << "\nIncluded from " << traceback();
00159        }
00160      }
00161         
00162 
00163   }
00164 }
00165 

Generated on Tue Jun 9 17:36:28 2009 for CMSSW by  doxygen 1.5.4