4070 def testModifier(self):
4072 Process._firstProcess =
True 4074 self.assertRaises(RuntimeError,
lambda: Process(
"test2", m1))
4076 Process._firstProcess =
True 4077 p = Process(
"test",m1)
4078 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
4081 m1.toModify(p.a,_mod_fred)
4082 self.assertEqual(p.a.fred.value(),2)
4083 p.b = EDAnalyzer(
"YourAnalyzer", wilma = int32(1))
4084 m1.toModify(p.b, wilma = 2)
4085 self.assertEqual(p.b.wilma.value(),2)
4086 self.assertTrue(p.isUsingModifier(m1))
4089 Process._firstProcess =
True 4091 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
4092 m1.toModify(p.a,_mod_fred)
4093 p.b = EDAnalyzer(
"YourAnalyzer", wilma = int32(1))
4094 m1.toModify(p.b, wilma = 2)
4095 self.assertEqual(p.a.fred.value(),1)
4096 self.assertEqual(p.b.wilma.value(),1)
4097 self.assertEqual(p.isUsingModifier(m1),
False)
4100 Process._firstProcess =
True 4101 p = Process(
"test",m1)
4102 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
4103 m1.toModify(p.a, fred = int32(2))
4104 p.b = p.a.clone(wilma = int32(3))
4105 self.assertEqual(p.a.fred.value(),2)
4106 self.assertEqual(p.a.wilma.value(),1)
4107 self.assertEqual(p.b.fred.value(),2)
4108 self.assertEqual(p.b.wilma.value(),3)
4111 Process._firstProcess =
True 4112 p = Process(
"test",m1)
4113 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1), fintstones = PSet(fred = int32(1)))
4114 m1.toModify(p.a, fred =
None, fintstones = dict(fred =
None))
4115 self.assertEqual(hasattr(p.a,
"fred"),
False)
4116 self.assertEqual(hasattr(p.a.fintstones,
"fred"),
False)
4117 self.assertEqual(p.a.wilma.value(),1)
4120 Process._firstProcess =
True 4121 p = Process(
"test",m1)
4122 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
4123 m1.toModify(p.a, wilma = int32(2))
4124 self.assertEqual(p.a.fred.value(), 1)
4125 self.assertEqual(p.a.wilma.value(),2)
4128 Process._firstProcess =
True 4129 p = Process(
"test",m1)
4130 p.a = EDAnalyzer(
"MyAnalyzer", flintstones = PSet(fred = int32(1), wilma = int32(1)))
4131 m1.toModify(p.a, flintstones = dict(fred = int32(2)))
4132 self.assertEqual(p.a.flintstones.fred.value(),2)
4133 self.assertEqual(p.a.flintstones.wilma.value(),1)
4136 Process._firstProcess =
True 4137 p = Process(
"test",m1)
4138 p.a = EDAnalyzer(
"MyAnalyzer", flintstones = PSet(fred = PSet(wilma = int32(1))))
4139 self.assertRaises(KeyError,
lambda: m1.toModify(p.a, flintstones = dict(imnothere = dict(wilma=2))))
4140 self.assertRaises(KeyError,
lambda: m1.toModify(p.a, foo = 1))
4143 Process._firstProcess =
True 4144 p = Process(
"test",m1)
4145 p.a = EDAnalyzer(
"MyAnalyzer", flintstones =
VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
4146 m1.toModify(p.a, flintstones = {1:dict(wilma = int32(2))})
4147 self.assertEqual(p.a.flintstones[0].fred.value(),1)
4148 self.assertEqual(p.a.flintstones[1].wilma.value(),2)
4151 Process._firstProcess =
True 4152 p = Process(
"test",m1)
4153 p.a = EDAnalyzer(
"MyAnalyzer", fred = vuint32(1,2,3))
4154 m1.toModify(p.a, fred = {1:7})
4155 self.assertEqual(p.a.fred[0],1)
4156 self.assertEqual(p.a.fred[1],7)
4157 self.assertEqual(p.a.fred[2],3)
4160 Process._firstProcess =
True 4161 p = Process(
"test",m1)
4162 p.a = EDAnalyzer(
"MyAnalyzer", fred = vuint32(1,2,3))
4164 try: m1.toModify(p.a, fred = {5:7})
4165 except IndexError
as e: raised =
True 4166 self.assertEqual(raised,
True)
4169 Process._firstProcess =
True 4170 p = Process(
"test",m1)
4171 p.a = EDAnalyzer(
"MyAnalyzer", flintstones =
VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
4173 try: m1.toModify(p.a, flintstones = dict(bogus = int32(37)))
4174 except TypeError
as e: raised =
True 4175 self.assertEqual(raised,
True)
4179 class ProcModifierMod(
object):
4181 self.proc_mod_ = modifier.makeProcessModifier(func)
4184 self.a = EDAnalyzer(
"Dummy")
4185 testMod = DummyMod()
4187 self.assertTrue(hasattr(p,
"a"))
4189 Process._firstProcess =
True 4190 p = Process(
"test",m1)
4191 testProcMod = ProcModifierMod(m1,_rem_a)
4193 p.extend(testProcMod)
4194 self.assertTrue(
not hasattr(p,
"a"))
4197 mc = ModifierChain(m1)
4198 Process._firstProcess =
True 4199 p = Process(
"test",mc)
4200 self.assertTrue(p.isUsingModifier(m1))
4201 self.assertTrue(p.isUsingModifier(mc))
4202 testMod = DummyMod()
4203 p.b = EDAnalyzer(
"Dummy2", fred = int32(1))
4204 m1.toModify(p.b, fred = int32(3))
4206 testProcMod = ProcModifierMod(m1,_rem_a)
4207 p.extend(testProcMod)
4208 self.assertTrue(
not hasattr(p,
"a"))
4209 self.assertEqual(p.b.fred.value(),3)
4213 mc = ModifierChain(m1,m2)
4214 mclone = mc.copyAndExclude([m2])
4215 self.assertTrue(
not mclone._isOrContains(m2))
4216 self.assertTrue(mclone._isOrContains(m1))
4218 mc2 = ModifierChain(mc,m3)
4219 mclone = mc2.copyAndExclude([m2])
4220 self.assertTrue(
not mclone._isOrContains(m2))
4221 self.assertTrue(mclone._isOrContains(m1))
4222 self.assertTrue(mclone._isOrContains(m3))
4226 Process._firstProcess =
True 4227 p = Process(
"test",m1)
4228 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
4229 (m1 & m2).toModify(p.a, fred = int32(2))
4230 self.assertRaises(TypeError,
lambda: (m1 & m2).toModify(p.a, 1, wilma=2))
4231 self.assertEqual(p.a.fred, 1)
4234 Process._firstProcess =
True 4235 p = Process(
"test",m1,m2)
4236 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
4237 (m1 & m2).toModify(p.a, fred = int32(2))
4238 self.assertEqual(p.a.fred, 2)
4242 Process._firstProcess =
True 4243 p = Process(
"test",m1,m2,m3)
4244 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
4245 (m1 & m2 & m3).toModify(p.a, fred = int32(2))
4246 self.assertEqual(p.a.fred, 2)
4247 (m1 & (m2 & m3)).toModify(p.a, fred = int32(3))
4248 self.assertEqual(p.a.fred, 3)
4249 ((m1 & m2) & m3).toModify(p.a, fred = int32(4))
4250 self.assertEqual(p.a.fred, 4)
4254 Process._firstProcess =
True 4255 p = Process(
"test", m1)
4256 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
4257 (~m1).toModify(p.a, fred=2)
4258 self.assertEqual(p.a.fred, 1)
4259 (~m2).toModify(p.a, wilma=2)
4260 self.assertEqual(p.a.wilma, 2)
4261 self.assertRaises(TypeError,
lambda: (~m1).toModify(p.a, 1, wilma=2))
4262 self.assertRaises(TypeError,
lambda: (~m2).toModify(p.a, 1, wilma=2))
4267 Process._firstProcess =
True 4268 p = Process(
"test", m1)
4269 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
4270 (m1 | m2).toModify(p.a, fred=2)
4271 self.assertEqual(p.a.fred, 2)
4272 (m1 | m2 | m3).toModify(p.a, fred=3)
4273 self.assertEqual(p.a.fred, 3)
4274 (m3 | m2 | m1).toModify(p.a, fred=4)
4275 self.assertEqual(p.a.fred, 4)
4276 ((m1 | m2) | m3).toModify(p.a, fred=5)
4277 self.assertEqual(p.a.fred, 5)
4278 (m1 | (m2 | m3)).toModify(p.a, fred=6)
4279 self.assertEqual(p.a.fred, 6)
4280 (m2 | m3).toModify(p.a, fred=7)
4281 self.assertEqual(p.a.fred, 6)
4282 self.assertRaises(TypeError,
lambda: (m1 | m2).toModify(p.a, 1, wilma=2))
4283 self.assertRaises(TypeError,
lambda: (m2 | m3).toModify(p.a, 1, wilma=2))
4289 Process._firstProcess =
True 4290 p = Process(
"test", m1, m2)
4291 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
4292 (m1 & ~m2).toModify(p.a, fred=2)
4293 self.assertEqual(p.a.fred, 1)
4294 (m1 & ~m3).toModify(p.a, fred=2)
4295 self.assertEqual(p.a.fred, 2)
4296 (m1 | ~m2).toModify(p.a, fred=3)
4297 self.assertEqual(p.a.fred, 3)
4298 (~m1 | ~m2).toModify(p.a, fred=4)
4299 self.assertEqual(p.a.fred, 3)
4300 (~m3 & ~m4).toModify(p.a, fred=4)
4301 self.assertEqual(p.a.fred, 4)
4302 ((m1 & m3) | ~m4).toModify(p.a, fred=5)
4303 self.assertEqual(p.a.fred, 5)
4306 Process._firstProcess =
True 4307 p = Process(
"test",m1)
4308 p.a =EDAnalyzer(
"MyAnalyzer", fred = int32(1))
4309 m1.toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer", wilma = int32(3)))
4310 self.assertRaises(TypeError,
lambda: m1.toReplaceWith(p.a, EDProducer(
"YourProducer")))
4312 p.b =EDAnalyzer(
"BAn")
4313 p.c =EDProducer(
"c")
4314 p.d =EDProducer(
"d")
4318 m1.toReplaceWith(p.s,
Sequence(p.a+p.b, p.td))
4319 self.assertEqual(p.a.wilma.value(),3)
4320 self.assertEqual(p.a.type_(),
"YourAnalyzer")
4321 self.assertEqual(hasattr(p,
"fred"),
False)
4322 self.assertTrue(p.s.dumpPython() ==
"cms.Sequence(process.a+process.b, process.td)\n")
4323 p.e =EDProducer(
"e")
4324 m1.toReplaceWith(p.td, Task(p.e))
4325 self.assertTrue(p.td._collection ==
OrderedSet([p.e]))
4327 p.b =EDAnalyzer(
"BAn")
4328 p.c =EDProducer(
"c")
4329 p.d =EDProducer(
"d")
4332 p.tc = ConditionalTask(p.c)
4333 p.td = ConditionalTask(p.d)
4335 m1.toReplaceWith(p.s,
Sequence(p.a+p.b, p.td))
4336 self.assertEqual(p.a.wilma.value(),3)
4337 self.assertEqual(p.a.type_(),
"YourAnalyzer")
4338 self.assertEqual(hasattr(p,
"fred"),
False)
4339 self.assertTrue(p.s.dumpPython() ==
"cms.Sequence(process.a+process.b, process.td)\n")
4340 p.e =EDProducer(
"e")
4341 m1.toReplaceWith(p.td, ConditionalTask(p.e))
4342 self.assertTrue(p.td._collection ==
OrderedSet([p.e]))
4345 Process._firstProcess =
True 4347 p.a =EDAnalyzer(
"MyAnalyzer", fred = int32(1))
4348 m1.toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer", wilma = int32(3)))
4349 self.assertEqual(p.a.type_(),
"MyAnalyzer")
4355 Process._firstProcess =
True 4356 p = Process(
"test", m1, m2)
4357 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
4358 self.assertRaises(TypeError,
lambda: (m1 & m2).toReplaceWith(p.a, EDProducer(
"YourProducer")))
4359 self.assertRaises(TypeError,
lambda: (m3 & m4).toReplaceWith(p.a, EDProducer(
"YourProducer")))
4360 self.assertRaises(TypeError,
lambda: (~m3).toReplaceWith(p.a, EDProducer(
"YourProducer")))
4361 self.assertRaises(TypeError,
lambda: (~m1).toReplaceWith(p.a, EDProducer(
"YourProducer")))
4362 self.assertRaises(TypeError,
lambda: (m1 | m3).toReplaceWith(p.a, EDProducer(
"YourProducer")))
4363 self.assertRaises(TypeError,
lambda: (m3 | m4).toReplaceWith(p.a, EDProducer(
"YourProducer")))
4364 (m1 & m2).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer1"))
4365 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
4366 (m1 & m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
4367 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
4368 (~m1).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
4369 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
4370 (~m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
4371 self.assertEqual(p.a.type_(),
"YourAnalyzer2")
4372 (m1 | m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer3"))
4373 self.assertEqual(p.a.type_(),
"YourAnalyzer3")
4374 (m3 | m4).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer4"))
4375 self.assertEqual(p.a.type_(),
"YourAnalyzer3")
4378 a = EDAlias(foo2 =
VPSet(PSet(type =
string(
"Foo2"))))
4382 m.toModify(a, foo2 = {0: dict(type =
"Foo3")})
4383 self.assertEqual(a.foo2[0].type,
"Foo3")
4385 m.toModify(a, foo4 =
VPSet(PSet(type =
string(
"Foo4"))))
4386 self.assertEqual(a.foo2[0].type,
"Foo3")
4387 self.assertEqual(a.foo4[0].type,
"Foo4")
4389 m.toModify(a, foo2 =
None)
4390 self.assertFalse(hasattr(a,
"foo2"))
4391 self.assertEqual(a.foo4[0].type,
"Foo4")
4393 m.toReplaceWith(a, EDAlias(bar =
VPSet(PSet(type =
string(
"Bar")))))
4394 self.assertFalse(hasattr(a,
"foo2"))
4395 self.assertFalse(hasattr(a,
"foo4"))
4396 self.assertTrue(hasattr(a,
"bar"))
4397 self.assertEqual(a.bar[0].type,
"Bar")
4400 sp = SwitchProducerTest(test1 = EDProducer(
"Foo",
4402 b = PSet(c = int32(2))),
4403 test2 = EDProducer(
"Bar",
4405 bb = PSet(cc = int32(12))))
4410 test1 = dict(a = 4, b = dict(c =
None)),
4411 test2 = dict(aa = 15, bb = dict(cc = 45, dd =
string(
"foo"))))
4412 self.assertEqual(sp.test1.a.value(), 4)
4413 self.assertEqual(sp.test1.b.hasParameter(
"c"),
False)
4414 self.assertEqual(sp.test2.aa.value(), 15)
4415 self.assertEqual(sp.test2.bb.cc.value(), 45)
4416 self.assertEqual(sp.test2.bb.dd.value(),
"foo")
4418 m.toReplaceWith(sp.test1, EDProducer(
"Fred", x = int32(42)))
4419 self.assertEqual(sp.test1.type_(),
"Fred")
4420 self.assertEqual(sp.test1.x.value(), 42)
4421 self.assertRaises(TypeError,
lambda: m.toReplaceWith(sp.test1, EDAnalyzer(
"Foo")))
4423 m.toModify(sp, test2 = EDProducer(
"Xyzzy", x = int32(24)))
4424 self.assertEqual(sp.test2.type_(),
"Xyzzy")
4425 self.assertEqual(sp.test2.x.value(), 24)
4426 self.assertRaises(TypeError,
lambda: m.toModify(sp, test2 = EDAnalyzer(
"Foo")))
4428 m.toModify(sp, test3 = EDProducer(
"Wilma", y = int32(24)))
4429 self.assertEqual(sp.test3.type_(),
"Wilma")
4430 self.assertEqual(sp.test3.y.value(), 24)
4431 self.assertRaises(TypeError,
lambda: m.toModify(sp, test4 = EDAnalyzer(
"Foo")))
4433 m.toModify(sp, test2 =
None)
4434 self.assertEqual(hasattr(sp,
"test2"),
False)
4436 m.toModify(sp, test2 = EDAlias(foo =
VPSet(PSet(type =
string(
"int")))))
4437 self.assertTrue(hasattr(sp.test2,
"foo"))
4439 m.toReplaceWith(sp.test2, EDAlias(bar =
VPSet(PSet(type =
string(
"int")))))
4440 self.assertTrue(hasattr(sp.test2,
"bar"))
4442 m.toModify(sp, test2 = EDAlias(xyzzy =
VPSet(PSet(type =
string(
"int")))))
4443 self.assertTrue(hasattr(sp.test2,
"xyzzy"))
4445 self.assertRaises(TypeError,
lambda: m.toReplaceWith(sp.test2, EDProducer(
"Foo")))
4446 m.toModify(sp, test2 = EDProducer(
"Foo"))
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)