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

 _isFrozen
 
 _isModified
 

Detailed Description

Base class for classes which allow addition of _ParameterTypeBase data

Definition at line 160 of file Mixins.py.

Constructor & Destructor Documentation

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

Definition at line 162 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

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

Member Function Documentation

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

Definition at line 230 of file Mixins.py.

References Mixins._Parameterizable.__raiseBadSetAttr(), 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(), and Config.SubProcess.dumpPython().

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

230  def __addParameter(self, name, value):
231  if not isinstance(value,_ParameterTypeBase):
232  self.__raiseBadSetAttr(name)
233  if name in self.__dict__:
234  message = "Duplicate insert of member " + name
235  message += "\nThe original parameters are:\n"
236  message += self.dumpPython() + '\n'
237  raise ValueError(message)
238  self.__dict__[name]=value
239  self.__parameterNames.append(name)
240  self._isModified = True
241 
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:283
def __addParameter(self, name, value)
Definition: Mixins.py:230
def __raiseBadSetAttr(name)
Definition: Mixins.py:281
def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 275 of file Mixins.py.

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

275  def __delattr__(self,name):
276  if self.isFrozen():
277  raise ValueError("Object already added to a process. It is read only now")
278  super(_Parameterizable,self).__delattr__(name)
279  self.__parameterNames.remove(name)
def __delattr__(self, name)
Definition: Mixins.py:275
def isFrozen(self)
Definition: Mixins.py:269
def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 281 of file Mixins.py.

Referenced by Mixins._Parameterizable.__addParameter().

281  def __raiseBadSetAttr(name):
282  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:281
def Mixins._Parameterizable.__repr__ (   self)
def Mixins._Parameterizable.__setattr__ (   self,
  name,
  value 
)

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

246  def __setattr__(self,name,value):
247  #since labels are not supposed to have underscores at the beginning
248  # I will assume that if we have such then we are setting an internal variable
249  if self.isFrozen() and not (name in ["_Labelable__label","_isFrozen"] or name.startswith('_')):
250  message = "Object already added to a process. It is read only now\n"
251  message += " %s = %s" %(name, value)
252  message += "\nThe original parameters are:\n"
253  message += self.dumpPython() + '\n'
254  raise ValueError(message)
255  # underscored names bypass checking for _ParameterTypeBase
256  if name[0]=='_':
257  super(_Parameterizable,self).__setattr__(name,value)
258  elif not name in self.__dict__:
259  self.__addParameter(name, value)
260  self._isModified = True
261  else:
262  # handle the case where users just replace with a value, a = 12, rather than a = cms.int32(12)
263  if isinstance(value,_ParameterTypeBase):
264  self.__dict__[name] = value
265  else:
266  self.__dict__[name].setValue(value)
267  self._isModified = True
268 
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:283
def __addParameter(self, name, value)
Definition: Mixins.py:230
def __setattr__(self, name, value)
Definition: Mixins.py:246
def isFrozen(self)
Definition: Mixins.py:269
def Mixins._Parameterizable.__setParameters (   self,
  parameters 
)
private

Definition at line 242 of file Mixins.py.

References Mixins._Parameterizable.__addParameter().

Referenced by Mixins._Parameterizable.__init__().

242  def __setParameters(self,parameters):
243  for name,value in six.iteritems(parameters):
244  self.__addParameter(name, value)
245 
def __setParameters(self, parameters)
Definition: Mixins.py:242
def __addParameter(self, name, value)
Definition: Mixins.py:230
def Mixins._Parameterizable.dumpPython (   self,
  options = PrintOptions() 
)

Definition at line 283 of file Mixins.py.

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

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

