Go to the documentation of this file.00001 import FWCore.ParameterSet.Config as cms
00002
00003 class RandomRunSource (cms.Source):
00004 """The class is a Source whose run is chosen randomly. This initializes identically to a cms.Source
00005 and after being initialized the run number distribution is set by calling 'setRunDistribution'.
00006 """
00007 def setRunDistribution(self,runsAndProbs):
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 class will normalize the
00010 weights so you do not have to. The pairs will be used to randomly choose what Run
00011 should be assigned to the job.
00012 """
00013 self.__dict__['runsAndProbs']=runsAndProbs
00014 def insertInto(self, parameterSet, myname):
00015 from random import SystemRandom
00016 totalProb = 0.
00017 for r,p in self.__dict__['runsAndProbs']:
00018 totalProb+=p
00019
00020 random = SystemRandom()
00021 runProb = random.uniform(0,totalProb)
00022 print runProb
00023 sumProb = 0
00024 runNumber = 0
00025 for r,p in self.__dict__['runsAndProbs']:
00026 sumProb+=p
00027 if sumProb >= runProb:
00028 runNumber = r
00029 break
00030 if self.type_() == "PoolSource":
00031 self.setRunNumber = cms.untracked.uint32(runNumber)
00032 else:
00033
00034 self.firstRun = cms.untracked.uint32(runNumber)
00035 super(RandomRunSource,self).insertInto(parameterSet,myname)