CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
Modules.SwitchProducer Class Reference
Inheritance diagram for Modules.SwitchProducer:
Modules.EDProducer Modules._Module Mixins._ConfigureComponent Mixins._TypedParameterizable Mixins._Labelable SequenceTypes._SequenceLeaf Mixins._Parameterizable SequenceTypes._Sequenceable Config.SwitchProducerTest Modules.SwitchProducerPickleable Modules.SwitchProducerTest Modules.SwitchProducerTest1Dis Modules.SwitchProducerTest2Dis

Public Member Functions

def __init__ (self, caseFunctionDict, kargs)
 
def __setattr__ (self, name, value)
 
def appendToProcessDescLists_ (self, modules, aliases, myname)
 
def caseLabel_ (self, name, case)
 
def clone (self, params)
 
def dumpPython (self, options=PrintOptions())
 
def insertInto (self, parameterSet, myname)
 
def moduleLabel_ (self, myname)
 
def nameInProcessDesc_ (self, myname)
 
- Public Member Functions inherited from Modules.EDProducer
def __init__ (self, type_, arg, kargs)
 
- Public Member Functions inherited from Modules._Module
def __init__ (self, type_, arg, kargs)
 
def insertInto (self, parameterSet, myname)
 
def setPrerequisites (self, libs)
 
- Public Member Functions inherited from Mixins._TypedParameterizable
def __init__ (self, type_, arg, kargs)
 
def appendToProcessDescList_ (self, lst, myname)
 
def clone (self, args, params)
 
def copy (self)
 
def dumpConfig (self, options=PrintOptions())
 
def dumpPython (self, options=PrintOptions())
 
def dumpPythonAttributes (self, myname, options)
 
def insertInto (self, parameterSet, myname)
 
def moduleLabel_ (self, myname)
 
def nameInProcessDesc_ (self, myname)
 
def type_ (self)
 
- Public Member Functions inherited from Mixins._Parameterizable
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)
 
- Public Member Functions inherited from Mixins._Labelable
def __str__ (self)
 
def dumpSequenceConfig (self)
 
def dumpSequencePython (self, options=PrintOptions())
 
def hasLabel_ (self)
 
def label (self)
 
def label_ (self)
 
def setLabel (self, label)
 
- Public Member Functions inherited from SequenceTypes._SequenceLeaf
def __init__ (self)
 
def isLeaf (self)
 
- Public Member Functions inherited from SequenceTypes._Sequenceable
def __add__ (self, rhs)
 
def __init__ (self)
 
def __invert__ (self)
 
def __mul__ (self, rhs)
 
def isLeaf (self)
 
def isOperation (self)
 
def resolve (self, processDict, keepIfCannotResolve=False)
 
def visitNode (self, visitor)
 

Static Public Member Functions

def getCpu ()
 

Private Member Functions

def __addParameter (self, name, value)
 
def __setParameters (self, parameters)
 
def _chooseCase (self)
 
def _clonesequence (self, lookuptable)
 
def _errorstr (self)
 
def _getProducer (self)
 
def _placeImpl (self, name, proc)
 

Static Private Member Functions

def __typeIsValid (typ)
 

Private Attributes

 _caseFunctionDict
 
 _isModified
 

Detailed Description

This purpose class is to provide a switch of EDProducers for a single module/product label.

The decision is done at the time when the python configuration is
translated to C++. This class is generic, and intended to be
inherited for concrete switches. Example:

class SwitchProducerFoo(SwitchProducer):
    def __init__(self, **kargs):
        super(SwitchProducerFoo,self).__init__(
            dict(case1 = case1Func, case2 = case2Func),
            **kargs
        )

foo = SwitchProducerFoo(
    case1 = EDProducer("Producer1"),
    case2 = EDProducer("Producer2")
)

Here case1Func and case2Func are functions that return a (bool,
int) tuple, where the bool tells whether that case is enabled or
not, and the int tells the priority of that case. The case with
the highest priority among those that are enabled will get chosen.

The end result is that the product(s) labeled as "foo" will be
produced with one of the producers. It would be good if their
output product types and instance names would be the same (or very
close).

Definition at line 221 of file Modules.py.

Constructor & Destructor Documentation

def Modules.SwitchProducer.__init__ (   self,
  caseFunctionDict,
  kargs 
)

Definition at line 250 of file Modules.py.

250  def __init__(self, caseFunctionDict, **kargs):
251  super(SwitchProducer,self).__init__(None)
252  self._caseFunctionDict = copy.copy(caseFunctionDict)
253  self.__setParameters(kargs)
254  self._isModified = False
255 
def __setParameters(self, parameters)
Definition: Mixins.py:242
def __init__(self, caseFunctionDict, kargs)
Definition: Modules.py:250

