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 // $Id: FWPSetCellEditor.cc,v 1.7 2012/09/08 06:27:35 amraktad Exp $
12 //
13 #include <boost/algorithm/string.hpp>
14 #include <sstream>
15 #include "KeySymbols.h"
16 
17 // user include files
21 
23 
24 //______________________________________________________________________________
25 
26 template <class T>
27 bool editNumericParameter(edm::ParameterSet &ps, bool tracked,
28  const std::string &label,
29  const std::string &value)
30 {
31  std::stringstream str(value);
32  T v;
33  str >> v;
34  bool fail = str.fail();
35  if (tracked)
36  ps.addParameter(label, v);
37  else
38  ps.addUntrackedParameter(label, v);
39 
40  return fail;
41 }
42 //______________________________________________________________________________
43 
44 void editStringParameter(edm::ParameterSet &ps, bool tracked,
45  const std::string &label,
46  const std::string &value)
47 {
48  if (tracked)
49  ps.addParameter(label, value);
50  else
51  ps.addUntrackedParameter(label, value);
52 }
53 
54 //______________________________________________________________________________
55 
56 void editBoolParameter(edm::ParameterSet &ps, bool tracked,
57  const std::string &label,
58  const std::string &value)
59 {
60  bool x = false;
61 
62  if (boost::iequals(value, "true")) {
63  x = true;
64  }
65  else if (boost::iequals(value, "false")){
66  x = false;
67  }
68  else {
69  fwLog(fwlog::kError) << "Invalid value. Possible values are true/false case insensitive." << std::endl;
70  return;
71  }
72  if (tracked)
73  ps.addParameter<bool>(label, x);
74  else
75  ps.addUntrackedParameter<bool>(label, x);
76 }
77 
78 //______________________________________________________________________________
79 void editFileInPath(edm::ParameterSet &ps, bool tracked,
80  const std::string &label,
81  const std::string &value)
82 {
83  if (tracked)
84  ps.addParameter(label, edm::FileInPath(value));
85  else
86  ps.addUntrackedParameter(label, edm::FileInPath(value));
87 }
88 
89 //______________________________________________________________________________
90 
91 bool editVInputTag(edm::ParameterSet &ps, bool tracked,
92  const std::string &label,
93  const std::string &value)
94 {
95  std::vector<edm::InputTag> inputTags;
96  std::stringstream iss(value);
97  std::string vitem;
98  bool fail = false;
99  size_t fst, lst;
100 
101  while (getline(iss, vitem, ','))
102  {
103  fst = vitem.find("[");
104  lst = vitem.find("]");
105 
106  if ( fst != std::string::npos )
107  vitem.erase(fst,1);
108  if ( lst != std::string::npos )
109  vitem.erase(lst,1);
110 
111  std::vector<std::string> tokens = edm::tokenize(vitem, ":");
112  size_t nwords = tokens.size();
113 
114  if ( nwords > 3 )
115  {
116  fail = true;
117  return fail;
118  }
119  else
120  {
121  std::string it_label("");
122  std::string it_instance("");
123  std::string it_process("");
124 
125  if ( nwords > 0 )
126  it_label = tokens[0];
127  if ( nwords > 1 )
128  it_instance = tokens[1];
129  if ( nwords > 2 )
130  it_process = tokens[2];
131 
132  inputTags.push_back(edm::InputTag(it_label, it_instance, it_process));
133  }
134  }
135 
136  if (tracked)
137  ps.addParameter(label, inputTags);
138  else
139  ps.addUntrackedParameter(label, inputTags);
140 
141  return fail;
142 }
143 
144 //______________________________________________________________________________
145 
146 bool editInputTag(edm::ParameterSet &ps, bool tracked,
147  const std::string &label,
148  const std::string &value)
149 {
150  std::vector<std::string> tokens = edm::tokenize(value, ":");
151  size_t nwords = tokens.size();
152 
153  bool fail;
154 
155  if ( nwords > 3 )
156  {
157  fail = true;
158  }
159  else
160  {
161  std::string it_label("");
162  std::string it_instance("");
163  std::string it_process("");
164 
165  if ( nwords > 0 )
166  it_label = tokens[0];
167  if ( nwords > 1 )
168  it_instance = tokens[1];
169  if ( nwords > 2 )
170  it_process = tokens[2];
171 
172  if ( tracked )
173  ps.addParameter(label, edm::InputTag(it_label, it_instance, it_process));
174  else
175  ps.addUntrackedParameter(label, edm::InputTag(it_label, it_instance, it_process));
176 
177  fail = false;
178  }
179 
180  return fail;
181 }
182 
183 //______________________________________________________________________________
184 
185 bool editESInputTag(edm::ParameterSet &ps, bool tracked,
186  const std::string &label,
187  const std::string &value)
188 {
189  std::vector<std::string> tokens = edm::tokenize(value, ":");
190  size_t nwords = tokens.size();
191 
192  bool fail;
193 
194  if ( nwords > 2 )
195  {
196  fail = true;
197  }
198  else
199  {
200  std::string it_module("");
201  std::string it_data("");
202 
203  if ( nwords > 0 )
204  it_module = tokens[0];
205  if ( nwords > 1 )
206  it_data = tokens[1];
207 
208  if ( tracked )
209  ps.addParameter(label, edm::ESInputTag(it_module, it_data));
210  else
211  ps.addUntrackedParameter(label, edm::ESInputTag(it_module, it_data));
212 
213  fail = false;
214  }
215 
216  return fail;
217 }
218 
219 //______________________________________________________________________________
220 template <typename T>
221 void editVectorParameter(edm::ParameterSet &ps, bool tracked,
222  const std::string &label,
223  const std::string &value)
224 {
225  std::vector<T> valueVector;
226 
227  std::stringstream iss(value);
228  std::string vitem;
229 
230  size_t fst, lst;
231 
232  while (getline(iss, vitem, ','))
233  {
234  fst = vitem.find("[");
235  lst = vitem.find("]");
236 
237  if ( fst != std::string::npos )
238  vitem.erase(fst,1);
239  if ( lst != std::string::npos )
240  vitem.erase(lst,1);
241 
242  std::stringstream oss(vitem);
243  T on;
244  oss >> on;
245 
246  valueVector.push_back(on);
247  }
248 
249  if (tracked)
250  ps.addParameter(label, valueVector);
251  else
252  ps.addUntrackedParameter(label, valueVector);
253 }
254 
255 //______________________________________________________________________________
256 
258 {
259  switch (data.type)
260  {
261  case 'I':
262  editNumericParameter<int32_t>(*parent.pset, data.tracked, data.label, GetText());
263  break;
264  case 'B':
265  editBoolParameter(*parent.pset, data.tracked, data.label, GetText());
266  break;
267  case 'U':
268  editNumericParameter<uint32_t>(*parent.pset, data.tracked, data.label, GetText());
269  break;
270  case 'D':
271  editNumericParameter<double>(*parent.pset, data.tracked, data.label, GetText());
272  break;
273  case 'L':
274  editNumericParameter<long long>(*parent.pset, data.tracked, data.label, GetText());
275  break;
276  case 'X':
277  editNumericParameter<unsigned long long>(*parent.pset, data.tracked, data.label, GetText());
278  break;
279  case 'S':
280  editStringParameter(*parent.pset, data.tracked, data.label, GetText());
281  break;
282  case 'i':
283  editVectorParameter<int32_t>(*parent.pset, data.tracked, data.label, GetText());
284  break;
285  case 'u':
286  editVectorParameter<uint32_t>(*parent.pset, data.tracked, data.label, GetText());
287  break;
288  case 'l':
289  editVectorParameter<long long>(*parent.pset, data.tracked, data.label, GetText());
290  break;
291  case 'x':
292  editVectorParameter<unsigned long long>(*parent.pset, data.tracked, data.label, GetText());
293  break;
294  case 'd':
295  editVectorParameter<double>(*parent.pset, data.tracked, data.label, GetText());
296  break;
297  case 's':
298  editVectorParameter<std::string>(*parent.pset, data.tracked, data.label, GetText());
299  break;
300  case 't':
301  editInputTag(*parent.pset, data.tracked, data.label, GetText());
302  break;
303  case 'g':
304  editESInputTag(*parent.pset, data.tracked, data.label, GetText());
305  break;
306  case 'v':
307  editVInputTag(*parent.pset, data.tracked, data.label, GetText());
308  break;
309  case 'F':
310  editFileInPath(*parent.pset, data.tracked, data.label, GetText());
311  break;
312  default:
313  fwLog(fwlog::kError) << "unsupported parameter" << std::endl;
314  UnmapWindow();
315  return false;
316  }
317  return true;
318 }
319 
320 //______________________________________________________________________________
321 
323 {
324  UInt_t keysym = event->fCode;
325 
326  if (keysym == (UInt_t) gVirtualX->KeysymToKeycode(kKey_Escape))
327  {
328  TGFrame *p = dynamic_cast<TGFrame*>(const_cast<TGWindow*>(GetParent()));
329  while (p)
330  {
331  TGMainFrame *mp = dynamic_cast<TGMainFrame*>(p);
332  // printf("editor find parent %p, %s, %p\n", p, p->ClassName(), mp);
333  if (mp)
334  {
335  return mp->HandleKey(event);
336  }
337  p = dynamic_cast<TGFrame*>(const_cast<TGWindow*>(p->GetParent()));
338  }
339  }
340 
341  return TGTextEntry::HandleKey(event);
342 }
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)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
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)
unsigned int UInt_t
Definition: FUTypes.h:12
#define fwLog(_level_)
Definition: fwLog.h:51
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:209
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
Definition: DDAxes.h:10
long double T
void editFileInPath(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)
mathSSE::Vec4< T > v
bool editInputTag(edm::ParameterSet &ps, bool tracked, const std::string &label, const std::string &value)