Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:03

0001 #include "FWCore/Utilities/interface/EDMException.h"
0002 #include "SimGeneral/HepPDTRecord/interface/PdtEntry.h"
0003 #include <cppunit/extensions/HelperMacros.h>
0004 #include <iostream>
0005 using namespace std;
0006 using namespace edm;
0007 
0008 class testPdtEntry : public CppUnit::TestFixture {
0009   CPPUNIT_TEST_SUITE(testPdtEntry);
0010   CPPUNIT_TEST(checkAll);
0011   CPPUNIT_TEST_SUITE_END();
0012 
0013 public:
0014   void setUp() override {}
0015   void tearDown() override {}
0016   void checkAll();
0017 };
0018 
0019 CPPUNIT_TEST_SUITE_REGISTRATION(testPdtEntry);
0020 
0021 void testPdtEntry::checkAll() {
0022   using namespace std;
0023   PdtEntry e(13);
0024   CPPUNIT_ASSERT_THROW(e.name(), cms::Exception);
0025   PdtEntry n("mu-");
0026   CPPUNIT_ASSERT_THROW(n.pdgId(), cms::Exception);
0027 
0028   {
0029     ParameterSet cfg;
0030     cfg.addParameter<int>("pdt1", 13);
0031     cfg.addParameter<string>("pdt2", "mu-");
0032     int pdt1 = cfg.getParameter<int>("pdt1");
0033     string pdt2 = cfg.getParameter<string>("pdt2");
0034     PdtEntry e1 = cfg.getParameter<PdtEntry>("pdt1");
0035     PdtEntry e2 = cfg.getParameter<PdtEntry>("pdt2");
0036     CPPUNIT_ASSERT(pdt1 == e1.pdgId());
0037     CPPUNIT_ASSERT(pdt2 == e2.name());
0038     vector<string> p = cfg.getParameterNamesForType<PdtEntry>();
0039     CPPUNIT_ASSERT(p.size() == 2);
0040   }
0041   {
0042     ParameterSet cfg;
0043     cfg.addUntrackedParameter<int>("pdt1", 13);
0044     cfg.addUntrackedParameter<string>("pdt2", "mu-");
0045     int pdt1 = cfg.getUntrackedParameter<int>("pdt1");
0046     string pdt2 = cfg.getUntrackedParameter<string>("pdt2");
0047     PdtEntry e1 = cfg.getUntrackedParameter<PdtEntry>("pdt1");
0048     PdtEntry e2 = cfg.getUntrackedParameter<PdtEntry>("pdt2");
0049     CPPUNIT_ASSERT(pdt1 == e1.pdgId());
0050     CPPUNIT_ASSERT(pdt2 == e2.name());
0051   }
0052   {
0053     ParameterSet cfg;
0054     int pdt1 = cfg.getUntrackedParameter<int>("pdt1", 13);
0055     string pdt2 = cfg.getUntrackedParameter<string>("pdt2", "mu-");
0056     PdtEntry e1 = cfg.getUntrackedParameter<PdtEntry>("pdt1", PdtEntry(13));
0057     PdtEntry e2 = cfg.getUntrackedParameter<PdtEntry>("pdt2", PdtEntry("mu-"));
0058     CPPUNIT_ASSERT(pdt1 == e1.pdgId());
0059     CPPUNIT_ASSERT(pdt2 == e2.name());
0060   }
0061   {
0062     ParameterSet cfg;
0063     cfg.addParameter<vector<int>>("pdt1", vector<int>(1, 13));
0064     cfg.addParameter<vector<string>>("pdt2", vector<string>(1, "mu-"));
0065     vector<int> pdt1 = cfg.getParameter<vector<int>>("pdt1");
0066     vector<string> pdt2 = cfg.getParameter<vector<string>>("pdt2");
0067     vector<PdtEntry> e1 = cfg.getParameter<vector<PdtEntry>>("pdt1");
0068     vector<PdtEntry> e2 = cfg.getParameter<vector<PdtEntry>>("pdt2");
0069     CPPUNIT_ASSERT(e1.size() == pdt1.size());
0070     CPPUNIT_ASSERT(e2.size() == pdt2.size());
0071     CPPUNIT_ASSERT(pdt1.front() == e1.front().pdgId());
0072     CPPUNIT_ASSERT(pdt2.front() == e2.front().name());
0073   }
0074   {
0075     ParameterSet cfg;
0076     cfg.addUntrackedParameter<vector<int>>("pdt1", vector<int>(1, 13));
0077     cfg.addUntrackedParameter<vector<string>>("pdt2", vector<string>(1, "mu-"));
0078     vector<int> pdt1 = cfg.getUntrackedParameter<vector<int>>("pdt1");
0079     vector<string> pdt2 = cfg.getUntrackedParameter<vector<string>>("pdt2");
0080     vector<PdtEntry> e1 = cfg.getUntrackedParameter<vector<PdtEntry>>("pdt1");
0081     vector<PdtEntry> e2 = cfg.getUntrackedParameter<vector<PdtEntry>>("pdt2");
0082     CPPUNIT_ASSERT(e1.size() == pdt1.size());
0083     CPPUNIT_ASSERT(e2.size() == pdt2.size());
0084     CPPUNIT_ASSERT(pdt1.front() == e1.front().pdgId());
0085     CPPUNIT_ASSERT(pdt2.front() == e2.front().name());
0086   }
0087   {
0088     ParameterSet cfg;
0089     vector<int> pdt1 = cfg.getUntrackedParameter<vector<int>>("pdt1", vector<int>(1, 13));
0090     vector<string> pdt2 = cfg.getUntrackedParameter<vector<string>>("pdt2", vector<string>(1, "mu-"));
0091     vector<PdtEntry> e1 = cfg.getUntrackedParameter<vector<PdtEntry>>("pdt1", vector<PdtEntry>(1, PdtEntry(13)));
0092     vector<PdtEntry> e2 = cfg.getUntrackedParameter<vector<PdtEntry>>("pdt2", vector<PdtEntry>(1, PdtEntry("mu-")));
0093     CPPUNIT_ASSERT(e1.size() == pdt1.size());
0094     CPPUNIT_ASSERT(e2.size() == pdt2.size());
0095     CPPUNIT_ASSERT(pdt1.front() == e1.front().pdgId());
0096     CPPUNIT_ASSERT(pdt2.front() == e2.front().name());
0097   }
0098 }