CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/FWCore/ParameterSet/src/ParameterSetEntry.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/ParameterSetEntry.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "FWCore/Utilities/interface/EDMException.h"
00004 #include "FWCore/Utilities/interface/Digest.h"
00005 
00006 #include <cassert>
00007 #include <sstream>
00008 #include <iostream>
00009 namespace edm {
00010 
00011   ParameterSetEntry::ParameterSetEntry()
00012   : isTracked_(false),
00013     thePSet_(0),
00014     theID_()
00015   {
00016   }
00017 
00018   ParameterSetEntry::ParameterSetEntry(ParameterSet const& pset, bool isTracked)
00019   : isTracked_(isTracked),
00020     thePSet_(new ParameterSet(pset)),
00021     theID_()
00022   {
00023     if (pset.isRegistered()) {
00024       theID_ = pset.id();
00025     }
00026   }
00027 
00028   ParameterSetEntry::ParameterSetEntry(ParameterSetID const& id, bool isTracked)
00029   : isTracked_(isTracked),
00030     thePSet_(),
00031     theID_(id)
00032   {
00033   }
00034 
00035   ParameterSetEntry::ParameterSetEntry(std::string const& rep)
00036   : isTracked_(rep[0] == '+'),
00037     thePSet_(),
00038     theID_()
00039   {
00040     assert(rep[0] == '+' || rep[0] == '-');
00041     assert(rep[2] == '(');
00042     assert(rep[rep.size()-1] == ')');
00043     ParameterSetID newID(std::string(rep.begin()+3, rep.end()-1) );
00044     theID_.swap(newID);
00045   }
00046     
00047   ParameterSetEntry::~ParameterSetEntry() {}
00048 
00049   void
00050   ParameterSetEntry::toString(std::string& result) const {
00051     result += isTracked() ? "+Q(" : "-Q(";
00052     if (!theID_.isValid()) {
00053       throw edm::Exception(edm::errors::LogicError)
00054         << "ParameterSet::toString() called prematurely\n"
00055         << "before ParameterSet::registerIt() has been called\n"
00056         << "for all nested parameter sets\n";
00057     }
00058     theID_.toString(result);
00059     result += ')';
00060   }
00061 
00062   void
00063   ParameterSetEntry::toDigest(cms::Digest &digest) const {
00064     digest.append(isTracked() ? "+Q(" : "-Q(", 3);
00065     if (!theID_.isValid()) {
00066       throw edm::Exception(edm::errors::LogicError)
00067         << "ParameterSet::toString() called prematurely\n"
00068         << "before ParameterSet::registerIt() has been called\n"
00069         << "for all nested parameter sets\n";
00070     }
00071     theID_.toDigest(digest);
00072     digest.append(")", 1);
00073   }
00074 
00075   std::string
00076   ParameterSetEntry::toString() const {
00077     std::string result;
00078     toString(result);
00079     return result;
00080   }
00081 
00082   ParameterSet const& ParameterSetEntry::pset() const {
00083     if(!thePSet_) {
00084       // get it from the registry, and save it here
00085       thePSet_ = value_ptr<ParameterSet>(new ParameterSet(getParameterSet(theID_)));
00086     }
00087     return *thePSet_;
00088   }
00089 
00090   ParameterSet& ParameterSetEntry::pset() {
00091     if(!thePSet_) {
00092       // get it from the registry, and save it here
00093       thePSet_ = value_ptr<ParameterSet>(new ParameterSet(getParameterSet(theID_)));
00094     }
00095     return *thePSet_;
00096   }
00097 
00098   void ParameterSetEntry::updateID() const {
00099     assert(pset().isRegistered());
00100     theID_ = pset().id();
00101   }
00102 
00103   std::ostream & operator<<(std::ostream & os, ParameterSetEntry const& psetEntry) {
00104      const char* trackiness = (psetEntry.isTracked()?"tracked":"untracked");
00105     os << "PSet "<<trackiness<<" = ("<< psetEntry.pset() << ")";
00106     return os;
00107   }
00108 }
00109 
00110