File indexing completed on 2024-04-06 12:12:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "FWCore/ParameterSet/interface/Entry.h"
0010 #include "FWCore/Utilities/interface/EDMException.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ParameterSet/interface/types.h"
0013 #include "FWCore/Utilities/interface/Digest.h"
0014
0015 #include <map>
0016 #include <sstream>
0017 #include <ostream>
0018 #include <cassert>
0019 #include <iostream>
0020 #include <string_view>
0021
0022 enum : char {
0023 kTbool = 'B',
0024 kTvBool = 'b',
0025 kTint32 = 'I',
0026 kTvint32 = 'i',
0027 kTuint32 = 'U',
0028 kTvuint32 = 'u',
0029 kTint64 = 'L',
0030 kTvint64 = 'l',
0031 kTuint64 = 'X',
0032 kTvuint64 = 'x',
0033 kTstringHex = 'S',
0034 kTvstringHex = 's',
0035 kTstringRaw = 'Z',
0036 kTvstringRaw = 'z',
0037 kTdouble = 'D',
0038 kTvdouble = 'd',
0039 kTPSet = 'P',
0040 kTvPSet = 'p',
0041 kTpath = 'T',
0042 kTFileInPath = 'F',
0043 kTInputTag = 't',
0044 kTVInputTag = 'v',
0045 kTESInputTag = 'g',
0046 kTVESInputTag = 'G',
0047 kTEventID = 'E',
0048 kTVEventID = 'e',
0049 kTLuminosityBlockID = 'M',
0050 kTVLuminosityBlockID = 'm',
0051 kTLuminosityBlockRange = 'A',
0052 kTVLuminosityBlockRange = 'a',
0053 kTEventRange = 'R',
0054 kTVEventRange = 'r'
0055 };
0056
0057 static constexpr const std::array<std::string_view, 32> s_types = {{"bool",
0058 "double",
0059 "int32",
0060 "int64",
0061 "path",
0062 "string",
0063 "deprecated_string",
0064 "uint32",
0065 "uint64",
0066 "vdouble",
0067 "vint32",
0068 "vint64",
0069 "vstring",
0070 "vstring_deprecated",
0071 "vuint32",
0072 "vuint64",
0073 "vBool",
0074 "vPSet",
0075 "EventID",
0076 "EventRange",
0077 "ESInputTag",
0078 "FileInPath",
0079 "InputTag",
0080 "LuminosityBlockID",
0081 "LuminosityBlockRange",
0082 "PSet",
0083 "VEventID",
0084 "VEventRange",
0085 "VESInputTag",
0086 "VInputTag",
0087 "VLuminosityBlockID",
0088 "VLuminosityBlockRange"}};
0089
0090 static constexpr const std::array<char, 32> s_codes = {{kTbool,
0091 kTdouble,
0092 kTint32,
0093 kTint64,
0094 kTpath,
0095 kTstringRaw,
0096 kTstringHex,
0097 kTuint32,
0098 kTuint64,
0099 kTvdouble,
0100 kTvint32,
0101 kTvint64,
0102 kTvstringRaw,
0103 kTvstringHex,
0104 kTvuint32,
0105 kTvuint64,
0106 kTvBool,
0107 kTvPSet,
0108 kTEventID,
0109 kTEventRange,
0110 kTESInputTag,
0111 kTFileInPath,
0112 kTInputTag,
0113 kTLuminosityBlockID,
0114 kTLuminosityBlockRange,
0115 kTPSet,
0116 kTVEventID,
0117 kTVEventRange,
0118 kTVESInputTag,
0119 kTVInputTag,
0120 kTVLuminosityBlockID,
0121 kTVLuminosityBlockRange}};
0122
0123
0124
0125 static constexpr std::string_view c2t(char iCode) {
0126 static_assert(s_codes.size() == s_types.size());
0127 for (size_t index = 0; index < s_codes.size(); ++index) {
0128 if (s_codes[index] == iCode) {
0129 return s_types[index];
0130 }
0131 }
0132 return std::string_view();
0133 }
0134
0135 static constexpr std::array<std::string_view, 255> fillTable() {
0136 std::array<std::string_view, 255> table_ = {{std::string_view()}};
0137 static_assert(not c2t(kTvBool).empty());
0138 table_[kTvBool] = c2t(kTvBool);
0139 static_assert(not c2t(kTbool).empty());
0140 table_[kTbool] = c2t(kTbool);
0141 static_assert(not c2t(kTvint32).empty());
0142 table_[kTvint32] = c2t(kTvint32);
0143 static_assert(not c2t(kTint32).empty());
0144 table_[kTint32] = c2t(kTint32);
0145 static_assert(not c2t(kTvuint32).empty());
0146 table_[kTvuint32] = c2t(kTvuint32);
0147 static_assert(not c2t(kTuint32).empty());
0148 table_[kTuint32] = c2t(kTuint32);
0149 static_assert(not c2t(kTvint64).empty());
0150 table_[kTvint64] = c2t(kTvint64);
0151 static_assert(not c2t(kTint64).empty());
0152 table_[kTint64] = c2t(kTint64);
0153 static_assert(not c2t(kTvuint64).empty());
0154 table_[kTvuint64] = c2t(kTvuint64);
0155 static_assert(not c2t(kTuint64).empty());
0156 table_[kTuint64] = c2t(kTuint64);
0157 static_assert(not c2t(kTvstringRaw).empty());
0158 table_[kTvstringRaw] = c2t(kTvstringRaw);
0159 static_assert(not c2t(kTvstringHex).empty());
0160 table_[kTvstringHex] = c2t(kTvstringHex);
0161 static_assert(not c2t(kTstringRaw).empty());
0162 table_[kTstringRaw] = c2t(kTstringRaw);
0163 static_assert(not c2t(kTstringHex).empty());
0164 table_[kTstringHex] = c2t(kTstringHex);
0165 static_assert(not c2t(kTvdouble).empty());
0166 table_[kTvdouble] = c2t(kTvdouble);
0167 static_assert(not c2t(kTdouble).empty());
0168 table_[kTdouble] = c2t(kTdouble);
0169 static_assert(not c2t(kTvPSet).empty());
0170 table_[kTvPSet] = c2t(kTvPSet);
0171 static_assert(not c2t(kTPSet).empty());
0172 table_[kTPSet] = c2t(kTPSet);
0173 static_assert(not c2t(kTpath).empty());
0174 table_[kTpath] = c2t(kTpath);
0175 static_assert(not c2t(kTFileInPath).empty());
0176 table_[kTFileInPath] = c2t(kTFileInPath);
0177 static_assert(not c2t(kTInputTag).empty());
0178 table_[kTInputTag] = c2t(kTInputTag);
0179 static_assert(not c2t(kTVInputTag).empty());
0180 table_[kTVInputTag] = c2t(kTVInputTag);
0181 static_assert(not c2t(kTESInputTag).empty());
0182 table_[kTESInputTag] = c2t(kTESInputTag);
0183 static_assert(not c2t(kTVESInputTag).empty());
0184 table_[kTVESInputTag] = c2t(kTVESInputTag);
0185 static_assert(not c2t(kTVEventID).empty());
0186 table_[kTVEventID] = c2t(kTVEventID);
0187 static_assert(not c2t(kTFileInPath).empty());
0188 table_[kTEventID] = c2t(kTEventID);
0189 static_assert(not c2t(kTVLuminosityBlockID).empty());
0190 table_[kTVLuminosityBlockID] = c2t(kTVLuminosityBlockID);
0191 static_assert(not c2t(kTLuminosityBlockID).empty());
0192 table_[kTLuminosityBlockID] = c2t(kTLuminosityBlockID);
0193 static_assert(not c2t(kTVLuminosityBlockRange).empty());
0194 table_[kTVLuminosityBlockRange] = c2t(kTVLuminosityBlockRange);
0195 static_assert(not c2t(kTLuminosityBlockRange).empty());
0196 table_[kTLuminosityBlockRange] = c2t(kTLuminosityBlockRange);
0197 static_assert(not c2t(kTVEventRange).empty());
0198 table_[kTVEventRange] = c2t(kTVEventRange);
0199 static_assert(not c2t(kTEventRange).empty());
0200 table_[kTEventRange] = c2t(kTEventRange);
0201 return table_;
0202 }
0203
0204 static constexpr const std::array<std::string_view, 255> s_table = fillTable();
0205
0206 static constexpr std::string_view typeFromCode(char iCode) { return s_table[iCode]; }
0207
0208 static char codeFromType(std::string_view iType) {
0209 auto itFound = std::lower_bound(s_types.begin(), s_types.end(), iType);
0210 if (itFound == s_types.end() or *itFound != iType) {
0211 throw edm::Exception(edm::errors::Configuration) << "bad type name used for Entry : " << iType;
0212 }
0213 return s_codes[itFound - s_types.begin()];
0214 }
0215 namespace edm {
0216
0217
0218
0219
0220 void Entry::validate() const {
0221
0222 assert(tracked_ == '+' || tracked_ == '-');
0223
0224
0225
0226
0227 switch (type_) {
0228 case kTbool: {
0229 bool val;
0230 if (!decode(val, rep_))
0231 throwEntryError("bool", rep_);
0232 break;
0233 }
0234 case kTvBool: {
0235 std::vector<bool> val;
0236 if (!decode(val, rep_))
0237 throwEntryError("vector<bool>", rep_);
0238 break;
0239 }
0240 case kTint32: {
0241 int val;
0242 if (!decode(val, rep_))
0243 throwEntryError("int", rep_);
0244 break;
0245 }
0246 case kTvint32: {
0247 std::vector<int> val;
0248 if (!decode(val, rep_))
0249 throwEntryError("vector<int>", rep_);
0250 break;
0251 }
0252 case kTuint32: {
0253 unsigned val;
0254 if (!decode(val, rep_))
0255 throwEntryError("unsigned int", rep_);
0256 break;
0257 }
0258 case kTvuint32: {
0259 std::vector<unsigned> val;
0260 if (!decode(val, rep_))
0261 throwEntryError("vector<unsigned int>", rep_);
0262 break;
0263 }
0264 case kTint64: {
0265 long long int val;
0266 if (!decode(val, rep_))
0267 throwEntryError("int64", rep_);
0268 break;
0269 }
0270 case kTvint64: {
0271 std::vector<long long int> val;
0272 if (!decode(val, rep_))
0273 throwEntryError("vector<int64>", rep_);
0274 break;
0275 }
0276 case kTuint64: {
0277 unsigned long long int val;
0278 if (!decode(val, rep_))
0279 throwEntryError("unsigned int64", rep_);
0280 break;
0281 }
0282 case kTvuint64: {
0283 std::vector<unsigned long long int> val;
0284 if (!decode(val, rep_))
0285 throwEntryError("vector<unsigned int64>", rep_);
0286 break;
0287 }
0288 case kTstringRaw: {
0289 std::string val;
0290 if (!decode(val, rep_))
0291 throwEntryError("string", rep_);
0292 break;
0293 }
0294 case kTvstringRaw: {
0295 std::vector<std::string> val;
0296 if (!decode(val, rep_))
0297 throwEntryError("vector<string>", rep_);
0298 break;
0299 }
0300 case kTstringHex: {
0301 std::string val;
0302 if (!decode_deprecated(val, rep_))
0303 throwEntryError("string_hex", rep_);
0304 break;
0305 }
0306 case kTvstringHex: {
0307 std::vector<std::string> val;
0308 if (!decode_deprecated(val, rep_))
0309 throwEntryError("vector<string_hex>", rep_);
0310 break;
0311 }
0312
0313 case kTFileInPath: {
0314 FileInPath val;
0315 if (!decode(val, rep_))
0316 throwEntryError("FileInPath", rep_);
0317 break;
0318 }
0319 case kTInputTag: {
0320 InputTag val;
0321 if (!decode(val, rep_))
0322 throwEntryError("InputTag", rep_);
0323 break;
0324 }
0325 case kTVInputTag: {
0326 std::vector<InputTag> val;
0327 if (!decode(val, rep_))
0328 throwEntryError("VInputTag", rep_);
0329 break;
0330 }
0331 case kTESInputTag: {
0332 ESInputTag val;
0333 if (!decode(val, rep_))
0334 throwEntryError("ESInputTag", rep_);
0335 break;
0336 }
0337 case kTVESInputTag: {
0338 std::vector<ESInputTag> val;
0339 if (!decode(val, rep_))
0340 throwEntryError("VESInputTag", rep_);
0341 break;
0342 }
0343 case kTEventID: {
0344 EventID val;
0345 if (!decode(val, rep_))
0346 throwEntryError("EventID", rep_);
0347 break;
0348 }
0349 case kTVEventID: {
0350 std::vector<EventID> val;
0351 if (!decode(val, rep_))
0352 throwEntryError("VEventID", rep_);
0353 break;
0354 }
0355 case kTLuminosityBlockID: {
0356 LuminosityBlockID val;
0357 if (!decode(val, rep_))
0358 throwEntryError("LuminosityBlockID", rep_);
0359 break;
0360 }
0361 case kTVLuminosityBlockID: {
0362 std::vector<LuminosityBlockID> val;
0363 if (!decode(val, rep_))
0364 throwEntryError("VLuminosityBlockID", rep_);
0365 break;
0366 }
0367 case kTdouble: {
0368 double val;
0369 if (!decode(val, rep_))
0370 throwEntryError("double", rep_);
0371 break;
0372 }
0373 case kTvdouble: {
0374 std::vector<double> val;
0375 if (!decode(val, rep_))
0376 throwEntryError("vector<double>", rep_);
0377 break;
0378 }
0379 case kTPSet: {
0380 ParameterSet val;
0381 if (!decode(val, rep_))
0382 throwEntryError("ParameterSet", rep_);
0383 break;
0384 }
0385 case kTvPSet: {
0386 std::vector<ParameterSet> val;
0387 if (!decode(val, rep_))
0388 throwEntryError("vector<ParameterSet>", rep_);
0389 break;
0390 }
0391 case kTLuminosityBlockRange: {
0392 LuminosityBlockRange val;
0393 if (!decode(val, rep_))
0394 throwEntryError("LuminosityBlockRange", rep_);
0395 break;
0396 }
0397 case kTVLuminosityBlockRange: {
0398 std::vector<LuminosityBlockRange> val;
0399 if (!decode(val, rep_))
0400 throwEntryError("VLuminosityBlockRange", rep_);
0401 break;
0402 }
0403 case kTEventRange: {
0404 EventRange val;
0405 if (!decode(val, rep_))
0406 throwEntryError("EventRange", rep_);
0407 break;
0408 }
0409 case kTVEventRange: {
0410 std::vector<EventRange> val;
0411 if (!decode(val, rep_))
0412 throwEntryError("VEventRange", rep_);
0413 break;
0414 }
0415 default: {
0416
0417 throw edm::Exception(edm::errors::Configuration) << "Unknown ParameterSet Entry type encoding: '" << type_
0418 << "'.\n This could be caused by reading a file which was "
0419 "written using a newer incompatible software release.";
0420 break;
0421 }
0422 }
0423 }
0424
0425
0426
0427
0428
0429
0430
0431
0432 Entry::Entry(std::string const& name, bool val, bool is_tracked)
0433 : name_(name), rep_(), type_(kTbool), tracked_(is_tracked ? '+' : '-') {
0434 if (!encode(rep_, val))
0435 throwEncodeError("bool");
0436 validate();
0437 }
0438
0439
0440
0441
0442 Entry::Entry(std::string const& name, int val, bool is_tracked)
0443 : name_(name), rep_(), type_(kTint32), tracked_(is_tracked ? '+' : '-') {
0444 if (!encode(rep_, val))
0445 throwEncodeError("int");
0446 validate();
0447 }
0448
0449
0450
0451
0452 Entry::Entry(std::string const& name, std::vector<int> const& val, bool is_tracked)
0453 : name_(name), rep_(), type_(kTvint32), tracked_(is_tracked ? '+' : '-') {
0454 if (!encode(rep_, val))
0455 throwEncodeError("vector<int>");
0456 validate();
0457 }
0458
0459
0460
0461
0462 Entry::Entry(std::string const& name, unsigned val, bool is_tracked)
0463 : name_(name), rep_(), type_(kTuint32), tracked_(is_tracked ? '+' : '-') {
0464 if (!encode(rep_, val))
0465 throwEncodeError("unsigned int");
0466 validate();
0467 }
0468
0469
0470
0471
0472 Entry::Entry(std::string const& name, std::vector<unsigned> const& val, bool is_tracked)
0473 : name_(name), rep_(), type_(kTvuint32), tracked_(is_tracked ? '+' : '-') {
0474 if (!encode(rep_, val))
0475 throwEncodeError("vector<unsigned int>");
0476 validate();
0477 }
0478
0479
0480
0481
0482 Entry::Entry(std::string const& name, long long val, bool is_tracked)
0483 : name_(name), rep_(), type_(kTint64), tracked_(is_tracked ? '+' : '-') {
0484 if (!encode(rep_, val))
0485 throwEncodeError("int64");
0486 validate();
0487 }
0488
0489
0490
0491
0492 Entry::Entry(std::string const& name, std::vector<long long> const& val, bool is_tracked)
0493 : name_(name), rep_(), type_(kTvint64), tracked_(is_tracked ? '+' : '-') {
0494 if (!encode(rep_, val))
0495 throwEncodeError("vector<int64>");
0496 validate();
0497 }
0498
0499
0500
0501
0502 Entry::Entry(std::string const& name, unsigned long long val, bool is_tracked)
0503 : name_(name), rep_(), type_(kTuint64), tracked_(is_tracked ? '+' : '-') {
0504 if (!encode(rep_, val))
0505 throwEncodeError("unsigned int64");
0506 validate();
0507 }
0508
0509
0510
0511
0512 Entry::Entry(std::string const& name, std::vector<unsigned long long> const& val, bool is_tracked)
0513 : name_(name), rep_(), type_(kTvuint64), tracked_(is_tracked ? '+' : '-') {
0514 if (!encode(rep_, val))
0515 throwEncodeError("vector<unsigned int64>");
0516 validate();
0517 }
0518
0519
0520
0521
0522 Entry::Entry(std::string const& name, double val, bool is_tracked)
0523 : name_(name), rep_(), type_(kTdouble), tracked_(is_tracked ? '+' : '-') {
0524 if (!encode(rep_, val))
0525 throwEncodeError("double");
0526 validate();
0527 }
0528
0529
0530
0531
0532 Entry::Entry(std::string const& name, std::vector<double> const& val, bool is_tracked)
0533 : name_(name), rep_(), type_(kTvdouble), tracked_(is_tracked ? '+' : '-') {
0534 if (!encode(rep_, val))
0535 throwEncodeError("vector<double>");
0536 validate();
0537 }
0538
0539
0540
0541
0542 Entry::Entry(std::string const& name, std::string const& val, bool is_tracked)
0543 : name_(name), rep_(), type_(kTstringRaw), tracked_(is_tracked ? '+' : '-') {
0544 if (!encode(rep_, val))
0545 throwEncodeError("string");
0546 validate();
0547 }
0548
0549
0550
0551
0552 Entry::Entry(std::string const& name, std::vector<std::string> const& val, bool is_tracked)
0553 : name_(name), rep_(), type_(kTvstringRaw), tracked_(is_tracked ? '+' : '-') {
0554 if (!encode(rep_, val))
0555 throwEncodeError("vector<string>");
0556 validate();
0557 }
0558
0559
0560
0561
0562 Entry::Entry(std::string const& name, FileInPath const& val, bool is_tracked)
0563 : name_(name), rep_(), type_(kTFileInPath), tracked_(is_tracked ? '+' : '-') {
0564 if (!encode(rep_, val))
0565 throwEncodeError("FileInPath");
0566 validate();
0567 }
0568
0569
0570
0571
0572 Entry::Entry(std::string const& name, InputTag const& val, bool is_tracked)
0573 : name_(name), rep_(), type_(kTInputTag), tracked_(is_tracked ? '+' : '-') {
0574 if (!encode(rep_, val))
0575 throwEncodeError("InputTag");
0576 validate();
0577 }
0578
0579
0580
0581
0582 Entry::Entry(std::string const& name, std::vector<InputTag> const& val, bool is_tracked)
0583 : name_(name), rep_(), type_(kTVInputTag), tracked_(is_tracked ? '+' : '-') {
0584 if (!encode(rep_, val))
0585 throwEncodeError("VInputTag");
0586 validate();
0587 }
0588
0589
0590
0591
0592 Entry::Entry(std::string const& name, ESInputTag const& val, bool is_tracked)
0593 : name_(name), rep_(), type_(kTESInputTag), tracked_(is_tracked ? '+' : '-') {
0594 if (!encode(rep_, val))
0595 throwEncodeError("InputTag");
0596 validate();
0597 }
0598
0599
0600
0601
0602 Entry::Entry(std::string const& name, std::vector<ESInputTag> const& val, bool is_tracked)
0603 : name_(name), rep_(), type_(kTVESInputTag), tracked_(is_tracked ? '+' : '-') {
0604 if (!encode(rep_, val))
0605 throwEncodeError("VESInputTag");
0606 validate();
0607 }
0608
0609
0610
0611
0612 Entry::Entry(std::string const& name, EventID const& val, bool is_tracked)
0613 : name_(name), rep_(), type_(kTEventID), tracked_(is_tracked ? '+' : '-') {
0614 if (!encode(rep_, val))
0615 throwEncodeError("EventID");
0616 validate();
0617 }
0618
0619
0620
0621
0622 Entry::Entry(std::string const& name, std::vector<EventID> const& val, bool is_tracked)
0623 : name_(name), rep_(), type_(kTVEventID), tracked_(is_tracked ? '+' : '-') {
0624 if (!encode(rep_, val))
0625 throwEncodeError("VEventID");
0626 validate();
0627 }
0628
0629
0630
0631
0632 Entry::Entry(std::string const& name, LuminosityBlockID const& val, bool is_tracked)
0633 : name_(name), rep_(), type_(kTLuminosityBlockID), tracked_(is_tracked ? '+' : '-') {
0634 if (!encode(rep_, val))
0635 throwEncodeError("LuminosityBlockID");
0636 validate();
0637 }
0638
0639
0640
0641
0642 Entry::Entry(std::string const& name, std::vector<LuminosityBlockID> const& val, bool is_tracked)
0643 : name_(name), rep_(), type_(kTVLuminosityBlockID), tracked_(is_tracked ? '+' : '-') {
0644 if (!encode(rep_, val))
0645 throwEncodeError("VLuminosityBlockID");
0646 validate();
0647 }
0648
0649
0650
0651
0652 Entry::Entry(std::string const& name, LuminosityBlockRange const& val, bool is_tracked)
0653 : name_(name), rep_(), type_(kTLuminosityBlockRange), tracked_(is_tracked ? '+' : '-') {
0654 if (!encode(rep_, val))
0655 throwEncodeError("LuminosityBlockRange");
0656 validate();
0657 }
0658
0659
0660
0661
0662 Entry::Entry(std::string const& name, std::vector<LuminosityBlockRange> const& val, bool is_tracked)
0663 : name_(name), rep_(), type_(kTVLuminosityBlockRange), tracked_(is_tracked ? '+' : '-') {
0664 if (!encode(rep_, val))
0665 throwEncodeError("VLuminosityBlockRange");
0666 validate();
0667 }
0668
0669
0670
0671
0672 Entry::Entry(std::string const& name, EventRange const& val, bool is_tracked)
0673 : name_(name), rep_(), type_(kTEventRange), tracked_(is_tracked ? '+' : '-') {
0674 if (!encode(rep_, val))
0675 throwEncodeError("EventRange");
0676 validate();
0677 }
0678
0679
0680
0681
0682 Entry::Entry(std::string const& name, std::vector<EventRange> const& val, bool is_tracked)
0683 : name_(name), rep_(), type_(kTVEventRange), tracked_(is_tracked ? '+' : '-') {
0684 if (!encode(rep_, val))
0685 throwEncodeError("VEventRange");
0686 validate();
0687 }
0688
0689
0690
0691
0692 Entry::Entry(std::string const& name, ParameterSet const& val, bool is_tracked)
0693 : name_(name), rep_(), type_(kTPSet), tracked_(is_tracked ? '+' : '-') {
0694 if (!encode(rep_, val))
0695 throwEncodeError("ParameterSet");
0696 validate();
0697 }
0698
0699
0700
0701
0702 Entry::Entry(std::string const& name, std::vector<ParameterSet> const& val, bool is_tracked)
0703 : name_(name), rep_(), type_(kTvPSet), tracked_(is_tracked ? '+' : '-') {
0704 if (!encode(rep_, val))
0705 throwEncodeError("vector<ParameterSet>");
0706 validate();
0707 }
0708
0709
0710
0711
0712 Entry::Entry(std::string name, std::string_view code) : name_(std::move(name)), rep_(), type_('?'), tracked_('?') {
0713 if (!fromString(code.begin(), code.end()))
0714 throwEncodeError("coded string");
0715 validate();
0716 }
0717
0718 Entry::Entry(std::string name, std::string_view type, std::string_view value, bool is_tracked)
0719 : name_(std::move(name)), rep_(), type_('?'), tracked_('?') {
0720 std::string codedString(is_tracked ? "-" : "+");
0721
0722 codedString += codeFromType(type);
0723 codedString += '(';
0724 codedString += value;
0725 codedString += ')';
0726
0727 std::string_view v = codedString;
0728 if (!fromString(v.begin(), v.end())) {
0729 throw Exception(errors::Configuration) << "bad encoded Entry string " << codedString;
0730 }
0731 validate();
0732 }
0733
0734 Entry::Entry(std::string name, std::string_view type, std::vector<std::string> const& value, bool is_tracked)
0735 : name_(std::move(name)), rep_(), type_('?'), tracked_('?') {
0736 std::string codedString(is_tracked ? "-" : "+");
0737
0738 codedString += codeFromType(type);
0739 codedString += '(';
0740 codedString += '{';
0741 std::vector<std::string>::const_iterator i = value.begin();
0742 std::vector<std::string>::const_iterator e = value.end();
0743 std::string const kSeparator(",");
0744 std::string sep("");
0745 for (; i != e; ++i) {
0746 codedString += sep;
0747 codedString += *i;
0748 sep = kSeparator;
0749 }
0750 codedString += '}';
0751 codedString += ')';
0752
0753 std::string_view v = codedString;
0754 if (!fromString(v.begin(), v.end())) {
0755 throw Exception(errors::Configuration) << "bad encoded Entry string " << codedString;
0756 }
0757 validate();
0758 }
0759
0760 std::string_view Entry::bounds(std::string_view iView, std::size_t iEndHint) {
0761 if (iView.size() < 4) {
0762 return {};
0763 }
0764 if (iView[1] == kTPSet) {
0765 auto extent = edm::decode_pset_extent(iView.substr(3));
0766 if (not extent) {
0767 return {};
0768 }
0769 return iView.substr(0, extent->size() + 3 + 1);
0770 } else if (iView[1] == kTvPSet) {
0771 auto extent = edm::decode_vpset_extent(iView.substr(3));
0772 if (not extent) {
0773 return {};
0774 }
0775 return iView.substr(0, extent->size() + 3 + 1);
0776 } else if (iView[1] != kTstringRaw and iView[1] != kTvstringRaw) {
0777 return iView.substr(0, iEndHint);
0778 }
0779 if (iView[1] == kTstringRaw) {
0780
0781
0782
0783 auto extent = edm::decode_string_extent(iView.substr(3));
0784 if (not extent) {
0785 return {};
0786 }
0787 return iView.substr(0, extent->size() + 3 + 1);
0788 }
0789
0790
0791
0792 auto extent = edm::decode_vstring_extent(iView.substr(3));
0793 if (not extent) {
0794 return {};
0795 }
0796 return iView.substr(0, extent->size() + 3 + 1);
0797 }
0798
0799
0800
0801
0802
0803 void Entry::toString(std::string& result) const {
0804 result.reserve(result.size() + sizeOfString());
0805 result += tracked_;
0806 result += type_;
0807 result += '(';
0808 result += rep_;
0809 result += ')';
0810 }
0811
0812 void Entry::toDigest(cms::Digest& digest) const {
0813 digest.append(&tracked_, 1);
0814 digest.append(&type_, 1);
0815 digest.append("(", 1);
0816 digest.append(rep_);
0817 digest.append(")", 1);
0818 }
0819
0820 std::string Entry::toString() const {
0821 std::string result;
0822 toString(result);
0823 return result;
0824 }
0825
0826
0827
0828 bool Entry::fromString(std::string_view::const_iterator const b, std::string_view::const_iterator const e) {
0829 if (static_cast<unsigned int>(e - b) < 4u || b[2] != '(' || e[-1] != ')')
0830
0831 return false;
0832
0833 tracked_ = b[0];
0834 type_ = b[1];
0835 rep_ = std::string(b + 3, e - 1);
0836
0837 return true;
0838 }
0839
0840
0841
0842
0843
0844
0845
0846
0847 bool Entry::getBool() const {
0848 if (type_ != kTbool)
0849 throwValueError("bool");
0850 bool val;
0851 if (!decode(val, rep_))
0852 throwEntryError("bool", rep_);
0853 return val;
0854 }
0855
0856
0857
0858
0859 int Entry::getInt32() const {
0860 if (type_ != kTint32)
0861 throwValueError("int");
0862 int val;
0863 if (!decode(val, rep_))
0864 throwEntryError("int", rep_);
0865 return val;
0866 }
0867
0868
0869
0870
0871 std::vector<int> Entry::getVInt32() const {
0872 if (type_ != kTvint32)
0873 throwValueError("vector<int>");
0874 std::vector<int> val;
0875 if (!decode(val, rep_))
0876 throwEntryError("vector<int>", rep_);
0877 return val;
0878 }
0879
0880
0881
0882
0883 long long Entry::getInt64() const {
0884 if (type_ != kTint64)
0885 throwValueError("int64");
0886 long long val;
0887 if (!decode(val, rep_))
0888 throwEntryError("int64", rep_);
0889 return val;
0890 }
0891
0892
0893
0894
0895 std::vector<long long> Entry::getVInt64() const {
0896 if (type_ != kTvint64)
0897 throwValueError("vector<int64>");
0898 std::vector<long long> val;
0899 if (!decode(val, rep_))
0900 throwEntryError("vector<int64>", rep_);
0901 return val;
0902 }
0903
0904
0905
0906
0907 unsigned Entry::getUInt32() const {
0908 if (type_ != kTuint32)
0909 throwValueError("unsigned int");
0910 unsigned val;
0911 if (!decode(val, rep_))
0912 throwEntryError("unsigned int", rep_);
0913 return val;
0914 }
0915
0916
0917
0918
0919 std::vector<unsigned> Entry::getVUInt32() const {
0920 if (type_ != kTvuint32)
0921 throwValueError("vector<unsigned int>");
0922 std::vector<unsigned> val;
0923 if (!decode(val, rep_))
0924 throwEntryError("vector<unsigned int>", rep_);
0925 return val;
0926 }
0927
0928
0929
0930
0931 unsigned long long Entry::getUInt64() const {
0932 if (type_ != kTuint64)
0933 throwValueError("uint64");
0934 unsigned long long val;
0935 if (!decode(val, rep_))
0936 throwEntryError("uint64", rep_);
0937 return val;
0938 }
0939
0940
0941
0942
0943 std::vector<unsigned long long> Entry::getVUInt64() const {
0944 if (type_ != kTvuint64)
0945 throwValueError("vector<uint64>");
0946 std::vector<unsigned long long> val;
0947 if (!decode(val, rep_))
0948 throwEntryError("vector<uint64>", rep_);
0949 return val;
0950 }
0951
0952
0953
0954
0955 double Entry::getDouble() const {
0956 if (type_ != kTdouble)
0957 throwValueError("double");
0958 double val;
0959 if (!decode(val, rep_))
0960 throwEntryError("double", rep_);
0961 return val;
0962 }
0963
0964
0965
0966
0967 std::vector<double> Entry::getVDouble() const {
0968 if (type_ != kTvdouble)
0969 throwValueError("vector<double>");
0970 std::vector<double> val;
0971 if (!decode(val, rep_))
0972 throwEntryError("vector<double>", rep_);
0973 return val;
0974 }
0975
0976
0977
0978
0979 std::string Entry::getString() const {
0980 if (type_ != kTstringRaw and type_ != kTstringHex)
0981 throwValueError("string");
0982 std::string val;
0983 if (type_ == kTstringHex) {
0984 if (!decode_deprecated(val, rep_)) {
0985 throwEntryError("string", rep_);
0986 }
0987 } else if (!decode(val, rep_)) {
0988 throwEntryError("string", rep_);
0989 }
0990 return val;
0991 }
0992
0993
0994
0995
0996 std::vector<std::string> Entry::getVString() const {
0997 if (type_ != kTvstringRaw and type_ != kTvstringHex)
0998 throwValueError("vector<string>");
0999 std::vector<std::string> val;
1000 if (type_ == kTvstringHex) {
1001 if (!decode_deprecated(val, rep_))
1002 throwEntryError("vector<string>", rep_);
1003 } else if (!decode(val, rep_)) {
1004 throwEntryError("vector<string>", rep_);
1005 }
1006 return val;
1007 }
1008
1009
1010
1011
1012 FileInPath Entry::getFileInPath() const {
1013 if (type_ != kTFileInPath)
1014 throwValueError("FileInPath");
1015 FileInPath val;
1016 if (!decode(val, rep_))
1017 throwEntryError("FileInPath", rep_);
1018 return val;
1019 }
1020
1021
1022
1023
1024 InputTag Entry::getInputTag() const {
1025 if (type_ != kTInputTag)
1026 throwValueError("InputTag");
1027 InputTag val;
1028 if (!decode(val, rep_))
1029 throwEntryError("InputTag", rep_);
1030 return val;
1031 }
1032
1033
1034
1035
1036 std::vector<InputTag> Entry::getVInputTag() const {
1037 if (type_ != kTVInputTag)
1038 throwValueError("VInputTag");
1039 std::vector<InputTag> val;
1040 if (!decode(val, rep_))
1041 throwEntryError("VInputTag", rep_);
1042 return val;
1043 }
1044
1045
1046
1047
1048 ESInputTag Entry::getESInputTag() const {
1049 if (type_ != kTESInputTag)
1050 throwValueError("ESInputTag");
1051 ESInputTag val;
1052 if (!decode(val, rep_))
1053 throwEntryError("ESInputTag", rep_);
1054 return val;
1055 }
1056
1057
1058
1059
1060 std::vector<ESInputTag> Entry::getVESInputTag() const {
1061 if (type_ != kTVESInputTag)
1062 throwValueError("VESInputTag");
1063 std::vector<ESInputTag> val;
1064 if (!decode(val, rep_))
1065 throwEntryError("VESInputTag", rep_);
1066 return val;
1067 }
1068
1069
1070
1071
1072 EventID Entry::getEventID() const {
1073 if (type_ != kTEventID)
1074 throwValueError("EventID");
1075 EventID val;
1076 if (!decode(val, rep_))
1077 throwEntryError("EventID", rep_);
1078 return val;
1079 }
1080
1081
1082
1083
1084 std::vector<EventID> Entry::getVEventID() const {
1085 if (type_ != kTVEventID)
1086 throwValueError("VEventID");
1087 std::vector<EventID> val;
1088 if (!decode(val, rep_))
1089 throwEntryError("EventID", rep_);
1090 return val;
1091 }
1092
1093
1094
1095
1096 LuminosityBlockID Entry::getLuminosityBlockID() const {
1097 if (type_ != kTLuminosityBlockID)
1098 throwValueError("LuminosityBlockID");
1099 LuminosityBlockID val;
1100 if (!decode(val, rep_))
1101 throwEntryError("LuminosityBlockID", rep_);
1102 return val;
1103 }
1104
1105
1106
1107
1108 std::vector<LuminosityBlockID> Entry::getVLuminosityBlockID() const {
1109 if (type_ != kTVLuminosityBlockID)
1110 throwValueError("VLuminosityBlockID");
1111 std::vector<LuminosityBlockID> val;
1112 if (!decode(val, rep_))
1113 throwEntryError("LuminosityBlockID", rep_);
1114 return val;
1115 }
1116
1117
1118
1119 LuminosityBlockRange Entry::getLuminosityBlockRange() const {
1120 if (type_ != kTLuminosityBlockRange)
1121 throwValueError("LuminosityBlockRange");
1122 LuminosityBlockRange val;
1123 if (!decode(val, rep_))
1124 throwEntryError("LuminosityBlockRange", rep_);
1125 return val;
1126 }
1127
1128
1129
1130
1131 std::vector<LuminosityBlockRange> Entry::getVLuminosityBlockRange() const {
1132 if (type_ != kTVLuminosityBlockRange)
1133 throwValueError("VLuminosityBlockRange");
1134 std::vector<LuminosityBlockRange> val;
1135 if (!decode(val, rep_))
1136 throwEntryError("LuminosityBlockRange", rep_);
1137 return val;
1138 }
1139
1140
1141
1142
1143 EventRange Entry::getEventRange() const {
1144 if (type_ != kTEventRange)
1145 throwValueError("EventRange");
1146 EventRange val;
1147 if (!decode(val, rep_))
1148 throwEntryError("EventRange", rep_);
1149 return val;
1150 }
1151
1152
1153
1154
1155 std::vector<EventRange> Entry::getVEventRange() const {
1156 if (type_ != kTVEventRange)
1157 throwValueError("VEventRange");
1158 std::vector<EventRange> val;
1159 if (!decode(val, rep_))
1160 throwEntryError("EventRange", rep_);
1161 return val;
1162 }
1163
1164
1165
1166
1167
1168 ParameterSet Entry::getPSet() const {
1169 if (type_ != kTPSet)
1170 throwValueError("ParameterSet");
1171 ParameterSet val;
1172 if (!decode(val, rep_))
1173 throwEntryError("ParameterSet", rep_);
1174 return val;
1175 }
1176
1177
1178
1179
1180 std::vector<ParameterSet> Entry::getVPSet() const {
1181 if (type_ != kTvPSet)
1182 throwValueError("vector<ParameterSet>");
1183 std::vector<ParameterSet> val;
1184 if (!decode(val, rep_))
1185 throwEntryError("vector<ParameterSet>", rep_);
1186 return val;
1187 }
1188
1189 std::ostream& operator<<(std::ostream& os, Entry const& entry) {
1190 os << typeFromCode(entry.typeCode()) << " " << (entry.isTracked() ? "tracked " : "untracked ") << " = ";
1191
1192
1193 switch (entry.typeCode()) {
1194 case kTPSet:
1195 {
1196 os << entry.getPSet();
1197 break;
1198 }
1199 case 'p':
1200 {
1201
1202
1203 std::vector<ParameterSet> whole = entry.getVPSet();
1204 std::vector<ParameterSet>::const_iterator i = whole.begin();
1205 std::vector<ParameterSet>::const_iterator e = whole.end();
1206 std::string start = "";
1207 std::string const between(",\n");
1208 os << "{" << std::endl;
1209 for (; i != e; ++i) {
1210 os << start << *i;
1211 start = between;
1212 }
1213 if (!whole.empty()) {
1214 os << std::endl;
1215 }
1216 os << "}";
1217 break;
1218 }
1219 case kTstringRaw: {
1220 os << "'" << entry.getString() << "'";
1221 break;
1222 }
1223 case kTvstringRaw: {
1224 os << "{";
1225 std::string_view start = "'";
1226 std::string_view const between(",'");
1227 std::vector<std::string> strings = entry.getVString();
1228 for (auto const& s : strings) {
1229 os << start << s << "'";
1230 start = between;
1231 }
1232 os << "}";
1233 break;
1234 }
1235 case kTstringHex: {
1236 os << "'" << entry.getString() << "'";
1237 break;
1238 }
1239 case kTvstringHex: {
1240 os << "{";
1241 std::string_view start = "'";
1242 std::string_view const between(",'");
1243 std::vector<std::string> strings = entry.getVString();
1244 for (auto const& s : strings) {
1245 os << start << s << "'";
1246 start = between;
1247 }
1248 os << "}";
1249 break;
1250 }
1251 case kTint32: {
1252 os << entry.getInt32();
1253 break;
1254 }
1255 case kTuint32: {
1256 os << entry.getUInt32();
1257 break;
1258 }
1259 case kTVInputTag: {
1260
1261
1262 os << "{";
1263 std::string start = "";
1264 std::string const between(",");
1265 std::vector<InputTag> tags = entry.getVInputTag();
1266 for (std::vector<InputTag>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it) {
1267 os << start << it->encode();
1268 start = between;
1269 }
1270 os << "}";
1271 break;
1272 }
1273 case kTVESInputTag: {
1274
1275
1276 os << "{";
1277 std::string start = "";
1278 std::string const between(",");
1279 std::vector<ESInputTag> tags = entry.getVESInputTag();
1280 for (std::vector<ESInputTag>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it) {
1281 os << start << it->encode();
1282 start = between;
1283 }
1284 os << "}";
1285 break;
1286 }
1287 default: {
1288 os << entry.rep_;
1289 break;
1290 }
1291 }
1292
1293 return os;
1294 }
1295
1296
1297
1298 void Entry::throwValueError(char const* expectedType) const {
1299 throw Exception(errors::Configuration, "ValueError")
1300 << "type of " << name_ << " is expected to be " << expectedType << " but declared as " << typeFromCode(type_);
1301 }
1302
1303 void Entry::throwEntryError(char const* expectedType, std::string const& badRep) const {
1304 throw Exception(errors::Configuration, "EntryError") << "can not convert representation of " << name_ << ": "
1305 << badRep << " to value of type " << expectedType << " ";
1306 }
1307
1308 void Entry::throwEncodeError(char const* type) const {
1309 throw Exception(errors::Configuration, "EncodingError") << "can not encode " << name_ << " as type: " << type;
1310 }
1311
1312 }