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 235 of file Mixins.py.

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

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

Definition at line 292 of file Mixins.py.

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

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

Definition at line 298 of file Mixins.py.

299  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 372 of file Mixins.py.

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

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

Definition at line 263 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(), Mixins._ParameterTypeBase.isFrozen(), Mixins._Parameterizable.isFrozen(), and reco::JetExtendedAssociation.setValue().

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

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

Referenced by Mixins._Parameterizable.__init__().

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

Definition at line 300 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__().

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

References print(), and str.

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  print(str(lastParam))
224  if lastParam == None:
225  return None
226  return lastParam
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)
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 374 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

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

Definition at line 286 of file Mixins.py.

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

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

287  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 227 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

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

Definition at line 288 of file Mixins.py.

Referenced by Modules._Module.__init__().

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

Member Data Documentation

Mixins._Parameterizable.__validator
private

Definition at line 237 of file Mixins.py.

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

Mixins._Parameterizable._isFrozen
private

Definition at line 289 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().