00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "FWCore/ParameterSet/interface/types.h"
00011
00012 #include "boost/lexical_cast.hpp"
00013 #include "FWCore/ParameterSet/interface/split.h"
00014 #include "FWCore/Utilities/interface/Parse.h"
00015 #include <cctype>
00016 #include <cstdlib>
00017 #include <limits>
00018 #include <sstream>
00019 #include <stdexcept>
00020 #include <cassert>
00021
00022 using namespace edm;
00023
00024
00025
00026
00027
00028
00029 static char
00030 to_hex(unsigned int i) {
00031 return i + (i < 10u ? '0' : ('A'-10));
00032 }
00033
00034
00035
00036 static unsigned int
00037 from_hex(char c) {
00038 switch(c) {
00039 case '0': case '1': case '2': case '3': case '4':
00040 case '5': case '6': case '7': case '8': case '9':
00041 return c - '0';
00042 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
00043 return 10 + c - 'a';
00044 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
00045 return 10 + c - 'A';
00046 default:
00047 return 0;
00048 }
00049 }
00050
00051
00052 static std::string
00053 to_hex_rep(unsigned int c) {
00054 char rep[] = "xy";
00055 rep[0] = to_hex(c / 16u);
00056 rep[1] = to_hex(c % 16u);
00057
00058 return rep;
00059 }
00060
00061
00062
00063
00064
00065
00066 bool
00067 edm::decode(bool& to, std::string const& from) {
00068 if(from == "true") { to = true; return true; }
00069 else if(from == "false") { to = false; return true; }
00070 else {return false;}
00071 }
00072
00073
00074
00075 bool
00076 edm::encode(std::string& to, bool from) {
00077 to = from ? "true" : "false";
00078 return true;
00079 }
00080
00081
00082
00083
00084
00085
00086 bool
00087 edm::decode(std::vector<bool>& to, std::string const& from) {
00088 std::vector<std::string> temp;
00089 if(!split(std::back_inserter(temp), from, '{', ',', '}')) {
00090 return false;
00091 }
00092
00093 to.clear();
00094 for(std::vector<std::string>::const_iterator b = temp.begin()
00095 , e = temp.end()
00096 ; b != e; ++b) {
00097 bool val = false;
00098 if(!decode(val, *b)) {
00099 return false;
00100 }
00101 to.push_back(val);
00102 }
00103 return true;
00104 }
00105
00106
00107
00108 bool
00109 edm::encode(std::string& to, std::vector<bool> const& from) {
00110 to = "{";
00111
00112 std::string converted;
00113 for(std::vector<bool>::const_iterator b = from.begin()
00114 , e = from.end()
00115 ; b != e; ++b) {
00116 if(!encode(converted, *b)) {
00117 return false;
00118 }
00119 if(b != from.begin()) {
00120 to += ",";
00121 }
00122 to += converted;
00123 }
00124 to += '}';
00125 return true;
00126 }
00127
00128
00129
00130
00131
00132
00133 bool
00134 edm::decode(int& to, std::string const& from) {
00135 std::string::const_iterator b = from.begin()
00136 , e = from.end();
00137
00138 if(*b != '+' && *b != '-') {
00139 return false;
00140 }
00141 int sign = (*b == '+') ? +1 : -1;
00142
00143 to = 0;
00144 while(++b != e) {
00145 if(!std::isdigit(*b)) {
00146 return false;
00147 }
00148 to = 10 * to + (*b - '0');
00149 }
00150 to *= sign;
00151
00152 return true;
00153 }
00154
00155
00156
00157 bool
00158 edm::encode(std::string& to, int from) {
00159 bool is_negative = (from < 0);
00160 if(is_negative) {
00161 from = -from;
00162 }
00163 to.clear();
00164 do {
00165 to = static_cast<char>(from % 10 + '0') + to;
00166 from /= 10;
00167 } while(from > 0);
00168 to = (is_negative ? '-' : '+') + to;
00169
00170 return true;
00171 }
00172
00173
00174
00175
00176
00177 bool
00178 edm::decode(long long& to, std::string const& from) {
00179 std::string::const_iterator b = from.begin()
00180 , e = from.end();
00181
00182 if(*b != '+' && *b != '-') {
00183 return false;
00184 }
00185 int sign = (*b == '+') ? +1 : -1;
00186
00187 to = 0;
00188 while(++b != e) {
00189 if(!std::isdigit(*b)) {
00190 return false;
00191 }
00192 to = 10 * to + (*b - '0');
00193 }
00194 to *= sign;
00195
00196 return true;
00197 }
00198
00199
00200
00201 bool
00202 edm::encode(std::string& to, long long from) {
00203 bool is_negative = (from < 0);
00204 if(is_negative) {
00205 from = -from;
00206 }
00207
00208 to.clear();
00209 do {
00210 to = static_cast<char>(from % 10 + '0') + to;
00211 from /= 10;
00212 } while(from > 0);
00213 to = (is_negative ? '-' : '+') + to;
00214
00215 return true;
00216 }
00217
00218
00219
00220
00221
00222 bool
00223 edm::decode(std::vector<int>& to, std::string const& from) {
00224 std::vector<std::string> temp;
00225 if(!split(std::back_inserter(temp), from, '{', ',', '}')) {
00226 return false;
00227 }
00228
00229 to.clear();
00230 for(std::vector<std::string>::const_iterator b = temp.begin()
00231 , e = temp.end()
00232 ; b != e; ++b) {
00233 int val = 0;
00234 if(!decode(val, *b)) {
00235 return false;
00236 }
00237 to.push_back(val);
00238 }
00239
00240 return true;
00241 }
00242
00243
00244
00245 bool
00246 edm::encode(std::string& to, std::vector<int> const& from) {
00247 to = "{";
00248
00249 std::string converted;
00250 for(std::vector<int>::const_iterator b = from.begin()
00251 , e = from.end()
00252 ; b != e; ++b) {
00253 if(!encode(converted, *b)) {
00254 return false;
00255 }
00256
00257 if(b != from.begin()) {
00258 to += ",";
00259 }
00260 to += converted;
00261 }
00262
00263 to += '}';
00264 return true;
00265 }
00266
00267
00268
00269
00270
00271 bool
00272 edm::decode(std::vector<long long>& to, std::string const& from) {
00273 std::vector<std::string> temp;
00274 if(!split(std::back_inserter(temp), from, '{', ',', '}')) {
00275 return false;
00276 }
00277
00278 to.clear();
00279 for(std::vector<std::string>::const_iterator b = temp.begin()
00280 , e = temp.end()
00281 ; b != e; ++b) {
00282 long long val = 0LL;
00283 if(!decode(val, *b)) {
00284 return false;
00285 }
00286 to.push_back(val);
00287 }
00288
00289 return true;
00290 }
00291
00292
00293
00294 bool
00295 edm::encode(std::string& to, std::vector<long long> const& from) {
00296 to = "{";
00297
00298 std::string converted;
00299 for(std::vector<long long>::const_iterator b = from.begin()
00300 , e = from.end()
00301 ; b != e; ++b) {
00302 if(!encode(converted, *b)) {
00303 return false;
00304 }
00305 if(b != from.begin()) {
00306 to += ",";
00307 }
00308 to += converted;
00309 }
00310 to += '}';
00311 return true;
00312 }
00313
00314
00315
00316
00317
00318 bool
00319 edm::decode(unsigned int& to, std::string const& from) {
00320 std::string::const_iterator b = from.begin()
00321 , e = from.end();
00322
00323 to = 0u;
00324 for(; b != e; ++b) {
00325 if(*b == 'u' || *b == 'U') {
00326 return true;
00327 }
00328 if(!std::isdigit(*b)) {
00329 return false;
00330 }
00331 to = 10u * to + (*b - '0');
00332 }
00333 return true;
00334 }
00335
00336
00337
00338 bool
00339 edm::encode(std::string& to, unsigned int from) {
00340 to.clear();
00341 do {
00342 to = static_cast<char>(from % 10 + '0') + to;
00343 from /= 10u;
00344 } while(from > 0u);
00345
00346 return true;
00347 }
00348
00349
00350
00351
00352
00353 bool
00354 edm::decode(unsigned long long& to, std::string const& from) {
00355 std::string::const_iterator b = from.begin()
00356 , e = from.end();
00357 to = 0u;
00358 for(; b != e; ++b) {
00359 if(*b == 'u' || *b == 'U') {
00360 return true;
00361 }
00362 if(!std::isdigit(*b)) {
00363 return false;
00364 }
00365 to = 10u * to + (*b - '0');
00366 }
00367 return true;
00368 }
00369
00370
00371
00372 bool
00373 edm::encode(std::string& to, unsigned long long from) {
00374 to.clear();
00375 do {
00376 to = static_cast<char>(from % 10 + '0') + to;
00377 from /= 10u;
00378 } while(from > 0u);
00379
00380 return true;
00381 }
00382
00383
00384
00385
00386
00387 bool
00388 edm::decode(std::vector<unsigned int>& to, std::string const& from) {
00389 std::vector<std::string> temp;
00390 if(!split(std::back_inserter(temp), from, '{', ',', '}')) {
00391 return false;
00392 }
00393 to.clear();
00394 for(std::vector<std::string>::const_iterator b = temp.begin()
00395 , e = temp.end()
00396 ; b != e; ++b) {
00397 unsigned int val = 0;
00398 if(!decode(val, *b)) {
00399 return false;
00400 }
00401 to.push_back(val);
00402 }
00403
00404 return true;
00405 }
00406
00407
00408
00409 bool
00410 edm::encode(std::string& to, std::vector<unsigned int> const& from) {
00411 to = "{";
00412
00413 std::string converted;
00414 for(std::vector<unsigned int>::const_iterator b = from.begin()
00415 , e = from.end()
00416 ; b != e; ++b) {
00417 if(!encode(converted, *b)) {
00418 return false;
00419 }
00420 if(b != from.begin()) {
00421 to += ",";
00422 }
00423 to += converted;
00424 }
00425
00426 to += '}';
00427 return true;
00428 }
00429
00430
00431
00432
00433
00434 bool
00435 edm::decode(std::vector<unsigned long long>& to, std::string const& from) {
00436 std::vector<std::string> temp;
00437 if(!split(std::back_inserter(temp), from, '{', ',', '}')) {
00438 return false;
00439 }
00440 to.clear();
00441 for(std::vector<std::string>::const_iterator b = temp.begin()
00442 , e = temp.end()
00443 ; b != e; ++b) {
00444 unsigned long long val = 0ULL;
00445 if(!decode(val, *b)) {
00446 return false;
00447 }
00448 to.push_back(val);
00449 }
00450
00451 return true;
00452 }
00453
00454
00455
00456 bool
00457 edm::encode(std::string& to, std::vector<unsigned long long> const& from) {
00458 to = "{";
00459
00460 std::string converted;
00461 for(std::vector<unsigned long long>::const_iterator b = from.begin()
00462 , e = from.end()
00463 ; b != e; ++b) {
00464 if(!encode(converted, *b)) {
00465 return false;
00466 }
00467
00468 if(b != from.begin()) {
00469 to += ",";
00470 }
00471 to += converted;
00472 }
00473
00474 to += '}';
00475 return true;
00476 }
00477
00478
00479
00480
00481
00482
00483 bool
00484 edm::decode(double& to, std::string const& from) {
00485 if(from == "NaN") {
00486 to = std::numeric_limits<double>::quiet_NaN();
00487 } else if(from == "+inf" || from == "inf") {
00488 to = std::numeric_limits<double>::has_infinity
00489 ? std::numeric_limits<double>::infinity()
00490 : std::numeric_limits<double>::max();
00491 } else if(from == "-inf") {
00492 to = std::numeric_limits<double>::has_infinity
00493 ? -std::numeric_limits<double>::infinity()
00494 : -std::numeric_limits<double>::max();
00495 }
00496
00497 else {
00498 try {
00499
00500 to = boost::lexical_cast<double>(from);
00501
00502 }
00503 catch(boost::bad_lexical_cast&) {
00504 return false;
00505 }
00506 }
00507 return true;
00508 }
00509
00510
00511
00512 bool
00513 edm::encode(std::string& to, double from) {
00514 std::ostringstream ost;
00515 ost.precision(std::numeric_limits<double>::digits10 + 1);
00516 ost << from;
00517 if(!ost) return false;
00518 to = ost.str();
00519 return true;
00520 }
00521
00522
00523
00524
00525
00526
00527 bool
00528 edm::decode(std::vector<double>& to, std::string const& from) {
00529 std::vector<std::string> temp;
00530 if(!split(std::back_inserter(temp), from, '{', ',', '}'))
00531 return false;
00532
00533 to.clear();
00534 for(std::vector<std::string>::const_iterator b = temp.begin()
00535 , e = temp.end()
00536 ; b != e; ++b) {
00537 double val;
00538 if(!decode(val, *b))
00539 return false;
00540 to.push_back(val);
00541 }
00542
00543 return true;
00544 }
00545
00546
00547
00548 bool
00549 edm::encode(std::string& to, std::vector<double> const& from) {
00550 to = "{";
00551
00552 std::string converted;
00553 for(std::vector<double>::const_iterator b = from.begin()
00554 , e = from.end()
00555 ; b != e; ++b) {
00556 if(!encode(converted, *b))
00557 return false;
00558
00559 if(b != from.begin())
00560 to += ",";
00561 to += converted;
00562 }
00563
00564 to += '}';
00565 return true;
00566 }
00567
00568
00569
00570
00571
00572
00573 bool
00574 edm::decode(std::string& to, std::string const& from) {
00575
00576 std::string::const_iterator b = from.begin()
00577 , e = from.end();
00578
00579 to = "";
00580 to.reserve((e-b)/2);
00581 char c = '\0';
00582 for(bool even_pos = true
00583 ; b != e; ++b, even_pos = !even_pos) {
00584 if(even_pos) {
00585
00586
00587
00588
00589
00590 c = static_cast<char>(from_hex(*b));
00591 }
00592 else {
00593
00594
00595
00596
00597
00598 c = static_cast<char>(c * 16 + from_hex(*b));
00599
00600
00601 to += c;
00602
00603
00604
00605
00606
00607 }
00608 }
00609
00610 return true;
00611 }
00612
00613
00614
00615
00616
00617
00618 bool
00619 edm::decode(FileInPath& to, std::string const& from) {
00620 std::istringstream is(from);
00621 FileInPath temp;
00622 is >> temp;
00623 if (!is) return false;
00624 to = temp;
00625 return true;
00626 }
00627
00628
00629
00630 bool
00631 edm::encode(std::string& to, FileInPath const& from) {
00632 std::ostringstream ost;
00633 ost << from;
00634 if (!ost) return false;
00635 to = ost.str();
00636 return true;
00637 }
00638
00639
00640
00641
00642
00643
00644 bool
00645 edm::decode(InputTag& to, std::string const& from) {
00646 to = InputTag(from);
00647 return true;
00648 }
00649
00650
00651
00652 bool
00653 edm::encode(std::string& to, InputTag const& from) {
00654 to = from.encode();
00655 return true;
00656 }
00657
00658
00659
00660
00661
00662
00663 bool
00664 edm::decode(std::vector<InputTag>& to, std::string const& from) {
00665 std::vector<std::string> strings;
00666 decode(strings, from);
00667
00668 for(std::vector<std::string>::const_iterator stringItr = strings.begin(), stringItrEnd = strings.end();
00669 stringItr != stringItrEnd; ++stringItr) {
00670 to.push_back(InputTag(*stringItr));
00671 }
00672 return true;
00673 }
00674
00675
00676
00677 bool
00678 edm::encode(std::string& to, std::vector<InputTag> const& from) {
00679 std::vector<std::string> strings;
00680 for(std::vector<InputTag>::const_iterator tagItr = from.begin(), tagItrEnd = from.end();
00681 tagItr != tagItrEnd; ++tagItr) {
00682 strings.push_back(tagItr->encode());
00683 }
00684 encode(to, strings);
00685 return true;
00686 }
00687
00688
00689
00690
00691
00692
00693
00694 bool
00695 edm::decode(ESInputTag& to, std::string const& from) {
00696 to = ESInputTag(from);
00697 return true;
00698 }
00699
00700
00701
00702 bool
00703 edm::encode(std::string& to, ESInputTag const& from) {
00704 to = from.encode();
00705 return true;
00706 }
00707
00708
00709
00710
00711
00712
00713 bool
00714 edm::decode(std::vector<ESInputTag>& to, std::string const& from) {
00715 std::vector<std::string> strings;
00716 decode(strings, from);
00717
00718 for(std::vector<std::string>::const_iterator stringItr = strings.begin(), stringItrEnd = strings.end();
00719 stringItr != stringItrEnd; ++stringItr) {
00720 to.push_back(ESInputTag(*stringItr));
00721 }
00722 return true;
00723 }
00724
00725
00726
00727 bool
00728 edm::encode(std::string& to, std::vector<ESInputTag> const& from) {
00729 std::vector<std::string> strings;
00730 for(std::vector<ESInputTag>::const_iterator tagItr = from.begin(), tagItrEnd = from.end();
00731 tagItr != tagItrEnd; ++tagItr) {
00732 strings.push_back(tagItr->encode());
00733 }
00734 encode(to, strings);
00735 return true;
00736 }
00737
00738
00739
00740
00741
00742
00743 bool
00744 edm::decode(edm::EventID& to, std::string const& from) {
00745 std::vector<std::string> tokens = edm::tokenize(from, ":");
00746 assert(tokens.size() == 2 || tokens.size() == 3);
00747 unsigned int run = strtoul(tokens[0].c_str(), 0, 0);
00748 unsigned int lumi = (tokens.size() == 2 ? 0 : strtoul(tokens[1].c_str(), 0, 0));
00749 unsigned int event = strtoul(tokens[tokens.size() - 1].c_str(), 0, 0);
00750 to = edm::EventID(run, lumi, event);
00751
00752 return true;
00753 }
00754
00755
00756
00757 bool
00758 edm::encode(std::string& to, edm::EventID const& from) {
00759 std::ostringstream os;
00760 if (from.luminosityBlock() == 0U) {
00761 os << from.run() << ":" << from.event();
00762 } else {
00763 os << from.run() << ":" << from.luminosityBlock() << ":" << from.event();
00764 }
00765 to = os.str();
00766 return true;
00767 }
00768
00769
00770
00771
00772
00773
00774 bool
00775 edm::decode(std::vector<edm::EventID>& to, std::string const& from) {
00776 std::vector<std::string> strings;
00777 decode(strings, from);
00778
00779 for(std::vector<std::string>::const_iterator stringItr = strings.begin(), stringItrEnd = strings.end();
00780 stringItr != stringItrEnd; ++stringItr) {
00781 edm::EventID eventID;
00782 decode(eventID, *stringItr);
00783 to.push_back(eventID);
00784 }
00785 return true;
00786 }
00787
00788
00789
00790 bool
00791 edm::encode(std::string& to, std::vector<edm::EventID> const& from) {
00792 std::vector<std::string> strings;
00793 for(std::vector<edm::EventID>::const_iterator idItr = from.begin(), idItrEnd = from.end();
00794 idItr != idItrEnd; ++idItr) {
00795 std::string encodedEventID;
00796 encode(encodedEventID, *idItr);
00797 strings.push_back(encodedEventID);
00798 }
00799 encode(to, strings);
00800 return true;
00801 }
00802
00803
00804
00805
00806
00807 bool
00808 edm::decode(edm::LuminosityBlockID& to, std::string const& from) {
00809 std::vector<std::string> tokens = edm::tokenize(from, ":");
00810 assert(tokens.size() == 2);
00811 unsigned int run = strtoul(tokens[0].c_str(), 0, 0);
00812 unsigned int lumi = strtoul(tokens[1].c_str(), 0, 0);
00813 to = edm::LuminosityBlockID(run, lumi);
00814 return true;
00815 }
00816
00817
00818
00819 bool
00820 edm::encode(std::string& to, edm::LuminosityBlockID const& from) {
00821 std::ostringstream os;
00822 os << from.run() << ":" << from.luminosityBlock();
00823 to = os.str();
00824 return true;
00825 }
00826
00827
00828
00829
00830
00831
00832 bool
00833 edm::decode(std::vector<edm::LuminosityBlockID>& to, std::string const& from) {
00834 std::vector<std::string> strings;
00835 decode(strings, from);
00836
00837 for(std::vector<std::string>::const_iterator stringItr = strings.begin(), stringItrEnd = strings.end();
00838 stringItr != stringItrEnd; ++stringItr) {
00839 edm::LuminosityBlockID lumiID;
00840 decode(lumiID, *stringItr);
00841 to.push_back(lumiID);
00842 }
00843 return true;
00844 }
00845
00846
00847
00848 bool
00849 edm::encode(std::string& to, std::vector<edm::LuminosityBlockID> const& from) {
00850 std::vector<std::string> strings;
00851 for(std::vector<edm::LuminosityBlockID>::const_iterator idItr = from.begin(), idItrEnd = from.end();
00852 idItr != idItrEnd; ++idItr) {
00853 std::string encodedLuminosityBlockID;
00854 encode(encodedLuminosityBlockID, *idItr);
00855 strings.push_back(encodedLuminosityBlockID);
00856 }
00857 encode(to, strings);
00858 return true;
00859 }
00860
00861
00862
00863
00864
00865
00866 bool
00867 edm::decode(edm::LuminosityBlockRange& to, std::string const& from) {
00868 std::vector<std::string> tokens = edm::tokenize(from, "-");
00869 assert(tokens.size() == 2);
00870 edm::LuminosityBlockID begin;
00871 edm::LuminosityBlockID end;
00872 edm::decode(begin,tokens[0]);
00873 edm::decode(end,tokens[1]);
00874 to = edm::LuminosityBlockRange(begin.run(), begin.luminosityBlock(),
00875 end.run(), end.luminosityBlock());
00876 return true;
00877 }
00878
00879 bool
00880 edm::encode(std::string& to, edm::LuminosityBlockRange const& from) {
00881 std::ostringstream os;
00882 os << from.startRun() << ":" << from.startLumi() << "-"
00883 << from.endRun() << ":" << from.endLumi();
00884 to = os.str();
00885 return true;
00886 }
00887
00888
00889
00890
00891
00892 bool
00893 edm::decode(std::vector<edm::LuminosityBlockRange>& to, std::string const& from) {
00894 std::vector<std::string> strings;
00895 decode(strings, from);
00896
00897 for(std::vector<std::string>::const_iterator stringItr = strings.begin(), stringItrEnd = strings.end();
00898 stringItr != stringItrEnd; ++stringItr) {
00899 edm::LuminosityBlockRange lumiRange;
00900 decode(lumiRange, *stringItr);
00901 to.push_back(lumiRange);
00902 }
00903 return true;
00904 }
00905
00906 bool
00907 edm::encode(std::string& to, std::vector<edm::LuminosityBlockRange> const& from) {
00908 std::vector<std::string> strings;
00909 for(std::vector<edm::LuminosityBlockRange>::const_iterator idItr = from.begin(), idItrEnd = from.end();
00910 idItr != idItrEnd; ++idItr) {
00911 std::string encodedLuminosityBlockRange;
00912 encode(encodedLuminosityBlockRange, *idItr);
00913 strings.push_back(encodedLuminosityBlockRange);
00914 }
00915 encode(to, strings);
00916 return true;
00917 }
00918
00919
00920
00921
00922
00923 bool
00924 edm::decode(edm::EventRange& to, std::string const& from) {
00925 std::vector<std::string> tokens = edm::tokenize(from, "-");
00926 assert(tokens.size() == 2);
00927 edm::EventID begin;
00928 edm::EventID end;
00929 edm::decode(begin,tokens[0]);
00930 edm::decode(end,tokens[1]);
00931 assert((begin.luminosityBlock() == 0) == (end.luminosityBlock() == 0));
00932 to = edm::EventRange(begin.run(), begin.luminosityBlock(), begin.event(),
00933 end.run(), end.luminosityBlock(), end.event());
00934 return true;
00935 }
00936
00937 bool
00938 edm::encode(std::string& to, edm::EventRange const& from) {
00939 std::ostringstream os;
00940 if (from.startLumi() == 0) {
00941 assert(from.endLumi() == 0);
00942 os << from.startRun() << ":" << from.startEvent() << "-"
00943 << from.endRun() << ":" << from.endEvent();
00944 } else {
00945 assert(from.endLumi() != 0);
00946 os << from.startRun() << ":" << from.startLumi() << ":" << from.startEvent() << "-"
00947 << from.endRun() << ":" << from.endLumi() << ":" << from.endEvent();
00948 }
00949 to = os.str();
00950 return true;
00951 }
00952
00953
00954
00955
00956
00957 bool
00958 edm::decode(std::vector<edm::EventRange>& to, std::string const& from) {
00959 std::vector<std::string> strings;
00960 decode(strings, from);
00961
00962 for(std::vector<std::string>::const_iterator stringItr = strings.begin(), stringItrEnd = strings.end();
00963 stringItr != stringItrEnd; ++stringItr) {
00964 edm::EventRange eventRange;
00965 decode(eventRange, *stringItr);
00966 to.push_back(eventRange);
00967 }
00968 return true;
00969 }
00970
00971 bool
00972 edm::encode(std::string& to, std::vector<edm::EventRange> const& from) {
00973 std::vector<std::string> strings;
00974 for(std::vector<edm::EventRange>::const_iterator idItr = from.begin(), idItrEnd = from.end();
00975 idItr != idItrEnd; ++idItr) {
00976 std::string encodedEventRange;
00977 encode(encodedEventRange, *idItr);
00978 strings.push_back(encodedEventRange);
00979 }
00980 encode(to, strings);
00981 return true;
00982 }
00983
00984
00985
00986 bool
00987 edm::encode(std::string& to, std::string const& from) {
00988 std::string::const_iterator b = from.begin()
00989 , e = from.end();
00990
00991 enum escape_state { NONE
00992 , BACKSLASH
00993 , HEX, HEX1
00994 , OCT1, OCT2
00995 };
00996
00997 escape_state state = NONE;
00998 int code = 0;
00999 to = "";
01000 for(; b != e; ++b) {
01001
01002 switch(state) {
01003 case NONE: {
01004 if(*b == '\\') state = BACKSLASH;
01005 else to += to_hex_rep(*b);
01006
01007 break;
01008 }
01009 case BACKSLASH: {
01010 code = 0;
01011 switch(*b) {
01012 case 'x': case 'X': {
01013 state = HEX;
01014 break;
01015 }
01016 case '0': case '1': case '2': case '3':
01017 case '4': case '5': case '6': case '7': {
01018 code = 8 * code + from_hex(*b);
01019 state = OCT1;
01020 break;
01021 }
01022 case 'n': {
01023 to += to_hex_rep(10);
01024 state = NONE;
01025 break;
01026 }
01027 case 't': {
01028 to += to_hex_rep(9);
01029 state = NONE;
01030 break;
01031 }
01032 default: {
01033 to += to_hex_rep(*b);
01034 state = NONE;
01035 break;
01036 }
01037 }
01038 break;
01039 }
01040 case HEX: {
01041 to += *b;
01042 state = HEX1;
01043 break;
01044 }
01045 case HEX1: {
01046 to += *b;
01047 state = NONE;
01048 break;
01049 }
01050 case OCT1: {
01051 switch(*b) {
01052 case '0': case '1': case '2': case '3':
01053 case '4': case '5': case '6': case '7': {
01054 code = 8 * code + from_hex(*b);
01055 state = OCT2;
01056 break;
01057 }
01058 default: {
01059 to += to_hex_rep(code);
01060 state = NONE;
01061 break;
01062 }
01063 }
01064 break;
01065 }
01066 case OCT2: {
01067 switch(*b) {
01068 case '0': case '1': case '2': case '3':
01069 case '4': case '5': case '6': case '7': {
01070 code = 8 * code + from_hex(*b);
01071 break;
01072 }
01073 default: {
01074 to += to_hex_rep(code);
01075 break;
01076 }
01077 }
01078 state = NONE;
01079 break;
01080 }
01081 default: {
01082 throw std::logic_error("can't happen");
01083 break;
01084 }
01085 }
01086 }
01087
01088 return true;
01089 }
01090
01091
01092
01093
01094
01095
01096 bool
01097 edm::decode(std::vector<std::string>& to, std::string const& from) {
01098 std::vector<std::string> temp;
01099 if(!split(std::back_inserter(temp), from, '{', ',', '}'))
01100 return false;
01101
01102 to.clear();
01103 for(std::vector<std::string>::const_iterator b = temp.begin()
01104 , e = temp.end()
01105 ; b != e; ++b) {
01106 std::string val;
01107
01108 if(*b == "XXX") {
01109 val = "";
01110 } else if(!decode(val, *b)) {
01111 return false;
01112 }
01113 to.push_back(val);
01114 }
01115
01116 return true;
01117 }
01118
01119
01120
01121 bool
01122 edm::encode(std::string& to, std::vector<std::string> const& from) {
01123 to = "{";
01124
01125 std::string converted;
01126 for(std::vector<std::string>::const_iterator b = from.begin()
01127 , e = from.end()
01128 ; b != e; ++b) {
01129
01130 if(*b == "") {
01131 converted = "XXX";
01132 } else if(!encode(converted, *b)) {
01133 return false;
01134 }
01135
01136 if(b != from.begin())
01137 to += ",";
01138 to += converted;
01139 }
01140
01141 to += '}';
01142 return true;
01143 }
01144
01145
01146
01147
01148
01149
01150 bool
01151 edm::decode(ParameterSet& to, std::string const& from) {
01152 to = ParameterSet(from);
01153 return true;
01154 }
01155
01156
01157
01158 bool
01159 edm::encode(std::string& to, ParameterSet const& from) {
01160 to = from.toString();
01161 return true;
01162 }
01163
01164
01165
01166
01167
01168
01169 bool
01170 edm::decode(std::vector<ParameterSet>& to, std::string const& from) {
01171 std::vector<std::string> temp;
01172 if(!split(std::back_inserter(temp), from, '{', ',', '}'))
01173 return false;
01174
01175 to.clear();
01176 for(std::vector<std::string>::const_iterator b = temp.begin()
01177 , e = temp.end()
01178 ; b != e; ++b) {
01179 ParameterSet val;
01180 if(!decode(val, *b)) {
01181 return false;
01182 }
01183 to.push_back(val);
01184 }
01185
01186 return true;
01187 }
01188
01189
01190
01191 bool
01192 edm::encode(std::string& to, std::vector<ParameterSet> const& from) {
01193 to = "{";
01194
01195 std::string converted;
01196 for(std::vector<ParameterSet>::const_iterator b = from.begin()
01197 , e = from.end()
01198 ; b != e; ++b) {
01199 if(!encode(converted, *b)) {
01200 return false;
01201 }
01202 if(b != from.begin()) {
01203 to += ",";
01204 }
01205 to += converted;
01206 }
01207 to += '}';
01208 return true;
01209 }
01210
01211
01212