CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FWPSetCellEditor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWInterface
4 // Class : FWPSetCellEditor
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Mon Feb 28 20:44:59 CET 2011
11 //
12 #include <boost/algorithm/string.hpp>
13 #include <sstream>
14 #include "KeySymbols.h"
15 
16 // user include files
20 
22 
23 //______________________________________________________________________________
24 
25 template <class T>
26 bool editNumericParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value) {
27  std::stringstream str(value);
28  T v;
29  str >> v;
30  bool fail = str.fail();
31  if (tracked)
32  ps.addParameter(label, v);
33  else
34  ps.addUntrackedParameter(label, v);
35 
36  return fail;
37 }
38 //______________________________________________________________________________
39 
40 void editStringParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value) {
41  if (tracked)
42  ps.addParameter(label, value);
43  else
44  ps.addUntrackedParameter(label, value);
45 }
46 
47 //______________________________________________________________________________
48 
49 void editBoolParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value) {
50  bool x = false;
51 
52  if (boost::iequals(value, "true")) {
53  x = true;
54  } else if (boost::iequals(value, "false")) {
55  x = false;
56  } else {
57  fwLog(fwlog::kError) << "Invalid value. Possible values are true/false case insensitive." << std::endl;
58  return;
59  }
60  if (tracked)
61  ps.addParameter<bool>(label, x);
62  else
63  ps.addUntrackedParameter<bool>(label, x);
64 }
65 
66 //______________________________________________________________________________
67 void editFileInPath(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value) {
68  if (tracked)
69  ps.addParameter(label, edm::FileInPath(value));
70  else
71  ps.addUntrackedParameter(label, edm::FileInPath(value));
72 }
73 
74 //______________________________________________________________________________
75 
76 bool editVInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value) {
77  std::vector<edm::InputTag> inputTags;
78  std::stringstream iss(value);
79  std::string vitem;
80  bool fail = false;
81  size_t fst, lst;
82 
83  while (getline(iss, vitem, ',')) {
84  fst = vitem.find('[');
85  lst = vitem.find(']');
86 
87  if (fst != std::string::npos)
88  vitem.erase(fst, 1);
89  if (lst != std::string::npos)
90  vitem.erase(lst, 1);
91 
92  std::vector<std::string> tokens = edm::tokenize(vitem, ":");
93  size_t nwords = tokens.size();
94 
95  if (nwords > 3) {
96  fail = true;
97  return fail;
98  } else {
99  std::string it_label("");
100  std::string it_instance("");
101  std::string it_process("");
102 
103  if (nwords > 0)
104  it_label = tokens[0];
105  if (nwords > 1)
106  it_instance = tokens[1];
107  if (nwords > 2)
108  it_process = tokens[2];
109 
110  inputTags.push_back(edm::InputTag(it_label, it_instance, it_process));
111  }
112  }
113 
114  if (tracked)
115  ps.addParameter(label, inputTags);
116  else
117  ps.addUntrackedParameter(label, inputTags);
118 
119  return fail;
120 }
121 
122 //______________________________________________________________________________
123 
124 bool editInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value) {
125  std::vector<std::string> tokens = edm::tokenize(value, ":");
126  size_t nwords = tokens.size();
127 
128  bool fail;
129 
130  if (nwords > 3) {
131  fail = true;
132  } else {
133  std::string it_label("");
134  std::string it_instance("");
135  std::string it_process("");
136 
137  if (nwords > 0)
138  it_label = tokens[0];
139  if (nwords > 1)
140  it_instance = tokens[1];
141  if (nwords > 2)
142  it_process = tokens[2];
143 
144  if (tracked)
145  ps.addParameter(label, edm::InputTag(it_label, it_instance, it_process));
146  else
147  ps.addUntrackedParameter(label, edm::InputTag(it_label, it_instance, it_process));
148 
149  fail = false;
150  }
151 
152  return fail;
153 }
154 
155 //______________________________________________________________________________
156 
157 bool editESInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value) {
158  std::vector<std::string> tokens = edm::tokenize(value, ":");
159  size_t nwords = tokens.size();
160 
161  bool fail;
162 
163  if (nwords > 2) {
164  fail = true;
165  } else {
166  std::string it_module("");
167  std::string it_data("");
168 
169  if (nwords > 0)
170  it_module = tokens[0];
171  if (nwords > 1)
172  it_data = tokens[1];
173 
174  if (tracked)
175  ps.addParameter(label, edm::ESInputTag(it_module, it_data));
176  else
177  ps.addUntrackedParameter(label, edm::ESInputTag(it_module, it_data));
178 
179  fail = false;
180  }
181 
182  return fail;
183 }
184 
185 //______________________________________________________________________________
186 template <typename T>
187 void editVectorParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value) {
188  std::vector<T> valueVector;
189 
190  std::stringstream iss(value);
191  std::string vitem;
192 
193  size_t fst, lst;
194 
195  while (getline(iss, vitem, ',')) {
196  fst = vitem.find('[');
197  lst = vitem.find(']');
198 
199  if (fst != std::string::npos)
200  vitem.erase(fst, 1);
201  if (lst != std::string::npos)
202  vitem.erase(lst, 1);
203 
204  std::stringstream oss(vitem);
205  T on;
206  oss >> on;
207 
208  valueVector.push_back(on);
209  }
210 
211  if (tracked)
212  ps.addParameter(label, valueVector);
213  else
214  ps.addUntrackedParameter(label, valueVector);
215 }
216 
217 //______________________________________________________________________________
218 
220  switch (data.type) {
221  case 'I':
222  editNumericParameter<int32_t>(*parent.pset, data.tracked, data.label, GetText());
223  break;
224  case 'B':
225  editBoolParameter(*parent.pset, data.tracked, data.label, GetText());
226  break;
227  case 'U':
228  editNumericParameter<uint32_t>(*parent.pset, data.tracked, data.label, GetText());
229  break;
230  case 'D':
231  editNumericParameter<double>(*parent.pset, data.tracked, data.label, GetText());
232  break;
233  case 'L':
234  editNumericParameter<long long>(*parent.pset, data.tracked, data.label, GetText());
235  break;
236  case 'X':
237  editNumericParameter<unsigned long long>(*parent.pset, data.tracked, data.label, GetText());
238  break;
239  case 'S':
240  editStringParameter(*parent.pset, data.tracked, data.label, GetText());
241  break;
242  case 'i':
243  editVectorParameter<int32_t>(*parent.pset, data.tracked, data.label, GetText());
244  break;
245  case 'u':
246  editVectorParameter<uint32_t>(*parent.pset, data.tracked, data.label, GetText());
247  break;
248  case 'l':
249  editVectorParameter<long long>(*parent.pset, data.tracked, data.label, GetText());
250  break;
251  case 'x':
252  editVectorParameter<unsigned long long>(*parent.pset, data.tracked, data.label, GetText());
253  break;
254  case 'd':
255  editVectorParameter<double>(*parent.pset, data.tracked, data.label, GetText());
256  break;
257  case 's':
258  editVectorParameter<std::string>(*parent.pset, data.tracked, data.label, GetText());
259  break;
260  case 't':
261  editInputTag(*parent.pset, data.tracked, data.label, GetText());
262  break;
263  case 'g':
264  editESInputTag(*parent.pset, data.tracked, data.label, GetText());
265  break;
266  case 'v':
267  editVInputTag(*parent.pset, data.tracked, data.label, GetText());
268  break;
269  case 'F':
270  editFileInPath(*parent.pset, data.tracked, data.label, GetText());
271  break;
272  default:
273  fwLog(fwlog::kError) << "unsupported parameter" << std::endl;
274  UnmapWindow();
275  return false;
276  }
277  return true;
278 }
279 
280 //______________________________________________________________________________
281 
283  UInt_t keysym = event->fCode;
284 
285  if (keysym == (UInt_t)gVirtualX->KeysymToKeycode(kKey_Escape)) {
286  TGFrame *p = dynamic_cast<TGFrame *>(const_cast<TGWindow *>(GetParent()));
287  while (p) {
288  TGMainFrame *mp = dynamic_cast<TGMainFrame *>(p);
289  // printf("editor find parent %p, %s, %p\n", p, p->ClassName(), mp);
290  if (mp) {
291  return mp->HandleKey(event);
292  }
293  p = dynamic_cast<TGFrame *>(const_cast<TGWindow *>(p->GetParent()));
294  }
295  }
296 
297  return TGTextEntry::HandleKey(event);
298 }
bool editESInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
void editVectorParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
void editStringParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
int lst[30]
bool editVInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
char const * label
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
bool apply(FWPSetTableManager::PSetData &data, FWPSetTableManager::PSetData &parent)
void editBoolParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
#define fwLog(_level_)
Definition: fwLog.h:45
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:192
std::vector< std::string > tokenize(std::string const &input, std::string const &separator)
breaks the input string into tokens, delimited by the separator
Definition: Parse.cc:52
bool editNumericParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
#define str(s)
long double T
void editFileInPath(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
bool HandleKey(Event_t *event) override
bool editInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)