00001 #ifndef FWCore_ParameterSet_ParameterSet_h
00002 #define FWCore_ParameterSet_ParameterSet_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "DataFormats/Provenance/interface/ParameterSetID.h"
00018 #include "FWCore/ParameterSet/interface/Entry.h"
00019 #include "FWCore/ParameterSet/interface/FileInPath.h"
00020 #include <string>
00021 #include <map>
00022 #include <vector>
00023 #include <iosfwd>
00024
00025
00026
00027
00028
00029 namespace edm {
00030
00031 class ParameterSet {
00032 public:
00033
00034 ParameterSet();
00035
00036
00037 explicit ParameterSet(std::string const&);
00038
00039
00040 ParameterSetID id() const;
00041
00042
00043 Entry const& retrieve(std::string const&) const;
00044
00045 Entry const* const retrieveUntracked(std::string const&) const;
00046 void insert(bool ok_to_replace, std::string const& , Entry const&);
00047 void augment(ParameterSet const& from);
00048
00049 std::string toString() const;
00050 std::string toStringOfTracked() const;
00051
00052 bool fromString(std::string const&);
00053
00054
00055 template <class T>
00056 T
00057 getParameter(std::string const&) const;
00058
00059 template <class T>
00060 void
00061 addParameter(std::string const& name, T value)
00062 {
00063 invalidate();
00064 insert(true, name, Entry(name, value, true));
00065 }
00066
00067 template <class T>
00068 T
00069 getUntrackedParameter(std::string const&, T const&) const;
00070
00071 template <class T>
00072 T
00073 getUntrackedParameter(std::string const&) const;
00074
00079 std::vector<edm::FileInPath>::size_type
00080 getAllFileInPaths(std::vector<edm::FileInPath>& output) const;
00081
00082 std::vector<std::string> getParameterNames() const;
00083
00085 bool exists(const std::string & parameterName) const;
00087 template <class T>
00088 bool existsAs(const std::string & parameterName, bool trackiness=true) const
00089 {
00090 std::vector<std::string> names = getParameterNamesForType<T>(trackiness);
00091 return std::find(names.begin(), names.end(), parameterName) != names.end();
00092 }
00093
00094 void depricatedInputTagWarning(std::string const& name, std::string const& label) const;
00095
00096 template <class T>
00097 std::vector<std::string> getParameterNamesForType(bool trackiness =
00098 true) const
00099 {
00100 std::vector<std::string> result;
00101
00102
00103 T value = T();
00104 edm::Entry type_translator("", value, trackiness);
00105 char type_code = type_translator.typeCode();
00106
00107 (void)getNamesByCode_(type_code, trackiness, result);
00108 return result;
00109 }
00110
00111 template <class T>
00112 void
00113 addUntrackedParameter(std::string const& name, T value)
00114 {
00115
00116 insert(true, name, Entry(name, value, false));
00117 }
00118
00119 bool empty() const
00120 {
00121 return tbl_.empty();
00122 }
00123
00124 ParameterSet trackedPart() const;
00125
00126
00127
00128
00129
00130
00131 size_t getParameterSetNames(std::vector<std::string>& output,
00132 bool trackiness = true) const;
00133
00134
00135
00136
00137
00138
00139 size_t getParameterSetVectorNames(std::vector<std::string>& output,
00140 bool trackiness=true) const;
00141
00142
00143 std::string dump() const;
00144
00145 friend std::ostream & operator<<(std::ostream & os, const ParameterSet & pset);
00146
00147 private:
00148 typedef std::map<std::string, Entry> table;
00149 table tbl_;
00150
00151
00152
00153
00154 mutable ParameterSetID id_;
00155
00156
00157
00158
00159 void validate() const;
00160
00161
00162
00163 void invalidate() const;
00164
00165
00166
00167 Entry const* getEntryPointerOrThrow_(std::string const& name) const;
00168
00169
00170
00171 size_t getNamesByCode_(char code,
00172 bool trackiness,
00173 std::vector<std::string>& output) const;
00174
00175
00176 };
00177
00178 inline
00179 bool
00180 operator==(ParameterSet const& a, ParameterSet const& b) {
00181
00182 return a.toStringOfTracked() == b.toStringOfTracked();
00183 }
00184
00185 inline
00186 bool
00187 operator!=(ParameterSet const& a, ParameterSet const& b) {
00188 return !(a == b);
00189 }
00190
00191
00192
00193
00194
00195 template<>
00196 inline
00197 bool
00198 ParameterSet::getParameter<bool>(std::string const& name) const {
00199 return retrieve(name).getBool();
00200 }
00201
00202
00203
00204
00205 template<>
00206 inline
00207 int
00208 ParameterSet::getParameter<int>(std::string const& name) const {
00209 return retrieve(name).getInt32();
00210 }
00211
00212
00213 template<>
00214 inline
00215 std::vector<int>
00216 ParameterSet::getParameter<std::vector<int> >(std::string const& name) const {
00217 return retrieve(name).getVInt32();
00218 }
00219
00220
00221
00222
00223 template<>
00224 inline
00225 boost::int64_t
00226 ParameterSet::getParameter<boost::int64_t>(std::string const& name) const {
00227 return retrieve(name).getInt64();
00228 }
00229
00230
00231 template<>
00232 inline
00233 std::vector<boost::int64_t>
00234 ParameterSet::getParameter<std::vector<boost::int64_t> >(std::string const& name) const {
00235 return retrieve(name).getVInt64();
00236 }
00237
00238
00239
00240
00241
00242 template<>
00243 inline
00244 unsigned int
00245 ParameterSet::getParameter<unsigned int>(std::string const& name) const {
00246 return retrieve(name).getUInt32();
00247 }
00248
00249 template<>
00250 inline
00251 std::vector<unsigned int>
00252 ParameterSet::getParameter<std::vector<unsigned int> >(std::string const& name) const {
00253 return retrieve(name).getVUInt32();
00254 }
00255
00256
00257
00258
00259 template<>
00260 inline
00261 boost::uint64_t
00262 ParameterSet::getParameter<boost::uint64_t>(std::string const& name) const {
00263 return retrieve(name).getUInt64();
00264 }
00265
00266 template<>
00267 inline
00268 std::vector<boost::uint64_t>
00269 ParameterSet::getParameter<std::vector<boost::uint64_t> >(std::string const& name) const {
00270 return retrieve(name).getVUInt64();
00271 }
00272
00273
00274
00275
00276
00277 template<>
00278 inline
00279 double
00280 ParameterSet::getParameter<double>(std::string const& name) const {
00281 return retrieve(name).getDouble();
00282 }
00283
00284 template<>
00285 inline
00286 std::vector<double>
00287 ParameterSet::getParameter<std::vector<double> >(std::string const& name) const {
00288 return retrieve(name).getVDouble();
00289 }
00290
00291
00292
00293
00294 template<>
00295 inline
00296 std::string
00297 ParameterSet::getParameter<std::string>(std::string const& name) const {
00298 return retrieve(name).getString();
00299 }
00300
00301 template<>
00302 inline
00303 std::vector<std::string>
00304 ParameterSet::getParameter<std::vector<std::string> >(std::string const& name) const {
00305 return retrieve(name).getVString();
00306 }
00307
00308
00309
00310
00311 template <>
00312 inline
00313 edm::FileInPath
00314 ParameterSet::getParameter<edm::FileInPath>(std::string const& name) const {
00315 return retrieve(name).getFileInPath();
00316 }
00317
00318
00319
00320
00321 template <>
00322 inline
00323 edm::InputTag
00324 ParameterSet::getParameter<edm::InputTag>(std::string const& name) const {
00325 const Entry & e_input = retrieve(name);
00326 switch (e_input.typeCode())
00327 {
00328 case 't':
00329 return e_input.getInputTag();
00330 case 'S':
00331 const std::string & label = e_input.getString();
00332 depricatedInputTagWarning(name, label);
00333 return InputTag( label );
00334 }
00335 throw edm::Exception(errors::Configuration, "ValueError") << "type of "
00336 << name << " is expected to be InputTag or string (deprecated)";
00337
00338 }
00339
00340
00341
00342
00343
00344 template <>
00345 inline
00346 std::vector<edm::InputTag>
00347 ParameterSet::getParameter<std::vector<edm::InputTag> >(std::string const& name) const {
00348 return retrieve(name).getVInputTag();
00349 }
00350
00351
00352
00353
00354
00355 template <>
00356 inline
00357 edm::EventID
00358 ParameterSet::getParameter<edm::EventID>(std::string const& name) const {
00359 return retrieve(name).getEventID();
00360 }
00361
00362
00363
00364
00365
00366 template <>
00367 inline
00368 std::vector<edm::EventID>
00369 ParameterSet::getParameter<std::vector<edm::EventID> >(std::string const& name) const {
00370 return retrieve(name).getVEventID();
00371 }
00372
00373
00374
00375
00376
00377
00378 template <>
00379 inline
00380 edm::LuminosityBlockID
00381 ParameterSet::getParameter<edm::LuminosityBlockID>(std::string const& name) const {
00382 return retrieve(name).getLuminosityBlockID();
00383 }
00384
00385
00386
00387
00388
00389 template <>
00390 inline
00391 std::vector<edm::LuminosityBlockID>
00392 ParameterSet::getParameter<std::vector<edm::LuminosityBlockID> >(std::string const& name) const {
00393 return retrieve(name).getVLuminosityBlockID();
00394 }
00395
00396
00397
00398
00399
00400
00401 template<>
00402 inline
00403 edm::ParameterSet
00404 ParameterSet::getParameter<edm::ParameterSet>(std::string const& name) const {
00405 return retrieve(name).getPSet();
00406 }
00407
00408 template<>
00409 inline
00410 std::vector<edm::ParameterSet>
00411 ParameterSet::getParameter<std::vector<edm::ParameterSet> >(std::string const& name) const {
00412 return retrieve(name).getVPSet();
00413 }
00414
00415
00416
00417
00418
00419
00420 template<>
00421 inline
00422 bool
00423 ParameterSet::getUntrackedParameter<bool>(std::string const& name, bool const& defaultValue) const {
00424 Entry const* entryPtr = retrieveUntracked(name);
00425 return entryPtr == 0 ? defaultValue : entryPtr->getBool();
00426 }
00427
00428 template<>
00429 inline
00430 bool
00431 ParameterSet::getUntrackedParameter<bool>(std::string const& name) const {
00432 return getEntryPointerOrThrow_(name)->getBool();
00433 }
00434
00435
00436
00437
00438
00439 template<>
00440 inline
00441 int
00442 ParameterSet::getUntrackedParameter<int>(std::string const& name, int const& defaultValue) const {
00443 Entry const* entryPtr = retrieveUntracked(name);
00444 return entryPtr == 0 ? defaultValue : entryPtr->getInt32();
00445 }
00446
00447 template<>
00448 inline
00449 int
00450 ParameterSet::getUntrackedParameter<int>(std::string const& name) const {
00451 return getEntryPointerOrThrow_(name)->getInt32();
00452 }
00453
00454 template<>
00455 inline
00456 std::vector<int>
00457 ParameterSet::getUntrackedParameter<std::vector<int> >(std::string const& name, std::vector<int> const& defaultValue) const {
00458 Entry const* entryPtr = retrieveUntracked(name);
00459 return entryPtr == 0 ? defaultValue : entryPtr->getVInt32();
00460 }
00461
00462 template<>
00463 inline
00464 std::vector<int>
00465 ParameterSet::getUntrackedParameter<std::vector<int> >(std::string const& name) const {
00466 return getEntryPointerOrThrow_(name)->getVInt32();
00467 }
00468
00469
00470
00471
00472 template<>
00473 inline
00474 unsigned int
00475 ParameterSet::getUntrackedParameter<unsigned int>(std::string const& name, unsigned int const& defaultValue) const {
00476 Entry const* entryPtr = retrieveUntracked(name);
00477 return entryPtr == 0 ? defaultValue : entryPtr->getUInt32();
00478 }
00479
00480 template<>
00481 inline
00482 unsigned int
00483 ParameterSet::getUntrackedParameter<unsigned int>(std::string const& name) const {
00484 return getEntryPointerOrThrow_(name)->getUInt32();
00485 }
00486
00487 template<>
00488 inline
00489 std::vector<unsigned int>
00490 ParameterSet::getUntrackedParameter<std::vector<unsigned int> >(std::string const& name, std::vector<unsigned int> const& defaultValue) const {
00491 Entry const* entryPtr = retrieveUntracked(name);
00492 return entryPtr == 0 ? defaultValue : entryPtr->getVUInt32();
00493 }
00494
00495 template<>
00496 inline
00497 std::vector<unsigned int>
00498 ParameterSet::getUntrackedParameter<std::vector<unsigned int> >(std::string const& name) const {
00499 return getEntryPointerOrThrow_(name)->getVUInt32();
00500 }
00501
00502
00503
00504
00505
00506 template<>
00507 inline
00508 boost::uint64_t
00509 ParameterSet::getUntrackedParameter<boost::uint64_t>(std::string const& name, boost::uint64_t const& defaultValue) const {
00510 Entry const* entryPtr = retrieveUntracked(name);
00511 return entryPtr == 0 ? defaultValue : entryPtr->getUInt64();
00512 }
00513
00514 template<>
00515 inline
00516 boost::uint64_t
00517 ParameterSet::getUntrackedParameter<boost::uint64_t>(std::string const& name) const {
00518 return getEntryPointerOrThrow_(name)->getUInt64();
00519 }
00520
00521 template<>
00522 inline
00523 std::vector<boost::uint64_t>
00524 ParameterSet::getUntrackedParameter<std::vector<boost::uint64_t> >(std::string const& name, std::vector<boost::uint64_t> const& defaultValue) const {
00525 Entry const* entryPtr = retrieveUntracked(name);
00526 return entryPtr == 0 ? defaultValue : entryPtr->getVUInt64();
00527 }
00528
00529 template<>
00530 inline
00531 std::vector<boost::uint64_t>
00532 ParameterSet::getUntrackedParameter<std::vector<boost::uint64_t> >(std::string const& name) const {
00533 return getEntryPointerOrThrow_(name)->getVUInt64();
00534 }
00535
00536
00537
00538
00539
00540 template<>
00541 inline
00542 boost::int64_t
00543 ParameterSet::getUntrackedParameter<boost::int64_t>(std::string const& name, boost::int64_t const& defaultValue) const {
00544 Entry const* entryPtr = retrieveUntracked(name);
00545 return entryPtr == 0 ? defaultValue : entryPtr->getInt64();
00546 }
00547
00548 template<>
00549 inline
00550 boost::int64_t
00551 ParameterSet::getUntrackedParameter<boost::int64_t>(std::string const& name) const {
00552 return getEntryPointerOrThrow_(name)->getInt64();
00553 }
00554
00555 template<>
00556 inline
00557 std::vector<boost::int64_t>
00558 ParameterSet::getUntrackedParameter<std::vector<boost::int64_t> >(std::string const& name, std::vector<boost::int64_t> const& defaultValue) const {
00559 Entry const* entryPtr = retrieveUntracked(name);
00560 return entryPtr == 0 ? defaultValue : entryPtr->getVInt64();
00561 }
00562
00563 template<>
00564 inline
00565 std::vector<boost::int64_t>
00566 ParameterSet::getUntrackedParameter<std::vector<boost::int64_t> >(std::string const& name) const {
00567 return getEntryPointerOrThrow_(name)->getVInt64();
00568 }
00569
00570
00571
00572
00573
00574 template<>
00575 inline
00576 double
00577 ParameterSet::getUntrackedParameter<double>(std::string const& name, double const& defaultValue) const {
00578 Entry const* entryPtr = retrieveUntracked(name);
00579 return entryPtr == 0 ? defaultValue : entryPtr->getDouble();
00580 }
00581
00582
00583 template<>
00584 inline
00585 double
00586 ParameterSet::getUntrackedParameter<double>(std::string const& name) const {
00587 return getEntryPointerOrThrow_(name)->getDouble();
00588 }
00589
00590 template<>
00591 inline
00592 std::vector<double>
00593 ParameterSet::getUntrackedParameter<std::vector<double> >(std::string const& name, std::vector<double> const& defaultValue) const {
00594 Entry const* entryPtr = retrieveUntracked(name); return entryPtr == 0 ? defaultValue : entryPtr->getVDouble();
00595 }
00596
00597 template<>
00598 inline
00599 std::vector<double>
00600 ParameterSet::getUntrackedParameter<std::vector<double> >(std::string const& name) const {
00601 return getEntryPointerOrThrow_(name)->getVDouble();
00602 }
00603
00604
00605
00606
00607 template<>
00608 inline
00609 std::string
00610 ParameterSet::getUntrackedParameter<std::string>(std::string const& name, std::string const& defaultValue) const {
00611 Entry const* entryPtr = retrieveUntracked(name);
00612 return entryPtr == 0 ? defaultValue : entryPtr->getString();
00613 }
00614
00615 template<>
00616 inline
00617 std::string
00618 ParameterSet::getUntrackedParameter<std::string>(std::string const& name) const {
00619 return getEntryPointerOrThrow_(name)->getString();
00620 }
00621
00622 template<>
00623 inline
00624 std::vector<std::string>
00625 ParameterSet::getUntrackedParameter<std::vector<std::string> >(std::string const& name, std::vector<std::string> const& defaultValue) const {
00626 Entry const* entryPtr = retrieveUntracked(name);
00627 return entryPtr == 0 ? defaultValue : entryPtr->getVString();
00628 }
00629
00630
00631 template<>
00632 inline
00633 std::vector<std::string>
00634 ParameterSet::getUntrackedParameter<std::vector<std::string> >(std::string const& name) const {
00635 return getEntryPointerOrThrow_(name)->getVString();
00636 }
00637
00638
00639
00640
00641 template<>
00642 inline
00643 edm::FileInPath
00644 ParameterSet::getUntrackedParameter<edm::FileInPath>(std::string const& name, edm::FileInPath const& defaultValue) const {
00645 Entry const* entryPtr = retrieveUntracked(name);
00646 return entryPtr == 0 ? defaultValue : entryPtr->getFileInPath();
00647 }
00648
00649 template<>
00650 inline
00651 edm::FileInPath
00652 ParameterSet::getUntrackedParameter<edm::FileInPath>(std::string const& name) const {
00653 return getEntryPointerOrThrow_(name)->getFileInPath();
00654 }
00655
00656
00657
00658
00659
00660 template<>
00661 inline
00662 edm::InputTag
00663 ParameterSet::getUntrackedParameter<edm::InputTag>(std::string const& name, edm::InputTag const& defaultValue) const {
00664 Entry const* entryPtr = retrieveUntracked(name);
00665 return entryPtr == 0 ? defaultValue : entryPtr->getInputTag();
00666 }
00667
00668 template<>
00669 inline
00670 edm::InputTag
00671 ParameterSet::getUntrackedParameter<edm::InputTag>(std::string const& name) const {
00672 return getEntryPointerOrThrow_(name)->getInputTag();
00673 }
00674
00675 template<>
00676 inline
00677 std::vector<edm::InputTag>
00678 ParameterSet::getUntrackedParameter<std::vector<edm::InputTag> >(std::string const& name,
00679 std::vector<edm::InputTag> const& defaultValue) const
00680 {
00681 Entry const* entryPtr = retrieveUntracked(name);
00682 return entryPtr == 0 ? defaultValue : entryPtr->getVInputTag();
00683 }
00684
00685
00686 template<>
00687 inline
00688 std::vector<edm::InputTag>
00689 ParameterSet::getUntrackedParameter<std::vector<edm::InputTag> >(std::string const& name) const {
00690 return getEntryPointerOrThrow_(name)->getVInputTag();
00691 }
00692
00693
00694
00695
00696 template<>
00697 inline
00698 edm::EventID
00699 ParameterSet::getUntrackedParameter<edm::EventID>(std::string const& name, edm::EventID const& defaultValue) const {
00700 Entry const* entryPtr = retrieveUntracked(name);
00701 return entryPtr == 0 ? defaultValue : entryPtr->getEventID();
00702 }
00703
00704 template<>
00705 inline
00706 edm::EventID
00707 ParameterSet::getUntrackedParameter<edm::EventID>(std::string const& name) const {
00708 return getEntryPointerOrThrow_(name)->getEventID();
00709 }
00710
00711 template<>
00712 inline
00713 std::vector<edm::EventID>
00714 ParameterSet::getUntrackedParameter<std::vector<edm::EventID> >(std::string const& name,
00715 std::vector<edm::EventID> const& defaultValue) const
00716 {
00717 Entry const* entryPtr = retrieveUntracked(name);
00718 return entryPtr == 0 ? defaultValue : entryPtr->getVEventID();
00719 }
00720
00721
00722 template<>
00723 inline
00724 std::vector<edm::EventID>
00725 ParameterSet::getUntrackedParameter<std::vector<edm::EventID> >(std::string const& name) const {
00726 return getEntryPointerOrThrow_(name)->getVEventID();
00727 }
00728
00729
00730
00731
00732
00733
00734
00735 template<>
00736 inline
00737 edm::LuminosityBlockID
00738 ParameterSet::getUntrackedParameter<edm::LuminosityBlockID>(std::string const& name, edm::LuminosityBlockID const& defaultValue) const {
00739 Entry const* entryPtr = retrieveUntracked(name);
00740 return entryPtr == 0 ? defaultValue : entryPtr->getLuminosityBlockID();
00741 }
00742
00743 template<>
00744 inline
00745 edm::LuminosityBlockID
00746 ParameterSet::getUntrackedParameter<edm::LuminosityBlockID>(std::string const& name) const {
00747 return getEntryPointerOrThrow_(name)->getLuminosityBlockID();
00748 }
00749
00750 template<>
00751 inline
00752 std::vector<edm::LuminosityBlockID>
00753 ParameterSet::getUntrackedParameter<std::vector<edm::LuminosityBlockID> >(std::string const& name,
00754 std::vector<edm::LuminosityBlockID> const& defaultValue) const
00755 {
00756 Entry const* entryPtr = retrieveUntracked(name);
00757 return entryPtr == 0 ? defaultValue : entryPtr->getVLuminosityBlockID();
00758 }
00759
00760
00761 template<>
00762 inline
00763 std::vector<edm::LuminosityBlockID>
00764 ParameterSet::getUntrackedParameter<std::vector<edm::LuminosityBlockID> >(std::string const& name) const {
00765 return getEntryPointerOrThrow_(name)->getVLuminosityBlockID();
00766 }
00767
00768
00769
00770
00771
00772
00773
00774 template<>
00775 inline
00776 ParameterSet
00777 ParameterSet::getUntrackedParameter<edm::ParameterSet>(std::string const& name, edm::ParameterSet const& defaultValue) const {
00778 Entry const* entryPtr = retrieveUntracked(name);
00779 return entryPtr == 0 ? defaultValue : entryPtr->getPSet();
00780 }
00781
00782 template<>
00783 inline
00784 ParameterSet
00785 ParameterSet::getUntrackedParameter<edm::ParameterSet>(std::string const& name) const {
00786 return getEntryPointerOrThrow_(name)->getPSet();
00787 }
00788
00789 template<>
00790 inline
00791 std::vector<edm::ParameterSet>
00792 ParameterSet::getUntrackedParameter<std::vector<edm::ParameterSet> >(std::string const& name, std::vector<edm::ParameterSet> const& defaultValue) const {
00793 Entry const* entryPtr = retrieveUntracked(name);
00794 return entryPtr == 0 ? defaultValue : entryPtr->getVPSet();
00795 }
00796
00797 template<>
00798 inline
00799 std::vector<edm::ParameterSet>
00800 ParameterSet::getUntrackedParameter<std::vector<edm::ParameterSet> >(std::string const& name) const {
00801 return getEntryPointerOrThrow_(name)->getVPSet();
00802 }
00803
00804
00805 namespace pset
00806 {
00807
00808
00809 void explode(edm::ParameterSet const& top,
00810 std::vector<edm::ParameterSet>& results);
00811 }
00812
00813
00814 ParameterSet
00815 getParameterSet(ParameterSetID const& id);
00816
00817 }
00818 #endif