CMS 3D CMS Logo

ParameterSetConverter.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 
3 ParameterSetConverter.cc
4 
5 ----------------------------------------------------------------------*/
6  //------------------------------------------------------------
7  // Adapts parameter sets by value (fileFormatVersion_.value() < 12) to parameter sets by reference
8  // Adapts untracked @trigger_paths (fileFormatVersion_.value() < 13) to tracked @trigger_paths.
9 
11 #include <iterator>
15 
16 namespace edm {
17 
18  namespace {
19  void
20  insertIntoReplace(ParameterSetConverter::StringMap& replace,
21  std::string const& fromPrefix,
22  std::string const& from,
23  std::string const& fromPostfix,
24  std::string const& toPrefix,
25  std::string const& to,
26  std::string const& toPostfix) {
27  replace.insert(std::make_pair(fromPrefix+from+fromPostfix, toPrefix+to+toPostfix));
28  }
29  }
30 
32  oldID_(oldID),
33  parameterSet_(psetString),
34  paths_(parameterSet_.getParameter<StringVector>("@paths")),
35  endPaths_(),
36  triggerPaths_() {
37  if (parameterSet_.existsAs<StringVector>("@end_paths")) {
39  }
40  for (StringVector::const_iterator i = paths_.begin(), e = paths_.end(); i != e; ++i) {
41  if (!search_all(endPaths_, *i)) {
42  triggerPaths_.insert(*i);
43  }
44  }
45  }
46 
48 
50  parameterSet_(pset),
51  tPaths_(parameterSet_.getParameter<StringVector>("@trigger_paths")),
52  triggerPaths_() {
53  for (StringVector::const_iterator i = tPaths_.begin(), e = tPaths_.end(); i != e; ++i) {
54  triggerPaths_.insert(*i);
55  }
56  }
57 
59 
60  //------------------------------------------------------------
61 
63  ParameterSetIdConverter& idConverter,
64  bool alreadyByReference) :
65  parameterSets_(),
66  mainParameterSets_(),
67  triggerPaths_(),
68  replace_(),
69  parameterSetIdConverter_(idConverter)
70  {
71  for (ParameterSetMap::const_iterator i = psetMap.begin(), iEnd = psetMap.end(); i != iEnd; ++i) {
72  parameterSets_.push_back(std::make_pair(i->second.pset(), i->first));
73  }
74  if (alreadyByReference) {
76  } else {
77  replace_.insert(std::make_pair(std::string("=+p({})"), std::string("=+q({})")));
79  }
80  for (std::vector<MainParameterSet>::iterator j = mainParameterSets_.begin(), jEnd = mainParameterSets_.end(); j != jEnd; ++j) {
81  for (std::vector<TriggerPath>::iterator i = triggerPaths_.begin(), iEnd = triggerPaths_.end(); i != iEnd; ++i) {
82  if (i->triggerPaths_ == j->triggerPaths_) {
83  j->parameterSet_.addParameter("@trigger_paths", i->parameterSet_);
84  break;
85  }
86  }
87  }
88  for (std::vector<MainParameterSet>::iterator i = mainParameterSets_.begin(), iEnd = mainParameterSets_.end(); i != iEnd; ++i) {
89  ParameterSet& pset = i->parameterSet_;
90  pset.registerIt();
91  ParameterSetID newID(pset.id());
92  if (i->oldID_ != newID && i->oldID_ != ParameterSetID()) {
93  parameterSetIdConverter_.insert(std::make_pair(i->oldID_, newID));
94  }
95  }
96  }
97 
99 
100  void
102  for (StringWithIDList::iterator i = parameterSets_.begin(), iEnd = parameterSets_.end(); i != iEnd; ++i) {
103  if (i->first.find("@all_sources") != std::string::npos) {
104  mainParameterSets_.push_back(MainParameterSet(i->second, i->first));
105  } else {
106  ParameterSet pset(i->first);
107  pset.setID(i->second);
109  if (i->first.find("@trigger_paths") != std::string::npos) {
110  triggerPaths_.push_back(pset);
111  }
112  }
113  }
114  }
115 
116  void
118  std::string const comma(",");
119  std::string const rparam(")");
120  std::string const rvparam("})");
121  std::string const loldparam("=+P(");
122  std::string const loldvparam("=+p({");
123  std::string const lparam("=+Q(");
124  std::string const lvparam("=+q({");
125  bool doItAgain = false;
126  for (StringMap::const_iterator j = replace_.begin(), jEnd = replace_.end(); j != jEnd; ++j) {
127  for (StringWithIDList::iterator i = parameterSets_.begin(), iEnd = parameterSets_.end(); i != iEnd; ++i) {
128  for (std::string::size_type it = i->first.find(j->first); it != std::string::npos; it = i->first.find(j->first)) {
129  i->first.replace(it, j->first.size(), j->second);
130  doItAgain = true;
131  }
132  }
133  }
134  for (StringWithIDList::iterator i = parameterSets_.begin(), iEnd = parameterSets_.end(); i != iEnd; ++i) {
135  if (i->first.find("+P") == std::string::npos && i->first.find("+p") == std::string::npos) {
136  if (i->first.find("@all_sources") != std::string::npos) {
137  mainParameterSets_.push_back(MainParameterSet(i->second, i->first));
138  } else {
139  ParameterSet pset(i->first);
140  pset.registerIt();
141  std::string& from = i->first;
142  std::string to;
143  ParameterSetID newID(pset.id());
144  newID.toString(to);
145  insertIntoReplace(replace_, loldparam, from, rparam, lparam, to, rparam);
146  insertIntoReplace(replace_, comma, from, comma, comma, to, comma);
147  insertIntoReplace(replace_, comma, from, rvparam, comma, to, rvparam);
148  insertIntoReplace(replace_, loldvparam, from, comma, lvparam, to, comma);
149  insertIntoReplace(replace_, loldvparam, from, rvparam, lvparam, to, rvparam);
150  if (i->second != newID && i->second != ParameterSetID()) {
151  parameterSetIdConverter_.insert(std::make_pair(i->second, newID));
152  }
153  if (i->first.find("@trigger_paths") != std::string::npos) {
154  triggerPaths_.push_back(pset);
155  }
156  }
157  StringWithIDList::iterator icopy = i;
158  ++i;
159  parameterSets_.erase(icopy);
160  --i;
161  doItAgain = true;
162  }
163  }
164  if (!doItAgain && !parameterSets_.empty()) {
165  for (StringWithIDList::iterator i = parameterSets_.begin(), iEnd = parameterSets_.end(); i != iEnd; ++i) {
166  std::list<std::string> pieces;
167  split(std::back_inserter(pieces), i->first, '<', ';', '>');
168  for (std::list<std::string>::iterator i= pieces.begin(), e = pieces.end(); i != e; ++i) {
169  std::string removeName = i->substr(i->find('+'));
170  if (removeName.size() >= 4) {
171  if (removeName[1] == 'P') {
172  std::string psetString(removeName.begin()+3, removeName.end()-1);
173  parameterSets_.push_back(std::make_pair(psetString, ParameterSetID()));
174  doItAgain = true;
175  } else if (removeName[1] == 'p') {
176  std::string pvec = std::string(removeName.begin()+3, removeName.end()-1);
178  split(std::back_inserter(temp), pvec, '{', ',', '}');
179  for (StringList::const_iterator j = temp.begin(), f = temp.end(); j != f; ++j) {
180  parameterSets_.push_back(std::make_pair(*j, ParameterSetID()));
181  }
182  doItAgain = true;
183  }
184  }
185  }
186  }
187  }
188  if (doItAgain) {
190  }
191  }
192 }
void setID(ParameterSetID const &id)
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
const_iterator end() const
Definition: StringMap.h:32
ParameterSetID id() const
TriggerPath(ParameterSet const &pset)
std::vector< std::string > StringVector
def replace(string, replacements)
const_iterator begin() const
Definition: StringMap.h:31
ParameterSetIdConverter & parameterSetIdConverter_
uint16_t size_type
ParameterSetConverter(ParameterSetMap const &psetMap, ParameterSetIdConverter &idConverter, bool alreadyByReference)
std::vector< MainParameterSet > mainParameterSets_
std::vector< TriggerPath > triggerPaths_
vector_type::const_iterator const_iterator
Definition: StringMap.h:12
std::map< ParameterSetID, ParameterSetID > ParameterSetIdConverter
double f[11][100]
std::map< std::string, std::string > StringMap
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:36
bool split(OutIter result, std::string const &string_to_split, char first, char sep, char last)
Definition: split.h:88
Hash< ParameterSetType > ParameterSetID
bool search_all(ForwardSequence const &s, Datum const &d)
Definition: Algorithms.h:46
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
std::set< std::string > triggerPaths_
HLT enums.
void toString(std::string &result) const
Definition: Hash.h:196
std::list< std::string > StringList
MainParameterSet(ParameterSetID const &oldID, std::string const &psetString)
ParameterSet const & registerIt()
std::set< std::string > triggerPaths_
static Registry * instance()
Definition: Registry.cc:13