CMS 3D CMS Logo

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