CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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,
27  const std::string &label,
28  const std::string &value)
29 {
30  std::stringstream str(value);
31  T v;
32  str >> v;
33  bool fail = str.fail();
34  if (tracked)
35  ps.addParameter(label, v);
36  else
37  ps.addUntrackedParameter(label, v);
38 
39  return fail;
40 }
41 //______________________________________________________________________________
42 
43 void editStringParameter(edm::ParameterSet &ps, bool tracked,
44  const std::string &label,
45  const std::string &value)
46 {
47  if (tracked)
48  ps.addParameter(label, value);
49  else
50  ps.addUntrackedParameter(label, value);
51 }
52 
53 //______________________________________________________________________________
54 
55 void editBoolParameter(edm::ParameterSet &ps, bool tracked,
56  const std::string &label,
57  const std::string &value)
58 {
59  bool x = false;
60 
61  if (boost::iequals(value, "true")) {
62  x = true;
63  }
64  else if (boost::iequals(value, "false")){
65  x = false;
66  }
67  else {
68  fwLog(fwlog::kError) << "Invalid value. Possible values are true/false case insensitive." << std::endl;
69  return;
70  }
71  if (tracked)
72  ps.addParameter<bool>(label, x);
73  else
74  ps.addUntrackedParameter<bool>(label, x);
75 }
76 
77 //______________________________________________________________________________
78 void editFileInPath(edm::ParameterSet &ps, bool tracked,
79  const std::string &label,
80  const std::string &value)
81 {
82  if (tracked)
83  ps.addParameter(label, edm::FileInPath(value));
84  else
85  ps.addUntrackedParameter(label, edm::FileInPath(value));
86 }
87 
88 //______________________________________________________________________________
89 
90 bool editVInputTag(edm::ParameterSet &ps, bool tracked,
91  const std::string &label,
92  const std::string &value)
93 {
94  std::vector<edm::InputTag> inputTags;
95  std::stringstream iss(value);
96  std::string vitem;
97  bool fail = false;
98  size_t fst, lst;
99 
100  while (getline(iss, vitem, ','))
101  {
102  fst = vitem.find("[");
103  lst = vitem.find("]");
104 
105  if ( fst != std::string::npos )
106  vitem.erase(fst,1);
107  if ( lst != std::string::npos )
108  vitem.erase(lst,1);
109 
110  std::vector<std::string> tokens = edm::tokenize(vitem, ":");
111  size_t nwords = tokens.size();
112 
113  if ( nwords > 3 )
114  {
115  fail = true;
116  return fail;
117  }
118  else
119  {
120  std::string it_label("");
121  std::string it_instance("");
122  std::string it_process("");
123 
124  if ( nwords > 0 )
125  it_label = tokens[0];
126  if ( nwords > 1 )
127  it_instance = tokens[1];
128  if ( nwords > 2 )
129  it_process = tokens[2];
130 
131  inputTags.push_back(edm::InputTag(it_label, it_instance, it_process));
132  }
133  }
134 
135  if (tracked)
136  ps.addParameter(label, inputTags);
137  else
138  ps.addUntrackedParameter(label, inputTags);
139 
140  return fail;
141 }
142 
143 //______________________________________________________________________________
144 
145 bool editInputTag(edm::ParameterSet &ps, bool tracked,
146  const std::string &label,
147  const std::string &value)
148 {
149  std::vector<std::string> tokens = edm::tokenize(value, ":");
150  size_t nwords = tokens.size();
151 
152  bool fail;
153 
154  if ( nwords > 3 )
155  {
156  fail = true;
157  }
158  else
159  {
160  std::string it_label("");
161  std::string it_instance("");
162  std::string it_process("");
163 
164  if ( nwords > 0 )
165  it_label = tokens[0];
166  if ( nwords > 1 )
167  it_instance = tokens[1];
168  if ( nwords > 2 )
169  it_process = tokens[2];
170 
171  if ( tracked )
172  ps.addParameter(label, edm::InputTag(it_label, it_instance, it_process));
173  else
174  ps.addUntrackedParameter(label, edm::InputTag(it_label, it_instance, it_process));
175 
176  fail = false;
177  }
178 
179  return fail;
180 }
181 
182 //______________________________________________________________________________
183 
184 bool editESInputTag(edm::ParameterSet &ps, bool tracked,
185  const std::string &label,
186  const std::string &value)
187 {
188  std::vector<std::string> tokens = edm::tokenize(value, ":");
189  size_t nwords = tokens.size();
190 
191  bool fail;
192 
193  if ( nwords > 2 )
194  {
195  fail = true;
196  }
197  else
198  {
199  std::string it_module("");
200  std::string it_data("");
201 
202  if ( nwords > 0 )
203  it_module = tokens[0];
204  if ( nwords > 1 )
205  it_data = tokens[1];
206 
207  if ( tracked )
208  ps.addParameter(label, edm::ESInputTag(it_module, it_data));
209  else
210  ps.addUntrackedParameter(label, edm::ESInputTag(it_module, it_data));
211 
212  fail = false;
213  }
214 
215  return fail;
216 }
217 
218 //______________________________________________________________________________
219 template <typename T>
220 void editVectorParameter(edm::ParameterSet &ps, bool tracked,
221  const std::string &label,
222  const std::string &value)
223 {
224  std::vector<T> valueVector;
225 
226  std::stringstream iss(value);
227  std::string vitem;
228 
229  size_t fst, lst;
230 
231  while (getline(iss, vitem, ','))
232  {
233  fst = vitem.find("[");
234  lst = vitem.find("]");
235 
236  if ( fst != std::string::npos )
237  vitem.erase(fst,1);
238  if ( lst != std::string::npos )
239  vitem.erase(lst,1);
240 
241  std::stringstream oss(vitem);
242  T on;
243  oss >> on;
244 
245  valueVector.push_back(on);
246  }
247 
248  if (tracked)
249  ps.addParameter(label, valueVector);
250  else
251  ps.addUntrackedParameter(label, valueVector);
252 }
253 
254 //______________________________________________________________________________
255 
257 {
258  switch (data.type)
259  {
260  case 'I':
261  editNumericParameter<int32_t>(*parent.pset, data.tracked, data.label, GetText());
262  break;
263  case 'B':
264  editBoolParameter(*parent.pset, data.tracked, data.label, GetText());
265  break;
266  case 'U':
267  editNumericParameter<uint32_t>(*parent.pset, data.tracked, data.label, GetText());
268  break;
269  case 'D':
270  editNumericParameter<double>(*parent.pset, data.tracked, data.label, GetText());
271  break;
272  case 'L':
273  editNumericParameter<long long>(*parent.pset, data.tracked, data.label, GetText());
274  break;
275  case 'X':
276  editNumericParameter<unsigned long long>(*parent.pset, data.tracked, data.label, GetText());
277  break;
278  case 'S':
279  editStringParameter(*parent.pset, data.tracked, data.label, GetText());
280  break;
281  case 'i':
282  editVectorParameter<int32_t>(*parent.pset, data.tracked, data.label, GetText());
283  break;
284  case 'u':
285  editVectorParameter<uint32_t>(*parent.pset, data.tracked, data.label, GetText());
286  break;
287  case 'l':
288  editVectorParameter<long long>(*parent.pset, data.tracked, data.label, GetText());
289  break;
290  case 'x':
291  editVectorParameter<unsigned long long>(*parent.pset, data.tracked, data.label, GetText());
292  break;
293  case 'd':
294  editVectorParameter<double>(*parent.pset, data.tracked, data.label, GetText());
295  break;
296  case 's':
297  editVectorParameter<std::string>(*parent.pset, data.tracked, data.label, GetText());
298  break;
299  case 't':
300  editInputTag(*parent.pset, data.tracked, data.label, GetText());
301  break;
302  case 'g':
303  editESInputTag(*parent.pset, data.tracked, data.label, GetText());
304  break;
305  case 'v':
306  editVInputTag(*parent.pset, data.tracked, data.label, GetText());
307  break;
308  case 'F':
309  editFileInPath(*parent.pset, data.tracked, data.label, GetText());
310  break;
311  default:
312  fwLog(fwlog::kError) << "unsupported parameter" << std::endl;
313  UnmapWindow();
314  return false;
315  }
316  return true;
317 }
318 
319 //______________________________________________________________________________
320 
322 {
323  UInt_t keysym = event->fCode;
324 
325  if (keysym == (UInt_t) gVirtualX->KeysymToKeycode(kKey_Escape))
326  {
327  TGFrame *p = dynamic_cast<TGFrame*>(const_cast<TGWindow*>(GetParent()));
328  while (p)
329  {
330  TGMainFrame *mp = dynamic_cast<TGMainFrame*>(p);
331  // printf("editor find parent %p, %s, %p\n", p, p->ClassName(), mp);
332  if (mp)
333  {
334  return mp->HandleKey(event);
335  }
336  p = dynamic_cast<TGFrame*>(const_cast<TGWindow*>(p->GetParent()));
337  }
338  }
339 
340  return TGTextEntry::HandleKey(event);
341 }
virtual bool HandleKey(Event_t *event)
bool editESInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
list parent
Definition: dbtoconf.py:74
void editVectorParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
void valueVector(const std::map< K, V > &extract, std::vector< V > &output)
Definition: Operators.h:43
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)
T x() const
Cartesian x coordinate.
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
bool apply(FWPSetTableManager::PSetData &data, FWPSetTableManager::PSetData &parent)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void editBoolParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
#define fwLog(_level_)
Definition: fwLog.h:50
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:208
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:57
bool editNumericParameter(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
long double T
void editFileInPath(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
bool editInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)