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
edm::ParameterSetID
Hash< ParameterSetType > ParameterSetID
Definition: ParameterSetID.h:21
edm::ParameterSetConverter::mainParameterSets_
std::vector< MainParameterSet > mainParameterSets_
Definition: ParameterSetConverter.h:57
edm::pset::Registry::instance
static Registry * instance()
Definition: Registry.cc:12
ParameterSetConverter.h
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetConverter::convertParameterSets
void convertParameterSets()
Definition: ParameterSetConverter.cc:111
edm::ParameterSetConverter::triggerPaths_
std::vector< TriggerPath > triggerPaths_
Definition: ParameterSetConverter.h:58
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
edm::ParameterSetConverter::noConvertParameterSets
void noConvertParameterSets()
Definition: ParameterSetConverter.cc:96
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::MainParameterSet
Definition: ParameterSetConverter.h:19
findQualityFiles.comma
string comma
Definition: findQualityFiles.py:451
edm::TriggerPath::triggerPaths_
std::set< std::string > triggerPaths_
Definition: ParameterSetConverter.h:34
Algorithms.h
to
StringMap::const_iterator
vector_type::const_iterator const_iterator
Definition: StringMap.h:12
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
edm::TriggerPath::~TriggerPath
~TriggerPath()
Definition: ParameterSetConverter.cc:55
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::ParameterSetMap
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
Definition: ParameterSetConverter.h:40
edm::MainParameterSet::endPaths_
StringVector endPaths_
Definition: ParameterSetConverter.h:25
edm::ParameterSetConverter::replace_
StringMap replace_
Definition: ParameterSetConverter.h:59
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::ParameterSetConverter::~ParameterSetConverter
~ParameterSetConverter()
Definition: ParameterSetConverter.cc:94
edm::ParameterSetConverter::StringList
std::list< std::string > StringList
Definition: ParameterSetConverter.h:43
edm::Hash< ParameterSetType >
dqmdumpme.k
k
Definition: dqmdumpme.py:60
csv2json.pieces
pieces
Definition: csv2json.py:32
edm::MainParameterSet::paths_
StringVector paths_
Definition: ParameterSetConverter.h:24
edm::MainParameterSet::MainParameterSet
MainParameterSet(ParameterSetID const &oldID, std::string const &psetString)
Definition: ParameterSetConverter.cc:30
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::TriggerPath::tPaths_
StringVector tPaths_
Definition: ParameterSetConverter.h:33
edm::ParameterSet
Definition: ParameterSet.h:36
split.h
edm::MainParameterSet::triggerPaths_
std::set< std::string > triggerPaths_
Definition: ParameterSetConverter.h:26
edm::Hash::toString
void toString(std::string &result) const
Definition: Hash.h:171
StringMap::end
const_iterator end() const
Definition: StringMap.h:32
edm::StringVector
std::vector< std::string > StringVector
Definition: ParameterSetConverter.h:17
edm::ParameterSetConverter::parameterSets_
StringWithIDList parameterSets_
Definition: ParameterSetConverter.h:56
edm::pset::Registry::insertMapped
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:32
Registry.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
StringMap::begin
const_iterator begin() const
Definition: StringMap.h:31
edm::MainParameterSet::parameterSet_
ParameterSet parameterSet_
Definition: ParameterSetConverter.h:23
edm::MainParameterSet::~MainParameterSet
~MainParameterSet()
Definition: ParameterSetConverter.cc:46
edm::ParameterSetConverter::ParameterSetConverter
ParameterSetConverter(ParameterSetMap const &psetMap, ParameterSetIdConverter &idConverter, bool alreadyByReference)
Definition: ParameterSetConverter.cc:59
edm::TriggerPath::TriggerPath
TriggerPath(ParameterSet const &pset)
Definition: ParameterSetConverter.cc:48
edm::search_all
bool search_all(ForwardSequence const &s, Datum const &d)
Definition: Algorithms.h:36
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::ParameterSetConverter::parameterSetIdConverter_
ParameterSetIdConverter & parameterSetIdConverter_
Definition: ParameterSetConverter.h:60
edm::split
bool split(OutIter result, std::string const &string_to_split, char first, char sep, char last)
Definition: split.h:68
edm::ParameterSetConverter::ParameterSetIdConverter
std::map< ParameterSetID, ParameterSetID > ParameterSetIdConverter
Definition: ParameterSetConverter.h:46
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::ParameterSetConverter::StringMap
std::map< std::string, std::string > StringMap
Definition: ParameterSetConverter.h:44
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444