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