CMS 3D CMS Logo

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