Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:26

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