File indexing completed on 2023-03-17 11:25:06
0001 from __future__ import print_function
0002 import FWCore.ParameterSet.Config as cms
0003
0004
0005
0006
0007 def throwAndSetRandomRun(source,runsAndProbs):
0008 """Pass a list of tuple pairs, with the first item of the pair a run number
0009 and the second number of the pair a weight. The function will normalize the
0010 weights so you do not have to worry about that. The pairs will be used to randomly choose what Run
0011 should be assigned to the job.
0012 """
0013 from random import SystemRandom
0014 totalProb = 0.
0015 for r,p in runsAndProbs:
0016 totalProb+=p
0017
0018 random = SystemRandom()
0019 runProb = random.uniform(0,totalProb)
0020 sumProb = 0
0021 runNumber = 0
0022 for r,p in runsAndProbs:
0023 sumProb+=p
0024 if sumProb >= runProb:
0025 runNumber = r
0026 break
0027 print('setting runNumber to: ',runNumber)
0028 if source.type_() == "PoolSource":
0029 source.setRunNumber = cms.untracked.uint32(runNumber)
0030 else:
0031
0032 source.firstRun = cms.untracked.uint32(runNumber)
0033
0034 return