Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:32

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