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

Constructor & Destructor Documentation

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

Definition at line 129 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

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

Member Function Documentation

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

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

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

Definition at line 242 of file Mixins.py.

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

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

Definition at line 248 of file Mixins.py.

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

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

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

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

Definition at line 209 of file Mixins.py.

References Mixins._Parameterizable.__addParameter().

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

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

Definition at line 250 of file Mixins.py.

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

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

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

References edm.print(), and str.

Referenced by Mixins._Parameterizable.hasParameter().

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

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

Definition at line 319 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

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

Definition at line 145 of file Mixins.py.

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

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

Definition at line 189 of file Mixins.py.

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

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

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

Definition at line 238 of file Mixins.py.

Referenced by Modules._Module.__init__().

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

Member Data Documentation

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