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

 __validator
 
 _isFrozen
 
 _isModified
 

Detailed Description

Base class for classes which allow addition of _ParameterTypeBase data

Definition at line 163 of file Mixins.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 165 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

165  def __init__(self,*arg,**kargs):
166  self.__dict__['_Parameterizable__parameterNames'] = []
167  self.__dict__["_isFrozen"] = False
168  self.__dict__['_Parameterizable__validator'] = None
169  """The named arguments are the 'parameters' which are added as 'python attributes' to the object"""
170  if len(arg) != 0:
171  #raise ValueError("unnamed arguments are not allowed. Please use the syntax 'name = value' when assigning arguments.")
172  for block in arg:
173  # Allow __PSet for testing
174  if type(block).__name__ not in ["PSet", "__PSet"]:
175  raise ValueError("Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
176  self.__setParameters(block.parameters_())
177  self.__setParameters(kargs)
178  self._isModified = False
179 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ __addParameter()

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

Definition at line 234 of file Mixins.py.

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

234  def __addParameter(self, name, value):
235  if name == 'allowAnyLabel_':
236  self.__validator = value
237  self._isModified = True
238  return
239  if not isinstance(value,_ParameterTypeBase):
240  if self.__validator is not None:
241  value = self.__validator.convert_(value)
242  else:
243  self.__raiseBadSetAttr(name)
244  if name in self.__dict__:
245  message = "Duplicate insert of member " + name
246  message += "\nThe original parameters are:\n"
247  message += self.dumpPython() + '\n'
248  raise ValueError(message)
249  self.__dict__[name]=value
250  self.__parameterNames.append(name)
251  self._isModified = True
252 

◆ __delattr__()

def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 291 of file Mixins.py.

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

291  def __delattr__(self,name):
292  if self.isFrozen():
293  raise ValueError("Object already added to a process. It is read only now")
294  super(_Parameterizable,self).__delattr__(name)
295  self.__parameterNames.remove(name)
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:223

◆ __raiseBadSetAttr()

def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 297 of file Mixins.py.

297  def __raiseBadSetAttr(name):
298  raise TypeError(name+" does not already exist, so it can only be set to a CMS python configuration type")

◆ __repr__()

def Mixins._Parameterizable.__repr__ (   self)

◆ __setattr__()

def Mixins._Parameterizable.__setattr__ (   self,
  name,
  value 
)

Definition at line 262 of file Mixins.py.

References Mixins._Parameterizable.__addParameter(), Mixins._ParameterTypeBase._isModified, Mixins._SimpleParameterTypeBase._isModified, Mixins._Parameterizable._isModified, Mixins._ParameterTypeBase.dumpPython(), Mixins.UsingBlock.dumpPython(), Mixins._Parameterizable.dumpPython(), Config.Process.dumpPython(), Config.SubProcess.dumpPython(), Config.ProcessAccelerator.dumpPython(), Mixins._ParameterTypeBase.isFrozen(), Mixins._Parameterizable.isFrozen(), and reco::JetExtendedAssociation.setValue().

Referenced by GenObject.GenObject.setValue().

262  def __setattr__(self,name,value):
263  #since labels are not supposed to have underscores at the beginning
264  # I will assume that if we have such then we are setting an internal variable
265  if self.isFrozen() and not (name in ["_Labelable__label","_isFrozen"] or name.startswith('_')):
266  message = "Object already added to a process. It is read only now\n"
267  message += " %s = %s" %(name, value)
268  message += "\nThe original parameters are:\n"
269  message += self.dumpPython() + '\n'
270  raise ValueError(message)
271  # underscored names bypass checking for _ParameterTypeBase
272  if name[0]=='_':
273  super(_Parameterizable,self).__setattr__(name,value)
274  elif not name in self.__dict__:
275  self.__addParameter(name, value)
276  self._isModified = True
277  else:
278  # handle the case where users just replace with a value, a = 12, rather than a = cms.int32(12)
279  if isinstance(value,_ParameterTypeBase):
280  self.__dict__[name] = value
281  else:
282  self.__dict__[name].setValue(value)
283  self._isModified = True
284 
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...

◆ __setParameters()

def Mixins._Parameterizable.__setParameters (   self,
  parameters 
)
private

Definition at line 253 of file Mixins.py.

References Mixins._Parameterizable.__addParameter(), and Mixins._Parameterizable.__validator.

Referenced by Mixins._Parameterizable.__init__().

253  def __setParameters(self,parameters):
254  v = None
255  for name,value in parameters.items():
256  if name == 'allowAnyLabel_':
257  v = value
258  continue
259  self.__addParameter(name, value)
260  if v is not None:
261  self.__validator=v

◆ dumpPython()

def Mixins._Parameterizable.dumpPython (   self,
  options = PrintOptions() 
)

Definition at line 299 of file Mixins.py.

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

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

299  def dumpPython(self, options=PrintOptions()):
300  specialImportRegistry.registerUse(self)
301  sortedNames = sorted(self.parameterNames_())
302  if len(sortedNames) > 200:
303  #Too many parameters for a python function call
304  # The solution is to create a temporary dictionary which
305  # is constructed by concatenating long lists (with maximum
306  # 200 entries each) together.
307  # This looks like
308  # **dict( [(...,...), ...] + [...] + ... )
309  others = []
310  usings = []
311  for name in sortedNames:
312  param = self.__dict__[name]
313  # we don't want minuses in names
314  name2 = name.replace('-','_')
315  options.indent()
316  #_UsingNodes don't get assigned variables
317  if name.startswith("using_"):
318  usings.append(options.indentation()+param.dumpPython(options))
319  else:
320  others.append((name2, param.dumpPython(options)))
321  options.unindent()
322 
323  resultList = ',\n'.join(usings)
324  longOthers = options.indentation()+"**dict(\n"
325  options.indent()
326  longOthers += options.indentation()+"[\n"
327  entriesInList = 0
328  options.indent()
329  for n,v in others:
330  entriesInList +=1
331  if entriesInList > 200:
332  #need to start a new list
333  options.unindent()
334  longOthers += options.indentation()+"] +\n"+options.indentation()+"[\n"
335  entriesInList = 0
336  options.indent()
337  longOthers += options.indentation()+'("'+n+'" , '+v+' ),\n'
338 
339  longOthers += options.indentation()+"]\n"
340  options.unindent()
341  longOthers +=options.indentation()+")\n"
342  options.unindent()
343  ret = []
344  if resultList:
345  ret.append(resultList)
346  if longOthers:
347  ret.append(longOthers)
348  return ",\n".join(ret)
349  #Standard case, small number of parameters
350  others = []
351  usings = []
352  for name in sortedNames:
353  param = self.__dict__[name]
354  # we don't want minuses in names
355  name2 = name.replace('-','_')
356  options.indent()
357  #_UsingNodes don't get assigned variables
358  if name.startswith("using_"):
359  usings.append(options.indentation()+param.dumpPython(options))
360  else:
361  others.append(options.indentation()+name2+' = '+param.dumpPython(options))
362  options.unindent()
363  # usings need to go first
364  resultList = usings
365  resultList.extend(others)
366  if self.__validator is not None:
367  options.indent()
368  resultList.append(options.indentation()+"allowAnyLabel_="+self.__validator.dumpPython(options))
369  options.unindent()
370  return ',\n'.join(resultList)+'\n'
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def dumpPython(process, name)

◆ getParameter()

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

Referenced by Mixins._Parameterizable.hasParameter().

207  def getParameter(self, params):
208  """
209  _getParameter_
210 
211  Retrieve the specified parameter from the PSet Provided
212  given the attribute chain
213 
214  returns None if not found
215  """
216  lastParam = self
217  # Don't accidentally iterate over letters in a string
218  if type(params).__name__ == 'str':
219  return getattr(self, params, None)
220  for param in params:
221  lastParam = getattr(lastParam, param, None)
222  if lastParam == None:
223  return None
224  return lastParam
225 

◆ hasParameter()

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

193  def hasParameter(self, params):
194  """
195  _hasParameter_
196 
197  check that pset provided has the attribute chain
198  specified.
199 
200  Eg, if params is [ 'attr1', 'attr2', 'attr3' ]
201  check for pset.attr1.attr2.attr3
202 
203  returns True if parameter exists, False if not
204  """
205  return (self.getParameter(params) != None)
206 

◆ insertContentsInto()

def Mixins._Parameterizable.insertContentsInto (   self,
  parameterSet 
)

Definition at line 373 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

373  def insertContentsInto(self, parameterSet):
374  for name in self.parameterNames_():
375  param = getattr(self,name)
376  param.insertInto(parameterSet, name)
377 
378 

◆ isFrozen()

def Mixins._Parameterizable.isFrozen (   self)

Definition at line 285 of file Mixins.py.

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

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

285  def isFrozen(self):
286  return self._isFrozen

◆ isModified()

def Mixins._Parameterizable.isModified (   self)

Definition at line 183 of file Mixins.py.

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

183  def isModified(self):
184  if self._isModified:
185  return True
186  for name in self.parameterNames_():
187  param = self.__dict__[name]
188  if isinstance(param, _Parameterizable) and param.isModified():
189  self._isModified = True
190  return True
191  return False
192 

◆ parameterNames_()

def Mixins._Parameterizable.parameterNames_ (   self)

◆ parameters_()

def Mixins._Parameterizable.parameters_ (   self)
Returns a dictionary of copies of the user-set parameters

Definition at line 226 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

226  def parameters_(self):
227  """Returns a dictionary of copies of the user-set parameters"""
228  import copy
229  result = dict()
230  for name in self.parameterNames_():
231  result[name]=copy.deepcopy(self.__dict__[name])
232  return result
233 

◆ setIsFrozen()

def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 287 of file Mixins.py.

Referenced by Modules._Module.__init__().

287  def setIsFrozen(self):
288  self._isFrozen = True
289  for name in self.parameterNames_():
290  self.__dict__[name].setIsFrozen()

Member Data Documentation

◆ __validator

Mixins._Parameterizable.__validator
private

◆ _isFrozen

Mixins._Parameterizable._isFrozen
private

◆ _isModified

Mixins._Parameterizable._isModified
private