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

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

Definition at line 164 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

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 
def __setParameters(self, parameters)
Definition: Mixins.py:252
def __init__(self, arg, kargs)
Definition: Mixins.py:164

Member Function Documentation

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

Definition at line 233 of file Mixins.py.

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

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 
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:298
def __addParameter(self, name, value)
Definition: Mixins.py:233
def __raiseBadSetAttr(name)
Definition: Mixins.py:296
def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 290 of file Mixins.py.

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

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)
def __delattr__(self, name)
Definition: Mixins.py:290
def isFrozen(self)
Definition: Mixins.py:284
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")
def __raiseBadSetAttr(name)
Definition: Mixins.py:296
def Mixins._Parameterizable.__repr__ (   self)
def Mixins._Parameterizable.__setattr__ (   self,
  name,
  value 
)

Definition at line 261 of file Mixins.py.

References Mixins._Parameterizable.__addParameter(), Mixins._ParameterTypeBase._isModified, Mixins._SimpleParameterTypeBase._isModified, Mixins._Parameterizable._isModified, editorTools.UserCodeTool.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ImportTool.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ApplyTool.dumpPython(), Mixins._ParameterTypeBase.dumpPython(), ConfigToolBase.ConfigToolBase.dumpPython(), Mixins.UsingBlock.dumpPython(), Vispa.Plugins.ConfigEditor.ConfigEditorTabController.ConfigEditorTabController.dumpPython(), Mixins._Parameterizable.dumpPython(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor.dumpPython(), Config.Process.dumpPython(), Config.SubProcess.dumpPython(), Mixins._ParameterTypeBase.isFrozen(), Mixins._Parameterizable.isFrozen(), and reco::JetExtendedAssociation.setValue().

Referenced by GenObject.GenObject.setValue().

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 
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:298
def __addParameter(self, name, value)
Definition: Mixins.py:233
def __setattr__(self, name, value)
Definition: Mixins.py:261
def isFrozen(self)
Definition: Mixins.py:284
def Mixins._Parameterizable.__setParameters (   self,
  parameters 
)
private

Definition at line 252 of file Mixins.py.

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

Referenced by Mixins._Parameterizable.__init__().

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
def __setParameters(self, parameters)
Definition: Mixins.py:252
def __addParameter(self, name, value)
Definition: Mixins.py:233
def Mixins._Parameterizable.dumpPython (   self,
  options = PrintOptions() 
)

Definition at line 298 of file Mixins.py.

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

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

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'
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:298
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
def parameterNames_(self)
Definition: Mixins.py:178
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.

References edm.print(), and str.

Referenced by Mixins._Parameterizable.hasParameter().

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 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
#define str(s)
def getParameter(self, params)
Definition: Mixins.py:205
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.

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

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 
def hasParameter(self, params)
Definition: Mixins.py:191
def getParameter(self, params)
Definition: Mixins.py:205
def Mixins._Parameterizable.insertContentsInto (   self,
  parameterSet 
)

Definition at line 368 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

368  def insertContentsInto(self, parameterSet):
369  for name in self.parameterNames_():
370  param = getattr(self,name)
371  param.insertInto(parameterSet, name)
372 
373 
def parameterNames_(self)
Definition: Mixins.py:178
def insertContentsInto(self, parameterSet)
Definition: Mixins.py:368
def Mixins._Parameterizable.isFrozen (   self)
def Mixins._Parameterizable.isModified (   self)

Definition at line 181 of file Mixins.py.

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

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 
def isModified(self)
Definition: Mixins.py:181
def parameterNames_(self)
Definition: Mixins.py:178
def Mixins._Parameterizable.parameterNames_ (   self)
def Mixins._Parameterizable.parameters_ (   self)
Returns a dictionary of copies of the user-set parameters

Definition at line 225 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

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 
def parameterNames_(self)
Definition: Mixins.py:178
def parameters_(self)
Definition: Mixins.py:225
def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 286 of file Mixins.py.

Referenced by Modules._Module.__init__().

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

Member Data Documentation

Mixins._Parameterizable.__validator
private

Definition at line 235 of file Mixins.py.

Referenced by Mixins._Parameterizable.__setParameters().

Mixins._Parameterizable._isFrozen
private
Mixins._Parameterizable._isModified
private