Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-27 03:18:08

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 class RandomRunSource (cms.Source):
0004     """The class is a Source whose run is chosen randomly.  This initializes identically to a cms.Source
0005     and after being initialized the run number distribution is set by calling 'setRunDistribution'.
0006     """
0007     def setRunDistribution(self,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 class will normalize the
0010         weights so you do not have to.  The pairs will be used to randomly choose what Run
0011         should be assigned to the job.
0012         """
0013         self.__dict__['runsAndProbs']=runsAndProbs
0014     def insertInto(self, parameterSet, myname):
0015         from random import SystemRandom
0016         totalProb = 0.
0017         for r,p in self.__dict__['runsAndProbs']:
0018             totalProb+=p
0019         #this is the same random generator used to set the seeds for the RandomNumberGeneratorService
0020         random = SystemRandom()
0021         runProb = random.uniform(0,totalProb)
0022         print(runProb)
0023         sumProb = 0
0024         runNumber = 0
0025         for r,p in self.__dict__['runsAndProbs']:
0026             sumProb+=p
0027             if sumProb >= runProb:
0028                 runNumber = r
0029                 break
0030         if self.type_() == "PoolSource":
0031             self.setRunNumber = cms.untracked.uint32(runNumber)
0032         else:
0033             #sources that inherit from ConfigurableInputSource use 'firstRun'
0034             self.firstRun = cms.untracked.uint32(runNumber)
0035         super(RandomRunSource,self).insertInto(parameterSet,myname)