Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copyAndAdd() to Task for easier interplay with Modifier #33515

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions FWCore/ParameterSet/python/SequenceTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,11 @@ def copyAndExclude(self,listOfModulesToExclude):
v = _CopyAndExcludeSequenceVisitor(listOfModulesToExclude)
self.visit(v)
return Task(*v.result(self))
def copyAndAdd(self, *modulesToAdd):
"""Returns a copy of the Task adding modules/tasks"""
t = self.copy()
t.add(*modulesToAdd)
return t
def expandAndClone(self):
# Name of this function is not very good. It makes a shallow copy with all
# the subTasks flattened out (removed), but keeping all the
Expand Down Expand Up @@ -2460,6 +2465,27 @@ def testCopy(self):
self.assertTrue(id(t1Contents[0]) == id(t2Contents[0]))
self.assertTrue(id(t1Contents[1]) == id(t2Contents[1]))
self.assertTrue(id(t1._collection) != id(t2._collection))
def testCopyAndAdd(self):
a = DummyModule("a")
b = DummyModule("b")
c = DummyModule("c")
d = DummyModule("d")
e = DummyModule("e")
t1 = Task(a, b, c)
self.assertEqual(t1.dumpPython(), "cms.Task(process.a, process.b, process.c)\n")
t2 = t1.copyAndAdd(d, e)
self.assertEqual(t1.dumpPython(), "cms.Task(process.a, process.b, process.c)\n")
self.assertEqual(t2.dumpPython(), "cms.Task(process.a, process.b, process.c, process.d, process.e)\n")
t3 = t2.copyAndExclude([b])
self.assertEqual(t1.dumpPython(), "cms.Task(process.a, process.b, process.c)\n")
self.assertEqual(t2.dumpPython(), "cms.Task(process.a, process.b, process.c, process.d, process.e)\n")
self.assertEqual(t3.dumpPython(), "cms.Task(process.a, process.c, process.d, process.e)\n")
t4 = t1.copyAndExclude([b]).copyAndAdd(d)
self.assertEqual(t4.dumpPython(), "cms.Task(process.a, process.c, process.d)\n")
t5 = t2.copyAndExclude([b]).copyAndAdd(d)
self.assertEqual(t5.dumpPython(), "cms.Task(process.a, process.c, process.d, process.e)\n")
t6 = t4.copyAndAdd(Task(b))
self.assertEqual(t6.dumpPython(), "cms.Task(process.a, process.b, process.c, process.d)\n")
def testInsertInto(self):
from FWCore.ParameterSet.Types import vstring
class TestPSet(object):
Expand Down