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