CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
Mixins._Parameterizable Class Reference
Inheritance diagram for Mixins._Parameterizable:
Mixins._TypedParameterizable

Public Member Functions

def __delattr__
 
def __init__
 
def __repr__
 
def __setattr__
 
def dumpPython
 
def getParameter
 
def hasParameter
 
def insertContentsInto
 
def isFrozen
 
def isModified
 
def parameterNames_
 
def parameters_
 
def setIsFrozen
 

Private Member Functions

def __addParameter
 
def __setParameters
 

Static Private Member Functions

def __raiseBadSetAttr
 

Private Attributes

 __validator
 
 _isFrozen
 
 _isModified
 

Detailed Description

Base class for classes which allow addition of _ParameterTypeBase data

Definition at line 163 of file Mixins.py.

Constructor & Destructor Documentation

def Mixins._Parameterizable.__init__ (   self,
  arg,
  kargs 
)

Definition at line 165 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

166  def __init__(self,*arg,**kargs):
167  self.__dict__['_Parameterizable__parameterNames'] = []
168  self.__dict__["_isFrozen"] = False
169  self.__dict__['_Parameterizable__validator'] = None
170  """The named arguments are the 'parameters' which are added as 'python attributes' to the object"""
171  if len(arg) != 0:
172  #raise ValueError("unnamed arguments are not allowed. Please use the syntax 'name = value' when assigning arguments.")
173  for block in arg:
174  # Allow __PSet for testing
175  if type(block).__name__ not in ["PSet", "__PSet"]:
176  raise ValueError("Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
177  self.__setParameters(block.parameters_())
178  self.__setParameters(kargs)
179  self._isModified = False

Member Function Documentation

def Mixins._Parameterizable.__addParameter (   self,
  name,
  value 
)
private

Definition at line 234 of file Mixins.py.

Referenced by Mixins._Parameterizable.__setattr__(), Modules.SwitchProducer.__setattr__(), Mixins._Parameterizable.__setParameters(), and Modules.SwitchProducer.__setParameters().

235  def __addParameter(self, name, value):
236  if name == 'allowAnyLabel_':
237  self.__validator = value
238  self._isModified = True
239  return
240  if not isinstance(value,_ParameterTypeBase):
241  if self.__validator is not None:
242  value = self.__validator.convert_(value)
243  else:
244  self.__raiseBadSetAttr(name)
245  if name in self.__dict__:
246  message = "Duplicate insert of member " + name
247  message += "\nThe original parameters are:\n"
248  message += self.dumpPython() + '\n'
249  raise ValueError(message)
250  self.__dict__[name]=value
251  self.__parameterNames.append(name)
252  self._isModified = True
def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 291 of file Mixins.py.

References Mixins._ParameterTypeBase.isFrozen(), and Mixins._Parameterizable.isFrozen().

292  def __delattr__(self,name):
293  if self.isFrozen():
294  raise ValueError("Object already added to a process. It is read only now")
295  super(_Parameterizable,self).__delattr__(name)
self.__parameterNames.remove(name)
def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 297 of file Mixins.py.

298  def __raiseBadSetAttr(name):
raise TypeError(name+" does not already exist, so it can only be set to a CMS python configuration type")
def Mixins._Parameterizable.__repr__ (   self)

Definition at line 371 of file Mixins.py.

References Mixins._ParameterTypeBase.dumpPython(), Mixins.UsingBlock.dumpPython(), Mixins._Parameterizable.dumpPython(), Config.Process.dumpPython(), Config.SubProcess.dumpPython(), and Config.ProcessAccelerator.dumpPython().

372  def __repr__(self):
return self.dumpPython()
def Mixins._Parameterizable.__setattr__ (   self,
  name,
  value 
)

Definition at line 262 of file Mixins.py.

References Mixins._Parameterizable.__addParameter(), Mixins._ParameterTypeBase._isModified, Mixins._SimpleParameterTypeBase._isModified, Mixins._Parameterizable._isModified, Mixins._ParameterTypeBase.dumpPython(), Mixins.UsingBlock.dumpPython(), Mixins._Parameterizable.dumpPython(), Config.Process.dumpPython(), Config.SubProcess.dumpPython(), Config.ProcessAccelerator.dumpPython(), Mixins._ParameterTypeBase.isFrozen(), Mixins._Parameterizable.isFrozen(), and reco::JetExtendedAssociation.setValue().

263  def __setattr__(self,name,value):
264  #since labels are not supposed to have underscores at the beginning
265  # I will assume that if we have such then we are setting an internal variable
266  if self.isFrozen() and not (name in ["_Labelable__label","_isFrozen"] or name.startswith('_')):
267  message = "Object already added to a process. It is read only now\n"
268  message += " %s = %s" %(name, value)
269  message += "\nThe original parameters are:\n"
270  message += self.dumpPython() + '\n'
271  raise ValueError(message)
272  # underscored names bypass checking for _ParameterTypeBase
273  if name[0]=='_':
274  super(_Parameterizable,self).__setattr__(name,value)
275  elif not name in self.__dict__:
276  self.__addParameter(name, value)
277  self._isModified = True
278  else:
279  # handle the case where users just replace with a value, a = 12, rather than a = cms.int32(12)
280  if isinstance(value,_ParameterTypeBase):
281  self.__dict__[name] = value
282  else:
283  self.__dict__[name].setValue(value)
284  self._isModified = True
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
def Mixins._Parameterizable.__setParameters (   self,
  parameters 
)
private

Definition at line 253 of file Mixins.py.

References Mixins._Parameterizable.__addParameter(), and Mixins._Parameterizable.__validator.

Referenced by Mixins._Parameterizable.__init__().

254  def __setParameters(self,parameters):
255  v = None
256  for name,value in parameters.items():
257  if name == 'allowAnyLabel_':
258  v = value
259  continue
260  self.__addParameter(name, value)
261  if v is not None:
self.__validator=v
def Mixins._Parameterizable.dumpPython (   self,
  options = PrintOptions() 
)

Definition at line 299 of file Mixins.py.

References Mixins._Parameterizable.__validator, join(), and Mixins._Parameterizable.parameterNames_().

Referenced by Modules.SwitchProducer.__addParameter(), Types._AllowedParameterTypes.__init__(), Mixins._Parameterizable.__repr__(), Types.VPSet.__repr__(), Mixins._Parameterizable.__setattr__(), Modules.SwitchProducer.__setattr__(), and SequenceTypes.Schedule.__str__().

300  def dumpPython(self, options=PrintOptions()):
301  specialImportRegistry.registerUse(self)
302  sortedNames = sorted(self.parameterNames_())
303  if len(sortedNames) > 200:
304  #Too many parameters for a python function call
305  # The solution is to create a temporary dictionary which
306  # is constructed by concatenating long lists (with maximum
307  # 200 entries each) together.
308  # This looks like
309  # **dict( [(...,...), ...] + [...] + ... )
310  others = []
311  usings = []
312  for name in sortedNames:
313  param = self.__dict__[name]
314  # we don't want minuses in names
315  name2 = name.replace('-','_')
316  options.indent()
317  #_UsingNodes don't get assigned variables
318  if name.startswith("using_"):
319  usings.append(options.indentation()+param.dumpPython(options))
320  else:
321  others.append((name2, param.dumpPython(options)))
322  options.unindent()
323 
324  resultList = ',\n'.join(usings)
325  longOthers = options.indentation()+"**dict(\n"
326  options.indent()
327  longOthers += options.indentation()+"[\n"
328  entriesInList = 0
329  options.indent()
330  for n,v in others:
331  entriesInList +=1
332  if entriesInList > 200:
333  #need to start a new list
334  options.unindent()
335  longOthers += options.indentation()+"] +\n"+options.indentation()+"[\n"
336  entriesInList = 0
337  options.indent()
338  longOthers += options.indentation()+'("'+n+'" , '+v+' ),\n'
339 
340  longOthers += options.indentation()+"]\n"
341  options.unindent()
342  longOthers +=options.indentation()+")\n"
343  options.unindent()
344  ret = []
345  if resultList:
346  ret.append(resultList)
347  if longOthers:
348  ret.append(longOthers)
349  return ",\n".join(ret)
350  #Standard case, small number of parameters
351  others = []
352  usings = []
353  for name in sortedNames:
354  param = self.__dict__[name]
355  # we don't want minuses in names
356  name2 = name.replace('-','_')
357  options.indent()
358  #_UsingNodes don't get assigned variables
359  if name.startswith("using_"):
360  usings.append(options.indentation()+param.dumpPython(options))
361  else:
362  others.append(options.indentation()+name2+' = '+param.dumpPython(options))
363  options.unindent()
364  # usings need to go first
365  resultList = usings
366  resultList.extend(others)
367  if self.__validator is not None:
368  options.indent()
369  resultList.append(options.indentation()+"allowAnyLabel_="+self.__validator.dumpPython(options))
370  options.unindent()
return ',\n'.join(resultList)+'\n'
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def Mixins._Parameterizable.getParameter (   self,
  params 
)
_getParameter_

Retrieve the specified parameter from the PSet Provided
given the attribute chain

returns None if not found

Definition at line 207 of file Mixins.py.

Referenced by Mixins._Parameterizable.hasParameter().

208  def getParameter(self, params):
209  """
210  _getParameter_
211 
212  Retrieve the specified parameter from the PSet Provided
213  given the attribute chain
214 
215  returns None if not found
216  """
217  lastParam = self
218  # Don't accidentally iterate over letters in a string
219  if type(params).__name__ == 'str':
220  return getattr(self, params, None)
221  for param in params:
222  lastParam = getattr(lastParam, param, None)
223  if lastParam == None:
224  return None
225  return lastParam
def Mixins._Parameterizable.hasParameter (   self,
  params 
)
_hasParameter_

check that pset provided has the attribute chain
specified.

Eg, if params is [ 'attr1', 'attr2', 'attr3' ]
check for pset.attr1.attr2.attr3

returns True if parameter exists, False if not

Definition at line 193 of file Mixins.py.

References DropBoxMetadata::Parameters.getParameter(), Args.getParameter(), QIE8Simulator.getParameter(), AbsElectronicODERHS.getParameter(), SiStripLorentzAngleCalibration.getParameter(), SiPixelLorentzAngleCalibration.getParameter(), IntegratedCalibrationBase.getParameter(), SiStripBackplaneCalibration.getParameter(), edm::ParameterSet.getParameter(), and Mixins._Parameterizable.getParameter().

194  def hasParameter(self, params):
195  """
196  _hasParameter_
197 
198  check that pset provided has the attribute chain
199  specified.
200 
201  Eg, if params is [ 'attr1', 'attr2', 'attr3' ]
202  check for pset.attr1.attr2.attr3
203 
204  returns True if parameter exists, False if not
205  """
206  return (self.getParameter(params) != None)
def Mixins._Parameterizable.insertContentsInto (   self,
  parameterSet 
)

Definition at line 373 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

Referenced by Modules.Service.insertInto(), Mixins._TypedParameterizable.insertInto(), and Types.PSet.insertInto().

374  def insertContentsInto(self, parameterSet):
375  for name in self.parameterNames_():
376  param = getattr(self,name)
377  param.insertInto(parameterSet, name)
378 
def Mixins._Parameterizable.isFrozen (   self)

Definition at line 285 of file Mixins.py.

References Mixins._ParameterTypeBase._isFrozen, and Mixins._Parameterizable._isFrozen.

Referenced by Mixins._Parameterizable.__delattr__(), Mixins._Parameterizable.__setattr__(), and Modules.SwitchProducer.__setattr__().

286  def isFrozen(self):
return self._isFrozen
def Mixins._Parameterizable.isModified (   self)

Definition at line 183 of file Mixins.py.

References Mixins._ParameterTypeBase._isModified, Mixins._SimpleParameterTypeBase._isModified, Mixins._Parameterizable._isModified, and Mixins._Parameterizable.parameterNames_().

184  def isModified(self):
185  if self._isModified:
186  return True
187  for name in self.parameterNames_():
188  param = self.__dict__[name]
189  if isinstance(param, _Parameterizable) and param.isModified():
190  self._isModified = True
191  return True
192  return False
def Mixins._Parameterizable.parameterNames_ (   self)
Returns the name of the parameters

Definition at line 180 of file Mixins.py.

Referenced by Modules.SwitchProducer._chooseCase(), Modules.SwitchProducer.appendToProcessDescLists_(), Modules.SwitchProducer.clone(), Types.PSet.configValue(), Mixins._TypedParameterizable.dumpConfig(), Mixins._Parameterizable.dumpPython(), Modules.SwitchProducer.dumpPython(), Mixins._TypedParameterizable.dumpPython(), Types.EDAlias.dumpPython(), Modules.ESPrefer.dumpPythonAs(), Mixins._TypedParameterizable.dumpPythonAttributes(), Mixins._Parameterizable.insertContentsInto(), Modules.SwitchProducer.insertInto(), Types.EDAlias.insertInto(), Mixins._Parameterizable.isModified(), and Mixins._Parameterizable.parameters_().

181  def parameterNames_(self):
182  """Returns the name of the parameters"""
return self.__parameterNames[:]
def Mixins._Parameterizable.parameters_ (   self)
Returns a dictionary of copies of the user-set parameters

Definition at line 226 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

Referenced by Mixins._TypedParameterizable.clone(), Types.PSet.clone(), Types.EDAlias.clone(), and Mixins._TypedParameterizable.copy().

227  def parameters_(self):
228  """Returns a dictionary of copies of the user-set parameters"""
229  import copy
230  result = dict()
231  for name in self.parameterNames_():
232  result[name]=copy.deepcopy(self.__dict__[name])
233  return result
def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 287 of file Mixins.py.

Referenced by Modules._Module.__init__().

288  def setIsFrozen(self):
289  self._isFrozen = True
290  for name in self.parameterNames_():
self.__dict__[name].setIsFrozen()

Member Data Documentation

Mixins._Parameterizable.__validator
private

Definition at line 236 of file Mixins.py.

Referenced by Mixins._Parameterizable.__setParameters(), and Mixins._Parameterizable.dumpPython().

Mixins._Parameterizable._isFrozen
private

Definition at line 288 of file Mixins.py.

Referenced by Mixins._Parameterizable.isFrozen(), and SequenceTypes._ModuleSequenceType.isFrozen().

Mixins._Parameterizable._isModified
private

Definition at line 178 of file Mixins.py.

Referenced by Modules.SwitchProducer.__addParameter(), Mixins._Parameterizable.__setattr__(), Modules.SwitchProducer.__setattr__(), Mixins._TypedParameterizable.copy(), Mixins._Parameterizable.isModified(), Types.InputTag.setValue(), and Types.ESInputTag.setValue().