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

Constructor & Destructor Documentation

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

Definition at line 127 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

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

Member Function Documentation

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

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

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

Definition at line 240 of file Mixins.py.

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

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

Definition at line 246 of file Mixins.py.

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

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

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

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

Definition at line 207 of file Mixins.py.

References Mixins._Parameterizable.__addParameter().

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

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

Definition at line 248 of file Mixins.py.

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

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

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

References harvestTrackValidationPlots.str.

Referenced by Mixins._Parameterizable.hasParameter().

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

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

Definition at line 317 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

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

Definition at line 143 of file Mixins.py.

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

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

Definition at line 187 of file Mixins.py.

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

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

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

Definition at line 236 of file Mixins.py.

Referenced by Modules._Module.__init__().

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

Member Data Documentation

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