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
00005 #include <cassert>
00006 #include <ostream>
00007
00008 namespace edm {
00009
00010 VParameterSetEntry::VParameterSetEntry()
00011 : tracked(false),
00012 theVPSet(),
00013 theIDs()
00014 {
00015 }
00016
00017 VParameterSetEntry::VParameterSetEntry(std::vector<ParameterSet> const& vpset, bool isTracked)
00018 : tracked(isTracked),
00019 theVPSet(new std::vector<ParameterSet>),
00020 theIDs()
00021 {
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 {
00032 assert(rep[0] == '+' || rep[0] == '-');
00033 std::vector<std::string> temp;
00034
00035 std::string bracketedRepr(rep.begin()+2, rep.end());
00036 split(std::back_inserter(temp), bracketedRepr, '{', ',', '}');
00037 theIDs->reserve(temp.size());
00038 for (std::vector<std::string>::const_iterator i = temp.begin(), e = temp.end(); i != e; ++i) {
00039 theIDs->push_back(ParameterSetID(*i));
00040 }
00041 }
00042
00043 VParameterSetEntry::~VParameterSetEntry() {}
00044
00045 void
00046 VParameterSetEntry::toString(std::string& result) const {
00047 assert(theIDs);
00048 result += tracked ? "+q" : "-q";
00049 result += '{';
00050 std::string start;
00051 std::string const between(",");
00052 for (std::vector<ParameterSetID>::const_iterator i = theIDs->begin(), e = theIDs->end(); i != e; ++i) {
00053 result += start;
00054 i->toString(result);
00055 start = between;
00056 }
00057 result += '}';
00058 }
00059
00060 std::string VParameterSetEntry::toString() const {
00061 std::string result;
00062 toString(result);
00063 return result;
00064 }
00065
00066 std::vector<ParameterSet> const& VParameterSetEntry::vpset() const {
00067 if (!theVPSet) {
00068 assert(theIDs);
00069 theVPSet = value_ptr<std::vector<ParameterSet> >(new std::vector<ParameterSet>);
00070 theVPSet->reserve(theIDs->size());
00071 for (std::vector<ParameterSetID>::const_iterator i = theIDs->begin(), e = theIDs->end(); i != e; ++i) {
00072 theVPSet->push_back(getParameterSet(*i));
00073 }
00074 }
00075 return *theVPSet;
00076 }
00077
00078 ParameterSet & VParameterSetEntry::psetInVector(int i) {
00079 assert(theVPSet);
00080 return theVPSet->at(i);
00081 }
00082
00083 void VParameterSetEntry::registerPsetsAndUpdateIDs() {
00084 vpset();
00085 theIDs = value_ptr<std::vector<ParameterSetID> >(new std::vector<ParameterSetID>);
00086 theIDs->resize(theVPSet->size());
00087 for (std::vector<ParameterSet>::iterator i = theVPSet->begin(), e = theVPSet->end(); i != e; ++i) {
00088 if (!i->isRegistered()) {
00089 i->registerIt();
00090 }
00091 theIDs->at(i - theVPSet->begin()) = i->id();
00092 }
00093 }
00094
00095 std::ostream & operator<<(std::ostream & os, VParameterSetEntry const& vpsetEntry) {
00096 std::vector<ParameterSet> const& vps = vpsetEntry.vpset();
00097 os << "VPSet "<<(vpsetEntry.isTracked()?"tracked":"untracked")<<" = ({" << std::endl;
00098 std::string start;
00099 std::string const between(",\n");
00100 for(std::vector<ParameterSet>::const_iterator i = vps.begin(), e = vps.end(); i != e; ++i) {
00101 os << start << *i;
00102 start = between;
00103 }
00104 if (!vps.empty()) {
00105 os << std::endl;
00106 }
00107 os << "})";
00108 return os;
00109 }
00110 }