Member Function Documentation

def Modules.SwitchProducer.__addParameter (   self,
  name,
  value 
)
private

Definition at line 281 of file Modules.py.

References Modules.SwitchProducer.__typeIsValid(), Modules.SwitchProducer._caseFunctionDict, Mixins._ParameterTypeBase._isModified, Mixins._SimpleParameterTypeBase._isModified, Mixins._Parameterizable._isModified, editorTools.UserCodeTool.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ImportTool.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ApplyTool.dumpPython(), Mixins._ParameterTypeBase.dumpPython(), ConfigToolBase.ConfigToolBase.dumpPython(), Mixins.UsingBlock.dumpPython(), Vispa.Plugins.ConfigEditor.ConfigEditorTabController.ConfigEditorTabController.dumpPython(), Mixins._Parameterizable.dumpPython(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor.dumpPython(), Config.Process.dumpPython(), Config.SubProcess.dumpPython(), and join().

281  def __addParameter(self, name, value):
282  if not self.__typeIsValid(value):
283  raise TypeError(name+" does not already exist, so it can only be set to a cms.EDProducer or cms.EDAlias")
284  if name not in self._caseFunctionDict:
285  raise ValueError("Case '%s' is not allowed (allowed ones are %s)" % (name, ",".join(six.iterkeys(self._caseFunctionDict))))
286  if name in self.__dict__:
287  message = "Duplicate insert of member " + name
288  message += "\nThe original parameters are:\n"
289  message += self.dumpPython() + '\n'
290  raise ValueError(message)
291  self.__dict__[name]=value
292  self._Parameterizable__parameterNames.append(name)
293  self._isModified = True
294 
def __typeIsValid(typ)
Definition: Modules.py:278
def __addParameter(self, name, value)
Definition: Modules.py:281
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:283
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def Modules.SwitchProducer.__setattr__ (   self,
  name,
  value 
)

Definition at line 299 of file Modules.py.

References Mixins._Parameterizable.__addParameter(), Modules.SwitchProducer.__typeIsValid(), Mixins._ParameterTypeBase._isModified, Mixins._SimpleParameterTypeBase._isModified, Mixins._Parameterizable._isModified, editorTools.UserCodeTool.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ImportTool.dumpPython(), Vispa.Plugins.ConfigEditor.ToolDataAccessor.ApplyTool.dumpPython(), Mixins._ParameterTypeBase.dumpPython(), ConfigToolBase.ConfigToolBase.dumpPython(), Mixins.UsingBlock.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(), and Mixins._Parameterizable.isFrozen().

Referenced by GenObject.GenObject.setValue().

299  def __setattr__(self, name, value):
300  # Following snippet copied and customized from
301  # _Parameterizable in order to support Modifier.toModify
302  #
303  #since labels are not supposed to have underscores at the beginning
304  # I will assume that if we have such then we are setting an internal variable
305  if self.isFrozen() and not (name in ["_Labelable__label","_isFrozen"] or name.startswith('_')):
306  message = "Object already added to a process. It is read only now\n"
307  message += " %s = %s" %(name, value)
308  message += "\nThe original parameters are:\n"
309  message += self.dumpPython() + '\n'
310  raise ValueError(message)
311  # underscored names bypass checking for _ParameterTypeBase
312  if name[0]=='_':
313  super(SwitchProducer, self).__setattr__(name,value)
314  elif not name in self.__dict__:
315  self.__addParameter(name, value)
316  self._isModified = True
317  else:
318  if not self.__typeIsValid(value):
319  raise TypeError(name+" can only be set to a cms.EDProducer or cms.EDAlias")
320  # We should always receive an cms.EDProducer
321  self.__dict__[name] = value
322  self._isModified = True
323 
def __typeIsValid(typ)
Definition: Modules.py:278
def dumpPython(self, options=PrintOptions())
Definition: Mixins.py:283
def __addParameter(self, name, value)
Definition: Mixins.py:230
def __setattr__(self, name, value)
Definition: Modules.py:299
def isFrozen(self)
Definition: Mixins.py:269
def Modules.SwitchProducer.__setParameters (   self,
  parameters 
)
private

Definition at line 295 of file Modules.py.

References Mixins._Parameterizable.__addParameter().

295  def __setParameters(self, parameters):
296  for name, value in six.iteritems(parameters):
297  self.__addParameter(name, value)
298 
def __setParameters(self, parameters)
Definition: Modules.py:295
def __addParameter(self, name, value)
Definition: Mixins.py:230
def Modules.SwitchProducer.__typeIsValid (   typ)
staticprivate

Definition at line 278 of file Modules.py.

Referenced by Modules.SwitchProducer.__addParameter(), and Modules.SwitchProducer.__setattr__().

278  def __typeIsValid(typ):
279  return (isinstance(typ, EDProducer) and not isinstance(typ, SwitchProducer)) or isinstance(typ, EDAlias)
280 
def __typeIsValid(typ)
Definition: Modules.py:278
def Modules.SwitchProducer._chooseCase (   self)
private
Returns the name of the chosen case.

Definition at line 261 of file Modules.py.

References Modules.SwitchProducer._caseFunctionDict, Mixins._Parameterizable.parameterNames_(), and str.

Referenced by Modules.SwitchProducer._getProducer(), and Modules.SwitchProducer.insertInto().

261  def _chooseCase(self):
262  """Returns the name of the chosen case."""
263  cases = self.parameterNames_()
264  bestCase = None
265  for case in cases:
266  (enabled, priority) = self._caseFunctionDict[case]()
267  if enabled and (bestCase is None or bestCase[0] < priority):
268  bestCase = (priority, case)
269  if bestCase is None:
270  raise RuntimeError("All cases '%s' were disabled" % (str(cases)))
271  return bestCase[1]
272 
def parameterNames_(self)
Definition: Mixins.py:175
def _chooseCase(self)
Definition: Modules.py:261
#define str(s)
def Modules.SwitchProducer._clonesequence (   self,
  lookuptable 
)
private

Definition at line 405 of file Modules.py.

References Modules._Module._errorstr(), and triggerObjects_cff.id.

405  def _clonesequence(self, lookuptable):
406  try:
407  return lookuptable[id(self)]
408  except:
409  raise ModuleCloneError(self._errorstr())
def _errorstr(self)
Definition: Modules.py:147
def _clonesequence(self, lookuptable)
Definition: Modules.py:405
def Modules.SwitchProducer._errorstr (   self)
private

Definition at line 410 of file Modules.py.

410  def _errorstr(self):
411  return "SwitchProducer"
412 
413 
def _errorstr(self)
Definition: Modules.py:410
def Modules.SwitchProducer._getProducer (   self)
private
Returns the EDroducer of the chosen case

Definition at line 273 of file Modules.py.

References Modules.SwitchProducer._chooseCase().

273  def _getProducer(self):
274  """Returns the EDroducer of the chosen case"""
275  return self.__dict__[self._chooseCase()]
276 
def _getProducer(self)
Definition: Modules.py:273
def _chooseCase(self)
Definition: Modules.py:261
def Modules.SwitchProducer._placeImpl (   self,
  name,
  proc 
)
private

Definition at line 390 of file Modules.py.

Referenced by SequenceTypes._ModuleSequenceType._place(), and Mixins._TypedParameterizable._place().

390  def _placeImpl(self,name,proc):
391  proc._placeSwitchProducer(name,self)
392 # for case in self.parameterNames_():
393 # caseLabel = self.caseLabel_(name, case)
394 # caseObj = self.__dict__[case]
395 #
396 # if isinstance(caseObj, EDAlias):
397 # # EDAliases end up in @all_aliases automatically
398 # proc._placeAlias(caseLabel, caseObj)
399 # else:
400 # # Note that these don't end up in @all_modules
401 # # automatically because they're not part of any
402 # # Task/Sequence/Path
403 # proc._placeProducer(caseLabel, caseObj)
404 
def _placeImpl(self, name, proc)
Definition: Modules.py:390
def Modules.SwitchProducer.appendToProcessDescLists_ (   self,
  modules,
  aliases,
  myname 
)

Definition at line 368 of file Modules.py.

References Modules.SwitchProducer.caseLabel_(), and Mixins._Parameterizable.parameterNames_().

368  def appendToProcessDescLists_(self, modules, aliases, myname):
369  # This way we can insert the chosen EDProducer to @all_modules
370  # so that we get easily a worker for it
371  modules.append(myname)
372  for case in self.parameterNames_():
373  if isinstance(self.__dict__[case], EDAlias):
374  aliases.append(self.caseLabel_(myname, case))
375  else:
376  modules.append(self.caseLabel_(myname, case))
377 
def appendToProcessDescLists_(self, modules, aliases, myname)
Definition: Modules.py:368
def parameterNames_(self)
Definition: Mixins.py:175
def caseLabel_(self, name, case)
Definition: Modules.py:366
def Modules.SwitchProducer.caseLabel_ (   self,
  name,
  case 
)

Definition at line 366 of file Modules.py.

Referenced by Modules.SwitchProducer.appendToProcessDescLists_(), and Modules.SwitchProducer.insertInto().

366  def caseLabel_(self, name, case):
367  return name+"@"+case
def caseLabel_(self, name, case)
Definition: Modules.py:366
def Modules.SwitchProducer.clone (   self,
  params 
)

Definition at line 324 of file Modules.py.

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

324  def clone(self, **params):
325  returnValue = SwitchProducer.__new__(type(self))
326 
327  # Need special treatment as cms.EDProducer is not a valid parameter type (except in this case)
328  myparams = dict()
329  for name, value in six.iteritems(params):
330  if value is None:
331  continue
332  elif isinstance(value, dict):
333  myparams[name] = self.__dict__[name].clone(**value)
334  else: # value is an EDProducer
335  myparams[name] = value.clone()
336 
337  # Add the ones that were not customized
338  for name in self.parameterNames_():
339  if name not in params:
340  myparams[name] = self.__dict__[name].clone()
341  returnValue.__init__(**myparams)
342  returnValue._isModified = False
343  returnValue._isFrozen = False
344  saveOrigin(returnValue, 1)
345  return returnValue
346 
def saveOrigin(obj, level)
Definition: Mixins.py:659
def clone(self, params)
Definition: Modules.py:324
def parameterNames_(self)
Definition: Mixins.py:175
def Modules.SwitchProducer.dumpPython (   self,
  options = PrintOptions() 
)

Definition at line 347 of file Modules.py.

References Mixins._Parameterizable.parameterNames_().

347  def dumpPython(self, options=PrintOptions()):
348  # Note that if anyone uses the generic SwitchProducer instead
349  # of a derived-one, the information on the functions for the
350  # producer decision is lost
351  specialImportRegistry.registerUse(self)
352  result = "%s(" % self.__class__.__name__ # not including cms. since the deriving classes are not in cms "namespace"
353  options.indent()
354  for resource in sorted(self.parameterNames_()):
355  result += "\n" + options.indentation() + resource + " = " + getattr(self, resource).dumpPython(options).rstrip() + ","
356  if result[-1] == ",":
357  result = result.rstrip(",")
358  options.unindent()
359  result += "\n)\n"
360  return result
361 
def dumpPython(self, options=PrintOptions())
Definition: Modules.py:347
def parameterNames_(self)
Definition: Mixins.py:175
def Modules.SwitchProducer.getCpu ( )
static
Returns a function that returns the priority for a CPU "computing device". Intended to be used by deriving classes.

Definition at line 257 of file Modules.py.

257  def getCpu():
258  """Returns a function that returns the priority for a CPU "computing device". Intended to be used by deriving classes."""
259  return _switch_cpu
260 
def Modules.SwitchProducer.insertInto (   self,
  parameterSet,
  myname 
)

Definition at line 378 of file Modules.py.

References Modules.SwitchProducer._chooseCase(), Modules.SwitchProducer.caseLabel_(), FWJobMetadataManager::Data.moduleLabel_, PFMatchedCandidateRefExtractor.moduleLabel_, edm::ModuleLabelMatch.moduleLabel_, GBRForestWriter.moduleLabel_, MuonMETcorrInputProducer.moduleLabel_, edm::BranchKey.moduleLabel_, SysShiftMETcorrInputProducer.moduleLabel_, ShiftedJetProducerByMatchedObjectT< T >.moduleLabel_, Type0PFMETcorrInputProducer.moduleLabel_, PFCandMETcorrInputProducer.moduleLabel_, NoPileUpPFMEtProducer.moduleLabel_, PFchsMETcorrInputProducer.moduleLabel_, ShiftedPFCandidateProducerForPFMVAMEt.moduleLabel_, MultShiftMETcorrInputProducer.moduleLabel_, MultShiftMETcorrDBInputProducer.moduleLabel_, ShiftedParticleProducer.moduleLabel_, RecoTauDiscriminantCutMultiplexer.moduleLabel_, PATTauDiscriminantCutMultiplexer.moduleLabel_, NoPileUpPFMEtDataProducer.moduleLabel_, ShiftedPFCandidateProducerForPFNoPUMEt.moduleLabel_, BoostedTauSeedsProducer.moduleLabel_, RecoTauGenericJetRegionProducer< JetType, CandType >.moduleLabel_, PATTauDiscriminationAgainstElectronMVA6.moduleLabel_, TauDiscriminationAgainstElectronDeadECAL< TauType, TauDiscriminator >.moduleLabel_, SubjetFilterAlgorithm.moduleLabel_, pat::TauJetCorrFactorsProducer.moduleLabel_, PFRecoTauDiscriminationAgainstElectronMVA6.moduleLabel_, PFRecoTauDiscriminationAgainstElectronMVA5.moduleLabel_, ObjectViewMatcher< T1, T2 >.moduleLabel_, ObjectViewCleaner< T >.moduleLabel_, PFRecoTauDiscriminationAgainstMuonSimple.moduleLabel_, JetIdSelector< T >.moduleLabel_, PFRecoTauChargedHadronProducer.moduleLabel_, edm::ProductSelectorRules::Rule.moduleLabel_, PFRecoTauDiscriminationAgainstMuon2.moduleLabel_, TauTagValidation.moduleLabel_, MinMETProducerT< T >.moduleLabel_, edm::ModuleDescription.moduleLabel_, ShiftedParticleProducerT< T >.moduleLabel_, TauDiscriminationProducerBase< TauType, TauDiscriminator >.moduleLabel_, PFRecoTauDiscriminationAgainstMuonMVA.moduleLabel_, HLTMuonMatchAndPlot.moduleLabel_, CorrectedMETProducerT< T >.moduleLabel_, PFRecoTauDiscriminationByIsolationMVA2.moduleLabel_, edm::test::TestProcessorConfig::ProduceEntry.moduleLabel_, reco::tau::PFRecoTauDiscriminationByMVAIsolationRun2.moduleLabel_, reco::tau::PATTauDiscriminationByMVAIsolationRun2.moduleLabel_, VirtualJetProducer.moduleLabel_, ShiftedJetProducerT< T, Textractor >.moduleLabel_, edm::PoolOutputModule.moduleLabel_, CaloJetMETcorrInputProducerT< T, Textractor >.moduleLabel_, PFRecoTauDiscriminationByIsolation.moduleLabel_, edm::BranchDescription.moduleLabel_, JetCleanerForType1METT< T, Textractor >.moduleLabel_, PFJetMETcorrInputProducerT< T, Textractor >.moduleLabel_, edm::ProductResolverIndexHelper::Item.moduleLabel_, Mixins._TypedParameterizable.moduleLabel_(), Mixins._TypedParameterizable.nameInProcessDesc_(), Config.SubProcess.nameInProcessDesc_(), and Mixins._Parameterizable.parameterNames_().

378  def insertInto(self, parameterSet, myname):
379  for case in self.parameterNames_():
380  producer = self.__dict__[case]
381  producer.insertInto(parameterSet, self.caseLabel_(myname, case))
382  newpset = parameterSet.newPSet()
383  newpset.addString(True, "@module_label", self.moduleLabel_(myname))
384  newpset.addString(True, "@module_type", "SwitchProducer")
385  newpset.addString(True, "@module_edm_type", "EDProducer")
386  newpset.addVString(True, "@all_cases", [myname+"@"+p for p in self.parameterNames_()])
387  newpset.addString(False, "@chosen_case", myname+"@"+self._chooseCase())
388  parameterSet.addPSet(True, self.nameInProcessDesc_(myname), newpset)
389 
def moduleLabel_(self, myname)
Definition: Mixins.py:473
def nameInProcessDesc_(self, myname)
Definition: Mixins.py:471
def insertInto(self, parameterSet, myname)
Definition: Modules.py:378
def parameterNames_(self)
Definition: Mixins.py:175
def caseLabel_(self, name, case)
Definition: Modules.py:366
def _chooseCase(self)
Definition: Modules.py:261
def Modules.SwitchProducer.moduleLabel_ (   self,
  myname 
)

Definition at line 364 of file Modules.py.

Referenced by ExternalGeneratorFilter.ExternalGeneratorFilter.insertInto().

364  def moduleLabel_(self, myname):
365  return myname
def moduleLabel_(self, myname)
Definition: Modules.py:364
def Modules.SwitchProducer.nameInProcessDesc_ (   self,
  myname 
)

Definition at line 362 of file Modules.py.

Referenced by Types.EDAlias.appendToProcessDescList_(), ExternalGeneratorFilter.ExternalGeneratorFilter.insertInto(), and Types.EDAlias.insertInto().

362  def nameInProcessDesc_(self, myname):
363  return myname
def nameInProcessDesc_(self, myname)
Definition: Modules.py:362

Member Data Documentation

Modules.SwitchProducer._caseFunctionDict
private
Modules.SwitchProducer._isModified
private

Definition at line 254 of file Modules.py.