CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Entry.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 // definition of Entry's function members
3 // ----------------------------------------------------------------------
4 
5 
6 // ----------------------------------------------------------------------
7 // prerequisite source files and headers
8 // ----------------------------------------------------------------------
9 
15 
16 #include <map>
17 #include <sstream>
18 #include <ostream>
19 #include <assert.h>
20 #include <iostream>
21 
22 enum {
23  kTESInputTag = 'g',
25 };
26 
27 namespace edm {
28  namespace pset {
29 
30  struct TypeTrans {
31  TypeTrans();
32 
33  typedef std::vector<std::string> CodeMap;
35  std::map<std::string, char> type2Code_;
36  };
37 
39  table_['b'] = "vBool";
40  table_['B'] = "bool";
41  table_['i'] = "vint32";
42  table_['I'] = "int32";
43  table_['u'] = "vuint32";
44  table_['U'] = "uint32";
45  table_['l'] = "vint64";
46  table_['L'] = "int64";
47  table_['x'] = "vuint64";
48  table_['X'] = "uint64";
49  table_['s'] = "vstring";
50  table_['S'] = "string";
51  table_['d'] = "vdouble";
52  table_['D'] = "double";
53  table_['p'] = "vPSet";
54  table_['P'] = "PSet";
55  table_['T'] = "path";
56  table_['F'] = "FileInPath";
57  table_['t'] = "InputTag";
58  table_['v'] = "VInputTag";
59  table_[kTESInputTag] = "ESInputTag";
60  table_[kTVESInputTag] = "VESInputTag";
61  table_['e'] = "VEventID";
62  table_['E'] = "EventID";
63  table_['m'] = "VLuminosityBlockID";
64  table_['M'] = "LuminosityBlockID";
65  table_['a'] = "VLuminosityBlockRange";
66  table_['A'] = "LuminosityBlockRange";
67  table_['r'] = "VEventRange";
68  table_['R'] = "EventRange";
69 
70  for(CodeMap::const_iterator itCode = table_.begin(), itCodeEnd = table_.end();
71  itCode != itCodeEnd;
72  ++itCode) {
73  type2Code_[*itCode] = (itCode - table_.begin());
74  }
75  }
76  }
77 
79  typedef std::map<std::string, char> Type2Code;
80 
82 
83 // ----------------------------------------------------------------------
84 // consistency-checker
85 // ----------------------------------------------------------------------
86 
87  void
88  Entry::validate() const {
89  // tracked
90  assert (tracked == '+' || tracked == '-');
91 // if(tracked != '+' && tracked != '-')
92 // throw EntryError(std::string("invalid tracked code ") + tracked);
93 
94  // type and rep
95  switch(type) {
96  case 'B': { // Bool
97  bool val;
98  if (!decode(val, rep)) throwEntryError("bool", rep);
99  break;
100  }
101  case 'b': { // vBool
102  std::vector<bool> val;
103  if(!decode(val, rep)) throwEntryError("vector<bool>", rep);
104  break;
105  }
106  case 'I': { // Int32
107  int val;
108  if(!decode(val, rep)) throwEntryError("int", rep);
109  break;
110  }
111  case 'i': { // vInt32
112  std::vector<int> val;
113  if(!decode(val, rep)) throwEntryError("vector<int>", rep);
114  break;
115  }
116  case 'U': { // Uint32
117  unsigned val;
118  if(!decode(val, rep)) throwEntryError("unsigned int", rep);
119  break;
120  }
121  case 'u': { // vUint32
122  std::vector<unsigned> val;
123  if(!decode(val, rep)) throwEntryError("vector<unsigned int>", rep);
124  break;
125  }
126  case 'L': { // Int64
127  int val;
128  if(!decode(val, rep)) throwEntryError("int64", rep);
129  break;
130  }
131  case 'l': { // vInt64
132  std::vector<int> val;
133  if(!decode(val, rep)) throwEntryError("vector<int64>", rep);
134  break;
135  }
136  case 'X': { // Uint64
137  unsigned val;
138  if(!decode(val, rep)) throwEntryError("unsigned int64", rep);
139  break;
140  }
141  case 'x': { // vUint64
142  std::vector<unsigned> val;
143  if(!decode(val, rep)) throwEntryError("vector<unsigned int64>", rep);
144  break;
145  }
146  case 'S': { // String
147  std::string val;
148  if(!decode(val, rep)) throwEntryError("string", rep);
149  break;
150  }
151  case 's': { // vString
152  std::vector<std::string> val;
153  if(!decode(val, rep)) throwEntryError("vector<string>", rep);
154  break;
155  }
156  case 'F': { // FileInPath
157  FileInPath val;
158  if(!decode(val, rep)) throwEntryError("FileInPath", rep);
159  break;
160  }
161  case 't': { // InputTag
162  InputTag val;
163  if(!decode(val, rep)) throwEntryError("InputTag", rep);
164  break;
165  }
166  case 'v': { // VInputTag
167  std::vector<InputTag> val;
168  if(!decode(val, rep)) throwEntryError("VInputTag", rep);
169  break;
170  }
171  case kTESInputTag: { //ESInputTag
172  ESInputTag val;
173  if(!decode(val,rep)) throwEntryError("ESInputTag", rep);
174  break;
175  }
176  case kTVESInputTag: { //ESInputTag
177  std::vector<ESInputTag> val;
178  if(!decode(val,rep)) throwEntryError("VESInputTag", rep);
179  break;
180  }
181  case 'E': { // EventID
182  EventID val;
183  if(!decode(val, rep)) throwEntryError("EventID", rep);
184  break;
185  }
186  case 'e': { // VEventID
187  std::vector<EventID> val;
188  if(!decode(val, rep)) throwEntryError("VEventID", rep);
189  break;
190  }
191  case 'M': { // LuminosityBlockID
192  LuminosityBlockID val;
193  if(!decode(val, rep)) throwEntryError("LuminosityBlockID", rep);
194  break;
195  }
196  case 'm': { // VLuminosityBlockID
197  std::vector<LuminosityBlockID> val;
198  if(!decode(val, rep)) throwEntryError("VLuminosityBlockID", rep);
199  break;
200  }
201  case 'D': { // Double
202  double val;
203  if(!decode(val, rep)) throwEntryError("double", rep);
204  break;
205  }
206  case 'd': { // vDouble
207  std::vector<double> val;
208  if(!decode(val, rep)) throwEntryError("vector<double>", rep);
209  break;
210  }
211  case 'P': { // ParameterSet
212  ParameterSet val;
213  if(!decode(val, rep)) throwEntryError("ParameterSet", rep);
214  break;
215  }
216  case 'p': { // vParameterSet
217  std::vector<ParameterSet> val;
218  if(!decode(val, rep)) throwEntryError("vector<ParameterSet>", rep);
219  break;
220  }
221  case 'A': { // LuminosityBlockRange
223  if(!decode(val, rep)) throwEntryError("LuminosityBlockRange", rep);
224  break;
225  }
226  case 'a': { // VLuminosityBlockRange
227  std::vector<LuminosityBlockRange> val;
228  if(!decode(val, rep)) throwEntryError("VLuminosityBlockRange", rep);
229  break;
230  }
231  case 'R': { // EventRange
232  EventRange val;
233  if(!decode(val, rep)) throwEntryError("EventRange", rep);
234  break;
235  }
236  case 'r': { // VEventRange
237  std::vector<EventRange> val;
238  if(!decode(val, rep)) throwEntryError("VEventRange", rep);
239  break;
240  }
241  default: {
242  // We should never get here.
243  assert ("Invalid type code" == 0);
244  //throw EntryError(std::string("invalid type code ") + type);
245  break;
246  }
247  } // switch(type)
248  } // Entry::validate()
249 
250 // ----------------------------------------------------------------------
251 // constructors
252 // ----------------------------------------------------------------------
253 
254 // ----------------------------------------------------------------------
255 // Bool
256 
257  Entry::Entry(std::string const& name, bool val, bool is_tracked) :
258  name_(name), rep(), type('B'), tracked(is_tracked ? '+' : '-') {
259  if(!encode(rep, val)) throwEncodeError("bool");
260  validate();
261  }
262 
263 // ----------------------------------------------------------------------
264 // Int32
265 
266  Entry::Entry(std::string const& name, int val, bool is_tracked) :
267  name_(name), rep(), type('I'), tracked(is_tracked ? '+' : '-') {
268  if(!encode(rep, val)) throwEncodeError("int");
269  validate();
270  }
271 
272 // ----------------------------------------------------------------------
273 // vInt32
274 
275  Entry::Entry(std::string const& name, std::vector<int> const& val, bool is_tracked) :
276  name_(name), rep(), type('i'), tracked(is_tracked ? '+' : '-') {
277  if(!encode(rep, val)) throwEncodeError("vector<int>");
278  validate();
279  }
280 
281 // ----------------------------------------------------------------------
282 // Uint32
283 
284  Entry::Entry(std::string const& name, unsigned val, bool is_tracked) :
285  name_(name), rep(), type('U'), tracked(is_tracked ? '+' : '-') {
286  if(!encode(rep, val)) throwEncodeError("unsigned int");
287  validate();
288  }
289 
290 // ----------------------------------------------------------------------
291 // vUint32
292 
293  Entry::Entry(std::string const& name, std::vector<unsigned> const& val, bool is_tracked) :
294  name_(name), rep(), type('u'), tracked(is_tracked ? '+' : '-') {
295  if(!encode(rep, val)) throwEncodeError("vector<unsigned int>");
296  validate();
297  }
298 
299 // ----------------------------------------------------------------------
300 // Int64
301 
302  Entry::Entry(std::string const& name, long long val, bool is_tracked) :
303  name_(name), rep(), type('L'), tracked(is_tracked ? '+' : '-') {
304  if(!encode(rep, val)) throwEncodeError("int64");
305  validate();
306  }
307 
308 // ----------------------------------------------------------------------
309 // vInt64
310 
311  Entry::Entry(std::string const& name, std::vector<long long> const& val, bool is_tracked) :
312  name_(name), rep(), type('l'), tracked(is_tracked ? '+' : '-') {
313  if(!encode(rep, val)) throwEncodeError("vector<int64>");
314  validate();
315  }
316 
317 // ----------------------------------------------------------------------
318 // Uint64
319 
320  Entry::Entry(std::string const& name, unsigned long long val, bool is_tracked) :
321  name_(name), rep(), type('X'), tracked(is_tracked ? '+' : '-') {
322  if(!encode(rep, val)) throwEncodeError("unsigned int64");
323  validate();
324  }
325 
326 // ----------------------------------------------------------------------
327 // vUint64
328 
329  Entry::Entry(std::string const& name, std::vector<unsigned long long> const& val, bool is_tracked) :
330  name_(name), rep(), type('x'), tracked(is_tracked ? '+' : '-') {
331  if(!encode(rep, val)) throwEncodeError("vector<unsigned int64>");
332  validate();
333  }
334 
335 // ----------------------------------------------------------------------
336 // Double
337 
338  Entry::Entry(std::string const& name, double val, bool is_tracked) :
339  name_(name), rep(), type('D'), tracked(is_tracked ? '+' : '-') {
340  if(!encode(rep, val)) throwEncodeError("double");
341  validate();
342  }
343 
344 // ----------------------------------------------------------------------
345 // vDouble
346 
347  Entry::Entry(std::string const& name, std::vector<double> const& val, bool is_tracked) :
348  name_(name), rep(), type('d'), tracked(is_tracked ? '+' : '-') {
349  if(!encode(rep, val)) throwEncodeError("vector<double>");
350  validate();
351  }
352 
353 // ----------------------------------------------------------------------
354 // String
355 
356  Entry::Entry(std::string const& name, std::string const& val, bool is_tracked) :
357  name_(name), rep(), type('S'), tracked(is_tracked ? '+' : '-') {
358  if(!encode(rep, val)) throwEncodeError("string");
359  validate();
360  }
361 
362 // ----------------------------------------------------------------------
363 // vString
364 
365  Entry::Entry(std::string const& name, std::vector<std::string> const& val, bool is_tracked) :
366  name_(name), rep(), type('s'), tracked(is_tracked ? '+' : '-') {
367  if(!encode(rep, val)) throwEncodeError("vector<string>");
368  validate();
369  }
370 
371 // ----------------------------------------------------------------------
372 // FileInPath
373 
374  Entry::Entry(std::string const& name, FileInPath const& val, bool is_tracked) :
375  name_(name), rep(), type('F'), tracked(is_tracked ? '+' : '-') {
376  if (!encode(rep, val)) throwEncodeError("FileInPath");
377  validate();
378  }
379 
380 // ----------------------------------------------------------------------
381 // InputTag
382 
383  Entry::Entry(std::string const& name, InputTag const& val, bool is_tracked) :
384  name_(name), rep(), type('t'), tracked(is_tracked ? '+' : '-') {
385  if (!encode(rep, val)) throwEncodeError("InputTag");
386  validate();
387  }
388 
389 
390 // ----------------------------------------------------------------------
391 // VInputTag
392 
393  Entry::Entry(std::string const& name, std::vector<InputTag> const& val, bool is_tracked) :
394  name_(name), rep(), type('v'), tracked(is_tracked ? '+' : '-') {
395  if (!encode(rep, val)) throwEncodeError("VInputTag");
396  validate();
397  }
398 
399 
400 // ----------------------------------------------------------------------
401 // ESInputTag
402 
403  Entry::Entry(std::string const& name, ESInputTag const& val, bool is_tracked) :
404  name_(name), rep(), type(kTESInputTag), tracked(is_tracked ? '+' : '-') {
405  if (!encode(rep, val)) throwEncodeError("InputTag");
406  validate();
407  }
408 
409 // ----------------------------------------------------------------------
410 // VESInputTag
411 
412  Entry::Entry(std::string const& name, std::vector<ESInputTag> const& val, bool is_tracked) :
413  name_(name), rep(), type(kTVESInputTag), tracked(is_tracked ? '+' : '-') {
414  if (!encode(rep, val)) throwEncodeError("VESInputTag");
415  validate();
416  }
417 
418 
419 // ----------------------------------------------------------------------
420 // EventID
421 
422  Entry::Entry(std::string const& name, EventID const& val, bool is_tracked) :
423  name_(name), rep(), type('E'), tracked(is_tracked ? '+' : '-') {
424  if (!encode(rep, val)) throwEncodeError("EventID");
425  validate();
426  }
427 
428 
429 // ----------------------------------------------------------------------
430 // VEventID
431 
432  Entry::Entry(std::string const& name, std::vector<EventID> const& val, bool is_tracked) :
433  name_(name), rep(), type('e'), tracked(is_tracked ? '+' : '-') {
434  if (!encode(rep, val)) throwEncodeError("VEventID");
435  validate();
436  }
437 
438 
439 
440 // ----------------------------------------------------------------------
441 // LuminosityBlockID
442 
443  Entry::Entry(std::string const& name, LuminosityBlockID const& val, bool is_tracked) :
444  name_(name), rep(), type('M'), tracked(is_tracked ? '+' : '-') {
445  if (!encode(rep, val)) throwEncodeError("LuminosityBlockID");
446  validate();
447  }
448 
449 
450 // ----------------------------------------------------------------------
451 // VLuminosityBlockID
452 
453  Entry::Entry(std::string const& name, std::vector<LuminosityBlockID> const& val, bool is_tracked) :
454  name_(name), rep(), type('m'), tracked(is_tracked ? '+' : '-') {
455  if (!encode(rep, val)) throwEncodeError("VLuminosityBlockID");
456  validate();
457  }
458 
459 // ----------------------------------------------------------------------
460 // LuminosityBlockRange
461 
462  Entry::Entry(std::string const& name, LuminosityBlockRange const& val, bool is_tracked) :
463  name_(name), rep(), type('A'), tracked(is_tracked ? '+' : '-') {
464  if (!encode(rep, val)) throwEncodeError("LuminosityBlockRange");
465  validate();
466  }
467 
468 
469 // ----------------------------------------------------------------------
470 // VLuminosityBlockRange
471 
472  Entry::Entry(std::string const& name, std::vector<LuminosityBlockRange> const& val, bool is_tracked) :
473  name_(name), rep(), type('a'), tracked(is_tracked ? '+' : '-') {
474  if (!encode(rep, val)) throwEncodeError("VLuminosityBlockRange");
475  validate();
476  }
477 
478 // ----------------------------------------------------------------------
479 // EventRange
480 
481  Entry::Entry(std::string const& name, EventRange const& val, bool is_tracked) :
482  name_(name), rep(), type('R'), tracked(is_tracked ? '+' : '-') {
483  if (!encode(rep, val)) throwEncodeError("EventRange");
484  validate();
485  }
486 
487 // ----------------------------------------------------------------------
488 // VEventRange
489 
490  Entry::Entry(std::string const& name, std::vector<EventRange> const& val, bool is_tracked) :
491  name_(name), rep(), type('r'), tracked(is_tracked ? '+' : '-') {
492  if (!encode(rep, val)) throwEncodeError("VEventRange");
493  validate();
494  }
495 
496 
497 // ----------------------------------------------------------------------
498 // ParameterSet
499 
500  Entry::Entry(std::string const& name, ParameterSet const& val, bool is_tracked) :
501  name_(name), rep(), type('P'), tracked(is_tracked ? '+' : '-') {
502  if(!encode(rep, val)) throwEncodeError("ParameterSet");
503  validate();
504  }
505 
506 // ----------------------------------------------------------------------
507 // vPSet
508 
509  Entry::Entry(std::string const& name, std::vector<ParameterSet> const& val, bool is_tracked) :
510  name_(name), rep(), type('p'), tracked(is_tracked ? '+' : '-') {
511  if(!encode(rep, val)) throwEncodeError("vector<ParameterSet>");
512  validate();
513  }
514 
515 // ----------------------------------------------------------------------
516 // coded string
517 
518  Entry::Entry(std::string const& name, std::string const& code) :
519  name_(name), rep(), type('?'), tracked('?') {
520  if(!fromString(code.begin(), code.end()))
521  throwEncodeError("coded string");
522  validate();
523  }
524 
525 
526  Entry::Entry(std::string const& name, std::string const& type, std::string const& value,
527  bool is_tracked) :
528  name_(name), rep(), type('?'), tracked('?') {
529  std::string codedString(is_tracked ?"-":"+");
530 
531  Type2Code::const_iterator itFound = sTypeTranslations.type2Code_.find(type);
532  if(itFound == sTypeTranslations.type2Code_.end()) {
534  << "bad type name used for Entry : " << type;
535  }
536 
537  codedString += itFound->second;
538  codedString +='(';
539  codedString += value;
540  codedString +=')';
541 
542  if(!fromString(codedString.begin(), codedString.end())) {
544  << "bad encoded Entry string " << codedString;
545  }
546  validate();
547  }
548 
549  Entry::Entry(std::string const& name, std::string const& type,
550  std::vector<std::string> const& value,
551  bool is_tracked) :
552  name_(name), rep() , type('?'), tracked('?') {
553  std::string codedString(is_tracked ?"-":"+");
554 
555  Type2Code::const_iterator itFound =
556  sTypeTranslations.type2Code_.find(type);
557  if(itFound == sTypeTranslations.type2Code_.end()) {
559  << "bad type name used for Entry : " << type;
560  }
561 
562  codedString += itFound->second;
563  codedString += '(';
564  codedString += '{';
565  std::vector<std::string>::const_iterator i = value.begin();
566  std::vector<std::string>::const_iterator e = value.end();
567  std::string const kSeparator(",");
568  std::string sep("");
569  for(; i!= e; ++i) {
570  codedString += sep;
571  codedString += *i;
572  sep = kSeparator;
573  }
574  codedString += '}';
575  codedString += ')';
576 
577  if(!fromString(codedString.begin(), codedString.end())) {
579  << "bad encoded Entry string " << codedString;
580  }
581  validate();
582  }
583 
584 // ----------------------------------------------------------------------
585 // coding
586 // ----------------------------------------------------------------------
587 
588  void
589  Entry::toString(std::string& result) const {
590  result.reserve(result.size() + sizeOfString());
591  result += tracked;
592  result += type;
593  result += '(';
594  result += rep;
595  result += ')';
596  }
597 
598  void
599  Entry::toDigest(cms::Digest &digest) const {
600  digest.append(&tracked, 1);
601  digest.append(&type, 1);
602  digest.append("(", 1);
603  digest.append(rep);
604  digest.append(")", 1);
605  }
606 
607  std::string
608  Entry::toString() const {
609  std::string result;
610  toString(result);
611  return result;
612  }
613 
614 // ----------------------------------------------------------------------
615 
616  bool
617  Entry::fromString(std::string::const_iterator const b, std::string::const_iterator const e) {
618  if(static_cast<unsigned int>(e - b) < 4u || b[2] != '(' || e[-1] != ')')
619 
620  return false;
621 
622  tracked = b[0];
623  type = b[1];
624  rep = std::string(b+3, e-1);
625 
626  return true;
627  } // from_string()
628 
629 // ----------------------------------------------------------------------
630 // value accessors
631 // ----------------------------------------------------------------------
632 
633 
634 // ----------------------------------------------------------------------
635 // Bool
636 
637  bool
638  Entry::getBool() const {
639  if (type != 'B') throwValueError("bool");
640  bool val;
641  if (!decode(val, rep)) throwEntryError("bool", rep);
642  return val;
643  }
644 
645 
646 // ----------------------------------------------------------------------
647 // Int32
648 
649  int
650  Entry::getInt32() const {
651  if(type != 'I') throwValueError("int");
652  int val;
653  if(!decode(val, rep)) throwEntryError("int", rep);
654  return val;
655  }
656 
657 // ----------------------------------------------------------------------
658 // vInt32
659 
660  std::vector<int>
662  if(type != 'i') throwValueError("vector<int>");
663  std::vector<int> val;
664  if(!decode(val, rep)) throwEntryError("vector<int>", rep);
665  return val;
666  }
667 
668 
669 // ----------------------------------------------------------------------
670 // Int32
671 
672  long long
673  Entry::getInt64() const {
674  if(type != 'L') throwValueError("int64");
675  long long val;
676  if(!decode(val, rep)) throwEntryError("int64", rep);
677  return val;
678  }
679 
680 // ----------------------------------------------------------------------
681 // vInt32
682 
683  std::vector<long long>
685  if(type != 'l') throwValueError("vector<int64>");
686  std::vector<long long> val;
687  if(!decode(val, rep)) throwEntryError("vector<int64>", rep);
688  return val;
689  }
690 
691 
692 
693 // ----------------------------------------------------------------------
694 // Uint32
695 
696  unsigned
698  if(type != 'U') throwValueError("unsigned int");
699  unsigned val;
700  if(!decode(val, rep)) throwEntryError("unsigned int", rep);
701  return val;
702  }
703 
704 // ----------------------------------------------------------------------
705 // vUint32
706 
707  std::vector<unsigned>
709  if(type != 'u') throwValueError("vector<unsigned int>");
710  std::vector<unsigned> val;
711  if(!decode(val, rep)) throwEntryError("vector<unsigned int>", rep);
712  return val;
713  }
714 
715 
716 // ----------------------------------------------------------------------
717 // Uint64
718 
719  unsigned long long
721  if(type != 'X') throwValueError("uint64");
722  unsigned long long val;
723  if(!decode(val, rep)) throwEntryError("uint64", rep);
724  return val;
725  }
726 
727 // ----------------------------------------------------------------------
728 // vUint64
729 
730  std::vector<unsigned long long>
732  if(type != 'x') throwValueError("vector<uint64>");
733  std::vector<unsigned long long> val;
734  if(!decode(val, rep)) throwEntryError("vector<uint64>", rep);
735  return val;
736  }
737 
738 // ----------------------------------------------------------------------
739 // Double
740 
741  double
743  if(type != 'D') throwValueError("double");
744  double val;
745  if(!decode(val, rep)) throwEntryError("double", rep);
746  return val;
747  }
748 
749 // ----------------------------------------------------------------------
750 // vDouble
751 
752  std::vector<double>
754  if(type != 'd') throwValueError("vector<double>");
755  std::vector<double> val;
756  if(!decode(val, rep)) throwEntryError("vector<double>", rep);
757  return val;
758  }
759 
760 // ----------------------------------------------------------------------
761 // String
762 
763  std::string
765  if(type != 'S') throwValueError("string");
766  std::string val;
767  if(!decode(val, rep)) throwEntryError("string", rep);
768  return val;
769  }
770 
771 // ----------------------------------------------------------------------
772 // vString
773 
774  std::vector<std::string>
776  if(type != 's') throwValueError("vector<string>");
777  std::vector<std::string> val;
778  if(!decode(val, rep)) throwEntryError("vector<string>", rep);
779  return val;
780  }
781 
782 
783 // ----------------------------------------------------------------------
784 // FileInPath
785 
786  FileInPath
788  if(type != 'F') throwValueError("FileInPath");
789  FileInPath val;
790  if(!decode(val, rep)) throwEntryError("FileInPath", rep);
791  return val;
792  }
793 
794 // ----------------------------------------------------------------------
795 // InputTag
796 
797  InputTag
799  if(type != 't') throwValueError("InputTag");
800  InputTag val;
801  if(!decode(val, rep)) throwEntryError("InputTag", rep);
802  return val;
803  }
804 
805 
806 // ----------------------------------------------------------------------
807 // VInputTag
808 
809  std::vector<InputTag>
811  if(type != 'v') throwValueError("VInputTag");
812  std::vector<InputTag> val;
813  if(!decode(val, rep)) throwEntryError("VInputTag", rep);
814  return val;
815  }
816 
817 
818 // ----------------------------------------------------------------------
819 // ESInputTag
820 
821  ESInputTag
823  if(type != kTESInputTag) throwValueError("ESInputTag");
824  ESInputTag val;
825  if(!decode(val, rep)) throwEntryError("ESInputTag", rep);
826  return val;
827  }
828 
829 
830 // ----------------------------------------------------------------------
831 // VESInputTag
832 
833  std::vector<ESInputTag>
835  if(type != kTVESInputTag) throwValueError("VESInputTag");
836  std::vector<ESInputTag> val;
837  if(!decode(val, rep)) throwEntryError("VESInputTag", rep);
838  return val;
839  }
840 
841 // ----------------------------------------------------------------------
842 // EventID
843 
844  EventID
846  if(type != 'E') throwValueError("EventID");
847  EventID val;
848  if(!decode(val, rep)) throwEntryError("EventID", rep);
849  return val;
850  }
851 
852 // ----------------------------------------------------------------------
853 // VEventID
854 
855  std::vector<EventID>
857  if(type != 'e') throwValueError("VEventID");
858  std::vector<EventID> val;
859  if(!decode(val, rep)) throwEntryError("EventID", rep);
860  return val;
861  }
862 
863 
864 // ----------------------------------------------------------------------
865 // LuminosityBlockID
866 
869  if(type != 'M') throwValueError("LuminosityBlockID");
870  LuminosityBlockID val;
871  if(!decode(val, rep)) throwEntryError("LuminosityBlockID", rep);
872  return val;
873  }
874 
875 // ----------------------------------------------------------------------
876 // VLuminosityBlockID
877 
878  std::vector<LuminosityBlockID>
880  if(type != 'm') throwValueError("VLuminosityBlockID");
881  std::vector<LuminosityBlockID> val;
882  if(!decode(val, rep)) throwEntryError("LuminosityBlockID", rep);
883  return val;
884  }
885 
886 // LuminosityBlockRange
887 
890  if(type != 'A') throwValueError("LuminosityBlockRange");
892  if(!decode(val, rep)) throwEntryError("LuminosityBlockRange", rep);
893  return val;
894  }
895 
896 // ----------------------------------------------------------------------
897 // VLuminosityBlockRange
898 
899  std::vector<LuminosityBlockRange>
901  if(type != 'a') throwValueError("VLuminosityBlockRange");
902  std::vector<LuminosityBlockRange> val;
903  if(!decode(val, rep)) throwEntryError("LuminosityBlockRange", rep);
904  return val;
905  }
906 
907 // ----------------------------------------------------------------------
908 // EventRange
909 
910  EventRange
912  if(type != 'R') throwValueError("EventRange");
913  EventRange val;
914  if(!decode(val, rep)) throwEntryError("EventRange", rep);
915  return val;
916  }
917 
918 // ----------------------------------------------------------------------
919 // VEventRange
920 
921  std::vector<EventRange>
923  if(type != 'r') throwValueError("VEventRange");
924  std::vector<EventRange> val;
925  if(!decode(val, rep)) throwEntryError("EventRange", rep);
926  return val;
927  }
928 
929 // ----------------------------------------------------------------------
930 // ----------------------------------------------------------------------
931 // ParameterSet
932 
934  Entry::getPSet() const {
935  if(type != 'P') throwValueError("ParameterSet");
936  ParameterSet val;
937  if(!decode(val, rep)) throwEntryError("ParameterSet", rep);
938  return val;
939  }
940 
941 // ----------------------------------------------------------------------
942 // vPSet
943 
944  std::vector<ParameterSet>
945  Entry::getVPSet() const {
946  if(type != 'p') throwValueError("vector<ParameterSet>");
947  std::vector<ParameterSet> val;
948  if(!decode(val, rep)) throwEntryError("vector<ParameterSet>", rep);
949  return val;
950  }
951 
952 
953  std::ostream&
954  operator<< (std::ostream& os, Entry const& entry) {
955  os << sTypeTranslations.table_[entry.typeCode()] << " "
956  << (entry.isTracked() ? "tracked " : "untracked ") <<" = ";
957 
958  // now handle the difficult cases
959  switch(entry.typeCode()) {
960  case 'P': // ParameterSet
961  {
962  os << entry.getPSet();
963  break;
964  }
965  case 'p': // vector<ParameterSet>
966  {
967  // Make sure we get the representation of each contained
968  // ParameterSet including *only* tracked parameters
969  std::vector<ParameterSet> whole = entry.getVPSet();
970  std::vector<ParameterSet>::const_iterator i = whole.begin();
971  std::vector<ParameterSet>::const_iterator e = whole.end();
972  std::string start ="";
973  std::string const between(",\n");
974  os << "{"<<std::endl;
975  for (; i != e; ++i) {
976  os << start<< *i;
977  start = between;
978  }
979  if (whole.size()) {
980  os << std::endl;
981  }
982  os << "}";
983  break;
984  }
985  case 'S':
986  {
987  os << "'" << entry.getString() << "'";
988  break;
989  }
990  case 's':
991  {
992 
993  os << "{";
994  std::string start ="'";
995  std::string const between(",'");
996  std::vector<std::string> strings = entry.getVString();
997  for(std::vector<std::string>::const_iterator it = strings.begin(), itEnd = strings.end();
998  it != itEnd;
999  ++it) {
1000  os << start << *it << "'";
1001  start = between;
1002  }
1003  os << "}";
1004  break;
1005  }
1006  case 'I':
1007  {
1008  os << entry.getInt32();
1009  break;
1010  }
1011  case 'U':
1012  {
1013  os << entry.getUInt32();
1014  break;
1015  }
1016  case 'v':
1017  {
1018  //VInputTag needs to be treated seperately because it is encode like
1019  // vector<string> rather than using the individual encodings of each InputTag
1020  os << "{";
1021  std::string start = "";
1022  std::string const between(",");
1023  std::vector<InputTag> tags = entry.getVInputTag();
1024  for(std::vector<InputTag>::const_iterator it = tags.begin(), itEnd = tags.end();
1025  it != itEnd;
1026  ++it) {
1027  os << start << it->encode();
1028  start = between;
1029  }
1030  os << "}";
1031  break;
1032  }
1033  case kTVESInputTag:
1034  {
1035  //VESInputTag needs to be treated seperately because it is encode like
1036  // vector<string> rather than using the individual encodings of each ESInputTag
1037  os << "{";
1038  std::string start = "";
1039  std::string const between(",");
1040  std::vector<ESInputTag> tags = entry.getVESInputTag();
1041  for(std::vector<ESInputTag>::const_iterator it = tags.begin(), itEnd = tags.end();
1042  it != itEnd;
1043  ++it) {
1044  os << start << it->encode();
1045  start = between;
1046  }
1047  os << "}";
1048  break;
1049  }
1050  default:
1051  {
1052  os << entry.rep;
1053  break;
1054  }
1055  }
1056 
1057  return os;
1058  }
1059 
1060  // Helper functions for throwing exceptions
1061 
1062  void Entry::throwValueError(char const* expectedType) const {
1063  throw Exception(errors::Configuration, "ValueError")
1064  << "type of " << name_ << " is expected to be " << expectedType
1065  << " but declared as " << sTypeTranslations.table_[type];
1066  }
1067 
1068  void Entry::throwEntryError(char const* expectedType,
1069  std::string const& badRep) const {
1070  throw Exception(errors::Configuration, "EntryError")
1071  << "can not convert representation of " << name_ << ": "
1072  << badRep
1073  << " to value of type " << expectedType << " ";
1074  }
1075 
1076  void Entry::throwEncodeError(char const* type) const {
1077  throw Exception(errors::Configuration, "EncodingError")
1078  << "can not encode " << name_ << " as type: " << type;
1079  }
1080 
1081 
1082 }
std::vector< unsigned > getVUInt32() const
Definition: Entry.cc:708
type
Definition: HCALResponse.h:22
std::vector< double > getVDouble() const
Definition: Entry.cc:753
int i
Definition: DBlmapReader.cc:9
CodeMap table_
Definition: Entry.cc:34
std::vector< unsigned long long > getVUInt64() const
Definition: Entry.cc:731
~Entry()
Definition: Entry.cc:81
std::string rep
Definition: Entry.h:181
std::vector< LuminosityBlockID > getVLuminosityBlockID() const
Definition: Entry.cc:879
ParameterSet getPSet() const
Definition: Entry.cc:934
int getInt32() const
Definition: Entry.cc:650
unsigned getUInt32() const
Definition: Entry.cc:697
char type
Definition: Entry.h:182
bool encode(std::string &, bool)
Definition: types.cc:71
std::vector< InputTag > getVInputTag() const
Definition: Entry.cc:810
Entry(std::string const &name, bool val, bool is_tracked)
Definition: Entry.cc:257
void throwValueError(char const *expectedType) const
Definition: Entry.cc:1062
LuminosityBlockRange getLuminosityBlockRange() const
Definition: Entry.cc:889
double getDouble() const
Definition: Entry.cc:742
std::vector< EventID > getVEventID() const
Definition: Entry.cc:856
size_t sizeOfString() const
Definition: Entry.h:170
void throwEntryError(char const *expectedType, std::string const &badRep) const
Definition: Entry.cc:1068
unsigned long long getUInt64() const
Definition: Entry.cc:720
long long getInt64() const
Definition: Entry.cc:673
bool isTracked() const
Definition: Entry.h:173
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
tuple result
Definition: query.py:137
std::vector< ParameterSet > getVPSet() const
Definition: Entry.cc:945
std::map< std::string, char > Type2Code
Definition: Entry.cc:79
bool decode(bool &, std::string const &)
Definition: types.cc:62
bool getBool() const
Definition: Entry.cc:638
InputTag getInputTag() const
Definition: Entry.cc:798
void throwEncodeError(char const *type) const
Definition: Entry.cc:1076
std::vector< long long > getVInt64() const
Definition: Entry.cc:684
std::vector< ESInputTag > getVESInputTag() const
Definition: Entry.cc:834
std::vector< EventRange > getVEventRange() const
Definition: Entry.cc:922
tuple tags
Definition: o2o.py:248
void validate() const
Definition: Entry.cc:88
std::string name_
Definition: Entry.h:180
FileInPath getFileInPath() const
Definition: Entry.cc:787
bool fromString(std::string::const_iterator b, std::string::const_iterator e)
Definition: Entry.cc:617
char tracked
Definition: Entry.h:183
std::vector< int > getVInt32() const
Definition: Entry.cc:661
double b
Definition: hdecay.h:120
LuminosityBlockID getLuminosityBlockID() const
Definition: Entry.cc:868
EventRange getEventRange() const
Definition: Entry.cc:911
std::vector< LuminosityBlockRange > getVLuminosityBlockRange() const
Definition: Entry.cc:900
char typeCode() const
Definition: Entry.h:175
ESInputTag getESInputTag() const
Definition: Entry.cc:822
void toDigest(cms::Digest &digest) const
Definition: Entry.cc:599
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
std::string toString() const
Definition: Entry.cc:608
Table table_
Definition: Actions.cc:22
std::vector< std::string > getVString() const
Definition: Entry.cc:775
std::string getString() const
Definition: Entry.cc:764
std::map< std::string, char > type2Code_
Definition: Entry.cc:35
std::vector< std::string > CodeMap
Definition: Entry.cc:33
static pset::TypeTrans const sTypeTranslations
Definition: Entry.cc:78
void append(std::string const &s)
Definition: Digest.cc:182
EventID getEventID() const
Definition: Entry.cc:845