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__
 
def __init__ (self, arg, kargs)
 
def __repr__ (self)
 
def __setattr__
 
def dumpPython
 
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
 
def __setParameters (self, parameters)
 

Static Private Member Functions

def __raiseBadSetAttr
 

Private Attributes

 __validator
 
 _isFrozen
 
 _isModified
 

Detailed Description

Base class for classes which allow addition of _ParameterTypeBase data

Definition at line 169 of file Mixins.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 171 of file Mixins.py.

References Mixins._Parameterizable.__setParameters().

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

Definition at line 243 of file Mixins.py.

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

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

◆ __delattr__()

def Mixins._Parameterizable.__delattr__ (   self,
  name 
)

Definition at line 300 of file Mixins.py.

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

300  def __delattr__(self,name:str):
301  if self.isFrozen():
302  raise ValueError("Object already added to a process. It is read only now")
303  super(_Parameterizable,self).__delattr__(name)
304  self.__parameterNames.remove(name)
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:233

◆ __raiseBadSetAttr()

def Mixins._Parameterizable.__raiseBadSetAttr (   name)
staticprivate

Definition at line 306 of file Mixins.py.

306  def __raiseBadSetAttr(name:str):
307  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,
  str 
)

◆ __setattr__()

def Mixins._Parameterizable.__setattr__ (   self,
  name 
)

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

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

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

Referenced by Mixins._Parameterizable.__init__().

262  def __setParameters(self,parameters):
263  v = None
264  for name,value in parameters.items():
265  if name == 'allowAnyLabel_':
266  v = value
267  continue
268  self.__addParameter(name, value)
269  if v is not None:
270  self.__validator=v

◆ dumpPython()

def Mixins._Parameterizable.dumpPython (   self,
  options 
)

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

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

Referenced by Mixins._Parameterizable.hasParameter().

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

◆ hasParameter()

def Mixins._Parameterizable.hasParameter (   self,
  params,
  bool 
)
_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 202 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().

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

◆ insertContentsInto()

def Mixins._Parameterizable.insertContentsInto (   self,
  parameterSet 
)

Definition at line 382 of file Mixins.py.

References Mixins._Parameterizable.parameterNames_().

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

382  def insertContentsInto(self, parameterSet):
383  for name in self.parameterNames_():
384  param = getattr(self,name)
385  param.insertInto(parameterSet, name)
386 
387 

◆ isFrozen()

def Mixins._Parameterizable.isFrozen (   self,
  bool 
)

Definition at line 294 of file Mixins.py.

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

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

294  def isFrozen(self) -> bool:
295  return self._isFrozen

◆ isModified()

def Mixins._Parameterizable.isModified (   self,
  bool 
)

Definition at line 192 of file Mixins.py.

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

192  def isModified(self) -> bool:
193  if self._isModified:
194  return True
195  for name in self.parameterNames_():
196  param = self.__dict__[name]
197  if isinstance(param, _Parameterizable) and param.isModified():
198  self._isModified = True
199  return True
200  return False
201 

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

References Mixins._Parameterizable.parameterNames_().

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

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

◆ setIsFrozen()

def Mixins._Parameterizable.setIsFrozen (   self)

Definition at line 296 of file Mixins.py.

Referenced by Modules._Module.__init__().

296  def setIsFrozen(self):
297  self._isFrozen = True
298  for name in self.parameterNames_():
299  self.__dict__[name].setIsFrozen()

Member Data Documentation

◆ __validator

Mixins._Parameterizable.__validator
private

◆ _isFrozen

Mixins._Parameterizable._isFrozen
private

◆ _isModified

Mixins._Parameterizable._isModified
private