Repository: dmwm/wmcore
Issue: MonteCarlo policy workflow failed in global workqueue

This taskchain workflow - starting from scratch - failed to be acquired in the global workqueue with this error message:
```
2018-04-13 11:24:07,479:INFO:WorkQueue:queueWork() begin queueing "https://cmsweb.cern.ch/couchdb/reqmgr_workload_cache/pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127/spec"
2018-04-13 11:24:09,591:INFO:WorkQueue:Splitting /pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127/SUS-RunIIFall17wmLHEGS-00032_0 with policy MonteCarlo params = {'ResubmitBlock': {'args': {}, 'name': 'ResubmitBlock'}, 'MonteCarlo': {'args': {}, 'name': 'MonteCarlo'}, 'Dataset': {'args': {}, 'name': 'Dataset'}, 'Block': {'args': {}, 'name': 'Block'}, 'DatasetBlock': {'args': {}, 'name': 'Block'}}
2018-04-13 11:24:09,592:ERROR:WorkQueue:Terminal exception splitting WQE: {'ChildQueueUrl': None, 'NumberOfEvents': 0, 'StartPolicy': {'SliceSize': 0, 'policyName': 'MonteCarlo', 'SubSliceSize': 11764, 'SplittingAlgo': 'EventBased', 'blowupFactor': 1.4419067393499998, 'SubSliceType': 'NumberOfEventsPerLumi', 'SliceType': 'NumberOfEvents'}, 'CreationTime': 0, 'NumOfFilesAdded': 0, 'Priority': 0, 'ParentData': {}, 'PileupData': {}, 'RejectedInputs': [], 'ParentFlag': False, 'TaskName': None, 'Status': 'Negotiating', 'Inputs': {}, 'NumberOfLumis': 0, 'Jobs': 0, 'ParentQueueUrl': None, 'ParentQueueId': None, 'PercentSuccess': 0, 'PercentComplete': 0, 'WMBSUrl': None, 'OpenForNewData': False, 'EndPolicy': {'policyName': 'SingleShot'}, 'FilesProcessed': 0, 'Task': None, 'SiteWhitelist': [], 'ACDC': {}, 'NumberOfFiles': 0, 'TeamName': u'production', 'NoPileupUpdate': False, 'RequestName': u'pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127', 'SubscriptionId': None, 'WMSpec': <WMCore.WMSpec.WMWorkload.WMWorkloadHelper instance at 0x7f55c137cf38>, 'NoInputUpdate': False, 'TimestampFoundNewData': 0, 'ProcessedInputs': [], 'SiteBlacklist': [], 'Mask': None, 'Dbs': None, 'EventsWritten': 0}
2018-04-13 11:24:10,173:ERROR:WorkQueue:Failing workflow "pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127": Invalid WMSpec: 'pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127': Zero or negative SliceSize parameter
```

and the reason seems to be coming from the splitting section for Task1
```
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.section_('splitting')
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.algorithm = 'EventBased'
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.events_per_lumi = 11764
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.lheInputFiles = False
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.deterministicPileup = False
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.events_per_job = 0
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.section_('performance')
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.performance.sizePerEvent = 116.28
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.performance.memoryRequirement = 4000.0
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.performance.timePerEvent = 10.157120497
pdmvserv_task_SUS-RunIIFall17wmLHEGS-00032__v1_T_180409_121652_7127.tasks.SUS-RunIIFall17wmLHEGS-00032_0.input.splitting.include_parents = False
```

Changed files:
test/python/WMCore_t/WMSpec_t/StdSpecs_t/StdBase_t.py, src/python/WMCore/WMSpec/StdSpecs/StdBase.py

diff --git a/src/python/WMCore/WMSpec/StdSpecs/StdBase.py b/src/python/WMCore/WMSpec/StdSpecs/StdBase.py
index 0700cd409..4a9257711 100644
--- a/src/python/WMCore/WMSpec/StdSpecs/StdBase.py
+++ b/src/python/WMCore/WMSpec/StdSpecs/StdBase.py
@@ -99,6 +99,8 @@ class StdBase(object):
             ePerJob = int((8.0 * 3600.0) / tPerEvent)
             # then make EventsPerJob multiple of EventsPerLumi and still closer to 8h jobs
             multiplier = int(round(ePerJob / ePerLumi))
+            # make sure not to have 0 EventsPerJob
+            multiplier = max(multiplier, 1)
             ePerJob = ePerLumi * multiplier
         elif ePerLumi is None:
             ePerLumi = ePerJob
diff --git a/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StdBase_t.py b/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StdBase_t.py
index 47390f9cd..6f0bc5921 100644
--- a/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StdBase_t.py
+++ b/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StdBase_t.py
@@ -67,6 +67,9 @@ class StdBaseTest(unittest.TestCase):
         self.assertEqual((23040, 23040), StdBase.calcEvtsPerJobLumi(None, None, 1.25))
         self.assertEqual((229, 229), StdBase.calcEvtsPerJobLumi(None, None, 125.5))
 
+        self.assertEqual((24000, 11764), StdBase.calcEvtsPerJobLumi(24000, 11764, 10.157120496967591))
+        self.assertEqual((11764, 11764), StdBase.calcEvtsPerJobLumi(None, 11764, 10.157120496967591))  # non rounded result is 2835
+
         return