File indexing completed on 2024-04-06 12:13:01
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <cppunit/extensions/HelperMacros.h>
0010
0011 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0012 #include <FWCore/PythonParameterSet/interface/PyBind11ProcessDesc.h>
0013 #include "FWCore/Utilities/interface/EDMException.h"
0014
0015 #include <memory>
0016
0017 #include <vector>
0018 #include <string>
0019 #include <iostream>
0020
0021 class testProcessDesc : public CppUnit::TestFixture {
0022 CPPUNIT_TEST_SUITE(testProcessDesc);
0023
0024 CPPUNIT_TEST(trivialPathTest);
0025 CPPUNIT_TEST(simplePathTest);
0026 CPPUNIT_TEST(sequenceSubstitutionTest);
0027 CPPUNIT_TEST(attriggertest);
0028 CPPUNIT_TEST(nestedSequenceSubstitutionTest);
0029 CPPUNIT_TEST(sequenceSubstitutionTest2);
0030 CPPUNIT_TEST(sequenceSubstitutionTest3);
0031 CPPUNIT_TEST(multiplePathsTest);
0032
0033
0034
0035
0036 CPPUNIT_TEST_SUITE_END();
0037
0038 public:
0039 void setUp() {}
0040 void tearDown() {}
0041
0042 void trivialPathTest();
0043 void simplePathTest();
0044 void sequenceSubstitutionTest();
0045 void attriggertest();
0046 void nestedSequenceSubstitutionTest();
0047 void sequenceSubstitutionTest2();
0048 void sequenceSubstitutionTest3();
0049 void multiplePathsTest();
0050 void inconsistentPathTest();
0051 void inconsistentMultiplePathTest();
0052 };
0053
0054
0055 CPPUNIT_TEST_SUITE_REGISTRATION(testProcessDesc);
0056
0057 void testProcessDesc::trivialPathTest() {
0058 std::string str =
0059 "import FWCore.ParameterSet.Config as cms\n"
0060 "process = cms.Process('X')\n"
0061 "process.a = cms.EDFilter('A',\n"
0062 " p = cms.int32(3)\n"
0063 ")\n"
0064 "process.b = cms.EDProducer('B')\n"
0065 "process.c = cms.EDProducer('C')\n"
0066 "process.p = cms.Path(process.a*process.b*process.c)\n";
0067
0068 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0069
0070 typedef std::vector<std::string> Strs;
0071
0072 Strs s = (*test).getParameter<std::vector<std::string> >("p");
0073 CPPUNIT_ASSERT(s[0] == "a");
0074
0075 }
0076
0077 void testProcessDesc::simplePathTest() {
0078 std::string str =
0079 "import FWCore.ParameterSet.Config as cms\n"
0080 "process = cms.Process('X')\n"
0081 "process.a = cms.EDFilter('A',\n"
0082 " p = cms.int32(3)\n"
0083 ")\n"
0084 "process.b = cms.EDFilter('A',\n"
0085 " p = cms.int32(3)\n"
0086 ")\n"
0087 "process.c = cms.EDFilter('A',\n"
0088 " p = cms.int32(3)\n"
0089 ")\n"
0090 "process.p = cms.Path(process.a*process.b*process.c)\n";
0091
0092 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0093
0094 typedef std::vector<std::string> Strs;
0095
0096 Strs s = (*test).getParameter<std::vector<std::string> >("p");
0097 CPPUNIT_ASSERT(s[0] == "a");
0098 CPPUNIT_ASSERT(s[1] == "b");
0099 CPPUNIT_ASSERT(s[2] == "c");
0100
0101
0102
0103
0104 }
0105
0106 void testProcessDesc::attriggertest() {
0107 std::string str =
0108 "import FWCore.ParameterSet.Config as cms\n"
0109 "process = cms.Process('test')\n"
0110 "process.cone1 = cms.EDFilter('PhonyConeJet',\n"
0111 " i = cms.int32(5)\n"
0112 ")\n"
0113 "process.cone2 = cms.EDFilter('PhonyConeJet',\n"
0114 " i = cms.int32(7)\n"
0115 ")\n"
0116 "process.somejet1 = cms.EDFilter('PhonyJet',\n"
0117 " i = cms.int32(7)\n"
0118 ")\n"
0119 "process.somejet2 = cms.EDFilter('PhonyJet',\n"
0120 " i = cms.int32(7)\n"
0121 ")\n"
0122 "process.jtanalyzer = cms.EDFilter('PhonyConeJet',\n"
0123 " i = cms.int32(7)\n"
0124 ")\n"
0125 "process.output = cms.OutputModule('OutputModule')\n"
0126 "process.cones = cms.Sequence(process.cone1*process.cone2)\n"
0127 "process.jets = cms.Sequence(process.somejet1*process.somejet2)\n"
0128 "process.path1 = cms.Path(process.cones*process.jets*process.jtanalyzer)\n"
0129 "process.epath = cms.EndPath(process.output)\n";
0130
0131 try {
0132 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0133
0134 typedef std::vector<std::string> Strs;
0135
0136 edm::ParameterSet const& trig_pset = (*test).getParameterSet("@trigger_paths");
0137 Strs tnames = trig_pset.getParameter<Strs>("@trigger_paths");
0138 Strs enames = (*test).getParameter<Strs>("@end_paths");
0139
0140 CPPUNIT_ASSERT(tnames[0] == "path1");
0141 CPPUNIT_ASSERT(enames[0] == "epath");
0142
0143
0144 Strs schedule = (*test).getParameter<Strs>("@paths");
0145 CPPUNIT_ASSERT(schedule.size() == 2);
0146 CPPUNIT_ASSERT(schedule[0] == "path1");
0147 CPPUNIT_ASSERT(schedule[1] == "epath");
0148
0149 } catch (cms::Exception& exc) {
0150 std::cerr << "Got an cms::Exception: " << exc.what() << "\n";
0151 throw;
0152 } catch (std::exception& exc) {
0153 std::cerr << "Got an std::exception: " << exc.what() << "\n";
0154 throw;
0155 } catch (...) {
0156 std::cerr << "Got an unknown exception: "
0157 << "\n";
0158 throw;
0159 }
0160 }
0161
0162 void testProcessDesc::sequenceSubstitutionTest() {
0163 std::string str =
0164 "import FWCore.ParameterSet.Config as cms\n"
0165 "process = cms.Process('test')\n"
0166 "process.cone1 = cms.EDFilter('PhonyConeJet',\n"
0167 " i = cms.int32(5)\n"
0168 ")\n"
0169 "process.cone2 = cms.EDFilter('PhonyConeJet',\n"
0170 " i = cms.int32(7)\n"
0171 ")\n"
0172 "process.somejet1 = cms.EDFilter('PhonyJet',\n"
0173 " i = cms.int32(7)\n"
0174 ")\n"
0175 "process.somejet2 = cms.EDFilter('PhonyJet',\n"
0176 " i = cms.int32(7)\n"
0177 ")\n"
0178 "process.jtanalyzer = cms.EDFilter('PhonyConeJet',\n"
0179 " i = cms.int32(7)\n"
0180 ")\n"
0181 "process.cones = cms.Sequence(process.cone1*process.cone2)\n"
0182 "process.jets = cms.Sequence(process.somejet1*process.somejet2)\n"
0183 "process.path1 = cms.Path(process.cones*process.jets*process.jtanalyzer)\n";
0184
0185 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0186
0187 typedef std::vector<std::string> Strs;
0188
0189 Strs s = (*test).getParameter<std::vector<std::string> >("path1");
0190 CPPUNIT_ASSERT(s[0] == "cone1");
0191 CPPUNIT_ASSERT(s[1] == "cone2");
0192 CPPUNIT_ASSERT(s[2] == "somejet1");
0193 CPPUNIT_ASSERT(s[3] == "somejet2");
0194 CPPUNIT_ASSERT(s[4] == "jtanalyzer");
0195
0196
0197
0198
0199
0200
0201 }
0202
0203 void testProcessDesc::nestedSequenceSubstitutionTest() {
0204 std::string str =
0205 "import FWCore.ParameterSet.Config as cms\n"
0206 "process = cms.Process('test')\n"
0207 "process.a = cms.EDProducer('PhonyConeJet', i = cms.int32(5))\n"
0208 "process.b = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0209 "process.c = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0210 "process.d = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0211 "process.s1 = cms.Sequence( process.a+ process.b)\n"
0212 "process.s2 = cms.Sequence(process.s1+ process.c)\n"
0213 "process.path1 = cms.Path(process.s2+process.d)\n";
0214 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0215
0216 typedef std::vector<std::string> Strs;
0217
0218 Strs s = (*test).getParameter<std::vector<std::string> >("path1");
0219 CPPUNIT_ASSERT(s[0] == "a");
0220 CPPUNIT_ASSERT(s[1] == "b");
0221 CPPUNIT_ASSERT(s[2] == "c");
0222 CPPUNIT_ASSERT(s[3] == "d");
0223
0224
0225
0226
0227
0228 }
0229
0230 void testProcessDesc::sequenceSubstitutionTest2() {
0231 std::string str =
0232 "import FWCore.ParameterSet.Config as cms\n"
0233 "process = cms.Process('test')\n"
0234 "process.cone1 = cms.EDProducer('PhonyConeJet', i = cms.int32(5))\n"
0235 "process.cone2 = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0236 "process.cone3 = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0237 "process.somejet1 = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0238 "process.somejet2 = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0239 "process.jtanalyzer = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0240 "process.cones = cms.Sequence(process.cone1+ process.cone2+ process.cone3)\n"
0241 "process.jets = cms.Sequence(process.somejet1+ process.somejet2)\n"
0242 "process.path1 = cms.Path(process.cones+process.jets+ process.jtanalyzer)\n";
0243
0244 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0245
0246 typedef std::vector<std::string> Strs;
0247
0248 Strs s = (*test).getParameter<std::vector<std::string> >("path1");
0249 CPPUNIT_ASSERT(s[0] == "cone1");
0250 CPPUNIT_ASSERT(s[1] == "cone2");
0251 CPPUNIT_ASSERT(s[2] == "cone3");
0252 CPPUNIT_ASSERT(s[3] == "somejet1");
0253 CPPUNIT_ASSERT(s[4] == "somejet2");
0254 CPPUNIT_ASSERT(s[5] == "jtanalyzer");
0255
0256
0257
0258
0259
0260
0261
0262 }
0263
0264 void testProcessDesc::sequenceSubstitutionTest3() {
0265 std::string str =
0266 "import FWCore.ParameterSet.Config as cms\n"
0267 "process = cms.Process('test')\n"
0268 "process.a = cms.EDProducer('PhonyConeJet', i = cms.int32(5))\n"
0269 "process.b = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0270 "process.c = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0271 "process.aa = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0272 "process.bb = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0273 "process.cc = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0274 "process.dd = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0275 "process.aaa = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0276 "process.bbb = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0277 "process.ccc = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0278 "process.ddd = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0279 "process.eee = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0280 "process.last = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0281
0282 "process.s1 = cms.Sequence(process.a* process.b* process.c)\n"
0283 "process.s2 = cms.Sequence(process.aa*process.bb*cms.ignore(process.cc)*process.dd)\n"
0284 "process.s3 = cms.Sequence(process.aaa*process.bbb*~process.ccc*process.ddd*process.eee)\n"
0285 "process.path1 = cms.Path(process.s1+process.s3+process.s2+process.last)\n";
0286
0287 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0288
0289 typedef std::vector<std::string> Strs;
0290
0291 Strs s = (*test).getParameter<std::vector<std::string> >("path1");
0292 CPPUNIT_ASSERT(s[0] == "a");
0293 CPPUNIT_ASSERT(s[1] == "b");
0294 CPPUNIT_ASSERT(s[2] == "c");
0295 CPPUNIT_ASSERT(s[3] == "aaa");
0296 CPPUNIT_ASSERT(s[4] == "bbb");
0297 CPPUNIT_ASSERT(s[5] == "!ccc");
0298 CPPUNIT_ASSERT(s[6] == "ddd");
0299 CPPUNIT_ASSERT(s[7] == "eee");
0300 CPPUNIT_ASSERT(s[8] == "aa");
0301 CPPUNIT_ASSERT(s[9] == "bb");
0302 CPPUNIT_ASSERT(s[10] == "-cc");
0303 CPPUNIT_ASSERT(s[11] == "dd");
0304 CPPUNIT_ASSERT(s[12] == "last");
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319 }
0320
0321 void testProcessDesc::multiplePathsTest() {
0322 std::string str =
0323 "import FWCore.ParameterSet.Config as cms\n"
0324 "process = cms.Process('test')\n"
0325 "process.cone1 = cms.EDProducer('PhonyConeJet', i = cms.int32(5))\n"
0326 "process.cone2 = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0327 "process.cone3 = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0328 "process.somejet1 = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0329 "process.somejet2 = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0330 "process.jtanalyzer = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0331 "process.anotherjtanalyzer = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0332 "process.cones = cms.Sequence(process.cone1* process.cone2* process.cone3)\n"
0333 "process.jets = cms.Sequence(process.somejet1* process.somejet2)\n"
0334 "process.path1 = cms.Path(process.cones+ process.jtanalyzer)\n"
0335 "process.path2 = cms.Path(process.jets+ process.anotherjtanalyzer)\n"
0336 "process.schedule = cms.Schedule(process.path2, process.path1)\n";
0337
0338 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0339
0340 typedef std::vector<std::string> Strs;
0341
0342 Strs s = (*test).getParameter<std::vector<std::string> >("path1");
0343 CPPUNIT_ASSERT(s[0] == "cone1");
0344 CPPUNIT_ASSERT(s[1] == "cone2");
0345 CPPUNIT_ASSERT(s[2] == "cone3");
0346 CPPUNIT_ASSERT(s[3] == "jtanalyzer");
0347
0348
0349
0350
0351
0352
0353 s = (*test).getParameter<std::vector<std::string> >("path2");
0354 CPPUNIT_ASSERT(s[0] == "somejet1");
0355 CPPUNIT_ASSERT(s[1] == "somejet2");
0356 CPPUNIT_ASSERT(s[2] == "anotherjtanalyzer");
0357
0358
0359
0360
0361
0362 Strs schedule = (*test).getParameter<std::vector<std::string> >("@paths");
0363
0364 CPPUNIT_ASSERT(schedule.size() == 2);
0365 CPPUNIT_ASSERT(schedule[0] == "path2");
0366 CPPUNIT_ASSERT(schedule[1] == "path1");
0367 }
0368
0369 void testProcessDesc::inconsistentPathTest() {
0370 std::string str =
0371 "import FWCore.ParameterSet.Config as cms\n"
0372 "process = cms.Process('test')\n"
0373 "process.a = cms.EDProducer('PhonyConeJet', i = cms.int32(5))\n"
0374 "process.b = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0375 "process.c = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0376 "process.path1 = cms.Path((process.a*process.b)+ (process.c*process.b))\n";
0377 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0378 }
0379
0380 void testProcessDesc::inconsistentMultiplePathTest() {
0381 std::string str =
0382 "import FWCore.ParameterSet.Config as cms\n"
0383 "process = cms.Process('test')\n"
0384 "process.cone1 = cms.EDProducer('PhonyConeJet', i = cms.int32(5))\n"
0385 "process.cone2 = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0386 "process.somejet1 = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0387 "process.somejet2 = cms.EDProducer('PhonyJet', i = cms.int32(7))\n"
0388 "process.jtanalyzer = cms.EDProducer('PhonyConeJet', i = cms.int32(7))\n"
0389 "process.cones = cms.Sequence(process.cone1+ process.cone2)\n"
0390 "process.jets = cms.Sequence(process.somejet1* process.somejet2)\n"
0391 "process.path1 = cms.Path(process.cones*process.jtanalyzer)\n"
0392 "process.path2 = cms.Path(process.jets*process.jtanalyzer)\n";
0393
0394 std::shared_ptr<edm::ParameterSet> test = PyBind11ProcessDesc(str, false).parameterSet();
0395 }
0396
0397 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>