Add pileup support to StepChain MC from scratch
While working on something else, I noticed the `pileup` section is not created IF the StepChain contains a single step and the first step does not have an input dataset, i.e., if `setupGeneratorTask` is called instead of `setupTask`.
diff --git a/src/python/WMCore/WMSpec/StdSpecs/StepChain.py b/src/python/WMCore/WMSpec/StdSpecs/StepChain.py
index fa5f5a30d..02709c558 100644
--- a/src/python/WMCore/WMSpec/StdSpecs/StepChain.py
+++ b/src/python/WMCore/WMSpec/StdSpecs/StepChain.py
@@ -225,6 +225,9 @@ class StepChainWorkloadFactory(StdBase):
                                            globalTag=taskConf.get("GlobalTag", None),
                                            taskConf=taskConf)
 
+        if taskConf["PileupConfig"]:
+            self.setupPileup(task, taskConf['PileupConfig'])
+
         # outputModules were added already, we just want to create merge tasks here
         if strToBool(taskConf.get('KeepOutput', True)):
             self.setupMergeTask(task, taskConf, "cmsRun1", outMods)
diff --git a/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py b/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py
index 2873c0260..1cbbafb2b 100644
--- a/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py
+++ b/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py
@@ -490,6 +490,32 @@ class StepChainTests(EmulatedUnitTestCase):
 
         return
 
+    def testPileupWithoutInputData(self):
+        """
+        Test whether we can properly setup the Pileup information even
+        when the top level step has no input dataset (so pileup over a
+        MC from scratch step)
+        """
+        testArguments = StepChainWorkloadFactory.getTestArguments()
+        testArguments.update(deepcopy(REQUEST))
+
+        configId = injectStepChainConfigSingle(self.configDatabase)
+        testArguments['Step1'].update(ConfigCacheID=configId,
+                                      MCPileup=testArguments['Step2']['MCPileup'])
+        testArguments.pop("Step2", None)
+        testArguments.pop("Step3", None)
+        testArguments['StepChain'] = 1
+
+        factory = StepChainWorkloadFactory()
+        testWorkload = factory.factoryWorkloadConstruction("TestWorkload", testArguments)
+
+        # workload level check
+        self.assertEqual(testWorkload.getDashboardActivity(), "production")
+        self.assertEqual(testWorkload.listInputDatasets(), [])
+        pileups = testWorkload.listPileupDatasets().values()
+        pileups = [item for puSet in pileups for item in puSet]
+        self.assertItemsEqual(pileups, [testArguments['Step1']['MCPileup']])
+
     def testStepChainIncludeParentsValidation(self):
         """
         Check that the test arguments pass basic validation,
['test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py', 'src/python/WMCore/WMSpec/StdSpecs/StepChain.py']