test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RandomRunSource.py
Go to the documentation of this file.
2 
3 class RandomRunSource (cms.Source):
4  """The class is a Source whose run is chosen randomly. This initializes identically to a cms.Source
5  and after being initialized the run number distribution is set by calling 'setRunDistribution'.
6  """
7  def setRunDistribution(self,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 class will normalize the
10  weights so you do not have to. The pairs will be used to randomly choose what Run
11  should be assigned to the job.
12  """
13  self.__dict__['runsAndProbs']=runsAndProbs
14  def insertInto(self, parameterSet, myname):
15  from random import SystemRandom
16  totalProb = 0.
17  for r,p in self.__dict__['runsAndProbs']:
18  totalProb+=p
19  #this is the same random generator used to set the seeds for the RandomNumberGeneratorService
20  random = SystemRandom()
21  runProb = random.uniform(0,totalProb)
22  print runProb
23  sumProb = 0
24  runNumber = 0
25  for r,p in self.__dict__['runsAndProbs']:
26  sumProb+=p
27  if sumProb >= runProb:
28  runNumber = r
29  break
30  if self.type_() == "PoolSource":
31  self.setRunNumber = cms.untracked.uint32(runNumber)
32  else:
33  #sources that inherit from ConfigurableInputSource use 'firstRun'
34  self.firstRun = cms.untracked.uint32(runNumber)
35  super(RandomRunSource,self).insertInto(parameterSet,myname)