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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 170 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

170  def __init__(self,*arg,**kargs):
171  self.__dict__['_Parameterizable__parameterNames'] = []
172  self.__dict__["_isFrozen"] = False
173  self.__dict__['_Parameterizable__validator'] = None
174  """The named arguments are the 'parameters' which are added as 'python attributes' to the object"""
175  if len(arg) != 0:
176  #raise ValueError("unnamed arguments are not allowed. Please use the syntax 'name = value' when assigning arguments.")
177  for block in arg:
178  # Allow __PSet for testing
179  if type(block).__name__ not in ["PSet", "__PSet"]:
180  raise ValueError("Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
181  self.__setParameters(block.parameters_())
182  self.__setParameters(kargs)
183  self._isModified = False
184 
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 239 of file Mixins.py.

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

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

◆ __delattr__()

def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 296 of file Mixins.py.

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

296  def __delattr__(self,name):
297  if self.isFrozen():
298  raise ValueError("Object already added to a process. It is read only now")
299  super(_Parameterizable,self).__delattr__(name)
300  self.__parameterNames.remove(name)
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:223

◆ __raiseBadSetAttr()

def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 302 of file Mixins.py.

302  def __raiseBadSetAttr(name):
303  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 267 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().

267  def __setattr__(self,name,value):
268  #since labels are not supposed to have underscores at the beginning
269  # I will assume that if we have such then we are setting an internal variable
270  if self.isFrozen() and not (name in ["_Labelable__label","_isFrozen"] or name.startswith('_')):
271  message = "Object already added to a process. It is read only now\n"
272  message += " %s = %s" %(name, value)
273  message += "\nThe original parameters are:\n"
274  message += self.dumpPython() + '\n'
275  raise ValueError(message)
276  # underscored names bypass checking for _ParameterTypeBase
277  if name[0]=='_':
278  super(_Parameterizable,self).__setattr__(name,value)
279  elif not name in self.__dict__:
280  self.__addParameter(name, value)
281  self._isModified = True
282  else:
283  # handle the case where users just replace with a value, a = 12, rather than a = cms.int32(12)
284  if isinstance(value,_ParameterTypeBase):
285  self.__dict__[name] = self.__dict__[name]._checkAndReturnValueWithType(value)
286  else:
287  self.__dict__[name].setValue(value)
288  self._isModified = True
289 
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 258 of file Mixins.py.

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

Referenced by Mixins._Parameterizable.__init__().

258  def __setParameters(self,parameters):
259  v = None
260  for name,value in parameters.items():
261  if name == 'allowAnyLabel_':
262  v = value
263  continue
264  self.__addParameter(name, value)
265  if v is not None:
266  self.__validator=v

◆ dumpPython()

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

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

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

Referenced by Mixins._Parameterizable.hasParameter().

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

◆ 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 198 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().

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

◆ insertContentsInto()

def Mixins._Parameterizable.insertContentsInto (   self,
  parameterSet 
)

Definition at line 378 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

378  def insertContentsInto(self, parameterSet):
379  for name in self.parameterNames_():
380  param = getattr(self,name)
381  param.insertInto(parameterSet, name)
382 
383 

◆ isFrozen()

def Mixins._Parameterizable.isFrozen (   self)

Definition at line 290 of file Mixins.py.

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

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

290  def isFrozen(self):
291  return self._isFrozen

◆ isModified()

def Mixins._Parameterizable.isModified (   self)

Definition at line 188 of file Mixins.py.

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

188  def isModified(self):
189  if self._isModified:
190  return True
191  for name in self.parameterNames_():
192  param = self.__dict__[name]
193  if isinstance(param, _Parameterizable) and param.isModified():
194  self._isModified = True
195  return True
196  return False
197 

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

References Mixins._Parameterizable.parameterNames_().

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

231  def parameters_(self):
232  """Returns a dictionary of copies of the user-set parameters"""
233  import copy
234  result = dict()
235  for name in self.parameterNames_():
236  result[name]=copy.deepcopy(self.__dict__[name])
237  return result
238 

◆ setIsFrozen()

def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 292 of file Mixins.py.

Referenced by Modules._Module.__init__().

292  def setIsFrozen(self):
293  self._isFrozen = True
294  for name in self.parameterNames_():
295  self.__dict__[name].setIsFrozen()

Member Data Documentation

◆ __validator

Mixins._Parameterizable.__validator
private

◆ _isFrozen

Mixins._Parameterizable._isFrozen
private

◆ _isModified

Mixins._Parameterizable._isModified
private