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

Constructor & Destructor Documentation

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

Definition at line 128 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

128  def __init__(self,*arg,**kargs):
129  self.__dict__['_Parameterizable__parameterNames'] = []
130  self.__dict__["_isFrozen"] = False
131  """The named arguments are the 'parameters' which are added as 'python attributes' to the object"""
132  if len(arg) != 0:
133  #raise ValueError("unnamed arguments are not allowed. Please use the syntax 'name = value' when assigning arguments.")
134  for block in arg:
135  if type(block).__name__ != "PSet":
136  raise ValueError("Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
137  self.__setParameters(block.parameters_())
138  self.__setParameters(kargs)
139  self._isModified = False
140 
def __setParameters(self, parameters)
Definition: Mixins.py:208
def __init__(self, arg, kargs)
Definition: Mixins.py:128

Member Function Documentation

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

Definition at line 196 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(), Mixins._ParameterTypeBase.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ApplyTool.dumpPython(), Mixins.UsingBlock.dumpPython(), ConfigToolBase.ConfigToolBase.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__(), Mixins._Parameterizable.__setParameters(), and Types.EDAlias.__setParameters().

196  def __addParameter(self, name, value):
197  if not isinstance(value,_ParameterTypeBase):
198  self.__raiseBadSetAttr(name)
199  if name in self.__dict__:
200  message = "Duplicate insert of member " + name
201  message += "\nThe original parameters are:\n"
202  message += self.dumpPython() + '\n'
203  raise ValueError(message)
204  self.__dict__[name]=value
205  self.__parameterNames.append(name)
206  self._isModified = True
207 
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:249
def __addParameter(self, name, value)
Definition: Mixins.py:196
def __raiseBadSetAttr(name)
Definition: Mixins.py:247
def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 241 of file Mixins.py.

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

241  def __delattr__(self,name):
242  if self.isFrozen():
243  raise ValueError("Object already added to a process. It is read only now")
244  super(_Parameterizable,self).__delattr__(name)
245  self.__parameterNames.remove(name)
def __delattr__(self, name)
Definition: Mixins.py:241
def isFrozen(self)
Definition: Mixins.py:235
def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 247 of file Mixins.py.

Referenced by Mixins._Parameterizable.__addParameter(), and Types.EDAlias.__addParameter().

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

Definition at line 212 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(), Mixins._ParameterTypeBase.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ApplyTool.dumpPython(), Mixins.UsingBlock.dumpPython(), ConfigToolBase.ConfigToolBase.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().

212  def __setattr__(self,name,value):
213  #since labels are not supposed to have underscores at the beginning
214  # I will assume that if we have such then we are setting an internal variable
215  if self.isFrozen() and not (name in ["_Labelable__label","_isFrozen"] or name.startswith('_')):
216  message = "Object already added to a process. It is read only now\n"
217  message += " %s = %s" %(name, value)
218  message += "\nThe original parameters are:\n"
219  message += self.dumpPython() + '\n'
220  raise ValueError(message)
221  # underscored names bypass checking for _ParameterTypeBase
222  if name[0]=='_':
223  super(_Parameterizable,self).__setattr__(name,value)
224  elif not name in self.__dict__:
225  self.__addParameter(name, value)
226  self._isModified = True
227  else:
228  # handle the case where users just replace with a value, a = 12, rather than a = cms.int32(12)
229  if isinstance(value,_ParameterTypeBase):
230  self.__dict__[name] = value
231  else:
232  self.__dict__[name].setValue(value)
233  self._isModified = True
234 
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:249
def __addParameter(self, name, value)
Definition: Mixins.py:196
def __setattr__(self, name, value)
Definition: Mixins.py:212
def isFrozen(self)
Definition: Mixins.py:235
def Mixins._Parameterizable.__setParameters (   self,
  parameters 
)
private

Definition at line 208 of file Mixins.py.

References Mixins._Parameterizable.__addParameter().

Referenced by Mixins._Parameterizable.__init__(), and Types.EDAlias.__init__().

208  def __setParameters(self,parameters):
209  for name,value in six.iteritems(parameters):
210  self.__addParameter(name, value)
211 
def __setParameters(self, parameters)
Definition: Mixins.py:208
def __addParameter(self, name, value)
Definition: Mixins.py:196
def Mixins._Parameterizable.dumpPython (   self,
  options = PrintOptions() 
)

Definition at line 249 of file Mixins.py.

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

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

249  def dumpPython(self, options=PrintOptions()):
250  sortedNames = sorted(self.parameterNames_())
251  if len(sortedNames) > 200:
252  #Too many parameters for a python function call
253  # The solution is to create a temporary dictionary which
254  # is constructed by concatenating long lists (with maximum
255  # 200 entries each) together.
256  # This looks like
257  # **dict( [(...,...), ...] + [...] + ... )
258  others = []
259  usings = []
260  for name in sortedNames:
261  param = self.__dict__[name]
262  # we don't want minuses in names
263  name2 = name.replace('-','_')
264  options.indent()
265  #_UsingNodes don't get assigned variables
266  if name.startswith("using_"):
267  usings.append(options.indentation()+param.dumpPython(options))
268  else:
269  others.append((name2, param.dumpPython(options)))
270  options.unindent()
271 
272  resultList = ',\n'.join(usings)
273  longOthers = options.indentation()+"**dict(\n"
274  options.indent()
275  longOthers += options.indentation()+"[\n"
276  entriesInList = 0
277  options.indent()
278  for n,v in others:
279  entriesInList +=1
280  if entriesInList > 200:
281  #need to start a new list
282  options.unindent()
283  longOthers += options.indentation()+"] +\n"+options.indentation()+"[\n"
284  entriesInList = 0
285  options.indent()
286  longOthers += options.indentation()+'("'+n+'" , '+v+' ),\n'
287 
288  longOthers += options.indentation()+"]\n"
289  options.unindent()
290  longOthers +=options.indentation()+")\n"
291  options.unindent()
292  ret = []
293  if resultList:
294  ret.append(resultList)
295  if longOthers:
296  ret.append(longOthers)
297  return ",\n".join(ret)
298  #Standard case, small number of parameters
299  others = []
300  usings = []
301  for name in sortedNames:
302  param = self.__dict__[name]
303  # we don't want minuses in names
304  name2 = name.replace('-','_')
305  options.indent()
306  #_UsingNodes don't get assigned variables
307  if name.startswith("using_"):
308  usings.append(options.indentation()+param.dumpPython(options))
309  else:
310  others.append(options.indentation()+name2+' = '+param.dumpPython(options))
311  options.unindent()
312  # usings need to go first
313  resultList = usings
314  resultList.extend(others)
315  return ',\n'.join(resultList)+'\n'
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:249
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def parameterNames_(self)
Definition: Mixins.py:141
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 168 of file Mixins.py.

References str.

Referenced by Mixins._Parameterizable.hasParameter().

168  def getParameter(self, params):
169  """
170  _getParameter_
171 
172  Retrieve the specified parameter from the PSet Provided
173  given the attribute chain
174 
175  returns None if not found
176  """
177  lastParam = self
178  # Don't accidentally iterate over letters in a string
179  if type(params).__name__ == 'str':
180  return getattr(self, params, None)
181  for param in params:
182  lastParam = getattr(lastParam, param, None)
183  print str(lastParam)
184  if lastParam == None:
185  return None
186  return lastParam
187 
#define str(s)
def getParameter(self, params)
Definition: Mixins.py:168
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 154 of file Mixins.py.

References DropBoxMetadata::Parameters.getParameter(), Args.getParameter(), QIE8Simulator.getParameter(), AbsElectronicODERHS.getParameter(), IntegratedCalibrationBase.getParameter(), SiStripLorentzAngleCalibration.getParameter(), SiPixelLorentzAngleCalibration.getParameter(), SiStripBackplaneCalibration.getParameter(), edm::ParameterSet.getParameter(), and Mixins._Parameterizable.getParameter().

154  def hasParameter(self, params):
155  """
156  _hasParameter_
157 
158  check that pset provided has the attribute chain
159  specified.
160 
161  Eg, if params is [ 'attr1', 'attr2', 'attr3' ]
162  check for pset.attr1.attr2.attr3
163 
164  returns True if parameter exists, False if not
165  """
166  return (self.getParameter(params) != None)
167 
def hasParameter(self, params)
Definition: Mixins.py:154
def getParameter(self, params)
Definition: Mixins.py:168
def Mixins._Parameterizable.insertContentsInto (   self,
  parameterSet 
)

Definition at line 318 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

318  def insertContentsInto(self, parameterSet):
319  for name in self.parameterNames_():
320  param = getattr(self,name)
321  param.insertInto(parameterSet, name)
322 
323 
def parameterNames_(self)
Definition: Mixins.py:141
def insertContentsInto(self, parameterSet)
Definition: Mixins.py:318
def Mixins._Parameterizable.isFrozen (   self)
def Mixins._Parameterizable.isModified (   self)

Definition at line 144 of file Mixins.py.

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

144  def isModified(self):
145  if self._isModified:
146  return True
147  for name in self.parameterNames_():
148  param = self.__dict__[name]
149  if isinstance(param, _Parameterizable) and param.isModified():
150  self._isModified = True
151  return True
152  return False
153 
def isModified(self)
Definition: Mixins.py:144
def parameterNames_(self)
Definition: Mixins.py:141
def Mixins._Parameterizable.parameterNames_ (   self)
def Mixins._Parameterizable.parameters_ (   self)
Returns a dictionary of copies of the user-set parameters

Definition at line 188 of file Mixins.py.

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

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

188  def parameters_(self):
189  """Returns a dictionary of copies of the user-set parameters"""
190  import copy
191  result = dict()
192  for name in self.parameterNames_():
193  result[name]=copy.deepcopy(self.__dict__[name])
194  return result
195 
def parameterNames_(self)
Definition: Mixins.py:141
def parameters_(self)
Definition: Mixins.py:188
def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 237 of file Mixins.py.

Referenced by Modules._Module.__init__().

237  def setIsFrozen(self):
238  self._isFrozen = True
239  for name in self.parameterNames_():
240  self.__dict__[name].setIsFrozen()
def setIsFrozen(self)
Definition: Mixins.py:237
def parameterNames_(self)
Definition: Mixins.py:141

Member Data Documentation

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