test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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.

6 
7 def throwAndSetRandomRun(source,runsAndProbs):
8  """Pass a list of tuple pairs, with the first item of the pair a run number
9  and the second number of the pair a weight. The function will normalize the
10  weights so you do not have to worry about that. The pairs will be used to randomly choose what Run
11  should be assigned to the job.
12  """
13  from random import SystemRandom
14  totalProb = 0.
15  for r,p in runsAndProbs:
16  totalProb+=p
17  #this is the same random generator used to set the seeds for the RandomNumberGeneratorService
18  random = SystemRandom()
19  runProb = random.uniform(0,totalProb)
20  sumProb = 0
21  runNumber = 0
22  for r,p in runsAndProbs:
23  sumProb+=p
24  if sumProb >= runProb:
25  runNumber = r
26  break
27  print 'setting runNumber to: ',runNumber
28  if source.type_() == "PoolSource":
29  source.setRunNumber = cms.untracked.uint32(runNumber)
30  else:
31  #sources that inherit from ConfigurableInputSource use 'firstRun'
32  source.firstRun = cms.untracked.uint32(runNumber)
33 
34  return