00001 #include "FWCore/ParameterSet/interface/Node.h"
00002 #include "FWCore/Utilities/interface/EDMException.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004
00005 #include <iostream>
00006
00007 namespace edm {
00008
00009 namespace pset {
00010
00011 Node::Node(std::string const& n, int li)
00012 : name_(n),
00013 line_(li),
00014 modified_(false),
00015 cloned_(false),
00016 parent_(0)
00017 {
00018 }
00019
00020
00021 Node::~Node() { }
00022
00023 void Node::setModified(bool value)
00024 {
00025 modified_ = value;
00026 }
00027
00028 void Node::replaceWith(const ReplaceNode *) {
00029 throw edm::Exception(errors::Configuration)
00030 << "No way to replace node " << name()
00031 << "\nfrom " << traceback();
00032 }
00033
00034
00035 bool Node::isInclude() const
00036 {
00037 return (type().substr(0,7) == "include");
00038 }
00039
00040
00041 const Node * Node::getIncludeParent() const
00042 {
00043 const Node * result = 0;
00044 const Node * currentNode = this;
00045 bool done = false;
00046 while(!done)
00047 {
00048 currentNode = currentNode->getParent();
00049 if(currentNode == 0)
00050 {
00051 done = true;
00052 }
00053 else
00054 {
00055 if(currentNode->isInclude())
00056 {
00057 result = currentNode;
00058 done = true;
00059 }
00060 }
00061 }
00062 return result;
00063 }
00064
00065
00066 std::string Node::includeParentSuffix() const
00067 {
00068 const Node * includeParent = getIncludeParent();
00069 if(includeParent == 0) return "";
00070
00071 int nletters = includeParent->name().length();
00072 assert(nletters >= 3);
00073 return includeParent->name().substr(nletters-3);
00074 }
00075
00076
00077 void Node::dotDelimitedPath(std::string & path) const
00078 {
00079 if(!path.empty())
00080 {
00081 path.insert(0, ".");
00082 }
00083 path.insert(0, name());
00084
00085
00086 if(parent_ != 0)
00087 {
00088 parent_->dotDelimitedPath(path);
00089 }
00090 }
00091
00092
00093 void Node::printTrace(std::ostream & out) const
00094 {
00095
00096
00097 if(parent_ != 0)
00098 {
00099 parent_->printTrace(out);
00100 }
00101 }
00102
00103
00104 std::string Node::traceback() const
00105 {
00106 std::ostringstream tr;
00107 printTrace(tr);
00108 std::string result = tr.str();
00109 if(result.empty()) result = "<MAIN CFG>";
00110 return result;
00111 }
00112
00113
00114 void Node::locate(const std::string & s, std::ostream & out) const
00115 {
00116 if(name().find(s,0) != std::string::npos)
00117 {
00118 print(out);
00119 out << "\n";
00120 printTrace(out);
00121 out << "\n";
00122 }
00123 }
00124
00125
00126 void Node::insertInto(edm::ParameterSet & pset) const
00127 {
00128 pset.insert(false, name(), makeEntry());
00129 }
00130
00131
00132 void Node::insertInto(edm::ProcessDesc & procDesc) const
00133 {
00134
00135
00136 throw edm::Exception(errors::Configuration)
00137 << "No way to convert this node, " << name()
00138 << ", to a ProcessDesc Entry";
00139 }
00140
00141
00142 edm::Entry Node::makeEntry() const
00143 {
00144
00145
00146 throw edm::Exception(errors::Configuration)
00147 << "No way to convert this node, " << name()
00148 << ", to a ParameterSet Entry";
00149 }
00150
00151
00152 }
00153 }