CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/FWCore/ParameterSet/src/VParameterSetEntry.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/VParameterSetEntry.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "FWCore/ParameterSet/interface/split.h"
00004 #include "FWCore/Utilities/interface/Digest.h"
00005 
00006 #include <cassert>
00007 #include <ostream>
00008 
00009 namespace edm {
00010 
00011   VParameterSetEntry::VParameterSetEntry() :
00012       tracked(false),
00013       theVPSet(),
00014       theIDs() {
00015   }
00016 
00017   VParameterSetEntry::VParameterSetEntry(std::vector<ParameterSet> const& vpset, bool isTracked) :
00018       tracked(isTracked),
00019       theVPSet(new std::vector<ParameterSet>),
00020       theIDs() {
00021     for (std::vector<ParameterSet>::const_iterator i = vpset.begin(), e = vpset.end(); i != e; ++i) {
00022       theVPSet->push_back(*i);
00023     }
00024   }
00025 
00026   VParameterSetEntry::VParameterSetEntry(std::string const& rep) :
00027       tracked(rep[0] == '+'),
00028       theVPSet(),
00029       theIDs(new std::vector<ParameterSetID>) {
00030     assert(rep[0] == '+' || rep[0] == '-');
00031     std::vector<std::string> temp;
00032     // need a substring that starts at the '{'
00033     std::string bracketedRepr(rep.begin()+2, rep.end());
00034     split(std::back_inserter(temp), bracketedRepr, '{', ',', '}');
00035     theIDs->reserve(temp.size());
00036     for (std::vector<std::string>::const_iterator i = temp.begin(), e = temp.end(); i != e; ++i) {
00037       theIDs->push_back(ParameterSetID(*i));
00038     }
00039   }
00040 
00041   VParameterSetEntry::~VParameterSetEntry() {}
00042 
00043   void
00044   VParameterSetEntry::toString(std::string& result) const {
00045     assert(theIDs);
00046     result += tracked ? "+q" : "-q";
00047     result += '{';
00048     std::string start;
00049     std::string const between(",");
00050     for (std::vector<ParameterSetID>::const_iterator i = theIDs->begin(), e = theIDs->end(); i != e; ++i) {
00051       result += start;
00052       i->toString(result);
00053       start = between;
00054     }
00055     result += '}';
00056   }
00057 
00058   void
00059   VParameterSetEntry::toDigest(cms::Digest &digest) const {
00060     assert(theIDs);
00061     digest.append(tracked ? "+q{" : "-q{", 3);
00062     bool started = false;
00063     for (std::vector<ParameterSetID>::const_iterator i = theIDs->begin(), e = theIDs->end(); i != e; ++i) {
00064       if (started)
00065         digest.append(",", 1);
00066       i->toDigest(digest);
00067       started = true;
00068     }
00069     digest.append("}",1);
00070   }
00071 
00072   std::string VParameterSetEntry::toString() const {
00073     std::string result;
00074     toString(result);
00075     return result;
00076   }
00077 
00078   std::vector<ParameterSet> const& VParameterSetEntry::vpset() const {
00079     if (!theVPSet) {
00080       assert(theIDs);
00081       theVPSet = value_ptr<std::vector<ParameterSet> >(new std::vector<ParameterSet>);
00082       theVPSet->reserve(theIDs->size());
00083       for (std::vector<ParameterSetID>::const_iterator i = theIDs->begin(), e = theIDs->end(); i != e; ++i) {
00084         theVPSet->push_back(getParameterSet(*i));
00085       }
00086     }
00087     return *theVPSet;
00088   }
00089 
00090   std::vector<ParameterSet>& VParameterSetEntry::vpset() {
00091     if (!theVPSet) {
00092       assert(theIDs);
00093       theVPSet = value_ptr<std::vector<ParameterSet> >(new std::vector<ParameterSet>);
00094       theVPSet->reserve(theIDs->size());
00095       for (std::vector<ParameterSetID>::const_iterator i = theIDs->begin(), e = theIDs->end(); i != e; ++i) {
00096         theVPSet->push_back(getParameterSet(*i));
00097       }
00098     }
00099     return *theVPSet;
00100   }
00101 
00102   ParameterSet& VParameterSetEntry::psetInVector(int i) {
00103     assert(theVPSet);
00104     return theVPSet->at(i);
00105   }
00106 
00107   void VParameterSetEntry::registerPsetsAndUpdateIDs() {
00108     vpset();
00109     theIDs = value_ptr<std::vector<ParameterSetID> >(new std::vector<ParameterSetID>);
00110     theIDs->resize(theVPSet->size());
00111     for (std::vector<ParameterSet>::iterator i = theVPSet->begin(), e = theVPSet->end(); i != e; ++i) {
00112       if (!i->isRegistered()) {
00113         i->registerIt();
00114       }
00115       theIDs->at(i - theVPSet->begin()) = i->id();
00116     }
00117   }
00118 
00119   std::ostream& operator<<(std::ostream& os, VParameterSetEntry const& vpsetEntry) {
00120     std::vector<ParameterSet> const& vps = vpsetEntry.vpset();
00121     os << "VPSet "<<(vpsetEntry.isTracked()?"tracked":"untracked")<<" = ({" << std::endl;
00122     std::string start;
00123     std::string const between(",\n");
00124     for(std::vector<ParameterSet>::const_iterator i = vps.begin(), e = vps.end(); i != e; ++i) {
00125       os << start << *i;
00126       start = between;
00127     }
00128     if (!vps.empty()) {
00129       os << std::endl;
00130     }
00131     os << "})";
00132     return os;
00133   }
00134 }