CMS 3D CMS Logo

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 Types.EDAlias Types.PSet Modules._Module Modules.ESPrefer Modules.ESProducer Modules.ESSource Modules.Looper Modules.Service Modules.Source Types.SecSource

Public Member Functions

def __delattr__ (self, name)
 
def __init__ (self, *arg, **kargs)
 
def __repr__ (self)
 
def __setattr__ (self, name, value)
 
def dumpPython (self, options=PrintOptions())
 
def getParameter (self, params)
 
def hasParameter (self, params)
 
def insertContentsInto (self, parameterSet)
 
def isFrozen (self)
 
def isModified (self)
 
def parameterNames_ (self)
 
def parameters_ (self)
 
def setIsFrozen (self)
 

Private Member Functions

def __addParameter (self, name, value)
 
def __setParameters (self, parameters)
 

Static Private Member Functions

def __raiseBadSetAttr (name)
 

Private Attributes

 __validator
 
 _isFrozen
 
 _isModified
 

Detailed Description

Base class for classes which allow addition of _ParameterTypeBase data

Definition at line 164 of file Mixins.py.

Constructor & Destructor Documentation

◆ __init__()

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

Reimplemented in Types.EDAlias, and Types.PSet.

Definition at line 166 of file Mixins.py.

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  if type(block).__name__ != "PSet":
175  raise ValueError("Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
176  self.__setParameters(block.parameters_())
177  self.__setParameters(kargs)
178  self._isModified = False
179 

References Mixins._Parameterizable.__setParameters().

Member Function Documentation

◆ __addParameter()

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

Reimplemented in Modules.SwitchProducer.

Definition at line 235 of file Mixins.py.

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
253 

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

◆ __delattr__()

def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 292 of file Mixins.py.

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)
296  self.__parameterNames.remove(name)

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

◆ __raiseBadSetAttr()

def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 298 of file Mixins.py.

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

◆ __repr__()

def Mixins._Parameterizable.__repr__ (   self)

◆ __setattr__()

def Mixins._Parameterizable.__setattr__ (   self,
  name,
  value 
)

Reimplemented in Modules.SwitchProducer.

Definition at line 263 of file Mixins.py.

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
285 

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().

Referenced by GenObject.GenObject.setValue().

◆ __setParameters()

def Mixins._Parameterizable.__setParameters (   self,
  parameters 
)
private

Reimplemented in Modules.SwitchProducer.

Definition at line 254 of file Mixins.py.

254  def __setParameters(self,parameters):
255  v = None
256  for name,value in six.iteritems(parameters):
257  if name == 'allowAnyLabel_':
258  v = value
259  continue
260  self.__addParameter(name, value)
261  if v is not None:
262  self.__validator=v

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

Referenced by Mixins._Parameterizable.__init__().

◆ dumpPython()

def Mixins._Parameterizable.dumpPython (   self,
  options = PrintOptions() 
)

Reimplemented in Types.EDAlias, Types.PSet, Types.SecSource, Mixins._TypedParameterizable, and Modules.SwitchProducer.

Definition at line 300 of file Mixins.py.

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()
371  return ',\n'.join(resultList)+'\n'

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

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

◆ getParameter()

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.

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

References print(), and str.

Referenced by Mixins._Parameterizable.hasParameter().

◆ hasParameter()

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.

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

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().

◆ insertContentsInto()

def Mixins._Parameterizable.insertContentsInto (   self,
  parameterSet 
)

Reimplemented in Types.PSet.

Definition at line 374 of file Mixins.py.

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

References Mixins._Parameterizable.parameterNames_().

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

◆ isFrozen()

def Mixins._Parameterizable.isFrozen (   self)

Definition at line 286 of file Mixins.py.

286  def isFrozen(self):
287  return self._isFrozen

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

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

◆ isModified()

def Mixins._Parameterizable.isModified (   self)

Definition at line 183 of file Mixins.py.

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

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

◆ parameterNames_()

def Mixins._Parameterizable.parameterNames_ (   self)

◆ parameters_()

def Mixins._Parameterizable.parameters_ (   self)
Returns a dictionary of copies of the user-set parameters

Definition at line 227 of file Mixins.py.

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
234 

References Mixins._Parameterizable.parameterNames_().

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

◆ setIsFrozen()

def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 288 of file Mixins.py.

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

Referenced by Modules._Module.__init__().

Member Data Documentation

◆ __validator

Mixins._Parameterizable.__validator
private

◆ _isFrozen

Mixins._Parameterizable._isFrozen
private

◆ _isModified

Mixins._Parameterizable._isModified
private
reco::JetExtendedAssociation::setValue
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated
Definition: JetExtendedAssociation.cc:44
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
str
#define str(s)
Definition: TestProcessor.cc:51
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
mps_setup.append
append
Definition: mps_setup.py:85
ConfigBuilder.dumpPython
def dumpPython(process, name)
Definition: ConfigBuilder.py:92
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:219