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

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

References Mixins._Parameterizable.__setParameters().

Member Function Documentation

◆ __addParameter()

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

Reimplemented in Modules.SwitchProducer.

Definition at line 233 of file Mixins.py.

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

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

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

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

◆ __raiseBadSetAttr()

def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 296 of file Mixins.py.

296  def __raiseBadSetAttr(name):
297  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 261 of file Mixins.py.

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

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

252  def __setParameters(self,parameters):
253  v = None
254  for name,value in six.iteritems(parameters):
255  if name == 'allowAnyLabel_':
256  v = value
257  continue
258  self.__addParameter(name, value)
259  if v is not None:
260  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 298 of file Mixins.py.

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

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

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

References edm.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 191 of file Mixins.py.

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

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

368  def insertContentsInto(self, parameterSet):
369  for name in self.parameterNames_():
370  param = getattr(self,name)
371  param.insertInto(parameterSet, name)
372 
373 

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

284  def isFrozen(self):
285  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 181 of file Mixins.py.

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

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

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

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

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

Referenced by Modules._Module.__init__().

Member Data Documentation

◆ __validator

Mixins._Parameterizable.__validator
private

Definition at line 235 of file Mixins.py.

Referenced by Mixins._Parameterizable.__setParameters().

◆ _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:48
mps_setup.append
append
Definition: mps_setup.py:85
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
ConfigBuilder.dumpPython
def dumpPython(process, name)
Definition: ConfigBuilder.py:92
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:212