283  def dumpPython(self, options=PrintOptions()):
284  specialImportRegistry.registerUse(self)
285  sortedNames = sorted(self.parameterNames_())
286  if len(sortedNames) > 200:
287  #Too many parameters for a python function call
288  # The solution is to create a temporary dictionary which
289  # is constructed by concatenating long lists (with maximum
290  # 200 entries each) together.
291  # This looks like
292  # **dict( [(...,...), ...] + [...] + ... )
293  others = []
294  usings = []
295  for name in sortedNames:
296  param = self.__dict__[name]
297  # we don't want minuses in names
298  name2 = name.replace('-','_')
299  options.indent()
300  #_UsingNodes don't get assigned variables
301  if name.startswith("using_"):
302  usings.append(options.indentation()+param.dumpPython(options))
303  else:
304  others.append((name2, param.dumpPython(options)))
305  options.unindent()
306 
307  resultList = ',\n'.join(usings)
308  longOthers = options.indentation()+"**dict(\n"
309  options.indent()
310  longOthers += options.indentation()+"[\n"
311  entriesInList = 0
312  options.indent()
313  for n,v in others:
314  entriesInList +=1
315  if entriesInList > 200:
316  #need to start a new list
317  options.unindent()
318  longOthers += options.indentation()+"] +\n"+options.indentation()+"[\n"
319  entriesInList = 0
320  options.indent()
321  longOthers += options.indentation()+'("'+n+'" , '+v+' ),\n'
322 
323  longOthers += options.indentation()+"]\n"
324  options.unindent()
325  longOthers +=options.indentation()+")\n"
326  options.unindent()
327  ret = []
328  if resultList:
329  ret.append(resultList)
330  if longOthers:
331  ret.append(longOthers)
332  return ",\n".join(ret)
333  #Standard case, small number of parameters
334  others = []
335  usings = []
336  for name in sortedNames:
337  param = self.__dict__[name]
338  # we don't want minuses in names
339  name2 = name.replace('-','_')
340  options.indent()
341  #_UsingNodes don't get assigned variables
342  if name.startswith("using_"):
343  usings.append(options.indentation()+param.dumpPython(options))
344  else:
345  others.append(options.indentation()+name2+' = '+param.dumpPython(options))
346  options.unindent()
347  # usings need to go first
348  resultList = usings
349  resultList.extend(others)
350  return ',\n'.join(resultList)+'\n'
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:283
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def parameterNames_(self)
Definition: Mixins.py:175
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 202 of file Mixins.py.

References edm.print(), and str.

Referenced by Mixins._Parameterizable.hasParameter().

202  def getParameter(self, params):
203  """
204  _getParameter_
205 
206  Retrieve the specified parameter from the PSet Provided
207  given the attribute chain
208 
209  returns None if not found
210  """
211  lastParam = self
212  # Don't accidentally iterate over letters in a string
213  if type(params).__name__ == 'str':
214  return getattr(self, params, None)
215  for param in params:
216  lastParam = getattr(lastParam, param, None)
217  print(str(lastParam))
218  if lastParam == None:
219  return None
220  return lastParam
221 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
#define str(s)
def getParameter(self, params)
Definition: Mixins.py:202
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 188 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().

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

Definition at line 353 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

353  def insertContentsInto(self, parameterSet):
354  for name in self.parameterNames_():
355  param = getattr(self,name)
356  param.insertInto(parameterSet, name)
357 
358 
def parameterNames_(self)
Definition: Mixins.py:175
def insertContentsInto(self, parameterSet)
Definition: Mixins.py:353
def Mixins._Parameterizable.isFrozen (   self)
def Mixins._Parameterizable.isModified (   self)

Definition at line 178 of file Mixins.py.

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

178  def isModified(self):
179  if self._isModified:
180  return True
181  for name in self.parameterNames_():
182  param = self.__dict__[name]
183  if isinstance(param, _Parameterizable) and param.isModified():
184  self._isModified = True
185  return True
186  return False
187 
def isModified(self)
Definition: Mixins.py:178
def parameterNames_(self)
Definition: Mixins.py:175
def Mixins._Parameterizable.parameterNames_ (   self)
def Mixins._Parameterizable.parameters_ (   self)
Returns a dictionary of copies of the user-set parameters

Definition at line 222 of file Mixins.py.

References cmsPerfStripChart.dict, and Mixins._Parameterizable.parameterNames_().

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

222  def parameters_(self):
223  """Returns a dictionary of copies of the user-set parameters"""
224  import copy
225  result = dict()
226  for name in self.parameterNames_():
227  result[name]=copy.deepcopy(self.__dict__[name])
228  return result
229 
def parameterNames_(self)
Definition: Mixins.py:175
def parameters_(self)
Definition: Mixins.py:222
def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 271 of file Mixins.py.

Referenced by Modules._Module.__init__().

271  def setIsFrozen(self):
272  self._isFrozen = True
273  for name in self.parameterNames_():
274  self.__dict__[name].setIsFrozen()
def setIsFrozen(self)
Definition: Mixins.py:271
def parameterNames_(self)
Definition: Mixins.py:175

Member Data Documentation

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