CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/ParameterSet/src/Entry.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 // definition of Entry's function members
00003 // ----------------------------------------------------------------------
00004 
00005 
00006 // ----------------------------------------------------------------------
00007 // prerequisite source files and headers
00008 // ----------------------------------------------------------------------
00009 
00010 #include "FWCore/ParameterSet/interface/Entry.h"
00011 #include "FWCore/Utilities/interface/EDMException.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/ParameterSet/interface/types.h"
00014 
00015 #include <map>
00016 #include <sstream>
00017 #include <ostream>
00018 #include <assert.h>
00019 #include <iostream>
00020 
00021 enum {
00022    kTESInputTag  = 'g',
00023    kTVESInputTag = 'G'
00024 };
00025 
00026 namespace edm {
00027   namespace pset {
00028 
00029     struct TypeTrans {
00030       TypeTrans();
00031 
00032       typedef std::vector<std::string> CodeMap;
00033       CodeMap table_;
00034       std::map<std::string, char> type2Code_;
00035     };
00036 
00037     TypeTrans::TypeTrans():table_(255) {
00038       table_['b'] = "vBool";
00039       table_['B'] = "bool";
00040       table_['i'] = "vint32";
00041       table_['I'] = "int32";
00042       table_['u'] = "vuint32";
00043       table_['U'] = "uint32";
00044       table_['l'] = "vint64";
00045       table_['L'] = "int64";
00046       table_['x'] = "vuint64";
00047       table_['X'] = "uint64";
00048       table_['s'] = "vstring";
00049       table_['S'] = "string";
00050       table_['d'] = "vdouble";
00051       table_['D'] = "double";
00052       table_['p'] = "vPSet";
00053       table_['P'] = "PSet";
00054       table_['T'] = "path";
00055       table_['F'] = "FileInPath";
00056       table_['t'] = "InputTag";
00057       table_['v'] = "VInputTag";
00058       table_[kTESInputTag] = "ESInputTag";
00059       table_[kTVESInputTag] = "VESInputTag";
00060       table_['e'] = "VEventID";
00061       table_['E'] = "EventID";
00062       table_['m'] = "VLuminosityBlockID";
00063       table_['M'] = "LuminosityBlockID";
00064       table_['a'] = "VLuminosityBlockRange";
00065       table_['A'] = "LuminosityBlockRange";
00066       table_['r'] = "VEventRange";
00067       table_['R'] = "EventRange";
00068 
00069       for(CodeMap::const_iterator itCode = table_.begin(), itCodeEnd = table_.end();
00070            itCode != itCodeEnd;
00071            ++itCode) {
00072          type2Code_[*itCode] = (itCode - table_.begin());
00073       }
00074     }
00075   }
00076 
00077   static pset::TypeTrans const sTypeTranslations;
00078   typedef std::map<std::string, char> Type2Code;
00079 
00080   Entry::~Entry() {}
00081 
00082 // ----------------------------------------------------------------------
00083 // consistency-checker
00084 // ----------------------------------------------------------------------
00085 
00086   void
00087   Entry::validate() const {
00088     // tracked
00089     assert (tracked == '+' || tracked == '-');
00090 //     if(tracked != '+' && tracked != '-')
00091 //       throw EntryError(std::string("invalid tracked code ") + tracked);
00092 
00093     // type and rep
00094     switch(type)  {
00095       case 'B':  {  // Bool
00096         bool  val;
00097         if (!decode(val, rep)) throwEntryError("bool", rep);
00098         break;
00099       }
00100       case 'b':  {  // vBool
00101         std::vector<bool>  val;
00102         if(!decode(val, rep)) throwEntryError("vector<bool>", rep);
00103         break;
00104       }
00105       case 'I':  {  // Int32
00106         int  val;
00107         if(!decode(val, rep)) throwEntryError("int", rep);
00108         break;
00109       }
00110       case 'i':  {  // vInt32
00111         std::vector<int>  val;
00112         if(!decode(val, rep)) throwEntryError("vector<int>", rep);
00113         break;
00114       }
00115       case 'U':  {  // Uint32
00116         unsigned  val;
00117         if(!decode(val, rep)) throwEntryError("unsigned int", rep);
00118         break;
00119       }
00120       case 'u':  {  // vUint32
00121         std::vector<unsigned>  val;
00122         if(!decode(val, rep)) throwEntryError("vector<unsigned int>", rep);
00123         break;
00124       }
00125       case 'L':  {  // Int64
00126         int  val;
00127         if(!decode(val, rep)) throwEntryError("int64", rep);
00128         break;
00129       }
00130       case 'l':  {  // vInt64
00131         std::vector<int>  val;
00132         if(!decode(val, rep)) throwEntryError("vector<int64>", rep);
00133         break;
00134       }
00135       case 'X':  {  // Uint64
00136         unsigned  val;
00137         if(!decode(val, rep)) throwEntryError("unsigned int64", rep);
00138         break;
00139       }
00140       case 'x':  {  // vUint64
00141         std::vector<unsigned>  val;
00142         if(!decode(val, rep)) throwEntryError("vector<unsigned int64>", rep);
00143         break;
00144       }
00145       case 'S':  {  // String
00146         std::string  val;
00147         if(!decode(val, rep)) throwEntryError("string", rep);
00148         break;
00149       }
00150       case 's':  {  // vString
00151         std::vector<std::string>  val;
00152         if(!decode(val, rep)) throwEntryError("vector<string>", rep);
00153         break;
00154       }
00155       case 'F':  {  // FileInPath
00156         FileInPath val;
00157         if(!decode(val, rep)) throwEntryError("FileInPath", rep);
00158         break;
00159       }
00160       case 't':  {  // InputTag
00161         InputTag val;
00162         if(!decode(val, rep)) throwEntryError("InputTag", rep);
00163         break;
00164       }
00165       case 'v':  {  // VInputTag
00166         std::vector<InputTag> val;
00167         if(!decode(val, rep)) throwEntryError("VInputTag", rep);
00168         break;
00169       }
00170       case kTESInputTag: { //ESInputTag
00171          ESInputTag val;
00172          if(!decode(val,rep)) throwEntryError("ESInputTag", rep);
00173          break;
00174       }
00175       case kTVESInputTag: { //ESInputTag
00176          std::vector<ESInputTag> val;
00177          if(!decode(val,rep)) throwEntryError("VESInputTag", rep);
00178          break;
00179       }
00180       case 'E':  {  // EventID
00181         EventID val;
00182         if(!decode(val, rep)) throwEntryError("EventID", rep);
00183         break;
00184       }
00185       case 'e':  {  // VEventID
00186         std::vector<EventID> val;
00187         if(!decode(val, rep)) throwEntryError("VEventID", rep);
00188         break;
00189       }
00190       case 'M':  {  // LuminosityBlockID
00191         LuminosityBlockID val;
00192         if(!decode(val, rep)) throwEntryError("LuminosityBlockID", rep);
00193         break;
00194       }
00195       case 'm':  {  // VLuminosityBlockID
00196         std::vector<LuminosityBlockID> val;
00197         if(!decode(val, rep)) throwEntryError("VLuminosityBlockID", rep);
00198         break;
00199       }
00200       case 'D':  {  // Double
00201         double  val;
00202         if(!decode(val, rep)) throwEntryError("double", rep);
00203         break;
00204       }
00205       case 'd':  {  // vDouble
00206         std::vector<double>  val;
00207         if(!decode(val, rep)) throwEntryError("vector<double>", rep);
00208         break;
00209       }
00210       case 'P':  {  // ParameterSet
00211         ParameterSet val;
00212         if(!decode(val, rep)) throwEntryError("ParameterSet", rep);
00213         break;
00214       }
00215       case 'p':  {  // vParameterSet
00216         std::vector<ParameterSet>  val;
00217         if(!decode(val, rep)) throwEntryError("vector<ParameterSet>", rep);
00218         break;
00219       }
00220       case 'A':  {  // LuminosityBlockRange
00221         LuminosityBlockRange val;
00222         if(!decode(val, rep)) throwEntryError("LuminosityBlockRange", rep);
00223         break;
00224       }
00225       case 'a':  {  // VLuminosityBlockRange
00226         std::vector<LuminosityBlockRange> val;
00227         if(!decode(val, rep)) throwEntryError("VLuminosityBlockRange", rep);
00228         break;
00229       }
00230       case 'R':  {  // EventRange
00231         EventRange val;
00232         if(!decode(val, rep)) throwEntryError("EventRange", rep);
00233         break;
00234       }
00235       case 'r':  {  // VEventRange
00236         std::vector<EventRange> val;
00237         if(!decode(val, rep)) throwEntryError("VEventRange", rep);
00238         break;
00239       }
00240       default:  {
00241         // We should never get here.
00242         assert ("Invalid type code" == 0);
00243         //throw EntryError(std::string("invalid type code ") + type);
00244         break;
00245       }
00246     }  // switch(type)
00247   }  // Entry::validate()
00248 
00249 // ----------------------------------------------------------------------
00250 // constructors
00251 // ----------------------------------------------------------------------
00252 
00253 // ----------------------------------------------------------------------
00254 // Bool
00255 
00256   Entry::Entry(std::string const& name, bool val, bool is_tracked) :
00257     name_(name), rep(), type('B'), tracked(is_tracked ? '+' : '-') {
00258     if(!encode(rep, val)) throwEncodeError("bool");
00259     validate();
00260   }
00261 
00262 // ----------------------------------------------------------------------
00263 // Int32
00264 
00265   Entry::Entry(std::string const& name, int  val, bool is_tracked) :
00266     name_(name), rep(), type('I'), tracked(is_tracked ? '+' : '-') {
00267     if(!encode(rep, val)) throwEncodeError("int");
00268     validate();
00269   }
00270 
00271 // ----------------------------------------------------------------------
00272 // vInt32
00273 
00274   Entry::Entry(std::string const& name, std::vector<int> const& val, bool is_tracked) :
00275     name_(name), rep(), type('i'), tracked(is_tracked ? '+' : '-') {
00276     if(!encode(rep, val)) throwEncodeError("vector<int>");
00277     validate();
00278   }
00279 
00280 // ----------------------------------------------------------------------
00281 // Uint32
00282 
00283   Entry::Entry(std::string const& name, unsigned val, bool is_tracked) :
00284     name_(name), rep(), type('U'), tracked(is_tracked ? '+' : '-') {
00285     if(!encode(rep, val)) throwEncodeError("unsigned int");
00286     validate();
00287   }
00288 
00289 // ----------------------------------------------------------------------
00290 // vUint32
00291 
00292  Entry::Entry(std::string const& name, std::vector<unsigned> const& val, bool is_tracked) :
00293    name_(name), rep(), type('u'), tracked(is_tracked ? '+' : '-') {
00294    if(!encode(rep, val)) throwEncodeError("vector<unsigned int>");
00295     validate();
00296   }
00297 
00298 // ----------------------------------------------------------------------
00299 // Int64
00300 
00301   Entry::Entry(std::string const& name, long long val, bool is_tracked) :
00302     name_(name), rep(), type('L'), tracked(is_tracked ? '+' : '-') {
00303     if(!encode(rep, val)) throwEncodeError("int64");
00304     validate();
00305   }
00306 
00307 // ----------------------------------------------------------------------
00308 // vInt64
00309 
00310   Entry::Entry(std::string const& name, std::vector<long long> const& val, bool is_tracked) :
00311     name_(name), rep(), type('l'), tracked(is_tracked ? '+' : '-') {
00312     if(!encode(rep, val)) throwEncodeError("vector<int64>");
00313     validate();
00314   }
00315 
00316 // ----------------------------------------------------------------------
00317 // Uint64
00318 
00319   Entry::Entry(std::string const& name, unsigned long long val, bool is_tracked) :
00320     name_(name), rep(), type('X'), tracked(is_tracked ? '+' : '-') {
00321     if(!encode(rep, val)) throwEncodeError("unsigned int64");
00322     validate();
00323   }
00324 
00325 // ----------------------------------------------------------------------
00326 // vUint64
00327 
00328  Entry::Entry(std::string const& name, std::vector<unsigned long long> const& val, bool is_tracked) :
00329    name_(name), rep(), type('x'), tracked(is_tracked ? '+' : '-') {
00330    if(!encode(rep, val)) throwEncodeError("vector<unsigned int64>");
00331     validate();
00332   }
00333 
00334 // ----------------------------------------------------------------------
00335 // Double
00336 
00337  Entry::Entry(std::string const& name, double val, bool is_tracked) :
00338    name_(name), rep(), type('D'), tracked(is_tracked ? '+' : '-') {
00339    if(!encode(rep, val)) throwEncodeError("double");
00340     validate();
00341   }
00342 
00343 // ----------------------------------------------------------------------
00344 // vDouble
00345 
00346   Entry::Entry(std::string const& name, std::vector<double> const& val, bool is_tracked) :
00347     name_(name), rep(), type('d'), tracked(is_tracked ? '+' : '-') {
00348     if(!encode(rep, val)) throwEncodeError("vector<double>");
00349     validate();
00350   }
00351 
00352 // ----------------------------------------------------------------------
00353 // String
00354 
00355   Entry::Entry(std::string const& name, std::string const& val, bool is_tracked) :
00356     name_(name), rep(), type('S'), tracked(is_tracked ? '+' : '-') {
00357     if(!encode(rep, val)) throwEncodeError("string");
00358     validate();
00359   }
00360 
00361 // ----------------------------------------------------------------------
00362 // vString
00363 
00364   Entry::Entry(std::string const& name, std::vector<std::string> const& val, bool is_tracked) :
00365        name_(name), rep(), type('s'), tracked(is_tracked ? '+' : '-') {
00366     if(!encode(rep, val)) throwEncodeError("vector<string>");
00367     validate();
00368   }
00369 
00370 // ----------------------------------------------------------------------
00371 // FileInPath
00372 
00373   Entry::Entry(std::string const& name, FileInPath const& val, bool is_tracked) :
00374     name_(name), rep(), type('F'), tracked(is_tracked ? '+' : '-') {
00375     if (!encode(rep, val)) throwEncodeError("FileInPath");
00376     validate();
00377   }
00378 
00379 // ----------------------------------------------------------------------
00380 // InputTag
00381 
00382   Entry::Entry(std::string const& name, InputTag const& val, bool is_tracked) :
00383     name_(name), rep(), type('t'), tracked(is_tracked ? '+' : '-') {
00384     if (!encode(rep, val)) throwEncodeError("InputTag");
00385     validate();
00386   }
00387 
00388 
00389 // ----------------------------------------------------------------------
00390 // VInputTag
00391 
00392   Entry::Entry(std::string const& name, std::vector<InputTag> const& val, bool is_tracked) :
00393     name_(name), rep(), type('v'), tracked(is_tracked ? '+' : '-') {
00394     if (!encode(rep, val)) throwEncodeError("VInputTag");
00395     validate();
00396   }
00397 
00398 
00399 // ----------------------------------------------------------------------
00400 // ESInputTag
00401 
00402    Entry::Entry(std::string const& name, ESInputTag const& val, bool is_tracked) :
00403    name_(name), rep(), type(kTESInputTag), tracked(is_tracked ? '+' : '-') {
00404       if (!encode(rep, val)) throwEncodeError("InputTag");
00405       validate();
00406    }
00407 
00408 // ----------------------------------------------------------------------
00409 // VESInputTag
00410 
00411    Entry::Entry(std::string const& name, std::vector<ESInputTag> const& val, bool is_tracked) :
00412    name_(name), rep(), type(kTVESInputTag), tracked(is_tracked ? '+' : '-') {
00413       if (!encode(rep, val)) throwEncodeError("VESInputTag");
00414       validate();
00415    }
00416 
00417 
00418 // ----------------------------------------------------------------------
00419 //  EventID
00420 
00421   Entry::Entry(std::string const& name, EventID const& val, bool is_tracked) :
00422     name_(name), rep(), type('E'), tracked(is_tracked ? '+' : '-') {
00423     if (!encode(rep, val)) throwEncodeError("EventID");
00424     validate();
00425   }
00426 
00427 
00428 // ----------------------------------------------------------------------
00429 // VEventID
00430 
00431   Entry::Entry(std::string const& name, std::vector<EventID> const& val, bool is_tracked) :
00432     name_(name), rep(), type('e'), tracked(is_tracked ? '+' : '-') {
00433     if (!encode(rep, val)) throwEncodeError("VEventID");
00434     validate();
00435   }
00436 
00437 
00438 
00439 // ----------------------------------------------------------------------
00440 //  LuminosityBlockID
00441 
00442   Entry::Entry(std::string const& name, LuminosityBlockID const& val, bool is_tracked) :
00443     name_(name), rep(), type('M'), tracked(is_tracked ? '+' : '-') {
00444     if (!encode(rep, val)) throwEncodeError("LuminosityBlockID");
00445     validate();
00446   }
00447 
00448 
00449 // ----------------------------------------------------------------------
00450 // VLuminosityBlockID
00451 
00452   Entry::Entry(std::string const& name, std::vector<LuminosityBlockID> const& val, bool is_tracked) :
00453     name_(name), rep(), type('m'), tracked(is_tracked ? '+' : '-') {
00454     if (!encode(rep, val)) throwEncodeError("VLuminosityBlockID");
00455     validate();
00456   }
00457 
00458 // ----------------------------------------------------------------------
00459 //  LuminosityBlockRange
00460 
00461   Entry::Entry(std::string const& name, LuminosityBlockRange const& val, bool is_tracked) :
00462     name_(name), rep(), type('A'), tracked(is_tracked ? '+' : '-') {
00463     if (!encode(rep, val)) throwEncodeError("LuminosityBlockRange");
00464     validate();
00465   }
00466 
00467 
00468 // ----------------------------------------------------------------------
00469 // VLuminosityBlockRange
00470 
00471   Entry::Entry(std::string const& name, std::vector<LuminosityBlockRange> const& val, bool is_tracked) :
00472     name_(name), rep(), type('a'), tracked(is_tracked ? '+' : '-') {
00473     if (!encode(rep, val)) throwEncodeError("VLuminosityBlockRange");
00474     validate();
00475   }
00476 
00477 // ----------------------------------------------------------------------
00478 //  EventRange
00479 
00480   Entry::Entry(std::string const& name, EventRange const& val, bool is_tracked) :
00481     name_(name), rep(), type('R'), tracked(is_tracked ? '+' : '-') {
00482     if (!encode(rep, val)) throwEncodeError("EventRange");
00483     validate();
00484   }
00485 
00486 // ----------------------------------------------------------------------
00487 // VEventRange
00488 
00489   Entry::Entry(std::string const& name, std::vector<EventRange> const& val, bool is_tracked) :
00490     name_(name), rep(), type('r'), tracked(is_tracked ? '+' : '-') {
00491     if (!encode(rep, val)) throwEncodeError("VEventRange");
00492     validate();
00493   }
00494 
00495 
00496 // ----------------------------------------------------------------------
00497 // ParameterSet
00498 
00499   Entry::Entry(std::string const& name, ParameterSet const& val, bool is_tracked) :
00500     name_(name), rep(), type('P'), tracked(is_tracked ? '+' : '-') {
00501     if(!encode(rep, val)) throwEncodeError("ParameterSet");
00502     validate();
00503   }
00504 
00505 // ----------------------------------------------------------------------
00506 // vPSet
00507 
00508   Entry::Entry(std::string const& name, std::vector<ParameterSet> const& val, bool is_tracked) :
00509       name_(name), rep(), type('p'), tracked(is_tracked ? '+' : '-') {
00510     if(!encode(rep, val)) throwEncodeError("vector<ParameterSet>");
00511     validate();
00512   }
00513 
00514 // ----------------------------------------------------------------------
00515 // coded string
00516 
00517   Entry::Entry(std::string const& name, std::string const& code) :
00518     name_(name), rep(), type('?'), tracked('?') {
00519     if(!fromString(code.begin(), code.end()))
00520       throwEncodeError("coded string");
00521     validate();
00522   }
00523 
00524 
00525   Entry::Entry(std::string const& name, std::string const& type, std::string const& value,
00526                bool is_tracked) :
00527     name_(name), rep(), type('?'), tracked('?') {
00528     std::string codedString(is_tracked ?"-":"+");
00529 
00530     Type2Code::const_iterator itFound = sTypeTranslations.type2Code_.find(type);
00531     if(itFound == sTypeTranslations.type2Code_.end()) {
00532         throw Exception(errors::Configuration)
00533           << "bad type name used for Entry : " << type;
00534     }
00535 
00536     codedString += itFound->second;
00537     codedString +='(';
00538     codedString += value;
00539     codedString +=')';
00540 
00541     if(!fromString(codedString.begin(), codedString.end())) {
00542         throw Exception(errors::Configuration)
00543           <<  "bad encoded Entry string " <<  codedString;
00544     }
00545     validate();
00546   }
00547 
00548   Entry::Entry(std::string const& name, std::string const& type,
00549                std::vector<std::string> const& value,
00550                bool is_tracked) :
00551     name_(name), rep() , type('?'), tracked('?') {
00552     std::string codedString(is_tracked ?"-":"+");
00553 
00554     Type2Code::const_iterator itFound =
00555       sTypeTranslations.type2Code_.find(type);
00556     if(itFound == sTypeTranslations.type2Code_.end()) {
00557         throw Exception(errors::Configuration)
00558           << "bad type name used for Entry : " << type;
00559     }
00560 
00561     codedString += itFound->second;
00562     codedString += '(';
00563     codedString += '{';
00564     std::vector<std::string>::const_iterator i = value.begin();
00565     std::vector<std::string>::const_iterator e = value.end();
00566     std::string const kSeparator(",");
00567     std::string sep("");
00568     for(; i!= e; ++i) {
00569       codedString += sep;
00570       codedString += *i;
00571       sep = kSeparator;
00572     }
00573     codedString += '}';
00574     codedString += ')';
00575 
00576     if(!fromString(codedString.begin(), codedString.end())) {
00577         throw Exception(errors::Configuration)
00578           << "bad encoded Entry string " << codedString;
00579     }
00580     validate();
00581   }
00582 
00583 // ----------------------------------------------------------------------
00584 // coding
00585 // ----------------------------------------------------------------------
00586 
00587   void
00588   Entry::toString(std::string& result) const {
00589     result.reserve(result.size() + sizeOfString());
00590     result += tracked;
00591     result += type;
00592     result += '(';
00593     result += rep;
00594     result += ')';
00595   }
00596 
00597   std::string
00598   Entry::toString() const {
00599     std::string result;
00600     toString(result);
00601     return result;
00602   }
00603 
00604 // ----------------------------------------------------------------------
00605 
00606   bool
00607   Entry::fromString(std::string::const_iterator const b, std::string::const_iterator const e) {
00608     if(static_cast<unsigned int>(e - b) < 4u || b[2] != '(' || e[-1] != ')')
00609 
00610       return false;
00611 
00612     tracked = b[0];
00613     type = b[1];
00614     rep = std::string(b+3, e-1);
00615 
00616     return true;
00617   }  // from_string()
00618 
00619 // ----------------------------------------------------------------------
00620 // value accessors
00621 // ----------------------------------------------------------------------
00622 
00623 
00624 // ----------------------------------------------------------------------
00625 // Bool
00626 
00627   bool
00628   Entry::getBool() const {
00629     if (type != 'B') throwValueError("bool");
00630     bool  val;
00631     if (!decode(val, rep)) throwEntryError("bool", rep);
00632     return val;
00633   }
00634 
00635 
00636 // ----------------------------------------------------------------------
00637 // Int32
00638 
00639   int
00640   Entry::getInt32() const {
00641     if(type != 'I') throwValueError("int");
00642     int  val;
00643     if(!decode(val, rep)) throwEntryError("int", rep);
00644     return val;
00645   }
00646 
00647 // ----------------------------------------------------------------------
00648 // vInt32
00649 
00650   std::vector<int>
00651   Entry::getVInt32() const {
00652     if(type != 'i') throwValueError("vector<int>");
00653     std::vector<int>  val;
00654     if(!decode(val, rep)) throwEntryError("vector<int>", rep);
00655     return val;
00656   }
00657 
00658 
00659 // ----------------------------------------------------------------------
00660 // Int32
00661 
00662   long long
00663   Entry::getInt64() const {
00664     if(type != 'L') throwValueError("int64");
00665     long long  val;
00666     if(!decode(val, rep)) throwEntryError("int64", rep);
00667     return val;
00668   }
00669 
00670 // ----------------------------------------------------------------------
00671 // vInt32
00672 
00673   std::vector<long long>
00674   Entry::getVInt64() const {
00675     if(type != 'l') throwValueError("vector<int64>");
00676     std::vector<long long>  val;
00677     if(!decode(val, rep)) throwEntryError("vector<int64>", rep);
00678     return val;
00679   }
00680 
00681 
00682 
00683 // ----------------------------------------------------------------------
00684 // Uint32
00685 
00686   unsigned
00687   Entry::getUInt32() const {
00688     if(type != 'U') throwValueError("unsigned int");
00689     unsigned  val;
00690     if(!decode(val, rep)) throwEntryError("unsigned int", rep);
00691     return val;
00692   }
00693 
00694 // ----------------------------------------------------------------------
00695 // vUint32
00696 
00697   std::vector<unsigned>
00698   Entry::getVUInt32() const {
00699     if(type != 'u') throwValueError("vector<unsigned int>");
00700     std::vector<unsigned>  val;
00701     if(!decode(val, rep)) throwEntryError("vector<unsigned int>", rep);
00702     return val;
00703   }
00704 
00705 
00706 // ----------------------------------------------------------------------
00707 // Uint64
00708 
00709   unsigned long long
00710   Entry::getUInt64() const {
00711     if(type != 'X') throwValueError("uint64");
00712     unsigned long long val;
00713     if(!decode(val, rep)) throwEntryError("uint64", rep);
00714     return val;
00715   }
00716 
00717 // ----------------------------------------------------------------------
00718 // vUint64
00719 
00720   std::vector<unsigned long long>
00721   Entry::getVUInt64() const {
00722     if(type != 'x') throwValueError("vector<uint64>");
00723     std::vector<unsigned long long>  val;
00724     if(!decode(val, rep)) throwEntryError("vector<uint64>", rep);
00725     return val;
00726   }
00727 
00728 // ----------------------------------------------------------------------
00729 // Double
00730 
00731   double
00732   Entry::getDouble() const {
00733     if(type != 'D') throwValueError("double");
00734     double  val;
00735     if(!decode(val, rep)) throwEntryError("double", rep);
00736     return val;
00737   }
00738 
00739 // ----------------------------------------------------------------------
00740 // vDouble
00741 
00742   std::vector<double>
00743   Entry::getVDouble() const {
00744     if(type != 'd') throwValueError("vector<double>");
00745     std::vector<double>  val;
00746     if(!decode(val, rep)) throwEntryError("vector<double>", rep);
00747     return val;
00748   }
00749 
00750 // ----------------------------------------------------------------------
00751 // String
00752 
00753   std::string
00754   Entry::getString() const {
00755     if(type != 'S') throwValueError("string");
00756     std::string  val;
00757     if(!decode(val, rep)) throwEntryError("string", rep);
00758     return val;
00759   }
00760 
00761 // ----------------------------------------------------------------------
00762 // vString
00763 
00764   std::vector<std::string>
00765   Entry::getVString() const {
00766     if(type != 's') throwValueError("vector<string>");
00767     std::vector<std::string>  val;
00768     if(!decode(val, rep)) throwEntryError("vector<string>", rep);
00769     return val;
00770   }
00771 
00772 
00773 // ----------------------------------------------------------------------
00774 // FileInPath
00775 
00776   FileInPath
00777   Entry::getFileInPath() const {
00778     if(type != 'F') throwValueError("FileInPath");
00779     FileInPath val;
00780     if(!decode(val, rep)) throwEntryError("FileInPath", rep);
00781     return val;
00782   }
00783 
00784 // ----------------------------------------------------------------------
00785 // InputTag
00786 
00787   InputTag
00788   Entry::getInputTag() const {
00789     if(type != 't') throwValueError("InputTag");
00790     InputTag val;
00791     if(!decode(val, rep)) throwEntryError("InputTag", rep);
00792     return val;
00793   }
00794 
00795 
00796 // ----------------------------------------------------------------------
00797 // VInputTag
00798 
00799   std::vector<InputTag>
00800   Entry::getVInputTag() const {
00801     if(type != 'v') throwValueError("VInputTag");
00802     std::vector<InputTag> val;
00803     if(!decode(val, rep)) throwEntryError("VInputTag", rep);
00804     return val;
00805   }
00806 
00807 
00808 // ----------------------------------------------------------------------
00809 // ESInputTag
00810 
00811    ESInputTag
00812    Entry::getESInputTag() const {
00813       if(type != kTESInputTag) throwValueError("ESInputTag");
00814       ESInputTag val;
00815       if(!decode(val, rep)) throwEntryError("ESInputTag", rep);
00816       return val;
00817    }
00818 
00819 
00820 // ----------------------------------------------------------------------
00821 // VESInputTag
00822 
00823    std::vector<ESInputTag>
00824    Entry::getVESInputTag() const {
00825       if(type != kTVESInputTag) throwValueError("VESInputTag");
00826       std::vector<ESInputTag> val;
00827       if(!decode(val, rep)) throwEntryError("VESInputTag", rep);
00828       return val;
00829    }
00830 
00831 // ----------------------------------------------------------------------
00832 // EventID
00833 
00834   EventID
00835   Entry::getEventID() const {
00836     if(type != 'E') throwValueError("EventID");
00837     EventID val;
00838     if(!decode(val, rep)) throwEntryError("EventID", rep);
00839     return val;
00840   }
00841 
00842 // ----------------------------------------------------------------------
00843 // VEventID
00844 
00845   std::vector<EventID>
00846   Entry::getVEventID() const {
00847     if(type != 'e') throwValueError("VEventID");
00848     std::vector<EventID> val;
00849     if(!decode(val, rep)) throwEntryError("EventID", rep);
00850     return val;
00851   }
00852 
00853 
00854 // ----------------------------------------------------------------------
00855 // LuminosityBlockID
00856 
00857   LuminosityBlockID
00858   Entry::getLuminosityBlockID() const {
00859     if(type != 'M') throwValueError("LuminosityBlockID");
00860     LuminosityBlockID val;
00861     if(!decode(val, rep)) throwEntryError("LuminosityBlockID", rep);
00862     return val;
00863   }
00864 
00865 // ----------------------------------------------------------------------
00866 // VLuminosityBlockID
00867 
00868   std::vector<LuminosityBlockID>
00869   Entry::getVLuminosityBlockID() const {
00870     if(type != 'm') throwValueError("VLuminosityBlockID");
00871     std::vector<LuminosityBlockID> val;
00872     if(!decode(val, rep)) throwEntryError("LuminosityBlockID", rep);
00873     return val;
00874   }
00875 
00876 // LuminosityBlockRange
00877 
00878   LuminosityBlockRange
00879   Entry::getLuminosityBlockRange() const {
00880     if(type != 'A') throwValueError("LuminosityBlockRange");
00881     LuminosityBlockRange val;
00882     if(!decode(val, rep)) throwEntryError("LuminosityBlockRange", rep);
00883     return val;
00884   }
00885 
00886 // ----------------------------------------------------------------------
00887 // VLuminosityBlockRange
00888 
00889   std::vector<LuminosityBlockRange>
00890   Entry::getVLuminosityBlockRange() const {
00891     if(type != 'a') throwValueError("VLuminosityBlockRange");
00892     std::vector<LuminosityBlockRange> val;
00893     if(!decode(val, rep)) throwEntryError("LuminosityBlockRange", rep);
00894     return val;
00895   }
00896 
00897 // ----------------------------------------------------------------------
00898 // EventRange
00899 
00900   EventRange
00901   Entry::getEventRange() const {
00902     if(type != 'R') throwValueError("EventRange");
00903     EventRange val;
00904     if(!decode(val, rep)) throwEntryError("EventRange", rep);
00905     return val;
00906   }
00907 
00908 // ----------------------------------------------------------------------
00909 // VEventRange
00910 
00911   std::vector<EventRange>
00912   Entry::getVEventRange() const {
00913     if(type != 'r') throwValueError("VEventRange");
00914     std::vector<EventRange> val;
00915     if(!decode(val, rep)) throwEntryError("EventRange", rep);
00916     return val;
00917   }
00918 
00919 // ----------------------------------------------------------------------
00920 // ----------------------------------------------------------------------
00921 // ParameterSet
00922 
00923   ParameterSet
00924   Entry::getPSet() const {
00925     if(type != 'P') throwValueError("ParameterSet");
00926     ParameterSet val;
00927     if(!decode(val, rep)) throwEntryError("ParameterSet", rep);
00928     return val;
00929   }
00930 
00931 // ----------------------------------------------------------------------
00932 // vPSet
00933 
00934   std::vector<ParameterSet>
00935   Entry::getVPSet() const {
00936     if(type != 'p') throwValueError("vector<ParameterSet>");
00937     std::vector<ParameterSet>  val;
00938     if(!decode(val, rep)) throwEntryError("vector<ParameterSet>", rep);
00939     return val;
00940   }
00941 
00942 
00943   std::ostream&
00944   operator<< (std::ostream& os, Entry const& entry) {
00945     os << sTypeTranslations.table_[entry.typeCode()] << " "
00946        << (entry.isTracked() ? "tracked " : "untracked ") <<" = ";
00947 
00948     // now handle the difficult cases
00949     switch(entry.typeCode()) {
00950       case 'P': // ParameterSet
00951       {
00952         os << entry.getPSet();
00953         break;
00954       }
00955       case 'p': // vector<ParameterSet>
00956       {
00957         // Make sure we get the representation of each contained
00958         // ParameterSet including *only* tracked parameters
00959         std::vector<ParameterSet> whole = entry.getVPSet();
00960         std::vector<ParameterSet>::const_iterator i = whole.begin();
00961         std::vector<ParameterSet>::const_iterator e = whole.end();
00962         std::string start ="";
00963         std::string const between(",\n");
00964         os << "{"<<std::endl;
00965          for (; i != e; ++i) {
00966            os <<  start<< *i;
00967            start = between;
00968          }
00969          if (whole.size()) {
00970            os << std::endl;
00971          }
00972          os << "}";
00973          break;
00974       }
00975       case 'S':
00976       {
00977         os << "'" << entry.getString() << "'";
00978         break;
00979       }
00980       case 's':
00981       {
00982 
00983         os << "{";
00984         std::string start ="'";
00985         std::string const between(",'");
00986         std::vector<std::string> strings = entry.getVString();
00987         for(std::vector<std::string>::const_iterator it = strings.begin(), itEnd = strings.end();
00988             it != itEnd;
00989             ++it) {
00990           os << start << *it << "'";
00991           start = between;
00992         }
00993         os << "}";
00994         break;
00995       }
00996       case 'I':
00997       {
00998         os << entry.getInt32();
00999         break;
01000       }
01001       case 'U':
01002       {
01003         os << entry.getUInt32();
01004         break;
01005       }
01006       case 'v':
01007       {
01008         //VInputTag needs to be treated seperately because it is encode like
01009         // vector<string> rather than using the individual encodings of each InputTag
01010         os << "{";
01011         std::string start = "";
01012         std::string const between(",");
01013         std::vector<InputTag> tags = entry.getVInputTag();
01014         for(std::vector<InputTag>::const_iterator it = tags.begin(), itEnd = tags.end();
01015             it != itEnd;
01016             ++it) {
01017           os << start << it->encode();
01018           start = between;
01019         }
01020         os << "}";
01021         break;
01022       }
01023        case kTVESInputTag:
01024        {
01025           //VESInputTag needs to be treated seperately because it is encode like
01026           // vector<string> rather than using the individual encodings of each ESInputTag
01027           os << "{";
01028           std::string start = "";
01029           std::string const between(",");
01030           std::vector<ESInputTag> tags = entry.getVESInputTag();
01031           for(std::vector<ESInputTag>::const_iterator it = tags.begin(), itEnd = tags.end();
01032               it != itEnd;
01033               ++it) {
01034              os << start << it->encode();
01035              start = between;
01036           }
01037           os << "}";
01038           break;
01039        }
01040        default:
01041       {
01042         os << entry.rep;
01043         break;
01044       }
01045     }
01046 
01047     return os;
01048   }
01049 
01050     // Helper functions for throwing exceptions
01051 
01052     void Entry::throwValueError(char const* expectedType) const {
01053       throw Exception(errors::Configuration, "ValueError")
01054         << "type of " << name_ << " is expected to be " << expectedType
01055         << " but declared as " << sTypeTranslations.table_[type];
01056     }
01057 
01058     void Entry::throwEntryError(char const* expectedType,
01059                          std::string const& badRep) const {
01060       throw Exception(errors::Configuration, "EntryError")
01061         << "can not convert representation of " << name_ << ": "
01062         << badRep
01063         << " to value of type " << expectedType << " ";
01064     }
01065 
01066     void Entry::throwEncodeError(char const* type) const {
01067       throw Exception(errors::Configuration, "EncodingError")
01068         << "can not encode " << name_ << " as type: " << type;
01069     }
01070 
01071 
01072 }