CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
common.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 def producers_by_type(process, *types):
4  "Find all EDProducers in the Process that are instances of the given C++ type."
5  return (module for module in process._Process__producers.values() if module._TypedParameterizable__type in types)
6 
7 def filters_by_type(process, *types):
8  "Find all EDFilters in the Process that are instances of the given C++ type."
9  return (filter for filter in process._Process__filters.values() if filter._TypedParameterizable__type in types)
10 
11 def analyzers_by_type(process, *types):
12  "Find all EDAnalyzers in the Process that are instances of the given C++ type."
13  return (analyzer for analyzer in process._Process__analyzers.values() if analyzer._TypedParameterizable__type in types)
14 
15 def esproducers_by_type(process, *types):
16  "Find all ESProducers in the Process that are instances of the given C++ type."
17  return (module for module in process._Process__esproducers.values() if module._TypedParameterizable__type in types)
18 
19 
20 # logic from Modifier.toModify from FWCore/ParameterSet/python/Config.py
21 def replace_with(fromObj, toObj):
22  """Replace one object with a different one of the same type.
23 
24  This function replaces the contents of `fromObj` object with those of `toObj`,
25  so all references ot it remain valid.
26  """
27 
28  if type(toObj) != type(fromObj):
29  raise TypeError('replaceWith requires both arguments to be the same type')
30 
31  if isinstance(toObj, cms._ModuleSequenceType):
32  fromObj._seq = toObj._seq
33 
34  elif isinstance(toObj, cms._Parameterizable):
35  # delete the old items, in case `toObj` is not a complete superset of `fromObj`
36  for p in fromObj.parameterNames_():
37  delattr(fromObj, p)
38  for p in toObj.parameterNames_():
39  setattr(fromObj, p, getattr(toObj, p))
40  if isinstance(toObj, cms._TypedParameterizable):
41  fromObj._TypedParameterizable__type = toObj._TypedParameterizable__type
42 
43  else:
44  raise TypeError('replaceWith does not work with "%s" objects' % str(type(fromObj)))
45 
def filters_by_type
Definition: common.py:7
def esproducers_by_type
Definition: common.py:15
def replace_with
Definition: common.py:21
def producers_by_type
Definition: common.py:3
def analyzers_by_type
Definition: common.py:11