CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
RandomServiceHelper.RandomNumberServiceHelper Class Reference
Inheritance diagram for RandomServiceHelper.RandomNumberServiceHelper:

Public Member Functions

def __init__ (self, randService)
 
def countSeeds (self)
 
def getNamedSeed (self, psetName)
 
def insertSeeds (self, seeds)
 
def populate (self, excludePSets)
 
def resetSeeds (self, value)
 
def setNamedSeed (self, psetName, seeds)
 

Private Member Functions

def __containsSeed (self, psetInstance)
 
def __psetsWithSeeds (self)
 

Private Attributes

 _lockedSeeds
 
 _randService
 

Detailed Description

_RandomNumberServiceHelper_

Helper class to hold and handle the Random number generator service.

Provide both user level and WM APIs.

Author:   Dave Evans
Modified: Eric Vaandering

Definition at line 8 of file RandomServiceHelper.py.

Constructor & Destructor Documentation

def RandomServiceHelper.RandomNumberServiceHelper.__init__ (   self,
  randService 
)

Member Function Documentation

def RandomServiceHelper.RandomNumberServiceHelper.__containsSeed (   self,
  psetInstance 
)
private
_keeper_

True/False if the psetInstance has seeds in it

Definition at line 25 of file RandomServiceHelper.py.

Referenced by RandomServiceHelper.RandomNumberServiceHelper.__psetsWithSeeds().

25  def __containsSeed(self,psetInstance):
26  """
27  _keeper_
28 
29  True/False if the psetInstance has seeds in it
30 
31  """
32  if psetInstance is None:
33  return False
34  if not isinstance(psetInstance,CfgTypes.PSet):
35  return False
36  seedList = getattr(psetInstance, "initialSeedSet", None)
37  if seedList != None:
38  return True
39  seedVal = getattr(psetInstance, "initialSeed", None)
40  if seedVal != None:
41  return True
42  return False
43 
44 
def RandomServiceHelper.RandomNumberServiceHelper.__psetsWithSeeds (   self)
private
_psetsWithSeeds_

*private method*

return the list of PSet instances with seeds in them

Definition at line 45 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper.__containsSeed(), RandomServiceHelper.RandomNumberServiceHelper._lockedSeeds, RandomServiceHelper.RandomNumberServiceHelper._randService, and ALCARECOTkAlBeamHalo_cff.filter.

Referenced by RandomServiceHelper.RandomNumberServiceHelper.countSeeds(), and RandomServiceHelper.RandomNumberServiceHelper.insertSeeds().

45  def __psetsWithSeeds(self):
46  """
47  _psetsWithSeeds_
48 
49  *private method*
50 
51  return the list of PSet instances with seeds in them
52 
53  """
54  svcAttrs = [getattr(self._randService, item, None)
55  for item in self._randService.parameters_()
56  if item not in self._lockedSeeds]
57 
58  #print svcAttrs
59 
60  return filter(self.__containsSeed, svcAttrs)
61 
62 
def RandomServiceHelper.RandomNumberServiceHelper.countSeeds (   self)
_countSeeds_

Count the number of seeds required by this service by
summing up the initialSeed and initialSeedSet entries
in all PSets in the service that contain those parameters.

Definition at line 63 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper.__psetsWithSeeds().

Referenced by RandomServiceHelper.RandomNumberServiceHelper.insertSeeds(), RandomServiceHelper.RandomNumberServiceHelper.populate(), and RandomServiceHelper.RandomNumberServiceHelper.resetSeeds().

63  def countSeeds(self):
64  """
65  _countSeeds_
66 
67  Count the number of seeds required by this service by
68  summing up the initialSeed and initialSeedSet entries
69  in all PSets in the service that contain those parameters.
70 
71  """
72  count = 0
73 
74  for itemRef in self.__psetsWithSeeds():
75  # //
76  # // PSet has list of seeds
77  #//
78  seedSet = getattr(itemRef, "initialSeedSet", None)
79  if seedSet != None:
80  count += len( seedSet.value())
81  continue
82  # //
83  # // PSet has single seed
84  #//
85  seedVal = getattr(itemRef, "initialSeed", None)
86  if seedVal != None:
87  count += 1
88 
89  # //
90  # // PSet has no recognisable seed, therfore do nothing
91  #// with it
92  return count
93 
94 
def RandomServiceHelper.RandomNumberServiceHelper.getNamedSeed (   self,
  psetName 
)
_getNamedSeed_

This method returns the seeds in a PSet in this service. Returned

- *psetName* : Name of the pset containing the seeds

Definition at line 137 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper._randService.

137  def getNamedSeed(self, psetName):
138  """
139  _getNamedSeed_
140 
141  This method returns the seeds in a PSet in this service. Returned
142 
143  - *psetName* : Name of the pset containing the seeds
144 
145  """
146  pset = getattr(self._randService, psetName, None)
147  if pset == None:
148  msg = "No PSet named %s belongs to this instance of the" % (
149  psetName,)
150  msg += "Random Seed Service"
151  raise RuntimeError(msg)
152 
153  seedVal = getattr(pset, "initialSeed", None)
154  if seedVal != None:
155  return [pset.initialSeed.value()]
156 
157  seedSet = getattr(pset, "initialSeedSet", None)
158  if seedSet != None:
159  return pset.initialSeedSet
160 
161 
def RandomServiceHelper.RandomNumberServiceHelper.insertSeeds (   self,
  seeds 
)
_insertSeeds_

Given some list of specific seeds, insert them into the
service.

