CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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__
 
def __init__
 
def __repr__
 
def __setattr__
 
def dumpPython
 
def getParameter
 
def hasParameter
 
def insertContentsInto
 
def isFrozen
 
def isModified
 
def parameterNames_
 
def parameters_
 
def setIsFrozen
 

Private Member Functions

def __addParameter
 
def __setParameters
 

Static Private Member Functions

def __raiseBadSetAttr
 

Private Attributes

 _isFrozen
 
 _isModified
 

Detailed Description

Base class for classes which allow addition of _ParameterTypeBase data

Definition at line 108 of file Mixins.py.

Constructor & Destructor Documentation

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

Definition at line 110 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

111  def __init__(self,*arg,**kargs):
112  self.__dict__['_Parameterizable__parameterNames'] = []
113  self.__dict__["_isFrozen"] = False
114  """The named arguments are the 'parameters' which are added as 'python attributes' to the object"""
115  if len(arg) != 0:
116  #raise ValueError("unnamed arguments are not allowed. Please use the syntax 'name = value' when assigning arguments.")
117  for block in arg:
118  if type(block).__name__ != "PSet":
119  raise ValueError("Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
120  self.__setParameters(block.parameters_())
121  self.__setParameters(kargs)
122  self._isModified = False

Member Function Documentation

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

Definition at line 178 of file Mixins.py.

References Mixins._Parameterizable.__raiseBadSetAttr(), Mixins._ParameterTypeBase._isModified, Mixins._SimpleParameterTypeBase._isModified, Mixins._Parameterizable._isModified, editorTools.UserCodeTool.dumpPython(), Mixins._ParameterTypeBase.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ImportTool.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().

179  def __addParameter(self, name, value):
180  if not isinstance(value,_ParameterTypeBase):
181  self.__raiseBadSetAttr(name)
182  if name in self.__dict__:
183  message = "Duplicate insert of member " + name
184  message += "\nThe original parameters are:\n"
185  message += self.dumpPython() + '\n'
186  raise ValueError(message)
187  self.__dict__[name]=value
188  self.__parameterNames.append(name)
189  self._isModified = True
def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 223 of file Mixins.py.

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

224  def __delattr__(self,name):
225  if self.isFrozen():
226  raise ValueError("Object already added to a process. It is read only now")
227  super(_Parameterizable,self).__delattr__(name)
self.__parameterNames.remove(name)
def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 229 of file Mixins.py.

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

230  def __raiseBadSetAttr(name):
raise TypeError(name+" does not already exist, so it can only be set to a CMS python configuration type")
def Mixins._Parameterizable.__repr__ (   self)

Definition at line 298 of file Mixins.py.

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

299  def __repr__(self):
return self.dumpPython()
def Mixins._Parameterizable.__setattr__ (   self,
  name,
  value 
)

Definition at line 194 of file Mixins.py.

References Mixins._Parameterizable.__addParameter(), Mixins._ParameterTypeBase._isModified, Mixins._SimpleParameterTypeBase._isModified, Mixins._Parameterizable._isModified, editorTools.UserCodeTool.dumpPython(), Mixins._ParameterTypeBase.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ImportTool.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().

195  def __setattr__(self,name,value):
196  #since labels are not supposed to have underscores at the beginning
197  # I will assume that if we have such then we are setting an internal variable
198  if self.isFrozen() and not (name in ["_Labelable__label","_isFrozen"] or name.startswith('_')):
199  message = "Object already added to a process. It is read only now\n"
200  message += " %s = %s" %(name, value)
201  message += "\nThe original parameters are:\n"
202  message += self.dumpPython() + '\n'
203  raise ValueError(message)
204  # underscored names bypass checking for _ParameterTypeBase
205  if name[0]=='_':
206  super(_Parameterizable,self).__setattr__(name,value)
207  elif not name in self.__dict__:
208  self.__addParameter(name, value)
209  self._isModified = True
210  else:
211  # handle the case where users just replace with a value, a = 12, rather than a = cms.int32(12)
212  if isinstance(value,_ParameterTypeBase):
213  self.__dict__[name] = value
214  else:
215  self.__dict__[name].setValue(value)
216  self._isModified = True
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
def Mixins._Parameterizable.__setParameters (   self,
  parameters 
)
private

Definition at line 190 of file Mixins.py.

References Mixins._Parameterizable.__addParameter().

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

191  def __setParameters(self,parameters):
192  for name,value in parameters.iteritems():
193  self.__addParameter(name, value)
def Mixins._Parameterizable.dumpPython (   self,
  options = PrintOptions() 
)

Definition at line 231 of file Mixins.py.

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

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

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

Referenced by Mixins._Parameterizable.hasParameter().

151  def getParameter(self, params):
152  """
153  _getParameter_
154 
155  Retrieve the specified parameter from the PSet Provided
156  given the attribute chain
157 
158  returns None if not found
159  """
160  lastParam = self
161  # Don't accidentally iterate over letters in a string
162  if type(params).__name__ == 'str':
163  return getattr(self, params, None)
164  for param in params:
165  lastParam = getattr(lastParam, param, None)
166  print str(lastParam)
167  if lastParam == None:
168  return None
169  return lastParam
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 136 of file Mixins.py.

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

137  def hasParameter(self, params):
138  """
139  _hasParameter_
140 
141  check that pset provided has the attribute chain
142  specified.
143 
144  Eg, if params is [ 'attr1', 'attr2', 'attr3' ]
145  check for pset.attr1.attr2.attr3
146 
147  returns True if parameter exists, False if not
148  """
149  return (self.getParameter(params) != None)
def Mixins._Parameterizable.insertContentsInto (   self,
  parameterSet 
)

Definition at line 300 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

301  def insertContentsInto(self, parameterSet):
302  for name in self.parameterNames_():
303  param = getattr(self,name)
304  param.insertInto(parameterSet, name)
305 
def Mixins._Parameterizable.isFrozen (   self)

Definition at line 217 of file Mixins.py.

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

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

218  def isFrozen(self):
return self._isFrozen
def Mixins._Parameterizable.isModified (   self)

Definition at line 126 of file Mixins.py.

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

127  def isModified(self):
128  if self._isModified:
129  return True
130  for name in self.parameterNames_():
131  param = self.__dict__[name]
132  if isinstance(param, _Parameterizable) and param.isModified():
133  self._isModified = True
134  return True
135  return False
def Mixins._Parameterizable.parameterNames_ (   self)
Returns the name of the parameters

Definition at line 123 of file Mixins.py.

Referenced by Types.PSet.configValue(), Mixins._TypedParameterizable.dumpConfig(), Mixins._Parameterizable.dumpPython(), Mixins._TypedParameterizable.dumpPython(), Types.EDAlias.dumpPython(), Modules.ESPrefer.dumpPythonAs(), Mixins._TypedParameterizable.dumpPythonAttributes(), Mixins._Parameterizable.insertContentsInto(), Types.EDAlias.insertInto(), Mixins._Parameterizable.isModified(), and Mixins._Parameterizable.parameters_().

124  def parameterNames_(self):
125  """Returns the name of the parameters"""
return self.__parameterNames[:]
def Mixins._Parameterizable.parameters_ (   self)
Returns a dictionary of copies of the user-set parameters

Definition at line 170 of file Mixins.py.

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

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

171  def parameters_(self):
172  """Returns a dictionary of copies of the user-set parameters"""
173  import copy
174  result = dict()
175  for name in self.parameterNames_():
176  result[name]=copy.deepcopy(self.__dict__[name])
177  return result
def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 219 of file Mixins.py.

Referenced by Modules._Module.__init__().

220  def setIsFrozen(self):
221  self._isFrozen = True
222  for name in self.parameterNames_():
self.__dict__[name].setIsFrozen()

Member Data Documentation

Mixins._Parameterizable._isFrozen
private

Definition at line 220 of file Mixins.py.

Referenced by SequenceTypes._ModuleSequenceType.isFrozen(), and Mixins._Parameterizable.isFrozen().

Mixins._Parameterizable._isModified
private

Definition at line 121 of file Mixins.py.

Referenced by Mixins._Parameterizable.__addParameter(), Mixins._Parameterizable.__setattr__(), Mixins._TypedParameterizable.copy(), and Mixins._Parameterizable.isModified().