Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:01

0001 /*
0002  */
0003 
0004 #include <cppunit/extensions/HelperMacros.h>
0005 
0006 #include <algorithm>
0007 #include <iostream>
0008 #include <limits>
0009 #include <string>
0010 #include <cassert>
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/EDMException.h"
0014 #include "FWCore/Utilities/interface/Algorithms.h"
0015 #include "FWCore/Utilities/interface/Digest.h"
0016 
0017 class testps : public CppUnit::TestFixture {
0018   //CPPUNIT_TEST_EXCEPTION(emptyTest,edm::Exception);
0019   CPPUNIT_TEST_SUITE(testps);
0020   CPPUNIT_TEST(emptyTest);
0021   CPPUNIT_TEST(boolTest);
0022   CPPUNIT_TEST(intTest);
0023   CPPUNIT_TEST(uintTest);
0024   CPPUNIT_TEST(doubleTest);
0025   CPPUNIT_TEST(stringTest);
0026   CPPUNIT_TEST(eventIDTest);
0027   CPPUNIT_TEST(eventRangeTest);
0028   CPPUNIT_TEST(vEventRangeTest);
0029   CPPUNIT_TEST(doubleEqualityTest);
0030   CPPUNIT_TEST(negativeZeroTest);
0031   CPPUNIT_TEST(idTest);
0032   CPPUNIT_TEST(mapByIdTest);
0033   CPPUNIT_TEST(nameAccessTest);
0034   CPPUNIT_TEST(fileInPathTest);
0035   CPPUNIT_TEST(testEmbeddedPSet);
0036   CPPUNIT_TEST(testRegistration);
0037   CPPUNIT_TEST(testCopyFrom);
0038   CPPUNIT_TEST(testGetParameterAsString);
0039   CPPUNIT_TEST(calculateIDTest);
0040   CPPUNIT_TEST_SUITE_END();
0041 
0042 public:
0043   void setUp() {}
0044   void tearDown() {}
0045 
0046   void emptyTest();
0047   void boolTest();
0048   void intTest();
0049   void uintTest();
0050   void doubleTest();
0051   void stringTest();
0052   void eventIDTest();
0053   void eventRangeTest();
0054   void vEventRangeTest();
0055   void doubleEqualityTest();
0056   void negativeZeroTest();
0057   void idTest();
0058   void mapByIdTest();
0059   void nameAccessTest();
0060   void fileInPathTest();
0061   void testEmbeddedPSet();
0062   void testRegistration();
0063   void testCopyFrom();
0064   void testGetParameterAsString();
0065   void calculateIDTest();
0066   // Still more to do...
0067 private:
0068 };
0069 
0070 ///registration of the test so that the runner can find it
0071 CPPUNIT_TEST_SUITE_REGISTRATION(testps);
0072 
0073 void testps::emptyTest() {
0074   edm::ParameterSet p1;
0075   std::string p1_encoded = p1.toString();
0076   edm::ParameterSet p2(p1_encoded);
0077   CPPUNIT_ASSERT(p1 == p2);
0078 }
0079 
0080 namespace {
0081   bool do_compare(const edm::EventRange& iLHS, const edm::EventRange& iRHS) {
0082     return iLHS.startEventID() == iRHS.startEventID() && iLHS.endEventID() == iRHS.endEventID();
0083   }
0084 
0085   template <class T>
0086   bool do_compare(const T& iLHS, const T& iRHS) {
0087     return iLHS == iRHS;
0088   }
0089 
0090   template <class T, class A>
0091   bool do_compare(const std::vector<T, A>& iLHS, const std::vector<T, A>& iRHS) {
0092     if (iLHS.size() != iRHS.size()) {
0093       return false;
0094     }
0095     typename std::vector<T, A>::const_iterator itL = iLHS.begin();
0096     typename std::vector<T, A>::const_iterator itR = iRHS.begin();
0097     typename std::vector<T, A>::const_iterator itLEnd = iLHS.end();
0098     for (; itL != itLEnd; ++itL, ++itR) {
0099       if (!do_compare(*itL, *itR)) {
0100         return false;
0101       }
0102     }
0103     return true;
0104   }
0105 
0106 }  // namespace
0107 
0108 template <class T>
0109 void trackedTestbody(const T& value) {
0110   try {
0111     edm::ParameterSet p1;
0112     p1.template addParameter<T>("x", value);
0113     p1.registerIt();
0114     CPPUNIT_ASSERT(do_compare(p1.template getParameter<T>("x"), value));
0115     std::string p1_encoded = p1.toString();
0116     edm::ParameterSet p2(p1_encoded);
0117     CPPUNIT_ASSERT(p1 == p2);
0118     CPPUNIT_ASSERT(do_compare(p2.template getParameter<T>("x"), value));
0119   } catch (cms::Exception& x) {
0120     std::cerr << "cms Exception caught, message follows\n" << x.what();
0121     throw;
0122   } catch (std::exception& x) {
0123     std::cerr << "std exception caught, message follows\n" << x.what();
0124     throw;
0125   } catch (...) {
0126     std::cerr << "Unrecognized exception type thrown\n"
0127               << "no details available\n";
0128     throw;
0129   }
0130 }
0131 
0132 template <class T>
0133 void untrackedTestbody(const T& value) {
0134   edm::ParameterSet p;
0135   p.template addUntrackedParameter<T>("x", value);
0136   CPPUNIT_ASSERT(do_compare(p.template getUntrackedParameter<T>("x"), value));
0137 
0138   CPPUNIT_ASSERT_THROW(p.template getUntrackedParameter<T>("does not exist"), cms::Exception);
0139 }
0140 
0141 template <class T>
0142 void testbody(T value) {
0143   trackedTestbody<T>(value);
0144   untrackedTestbody<T>(value);
0145 }
0146 
0147 void testps::boolTest() {
0148   testbody<bool>(false);
0149   testbody<bool>(true);
0150 }
0151 
0152 void testps::intTest() {
0153   testbody<int>(-std::numeric_limits<int>::max());
0154   testbody<int>(-2112);
0155   testbody<int>(-0);
0156   testbody<int>(0);
0157   testbody<int>(35621);
0158   testbody<int>(std::numeric_limits<int>::max());
0159 }
0160 
0161 void testps::uintTest() {
0162   testbody<unsigned int>(0);
0163   testbody<unsigned int>(35621);
0164   testbody<unsigned int>(std::numeric_limits<unsigned int>::max());
0165 
0166   testbody<std::vector<unsigned int> >(std::vector<unsigned int>());
0167   testbody<std::vector<unsigned int> >(std::vector<unsigned int>(1, 35621));
0168   testbody<std::vector<unsigned int> >(std::vector<unsigned int>(1, std::numeric_limits<unsigned int>::max()));
0169 }
0170 
0171 void testps::doubleTest() {
0172   testbody<double>(-1.25);
0173   testbody<double>(-0.0);
0174   testbody<double>(0.0);
0175   testbody<double>(1.25);
0176   //testbody<double>(1.0/0.0);  // parameter set does not handle infinity?
0177   //testbody<double>(0.0/0.0);  // parameter set does not handle NaN?
0178   testbody<double>(-2.3456789e-231);
0179   testbody<double>(-2.3456789e231);
0180   testbody<double>(2.3456789e-231);
0181   testbody<double>(2.3456789e231);
0182   double oneThird = 1.0 / 3.0;
0183   testbody<double>(oneThird);
0184 }
0185 
0186 void testps::stringTest() {
0187   testbody<std::string>("");
0188   testbody<std::string>("Hello there");
0189   testbody<std::string>("123");
0190   testbody<std::string>("This\nis\tsilly\n");
0191   std::vector<std::string> vs;
0192   vs.push_back("");
0193   vs.push_back("1");
0194   vs.push_back("");
0195   vs.push_back("three");
0196   testbody<std::vector<std::string> >(vs);
0197   edm::ParameterSet p1;
0198   p1.addParameter<std::vector<std::string> >("vs", vs);
0199   p1.registerIt();
0200   std::vector<std::string> vs2 = p1.getParameter<std::vector<std::string> >("vs");
0201   //FIXME doesn't count spaces
0202 }
0203 
0204 void testps::eventIDTest() {
0205   testbody<edm::EventID>(edm::EventID());
0206   testbody<edm::EventID>(edm::EventID::firstValidEvent());
0207   testbody<edm::EventID>(edm::EventID(2, 3, 4));
0208   testbody<edm::EventID>(edm::EventID(2, 3, edm::EventID::maxEventNumber()));
0209   testbody<edm::EventID>(edm::EventID(
0210       edm::EventID::maxRunNumber(), edm::EventID::maxLuminosityBlockNumber(), edm::EventID::maxEventNumber()));
0211 }
0212 
0213 void testps::eventRangeTest() {
0214   testbody<edm::EventRange>(edm::EventRange());
0215   testbody<edm::EventRange>(edm::EventRange(
0216       1, 1, 1, edm::EventID::maxRunNumber(), edm::EventID::maxLuminosityBlockNumber(), edm::EventID::maxEventNumber()));
0217   testbody<edm::EventRange>(edm::EventRange(2, 3, 4, 2, 3, 10));
0218 
0219   testbody<edm::EventRange>(edm::EventRange(1, 0, 1, edm::EventID::maxRunNumber(), 0, edm::EventID::maxEventNumber()));
0220   testbody<edm::EventRange>(edm::EventRange(2, 0, 4, 2, 0, 10));
0221 }
0222 
0223 void testps::vEventRangeTest() {
0224   testbody<std::vector<edm::EventRange> >(std::vector<edm::EventRange>());
0225   testbody<std::vector<edm::EventRange> >(
0226       std::vector<edm::EventRange>(1,
0227                                    edm::EventRange(1,
0228                                                    1,
0229                                                    1,
0230                                                    edm::EventID::maxRunNumber(),
0231                                                    edm::EventID::maxLuminosityBlockNumber(),
0232                                                    edm::EventID::maxEventNumber())));
0233 
0234   testbody<std::vector<edm::EventRange> >(std::vector<edm::EventRange>(
0235       1, edm::EventRange(1, 0, 1, edm::EventID::maxRunNumber(), 0, edm::EventID::maxEventNumber())));
0236 
0237   std::vector<edm::EventRange> er;
0238   er.reserve(2);
0239   er.push_back(edm::EventRange(2, 3, 4, 2, 3, 10));
0240   er.push_back(edm::EventRange(5, 1, 1, 10, 3, 10));
0241 
0242   testbody<std::vector<edm::EventRange> >(er);
0243 }
0244 
0245 void testps::fileInPathTest() {
0246   edm::ParameterSet p;
0247   edm::FileInPath fip("FWCore/ParameterSet/python/Config.py");
0248   p.addParameter<edm::FileInPath>("fip", fip);
0249   CPPUNIT_ASSERT(p.existsAs<edm::FileInPath>("fip"));
0250   CPPUNIT_ASSERT(p.getParameterNamesForType<edm::FileInPath>()[0] == "fip");
0251 }
0252 
0253 void testps::doubleEqualityTest() {
0254   edm::ParameterSet p1, p2, p3;
0255   p1.addParameter<double>("x", 0.1);
0256   p2.addParameter<double>("x", 1.0e-1);
0257   p3.addParameter<double>("x", 0.100);
0258   p1.registerIt();
0259   p2.registerIt();
0260   p3.registerIt();
0261   CPPUNIT_ASSERT(p1 == p2);
0262   CPPUNIT_ASSERT(p1 == p3);
0263   CPPUNIT_ASSERT(p2 == p3);
0264 
0265   CPPUNIT_ASSERT(p1.toString() == p2.toString());
0266   CPPUNIT_ASSERT(p1.toString() == p3.toString());
0267   CPPUNIT_ASSERT(p2.toString() == p3.toString());
0268 }
0269 
0270 void testps::negativeZeroTest() {
0271   edm::ParameterSet a1, a2;
0272   a1.addParameter<double>("x", 0.0);
0273   a2.addParameter<double>("x", -0.0);
0274   a1.registerIt();
0275   a2.registerIt();
0276   // Negative and positive zero should be coded differently.
0277   CPPUNIT_ASSERT(a1.toString() != a2.toString());
0278   CPPUNIT_ASSERT(a1 != a2);
0279   // Negative and positive zero should test equal.
0280   CPPUNIT_ASSERT(a1.getParameter<double>("x") == a2.getParameter<double>("x"));
0281 }
0282 
0283 void testps::idTest() {
0284   edm::ParameterSet a;
0285   a.registerIt();
0286   edm::ParameterSetID a_id = a.id();
0287   edm::ParameterSet b;
0288   b.addParameter<int>("x", -23);
0289   b.registerIt();
0290   edm::ParameterSetID b_id = b.id();
0291 
0292   CPPUNIT_ASSERT(a != b);
0293   CPPUNIT_ASSERT(a.id() != b.id());
0294 
0295   {
0296     //Check that changes to ESInputTag do not affect ID
0297     // as that would affect reading back stored PSets
0298 
0299     edm::ParameterSet ps;
0300     ps.addParameter<edm::ESInputTag>("default", edm::ESInputTag());
0301     ps.addParameter<edm::ESInputTag>("moduleOnly", edm::ESInputTag("Prod", ""));
0302     ps.addParameter<edm::ESInputTag>("dataOnly", edm::ESInputTag("", "data"));
0303     ps.addParameter<edm::ESInputTag>("allLabels", edm::ESInputTag("Prod", "data"));
0304     ps.registerIt();
0305 
0306     std::string stringValue;
0307     ps.id().toString(stringValue);
0308     CPPUNIT_ASSERT(stringValue == "01642a9a7311dea2df2f9ee430855a99");
0309   }
0310 }
0311 
0312 void testps::calculateIDTest() {
0313   std::vector<int> thousand(1000, 0);
0314   std::vector<int> hundred(100, 0);
0315   edm::ParameterSet a;
0316   edm::ParameterSet b;
0317   edm::ParameterSet c;
0318   a.addParameter<double>("pi", 3.14);
0319   a.addParameter<int>("answer", 42), a.addParameter<std::string>("amiga", "rules");
0320   a.addParameter<std::vector<int> >("thousands", thousand);
0321   a.addUntrackedParameter<double>("e", 2.72);
0322   a.addUntrackedParameter<int>("question", 41 + 1);
0323   a.addUntrackedParameter<std::string>("atari", "too");
0324   a.addUntrackedParameter<std::vector<int> >("hundred", hundred);
0325 
0326   b.addParameter<double>("pi", 3.14);
0327   b.addParameter<int>("answer", 42), b.addParameter<std::string>("amiga", "rules");
0328   b.addParameter<std::vector<int> >("thousands", thousand);
0329   b.addUntrackedParameter<double>("e", 2.72);
0330   b.addUntrackedParameter<int>("question", 41 + 1);
0331   b.addUntrackedParameter<std::string>("atari", "too");
0332   b.addUntrackedParameter<std::vector<int> >("hundred", hundred);
0333 
0334   c.addParameter<double>("pi", 3.14);
0335   c.addParameter<int>("answer", 42), c.addParameter<std::string>("amiga", "rules");
0336   c.addParameter<std::vector<int> >("thousands", thousand);
0337   c.addUntrackedParameter<double>("e", 2.72);
0338   c.addUntrackedParameter<int>("question", 41 + 1);
0339   c.addUntrackedParameter<std::string>("atari", "too");
0340   c.addUntrackedParameter<std::vector<int> >("hundred", hundred);
0341 
0342   b.addParameter<edm::ParameterSet>("nested", c);
0343   std::vector<edm::ParameterSet> vb;
0344   vb.push_back(b);
0345 
0346   a.addUntrackedParameter<std::vector<edm::ParameterSet> >("vps", vb);
0347   std::string stringrep;
0348   a.toString(stringrep);
0349   cms::Digest md5alg(stringrep);
0350   cms::Digest newDigest;
0351   a.toDigest(newDigest);
0352   CPPUNIT_ASSERT(md5alg.digest().toString() == newDigest.digest().toString());
0353 }
0354 
0355 void testps::mapByIdTest() {
0356   // makes parameter sets and ids
0357   edm::ParameterSet a;
0358   a.addParameter<double>("pi", 3.14);
0359   a.addParameter<std::string>("name", "Bub");
0360   a.registerIt();
0361   CPPUNIT_ASSERT(a.exists("pi"));
0362   CPPUNIT_ASSERT(!a.exists("pie"));
0363 
0364   edm::ParameterSet b;
0365   b.addParameter<bool>("b", false);
0366   b.addParameter<std::vector<int> >("three_zeros", std::vector<int>(3, 0));
0367   b.registerIt();
0368 
0369   edm::ParameterSet c;
0370   c.registerIt();
0371 
0372   edm::ParameterSet d;
0373   d.addParameter<unsigned int>("hundred", 100);
0374   d.addParameter<std::vector<double> >("empty", std::vector<double>());
0375   d.registerIt();
0376 
0377   edm::ParameterSetID id_a = a.id();
0378   edm::ParameterSetID id_b = b.id();
0379   edm::ParameterSetID id_c = c.id();
0380   edm::ParameterSetID id_d = d.id();
0381 
0382   // fill map
0383   typedef std::map<edm::ParameterSetID, edm::ParameterSet> map_t;
0384   map_t psets;
0385 
0386   psets.insert(std::make_pair(id_a, a));
0387   psets.insert(std::make_pair(id_b, b));
0388   psets.insert(std::make_pair(id_c, c));
0389   psets.insert(std::make_pair(id_d, d));
0390 
0391   // query map
0392   CPPUNIT_ASSERT(psets.size() == 4);
0393   CPPUNIT_ASSERT(psets[id_a] == a);
0394   CPPUNIT_ASSERT(psets[id_b] == b);
0395   CPPUNIT_ASSERT(psets[id_c] == c);
0396   CPPUNIT_ASSERT(psets[id_d] == d);
0397 }
0398 
0399 template <class T>
0400 void test_for_name() {
0401   edm::ParameterSet preal;
0402   edm::ParameterSet const& ps = preal;
0403   // Use 'ps' to make sure we're only getting 'const' access;
0404   // use 'preal' when we need to modify the underlying ParameterSet.
0405 
0406   std::vector<std::string> names = ps.getParameterNames();
0407   CPPUNIT_ASSERT(names.empty());
0408 
0409   // The following causes failure, because of an apparent GCC bug in comparing bools!
0410   //T value;
0411   // Instead, we use this more verbose initialization...
0412   T value = T();
0413   preal.template addParameter<T>("x", value);
0414   names = ps.getParameterNames();
0415   CPPUNIT_ASSERT(names.size() == 1);
0416   CPPUNIT_ASSERT(names[0] == "x");
0417   T stored_value = ps.template getParameter<T>(names[0]);
0418   CPPUNIT_ASSERT(stored_value == value);
0419 
0420   preal.template addUntrackedParameter<T>("y", value);
0421   preal.registerIt();
0422   names = ps.getParameterNames();
0423   CPPUNIT_ASSERT(names.size() == 2);
0424 
0425   edm::sort_all(names);
0426   CPPUNIT_ASSERT(edm::binary_search_all(names, "x"));
0427   CPPUNIT_ASSERT(edm::binary_search_all(names, "y"));
0428   names = ps.template getParameterNamesForType<T>();
0429   CPPUNIT_ASSERT(names.size() == 1);
0430   edm::sort_all(names);
0431   CPPUNIT_ASSERT(edm::binary_search_all(names, "x"));
0432   names = ps.template getParameterNamesForType<T>(false);
0433   CPPUNIT_ASSERT(names.size() == 1);
0434   edm::sort_all(names);
0435   CPPUNIT_ASSERT(edm::binary_search_all(names, "y"));
0436 
0437   std::string firstString = ps.toString();
0438   edm::ParameterSet p2(firstString);
0439 
0440   p2.registerIt();
0441   // equality tests toStringOfTracked internally
0442   CPPUNIT_ASSERT(ps == p2);
0443   std::string allString;
0444   ps.allToString(allString);
0445   //since have untracked parameter these strings will not be identical
0446   CPPUNIT_ASSERT(firstString != allString);
0447 
0448   edm::ParameterSet pAll(allString);
0449   CPPUNIT_ASSERT(pAll.getParameterNames().size() == 2);
0450 }
0451 
0452 void testps::nameAccessTest() {
0453   test_for_name<bool>();
0454 
0455   test_for_name<int>();
0456   test_for_name<std::vector<int> >();
0457 
0458   test_for_name<unsigned int>();
0459   test_for_name<std::vector<unsigned int> >();
0460 
0461   test_for_name<double>();
0462   test_for_name<std::vector<double> >();
0463 
0464   test_for_name<std::string>();
0465   test_for_name<std::vector<std::string> >();
0466   test_for_name<edm::ParameterSet>();
0467   test_for_name<std::vector<edm::ParameterSet> >();
0468 
0469   // Can't make default FileInPath objects...
0470 
0471   // Now make sure that if we put in a parameter of type A, we don't
0472   // see it when we ask for names of type B != A.
0473   {
0474     edm::ParameterSet p;
0475     p.addParameter<double>("a", 2.5);
0476     p.registerIt();
0477     const bool tracked = true;
0478     std::vector<std::string> names = p.getParameterNamesForType<int>(tracked);
0479     CPPUNIT_ASSERT(names.empty());
0480   }
0481 }
0482 
0483 void testps::testEmbeddedPSet() {
0484   edm::ParameterSet ps;
0485   edm::ParameterSet psEmbedded, psDeeper;
0486   psEmbedded.addUntrackedParameter<std::string>("p1", "wham");
0487   psEmbedded.addParameter<std::string>("p2", "bam");
0488   psDeeper.addParameter<int>("deepest", 6);
0489   psDeeper.registerIt();
0490   edm::InputTag it("label", "instance");
0491   std::vector<edm::InputTag> vit;
0492   vit.push_back(it);
0493   psEmbedded.addParameter<edm::InputTag>("it", it);
0494   psEmbedded.addParameter<std::vector<edm::InputTag> >("vit", vit);
0495   psEmbedded.addParameter<edm::ParameterSet>("psDeeper", psDeeper);
0496   psEmbedded.registerIt();
0497   ps.addParameter<edm::ParameterSet>("psEmbedded", psEmbedded);
0498   ps.addParameter<double>("topLevel", 1.);
0499   ps.addUntrackedParameter<unsigned long long>("u64", 64);
0500 
0501   std::vector<edm::ParameterSet> vpset;
0502   edm::ParameterSet pset1;
0503   pset1.addParameter<int>("int1", 1);
0504   edm::ParameterSet pset2;
0505   pset2.addParameter<int>("int2", 2);
0506   edm::ParameterSet pset3;
0507   pset3.addParameter<int>("int3", 3);
0508   vpset.push_back(pset1);
0509   vpset.push_back(pset2);
0510   vpset.push_back(pset3);
0511   ps.addParameter<std::vector<edm::ParameterSet> >("psVPset", vpset);
0512 
0513   ps.registerIt();
0514 
0515   std::string rep = ps.toString();
0516   edm::ParameterSet defrosted(rep);
0517   defrosted.registerIt();
0518   edm::ParameterSet trackedPart(ps.trackedPart());
0519 
0520   CPPUNIT_ASSERT(defrosted == ps);
0521   CPPUNIT_ASSERT(trackedPart.exists("psEmbedded"));
0522   CPPUNIT_ASSERT(trackedPart.getParameterSet("psEmbedded").exists("p2"));
0523   CPPUNIT_ASSERT(!trackedPart.getParameterSet("psEmbedded").exists("p1"));
0524   CPPUNIT_ASSERT(trackedPart.getParameterSet("psEmbedded").getParameterSet("psDeeper").getParameter<int>("deepest") ==
0525                  6);
0526   CPPUNIT_ASSERT(ps.getUntrackedParameter<unsigned long long>("u64") == 64);
0527   CPPUNIT_ASSERT(!trackedPart.exists("u64"));
0528   std::vector<edm::ParameterSet> const& vpset1 = trackedPart.getParameterSetVector("psVPset");
0529   CPPUNIT_ASSERT(vpset1[0].getParameter<int>("int1") == 1);
0530   CPPUNIT_ASSERT(vpset1[1].getParameter<int>("int2") == 2);
0531   CPPUNIT_ASSERT(vpset1[2].getParameter<int>("int3") == 3);
0532 }
0533 
0534 void testps::testRegistration() {
0535   edm::ParameterSet ps;
0536   edm::ParameterSet psEmbedded, psDeeper;
0537   psEmbedded.addUntrackedParameter<std::string>("p1", "wham");
0538   psEmbedded.addParameter<std::string>("p2", "bam");
0539   psDeeper.addParameter<int>("deepest", 6);
0540   psDeeper.registerIt();
0541   edm::InputTag it("label", "instance");
0542   std::vector<edm::InputTag> vit;
0543   vit.push_back(it);
0544   psEmbedded.addParameter<edm::InputTag>("it", it);
0545   psEmbedded.addParameter<std::vector<edm::InputTag> >("vit", vit);
0546   psEmbedded.addParameter<edm::ParameterSet>("psDeeper", psDeeper);
0547   psEmbedded.registerIt();
0548   ps.addParameter<edm::ParameterSet>("psEmbedded", psEmbedded);
0549   ps.addParameter<double>("topLevel", 1.);
0550   ps.addUntrackedParameter<unsigned long long>("u64", 64);
0551   ps.registerIt();
0552   CPPUNIT_ASSERT(ps.isRegistered());
0553   CPPUNIT_ASSERT(psEmbedded.isRegistered());
0554   CPPUNIT_ASSERT(psDeeper.isRegistered());
0555   psEmbedded.addParameter<std::string>("p3", "slam");
0556   CPPUNIT_ASSERT(ps.isRegistered());
0557   CPPUNIT_ASSERT(!psEmbedded.isRegistered());
0558   CPPUNIT_ASSERT(psDeeper.isRegistered());
0559 }
0560 
0561 void testps::testCopyFrom() {
0562   edm::ParameterSet psOld;
0563   edm::ParameterSet psNew;
0564   edm::ParameterSet psInternal;
0565   std::vector<edm::ParameterSet> vpset;
0566   vpset.push_back(psInternal);
0567   psOld.addParameter<int>("i", 5);
0568   psOld.addParameter<edm::ParameterSet>("ps", psInternal);
0569   psOld.addParameter<std::vector<edm::ParameterSet> >("vps", vpset);
0570   psNew.copyFrom(psOld, "i");
0571   psNew.copyFrom(psOld, "ps");
0572   psNew.copyFrom(psOld, "vps");
0573   CPPUNIT_ASSERT(psNew.existsAs<int>("i"));
0574   CPPUNIT_ASSERT(psNew.existsAs<edm::ParameterSet>("ps"));
0575   CPPUNIT_ASSERT(psNew.existsAs<std::vector<edm::ParameterSet> >("vps"));
0576 }
0577 
0578 void testps::testGetParameterAsString() {
0579   edm::ParameterSet ps;
0580   edm::ParameterSet psInternal;
0581   std::vector<edm::ParameterSet> vpset;
0582   vpset.push_back(psInternal);
0583   ps.addParameter<int>("i", 5);
0584   ps.addParameter<edm::ParameterSet>("ps", psInternal);
0585   ps.addParameter<std::vector<edm::ParameterSet> >("vps", vpset);
0586   ps.registerIt();
0587   psInternal.registerIt();
0588   std::string parStr = ps.getParameterAsString("i");
0589   std::string psetStr = ps.getParameterAsString("ps");
0590   std::string vpsetStr = ps.getParameterAsString("vps");
0591   std::string parStr2 = ps.retrieve("i").toString();
0592   std::string psetStr2 = ps.retrieveParameterSet("ps").toString();
0593   std::string vpsetStr2 = ps.retrieveVParameterSet("vps").toString();
0594   CPPUNIT_ASSERT(parStr == parStr2);
0595   CPPUNIT_ASSERT(psetStr == psetStr2);
0596   CPPUNIT_ASSERT(vpsetStr == vpsetStr2);
0597 }
0598 
0599 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>