CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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__
 
def countSeeds
 
def getNamedSeed
 
def insertSeeds
 
def populate
 
def resetSeeds
 
def setNamedSeed
 

Private Member Functions

def __containsSeed
 
def __psetsWithSeeds
 

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.

Revision: "$Id: RandomServiceHelper.py,v 1.4.4.1 2012/10/30 10:24:28 vlimant Exp $"
Version   "$Revision: 1.4.4.1 $"
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 27 of file RandomServiceHelper.py.

Referenced by RandomServiceHelper.RandomNumberServiceHelper.__psetsWithSeeds().

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

*private method*

return the list of PSet instances with seeds in them

Definition at line 47 of file RandomServiceHelper.py.

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

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

47 
48  def __psetsWithSeeds(self):
49  """
50  _psetsWithSeeds_
51 
52  *private method*
53 
54  return the list of PSet instances with seeds in them
55 
56  """
57  svcAttrs = [getattr(self._randService, item, None)
58  for item in self._randService.parameters_()
59  if item not in self._lockedSeeds]
60 
61  #print svcAttrs
62 
63  return filter(self.__containsSeed, svcAttrs)
64 
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 65 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper.__psetsWithSeeds().

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

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

References RandomServiceHelper.RandomNumberServiceHelper._randService.

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

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

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

165  def insertSeeds(self, *seeds):
166  """
167  _insertSeeds_
168 
169  Given some list of specific seeds, insert them into the
170  service.
171 
172  Length of seed list is required to be same as the seed count for
173  the service.
174 
175  Usage: WM Tools.
176 
177  """
178  seeds = list(seeds)
179  if len(seeds) < self.countSeeds():
180  msg = "Not enough seeds provided\n"
181  msg += "Service requires %s seeds, only %s provided\n"
182  msg += "to RandomeService.insertSeeds method\n"
183  raise RuntimeError, msg
184 
185  for item in self.__psetsWithSeeds():
186  seedSet = getattr(item, "initialSeedSet", None)
187  if seedSet != None:
188  numSeeds = len(seedSet.value())
189  useSeeds = seeds[:numSeeds]
190  seeds = seeds[numSeeds:]
191  item.initialSeedSet = CfgTypes.untracked(
192  CfgTypes.vuint32(*useSeeds))
193  continue
194  useSeed = seeds[0]
195  seeds = seeds[1:]
196  item.initialSeed = CfgTypes.untracked(
197  CfgTypes.uint32(useSeed)
198  )
199  continue
200  return
201 
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 202 of file RandomServiceHelper.py.

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

203  def populate(self, *excludePSets):
204  """
205  _populate_
206 
207  generate a bunch of seeds and stick them into this service
208  This is the lazy user method.
209 
210  Optional args are names of PSets to *NOT* alter seeds.
211 
212  Eg:
213  populate() will set all seeds
214  populate("pset1", "pset2") will set all seeds but not those in
215  psets named pset1 and pset2
216 
217  """
218 
219  import random
220  from random import SystemRandom
221  _inst = SystemRandom()
222  _MAXINT = 900000000
223 
224  # //
225  # // count seeds and create the required number of seeds
226  #//
227  newSeeds = [ _inst.randint(1, _MAXINT)
228  for i in range(self.countSeeds())]
229 
230 
231  self._lockedSeeds = list(excludePSets)
232  self.insertSeeds(*newSeeds)
233  self._lockedSeeds = []
234  return
235 
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 236 of file RandomServiceHelper.py.

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

237  def resetSeeds(self, value):
238  """
239  _resetSeeds_
240 
241  reset all seeds to given value
242 
243  """
244  newSeeds = [ value for i in range(self.countSeeds())]
245  self.insertSeeds(*newSeeds)
246  return
247 
248 
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 97 of file RandomServiceHelper.py.

References RandomServiceHelper.RandomNumberServiceHelper._randService.

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

Member Data Documentation

RandomServiceHelper.RandomNumberServiceHelper._lockedSeeds
private

Definition at line 24 of file RandomServiceHelper.py.

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

RandomServiceHelper.RandomNumberServiceHelper._randService
private

Definition at line 23 of file RandomServiceHelper.py.

Referenced by RandomServiceHelper.RandomNumberServiceHelper.__psetsWithSeeds(), RandomServiceHelper.RandomNumberServiceHelper.getNamedSeed(), and RandomServiceHelper.RandomNumberServiceHelper.setNamedSeed().