CMS 3D CMS Logo

Functions

ThrowAndSetRandomRun Namespace Reference

Functions

def throwAndSetRandomRun

Function Documentation

def ThrowAndSetRandomRun::throwAndSetRandomRun (   source,
  runsAndProbs 
)
Pass a list of tuple pairs, with the first item of the pair a run number
and the second number of the pair a weight.  The function will normalize the
weights so you do not have to worry about that.  The pairs will be used to randomly choose what Run
should be assigned to the job.

Definition at line 6 of file ThrowAndSetRandomRun.py.

00007                                              :
00008         """Pass a list of tuple pairs, with the first item of the pair a run number
00009         and the second number of the pair a weight.  The function will normalize the
00010         weights so you do not have to worry about that.  The pairs will be used to randomly choose what Run
00011         should be assigned to the job.
00012         """
00013         from random import SystemRandom
00014         totalProb = 0.
00015         for r,p in runsAndProbs:
00016             totalProb+=p
00017         #this is the same random generator used to set the seeds for the RandomNumberGeneratorService
00018         random = SystemRandom()
00019         runProb = random.uniform(0,totalProb)
00020         sumProb = 0
00021         runNumber = 0
00022         for r,p in runsAndProbs:
00023             sumProb+=p
00024             if sumProb >= runProb:
00025                 runNumber = r
00026                 break
00027         print 'setting runNumber to: ',runNumber
00028         if source.type_() == "PoolSource":
00029             source.setRunNumber = cms.untracked.uint32(runNumber)
00030         else:
00031             #sources that inherit from ConfigurableInputSource use 'firstRun'
00032             source.firstRun = cms.untracked.uint32(runNumber)
00033 
00034         return