CMS 3D CMS Logo

PSetNode.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/PSetNode.h"
00002 #include "FWCore/ParameterSet/interface/Visitor.h"
00003 #include "FWCore/ParameterSet/interface/ReplaceNode.h"
00004 #include "FWCore/ParameterSet/interface/Entry.h"
00005 #include "FWCore/ParameterSet/interface/VEntryNode.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ParameterSet/interface/ProcessDesc.h"
00008 #include "FWCore/Utilities/interface/EDMException.h"
00009 #include <ostream>
00010 #include <iostream>
00011 
00012 namespace edm {
00013 
00014   namespace pset {
00015 
00016 
00017     PSetNode::PSetNode(const std::string& t,
00018                        const std::string& n,
00019                        NodePtrListPtr v,
00020                        bool untracked,
00021                        int line) :
00022       CompositeNode(n, v, line),
00023       type_(t),
00024       tracked_(!untracked)
00025     {
00026       // processes shouldn't have minuses in their names
00027       if(type() == "process" && n.find("-",0) != std::string::npos)
00028       {
00029         throw edm::Exception(errors::Configuration,"PSetError")
00030            << "Process names should not have minus signs in them.\n"
00031            << "It will lead to a ROOT error.";
00032       } 
00033     }
00034 
00035 
00036     std::string PSetNode::type() const { return type_; }
00037 
00038 
00039     void PSetNode::dotDelimitedPath(std::string & path) const
00040     {
00041       // processes don't add their names to the path
00042       if(type() != "process")
00043       {
00044         CompositeNode::dotDelimitedPath(path);
00045       }
00046     }
00047 
00048 
00049     void PSetNode::print(std::ostream& ost, Node::PrintOptions options) const
00050     {
00051       const char* t = tracked_ ? "" : "untracked ";
00052       ost << t << type() << " " << name() << " = ";
00053 
00054       CompositeNode::print(ost, options);
00055     }
00056 
00057     void PSetNode::accept(Visitor& v) const
00058     {
00059       v.visitPSet(*this);
00060     }
00061 
00062 
00063     bool PSetNode::isModified() const 
00064     {
00065       return Node::isModified() || CompositeNode::isModified();
00066     }
00067 
00068 
00069     void PSetNode::replaceWith(const ReplaceNode * replaceNode)
00070     {
00071       PSetNode * replacement = replaceNode->value<PSetNode>();
00072       if(replacement != 0)
00073       {
00074         nodes_ = replacement->nodes_;
00075       }
00076       else
00077       {
00078         // maybe it's an empty {}, interpretedf as a VEntry
00079         VEntryNode * entries  = replaceNode->value<VEntryNode>();
00080         if(entries == 0 || entries->value()->size() != 0) 
00081         {
00082            throw edm::Exception(errors::Configuration,"PSetError")
00083             << " Bad replace for PSet " << name()
00084             << "\nIn " << traceback() << std ::endl;
00085         }
00086         else {
00087           nodes_->clear();
00088         }
00089       }
00090       setModified(true);
00091     }
00092 
00093 
00094     edm::Entry PSetNode::makeEntry() const
00095     {
00096       // verify that this ia not a process related node
00097       if(type()=="process")
00098         {
00099           throw edm::Exception(errors::Configuration,"PSetError")
00100             << "ParameterSet: problem with making a parameter set.\n"
00101             << "Attempt to convert process input to ParameterSet";
00102         }
00103 
00104       boost::shared_ptr<ParameterSet> psetPtr(new ParameterSet);
00105       // do the subnodes
00106       CompositeNode::insertInto(*psetPtr);
00107       return Entry(name(), *psetPtr, tracked_);
00108     }
00109 
00110     void PSetNode::insertInto(edm::ParameterSet & pset) const
00111     {
00112       pset.insert(false, name(), makeEntry());
00113     }
00114 
00115 
00116 
00117     void PSetNode::insertInto(edm::ProcessDesc & procDesc) const
00118     {
00119       insertInto(*(procDesc.getProcessPSet()));
00120     }
00121 
00122 
00123     void PSetNode::fillProcess(edm::ProcessDesc & procDesc) const
00124     {
00125       if(type()!="process")
00126       {
00127         throw edm::Exception(errors::Configuration,"PSetError")
00128           << "ParameterSet: problem with making a parameter set.\n"
00129           << "Attempt to make a ProcessDesc with a PSetNode which is not a process"
00130           << "\nIn " << traceback();
00131       }
00132 
00133       procDesc.getProcessPSet()->addParameter("@process_name", name());
00134       // insert the subnodes as top-level nodes
00135       NodePtrList::const_iterator i(nodes()->begin()),e(nodes()->end());
00136       for(;i!=e;++i)
00137       {
00138         try
00139         {
00140           (**i).insertInto(procDesc);
00141         }
00142         catch(edm::Exception & e)
00143         {
00144           // print some extra debugging
00145           std::ostringstream message;
00146           message << "\nIn variable " << (**i).name() 
00147                   << "\nIncluded from:\n" << (**i).traceback();
00148           e.append(message.str());
00149          
00150           // pass it on(errors::Configuration
00151           throw e;
00152         }
00153       }
00154 
00155     }
00156 
00157 
00158   }
00159 }

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