CMS 3D CMS Logo

RandomRunSource.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import FWCore.ParameterSet.Config as cms
3 
4 class RandomRunSource (cms.Source):
5  """The class is a Source whose run is chosen randomly. This initializes identically to a cms.Source
6  and after being initialized the run number distribution is set by calling 'setRunDistribution'.
7  """
8  def setRunDistribution(self,runsAndProbs):
9  """Pass a list of tuple pairs, with the first item of the pair a run number
10  and the second number of the pair a weight. The class will normalize the
11  weights so you do not have to. The pairs will be used to randomly choose what Run
12  should be assigned to the job.
13  """
14  self.__dict__['runsAndProbs']=runsAndProbs
15  def insertInto(self, parameterSet, myname):
16  from random import SystemRandom
17  totalProb = 0.
18  for r,p in self.__dict__['runsAndProbs']:
19  totalProb+=p
20  #this is the same random generator used to set the seeds for the RandomNumberGeneratorService
21  random = SystemRandom()
22  runProb = random.uniform(0,totalProb)
23  print(runProb)
24  sumProb = 0
25  runNumber = 0
26  for r,p in self.__dict__['runsAndProbs']:
27  sumProb+=p
28  if sumProb >= runProb:
29  runNumber = r
30  break
31  if self.type_() == "PoolSource":
32  self.setRunNumber = cms.untracked.uint32(runNumber)
33  else:
34  #sources that inherit from ConfigurableInputSource use 'firstRun'
35  self.firstRun = cms.untracked.uint32(runNumber)
36  super(RandomRunSource,self).insertInto(parameterSet,myname)
RandomRunSource.RandomRunSource.setRunDistribution
def setRunDistribution(self, runsAndProbs)
Definition: RandomRunSource.py:8
RandomRunSource.RandomRunSource
Definition: RandomRunSource.py:4
RandomRunSource.RandomRunSource.insertInto
def insertInto(self, parameterSet, myname)
Definition: RandomRunSource.py:15
RandomRunSource.RandomRunSource.setRunNumber
setRunNumber
Definition: RandomRunSource.py:32
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
RandomRunSource.RandomRunSource.firstRun
firstRun
Definition: RandomRunSource.py:35