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