CMS 3D CMS Logo

VPSetNode.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/VPSetNode.h"
00002 #include "FWCore/ParameterSet/interface/PSetNode.h"
00003 #include "FWCore/ParameterSet/interface/VEntryNode.h"
00004 #include "FWCore/ParameterSet/interface/Nodes.h"
00005 #include "FWCore/ParameterSet/interface/Visitor.h"
00006 #include "FWCore/ParameterSet/interface/ReplaceNode.h"
00007 #include "FWCore/ParameterSet/interface/Entry.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/ParameterSet/interface/ProcessDesc.h"
00010 #include "FWCore/Utilities/interface/EDMException.h"
00011 
00012 #include <ostream>
00013 #include <iterator>
00014 #include <iosfwd>
00015 
00016 namespace edm {
00017   namespace pset {
00018 
00019     VPSetNode::VPSetNode(const std::string& typ,
00020                          const std::string& name,
00021                          NodePtrListPtr value,
00022                          bool untracked,
00023                          int line) :
00024       CompositeNode(name,value, line),
00025       type_(typ),
00026       tracked_(!untracked)
00027     { }
00028 
00029     std::string VPSetNode::type() const { return type_; }
00030 
00031 
00032     void VPSetNode::print(std::ostream& ost, Node::PrintOptions options) const
00033     {
00034       assert(nodes()!=0);
00035 
00036       ost << type() << " " << name() << " = {\n";
00037       if(!nodes()->empty())
00038         {
00039           //copy_all(*value_, std::ostream_iterator<NodePtr>(ost,",\n  "));
00040           NodePtrList::const_iterator ie(nodes()->end()),ib(nodes()->begin());
00041           --ie;
00042           copy(ib,ie,
00043                std::ostream_iterator<NodePtr>(ost,", "));
00044           ost << *ie;
00045         }  ost << "\n}\n";
00046 
00047     }
00048 
00049     void VPSetNode::accept(Visitor& v) const
00050     {
00051       v.visitVPSet(*this);
00052     }
00053 
00054 
00055     void VPSetNode::resolveUsingNodes(const NodeMap & blocks, bool strict)
00056     {
00057       // if a node is just a std::string, find the block it refers to
00058       NodePtrList::iterator nodeItr(nodes_->begin()),e(nodes_->end());
00059       for(;nodeItr!=e;++nodeItr)
00060       {
00061         if((**nodeItr).type() == "string")
00062         {
00063           // find the block
00064           std::string blockName = (**nodeItr).name();
00065           NodeMap::const_iterator blockPtrItr = blocks.find(blockName);
00066           if(blockPtrItr == blocks.end()) {
00067              throw edm::Exception(errors::Configuration,"")
00068                << "VPSet: Cannot find parameter block " << blockName
00069                << "\nfrom " << traceback();
00070           }
00071 
00072           //@@ will this destruct the old entry correctly?
00073           // doesn't deep-copy
00074           *nodeItr = blockPtrItr->second;
00075         }
00076         else
00077         {
00078           // if it isn't a using node, check the grandchildren
00079           (**nodeItr).resolveUsingNodes(blocks, strict);
00080         }
00081       } // loop over subnodes
00082     }
00083 
00084 
00087     void VPSetNode::insertInto(ProcessDesc & procDesc) const
00088     {
00089       insertInto(*(procDesc.getProcessPSet()));
00090     }
00091 
00094     void VPSetNode::insertInto(edm::ParameterSet & pset) const 
00095     {
00096       pset.insert(false, name(), makeEntry());
00097     }
00098 
00100     edm::Entry VPSetNode::makeEntry() const
00101     {
00102       std::vector<ParameterSet> sets;
00103       NodePtrList::const_iterator ie(nodes()->end()),ib(nodes()->begin());
00104 
00105       for( ; ib != ie; ++ib)
00106       {
00107         // make a ParameterSet for this PSetNode
00108         boost::shared_ptr<ParameterSet> pset(new ParameterSet);
00109         (**ib).insertInto(*pset);
00110         sets.push_back(*pset);
00111       }
00112       
00113       return Entry(name(), sets, tracked_); 
00114     }
00115 
00116 
00117     void VPSetNode::replaceWith(const ReplaceNode * replaceNode)
00118     {
00119       // see if it's a replace or an append
00120       if(replaceNode->type() == "replace")
00121       {
00122         VPSetNode * replacement = replaceNode->value<VPSetNode>();
00123 
00124         if(replacement != 0) 
00125         {
00126           nodes_ = replacement->nodes_;
00127         }
00128         else 
00129         {
00130           // maybe it's a blank VEntryNode
00131           VEntryNode * ventryNode = replaceNode->value<VEntryNode>();
00132           if(ventryNode != 0 && ventryNode->value()->empty())
00133           {
00134             nodes_->clear();
00135           }
00136           else 
00137           {
00138             throw edm::Exception(errors::Configuration)
00139               << "Cannot replace entry vector " << name()
00140               <<   " with " << replaceNode->type()
00141               << "\nfrom " << traceback();
00142           }
00143         }
00144       }
00145       else if(replaceNode->type() == "replaceAppend")
00146       {
00147         append(replaceNode->value());
00148       }
00149       else
00150       {
00151          throw edm::Exception(errors::Configuration)
00152             << "Cannot replace entry vector" << name()
00153             <<   " with " << replaceNode->type()
00154             << "\nfrom " << traceback();
00155       }
00156 
00157       setModified(true);
00158     }
00159 
00160 
00161     void VPSetNode::append(NodePtr ptr)
00162     {
00163       // single or multiple?  ContentsNodes never say their type.
00164       // they represent a single PSet
00165       if(ptr->type() == "")
00166       {
00167         nodes_->push_back(ptr);
00168       }
00169       else if(ptr->type() == "PSet")
00170       {
00171         // make a ContentsNode from this PSetNode
00172         PSetNode * psetNode =  dynamic_cast<PSetNode*>(ptr.get());
00173         NodePtr n(new ContentsNode(psetNode->nodes(), psetNode->line()));
00174         nodes_->push_back(n);
00175       }
00176       else
00177       {
00178         // try VPSet
00179         VPSetNode * vpsetNode =  dynamic_cast<VPSetNode*>(ptr.get());
00180         if(vpsetNode != 0)
00181         {
00182           NodePtrListPtr entries = vpsetNode->nodes_;
00183           for(NodePtrList::const_iterator itr = entries->begin(), itrEnd = entries->end();
00184               itr != itrEnd; ++itr)
00185           {
00186             nodes_->push_back(*itr);
00187           }
00188         }
00189         // neither Entry or VPSet
00190         else
00191         {
00192           throw edm::Exception(errors::Configuration)
00193             << "Bad type to append to VPSet "
00194             <<  ptr->type();
00195         }
00196       }
00197     }
00198 
00199 
00200   }
00201 }

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