Length of seed list is required to be same as the seed count for
the service.

Usage: WM Tools.

Definition at line 162 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper.__psetsWithSeeds(), RandomServiceHelper.RandomNumberServiceHelper.countSeeds(), and list().

Referenced by RandomServiceHelper.RandomNumberServiceHelper.populate(), and RandomServiceHelper.RandomNumberServiceHelper.resetSeeds().

162  def insertSeeds(self, *seeds):
163  """
164  _insertSeeds_
165 
166  Given some list of specific seeds, insert them into the
167  service.
168 
169  Length of seed list is required to be same as the seed count for
170  the service.
171 
172  Usage: WM Tools.
173 
174  """
175  seeds = list(seeds)
176  if len(seeds) < self.countSeeds():
177  msg = "Not enough seeds provided\n"
178  msg += "Service requires %s seeds, only %s provided\n"
179  msg += "to RandomeService.insertSeeds method\n"
180  raise RuntimeError(msg)
181 
182  for item in self.__psetsWithSeeds():
183  seedSet = getattr(item, "initialSeedSet", None)
184  if seedSet != None:
185  numSeeds = len(seedSet.value())
186  useSeeds = seeds[:numSeeds]
187  seeds = seeds[numSeeds:]
188  item.initialSeedSet = CfgTypes.untracked(
189  CfgTypes.vuint32(*useSeeds))
190  continue
191  useSeed = seeds[0]
192  seeds = seeds[1:]
193  item.initialSeed = CfgTypes.untracked(
194  CfgTypes.uint32(useSeed)
195  )
196  continue
197  return
198 
199 
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def RandomServiceHelper.RandomNumberServiceHelper.populate (   self,
  excludePSets 
)
_populate_

generate a bunch of seeds and stick them into this service
This is the lazy user method.

Optional args are names of PSets to *NOT* alter seeds.

Eg:
populate() will set all seeds
populate("pset1", "pset2") will set all seeds but not those in
psets named pset1 and pset2

Definition at line 200 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper._lockedSeeds, RandomServiceHelper.RandomNumberServiceHelper.countSeeds(), RandomServiceHelper.RandomNumberServiceHelper.insertSeeds(), and list().

200  def populate(self, *excludePSets):
201  """
202  _populate_
203 
204  generate a bunch of seeds and stick them into this service
205  This is the lazy user method.
206 
207  Optional args are names of PSets to *NOT* alter seeds.
208 
209  Eg:
210  populate() will set all seeds
211  populate("pset1", "pset2") will set all seeds but not those in
212  psets named pset1 and pset2
213 
214  """
215 
216  import random
217  from random import SystemRandom
218  _inst = SystemRandom()
219  _MAXINT = 900000000
220 
221  # //
222  # // count seeds and create the required number of seeds
223  #//
224  newSeeds = [ _inst.randint(1, _MAXINT)
225  for i in range(self.countSeeds())]
226 
227 
228  self._lockedSeeds = list(excludePSets)
229  self.insertSeeds(*newSeeds)
230  self._lockedSeeds = []
231  return
232 
233 
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def RandomServiceHelper.RandomNumberServiceHelper.resetSeeds (   self,
  value 
)
_resetSeeds_

reset all seeds to given value

Definition at line 234 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper.countSeeds(), and RandomServiceHelper.RandomNumberServiceHelper.insertSeeds().

234  def resetSeeds(self, value):
235  """
236  _resetSeeds_
237 
238  reset all seeds to given value
239 
240  """
241  newSeeds = [ value for i in range(self.countSeeds())]
242  self.insertSeeds(*newSeeds)
243  return
244 
245 
246 
def RandomServiceHelper.RandomNumberServiceHelper.setNamedSeed (   self,
  psetName,
  seeds 
)
_setNamedSeed_

If a specific set of seeds is needed for a PSet in this
service, they can be set by name using this method.

- *psetName* : Name of the pset containing the seeds

- *seeds*    : list of seeds to be added, should be a single seed
for initialSeed values.

Definition at line 95 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper._randService.

95  def setNamedSeed(self, psetName, *seeds):
96  """
97  _setNamedSeed_
98 
99  If a specific set of seeds is needed for a PSet in this
100  service, they can be set by name using this method.
101 
102  - *psetName* : Name of the pset containing the seeds
103 
104  - *seeds* : list of seeds to be added, should be a single seed
105  for initialSeed values.
106 
107  """
108  pset = getattr(self._randService, psetName, None)
109  if pset == None:
110  msg = "No PSet named %s belongs to this instance of the" % (
111  psetName,)
112  msg += "Random Seed Service"
113  raise RuntimeError(msg)
114 
115  seedVal = getattr(pset, "initialSeed", None)
116  if seedVal != None:
117  pset.initialSeed = CfgTypes.untracked(
118  CfgTypes.uint32(seeds[0])
119  )
120 
121  return
122  seedSet = getattr(pset, "initialSeedSet", None)
123  if seedSet != None:
124  # //
125  # // Do we want to check the number of seeds??
126  #//
127  #if len(seeds) != len( seedSet.value()): pass
128  pset.initialSeedSet = CfgTypes.untracked(
129  CfgTypes.vuint32(*seeds))
130  return
131  # //
132  # // No seeds for that PSet
133  #// Error throw?
134  return
135 
136 

Member Data Documentation

RandomServiceHelper.RandomNumberServiceHelper._lockedSeeds
private
RandomServiceHelper.RandomNumberServiceHelper._randService
private